Added floor command

This commit is contained in:
stijnb1234 2020-01-30 14:39:22 +01:00
parent 9e2a758dee
commit 46bd6676e3
2 changed files with 86 additions and 7 deletions

View file

@ -1,16 +1,20 @@
package nl.SBDeveloper.V10Lift.API.Objects; package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID; import java.util.UUID;
@Getter @Setter @AllArgsConstructor @Getter @Setter
public class Floor { public class Floor {
private String world; private String world;
private int y; private int y;
private ArrayList<LiftBlock> doorBlocks; private ArrayList<LiftBlock> doorBlocks;
private ArrayList<UUID> whitelist; private ArrayList<UUID> whitelist;
public Floor(int y, String world) {
this.y = y;
this.world = world;
}
} }

View file

@ -1,5 +1,6 @@
package nl.SBDeveloper.V10Lift.Commands; package nl.SBDeveloper.V10Lift.Commands;
import nl.SBDeveloper.V10Lift.API.Objects.Floor;
import nl.SBDeveloper.V10Lift.API.Objects.Lift; import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock; import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign; import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
@ -61,10 +62,89 @@ public class V10LiftCommand implements CommandExecutor {
} 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("floor") && (args.length == 3 || args.length == 4)) {
//v10lift floor add <Name> || v10lift floor del <Name> || v10lift floor rename <Old> <New>
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 floorCommand(sender, args);
} else {
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
}
} }
return false; return false;
} }
private boolean floorCommand(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")) {
Block b = p.getLocation().getBlock();
String floorName = args[2];
int response = V10LiftPlugin.getAPI().addFloor(liftName, floorName, new Floor(b.getY() - 1, b.getWorld().getName()));
switch (response) {
case 0:
sender.sendMessage(ChatColor.GREEN + "Floor successfully added!");
break;
case -2:
sender.sendMessage(ChatColor.RED + "That floor is too high!");
break;
case -3:
sender.sendMessage(ChatColor.RED + "That floor already exists!");
break;
default:
sender.sendMessage(ChatColor.RED + "Internal error!");
break;
}
} else if (args[1].equalsIgnoreCase("del")) {
String floorName = args[2];
if (!V10LiftPlugin.getAPI().removeFloor(liftName, floorName)) {
sender.sendMessage(ChatColor.RED + "Internal error!");
} else {
sender.sendMessage(ChatColor.GREEN + "Floor successfully removed!");
}
} else if (args[1].equalsIgnoreCase("rename")) {
if (args.length < 4) {
sender.sendMessage(ChatColor.RED + "Please use: /v10lift floor rename <Old name> <New name>");
return true;
}
String floorName = args[2];
String newFloorName = args[3];
int response = V10LiftPlugin.getAPI().renameFloor(liftName, floorName, newFloorName);
switch (response) {
case 0:
sender.sendMessage(ChatColor.GREEN + "Floor successfully renamed!");
break;
case -2:
sender.sendMessage(ChatColor.RED + "That floor doesn't exists!");
break;
case -3:
sender.sendMessage(ChatColor.RED + "That floor already exists!");
break;
default:
sender.sendMessage(ChatColor.RED + "Internal error!");
break;
}
} else {
//args[1] not found!
return helpCommand(sender);
}
return true;
}
private boolean editCommand(@Nonnull CommandSender sender, @Nonnull String[] args) { private boolean editCommand(@Nonnull CommandSender sender, @Nonnull String[] args) {
Player p = (Player) sender; Player p = (Player) sender;
if (DataManager.containsEditPlayer(p.getUniqueId())) { if (DataManager.containsEditPlayer(p.getUniqueId())) {
@ -174,11 +254,6 @@ public class V10LiftCommand implements CommandExecutor {
private boolean deleteCommand(@Nonnull CommandSender sender, @Nonnull String[] args) { private boolean deleteCommand(@Nonnull CommandSender sender, @Nonnull String[] args) {
Player p = (Player) sender; Player p = (Player) sender;
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Please use /v10lift delete <Name>");
return true;
}
if (!DataManager.containsLift(args[1])) { if (!DataManager.containsLift(args[1])) {
sender.sendMessage(ChatColor.RED + "That lift doesn't exists."); sender.sendMessage(ChatColor.RED + "That lift doesn't exists.");
return true; return true;