From bcdad0739db5427c266835ac2fded6b754fb299f Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Fri, 12 Jun 2020 13:23:27 +0200 Subject: [PATCH] minor optimizations --- src/net/mindoverflow/hubthat/HubThat.java | 17 ++++++++++------- .../hubthat/commands/HubCommand.java | 8 +++----- .../hubthat/utils/TeleportUtils.java | 6 +++++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/net/mindoverflow/hubthat/HubThat.java b/src/net/mindoverflow/hubthat/HubThat.java index 64956b4..bb951d2 100644 --- a/src/net/mindoverflow/hubthat/HubThat.java +++ b/src/net/mindoverflow/hubthat/HubThat.java @@ -32,7 +32,10 @@ public class HubThat extends JavaPlugin public UpdateChecker updateChecker; private static HubThat instance; - public HubThat() { instance = this; } + public HubThat() + { + instance = this; + } // Method called when the plugin is being loaded. @Override @@ -57,7 +60,7 @@ public class HubThat extends JavaPlugin SetSpawnCommand setSpawnCommandInstance = new SetSpawnCommand(this); WorldListCommand worldListCommandInstance = new WorldListCommand(this); WorldTpCommand worldTpCommandInstance = new WorldTpCommand(this); - + // We need to instantiate Utils classes because they need to access plugin data and server. TeleportUtils teleportUtilsInstance = new TeleportUtils(this); UpdateChecker updateCheckerInstance = new UpdateChecker(this); @@ -72,7 +75,6 @@ public class HubThat extends JavaPlugin pluginManager.registerEvents(new PlayerRespawnListener(this), this); - debugger.sendDebugMessage(Level.INFO, "Done registering listeners!"); // Register Commands @@ -112,9 +114,9 @@ public class HubThat extends JavaPlugin FileUtils.reloadYamls(); debugger.sendDebugMessage(Level.INFO, "Done!"); - debugger.sendDebugMessage(Level.INFO,"Setting up Metrics..."); + debugger.sendDebugMessage(Level.INFO, "Setting up Metrics..."); setupMetrics(); - debugger.sendDebugMessage(Level.INFO,"Done setting up Metrics!"); + debugger.sendDebugMessage(Level.INFO, "Done setting up Metrics!"); // Send success output message to console. logger.log(Level.INFO, "Plugin " + getDescription().getName() + " Successfully Loaded!"); @@ -124,7 +126,8 @@ public class HubThat extends JavaPlugin // Method called when the plugin is being unloaded. @Override - public void onDisable() { + public void onDisable() + { debugger.sendDebugMessage(Level.WARNING, "---[ DEBUGGER IS ENABLED! ]---"); debugger.sendDebugMessage(Level.WARNING, "---[ DISABLING PLUGIN ]---"); getServer().getScheduler().cancelTasks(this); @@ -145,7 +148,7 @@ public class HubThat extends JavaPlugin metrics.addCustomChart(new Metrics.SimplePie("tp-hub-on-join", () -> config.getString(ConfigEntries.TELEPORTATION_TP_HUB_ON_JOIN.path))); metrics.addCustomChart(new Metrics.SimplePie("tp-hub-on-respawn", () -> config.getString(ConfigEntries.TELEPORTATION_TP_HUB_ON_RESPAWN.path))); - if(config.getBoolean(ConfigEntries.GAMEMODE_SET_ON_JOIN.path)) + if (config.getBoolean(ConfigEntries.GAMEMODE_SET_ON_JOIN.path)) { metrics.addCustomChart(new Metrics.SimplePie("join-gamemode", () -> config.getString(ConfigEntries.GAMEMODE.path))); } diff --git a/src/net/mindoverflow/hubthat/commands/HubCommand.java b/src/net/mindoverflow/hubthat/commands/HubCommand.java index 287474f..6d18ed0 100644 --- a/src/net/mindoverflow/hubthat/commands/HubCommand.java +++ b/src/net/mindoverflow/hubthat/commands/HubCommand.java @@ -137,15 +137,13 @@ public class HubCommand implements CommandExecutor } // Method to teleport the player to the hub. - public static void teleportToHub(CommandSender sender, Player player) + public static void teleportToHub(CommandSender actor, Player player) { String username = player.getName(); - // Require the world to be Non Null - String worldName = Objects.requireNonNull(player.getWorld().getName()); - debugger.sendDebugMessage(Level.INFO, "Player name: " + username + "; World name: " + worldName); // Teleport the player to the destination. - TeleportUtils.teleportPlayer(sender, player, FileUtils.FileType.HUB_YAML, worldName); + TeleportUtils.teleportPlayer(actor, player, FileUtils.FileType.HUB_YAML); + // Remove it from the "teleporting" list - so it won't get teleported if it's waiting the spawn delay. CommonValues.teleporting.remove(username); } diff --git a/src/net/mindoverflow/hubthat/utils/TeleportUtils.java b/src/net/mindoverflow/hubthat/utils/TeleportUtils.java index 1811049..11cd658 100644 --- a/src/net/mindoverflow/hubthat/utils/TeleportUtils.java +++ b/src/net/mindoverflow/hubthat/utils/TeleportUtils.java @@ -120,7 +120,7 @@ public class TeleportUtils } // Store the location in a variable and teleport the player to it. - Location finalLocation = new Location(destinationWorld, x, y, z, (float)yaw, (float)pitch); + final Location finalLocation = new Location(destinationWorld, x, y, z, (float)yaw, (float)pitch); player.teleport(finalLocation); // Check if the player is teleporting to the hub. @@ -146,4 +146,8 @@ public class TeleportUtils } } } + public static void teleportPlayer(CommandSender sender, Player player, FileUtils.FileType type) + { + teleportPlayer(sender, player, type, null); + } }