···1010- Adding comments to alot of code (W.I.P)
1111- Made it so the DeathLocation is only kept in memory
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)
13151416### [v1.2.2]
1517- Handled a case where the client (geyser) will return the language as uppercase instead of lowercase.
···11+package dev.mrsnowy.teleport_commands.storage;
22+33+import dev.mrsnowy.teleport_commands.storage.classes.DeathLocation;
44+import net.minecraft.core.BlockPos;
55+66+import java.util.ArrayList;
77+import java.util.Objects;
88+import java.util.Optional;
99+1010+public class DeathLocationStorage {
1111+ private static final ArrayList<DeathLocation> deathLocations = new ArrayList<>();
1212+1313+ // filters the deathLocationList and finds the one with the matching player uuid (if there is one)
1414+ public static Optional<DeathLocation> getDeathLocation(String uuid) {
1515+ return deathLocations.stream()
1616+ .filter( deathLocation -> Objects.equals( deathLocation.getUUID(), uuid ))
1717+ .findFirst();
1818+ }
1919+2020+ // updates the deathLocation of a player, if there is no existing entry it will create a new deathLocation.
2121+ public static void setDeathLocation(String uuid, BlockPos pos, String world) {
2222+ Optional<DeathLocation> OptionalDeathLocation = getDeathLocation(uuid);
2323+2424+ if (OptionalDeathLocation.isEmpty()) {
2525+ // create a new deathLocation
2626+ DeathLocation deathLocation = new DeathLocation(uuid, pos, world);
2727+ deathLocations.add(deathLocation);
2828+ } else {
2929+ // modify existing deathLocation
3030+ DeathLocation deathLocation = OptionalDeathLocation.get();
3131+3232+ deathLocation.setBlockPos(pos);
3333+ deathLocation.setWorld(world);
3434+ }
3535+ }
3636+}
···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;
68import net.minecraft.core.BlockPos;
79810import java.io.File;
···1012import java.nio.file.Path;
1113import java.nio.file.StandardOpenOption;
1214import java.util.ArrayList;
1313-import java.util.List;
1415import java.util.Objects;
1516import java.util.Optional;
1617···4748 }
4849 }
49505050-// public static StorageClass.Player PlayerAdd(String UUID) {
5151-//
5252-// // try to find an exising storage for this player
5353-// Optional<StorageClass.Player> playerStorage = STORAGE.Players.stream()
5454-// .filter(player -> Objects.equals(UUID, player.UUID))
5555-// .findFirst();
5656-//
5757-// if (playerStorage.isEmpty()) {
5858-// StorageClass.Player newPlayer = new StorageClass.Player(UUID); // TODO! verify that it creates the player proper
5959-//
6060-// List<StorageClass.Player> playerList = STORAGE.Players;
6161-// playerList.add(newPlayer);
6262-//
6363-//// StorageSaver(); // no need to save since no data is actually set yet!
6464-// TeleportCommands.LOGGER.info("Player '{}' added successfully in storage!", UUID);
6565-// return newPlayer;
6666-// } else {
6767-// TeleportCommands.LOGGER.info("Player '{}' already exists!", UUID);
6868-// return playerStorage.get();
6969-// }
7070-// }
7171-7251 public static void StorageSaver() throws Exception {
7352 Gson gson = new GsonBuilder().create();
7453 byte[] json = gson.toJson( STORAGE ).getBytes();
75547676- TeleportCommands.LOGGER.info(STORAGE.toString());
7777-7855 Files.write(STORAGE_FILE, json, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
7956 }
80578181-// public static Pair<StorageClass, List<StorageClass.NamedLocation>> getWarpStorage() {
8282-// return new Pair<>(STORAGE, STORAGE.Warps);
8383-// }
84588585-// public static Pair<StorageClass, StorageClass.Player> GetPlayerStorage(String UUID) {
8686-//
8787-// // try to find an exising storage for this player
8888-// Optional<StorageClass.Player> playerStorage = STORAGE.Players.stream()
8989-// .filter(player -> Objects.equals(UUID, player.UUID))
9090-// .findFirst();
9191-//
9292-// if (playerStorage.isEmpty()) {
9393-// StorageClass.Player player = PlayerAdd(UUID); // create a new player
9494-//
9595-// return new Pair<>(STORAGE, player);
9696-// }
9797-//
9898-// return new Pair<>(STORAGE, playerStorage.get());
9999-// }
5959+ public static class StorageClass {
6060+ private static final ArrayList<NamedLocation> Warps = new ArrayList<>();
6161+ private static final ArrayList<Player> Players = new ArrayList<>();
100626363+ // -----
10164102102- public static class StorageClass {
103103- public static warpList Warps = new warpList();
104104- public static playerList Players = new playerList();
6565+ // returns all warps
6666+ public ArrayList<NamedLocation> getWarps() {
6767+ return Warps;
6868+ }
10569106106- public static class NamedLocation {
107107- public String name;
108108- public final int x;
109109- public final int y;
110110- public final int z;
111111- public final String world;
7070+ // filters the warpList and finds the one with the name (if there is one)
7171+ public Optional<NamedLocation> getWarp(String name) {
7272+ return Warps.stream()
7373+ .filter(warp -> Objects.equals(warp.getName(), name))
7474+ .findFirst();
7575+ }
11276113113- public NamedLocation(String name, BlockPos pos, String world) {
114114- this.name = name;
115115- this.x = pos.getX();
116116- this.y = pos.getY();
117117- this.z = pos.getZ();
118118- this.world = world;
119119- }
7777+ // filters the playerList and finds the one with the uuid (if there is one)
7878+ public Optional<Player> getPlayer(String uuid) {
7979+ return Players.stream()
8080+ .filter( player -> Objects.equals( player.getUUID(), uuid ))
8181+ .findFirst();
12082 }
12183122122- public static class warpList {
123123- private final ArrayList<NamedLocation> warpList = new ArrayList<>();
8484+ // -----
12485125125- // filters the warpList and finds the one with the name (if there is one)
126126- public Optional<NamedLocation> getWarp(String name) {
127127- return warpList.stream()
128128- .filter( warp -> Objects.equals( warp.name, name ))
129129- .findFirst();
130130- }
8686+ // creates a new warp, if there already is a warp it will update the existing one
8787+ public void setWarp(String name, BlockPos pos, String world) throws Exception {
8888+ Optional<NamedLocation> OptionalWarp = getWarp(name);
13189132132- // returns all warps
133133- public ArrayList<NamedLocation> getWarps() {
134134- return warpList;
9090+ if (OptionalWarp.isEmpty()) {
9191+ // create a new warp
9292+ NamedLocation warp = new NamedLocation(name, pos, world);
9393+ Warps.add(warp);
9494+ } else {
9595+ // modify existing warp
9696+ NamedLocation warp = OptionalWarp.get();
9797+ warp.setName(name);
13598 }
13699137137- // creates a new warp, if there already is a warp it will update the existing one
138138- public void setWarp(String name, BlockPos pos, String world) throws Exception {
139139- Optional<NamedLocation> OptionalWarp = getWarp(name);
140140-141141- if (OptionalWarp.isEmpty()) {
142142- // create a new warp
143143- NamedLocation warp = new NamedLocation(name, pos, world);
144144- warpList.add(warp);
145145- StorageSaver();
146146- } else {
147147- // modify existing warp
148148- NamedLocation warp = OptionalWarp.get();
149149- warp.name = name;
150150- }
151151- }
100100+ StorageSaver();
152101 }
153102154154- public static class playerList {
155155- private final ArrayList<Player> playerList = new ArrayList<>();
103103+ // 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+ public Player addPlayer(String uuid) {
105105+ final Optional<Player> OptionalPlayer = getPlayer(uuid);
156106157157- // filters the playerList and finds the one with the uuid (if there is one)
158158- public Optional<Player> getPlayer(String uuid) {
159159- return playerList.stream()
160160- .filter( player -> Objects.equals( player.UUID, uuid ))
161161- .findFirst();
162162- }
107107+ if (OptionalPlayer.isEmpty()) {
108108+ // create new player
109109+ Player player = new Player(uuid);
110110+ Players.add(player);
111111+// TeleportCommands.LOGGER.info("Player '{}' added successfully in storage!", uuid); // todo! prob remove these loggers
163112164164- // creates a new player, if there already is a player it will return the existing one
165165- public Player addPlayer(String uuid, BlockPos pos, String world) {
166166- Optional<Player> OptionalPlayer = getPlayer(uuid);
167167-168168- if (OptionalPlayer.isEmpty()) {
169169- // create new player
170170- Player player = new Player(uuid);
171171- playerList.add(player);
172172- TeleportCommands.LOGGER.info("Player '{}' added successfully in storage!", uuid);
173173-174174- return player;
175175- } else {
176176- // return existing player
177177- TeleportCommands.LOGGER.info("Player '{}' already exists!", uuid);
178178- return OptionalPlayer.get();
179179- }
113113+ return player;
114114+ } else {
115115+ // return existing player
116116+// TeleportCommands.LOGGER.info("Player '{}' already exists!", uuid);
117117+ return OptionalPlayer.get();
180118 }
181119 }
182120183183-184184- public static class Player {
185185- public final String UUID;
186186- public String DefaultHome = "";
187187- public homeList Homes = new homeList();
188188-189189- public Player(String uuid) {
190190- this.UUID = uuid;
191191- }
192192-193193- public static class homeList {
194194- private final List<NamedLocation> Homes = new ArrayList<>();
195195-196196- // filters the Homes and finds the one with the name (if there is one)
197197- public Optional<NamedLocation> getHome(String name) {
198198- return Homes.stream()
199199- .filter( home -> Objects.equals( home.name, name ))
200200- .findFirst();
201201- }
202202-203203- // returns all homes
204204- public List<NamedLocation> getHomes() {
205205- return Homes;
206206- }
121121+ // -----
207122208208- // creates a new home, if there already is a home it will update the existing one
209209- public void setHome(String name, BlockPos pos, String world) throws Exception {
210210- Optional<NamedLocation> OptionalHome = getHome(name);
123123+ public void removeWarp(String name) throws Exception {
124124+ Optional<NamedLocation> OptionalWarp = getWarp(name);
211125212212- if (OptionalHome.isEmpty()) {
213213- NamedLocation home = new NamedLocation(name, pos, world);
214214-215215- Homes.add(home);
216216- StorageSaver();
217217- } else {
218218- NamedLocation home = OptionalHome.get();
219219-220220- home.name = name;
221221- StorageSaver();
222222- }
223223- }
126126+ if (OptionalWarp.isPresent()) {
127127+ Warps.remove(OptionalWarp.get());
128128+ StorageSaver();
129129+ } else {
130130+ //todo! ???
224131 }
225132 }
226133 }
···6161 "commands.teleport_commands.common.delete": "[Törlés]",
6262 "commands.teleport_commands.common.default": "(Alap)",
6363 "commands.teleport_commands.common.renameExists": "A név már létezik!",
6464- "commands.teleport_commands.common.noLocation": "Nem található a koordináta"
6464+ "commands.teleport_commands.common.noLocation": "Nem található a koordináta",
6565+ "commands.teleport_commands.common.hoverCopy": "Click to copy!"
6566}