public Ingredient(String ingredient, UltraItems instance) throws Exception { this.ingredient = ingredient; plugin = instance; String[] item = null; try { item = ingredient.split("[:,;-]"); if (item.length >= 1) { itemid = Integer.decode(item[0]); if (item.length >= 2) { itemdata = Integer.decode(item[1]); if (item.length >= 3) { amount = Integer.decode(item[2]); } } } material = MaterialData.getMaterial(itemid, getData()); } catch (Exception e) { if (plugin.itemManager.getItem(ingredient) != null) { material = plugin.itemManager.getItem(ingredient).getCustomItem(); itemid = material.getRawId(); itemdata = material.getRawData(); } } if (material == null) { throw new DataFormatException("Ingredient \"" + ingredient + "\" doesn't exist"); } }
public static final char getWoodMatRefLetter(Material mat) { if (mat.equals(MaterialData.wood)) return '!'; if (mat.equals(MaterialData.jungleWood)) return '@'; if (mat.equals(MaterialData.birchWood)) return '#'; if (mat.equals(MaterialData.spruceWood)) return '$'; return '!'; }
@Override public void setItemName(Material item, String name) { customNames.put(item.getRawId(), item.getRawData(), name); for (Player player : Bukkit.getServer().getOnlinePlayers()) { if (player instanceof SpoutCraftPlayer) { if (((SpoutPlayer) player).isSpoutCraftEnabled()) { ((SpoutPlayer) player) .sendPacket(new PacketItemName(item.getRawId(), (short) item.getRawData(), name)); } } } }
@Override public void resetName(Material item) { int id = item.getRawId(); int data = item.getRawData(); if (customNames.containsKey(id, data)) { customNames.remove(id, data); for (Player player : Bukkit.getServer().getOnlinePlayers()) { if (player instanceof SpoutCraftPlayer) { if (((SpoutPlayer) player).isSpoutCraftEnabled()) { ((SpoutPlayer) player).sendPacket(new PacketItemName(id, (short) data, "[reset]")); } } } } }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { // Prevent trampling switch (event.getAction()) { case PHYSICAL: final Block top = event.getClickedBlock().getRelative((BlockFace.UP)); if (plugin .getWorldRegistry() .contains(top.getWorld().getName(), top.getX(), top.getY(), top.getZ())) { event.setCancelled(true); break; } case RIGHT_CLICK_BLOCK: // Exit this method if player clicking on chest, door, button, etc. switch (event.getClickedBlock().getType()) { case CHEST: case WOOD_BUTTON: case STONE_BUTTON: case WOOD_DOOR: case IRON_DOOR: case IRON_DOOR_BLOCK: case FENCE_GATE: case BREWING_STAND: case FURNACE: case BURNING_FURNACE: return; } final Player interacter = event.getPlayer(); final ItemStack held = event.getItem(); if (held == null) { return; } final Block interacted = event.getClickedBlock(); final SpoutItemStack stack = new SpoutItemStack(held); final String name; // Grab the material's name if (stack.isCustomItem()) { name = stack.getMaterial().getNotchianName(); } else { name = held.getType().name(); } // Fertilizer logic final Sprout dispersed = plugin .getWorldRegistry() .get( interacted.getWorld().getName(), interacted.getX(), interacted.getY(), interacted.getZ()); if (dispersed != null && !((SimpleSprout) dispersed).isOnLastStage() && dispersed.getVariables().allowFertilization()) { final Stage current = dispersed.getCurrentStage(); final Fertilizer fertilizer; if (current == null) { fertilizer = dispersed.getFertilizerSource(); } else { fertilizer = current.getFertilizer(); } boolean toContinue = false; // Bonemeal if ((fertilizer.getName().equals("bonemeal") && name.equals("INK_SACK"))) { toContinue = true; // Custom Block } else if (fertilizer.getName().endsWith(name)) { toContinue = true; // Material } else if (fertilizer.getName().equals(name.toLowerCase())) { toContinue = true; } if (!toContinue) { return; } event.setCancelled(true); Stage stage; org.getspout.spoutapi.material.Material customMaterial; Material material; // Stage 0 if (current == null) { stage = dispersed.getStage(1); customMaterial = MaterialData.getCustomBlock(stage.getName()); material = Material.getMaterial(stage.getName().toUpperCase()); if (customMaterial == null) { if (material == null) { return; } } // Grow to stage 1 ((SimpleSprout) dispersed).grow(stage); if (customMaterial != null) { ((SpoutBlock) interacted).setCustomBlock((CustomBlock) customMaterial); } else { ((SpoutBlock) interacted).setCustomBlock(null); interacted.setType(material); } } else { stage = ((SimpleSprout) dispersed).getNextStage(); if (stage == null) { return; } customMaterial = MaterialData.getCustomBlock(stage.getName()); material = Material.getMaterial(stage.getName().toUpperCase()); if (customMaterial == null) { if (material == null) { return; } } ((SimpleSprout) dispersed).incrementFertilizerCount(stage); if (((SimpleSprout) dispersed).getFertilizerCount(stage) >= fertilizer.getAmount()) { if (customMaterial != null) { ((SpoutBlock) interacted).setCustomBlock((CustomBlock) customMaterial); } else { ((SpoutBlock) interacted).setCustomBlock(null); interacted.setType(material); } ((SimpleSprout) dispersed).grow(stage); } if (((SimpleSprout) dispersed).isOnLastStage()) { ((SimpleSprout) dispersed).setFullyGrown(true); final SaveThread thread = ((SaveThread) ThreadRegistry.get(interacted.getWorld().getName())); if (thread != null) { thread.add(interacted.getLocation(), (SimpleSprout) dispersed); } } } decrementInventory(interacter, interacter.getItemInHand()); } else { // Non-fertilizer logic final Sprout sprout = plugin.getSproutRegistry().find(name); if (sprout == null) { return; } event.setCancelled(true); // Block face logic. TODO Customizable? if (event.getBlockFace() != BlockFace.UP) { return; } // Soil logic org.getspout.spoutapi.material.Material customMaterial = MaterialData.getCustomItem(sprout.getPlacementSource()); Material material = Material.getMaterial(sprout.getPlacementSource().toUpperCase()); if (customMaterial == null || !(((SpoutBlock) interacted).getBlockType() instanceof CustomBlock) || !((CustomBlock) ((SpoutBlock) interacted).getBlockType()) .getFullName() .equalsIgnoreCase(customMaterial.getName())) { if (material == null || !interacted.getType().equals(material)) { return; } } final Block where = interacted.getRelative(BlockFace.UP); // Make sure where we are setting the block won't be already obstructed. if (where.getType() != Material.AIR) { return; } // Handle Jobs Integration Calls if (SproutConfiguration.jobsEnabled) { if (!Jobs.hasRequiredJobAndLevel( event.getPlayer(), "Farmer", sprout.getMinimumLevelRequired())) { event .getPlayer() .sendMessage( ChatColor.DARK_AQUA + "[Sprout]" + ChatColor.WHITE + " Planting this seed requires the job " + ChatColor.GOLD + "[Farmer]" + ChatColor.WHITE + ", at level " + ChatColor.GOLD + sprout.getMinimumLevelRequired() + ChatColor.WHITE + " or higher."); return; } // Planting experience within jobs is handled by block place of the vanilla block of // "CROP" } final Sprout toInject = cloner.deepClone(sprout); plugin .getWorldRegistry() .add(where.getWorld().getName(), where.getX(), where.getY(), where.getZ(), toInject); final SaveThread thread = ((SaveThread) ThreadRegistry.get(where.getWorld().getName())); if (thread != null) { thread.add(where.getLocation(), (SimpleSprout) toInject); } // Set material if (stack.isCustomItem()) { final CustomBlock block = MaterialData.getCustomBlock(sprout.getBlockSource()); ((SpoutBlock) where).setCustomBlock(block); interacter.playSound(interacter.getLocation(), Sound.DIG_GRASS, 1.0F, 0.7936508F); decrementInventory(interacter, held); } // Handle Jobs Integration Calls if (SproutConfiguration.jobsEnabled) { JobsWorker.jobsPlace(event.getPlayer(), where); } } } }