diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java index 5f78fca..44dc8cc 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java @@ -16,6 +16,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -809,64 +810,63 @@ public class V10LiftAPI { /** * Send info about a lift to a player - * @param p The player + * @param send Where you want to send it to * @param liftName The name of the lift */ - public void sendLiftInfo(Player p, String liftName) { - sendLiftInfo(p, liftName, DataManager.getLift(liftName)); + public void sendLiftInfo(Object send, String liftName) { + sendLiftInfo(send, liftName, DataManager.getLift(liftName)); } /** * Send info about a lift to a player - * @param p The player + * @param send Where you want to send it to * @param liftName The name of the lift * @param lift The lift */ - public void sendLiftInfo(@Nonnull Player p, String liftName, @Nonnull Lift lift) { - if (!lift.getOwners().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { - p.sendMessage(ChatColor.RED + "You don't have the permission to check this lift!"); + public void sendLiftInfo(@Nonnull Object send, String liftName, @Nonnull Lift lift) { + + CommandSender ent = (CommandSender) send; + + ent.sendMessage(ChatColor.GOLD + "Elevator: " + ChatColor.YELLOW + liftName); + ent.sendMessage(ChatColor.GOLD + "Settings:"); + ent.sendMessage(ChatColor.GREEN + " Speed: " + ChatColor.YELLOW + lift.getSpeed()); + ent.sendMessage(ChatColor.GREEN + " Realistic Mode: " + ChatColor.YELLOW + lift.isRealistic()); + ent.sendMessage(ChatColor.GREEN + " Malfunction: " + ChatColor.YELLOW + lift.isDefective()); + ent.sendMessage(ChatColor.GOLD + "Floors:"); + if (lift.getFloors().isEmpty()) { + ent.sendMessage(ChatColor.RED + "None."); } else { - p.sendMessage(ChatColor.GOLD + "Elevator: " + ChatColor.YELLOW + liftName); - p.sendMessage(ChatColor.GOLD + "Settings:"); - p.sendMessage(ChatColor.GREEN + " Speed: " + ChatColor.YELLOW + lift.getSpeed()); - p.sendMessage(ChatColor.GREEN + " Realistic Mode: " + ChatColor.YELLOW + lift.isRealistic()); - p.sendMessage(ChatColor.GREEN + " Malfunction: " + ChatColor.YELLOW + lift.isDefective()); - p.sendMessage(ChatColor.GOLD + "Floors:"); - if (lift.getFloors().isEmpty()) { - p.sendMessage(ChatColor.RED + "None."); - } else { - for (Map.Entry entry : lift.getFloors().entrySet()) { - p.sendMessage(ChatColor.GREEN + " " + entry.getKey() + ":"); - Floor f = entry.getValue(); - p.sendMessage(ChatColor.YELLOW + " World: " + ChatColor.GREEN + f.getWorld()); - p.sendMessage(ChatColor.YELLOW + " Height: " + ChatColor.GREEN + f.getY()); - p.sendMessage(ChatColor.YELLOW + " Whitelist:"); - if (f.getUserWhitelist().isEmpty() && f.getGroupWhitelist().isEmpty()) { - p.sendMessage(ChatColor.GOLD + " None."); - } else { - ChatColor color = ChatColor.DARK_PURPLE; - Iterator iter = f.getUserWhitelist().iterator(); - Iterator iter2 = f.getGroupWhitelist().iterator(); - StringBuilder sb = new StringBuilder(); - sb.append(" ").append(color).append(Bukkit.getOfflinePlayer(iter.next()).getName()); - while (iter.hasNext()) { - if (color == ChatColor.DARK_PURPLE) { - color = ChatColor.LIGHT_PURPLE; - } else { - color = ChatColor.DARK_PURPLE; - } - sb.append(ChatColor.AQUA).append(", ").append(color).append(Bukkit.getOfflinePlayer(iter.next()).getName()); + for (Map.Entry entry : lift.getFloors().entrySet()) { + ent.sendMessage(ChatColor.GREEN + " " + entry.getKey() + ":"); + Floor f = entry.getValue(); + ent.sendMessage(ChatColor.YELLOW + " World: " + ChatColor.GREEN + f.getWorld()); + ent.sendMessage(ChatColor.YELLOW + " Height: " + ChatColor.GREEN + f.getY()); + ent.sendMessage(ChatColor.YELLOW + " Whitelist:"); + if (f.getUserWhitelist().isEmpty() && f.getGroupWhitelist().isEmpty()) { + ent.sendMessage(ChatColor.GOLD + " None."); + } else { + ChatColor color = ChatColor.DARK_PURPLE; + Iterator iter = f.getUserWhitelist().iterator(); + Iterator iter2 = f.getGroupWhitelist().iterator(); + StringBuilder sb = new StringBuilder(); + sb.append(" ").append(color).append(Bukkit.getOfflinePlayer(iter.next()).getName()); + while (iter.hasNext()) { + if (color == ChatColor.DARK_PURPLE) { + color = ChatColor.LIGHT_PURPLE; + } else { + color = ChatColor.DARK_PURPLE; } - while (iter2.hasNext()) { - if (color == ChatColor.DARK_PURPLE) { - color = ChatColor.LIGHT_PURPLE; - } else { - color = ChatColor.DARK_PURPLE; - } - sb.append(ChatColor.AQUA).append(", ").append(color).append("Group: ").append(iter2.next()); - } - p.sendMessage(sb.toString()); + sb.append(ChatColor.AQUA).append(", ").append(color).append(Bukkit.getOfflinePlayer(iter.next()).getName()); } + while (iter2.hasNext()) { + if (color == ChatColor.DARK_PURPLE) { + color = ChatColor.LIGHT_PURPLE; + } else { + color = ChatColor.DARK_PURPLE; + } + sb.append(ChatColor.AQUA).append(", ").append(color).append("Group: ").append(iter2.next()); + } + ent.sendMessage(sb.toString()); } } } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java index 5209b4e..58d5343 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java @@ -157,11 +157,6 @@ public class V10LiftCommand implements CommandExecutor { } } else if (args[0].equalsIgnoreCase("whois") && (args.length == 1 || args.length == 2)) { //v10lift whois || v10lift whois - //@TODO Make non-player - 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 whoisCommand(sender, args); } else { @@ -220,11 +215,6 @@ public class V10LiftCommand implements CommandExecutor { } } else if (args[0].equalsIgnoreCase("repair") && args.length == 2) { //v10lift repair - //@TODO Make non-player - if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); - return true; - } if (sender.hasPermission("v10lift.repair") || sender.hasPermission("v10lift.admin")) { return repairCommand(sender, args); } else { @@ -238,24 +228,14 @@ public class V10LiftCommand implements CommandExecutor { sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); } } else if (args[0].equalsIgnoreCase("start")) { - //@TODO Make non-player //v10lift start - if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); - return true; - } if (sender.hasPermission("v10lift.start") || sender.hasPermission("v10lift.admin")) { return startCommand(sender, args); } else { sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!"); } } else if (args[0].equalsIgnoreCase("stop")) { - //@TODO Make non-player //v10lift stop - if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You have to be a player to do this."); - return true; - } if (sender.hasPermission("v10lift.stop") || sender.hasPermission("v10lift.admin")) { return stopCommand(sender, args); } else { @@ -453,7 +433,6 @@ public class V10LiftCommand implements CommandExecutor { } private boolean repairCommand(CommandSender sender, @Nonnull String[] args) { - Player p = (Player) sender; String liftName = args[1]; if (!DataManager.containsLift(liftName)) { sender.sendMessage(ChatColor.RED + "Lift " + args[1] + " doesn't exists!"); @@ -467,23 +446,26 @@ public class V10LiftCommand implements CommandExecutor { return true; } - int masterAmount = V10LiftPlugin.getSConfig().getFile().getInt("MasterRepairAmount"); - Optional mat = XMaterial.matchXMaterial(Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString("MasterRepairItem"), "MasterRepairItem is null")); - if (!mat.isPresent()) { - Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!"); - return true; - } - Material masterItem = mat.get().parseMaterial(); - if (masterItem == null) { - Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!"); - return true; - } - if (p.getGameMode() != GameMode.CREATIVE && masterAmount > 0) { - if (!p.getInventory().contains(masterItem)) { - sender.sendMessage(ChatColor.RED + "You need " + masterAmount + "x " + masterItem.toString().toLowerCase() + "!"); + if (sender instanceof Player) { + Player p = (Player) sender; + int masterAmount = V10LiftPlugin.getSConfig().getFile().getInt("MasterRepairAmount"); + Optional mat = XMaterial.matchXMaterial(Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString("MasterRepairItem"), "MasterRepairItem is null")); + if (!mat.isPresent()) { + Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!"); return true; } - p.getInventory().remove(new ItemStack(masterItem, masterAmount)); + Material masterItem = mat.get().parseMaterial(); + if (masterItem == null) { + Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!"); + return true; + } + if (p.getGameMode() != GameMode.CREATIVE && masterAmount > 0) { + if (!p.getInventory().contains(masterItem)) { + sender.sendMessage(ChatColor.RED + "You need " + masterAmount + "x " + masterItem.toString().toLowerCase() + "!"); + return true; + } + p.getInventory().remove(new ItemStack(masterItem, masterAmount)); + } } V10LiftPlugin.getAPI().setDefective(liftName, false); sender.sendMessage(ChatColor.GREEN + "Lift repaired!"); @@ -536,9 +518,14 @@ public class V10LiftCommand implements CommandExecutor { } private boolean whoisCommand(CommandSender sender, @Nonnull String[] args) { - Player p = (Player) sender; if (args.length < 2) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "You need to be a player to use this command without name."); + return true; + } + //Without name + Player p = (Player) sender; DataManager.addWhoisREQPlayer(p.getUniqueId()); sender.sendMessage(ChatColor.GREEN + "Now right-click on the block you want to check."); } else { @@ -546,7 +533,7 @@ public class V10LiftCommand implements CommandExecutor { if (!DataManager.containsLift(liftName)) { sender.sendMessage(ChatColor.RED + "Lift " + liftName + " not found!"); } else { - V10LiftPlugin.getAPI().sendLiftInfo(p, liftName); + V10LiftPlugin.getAPI().sendLiftInfo(sender, liftName); } } return true;