Java Code Examples for org.bukkit.entity.TNTPrimed#setMetadata()

The following examples show how to use org.bukkit.entity.TNTPrimed#setMetadata() . 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: SelfDestruct.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 2
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));
                        }
                    }
                }
            }
        }
    }
}