From fdb0795b8333064b4553d03eee257ba4c6a10296 Mon Sep 17 00:00:00 2001 From: kivattt Date: Fri, 13 Oct 2023 13:33:33 +0200 Subject: [PATCH] Version 1.0.0 --- README.md | 12 ++++-- TODO.md | 7 +--- build.gradle | 4 +- .../com/kiva/kivaserverutils/Coordinate.java | 20 +++++++++- .../kiva/kivaserverutils/KivaServerUtils.java | 2 +- .../FileWriteAndLoadCoordinate.java | 35 +++++++++++------ .../FileWriteAndLoadStringBooleanHashmap.java | 2 +- .../KivaServerUtilsServer.java | 2 + .../commands/ExplosionsBreakChests.java | 1 - .../kiva/kivaserverutils/commands/Home.java | 8 +++- .../commands/HomeCommandsDisabled.java | 0 .../kivaserverutils/commands/HomeWhere.java | 39 +++++++++++++++++++ .../commands/KivaShowConfig.java | 0 .../kivaserverutils/commands/KivaVersion.java | 0 .../commands/MobcapDisabled.java | 0 .../kiva/kivaserverutils/commands/Nick.java | 0 .../kivaserverutils/commands/NickList.java | 0 .../kivaserverutils/commands/NickReset.java | 0 .../kivaserverutils/commands/NickSet.java | 0 .../kivaserverutils/commands/Pronouns.java | 0 .../commands/PronounsList.java | 0 .../commands/PronounsReset.java | 0 .../kivaserverutils/commands/PronounsSet.java | 0 .../kivaserverutils/commands/SetHome.java | 4 +- .../kiva/kivaserverutils/commands/Spawn.java | 10 +++++ .../kivaserverutils/commands/SpawnReset.java | 2 - .../kivaserverutils/commands/SpawnSet.java | 23 ++++------- .../kivaserverutils/commands/SpawnWhere.java | 28 +++++++++++++ .../kivaserverutils/commands/Teleport.java | 0 .../server/mixins/MixinSpawnerAnimals.java | 4 +- 30 files changed, 155 insertions(+), 48 deletions(-) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/ExplosionsBreakChests.java (96%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/Home.java (79%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/HomeCommandsDisabled.java (100%) create mode 100644 src/server/java/com/kiva/kivaserverutils/commands/HomeWhere.java rename src/{main => server}/java/com/kiva/kivaserverutils/commands/KivaShowConfig.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/KivaVersion.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/MobcapDisabled.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/Nick.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/NickList.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/NickReset.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/NickSet.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/Pronouns.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/PronounsList.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/PronounsReset.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/PronounsSet.java (100%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/SetHome.java (79%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/Spawn.java (66%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/SpawnReset.java (85%) rename src/{main => server}/java/com/kiva/kivaserverutils/commands/SpawnSet.java (50%) create mode 100644 src/server/java/com/kiva/kivaserverutils/commands/SpawnWhere.java rename src/{main => server}/java/com/kiva/kivaserverutils/commands/Teleport.java (100%) diff --git a/README.md b/README.md index 063a0c4..0202f66 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,18 @@ Improved logging for players throwing dynamite `/home`\ Teleport to home (If home exists) +`/homewhere`\ +Show home location without teleporting to it + `/sethome`\ Sets your home location `/spawn`\ Teleport to spawn (If spawn location specified) +`/spawnwhere`\ +Show spawn location without teleporting to it + `/spawnset` (OP-only command)\ Set the location `/spawn` sends the player @@ -43,6 +49,9 @@ When player supplied, an OP can force reset a players nickname `/pronouns `\ Give yourself pronouns in chat +`/pronounslist`\ +See everyone's pronouns + `/pronounsset ` (OP-only command)\ Force set a players pronouns @@ -68,9 +77,6 @@ Shows config for KivaServerUtils `/kivaversion`\ Displays mod version -# Known issues/bugs -`/home` and `/sethome` don't check the players dimension, teleporting to the coordinate no matter the dimension - # Info for mod developers `Container.updateInventory` is overwritten by this mod,\ keep this in mind if you are writing mixins for this method diff --git a/TODO.md b/TODO.md index 71e5ebc..e54185d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,9 @@ - Better system for configuration, less confusing commands (something like /gamerule \ \) -- In `/spawn`, `/teleport` command check if the target chunk is loaded by the player +- In `/spawn`, `/teleport`, `/home` commands check if the target chunk is loaded by the player and if not, warn them to try relogging if they're stuck in air - + - Improve the 100% CPU fix to not sleep on server close (saving chunks?) -# Chest/crate logging -Username in the logging - More descriptive logging? - Itemstack amount changed - Itemstack added diff --git a/build.gradle b/build.gradle index 3200856..8eac6a2 100644 --- a/build.gradle +++ b/build.gradle @@ -4,13 +4,13 @@ buildscript { maven { url 'https://jitpack.io/' } } dependencies { - classpath('com.github.Fox2Code.FoxLoader:dev:1.2.18') + classpath('com.github.Fox2Code.FoxLoader:dev:1.2.19') } } apply plugin: 'foxloader.dev' -version '0.8.0' +version '1.0.0' foxloader { // forceReload = true diff --git a/src/main/java/com/kiva/kivaserverutils/Coordinate.java b/src/main/java/com/kiva/kivaserverutils/Coordinate.java index b51ae47..47208af 100644 --- a/src/main/java/com/kiva/kivaserverutils/Coordinate.java +++ b/src/main/java/com/kiva/kivaserverutils/Coordinate.java @@ -2,6 +2,17 @@ public class Coordinate { public double x, y, z; + public Integer dimension; + public static String dimensionToString(final Integer dimension){ + switch(dimension){ + case -1: + return "nether"; + case 0: + return "overworld"; + default: + return "unknown dimension"; + } + } public Coordinate(){} @@ -11,9 +22,11 @@ public Coordinate(String str){ @Override public String toString() { - return x + " " + y + " " + z; + return x + " " + y + " " + z + " " + dimension; } + public String toStringXYZInt(){return (int)x + " " + (int)y + " " + (int)z;} + // TODO Use temporary values? public void fromString(final String str){ String[] values = str.split(" "); @@ -21,6 +34,11 @@ public void fromString(final String str){ x = Double.parseDouble(values[0]); y = Double.parseDouble(values[1]); z = Double.parseDouble(values[2]); + + if (values.length >= 4) + dimension = Integer.parseInt(values[3]); + else + dimension = 0; // Let's assume overworld for old playerhomes.txt format } catch(NumberFormatException e){ e.printStackTrace(); } diff --git a/src/main/java/com/kiva/kivaserverutils/KivaServerUtils.java b/src/main/java/com/kiva/kivaserverutils/KivaServerUtils.java index 5feff1e..f71fbbd 100644 --- a/src/main/java/com/kiva/kivaserverutils/KivaServerUtils.java +++ b/src/main/java/com/kiva/kivaserverutils/KivaServerUtils.java @@ -9,7 +9,7 @@ public class KivaServerUtils extends Mod { public static HashMap playerPronouns = new HashMap<>(); public static HashMap playerHomes = new HashMap<>(); public static Coordinate spawnCommandLocation = null; - public static String version = "0.8.0"; + public static String version = "1.0.0"; public static HashMap config = new HashMap<>(); public static String handleWindowClickLatestPlayerUsername; diff --git a/src/server/java/com/kiva/kivaserverutils/FileWriteAndLoadCoordinate.java b/src/server/java/com/kiva/kivaserverutils/FileWriteAndLoadCoordinate.java index 392a5bf..7450fc1 100644 --- a/src/server/java/com/kiva/kivaserverutils/FileWriteAndLoadCoordinate.java +++ b/src/server/java/com/kiva/kivaserverutils/FileWriteAndLoadCoordinate.java @@ -1,16 +1,31 @@ package com.kiva.kivaserverutils; -import java.io.*; -import java.util.Scanner; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; public class FileWriteAndLoadCoordinate { public static void writeCoordinateToFile(final Coordinate coordinate, final String filename){ - if (coordinate == null) + if (coordinate == null) { + File f = new File(filename); + if (!f.exists()) + return; + + System.out.println("No spawn set, attempting to delete " + filename); + + if (f.delete()) + System.out.println("Deleted " + filename + " successfully"); + else + System.err.println("Failed to delete " + filename); + return; + } try { FileWriter fileWriter = new FileWriter(filename); - fileWriter.write(coordinate.x + " " + coordinate.y + " " + coordinate.z); + fileWriter.write(coordinate.toString()); fileWriter.close(); } catch(IOException e){ System.err.println("Failed to write coordinate to file: " + filename); @@ -22,14 +37,10 @@ public static Coordinate loadCoordinateFromFile(final String filename){ Coordinate ret = new Coordinate(); try { - File file = new File(filename); - Scanner scanner = new Scanner(file); - ret.x = scanner.nextDouble(); - ret.y = scanner.nextDouble(); - ret.z = scanner.nextDouble(); - scanner.close(); - } catch(FileNotFoundException e){ - System.err.println("Failed to load coordinate from file: " + filename); + ret.fromString(Files.readAllLines(Paths.get(filename)).get(0)); + } catch(IOException | IndexOutOfBoundsException e) { + // Removed since this is expected when no spawn is set, to avoid confusion + //System.err.println("Failed to load coordinate from file: " + filename); return null; } diff --git a/src/server/java/com/kiva/kivaserverutils/FileWriteAndLoadStringBooleanHashmap.java b/src/server/java/com/kiva/kivaserverutils/FileWriteAndLoadStringBooleanHashmap.java index c36aca9..a685f32 100644 --- a/src/server/java/com/kiva/kivaserverutils/FileWriteAndLoadStringBooleanHashmap.java +++ b/src/server/java/com/kiva/kivaserverutils/FileWriteAndLoadStringBooleanHashmap.java @@ -32,7 +32,7 @@ public static HashMap loadStringBooleanHashmapFromFile(final St String line = reader.readLine(); while (line != null){ - if (line.startsWith("#")) { + if (line.startsWith("#") || line.isEmpty()) { line = reader.readLine(); continue; } diff --git a/src/server/java/com/kiva/kivaserverutils/KivaServerUtilsServer.java b/src/server/java/com/kiva/kivaserverutils/KivaServerUtilsServer.java index 3098edc..4b3acf1 100644 --- a/src/server/java/com/kiva/kivaserverutils/KivaServerUtilsServer.java +++ b/src/server/java/com/kiva/kivaserverutils/KivaServerUtilsServer.java @@ -34,9 +34,11 @@ public void onInit(){ CommandCompat.registerCommand(new PronounsReset()); CommandCompat.registerCommand(new Teleport()); CommandCompat.registerCommand(new Spawn()); + CommandCompat.registerCommand(new SpawnWhere()); CommandCompat.registerCommand(new SpawnSet()); CommandCompat.registerCommand(new SpawnReset()); CommandCompat.registerCommand(new Home()); + CommandCompat.registerCommand(new HomeWhere()); CommandCompat.registerCommand(new SetHome()); System.out.println("KivaServerUtils initialized"); diff --git a/src/main/java/com/kiva/kivaserverutils/commands/ExplosionsBreakChests.java b/src/server/java/com/kiva/kivaserverutils/commands/ExplosionsBreakChests.java similarity index 96% rename from src/main/java/com/kiva/kivaserverutils/commands/ExplosionsBreakChests.java rename to src/server/java/com/kiva/kivaserverutils/commands/ExplosionsBreakChests.java index 84a16b7..cd00c85 100644 --- a/src/main/java/com/kiva/kivaserverutils/commands/ExplosionsBreakChests.java +++ b/src/server/java/com/kiva/kivaserverutils/commands/ExplosionsBreakChests.java @@ -4,7 +4,6 @@ import com.fox2code.foxloader.network.NetworkPlayer; import com.fox2code.foxloader.registry.CommandCompat; import com.kiva.kivaserverutils.KivaServerUtils; -import com.kiva.kivaserverutils.UsageMessage; import static com.kiva.kivaserverutils.UsageMessage.sendUsageMessage; diff --git a/src/main/java/com/kiva/kivaserverutils/commands/Home.java b/src/server/java/com/kiva/kivaserverutils/commands/Home.java similarity index 79% rename from src/main/java/com/kiva/kivaserverutils/commands/Home.java rename to src/server/java/com/kiva/kivaserverutils/commands/Home.java index c73b2e3..3162f4a 100644 --- a/src/main/java/com/kiva/kivaserverutils/commands/Home.java +++ b/src/server/java/com/kiva/kivaserverutils/commands/Home.java @@ -1,13 +1,12 @@ package com.kiva.kivaserverutils.commands; +import com.fox2code.foxloader.loader.ServerMod; import com.fox2code.foxloader.network.ChatColors; import com.fox2code.foxloader.network.NetworkPlayer; import com.fox2code.foxloader.registry.CommandCompat; import com.kiva.kivaserverutils.Coordinate; import com.kiva.kivaserverutils.KivaServerUtils; -import static com.kiva.kivaserverutils.KivaServerUtils.spawnCommandLocation; - public class Home extends CommandCompat{ public Home(){ super("home", false); @@ -35,6 +34,11 @@ public void onExecute(final String[] args, final NetworkPlayer commandExecutor) return; } + if (homeCoordinate.dimension != ServerMod.toEntityPlayerMP(commandExecutor).dimension){ + commandExecutor.displayChatMessage(ChatColors.YELLOW + "Your home is in the " + Coordinate.dimensionToString(homeCoordinate.dimension) + ", unable to teleport you"); + return; + } + commandExecutor.teleportRegistered(homeCoordinate.x, homeCoordinate.y, homeCoordinate.z); commandExecutor.displayChatMessage(ChatColors.GREEN + "Teleported to home!"); } diff --git a/src/main/java/com/kiva/kivaserverutils/commands/HomeCommandsDisabled.java b/src/server/java/com/kiva/kivaserverutils/commands/HomeCommandsDisabled.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/HomeCommandsDisabled.java rename to src/server/java/com/kiva/kivaserverutils/commands/HomeCommandsDisabled.java diff --git a/src/server/java/com/kiva/kivaserverutils/commands/HomeWhere.java b/src/server/java/com/kiva/kivaserverutils/commands/HomeWhere.java new file mode 100644 index 0000000..bc045ff --- /dev/null +++ b/src/server/java/com/kiva/kivaserverutils/commands/HomeWhere.java @@ -0,0 +1,39 @@ +package com.kiva.kivaserverutils.commands; + +import com.fox2code.foxloader.loader.ServerMod; +import com.fox2code.foxloader.network.ChatColors; +import com.fox2code.foxloader.network.NetworkPlayer; +import com.fox2code.foxloader.registry.CommandCompat; +import com.kiva.kivaserverutils.Coordinate; +import com.kiva.kivaserverutils.KivaServerUtils; + +public class HomeWhere extends CommandCompat{ + public HomeWhere(){ + super("homewhere", false); + } + + public String commandSyntax(){ + return "§e/homewhere"; + } + + // TODO Make DRY + public void onExecute(final String[] args, final NetworkPlayer commandExecutor) { + if (KivaServerUtils.getConfigValue("homecommandsdisabled")){ + commandExecutor.displayChatMessage(ChatColors.RED + "Home commands are disabled"); + return; + } + + if (KivaServerUtils.playerHomes == null){ + commandExecutor.displayChatMessage(ChatColors.RED + "You have no home, use /sethome"); + return; + } + + Coordinate homeCoordinate = KivaServerUtils.playerHomes.get(commandExecutor.getPlayerName()); + if (homeCoordinate == null){ + commandExecutor.displayChatMessage(ChatColors.RED + "You have no home, use /sethome"); + return; + } + + commandExecutor.displayChatMessage(ChatColors.GREEN + "Your home is at [" + ChatColors.RESET + homeCoordinate.toStringXYZInt() + ChatColors.GREEN + "] in the " + ChatColors.RESET + Coordinate.dimensionToString(homeCoordinate.dimension)); + } +} diff --git a/src/main/java/com/kiva/kivaserverutils/commands/KivaShowConfig.java b/src/server/java/com/kiva/kivaserverutils/commands/KivaShowConfig.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/KivaShowConfig.java rename to src/server/java/com/kiva/kivaserverutils/commands/KivaShowConfig.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/KivaVersion.java b/src/server/java/com/kiva/kivaserverutils/commands/KivaVersion.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/KivaVersion.java rename to src/server/java/com/kiva/kivaserverutils/commands/KivaVersion.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/MobcapDisabled.java b/src/server/java/com/kiva/kivaserverutils/commands/MobcapDisabled.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/MobcapDisabled.java rename to src/server/java/com/kiva/kivaserverutils/commands/MobcapDisabled.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/Nick.java b/src/server/java/com/kiva/kivaserverutils/commands/Nick.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/Nick.java rename to src/server/java/com/kiva/kivaserverutils/commands/Nick.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/NickList.java b/src/server/java/com/kiva/kivaserverutils/commands/NickList.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/NickList.java rename to src/server/java/com/kiva/kivaserverutils/commands/NickList.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/NickReset.java b/src/server/java/com/kiva/kivaserverutils/commands/NickReset.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/NickReset.java rename to src/server/java/com/kiva/kivaserverutils/commands/NickReset.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/NickSet.java b/src/server/java/com/kiva/kivaserverutils/commands/NickSet.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/NickSet.java rename to src/server/java/com/kiva/kivaserverutils/commands/NickSet.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/Pronouns.java b/src/server/java/com/kiva/kivaserverutils/commands/Pronouns.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/Pronouns.java rename to src/server/java/com/kiva/kivaserverutils/commands/Pronouns.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/PronounsList.java b/src/server/java/com/kiva/kivaserverutils/commands/PronounsList.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/PronounsList.java rename to src/server/java/com/kiva/kivaserverutils/commands/PronounsList.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/PronounsReset.java b/src/server/java/com/kiva/kivaserverutils/commands/PronounsReset.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/PronounsReset.java rename to src/server/java/com/kiva/kivaserverutils/commands/PronounsReset.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/PronounsSet.java b/src/server/java/com/kiva/kivaserverutils/commands/PronounsSet.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/PronounsSet.java rename to src/server/java/com/kiva/kivaserverutils/commands/PronounsSet.java diff --git a/src/main/java/com/kiva/kivaserverutils/commands/SetHome.java b/src/server/java/com/kiva/kivaserverutils/commands/SetHome.java similarity index 79% rename from src/main/java/com/kiva/kivaserverutils/commands/SetHome.java rename to src/server/java/com/kiva/kivaserverutils/commands/SetHome.java index b704cbd..4cc2272 100644 --- a/src/main/java/com/kiva/kivaserverutils/commands/SetHome.java +++ b/src/server/java/com/kiva/kivaserverutils/commands/SetHome.java @@ -1,5 +1,6 @@ package com.kiva.kivaserverutils.commands; +import com.fox2code.foxloader.loader.ServerMod; import com.fox2code.foxloader.network.ChatColors; import com.fox2code.foxloader.network.NetworkPlayer; import com.fox2code.foxloader.registry.CommandCompat; @@ -25,6 +26,7 @@ public void onExecute(final String[] args, final NetworkPlayer commandExecutor){ playersCurrentCoordinate.x = commandExecutor.getRegisteredX(); playersCurrentCoordinate.y = commandExecutor.getRegisteredY(); playersCurrentCoordinate.z = commandExecutor.getRegisteredZ(); + playersCurrentCoordinate.dimension = ServerMod.toEntityPlayerMP(commandExecutor).dimension; if (playersCurrentCoordinate.y < 1){ commandExecutor.displayChatMessage(ChatColors.RED + "You can't set a home below y=1"); @@ -32,6 +34,6 @@ public void onExecute(final String[] args, final NetworkPlayer commandExecutor){ } KivaServerUtils.playerHomes.put(commandExecutor.getPlayerName(), playersCurrentCoordinate); - commandExecutor.displayChatMessage(ChatColors.GREEN + "Home location set! [" + ChatColors.RESET + (int)playersCurrentCoordinate.x + " " + (int)playersCurrentCoordinate.y + " " + (int)playersCurrentCoordinate.z + ChatColors.GREEN + "]" + ChatColors.RESET); + commandExecutor.displayChatMessage(ChatColors.GREEN + "Home location set! [" + ChatColors.RESET + playersCurrentCoordinate.toStringXYZInt() + ChatColors.GREEN + "] in the " + ChatColors.RESET + Coordinate.dimensionToString(playersCurrentCoordinate.dimension)); } } diff --git a/src/main/java/com/kiva/kivaserverutils/commands/Spawn.java b/src/server/java/com/kiva/kivaserverutils/commands/Spawn.java similarity index 66% rename from src/main/java/com/kiva/kivaserverutils/commands/Spawn.java rename to src/server/java/com/kiva/kivaserverutils/commands/Spawn.java index 73315ee..bf18a7a 100644 --- a/src/main/java/com/kiva/kivaserverutils/commands/Spawn.java +++ b/src/server/java/com/kiva/kivaserverutils/commands/Spawn.java @@ -1,8 +1,12 @@ package com.kiva.kivaserverutils.commands; +import com.fox2code.foxloader.launcher.ServerMain; +import com.fox2code.foxloader.loader.ServerMod; import com.fox2code.foxloader.network.ChatColors; import com.fox2code.foxloader.network.NetworkPlayer; import com.fox2code.foxloader.registry.CommandCompat; +import com.kiva.kivaserverutils.Coordinate; + import static com.kiva.kivaserverutils.KivaServerUtils.spawnCommandLocation; public class Spawn extends CommandCompat{ @@ -19,6 +23,12 @@ public void onExecute(final String[] args, final NetworkPlayer commandExecutor){ commandExecutor.displayChatMessage(ChatColors.RED + "No spawn has been set"); return; } + + if (spawnCommandLocation.dimension != ServerMod.toEntityPlayerMP(commandExecutor).dimension){ + commandExecutor.displayChatMessage(ChatColors.YELLOW + "Spawn is in the " + Coordinate.dimensionToString(spawnCommandLocation.dimension) + ", unable to teleport you"); + return; + } + commandExecutor.teleportRegistered(spawnCommandLocation.x, spawnCommandLocation.y, spawnCommandLocation.z); commandExecutor.displayChatMessage(ChatColors.GREEN + "Teleported to spawn!"); } diff --git a/src/main/java/com/kiva/kivaserverutils/commands/SpawnReset.java b/src/server/java/com/kiva/kivaserverutils/commands/SpawnReset.java similarity index 85% rename from src/main/java/com/kiva/kivaserverutils/commands/SpawnReset.java rename to src/server/java/com/kiva/kivaserverutils/commands/SpawnReset.java index b89bbf0..fcf412c 100644 --- a/src/main/java/com/kiva/kivaserverutils/commands/SpawnReset.java +++ b/src/server/java/com/kiva/kivaserverutils/commands/SpawnReset.java @@ -3,10 +3,8 @@ import com.fox2code.foxloader.network.ChatColors; import com.fox2code.foxloader.network.NetworkPlayer; import com.fox2code.foxloader.registry.CommandCompat; -import com.kiva.kivaserverutils.Coordinate; import static com.kiva.kivaserverutils.KivaServerUtils.spawnCommandLocation; -import static com.kiva.kivaserverutils.UsageMessage.sendUsageMessage; public class SpawnReset extends CommandCompat{ public SpawnReset(){ diff --git a/src/main/java/com/kiva/kivaserverutils/commands/SpawnSet.java b/src/server/java/com/kiva/kivaserverutils/commands/SpawnSet.java similarity index 50% rename from src/main/java/com/kiva/kivaserverutils/commands/SpawnSet.java rename to src/server/java/com/kiva/kivaserverutils/commands/SpawnSet.java index d526452..d4f3d5b 100644 --- a/src/main/java/com/kiva/kivaserverutils/commands/SpawnSet.java +++ b/src/server/java/com/kiva/kivaserverutils/commands/SpawnSet.java @@ -1,5 +1,6 @@ package com.kiva.kivaserverutils.commands; +import com.fox2code.foxloader.loader.ServerMod; import com.fox2code.foxloader.network.ChatColors; import com.fox2code.foxloader.network.NetworkPlayer; import com.fox2code.foxloader.registry.CommandCompat; @@ -14,26 +15,18 @@ public SpawnSet(){ } public String commandSyntax(){ - return "§e/spawnset "; + return "§e/spawnset"; } public void onExecute(final String[] args, final NetworkPlayer commandExecutor){ - if (args.length != 4){ - sendUsageMessage(commandSyntax(), commandExecutor); - return; - } - Coordinate pos = new Coordinate(); - try { - pos.x = Double.parseDouble(args[1]); - pos.y = Double.parseDouble(args[2]); - pos.z = Double.parseDouble(args[3]); + pos.x = commandExecutor.getRegisteredX(); + pos.y = commandExecutor.getRegisteredY(); + pos.z = commandExecutor.getRegisteredZ(); + pos.dimension = ServerMod.toEntityPlayerMP(commandExecutor).dimension; - spawnCommandLocation = pos; - commandExecutor.displayChatMessage(ChatColors.GREEN + "Spawn location set! [" + ChatColors.RESET + pos.x + " " + pos.y + " " + pos.z + ChatColors.GREEN + "]" + ChatColors.RESET); - } catch (NumberFormatException e){ - sendUsageMessage(commandSyntax(), commandExecutor); - } + spawnCommandLocation = pos; + commandExecutor.displayChatMessage(ChatColors.GREEN + "Spawn location set! [" + ChatColors.RESET + pos.toStringXYZInt() + ChatColors.GREEN + "] in the " + ChatColors.RESET + Coordinate.dimensionToString(pos.dimension)); } } diff --git a/src/server/java/com/kiva/kivaserverutils/commands/SpawnWhere.java b/src/server/java/com/kiva/kivaserverutils/commands/SpawnWhere.java new file mode 100644 index 0000000..cc4ee6a --- /dev/null +++ b/src/server/java/com/kiva/kivaserverutils/commands/SpawnWhere.java @@ -0,0 +1,28 @@ +package com.kiva.kivaserverutils.commands; + +import com.fox2code.foxloader.loader.ServerMod; +import com.fox2code.foxloader.network.ChatColors; +import com.fox2code.foxloader.network.NetworkPlayer; +import com.fox2code.foxloader.registry.CommandCompat; +import com.kiva.kivaserverutils.Coordinate; + +import static com.kiva.kivaserverutils.KivaServerUtils.spawnCommandLocation; + +public class SpawnWhere extends CommandCompat{ + public SpawnWhere(){ + super("spawnwhere", false); + } + + public String commandSyntax(){ + return "§e/spawnwhere"; + } + + public void onExecute(final String[] args, final NetworkPlayer commandExecutor){ + if (spawnCommandLocation == null){ + commandExecutor.displayChatMessage(ChatColors.RED + "No spawn has been set"); + return; + } + + commandExecutor.displayChatMessage(ChatColors.GREEN + "Spawn is at [" + ChatColors.RESET + spawnCommandLocation.toStringXYZInt() + ChatColors.GREEN + "] in the " + ChatColors.RESET + Coordinate.dimensionToString(spawnCommandLocation.dimension)); + } +} diff --git a/src/main/java/com/kiva/kivaserverutils/commands/Teleport.java b/src/server/java/com/kiva/kivaserverutils/commands/Teleport.java similarity index 100% rename from src/main/java/com/kiva/kivaserverutils/commands/Teleport.java rename to src/server/java/com/kiva/kivaserverutils/commands/Teleport.java diff --git a/src/server/java/com/kiva/server/mixins/MixinSpawnerAnimals.java b/src/server/java/com/kiva/server/mixins/MixinSpawnerAnimals.java index 382b952..fd54b1a 100644 --- a/src/server/java/com/kiva/server/mixins/MixinSpawnerAnimals.java +++ b/src/server/java/com/kiva/server/mixins/MixinSpawnerAnimals.java @@ -17,8 +17,8 @@ private static int mobcap(Set instance, World world){ if (KivaServerUtils.getConfigValue("mobcapdisabled")) return instance.size(); - // Unfortunately a little stepped since this has to return int, but should not be an issue - return (int)((Math.pow(world.playerEntities.size(), 0.7) * 1.5) * 256); + // Unfortunately a little stepped since this has to return int, but should not be an issue since its still very accurate + return (int)((Math.pow(world.playerEntities.size(), 0.35) * 2) * 256); } @Redirect(method = "performSpawning", at = @At(value = "INVOKE", target = "Lnet/minecraft/src/game/entity/EnumCreatureType;getMaxNumberOfCreature()I"))