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.

Updated multi-modloader template. Worked through the todos. Moved some variables to a Constants.java file.

+405 -300
+13 -4
CHANGELOG.md
··· 6 6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 7 8 8 ### [W.I.P] 9 + #### Changed 9 10 - Storage is loaded in memory instead of reading it again and again, Improves speed and IO usage, however there might be slightly higher passive memory usage. 10 11 - Added a new merged jar file that combines the jars of the mod-loaders into one. (Thanks to [forgix](https://github.com/PacifistMC/Forgix)!) (This will also from now on be published on Modrinth) 11 12 - Made it so the DeathLocations (for `/back`) are only kept in memory. (before they would get saved and deleted on startup lol) 12 13 - Improved the Storage classes and it's functions (I'm doing proper java, yipie) 13 14 - Improved the error messages for command suggestions. 14 - - Improved the error handling for when a world isn't found (when going back, going home or warping). 15 + - Improved the messages styling for when no safe location is found while running `/back` or `/worldspawn` 16 + - Improved the sending of the homes/warps when doing `/homes` or `/warps` (They now get sent in one message instead of multiple) 17 + - Reduced the size of the mod icon by 60% (a 40kb reduction) using some `zopflipng` black magic. (sadly this only made the mod jar 5kb smaller :<) 18 + 19 + #### Fixed 20 + - Fixed the markdown for the translations from being bundled with the mod jar. 21 + - Fixed the usage of an invalid translation string when renaming a Home or Warp to a name that already exists. 22 + - Fixed the error handling for when a world isn't found (when going back, going home or warping). 15 23 - It now throws a warning and gives the player a new error message (before it would give an incorrect `notFound` error) 16 - - Improved the sending of the homes/warps when doing `/home` or `/warps` (They now get sent in one message instead of multiple) 17 - - Reduced the size of the mod icon by 60% (a 40kb reduction) using some `zopflipng` black magic. (sadly this only made the mod jar 5kb smaller :<) 18 - - Removed the markdown for the translations from being bundled with the mod jar. 24 + 25 + #### Added 26 + - added version 19 27 - Added hover effects for warp and homes text (W.I.P) 20 28 - Added comments to a lot of code (W.I.P) 21 29 - Added a new `home.defaultNone` translation key for when there is no default house set. (before this would give `home.homeless` for some reason) 22 30 - Added a new `common.worldNotFound` translation key for when a world cannot be found 23 31 - Added a new `common.defaultPrompt` translation key for a new "Set Default" button for `/homes` 32 + - Added a new `common.nameExists` translation key for when that name already exists 24 33 25 34 ### [v1.2.2] 26 35 - Handled a case where the client (geyser) will return the language as uppercase instead of lowercase.
+3 -2
build.gradle
··· 1 1 plugins { 2 - // Required for NeoGradle 3 - id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7" 2 + id 'fabric-loom' version "${fabric_loom}" apply false 3 + id 'net.neoforged.moddev' version "${neoforge_moddevgradle}" apply false 4 + 4 5 id "io.github.pacifistmc.forgix" version "1.2.9" 5 6 } 6 7
+35 -12
buildSrc/src/main/groovy/multiloader-common.gradle
··· 13 13 repositories { 14 14 mavenCentral() 15 15 // https://docs.gradle.org/current/userguide/declaring_repositories.html#declaring_content_exclusively_found_in_one_repository 16 - 16 + exclusiveContent { 17 + forRepository { 18 + maven { 19 + name = 'Sponge' 20 + url = 'https://repo.spongepowered.org/repository/maven-public' 21 + } 22 + } 23 + filter { includeGroupAndSubgroups('org.spongepowered') } 24 + } 25 + exclusiveContent { 26 + forRepositories( 27 + maven { 28 + name = 'ParchmentMC' 29 + url = 'https://maven.parchmentmc.org/' 30 + }, 31 + maven { 32 + name = "NeoForge" 33 + url = 'https://maven.neoforged.net/releases' 34 + } 35 + ) 36 + filter { includeGroup('org.parchmentmc.data') } 37 + } 17 38 maven { 18 - name = 'Sponge' 19 - url = 'https://repo.spongepowered.org/repository/maven-public' 39 + name = 'BlameJared' 40 + url = 'https://maven.blamejared.com' 20 41 } 21 - } 22 - 23 - dependencies { 24 - implementation 'org.jetbrains:annotations:24.1.0' 25 42 } 26 43 27 44 // Declare capabilities on the outgoing configurations. 28 45 // Read more about capabilities here: https://docs.gradle.org/current/userguide/component_capabilities.html#sec:declaring-additional-capabilities-for-a-local-component 29 46 ['apiElements', 'runtimeElements'].each { variant -> 30 47 configurations."$variant".outgoing { 48 + capability("$group:${project.name}:$version") 49 + capability("$group:${base.archivesName.get()}:$version") 31 50 capability("$group:$mod_id-${project.name}-${minecraft_version}:$version") 32 51 capability("$group:$mod_id:$version") 33 52 } ··· 86 105 "java_version": java_version 87 106 ] 88 107 89 - filesMatching(['pack.mcmeta', 'fabric.mod.json', 'quilt.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) { 90 - expand expandProps 108 + var jsonExpandProps = expandProps.collectEntries { 109 + key, value -> [(key): value instanceof String ? value.replace("\n", "\\\\n") : value] 91 110 } 92 - inputs.properties(expandProps) 93 111 112 + filesMatching(['META-INF/mods.toml', 'META-INF/neoforge.mods.toml']) { 113 + expand expandProps 114 + } 94 115 95 - filesMatching("version") { 96 - expand(version: project.version) 116 + filesMatching(['pack.mcmeta', 'fabric.mod.json', '*.mixins.json']) { 117 + expand jsonExpandProps 97 118 } 119 + 120 + inputs.properties(expandProps) 98 121 }
+16 -8
common/build.gradle
··· 1 1 plugins { 2 - id "multiloader-common" 3 - id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' 2 + id 'multiloader-common' 3 + id 'net.neoforged.moddev' 4 4 } 5 5 6 - minecraft { 7 - version(minecraft_version) 8 - def aw = file("src/main/resources/${mod_id}.accesswidener") 9 - if(aw.exists()){ 10 - accessWideners(aw) 6 + neoForge { 7 + neoFormVersion = neo_form_version 8 + // Automatically enable AccessTransformers if the file exists 9 + def at = file('src/main/resources/META-INF/accesstransformer.cfg') 10 + if (at.exists()) { 11 + accessTransformers.from(at.absolutePath) 12 + } 13 + parchment { 14 + minecraftVersion = parchment_minecraft 15 + mappingsVersion = parchment_version 11 16 } 12 17 } 13 18 14 19 dependencies { 15 - compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5' 20 + compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5' 21 + // fabric and neoforge both bundle mixinextras, so it is safe to use it in common 22 + compileOnly group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.3.5' 23 + annotationProcessor group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.3.5' 16 24 } 17 25 18 26 configurations {
+12
common/src/main/java/dev/mrsnowy/teleport_commands/Constants.java
··· 1 + package dev.mrsnowy.teleport_commands; 2 + 3 + import org.slf4j.Logger; 4 + import org.slf4j.LoggerFactory; 5 + 6 + public class Constants { 7 + public static final String MOD_ID = "teleport_commands"; 8 + public static final String MOD_NAME = "Teleport Commands"; 9 + public static final String VERSION = "1.3.0"; 10 + 11 + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME); 12 + }
+13 -21
common/src/main/java/dev/mrsnowy/teleport_commands/TeleportCommands.java
··· 8 8 import net.minecraft.server.MinecraftServer; 9 9 import net.minecraft.server.level.ServerPlayer; 10 10 import net.minecraft.world.level.storage.LevelResource; 11 - import org.slf4j.Logger; 12 - import org.slf4j.LoggerFactory; 13 11 14 12 import java.io.*; 15 - import java.nio.charset.StandardCharsets; 16 13 import java.nio.file.Files; 17 14 import java.nio.file.Path; 18 15 import java.nio.file.Paths; 19 16 import java.nio.file.StandardOpenOption; 20 - import java.util.Objects; 21 17 22 18 import net.minecraft.core.BlockPos; 23 19 24 20 import static dev.mrsnowy.teleport_commands.storage.StorageManager.*; 25 21 26 22 public class TeleportCommands { 27 - public static final String MOD_ID = "teleport_commands"; 28 - public static final String MOD_NAME = "Teleport Commands"; 29 - public static String VERSION = "unknown"; 30 - public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME); 31 23 public static String MOD_LOADER; 32 24 public static Path SAVE_DIR; 33 25 public static Path CONFIG_DIR; ··· 37 29 // Gets ran when the server starts 38 30 public static void initializeMod(MinecraftServer server) { 39 31 40 - InputStream stream = TeleportCommands.class.getResourceAsStream("/version"); 41 - try { 42 - BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(stream, "Couldn't find the version file!"), StandardCharsets.UTF_8)); 43 - VERSION = reader.readLine(); 44 - 45 - } catch (Exception e) { 46 - LOGGER.error("Couldn't find the version file!"); 47 - } 32 + // InputStream stream = TeleportCommands.class.getResourceAsStream("/version"); 33 + // try { 34 + // BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(stream, "Couldn't find the version file!"), StandardCharsets.UTF_8)); 35 + // Constants.VERSION = reader.readLine(); 36 + // 37 + // } catch (Exception e) { 38 + // Constants.LOGGER.error("Couldn't find the version file!"); 39 + // } 48 40 49 41 // initialize da variables 50 - LOGGER.info("Initializing Teleport Commands (V{})! Hello {}!", VERSION, MOD_LOADER); 42 + Constants.LOGGER.info("Initializing Teleport Commands (V{})! Hello {}!", Constants.VERSION, MOD_LOADER); 51 43 52 44 SAVE_DIR = Path.of(String.valueOf(server.getWorldPath(LevelResource.ROOT))); 53 45 ··· 79 71 80 72 // cleans and updates Storage to the newest "version". This is painful 81 73 private static StorageClass storageValidator() { 82 - LOGGER.info("Cleaning and updating Storage!"); 74 + Constants.LOGGER.info("Cleaning and updating Storage!"); 83 75 84 76 try { 85 77 StorageInit(); ··· 233 225 int diff = Math.round(( startFileSize - Files.size(StorageManager.STORAGE_FILE) )); 234 226 235 227 if (diff > 0) { 236 - LOGGER.info("Success! Cleaned: {}B", diff); 228 + Constants.LOGGER.info("Success! Cleaned: {}B", diff); 237 229 } else { 238 - LOGGER.info("Success!"); 230 + Constants.LOGGER.info("Success!"); 239 231 } 240 232 241 233 return gson.fromJson(mainJsonObject, StorageManager.StorageClass.class); 242 234 } 243 235 244 236 } catch (IOException e) { 245 - LOGGER.error("Error while cleaning the database!", e); 237 + Constants.LOGGER.error("Error while cleaning the database!", e); 246 238 } 247 239 248 240 return null;
+20 -8
common/src/main/java/dev/mrsnowy/teleport_commands/commands/back.java
··· 1 1 package dev.mrsnowy.teleport_commands.commands; 2 2 3 3 import com.mojang.brigadier.arguments.BoolArgumentType; 4 - import dev.mrsnowy.teleport_commands.TeleportCommands; 4 + import dev.mrsnowy.teleport_commands.Constants; 5 5 6 6 import java.util.*; 7 7 ··· 12 12 import net.minecraft.commands.Commands; 13 13 import net.minecraft.core.BlockPos; 14 14 import net.minecraft.network.chat.ClickEvent; 15 + import net.minecraft.network.chat.Component; 15 16 import net.minecraft.server.level.ServerLevel; 16 17 import net.minecraft.server.level.ServerPlayer; 17 18 import net.minecraft.world.phys.Vec3; ··· 32 33 ToDeathLocation(player, false); 33 34 34 35 } catch (Exception e) { 35 - TeleportCommands.LOGGER.error("Error while going back! => ", e); 36 + Constants.LOGGER.error("Error while going back! => ", e); 36 37 player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 37 38 return 1; 38 39 } ··· 48 49 ToDeathLocation(player, safety); 49 50 50 51 } catch (Exception e) { 51 - TeleportCommands.LOGGER.error("Error while going back! => ", e); 52 + Constants.LOGGER.error("Error while going back! => ", e); 52 53 player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 53 54 return 1; 54 55 } ··· 78 79 Optional<ServerLevel> optionalWorld = deathLocation.getWorld(); 79 80 80 81 if (optionalWorld.isEmpty()) { 81 - TeleportCommands.LOGGER.warn("({}) Error while going back! \nCouldn't find a world with the id: \"{}\" \nAvailable worlds: {}", 82 + Constants.LOGGER.warn("({}) Error while going back! \nCouldn't find a world with the id: \"{}\" \nAvailable worlds: {}", 82 83 player.getName().getString(), 83 84 deathLocation.getWorldString(), 84 85 tools.getWorldIds()); ··· 102 103 103 104 } else { 104 105 // asks the player if they want to teleport anyway 105 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.noSafeLocation", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), false); 106 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.safetyIsForLosers", player).withStyle(ChatFormatting.AQUA), false); 107 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.forceTeleport", player).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD) 108 - .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/back true"))),false); 106 + player.displayClientMessage( 107 + Component.empty() 108 + .append(getTranslatedText("commands.teleport_commands.common.noSafeLocation", player) 109 + .withStyle(ChatFormatting.RED, ChatFormatting.BOLD) 110 + ) 111 + .append("\n") 112 + .append(getTranslatedText("commands.teleport_commands.common.safetyIsForLosers", player) 113 + .withStyle(ChatFormatting.WHITE) 114 + ) 115 + .append("\n") 116 + .append(getTranslatedText("commands.teleport_commands.common.forceTeleport", player) 117 + .withStyle(ChatFormatting.DARK_AQUA, ChatFormatting.BOLD) 118 + .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/back true"))) 119 + ) 120 + .append("\n"), false); 109 121 return; 110 122 } 111 123
+28 -28
common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java
··· 1 1 package dev.mrsnowy.teleport_commands.commands; 2 2 3 3 import com.mojang.brigadier.arguments.StringArgumentType; 4 - import dev.mrsnowy.teleport_commands.TeleportCommands; 4 + import dev.mrsnowy.teleport_commands.Constants; 5 5 import dev.mrsnowy.teleport_commands.storage.StorageManager; 6 6 import dev.mrsnowy.teleport_commands.common.NamedLocation; 7 7 import dev.mrsnowy.teleport_commands.common.Player; 8 8 import dev.mrsnowy.teleport_commands.suggestions.HomeSuggestionProvider; 9 9 10 - import java.awt.*; 11 10 import java.util.List; 12 11 import java.util.Optional; 13 12 ··· 22 21 import net.minecraft.server.level.ServerLevel; 23 22 import net.minecraft.server.level.ServerPlayer; 24 23 import net.minecraft.world.phys.Vec3; 25 - import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder; 26 24 27 25 import static dev.mrsnowy.teleport_commands.storage.StorageManager.STORAGE; 28 26 import static dev.mrsnowy.teleport_commands.utils.tools.getTranslatedText; ··· 43 41 SetHome(player, name); 44 42 45 43 } catch (Exception e) { 46 - TeleportCommands.LOGGER.error("Error while setting a home! => ", e); 44 + Constants.LOGGER.error("Error while setting a home! => ", e); 47 45 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.setError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 48 46 return 1; 49 47 } ··· 60 58 GoHome(player, ""); 61 59 62 60 } catch (Exception e) { 63 - TeleportCommands.LOGGER.error("Error while going home! => ", e); 61 + Constants.LOGGER.error("Error while going home! => ", e); 64 62 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.goError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 65 63 return 1; 66 64 } ··· 76 74 GoHome(player, name); 77 75 78 76 } catch (Exception e) { 79 - TeleportCommands.LOGGER.error("Error while going to a specific home! => ", e); 77 + Constants.LOGGER.error("Error while going to a specific home! => ", e); 80 78 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.goError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 81 79 return 1; 82 80 } ··· 94 92 DeleteHome(player, name); 95 93 96 94 } catch (Exception e) { 97 - TeleportCommands.LOGGER.error("Error while deleting a home! => ", e); 95 + Constants.LOGGER.error("Error while deleting a home! => ", e); 98 96 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.deleteError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 99 97 return 1; 100 98 } ··· 114 112 RenameHome(player, name, newName); 115 113 116 114 } catch (Exception e) { 117 - TeleportCommands.LOGGER.error("Error while renaming a home! => ", e); 115 + Constants.LOGGER.error("Error while renaming a home! => ", e); 118 116 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.renameError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 119 117 return 1; 120 118 } ··· 133 131 SetDefaultHome(player, name); 134 132 135 133 } catch (Exception e) { 136 - TeleportCommands.LOGGER.error("Error while setting the default home! => ", e); 134 + Constants.LOGGER.error("Error while setting the default home! => ", e); 137 135 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.defaultError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 138 136 return 1; 139 137 } ··· 149 147 PrintHomes(player); 150 148 151 149 } catch (Exception e) { 152 - TeleportCommands.LOGGER.error("Error while printing the homes! => ", e); 150 + Constants.LOGGER.error("Error while printing the homes! => ", e); 153 151 player.displayClientMessage(getTranslatedText("commands.teleport_commands.homes.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 154 152 return 1; 155 153 } ··· 166 164 BlockPos blockPos = player.blockPosition(); 167 165 String worldString = player.serverLevel().dimension().location().toString(); 168 166 169 - // Gets player storage and makes it if it doesn't exist 167 + // Gets the player's storage and creates it if it doesn't exist 170 168 Player playerStorage = StorageManager.STORAGE.addPlayer(player.getStringUUID()); 171 169 172 - // check for duplicates 173 - if (playerStorage.getHome(homeName).isPresent()) { 170 + // Create the NamedLocation 171 + NamedLocation warp = new NamedLocation(homeName, blockPos, worldString); 172 + 173 + // Adds the home, returns true if the home already exists 174 + boolean homeExists = playerStorage.addHome(warp); 175 + 176 + if (homeExists) { 177 + // Display error message that the home already exists 174 178 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.exists", player).withStyle(ChatFormatting.RED), true); 175 - return; 176 - } 177 179 178 - // Create a new NamedLocation 179 - playerStorage.setHome(homeName, blockPos, worldString); 180 + } else { 181 + // Set it as the default if there are no other homes 182 + if (playerStorage.getHomes().size() == 1) { 183 + playerStorage.setDefaultHome(homeName); 184 + } 180 185 181 - // Set it as the default if there are no other homes 182 - if (playerStorage.getHomes().size() == 1) { 183 - playerStorage.setDefaultHome(homeName); 186 + // Display message that the home has been set 187 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.set", player), true); 184 188 } 185 - 186 - // Display message that the home as been set 187 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.set", player), true); 188 189 } 189 190 190 191 // Teleports the player to the home. It will go to the defaultHome if homeName is empty ··· 227 228 Optional<ServerLevel> optionalWorld = home.getWorld(); 228 229 229 230 if (optionalWorld.isEmpty()) { 230 - TeleportCommands.LOGGER.warn("({}) Error while going to the home \"{}\"! \nCouldn't find a world with the id: \"{}\" \nAvailable worlds: {}", 231 + Constants.LOGGER.warn("({}) Error while going to the home \"{}\"! \nCouldn't find a world with the id: \"{}\" \nAvailable worlds: {}", 231 232 player.getName().getString(), 232 233 home.getName(), 233 234 home.getWorldString(), ··· 302 303 Player playerStorage = optionalPlayerStorage.get(); 303 304 304 305 // Check if there already is a home with the new name 305 - playerStorage.getHome("newHomeName").ifPresent(name -> { 306 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.renameExists", player).withStyle(ChatFormatting.RED), true); 306 + if (playerStorage.getHome(newHomeName).isPresent()) { 307 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.nameExists", player).withStyle(ChatFormatting.RED), true); 307 308 return; 308 - // todo! does this exit correctly? 309 - }); 309 + } 310 310 311 311 // Get the home that needs to be renamed 312 312 Optional<NamedLocation> optionalHome = playerStorage.getHome(homeName);
+76 -76
common/src/main/java/dev/mrsnowy/teleport_commands/commands/main.java
··· 1 - package dev.mrsnowy.teleport_commands.commands; 2 - 3 - import com.mojang.brigadier.arguments.BoolArgumentType; 4 - import dev.mrsnowy.teleport_commands.TeleportCommands; 5 - import dev.mrsnowy.teleport_commands.common.DeathLocation; 6 - import dev.mrsnowy.teleport_commands.storage.DeathLocationStorage; 7 - import net.minecraft.ChatFormatting; 8 - import net.minecraft.commands.Commands; 9 - import net.minecraft.core.BlockPos; 10 - import net.minecraft.network.chat.ClickEvent; 11 - import net.minecraft.network.chat.Component; 12 - import net.minecraft.server.level.ServerLevel; 13 - import net.minecraft.server.level.ServerPlayer; 14 - import net.minecraft.world.phys.Vec3; 15 - 16 - import java.util.Optional; 17 - 18 - import static dev.mrsnowy.teleport_commands.utils.tools.*; 19 - import static net.minecraft.commands.Commands.argument; 20 - 21 - // TODO! add option to reload registered commands! 22 - 23 - public class main { 24 - 25 - public static void register(Commands commandManager) { 26 - 27 - commandManager.getDispatcher().register(Commands.literal("teleportcommands") 28 - .then(Commands.literal("help") 29 - .requires(source -> source.getPlayer() != null) 30 - .executes(context -> { 31 - final ServerPlayer player = context.getSource().getPlayerOrException(); 32 - 33 - try { 34 - printCommands(player); 35 - 36 - } catch (Exception e) { 37 - TeleportCommands.LOGGER.error("Error while going back! => ", e); 38 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 39 - return 1; 40 - } 41 - return 0; 42 - })) 43 - .then(argument("Disable Safety", BoolArgumentType.bool()) 44 - .requires(source -> source.getPlayer() != null) 45 - .executes(context -> { 46 - final boolean safety = BoolArgumentType.getBool(context, "Disable Safety"); 47 - final ServerPlayer player = context.getSource().getPlayerOrException(); 48 - 49 - try { 50 - // ToDeathLocation(player, safety); 51 - 52 - } catch (Exception e) { 53 - TeleportCommands.LOGGER.error("Error while going back! => ", e); 54 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 55 - return 1; 56 - } 57 - return 0; 58 - })) 59 - ); 60 - } 61 - 62 - 63 - // ----- 64 - 65 - 66 - // Gets the DeathLocation of the player and teleports the player to it 67 - private static void printCommands(ServerPlayer player) throws Exception { 68 - 69 - player.displayClientMessage(Component.literal("Thank you for using Teleport Commands (V)!").withStyle(ChatFormatting.AQUA), false); 70 - player.displayClientMessage(Component.literal("Teleport Commands is a server-side mod that adds various teleportation related commands").withStyle(ChatFormatting.AQUA), false); 71 - 72 - player.displayClientMessage(Component.literal("----").withStyle(ChatFormatting.AQUA), false); 73 - 74 - player.displayClientMessage(Component.literal("Usage:").withStyle(ChatFormatting.AQUA), false); 75 - } 76 - } 1 + //package dev.mrsnowy.teleport_commands.commands; 2 + // 3 + //import com.mojang.brigadier.arguments.BoolArgumentType; 4 + //import dev.mrsnowy.teleport_commands.TeleportCommands; 5 + //import dev.mrsnowy.teleport_commands.common.DeathLocation; 6 + //import dev.mrsnowy.teleport_commands.storage.DeathLocationStorage; 7 + //import net.minecraft.ChatFormatting; 8 + //import net.minecraft.commands.Commands; 9 + //import net.minecraft.core.BlockPos; 10 + //import net.minecraft.network.chat.ClickEvent; 11 + //import net.minecraft.network.chat.Component; 12 + //import net.minecraft.server.level.ServerLevel; 13 + //import net.minecraft.server.level.ServerPlayer; 14 + //import net.minecraft.world.phys.Vec3; 15 + // 16 + //import java.util.Optional; 17 + // 18 + //import static dev.mrsnowy.teleport_commands.utils.tools.*; 19 + //import static net.minecraft.commands.Commands.argument; 20 + // 21 + //// TODO! add option to reload registered commands! 22 + // 23 + //public class main { 24 + // 25 + // public static void register(Commands commandManager) { 26 + // 27 + // commandManager.getDispatcher().register(Commands.literal("teleportcommands") 28 + // .then(Commands.literal("help") 29 + // .requires(source -> source.getPlayer() != null) 30 + // .executes(context -> { 31 + // final ServerPlayer player = context.getSource().getPlayerOrException(); 32 + // 33 + // try { 34 + // printCommands(player); 35 + // 36 + // } catch (Exception e) { 37 + // TeleportCommands.LOGGER.error("Error while going back! => ", e); 38 + // player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 39 + // return 1; 40 + // } 41 + // return 0; 42 + // })) 43 + // .then(argument("Disable Safety", BoolArgumentType.bool()) 44 + // .requires(source -> source.getPlayer() != null) 45 + // .executes(context -> { 46 + // final boolean safety = BoolArgumentType.getBool(context, "Disable Safety"); 47 + // final ServerPlayer player = context.getSource().getPlayerOrException(); 48 + // 49 + // try { 50 + //// ToDeathLocation(player, safety); 51 + // 52 + // } catch (Exception e) { 53 + // TeleportCommands.LOGGER.error("Error while going back! => ", e); 54 + // player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 55 + // return 1; 56 + // } 57 + // return 0; 58 + // })) 59 + // ); 60 + // } 61 + // 62 + // 63 + // // ----- 64 + // 65 + // 66 + // // Gets the DeathLocation of the player and teleports the player to it 67 + // private static void printCommands(ServerPlayer player) throws Exception { 68 + // 69 + // player.displayClientMessage(Component.literal("Thank you for using Teleport Commands (V)!").withStyle(ChatFormatting.AQUA), false); 70 + // player.displayClientMessage(Component.literal("Teleport Commands is a server-side mod that adds various teleportation related commands").withStyle(ChatFormatting.AQUA), false); 71 + // 72 + // player.displayClientMessage(Component.literal("----").withStyle(ChatFormatting.AQUA), false); 73 + // 74 + // player.displayClientMessage(Component.literal("Usage:").withStyle(ChatFormatting.AQUA), false); 75 + // } 76 + //}
+5 -5
common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java
··· 2 2 3 3 import java.util.*; 4 4 5 - import dev.mrsnowy.teleport_commands.TeleportCommands; 5 + import dev.mrsnowy.teleport_commands.Constants; 6 6 import dev.mrsnowy.teleport_commands.suggestions.tpaSuggestionProvider; 7 7 8 8 import net.minecraft.ChatFormatting; ··· 48 48 } catch (Exception e) { 49 49 // this shouldn't happen with any of these commands, but if it does happen I am at least printing it to the logs and catching it. 50 50 // if it appears that this can happen then I'll add error messages for the client, for now the default minecraft ones will do 51 - TeleportCommands.LOGGER.error("Error while sending a tpa request! => ", e); 51 + Constants.LOGGER.error("Error while sending a tpa request! => ", e); 52 52 return 1; 53 53 } 54 54 return 0; ··· 65 65 tpaCommandHandler(player, TargetPlayer, true); 66 66 67 67 } catch (Exception e) { 68 - TeleportCommands.LOGGER.error("Error while sending a tpahere request! => ", e); 68 + Constants.LOGGER.error("Error while sending a tpahere request! => ", e); 69 69 return 1; 70 70 } 71 71 return 0; ··· 82 82 tpaAccept(player, TargetPlayer); 83 83 84 84 } catch (Exception e) { 85 - TeleportCommands.LOGGER.error("Error while accepting a tpa(here) request! => ", e); 85 + Constants.LOGGER.error("Error while accepting a tpa(here) request! => ", e); 86 86 return 1; 87 87 } 88 88 ··· 100 100 tpaDeny(player, TargetPlayer); 101 101 102 102 } catch (Exception e) { 103 - TeleportCommands.LOGGER.error("Error while denying a tpa(here) request! => ", e); 103 + Constants.LOGGER.error("Error while denying a tpa(here) request! => ", e); 104 104 player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.setError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 105 105 return 1; 106 106 }
+21 -18
common/src/main/java/dev/mrsnowy/teleport_commands/commands/warp.java
··· 1 1 package dev.mrsnowy.teleport_commands.commands; 2 2 3 3 import com.mojang.brigadier.arguments.StringArgumentType; 4 - import dev.mrsnowy.teleport_commands.TeleportCommands; 4 + import dev.mrsnowy.teleport_commands.Constants; 5 5 import dev.mrsnowy.teleport_commands.common.NamedLocation; 6 6 import dev.mrsnowy.teleport_commands.suggestions.WarpSuggestionProvider; 7 7 import dev.mrsnowy.teleport_commands.utils.tools; ··· 41 41 SetWarp(player, name); 42 42 43 43 } catch (Exception e) { 44 - TeleportCommands.LOGGER.error("Error while setting the warp!", e); 44 + Constants.LOGGER.error("Error while setting the warp!", e); 45 45 player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.setError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 46 46 return 1; 47 47 } ··· 59 59 GoToWarp(player, name); 60 60 61 61 } catch (Exception e) { 62 - TeleportCommands.LOGGER.error("Error while going to the warp!",e); 62 + Constants.LOGGER.error("Error while going to the warp!",e); 63 63 player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.goError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 64 64 return 1; 65 65 } ··· 80 80 DeleteWarp(player, name); 81 81 82 82 } catch (Exception e) { 83 - TeleportCommands.LOGGER.error("Error while deleting to the warp!", e); 83 + Constants.LOGGER.error("Error while deleting to the warp!", e); 84 84 player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.deleteError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 85 85 return 1; 86 86 } ··· 103 103 RenameWarp(player, name, newName); 104 104 105 105 } catch (Exception e) { 106 - TeleportCommands.LOGGER.error("Error while renaming the warp!", e); 106 + Constants.LOGGER.error("Error while renaming the warp!", e); 107 107 player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.renameError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 108 108 return 1; 109 109 } ··· 119 119 PrintWarps(player); 120 120 121 121 } catch (Exception e) { 122 - TeleportCommands.LOGGER.error("Error while printing warps!", e); 122 + Constants.LOGGER.error("Error while printing warps!", e); 123 123 player.displayClientMessage(getTranslatedText("commands.teleport_commands.warps.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 124 124 return 1; 125 125 } ··· 134 134 BlockPos blockPos = new BlockPos(player.getBlockX(), player.getBlockY(), player.getBlockZ()); 135 135 String worldString = player.serverLevel().dimension().location().toString(); 136 136 137 - // Check if warp already exists 138 - if ( STORAGE.getWarp(warpName).isPresent() ) { 137 + // Create the NamedLocation 138 + NamedLocation warp = new NamedLocation(warpName, blockPos, worldString); 139 + 140 + // Adds the warp, returns true if the warp already exists 141 + boolean warpExists = STORAGE.addWarp(warp); 142 + 143 + if (warpExists) { 144 + // Display error message that the warp already exists 139 145 player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.exists", player).withStyle(ChatFormatting.RED), true); 140 - return; 141 - } 142 146 143 - // Create the warp 144 - STORAGE.setWarp(warpName, blockPos, worldString); 145 - 146 - // Display message that the home as been set 147 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.set", player), true); 147 + } else { 148 + // Display message that the home as been set 149 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.set", player), true); 150 + } 148 151 } 149 152 150 153 private static void GoToWarp(ServerPlayer player, String warpName) throws Exception { ··· 163 166 Optional<ServerLevel> optionalWorld = warp.getWorld(); 164 167 165 168 if (optionalWorld.isEmpty()) { 166 - TeleportCommands.LOGGER.warn("({}) Error while going to the warp \"{}\"! \nCouldn't find a world with the id: \"{}\" \nAvailable worlds: {}", 169 + Constants.LOGGER.warn("({}) Error while going to the warp \"{}\"! \nCouldn't find a world with the id: \"{}\" \nAvailable worlds: {}", 167 170 player.getName().getString(), 168 171 warp.getName(), 169 172 warp.getWorldString(), ··· 200 203 201 204 if (optionalWarp.isPresent()) { 202 205 // Delete the warp 203 - STORAGE.rmWarp(optionalWarp.get()); 206 + STORAGE.removeWarp(optionalWarp.get()); 204 207 205 208 player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.delete", player), true); 206 209 ··· 216 219 217 220 // check if there is no existing warp with the new name 218 221 if (STORAGE.getWarp(newWarpName).isPresent()) { 219 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.warp.renameExists", player).withStyle(ChatFormatting.RED), true); 222 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.nameExists", player).withStyle(ChatFormatting.RED), true); 220 223 return; 221 224 } 222 225
+21 -7
common/src/main/java/dev/mrsnowy/teleport_commands/commands/worldspawn.java
··· 1 1 package dev.mrsnowy.teleport_commands.commands; 2 2 3 3 import com.mojang.brigadier.arguments.BoolArgumentType; 4 + import dev.mrsnowy.teleport_commands.Constants; 4 5 import dev.mrsnowy.teleport_commands.TeleportCommands; 5 6 import net.minecraft.ChatFormatting; 6 7 import net.minecraft.commands.Commands; 7 8 import net.minecraft.core.BlockPos; 8 9 import net.minecraft.network.chat.ClickEvent; 10 + import net.minecraft.network.chat.Component; 9 11 import net.minecraft.server.level.ServerLevel; 10 12 import net.minecraft.server.level.ServerPlayer; 11 13 import net.minecraft.world.phys.Vec3; ··· 30 32 toWorldSpawn(player, false); 31 33 32 34 } catch (Exception error) { 33 - TeleportCommands.LOGGER.error("Error while going to the worldspawn! => ", error); 35 + Constants.LOGGER.error("Error while going to the worldspawn! => ", error); 34 36 player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 35 37 return 1; 36 38 } ··· 46 48 toWorldSpawn(player, safety); 47 49 48 50 } catch (Exception error) { 49 - TeleportCommands.LOGGER.error("Error while going to the worldspawn! => ", error); 51 + Constants.LOGGER.error("Error while going to the worldspawn! => ", error); 50 52 player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 51 53 return 1; 52 54 } ··· 57 59 } 58 60 59 61 private static void toWorldSpawn(ServerPlayer player, boolean safetyDisabled) throws NullPointerException { 60 - // todo! maybe make this more fool proof? 62 + // todo! make the dimension customizable 61 63 ServerLevel world = TeleportCommands.SERVER.getLevel(OVERWORLD); 62 64 BlockPos worldSpawn = Objects.requireNonNull(world,"Overworld cannot be null!").getSharedSpawnPos(); 63 65 ··· 79 81 } 80 82 81 83 } else { 82 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.noSafeLocation", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), false); 83 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.safetyIsForLosers", player).withStyle(ChatFormatting.AQUA), false); 84 - player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.forceTeleport", player).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD) 85 - .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/worldspawn true"))),false); 84 + 85 + player.displayClientMessage( 86 + Component.empty() 87 + .append(getTranslatedText("commands.teleport_commands.common.noSafeLocation", player) 88 + .withStyle(ChatFormatting.RED, ChatFormatting.BOLD) 89 + ) 90 + .append("\n") 91 + .append(getTranslatedText("commands.teleport_commands.common.safetyIsForLosers", player) 92 + .withStyle(ChatFormatting.WHITE) 93 + ) 94 + .append("\n") 95 + .append(getTranslatedText("commands.teleport_commands.common.forceTeleport", player) 96 + .withStyle(ChatFormatting.DARK_AQUA, ChatFormatting.BOLD) 97 + .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/worldspawn true"))) 98 + ) 99 + .append("\n"), false); 86 100 } 87 101 88 102 } else {
+1
common/src/main/java/dev/mrsnowy/teleport_commands/common/NamedLocation.java
··· 46 46 return this.z; 47 47 } 48 48 49 + // Return the world id as a string 49 50 public String getWorldString() { 50 51 return this.world; 51 52 }
+8 -14
common/src/main/java/dev/mrsnowy/teleport_commands/common/Player.java
··· 48 48 StorageManager.StorageSaver(); 49 49 } 50 50 51 - // todo! modify this so it uses a NamedLocation 52 - // creates a new home, if there already is a home it will update the existing one 53 - public void setHome(String name, BlockPos pos, String world) throws Exception { 54 - Optional<NamedLocation> optionalHome = getHome(name); 55 - NamedLocation home; 56 - 57 - if (optionalHome.isEmpty()) { 58 - home = new NamedLocation(name, pos, world); 51 + // Adds a NamedLocation to the home list, returns true if it already exists 52 + public boolean addHome(NamedLocation home) throws Exception { 53 + if (getHome(home.getName()).isPresent()) { 54 + // Home with same name found! 55 + return true; 59 56 60 - Homes.add(home); 61 57 } else { 62 - home = optionalHome.get(); 63 - 64 - home.setName(name); 58 + Homes.add(home); 59 + StorageManager.StorageSaver(); 60 + return false; 65 61 } 66 - 67 - StorageManager.StorageSaver(); 68 62 } 69 63 70 64 // -----
+15 -21
common/src/main/java/dev/mrsnowy/teleport_commands/storage/StorageManager.java
··· 2 2 3 3 import com.google.gson.Gson; 4 4 import com.google.gson.GsonBuilder; 5 + import dev.mrsnowy.teleport_commands.Constants; 5 6 import dev.mrsnowy.teleport_commands.TeleportCommands; 6 7 import dev.mrsnowy.teleport_commands.common.NamedLocation; 7 8 import dev.mrsnowy.teleport_commands.common.Player; 8 - import net.minecraft.core.BlockPos; 9 9 10 10 import java.io.File; 11 11 import java.nio.file.Files; ··· 45 45 } 46 46 47 47 } catch (Exception e) { 48 - TeleportCommands.LOGGER.error("Error while creating the storage file! Exiting! => ", e); 48 + Constants.LOGGER.error("Error while creating the storage file! Exiting! => ", e); 49 49 // crashing is probably better here, otherwise the whole mod will be broken 50 50 System.exit(1); 51 51 } ··· 87 87 88 88 // ----- 89 89 90 - // todo! modify this so it uses a NamedLocation as an input 91 - // creates a new warp, if there already is a warp it will update the existing one 92 - public void setWarp(String name, BlockPos pos, String world) throws Exception { 93 - Optional<NamedLocation> OptionalWarp = getWarp(name); 90 + // Adds a NamedLocation to the warp list, returns true if a warp with the same name already exists 91 + public boolean addWarp(NamedLocation warp) throws Exception { 92 + if (getWarp(warp.getName()).isPresent()) { 93 + // Warp with same name found! 94 + return true; 94 95 95 - if (OptionalWarp.isEmpty()) { 96 - // create a new warp 97 - NamedLocation warp = new NamedLocation(name, pos, world); 98 - Warps.add(warp); 99 96 } else { 100 - // modify existing warp 101 - NamedLocation warp = OptionalWarp.get(); 102 - warp.setName(name); 97 + Warps.add(warp); 98 + StorageSaver(); 99 + return false; 103 100 } 104 - 105 - StorageSaver(); 106 101 } 107 102 108 - // 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 109 - // todo! check if this works fully 103 + // 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 104 + // The name of this function is wack but whatever kewk 110 105 public Player addPlayer(String uuid) { 111 106 final Optional<Player> OptionalPlayer = getPlayer(uuid); 112 107 113 108 if (OptionalPlayer.isEmpty()) { 114 - // create new player 109 + // create and return new player 115 110 Player player = new Player(uuid); 116 111 Players.add(player); 117 - // TeleportCommands.LOGGER.info("Player '{}' added successfully in storage!", uuid); // todo! prob remove these loggers 118 112 119 113 return player; 120 114 } else { 121 115 // return existing player 122 - // TeleportCommands.LOGGER.info("Player '{}' already exists!", uuid); 123 116 return OptionalPlayer.get(); 124 117 } 125 118 } 126 119 127 120 // ----- 128 121 129 - public void rmWarp(NamedLocation warp) throws Exception { 122 + // Remove a warp, if the warp isn't found then nothing will happen 123 + public void removeWarp(NamedLocation warp) throws Exception { 130 124 Warps.remove(warp); 131 125 StorageSaver(); 132 126 }
+2 -2
common/src/main/java/dev/mrsnowy/teleport_commands/suggestions/HomeSuggestionProvider.java
··· 4 4 import com.mojang.brigadier.suggestion.SuggestionProvider; 5 5 import com.mojang.brigadier.suggestion.Suggestions; 6 6 import com.mojang.brigadier.suggestion.SuggestionsBuilder; 7 - import dev.mrsnowy.teleport_commands.TeleportCommands; 7 + import dev.mrsnowy.teleport_commands.Constants; 8 8 9 9 import java.util.Optional; 10 10 import java.util.concurrent.CompletableFuture; ··· 34 34 // Build and return the suggestions 35 35 return builder.buildFuture(); 36 36 } catch (Exception e) { 37 - TeleportCommands.LOGGER.error("Error getting home suggestions! ", e); 37 + Constants.LOGGER.error("Error getting home suggestions! ", e); 38 38 return null; 39 39 } 40 40 }
+2 -2
common/src/main/java/dev/mrsnowy/teleport_commands/suggestions/WarpSuggestionProvider.java
··· 5 5 import com.mojang.brigadier.suggestion.Suggestions; 6 6 import com.mojang.brigadier.suggestion.SuggestionsBuilder; 7 7 8 - import dev.mrsnowy.teleport_commands.TeleportCommands; 8 + import dev.mrsnowy.teleport_commands.Constants; 9 9 import dev.mrsnowy.teleport_commands.storage.StorageManager; 10 10 import dev.mrsnowy.teleport_commands.common.NamedLocation; 11 11 ··· 28 28 // Build and return the suggestions 29 29 return builder.buildFuture(); 30 30 } catch (Exception e) { 31 - TeleportCommands.LOGGER.error("Error getting warp suggestions! ", e); 31 + Constants.LOGGER.error("Error getting warp suggestions! ", e); 32 32 return null; 33 33 } 34 34 }
+2 -2
common/src/main/java/dev/mrsnowy/teleport_commands/suggestions/tpaSuggestionProvider.java
··· 4 4 import com.mojang.brigadier.suggestion.SuggestionProvider; 5 5 import com.mojang.brigadier.suggestion.Suggestions; 6 6 import com.mojang.brigadier.suggestion.SuggestionsBuilder; 7 - import dev.mrsnowy.teleport_commands.TeleportCommands; 7 + import dev.mrsnowy.teleport_commands.Constants; 8 8 import dev.mrsnowy.teleport_commands.commands.tpa; 9 9 10 10 import net.minecraft.commands.CommandSourceStack; ··· 36 36 // Build and return the suggestions 37 37 return builder.buildFuture(); 38 38 } catch (Exception e) { 39 - TeleportCommands.LOGGER.error("Error getting tpa suggestions! ", e); 39 + Constants.LOGGER.error("Error getting tpa suggestions! ", e); 40 40 return null; 41 41 } 42 42 }
+15 -3
common/src/main/java/dev/mrsnowy/teleport_commands/utils/tools.java
··· 1 1 package dev.mrsnowy.teleport_commands.utils; 2 2 3 3 import com.google.gson.*; 4 + import dev.mrsnowy.teleport_commands.Constants; 4 5 import dev.mrsnowy.teleport_commands.TeleportCommands; 5 6 6 7 import java.io.*; ··· 20 21 import net.minecraft.sounds.SoundSource; 21 22 import net.minecraft.world.phys.Vec3; 22 23 23 - import static dev.mrsnowy.teleport_commands.TeleportCommands.MOD_ID; 24 + import static dev.mrsnowy.teleport_commands.Constants.MOD_ID; 24 25 import static net.minecraft.sounds.SoundEvents.ENDERMAN_TELEPORT; 25 26 26 27 public class tools { ··· 113 114 String regex = "%(\\d+)%"; 114 115 Pattern pattern = Pattern.compile(regex); 115 116 117 + // MinecraftServer server = player.getServer(); 118 + 119 + // MinecraftServer.ServerResourcePackInfo silly2 = server.getResourceManager().listResources() 120 + 121 + // java.util.stream.Stream<net.minecraft.server.packs.PackResources> SILLY = server.getResourceManager().listPacks(); 122 + // 123 + // SILLY.forEach(pack -> { 124 + // Constants.LOGGER.info("{} : {} : {}", pack.packId(), pack.location(), pack.getClass()); 125 + // }); 126 + 127 + // player.displayClientMessage(Component.literal(.toString()), false); 128 + 116 129 // the try catch stuff is so wacky, but it works fine and I don't need to check everything 117 130 try { 118 131 String filePath = String.format("/assets/%s/lang/%s.json", MOD_ID, language); ··· 173 186 return component; 174 187 } 175 188 } catch (Exception ignored1) {} 176 - TeleportCommands.LOGGER.error("Key \"{}\" not found in the default language (en_us), sending raw key as fallback.", key); 189 + Constants.LOGGER.error("Key \"{}\" not found in the default language (en_us), sending raw key as fallback.", key); 177 190 return Component.literal(key); 178 191 } 179 192 } ··· 187 200 } 188 201 189 202 190 - // todo! test 191 203 // checks if a BlockPos is safe, used by the teleportSafetyChecker. 192 204 private static boolean isBlockPosSafe(BlockPos bottomPlayer, ServerLevel world) { 193 205
+2 -1
common/src/main/resources/assets/teleport_commands/lang/en_us.json
··· 64 64 "commands.teleport_commands.common.defaultPrompt": "[Set Default]", 65 65 "commands.teleport_commands.common.noLocation": "No location found!", 66 66 "commands.teleport_commands.common.hoverCopy": "Click to copy!", 67 - "commands.teleport_commands.common.worldNotFound": "World not found!" 67 + "commands.teleport_commands.common.worldNotFound": "World not found!", 68 + "commands.teleport_commands.common.nameExists": "That name already exists!" 68 69 }
+2 -1
common/src/main/resources/assets/teleport_commands/lang/hu_hu.json
··· 64 64 "commands.teleport_commands.common.defaultPrompt": "[Set Default]", 65 65 "commands.teleport_commands.common.noLocation": "Nem található a koordináta", 66 66 "commands.teleport_commands.common.hoverCopy": "Click to copy!", 67 - "commands.teleport_commands.common.worldNotFound": "World not found!" 67 + "commands.teleport_commands.common.worldNotFound": "World not found!", 68 + "commands.teleport_commands.common.nameExists": "That name already exists!" 68 69 }
+2 -1
common/src/main/resources/assets/teleport_commands/lang/it_it.json
··· 64 64 "commands.teleport_commands.common.defaultPrompt": "[Set Default]", 65 65 "commands.teleport_commands.common.noLocation": "Nessuna Posizione Trovata!", 66 66 "commands.teleport_commands.common.hoverCopy": "Click to copy!", 67 - "commands.teleport_commands.common.worldNotFound": "World not found!" 67 + "commands.teleport_commands.common.worldNotFound": "World not found!", 68 + "commands.teleport_commands.common.nameExists": "That name already exists!" 68 69 }
+2 -1
common/src/main/resources/assets/teleport_commands/lang/nl_nl.json
··· 64 64 "commands.teleport_commands.common.defaultPrompt": "[Standaard instellen]", 65 65 "commands.teleport_commands.common.noLocation": "Geen Locatie Gevonden!", 66 66 "commands.teleport_commands.common.hoverCopy": "Klik om te kopiëren!", 67 - "commands.teleport_commands.common.worldNotFound": "Wereld niet gevonden!" 67 + "commands.teleport_commands.common.worldNotFound": "Wereld niet gevonden!", 68 + "commands.teleport_commands.common.nameExists": "Die naam bestaad al!" 68 69 }
+2 -1
common/src/main/resources/assets/teleport_commands/lang/ru_ru.json
··· 64 64 "commands.teleport_commands.common.defaultPrompt": "[Set Default]", 65 65 "commands.teleport_commands.common.noLocation": "Местоположение не найдено!", 66 66 "commands.teleport_commands.common.hoverCopy": "Нажмите, чтобы скопировать!", 67 - "commands.teleport_commands.common.worldNotFound": "World not found!" 67 + "commands.teleport_commands.common.worldNotFound": "World not found!", 68 + "commands.teleport_commands.common.nameExists": "That name already exists!" 68 69 }
+2 -1
common/src/main/resources/assets/teleport_commands/lang/zh_cn.json
··· 64 64 "commands.teleport_commands.common.defaultPrompt": "[Set Default]", 65 65 "commands.teleport_commands.common.noLocation": "找不到位置!", 66 66 "commands.teleport_commands.common.hoverCopy": "点击以复制!", 67 - "commands.teleport_commands.common.worldNotFound": "World not found!" 67 + "commands.teleport_commands.common.worldNotFound": "World not found!", 68 + "commands.teleport_commands.common.nameExists": "That name already exists!" 68 69 }
+2 -1
common/src/main/resources/assets/teleport_commands/lang/zh_tw.json
··· 64 64 "commands.teleport_commands.common.defaultPrompt": "[Set Default]", 65 65 "commands.teleport_commands.common.noLocation": "找不到位置!", 66 66 "commands.teleport_commands.common.hoverCopy": "點擊以複製!", 67 - "commands.teleport_commands.common.worldNotFound": "World not found!" 67 + "commands.teleport_commands.common.worldNotFound": "World not found!", 68 + "commands.teleport_commands.common.nameExists": "That name already exists!" 68 69 }
-1
common/src/main/resources/version
··· 1 - ${version}
+2 -1
fabric/build.gradle
··· 1 1 plugins { 2 2 id 'multiloader-loader' 3 - id 'fabric-loom' version "${fabric_loom}" 3 + id 'fabric-loom' 4 4 } 5 5 6 6 dependencies { 7 7 minecraft "com.mojang:minecraft:${minecraft_version}" 8 8 mappings loom.layered() { 9 9 officialMojangMappings() 10 + parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip") 10 11 } 11 12 modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" 12 13 // modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_api}"
+14 -2
gradle.properties
··· 14 14 license=MIT 15 15 credits=Mr. Snowy 16 16 description=A server-side mod that adds various teleportation related commands. 17 - minecraft_version_range=[1.21.4,1.22] 17 + minecraft_version_range=[1.21.4, 1.22] 18 + 19 + # see https://projects.neoforged.net/neoforged/neoform for new versions 20 + neo_form_version=1.21.4-20241203.161809 21 + 22 + # see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions 23 + parchment_minecraft=1.21.4 24 + parchment_version=2025.03.23 18 25 19 26 # Fabric 20 27 fabric_loader_version=0.16.9 21 28 #fabric_api=0.97.0+1.20.4 22 - fabric_loom=1.9-SNAPSHOT 29 + 30 + # see https://fabricmc.net/develop/ for new versions 31 + fabric_loom=1.10-SNAPSHOT 23 32 24 33 # Quilt (Currently disabled since fabric port works better) 25 34 #quilt_loader_version=0.25.0 ··· 31 40 neoforge_version=21.4.0-beta 32 41 neoforge_loader_version_range=[2,) 33 42 NeoGradle=7.0.171 43 + 44 + # see https://projects.neoforged.net/neoforged/moddevgradle for new versions 45 + neoforge_moddevgradle=2.0.80 34 46 35 47 # Gradle 36 48 org.gradle.jvmargs=-Xmx6G
+1 -1
gradle/wrapper/gradle-wrapper.properties
··· 1 1 distributionBase=GRADLE_USER_HOME 2 2 distributionPath=wrapper/dists 3 - distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip 3 + distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip 4 4 networkTimeout=10000 5 5 validateDistributionUrl=true 6 6 zipStoreBase=GRADLE_USER_HOME
+32 -39
neoforge/build.gradle
··· 1 1 plugins { 2 2 id 'multiloader-loader' 3 - id 'net.neoforged.gradle.userdev' version "${NeoGradle}" 3 + id 'net.neoforged.moddev' 4 4 } 5 5 6 - // Automatically enable neoforge AccessTransformers if the file exists 7 - // This location is hardcoded in FML and can not be changed. 8 - // https://github.com/neoforged/FancyModLoader/blob/a952595eaaddd571fbc53f43847680b00894e0c1/loader/src/main/java/net/neoforged/fml/loading/moddiscovery/ModFile.java#L118 9 - def at = file('src/main/resources/META-INF/accesstransformer.cfg') 10 - if (at.exists()) { 11 - minecraft.accessTransformers.file at 12 - } 6 + neoForge { 7 + version = neoforge_version 8 + // Automatically enable neoforge AccessTransformers if the file exists 9 + def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg') 10 + if (at.exists()) { 11 + accessTransformers.from(at.absolutePath) 12 + } 13 13 14 - runs { 15 - configureEach { 16 - modSource project.sourceSets.main 14 + parchment { 15 + minecraftVersion = parchment_minecraft 16 + mappingsVersion = parchment_version 17 17 } 18 - client { 19 - systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id 20 - } 21 - server { 22 - systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id 23 - programArgument '--nogui' 18 + 19 + runs { 20 + configureEach { 21 + systemProperty('neoforge.enabledGameTestNamespaces', mod_id) 22 + ideName = "NeoForge ${it.name.capitalize()} (${project.path})" // Unify the run config names with fabric 23 + } 24 + client { 25 + client() 26 + } 27 + data { 28 + clientData() 29 + } 30 + server { 31 + server() 32 + } 24 33 } 25 34 26 - // gameTestServer { 27 - // systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id 28 - // } 29 - 30 - // data { 31 - // programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() 32 - // } 35 + mods { 36 + "${mod_id}" { 37 + sourceSet sourceSets.main 38 + } 39 + } 33 40 } 34 41 35 - sourceSets.main.resources { srcDir 'src/generated/resources' } 36 - configurations { 37 - runtimeClasspath.extendsFrom localRuntime 38 - } 39 - 40 - dependencies { 41 - implementation "net.neoforged:neoforge:${neoforge_version}" 42 - } 43 - 44 - idea { 45 - module { 46 - downloadSources = true 47 - downloadJavadoc = true 48 - } 49 - } 42 + sourceSets.main.resources { srcDir 'src/generated/resources' }
+3 -2
neoforge/src/main/java/dev/mrsnowy/teleport_commands/neoforgeInit.java
··· 1 1 package dev.mrsnowy.teleport_commands; 2 2 3 + import net.neoforged.bus.api.IEventBus; 3 4 import net.neoforged.fml.common.Mod; 4 5 5 - @Mod(TeleportCommands.MOD_ID) 6 + @Mod(Constants.MOD_ID) 6 7 public class neoforgeInit { 7 8 8 - public neoforgeInit() { 9 + public neoforgeInit(IEventBus eventBus) { 9 10 // This method is invoked by the NeoForge mod loader when it is ready 10 11 // to load your mod. You can access NeoForge and Common code in this 11 12 // project.
+31 -14
settings.gradle
··· 2 2 repositories { 3 3 gradlePluginPortal() 4 4 mavenCentral() 5 - 6 - maven { 7 - name = 'Fabric' 8 - url = uri("https://maven.fabricmc.net") 5 + exclusiveContent { 6 + forRepository { 7 + maven { 8 + name = 'Fabric' 9 + url = uri('https://maven.fabricmc.net') 10 + } 11 + } 12 + filter { 13 + includeGroup('net.fabricmc') 14 + includeGroup('fabric-loom') 15 + } 9 16 } 10 - maven { 11 - name = 'Quilt' 12 - url = uri("https://maven.quiltmc.org/repository/release") 17 + exclusiveContent { 18 + forRepository { 19 + maven { 20 + name = 'Sponge' 21 + url = uri('https://repo.spongepowered.org/repository/maven-public') 22 + } 23 + } 24 + filter { 25 + includeGroupAndSubgroups("org.spongepowered") 26 + } 13 27 } 14 - maven { 15 - name = 'NeoForge' 16 - url = uri("https://maven.neoforged.net/releases") 17 - } 18 - maven { 19 - name = 'Sponge Snapshots' 20 - url = uri("https://repo.spongepowered.org/repository/maven-public") 28 + exclusiveContent { 29 + forRepository { 30 + maven { 31 + name = 'Forge' 32 + url = uri('https://maven.minecraftforge.net') 33 + } 34 + } 35 + filter { 36 + includeGroupAndSubgroups('net.minecraftforge') 37 + } 21 38 } 22 39 } 23 40 }