Java Code Examples for org.bukkit.entity.Entity#getWorld()
The following examples show how to use
org.bukkit.entity.Entity#getWorld() .
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: BlockEventTracker.java From GriefDefender with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockFalling(EntitySpawnEvent event) { final Entity entity = event.getEntity(); final World world = entity.getWorld(); if (entity instanceof FallingBlock) { // add owner final Location location = entity.getLocation(); final Block block = world.getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(location.getWorld().getUID()); final GDChunk gdChunk = claimWorldManager.getChunk(location.getChunk()); final UUID ownerUniqueId = gdChunk.getBlockOwnerUUID(block.getLocation()); if (ownerUniqueId != null) { final GDEntity gdEntity = new GDEntity(event.getEntity().getEntityId()); gdEntity.setOwnerUUID(ownerUniqueId); gdEntity.setNotifierUUID(ownerUniqueId); EntityTracker.addTempEntity(gdEntity); } } }
Example 2
Source File: Molotov.java From ce with GNU Lesser General Public License v3.0 | 6 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(); World world = target.getWorld(); world.playEffect(target.getLocation(), Effect.POTION_BREAK, 10); double boundaries = 0.1*level; for(double x = boundaries; x >= -boundaries; x-=0.1) for(double z = boundaries; z >= -boundaries; z-=0.1) { FallingBlock b = world.spawnFallingBlock(target.getLocation(), Material.FIRE.getId(), (byte) 0x0); b.setVelocity(new Vector(x, 0.1, z)); b.setDropItem(false); } } }
Example 3
Source File: EntityEventHandler.java From GriefDefender with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onEntityMount(VehicleEnterEvent event) { if (!GDFlags.ENTITY_RIDING) { return; } final Entity source = event.getEntered(); final World world = source.getWorld(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) { return; } if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ENTITY_RIDING.getName(), source, world.getUID())) { return; } if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ENTITY_RIDING.getName(), event.getVehicle(), world.getUID())) { return; } GDTimings.ENTITY_MOUNT_EVENT.startTiming(); Player player = source instanceof Player ? (Player) source : null; if (player != null) { GDCauseStackManager.getInstance().pushCause(player); } final Location location = event.getVehicle().getLocation(); final GDClaim targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location); if (GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.ENTITY_RIDING, source, event.getVehicle(), player, TrustTypes.ACCESSOR, true) == Tristate.FALSE) { if (player != null) { PlayerUtil.getInstance().sendInteractEntityDenyMessage(targetClaim, player, null, event.getVehicle()); } event.setCancelled(true); } GDTimings.ENTITY_MOUNT_EVENT.stopTiming(); }
Example 4
Source File: TargetHelper.java From ActionHealth with MIT License | 5 votes |
/** * Checks if the entity is in front of the entity * * @param entity entity to check for * @param target target to check against * @return true if the target is in front of the entity */ public boolean isInFront(Entity entity, Entity target) { if (entity.getWorld() != target.getWorld()) return false; // Get the necessary vectors Vector facing = entity.getLocation().getDirection(); Vector relative = target.getLocation().subtract(entity.getLocation()).toVector(); // If the dot product is positive, the target is in front return facing.dot(relative) >= main.configStore.lookDot; }
Example 5
Source File: HealthUtil.java From ActionHealth with MIT License | 5 votes |
public boolean matchesRequirements(Player player, Entity damaged) { if (damaged.getType().name().equals("ARMOR_STAND")) return false; if (player.getWorld() != damaged.getWorld()) return false; if (damaged instanceof Player) { if (!plugin.configStore.showPlayers && !damaged.hasMetadata("NPC")) return false; } else { if (!plugin.configStore.showMobs) return false; } if (!plugin.configStore.showNPC && damaged.hasMetadata("NPC")) return false; if (!plugin.configStore.showMiniaturePets && damaged.hasMetadata("MiniaturePet")) return false; if (plugin.healthUtil.isDisabled(player.getLocation())) return false; if (plugin.configStore.worlds.contains(player.getWorld().getName())) return false; if (plugin.configStore.usePerms && !player.hasPermission("ActionHealth.Health")) return false; if (player.getUniqueId() == damaged.getUniqueId()) return false; if (plugin.toggle.contains(player.getUniqueId())) { sendMessage(player); return false; } return true; }
Example 6
Source File: BeastmastersBow.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean effect(Event event, Player player) { // List<String> lore = e.getBow().getItemMeta().getLore(); // if(!lore.contains(placeHolder)) { // for(int i = descriptionSize; i != 0; i--) // lore.remove(i); // e.getProjectile().setMetadata("ce." + this.getOriginalName(), new FixedMetadataValue(main, writeType(lore))); // player.setMetadata("ce.CanUnleashBeasts", null); // } else // e.getProjectile().setMetadata("ce." + this.getOriginalName(), null); if(event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; if(e.getDamager() != player) return false; Entity ent = e.getEntity(); Location loc = ent.getLocation(); World w = ent.getWorld(); if(ent instanceof Silverfish || ent instanceof EnderDragon || ent instanceof Spider || ent instanceof Slime || ent instanceof Ghast || ent instanceof MagmaCube || ent instanceof CaveSpider || (ent instanceof Wolf && ((Wolf) ent).isAngry()) || ent instanceof PigZombie) { e.setDamage(e.getDamage()*DamageMultiplication); w.playEffect(loc, Effect.SMOKE, 50); w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 50); EffectManager.playSound(loc, "BLOCK_PISTON_RETRACT", 1.3f, 3f); return true; } else if (ent instanceof Player) { for(int i = 0; i < MaximumMobs; i++) { if(rand.nextInt(100) < MobAppearanceChance) { w.spawnEntity(loc, rand.nextInt(2) == 1 ? EntityType.SPIDER : EntityType.SLIME); w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 30); w.playEffect(loc, Effect.SMOKE, 30); EffectManager.playSound(loc, "BLOCK_ANVIL_BREAK", 0.3f, 0.1f); } } } } return false; }
Example 7
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); } }