Fixed some non-player commands
This commit is contained in:
parent
90f6e4c6ab
commit
5991e4ade7
2 changed files with 71 additions and 84 deletions
|
@ -16,6 +16,7 @@ import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -809,64 +810,63 @@ public class V10LiftAPI {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send info about a lift to a player
|
* 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 liftName The name of the lift
|
||||||
*/
|
*/
|
||||||
public void sendLiftInfo(Player p, String liftName) {
|
public void sendLiftInfo(Object send, String liftName) {
|
||||||
sendLiftInfo(p, liftName, DataManager.getLift(liftName));
|
sendLiftInfo(send, liftName, DataManager.getLift(liftName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send info about a lift to a player
|
* 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 liftName The name of the lift
|
||||||
* @param lift The lift
|
* @param lift The lift
|
||||||
*/
|
*/
|
||||||
public void sendLiftInfo(@Nonnull Player p, String liftName, @Nonnull Lift lift) {
|
public void sendLiftInfo(@Nonnull Object send, 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!");
|
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 {
|
} else {
|
||||||
p.sendMessage(ChatColor.GOLD + "Elevator: " + ChatColor.YELLOW + liftName);
|
for (Map.Entry<String, Floor> entry : lift.getFloors().entrySet()) {
|
||||||
p.sendMessage(ChatColor.GOLD + "Settings:");
|
ent.sendMessage(ChatColor.GREEN + " " + entry.getKey() + ":");
|
||||||
p.sendMessage(ChatColor.GREEN + " Speed: " + ChatColor.YELLOW + lift.getSpeed());
|
Floor f = entry.getValue();
|
||||||
p.sendMessage(ChatColor.GREEN + " Realistic Mode: " + ChatColor.YELLOW + lift.isRealistic());
|
ent.sendMessage(ChatColor.YELLOW + " World: " + ChatColor.GREEN + f.getWorld());
|
||||||
p.sendMessage(ChatColor.GREEN + " Malfunction: " + ChatColor.YELLOW + lift.isDefective());
|
ent.sendMessage(ChatColor.YELLOW + " Height: " + ChatColor.GREEN + f.getY());
|
||||||
p.sendMessage(ChatColor.GOLD + "Floors:");
|
ent.sendMessage(ChatColor.YELLOW + " Whitelist:");
|
||||||
if (lift.getFloors().isEmpty()) {
|
if (f.getUserWhitelist().isEmpty() && f.getGroupWhitelist().isEmpty()) {
|
||||||
p.sendMessage(ChatColor.RED + "None.");
|
ent.sendMessage(ChatColor.GOLD + " None.");
|
||||||
} else {
|
} else {
|
||||||
for (Map.Entry<String, Floor> entry : lift.getFloors().entrySet()) {
|
ChatColor color = ChatColor.DARK_PURPLE;
|
||||||
p.sendMessage(ChatColor.GREEN + " " + entry.getKey() + ":");
|
Iterator<UUID> iter = f.getUserWhitelist().iterator();
|
||||||
Floor f = entry.getValue();
|
Iterator<String> iter2 = f.getGroupWhitelist().iterator();
|
||||||
p.sendMessage(ChatColor.YELLOW + " World: " + ChatColor.GREEN + f.getWorld());
|
StringBuilder sb = new StringBuilder();
|
||||||
p.sendMessage(ChatColor.YELLOW + " Height: " + ChatColor.GREEN + f.getY());
|
sb.append(" ").append(color).append(Bukkit.getOfflinePlayer(iter.next()).getName());
|
||||||
p.sendMessage(ChatColor.YELLOW + " Whitelist:");
|
while (iter.hasNext()) {
|
||||||
if (f.getUserWhitelist().isEmpty() && f.getGroupWhitelist().isEmpty()) {
|
if (color == ChatColor.DARK_PURPLE) {
|
||||||
p.sendMessage(ChatColor.GOLD + " None.");
|
color = ChatColor.LIGHT_PURPLE;
|
||||||
} else {
|
} else {
|
||||||
ChatColor color = ChatColor.DARK_PURPLE;
|
color = ChatColor.DARK_PURPLE;
|
||||||
Iterator<UUID> iter = f.getUserWhitelist().iterator();
|
|
||||||
Iterator<String> 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());
|
|
||||||
}
|
}
|
||||||
while (iter2.hasNext()) {
|
sb.append(ChatColor.AQUA).append(", ").append(color).append(Bukkit.getOfflinePlayer(iter.next()).getName());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,11 +157,6 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
} else if (args[0].equalsIgnoreCase("whois") && (args.length == 1 || args.length == 2)) {
|
} else if (args[0].equalsIgnoreCase("whois") && (args.length == 1 || args.length == 2)) {
|
||||||
//v10lift whois || v10lift whois <Name>
|
//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")) {
|
if (sender.hasPermission("v10lift.build") || sender.hasPermission("v10lift.admin")) {
|
||||||
return whoisCommand(sender, args);
|
return whoisCommand(sender, args);
|
||||||
} else {
|
} else {
|
||||||
|
@ -220,11 +215,6 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
} else if (args[0].equalsIgnoreCase("repair") && args.length == 2) {
|
} else if (args[0].equalsIgnoreCase("repair") && args.length == 2) {
|
||||||
//v10lift repair <Name>
|
//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")) {
|
if (sender.hasPermission("v10lift.repair") || sender.hasPermission("v10lift.admin")) {
|
||||||
return repairCommand(sender, args);
|
return repairCommand(sender, args);
|
||||||
} else {
|
} else {
|
||||||
|
@ -238,24 +228,14 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||||
}
|
}
|
||||||
} else if (args[0].equalsIgnoreCase("start")) {
|
} else if (args[0].equalsIgnoreCase("start")) {
|
||||||
//@TODO Make non-player
|
|
||||||
//v10lift start <Name> <Floor>
|
//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")) {
|
if (sender.hasPermission("v10lift.start") || sender.hasPermission("v10lift.admin")) {
|
||||||
return startCommand(sender, args);
|
return startCommand(sender, args);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
|
||||||
}
|
}
|
||||||
} else if (args[0].equalsIgnoreCase("stop")) {
|
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||||
//@TODO Make non-player
|
|
||||||
//v10lift stop <Name>
|
//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")) {
|
if (sender.hasPermission("v10lift.stop") || sender.hasPermission("v10lift.admin")) {
|
||||||
return stopCommand(sender, args);
|
return stopCommand(sender, args);
|
||||||
} else {
|
} else {
|
||||||
|
@ -453,7 +433,6 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean repairCommand(CommandSender sender, @Nonnull String[] args) {
|
private boolean repairCommand(CommandSender sender, @Nonnull String[] args) {
|
||||||
Player p = (Player) sender;
|
|
||||||
String liftName = args[1];
|
String liftName = args[1];
|
||||||
if (!DataManager.containsLift(liftName)) {
|
if (!DataManager.containsLift(liftName)) {
|
||||||
sender.sendMessage(ChatColor.RED + "Lift " + args[1] + " doesn't exists!");
|
sender.sendMessage(ChatColor.RED + "Lift " + args[1] + " doesn't exists!");
|
||||||
|
@ -467,23 +446,26 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int masterAmount = V10LiftPlugin.getSConfig().getFile().getInt("MasterRepairAmount");
|
if (sender instanceof Player) {
|
||||||
Optional<XMaterial> mat = XMaterial.matchXMaterial(Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString("MasterRepairItem"), "MasterRepairItem is null"));
|
Player p = (Player) sender;
|
||||||
if (!mat.isPresent()) {
|
int masterAmount = V10LiftPlugin.getSConfig().getFile().getInt("MasterRepairAmount");
|
||||||
Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!");
|
Optional<XMaterial> mat = XMaterial.matchXMaterial(Objects.requireNonNull(V10LiftPlugin.getSConfig().getFile().getString("MasterRepairItem"), "MasterRepairItem is null"));
|
||||||
return true;
|
if (!mat.isPresent()) {
|
||||||
}
|
Bukkit.getLogger().severe("[V10Lift] The material for MasterRepairItem is undefined!");
|
||||||
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;
|
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);
|
V10LiftPlugin.getAPI().setDefective(liftName, false);
|
||||||
sender.sendMessage(ChatColor.GREEN + "Lift repaired!");
|
sender.sendMessage(ChatColor.GREEN + "Lift repaired!");
|
||||||
|
@ -536,9 +518,14 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean whoisCommand(CommandSender sender, @Nonnull String[] args) {
|
private boolean whoisCommand(CommandSender sender, @Nonnull String[] args) {
|
||||||
Player p = (Player) sender;
|
|
||||||
if (args.length < 2) {
|
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
|
//Without name
|
||||||
|
Player p = (Player) sender;
|
||||||
DataManager.addWhoisREQPlayer(p.getUniqueId());
|
DataManager.addWhoisREQPlayer(p.getUniqueId());
|
||||||
sender.sendMessage(ChatColor.GREEN + "Now right-click on the block you want to check.");
|
sender.sendMessage(ChatColor.GREEN + "Now right-click on the block you want to check.");
|
||||||
} else {
|
} else {
|
||||||
|
@ -546,7 +533,7 @@ public class V10LiftCommand implements CommandExecutor {
|
||||||
if (!DataManager.containsLift(liftName)) {
|
if (!DataManager.containsLift(liftName)) {
|
||||||
sender.sendMessage(ChatColor.RED + "Lift " + liftName + " not found!");
|
sender.sendMessage(ChatColor.RED + "Lift " + liftName + " not found!");
|
||||||
} else {
|
} else {
|
||||||
V10LiftPlugin.getAPI().sendLiftInfo(p, liftName);
|
V10LiftPlugin.getAPI().sendLiftInfo(sender, liftName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue