diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java index 84aab0f..a154bb2 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java @@ -20,6 +20,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import javax.annotation.Nonnull; +import java.sql.SQLException; import java.util.*; public class V10LiftCommand implements CommandExecutor { @@ -197,6 +198,28 @@ public class V10LiftCommand implements CommandExecutor { } else { sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); } + } else if (args[0].equalsIgnoreCase("abort") && args.length == 1) { + //v10lift abort + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + return true; + } + if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { + return abortCommand(sender); + } else { + sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + } + } else if (args[0].equalsIgnoreCase("reload") && args.length == 1) { + //v10lift reload + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + return true; + } + if (sender.hasPermission("v10lift.admin")) { + return reloadCommand(sender); + } else { + sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + } } else if (args[0].equalsIgnoreCase("repair") && args.length == 2) { //v10lift repair if (!(sender instanceof Player)) { @@ -214,6 +237,93 @@ public class V10LiftCommand implements CommandExecutor { return true; } + private boolean reloadCommand(CommandSender sender) { + for (Map.Entry e : DataManager.getLifts().entrySet()) { + String lift = e.getKey(); + if (DataManager.containsMovingTask(lift)) { + Bukkit.getScheduler().cancelTask(DataManager.getMovingTask(lift)); + } + + e.getValue().setQueue(null); + V10LiftPlugin.getAPI().sortLiftBlocks(lift); + } + + DataManager.clearMovingTasks(); + V10LiftPlugin.getSConfig().reloadConfig(); + V10LiftPlugin.getDBManager().save(); + try { + V10LiftPlugin.getDBManager().load(); + } catch (SQLException e) { + e.printStackTrace(); + } + + sender.sendMessage(ChatColor.YELLOW + "Plugin reset successful!"); + return true; + } + + private boolean abortCommand(CommandSender sender) { + Player p = (Player) sender; + boolean abort = false; + + if (DataManager.containsPlayer(p.getUniqueId())) { + DataManager.removePlayer(p.getUniqueId()); + abort = true; + } + + if (DataManager.containsWhoisREQPlayer(p.getUniqueId())) { + DataManager.removeWhoisREQPlayer(p.getUniqueId()); + abort = true; + } + + if (DataManager.containsInputEditsPlayer(p.getUniqueId())) { + DataManager.removeInputEditsPlayer(p.getUniqueId()); + abort = true; + } + + if (DataManager.containsInputRemovesPlayer(p.getUniqueId())) { + DataManager.removeInputRemovesPlayer(p.getUniqueId()); + abort = true; + } + + if (DataManager.containsOfflineEditsPlayer(p.getUniqueId())) { + DataManager.removeOfflineEditsPlayer(p.getUniqueId()); + abort = true; + } + + if (DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) { + DataManager.removeOfflineRemovesPlayer(p.getUniqueId()); + abort = true; + } + + if (DataManager.containsBuilderPlayer(p.getUniqueId())) { + DataManager.removeBuilderPlayer(p.getUniqueId()); + V10LiftPlugin.getAPI().sortLiftBlocks(DataManager.getEditPlayer(p.getUniqueId())); + abort = true; + } + + if (DataManager.containsRopeEditPlayer(p.getUniqueId())) { + DataManager.removeRopeEditPlayer(p.getUniqueId()); + abort = true; + } + + if (DataManager.containsRopeRemovesPlayer(p.getUniqueId())) { + DataManager.removeRopeRemovesPlayer(p.getUniqueId()); + abort = true; + } + + if (DataManager.containsDoorEditPlayer(p.getUniqueId())) { + DataManager.removeDoorEditPlayer(p.getUniqueId()); + abort = true; + } + + if (abort) { + p.sendMessage(ChatColor.GOLD + "Cancelled."); + } else { + p.sendMessage(ChatColor.RED + "Oops! You can't cancel anything."); + } + return true; + } + private boolean repairCommand(CommandSender sender, @Nonnull String[] args) { Player p = (Player) sender; String liftName = args[1]; diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java index 6e9e604..8adaa4f 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java @@ -133,6 +133,8 @@ public class DataManager { return movingTasks.get(liftName); } + public static void clearMovingTasks() { movingTasks.clear(); } + // // public static boolean containsDoorEditPlayer(UUID player) { return doorEdits.containsKey(player); diff --git a/src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java b/src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java index c514c93..9c21cd4 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/V10LiftPlugin.java @@ -74,6 +74,10 @@ public class V10LiftPlugin extends JavaPlugin { return config; } + public static DBManager getDBManager() { + return dbManager; + } + public static V10LiftAPI getAPI() { return api; }