A Minecraft server-side mod that adds various teleportation related commands
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Stuff is starting to work

+41 -14
+9 -1
common/src/main/java/dev/mrsnowy/teleport_commands/TeleportCommands.java
··· 217 217 byte[] json = gson.toJson(mainJsonObject).getBytes(); 218 218 Files.write(StorageManager.STORAGE_FILE, json, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); 219 219 220 - LOGGER.info("Success! Cleaned: {}B", Math.round(( startFileSize - Files.size(StorageManager.STORAGE_FILE) ))); 220 + // Only show amount cleaned when it isn't 0B lool 221 + int diff = Math.round(( startFileSize - Files.size(StorageManager.STORAGE_FILE) )); 222 + 223 + if (diff > 0) { 224 + LOGGER.info("Success! Cleaned: {}B", diff); 225 + } else { 226 + LOGGER.info("Success!"); 227 + } 228 + 221 229 return gson.fromJson(mainJsonObject, StorageManager.StorageClass.class); 222 230 } 223 231
+16 -2
common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java
··· 7 7 import dev.mrsnowy.teleport_commands.common.Player; 8 8 import dev.mrsnowy.teleport_commands.suggestions.HomeSuggestionProvider; 9 9 10 - import java.util.ArrayList; 10 + import java.util.List; 11 11 import java.util.Optional; 12 12 13 13 import net.minecraft.ChatFormatting; ··· 341 341 342 342 private static void PrintHomes(ServerPlayer player) throws Exception { 343 343 344 + // todo! fix the values 345 + 344 346 // Gets player storage 345 347 Optional<Player> optionalPlayerStorage = STORAGE.getPlayer(player.getStringUUID()); 346 348 if (optionalPlayerStorage.isEmpty()) { ··· 350 352 351 353 Player playerStorage = optionalPlayerStorage.get(); 352 354 353 - ArrayList<NamedLocation> homes = playerStorage.getHomes(); 355 + List<NamedLocation> homes = playerStorage.getHomes(); 354 356 355 357 // Check if there are any homes lol 356 358 if (homes.isEmpty()) { ··· 433 435 new ClickEvent( 434 436 ClickEvent.Action.SUGGEST_COMMAND, 435 437 String.format("/renamehome %s ", currentHome.getName()) 438 + ) 439 + ) 440 + ) 441 + ) 442 + .append(" ") 443 + .append(getTranslatedText("commands.teleport_commands.common.default", player) 444 + .withStyle(ChatFormatting.DARK_BLUE) 445 + .withStyle(style -> 446 + style.withClickEvent( 447 + new ClickEvent( 448 + ClickEvent.Action.RUN_COMMAND, 449 + String.format("/defaulthome %s", currentHome.getName()) 436 450 ) 437 451 ) 438 452 )
+2 -2
common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java
··· 14 14 import net.minecraft.server.level.ServerPlayer; 15 15 import net.minecraft.world.phys.Vec3; 16 16 17 - import java.util.ArrayList; 17 + import java.util.List; 18 18 import java.util.Optional; 19 19 20 20 import static dev.mrsnowy.teleport_commands.storage.StorageManager.*; ··· 225 225 226 226 private static void PrintWarps(ServerPlayer player) throws Exception { 227 227 // Get warps 228 - ArrayList<NamedLocation> warps = STORAGE.getWarps(); 228 + List<NamedLocation> warps = STORAGE.getWarps(); 229 229 230 230 // Check if there are any warps lol 231 231 if (warps.isEmpty()) {
+3 -2
common/src/main/java/dev/mrsnowy/teleport_commands/common/Player.java
··· 4 4 import net.minecraft.core.BlockPos; 5 5 6 6 import java.util.ArrayList; 7 + import java.util.List; 7 8 import java.util.Objects; 8 9 import java.util.Optional; 9 10 ··· 29 30 } 30 31 31 32 // returns all homes 32 - public ArrayList<NamedLocation> getHomes() { 33 - return (ArrayList<NamedLocation>) unmodifiableList(Homes); 33 + public List<NamedLocation> getHomes() { 34 + return unmodifiableList(Homes); 34 35 } 35 36 36 37 // returns a specific home based on the name (if there is one)
+10 -6
common/src/main/java/dev/mrsnowy/teleport_commands/storage/StorageManager.java
··· 12 12 import java.nio.file.Path; 13 13 import java.nio.file.StandardOpenOption; 14 14 import java.util.ArrayList; 15 + import java.util.List; 15 16 import java.util.Objects; 16 17 import java.util.Optional; 18 + 19 + import static java.util.Collections.unmodifiableList; 17 20 18 21 public class StorageManager { 19 22 public static Path STORAGE_FOLDER; ··· 37 40 38 41 // create the basic storage if it is empty 39 42 if (new File(String.valueOf(STORAGE_FILE)).length() == 0) { 40 - STORAGE = new StorageClass(); 43 + StorageManager.STORAGE = new StorageClass(); 41 44 StorageSaver(); // todo! verify that it creates em correctly 42 45 } 43 46 ··· 49 52 } 50 53 51 54 public static void StorageSaver() throws Exception { 55 + // todo! maybe throttle saves? 52 56 Gson gson = new GsonBuilder().create(); 53 - byte[] json = gson.toJson( STORAGE ).getBytes(); 57 + byte[] json = gson.toJson( StorageManager.STORAGE ).getBytes(); 54 58 55 59 Files.write(STORAGE_FILE, json, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); 56 60 } 57 61 58 62 59 63 public static class StorageClass { 60 - private static final ArrayList<NamedLocation> Warps = new ArrayList<>(); 61 - private static final ArrayList<Player> Players = new ArrayList<>(); 64 + private final ArrayList<NamedLocation> Warps = new ArrayList<>(); 65 + private final ArrayList<Player> Players = new ArrayList<>(); 62 66 63 67 // ----- 64 68 65 69 // returns all warps 66 - public ArrayList<NamedLocation> getWarps() { 67 - return Warps; 70 + public List<NamedLocation> getWarps() { 71 + return unmodifiableList(Warps); 68 72 } 69 73 70 74 // filters the warpList and finds the one with the name (if there is one)
+1 -1
common/src/main/java/dev/mrsnowy/teleport_commands/utils/tools.java
··· 177 177 } 178 178 179 179 // todo! test 180 - // checks if a bock position is unsafe, used by the teleportSafetyChecker. 180 + // checks if a BlockPos is safe, used by the teleportSafetyChecker. 181 181 private static boolean isBlockPosSafe(BlockPos bottomPlayer, ServerLevel world) { 182 182 183 183 // get the block below the player