public static void transferEnchantmentStorageMeta( EnchantmentStorageMeta meta, JsonObject json, boolean meta2json) { if (meta2json) { if (!meta.hasStoredEnchants()) return; json.add(STORED_ENCHANTS, convertEnchantLevelMap(meta.getStoredEnchants())); } else { JsonElement element = json.get(STORED_ENCHANTS); if (element == null) return; // TODO: Add a pull request to get rid of this entry set loop! // TODO: A set, clear, remove all system is missing for (Entry<Enchantment, Integer> entry : convertEnchantLevelMap(element).entrySet()) { meta.addStoredEnchant(entry.getKey(), entry.getValue(), true); } } }
@Override public Map<MCEnchantment, Integer> getStoredEnchants() { Map<MCEnchantment, Integer> ret = new HashMap<MCEnchantment, Integer>(); for (Map.Entry<Enchantment, Integer> entry : es.getStoredEnchants().entrySet()) { ret.put(new BukkitMCEnchantment(entry.getKey()), entry.getValue()); } return ret; }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args == null || args.length == 0) { return false; } String subcommand = args[0]; ItemStack book = new ItemStack(Material.ENCHANTED_BOOK); EnchantmentStorageMeta esm = (EnchantmentStorageMeta) book.getItemMeta(); esm.addStoredEnchant(Enchantment.ARROW_INFINITE, 1, true); book.setItemMeta(esm); ItemStack arrow = new ItemStack(Material.ARROW); ItemStack string = new ItemStack(Material.STRING, 2); if (subcommand.compareToIgnoreCase("start") == 0) { if (bowfighters.getRunning()) { sender.sendMessage(ChatColor.RED + "Bowfighters is already running!"); return true; } for (Player player : Bukkit.getServer().getOnlinePlayers()) { player.getInventory().addItem(book, arrow, string); } bowfighters.setRunning(true); Bukkit.getServer() .broadcastMessage(ChatColor.GREEN + "Bowfighters started! Items were distributed!"); } else if (subcommand.compareToIgnoreCase("stop") == 0) { if (!bowfighters.getRunning()) { sender.sendMessage(ChatColor.RED + "Bowfighters is not running!"); return true; } bowfighters.setRunning(false); Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "Bowfighters stopped!"); } else if (subcommand.compareToIgnoreCase("resume") == 0) { if (bowfighters.getRunning()) { sender.sendMessage(ChatColor.RED + "Bowfighters is already running!"); return true; } bowfighters.setRunning(true); Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "Bowfighters resumed!"); } else if (subcommand.compareToIgnoreCase("status") == 0) { if (bowfighters.getRunning()) { sender.sendMessage(ChatColor.GOLD + "Bowfighters is running!"); } else { sender.sendMessage(ChatColor.GOLD + "Bowfighters is stopped!"); } } else if (subcommand.compareToIgnoreCase("items") == 0) { if (args.length < 2) { sender.sendMessage(ChatColor.RED + "You must specify a player!"); return true; } if (!bowfighters.getRunning()) { sender.sendMessage(ChatColor.RED + "Bowfighters is not running!"); return true; } String playerName = args[1]; Player player = Bukkit.getPlayer(playerName); if (player == null) { sender.sendMessage(ChatColor.RED + "Player is not online!"); return true; } player.getInventory().addItem(book, arrow, string); sender.sendMessage(ChatColor.GOLD + "Giving items to " + player.getName() + "."); player.sendMessage(ChatColor.GREEN + "You received the bowfighter items."); } return true; }
/** * Sends a display of item information to the specified command sender * * @param item the item to display, cannot be null * @param sender the command sender to send the display to, cannot be null */ public static void showInformation(ItemStack item, CommandSender sender) { if (item == null || sender == null) throw new IllegalArgumentException(); StringBuilder builder = new StringBuilder(); builder.append(ChatColor.BOLD).append(getName(item)).append(" "); if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) { builder.append(ChatColor.ITALIC).append("(").append(getName(item, true)).append(") "); } builder.append(ChatColor.BLUE).append("x").append(item.getAmount()); DumbAuction.getInstance().sendMessage(sender, ChatColor.AQUA + builder.toString().trim()); // Display durability if (item.getType().getMaxDurability() > 0 && item.getDurability() != 0) { double durability = 1 - ((double) item.getDurability() / (double) item.getType().getMaxDurability()); int percent = (int) Math.round(durability * 100); DumbAuction.getInstance() .sendMessage( sender, ChatColor.GRAY + "Durability: " + ChatColor.AQUA + "" + percent + "%"); } Potion pot = null; try { pot = Potion.fromItemStack(item); } catch (Exception e) { } // Consume error List<String> metaMessage = new ArrayList<String>(); if (item.hasItemMeta() || pot != null) { ItemMeta meta = item.getItemMeta(); if (meta.hasLore()) { List<String> lore = meta.getLore(); metaMessage.add(ChatColor.LIGHT_PURPLE + "Lore: "); metaMessage.add(ChatColor.DARK_GRAY + "-------------"); for (String l : lore) { metaMessage.add(ChatColor.GRAY + l); } metaMessage.add(ChatColor.DARK_GRAY + "-------------"); } if (meta.hasEnchants() || meta instanceof EnchantmentStorageMeta) { metaMessage.add(ChatColor.LIGHT_PURPLE + "Enchants: "); metaMessage.add(ChatColor.DARK_GRAY + "-------------"); if (meta.hasEnchants()) { Map<Enchantment, Integer> enchants = meta.getEnchants(); for (Enchantment e : enchants.keySet()) { int level = enchants.get(e); String strLevel = integerToRomanNumeral(level) + " " + ChatColor.GRAY + "(" + level + ")"; metaMessage.add(ChatColor.AQUA + getEnchantmentName(e) + " " + strLevel); } } if (meta instanceof EnchantmentStorageMeta) { EnchantmentStorageMeta emeta = (EnchantmentStorageMeta) meta; if (emeta.hasStoredEnchants()) { Map<Enchantment, Integer> enchants = emeta.getStoredEnchants(); for (Enchantment e : enchants.keySet()) { int level = enchants.get(e); String strLevel = integerToRomanNumeral(level) + " " + ChatColor.GRAY + "(" + level + ")"; metaMessage.add(ChatColor.AQUA + getEnchantmentName(e) + " " + strLevel); } } } metaMessage.add(ChatColor.DARK_GRAY + "-------------"); } if (meta instanceof BookMeta) { BookMeta book = (BookMeta) meta; if (book.hasTitle()) metaMessage.add(ChatColor.GRAY + "Book Title: " + ChatColor.AQUA + book.getTitle()); if (book.hasAuthor()) metaMessage.add(ChatColor.GRAY + "Book Author: " + ChatColor.AQUA + book.getAuthor()); } List<FireworkEffect> effects = new ArrayList<FireworkEffect>(); int fireworkPower = -1; if (meta instanceof FireworkEffectMeta) { FireworkEffectMeta firework = (FireworkEffectMeta) meta; if (firework.hasEffect()) { effects.add(firework.getEffect()); } } if (meta instanceof FireworkMeta) { FireworkMeta firework = (FireworkMeta) meta; if (firework.hasEffects()) { effects.addAll(firework.getEffects()); } fireworkPower = firework.getPower(); } if (effects.size() > 0) { metaMessage.add(ChatColor.LIGHT_PURPLE + "Firework Effects: "); metaMessage.add(ChatColor.DARK_GRAY + "-------------"); for (FireworkEffect effect : effects) { metaMessage.add(ChatColor.AQUA + getFireworkTypeName(effect.getType())); if (effect.getColors().size() > 0) { builder = new StringBuilder(); for (Color color : effect.getColors()) { ChatColor chat = ChatColorPalette.matchColor(color.getRed(), color.getGreen(), color.getBlue()); String name = getChatName(chat); builder.append(chat).append(name).append(ChatColor.GRAY).append(", "); } metaMessage.add( ChatColor.GRAY + " Colors: " + builder.toString().substring(0, builder.toString().length() - 2)); } if (effect.getFadeColors().size() > 0) { builder = new StringBuilder(); for (Color color : effect.getFadeColors()) { ChatColor chat = ChatColorPalette.matchColor(color.getRed(), color.getGreen(), color.getBlue()); String name = getChatName(chat); builder.append(chat).append(name).append(ChatColor.GRAY).append(", "); } metaMessage.add( ChatColor.GRAY + " Fade Colors: " + builder.toString().substring(0, builder.toString().length() - 2)); } } metaMessage.add(ChatColor.DARK_GRAY + "-------------"); } if (fireworkPower >= 0) { metaMessage.add(ChatColor.GRAY + "Firework Power: " + ChatColor.AQUA + "" + fireworkPower); } if (meta instanceof LeatherArmorMeta) { LeatherArmorMeta leather = (LeatherArmorMeta) meta; if (!leather .getColor() .equals( DumbAuction.getInstance().getServer().getItemFactory().getDefaultLeatherColor())) { ChatColor chat = ChatColorPalette.matchColor( leather.getColor().getRed(), leather.getColor().getGreen(), leather.getColor().getBlue()); metaMessage.add(ChatColor.GRAY + "Leather Color: " + chat + getChatName(chat)); } } if (meta instanceof SkullMeta) { SkullMeta skull = (SkullMeta) meta; if (skull.hasOwner()) { metaMessage.add(ChatColor.GRAY + "Skull Player: " + ChatColor.AQUA + skull.getOwner()); } } if (meta instanceof PotionMeta || pot != null) { metaMessage.add(ChatColor.LIGHT_PURPLE + "Potion Effects: "); metaMessage.add(ChatColor.DARK_GRAY + "-------------"); if (pot != null) { for (PotionEffect effect : pot.getEffects()) { int amplifier = effect.getAmplifier() + 1; int time = effect.getDuration() / 20; metaMessage.add( ChatColor.AQUA + getPotionEffectName(effect.getType()) + " " + integerToRomanNumeral(amplifier) + " " + ChatColor.GRAY + "(" + amplifier + ") for " + ChatColor.AQUA + toTime(time)); } } if (meta instanceof PotionMeta) { PotionMeta potion = (PotionMeta) meta; if (potion.hasCustomEffects()) { for (PotionEffect effect : potion.getCustomEffects()) { int amplifier = effect.getAmplifier() + 1; int time = effect.getDuration() / 20; metaMessage.add( ChatColor.AQUA + getPotionEffectName(effect.getType()) + " " + integerToRomanNumeral(amplifier) + " " + ChatColor.GRAY + "(" + amplifier + ") for " + ChatColor.AQUA + toTime(time)); } } } metaMessage.add(ChatColor.DARK_GRAY + "-------------"); } // Note: MapMeta is useless and not used } for (String s : metaMessage) { DumbAuction.getInstance().sendMessage(sender, s); } }
@SuppressWarnings("deprecation") @Override public void populate(World world, Random rand, Chunk chunk) { if (chunk.getX() % 20 == 0 && chunk.getZ() % 20 == 0) { try { InputStream is = plugin.getClass().getClassLoader().getResourceAsStream(filename); SchematicsManager man = new SchematicsManager(); man.loadGzipedSchematic(is); int width = man.getWidth(); int height = man.getHeight(); int length = man.getLength(); int starty = 10; int endy = starty + height; boolean chest1Filled = false, chest2Filled = false, chest3Filled = false, chest4Filled = false, chest5Filled = false, chest6Filled = false; for (int x = 0; x < width; x++) { for (int z = 0; z < length; z++) { int realX = x + chunk.getX() * 16; int realZ = z + chunk.getZ() * 16; for (int y = starty; y <= endy && y < 255; y++) { int rely = y - starty; int id = man.getBlockIdAt(x, rely, z); byte data = man.getMetadataAt(x, rely, z); if (id == -103) world.getBlockAt(realX, y, realZ).setTypeIdAndData(153, data, true); if (id > -1 && world.getBlockAt(realX, y, realZ) != null) { world.getBlockAt(realX, y, realZ).setTypeIdAndData(id, data, true); } if (world.getBlockAt(realX, y, realZ).getType() == Material.MOB_SPAWNER) { BlockState state = world.getBlockAt(realX, y, realZ).getState(); if (state instanceof CreatureSpawner) { ((CreatureSpawner) state).setSpawnedType(EntityType.BLAZE); } } else if (world.getBlockAt(realX, y, realZ).getType() == Material.CHEST) { BlockState state = world.getBlockAt(realX, y, realZ).getState(); if (state instanceof Chest) { Inventory chest = ((Chest) state).getInventory(); if (!chest1Filled) { chest.setItem(7, new ItemStack(Material.DIAMOND, 2)); chest.setItem(10, new ItemStack(Material.SUGAR_CANE, 6)); ItemStack Thorns3 = new ItemStack(Material.ENCHANTED_BOOK); EnchantmentStorageMeta meta = (EnchantmentStorageMeta) Thorns3.getItemMeta(); meta.addStoredEnchant(Enchantment.THORNS, 3, false); Thorns3.setItemMeta(meta); chest.setItem(24, Thorns3); chest1Filled = true; } else if (chest1Filled && !chest2Filled) { chest.setItem(1, new ItemStack(Material.GOLD_INGOT, 3)); chest.setItem(14, new ItemStack(Material.IRON_BARDING, 1)); chest.setItem(20, new ItemStack(Material.NETHER_STALK, 6)); chest2Filled = true; } else if (chest1Filled && chest2Filled && !chest3Filled) { chest.setItem(3, new ItemStack(Material.FLINT_AND_STEEL, 1)); chest.setItem(15, new ItemStack(Material.SADDLE, 1)); chest.setItem(20, new ItemStack(Material.DIAMOND_BARDING, 1)); chest3Filled = true; } else if (chest1Filled && chest2Filled && chest3Filled && !chest4Filled) { chest.setItem(1, new ItemStack(Material.OBSIDIAN, 1)); chest.setItem(21, new ItemStack(Material.GOLD_BARDING, 1)); chest.setItem(26, new ItemStack(Material.DIAMOND, 1)); chest4Filled = true; } else if (chest1Filled && chest2Filled && chest3Filled && chest4Filled && !chest5Filled) { chest.setItem(16, new ItemStack(Material.IRON_INGOT, 8)); chest.setItem(20, new ItemStack(Material.GOLD_INGOT, 5)); chest5Filled = true; } else if (chest1Filled && chest2Filled && chest3Filled && chest4Filled && chest5Filled && !chest6Filled) { chest.setItem(13, new ItemStack(Material.ENDER_PEARL, 1)); chest6Filled = true; } else continue; } } } } } } catch (Exception e) { System.out.println("Could not read the schematic file"); e.printStackTrace(); } } }
@Override public boolean removeStoredEnchant(MCEnchantment ench) { return es.removeStoredEnchant(((BukkitMCEnchantment) ench).__Enchantment()); }
@Override public boolean hasStoredEnchants() { return es.hasStoredEnchants(); }
@Override public int getStoredEnchantLevel(MCEnchantment ench) { return es.getStoredEnchantLevel(((BukkitMCEnchantment) ench).__Enchantment()); }
@Override public boolean addStoredEnchant(MCEnchantment ench, int level, boolean ignoreRestriction) { return es.addStoredEnchant( ((BukkitMCEnchantment) ench).__Enchantment(), level, ignoreRestriction); }