@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onTNTChain(EntityExplodeEvent event) { if(!this.tracker.isEnabled(event.getEntity().getWorld())) return; // Transfer ownership to chain-activated TNT if(event.getEntity() instanceof TNTPrimed) { Player owner = this.tracker.setOwner((TNTPrimed) event.getEntity(), null); if(owner != null) { for(Block block : event.blockList()) { if(block.getType() == Material.TNT) { this.tracker.setPlacer(block, owner); } } } } }
public void clear(@Nonnull World world) { Preconditions.checkNotNull(world, "world"); // clear information about blocks in that world for(Iterator<Map.Entry<Block, Player>> it = this.placedBlocks.entrySet().iterator(); it.hasNext(); ) { Block block = it.next().getKey(); if(block.getWorld().equals(world)) { it.remove(); } } // clear information about entities in that world for(Iterator<Map.Entry<TNTPrimed, Player>> it = this.ownedTNTs.entrySet().iterator(); it.hasNext(); ) { TNTPrimed tnt = it.next().getKey(); if(tnt.getWorld().equals(world)) { it.remove(); } } }
public @Nullable DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) { if(damageEvent instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) damageEvent; if(event.getDamager() instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) event.getDamager(); Player owner = null; if(this.explosiveTracker.hasOwner(tnt)) { owner = this.explosiveTracker.getOwner(tnt); } else if(this.dispenserTracker.hasOwner(tnt)) { // getPlayer() is temporary to keep owner uniform until other services use OfflinePlayer owner = this.dispenserTracker.getOwner(tnt).getPlayer(); } return new TNTDamageInfo(tnt, owner); } } return null; }
public void spawn() { Location location = data.region().getRandom(match.getRandom()).toLocation(world); effects(Sound.BLOCK_NOTE_BASEDRUM, Particle.CLOUD); Entity entity = world.spawn(location, (Class) data.appearance().getEntityClass()); entity.setKnockbackReduction(1); data.name().ifPresent(name -> { entity.setCustomName(ChatColor.translateAlternateColorCodes('`', name)); entity.setCustomNameVisible(true); }); switch(data.appearance()) { // TODO: Support more appearances later case ENDER_CRYSTAL: ifInstance(entity, EnderCrystal.class, crystal -> crystal.setShowingBottom(false)); break; case PRIMED_TNT: ifInstance(entity, TNTPrimed.class, tnt -> tnt.setFuseTicks(Integer.MAX_VALUE)); break; } this.entity = Optional.of(entity); spawnAt = Optional.empty(); }
/** * Spawns a creeper or primed TNT when a player breaks an ore block, by chance. * * @param event The event */ @EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); if (ORES.contains(block.getType())) { double chance = Math.random(); Location location = block.getLocation().add(0.5, 0.5, 0.5); if (0.05 > chance) { TNTPrimed tnt = location.getWorld().spawn(location, TNTPrimed.class); tnt.setFuseTicks(80); } else if (0.1 > chance) { Creeper creeper = location.getWorld().spawn(location, Creeper.class); creeper.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 2, 2)); } } }
@EventHandler public void onEntityExplode(EntityExplodeEvent event) { if (event.getEntity() != null) { if (event.getEntity().getType() == EntityType.PRIMED_TNT) { for (Block block : event.blockList()) { if (block.getType() == Material.TNT && getWhoPlaced(event.getEntity()) != null) { Location location = block.getLocation(); tntPlaced.put(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ(), getWhoPlaced(event.getEntity())); } } for (Entity entity : event.getEntity().getNearbyEntities(8, 8, 8)) { // F.debug("Found tnt"); if (entity instanceof TNTPrimed) { UUID playerUUID = getWhoPlaced(event.getEntity()); if(playerUUID != null) { Dispenser dispenser; // F.debug("found placer: " + Bukkit.getServer().getPlayer(playerUUID)); entity.setMetadata("source", new FixedMetadataValue(GamePlate.getInstance(), playerUUID)); } } } } } }
@EventHandler(ignoreCancelled = true) public void onExplosionPrime(ExplosionPrimeEvent event) { if (event.getEntity() instanceof TNTPrimed) { Block block = event.getEntity().getLocation().getBlock(); if (!block.getType().equals(Material.TNT)) { return; } Player player = null; if (event instanceof ExplosionPrimeByEntityEvent) { ExplosionPrimeByEntityEvent primeByEntity = (ExplosionPrimeByEntityEvent) event; Entity entity = primeByEntity.getPrimer(); if (entity instanceof Player) { player = (Player) entity; } } this.post(event, block.getState(), this.applyAir(block), player); } }
@Override public void change(Event e, Object[] delta, Changer.ChangeMode mode){ if (entity.getSingle(e) instanceof TNTPrimed) { Number ticks = (Number)delta[0]; Number ticksNow = ((TNTPrimed)entity.getSingle(e)).getFuseTicks(); if (mode == ChangeMode.SET) { ((TNTPrimed)entity.getSingle(e)).setFuseTicks(ticks.intValue()); } else if (mode == ChangeMode.ADD) { ((TNTPrimed)entity.getSingle(e)).setFuseTicks(ticksNow.intValue() + ticks.intValue()); } else if (mode == ChangeMode.REMOVE) { ((TNTPrimed)entity.getSingle(e)).setFuseTicks(ticksNow.intValue() - ticks.intValue()); } } else { return; } }
@EventHandler(ignoreCancelled = true) public void onEntityExplodeEvent(EntityExplodeEvent event) { AttackType attackType = AttackType.UNKNOWN; Entity attacker = event.getEntity(); if (attacker instanceof TNTPrimed) { attackType = AttackType.TNT; } else if (attacker instanceof Creeper) { attackType = AttackType.CREEPER; } else if (attacker instanceof Fireball) { if (((Fireball) attacker).getShooter() instanceof Ghast) { attackType = AttackType.GHAST; } } if (plugin.getChestSettings().allowDestroyBy(attackType)) { return; } for (Iterator<Block> it = event.blockList().iterator(); it.hasNext();) { Block block = it.next(); if (isProtected(block)) { it.remove(); } } }
/** * Detonate TNT for Blast Mining */ public void remoteDetonation() { Player player = getPlayer(); Block targetBlock = player.getTargetBlock(BlockUtils.getTransparentBlocks(), BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE); if (targetBlock.getType() != Material.TNT || !EventUtils.simulateBlockBreak(targetBlock, player, true) || !blastMiningCooldownOver()) { return; } TNTPrimed tnt = player.getWorld().spawn(targetBlock.getLocation(), TNTPrimed.class); SkillUtils.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player)); player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom")); tnt.setMetadata(mcMMO.tntMetadataKey, mcMMOPlayer.getPlayerMetadata()); tnt.setFuseTicks(0); targetBlock.setType(Material.AIR); mcMMOPlayer.setAbilityDATS(AbilityType.BLAST_MINING, System.currentTimeMillis()); mcMMOPlayer.setAbilityInformed(AbilityType.BLAST_MINING, false); new AbilityCooldownTask(mcMMOPlayer, AbilityType.BLAST_MINING).runTaskLaterAsynchronously(mcMMO.p, AbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR); }
/** * Handle ExplosionPrime events that involve modifying the event. * * @param event The event to modify */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onExplosionPrime(ExplosionPrimeEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) { return; } // We can make this assumption because we (should) be the only ones using this exact metadata Player player = plugin.getServer().getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString()); if (!UserManager.hasPlayerDataKey(player)) { return; } MiningManager miningManager = UserManager.getPlayer(player).getMiningManager(); if (miningManager.canUseBiggerBombs()) { event.setRadius(miningManager.biggerBombs(event.getRadius())); } }
/** * Handle EntityExplode events that involve modifying the event. * * @param event The event to modify */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEnitityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) { return; } // We can make this assumption because we (should) be the only ones using this exact metadata Player player = plugin.getServer().getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString()); if (!UserManager.hasPlayerDataKey(player)) { return; } MiningManager miningManager = UserManager.getPlayer(player).getMiningManager(); if (miningManager.canUseBlastMining()) { miningManager.blastMiningDropProcessing(event.getYield(), event.blockList()); event.setYield(0); } }
private static void tntBarrage(CircleOfBoom circle){ COBUtils.setCircle(circle); taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(), new Runnable() { int distance = 1; int x = (int)COBUtils.getCircle().getCenter().getX(); int z = (int)COBUtils.getCircle().getCenter().getZ(); World world = COBUtils.getCircle().getWorld(); @Override public void run() { if(distance<COBUtils.getCircle().getRadious()){ world.spawn(new Location(world, x+distance, COBUtils.getCircle().getCenter().getY()+20, z), TNTPrimed.class); world.spawn(new Location(world, x-distance, COBUtils.getCircle().getCenter().getY()+20, z), TNTPrimed.class); world.spawn(new Location(world, x, COBUtils.getCircle().getCenter().getY()+20, z+distance), TNTPrimed.class); world.spawn(new Location(world, x, COBUtils.getCircle().getCenter().getY()+20, z-distance), TNTPrimed.class); } else { Bukkit.getScheduler().cancelTask(taskId); } distance++; } }, 0L, 5L); }
@EventHandler(priority = EventPriority.LOW) public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); Client client = Client.getClient(player); if(client.isObserver() || !Rixor.getRotation().getSlot().getMatch().isCurrentlyRunning()) { event.setCancelled(true); return; } if (event.getBlockPlaced().getType() == Material.TNT && Rixor.getRotation().getSlot().getMap().getTntsettings().isInstantIgnite()){ event.getBlockPlaced().setType(Material.AIR); TNTPrimed tnt = event.getBlockPlaced().getWorld().spawn(event.getBlockPlaced().getLocation(), TNTPrimed.class); } if(!client.isObserver()) { Map map = Rixor.getRotation().getSlot().getMap(); BlockChangeEvent change = new BlockChangeEvent(event, map, client, event.getBlockReplacedState(), event.getBlockPlaced().getState()); Rixor.callEvent(change); } }
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onEntityExplodeNormal(EntityExplodeEvent event) { Map map = Rixor.getRotation().getSlot().getMap(); Client client = null; if(event.getEntity() instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) event.getEntity(); if(tnt.getSource() instanceof Player) client = Client.getClient((Player) tnt.getSource()); } for(Block block : event.blockList()) { BlockState newState = block.getState(); newState.setData(new MaterialData(Material.AIR, (byte) 0)); BlockChangeEvent change = new BlockChangeEvent(event, map, client, block.getState(), newState); Rixor.callEvent(change); } }
@Override public void doOnLeftClick(Racer racer, Action action) { // This will be performed in the event that you left-click with the item. if(EquestrianDash.plugin.getConfig().getBoolean("Powerups.TNT.ThrowDirections.ThrowAheadEnabled")) { Player p = racer.getPlayer(); p.playSound(p.getLocation(), Sound.FUSE, 7, 1); TNTPrimed tnt = p.getWorld().spawn(p.getLocation(), TNTPrimed.class); tnt.setVelocity(p.getLocation().getDirection().normalize().multiply(EquestrianDash.plugin.getConfig().getDouble("Powerups.TNT.ThrowDirections.ThrowAheadMultiplier"))); tnt.setFuseTicks(EquestrianDash.plugin.getConfig().getInt("Powerups.TNT.ThrowDirections.ThrowAheadTicks")); racer.getPlayer().getInventory().clear(); } }
@Override public boolean run(Player player, ConfigurationSection config) { Location loc = player.getTargetBlock(null, config.getInt("max_distence")).getLocation(); final TNTPrimed tnt = player.getWorld().spawn(loc.add(0, 1, 0), TNTPrimed.class); tnt.setYield((float) config.getDouble("power")); tnt.setIsIncendiary(config.getBoolean("enable_fire")); tnt.setFuseTicks(0); bombSites.put(tnt, player.getName()); Bukkit.getScheduler().scheduleSyncDelayedTask(RodsTwo.getInstance(), new Runnable(){ @Override public void run() { bombSites.remove(tnt); }}, 10L); //player.getWorld().createExplosion(loc, (float) config.getDouble("power"), config.getBoolean("enable_fire")); return true; }
@EventHandler(ignoreCancelled=true) public void onEntityExplode(EntityExplodeEvent event) { if (event.getEntity() instanceof TNTPrimed && bombSites.containsKey((TNTPrimed) event.getEntity())) { for (Block b : event.blockList()) { if (Math.random() < 0.4) { FallingBlock block = event.getEntity().getWorld().spawnFallingBlock(b.getLocation().add(0, 1, 0), b.getType(), b.getData()); Location bLoc = b.getLocation(); Location tLoc = event.getEntity().getLocation(); double power = 0.15; double x = (bLoc.getX() - tLoc.getX()) * power + Math.random() - 0.5; double z = (bLoc.getZ() - tLoc.getZ()) * power + Math.random() - 0.5; double y = 0.8; block.setVelocity(new Vector(x, y, z)); block.setDropItem(false); } b.setType(Material.AIR); } } }
@EventHandler public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); if (SweetPvP.inGame.contains(player)) { if (event.getBlockPlaced().getType() == Material.TNT) { event.getBlockPlaced().setType(Material.AIR); Location loc = event.getBlockPlaced().getLocation(); loc.setY(loc.getY() + 0.4); Entity tnt = event.getPlayer().getWorld().spawn(loc, TNTPrimed.class); ((TNTPrimed) tnt).setFuseTicks(80); event.getPlayer().getInventory().removeItem(new ItemStack(Material.TNT, 1)); } if (event.getBlockPlaced().getType() != Material.FIRE) { event.setCancelled(true); } } }
@Override public void rightClick(Player player) { long cooldown; RPGValue value = RPGValue.get(player, item, "tnt.cooldown"); if (value == null) { cooldown = System.currentTimeMillis() / 50; value = new RPGValue(player, item, "tnt.cooldown", cooldown); } else { cooldown = value.asLong(); } if (cooldown <= System.currentTimeMillis() / 50) { value.set(System.currentTimeMillis() / 50 + cooldownTime); player.playSound(player.getLocation(), Sound.SHOOT_ARROW, 1.0f, 1.0f); TNTPrimed tnt = player.getWorld().spawn(player.getLocation().add(0, 1.8, 0), TNTPrimed.class); tnt.setVelocity(player.getLocation().getDirection().multiply(2d)); } else { player.sendMessage(ChatColor.AQUA + String.format(Locale.get("message.cooldown", Locale.getPlayerLocale(player)), ((double) (cooldown - System.currentTimeMillis() / 50)) / 20d)); } }
@Override public void rightClick(Player player) { long cooldown; if (item.getHasPermission() == true && player.hasPermission(item.getPermission()) == false){ }else{ RPGValue value = RPGValue.get(player, item, "tnt.cooldown"); if (value == null) { cooldown = System.currentTimeMillis() / 50; value = new RPGValue(player, item, "tnt.cooldown", cooldown); } else { cooldown = value.asLong(); } if (cooldown <= System.currentTimeMillis() / 50) { value.set(System.currentTimeMillis() / 50 + cooldownTime); player.playSound(player.getLocation(), Sound.SHOOT_ARROW, 1.0f, 1.0f); TNTPrimed tnt = player.getWorld().spawn(player.getLocation().add(0, 1.8, 0), TNTPrimed.class); tnt.setVelocity(player.getLocation().getDirection().multiply(2d)); } else { player.sendMessage(ChatColor.AQUA + String.format(Locale.get("message.cooldown", Locale.getPlayerLocale(player)), ((double) (cooldown - System.currentTimeMillis() / 50)) / 20d)); } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onTNTIgnite(ExplosionPrimeEvent event) { if(!this.tracker.isEnabled(event.getEntity().getWorld())) return; if(event.getEntity() instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) event.getEntity(); Block block = event.getEntity().getWorld().getBlockAt(event.getEntity().getLocation()); if(block != null) { Player placer = this.tracker.setPlacer(block, null); if(placer != null) { this.tracker.setOwner(tnt, placer); } } } }
public @Nullable Player setOwner(@Nonnull TNTPrimed entity, @Nullable Player player) { Preconditions.checkNotNull(entity, "tnt entity"); if(player != null) { return this.ownedTNTs.put(entity, player); } else { return this.ownedTNTs.remove(entity); } }
private void participantDefuse(Player player, Entity entity) { if(!AntiGrief.Defuse.enabled()) return; // check tnt if(!(entity instanceof TNTPrimed)) return; TNTMatchModule tntmm = mm.getMatch(player.getWorld()).getMatchModule(TNTMatchModule.class); if(tntmm != null && !tntmm.getProperties().friendlyDefuse) return; MatchPlayer clicker = this.mm.getPlayer(player); if(clicker == null || !clicker.canInteract()) return; // check water Block block = entity.getLocation().getBlock(); if(block != null && (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)) { clicker.sendMessage(ChatColor.RED + PGMTranslations.t("defuse.water", clicker)); return; } // check owner MatchPlayer owner = this.mm.getPlayer(entityResolver.getOwner(entity)); if(owner == null || (owner != clicker && owner.getParty() == clicker.getParty())) { // cannot defuse own TNT // defuse TNT entity.remove(); if(owner != null) { this.notifyDefuse(clicker, entity, ChatColor.RED + PGMTranslations.t("defuse.player", clicker, owner.getDisplayName(clicker) + ChatColor.RED)); adminChannel.broadcast(clicker.getDisplayName() + ChatColor.WHITE + " defused " + owner.getDisplayName() + ChatColor.WHITE + "'s " + ChatColor.DARK_RED + "TNT"); } else { this.notifyDefuse(clicker, entity, ChatColor.RED + PGMTranslations.t("defuse.world", clicker)); } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void handleInstantActivation(BlockPlaceEvent event) { if(this.properties.instantIgnite && event.getBlock().getType() == Material.TNT) { World world = event.getBlock().getWorld(); TNTPrimed tnt = world.spawn(BlockUtils.base(event.getBlock()), TNTPrimed.class); if(this.properties.fuse != null) { tnt.setFuseTicks(this.getFuseTicks()); } if(this.properties.power != null) { tnt.setYield(this.properties.power); // Note: not related to EntityExplodeEvent.yield } if(callPrimeEvent(tnt, event.getPlayer(), true)) { // Only cancel the block placement if the prime event is NOT cancelled. // If priming is cancelled, the block is allowed to stay (unless some // other handler has already cancelled the place event). event.setCancelled(true); world.playSound(tnt.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1); ItemStack inHand = event.getItemInHand(); if(inHand.getAmount() == 1) { inHand = null; } else { inHand.setAmount(inHand.getAmount() - 1); } event.getPlayer().getInventory().setItem(event.getHand(), inHand); } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void setCustomProperties(ExplosionPrimeEvent event) { if(event.getEntity() instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) event.getEntity(); if(this.properties.fuse != null) { tnt.setFuseTicks(this.getFuseTicks()); } if(this.properties.power != null) { tnt.setYield(this.properties.power); // Note: not related to EntityExplodeEvent.yield } } }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void dispenserNukes(BlockTransformEvent event) { BlockState oldState = event.getOldState(); if(oldState instanceof Dispenser && this.properties.dispenserNukeLimit > 0 && this.properties.dispenserNukeMultiplier > 0 && event.getCause() instanceof EntityExplodeEvent) { EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause(); Dispenser dispenser = (Dispenser) oldState; int tntLimit = Math.round(this.properties.dispenserNukeLimit / this.properties.dispenserNukeMultiplier); int tntCount = 0; for(ItemStack stack : dispenser.getInventory().contents()) { if(stack != null && stack.getType() == Material.TNT) { int transfer = Math.min(stack.getAmount(), tntLimit - tntCount); if(transfer > 0) { stack.setAmount(stack.getAmount() - transfer); tntCount += transfer; } } } tntCount = (int) Math.ceil(tntCount * this.properties.dispenserNukeMultiplier); for(int i = 0; i < tntCount; i++) { TNTPrimed tnt = this.getMatch().getWorld().spawn(BlockUtils.base(dispenser), TNTPrimed.class); tnt.setFuseTicks(10 + this.getMatch().getRandom().nextInt(10)); // between 0.5 and 1.0 seconds, same as vanilla TNT chaining Random random = this.getMatch().getRandom(); Vector velocity = new Vector(random.nextGaussian(), random.nextGaussian(), random.nextGaussian()); // uniform random direction velocity.normalize().multiply(0.5 + 0.5 * random.nextDouble()); tnt.setVelocity(velocity); callPrimeEvent(tnt, explodeEvent.getEntity(), false); } } }
private void removeEntities(Location origin, double radius) { if(radius <= 0) return; double radiusSq = radius * radius; for(Entity ent : origin.getWorld().getEntities()) { if(origin.distanceSquared(ent.getLocation()) > radiusSq) continue; if(ent instanceof TNTPrimed) { ent.remove(); } } }
@EventWrapper public void onPrimeTNT(ExplosionPrimeEvent event) { if(event.getEntity() instanceof TNTPrimed && !(event instanceof InstantTNTPlaceEvent)) { Block block = event.getEntity().getLocation().getBlock(); if(block.getType() == Material.TNT) { ParticipantState player; if(event instanceof ExplosionPrimeByEntityEvent) { player = entityResolver.getOwner(((ExplosionPrimeByEntityEvent) event).getPrimer()); } else { player = null; } callEvent(event, block.getState(), BlockStateUtils.toAir(block), player); } } }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPrime(ExplosionPrimeEvent event) { if(event.getEntity() instanceof TNTPrimed) { // Some TNT was activated, try to figure out why TNTPrimed tnt = (TNTPrimed) event.getEntity(); TNTInfo info = null; if(event instanceof ExplosionPrimeByEntityEvent) { Entity primer = ((ExplosionPrimeByEntityEvent) event).getPrimer(); if(primer instanceof TNTPrimed) { // Primed by another owned explosive, propagate the damage info (e.g. origin location) info = resolveEntity(primer); } else { ParticipantState owner = entities().getOwner(primer); if(owner != null) { // Primed by some other type of owned entity e.g. flaming arrow, pet creeper, etc. info = new TNTInfo(owner, tnt.getLocation()); } } } if(info == null) { ParticipantState placer = blocks().getOwner(tnt.getLocation().getBlock()); if(placer != null) { // If no primer was resolved for the event, give the TNT entity to the block placer, if any info = new TNTInfo(placer, tnt.getLocation()); } } if(info != null) { entities().trackEntity(tnt, info); } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDispense(BlockDispenseEntityEvent event) { if(event.getEntity() instanceof TNTPrimed) { ParticipantState owner = blocks().getOwner(event.getBlock()); if(owner != null) { entities().trackEntity(event.getEntity(), new TNTInfo(owner, event.getEntity().getLocation())); } } }
public static String getTranslationKey(Entity entity) { if(entity instanceof TNTPrimed) { return "tile.tnt.name"; } else if(entity instanceof Egg) { return "item.egg.name"; } else { final String id = EntityTypes.b(((CraftEntity) entity).getHandle()); return "entity." + (id != null ? id : "generic") + ".name"; } }
@EventHandler(priority = EventPriority.HIGH) public void onEntityExplode(EntityExplodeEvent event) { Entity ent = event.getEntity(); if( (ent != null && ent instanceof TNTPrimed) ) { if( event.getLocation() != null ) { if( NavyCraft.shotTNTList.containsKey(ent.getUniqueId()) ) { Craft checkCraft; checkCraft = structureUpdate(event.getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId())); if( checkCraft == null ) { checkCraft = structureUpdate(event.getLocation().getBlock().getRelative(4,4,4).getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId())); if( checkCraft == null ) { checkCraft = structureUpdate(event.getLocation().getBlock().getRelative(-4,-4,-4).getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId())); if( checkCraft == null ) { checkCraft = structureUpdate(event.getLocation().getBlock().getRelative(2,-2,-2).getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId())); if( checkCraft == null ) { checkCraft = structureUpdate(event.getLocation().getBlock().getRelative(-2,2,2).getLocation(), NavyCraft.shotTNTList.get(ent.getUniqueId())); } } } } NavyCraft.shotTNTList.remove(ent.getUniqueId()); } else structureUpdate(event.getLocation(), null); } } }
@EventHandler public void onThrowTNT(PlayerInteractEvent event) { Player p = event.getPlayer(); Gamer g = Gamer.get(p.getName()); if (g.getVariable("spectator") != null) return; if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (p.getItemInHand().getType() == Material.TNT) { // Frag Grenades TNTPrimed e = (TNTPrimed) event.getPlayer().getWorld().spawnEntity(p.getEyeLocation(), EntityType.PRIMED_TNT); e.setFuseTicks(38); e.setYield(2.5F); e.setVelocity(event.getPlayer().getEyeLocation().getDirection()); e.setMetadata("Player", new FixedMetadataValue(Nexus.getPlugin(), g.getPlayer().getName())); e.setMetadata("Cause", new FixedMetadataValue(Nexus.getPlugin(), CustomDamageCause.TNT_GRENADE.name())); event.setUseItemInHand(Event.Result.DENY); ItemStack stack = null; if (event.getItem().getAmount() > 1) { ItemStack s = event.getItem(); s.setAmount(event.getItem().getAmount() - 1); stack = s; } p.getInventory().setItem(p.getInventory().getHeldItemSlot(), stack); event.setCancelled(true); } } }
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Gamer g = Gamer.get(event.getPlayer()); if (event.getAction() != Action.PHYSICAL) return; Block b = event.getClickedBlock(); if (!b.hasMetadata("Mine")) return; Mine mine = Mine.getList().get(b.getMetadata("Mine").get(0).asInt()); Team playerTeam = Nexus.getRotary().getCurrentMap().getTeam(g); Team targetTeam = Nexus.getRotary().getCurrentMap().getTeam(mine.getGamer()); if (playerTeam == targetTeam) return; mine.setIgnited(true); TNTPrimed e = (TNTPrimed) event.getPlayer().getWorld().spawnEntity(event.getPlayer().getEyeLocation(), EntityType.PRIMED_TNT); e.setFuseTicks(10); e.setYield(2.7F); e.setMetadata("Player", new FixedMetadataValue(Nexus.getPlugin(), mine.getGamer().getName())); e.setMetadata("Cause", new FixedMetadataValue(Nexus.getPlugin(), CustomDamageCause.TNT_MINE.name())); event.getClickedBlock().setType(Material.AIR); }
/** * Fire the TNT's automatically * * @param event Event */ @EventHandler public void onBlockPlace(BlockPlaceEvent event) { if (this.game != null && this.game.isPvPActivated() && event.getBlock().getType() == Material.TNT) { event.getBlock().setType(Material.AIR); TNTPrimed tnt = event.getBlock().getWorld().spawn(event.getBlock().getLocation(), TNTPrimed.class); tnt.setFuseTicks(tnt.getFuseTicks() / 2); } }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onTNTExplode(EntityExplodeEvent e) { if (!cm.disableChainReaction) { return; } Entity entity = e.getEntity(); if (entity instanceof TNTPrimed) { for (Entity primedTNT : entity.getNearbyEntities(4.5, 4.5, 4.5)) { if (primedTNT instanceof TNTPrimed) { primedTNT.remove(); } } } }
@EventHandler public void onExplosionPrime(ExplosionPrimeEvent event) { if (event.getEntity().getType() == EntityType.PRIMED_TNT) { TNTPrimed tnt = (TNTPrimed) event.getEntity(); Location location = event.getEntity().getLocation(); if (tntPlaced.containsKey(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ())) { UUID playerUUID = tntPlaced.get(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ()); event.getEntity().setMetadata("source", new FixedMetadataValue(GamePlate.getInstance(), playerUUID)); tntPlaced.remove(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ()); } } }
@EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (event.isCancelled()) return; if (event.getEntity() instanceof Player) { TrackerDamageEvent damage; Description description = null; if (event.getEntity().getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.LADDER)) { description = Description.OFF_A_LADDER; } else if (event.getEntity().getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.VINE)) { description = Description.OFF_A_VINE; } else if (event.getEntity().getLocation().getBlock().getType().equals(Material.WATER) || event.getEntity().getLocation().getBlock().getType().equals(Material.STATIONARY_WATER)) { description = Description.OUT_OF_THE_WATER; } else if (event.getEntity().getLocation().getBlock().getType().equals(Material.LAVA) || event.getEntity().getLocation().getBlock().getType().equals(Material.STATIONARY_LAVA)) { description = Description.OUT_OF_THE_LAVA; } if (event.getDamager() instanceof Projectile) { OfflinePlayer source = null; if (((Projectile) event.getDamager()).getShooter() instanceof Player) { source = (Player) ((Projectile) event.getDamager()).getShooter(); } damage = new TrackerDamageEvent((Player) event.getEntity(), source, null, Cause.PLAYER, description, Type.SHOT); } else if (event.getDamager() instanceof Player) { damage = new TrackerDamageEvent((Player) event.getEntity(), (Player) event.getDamager(), ((Player) event.getDamager()).getItemInHand(), Cause.PLAYER, description, Type.KNOCKED); } else if (event.getDamager() instanceof TNTPrimed) { UUID uuid = TntTracker.getWhoPlaced(event.getDamager()); if (uuid != null) { damage = new TrackerDamageEvent((Player) event.getEntity(), Bukkit.getOfflinePlayer(uuid), null, Cause.TNT, description, Type.BLOWN); } else damage = new TrackerDamageEvent((Player) event.getEntity(), null, null, Cause.TNT, description, Type.BLOWN); } else { damage = new TrackerDamageEvent((Player) event.getEntity(), null, null, Cause.PLAYER, description, Type.KNOCKED); } Bukkit.getServer().getPluginManager().callEvent(damage); } }