Fixed some non-player commands

This commit is contained in:
stijnb1234 2020-02-26 10:17:34 +01:00
parent 90f6e4c6ab
commit 5991e4ade7
2 changed files with 71 additions and 84 deletions

View file

@ -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,40 +810,40 @@ 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!");
} 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:");
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()) {
p.sendMessage(ChatColor.RED + "None.");
ent.sendMessage(ChatColor.RED + "None.");
} else {
for (Map.Entry<String, Floor> entry : lift.getFloors().entrySet()) {
p.sendMessage(ChatColor.GREEN + " " + entry.getKey() + ":");
ent.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:");
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()) {
p.sendMessage(ChatColor.GOLD + " None.");
ent.sendMessage(ChatColor.GOLD + " None.");
} else {
ChatColor color = ChatColor.DARK_PURPLE;
Iterator<UUID> iter = f.getUserWhitelist().iterator();
@ -865,8 +866,7 @@ public class V10LiftAPI {
}
sb.append(ChatColor.AQUA).append(", ").append(color).append("Group: ").append(iter2.next());
}
p.sendMessage(sb.toString());
}
ent.sendMessage(sb.toString());
}
}
}

View file

@ -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 <Name>
//@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 <Name>
//@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 <Name> <Floor>
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 <Name>
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,6 +446,8 @@ public class V10LiftCommand implements CommandExecutor {
return true;
}
if (sender instanceof Player) {
Player p = (Player) sender;
int masterAmount = V10LiftPlugin.getSConfig().getFile().getInt("MasterRepairAmount");
Optional<XMaterial> mat = XMaterial.matchXMaterial(Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString("MasterRepairItem"), "MasterRepairItem is null"));
if (!mat.isPresent()) {
@ -485,6 +466,7 @@ public class V10LiftCommand implements CommandExecutor {
}
p.getInventory().remove(new ItemStack(masterItem, masterAmount));
}
}
V10LiftPlugin.getAPI().setDefective(liftName, false);
sender.sendMessage(ChatColor.GREEN + "Lift repaired!");
return true;
@ -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;