From 6041b3a4a5df2f96e65362f935cb1acab0ae8664 Mon Sep 17 00:00:00 2001 From: ShakeforProtein Date: Mon, 7 Jun 2021 14:03:56 +1000 Subject: [PATCH] Fix for missing commands and commands being hijacked by EssentialsX. Removes ability to disable commands in the config. --- pom.xml | 2 +- .../treeboteleport/Commands/AddMaxHomes.java | 23 +- .../treeboteleport/Commands/Back.java | 20 +- .../treeboteleport/Commands/Bed.java | 19 +- .../treeboteleport/Commands/ClearMyChat.java | 12 +- .../Commands/ConfigureHomes.java | 55 +++- .../Commands/ConfigureHubMenu.java | 58 +++- .../Commands/ConfigureWarps.java | 61 +++- .../treeboteleport/Commands/DeleteHome.java | 63 +++- .../treeboteleport/Commands/DeleteWarp.java | 34 +- .../Commands/DisableTpSafety.java | 25 +- .../Commands/GetWorldSpawn.java | 13 +- .../treeboteleport/Commands/GiveHubItem.java | 15 +- .../treeboteleport/Commands/Home.java | 66 +++- .../treeboteleport/Commands/Homes.java | 34 +- .../treeboteleport/Commands/Hub.java | 16 +- .../Commands/JoinServerAtWorld.java | 22 +- .../treeboteleport/Commands/MayITp.java | 37 ++- .../treeboteleport/Commands/Reload.java | 9 +- .../Commands/RestorePlayerInventory.java | 56 +++- .../treeboteleport/Commands/SaveConfig.java | 10 +- .../treeboteleport/Commands/SendSpawn.java | 52 ++- .../treeboteleport/Commands/SetHome.java | 69 +++- .../Commands/SetPersonalWarp.java | 59 +++- .../treeboteleport/Commands/SetShop.java | 24 +- .../Commands/SetTTeleCooldown.java | 24 +- .../Commands/SetVanillaWorldSpawn.java | 14 +- .../treeboteleport/Commands/SetWarp.java | 59 +++- .../Commands/SetWorldSpawn.java | 59 +++- .../treeboteleport/Commands/Shop.java | 23 +- .../treeboteleport/Commands/ShowMaxHomes.java | 14 +- .../treeboteleport/Commands/Spawn.java | 49 ++- .../Commands/ToggleDeathDocket.java | 17 +- .../treeboteleport/Commands/Top.java | 35 +- .../treeboteleport/Commands/Tp2Me.java | 30 +- .../treeboteleport/Commands/Tp2MePls.java | 41 ++- .../treeboteleport/Commands/Tp2Player.java | 27 +- .../treeboteleport/Commands/Tp2Pos.java | 55 +++- .../treeboteleport/Commands/Tp2WorldAt.java | 60 +++- .../treeboteleport/Commands/TpNo.java | 20 +- .../treeboteleport/Commands/TpOk.java | 57 +++- .../treeboteleport/Commands/TpToggle.java | 16 +- .../treeboteleport/Commands/Version.java | 9 +- .../treeboteleport/Commands/WarpTo.java | 60 +++- .../treeboteleport/Commands/Wild2.java | 26 +- .../treeboteleport/TreeboTeleport.java | 181 +++++++---- src/main/resources/plugin.yml | 304 ++++++++---------- 47 files changed, 1748 insertions(+), 286 deletions(-) diff --git a/pom.xml b/pom.xml index 83a8b3f..1e74b76 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.ShakeforProtein TreeboTeleport - 2.0.0 + 2.0.2 jar TreeboTeleport diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/AddMaxHomes.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/AddMaxHomes.java index 275e8bf..5e12bc1 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/AddMaxHomes.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/AddMaxHomes.java @@ -3,6 +3,8 @@ import me.shakeforprotein.treeboteleport.TreeboTeleport; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; @@ -11,7 +13,7 @@ import java.lang.reflect.Field; -public class AddMaxHomes { +public class AddMaxHomes implements CommandExecutor { private TreeboTeleport pl; @@ -79,4 +81,23 @@ private void registerNewCommand(String fallback, BukkitCommand command) { e.printStackTrace(); } } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 2) { + sender.sendMessage(pl.err + "Incorrect usage. Correct usage is /addmaxhomes "); + } else { + if (pl.isInteger(args[1])) { + Player p = Bukkit.getOfflinePlayer(args[0]).getPlayer(); + int currentMaxHomes = getHomes(p); + int newHomes = currentMaxHomes + Integer.parseInt(args[1]); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user " + p.getName() + " add tbteleport.maxhomes." + newHomes); + sender.sendMessage(pl.badge + "Successfully set " + p.getName() + "'s maximum homes to " + getHomes(p)); + } else { + sender.sendMessage(pl.err + "Second argument must be a number"); + } + } + + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Back.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Back.java index 64eb8f6..7364567 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Back.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Back.java @@ -14,7 +14,7 @@ import java.lang.reflect.Field; -public class Back { +public class Back implements CommandExecutor { private TreeboTeleport pl; @@ -67,4 +67,22 @@ private void registerNewCommand(String fallback, BukkitCommand command) { e.printStackTrace(); } } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if (sender instanceof Player) { + Player p = (Player) sender; + + if (pl.lastLocConf.containsKey(p.getUniqueId())) { + p.sendMessage(pl.badge + "Sending you to your previous location"); + p.teleport(pl.lastLocConf.get(p.getUniqueId())); + } else { + p.sendMessage(pl.err + "Could not find previous location"); + } + } else { + sender.sendMessage(pl.badge + "This command can only be run by a player"); + } + return true; + } } \ No newline at end of file diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Bed.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Bed.java index e28a2a0..b9fc27c 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Bed.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Bed.java @@ -3,11 +3,13 @@ import me.shakeforprotein.treeboteleport.TreeboTeleport; import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class Bed { +public class Bed implements CommandExecutor { private TreeboTeleport pl; @@ -48,4 +50,19 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player p = (Player) sender; + + if (p.getBedSpawnLocation() != null) { + p.sendMessage(pl.badge + "Sending you to your bed"); + p.teleport(p.getBedSpawnLocation()); + } else { + p.sendMessage(pl.err + "Bed Missing"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ClearMyChat.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ClearMyChat.java index 21ded89..81d7177 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ClearMyChat.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ClearMyChat.java @@ -6,9 +6,8 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; -import org.bukkit.entity.Player; -public class ClearMyChat { +public class ClearMyChat implements CommandExecutor { private TreeboTeleport pl; @@ -42,4 +41,13 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + int i; + for (i = 0; i < 30; i++) { + sender.sendMessage(""); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureHomes.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureHomes.java index c6e4bdb..99594fd 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureHomes.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureHomes.java @@ -3,6 +3,8 @@ import me.shakeforprotein.treeboteleport.TreeboTeleport; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.configuration.file.YamlConfiguration; @@ -10,7 +12,7 @@ import java.io.File; -public class ConfigureHomes { +public class ConfigureHomes implements CommandExecutor { private TreeboTeleport pl; private File homeFile; @@ -124,4 +126,55 @@ public void doHelp(CommandSender s) { s.sendMessage("/configurehome set "); s.sendMessage("/configurehome set default "); } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + homeFile = new File(pl.getPlayerDataFolder() + File.separator + ((Player) sender).getUniqueId(), File.separator + "homes"+ ".yml"); + homeYaml = YamlConfiguration.loadConfiguration(homeFile); + boolean found = false; + + if (args.length > 2) { + if (args[0].equalsIgnoreCase("set")) { + if (args[2].equalsIgnoreCase("colour") || args[2].equalsIgnoreCase("color") || args[2].equalsIgnoreCase("icon")) { + if (args[2].equalsIgnoreCase("colour") || args[2].equalsIgnoreCase("color")) { + for (String item : homeYaml.getConfigurationSection("homes").getKeys(false)) { + if (item.equalsIgnoreCase(args[1])) { + found = true; + try { + ChatColor newColour = ChatColor.valueOf(args[3].toUpperCase()); + setYml(item, "colour", args[3].toUpperCase(), sender); + } catch (IllegalArgumentException e) { + sender.sendMessage("Unknown colour: '" + args[3].toUpperCase() + "'"); + } + } + } + } else if (args[2].equalsIgnoreCase("icon")) { + for (String item : homeYaml.getConfigurationSection("homes").getKeys(false)) { + if (item.equalsIgnoreCase(args[1])) { + found = true; + if (Material.getMaterial(args[3].toUpperCase()) != null) { + setYml(item, "icon", args[3].toUpperCase(), sender); + } else { + sender.sendMessage(pl.err + "Unknown Item: '" + args[3].toUpperCase() + "'"); + } + } + } + } + if (!found) { + sender.sendMessage(pl.err + ""); + } + } else { + sender.sendMessage(pl.err + "Unknown argument '" + args[2] + "'"); + } + } else { + sender.sendMessage(pl.err + "Unknown argument '" + args[0] + "'"); + } + } else { + sender.sendMessage(pl.err + "Insufficient arguments"); + doHelp(sender); + } + pl.saveFileConfigurationToFile(homeFile, homeYaml, sender); + + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureHubMenu.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureHubMenu.java index 7caa9d8..db0eef6 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureHubMenu.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureHubMenu.java @@ -3,6 +3,8 @@ import me.shakeforprotein.treeboteleport.TreeboTeleport; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.configuration.file.YamlConfiguration; @@ -10,7 +12,7 @@ import java.io.File; -public class ConfigureHubMenu { +public class ConfigureHubMenu implements CommandExecutor { private TreeboTeleport pl; private File hubFile; @@ -134,4 +136,58 @@ public void doHelp(CommandSender s) { s.sendMessage("Usage: /configureHub set "); s.sendMessage(" /configurehub set rows (1 - 6)"); } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if (args.length == 0) { + sender.sendMessage(pl.err + "This command requires multiple inputs"); + doHelp(sender); + } else if (args[0].equalsIgnoreCase("set")) { + if (args[2] != null) { + if (pl.isInteger(args[2])) { + if (args[1].equalsIgnoreCase("icon")) { + if (Material.getMaterial(args[3].toUpperCase()) != null) { + setYml(args[2], "icon", args[3].toUpperCase(), sender); + } else { + sender.sendMessage(pl.err + "Unknown Material -->" + args[3] + "<--"); + } + } else if (args[1].equalsIgnoreCase("label")) { + int i; + StringBuilder labelText = new StringBuilder(); + for (i = 3; i < args.length; i++) { + labelText.append(args[i] + " "); + } + setYml(args[2], "label", labelText.toString(), sender); + } else if (args[1].equalsIgnoreCase("position")) { + + setYml(args[2], "position", args[3], sender); + } else if (args[1].equalsIgnoreCase("command")) { + int i; + StringBuilder commandText = new StringBuilder(); + for (i = 3; i < args.length; i++) { + commandText.append(args[i] + " "); + } + setYml(args[2], "command", commandText.toString(), sender); + } else if (args[1].equalsIgnoreCase("colour") || args[1].equalsIgnoreCase("color")) { + if (args[1].equalsIgnoreCase("color")) { + sender.sendMessage("You seem to have dropped your U. Don't worry, I've made sure to include it with your other letters."); + } + setYml(args[2], "color", args[3], sender); + } else if (args[1].equalsIgnoreCase("rows")) { + setRows(args[2], sender); + } + + + } else { + sender.sendMessage(pl.err + "Expected integer at -->" + args[2] + "<--"); + } + } else { + sender.sendMessage(pl.err + "Insufficient arguments"); + doHelp(sender); + } + } + pl.saveFileConfigurationToFile(hubFile, hubYaml, sender); + return true; + } } \ No newline at end of file diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureWarps.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureWarps.java index 38cb9a5..a6be4f1 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureWarps.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ConfigureWarps.java @@ -3,6 +3,8 @@ import me.shakeforprotein.treeboteleport.TreeboTeleport; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.configuration.file.YamlConfiguration; @@ -10,7 +12,7 @@ import java.io.File; import java.io.IOException; -public class ConfigureWarps { +public class ConfigureWarps implements CommandExecutor { private TreeboTeleport pl; @@ -96,4 +98,61 @@ private void doHelp(CommandSender s) { s.sendMessage(pl.badge + "Correct usage is as follows"); s.sendMessage("/configurewarps set "); } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + File warpsFile = new File(pl.getDataFolder(), "warps.yml"); + YamlConfiguration warpsYaml = YamlConfiguration.loadConfiguration(warpsFile); + boolean found = false; + + + if (args.length < 4) { + sender.sendMessage(pl.err + "Insufficient Arguments"); + doHelp(sender); + } else if (args[0].equalsIgnoreCase("set")) { + for (String item : warpsYaml.getConfigurationSection("warps").getKeys(false)) { + if (args[2].equalsIgnoreCase(item)) { + found = true; + if (args[1].equalsIgnoreCase("icon")) { + if (Material.getMaterial(args[3].toUpperCase()) != null) { + warpsYaml.set("warps." + item + ".icon", args[3].toUpperCase()); + try { + warpsYaml.save(warpsFile); + sender.sendMessage("Warps file saved"); + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + sender.sendMessage(pl.err + "Failed to save warps file"); + } + } else { + sender.sendMessage(pl.err + "Unknown Item: '" + args[3].toUpperCase() + "'"); + } + + } else if (args[1].equalsIgnoreCase("title")) { + StringBuilder fullText = new StringBuilder(); + int i; + for (i = 3; i < args.length; i++) { + fullText.append(args[i] + " "); + } + warpsYaml.set("warps." + item + ".title", fullText.toString().trim()); + try { + warpsYaml.save(warpsFile); + sender.sendMessage("Warps file saved"); + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + sender.sendMessage(pl.err + "Failed to save warps file"); + } + } else { + sender.sendMessage(pl.err + "Unknown setting '" + args[1] + "'"); + } + } + } + if (!found) { + sender.sendMessage(pl.err + "Could not find warp with that id"); + } + } else { + sender.sendMessage(pl.err + "Incorrect usage"); + doHelp(sender); + } + return true; + } } \ No newline at end of file diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/DeleteHome.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/DeleteHome.java index 5518f14..2dcdefd 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/DeleteHome.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/DeleteHome.java @@ -2,6 +2,8 @@ import me.shakeforprotein.treeboteleport.TreeboTeleport; import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.configuration.file.FileConfiguration; @@ -12,7 +14,7 @@ import java.io.FileNotFoundException; import java.io.IOException; -public class DeleteHome { +public class DeleteHome implements CommandExecutor { private TreeboTeleport pl; @@ -28,11 +30,11 @@ public boolean execute(CommandSender sender, String label, String[] args) { this.setDescription("Allows player to delete their homes"); this.setUsage("/DeleteHome or /DelHome - requires tbteleport.player.delhome"); this.setPermission("tbteleport.player.delhome"); - if(sender.hasPermission(this.getPermission())) { + if (sender.hasPermission(this.getPermission())) { - Player p = (Player) sender; + Player p = (Player) sender; //File homesYml = new File(pl.getDataFolder() + File.separator + "homes", File.separator + p.getUniqueId().toString() + ".yml"); - File homesYml = new File(pl.getPlayerDataFolder() + File.separator + p.getUniqueId().toString(), File.separator + "homes"+ ".yml"); + File homesYml = new File(pl.getPlayerDataFolder() + File.separator + p.getUniqueId().toString(), File.separator + "homes" + ".yml"); if (!homesYml.exists()) { p.sendMessage(pl.err + "Homes file not found. Attempting to Recover."); @@ -75,8 +77,7 @@ public boolean execute(CommandSender sender, String label, String[] args) { } } - } - else{ + } else { sender.sendMessage(ChatColor.RED + "You do not have access to this command. You require permission node " + ChatColor.GOLD + this.getPermission()); } @@ -87,4 +88,54 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + Player p = (Player) sender; + //File homesYml = new File(pl.getDataFolder() + File.separator + "homes", File.separator + p.getUniqueId().toString() + ".yml"); + File homesYml = new File(pl.getPlayerDataFolder() + File.separator + p.getUniqueId().toString(), File.separator + "homes" + ".yml"); + + if (!homesYml.exists()) { + p.sendMessage(pl.err + "Homes file not found. Attempting to Recover."); + try { + homesYml.createNewFile(); + FileConfiguration homes = YamlConfiguration.loadConfiguration(homesYml); + try { + homes.options().copyDefaults(); + homes.save(homesYml); + } catch (FileNotFoundException ex) { + pl.roots.errorLogger.logError(pl, ex); + } + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + p.sendMessage(pl.err + "Creating Homes file failed"); + } + } + FileConfiguration homes = YamlConfiguration.loadConfiguration(homesYml); + + if (args.length == 0) { + p.sendMessage(pl.err + "You must provide the home name to delete"); + } else if (args.length > 1) { + p.sendMessage(pl.err + "Too many arguments"); + } else { + args[0] = args[0].toLowerCase(); + homes.set("homes." + args[0] + ".name", null); + homes.set("homes." + args[0] + ".world", null); + homes.set("homes." + args[0] + ".x", null); + homes.set("homes." + args[0] + ".y", null); + homes.set("homes." + args[0] + ".z", null); + homes.set("homes." + args[0] + ".pitch", null); + homes.set("homes." + args[0] + ".yaw", null); + homes.set("homes." + args[0], null); + try { + homes.save(homesYml); + p.sendMessage(pl.badge + "If a home existed with name: " + ChatColor.GOLD + args[0] + ChatColor.RESET + " it has now been deleted."); + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + p.sendMessage(pl.err + "Saving homes file failed"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/DeleteWarp.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/DeleteWarp.java index 901a67f..0bf83f1 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/DeleteWarp.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/DeleteWarp.java @@ -15,7 +15,7 @@ import java.io.FileNotFoundException; import java.io.IOException; -public class DeleteWarp { +public class DeleteWarp implements CommandExecutor{ private TreeboTeleport pl; @@ -70,4 +70,36 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + File warpsYml = new File(pl.getDataFolder(), "warps.yml"); + YamlConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); + + Player p = (Player) sender; + + if (args.length == 0) { + p.sendMessage(pl.err + "You must provide the warp name to delete"); + } else if (args.length > 1) { + p.sendMessage(pl.err + "Too many arguments"); + } else { + args[0] = args[0].toLowerCase(); + warps.set("warps." + args[0] + ".name", null); + warps.set("warps." + args[0] + ".world", null); + warps.set("warps." + args[0] + ".x", null); + warps.set("warps." + args[0] + ".y", null); + warps.set("warps." + args[0] + ".z", null); + warps.set("warps." + args[0] + ".pitch", null); + warps.set("warps." + args[0] + ".yaw", null); + warps.set("warps." + args[0], null); + try { + warps.save(warpsYml); + p.sendMessage(pl.badge + "If a warp existed with name: " + ChatColor.GOLD + args[0] + ChatColor.RESET + " it has now been deleted."); + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + p.sendMessage(pl.err + "Saving Warps file unsuccessful"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/DisableTpSafety.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/DisableTpSafety.java index a95d9b6..c813584 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/DisableTpSafety.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/DisableTpSafety.java @@ -9,7 +9,7 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class DisableTpSafety { +public class DisableTpSafety implements CommandExecutor{ private TreeboTeleport pl; @@ -56,4 +56,27 @@ else if(pl.getConfig().getBoolean("tpSafetyToggle." + p.getName())) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player p = (Player) sender; + + if (pl.getConfig().getInt("tpSafetyToggle." + p.getName()) == 0) { + pl.getConfig().set("tpSafetyToggle." + p.getName(), true); + p.sendMessage(pl.badge + "Teleport Safeties disabled. TreeboMC takes no responsibility for any death as a result of this. Be safe out there."); + } + else if(pl.getConfig().getBoolean("tpSafetyToggle." + p.getName())) { + pl.getConfig().set("tpSafetyToggle." + p.getName(), false); + p.sendMessage(pl.badge + "Teleport protection disabled."); + } + else{ + pl.getConfig().set("tpSafetyToggle." + p.getName(), true); + p.sendMessage(pl.badge + "Teleport Safeties disabled. TreeboMC takes no responsibility for any death as a result of this. Be safe out there."); + } + } else { + sender.sendMessage(pl.err + "Only players may disable their teleport protection."); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/GetWorldSpawn.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/GetWorldSpawn.java index 9130f9e..4d6776b 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/GetWorldSpawn.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/GetWorldSpawn.java @@ -9,7 +9,7 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class GetWorldSpawn { +public class GetWorldSpawn implements CommandExecutor{ private TreeboTeleport pl; @@ -43,4 +43,15 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + World w = ((Player) sender).getWorld(); + System.out.println("Player has requested Spawn Location"); + System.out.println(w.getSpawnLocation().toString()); + sender.sendMessage(w.getSpawnLocation().toString()); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/GiveHubItem.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/GiveHubItem.java index a17e15e..8ca51b9 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/GiveHubItem.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/GiveHubItem.java @@ -2,6 +2,8 @@ import me.shakeforprotein.treeboteleport.TreeboTeleport; import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; @@ -9,7 +11,7 @@ import org.bukkit.inventory.ItemStack; -public class GiveHubItem { +public class GiveHubItem implements CommandExecutor { private TreeboTeleport pl; @@ -47,4 +49,15 @@ public boolean execute(CommandSender sender, String label, String[] args) { return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + Inventory inv = p.getInventory(); + ItemStack hubItem = pl.getHubItemFromConfig(); + if (!inv.contains(hubItem)) { + inv.addItem(hubItem); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Home.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Home.java index 4affc18..12aa4ba 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Home.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Home.java @@ -16,7 +16,7 @@ import java.io.File; -public class Home{ +public class Home implements CommandExecutor{ private TreeboTeleport pl; @@ -105,4 +105,68 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + //File homesYml = new File(pl.getDataFolder() + File.separator + "homes", File.separator + p.getUniqueId().toString() + ".yml"); + File homesYml = new File(pl.getPlayerDataFolder() + File.separator + p.getUniqueId().toString(), File.separator + "homes.yml"); + + FileConfiguration homes = YamlConfiguration.loadConfiguration(homesYml); + + if (!homesYml.exists()) { + sender.sendMessage(pl.err + "You do not appear to have any homes. Use '/sethome ' to create a home at your current location."); + } else { + if (args.length == 0) { + if (homes.get("defaultHome") != null) { + Bukkit.dispatchCommand(sender, "home default"); + } else { + Bukkit.dispatchCommand(sender, "homes"); + } + } else if (args.length == 1) { + if (args[0].equalsIgnoreCase("default")) { + if (homes.get("defaultHome") != null) { + boolean found = false; + for (String home : homes.getConfigurationSection("homes").getKeys(false)) { + if (homes.getString("homes." + home + ".name").equalsIgnoreCase(homes.getString("defaultHome"))) { + Bukkit.dispatchCommand(sender, "home " + homes.getString("homes." + home + ".name")); + found = true; + } + } + if (!found) { + sender.sendMessage(pl.badge + "Couldn't find your default home. Have you deleted it?"); + } + } else { + sender.sendMessage(pl.badge + "Default home not set"); + } + } else if (args[0].equalsIgnoreCase("bed")) { + Bukkit.dispatchCommand(p, "bed"); + } else { + boolean found = false; + for (String home : homes.getConfigurationSection("homes").getKeys(false)) { + if (homes.getString("homes." + home + ".name").equalsIgnoreCase(args[0])) { + int x = homes.getInt("homes." + home + ".x"); + int y = homes.getInt("homes." + home + ".y"); + int z = homes.getInt("homes." + home + ".z"); + int pitch = homes.getInt("homes." + home + ".pitch"); + int yaw = homes.getInt("homes." + home + ".yaw"); + String world = homes.getString("homes." + home + ".world"); + Location tpLoc = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch); + p.sendMessage(pl.badge + "Returning you to " + home); + p.teleport(tpLoc); + + found = true; + } + } + if (!found) { + sender.sendMessage(pl.err + "No home found with name " + args[0]); + } + } + } else { + sender.sendMessage("Too many Arguments"); + Bukkit.dispatchCommand(sender, "homes"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Homes.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Homes.java index 2247e6e..1b045f1 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Homes.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Homes.java @@ -29,7 +29,7 @@ import java.util.ArrayList; import java.util.List; -public class Homes { +public class Homes implements CommandExecutor { private TreeboTeleport pl; private OpenHomesMenu openHomesMenu; @@ -248,4 +248,36 @@ private void OpenHomesMenu(Player opener, String owner, YamlConfiguration yamlCo } opener.openInventory(homesMenu); } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + /*****************************************************************************************************/ + /*ThoughtProcess: This section determines if the sender is staff, and if there is an Player argument */ + /*ThoughtProcess: If there is a player argument, it attempts to get the players uuid which it uses */ + /*ThoughtProcess: to get the appropriate homes file. If there is no player argument, or the sender is*/ + /*ThoughtProcess: not staff, it will get the senders personal homes file. */ + /*****************************************************************************************************/ + boolean staff = false; + String owner = sender.getName(); + if (sender.hasPermission("treeboteleport.staff.homes.other")) { + staff = true; + } + //File homesYml = new File(pl.getDataFolder() + File.separator + "homes", File.separator + ((Player) sender).getUniqueId().toString() + ".yml"); + File homesYml = new File(pl.getPlayerDataFolder() + File.separator + ((Player) sender).getUniqueId().toString(), File.separator + "homes.yml"); + + if (args.length == 1 && staff) { + //homesYml = new File(pl.getDataFolder() + File.separator + "homes", File.separator + (Bukkit.getOfflinePlayer(args[0])).getUniqueId().toString() + ".yml"); + homesYml = new File(pl.getDataFolder() + File.separator + Bukkit.getOfflinePlayer(args[0]).getUniqueId().toString(), File.separator + "homes.yml"); + owner = args[0].toLowerCase(); + } + + if (homesYml.exists()) { + YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(homesYml); + OpenHomesMenu((Player) sender, owner, yamlConfiguration); + } else { + sender.sendMessage(pl.err + "Homes file not found."); + } + return true; + } } \ No newline at end of file diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Hub.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Hub.java index 752121f..dd10063 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Hub.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Hub.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; -public class Hub { +public class Hub implements CommandExecutor{ private TreeboTeleport pl; private OpenHubMenu openHubMenu; @@ -50,4 +50,18 @@ public boolean execute(CommandSender sender, String label, String[] args) { return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + String w = player.getWorld().getName(); + if (args.length == 0) { + openHubMenu.openHubMenu((Player) sender); + } else { + sender.sendMessage(pl.err + "The HUB command does not support additional arguments"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/JoinServerAtWorld.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/JoinServerAtWorld.java index dc83ff9..c00211f 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/JoinServerAtWorld.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/JoinServerAtWorld.java @@ -6,12 +6,13 @@ import org.apache.commons.lang.ObjectUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class JoinServerAtWorld { +public class JoinServerAtWorld implements CommandExecutor{ private TreeboTeleport pl; private BungeeSend bungeeSend; @@ -57,4 +58,23 @@ public boolean execute(CommandSender sender, String label, String[] args) { return true; } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if (args.length == 2) { + String server = args[0]; + String world = args[1]; + if (pl.roots.getConfig().getString("General.ServerDetails.ServerName") != null && pl.roots.getConfig().getString("General.ServerDetails.ServerName").equalsIgnoreCase(server)) { + ((Player) sender).teleport(Bukkit.getWorld(world).getSpawnLocation()); + } else { + bungeeSend.sendConnectOther(server, sender.getName()); + bungeeSend.sendPluginMessage("Jsaw", server, world + "," + sender.getName()); + } + } else { + sender.sendMessage(pl.badge + ChatColor.RED + "ERROR: " + ChatColor.RESET + "No Help is available for this command"); + } + } + return true; + } } \ No newline at end of file diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/MayITp.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/MayITp.java index 2f177e8..cd42596 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/MayITp.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/MayITp.java @@ -12,7 +12,7 @@ import java.time.Instant; -public class MayITp { +public class MayITp implements CommandExecutor{ private TreeboTeleport pl; private BungeeSend bungeeSend; @@ -76,4 +76,39 @@ public boolean execute(CommandSender sender, String label, String[] args) { return true; } + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (args.length == 1) { + boolean foundPlayer = false; + for (Player p : Bukkit.getOnlinePlayers()) { + if (p.getName().equalsIgnoreCase(args[0])) { + foundPlayer = true; + if (pl.getConfig().get("tpRequest." + sender.getName()) == null || (System.currentTimeMillis() - 30000) > pl.getConfig().getLong("tpRequest." + sender.getName() + ".requestTime")) { + + if (pl.getConfig().get("tptoggle." + p.getName()) == null || pl.getConfig().getInt("tptoggle." + p.getName()) == 0) { + sender.sendMessage(pl.badge + "Request to teleport to " + p.getName() + "'s location has been sent."); + p.sendMessage(pl.badge + "Player " + ChatColor.GOLD + sender.getName() + ChatColor.RESET + " would like to teleport " + ChatColor.GOLD + "TO YOU"); + String command = "tellraw " + p.getName() + " [\"\",{\"text\":\"Please type \"},{\"text\":\"/tpok\",\"color\":\"green\"},{\"text\":\" or click \"},{\"text\":\"[HERE]\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/tpok\"}},{\"text\":\" in the next \"},{\"text\":\"30 Seconds\",\"color\":\"green\"},{\"text\":\" to Accept\"}]"; + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + pl.getConfig().set("tpRequest." + p.getName() + ".type", "toPlayer"); + pl.getConfig().set("tpRequest." + p.getName() + ".requestTime", System.currentTimeMillis()); + pl.getConfig().set("tpRequest." + p.getName() + ".requester", sender.getName()); + } else { + sender.sendMessage(pl.err + p.getName() + " has disabled incoming teleport requests"); + } + } else { + sender.sendMessage(pl.err + "You already have a pending teleport request."); + } + } + } + if (!foundPlayer) { + sender.sendMessage(pl.err + "Player " + ChatColor.GOLD + args[0] + ChatColor.RESET + " is not online on this server. Attempting to locate on other servers"); + bungeeSend.sendPluginMessage("CrossServerTPA", "ALL", "toPlayer," + sender.getName() + "," + args[0]); + + } + } else { + sender.sendMessage(pl.err + "Incorrect usage. This command requires a single player argument"); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Reload.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Reload.java index ae9fade..fbd1420 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Reload.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Reload.java @@ -8,7 +8,7 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class Reload { +public class Reload implements CommandExecutor{ private TreeboTeleport pl; @@ -37,4 +37,11 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + pl.reloadConfig(); + sender.sendMessage(pl.badge + "Config Reloaded"); + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/RestorePlayerInventory.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/RestorePlayerInventory.java index 741b7a2..321a699 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/RestorePlayerInventory.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/RestorePlayerInventory.java @@ -15,7 +15,7 @@ import java.io.File; import java.io.IOException; -public class RestorePlayerInventory { +public class RestorePlayerInventory implements CommandExecutor { private TreeboTeleport pl; @@ -92,4 +92,58 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length == 2) { + + if (Bukkit.getPlayer(args[0]) != null && Bukkit.getPlayer(args[0]).isOnline()) { + Player p = Bukkit.getPlayer(args[0]); + //File deathFile = new File(pl.getDataFolder() + File.separator + "deaths", File.separator + p.getUniqueId().toString() + "_" + args[1] + ".yml"); + //File deathFileUsed = new File(pl.getDataFolder() + File.separator + "deaths", File.separator + "USED_" + p.getUniqueId().toString() + "_" + args[1] + ".yml"); + File deathFile = new File(pl.getPlayerDataFolder() + File.separator + p.getUniqueId().toString() + File.separator + "deaths", File.separator + p.getUniqueId().toString() + "_" + args[1] + ".yml"); + File deathFileUsed = new File(pl.getPlayerDataFolder() + File.separator + p.getUniqueId().toString() + File.separator + "deaths", File.separator + "USED_" + p.getUniqueId().toString() + "_" + args[1] + ".yml"); + + if (deathFile.exists()) { + sender.sendMessage(pl.badge + "Death file found"); + FileConfiguration deathYaml = YamlConfiguration.loadConfiguration(deathFile); + if (deathYaml.getString("used").equalsIgnoreCase("false")) { + if (deathYaml.getString("uuid").equalsIgnoreCase(p.getUniqueId().toString())) { + if (p.getWorld().getName().equalsIgnoreCase(deathYaml.getString("world"))) { + int i = 0; + for (String key : deathYaml.getConfigurationSection("inventory").getKeys(false)) { + p.getInventory().addItem(deathYaml.getItemStack("inventory.slot_" + i)); + i++; + } + p.setTotalExperience(deathYaml.getInt("experience")); + deathYaml.set("used", true); + try { + deathYaml.save(deathFile); + deathFile.renameTo(deathFileUsed); + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + sender.sendMessage(pl.err + "Failed to update 'used' status on docket " + deathFile.toString()); + } + } else { + sender.sendMessage(pl.err + "Player world mismatch. This inventory is for World:" + deathYaml.getString("world")); + } + } else { + sender.sendMessage(pl.err + "Player UUID mismatch. This inventory does not belong to Player: " + args[0]); + } + } else { + sender.sendMessage(pl.err + "This inventory has already been recovered"); + } + } else { + sender.sendMessage(pl.err + "No matching death file on record."); + } + } else { + sender.sendMessage(pl.err + "Player: " + args[0] + " not found."); + } + } else if (args.length < 2) { + sender.sendMessage(pl.err + "Insufficient arguments. This command requires a and argument."); + } else { + sender.sendMessage(pl.err + "Too many arguments. This command requires only a and argument."); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SaveConfig.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SaveConfig.java index 83d5167..0759930 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SaveConfig.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SaveConfig.java @@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; -public class SaveConfig { +public class SaveConfig implements CommandExecutor{ private TreeboTeleport pl; @@ -37,4 +37,12 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + pl.saveConfig(); + sender.sendMessage(pl.badge + "Saved Config"); + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SendSpawn.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SendSpawn.java index ba25115..bac9551 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SendSpawn.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SendSpawn.java @@ -16,7 +16,7 @@ import java.io.FileNotFoundException; import java.io.IOException; -public class SendSpawn { +public class SendSpawn implements CommandExecutor { private TreeboTeleport pl; @@ -89,4 +89,54 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 0 && args.length < 3) { + if (Bukkit.getPlayer(args[0]) != null) { + Player p = Bukkit.getPlayer(args[0]); + File spawnsYml = new File(pl.getDataFolder(), File.separator + "spawns.yml"); + if (!spawnsYml.exists()) { + sender.sendMessage(pl.err + "Failed to load Spawns data. Attempting to recover"); + try { + spawnsYml.createNewFile(); + FileConfiguration spawns = YamlConfiguration.loadConfiguration(spawnsYml); + try { + spawns.options().copyDefaults(); + spawns.save(spawnsYml); + } catch (FileNotFoundException ex) { + pl.roots.errorLogger.logError(pl, ex); + } + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + sender.sendMessage(pl.err + "Loading Spawns Data Unsuccessful"); + } + } + FileConfiguration spawns = YamlConfiguration.loadConfiguration(spawnsYml); + String world = p.getWorld().getName(); + if (args.length == 2) { + world = args[1]; + } + + if (spawns.get("spawns." + world + ".x") != null) { + String confWorld = spawns.getString("spawns." + world + ".world"); + double x = spawns.getDouble("spawns." + world + ".x"); + double y = spawns.getDouble("spawns." + world + ".y"); + double z = spawns.getDouble("spawns." + world + ".z"); + float pitch = (float) spawns.getDouble("spawns." + world + ".pitch"); + float yaw = (float) spawns.getDouble("spawns." + world + ".yaw"); + Location loc = new Location(Bukkit.getWorld(confWorld), x, y, z, yaw, pitch); + p.sendMessage(pl.badge + "Returning you to Spawn"); + p.teleport(loc); + } else { + p.sendMessage(pl.err + "No spawn found for this world"); + } + } else { + sender.sendMessage(pl.err + "Player " + args[0] + "not found."); + } + } else if (args.length == 0) { + sender.sendMessage(pl.err + "Not enough arguments. Please specify a player and optionally which worlds spawn to send them to."); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetHome.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetHome.java index e331a27..409d745 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetHome.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetHome.java @@ -16,7 +16,7 @@ import java.io.FileNotFoundException; import java.io.IOException; -public class SetHome { +public class SetHome implements CommandExecutor{ private TreeboTeleport pl; @@ -122,4 +122,71 @@ private int getHomes(Player p) { return maxHomes; } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + //File homesYml = new File(pl.getDataFolder() + File.separator + "homes", File.separator + p.getUniqueId().toString() + ".yml"); + File homesYml = new File(pl.getPlayerDataFolder() + File.separator + p.getUniqueId().toString(), File.separator + "homes.yml"); + + if (!homesYml.exists()) { + try { + homesYml.createNewFile(); + FileConfiguration homes = YamlConfiguration.loadConfiguration(homesYml); + try { + homes.options().copyDefaults(); + homes.save(homesYml); + } catch (FileNotFoundException ex) { + pl.roots.errorLogger.logError(pl, ex); + } + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + } + } + FileConfiguration homes = YamlConfiguration.loadConfiguration(homesYml); + Location loc = p.getLocation(); + String world = loc.getWorld().getName(); + double x = loc.getX(); + double y = loc.getY(); + double z = loc.getZ(); + float pitch = loc.getPitch(); + float yaw = loc.getYaw(); + Vector direction = loc.getDirection(); + if (args.length == 0) { + p.sendMessage(pl.err + "You must provide a name for your new Home"); + } else if (args.length > 1) { + p.sendMessage(pl.err + "Too many arguments"); + } else { + if (args[0].equalsIgnoreCase("bed")) { + p.sendMessage(pl.err + ChatColor.GOLD + "Bed" + ChatColor.RESET + " is a disallowed warp name"); + } else { + int maxHomes = getHomes(p); + int existingHomes = 0; + if (homes.getConfigurationSection("homes") != null && homes.getConfigurationSection("homes").getKeys(false) != null) { + existingHomes = homes.getConfigurationSection("homes").getKeys(false).toArray().length; + } + if (maxHomes > existingHomes) { + String name = args[0]; + args[0] = args[0].toLowerCase(); + homes.set("homes." + args[0] + ".name", name); + homes.set("homes." + args[0] + ".world", world); + homes.set("homes." + args[0] + ".x", x); + homes.set("homes." + args[0] + ".y", y); + homes.set("homes." + args[0] + ".z", z); + homes.set("homes." + args[0] + ".pitch", pitch); + homes.set("homes." + args[0] + ".yaw", yaw); + + try { + homes.save(homesYml); + p.sendMessage(pl.badge + "Home with name: " + ChatColor.GOLD + args[0] + ChatColor.RESET + " has been saved."); + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + p.sendMessage(pl.err + "Saving Homes file Unsuccessful"); + } + } else { + p.sendMessage(pl.err + "You do not have any additional homes available. You may purchase more at " + ChatColor.BLUE + "http://store.treebomc.com " + ChatColor.RESET + "or consider " + ChatColor.RED + " deleting" + ChatColor.RESET + "one of your existing homes with " + ChatColor.RED + "/delhome"); + } + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetPersonalWarp.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetPersonalWarp.java index e2dc727..cdbe663 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetPersonalWarp.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetPersonalWarp.java @@ -3,6 +3,8 @@ import me.shakeforprotein.treeboteleport.TreeboTeleport; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.configuration.file.FileConfiguration; @@ -13,7 +15,7 @@ import java.io.FileNotFoundException; import java.io.IOException; -public class SetPersonalWarp { +public class SetPersonalWarp implements CommandExecutor { private TreeboTeleport pl; @@ -91,4 +93,59 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + File warpsYml = new File(pl.getDataFolder(), File.separator + "warps.yml"); + if (!warpsYml.exists()) { + sender.sendMessage(pl.err + "Warps data not found. Attempting to recover."); + try { + warpsYml.createNewFile(); + FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); + try { + warps.options().copyDefaults(); + warps.save(warpsYml); + } catch (FileNotFoundException ex) { + pl.roots.errorLogger.logError(pl, ex); + } + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + sender.sendMessage(pl.err + "Creating warps file failed"); + } + } + FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); + Player p = (Player) sender; + Location loc = p.getLocation(); + String world = loc.getWorld().getName(); + double x = loc.getX(); + double y = loc.getY(); + double z = loc.getZ(); + float pitch = loc.getPitch(); + float yaw = loc.getYaw(); + if (args.length == 0) { + p.sendMessage(pl.err + "You must provide a name for your new warp"); + } else if (args.length > 2) { + p.sendMessage(pl.err + "Too many arguments"); + } else { + String name = args[0]; + args[0] = args[0].toLowerCase(); + warps.set("playerWarps." + p.getUniqueId().toString() + ".name", name); + warps.set("playerWarps." + p.getUniqueId().toString() + ".world", world); + warps.set("playerWarps." + p.getUniqueId().toString() + ".x", x); + warps.set("playerWarps." + p.getUniqueId().toString() + ".y", y); + warps.set("playerWarps." + p.getUniqueId().toString() + ".z", z); + warps.set("playerWarps." + p.getUniqueId().toString() + ".pitch", pitch); + warps.set("playerWarps." + p.getUniqueId().toString() + ".yaw", yaw); + + try { + warps.save(warpsYml); + p.sendMessage(pl.badge + "Player Warp with name: " + ChatColor.GOLD + args[0] + ChatColor.RESET + " has been saved."); + p.sendMessage("If you choose to set a new PWarp, this warp will be overwritten."); + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + p.sendMessage(pl.err + "Saving warps file Unsuccessful"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetShop.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetShop.java index 4d18a2f..9619f5f 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetShop.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetShop.java @@ -9,7 +9,7 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class SetShop { +public class SetShop implements CommandExecutor { private TreeboTeleport pl; @@ -54,4 +54,26 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player p = (Player) sender; + + String world = p.getWorld().getName(); + + Location pLoc = p.getLocation(); + pl.getConfig().set("shop." + p.getWorld().getName() + ".world", world); + pl.getConfig().set("shop." + p.getWorld().getName() + ".x", pLoc.getX()); + pl.getConfig().set("shop." + p.getWorld().getName() + ".y", pLoc.getY()); + pl.getConfig().set("shop." + p.getWorld().getName() + ".z", pLoc.getZ()); + pl.getConfig().set("shop." + p.getWorld().getName() + ".pitch", pLoc.getPitch()); + pl.getConfig().set("shop." + p.getWorld().getName() + ".yaw", pLoc.getYaw()); + + 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"); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetTTeleCooldown.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetTTeleCooldown.java index 4894eae..e0017c8 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetTTeleCooldown.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetTTeleCooldown.java @@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; -public class SetTTeleCooldown { +public class SetTTeleCooldown implements CommandExecutor{ private TreeboTeleport pl; @@ -53,4 +53,26 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 1) { + sender.sendMessage(pl.err + "This command expects a single argument "); + } 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 "); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetVanillaWorldSpawn.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetVanillaWorldSpawn.java index 5a5db13..9eb0a1b 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetVanillaWorldSpawn.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetVanillaWorldSpawn.java @@ -10,7 +10,7 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class SetVanillaWorldSpawn { +public class SetVanillaWorldSpawn implements CommandExecutor{ private TreeboTeleport pl; @@ -46,4 +46,16 @@ public boolean execute(CommandSender sender, String label, String[] args) { return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + World w = ((Player) sender).getWorld(); + sender.sendMessage(pl.badge + "Current Vanilla World Spawn: " + w.getSpawnLocation().toString()); + Location pLoc = ((Player) sender).getLocation(); + w.setSpawnLocation(pLoc); + sender.sendMessage(pl.badge + "Set Vanilla World Spawn to: " + w.getSpawnLocation().toString()); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWarp.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWarp.java index d33edc5..3db3f40 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWarp.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWarp.java @@ -16,7 +16,7 @@ import java.io.FileNotFoundException; import java.io.IOException; -public class SetWarp { +public class SetWarp implements CommandExecutor{ private TreeboTeleport pl; @@ -96,4 +96,61 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + File warpsYml = new File(pl.getDataFolder(), File.separator + "warps.yml"); + if (!warpsYml.exists()) { + sender.sendMessage(pl.err + "Warps data not found. Attempting to recover."); + try { + warpsYml.createNewFile(); + FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); + try { + warps.options().copyDefaults(); + warps.save(warpsYml); + } catch (FileNotFoundException ex) { + pl.roots.errorLogger.logError(pl, ex); + } + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + sender.sendMessage(pl.err + "Creating warps file failed"); + } + } + FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); + Player p = (Player) sender; + Location loc = p.getLocation(); + String world = loc.getWorld().getName(); + double x = loc.getX(); + double y = loc.getY(); + double z = loc.getZ(); + float pitch = loc.getPitch(); + float yaw = loc.getYaw(); + if (args.length == 0) { + p.sendMessage(pl.err + "You must provide a name for your new warp"); + } else if (args.length > 2) { + p.sendMessage(pl.err + "Too many arguments"); + } else { + String name = args[0]; + args[0] = args[0].toLowerCase(); + warps.set("warps." + args[0] + ".name", name); + warps.set("warps." + args[0] + ".world", world); + warps.set("warps." + args[0] + ".x", x); + warps.set("warps." + args[0] + ".y", y); + warps.set("warps." + args[0] + ".z", z); + warps.set("warps." + args[0] + ".pitch", pitch); + warps.set("warps." + args[0] + ".yaw", yaw); + if (args.length > 1) { + warps.set("warps." + args[0] + ".requiredPermission", args[1]); + } + + try { + warps.save(warpsYml); + p.sendMessage(pl.badge + "Warp with name: " + ChatColor.GOLD + args[0] + ChatColor.RESET + " has been saved."); + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + p.sendMessage(pl.err + "Saving warps file Unsuccessful"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWorldSpawn.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWorldSpawn.java index a34e32f..c317d1a 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWorldSpawn.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/SetWorldSpawn.java @@ -104,10 +104,63 @@ public boolean execute(CommandSender sender, String label, String[] args) { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (!pl.getConfig().getBoolean("disabledCommands.setworldspawn")) { + File spawnsYml = new File(pl.getDataFolder(), "spawns.yml"); + if (!spawnsYml.exists()) { + sender.sendMessage("Spawns file not found"); + try { + spawnsYml.createNewFile(); + FileConfiguration spawns = YamlConfiguration.loadConfiguration(spawnsYml); + try { + spawns.options().copyDefaults(); + spawns.save(spawnsYml); + } catch (FileNotFoundException ex) { + pl.roots.errorLogger.logError(pl, ex); + } + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + sender.sendMessage(pl.badge + ChatColor.RED + "ERROR:" + ChatColor.RESET + "Creating Spawns file failed"); + } + } + FileConfiguration spawns = YamlConfiguration.loadConfiguration(spawnsYml); + Player p = (Player) sender; + Location loc = p.getLocation(); + String world = loc.getWorld().getName(); + double x = loc.getX(); + double y = loc.getY(); + double z = loc.getZ(); + float pitch = loc.getPitch(); + float yaw = loc.getYaw(); + if (args.length < 2) { + String name = world; + spawns.set("spawns." + name + ".name", name); + spawns.set("spawns." + name + ".world", world); + spawns.set("spawns." + name + ".x", x); + spawns.set("spawns." + name + ".y", y); + spawns.set("spawns." + name + ".z", z); + spawns.set("spawns." + name + ".pitch", pitch); + spawns.set("spawns." + name + ".yaw", yaw); + sender.sendMessage(pl.badge + "Spawn location set"); + if (args.length == 1 && args[0].equalsIgnoreCase("true")) { + 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); + sender.sendMessage(pl.badge + "Enabled on join spawn for this world"); + } + pl.saveConfig(); + - } else { - sender.sendMessage(pl.err + "The command /" + cmd + " has been disabled on this server"); + try { + spawns.save(spawnsYml); + p.sendMessage(pl.badge + "World spawn saved for world: " + ChatColor.YELLOW + "[" + ChatColor.GOLD + name + ChatColor.YELLOW + "]"); + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + p.sendMessage(pl.err + "Saving spawns file Unsuccessful"); + } + } else if (args.length > 1) { + p.sendMessage(pl.err + "Too many arguments"); } return true; diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Shop.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Shop.java index db849d4..c377052 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Shop.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Shop.java @@ -11,7 +11,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.PlayerDeathEvent; -public class Shop { +public class Shop implements CommandExecutor{ private TreeboTeleport pl; @@ -55,4 +55,25 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player p = (Player) sender; + + if (pl.getConfig().isSet("shop." + p.getWorld().getName() + ".world")) { + String world = pl.getConfig().getString("shop." + p.getWorld().getName() + ".world"); + double x = pl.getConfig().getDouble("shop." + p.getWorld().getName() + ".x"); + double y = pl.getConfig().getDouble("shop." + p.getWorld().getName() + ".y"); + double z = pl.getConfig().getDouble("shop." + p.getWorld().getName() + ".z"); + float pitch = (float) pl.getConfig().getDouble("shop." + p.getWorld().getName() + ".pitch"); + float yaw = (float) pl.getConfig().getDouble("shop." + p.getWorld().getName() + ".yaw"); + Location shopLoc = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch); + p.teleport(shopLoc); + } + } else { + sender.sendMessage(pl.err + "This command can only be run by a player."); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ShowMaxHomes.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ShowMaxHomes.java index 9587b1b..5a9a319 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ShowMaxHomes.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ShowMaxHomes.java @@ -9,7 +9,7 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class ShowMaxHomes { +public class ShowMaxHomes implements CommandExecutor{ private TreeboTeleport pl; @@ -59,4 +59,16 @@ private int getHomes(Player p) { } return maxHomes; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 1) { + sender.sendMessage(pl.err + "Incorrect usage. Correct usage is /showmaxhomes "); + } else { + Player p = Bukkit.getOfflinePlayer(args[0]).getPlayer(); + int currentMaxHomes = getHomes(p); + sender.sendMessage("Player: " + p + " has a maximum of " + currentMaxHomes + "Homes"); + } + return true; + } } \ No newline at end of file diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Spawn.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Spawn.java index 9da3313..39f9f0b 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Spawn.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Spawn.java @@ -18,7 +18,7 @@ import java.io.IOException; import java.util.HashMap; -public class Spawn { +public class Spawn implements CommandExecutor{ private TreeboTeleport pl; private HashMap spawnsHash = new HashMap(); @@ -89,4 +89,51 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + File spawnsYml = new File(pl.getDataFolder(), File.separator + "spawns.yml"); + + if (!spawnsYml.exists()) { + sender.sendMessage(pl.err + "Failed to load Spawns data. Attempting to recover"); + try { + spawnsYml.createNewFile(); + FileConfiguration spawns = YamlConfiguration.loadConfiguration(spawnsYml); + try { + spawns.options().copyDefaults(); + spawns.save(spawnsYml); + } catch (FileNotFoundException ex) { + pl.roots.errorLogger.logError(pl, ex); + } + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + sender.sendMessage(pl.err + "Loading Spawns Data Unsuccessful"); + } + } + FileConfiguration spawns = YamlConfiguration.loadConfiguration(spawnsYml); + + for (String key : spawns.getConfigurationSection("spawns").getKeys(false)) { + String world = spawns.getString("spawns." + key + ".world"); + int x = spawns.getInt("spawns." + key + ".x"); + int y = spawns.getInt("spawns." + key + ".y"); + int z = spawns.getInt("spawns." + key + ".z"); + float yaw = (float) spawns.getDouble("spawns." + key + ".yaw"); + float pitch = (float) spawns.getDouble("spawns." + key + ".pitch"); + Location worldSpawn = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch); + spawnsHash.putIfAbsent(key, worldSpawn); + } + //} + Player p = (Player) sender; + + + if (spawnsHash.containsKey(p.getWorld().getName())) { + Location loc = (Location) spawnsHash.get(p.getWorld().getName()); + p.sendMessage(pl.badge + "Returning you to Spawn"); + p.teleport(loc); + } else { + p.sendMessage(pl.err + "No spawn found for this world"); + } + + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ToggleDeathDocket.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ToggleDeathDocket.java index 0088399..7cc2c2b 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/ToggleDeathDocket.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/ToggleDeathDocket.java @@ -9,7 +9,7 @@ import org.bukkit.entity.Player; -public class ToggleDeathDocket { +public class ToggleDeathDocket implements CommandExecutor{ private TreeboTeleport pl; @@ -47,4 +47,19 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player p = (Player) sender; + if (pl.getConfig().get("deathDocket.toggle." + p.getUniqueId()) == null || pl.getConfig().get("deathDocket.toggle." + p.getUniqueId()).equals("false")) { + pl.getConfig().set("deathDocket.toggle." + p.getUniqueId(), "true"); + } else { + pl.getConfig().set("deathDocket.toggle." + p.getUniqueId(), "false"); + } + } else { + sender.sendMessage(pl.err + "Only players can run this command"); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Top.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Top.java index 6a8d3cf..3acc65d 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Top.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Top.java @@ -6,11 +6,13 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class Top { +public class Top implements CommandExecutor { private TreeboTeleport pl; @@ -64,4 +66,35 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player p = (Player) sender; + Location bLoc = p.getLocation().getBlock().getLocation(); + int i = 256; + if(p.getWorld().getEnvironment() == World.Environment.NETHER){ + i = 127; + } + for (i = i; i > 0; i--) { + Block block = bLoc.getWorld().getBlockAt((int) bLoc.getX(), i, (int) bLoc.getZ()); + Block buu = bLoc.getWorld().getBlockAt((int) bLoc.getX(), i + 2, (int) bLoc.getZ()); + Block buu2 = bLoc.getWorld().getBlockAt((int) bLoc.getX(), i + 1, (int) bLoc.getZ()); + Location tempLoc = p.getLocation(); + if ((!(block.getType() == Material.AIR) + && !(block.getType() == Material.LAVA) + && !(block.getType() == Material.CACTUS) + && !(block.getType() == Material.NETHER_PORTAL) + && !(block.getType() == Material.END_GATEWAY) + && !(block.getType() == Material.END_GATEWAY) + ) && buu.getType() == Material.AIR && buu2.getType() == Material.AIR + ) { + tempLoc = buu.getLocation(); + p.teleport(tempLoc); + break; + } + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Me.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Me.java index df4e2b1..b84e521 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Me.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Me.java @@ -11,7 +11,7 @@ import java.util.Iterator; -public class Tp2Me { +public class Tp2Me implements CommandExecutor{ private TreeboTeleport pl; @@ -62,4 +62,32 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (sender instanceof Player) { + Player player = (Player) sender; + if (args.length == 0) { + player.sendMessage(pl.err + "This command requires a player argument"); + } else if (args.length == 1) { + Player targetPlayer = null; + Iterator iter = Bukkit.getOnlinePlayers().iterator(); + while (iter.hasNext()) { + Player it = (Player) iter.next(); + if (it.getName().equalsIgnoreCase(args[0])) { + targetPlayer = it; + } + } + if (targetPlayer != null) { + targetPlayer.teleport(player); + } else { + sender.sendMessage(pl.err + "Unable to find player with name " + ChatColor.GREEN + args[0]); + sender.sendMessage("Are you sure they are on this server?"); + } + } else { + sender.sendMessage(pl.err + "This command only supports one argument"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2MePls.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2MePls.java index 71a17b6..9b47bbc 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2MePls.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2MePls.java @@ -14,7 +14,7 @@ import java.time.Instant; import java.util.Iterator; -public class Tp2MePls { +public class Tp2MePls implements CommandExecutor{ private TreeboTeleport pl; private BungeeSend bungeeSend; @@ -78,4 +78,43 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (args.length == 1) { + boolean foundPlayer = false; + + Iterator iter = Bukkit.getOnlinePlayers().iterator(); + while (iter.hasNext()) { + Player p = (Player) iter.next(); + if (p.getName().equalsIgnoreCase(args[0])) { + foundPlayer = true; + String command = ""; + if (pl.getConfig().get("tpRequest." + sender.getName()) == null || (System.currentTimeMillis() - 30000) > pl.getConfig().getLong("tpRequest." + sender.getName() + ".requestTime")) { + + if (pl.getConfig().get("tptoggle." + p.getName()) == null || pl.getConfig().getInt("tptoggle." + p.getName()) == 0) { + sender.sendMessage(pl.badge + "Request to teleport " + p.getName() + " to your location sent."); + p.sendMessage("Player " + ChatColor.GOLD + sender.getName() + ChatColor.RESET + " would like you to teleport " + ChatColor.GOLD + "TO THEM"); + command = "tellraw " + p.getName() + " [\"\",{\"text\":\"Please type \"},{\"text\":\"/tpok\",\"color\":\"green\"},{\"text\":\" or click \"},{\"text\":\"[HERE]\",\"color\":\"gold\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/tpok\"}},{\"text\":\" in the next \"},{\"text\":\"30 Seconds\",\"color\":\"green\"},{\"text\":\" to Accept\"}]"; + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + pl.getConfig().set("tpRequest." + p.getName() + ".type", "toSender"); + pl.getConfig().set("tpRequest." + p.getName() + ".requestTime", System.currentTimeMillis()); + pl.getConfig().set("tpRequest." + p.getName() + ".requester", sender.getName()); + } else { + sender.sendMessage(pl.err + p.getName() + " has disabled incomming teleport requests"); + } + } else { + sender.sendMessage(pl.err + "You already have a pending teleport request."); + } + } + } + if (!foundPlayer) { + sender.sendMessage(pl.err + "Player " + ChatColor.GOLD + args[0] + ChatColor.RESET + " was not found on this server. Attempting to locate on other servers"); + bungeeSend.sendPluginMessage("CrossServerTPAHere", "ALL", "toSender," + sender.getName() + "," + args[0]); + } + } else { + sender.sendMessage(pl.err + "This command requires a single player argument"); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Player.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Player.java index 57a39da..4904578 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Player.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Player.java @@ -11,7 +11,7 @@ import java.util.Iterator; -public class Tp2Player { +public class Tp2Player implements CommandExecutor{ private TreeboTeleport pl; @@ -61,4 +61,29 @@ public boolean execute(CommandSender sender, String label, String[] args) { return true; } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length == 0) { + sender.sendMessage(pl.err + "This command requires a player argument"); + } else if (args.length == 1) { + Player targetPlayer = null; + Iterator iter = Bukkit.getOnlinePlayers().iterator(); + while (iter.hasNext()) { + Player p = (Player) iter.next(); + if (p.getName().equalsIgnoreCase(args[0])) { + targetPlayer = p; + break; + } + } + if (targetPlayer != null) { + ((Player) sender).teleport(targetPlayer); + } else { + sender.sendMessage(pl.err + "Unable to find player with name " + ChatColor.GOLD + args[0]); + sender.sendMessage("Are you sure they are on this server?"); + } + } else { + sender.sendMessage(pl.err + "This command only supports one argument"); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Pos.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Pos.java index 3b9c504..79bd64f 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Pos.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2Pos.java @@ -10,7 +10,7 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class Tp2Pos { +public class Tp2Pos implements CommandExecutor{ private TreeboTeleport pl; @@ -86,4 +86,57 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length == 1) { + if (args[0].split(",").length == 3) { + String a1 = args[0].split(",")[0]; + String a2 = args[0].split(",")[1]; + String a3 = args[0].split(",")[2]; + if (pl.isInteger(a1) && pl.isInteger(a2) && pl.isInteger(a3)) { + int i1 = Integer.parseInt(a1); + int i2 = Integer.parseInt(a2); + int i3 = Integer.parseInt(a3); + Location tpLoc = ((Player) sender).getWorld().getBlockAt(i1, i2, i3).getLocation().add(0, 1, 0); + ((Player) sender).teleport(tpLoc); + } else { + sender.sendMessage(pl.err + "Invalid coordinate format"); + } + } else if (args[0].split(",").length == 2) { + String a1 = args[0].split(",")[0]; + String a3 = args[0].split(",")[1]; + if (pl.isInteger(a1) && pl.isInteger(a3)) { + int i1 = Integer.parseInt(a1); + int i3 = Integer.parseInt(a3); + int i2 = ((Player) sender).getWorld().getHighestBlockYAt(i1, i3); + Location tpLoc = ((Player) sender).getWorld().getBlockAt(i1, i2, i3).getLocation().add(0, 1, 0); + ((Player) sender).teleport(tpLoc); + } else { + sender.sendMessage(pl.err + "Invalid coordinate format"); + } + } + } else if (args.length == 2) { + if (pl.isInteger(args[0]) && pl.isInteger(args[1])) { + int i1 = Integer.parseInt(args[0]); + int i3 = Integer.parseInt(args[1]); + int i2 = ((Player) sender).getWorld().getHighestBlockYAt(i1, i3); + Location tpLoc = ((Player) sender).getWorld().getBlockAt(i1, i2, i3).getLocation().add(0, 1, 0); + ((Player) sender).teleport(tpLoc); + } else { + sender.sendMessage(pl.err + "Invalid Coordinate format"); + } + } else if (args.length == 3) { + if (pl.isInteger(args[0]) && pl.isInteger(args[1]) && pl.isInteger(args[2])) { + int i1 = Integer.parseInt(args[0]); + int i2 = Integer.parseInt(args[1]); + int i3 = Integer.parseInt(args[2]); + Location tpLoc = ((Player) sender).getWorld().getBlockAt(i1, i2, i3).getLocation().add(0, 1, 0); + ((Player) sender).teleport(tpLoc); + } else { + sender.sendMessage(pl.err + "Invalid coordinate format"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2WorldAt.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2WorldAt.java index 6cfefc9..7354c01 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2WorldAt.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Tp2WorldAt.java @@ -10,7 +10,7 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; -public class Tp2WorldAt { +public class Tp2WorldAt implements CommandExecutor{ private TreeboTeleport pl; @@ -91,4 +91,62 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + try { + if (args.length == 2) { + if (args[1].split(",").length == 3) { + String a1 = args[1].split(",")[0]; + String a2 = args[1].split(",")[1]; + String a3 = args[1].split(",")[2]; + if (pl.isInteger(a1) && pl.isInteger(a2) && pl.isInteger(a3)) { + int i1 = Integer.parseInt(a1); + int i2 = Integer.parseInt(a2); + int i3 = Integer.parseInt(a3); + Location tpLoc = Bukkit.getWorld(args[0]).getBlockAt(i1, i2, i3).getLocation().add(0, 1, 0); + ((Player) sender).teleport(tpLoc); + } else { + sender.sendMessage(pl.err + "Invalid coordinate format or world name"); + } + } else if (args[1].split(",").length == 2) { + String a1 = args[1].split(",")[0]; + String a3 = args[1].split(",")[1]; + if (pl.isInteger(a1) && pl.isInteger(a3)) { + int i1 = Integer.parseInt(a1); + int i3 = Integer.parseInt(a3); + int i2 = Bukkit.getWorld(args[0]).getHighestBlockYAt(i1, i3); + Location tpLoc = Bukkit.getWorld(args[0]).getBlockAt(i1, i2, i3).getLocation().add(0, 1, 0); + ((Player) sender).teleport(tpLoc); + } else { + sender.sendMessage(pl.err + "Invalid coordinate format or world name"); + } + } + } else if (args.length == 3) { + if (pl.isInteger(args[1]) && pl.isInteger(args[2])) { + int i1 = Integer.parseInt(args[1]); + int i3 = Integer.parseInt(args[2]); + int i2 = Bukkit.getWorld(args[0]).getHighestBlockYAt(i1, i3); + Location tpLoc = Bukkit.getWorld(args[0]).getBlockAt(i1, i2, i3).getLocation().add(0, 1, 0); + ((Player) sender).teleport(tpLoc); + } else { + sender.sendMessage(pl.err + " Invalid Coordinate format or world name"); + } + } else if (args.length == 4) { + if (pl.isInteger(args[3]) && pl.isInteger(args[1]) && pl.isInteger(args[2])) { + int i1 = Integer.parseInt(args[1]); + int i2 = Integer.parseInt(args[2]); + int i3 = Integer.parseInt(args[3]); + Location tpLoc = Bukkit.getWorld(args[0]).getBlockAt(i1, i2, i3).getLocation().add(0, 1, 0); + ((Player) sender).teleport(tpLoc); + } else { + sender.sendMessage(pl.err + " Invalid coordinate format or world name"); + } + } + } catch (NullPointerException ex) { + pl.roots.errorLogger.logError(pl, ex); + sender.sendMessage(pl.err + "Could not achieve teleport. Is the world loaded?"); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpNo.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpNo.java index efc9f84..2c7df64 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpNo.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpNo.java @@ -11,7 +11,7 @@ import org.bukkit.entity.Player; -public class TpNo { +public class TpNo implements CommandExecutor{ private TreeboTeleport pl; @@ -52,4 +52,22 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + pl.getConfig().set("tpRequest." + p.getName() + ".type", "toSender"); + pl.getConfig().set("tpRequest." + p.getName() + ".requestTime", 0); + pl.getConfig().set("tpRequest." + p.getName() + ".requester", sender.getName()); + sender.sendMessage("Teleport request has been denied."); + + for (OfflinePlayer offPlayer : Bukkit.getOfflinePlayers()) { + if (offPlayer.getName().equalsIgnoreCase(pl.getConfig().getString("tpRequest." + p.getName() + ".requester"))) { + if (offPlayer instanceof Player) { + ((Player) offPlayer).sendMessage(pl.badge + p.getName() + "has denied your teleport request."); + } + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpOk.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpOk.java index 6e33953..a84806f 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpOk.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpOk.java @@ -13,7 +13,7 @@ import java.util.Iterator; -public class TpOk { +public class TpOk implements CommandExecutor{ private TreeboTeleport pl; private BungeeSend bungeeSend; @@ -93,4 +93,59 @@ else if (type.equalsIgnoreCase("toSender")){ } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length == 0) { + Player targetPlayer = null; + + if (pl.getConfig().get("tpRequest." + sender.getName()) != null && (System.currentTimeMillis() - 30000) < pl.getConfig().getLong("tpRequest." + sender.getName() + ".requestTime")) { + String type = pl.getConfig().getString("tpRequest." + sender.getName() + ".type"); + String requester = pl.getConfig().getString("tpRequest." + sender.getName() + ".requester"); + Iterator iter = Bukkit.getOnlinePlayers().iterator(); + while (iter.hasNext()) { + Player p = (Player) iter.next(); + if (p.getName().equalsIgnoreCase(requester)) { + targetPlayer = p; + } + } + if (targetPlayer != null) { + if (type.equalsIgnoreCase("toPlayer")) { + targetPlayer.teleport((Player) sender); + pl.getConfig().set("tpRequest." + sender.getName() + ".requestTime", 0); + } else if (type.equalsIgnoreCase("toSender")) { + ((Player) sender).teleport(targetPlayer); + pl.getConfig().set("tpRequest." + sender.getName() + ".requestTime", 0); + } else { + sender.sendMessage(pl.err + "Invalid teleport Type"); + } + } else { + sender.sendMessage(pl.err + "Requesting player is not on this server. Attempting to locate."); + sender.sendMessage("You will not receive a fail message."); + if(type.equalsIgnoreCase("toPlayer")){ + + + bungeeSend.sendConnectOther(pl.getConfig().getString("general.serverName"), requester); + Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + @Override + public void run() { + Player telporter = Bukkit.getPlayer(requester); + Player reciever = (Player) sender; + + telporter.teleport(reciever); + } + }, 40L); + } + else if (type.equalsIgnoreCase("toSender")){ + bungeeSend.sendPluginMessage("CrossServerTeleport", "ALL", sender.getName() + "," + requester); + } + } + } else { + sender.sendMessage(pl.err + "Cannot find teleport request"); + } + } else { + sender.sendMessage(pl.err + "Incorrect usage. This command does not accept any arguments"); + } + return true; + } } \ No newline at end of file diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpToggle.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpToggle.java index f1074f9..03ed613 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpToggle.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/TpToggle.java @@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; -public class TpToggle { +public class TpToggle implements CommandExecutor{ private TreeboTeleport pl; @@ -47,4 +47,18 @@ public boolean execute(CommandSender sender, String label, String[] args) { return true; } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (pl.getConfig().get("tptoggle." + pl.getName()) == null) { + pl.getConfig().set("tptoggle." + pl.getName(), 1); + sender.sendMessage(pl.badge + "Teleport requests have been toggled OFF"); + } else if (pl.getConfig().getInt("tptoggle." + sender.getName()) == 1) { + pl.getConfig().set("tptoggle." + sender.getName(), 0); + sender.sendMessage(pl.badge + "Teleport requests have been toggled ON"); + } else if (pl.getConfig().getInt("tptoggle." + sender.getName()) == 0) { + pl.getConfig().set("tptoggle." + sender.getName(), 1); + sender.sendMessage(pl.badge + "Teleport requests have been toggled OFF"); + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Version.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Version.java index 1407f80..96ae190 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Version.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Version.java @@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; -public class Version { +public class Version implements CommandExecutor{ private TreeboTeleport pl; @@ -37,4 +37,11 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + sender.sendMessage(pl.badge + "Version - " + pl.getDescription().getVersion()); + + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/WarpTo.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/WarpTo.java index 61ffcc6..a300fb6 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/WarpTo.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/WarpTo.java @@ -18,7 +18,7 @@ import java.io.FileNotFoundException; import java.io.IOException; -public class WarpTo { +public class WarpTo implements CommandExecutor{ private TreeboTeleport pl; private OpenWarpsMenu openWarpsMenu; @@ -103,4 +103,62 @@ public boolean execute(CommandSender sender, String label, String[] args) { } return true; } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + File warpsYml = new File(pl.getDataFolder(), "warps.yml"); + if (!warpsYml.exists()) { + System.out.println(pl.err + "Warps data not found. Attempting to recover"); + try { + warpsYml.createNewFile(); + FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); + try { + warps.options().copyDefaults(); + warps.save(warpsYml); + } catch (FileNotFoundException ex) { + pl.roots.errorLogger.logError(pl, ex); + } + } catch (IOException ex) { + pl.roots.errorLogger.logError(pl, ex); + System.out.println(pl.err + "Creating warps file failed"); + } + } + FileConfiguration warps = YamlConfiguration.loadConfiguration(warpsYml); + + + Player p = (Player) sender; + if (args.length == 0) { + openWarpsMenu.openWarpsMenu(p); + + } else if (args.length > 1) { + p.sendMessage(pl.err + "Too many arguments"); + } else { + args[0] = args[0].toLowerCase(); + if (warps.get("warps." + args[0] + ".x") != null) { + boolean okWarp = false; + if (warps.get("warps." + args[0] + ".requiredPermission") == null) { + okWarp = true; + } else if (sender.hasPermission(warps.getString("warps." + args[0] + ".requiredPermission"))) { + okWarp = true; + } + + String world = warps.getString("warps." + args[0] + ".world"); + double x = warps.getDouble("warps." + args[0] + ".x"); + double y = warps.getDouble("warps." + args[0] + ".y"); + double z = warps.getDouble("warps." + args[0] + ".z"); + float pitch = (float) warps.getDouble("warps." + args[0] + ".pitch"); + float yaw = (float) warps.getDouble("warps." + args[0] + ".yaw"); + Location loc = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch); + p.sendMessage(pl.badge + "Warping you to: " + ChatColor.GOLD + args[0]); + if (okWarp) { + p.teleport(loc); + } else { + p.sendMessage(pl.err + "You lack the permissions required to use that warp"); + } + } else { + p.sendMessage(pl.err + "No warp found with that name"); + } + } + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild2.java b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild2.java index 32a2dba..f32bf89 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild2.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/Commands/Wild2.java @@ -3,6 +3,8 @@ import me.shakeforprotein.treeboteleport.TreeboTeleport; import org.bukkit.*; import org.bukkit.block.Block; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; @@ -12,7 +14,7 @@ import java.util.Random; import java.util.concurrent.ThreadLocalRandom; -public class Wild2 { +public class Wild2 implements CommandExecutor { public int minX; public int maxX; @@ -386,5 +388,27 @@ public boolean isDangerous(Material material) { return false; } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + minX = (pl.getConfig().getString("wild.minX") != null) ? pl.getConfig().getInt("wild.minX") : -50000; + maxX = (pl.getConfig().getString("wild.maxX") != null) ? pl.getConfig().getInt("wild.maxX") : 50000; + minZ = (pl.getConfig().getString("wild.minZ") != null) ? pl.getConfig().getInt("wild.minZ") : -50000; + maxZ = (pl.getConfig().getString("wild.maxZ") != null) ? pl.getConfig().getInt("wild.maxZ") : 50000; + + + if (sender instanceof Player) { + Player player = (Player) sender; + if (player.getWorld().getName().toLowerCase().contains("grid")) { + limit = 10; + } + if (args.length == 0) { + doWild(player); + } else if (args.length == 1 && !isNumeric(args[0])) { + doStaffWild(player, args[0]); + } + } + + return true; + } } diff --git a/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java b/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java index e7e11c2..45ba5b0 100644 --- a/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java +++ b/src/main/java/me/shakeforprotein/treeboteleport/TreeboTeleport.java @@ -24,7 +24,6 @@ import java.io.*; import java.lang.reflect.Field; -import java.nio.file.Files; import java.sql.*; import java.time.LocalDateTime; import java.util.ArrayList; @@ -205,14 +204,22 @@ public ItemStack getHubItemFromConfig() { } public void registerNewCommand(String fallback, BukkitCommand command) { - try { + /*try { + Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap"); bukkitCommandMap.setAccessible(true); CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer()); + + if(commandMap.getCommand(command.getName()) != null){ + System.out.println("Command: " + command.getName() + " - has already been registered by " + Bukkit.getPluginCommand(command.getName()).getPlugin().getDescription().getName()); + Bukkit.broadcastMessage("Command: " + command.getName() + " - has already been registered by " + Bukkit.getPluginCommand(command.getName()).getPlugin().getDescription().getName()); + } commandMap.register(fallback, command); } catch (IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException e) { e.printStackTrace(); } + + */ } public void saveFileConfigurationToFile(File file, FileConfiguration conf, CommandSender s) { @@ -350,67 +357,115 @@ public static boolean isInteger(String s) { @SuppressWarnings("ConstantConditions") private void registerCommands(){ - addMaxHomes.register("AddMaxHomes"); - bed.register("Bed"); - clearMyChat.register("ClearMyChat"); - configureHomes.register("ConfigureHomes"); - configureHubMenu.register("ConfigureHubMenu"); - configureWarps.register("ConfigureWarps"); - deleteHome.register("DeleteHome"); - deleteHome.register("DelHome"); - deleteWarp.register("DeleteWarp"); - deleteWarp.register("DelWarp"); - disableTpSafety.register("DisableTpSafety"); - disableTpSafety.register("ToggleTpSafety"); - getWorldSpawn.register("gws"); - getWorldSpawn.register("GetWorldSpawn"); - hub.register("Hub"); - nameIt.register("NameIt"); - reload.register("ttelereload"); - restorePlayerInventory.register("RestorePlayerInventory"); - saveConfig.register("ttelesaveconfig"); - sendSpawn.register("SendSpawn"); - setShop.register("SetShop"); - setTTeleCooldown.register("SetTTeleCoolDown"); - setVanillaWorldSpawn.register("SetVanillaWorldSpawn"); - setWarp.register("SetWarp"); - setWorldSpawn.register("SetWorldSpawn"); - shop.register("Shop"); - showMaxHomes.register("ShowMaxHomes"); - spawn.register("Spawn"); - //toggleDeathDocket.register("ToggleDeathDocket"); - getCommand("tp").setExecutor(tp); - getCommand("tp").setTabCompleter(new TabCompleterTp()); - if (getConfig().getBoolean("disabledCommands.tp")) { - unRegisterBukkitCommand(getCommand("tp")); - } - - tp2Me.register("tp2me"); - tp2Me.register("tphere"); - //disable these for hardcore - back.register("Back"); - giveHubItem.register("GiveHubItem"); - home.register("Home"); - homes.register("Homes"); - mayITp.register("MayITp"); - mayITp.register("tpa"); - mayITp.register("tpask"); - setHome.register("SetHome"); - tp2MePls.register("tp2mePls"); - tp2MePls.register("tpahere"); - tpNo.register("tpno"); - tpNo.register("tpdeny"); - tpOk.register("tpok"); - tpOk.register("tpyes"); - tpToggle.register("tptoggle"); - top.register("top"); - //disable above for hardcore - version.register("tteleversion"); - warpTo.register("warp"); - warpTo.register("warps"); - wild.register("wild"); - jsaw.register("jsaw"); - //tp2Player.register + try { + /*addMaxHomes.register("AddMaxHomes"); + configureHubMenu.register("ConfigureHubMenu"); + configureHomes.register("ConfigureHomes"); + bed.register("Bed"); + clearMyChat.register("ClearMyChat"); + configureWarps.register("ConfigureWarps"); + deleteHome.register("DeleteHome"); + deleteHome.register("DelHome"); + deleteWarp.register("DeleteWarp"); + deleteWarp.register("DelWarp"); + //disableTpSafety.register("DisableTpSafety"); + disableTpSafety.register("ToggleTpSafety"); + getWorldSpawn.register("gws"); + getWorldSpawn.register("GetWorldSpawn"); + //hub.register("Hub"); + //nameIt.register("NameIt"); + reload.register("ttelereload"); + restorePlayerInventory.register("RestorePlayerInventory"); + saveConfig.register("ttelesaveconfig"); + sendSpawn.register("SendSpawn"); + setShop.register("SetShop"); + setTTeleCooldown.register("SetTTeleCoolDown"); + setWarp.register("SetWarp"); + setWorldSpawn.register("SetWorldSpawn"); + shop.register("Shop"); + showMaxHomes.register("ShowMaxHomes"); + spawn.register("Spawn"); + tp2Me.register("tp2me"); + tp2Me.register("tphere"); + //disable these for hardcore + back.register("Back"); + giveHubItem.register("GiveHubItem"); + home.register("Home"); + homes.register("Homes"); + mayITp.register("MayITp"); + mayITp.register("tpa"); + mayITp.register("tpask"); + setHome.register("SetHome"); + tp2MePls.register("tp2mePls"); + tp2MePls.register("tpahere"); + tpNo.register("tpno"); + tpNo.register("tpdeny"); + tpOk.register("tpok"); + tpOk.register("tpyes"); + tpToggle.register("tptoggle"); + version.register("tteleversion"); + warpTo.register("warp"); + warpTo.register("warps"); + wild.register("wild"); + jsaw.register("jsaw"); + setVanillaWorldSpawn.register("SetVanillaWorldSpawn"); + top.register("top"); + //toggleDeathDocket.register("ToggleDeathDocket"); + Bukkit.broadcastMessage("registering commands");*/ + + + this.getCommand("addmaxhomes").setExecutor(new AddMaxHomes(this)); + this.getCommand("back").setExecutor(new Back(this)); + this.getCommand("bed").setExecutor(new Bed(this)); + this.getCommand("clearmychat").setExecutor(new ClearMyChat(this)); + this.getCommand("configurehomes").setExecutor(new ConfigureHubMenu(this)); + this.getCommand("configurehubmenu").setExecutor(new ConfigureHubMenu(this)); + this.getCommand("configurewarps").setExecutor(new ConfigureWarps(this)); + this.getCommand("deletehome").setExecutor(new DeleteHome(this)); + this.getCommand("deletewarp").setExecutor(new DeleteWarp(this)); + this.getCommand("delhome").setExecutor(new DeleteHome(this)); + this.getCommand("delwarp").setExecutor(new DeleteWarp(this)); + this.getCommand("getworldspawn").setExecutor(new GetWorldSpawn(this)); + this.getCommand("givehubitem").setExecutor(new GiveHubItem(this)); + this.getCommand("gws").setExecutor(new GetWorldSpawn(this)); + this.getCommand("home").setExecutor(new Home(this)); + this.getCommand("homes").setExecutor(new Homes(this)); + this.getCommand("jsaw").setExecutor(new JoinServerAtWorld(this)); + this.getCommand("restoreplayerinventory").setExecutor(new RestorePlayerInventory(this)); + this.getCommand("sendspawn").setExecutor(new SendSpawn(this)); + this.getCommand("sethome").setExecutor(new SetHome(this)); + this.getCommand("setshop").setExecutor(new SetShop(this)); + this.getCommand("setttelecooldown").setExecutor(new SetTTeleCooldown(this)); + this.getCommand("setvanillaworldspawn").setExecutor(new SetVanillaWorldSpawn(this)); + this.getCommand("setwarp").setExecutor(new SetWarp(this)); + this.getCommand("setworldspawn").setExecutor(new SetWorldSpawn(this)); + this.getCommand("shop").setExecutor(new Shop(this)); + this.getCommand("showmaxhomes").setExecutor(new ShowMaxHomes(this)); + this.getCommand("spawn").setExecutor(new Spawn(this)); + this.getCommand("toggletpsafety").setExecutor(new DisableTpSafety(this)); + this.getCommand("top").setExecutor(new Top(this)); + this.getCommand("tp").setExecutor(tp); + this.getCommand("tp").setTabCompleter(new TabCompleterTp()); + this.getCommand("tp2mepls").setExecutor(new Tp2MePls(this)); + this.getCommand("tpa").setExecutor(new MayITp(this)); + this.getCommand("tpahere").setExecutor(new Tp2MePls(this)); + this.getCommand("tpask").setExecutor(new MayITp(this)); + this.getCommand("tpdeny").setExecutor(new TpNo(this)); + this.getCommand("tpno").setExecutor(new TpNo(this)); + this.getCommand("tpok").setExecutor(new TpOk(this)); + this.getCommand("tptoggle").setExecutor(new TpToggle(this)); + this.getCommand("tpyes").setExecutor(new TpOk(this)); + this.getCommand("ttelereload").setExecutor(new Reload(this)); + this.getCommand("ttelesaveconfig").setExecutor(new SaveConfig(this)); + this.getCommand("version").setExecutor(new Version(this)); + this.getCommand("warp").setExecutor(new WarpTo(this)); + this.getCommand("warps").setExecutor(new WarpTo(this)); + this.getCommand("wild").setExecutor(new Wild2(this)); + Bukkit.broadcastMessage("done registering commands"); + } catch (NullPointerException ex){ + + Bukkit.broadcastMessage(ex.getLocalizedMessage()); + } } private void registerEventHandlers(){ diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 31dc4b9..da0afdf 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,178 +8,142 @@ description: Teleport and Hub functions website: treebo.games depend: [TreeboRoots] softdepend: [StaffUUIDLock] + commands: -# spawn: -# description: 'Allows a player to return to spawn as defined in spawns.yml' -# usage: -# permission: tbteleport.player.spawn -# hub: -# description: 'Opens Hub Gui as defined in hubmenu.yml' -# usage: -# permission: tbteleport.player.hub -# givehubitem: -# description: 'Gives command sender the hub item' -# usage: -# permission: tbteleport.player.givehubitem -# wild: -# description: 'Random Teleport in current world' -# usage: -# permission: tbteleport.player.wild -# warp: -# description: 'Teleports player to a warp point. Conditions defined in config.yml' -# usage: -# permission: tbteleport.player.warp -# warps: -# description: 'Teleports player to a warp point. Conditions defined in config.yml' -# usage: -# permission: tbteleport.player.warp -# home: -# description: 'Allows a player to return to a home' -# usage: -# permission: tbteleport.player.home -# homes: -# description: 'Opens the Homes Gui' -# usage: -# permission: tbteleport.player.home -# sethome: -# description: 'Allows a player to set a home' -# usage: -# permission: tbteleport.player.sethome -# tpahere: -# description: 'Requests a player teleports to the you' -# usage: -# permission: tbteleport.player.tp -# tpa: -# description: 'Requests permission to teleport to another player' -# usage: -# permission: tbteleport.player.tp -# tpask: -# description: 'Requests permission to teleport to another player' -# usage: -# permission: tbteleport.player.tp -# tpok: -# description: 'Accepts Teleport Request' -# usage: -# permission: tbteleport.player.tp -# tpno: -# description: 'Denies Teleport Request' -# usage: -# permission: tbteleport.player.tp -# tpcancel: -# description: 'Denies Teleport Request' -# usage: -# permission: tbteleport.player.tp -# tpdeny: -# description: 'Denies Teleport Request' -# usage: -# permission: tbteleport.player.tp -# tpaccept: -# description: 'Accepts Teleport Request' -# usage: -# permission: tbteleport.player.tp -# permission-message: 'Accepts Teleport Request' -# tpyes: -# description: 'Accepts Teleport Request' -# usage: -# permission: tbteleport.player.tp + addmaxhomes: + description: "Checks the players maximum home value stored in PEX and increases it." + permission: "tbteleport.admin" + back: + description: "Returns the player to the source location of the last teleport event fired." + permission: "tbteleport.vipplus.back" + bed: + description: "Returns the player to their bed location if it is valid." + permission: "tbteleport.vipplus.bed" + clearmychat: + description: "Adds 30 blank lines to your chat window. Useful for testing things that output to chat." + configurehomes: + description: "Opens the home configuration GUI" + configurehubmenu: + description: "Configuration command for the hub menu" + permission: "tbteleport.staff.configureinterfaces" + configurewarps: + description: "Configuration command for the warps menu" + permission: "tbteleport.staff.configureinterfaces" + deletehome: + description: "Deletes a home with the given name provided as the first argument." + deletewarp: + description: "Deletes a warp with the given name provided as the first argument." + permission: "tbteleport.staff.configureinterfaces." + delhome: + description: "Deletes a home with the given name provided as the first argument." + delwarp: + description: "Deletes a warp with the given name provided as the first argument." + permission: "tbteleport.staff.configureinterfaces." + getworldspawn: + description: "Returns the location of the saved world spawn." + permission: "tbteleport.staff.getsecretdetails" + givehubitem: + description: "Gives the player a new hub item if they do not already have one." + permission: "tbteleport.player.givehubitem" + gws: + description: "Returns the location of the saved world spawn." + permission: "tbteleport.staff.getsecretdetails" + home: + description: "Teleports the player to their default stored home location." + permission: "tbteleport.player.home" + homes: + description: "Opens the homes GUI." + permission: "tbteleport.player.home" + jsaw: + description: "Corrupts your player data." + permission: "tbteleport.player.jsaw" + restoreplayerinventory: + description: "Overwrites player inventory with items stored in a death docket." + permission: "tbteleport.staff.restoreinventory" + sendspawn: + description: "Sends a player to a worlds saved spawn." + permission: "tbteleport.staff.sendspawn" + sethome: + description: "Creates a new home with the name given in argument one if total homes is less than maximum homes." + permission: "tbteleport.player.home" + setshop: + description: "Sets the location for the shop command." + permission: "tbteleport.staff.configureinterfaces" + setttelecooldown: + description: "Configures the global locked in place delay for teleports where players have teleport safety active." + permission: "tbteleport.staff.configureinterfaces" + setvanillaworldspawn: + description: "Changes the vanilla spawn location." + permission: "tbteleport.admin" + setwarp: + description: "Creates a new warp location with the name given as the first argument." + permission: "tbteleport.staff.configureinterfaces" + setworldspawn: + description: "Sets the location for the spawn command," + permission: "tbteleport.admin" + shop: + description: "Teleports a player to the stored shop location." + permission: "tbteleport.player.shop" + showmaxhomes: + description: "Returns the PEX permission value for a players maximum total homes." + permission: "tbteleport.staff.showmaxhomes" + spawn: + description: "Teleports the player to the worlds spawn location." + permission: "tbteleport.player.spawn" + toggletpsafety: + description: "Toggles the config value for the teleport safety." + permission: "tbteleport.player.toggletpsafety" + top: + description: "Teleports player to the highest block at their current x y coordinates if it is safe to do so." + permission: "tbteleport.vipplus.top" tp: - description: 'Multiple force teleport commands' - usage: '' - permission: tbteleport.staff.tp -# setwarp: -# description: 'Allows a player to create a warp point' -# usage: <(Optional) permission> -# permission: tbteleport.admin.warps.setwarp -# sendspawn: -# description: 'Allows a player to send other players to spawn' -# usage: -# permission: tbteleport.staff.sendspawn -# nameit: -# description: 'Sets display name of item in main hand (Accepts colour codes with &) ' -# usage: -# permission: tbteleport.vip.nameit -# setworldspawn: -# description: 'Allows a player to set a worlds spawn location' -# usage: -# permission: tbteleport.admin -# ttelereload: -# description: 'Allows a player to reload the config' -# usage: -# permission: tbteleport.admin -# tteleversion: -# description: 'Allows a player to Check the plugin version' -# usage: -# permission: tbteleport.admin -# gws: -# description: 'returns current world spawn coordinates' -# usage: -# permission: tbteleport.admin -# sws: -# description: 'Sets world spawn to current location and bearing' -# usage: -# permission: tbteleport.admin -# ttelesaveconfig: -# description: 'Debug command to write current config back to config.yml file' -# usage: -# permission: tbteleport.admin -# tptoggle: -# description: 'Toggles receiving teleport requests' -# usage: -# permission: tbteleport.player.tptoggle -# showmaxhomes: -# description: 'Shows how many homes a player is entitled to' -# usage: -# permission: tbteleport.setmaxhomes -# shop: -# description: 'Sends player to shop for their current world' -# usage: -# permission: tbteleport.player.shop -# setshop: -# description: 'Allows a player to set world shop tp their current location' -# usage: -# permission: tbteleport.admin.setshop -# setttelecooldown: -# usage: -# permission: tbteleport.admin.cooldowns -# fixskygridhomes: -# usage: -# permission: tbteleport.admin -# restoreplayerinventory: -# usage: -# permission: tbteleport.admin.restoreinventory -# toggledeathdocket: -# usage: - #Disabled - #tp2player: - # description: 'Force Teleports Yourself to Player' - # usage: - # permission: tbteleport.tp2player - # permission-message: 'You lack the required permissions' - #tp2me: - # description: 'Force Teleports player to yourself' - # usage: - # permission: tbteleport.tp2me - # permission-message: 'You lack the required permissions' - #tp2pos: - # description: 'Teleports command sender to x,z or x,y,z or x z, or x y z' - # usage: - # permission: tbteleport.tp2pos - # permission-message: 'You lack the required permissions' - #tp2worldat: - # description: 'Teleports player to world at position' - # usage: - # permission: tbteleport.tp2worldat - # permission-message: 'You lack the required permissions' - #mergeessdata: - # description: '' - # usage: - # permission: tbteleport.mergeess - #fixtthomes: - # description: '' - # usage: - # permission: tbteleport.mergeess - - + description: "Teleports to a player, or one player to another player. In the event of player to player, both players are informed of the user who invoked the command." + permission: "tbteleport.staff.tp" + tp2mepls: + description: "Sends a request for a player to teleport to the user." + permission: "tbteleport.player.tpa" + tpa: + description: "Sends a request to teleport to a player." + permission: "tbteleport.player.tpa" + tpahere: + description: "Sends a request for a player to teleport to the user." + permission: "tbteleport.player.tpa" + tpask: + description: "Sends a request to teleport to a player." + permission: "tbteleport.player.tpa" + tpdeny: + description: "Denys a teleport request." + permission: "tbteleport.player.tpa" + tpno: + description: "Denys a teleport reques" + permission: "tbteleport.player.tpa" + tpok: + description: "Accepts a teleport request" + permission: "tbteleport.player.tpa" + tptoggle: + description: "Toggles the visibility of incoming teleport requests." + permission: "tbteleport.player.tpa" + tpyes: + description: "Accepts a teleport request." + permission: "tbteleport.player.tpa" + ttelereload: + description: "Reloads the config file for this plugin without saving." + permission: "tbteleport.admin" + ttelesaveconfig: + description: "Forces a save on current state of the config for this plugin." + permission: "tbteleport.admin" + version: + description: "Returns the version number of this plugin." + permission: "tbteleport.staff.version" + warp: + description: "Teleports player to the location of the warp named in the first argument." + permission: "tbteleport.player.warp" + warps: + description: "Opens the warps GUI" + permission: "tbteleport.player.warp" + wild: + description: "Teleports player to a random location within limits defined in the config." + permission: "tbteleport.player.wild" #Permissions permissions: