···31313232 // function to quickly filter the worlds and get the ServerLevel for the string
3333 public Optional<ServerLevel> getWorld() {
3434- return StreamSupport.stream( TeleportCommands.SERVER.getAllLevels().spliterator(), false ) // woa, this looks silly
3434+ return StreamSupport.stream( TeleportCommands.server.getAllLevels().spliterator(), false ) // woa, this looks silly
3535 .filter(level -> Objects.equals( level.dimension().location().toString(), this.world ))
3636 .findFirst();
3737 }
···53535454 // function to quickly filter the worlds and get the ServerLevel for the string
5555 public Optional<ServerLevel> getWorld() {
5656- return StreamSupport.stream( TeleportCommands.SERVER.getAllLevels().spliterator(), false ) // woa, this looks silly
5656+ return StreamSupport.stream( TeleportCommands.server.getAllLevels().spliterator(), false ) // woa, this looks silly
5757 .filter(level -> Objects.equals( level.dimension().location().toString(), this.world ))
5858 .findFirst();
5959 }
···1010import java.nio.file.StandardOpenOption;
11111212public class ConfigManager {
1313- public static Path CONFIG_FILE;
1414- public static ConfigClass CONFIG;
1515- private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
1616- private static final int defaultVersion = new ConfigClass().getVersion();
1313+ public Path CONFIG_FILE;
1414+ public ConfigClass CONFIG;
1515+ private final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
1616+ private final int defaultVersion = new ConfigClass().getVersion();
17171818- public static void ConfigInit() {
1919- CONFIG_FILE = TeleportCommands.CONFIG_DIR.resolve("teleport_commands.json");
1818+ public ConfigManager() {
1919+ CONFIG_FILE = TeleportCommands.TeleportCommands.configDir.resolve("teleport_commands.json");
20202121 try {
2222 ConfigLoader();
···2828 }
2929 }
30303131- public static void ConfigLoader() throws Exception {
3131+ public void ConfigLoader() throws Exception {
3232 if (!CONFIG_FILE.toFile().exists() || CONFIG_FILE.toFile().length() == 0) {
3333- Files.createDirectories(TeleportCommands.CONFIG_DIR);
3333+ Files.createDirectories(TeleportCommands.configDir);
34343535 Constants.LOGGER.warn("Config file was not found or was empty! Initializing config");
3636 CONFIG = new ConfigClass();
···5353 }
54545555 /// This function checks what version the config file is and migrates it to the current version of the mod.
5656- public static void ConfigMigrator() throws Exception {
5656+ public void ConfigMigrator() throws Exception {
5757 FileReader reader = new FileReader(CONFIG_FILE.toFile());
5858 JsonObject jsonObject = GSON.fromJson(reader, JsonObject.class);
5959···7676 }
7777 }
78787979- public static void ConfigSaver() throws Exception {
7979+ public void ConfigSaver() throws Exception {
8080 // todo! maybe throttle saves?
8181 byte[] json = GSON.toJson( ConfigManager.CONFIG ).getBytes();
82828383 Files.write(CONFIG_FILE, json, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);
8484 }
85858686- public static class ConfigClass {
8686+ public class ConfigClass {
8787 private final int version = 0;
8888 public Teleporting teleporting = new Teleporting();
8989 public Back back = new Back();
···9696 return version;
9797 }
98989999- public static final class Teleporting {
9999+ public final class Teleporting {
100100 private int delay = 5;
101101 private boolean whileMoving = true;
102102 private boolean whileFighting = false;
···77import java.util.Optional;
8899public class DeathLocationStorage {
1010- private static final HashMap<String, DeathLocation> deathLocations = new HashMap<>();
1010+ private final HashMap<String, DeathLocation> deathLocations = new HashMap<>();
11111212 // filters the deathLocationList and finds the one with the matching player uuid (if there is one)
1313- public static Optional<DeathLocation> getDeathLocation(String uuid) {
1313+ public Optional<DeathLocation> getDeathLocation(String uuid) {
1414 return Optional.ofNullable(deathLocations.get(uuid));
1515 }
16161717 // updates the deathLocation of a player, if there is no existing entry it will create a new deathLocation.
1818- public static void setDeathLocation(String uuid, BlockPos pos, String world) {
1818+ public void setDeathLocation(String uuid, BlockPos pos, String world) {
19192020 if (deathLocations.containsKey(uuid)) {
2121 // modify existing deathLocation
···2929 }
3030 }
31313232- public static void clearDeathLocations() {
3232+ public void clearDeathLocations() {
3333 deathLocations.clear();
3434 }
3535}
···1818import static java.util.Collections.unmodifiableList;
19192020public class StorageManager {
2121- public static Path STORAGE_FOLDER;
2222- public static Path STORAGE_FILE;
2323- public static StorageClass STORAGE;
2424- private static final Gson GSON = new GsonBuilder().create();
2525- private static final int defaultVersion = new StorageClass().getVersion();
2121+ public Path STORAGE_FOLDER;
2222+ public Path STORAGE_FILE;
2323+ public StorageClass STORAGE;
2424+ private final Gson GSON = new GsonBuilder().create();
2525+ private final int defaultVersion = new StorageClass().getVersion();
26262727 /// Initializes the StorageManager class and loads the storage from the filesystem.
2828- public static void StorageInit() {
2929- STORAGE_FOLDER = TeleportCommands.SAVE_DIR.resolve("TeleportCommands/");
2828+ public StorageManager() {
2929+ STORAGE_FOLDER = TeleportCommands.TeleportCommands.saveDir.resolve("TeleportCommands/");
3030 STORAGE_FILE = STORAGE_FOLDER.resolve("storage.json");
31313232 try {
···4040 }
41414242 /// Loads the storage from the filesystem
4343- public static void StorageLoader() throws Exception {
4343+ public void StorageLoader() throws Exception {
44444545 if (!STORAGE_FILE.toFile().exists() || STORAGE_FILE.toFile().length() == 0) {
4646 Constants.LOGGER.warn("Storage file was not found or was empty! Initializing storage");
···6868 }
69697070 /// This function checks what version the storage file is and migrates it to the current version of the mod.
7171- public static void StorageMigrator() throws Exception {
7171+ public void StorageMigrator() throws Exception {
7272 FileReader reader = new FileReader(STORAGE_FILE.toFile());
7373 JsonObject jsonObject = GSON.fromJson(reader, JsonObject.class);
7474···120120 }
121121122122 /// Saves the storage to the filesystem
123123- public static void StorageSaver() throws Exception {
123123+ public void StorageSaver() throws Exception {
124124 // todo! maybe throttle saves?
125125- byte[] json = GSON.toJson( StorageManager.STORAGE ).getBytes();
125125+ byte[] json = GSON.toJson( this.STORAGE ).getBytes();
126126127127 Files.write(STORAGE_FILE, json, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);
128128 }
129129130130131131- public static class StorageClass {
131131+ public class StorageClass {
132132 private final int version = 1;
133133 private final ArrayList<NamedLocation> Warps = new ArrayList<>();
134134 private final ArrayList<Player> Players = new ArrayList<>();
···144144 List<NamedLocation> homes = player.getHomes();
145145146146 // Delete any homes with an invalid world_id (if enabled in config)
147147- if (ConfigManager.CONFIG.home.isDeleteInvalid()) {
147147+ if (TeleportCommands.TeleportCommands.config.CONFIG.home.isDeleteInvalid()) {
148148 homes.removeIf(home -> home.getWorld().isEmpty());
149149 }
150150···155155 }
156156157157 // Delete any warps with an invalid world_id (if enabled in config)
158158- if (ConfigManager.CONFIG.warp.isDeleteInvalid()) {
158158+ if (TeleportCommands.TeleportCommands.config.CONFIG.warp.isDeleteInvalid()) {
159159 Warps.removeIf(warp -> warp.getWorld().isEmpty());
160160 }
161161
···1111import java.util.regex.Pattern;
1212import java.util.stream.StreamSupport;
13131414+import dev.mrsnowy.teleport_commands.storage.ConfigManager;
1415import net.minecraft.core.BlockPos;
1516import net.minecraft.core.particles.ParticleTypes;
1617import net.minecraft.network.chat.Component;
···2425import static dev.mrsnowy.teleport_commands.Constants.MOD_ID;
2526import static net.minecraft.sounds.SoundEvents.ENDERMAN_TELEPORT;
26272828+2729public class tools {
3030+ private final TeleportCommands teleportCommands;
28312929- private static final Set<String> unsafeCollisionFreeBlocks = Set.of("block.minecraft.lava", "block.minecraft.flowing_lava", "block.minecraft.end_portal", "block.minecraft.end_gateway","block.minecraft.fire", "block.minecraft.soul_fire", "block.minecraft.powder_snow", "block.minecraft.nether_portal");
3232+ private final Set<String> unsafeCollisionFreeBlocks = Set.of("block.minecraft.lava", "block.minecraft.flowing_lava", "block.minecraft.end_portal", "block.minecraft.end_gateway","block.minecraft.fire", "block.minecraft.soul_fire", "block.minecraft.powder_snow", "block.minecraft.nether_portal");
3333+3434+ private final Map<UUID, PlayerData> playerData = new HashMap<>();
3535+3636+ private class PlayerData {
3737+ long lastTeleportTime = 0;
3838+ long lastHitTime = 0;
3939+ Vec3 lastPosition = Vec3.ZERO;
4040+ }
4141+4242+ public tools(TeleportCommands teleportCommands) {
4343+ this.teleportCommands = teleportCommands;
4444+ }
4545+4646+ /// Teleport the player :P
4747+ public void Teleporter(ServerPlayer player, ServerLevel world, Vec3 coords) {
4848+ // Check if user is allowed to teleport by config settings
4949+5050+ int delay = teleportCommands.config.CONFIG.teleporting.getDelay();
5151+5252+ // save when they last teleported and check delay
5353+5454+ // save pos and check if they have moved.
5555+5656+ // check if they got hit? whileFighting
5757+5858+ // save when they last got hit and if it exceeds fightCooldown
5959+30603131- public static void Teleporter(ServerPlayer player, ServerLevel world, Vec3 coords) {
3261 // teleportation effects & sounds before teleporting
3362 world.sendParticles(ParticleTypes.SNOWFLAKE, player.getX(), player.getY() + 1, player.getZ(), 20, 0.0D, 0.0D, 0.0D, 0.01);
3463 world.sendParticles(ParticleTypes.WHITE_SMOKE, player.getX(), player.getY(), player.getZ(), 15, 0.0D, 1.0D, 0.0D, 0.03);
···649365946695 // checks a 7x7x7 location around the player in order to find a safe place to teleport them to.
6767- public static Optional<BlockPos> getSafeBlockPos(BlockPos blockPos, ServerLevel world) {
9696+ public Optional<BlockPos> getSafeBlockPos(BlockPos blockPos, ServerLevel world) {
6897 int row = 1;
6998 int rows = 3;
7099···108137109138110139 // Gets the translated text for each player based on their language, this is fully server side and actually works (UNLIKE MOJANG'S TRANSLATED KEY'S WHICH ARE CLIENT SIDE) (I'm not mad, I swear!)
111111- public static MutableComponent getTranslatedText(String key, ServerPlayer player, MutableComponent... args) {
140140+ public MutableComponent getTranslatedText(String key, ServerPlayer player, MutableComponent... args) {
112141 //todo! maybe make this also loaded in memory?
113142 String language = player.clientInformation().language().toLowerCase();
114143 String regex = "%(\\d+)%";
···193222194223195224 // Gets the ids of all the worlds
196196- public static List<String> getWorldIds() {
197197- return StreamSupport.stream(TeleportCommands.SERVER.getAllLevels().spliterator(), false)
225225+ public List<String> getWorldIds() {
226226+ return StreamSupport.stream(teleportCommands.server.getAllLevels().spliterator(), false)
198227 .map(level -> level.dimension().location().toString())
199228 .toList();
200229 }
201230202231203232 // checks if a BlockPos is safe, used by the teleportSafetyChecker.
204204- private static boolean isBlockPosSafe(BlockPos bottomPlayer, ServerLevel world) {
233233+ private boolean isBlockPosSafe(BlockPos bottomPlayer, ServerLevel world) {
205234206235 // get the block below the player
207236 BlockPos belowPlayer = new BlockPos(bottomPlayer.getX(), bottomPlayer.getY() -1, bottomPlayer.getZ()); // below the player
···1010 // However, some things (like resources) may still be uninitialized.
1111 // Proceed with mild caution.
12121313- TeleportCommands.MOD_LOADER = "Fabric";
1313+ TeleportCommands.modLoader = "Fabric";
1414 }
1515}
···1111 // to load your mod. You can access NeoForge and Common code in this
1212 // project.
13131414- TeleportCommands.MOD_LOADER = "NeoForge";
1414+ TeleportCommands.modLoader = "NeoForge";
1515 }
1616}
1717