From 9ef7830c69c37f78fab7d6c7dd5c88f98b90beb8 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Thu, 30 Jan 2020 14:47:22 +0100 Subject: [PATCH] Added input command --- .../V10Lift/Commands/V10LiftCommand.java | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java index 8385ced..df452dc 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java @@ -18,8 +18,10 @@ 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; import java.util.Objects; public class V10LiftCommand implements CommandExecutor { @@ -72,10 +74,80 @@ public class V10LiftCommand implements CommandExecutor { } else { sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); } + } else if (args[0].equalsIgnoreCase("input") && (args.length == 2 || args.length == 3)) { + //v10lift input add || v10lift input 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 inputCommand(sender, args); + } else { + sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); + } } return false; } + private boolean inputCommand(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")) { + String floor = null; + if (args.length < 3) { + Block b = p.getLocation().getBlock(); + Floor f = new Floor(b.getY() - 1, b.getWorld().getName()); + if (!lift.getFloors().containsValue(f)) { + sender.sendMessage(ChatColor.RED + "Automatic floor detection failed!"); + return true; + } + + for (Map.Entry e : lift.getFloors().entrySet()) { + Floor fl = e.getValue(); + if (fl.equals(f)) { + floor = e.getKey(); + } + } + } else { + floor = args[2]; + } + + if (DataManager.containsInputEditsPlayer(p.getUniqueId()) || DataManager.containsInputRemovesPlayer(p.getUniqueId())) { + sender.sendMessage(ChatColor.RED + "You are still adjusting an input!"); + return true; + } + + DataManager.addInputEditsPlayer(p.getUniqueId(), Objects.requireNonNull(floor, "Floor is null at input add command")); + sender.sendMessage(ChatColor.GREEN + "Now right click on the input block!"); + } else if (args[1].equalsIgnoreCase("del")) { + if (lift.getInputs().isEmpty()) { + sender.sendMessage(ChatColor.RED + "There is no input to remove!"); + return true; + } + + if (DataManager.containsInputEditsPlayer(p.getUniqueId()) || DataManager.containsInputRemovesPlayer(p.getUniqueId())) { + sender.sendMessage(ChatColor.RED + "You are still adjusting an input!"); + return true; + } + + DataManager.addInputRemovesPlayer(p.getUniqueId()); + sender.sendMessage(ChatColor.GREEN + "Now right click on the input block!"); + } else { + return helpCommand(sender); + } + return true; + } + private boolean floorCommand(CommandSender sender, String[] args) { Player p = (Player) sender; if (!DataManager.containsEditPlayer(p.getUniqueId())) { @@ -88,8 +160,6 @@ public class V10LiftCommand implements CommandExecutor { sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); return true; } - - Lift lift = DataManager.getLift(liftName); if (args[1].equalsIgnoreCase("add")) { Block b = p.getLocation().getBlock(); String floorName = args[2];