From d0d201870fc0c1ea8033137decdfcd7a758c777b Mon Sep 17 00:00:00 2001 From: ShakeforProtein Date: Sun, 26 May 2019 00:51:24 +1000 Subject: [PATCH] Added permission node tbteleport.player.shop - default True Added permission node tbteleport.admin.setshop - default OP Added permission node tbteleport.admin.cooldowns - default OP Added /shop - sends player to shop for current world Added /setshop - Sets current world /shop location to current location Added /setTTeleCooldown - Enables, disables and sets the timer for /wild cooldowns. Modified /setworldspawn to also save to config.yml for use with send to spawn on join. Modified /tp - Should no longer error if run from console. --- .../treeboteleport/Commands/SetShop.java | 13 +++---------- .../treeboteleport/Commands/SetTTeleCooldown.java | 7 +++++++ .../treeboteleport/Commands/SetWorldSpawn.java | 8 +++----- .../treeboteleport/Commands/Shop.java | 10 ++-------- .../treeboteleport/Commands/Wild.java | 4 +++- .../Listeners/PlayerJoinListener.java | 9 ++------- src/main/resources/config.yml | 1 + 7 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetShop.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetShop.java index c015b1b..67c8df8 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetShop.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetShop.java @@ -20,18 +20,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String Player p = (Player) sender; String world = p.getWorld().getName(); - double x = p.getLocation().getX(); - double y = p.getLocation().getY(); - double z = p.getLocation().getZ(); - float pitch = p.getLocation().getPitch(); - float yaw = p.getLocation().getYaw(); pl.getConfig().set("shop." + p.getWorld().getName() + ".world", world); - pl.getConfig().set("shop." + p.getWorld().getName() + ".x", x); - pl.getConfig().set("shop." + p.getWorld().getName() + ".y", y); - pl.getConfig().set("shop." + p.getWorld().getName() + ".z", z); - pl.getConfig().set("shop." + p.getWorld().getName() + ".pitch", pitch); - pl.getConfig().set("shop." + p.getWorld().getName() + ".yaw", yaw); + pl.getConfig().set("shop." + p.getWorld().getName() + ".location", p.getLocation()); + + sender.sendMessage(pl.badge + p.getWorld().getName() + "Shop set successfully, don't forget to run /ttelesaveconfig"); } else{ sender.sendMessage(pl.err + "This command can only be run as a player"); diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetTTeleCooldown.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetTTeleCooldown.java index 05b3969..fdca135 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetTTeleCooldown.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetTTeleCooldown.java @@ -22,9 +22,16 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String else{ if(args[0].equalsIgnoreCase("true") || args[0].equalsIgnoreCase("false")){ pl.getConfig().set("useCooldowns", args[0]); + if(args[0].equalsIgnoreCase("true")) { + sender.sendMessage(pl.badge + "useCooldowns enabled successfully, don't forget to run /ttelesaveconfig"); + } + else if(args[0].equalsIgnoreCase("false")){ + sender.sendMessage(pl.badge + "useCooldowns disabled successfully, don't forget to run /ttelesaveconfig"); + } } else if (pl.isInteger(args[0])){ pl.getConfig().set("CommandDelay", args[0]); + sender.sendMessage(pl.badge + "CommandDelay set to " + args[0] + " successfully, don't forget to run /ttelesaveconfig"); } else{ sender.sendMessage(pl.err + "Invalid input. Please use /setttelecooldown "); diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWorldSpawn.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWorldSpawn.java index 2167f70..a37aaf4 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWorldSpawn.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWorldSpawn.java @@ -62,11 +62,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String spawns.set("spawns." + name + ".yaw", yaw); pl.getConfig().set("onJoinSpawn." + p.getWorld().getName() + ".world", world); - pl.getConfig().set("onJoinSpawn." + p.getWorld().getName() + ".x", x); - pl.getConfig().set("onJoinSpawn." + p.getWorld().getName() + ".y", y); - pl.getConfig().set("onJoinSpawn." + p.getWorld().getName() + ".z", z); - pl.getConfig().set("onJoinSpawn." + p.getWorld().getName() + ".pitch", pitch); - pl.getConfig().set("onJoinSpawn." + p.getWorld().getName() + ".yaw", yaw); + pl.getConfig().set("onJoinSpawn." + p.getWorld().getName() + ".location", p.getLocation()); + sender.sendMessage(pl.badge + "onJoinSpawn set successfully, don't forget to run /ttelesaveconfig"); + try { spawns.save(spawnsYml); diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Shop.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Shop.java index 872046a..70d75f0 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Shop.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Shop.java @@ -24,14 +24,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String Player p = (Player) sender; if (pl.getConfig().isSet("shop." + p.getWorld().getName() + ".world")) { - String world = pl.getConfig().getString("shop." + p.getWorld().getName() + ".world"); - int x = Math.toIntExact(pl.getConfig().getInt("shop." + p.getWorld().getName() + ".x")); - int y = Math.toIntExact(pl.getConfig().getInt("shop." + p.getWorld().getName() + ".y")); - int z = Math.toIntExact(pl.getConfig().getInt("shop." + p.getWorld().getName() + ".z")); - float pitch = Math.toIntExact(pl.getConfig().getInt("shop." + p.getWorld().getName() + ".pitch")); - float yaw = Math.toIntExact(pl.getConfig().getInt("shop." + p.getWorld().getName() + ".yaw")); - Location shopLoc = new Location(Bukkit.getWorld(world), x, y, z, pitch, yaw); - p.teleport(shopLoc); + Location shopLoc = (Location) pl.getConfig().get("shop." + p.getWorld().getName() + ".location"); + pl.shakeTP(p, shopLoc); } } else { sender.sendMessage(pl.err + "This command can only be run by a player."); diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild.java index ac5e514..94b8e9b 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild.java @@ -129,7 +129,9 @@ private Location findSafeBlock(World w, CommandSender sender) { Location landOn = w.getBlockAt(X, (Y + 2), Z).getLocation(); landOn.add(0.5,0,0.5); - pl.setCooldown((Player) sender); + if(pl.getConfig().getBoolean("useCooldown")) { + pl.setCooldown((Player) sender); + } sender.sendMessage(ChatColor.translateAlternateColorCodes('&', pl.getConfig().getString("wild.messages.success")).replace("{COORDS}", X + "," + Y + "," + Z)); if(pl.getConfig().get("wild.cost") != null){ int cost = pl.getConfig().getInt("wild.cost"); diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerJoinListener.java b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerJoinListener.java index f882b94..97e8d59 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerJoinListener.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Listeners/PlayerJoinListener.java @@ -35,13 +35,8 @@ public boolean onPlayerJoin(PlayerJoinEvent e) { public void run() { System.out.println("Send to spawn triggered"); String world = pl.getConfig().getString("onJoinSpawn." + e.getPlayer().getWorld().getName() + ".world"); - int x = Math.toIntExact(pl.getConfig().getInt("onJoinSpawn." + e.getPlayer().getWorld().getName() + ".x")); - int y = Math.toIntExact(pl.getConfig().getInt("onJoinSpawn." + e.getPlayer().getWorld().getName() + ".y")); - int z = Math.toIntExact(pl.getConfig().getInt("onJoinSpawn." + e.getPlayer().getWorld().getName() + ".z")); - float pitch = Math.toIntExact(pl.getConfig().getInt("onJoinSpawn." + e.getPlayer().getWorld().getName() + ".pitch")); - float yaw = Math.toIntExact(pl.getConfig().getInt("onJoinSpawn." + e.getPlayer().getWorld().getName() + ".yaw")); - Location spawnLoc = new Location(Bukkit.getWorld(world), x, y, z, pitch, yaw); - e.getPlayer().teleport(spawnLoc); + Location spawnLoc = (Location) pl.getConfig().get("onJoinSpawn." + e.getPlayer().getWorld().getName() + ".location"); + pl.shakeTP(e.getPlayer(), spawnLoc); } }, 40L); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2bbce49..0361745 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -9,6 +9,7 @@ password: '' transferTable: 'treeboTeleport_serverTransfer' CommandDelay: 15 +useCooldown: false isHubServer: false