···1212- Improved the Storage classes and functions (I'm doing proper java, yipie)
1313- Better error handling for command suggestions
1414- Added hover effects for warp and homes text (W.I.P)
1515+- Throw an exception when the world isn't found (when doing back or home), instead of giving an incorrect notFound error.
15161617### [v1.2.2]
1718- Handled a case where the client (geyser) will return the language as uppercase instead of lowercase.
···11+package dev.mrsnowy.teleport_commands.common;
22+33+import dev.mrsnowy.teleport_commands.storage.StorageManager;
44+import net.minecraft.core.BlockPos;
55+66+import java.util.ArrayList;
77+import java.util.Objects;
88+import java.util.Optional;
99+1010+import static java.util.Collections.unmodifiableList;
1111+1212+public class Player {
1313+ private final String UUID;
1414+ private String DefaultHome = "";
1515+ private final ArrayList<NamedLocation> Homes = new ArrayList<>();
1616+1717+ public Player(String uuid) {
1818+ this.UUID = uuid;
1919+ }
2020+2121+ // -----
2222+2323+ public String getUUID() {
2424+ return UUID;
2525+ }
2626+2727+ public String getDefaultHome() {
2828+ return DefaultHome;
2929+ }
3030+3131+ // returns all homes
3232+ public ArrayList<NamedLocation> getHomes() {
3333+ return (ArrayList<NamedLocation>) unmodifiableList(Homes);
3434+ }
3535+3636+ // returns a specific home based on the name (if there is one)
3737+ public Optional<NamedLocation> getHome(String name) {
3838+ return Homes.stream()
3939+ .filter( home -> Objects.equals( home.getName(), name ))
4040+ .findFirst();
4141+ }
4242+4343+ // -----
4444+4545+ public void setDefaultHome(String defaultHome) throws Exception {
4646+ this.DefaultHome = defaultHome;
4747+ StorageManager.StorageSaver();
4848+ }
4949+5050+ // todo! modify this so it uses a NamedLocation as an input
5151+ // creates a new home, if there already is a home it will update the existing one
5252+ public void setHome(String name, BlockPos pos, String world) throws Exception {
5353+ Optional<NamedLocation> optionalHome = getHome(name);
5454+ NamedLocation home;
5555+5656+ if (optionalHome.isEmpty()) {
5757+ home = new NamedLocation(name, pos, world);
5858+5959+ Homes.add(home);
6060+ } else {
6161+ home = optionalHome.get();
6262+6363+ home.setName(name);
6464+ }
6565+6666+ StorageManager.StorageSaver();
6767+ }
6868+6969+ // -----
7070+7171+ public void deleteHome(NamedLocation home) throws Exception {
7272+ Homes.remove(home);
7373+7474+ StorageManager.StorageSaver();
7575+ }
7676+}
···33import com.google.gson.Gson;
44import com.google.gson.GsonBuilder;
55import dev.mrsnowy.teleport_commands.TeleportCommands;
66-import dev.mrsnowy.teleport_commands.storage.classes.NamedLocation;
77-import dev.mrsnowy.teleport_commands.storage.classes.Player;
66+import dev.mrsnowy.teleport_commands.common.NamedLocation;
77+import dev.mrsnowy.teleport_commands.common.Player;
88import net.minecraft.core.BlockPos;
991010import java.io.File;
···101101 }
102102103103 // creates a new player, if there already is a player it will return the existing one. The player won't be saved unless they actually do something lol
104104+ // todo! check if this works fully
104105 public Player addPlayer(String uuid) {
105106 final Optional<Player> OptionalPlayer = getPlayer(uuid);
106107···120121121122 // -----
122123123123- public void removeWarp(String name) throws Exception {
124124- Optional<NamedLocation> OptionalWarp = getWarp(name);
125125-126126- if (OptionalWarp.isPresent()) {
127127- Warps.remove(OptionalWarp.get());
128128- StorageSaver();
129129- } else {
130130- //todo! ???
131131- }
124124+ public void rmWarp(NamedLocation warp) throws Exception {
125125+ Warps.remove(warp);
126126+ StorageSaver();
132127 }
133128 }
134129}
···11package dev.mrsnowy.teleport_commands.utils;
2233import com.google.gson.*;
44-import com.mojang.datafixers.util.Pair;
54import dev.mrsnowy.teleport_commands.TeleportCommands;
6576import java.io.*;
···3938 // teleport!
4039 player.teleportTo(world, coords.x, coords.y, coords.z, Set.of(), player.getYRot(), player.getXRot(), false);
41404242- // Restore flying when teleporting dimensions
4141+ // Restore flying when teleporting trough dimensions
4342 if (flying) {
4443 player.getAbilities().flying = true;
4544 player.onUpdateAbilities();
···6160 );
6261 }
63626363+6464 // checks a 7x7x7 location around the player in order to find a safe place to teleport them to.
6565- public static Pair<Integer, Optional<Vec3>> teleportSafetyChecker(BlockPos blockPos, ServerLevel world, ServerPlayer player) {
6565+ public static Optional<BlockPos> getSafeBlockPos(BlockPos blockPos, ServerLevel world) {
6666 int row = 1;
6767 int rows = 3;
68686969- BlockPos playerBlockPos = new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ());
7070- int playerX = blockPos.getX();
7171- int playerY = blockPos.getY();
7272- int playerZ = blockPos.getZ();
6969+ int blockPosX = blockPos.getX();
7070+ int blockPosY = blockPos.getY();
7171+ int blockPosZ = blockPos.getZ();
73727474- // find a safe location in an x row radius
7575- if (isBlockPosUnsafe(blockPos, world)) {
7373+ if (isBlockPosSafe(blockPos, world)) {
7474+ return Optional.of(blockPos); // safe location found!
76757676+ } else {
7777+ // find a safe location in an x row radius
7778 while (row <= rows) {
7879 // TeleportCommands.LOGGER.info("currently doing row " + row + " of " + rows); //debug
7979-8080 for (int z = -row; z <= row; z++) {
8181 for (int x = -row; x <= row; x++) {
8282 for (int y = -row; y <= row; y++) {
···8484 // checks if we are on the outer layer of the row, not on the inside
8585 if ((x == -row || x == row) || (z == -row || z == row) || (y == -row || y == row)) {
86868787- BlockPos newSafePos = new BlockPos(playerX + x, playerY + y, playerZ + z);
8787+ // calculate a new blockPos based on the offset we generated
8888+ BlockPos newPos = new BlockPos(blockPosX + x, blockPosY + y, blockPosZ + z);
88898989- if (!isBlockPosUnsafe(newSafePos, world)) {
9090-9191- if (!playerBlockPos.equals(newSafePos) || player.level() != world) {
9292- return new Pair<>(0, Optional.of(new Vec3(newSafePos.getX() + 0.5, newSafePos.getY(), newSafePos.getZ() + 0.5))); // safe location found!
9393-9494- } else {
9595- return new Pair<>(1, Optional.of(new Vec3(newSafePos.getX() + 0.5, newSafePos.getY(), newSafePos.getZ() + 0.5))); // the location is already safe!
9696- }
9090+ if (isBlockPosSafe(newPos, world)) {
9191+// return Optional.of(new Vec3(newPos.getX() + 0.5, newPos.getY(), newPos.getZ() + 0.5)); // safe location found!
9292+ return Optional.of(newPos);
9793 }
9894 }
9995 }
···1029810399 row++;
104100 }
105105- // no safe location
106106- return new Pair<>(2, Optional.empty()); // no safe location found!
107101108108- // check if the location is the same
109109- } else if (!playerBlockPos.equals(blockPos) || player.level() != world) {
110110- return new Pair<>(0, Optional.of(new Vec3(playerX + 0.5, playerY, playerZ + 0.5))); // safe location found!
111111-112112- } else {
113113- return new Pair<>(1, Optional.of(new Vec3(playerX + 0.5, playerY, playerZ + 0.5))); // the location is already safe!
102102+ // no safe location
103103+ return Optional.empty(); // no safe location found!
114104 }
115105 }
116106···186176 }
187177 }
188178179179+ // todo! test
189180 // checks if a bock position is unsafe, used by the teleportSafetyChecker.
190190- private static boolean isBlockPosUnsafe(BlockPos bottomPlayer, ServerLevel world) {
181181+ private static boolean isBlockPosSafe(BlockPos bottomPlayer, ServerLevel world) {
191182192183 // get the block below the player
193184 BlockPos belowPlayer = new BlockPos(bottomPlayer.getX(), bottomPlayer.getY() -1, bottomPlayer.getZ()); // below the player
···206197 && (world.getBlockState(bottomPlayer).getCollisionShape(world, bottomPlayer).isEmpty() && !unsafeCollisionFreeBlocks.contains(BottomPlayerId)) // check if it is a collision free block that isn't dangerous
207198 && (!unsafeCollisionFreeBlocks.contains(TopPlayerId))) // check if it is a dangerous collision free block, if it is solid then the player crawls
208199 {
209209- return false; // it's safe
200200+ return true; // it's safe
210201 }
211211- return true; // it's not safe!
202202+ return false; // it's not safe!
212203 }
213204}