下面列出了org.bukkit.entity.TNTPrimed#setMetadata ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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));
}
}
@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));
}
}
}
}
}
}
}