@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void BlockBreakEvent(BlockBreakEvent e) { if (e.getBlock().hasMetadata("ce.Ice")) e.setCancelled(true); CEventHandler.handleEvent(e.getPlayer(), e, blockBroken); if (e.getBlock().hasMetadata("ce.mine")) { Block b = e.getBlock(); b.removeMetadata("ce.mine", Main.plugin); Block[] blocks = { b.getRelative(0, 1, 0), b.getRelative(1, 0, 0), b.getRelative(-1, 0, 0), b.getRelative(0, 0, 1), b.getRelative(0, 0, -1) }; for (Block block : blocks) { if (block.hasMetadata("ce.mine.secondary")) { String[] s = block.getMetadata("ce.mine.secondary").get(0).asString().split(" "); Location loc = new Location( e.getPlayer().getWorld(), Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2])); Location blockLoc = b.getLocation(); if (loc.getBlockX() == blockLoc.getBlockX() && loc.getBlockY() == blockLoc.getBlockY() && loc.getBlockZ() == blockLoc.getBlockZ()) block.removeMetadata("ce.mine.secondary", Main.plugin); } } } }
/** * Handle the Super Breaker ability. * * @param player The player using the ability * @param block The block being affected */ public static void SuperBreakerBlockCheck(Player player, Block block) { Material type = block.getType(); int tier = m.getTier(player.getItemInHand()); int durabilityLoss = LoadProperties.abilityDurabilityLoss; PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); switch (type) { case OBSIDIAN: if (tier < 4) { return; } durabilityLoss = durabilityLoss * 5; // Obsidian needs to do more damage than normal /* FALL THROUGH */ case DIAMOND_ORE: case GLOWING_REDSTONE_ORE: case GOLD_ORE: case LAPIS_ORE: case REDSTONE_ORE: if (tier < 3) { return; } /* FALL THROUGH */ case IRON_ORE: if (tier < 2) { return; } /* FALL THROUGH */ case COAL_ORE: case ENDER_STONE: case GLOWSTONE: case MOSSY_COBBLESTONE: case NETHERRACK: case SANDSTONE: case STONE: if (!block.hasMetadata("mcmmoPlacedBlock")) { return; } Bukkit.getPluginManager().callEvent(armswing); Skills.abilityDurabilityLoss(player.getItemInHand(), durabilityLoss); miningBlockCheck(player, block); miningBlockCheck(player, block); if (LoadProperties.spoutEnabled) { SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation()); } } }
@EventHandler public void onInteract(PlayerInteractEvent event) { if (event.isCancelled()) return; Block b = event.getClickedBlock(); if (event.getAction() == Action.PHYSICAL && b != null && b.hasMetadata("Placer") && b.getType() == Material.STONE_PLATE && b.getRelative(BlockFace.DOWN).getType() == Material.GRAVEL) { b.removeMetadata("Placer", HungergamesApi.getHungergames()); b.setType(Material.AIR); b.getWorld().createExplosion(b.getLocation().clone().add(0.5, 0.5, 0.5), 4F); } }
/** * Process Mining block drops. * * @param player The player mining the block * @param block The block being broken */ public static void miningBlockCheck(Player player, Block block) { if (block.hasMetadata("mcmmoPlacedBlock")) { return; } miningXP(player, block); if (canBeSuperBroken(block.getType())) { final int MAX_BONUS_LEVEL = 1000; int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING); if ((MAX_BONUS_LEVEL > 1000 || (Math.random() * 1000 <= skillLevel)) && mcPermissions.getInstance().miningDoubleDrops(player)) { if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { m.mcDropItem(block.getLocation(), new ItemStack(block.getType())); } else { miningDrops(block); } } } }
/** * Handler for what blocks drop from the explosion. * * @param ores List of ore blocks destroyed by the explosion * @param debris List of non-ore blocks destroyed by the explosion * @param yield Percentage of blocks to drop * @param oreBonus Percentage bonus for ore drops * @param debrisReduction Percentage reduction for non-ore drops * @param extraDrops Number of times to drop each block * @return A list of blocks dropped from the explosion */ private static List<Block> explosionYields( List<Block> ores, List<Block> debris, float yield, float oreBonus, float debrisReduction, int extraDrops) { Iterator<Block> oresIterator = ores.iterator(); List<Block> blocksDropped = new ArrayList<Block>(); while (oresIterator.hasNext()) { Block temp = oresIterator.next(); if (random.nextFloat() < (yield + oreBonus)) { blocksDropped.add(temp); Mining.miningDrops(temp); if (!temp.hasMetadata("mcmmoPlacedBlock")) { for (int i = 1; i < extraDrops; i++) { blocksDropped.add(temp); Mining.miningDrops(temp); } } } } if (yield - debrisReduction > 0) { Iterator<Block> debrisIterator = debris.iterator(); while (debrisIterator.hasNext()) { Block temp = debrisIterator.next(); if (random.nextFloat() < (yield - debrisReduction)) Mining.miningDrops(temp); } } return blocksDropped; }
/** * Gets the integer value from the block's metadata * * @param block Block to access data from * @param key MetadataKey of the value to access * @return Value of the key as an integer */ public static int getInt(Block block, String key) { if (block.hasMetadata(key)) return block.getMetadata(key).get(0).asInt(); else return -1; }
/** * Gets the string value from the block's metadata * * @param block Block to access data from * @param key MetadataKey of the value to access * @return Value of the key as a string */ public static String getString(Block block, String key) { if (block.hasMetadata(key)) return block.getMetadata(key).get(0).asString(); else return ""; }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) { return; } Block block = event.getBlock(); Player player = event.getPlayer(); // We just want the mob spawner events if (block.getType() != Material.MOB_SPAWNER) { return; } // We can't build here? Return then if (!su.canBuildHere(player, block.getLocation())) { return; } // Get the entityID from the spawner short entityID = su.getSpawnerEntityID(block); // Message the player about the broken spawner plugin.informPlayer( player, ChatColor.translateAlternateColorCodes( '\u0026', plugin.localization.getString("spawnerBroken")) .replace("%creature%", su.getCreatureName(entityID))); // If using silk touch, drop spawner itself ItemStack tool = player.getItemInHand(); // Check for SilkTocuh level boolean validToolAndSilkTouch = su.isValidItemAndHasSilkTouch(tool); // Get the world to drop in World world = player.getWorld(); // Mob String mobName = su.getCreatureName(entityID).toLowerCase().replace(" ", ""); // No drops in creative if (plugin.config.getBoolean("noDropsCreative", true) && player.getGameMode() == GameMode.CREATIVE) { return; } // Prevent XP farming/duping event.setExpToDrop(0); // assume not mined boolean mined = false; // drop XP only when destroyed and not silk picked boolean dropXPOnlyOnDestroy = plugin.config.getBoolean("dropXPOnlyOnDestroy", false); if (plugin.config.getBoolean("preventXPFarming", true) && block.hasMetadata("mined")) { mined = block.getMetadata("mined").get(0).asBoolean(); } // Drop maybe some XP if (player.hasPermission("silkspawners.silkdrop." + mobName) || player.hasPermission("silkspawners.destroydrop." + mobName)) { int addXP = plugin.config.getInt("destroyDropXP"); // If we have more than 0 XP, drop them // either we drop XP for destroy and silktouch or only when // destroyed and we have no silktouch if (!mined && addXP != 0 && (!dropXPOnlyOnDestroy || !validToolAndSilkTouch && dropXPOnlyOnDestroy)) { event.setExpToDrop(addXP); // check if we should flag spawners if (plugin.config.getBoolean("preventXPFarming", true)) { block.setMetadata("mined", new FixedMetadataValue(plugin, true)); } } } // random drop chance String mobID = su.eid2MobID.get(entityID); int randomNumber = rnd.nextInt(100); int dropChance = 0; // silk touch if (validToolAndSilkTouch && player.hasPermission("silkspawners.silkdrop." + mobName)) { // Calculate drop chance if (plugin.mobs.contains("creatures." + mobID + ".silkDropChance")) { dropChance = plugin.mobs.getInt("creatures." + mobID + ".silkDropChance", 100); } else { dropChance = plugin.config.getInt("silkDropChance", 100); } if (randomNumber < dropChance) { // Drop spawner world.dropItemNaturally( block.getLocation(), su.newSpawnerItem( entityID, su.getCustomSpawnerName(su.eid2MobID.get(entityID)), 1, false)); } return; } // no silk touch if (player.hasPermission("silkspawners.destroydrop." + mobName)) { if (plugin.config.getBoolean("destroyDropEgg", false)) { // Calculate drop chance randomNumber = rnd.nextInt(100); if (plugin.mobs.contains("creatures." + mobID + ".eggDropChance")) { dropChance = plugin.mobs.getInt("creatures." + mobID + ".eggDropChance", 100); } else { dropChance = plugin.config.getInt("eggDropChance", 100); } if (randomNumber < dropChance) { // Drop egg world.dropItemNaturally(block.getLocation(), su.newEggItem(entityID)); } } // Drop iron bars (or not) int dropBars = plugin.config.getInt("destroyDropBars", 0); if (dropBars != 0) { // Calculate drop chance randomNumber = rnd.nextInt(100); if (plugin.mobs.contains("creatures." + mobID + ".destroyDropChance")) { dropChance = plugin.mobs.getInt("creatures." + mobID + ".destroyDropChance", 100); } else { dropChance = plugin.config.getInt("destroyDropChance", 100); } if (randomNumber < dropChance) { world.dropItem(block.getLocation(), new ItemStack(Material.IRON_FENCE, dropBars)); } } } }
/** * Handler for explosion drops and XP gain. * * @param player Player triggering the explosion * @param event Event whose explosion is being processed */ public static void dropProcessing(Player player, EntityExplodeEvent event) { final int RANK_1_LEVEL = 125; final int RANK_2_LEVEL = 250; final int RANK_3_LEVEL = 375; final int RANK_4_LEVEL = 500; final int RANK_5_LEVEL = 625; final int RANK_6_LEVEL = 750; final int RANK_7_LEVEL = 875; final int RANK_8_LEVEL = 1000; int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING); float yield = event.getYield(); List<Block> blocks = event.blockList(); Iterator<Block> iterator = blocks.iterator(); List<Block> ores = new ArrayList<Block>(); List<Block> debris = new ArrayList<Block>(); List<Block> xp = new ArrayList<Block>(); while (iterator.hasNext()) { Block temp = iterator.next(); if (BlockChecks.isOre(temp.getType())) { ores.add(temp); } else { debris.add(temp); } } // Normal explosion if (skillLevel < RANK_1_LEVEL) { return; } event.setYield(0); // Triple Drops, No debris, +70% ores if (skillLevel >= RANK_8_LEVEL) { xp = explosionYields(ores, debris, yield, .70f, .30f, 3); } // Triple Drops, No debris, +65% ores else if (skillLevel >= RANK_7_LEVEL) { xp = explosionYields(ores, debris, yield, .65f, .30f, 3); } // Double Drops, No Debris, +60% ores else if (skillLevel >= RANK_6_LEVEL) { xp = explosionYields(ores, debris, yield, .60f, .30f, 2); } // Double Drops, No Debris, +55% ores else if (skillLevel >= RANK_5_LEVEL) { xp = explosionYields(ores, debris, yield, .55f, .30f, 2); } // No debris, +50% ores else if (skillLevel >= RANK_4_LEVEL) { xp = explosionYields(ores, debris, yield, .50f, .30f, 1); } // No debris, +45% ores else if (skillLevel >= RANK_3_LEVEL) { xp = explosionYields(ores, debris, yield, .45f, .30f, 1); } // +40% ores, -20% debris else if (skillLevel >= RANK_2_LEVEL) { xp = explosionYields(ores, debris, yield, .40f, .20f, 1); } // +35% ores, -10% debris else if (skillLevel >= RANK_1_LEVEL) { xp = explosionYields(ores, debris, yield, .35f, .10f, 1); } for (Block block : xp) { if (!block.hasMetadata("mcmmoPlacedBlock")) { Mining.miningXP(player, block); } } }
/** * Check for extra Herbalism drops. * * @param block The block to check for extra drops * @param player The player getting extra drops * @param event The event to use for Green Thumb * @param plugin mcMMO plugin instance */ public static void herbalismProcCheck( final Block block, Player player, BlockBreakEvent event, mcMMO plugin) { final PlayerProfile PP = Users.getProfile(player); final int MAX_BONUS_LEVEL = 1000; int herbLevel = PP.getSkillLevel(SkillType.HERBALISM); int id = block.getTypeId(); Material type = block.getType(); Byte data = block.getData(); Location loc = block.getLocation(); Material mat = null; int xp = 0; int catciDrops = 0; int caneDrops = 0; switch (type) { case BROWN_MUSHROOM: case RED_MUSHROOM: if (!block.hasMetadata("mcmmoPlacedBlock")) { mat = Material.getMaterial(id); xp = LoadProperties.mmushroom; } break; case CACTUS: for (int y = 0; y <= 2; y++) { Block b = block.getRelative(0, y, 0); if (b.getType().equals(Material.CACTUS)) { mat = Material.CACTUS; if (!b.hasMetadata("mcmmoPlacedBlock")) { if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) { catciDrops++; } xp += LoadProperties.mcactus; } } } break; case CROPS: if (data == CropState.RIPE.getData()) { mat = Material.WHEAT; xp = LoadProperties.mwheat; if (LoadProperties.wheatRegrowth && mcPermissions.getInstance().greenThumbWheat(player)) { greenThumbWheat(block, player, event, plugin); } } break; case MELON_BLOCK: if (!block.hasMetadata("mcmmoPlacedBlock")) { mat = Material.MELON; xp = LoadProperties.mmelon; } break; case NETHER_WARTS: if (data == (byte) 0x3) { mat = Material.NETHER_STALK; xp = LoadProperties.mnetherwart; } break; case PUMPKIN: case JACK_O_LANTERN: if (!block.hasMetadata("mcmmoPlacedBlock")) { mat = Material.getMaterial(id); xp = LoadProperties.mpumpkin; } break; case RED_ROSE: case YELLOW_FLOWER: if (!block.hasMetadata("mcmmoPlacedBlock")) { mat = Material.getMaterial(id); xp = LoadProperties.mflower; } break; case SUGAR_CANE_BLOCK: for (int y = 0; y <= 2; y++) { Block b = block.getRelative(0, y, 0); if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) { mat = Material.SUGAR_CANE; if (!b.hasMetadata("mcmmoPlacedBlock")) { if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) { caneDrops++; } xp += LoadProperties.msugar; } } } break; case VINE: if (!block.hasMetadata("mcmmoPlacedBlock")) { mat = type; xp = LoadProperties.mvines; } break; case WATER_LILY: if (!block.hasMetadata("mcmmoPlacedBlock")) { mat = type; xp = LoadProperties.mlilypad; } break; default: break; } if (mat == null) { return; } else { ItemStack is = new ItemStack(mat); if (herbLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= herbLevel) { if (type.equals(Material.CACTUS)) { m.mcDropItems(loc, is, catciDrops); } else if (type.equals(Material.MELON_BLOCK)) { m.mcDropItems(loc, is, 3); m.mcRandomDropItems(loc, is, 50, 4); } else if (type.equals(Material.NETHER_WARTS)) { m.mcDropItems(loc, is, 2); m.mcRandomDropItems(loc, is, 50, 3); } else if (type.equals(Material.SUGAR_CANE_BLOCK)) { m.mcDropItems(loc, is, caneDrops); } else { m.mcDropItem(loc, is); } } PP.addXP(SkillType.HERBALISM, xp); Skills.XpCheckSkill(SkillType.HERBALISM, player); } }