org.bukkit.entity.TNTPrimed Java Examples
The following examples show how to use
org.bukkit.entity.TNTPrimed.
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: GriefEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onCreeperExplode(ExplosionPrimeEvent event) { if (!creeperEnabled || !plugin.getWorldManager().isSkyWorld(event.getEntity().getWorld())) { return; } if (event.getEntity() instanceof Creeper && !isValidTarget(((Creeper)event.getEntity()).getTarget())) { event.setCancelled(true); } else if (event.getEntity() instanceof TNTPrimed) { TNTPrimed tntPrimed = (TNTPrimed) event.getEntity(); if (tntPrimed.getSource() instanceof Player && !isValidTarget(tntPrimed.getSource())) { event.setCancelled(true); } } }
Example #2
Source File: ProtectionsTests.java From Civs with GNU General Public License v3.0 | 6 votes |
private void explodeInRegion(boolean throwException, Location regionLocation) throws SuccessException { RegionsTests.loadRegionTypeCobble(); HashMap<UUID, String> people = new HashMap<>(); people.put(TestUtil.player.getUniqueId(), Constants.OWNER); HashMap<String, String> effects = new HashMap<>(); Region region = new Region("cobble", people, regionLocation, RegionsTests.getRadii(), effects,0); RegionManager.getInstance().addRegion(region); TNTPrimed tntPrimed = mock(TNTPrimed.class); ArrayList<Block> blockList = new ArrayList<>(); if (throwException) { when(Bukkit.getServer().getScheduler()).thenThrow(new SuccessException()); } EntityExplodeEvent event = new EntityExplodeEvent(tntPrimed, regionLocation.add(0, 1,0), blockList, (float) 2); if (throwException) { ProtectionHandler protectionHandler = new ProtectionHandler(); protectionHandler.onEntityExplode(event); } }
Example #3
Source File: Pickup.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
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(); }
Example #4
Source File: LuckyBlock.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
public void process(Player broker) { game.unregisterSpecialItem(this); Random rand = new Random(); int element = rand.nextInt(luckyBlockData.size()); Map<String, Object> map = luckyBlockData.get(element); String type = (String) map.getOrDefault("type", "nothing"); switch (type) { case "item": ItemStack stack = ((ItemStack) map.get("stack")).clone(); placedLocation.getWorld().dropItem(placedLocation, stack); break; case "potion": PotionEffect potionEffect = (PotionEffect) map.get("effect"); broker.addPotionEffect(potionEffect); break; case "tnt": new BukkitRunnable() { @Override public void run() { TNTPrimed tnt = (TNTPrimed) placedLocation.getWorld().spawnEntity(placedLocation, EntityType.PRIMED_TNT); tnt.setFuseTicks(0); } }.runTaskLater(Main.getInstance(), 10L); break; case "teleport": broker.teleport(broker.getLocation().add(0, (int) map.get("height"), 0)); break; } if (map.containsKey("message")) { broker.sendMessage((String) map.get("message")); } }
Example #5
Source File: TNTTracker.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@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); } } }
Example #6
Source File: TntDefuse.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerRightClick(PlayerInteractEntityEvent event) { if (event.getRightClicked() instanceof TNTPrimed && event.getPlayer().getItemInHand() != null && event.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) { if (TntTracker.getWhoPlaced(event.getRightClicked()) != null) { UUID player = TntTracker.getWhoPlaced(event.getRightClicked()); Optional<TeamModule> playerTeam = Teams.getTeamByPlayer(Bukkit.getPlayer(player)); if (Bukkit.getOfflinePlayer(player).isOnline()) { if (event.getPlayer().hasPermission("tnt.defuse") || Teams.getTeamByPlayer(Bukkit.getPlayer(player)).orNull() == Teams.getTeamByPlayer(event.getPlayer()).orNull()) { if (!event.getRightClicked().getLocation().getBlock().isLiquid()) { if (!Bukkit.getPlayer(player).equals(event.getPlayer())) { event.getRightClicked().remove(); ChatColor color = Teams.getTeamColorByPlayer(Bukkit.getOfflinePlayer(player)); event.getPlayer().sendMessage(ChatColor.RED + "You defused " + color + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RED + "'s TNT."); ChatChannel channel = GameHandler.getGameHandler().getMatch().getModules().getModule(AdminChannel.class); channel.sendMessage("[" + ChatColor.GOLD + "A" + ChatColor.WHITE + "] " + Teams.getTeamColorByPlayer(event.getPlayer()) + event.getPlayer().getDisplayName() + ChatColor.RESET + " defused " + color + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RESET + "'s " + ChatColor.DARK_RED + "TNT"); } } else { ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse TNT in water!"); } } else { ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT."); } } else { ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT."); } } } }
Example #7
Source File: TNTTracker.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@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())); } } }
Example #8
Source File: LuckyBlock.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
public void process(Player broker) { game.unregisterSpecialItem(this); Random rand = new Random(); int element = rand.nextInt(luckyBlockData.size()); Map<String, Object> map = luckyBlockData.get(element); String type = (String) map.getOrDefault("type", "nothing"); switch (type) { case "item": ItemStack stack = ((ItemStack) map.get("stack")).clone(); placedLocation.getWorld().dropItem(placedLocation, stack); break; case "potion": PotionEffect potionEffect = (PotionEffect) map.get("effect"); broker.addPotionEffect(potionEffect); break; case "tnt": new BukkitRunnable() { @Override public void run() { TNTPrimed tnt = (TNTPrimed) placedLocation.getWorld().spawnEntity(placedLocation, EntityType.PRIMED_TNT); tnt.setFuseTicks(0); } }.runTaskLater(Main.getInstance(), 10L); break; case "teleport": broker.teleport(broker.getLocation().add(0, (int) map.get("height"), 0)); break; } if (map.containsKey("message")) { broker.sendMessage((String) map.get("message")); } }
Example #9
Source File: Tnt.java From CardinalPGM with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onBlockPlace(BlockPlaceEvent event) { Block block = event.getBlock(); if (block.getType().equals(Material.TNT) && instantIgnite && !event.isCancelled()) { event.getBlock().setType(Material.AIR); TNTPrimed tnt = (TNTPrimed) GameHandler.getGameHandler().getMatchWorld().spawnEntity(block.getLocation().add(new Vector(0.5, 0.5, 0.5)), EntityType.PRIMED_TNT); Bukkit.getServer().getPluginManager().callEvent(new ExplosionPrimeEvent(tnt)); } }
Example #10
Source File: BlockTransformListener.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@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 #11
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 #12
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 #13
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 #14
Source File: TNTMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private boolean callPrimeEvent(TNTPrimed tnt, @Nullable Entity primer) { ExplosionPrimeEvent primeEvent = primer != null ? new ExplosionPrimeByEntityEvent(tnt, primer) : new ExplosionPrimeEvent(tnt); match.callEvent(primeEvent); if (primeEvent.isCancelled()) { tnt.remove(); return false; } else { return true; } }
Example #15
Source File: FreezeMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
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(); } } }
Example #16
Source File: DefuseListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
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)); } } }
Example #17
Source File: TntDefuse.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerLeftClick(PlayerAttackEntityEvent event) { if (event.getLeftClicked() instanceof TNTPrimed) { if (TntTracker.getWhoPlaced(event.getLeftClicked()) != null) { UUID player = TntTracker.getWhoPlaced(event.getLeftClicked()); Optional<TeamModule> playerTeam = Teams.getTeamByPlayer(Bukkit.getPlayer(player)); if (Bukkit.getOfflinePlayer(player).isOnline()) { if (playerTeam.isPresent() && playerTeam.get().equals(Teams.getTeamByPlayer(event.getPlayer()).orNull()) && Teams.getTeamByPlayer(Bukkit.getPlayer(player)) != null && !playerTeam.get().isObserver()) { if (!event.getLeftClicked().getLocation().getBlock().isLiquid()) { if (!Bukkit.getPlayer(player).equals(event.getPlayer())) { event.getLeftClicked().remove(); event.getPlayer().sendMessage(ChatColor.RED + "You defused " + playerTeam.get().getColor() + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RED + "'s TNT."); ChatChannel channel = GameHandler.getGameHandler().getMatch().getModules().getModule(AdminChannel.class); channel.sendMessage("[" + ChatColor.GOLD + "A" + ChatColor.WHITE + "] " + Teams.getTeamByPlayer(event.getPlayer()).get().getColor() + event.getPlayer().getDisplayName() + ChatColor.RESET + " defused " + playerTeam.get().getColor() + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RESET + "'s " + ChatColor.DARK_RED + "TNT"); } } else { ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse TNT in water!"); } } else { ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT."); } } else { ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT."); } } } }
Example #18
Source File: Bombardment.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public void effect(Event e, ItemStack item, final int level) { if(e instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e; Entity target = event.getEntity(); final World world = target.getWorld(); Vector vec = new Vector(0, -5, 0); Location spawnLocation = new Location(world, target.getLocation().getX(), 255, target.getLocation().getZ()); final FallingBlock b = world.spawnFallingBlock(spawnLocation, 46, (byte) 0x0); b.setVelocity(vec); new BukkitRunnable() { Location l = b.getLocation(); @Override public void run() { l = b.getLocation(); if(b.isDead()) { l.getBlock().setType(Material.AIR); for(int i = 0; i <= TNTAmount + level; i++) { TNTPrimed tnt = world.spawn(l, TNTPrimed.class); tnt.setFuseTicks(0); if(!Main.createExplosions) tnt.setMetadata("ce.explosive", new FixedMetadataValue(getPlugin(), null)); } this.cancel(); } EffectManager.playSound(l, "ENTITY_ENDERDRAGON_GROWL", Volume, 2f); } }.runTaskTimer(getPlugin(), 0l, 5l); } }
Example #19
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 #20
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 #21
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 #22
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 #23
Source File: Freeze.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
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(); } } }
Example #24
Source File: BlockTransformListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@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 #25
Source File: TNTTracker.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@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); } } }
Example #26
Source File: TNTTracker.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@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())); } } }
Example #27
Source File: NMSHacks.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
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"; } }
Example #28
Source File: ProtectionsTests.java From Civs with GNU General Public License v3.0 | 5 votes |
private void explodeInProtectedRegion(Location regionLocation, boolean useTown) { Region region; HashMap<UUID, String> people = new HashMap<>(); people.put(TestUtil.player.getUniqueId(), Constants.OWNER); HashMap<String, String> effects = new HashMap<>(); if (useTown) { RegionsTests.loadRegionTypeCobble(); region = new Region("cobble", people, regionLocation, RegionsTests.getRadii(), effects,0); TownTests.loadTownTypeHamlet2(); TownTests.loadTown("testTown", "hamlet2", regionLocation); } else { RegionsTests.loadRegionTypeShelter(); effects.put("block_explosion", ""); region = new Region("cobble", people, regionLocation, RegionsTests.getRadii(), effects,0); } try { when(Bukkit.getServer().getScheduler()).thenThrow(new SuccessException()); } catch (SuccessException e) { // Do nothing } RegionManager.getInstance().addRegion(region); TNTPrimed tntPrimed = mock(TNTPrimed.class); ArrayList<Block> blockList = new ArrayList<>(); EntityExplodeEvent event = new EntityExplodeEvent(tntPrimed, regionLocation.add(0, 1,0), blockList, (float) 2); ProtectionHandler protectionHandler = new ProtectionHandler(); protectionHandler.onEntityExplode(event); }
Example #29
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 #30
Source File: TNTSheep.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@Override public TNTPrimed getTNT() { return this.primedTnt; }