use of org.bukkit.inventory.ItemStack in project TotalFreedomMod by TotalFreedom.
the class Command_enchant method run.
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
if (args.length < 1) {
return false;
}
ItemStack item = playerSender.getEquipment().getItemInMainHand();
if (item == null || item.getType() == Material.AIR) {
msg("You have to hold an item to enchant it");
return true;
}
if (args[0].equalsIgnoreCase("list")) {
boolean has_enchantments = false;
StringBuilder possible_ench = new StringBuilder("Possible enchantments for held item: ");
for (Enchantment ench : Enchantment.values()) {
if (ench.canEnchantItem(item)) {
has_enchantments = true;
possible_ench.append(ench.getName()).append(", ");
}
}
if (has_enchantments) {
msg(possible_ench.toString());
} else {
msg("The held item has no enchantments.");
}
} else if (args[0].equalsIgnoreCase("addall")) {
for (Enchantment ench : Enchantment.values()) {
try {
if (ench.canEnchantItem(item)) {
item.addEnchantment(ench, ench.getMaxLevel());
}
} catch (Exception ex) {
msg("Could not add enchantment: " + ench.getName());
}
}
msg("Added all possible enchantments for this item.");
} else if (args[0].equalsIgnoreCase("reset")) {
for (Enchantment ench : item.getEnchantments().keySet()) {
item.removeEnchantment(ench);
}
msg("Removed all enchantments.");
} else {
if (args.length < 2) {
return false;
}
Enchantment ench = null;
try {
ench = Enchantment.getByName(args[1]);
} catch (Exception ex) {
}
if (ench == null) {
msg(args[1] + " is an invalid enchantment for the held item. Type \"/enchant list\" for valid enchantments for this item.");
return true;
}
if (args[0].equalsIgnoreCase("add")) {
if (ench.canEnchantItem(item)) {
item.addEnchantment(ench, ench.getMaxLevel());
msg("Added enchantment: " + ench.getName());
} else {
msg("Can't use this enchantment on held item.");
}
} else if (args[0].equals("remove")) {
item.removeEnchantment(ench);
msg("Removed enchantment: " + ench.getName());
}
}
return true;
}
use of org.bukkit.inventory.ItemStack in project TotalFreedomMod by TotalFreedom.
the class Command_cake method run.
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
final StringBuilder output = new StringBuilder();
final String[] words = CAKE_LYRICS.split(" ");
for (final String word : words) {
output.append(ChatColor.COLOR_CHAR).append(Integer.toHexString(1 + random.nextInt(14))).append(word).append(" ");
}
final ItemStack heldItem = new ItemStack(Material.CAKE);
final ItemMeta heldItemMeta = heldItem.getItemMeta();
heldItemMeta.setDisplayName((new StringBuilder()).append(ChatColor.WHITE).append("The ").append(ChatColor.DARK_GRAY).append("Lie").toString());
heldItem.setItemMeta(heldItemMeta);
for (final Player player : server.getOnlinePlayers()) {
final int firstEmpty = player.getInventory().firstEmpty();
if (firstEmpty >= 0) {
player.getInventory().setItem(firstEmpty, heldItem);
}
player.awardAchievement(Achievement.BAKE_CAKE);
}
FUtil.bcastMsg(output.toString());
return true;
}
use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.
the class ClassSelect method openGUI.
private void openGUI(Player player) {
inv = Bukkit.createInventory(null, 45, ChatColor.DARK_GRAY + "Select a class: ");
Integer inventoryIndex = 0;
for (Map.Entry<String, Class> clazzSet : ClassManager.classes.entrySet()) {
Class clazz = clazzSet.getValue();
ItemStack classStack = clazz.getItem();
ItemMeta classMeta = classStack.getItemMeta();
List<String> desc = new LinkedList<>(clazz.getDescription());
desc.add(0, ChatColor.translateAlternateColorCodes('&', "&7PRICE: &e" + clazz.getPrice()));
desc.add(1, ChatColor.GRAY + "ABILITY: " + ChatColor.YELLOW + clazz.getAbility());
classMeta.setLore(desc);
classMeta.setDisplayName(ChatColor.AQUA + clazz.getName());
classStack.setItemMeta(classMeta);
inv.setItem(inventoryIndex, classStack);
slots.put(inventoryIndex, clazz);
inventoryIndex = inventoryIndex + 1;
}
player.openInventory(inv);
}
use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.
the class Preferences method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Action a = event.getAction();
ItemStack is = event.getItem();
if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
return;
if (is.getType() == Material.REDSTONE_COMPARATOR)
tsGUI(event.getPlayer());
if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getPlayer().getName())) {
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
}
}
use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.
the class TeamSelect method tsGUI.
private void tsGUI(Player player) {
inv = Bukkit.createInventory(null, 9, ChatColor.DARK_GRAY + "Select a team:");
Wool wool_red = new Wool(DyeColor.RED);
ItemStack itemtsred = wool_red.toItemStack(1);
ItemMeta itemtsredmeta = itemtsred.getItemMeta();
itemtsredmeta.setDisplayName(ChatColor.RED + "Red");
itemtsred.setItemMeta(itemtsredmeta);
Wool wool_cyan = new Wool(DyeColor.CYAN);
ItemStack itemtscyan = wool_cyan.toItemStack(1);
ItemMeta itemtscyanmeta = itemtscyan.getItemMeta();
itemtscyanmeta.setDisplayName(ChatColor.DARK_AQUA + "Blue");
itemtscyan.setItemMeta(itemtscyanmeta);
ItemStack closemenu = new ItemStack(Material.BARRIER, 1);
ItemMeta closemenumeta = closemenu.getItemMeta();
closemenumeta.setDisplayName(ChatColor.DARK_RED + "Close selector");
closemenu.setItemMeta(closemenumeta);
inv.setItem(3, itemtsred);
inv.setItem(4, closemenu);
inv.setItem(5, itemtscyan);
player.openInventory(inv);
}
Aggregations