diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java index 7b6cee9..3bdb470 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java @@ -78,6 +78,22 @@ public class V10LiftAPI { return true; } + public void renameLift(String liftName, String newName) { + if (liftName == null || newName == null || !DataManager.containsLift(liftName)) return; + + Lift lift = DataManager.getLift(liftName); + DataManager.removeLift(liftName); + DataManager.addLift(newName, lift); + for (LiftSign ls : lift.getSigns()) { + Block block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ()); + BlockState bs = block.getState(); + if (!(bs instanceof Sign)) continue; + Sign si = (Sign) bs; + si.setLine(1, newName); + si.update(); + } + } + /** * Add a block to a lift * Use {@link nl.SBDeveloper.V10Lift.API.V10LiftAPI#sortLiftBlocks(String liftName)} after! diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java index df452dc..aae03bf 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java @@ -18,7 +18,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import javax.annotation.Nonnull; -import javax.xml.crypto.Data; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; @@ -84,10 +83,89 @@ public class V10LiftCommand implements CommandExecutor { } else { sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); } + } else if (args[0].equalsIgnoreCase("offline") && args.length == 2) { + //v10lift offline add || v10lift offline del + 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 offlineCommand(sender, args); + } else { + sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + } + } else if (args[0].equalsIgnoreCase("rename") && args.length == 2) { + //v10lift rename + 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 renameCommand(sender, args); + } else { + sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + } } return false; } + private boolean renameCommand(CommandSender sender, String[] args) { + Player p = (Player) sender; + if (!DataManager.containsEditPlayer(p.getUniqueId())) { + sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + return true; + } + + String liftName = DataManager.getEditPlayer(p.getUniqueId()); + if (!DataManager.containsLift(liftName)) { + sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); + return true; + } + + V10LiftPlugin.getAPI().renameLift(liftName, args[1]); + sender.sendMessage(ChatColor.GREEN + "Lift successfully renamed!"); + return true; + } + + private boolean offlineCommand(CommandSender sender, String[] args) { + Player p = (Player) sender; + if (!DataManager.containsEditPlayer(p.getUniqueId())) { + sender.sendMessage(ChatColor.RED + "First switch on the editor mode!"); + return true; + } + + 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); + if (args[1].equalsIgnoreCase("add")) { + if (DataManager.containsOfflineEditsPlayer(p.getUniqueId()) || DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) { + sender.sendMessage(ChatColor.RED + "You are still adjusting an input!"); + return true; + } + + DataManager.addOfflineEditsPlayer(p.getUniqueId()); + sender.sendMessage(ChatColor.GREEN + "Now right click on the offline input block!"); + } else if (args[1].equalsIgnoreCase("del")) { + if (lift.getOfflineInputs().isEmpty()) { + sender.sendMessage(ChatColor.RED + "There is no input to remove!"); + return true; + } + + if (DataManager.containsOfflineEditsPlayer(p.getUniqueId()) || DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) { + sender.sendMessage(ChatColor.RED + "You are still adjusting an input!"); + return true; + } + + DataManager.addOfflineRemovesPlayer(p.getUniqueId()); + sender.sendMessage(ChatColor.GREEN + "Now right click on the offline input block!"); + } else { + return helpCommand(sender); + } + return true; + } + private boolean inputCommand(CommandSender sender, String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) {