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.

a lot of stuff

Added translation system, added quilt support, improved messages, improved performance by changing the death event to be player specific (not on all entities), replaced all events with mixins...

i need to make a changelog

+464 -351
+21 -10
README.md
··· 28 28 ### TODO: 29 29 30 30 #### Planned commands: 31 - - `/wild` - Teleports you to a random location in the Overworld 32 - - `/worldspawn` - Teleports you to the worldspawn 33 - - `/spawn <dimension>` - Teleports you to your spawnpoint in a dimension, defaults to your current dimension 31 + -[ ] `/wild` - Teleports you to a random location in the Overworld 32 + -[ ] `/worldspawn` - Teleports you to the worldspawn 33 + -[ ] `/spawn <dimension>` - Teleports you to your spawnpoint in a dimension, defaults to your current dimension 34 34 35 35 #### Improvements: 36 - - Modify /back to check if the location is safe and automatically choose a nearby location that is safe 37 - - Create a config to add any delays and disable commands, also add commands for operators in game 38 - - Add translation file 39 - - Improve responses for commands 40 - - Add a perm system 41 - - Limit tpa requests for a player 42 - - Add Quilt support and maybe NeoForge 36 + -[ ] Modify /back to check if the location is safe and automatically choose a nearby location that is safe 37 + -[ ] Create a config to add any delays and disable commands, also add commands for operators in game 38 + -[ ] Add a perm system 39 + -[ ] Limit tpa requests for a player 40 + -[x] Add translation system 41 + -[x] Improve responses for commands 42 + -[x] Add Quilt support and NeoForge 43 + 44 + 45 + ### Want to help? 46 + 47 + #### You can create a Translation file so other people can use the mod in their native language 48 + 1. Clone the repository 49 + 2. Go to `common/src/main/resources/assets/teleport_commands/lang/` 50 + 3. Go to [here](https://minecraft.wiki/w/Language) and pick the in-game locale code for the language you want to translate 51 + 4. Copy `en_us.toml` and paste it in a new file called `[in-game locale code here].toml` 52 + 5. Translate the file 53 + 6. Submit a pull request with your translation :D!
+17 -42
buildSrc/src/main/groovy/multiloader-common.gradle
··· 1 1 plugins { 2 2 id 'java-library' 3 - id 'maven-publish' 4 3 } 5 4 6 5 base { ··· 9 8 10 9 java { 11 10 toolchain.languageVersion = JavaLanguageVersion.of(java_version) 12 - withSourcesJar() 13 - withJavadocJar() 14 11 } 15 12 16 13 repositories { 17 14 mavenCentral() 18 15 // https://docs.gradle.org/current/userguide/declaring_repositories.html#declaring_content_exclusively_found_in_one_repository 19 - exclusiveContent { 20 - forRepository { 21 - maven { 22 - name = 'Sponge' 23 - url = 'https://repo.spongepowered.org/repository/maven-public' 24 - } 25 - } 26 - filter { includeGroupAndSubgroups("org.spongepowered") } 27 - } 16 + 28 17 maven { 29 - name = 'BlameJared' 30 - url = 'https://maven.blamejared.com' 18 + name = 'Sponge' 19 + url = 'https://repo.spongepowered.org/repository/maven-public' 31 20 } 32 21 } 33 22 34 23 dependencies { 35 24 implementation 'org.jetbrains:annotations:24.1.0' 25 + implementation 'org.tomlj:tomlj:1.1.1' 36 26 } 37 27 38 28 // Declare capabilities on the outgoing configurations. 39 29 // Read more about capabilities here: https://docs.gradle.org/current/userguide/component_capabilities.html#sec:declaring-additional-capabilities-for-a-local-component 40 - ['apiElements', 'runtimeElements', 'sourcesElements', 'javadocElements'].each { variant -> 30 + ['apiElements', 'runtimeElements'].each { variant -> 41 31 configurations."$variant".outgoing { 42 32 capability("$group:$mod_id-${project.name}-${minecraft_version}:$version") 43 33 capability("$group:$mod_id:$version") 44 34 } 45 - publishing.publications.configureEach { 46 - suppressPomMetadataWarningsFor(variant) 47 - } 48 - } 49 - 50 - sourcesJar { 51 - from(rootProject.file("LICENSE")) { 52 - rename { "${it}_${mod_name}" } 53 - } 35 + // publishing.publications.configureEach { 36 + // suppressPomMetadataWarningsFor(variant) 37 + // } 54 38 } 55 39 56 40 jar { ··· 77 61 "group": project.group, //Else we target the task's group. 78 62 "minecraft_version": minecraft_version, 79 63 "minecraft_version_range": minecraft_version_range, 80 - "fabric_version": fabric_version, 64 + "parchment_mappings": parchment_mappings, 65 + // "fabric_api": fabric_api, 81 66 "fabric_loader_version": fabric_loader_version, 67 + "fabric_loom": fabric_loom, 68 + "neoforge_version": neoforge_version, 69 + "neoforge_loader_version_range": neoforge_loader_version_range, 70 + "quilt_loader_version": quilt_loader_version, 71 + "quilt_fabric_api": quilt_fabric_api, 72 + "quilt_loom": quilt_loom, 82 73 "mod_name": mod_name, 83 74 "mod_author": mod_author, 84 75 "mod_id": mod_id, 85 76 "license": license, 86 77 "description": project.description, 87 - "neoforge_version": neoforge_version, 88 - "neoforge_loader_version_range": neoforge_loader_version_range, 89 78 "credits": credits, 90 79 "java_version": java_version 91 80 ] 92 81 93 - filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) { 82 + filesMatching(['pack.mcmeta', 'fabric.mod.json', 'quilt.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) { 94 83 expand expandProps 95 84 } 96 85 inputs.properties(expandProps) 97 86 } 98 - 99 - publishing { 100 - publications { 101 - register('mavenJava', MavenPublication) { 102 - artifactId base.archivesName.get() 103 - from components.java 104 - } 105 - } 106 - repositories { 107 - maven { 108 - url System.getenv("local_maven_url") 109 - } 110 - } 111 - }
+1 -13
buildSrc/src/main/groovy/multiloader-loader.gradle
··· 29 29 processResources { 30 30 dependsOn(configurations.commonResources) 31 31 from(configurations.commonResources) 32 - } 33 - 34 - tasks.named('javadoc', Javadoc).configure { 35 - dependsOn(configurations.commonJava) 36 - source(configurations.commonJava) 37 - } 38 - 39 - tasks.named("sourcesJar", Jar) { 40 - dependsOn(configurations.commonJava) 41 - from(configurations.commonJava) 42 - dependsOn(configurations.commonResources) 43 - from(configurations.commonResources) 44 - } 32 + }
+2 -3
common/build.gradle
··· 1 1 plugins { 2 - id 'multiloader-common' 2 + id "multiloader-common" 3 3 id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' 4 4 } 5 5 ··· 29 29 artifacts { 30 30 commonJava sourceSets.main.java.sourceDirectories.singleFile 31 31 commonResources sourceSets.main.resources.sourceDirectories.singleFile 32 - } 33 - 32 + }
+3 -4
common/src/main/java/dev/mrsnowy/teleport_commands/TeleportCommands.java
··· 24 24 public static Path CONFIG_DIR; 25 25 public static MinecraftServer Server; 26 26 27 - public static void initializeMod(MinecraftServer server, String ModLoader) { 27 + public static void initializeMod(MinecraftServer server) { 28 28 // initialize da variables 29 - 30 - MOD_LOADER = ModLoader; 29 + LOGGER.info("Initializing Teleport Commands! Hello {}!", MOD_LOADER); 31 30 32 31 SAVE_DIR = Path.of(String.valueOf(server.getWorldPath(LevelResource.ROOT))); 33 32 ··· 51 50 DeathLocationUpdater(player.position(), player.serverLevel(), player.getStringUUID()); 52 51 53 52 } catch (Exception e) { 54 - throw new RuntimeException(e); 53 + LOGGER.error(e.toString()); 55 54 } 56 55 } 57 56 }
+21 -8
common/src/main/java/dev/mrsnowy/teleport_commands/commands/back.java
··· 12 12 13 13 import static dev.mrsnowy.teleport_commands.storage.StorageManager.GetPlayerStorage; 14 14 import static dev.mrsnowy.teleport_commands.utils.tools.Teleporter; 15 + import static dev.mrsnowy.teleport_commands.utils.tools.getTranslatedText; 15 16 16 17 public class back { 17 18 18 19 public static void register(Commands commandManager) { 19 20 20 21 commandManager.getDispatcher().register(Commands.literal("back").executes(context -> { 21 - ServerPlayer player = context.getSource().getPlayer(); 22 + ServerPlayer player = context.getSource().getPlayerOrException(); 22 23 23 - if (player == null) { 24 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 24 + try { 25 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.teleport", player), true); 26 + ToDeathLocation(player); 27 + } catch (Exception e) { 28 + TeleportCommands.LOGGER.error(String.valueOf(e)); 29 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.back.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 25 30 return 1; 26 31 } 32 + return 0; 33 + })); 34 + 35 + commandManager.getDispatcher().register(Commands.literal("lang").executes(context -> { 36 + ServerPlayer player = context.getSource().getPlayerOrException(); 27 37 28 38 try { 29 - player.displayClientMessage(Component.literal("Teleporting"), true); 30 - ToDeathLocation(player); 39 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.self", player), true); 31 40 } catch (Exception e) { 32 41 TeleportCommands.LOGGER.error(String.valueOf(e)); 33 - player.displayClientMessage(Component.literal("Error Teleporting!").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 42 + // player.displayClientMessage(Component.translatable("commands.teleport_commands.back.error").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 34 43 return 1; 35 44 } 36 45 return 0; ··· 47 56 boolean found = false; 48 57 for (ServerLevel currentWorld : Objects.requireNonNull(player.getServer()).getAllLevels()) { 49 58 if (Objects.equals(currentWorld.dimension().location().toString(), playerStorage.deathLocation.world)) { 50 - Teleporter(player, currentWorld, pos); 59 + if (!player.getPosition(0).equals(pos)) { 60 + Teleporter(player, currentWorld, pos); 61 + } else { 62 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.back.same", player).withStyle(ChatFormatting.AQUA), true); 63 + } 51 64 found = true; 52 65 break; 53 66 } 54 67 } 55 68 56 69 if (!found) { 57 - player.displayClientMessage(Component.literal("No Location Found!"), true); 70 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.back.noLocation", player).withStyle(ChatFormatting.RED), true); 58 71 } 59 72 } 60 73 }
+83 -112
common/src/main/java/dev/mrsnowy/teleport_commands/commands/home.java
··· 13 13 import net.minecraft.server.level.ServerPlayer; 14 14 import net.minecraft.world.phys.Vec3; 15 15 16 + import static dev.mrsnowy.teleport_commands.utils.tools.getTranslatedText; 16 17 import static net.minecraft.commands.Commands.argument; 17 18 import static dev.mrsnowy.teleport_commands.storage.StorageManager.GetPlayerStorage; 18 19 import static dev.mrsnowy.teleport_commands.storage.StorageManager.StorageSaver; ··· 25 26 .then(argument("name", StringArgumentType.string()) 26 27 .executes(context -> { 27 28 final String name = StringArgumentType.getString(context, "name"); 28 - ServerPlayer player = context.getSource().getPlayer(); 29 - 30 - if (player == null) { 31 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 32 - return 1; 33 - } 29 + ServerPlayer player = context.getSource().getPlayerOrException(); 34 30 35 31 try { 36 - player.displayClientMessage(Component.literal("Home Set"), true); 32 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.set", player), true); 37 33 SetHome(player, name); 38 34 39 35 } catch (Exception e) { 40 36 TeleportCommands.LOGGER.error(String.valueOf(e)); 41 - player.displayClientMessage(Component.literal("Error Setting Home!").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 37 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.setError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 42 38 return 1; 43 39 } 44 40 return 0; ··· 47 43 48 44 commandManager.getDispatcher().register(Commands.literal("home") 49 45 .executes(context -> { 50 - ServerPlayer player = context.getSource().getPlayer(); 51 - 52 - if (player == null) { 53 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 54 - return 1; 55 - } 46 + ServerPlayer player = context.getSource().getPlayerOrException(); 56 47 57 48 try { 58 - player.displayClientMessage(Component.literal("Going Home"), true); 49 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.go", player), true); 59 50 GoHome(player, ""); 60 51 61 52 } catch (Exception e) { 62 53 TeleportCommands.LOGGER.error(String.valueOf(e)); 63 - player.displayClientMessage(Component.literal("Error Going Home!").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 54 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.goError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 64 55 return 1; 65 56 } 66 57 return 0; ··· 68 59 .then(argument("name", StringArgumentType.string()).suggests(new HomesuggestionProvider()) 69 60 .executes(context -> { 70 61 final String name = StringArgumentType.getString(context, "name"); 71 - ServerPlayer player = context.getSource().getPlayer(); 72 - 73 - if (player == null) { 74 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 75 - return 1; 76 - } 62 + ServerPlayer player = context.getSource().getPlayerOrException(); 77 63 78 64 try { 79 - player.displayClientMessage(Component.literal("Going Home"), true); 65 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.go", player), true); 80 66 GoHome(player, name); 81 67 82 68 } catch (Exception e) { 83 - player.displayClientMessage(Component.literal("Error Going Home!").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 69 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.goError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 84 70 TeleportCommands.LOGGER.error(String.valueOf(e)); 85 71 return 1; 86 72 } ··· 91 77 .then(argument("name", StringArgumentType.string()).suggests(new HomesuggestionProvider()) 92 78 .executes(context -> { 93 79 final String name = StringArgumentType.getString(context, "name"); 94 - ServerPlayer player = context.getSource().getPlayer(); 95 - 96 - if (player == null) { 97 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 98 - return 1; 99 - } 80 + ServerPlayer player = context.getSource().getPlayerOrException();; 100 81 101 82 try { 102 - player.displayClientMessage(Component.literal("Home Deleted"), true); 83 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.delete", player), true); 103 84 DeleteHome(player, name); 104 85 105 86 } catch (Exception e) { 106 87 TeleportCommands.LOGGER.error(String.valueOf(e)); 107 - player.displayClientMessage(Component.literal("Error Deleting Home!").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 88 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.deleteError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 108 89 return 1; 109 90 } 110 91 return 0; ··· 116 97 .executes(context -> { 117 98 final String name = StringArgumentType.getString(context, "name"); 118 99 final String newName = StringArgumentType.getString(context, "newName"); 119 - ServerPlayer player = context.getSource().getPlayer(); 120 - 121 - if (player == null) { 122 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 123 - return 1; 124 - } 100 + ServerPlayer player = context.getSource().getPlayerOrException(); 125 101 126 102 try { 127 - player.displayClientMessage(Component.literal("Home Renamed"), true); 103 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.rename", player), true); 128 104 RenameHome(player, name, newName); 129 105 } catch (Exception e) { 130 106 TeleportCommands.LOGGER.error(String.valueOf(e)); 131 - player.displayClientMessage(Component.literal("Error Renaming Home!").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 107 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.renameError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 132 108 return 1; 133 109 } 134 110 return 0; 135 111 })))); 136 112 137 113 138 - commandManager.getDispatcher().register(Commands.literal("homes") 139 - .executes(context -> { 140 - ServerPlayer player = context.getSource().getPlayer(); 141 - 142 - if (player == null) { 143 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 144 - return 1; 145 - } 146 - 147 - try { 148 - PrintHomes(player); 149 - } catch (Exception e) { 150 - TeleportCommands.LOGGER.error(String.valueOf(e)); 151 - player.displayClientMessage(Component.literal("Error Getting Homes!").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 152 - return 1; 153 - } 154 - return 0; 155 - })); 156 - 157 114 commandManager.getDispatcher().register(Commands.literal("defaulthome") 158 115 .then(argument("name", StringArgumentType.string()).suggests(new HomesuggestionProvider()) 159 116 .executes(context -> { 160 117 final String name = StringArgumentType.getString(context, "name"); 161 - ServerPlayer player = context.getSource().getPlayer(); 162 - 163 - if (player == null) { 164 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 165 - return 1; 166 - } 118 + ServerPlayer player = context.getSource().getPlayerOrException(); 167 119 168 120 try { 121 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.default", player), true); 169 122 SetDefaultHome(player, name); 170 123 } catch (Exception e) { 171 124 TeleportCommands.LOGGER.error(String.valueOf(e)); 172 - player.displayClientMessage(Component.literal("Error Changing Default Home!").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 125 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.defaultError", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 173 126 return 1; 174 127 } 175 128 return 0; 176 129 }))); 130 + 131 + commandManager.getDispatcher().register(Commands.literal("homes") 132 + .executes(context -> { 133 + ServerPlayer player = context.getSource().getPlayerOrException(); 134 + 135 + try { 136 + PrintHomes(player); 137 + } catch (Exception e) { 138 + TeleportCommands.LOGGER.error(String.valueOf(e)); 139 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.homes.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true); 140 + return 1; 141 + } 142 + return 0; 143 + })); 177 144 } 178 145 179 146 ··· 215 182 216 183 StorageSaver(storage); 217 184 } else { 218 - player.displayClientMessage(Component.literal("Home Already Exists!"), true); 185 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.exists", player).withStyle(ChatFormatting.RED), true); 219 186 } 220 187 } 221 188 ··· 226 193 // check if there is a default exists 227 194 if (homeName.isEmpty()) { 228 195 if (playerStorage.DefaultHome.isEmpty()) { 229 - player.displayClientMessage(Component.literal("You Have No Homes!"), true); 196 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); 230 197 return; 231 198 } else { 232 199 homeName = playerStorage.DefaultHome; ··· 244 211 // find correct world 245 212 for (ServerLevel currentWorld : Objects.requireNonNull(player.getServer()).getAllLevels()) { 246 213 if (Objects.equals(currentWorld.dimension().location().toString(), currentHome.world)) { 247 - Teleporter(player, currentWorld, new Vec3(currentHome.x, currentHome.y, currentHome.z)); 214 + Vec3 coords = new Vec3(currentHome.x, currentHome.y, currentHome.z); 248 215 foundWorld = true; 216 + 217 + if (!player.getPosition(0).equals(coords)) { 218 + Teleporter(player, currentWorld, new Vec3(currentHome.x, currentHome.y, currentHome.z)); 219 + } else { 220 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.goSame", player).withStyle(ChatFormatting.AQUA), true); 221 + } 249 222 break; 250 223 } 251 224 } 252 225 } 253 226 } 254 227 255 - if (!foundHome) { 256 - player.displayClientMessage(Component.literal("Home Not Found!"), true); 257 - } else if (!foundWorld) { 258 - player.displayClientMessage(Component.literal("World Not Found!"), true); 228 + if (!foundHome || !foundWorld) { 229 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); 259 230 } 260 231 } 261 232 ··· 279 250 playerStorage.Homes.remove(homeToDelete); 280 251 StorageSaver(storage); 281 252 } else { 282 - player.displayClientMessage(Component.literal("Home Not Found!"), true); 253 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); 283 254 } 284 255 } 285 256 ··· 312 283 } 313 284 314 285 if (Objects.nonNull(homeToRename)) { 286 + // if the current home is the default home, then change it in the config 315 287 if (Objects.equals(playerStorage.DefaultHome, homeToRename.name)) { 316 288 playerStorage.DefaultHome = newHomeName; 317 289 } ··· 319 291 homeToRename.name = newHomeName; 320 292 StorageSaver(storage); 321 293 } else { 322 - player.displayClientMessage(Component.literal("Home Not Found!"), true); 294 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); 323 295 } 324 296 } else { 325 - player.displayClientMessage(Component.literal("Home Already Exists!"), true); 297 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.renameExists", player).withStyle(ChatFormatting.RED), true); 326 298 } 327 299 328 300 } 329 301 302 + private static void SetDefaultHome(ServerPlayer player, String homeName) throws Exception { 303 + homeName = homeName.toLowerCase(); 304 + StorageManager.PlayerStorageResult storages = GetPlayerStorage(player.getStringUUID()); 305 + StorageManager.StorageClass storage = storages.storage; 306 + StorageManager.StorageClass.Player playerStorage = storages.playerStorage; 307 + 308 + boolean homeExists = false; 309 + 310 + // check if home exists 311 + for (StorageManager.StorageClass.Player.Home currentHome : playerStorage.Homes) { 312 + if (Objects.equals(currentHome.name, homeName)){ 313 + homeExists = true; 314 + break; 315 + } 316 + } 317 + 318 + if (homeExists) { 319 + if (Objects.equals(playerStorage.DefaultHome, homeName)) { 320 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.defaultSame", player).withStyle(ChatFormatting.AQUA), true); 321 + 322 + } else { 323 + playerStorage.DefaultHome = homeName; 324 + StorageSaver(storage); 325 + } 326 + } else { 327 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.notFound", player).withStyle(ChatFormatting.RED), true); 328 + } 329 + } 330 + 330 331 private static void PrintHomes(ServerPlayer player) throws Exception { 331 332 StorageManager.StorageClass.Player playerStorage = GetPlayerStorage(player.getStringUUID()).playerStorage; 332 333 boolean anyHomes = false; 333 334 334 335 for (StorageManager.StorageClass.Player.Home currenthome : playerStorage.Homes) { 335 336 if (!anyHomes) { 336 - player.displayClientMessage(Component.literal("Homes: \n").withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD), false); 337 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.homes.homes", player).withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD), false); 337 338 anyHomes = true; 338 339 } 339 340 340 341 String name = String.format(" - %s", currenthome.name); 341 - String nameDefault = " (Default)"; 342 342 343 343 344 344 String coords = String.format(" [X%.1f Y%.1f Z%.1f]", currenthome.x, currenthome.y, currenthome.z); ··· 346 346 347 347 if (Objects.equals(currenthome.name, playerStorage.DefaultHome)) { 348 348 player.displayClientMessage(Component.literal(name).withStyle(ChatFormatting.AQUA) 349 - .append(Component.literal(nameDefault).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD)), 349 + .append(getTranslatedText("commands.teleport_commands.homes.default", player).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD)), 350 350 false 351 351 ); 352 352 } else { ··· 361 361 ); 362 362 363 363 player.displayClientMessage(Component.literal(" |").withStyle(ChatFormatting.AQUA) 364 - .append(Component.literal(" [Tp]").withStyle(ChatFormatting.GREEN).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/home %s", currenthome.name))))) 365 - .append(Component.literal(" [Rename]").withStyle(ChatFormatting.BLUE).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format("/renamehome %s ", currenthome.name))))) 366 - .append(Component.literal(" [Delete]\n").withStyle(ChatFormatting.RED).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format("/delhome %s", currenthome.name))))), 364 + .append(getTranslatedText("commands.teleport_commands.homes.tp", player).withStyle(ChatFormatting.GREEN).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/home %s", currenthome.name))))) 365 + .append(getTranslatedText("commands.teleport_commands.homes.rename", player).withStyle(ChatFormatting.BLUE).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format("/renamehome %s ", currenthome.name))))) 366 + .append(getTranslatedText("commands.teleport_commands.homes.delete", player).withStyle(ChatFormatting.RED).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format("/delhome %s", currenthome.name))))), 367 367 false 368 368 ); 369 369 } 370 370 371 371 if (!anyHomes) { 372 - player.displayClientMessage(Component.literal("No homes set"), true); 373 - } 374 - } 375 - 376 - private static void SetDefaultHome(ServerPlayer player, String homeName) throws Exception { 377 - homeName = homeName.toLowerCase(); 378 - StorageManager.PlayerStorageResult storages = GetPlayerStorage(player.getStringUUID()); 379 - StorageManager.StorageClass storage = storages.storage; 380 - StorageManager.StorageClass.Player playerStorage = storages.playerStorage; 381 - 382 - boolean homeExists = false; 383 - 384 - // check if home exists 385 - for (StorageManager.StorageClass.Player.Home currentHome : playerStorage.Homes) { 386 - if (Objects.equals(currentHome.name, homeName)){ 387 - homeExists = true; 388 - break; 389 - } 390 - } 391 - 392 - if (homeExists) { 393 - if (Objects.equals(playerStorage.DefaultHome, homeName)) { 394 - player.displayClientMessage(Component.literal("Home is already set as default!"), true); 395 - 396 - } else { 397 - playerStorage.DefaultHome = homeName; 398 - StorageSaver(storage); 399 - } 400 - } else { 401 - player.displayClientMessage(Component.literal("Home not found!"), true); 372 + player.displayClientMessage(getTranslatedText("commands.teleport_commands.home.homeless", player).withStyle(ChatFormatting.AQUA), true); 402 373 } 403 374 } 404 375 }
+31 -60
common/src/main/java/dev/mrsnowy/teleport_commands/commands/tpa.java
··· 7 7 import net.minecraft.commands.arguments.EntityArgument; 8 8 import net.minecraft.network.chat.ClickEvent; 9 9 import net.minecraft.network.chat.Component; 10 + import net.minecraft.network.chat.MutableComponent; 10 11 import net.minecraft.server.level.ServerPlayer; 11 12 12 13 import static dev.mrsnowy.teleport_commands.utils.tools.Teleporter; 14 + import static dev.mrsnowy.teleport_commands.utils.tools.getTranslatedText; 13 15 14 16 public class tpa { 15 17 ··· 27 29 .then(Commands.argument("player", EntityArgument.player()) 28 30 .executes(context -> { 29 31 final ServerPlayer TargetPlayer = EntityArgument.getPlayer(context, "player"); 30 - ServerPlayer player = context.getSource().getPlayer(); 31 - 32 - if (player == null) { 33 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 34 - return 1; 35 - } 32 + ServerPlayer player = context.getSource().getPlayerOrException(); 36 33 37 34 tpaCommandHandler(player, TargetPlayer, false); 38 35 return 0; ··· 42 39 .then(Commands.argument("player", EntityArgument.player()) 43 40 .executes(context -> { 44 41 final ServerPlayer TargetPlayer = EntityArgument.getPlayer(context, "player"); 45 - ServerPlayer player = context.getSource().getPlayer(); 42 + ServerPlayer player = context.getSource().getPlayerOrException(); 46 43 47 - if (player == null) { 48 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 49 - return 1; 50 - } 51 44 52 45 tpaCommandHandler(player, TargetPlayer, true); 53 46 return 0; ··· 57 50 .then(Commands.argument("player", EntityArgument.player()) 58 51 .executes(context -> { 59 52 final ServerPlayer TargetPlayer = EntityArgument.getPlayer(context, "player"); 60 - ServerPlayer player = context.getSource().getPlayer(); 61 - 62 - if (player == null) { 63 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 64 - return 1; 65 - } 53 + ServerPlayer player = context.getSource().getPlayerOrException(); 66 54 67 55 tpaAccept(player, TargetPlayer); 68 56 return 0; ··· 72 60 .then(Commands.argument("player", EntityArgument.player()) 73 61 .executes(context -> { 74 62 final ServerPlayer TargetPlayer = EntityArgument.getPlayer(context, "player"); 75 - ServerPlayer player = context.getSource().getPlayer(); 76 - 77 - if (player == null) { 78 - TeleportCommands.LOGGER.error("Error while executing the command, No player found!"); 79 - return 1; 80 - } 63 + ServerPlayer player = context.getSource().getPlayerOrException(); 81 64 82 65 tpaDeny(player, TargetPlayer); 83 66 return 0; ··· 86 69 87 70 88 71 89 - private static void tpaCommandHandler(ServerPlayer FromPlayer, ServerPlayer ToPlayer, boolean here) { 72 + private static void tpaCommandHandler(ServerPlayer FromPlayer, ServerPlayer ToPlayer, boolean here) throws NullPointerException { 90 73 91 74 if (FromPlayer == ToPlayer) { 92 - FromPlayer.displayClientMessage(Component.literal("Well, that was easy").withStyle(ChatFormatting.AQUA),true); 75 + FromPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.self", FromPlayer).withStyle(ChatFormatting.AQUA),true); 93 76 94 77 } else { 95 - String ToMessage; 96 - String FromMessage; 78 + String hereText = here ? "Here" : ""; 79 + MutableComponent ReceivedFromMessage = getTranslatedText("commands.teleport_commands.tpa.received", ToPlayer, hereText); 80 + MutableComponent SentToMessage = getTranslatedText("commands.teleport_commands.tpa.sent", FromPlayer, hereText); 97 81 98 82 // Store da request 99 83 tpaArrayClass tpaRequest = new tpaArrayClass(); ··· 102 86 tpaRequest.here = here; 103 87 tpaList.add(tpaRequest); 104 88 105 - if (here) { 106 - ToMessage = "TpaHere Request Received From "; 107 - FromMessage = "TpaHere Request Send to "; 89 + String ReceivedFromPlayer = Objects.requireNonNull(FromPlayer.getName().tryCollapseToString()); 90 + String SentToPlayer = Objects.requireNonNull(ToPlayer.getName().tryCollapseToString()); 108 91 109 - } else { 110 - ToMessage = "Tpa Request Received From "; 111 - FromMessage = "Tpa Request Send to "; 112 - } 113 - 114 - String ToPlayerString = Objects.requireNonNull(ToPlayer.getName().tryCollapseToString()); 115 - String FromPlayerString = Objects.requireNonNull(FromPlayer.getName().tryCollapseToString()); 116 - 117 - FromPlayer.displayClientMessage(Component.literal(FromMessage).withStyle(ChatFormatting.AQUA) 118 - .append(Component.literal(ToPlayerString).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD)) 119 - // .append(Text.literal("\n[Cancel]").formatted(Formatting.BLUE, Formatting.BOLD)) 92 + FromPlayer.displayClientMessage(SentToMessage 93 + .append(Component.literal(SentToPlayer).withStyle(ChatFormatting.BOLD)) 94 + // .append(Text.literal("\n[Cancel]").formatted(Formatting.BLUE, Formatting.BOLD)) 120 95 ,true 121 96 ); 122 97 123 - ToPlayer.displayClientMessage(Component.literal(ToMessage).withStyle(ChatFormatting.AQUA) 124 - .append(Component.literal(FromPlayerString).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD)) 125 - .append(Component.literal("\n[Accept]").withStyle(ChatFormatting.GREEN, ChatFormatting.BOLD).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/tpaaccept %s", FromPlayerString))))) 126 - .append(Component.literal(" [Deny]").withStyle(ChatFormatting.RED, ChatFormatting.BOLD).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/tpadeny %s", FromPlayerString))))), 98 + ToPlayer.displayClientMessage(ReceivedFromMessage.withStyle(ChatFormatting.AQUA) 99 + .append(Component.literal(ReceivedFromPlayer).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD)) 100 + .append(getTranslatedText("commands.teleport_commands.tpa.accept", ToPlayer).withStyle(ChatFormatting.GREEN, ChatFormatting.BOLD).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/tpaaccept %s", ReceivedFromPlayer))))) 101 + .append(getTranslatedText("commands.teleport_commands.tpa.deny", ToPlayer).withStyle(ChatFormatting.RED, ChatFormatting.BOLD).withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/tpadeny %s", ReceivedFromPlayer))))), 127 102 false 128 103 ); 129 104 ··· 134 109 public void run() { 135 110 boolean successful = tpaList.remove(tpaRequest); 136 111 if (successful) { 137 - if (here) { 138 - FromPlayer.displayClientMessage(Component.literal("TpaHere Request Expired").withStyle(ChatFormatting.AQUA),true); 139 - } else { 140 - FromPlayer.displayClientMessage(Component.literal("Tpa Request Expired").withStyle(ChatFormatting.AQUA),true); 141 - } 112 + FromPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.expired", FromPlayer, hereText).withStyle(ChatFormatting.RED, ChatFormatting.BOLD),true); 142 113 } 143 114 } 144 115 }, 30 * 1000 ··· 148 119 149 120 private static void tpaAccept(ServerPlayer FromPlayer, ServerPlayer ToPlayer) { 150 121 if (FromPlayer == ToPlayer) { 151 - FromPlayer.displayClientMessage(Component.literal("Uhm.. no?").withStyle(ChatFormatting.AQUA),true); 122 + FromPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.self", FromPlayer).withStyle(ChatFormatting.AQUA),true); 152 123 } else { 153 124 Optional<tpaArrayClass> tpaStorage = tpaList.stream() 154 125 .filter(tpa -> Objects.equals(ToPlayer.getStringUUID(), tpa.InitPlayer)) ··· 157 128 158 129 if (tpaStorage.isPresent()) { 159 130 if (tpaStorage.get().here) { 160 - FromPlayer.displayClientMessage(Component.literal("Teleporting"),true); 161 - ToPlayer.displayClientMessage(Component.literal("Request Accepted"),true); 131 + FromPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.common.teleport", FromPlayer).withStyle(ChatFormatting.AQUA),true); 132 + ToPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.accepted", ToPlayer).withStyle(ChatFormatting.GREEN),true); 162 133 163 134 Teleporter(FromPlayer, ToPlayer.serverLevel(), ToPlayer.position()); 164 135 } else { 165 - ToPlayer.displayClientMessage(Component.literal("Teleporting"),true); 166 - FromPlayer.displayClientMessage(Component.literal("Request Accepted"),true); 136 + ToPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.common.teleport", ToPlayer).withStyle(ChatFormatting.AQUA),true); 137 + FromPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.accepted", FromPlayer).withStyle(ChatFormatting.GREEN),true); 167 138 168 139 Teleporter(ToPlayer, FromPlayer.serverLevel(), FromPlayer.position()); 169 140 } 170 141 171 142 tpaList.remove(tpaStorage.get()); 172 143 } else { 173 - FromPlayer.displayClientMessage(Component.literal("No Requests found!").withStyle(ChatFormatting.AQUA),true); 144 + FromPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.notFound", FromPlayer).withStyle(ChatFormatting.RED),true); 174 145 } 175 146 } 176 147 } 177 148 178 149 private static void tpaDeny(ServerPlayer FromPlayer, ServerPlayer ToPlayer) { 179 150 if (FromPlayer == ToPlayer) { 180 - FromPlayer.displayClientMessage(Component.literal("Uhm.. no?").withStyle(ChatFormatting.AQUA),true); 151 + FromPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.self", FromPlayer).withStyle(ChatFormatting.AQUA),true); 181 152 } else { 182 153 Optional<tpaArrayClass> tpaStorage = tpaList.stream() 183 154 .filter(tpa -> Objects.equals(ToPlayer.getStringUUID(), tpa.InitPlayer)) ··· 188 159 tpaList.remove(tpaStorage.get()); 189 160 190 161 if (tpaStorage.get().here) { 191 - ToPlayer.displayClientMessage(Component.literal("Request Denied").withStyle(ChatFormatting.AQUA),true); 162 + ToPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.denied", ToPlayer).withStyle(ChatFormatting.RED, ChatFormatting.BOLD),true); 192 163 } else { 193 - FromPlayer.displayClientMessage(Component.literal("Request Denied").withStyle(ChatFormatting.AQUA),true); 164 + FromPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.denied", FromPlayer).withStyle(ChatFormatting.RED, ChatFormatting.BOLD),true); 194 165 } 195 166 } else { 196 - FromPlayer.displayClientMessage(Component.literal("No Requests found!").withStyle(ChatFormatting.AQUA),true); 167 + FromPlayer.displayClientMessage(getTranslatedText("commands.teleport_commands.tpa.notFound", FromPlayer).withStyle(ChatFormatting.RED),true); 197 168 } 198 169 } 199 170 }
+18
common/src/main/java/dev/mrsnowy/teleport_commands/mixin/PlayerDeathMixin.java
··· 1 + package dev.mrsnowy.teleport_commands.mixin; 2 + 3 + import dev.mrsnowy.teleport_commands.TeleportCommands; 4 + import net.minecraft.server.level.ServerPlayer; 5 + import org.spongepowered.asm.mixin.Mixin; 6 + import org.spongepowered.asm.mixin.injection.At; 7 + import org.spongepowered.asm.mixin.injection.Inject; 8 + import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 9 + 10 + @Mixin(ServerPlayer.class) 11 + public class PlayerDeathMixin { 12 + 13 + @Inject(method = "die", at = @At("HEAD")) 14 + private void notifyDeath(CallbackInfo ci) { 15 + 16 + TeleportCommands.onPlayerDeath((ServerPlayer) (Object) this); 17 + } 18 + }
+19
common/src/main/java/dev/mrsnowy/teleport_commands/mixin/ServerStartMixin.java
··· 1 + package dev.mrsnowy.teleport_commands.mixin; 2 + 3 + import dev.mrsnowy.teleport_commands.TeleportCommands; 4 + import net.minecraft.server.MinecraftServer; 5 + import org.spongepowered.asm.mixin.Mixin; 6 + import org.spongepowered.asm.mixin.injection.At; 7 + import org.spongepowered.asm.mixin.injection.Inject; 8 + import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 9 + 10 + @Mixin(MinecraftServer.class) 11 + public class ServerStartMixin { 12 + 13 + @Inject(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;buildServerStatus()Lnet/minecraft/network/protocol/status/ServerStatus;", ordinal = 0)) 14 + private void runServer(CallbackInfo info) { 15 + 16 + TeleportCommands.initializeMod((MinecraftServer) (Object) this); 17 + } 18 + } 19 +
+46 -1
common/src/main/java/dev/mrsnowy/teleport_commands/utils/tools.java
··· 1 1 package dev.mrsnowy.teleport_commands.utils; 2 2 3 + import dev.mrsnowy.teleport_commands.TeleportCommands; 3 4 import dev.mrsnowy.teleport_commands.storage.StorageManager; 5 + 6 + import java.io.*; 4 7 import java.util.*; 8 + 5 9 import net.minecraft.core.particles.ParticleTypes; 10 + import net.minecraft.network.chat.Component; 11 + import net.minecraft.network.chat.MutableComponent; 6 12 import net.minecraft.server.level.ServerLevel; 7 13 import net.minecraft.server.level.ServerPlayer; 8 14 import net.minecraft.sounds.SoundEvent; 9 15 import net.minecraft.sounds.SoundSource; 10 16 import net.minecraft.world.phys.Vec3; 17 + import org.tomlj.Toml; 18 + import org.tomlj.TomlParseResult; 11 19 20 + import static dev.mrsnowy.teleport_commands.TeleportCommands.MOD_ID; 12 21 import static dev.mrsnowy.teleport_commands.storage.StorageManager.GetPlayerStorage; 13 22 import static dev.mrsnowy.teleport_commands.storage.StorageManager.StorageSaver; 14 23 import static net.minecraft.sounds.SoundEvents.ENDERMAN_TELEPORT; ··· 30 39 player.onUpdateAbilities(); 31 40 } 32 41 42 + 33 43 world.playSound(null, player.blockPosition(), SoundEvent.createVariableRangeEvent(ENDERMAN_TELEPORT.getLocation()), SoundSource.PLAYERS, 0.4f, 1.0f); 34 44 Timer timer = new Timer(); 35 45 ··· 45 55 } 46 56 47 57 48 - 49 58 public static void DeathLocationUpdater(Vec3 pos, ServerLevel world, String UUID) throws Exception { 50 59 StorageManager.PlayerStorageResult storages = GetPlayerStorage(UUID); 51 60 ··· 58 67 playerStorage.deathLocation.world = world.dimension().location().toString(); 59 68 60 69 StorageSaver(storage); 70 + } 71 + 72 + // 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) 73 + public static MutableComponent getTranslatedText(String key, ServerPlayer player, Object... args) { 74 + String language = player.clientInformation().language(); 75 + 76 + try { 77 + String filePath = String.format("/assets/%s/lang/%s.toml", MOD_ID, language); 78 + InputStream stream = TeleportCommands.class.getResourceAsStream(filePath); 79 + 80 + assert stream != null; 81 + TomlParseResult toml = Toml.parse(stream); 82 + String translation = toml.getString(key); 83 + 84 + assert translation != null; 85 + return Component.literal(String.format(translation, args)); 86 + 87 + } catch (Exception ignored) { 88 + try { 89 + if (!Objects.equals(language, "en_us")) { 90 + TeleportCommands.LOGGER.warn("Key \"{}\" not found in the language: {}, falling back to default (en_us)", key, language); 91 + 92 + String filePath = String.format("/assets/%s/lang/en_us.toml", MOD_ID); 93 + InputStream stream = TeleportCommands.class.getResourceAsStream(filePath); 94 + 95 + assert stream != null; 96 + TomlParseResult toml = Toml.parse(stream); 97 + String translation = toml.getString(key); 98 + 99 + assert translation != null; 100 + return Component.literal(String.format(translation, args)); 101 + } 102 + } catch (Exception ignored1) {} 103 + TeleportCommands.LOGGER.error("Key \"{}\" not found in the default language (en_us), sending raw key as fallback.", key); 104 + return Component.literal(key); 105 + } 61 106 } 62 107 }
+44
common/src/main/resources/assets/teleport_commands/lang/en_us.toml
··· 1 + #back 2 + commands.teleport_commands.back.error = "Error Teleporting!" 3 + commands.teleport_commands.back.same = "Already Back" 4 + commands.teleport_commands.back.noLocation = "No Location Found!" 5 + 6 + #home 7 + commands.teleport_commands.home.set = "Home Set" 8 + commands.teleport_commands.home.setError = "Error Setting Home!" 9 + commands.teleport_commands.home.go = "Going Home" 10 + commands.teleport_commands.home.goError = "Error Going Home!" 11 + commands.teleport_commands.home.goSame = "Already Home" 12 + commands.teleport_commands.home.delete = "Home Deleted" 13 + commands.teleport_commands.home.deleteError = "Error Deleting Home!" 14 + commands.teleport_commands.home.rename = "Home Renamed" 15 + commands.teleport_commands.home.renameError = "Error Renaming Home!" 16 + commands.teleport_commands.home.renameExists = "That Name Already Exists!" 17 + commands.teleport_commands.home.default = "Default Home Set" 18 + commands.teleport_commands.home.defaultError = "Error Changing Default Home!" 19 + commands.teleport_commands.home.defaultSame = "Home is already set as default!" 20 + commands.teleport_commands.home.notFound = "Home Not Found!" 21 + commands.teleport_commands.home.exists = "Home Already Exists!" 22 + commands.teleport_commands.home.homeless = "You Have No Homes!" 23 + 24 + # homes 25 + commands.teleport_commands.homes.error = "Error Getting Homes!" 26 + commands.teleport_commands.homes.homes = "Homes: \n" 27 + commands.teleport_commands.homes.default = " (Default)" 28 + commands.teleport_commands.homes.tp = " [Tp]" 29 + commands.teleport_commands.homes.rename = " [Rename]" 30 + commands.teleport_commands.homes.delete = " [Delete]\n" 31 + 32 + # tpa 33 + commands.teleport_commands.tpa.self = "Well, that was easy" 34 + commands.teleport_commands.tpa.received = "Tpa%s Request Received From " 35 + commands.teleport_commands.tpa.sent = "Tpa%s Request Sent to " 36 + commands.teleport_commands.tpa.accept = "\n[Accept]" 37 + commands.teleport_commands.tpa.deny = " [Deny]" 38 + commands.teleport_commands.tpa.expired = "Tpa%s Request Expired" 39 + commands.teleport_commands.tpa.notFound = "No Requests found!" 40 + commands.teleport_commands.tpa.accepted = "Request Accepted" 41 + commands.teleport_commands.tpa.denied = "Request Denied" 42 + 43 + # common 44 + commands.teleport_commands.common.teleport = "Teleporting"
-6
common/src/main/resources/pack.mcmeta
··· 1 - { 2 - "pack": { 3 - "description": "${mod_name}", 4 - "pack_format": 8 5 - } 6 - }
+16
common/src/main/resources/teleport_commands.mixins.json
··· 1 + { 2 + "required": true, 3 + "minVersion": "0.8", 4 + "package": "${group}.mixin", 5 + "refmap": "${mod_id}.refmap.json", 6 + "compatibilityLevel": "JAVA_${java_version}", 7 + "mixins": [ 8 + "ServerStartMixin", 9 + "PlayerDeathMixin" 10 + ], 11 + "client": [], 12 + "server": [], 13 + "injectors": { 14 + "defaultRequire": 1 15 + } 16 + }
+9 -3
fabric/build.gradle
··· 1 1 plugins { 2 2 id 'multiloader-loader' 3 - id 'fabric-loom' version '1.6-SNAPSHOT' 3 + id 'fabric-loom' version "${fabric_loom}" 4 4 } 5 + 5 6 dependencies { 6 7 minecraft "com.mojang:minecraft:${minecraft_version}" 7 - mappings loom.officialMojangMappings() 8 + mappings loom.layered() { 9 + officialMojangMappings() 10 + parchment("org.parchmentmc.data:parchment-${parchment_mappings}@zip") 11 + } 8 12 modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" 9 - modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" 13 + // modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_api}" 14 + 15 + implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' 10 16 } 11 17 12 18 loom {
+1 -21
fabric/src/main/java/dev/mrsnowy/teleport_commands/fabricInit.java
··· 1 1 package dev.mrsnowy.teleport_commands; 2 2 3 3 import net.fabricmc.api.ModInitializer; 4 - import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents; 5 - import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; 6 - import net.minecraft.server.level.ServerPlayer; 7 - 8 - import java.util.Objects; 9 4 10 5 public class fabricInit implements ModInitializer { 11 6 ··· 15 10 // However, some things (like resources) may still be uninitialized. 16 11 // Proceed with mild caution. 17 12 18 - TeleportCommands.LOGGER.info("Teleport Commands loaded! Hello Fabric!"); 19 - 20 - // initialize the mod 21 - ServerLifecycleEvents.SERVER_STARTED.register((server) -> { 22 - TeleportCommands.initializeMod(server, "Fabric"); 23 - }); 24 - 25 - 26 - // check if it is a player and check if the player died 27 - ServerEntityEvents.ENTITY_UNLOAD.register((entity, world) -> { 28 - if (entity instanceof ServerPlayer player) { 29 - if (player.getRemovalReason() != null && (Objects.equals(player.getRemovalReason().toString(), "KILLED") || Objects.equals(player.getRemovalReason().toString(), "DISCARDED"))) { 30 - TeleportCommands.onPlayerDeath(player); 31 - } 32 - } 33 - }); 13 + TeleportCommands.MOD_LOADER = "Fabric"; 34 14 } 35 15 }
+4 -5
fabric/src/main/resources/fabric.mod.json
··· 20 20 "dev.mrsnowy.teleport_commands.fabricInit" 21 21 ] 22 22 }, 23 + "mixins": [ 24 + "${mod_id}.mixins.json" 25 + ], 23 26 "custom": { 24 27 "modmenu": { 25 28 "links": { ··· 30 33 }, 31 34 "depends": { 32 35 "fabricloader": ">=${fabric_loader_version}", 33 - "fabric-api": "*", 34 - "minecraft": "${minecraft_version}", 36 + "minecraft": "~${minecraft_version}", 35 37 "java": ">=${java_version}" 36 - }, 37 - "suggests": { 38 - "another-mod": "*" 39 38 } 40 39 } 41 40
+10 -2
gradle.properties
··· 8 8 9 9 # Common 10 10 minecraft_version=1.20.4 11 + parchment_mappings=1.20.4:2024.04.14 11 12 mod_name=Teleport Commands 12 13 mod_author=Mr. Snowy 13 14 mod_id=teleport_commands ··· 17 18 minecraft_version_range=[1.20.4, 1.21) 18 19 19 20 # Fabric 20 - fabric_version=0.97.0+1.20.4 21 - fabric_loader_version=0.15.10 21 + fabric_loader_version=0.15.7 22 + #fabric_api=0.97.0+1.20.4 23 + fabric_loom=1.6-SNAPSHOT 24 + 25 + # Quilt 26 + quilt_loader_version=0.25.0 27 + quilt_fabric_api=9.0.0-alpha.8+0.97.0-1.20.4 28 + quilt_loom=1.6.7 29 + 22 30 23 31 # NeoForge 24 32 neoforge_version=20.4.234
+2 -26
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.EventPriority; 4 - import net.neoforged.bus.api.IEventBus; 5 - import net.neoforged.bus.api.SubscribeEvent; 6 3 import net.neoforged.fml.common.Mod; 7 - import net.neoforged.neoforge.event.entity.living.LivingDeathEvent; 8 - import net.neoforged.neoforge.event.server.ServerStartingEvent; 9 - import net.minecraft.server.level.ServerPlayer; 10 4 11 5 @Mod(TeleportCommands.MOD_ID) 12 6 public class neoforgeInit { 13 7 14 - public neoforgeInit(IEventBus eventBus) { 8 + public neoforgeInit() { 15 9 // This method is invoked by the NeoForge mod loader when it is ready 16 10 // to load your mod. You can access NeoForge and Common code in this 17 11 // project. 18 12 19 - TeleportCommands.LOGGER.info("Teleport Commands loaded! Hello NeoForge!"); 20 - } 21 - 22 - @Mod.EventBusSubscriber(modid = TeleportCommands.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) 23 - private static class NeoForgeEventSubscriber { 24 - 25 - @SubscribeEvent(priority = EventPriority.HIGHEST) 26 - private static void onServerStarting(ServerStartingEvent event) { 27 - // initialize the mod 28 - TeleportCommands.initializeMod(event.getServer(), "NeoForge"); 29 - } 30 - 31 - @SubscribeEvent(priority = EventPriority.HIGHEST) 32 - private static void onEntityUnload(LivingDeathEvent event) { 33 - // check if it is a player 34 - if (event.getEntity() instanceof ServerPlayer player) { 35 - TeleportCommands.onPlayerDeath(player); 36 - } 37 - } 13 + TeleportCommands.MOD_LOADER = "NeoForge"; 38 14 } 39 15 } 40 16
+2
neoforge/src/main/resources/META-INF/mods.toml
··· 12 12 credits="${credits}" #optional 13 13 authors = "${mod_author}" #optional 14 14 description = '''${description}''' #mandatory (Supports multiline text) 15 + [[mixins]] 16 + config = "${mod_id}.mixins.json" 15 17 [[dependencies.${mod_id}]] #optional 16 18 modId = "neoforge" #mandatory 17 19 type="required" #mandatory (Can be one of "required", "optional", "incompatible" or "discouraged")
+2
neoforge/src/main/resources/META-INF/neoforge.mods.toml
··· 12 12 credits="${credits}" #optional 13 13 authors = "${mod_author}" #optional 14 14 description = '''${description}''' #mandatory (Supports multiline text) 15 + [[mixins]] 16 + config = "${mod_id}.mixins.json" 15 17 [[dependencies.${mod_id}]] #optional 16 18 modId = "neoforge" #mandatory 17 19 type="required" #mandatory (Can be one of "required", "optional", "incompatible" or "discouraged")
+35
quilt/build.gradle
··· 1 + plugins { 2 + id 'multiloader-loader' 3 + id 'org.quiltmc.loom' version "${quilt_loom}" 4 + } 5 + 6 + dependencies { 7 + minecraft "com.mojang:minecraft:${minecraft_version}" 8 + mappings loom.layered() { 9 + officialMojangMappings() 10 + // parchment("org.parchmentmc.data:parchment-${parchment_mappings}@zip") 11 + } 12 + modImplementation "org.quiltmc:quilt-loader:${quilt_loader_version}" 13 + modImplementation "org.quiltmc.quilted-fabric-api:quilted-fabric-api:${quilt_fabric_api}" 14 + } 15 + 16 + loom { 17 + def aw = project(":common").file("src/main/resources/${mod_id}.accesswidener") 18 + if (aw.exists()) { 19 + accessWidenerPath.set(aw) 20 + } 21 + runs { 22 + client { 23 + client() 24 + setConfigName("Quilt Client") 25 + ideConfigGenerated(true) 26 + runDir("runs/client") 27 + } 28 + server { 29 + server() 30 + setConfigName("Quilt Server") 31 + ideConfigGenerated(true) 32 + runDir("runs/server") 33 + } 34 + } 35 + }
+16
quilt/src/main/java/dev/mrsnowy/teleport_commands/quiltInit.java
··· 1 + package dev.mrsnowy.teleport_commands; 2 + 3 + import org.quiltmc.loader.api.ModContainer; 4 + import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; 5 + 6 + public class quiltInit implements ModInitializer { 7 + 8 + @Override 9 + public void onInitialize(ModContainer mod) { 10 + // This code runs as soon as Minecraft is in a mod-load-ready state. 11 + // However, some things (like resources) may still be uninitialized. 12 + // Proceed with mild caution. 13 + 14 + TeleportCommands.MOD_LOADER = "Quilt"; 15 + } 16 + }
+41
quilt/src/main/resources/quilt.mod.json
··· 1 + { 2 + "schema_version": 1, 3 + "quilt_loader": { 4 + "group": "${group}", 5 + "id": "${mod_id}", 6 + "version": "${version}", 7 + "metadata": { 8 + "name": "${mod_name}", 9 + "description": "${description}", 10 + "contributors": { 11 + "${mod_author}": "Owner" 12 + }, 13 + "contact": { 14 + "homepage": "https://mrsnowy.dev/", 15 + "sources": "https://github.com/MrSn0wy/TeleportCommands", 16 + "issues": "https://github.com/MrSn0wy/TeleportCommands/issues" 17 + }, 18 + "icon": "${mod_id}.png", 19 + "license": "${license}" 20 + }, 21 + "intermediate_mappings": "net.fabricmc:intermediary", 22 + "entrypoints": { 23 + "init": "dev.mrsnowy.teleport_commands.quiltInit" 24 + }, 25 + "depends": [ 26 + { 27 + "id": "quilt_loader", 28 + "versions": ">=${quilt_loader_version}" 29 + }, 30 + { 31 + "id": "minecraft", 32 + "versions": "~${minecraft_version}" 33 + }, 34 + { 35 + "id": "java", 36 + "versions": ">=${java_version}" 37 + } 38 + ] 39 + }, 40 + "mixin": "${mod_id}.mixins.json" 41 + }
+20 -35
settings.gradle
··· 1 1 pluginManagement { 2 2 repositories { 3 3 gradlePluginPortal() 4 - mavenCentral() 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 - } 4 + maven { 5 + name = 'Fabric' 6 + url = uri("https://maven.fabricmc.net") 16 7 } 17 - exclusiveContent { 18 - forRepository { 19 - maven { 20 - name = 'NeoForge' 21 - url = uri("https://maven.neoforged.net/releases") 22 - } 23 - } 24 - filter { 25 - includeGroupAndSubgroups("net.neoforged") 26 - includeGroup("codechicken") 27 - } 8 + maven { 9 + name = 'Quilt' 10 + url = 'https://maven.quiltmc.org/repository/release' 11 + } 12 + maven { 13 + name = 'NeoForge' 14 + url = uri("https://maven.neoforged.net/releases") 15 + } 16 + maven { 17 + name = 'Sponge Snapshots' 18 + url = uri("https://repo.spongepowered.org/repository/maven-public") 28 19 } 29 - exclusiveContent { 30 - forRepository { 31 - maven { 32 - name = 'Sponge Snapshots' 33 - url = uri("https://repo.spongepowered.org/repository/maven-public") 34 - } 35 - } 36 - filter { 37 - includeGroupAndSubgroups("org.spongepowered") 38 - includeGroup("net.minecraftforge") 39 - } 20 + maven { 21 + name = 'ParchmentMC' 22 + url = 'https://maven.parchmentmc.org' 40 23 } 41 24 } 42 25 } ··· 46 29 } 47 30 48 31 // This should match the folder name of the project, or else IDEA may complain (see https://youtrack.jetbrains.com/issue/IDEA-317606) 49 - rootProject.name = 'MultiLoader-Template' 32 + rootProject.name = "Teleport Commands" 50 33 include("common") 51 34 include("fabric") 52 35 include("neoforge") 36 + include("quilt") 37 +