use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.
the class Messages method describeCurrency.
@Override
public String describeCurrency(double amount) {
VaultController vault = VaultController.getInstance();
if (vault == null)
return Integer.toString((int) amount);
String formatted = vault.format(amount);
if (!VaultController.hasEconomy()) {
formatted = get("costs.currency_amount").replace("$amount", formatted);
}
return formatted;
}
use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.
the class CitizensTrait method configure.
public void configure(CommandSender sender, String key, String value) {
if (key == null) {
return;
}
if (key.equalsIgnoreCase("permission")) {
permissionNode = value;
if (value == null) {
sender.sendMessage(ChatColor.RED + "Cleared permission node");
} else {
sender.sendMessage(ChatColor.DARK_PURPLE + "Set required permission to: " + ChatColor.LIGHT_PURPLE + permissionNode);
}
} else if (key.equalsIgnoreCase("invisible")) {
if (value == null || !value.equalsIgnoreCase("true")) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Set NPC visible");
invisible = false;
} else {
invisible = true;
sender.sendMessage(ChatColor.DARK_PURPLE + "Set NPC invisible");
}
updateEntity();
} else if (key.equalsIgnoreCase("cost")) {
if (value == null) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Cleared cost");
cost = 0;
} else {
try {
cost = Double.parseDouble(value);
if (VaultController.hasEconomy()) {
VaultController vault = VaultController.getInstance();
sender.sendMessage(ChatColor.DARK_PURPLE + "Set cost to: " + ChatColor.GOLD + vault.format(cost));
} else {
sender.sendMessage(ChatColor.DARK_PURPLE + "Set cost to " + value);
}
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Invalid cost: " + value);
}
}
} else if (key.equalsIgnoreCase("requires")) {
if (value == null) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Cleared item requirement");
cost = 0;
} else {
try {
requireItem = api.createItem(value);
sender.sendMessage(ChatColor.DARK_PURPLE + "Set item requirement to " + api.describeItem(requireItem));
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Invalid item: " + value);
}
}
} else if (key.equalsIgnoreCase("hat")) {
hatItem = api.createItem(value);
if (hatItem == null) {
sender.sendMessage(ChatColor.DARK_PURPLE + "removed hat");
Entity entity = null;
try {
entity = npc.getEntity();
} catch (Exception ignored) {
}
LivingEntity li = entity instanceof LivingEntity ? (LivingEntity) entity : null;
if (li != null) {
li.getEquipment().setHelmet(hatItem);
}
} else {
try {
hatItem = api.createItem(value);
sender.sendMessage(ChatColor.DARK_PURPLE + "Set hat to " + api.describeItem(hatItem));
updateEntity();
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Invalid item: " + value);
}
}
} else {
sender.sendMessage(ChatColor.RED + "Not a valid configuration option- use the <tab> key for help");
}
}
use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.
the class CitizensTrait method onClick.
@EventHandler
public void onClick(net.citizensnpcs.api.event.NPCRightClickEvent event) {
if (event.getNPC() != this.getNPC())
return;
CommandSender sender = event.getClicker();
Player player = event.getClicker();
if (permissionNode != null && !player.hasPermission(permissionNode)) {
return;
}
if (cost > 0) {
if (!VaultController.hasEconomy()) {
sender.sendMessage(api.getMessages().get("economy.missing"));
return;
}
VaultController vault = VaultController.getInstance();
if (!vault.has(player, cost)) {
sender.sendMessage(api.getMessages().get("economy.insufficient").replace("$cost", vault.format(cost)));
return;
}
}
if (requireItem != null && !api.hasItem(player, requireItem)) {
sender.sendMessage(api.getMessages().get("economy.requires").replace("$cost", api.describeItem(requireItem)));
return;
}
boolean result = perform(event);
if (result && cost > 0) {
VaultController vault = VaultController.getInstance();
sender.sendMessage(api.getMessages().get("economy.deducted").replace("$cost", vault.format(cost)));
vault.withdrawPlayer(player, cost);
}
if (result && requireItem != null) {
sender.sendMessage(api.getMessages().get("economy.deducted").replace("$cost", api.describeItem(requireItem)));
api.takeItem(player, requireItem);
}
}
Aggregations