Skip to content

Commit

Permalink
[1.21-1.21.1] v1.2.1
Browse files Browse the repository at this point in the history
Check the CHANGELOG.md for all the new changes!
  • Loading branch information
MrSn0wy authored Dec 12, 2024
1 parent e013482 commit fd19ec6
Show file tree
Hide file tree
Showing 24 changed files with 1,039 additions and 249 deletions.
24 changes: 20 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### [v1.1.2]
- Added Italian Translations (Thanks to [Vlad Andrei Morariu](https://github.com/VladAndreiMorariu)
### [v1.2.1]
- Added support for 1.21.4
- Added Traditional Chinese translations (Thanks to [hugoalh](https://github.com/hugoalh)!)

### [v1.2.0]
- Added the following warp related commands: `/warp` `/setwarp` `/delwarp` `/renamewarp` and `/warps`
- Added `/worldspawn`
- Improved error handling and error messages a lot, this will make bug reporting (and fixing) a lot easier since it says on what command it fails, and it also gives a stack trace.
- Fixed some small things which may cause errors.
- Improved code of some commands to make them more sane and readable.
- Modified storage code to make it more sane.
- Fixed bug with /home when in a diff dimension. (apparently I did this for /back already but forgot to add it to /home)
- Added Russian Translations (Thanks to [rfin0](https://github.com/rfin0)!)

### [v1.1.3]
- Added support for 1.21.2 - 1.21.3

### [v1.1.2]
- Added Italian Translations (Thanks to [Vlad Andrei Morariu](https://github.com/VladAndreiMorariu)!)

### [v1.1.1]
- Added support for 1.21
Expand All @@ -23,7 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a CHANGELOG.md
- Added Tpa Accept/Deny Suggestions
- Added Dutch translations
- Added Hungarian translations (Thanks to [Martin Morningstar](https://github.com/RMI637))
- Added Hungarian translations (Thanks to [Martin Morningstar](https://github.com/RMI637)!)

#### Changed
- Limited the requests a player can do to the same player to 1
Expand Down Expand Up @@ -54,7 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### Changed
- Changed mappings to Mojang.
- Cleaned up commands code
- Changed build files to support multiple mod loader
- Changed build files to support multiple mod loaders


### [v1.0.2]
Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@ Here is the [Changelog](https://github.com/MrSn0wy/TeleportCommands/blob/main/CH

#### Currently available commands:

- `/worldspawn [<Disable Safety>]` - Teleports you to the world spawn (in the overworld), if given true it will not do safety checks
- `/back [<Disable Safety>]` - Teleports you to the location where you last died, if given true it will not do safety checks
<br>

<br><br>
**Homes are player specific locations that only that player can teleport to**
- `/sethome <name>` - Creates a new home
- `/home [<name>]` - Teleports you home, if no name is giving it will go to the default home
- `/home [<name>]` - Teleports you to the home, if no name is giving it will go to the default home
- `/delhome <name>` - Deletes a home
- `/renamehome <name> <newName>` - Renames a home
- `/homes` - Shows a list of your homes
- `/defaulthome <name>` - Sets the default home
<br>

<br><br>
**Warps are op managed locations that all players can teleport to**
- `/warp <name>` - Teleports you to the warp
- `/warps` - Shows a list of the available warp
- `/setwarp <name>` - Sets a warp. Permission level of 4 required (op)
- `/delwarp <name>` - Deletes a warp. Permission level of 4 required (op)
- `/renamewarp <name> <newName>` - Renames a warp. Permission level of 4 required (op)
<br><br>
**With tpa you can teleport to other players or make them teleport to you**
- `/tpa <player>` - Sends a tpa request to another player
- `/tpahere <player>` - Sends a tpaHere request to another player
- `/tpaaccept <player>` - Accepts the tpa/ tpahere request of that player
- `/tpaaccept <player>` - Accepts the tpa/tpahere request of that player
- `/tpadeny <player>` - Denies the tpa/tpaHere request of that player

<br>
Expand All @@ -28,10 +36,13 @@ Here is the [Changelog](https://github.com/MrSn0wy/TeleportCommands/blob/main/CH

#### Planned commands:
- [ ] `/wild` - Teleports you to a random location in the Overworld
- [ ] `/worldspawn` - Teleports you to the worldspawn
- [x] `/worldspawn` - Teleports you to the worldspawn
- [ ] `/spawn <dimension>` - Teleports you to your spawnpoint in a dimension, defaults to your current dimension

#### Improvements:
- [ ] Look into changing the mod into the more safe and sane kotlin (I love java)
- [ ] Find a way to combine the mod loader specific jars into one
- [ ] Find the easiest way to backport the mod to older version (help)
- [ ] Create a config to add any delays and disable commands, with commands for operators in game
- [ ] Add a perm system
- [x] Json Storage automatic updater & cleaner
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/groovy/multiloader-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ processResources {
"fabric_loom": fabric_loom,
"neoforge_version": neoforge_version,
"neoforge_loader_version_range": neoforge_loader_version_range,
"NeoGradle": NeoGradle,
// "quilt_loader_version": quilt_loader_version,
// "quilt_fabric_api": quilt_fabric_api,
// "quilt_loom": quilt_loom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TeleportCommands {
public static String MOD_LOADER;
public static Path SAVE_DIR;
public static Path CONFIG_DIR;
public static MinecraftServer SERVER;


// Gets ran when the server starts
Expand All @@ -39,13 +40,17 @@ public static void initializeMod(MinecraftServer server) {
// Construct the game directory path
CONFIG_DIR = Paths.get(System.getProperty("user.dir")).resolve("config");

SERVER = server;

cleanStorage();

// initialize commands, also allows me to easily disable any when there is a config
Commands commandManager = server.getCommands();
back.register(commandManager);
home.register(commandManager);
tpa.register(commandManager);
warp.register(commandManager);
worldspawn.register(commandManager);
}

public static void onPlayerDeath(ServerPlayer player) {
Expand All @@ -68,15 +73,50 @@ private static void cleanStorage() {
FileReader reader = new FileReader(StorageManager.STORAGE_FILE.toString());
JsonElement jsonElement = JsonParser.parseReader(reader);


if (jsonElement.isJsonObject()) {
JsonObject mainJsonObject = jsonElement.getAsJsonObject();
JsonArray newWarpsArray = new JsonArray();
JsonArray newPlayersArray = new JsonArray();

// get the Warps list
if (mainJsonObject.has("Warps") && mainJsonObject.get("Warps").isJsonArray()) {

// Warps
for (JsonElement warpElement : mainJsonObject.get("Warps").getAsJsonArray()) {

// Warp
if (warpElement.isJsonObject()) {
JsonObject warp = warpElement.getAsJsonObject();


String warpName = warp.has("name") ? warp.get("name").getAsString() : "";
Integer warpX = warp.has("x") ? warp.get("x").getAsInt() : null;
Integer warpY = warp.has("y") ? warp.get("y").getAsInt() : null;
Integer warpZ = warp.has("z") ? warp.get("z").getAsInt() : null;
String warpWorld = warp.has("world") ? warp.get("world").getAsString() : "";

// check if it is valid
if (!warpName.isBlank() && !warpWorld.isBlank() && warpX != null && warpY != null && warpZ != null) {
JsonObject newWarp = new JsonObject();

newWarp.addProperty("name", warpName);
newWarp.addProperty("x", warpX);
newWarp.addProperty("y", warpY);
newWarp.addProperty("z", warpZ);
newWarp.addProperty("world", warpWorld);

newWarpsArray.add(newWarp);
}
}
}


}


// get the Players list
if (mainJsonObject.has("Players") && mainJsonObject.get("Players").isJsonArray()) {

JsonArray newPlayersArray = new JsonArray();

// players
for (JsonElement playerElement : mainJsonObject.get("Players").getAsJsonArray()) {

Expand Down Expand Up @@ -171,23 +211,26 @@ private static void cleanStorage() {
}
}
}
}

// save the cleaned and updated file
mainJsonObject.remove("Players");
mainJsonObject.add("Players", newPlayersArray);
// save the cleaned and updated file
mainJsonObject.remove("Warps");
mainJsonObject.add("Warps", newWarpsArray);

Gson gson = new GsonBuilder().create();
byte[] json = gson.toJson(mainJsonObject).getBytes();
Files.write(StorageManager.STORAGE_FILE, json, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
mainJsonObject.remove("Players");
mainJsonObject.add("Players", newPlayersArray);

long endFileSize = Files.size(StorageManager.STORAGE_FILE);
// save the cleaned database
Gson gson = new GsonBuilder().create();
byte[] json = gson.toJson(mainJsonObject).getBytes();
Files.write(StorageManager.STORAGE_FILE, json, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);

LOGGER.info("Success! Cleaned: " + Math.round((startFileSize - endFileSize)) + "B");
}
}
long endFileSize = Files.size(StorageManager.STORAGE_FILE);

LOGGER.info("Success! Cleaned: {}B", Math.round((startFileSize - endFileSize)));
}
} catch (IOException e) {
LOGGER.error(e.toString());
LOGGER.error("Error while cleaning the database!", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,53 @@ public class back {

public static void register(Commands commandManager) {

commandManager.getDispatcher().register(Commands.literal("back").executes(context -> {
final ServerPlayer player = context.getSource().getPlayerOrException();

try {
ToDeathLocation(player, false);

} catch (Exception e) {
TeleportCommands.LOGGER.error(String.valueOf(e));
player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true);
return 1;
}
return 0;
})
.then(argument("Disable Safety", BoolArgumentType.bool()).executes(context -> {
final boolean safety = BoolArgumentType.getBool(context, "Disable Safety");
commandManager.getDispatcher().register(Commands.literal("back")
.requires(source -> source.getPlayer() != null)
.executes(context -> {
final ServerPlayer player = context.getSource().getPlayerOrException();

try {
ToDeathLocation(player, safety);
ToDeathLocation(player, false);

} catch (Exception e) {
TeleportCommands.LOGGER.error(String.valueOf(e));
TeleportCommands.LOGGER.error("Error while going back! => ", e);
player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true);
return 1;
}
return 0;
}))
})
.then(argument("Disable Safety", BoolArgumentType.bool())
.requires(source -> source.getPlayer() != null)
.executes(context -> {
final boolean safety = BoolArgumentType.getBool(context, "Disable Safety");
final ServerPlayer player = context.getSource().getPlayerOrException();

try {
ToDeathLocation(player, safety);

} catch (Exception e) {
TeleportCommands.LOGGER.error("Error while going back! => ", e);
player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.error", player).withStyle(ChatFormatting.RED, ChatFormatting.BOLD), true);
return 1;
}
return 0;
}))
);
}


private static void ToDeathLocation(ServerPlayer player, boolean safetyDisabled) throws Exception {
StorageManager.StorageClass.Player playerStorage = GetPlayerStorage(player.getStringUUID()).playerStorage;
StorageManager.StorageClass.Player playerStorage = GetPlayerStorage(player.getStringUUID()).getSecond();

// todo : fix
// todo : fix... what do i need to fix LMAO

if (playerStorage.deathLocation == null) {
player.displayClientMessage(getTranslatedText("commands.teleport_commands.back.noLocation", player).withStyle(ChatFormatting.RED), true);
} else {
final BlockPos pos = new BlockPos(playerStorage.deathLocation.x, playerStorage.deathLocation.y, playerStorage.deathLocation.z);

boolean found = false;
for (ServerLevel currentWorld : Objects.requireNonNull(player.getServer()).getAllLevels()) {
for (ServerLevel currentWorld : TeleportCommands.SERVER.getAllLevels()) {

if (Objects.equals(currentWorld.dimension().location().toString(), playerStorage.deathLocation.world)) {

Expand All @@ -75,7 +79,7 @@ private static void ToDeathLocation(ServerPlayer player, boolean safetyDisabled)
Pair<Integer, Optional<Vec3>> teleportData = teleportSafetyChecker(pos.getX(), pos.getY(), pos.getZ(), currentWorld, player);

switch (teleportData.getFirst()) {
case 0: // safe!
case 0: // safe location found!
if (teleportData.getSecond().isPresent()) {
player.displayClientMessage(getTranslatedText("commands.teleport_commands.back.go", player), true);
Teleporter(player, currentWorld, teleportData.getSecond().get());
Expand Down Expand Up @@ -115,7 +119,7 @@ private static void ToDeathLocation(ServerPlayer player, boolean safetyDisabled)
}

if (!found) {
player.displayClientMessage(getTranslatedText("commands.teleport_commands.back.noLocation", player).withStyle(ChatFormatting.RED), true);
player.displayClientMessage(getTranslatedText("commands.teleport_commands.common.noLocation", player).withStyle(ChatFormatting.RED), true);
}
}
}
Expand Down
Loading

0 comments on commit fd19ec6

Please sign in to comment.