use of me.botsko.prism.wands.InspectorWand in project Prism-Bukkit by prism.
the class WandCommand method handle.
@Override
public void handle(CallInfo call) {
String type = "i";
final boolean isInspect = call.getArg(0).equalsIgnoreCase("inspect") || call.getArg(0).equalsIgnoreCase("i");
if (!isInspect) {
if (call.getArgs().length < 2) {
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("wand-error-type")));
return;
}
type = call.getArg(1);
}
Wand oldWand = null;
if (Prism.playersWithActiveTools.containsKey(call.getPlayer().getName())) {
// Pull the wand in use
oldWand = Prism.playersWithActiveTools.get(call.getPlayer().getName());
}
// Always remove the old one
Prism.playersWithActiveTools.remove(call.getPlayer().getName());
// Determine default mode
String mode = plugin.getConfig().getString("prism.wands.default-mode");
// Check if the player has a personal override
if (plugin.getConfig().getBoolean("prism.wands.allow-user-override")) {
final String personalMode = Settings.getSetting("wand.mode", call.getPlayer());
if (personalMode != null) {
mode = personalMode;
}
}
// Determine which item we're using.
String toolKey = null;
if ("item".equals(mode)) {
toolKey = plugin.getConfig().getString("prism.wands.default-item-mode-id");
} else if ("block".equals(mode)) {
toolKey = plugin.getConfig().getString("prism.wands.default-block-mode-id");
}
// Check if the player has a personal override
if (plugin.getConfig().getBoolean("prism.wands.allow-user-override")) {
final String personalToolKey = Settings.getSetting("wand.item", call.getPlayer());
if (personalToolKey != null) {
toolKey = personalToolKey;
}
}
Material itemMaterial = null;
if (toolKey != null) {
itemMaterial = Material.matchMaterial(toolKey);
}
String wandOn = "";
String itemName = "";
StringBuilder parameters = new StringBuilder();
if (itemMaterial != null) {
itemName = Prism.getItems().getAlias(itemMaterial, null);
wandOn += " on a " + itemName;
}
for (int i = (isInspect ? 1 : 2); i < call.getArgs().length; i++) {
parameters.append(" ").append(call.getArg(i));
}
if (ItemUtils.isBadWand(itemMaterial)) {
final String itemNameFinal = itemName;
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("wand-bad").replaceText(Pattern.compile("<itemName>"), builder -> Component.text().content(itemNameFinal))));
return;
}
boolean enabled = false;
Wand wand = null;
/*
Inspector wand
*/
switch(type.toLowerCase()) {
case "i":
case "inpect":
if (checkNoPermissions(call.getPlayer(), "prism.lookup", "prism.wand.inspect")) {
return;
}
if (oldWand instanceof InspectorWand) {
sendWandStatus(call.getPlayer(), "wand-inspection", false, wandOn, parameters.toString());
} else {
wand = new InspectorWand(plugin);
sendWandStatus(call.getPlayer(), "wand-inspection", true, wandOn, parameters.toString());
enabled = true;
}
break;
case "p":
case "profile":
if (checkNoPermissions(call.getPlayer(), "prism.lookup", "prism.wand.profile")) {
return;
}
if (oldWand instanceof ProfileWand) {
sendWandStatus(call.getPlayer(), "wand-profile", false, wandOn, parameters.toString());
} else {
wand = new ProfileWand();
enabled = true;
sendWandStatus(call.getPlayer(), "wand-profile", true, wandOn, parameters.toString());
}
break;
case "rollback":
case "rb":
if (checkNoPermissions(call.getSender(), "prism.rollback", "prism.wand.rollback")) {
return;
}
if (oldWand instanceof RollbackWand) {
sendWandStatus(call.getPlayer(), "wand-rollback", false, wandOn, parameters.toString());
} else {
wand = new RollbackWand(plugin);
sendWandStatus(call.getPlayer(), "wand-rollback", true, wandOn, parameters.toString());
enabled = true;
}
break;
case "restore":
case "rs":
if (checkNoPermissions(call.getPlayer(), "prism.restor", "prism.wand.restore")) {
return;
}
if (oldWand instanceof RestoreWand) {
sendWandStatus(call.getPlayer(), "wand-current", false, wandOn, parameters.toString());
} else {
wand = new RestoreWand(plugin);
enabled = true;
sendWandStatus(call.getPlayer(), "wand-current", true, wandOn, parameters.toString());
}
break;
case "off":
sendWandStatus(call.getPlayer(), "wand-current", false, wandOn, parameters.toString());
break;
default:
Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("wand-invalid")));
return;
}
constructWand(call, enabled, itemMaterial, mode, wand, isInspect, oldWand);
}
Aggregations