use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.
the class MagicItemCommandExecutor method onItemExport.
public boolean onItemExport(Player player, ItemStack item, String[] parameters) {
if (parameters.length == 0) {
player.sendMessage(ChatColor.RED + "Usage: /mitem export filename");
return true;
}
PlayerInventory inventory = player.getInventory();
int itemSlot = inventory.getHeldItemSlot();
Map<String, MaterialAndData> items = new TreeMap<>();
VaultController vault = VaultController.getInstance();
for (Material material : Material.values()) {
ItemStack testItem = new ItemStack(material, 1);
inventory.setItem(itemSlot, testItem);
ItemStack setItem = inventory.getItem(itemSlot);
if (setItem == null || setItem.getType() != testItem.getType()) {
player.sendMessage("Skipped: " + material.name());
continue;
}
MaterialAndData mat = new MaterialAndData(material);
items.put(mat.getKey(), mat);
String baseName = mat.getName();
for (short data = 1; data < 32; data++) {
testItem = new ItemStack(material, 1, data);
inventory.setItem(itemSlot, testItem);
setItem = inventory.getItem(itemSlot);
if (setItem == null || setItem.getType() != testItem.getType() || setItem.getDurability() != testItem.getDurability())
break;
mat = new MaterialAndData(material, data);
if (mat.getName().equals(baseName))
break;
String testVaultName = vault == null ? null : vault.getItemName(material, data);
if (testVaultName == null || testVaultName.isEmpty())
break;
items.put(mat.getKey(), mat);
}
}
File file = new File(api.getPlugin().getDataFolder(), parameters[0] + ".csv");
try (Writer output = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
output.append("Name,Key,Cost\n");
for (MaterialAndData material : items.values()) {
Double worth = api.getController().getWorth(material.getItemStack(1));
String worthString = worth == null ? "" : worth.toString();
output.append(material.getName() + "," + material.getKey() + "," + worthString + "\n");
}
} catch (Exception ex) {
player.sendMessage(ChatColor.RED + "Error exporting data: " + ex.getMessage());
ex.printStackTrace();
}
inventory.setItem(itemSlot, item);
return true;
}
use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.
the class MaterialAndData method getName.
@Override
@SuppressWarnings("deprecation")
public String getName(Messages messages) {
if (!isValid())
return "";
VaultController controller = VaultController.getInstance();
if (controller != null && data != null) {
try {
String vaultName = controller.getItemName(material, data);
if (vaultName != null && !vaultName.isEmpty()) {
return vaultName;
}
} catch (Throwable ex) {
// Vault apparently throws exceptions on invalid item types
// So we're just going to ignore it.
}
}
String materialName = material.name();
if (data != null) {
if (material == Material.CARPET || material == Material.STAINED_GLASS || material == Material.STAINED_CLAY || material == Material.STAINED_GLASS_PANE || material == Material.WOOL) {
// Note that getByDyeData doesn't work for stained glass or clay. Kind of misleading?
DyeColor color = DyeColor.getByWoolData((byte) (short) data);
if (color != null) {
materialName = color.name().toLowerCase().replace('_', ' ') + " " + materialName;
}
} else if (material == Material.WOOD || material == Material.LOG || material == Material.SAPLING || material == Material.LEAVES || material == Material.LOG_2 || material == Material.LEAVES_2) {
TreeSpecies treeSpecies = TreeSpecies.getByData((byte) (short) data);
if (treeSpecies != null) {
materialName = treeSpecies.name().toLowerCase().replace('_', ' ') + " " + materialName;
}
} else if (material == Material.MOB_SPAWNER && extraData != null && extraData instanceof BlockMobSpawner) {
BlockMobSpawner spawnerData = (BlockMobSpawner) extraData;
if (spawnerData.mobName != null && !spawnerData.mobName.isEmpty()) {
materialName = materialName + " (" + spawnerData.mobName + ")";
}
} else if ((material == Material.STANDING_BANNER || material == Material.WALL_BANNER || material == Material.BANNER) && extraData != null && extraData instanceof BlockBanner) {
DyeColor color = ((BlockBanner) extraData).baseColor;
if (color != null) {
materialName = color.name().toLowerCase() + " " + materialName;
}
}
} else if (messages != null) {
materialName = materialName + messages.get("material.wildcard");
}
materialName = materialName.toLowerCase().replace('_', ' ');
return materialName;
}
use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.
the class CitizensTrait method describe.
public void describe(CommandSender sender) {
sender.sendMessage(ChatColor.AQUA + "Magic NPC: " + ChatColor.GOLD + npc.getName() + ChatColor.WHITE + "(" + ChatColor.GRAY + npc.getId() + ChatColor.WHITE + ")");
String permissionDescription = permissionNode == null ? (ChatColor.GRAY + "(None)") : (ChatColor.LIGHT_PURPLE + permissionNode);
sender.sendMessage(ChatColor.DARK_PURPLE + "Permission: " + permissionDescription);
String invisibleDescription = invisible ? (ChatColor.GREEN + "YES") : (ChatColor.GRAY + "NO");
sender.sendMessage(ChatColor.DARK_PURPLE + "Invisible: " + invisibleDescription);
if (VaultController.hasEconomy()) {
VaultController vault = VaultController.getInstance();
sender.sendMessage(ChatColor.DARK_PURPLE + "Cost: " + ChatColor.GOLD + vault.format(cost));
}
if (requireItem != null) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Requires: " + ChatColor.GOLD + api.describeItem(requireItem));
}
if (hatItem != null) {
sender.sendMessage(ChatColor.DARK_PURPLE + "Wearing Hat: " + ChatColor.GOLD + api.describeItem(hatItem));
}
}
use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.
the class MagicItemCommandExecutor method onItemWorth.
public boolean onItemWorth(Player player, ItemStack item) {
MageController controller = api.getController();
Double worth = controller.getWorth(item);
if (worth == null) {
player.sendMessage(ChatColor.RED + "No worth defined for that item");
return true;
}
String worthDescription = null;
int amount = item.getAmount();
double totalWorth = worth * amount;
if (VaultController.hasEconomy()) {
VaultController vault = VaultController.getInstance();
worthDescription = vault.format(totalWorth);
if (amount > 1) {
worthDescription = worthDescription + ChatColor.WHITE + " (" + ChatColor.GOLD + vault.format(worth) + ChatColor.WHITE + " each)";
}
} else {
worthDescription = Double.toString(totalWorth);
if (amount > 1) {
worthDescription = worthDescription + ChatColor.WHITE + " (" + ChatColor.GOLD + Double.toString(worth) + ChatColor.WHITE + " each)";
}
}
player.sendMessage("That item is worth " + ChatColor.GOLD + worthDescription);
return true;
}
use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.
the class Cost method deduct.
@Override
public void deduct(Mage mage, CasterProperties caster, CostReducer reducer) {
Player player = mage.getPlayer();
switch(type) {
case ITEM:
if (!isConsumeFree(reducer)) {
ItemStack itemStack = getItemStack(reducer);
mage.removeItem(itemStack, itemWildcard);
}
break;
case XP:
mage.removeExperience(getXP(reducer));
break;
case LEVELS:
if (player != null) {
int newLevel = Math.max(0, player.getLevel() - getLevels(reducer));
player.setLevel(newLevel);
}
break;
case MANA:
if (caster != null) {
caster.removeMana(getMana(reducer));
} else {
mage.removeMana(getMana(reducer));
}
break;
case CURRENCY:
VaultController vault = VaultController.getInstance();
if (vault != null) {
vault.withdrawPlayer(mage.getPlayer(), getCurrency(reducer));
}
break;
case SP:
mage.addSkillPoints(-getSkillPoints(reducer));
break;
case HEALTH:
LivingEntity living = mage.getLivingEntity();
if (living != null) {
living.setHealth(Math.max(0, living.getHealth() - getReducedCost(amount, reducer)));
}
break;
case HUNGER:
if (player != null) {
player.setFoodLevel(Math.max(0, player.getFoodLevel() - getRoundedCost(amount, reducer)));
}
break;
}
}
Aggregations