···11# Teleport Commands <img src="https://raw.githubusercontent.com/MrSn0wy/TeleportCommands/main/src/main/resources/assets/teleport_commands/icon.png" alt="Teleport Commands Logo" width="30"/>
223344-A Minecraft fabric server-side mod that adds various teleportation related commands, like /home /tpa and /back
44+A Minecraft Fabric and NeoForge server-side mod that adds various teleportation related commands, like /home /tpa and /back
5566### This mod is still in beta, if there are any problems then let me know!
77
+3-85
build.gradle
···11-plugins {
22- id 'fabric-loom' version '1.6-SNAPSHOT'
33- id 'maven-publish'
44-}
55-66-version = project.mod_version
77-group = project.maven_group
88-99-base {
1010- archivesName = project.archives_base_name
1111-}
1212-1313-repositories {
1414- // Add repositories to retrieve artifacts from in here.
1515- // You should only use this when depending on other mods because
1616- // Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
1717- // See https://docs.gradle.org/current/userguide/declaring_repositories.html
1818- // for more information about repositories.
1919-}
2020-2121-loom {
2222- splitEnvironmentSourceSets()
2323-2424- mods {
2525- "teleport_commands" {
2626- sourceSet sourceSets.main
2727- }
2828- }
2929-3030-}
3131-3232-dependencies {
3333- // To change the versions see the gradle.properties file
3434- minecraft "com.mojang:minecraft:${project.minecraft_version}"
3535- mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
3636- modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
3737-3838- // Fabric API. This is technically optional, but you probably want it anyway.
3939- modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
4040-4141-}
4242-4343-processResources {
4444- inputs.property "version", project.version
4545-4646- filesMatching("fabric.mod.json") {
4747- expand "version": project.version
4848- }
4949-}
5050-5151-tasks.withType(JavaCompile).configureEach {
5252- it.options.release = 17
5353-}
5454-5555-java {
5656- // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
5757- // if it is present.
5858- // If you remove this line, sources will not be generated.
5959- withSourcesJar()
6060-6161- sourceCompatibility = JavaVersion.VERSION_17
6262- targetCompatibility = JavaVersion.VERSION_17
6363-}
6464-6565-jar {
6666- from("LICENSE") {
6767- rename { "${it}_${project.base.archivesName.get()}"}
6868- }
6969-}
7070-7171-// configure the maven publication
7272-publishing {
7373- publications {
7474- create("mavenJava", MavenPublication) {
7575- from components.java
7676- }
7777- }
7878-7979- // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
8080- repositories {
8181- // Add repositories to publish to here.
8282- // Notice: This block does NOT have the same function as the block in the top level.
8383- // The repositories here will be used for publishing your artifact, not for
8484- // retrieving dependencies.
8585- }
11+plugins {
22+ // Required for NeoGradle
33+ id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7"
864}
+3
buildSrc/build.gradle
···11+plugins {
22+ id 'groovy-gradle-plugin'
33+}
···11+package dev.mrsnowy.teleport_commands;
22+33+import net.fabricmc.api.ModInitializer;
44+import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
55+import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
66+import net.minecraft.server.level.ServerPlayer;
77+88+import java.util.Objects;
99+1010+public class fabricInit implements ModInitializer {
1111+1212+ @Override
1313+ public void onInitialize() {
1414+ // This code runs as soon as Minecraft is in a mod-load-ready state.
1515+ // However, some things (like resources) may still be uninitialized.
1616+ // Proceed with mild caution.
1717+1818+ TeleportCommands.LOGGER.info("Teleport Commands loaded! Hello Fabric!");
1919+2020+ // initialize the mod
2121+ ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
2222+ TeleportCommands.initializeMod(server, "Fabric");
2323+ });
2424+2525+2626+ // check if it is a player and check if the player died
2727+ ServerEntityEvents.ENTITY_UNLOAD.register((entity, world) -> {
2828+ if (entity instanceof ServerPlayer player) {
2929+ if (player.getRemovalReason() != null && (Objects.equals(player.getRemovalReason().toString(), "KILLED") || Objects.equals(player.getRemovalReason().toString(), "DISCARDED"))) {
3030+ TeleportCommands.onPlayerDeath(player);
3131+ }
3232+ }
3333+ });
3434+ }
3535+}
···11-# Done to increase the memory available to gradle.
22-org.gradle.jvmargs=-Xmx2G
33-org.gradle.parallel=true
11+# Important Notes:
22+# Every field you add must be added to the root build.gradle expandProps map.
33+44+# Project
55+version=1.0.5
66+group=dev.mrsnowy.teleport_commands
77+java_version=17
4855-# Fabric Properties
66-# check these on https://fabricmc.net/develop
99+# Common
710minecraft_version=1.20.4
88-yarn_mappings=1.20.4+build.3
99-loader_version=0.15.9
1111+mod_name=Teleport Commands
1212+mod_author=Mr. Snowy
1313+mod_id=teleport_commands
1414+license=MIT
1515+credits=Mr. Snowy
1616+description=A server-side mod that adds various teleportation related commands.
1717+minecraft_version_range=[1.20.4, 1.21)
10181111-# Mod Properties
1212-mod_version=1.0.2
1313-maven_group=dev.mrsnowy.teleport_commands
1414-archives_base_name=teleport_commands
1919+# Fabric
2020+fabric_version=0.97.0+1.20.4
2121+fabric_loader_version=0.15.10
2222+2323+# NeoForge
2424+neoforge_version=20.4.234
2525+neoforge_loader_version_range=[2,)
15261616-# Dependencies
1717-fabric_version=0.97.0+1.20.42727+# Gradle
2828+org.gradle.jvmargs=-Xmx3G
2929+org.gradle.daemon=false
+38
neoforge/build.gradle
···11+plugins {
22+ id 'multiloader-loader'
33+ id 'net.neoforged.gradle.userdev' version '7.0.107'
44+}
55+66+// Automatically enable neoforge AccessTransformers if the file exists
77+// This location is hardcoded in FML and can not be changed.
88+// https://github.com/neoforged/FancyModLoader/blob/a952595eaaddd571fbc53f43847680b00894e0c1/loader/src/main/java/net/neoforged/fml/loading/moddiscovery/ModFile.java#L118
99+def at = file('src/main/resources/META-INF/accesstransformer.cfg')
1010+if (at.exists()) {
1111+ minecraft.accessTransformers.file at
1212+}
1313+runs {
1414+ configureEach {
1515+ modSource project.sourceSets.main
1616+ }
1717+ client {
1818+ systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
1919+ }
2020+ server {
2121+ systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
2222+ programArgument '--nogui'
2323+ }
2424+2525+ gameTestServer {
2626+ systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id
2727+ }
2828+2929+ data {
3030+ programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
3131+ }
3232+}
3333+3434+sourceSets.main.resources { srcDir 'src/generated/resources' }
3535+3636+dependencies {
3737+ implementation "net.neoforged:neoforge:${neoforge_version}"
3838+}
···11+package dev.mrsnowy.teleport_commands;
22+33+import net.neoforged.bus.api.EventPriority;
44+import net.neoforged.bus.api.IEventBus;
55+import net.neoforged.bus.api.SubscribeEvent;
66+import net.neoforged.fml.common.Mod;
77+import net.neoforged.neoforge.event.entity.living.LivingDeathEvent;
88+import net.neoforged.neoforge.event.server.ServerStartingEvent;
99+import net.minecraft.server.level.ServerPlayer;
1010+1111+@Mod(TeleportCommands.MOD_ID)
1212+public class neoforgeInit {
1313+1414+ public neoforgeInit(IEventBus eventBus) {
1515+ // This method is invoked by the NeoForge mod loader when it is ready
1616+ // to load your mod. You can access NeoForge and Common code in this
1717+ // project.
1818+1919+ TeleportCommands.LOGGER.info("Teleport Commands loaded! Hello NeoForge!");
2020+ }
2121+2222+ @Mod.EventBusSubscriber(modid = TeleportCommands.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
2323+ private static class NeoForgeEventSubscriber {
2424+2525+ @SubscribeEvent(priority = EventPriority.HIGHEST)
2626+ private static void onServerStarting(ServerStartingEvent event) {
2727+ // initialize the mod
2828+ TeleportCommands.initializeMod(event.getServer(), "NeoForge");
2929+ }
3030+3131+ @SubscribeEvent(priority = EventPriority.HIGHEST)
3232+ private static void onEntityUnload(LivingDeathEvent event) {
3333+ // check if it is a player
3434+ if (event.getEntity() instanceof ServerPlayer player) {
3535+ TeleportCommands.onPlayerDeath(player);
3636+ }
3737+ }
3838+ }
3939+}
4040+
+32
neoforge/src/main/resources/META-INF/mods.toml
···11+modLoader = "javafml" #mandatory
22+loaderVersion = "${neoforge_loader_version_range}" #mandatory
33+license = "${license}" # Review your options at https://choosealicense.com/.
44+issueTrackerURL="https://github.com/MrSn0wy/TeleportCommands/issues" #optional
55+[[mods]] #mandatory
66+modId = "${mod_id}" #mandatory
77+version = "${version}" #mandatory
88+displayName = "${mod_name}" #mandatory
99+#updateJSONURL="https://change.me.example.invalid/updates.json" #optional (see https://docs.neoforged.net/docs/misc/updatechecker/)
1010+displayURL="https://github.com/MrSn0wy/TeleportCommands" #optional (displayed in the mod UI)
1111+logoFile="${mod_id}.png" #optional
1212+credits="${credits}" #optional
1313+authors = "${mod_author}" #optional
1414+description = '''${description}''' #mandatory (Supports multiline text)
1515+[[dependencies.${mod_id}]] #optional
1616+modId = "neoforge" #mandatory
1717+type="required" #mandatory (Can be one of "required", "optional", "incompatible" or "discouraged")
1818+versionRange = "${neoforge_loader_version_range}" #mandatory
1919+ordering = "NONE" # The order that this dependency should load in relation to your mod, required to be either 'BEFORE' or 'AFTER' if the dependency is not mandatory
2020+side = "BOTH" # Side this dependency is applied on - 'BOTH', 'CLIENT' or 'SERVER'
2121+[[dependencies.${mod_id}]]
2222+modId = "minecraft"
2323+type="required" #mandatory (Can be one of "required", "optional", "incompatible" or "discouraged")
2424+versionRange = "${minecraft_version_range}"
2525+ordering = "NONE"
2626+side = "BOTH"
2727+2828+# Features are specific properties of the game environment, that you may want to declare you require. This example declares
2929+# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't
3030+# stop your mod loading on the server for example.
3131+#[features.${mod_id}]
3232+#openGLVersion="[3.2,)"
···11+modLoader = "javafml" #mandatory
22+loaderVersion = "${neoforge_loader_version_range}" #mandatory
33+license = "${license}" # Review your options at https://choosealicense.com/.
44+#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
55+[[mods]] #mandatory
66+modId = "${mod_id}" #mandatory
77+version = "${version}" #mandatory
88+displayName = "${mod_name}" #mandatory
99+#updateJSONURL="https://change.me.example.invalid/updates.json" #optional (see https://docs.neoforged.net/docs/misc/updatechecker/)
1010+#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional (displayed in the mod UI)
1111+logoFile="${mod_id}.png" #optional
1212+credits="${credits}" #optional
1313+authors = "${mod_author}" #optional
1414+description = '''${description}''' #mandatory (Supports multiline text)
1515+[[dependencies.${mod_id}]] #optional
1616+modId = "neoforge" #mandatory
1717+type="required" #mandatory (Can be one of "required", "optional", "incompatible" or "discouraged")
1818+versionRange = "${neoforge_loader_version_range}" #mandatory
1919+ordering = "NONE" # The order that this dependency should load in relation to your mod, required to be either 'BEFORE' or 'AFTER' if the dependency is not mandatory
2020+side = "BOTH" # Side this dependency is applied on - 'BOTH', 'CLIENT' or 'SERVER'
2121+[[dependencies.${mod_id}]]
2222+modId = "minecraft"
2323+type="required" #mandatory (Can be one of "required", "optional", "incompatible" or "discouraged")
2424+versionRange = "${minecraft_version_range}"
2525+ordering = "NONE"
2626+side = "BOTH"
2727+2828+# Features are specific properties of the game environment, that you may want to declare you require. This example declares
2929+# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't
3030+# stop your mod loading on the server for example.
3131+#[features.${mod_id}]
3232+#openGLVersion="[3.2,)"
+52-10
settings.gradle
···11-pluginManagement {
22- repositories {
33- maven {
44- name = 'Fabric'
55- url = 'https://maven.fabricmc.net/'
66- }
77- mavenCentral()
88- gradlePluginPortal()
99- }
1010-}11+pluginManagement {
22+ repositories {
33+ gradlePluginPortal()
44+ mavenCentral()
55+ exclusiveContent {
66+ forRepository {
77+ maven {
88+ name = 'Fabric'
99+ url = uri("https://maven.fabricmc.net")
1010+ }
1111+ }
1212+ filter {
1313+ includeGroup("net.fabricmc")
1414+ includeGroup("fabric-loom")
1515+ }
1616+ }
1717+ exclusiveContent {
1818+ forRepository {
1919+ maven {
2020+ name = 'NeoForge'
2121+ url = uri("https://maven.neoforged.net/releases")
2222+ }
2323+ }
2424+ filter {
2525+ includeGroupAndSubgroups("net.neoforged")
2626+ includeGroup("codechicken")
2727+ }
2828+ }
2929+ exclusiveContent {
3030+ forRepository {
3131+ maven {
3232+ name = 'Sponge Snapshots'
3333+ url = uri("https://repo.spongepowered.org/repository/maven-public")
3434+ }
3535+ }
3636+ filter {
3737+ includeGroupAndSubgroups("org.spongepowered")
3838+ includeGroup("net.minecraftforge")
3939+ }
4040+ }
4141+ }
4242+}
4343+4444+plugins {
4545+ id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
4646+}
4747+4848+// This should match the folder name of the project, or else IDEA may complain (see https://youtrack.jetbrains.com/issue/IDEA-317606)
4949+rootProject.name = 'MultiLoader-Template'
5050+include("common")
5151+include("fabric")
5252+include("neoforge")
···11-package dev.mrsnowy.teleport_commands;
22-33-import dev.mrsnowy.teleport_commands.storage.StorageManager;
44-import dev.mrsnowy.teleport_commands.utils.commands;
55-import net.fabricmc.api.ModInitializer;
66-77-import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
88-import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
99-import net.fabricmc.loader.api.FabricLoader;
1010-import net.minecraft.entity.Entity;
1111-import net.minecraft.server.MinecraftServer;
1212-import net.minecraft.server.network.ServerPlayerEntity;
1313-import net.minecraft.server.world.ServerWorld;
1414-import net.minecraft.util.WorldSavePath;
1515-import net.minecraft.world.World;
1616-import org.slf4j.Logger;
1717-import org.slf4j.LoggerFactory;
1818-1919-import java.nio.file.Path;
2020-import java.util.Objects;
2121-2222-import static dev.mrsnowy.teleport_commands.utils.tools.DeathLocationUpdater;
2323-2424-public class TeleportCommands implements ModInitializer {
2525- // This logger is used to write text to the console and the log file.
2626- // It is considered best practice to use your mod id as the logger's name.
2727- // That way, it's clear which mod wrote info, warnings, and errors.
2828- public static final String MOD_ID = "teleport_commands";
2929- public static final Logger LOGGER = LoggerFactory.getLogger("teleport_commands");
3030-3131- public static Path SAVE_DIR;
3232- public static Path CONFIG_DIR;
3333- public static StorageManager Storage;
3434- public static MinecraftServer Server;
3535-3636- @Override
3737- public void onInitialize() {
3838- // This code runs as soon as Minecraft is in a mod-load-ready state.
3939- // However, some things (like resources) may still be uninitialized.
4040- // Proceed with mild caution.
4141- ServerWorldEvents.LOAD.register(this::onWorldLoad);
4242-4343- ServerEntityEvents.ENTITY_UNLOAD.register(this::onPlayerUnload);
4444-4545- // todo: /back /tpa /tpahere /home /homes /sethome /delhome /renamehome /defaulthome /spawn /worldspawn
4646- commands.registerCommands();
4747- }
4848-4949-5050-5151- private void onPlayerUnload(Entity entity, ServerWorld world) {
5252- if (entity instanceof ServerPlayerEntity player) {
5353-// LOGGER.info(String.valueOf(entity.getRemovalReason()));
5454- if (player.getRemovalReason() != null && (Objects.equals(player.getRemovalReason().toString(), "KILLED") || Objects.equals(player.getRemovalReason().toString(), "DISCARDED"))) {
5555- try {
5656- // /back command position
5757- LOGGER.info(player.getPos().toString());
5858- DeathLocationUpdater(player.getPos(), player.getServerWorld(), player.getUuidAsString());
5959- } catch (Exception e) {
6060- throw new RuntimeException(e);
6161- }
6262- }
6363- }
6464- }
6565-6666- private void onWorldLoad(MinecraftServer minecraftServer, ServerWorld serverWorld) {
6767- // make it run only once
6868- if (serverWorld.getRegistryKey() == World.OVERWORLD) {
6969- // initialize da variables
7070- SAVE_DIR = Path.of(String.valueOf(minecraftServer.getSavePath(WorldSavePath.ROOT)));
7171- CONFIG_DIR = FabricLoader.getInstance().getConfigDir();
7272-7373- Server = minecraftServer;
7474- StorageManager.StorageInit();
7575- }
7676- }
7777-}