Added offline input and rename commands

This commit is contained in:
stijnb1234 2020-01-30 14:59:01 +01:00
parent 9ef7830c69
commit 5b1ef5bfa9
2 changed files with 95 additions and 1 deletions

View file

@ -78,6 +78,22 @@ public class V10LiftAPI {
return true;
}
public void renameLift(String liftName, String newName) {
if (liftName == null || newName == null || !DataManager.containsLift(liftName)) return;
Lift lift = DataManager.getLift(liftName);
DataManager.removeLift(liftName);
DataManager.addLift(newName, lift);
for (LiftSign ls : lift.getSigns()) {
Block block = Objects.requireNonNull(Bukkit.getWorld(ls.getWorld()), "World is null at setDefective").getBlockAt(ls.getX(), ls.getY(), ls.getZ());
BlockState bs = block.getState();
if (!(bs instanceof Sign)) continue;
Sign si = (Sign) bs;
si.setLine(1, newName);
si.update();
}
}
/**
* Add a block to a lift
* Use {@link nl.SBDeveloper.V10Lift.API.V10LiftAPI#sortLiftBlocks(String liftName)} after!

View file

@ -18,7 +18,6 @@ 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;
@ -84,10 +83,89 @@ public class V10LiftCommand implements CommandExecutor {
} else {
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
}
} else if (args[0].equalsIgnoreCase("offline") && args.length == 2) {
//v10lift offline add || v10lift offline 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 offlineCommand(sender, args);
} else {
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
}
} else if (args[0].equalsIgnoreCase("rename") && args.length == 2) {
//v10lift rename <New name>
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 renameCommand(sender, args);
} else {
sender.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
}
}
return false;
}
private boolean renameCommand(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;
}
V10LiftPlugin.getAPI().renameLift(liftName, args[1]);
sender.sendMessage(ChatColor.GREEN + "Lift successfully renamed!");
return true;
}
private boolean offlineCommand(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")) {
if (DataManager.containsOfflineEditsPlayer(p.getUniqueId()) || DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) {
sender.sendMessage(ChatColor.RED + "You are still adjusting an input!");
return true;
}
DataManager.addOfflineEditsPlayer(p.getUniqueId());
sender.sendMessage(ChatColor.GREEN + "Now right click on the offline input block!");
} else if (args[1].equalsIgnoreCase("del")) {
if (lift.getOfflineInputs().isEmpty()) {
sender.sendMessage(ChatColor.RED + "There is no input to remove!");
return true;
}
if (DataManager.containsOfflineEditsPlayer(p.getUniqueId()) || DataManager.containsOfflineRemovesPlayer(p.getUniqueId())) {
sender.sendMessage(ChatColor.RED + "You are still adjusting an input!");
return true;
}
DataManager.addOfflineRemovesPlayer(p.getUniqueId());
sender.sendMessage(ChatColor.GREEN + "Now right click on the offline input block!");
} else {
return helpCommand(sender);
}
return true;
}
private boolean inputCommand(CommandSender sender, String[] args) {
Player p = (Player) sender;
if (!DataManager.containsEditPlayer(p.getUniqueId())) {