Java Code Examples for org.bukkit.entity.TNTPrimed#setFuseTicks()
The following examples show how to use
org.bukkit.entity.TNTPrimed#setFuseTicks() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TNTMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@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( event.getBlock().getLocation().clone().add(new Location(world, 0.5, 0.5, 0.5)), 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())) { event.setCancelled(true); // Allow the block to be placed if priming is cancelled world.playSound(tnt.getLocation(), Sound.FUSE, 1, 1); ItemStack inHand = event.getPlayer().getItemInHand(); if (inHand.getAmount() == 1) { event.getPlayer().setItemInHand(null); } else { inHand.setAmount(inHand.getAmount() - 1); } } } }
Example 2
Source File: TNTMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@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 } } }
Example 3
Source File: TNTMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@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); } } }
Example 4
Source File: TNTMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@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 } } }
Example 5
Source File: TNTMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@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); } } }
Example 6
Source File: SelfDestruct.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void effect(Event e, ItemStack item, int level) { PlayerDeathEvent event = (PlayerDeathEvent) e; for(int i = level; i >= 0; i--) { TNTPrimed tnt = (TNTPrimed) event.getEntity().getWorld().spawnEntity(event.getEntity().getLocation(), EntityType.PRIMED_TNT); tnt.setFuseTicks(delay); tnt.setVelocity(new Vector(Tools.random.nextDouble()*1.5 - 1, Tools.random.nextDouble() * 1.5, Tools.random.nextDouble()*1.5 - 1)); if(!Main.createExplosions) tnt.setMetadata("ce.explosive", new FixedMetadataValue(getPlugin(), null)); } }
Example 7
Source File: Tnt.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onExplosionPrime(ExplosionPrimeEvent event) { if (event.getEntity() instanceof TNTPrimed) { TNTPrimed tnt = (TNTPrimed) event.getEntity(); if (fuse != 4) { tnt.setFuseTicks(fuse); } if (power != 4.0) { tnt.setYield((float) power); } } }
Example 8
Source File: Tnt.java From CardinalPGM with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityExplode(EntityExplodeEvent event) { if (GameHandler.getGameHandler().getMatch().isRunning() && event.getEntity() instanceof TNTPrimed) { if (!blockDamage) { event.blockList().clear(); } else if (yield != 0.3){ event.setYield((float)yield); } UUID player = TntTracker.getWhoPlaced(event.getEntity()); for (Block block : event.blockList()) { if (block.getState() instanceof Dispenser) { Inventory inventory = ((Dispenser) block.getState()).getInventory(); Location location = block.getLocation(); double tntCount = 0; for (ItemStack itemstack : inventory.getContents()) { if (itemstack != null && itemstack.getType() == Material.TNT) tntCount += itemstack.getAmount() * multiplier; if (tntCount >= limit) { tntCount = limit; break; } } inventory.remove(Material.TNT); if (tntCount > 0) { Random random = new Random(); for (double i = tntCount; i > 0; i--) { TNTPrimed tnt = event.getWorld().spawn(location, TNTPrimed.class); Vector velocity = new Vector((1.5 * random.nextDouble()) - 0.75, (1.5 * random.nextDouble()) - 0.75, (1.5 * random.nextDouble()) - 0.75); tnt.setVelocity(velocity); tnt.setFuseTicks(random.nextInt(10) + 10); if (player != null) { tnt.setMetadata("source", new FixedMetadataValue(Cardinal.getInstance(), player)); } } } } } } }
Example 9
Source File: TNTMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@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; ItemStack[] inv = dispenser.getInventory().getContents(); for (int slot = 0; slot < inv.length; slot++) { ItemStack stack = inv[slot]; 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; dispenser.getInventory().setItem(slot, stack); } } } tntCount = (int) Math.ceil(tntCount * this.properties.dispenserNukeMultiplier); for (int i = 0; i < tntCount; i++) { TNTPrimed tnt = match.getWorld().spawn(dispenser.getLocation(), TNTPrimed.class); tnt.setFuseTicks( 10 + match .getRandom() .nextInt(10)); // between 0.5 and 1.0 seconds, same as vanilla TNT chaining Random random = match.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()); } } }