Java Code Examples for org.bukkit.Material#TNT

The following examples show how to use org.bukkit.Material#TNT . 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: FlagBowspleef.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void dropBlock(Block block) {
	Plugin plugin = getHeavySpleef().getPlugin();
	Location location = block.getLocation();
	World world = location.getWorld();
	
	if (block.getType() == Material.TNT) {
		TNTPrimed tntEntity = (TNTPrimed) world.spawnEntity(location.add(0.5, 0, 0.5), EntityType.PRIMED_TNT);
		tntEntity.setMetadata(BOWSPLEEF_METADATA_KEY, new FixedMetadataValue(plugin, true));
		tntEntity.setVelocity(new Vector());
	} else {
		FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(location, block.getType(), block.getData());
		fallingBlock.setMetadata(BOWSPLEEF_METADATA_KEY, new FixedMetadataValue(plugin, true));
	}
	
	block.setType(Material.AIR);
}
 
Example 2
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.LOW)
public void onEvent(BlockPistonRetractEvent event)
{
    if (!Settings.allowTNTPushing) {
        // Check world
        if (!inWorld(event.getBlock())) {
            return;
        }
        for (Block block: event.getBlocks()) {
            if (block.getType() == Material.TNT) {
                event.setCancelled(true);
                break;
            }
        }
    }
    /* JAVA 8
    if (event.getBlocks().stream().anyMatch(it->it.getType()==Material.TNT))
        event.setCancelled(true);
     */
}
 
Example 3
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.LOW)
public void onEvent(BlockPistonExtendEvent event)
{
    if (!Settings.allowTNTPushing) {
        // Check world
        if (!inWorld(event.getBlock())) {
            return;
        }

        for (Block block: event.getBlocks()) {
            if (block.getType() == Material.TNT) {
                event.setCancelled(true);
                break;
            }
        }
    }
    /* JAVA 8
    if (event.getBlocks()..stream().anyMatch(it->it.getType()==Material.TNT))
        event.setCancelled(true);
     */
}
 
Example 4
Source File: TestRecipeService.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testShapelessRecipeShape() {
    MinecraftRecipeService service = new MinecraftRecipeService(plugin);

    Assertions.assertThrows(IllegalArgumentException.class, () -> service.getRecipeShape(null));

    NamespacedKey key = new NamespacedKey(plugin, "shapeless_test");
    ShapelessRecipe recipe = new ShapelessRecipe(key, new ItemStack(Material.TNT_MINECART));
    MaterialChoice choice = new MaterialChoice(Material.TNT);
    recipe.addIngredient(choice);

    server.addRecipe(recipe);
    service.refresh();

    Assertions.assertArrayEquals(new RecipeChoice[] { choice }, service.getRecipeShape(recipe));
}
 
Example 5
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onEntityChangeBlock(final EntityChangeBlockEvent event) {
    // Igniting TNT with an arrow is already handled from the ExplosionPrimeEvent
    if(event.getEntity() instanceof Arrow &&
       event.getBlock().getType() == Material.TNT &&
       event.getTo() == Material.AIR) return;

    callEvent(event, event.getBlock().getState(), BlockStateUtils.cloneWithMaterial(event.getBlock(), event.getToData()), entityResolver.getOwner(event.getEntity()));
}
 
Example 6
Source File: Tnt.java    From CardinalPGM with MIT License 5 votes vote down vote up
@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 7
Source File: TntTracker.java    From CardinalPGM with MIT License 5 votes vote down vote up
@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()));
                }
            }
        }
    }
}
 
Example 8
Source File: TestMultiBlocks.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testNotEqual() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));

    MultiBlock multiblock = new MultiBlock(item, new Material[] { Material.BIRCH_WOOD, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.CRAFTING_TABLE, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.BIRCH_WOOD }, BlockFace.DOWN);
    MultiBlock multiblock2 = new MultiBlock(item, new Material[] { Material.BIRCH_WOOD, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.EMERALD_BLOCK, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.BIRCH_WOOD }, BlockFace.DOWN);
    MultiBlock multiblock3 = new MultiBlock(item, new Material[] { Material.DROPPER, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.DIAMOND_BLOCK, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.TNT }, BlockFace.DOWN);
    MultiBlock multiblock4 = new MultiBlock(item, new Material[] { Material.BIRCH_WOOD, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.CRAFTING_TABLE, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.BIRCH_WOOD }, BlockFace.SELF);

    Assertions.assertFalse(multiblock.equals(null));
    Assertions.assertFalse(multiblock.equals(multiblock2));
    Assertions.assertFalse(multiblock.equals(multiblock3));
    Assertions.assertFalse(multiblock.equals(multiblock4));
}
 
Example 9
Source File: TNTMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 10
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onEntityExplode(final EntityExplodeEvent event) {
    ParticipantState playerState = entityResolver.getOwner(event.getEntity());

    for(Block block : event.blockList()) {
        if(block.getType() != Material.TNT) {
            // Don't cancel the explosion when individual blocks are cancelled
            callEvent(event, block.getState(), BlockStateUtils.toAir(block), playerState).setPropagateCancel(false);
        }
    }
}
 
Example 11
Source File: BlockTransformListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 12
Source File: TNTMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 13
Source File: TNTMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 14
Source File: TNTTracker.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlace(ParticipantBlockTransformEvent event) {
  if (event.getNewState().getMaterial() == Material.TNT) {
    blocks()
        .trackBlockState(
            event.getNewState(),
            new TNTInfo(event.getPlayerState(), event.getNewState().getLocation()));
  }
}
 
Example 15
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventWrapper
public void onEntityExplode(final EntityExplodeEvent event) {
  ParticipantState playerState = Trackers.getOwner(event.getEntity());

  for (Block block : event.blockList()) {
    if (block.getType() != Material.TNT) {
      // Don't cancel the explosion when individual blocks are cancelled
      callEvent(event, block.getState(), BlockStates.toAir(block), playerState)
          .setPropagateCancel(false);
    }
  }
}
 
Example 16
Source File: BlockTransformListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPrimeTNT(ExplosionPrimeEvent event) {
  if (event.getEntity() instanceof TNTPrimed) {
    Block block = event.getEntity().getLocation().getBlock();
    if (block.getType() == Material.TNT) {
      ParticipantState player;
      if (event instanceof ExplosionPrimeByEntityEvent) {
        player = Trackers.getOwner(((ExplosionPrimeByEntityEvent) event).getPrimer());
      } else {
        player = null;
      }
      callEvent(event, block.getState(), BlockStates.toAir(block), player);
    }
  }
}
 
Example 17
Source File: TNTTracker.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlace(ParticipantBlockTransformEvent event) {
    if(event.getNewState().getMaterial() == Material.TNT) {
        blocks().trackBlockState(event.getNewState(), new TNTInfo(event.getPlayerState(), event.getNewState().getLocation()));
    }
}
 
Example 18
Source File: BasicPane.java    From black with GNU General Public License v3.0 4 votes vote down vote up
private Element emptyElement() {
    return new BasicElement(
        new ItemStack(Material.TNT), "emptyElement"
    );
}
 
Example 19
Source File: TNTMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@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());
    }
  }
}