From 9e2a758dee9a8d0a3fbb2302663b5201897aa5a5 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Thu, 30 Jan 2020 14:19:13 +0100 Subject: [PATCH] Added some things, and added the edit command --- .../V10Lift/API/Objects/Floor.java | 10 +- .../V10Lift/API/Objects/LiftRope.java | 11 +- .../SBDeveloper/V10Lift/API/V10LiftAPI.java | 2 - .../V10Lift/Commands/V10LiftCommand.java | 125 ++++++++++++++ .../V10Lift/Managers/DataManager.java | 162 +++++++++++++++++- 5 files changed, 287 insertions(+), 23 deletions(-) diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java index 6d755e6..99c8a68 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java @@ -1,22 +1,16 @@ package nl.SBDeveloper.V10Lift.API.Objects; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import java.util.ArrayList; import java.util.UUID; -@Getter @Setter +@Getter @Setter @AllArgsConstructor public class Floor { private String world; private int y; private ArrayList doorBlocks; private ArrayList whitelist; - - public Floor(String world, int y) { - this.world = world; - this.y = y; - this.doorBlocks = new ArrayList<>(); - this.whitelist = new ArrayList<>(); - } } diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java index bd6fbf5..0ae0811 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java @@ -1,21 +1,14 @@ package nl.SBDeveloper.V10Lift.API.Objects; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -@Getter @Setter +@Getter @Setter @AllArgsConstructor public class LiftRope { private String world; private int x; private int z; private int minY; private int maxY; - - public LiftRope(String world, int x, int minY, int maxY, int z) { - this.world = world; - this.x = x; - this.minY = minY; - this.maxY = maxY; - this.z = z; - } } diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java index be227d1..7b6cee9 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java @@ -7,7 +7,6 @@ import nl.SBDeveloper.V10Lift.API.Objects.LiftSign; import nl.SBDeveloper.V10Lift.Managers.DataManager; import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager; import nl.SBDeveloper.V10Lift.Utils.LocationSerializer; -import nl.SBDeveloper.V10Lift.Utils.XMaterial; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -18,7 +17,6 @@ import org.bukkit.block.Sign; import org.bukkit.entity.Player; import javax.annotation.Nonnull; -import javax.xml.crypto.Data; import java.util.*; public class V10LiftAPI { diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java index 352463c..4a4077f 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java @@ -1,10 +1,16 @@ package nl.SBDeveloper.V10Lift.Commands; import nl.SBDeveloper.V10Lift.API.Objects.Lift; +import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock; +import nl.SBDeveloper.V10Lift.API.Objects.LiftSign; import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.Utils.LocationSerializer; import nl.SBDeveloper.V10Lift.V10LiftPlugin; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -12,6 +18,8 @@ import org.bukkit.entity.Player; import javax.annotation.Nonnull; import java.util.ArrayList; +import java.util.Iterator; +import java.util.Objects; public class V10LiftCommand implements CommandExecutor { @@ -43,10 +51,127 @@ public class V10LiftCommand implements CommandExecutor { } else { sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); } + } else if (args[0].equalsIgnoreCase("edit") && (args.length == 1 || args.length == 2)) { + //v10lift edit + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); + } + if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) { + return editCommand(sender, args); + } else { + sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + } } return false; } + private boolean editCommand(@Nonnull CommandSender sender, @Nonnull String[] args) { + Player p = (Player) sender; + if (DataManager.containsEditPlayer(p.getUniqueId())) { + //TURN OFF + if (args.length < 2) { + String liftName = DataManager.getEditPlayer(p.getUniqueId()); + if (!DataManager.containsLift(liftName)) { + sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + return true; + } + + Lift lift = DataManager.getLift(liftName); + DataManager.removeEditPlayer(p.getUniqueId()); + DataManager.removeInputEditsPlayer(p.getUniqueId()); + DataManager.removeInputRemovesPlayer(p.getUniqueId()); + DataManager.removeOfflineEditsPlayer(p.getUniqueId()); + DataManager.removeOfflineRemovesPlayer(p.getUniqueId()); + if (DataManager.containsBuilderPlayer(p.getUniqueId())) { + DataManager.removeBuilderPlayer(p.getUniqueId()); + V10LiftPlugin.getAPI().sortLiftBlocks(liftName); + } + DataManager.removeRopeEditPlayer(p.getUniqueId()); + DataManager.removeRopeRemovesPlayer(p.getUniqueId()); + DataManager.removeDoorEditsPlayer(p.getUniqueId()); + + BlockState bs; + Sign sign; + for (LiftBlock lb : lift.getBlocks()) { + bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at edit command").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState(); + if (!(bs instanceof Sign)) continue; + sign = (Sign) bs; + //TODO Add defaults + if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) continue; + sign.setLine(3, ""); + sign.update(); + } + + Iterator liter = lift.getSigns().iterator(); + while (liter.hasNext()) { + LiftSign ls = liter.next(); + bs = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at edit command").getBlockAt(ls.getX(), ls.getY(), ls.getZ()).getState(); + if (!(bs instanceof Sign)) { + Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(bs.getBlock().getLocation())); + liter.remove(); + continue; + } + sign = (Sign) bs; + //TODO Add defaults + sign.setLine(3, ls.getOldText()); + sign.update(); + ls.setOldText(null); + } + sender.sendMessage(ChatColor.GREEN + "Editor turned off!"); + } else { + sender.sendMessage(ChatColor.RED + "You are still in editor mode."); + return true; + } + } else { + //TURN ON + if (args.length < 2) { + sender.sendMessage(ChatColor.RED + "Please use /v10lift edit "); + return true; + } + + if (!DataManager.containsLift(args[1])) { + sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + return true; + } + + Lift lift = DataManager.getLift(args[1]); + if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { + sender.sendMessage(ChatColor.RED + "You don't have the permission to remove that lift."); + } + + DataManager.addEditPlayer(p.getUniqueId(), args[1]); + BlockState bs; + Sign sign; + for (LiftBlock lb : lift.getBlocks()) { + bs = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at edit command").getBlockAt(lb.getX(), lb.getY(), lb.getZ()).getState(); + if (!(bs instanceof Sign)) continue; + sign = (Sign) bs; + //TODO Add defaults + if (!sign.getLine(0).equalsIgnoreCase("[v10lift]")) continue; + sign.setLine(3, ChatColor.RED + "Maintenance"); + sign.update(); + } + + Iterator liter = lift.getSigns().iterator(); + while (liter.hasNext()) { + LiftSign ls = liter.next(); + bs = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at edit command").getBlockAt(ls.getX(), ls.getY(), ls.getZ()).getState(); + if (!(bs instanceof Sign)) { + Bukkit.getLogger().severe("[V10Lift] Wrong sign removed at: " + LocationSerializer.serialize(bs.getBlock().getLocation())); + liter.remove(); + continue; + } + sign = (Sign) bs; + ls.setOldText(sign.getLine(3)); + //TODO Add defaults + sign.setLine(3, ChatColor.RED + "Maintenance"); + sign.update(); + } + sender.sendMessage(ChatColor.GREEN + "Editor turned on!"); + } + return true; + } + private boolean deleteCommand(@Nonnull CommandSender sender, @Nonnull String[] args) { Player p = (Player) sender; if (args.length < 2) { diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java index 1f3bab6..4a14da1 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java @@ -11,7 +11,20 @@ public class DataManager { /* A manager for general HashMaps */ private static LinkedHashMap lifts = new LinkedHashMap<>(); private static LinkedHashMap> builds = new LinkedHashMap<>(); + private static LinkedHashMap editors = new LinkedHashMap<>(); + private static LinkedHashMap inputEdits = new LinkedHashMap<>(); + private static ArrayList inputRemoves = new ArrayList<>(); + private static ArrayList offlineEdits = new ArrayList<>(); + private static ArrayList offlineRemoves = new ArrayList<>(); + private static ArrayList builder = new ArrayList<>(); + private static LinkedHashMap ropeEdits = new LinkedHashMap<>(); + private static ArrayList ropeRemoves = new ArrayList<>(); + private static ArrayList doorEdits = new ArrayList<>(); + private static ArrayList whoisReq = new ArrayList<>(); + /* HashMap methods */ + + // // public static void addLift(String liftName, Lift lift) { lifts.put(liftName, lift); } @@ -28,10 +41,7 @@ public class DataManager { return lifts.get(liftName); } - public static LinkedHashMap getLifts() { - return lifts; - } - + // // public static boolean containsPlayer(UUID player) { return builds.containsKey(player); } @@ -47,4 +57,148 @@ public class DataManager { public static ArrayList getPlayer(UUID player) { return builds.get(player); } + + // // + public static boolean containsInputEditsPlayer(UUID player) { + return inputEdits.containsKey(player); + } + + public static void addInputEditsPlayer(UUID player, String liftName) { + inputEdits.put(player, liftName); + } + + public static void removeInputEditsPlayer(UUID player) { + inputEdits.remove(player); + } + + public static String getInputEditsPlayer(UUID player) { + return inputEdits.get(player); + } + + // // + public static boolean containsRopeEditPlayer(UUID player) { + return ropeEdits.containsKey(player); + } + + public static void addRopeEditPlayer(UUID player, String liftName) { + ropeEdits.put(player, liftName); + } + + public static void removeRopeEditPlayer(UUID player) { + ropeEdits.remove(player); + } + + public static String getRopeEditPlayer(UUID player) { + return ropeEdits.get(player); + } + + // // + public static boolean containsEditPlayer(UUID player) { + return editors.containsKey(player); + } + + public static void addEditPlayer(UUID player, String liftName) { + editors.put(player, liftName); + } + + public static void removeEditPlayer(UUID player) { + editors.remove(player); + } + + public static String getEditPlayer(UUID player) { + return editors.get(player); + } + + /* ArrayList methods */ + + // // + public static boolean containsOfflineEditsPlayer(UUID player) { + return offlineEdits.contains(player); + } + + public static void addOfflineEditsPlayer(UUID player) { + offlineEdits.add(player); + } + + public static void removeOfflineEditsPlayer(UUID player) { + offlineEdits.remove(player); + } + + // // + public static boolean containsOfflineRemovesPlayer(UUID player) { + return offlineRemoves.contains(player); + } + + public static void addOfflineRemovesPlayer(UUID player) { + offlineRemoves.add(player); + } + + public static void removeOfflineRemovesPlayer(UUID player) { + offlineRemoves.remove(player); + } + + // // + public static boolean containsBuilderPlayer(UUID player) { + return builder.contains(player); + } + + public static void addBuilderPlayer(UUID player) { + builder.add(player); + } + + public static void removeBuilderPlayer(UUID player) { + builder.remove(player); + } + + // // + public static boolean containsRopeRemovesPlayer(UUID player) { + return ropeRemoves.contains(player); + } + + public static void addRopeRemovesPlayer(UUID player) { + ropeRemoves.add(player); + } + + public static void removeRopeRemovesPlayer(UUID player) { + ropeRemoves.remove(player); + } + + // // + public static boolean containsDoorEditsPlayer(UUID player) { + return doorEdits.contains(player); + } + + public static void addDoorEditsPlayer(UUID player) { + doorEdits.add(player); + } + + public static void removeDoorEditsPlayer(UUID player) { + doorEdits.remove(player); + } + + // // + public static boolean containsInputRemovesPlayer(UUID player) { + return inputRemoves.contains(player); + } + + public static void addInputRemovesPlayer(UUID player) { + inputRemoves.add(player); + } + + public static void removeInputRemovesPlayer(UUID player) { + inputRemoves.remove(player); + } + + // // + public static boolean containsWhoisREQPlayer(UUID player) { + return whoisReq.contains(player); + } + + public static void addWhoisREQPlayer(UUID player) { + whoisReq.add(player); + } + + public static void removeWhoisREQPlayer(UUID player) { + whoisReq.remove(player); + } }