111 lines
4.3 KiB
Java
111 lines
4.3 KiB
Java
package tech.nevets.admininv;
|
|
|
|
import org.apache.commons.lang.Validate;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
import java.util.logging.Level;
|
|
|
|
public class AdminInvCmdExecutor implements CommandExecutor {
|
|
private final HashMap<UUID, SerializablePlayerInventory> playerMap;
|
|
private final AdminInv parent;
|
|
|
|
public AdminInvCmdExecutor(HashMap<UUID, SerializablePlayerInventory> map, AdminInv parentPlugin) {
|
|
this.playerMap = map;
|
|
this.parent = parentPlugin;
|
|
}
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
try {
|
|
if (args.length >= 1) {
|
|
if (args[0].equals("reload")) {
|
|
if (sender.hasPermission("adminmode.reload")) {
|
|
this.parent.reloadConfig();
|
|
sender.sendMessage("AdminMode config successfully reloaded.");
|
|
return true;
|
|
}
|
|
|
|
sender.sendMessage("You do not have the proper permissions to run this command.");
|
|
return true;
|
|
}
|
|
|
|
sender.sendMessage("Unrecognized command parameter. Ignoring.");
|
|
return false;
|
|
}
|
|
|
|
if (sender instanceof Player) {
|
|
Player player = (Player)sender;
|
|
if (player.hasPermission("adminmode.main")) {
|
|
SerializablePlayerInventory inventory = (SerializablePlayerInventory)this.playerMap.get(player.getUniqueId());
|
|
if (inventory == null) {
|
|
inventory = new SerializablePlayerInventory(player.getUniqueId(), this.parent);
|
|
this.playerMap.put(player.getUniqueId(), inventory);
|
|
this.parent.updateSaveList();
|
|
}
|
|
|
|
inventory.toggleAdminInventory();
|
|
this.runCommands("commands.generic", player);
|
|
if (inventory.getInAdminMode()) {
|
|
player.sendMessage("Setting inventory mode to admin mode.");
|
|
this.runCommands("commands.toAdmin", player);
|
|
} else {
|
|
player.sendMessage("Setting inventory mode to normal mode");
|
|
this.runCommands("commands.toSurvival", player);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
player.sendMessage("You do not have the proper permissions.");
|
|
} else {
|
|
sender.sendMessage("Command " + label + " can only be run by a player.");
|
|
}
|
|
} catch (Exception var7) {
|
|
this.parent.getLogger().log(Level.SEVERE, "Error, in the adminmode command.", var7);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private void runCommands(String commandPath, Player sender) {
|
|
Validate.notNull(commandPath, "The commandPath argument to runCommands cannot be null");
|
|
List commands = this.parent.getConfig().getList(commandPath);
|
|
if (commands == null) {
|
|
this.parent.getLogger().log(Level.WARNING, "No list and config path {0}. Ignoring.", commandPath);
|
|
} else {
|
|
Iterator i$ = commands.iterator();
|
|
|
|
while(true) {
|
|
Object o;
|
|
do {
|
|
if (!i$.hasNext()) {
|
|
return;
|
|
}
|
|
|
|
o = i$.next();
|
|
} while(!(o instanceof String));
|
|
|
|
StringBuilder builder = new StringBuilder((String)o);
|
|
|
|
while(builder.indexOf("<player>") >= 0) {
|
|
int startIndex = builder.indexOf("<player>");
|
|
builder.replace(startIndex, startIndex + 8, sender.getName());
|
|
}
|
|
|
|
if (builder.toString().startsWith("/")) {
|
|
builder.delete(0, 1);
|
|
Bukkit.getServer().dispatchCommand(sender, builder.toString());
|
|
} else {
|
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), builder.toString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |