use of org.bukkit.entity.Boat in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onEntityDamageByEntityEvent.
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent e) {
Player p = null;
RedProtect.get().logger.debug("RPLayerListener: Is EntityDamageByEntityEvent event");
if (e.getDamager() instanceof Player) {
p = (Player) e.getDamager();
} else if (e.getDamager() instanceof Projectile) {
Projectile proj = (Projectile) e.getDamager();
if (proj.getShooter() instanceof Player) {
p = (Player) proj.getShooter();
}
}
if (p != null) {
RedProtect.get().logger.debug("Player: " + p.getName());
} else {
RedProtect.get().logger.debug("Player: is null");
return;
}
RedProtect.get().logger.debug("Damager: " + e.getDamager().getType().name());
// check killaura or freekill
if (RPConfig.getBool("server-protection.check-killaura-freekill.enable")) {
startCheckRate(p.getName());
}
Location l = e.getEntity().getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r == null) {
return;
}
if (RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
if (e.getEntity() instanceof Player && !p.equals(e.getEntity()) && r.flagExists("pvp") && !r.canPVP((Player) e.getEntity(), p)) {
RPLang.sendMessage(p, "entitylistener.region.cantpvp");
e.setCancelled(true);
}
if ((e.getEntity() instanceof Hanging || e.getEntity() instanceof EnderCrystal) && !r.canBuild(p) && !r.canBreak(e.getEntityType())) {
RPLang.sendMessage(p, "playerlistener.region.cantremove");
e.setCancelled(true);
}
if ((e.getEntity() instanceof Boat || e.getEntity() instanceof Minecart) && !r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantbreak");
e.setCancelled(true);
}
}
use of org.bukkit.entity.Boat in project Essentials by EssentialsX.
the class Commandremove method removeHandler.
private void removeHandler(final CommandSource sender, final List<String> types, final List<String> customTypes, final World world, int radius) {
int removed = 0;
if (radius > 0) {
radius *= radius;
}
final ArrayList<ToRemove> removeTypes = new ArrayList<>();
final ArrayList<Mob> customRemoveTypes = new ArrayList<>();
for (final String s : types) {
removeTypes.add(ToRemove.valueOf(s));
}
boolean warnUser = false;
for (final String s : customTypes) {
final Mob mobType = Mob.fromName(s);
if (mobType == null) {
warnUser = true;
} else {
customRemoveTypes.add(mobType);
}
}
if (warnUser) {
sender.sendMessage(tl("invalidMob"));
}
for (final Chunk chunk : world.getLoadedChunks()) {
for (final Entity e : chunk.getEntities()) {
if (radius > 0) {
if (sender.getPlayer().getLocation().distanceSquared(e.getLocation()) > radius) {
continue;
}
}
if (e instanceof HumanEntity) {
continue;
}
for (final ToRemove toRemove : removeTypes) {
// We should skip any animals tamed by players unless we are specifially targetting them.
if (e instanceof Tameable && ((Tameable) e).isTamed() && (((Tameable) e).getOwner() instanceof Player || ((Tameable) e).getOwner() instanceof OfflinePlayer) && !removeTypes.contains(ToRemove.TAMED)) {
continue;
}
// We should skip any NAMED animals unless we are specifially targetting them.
if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
continue;
}
switch(toRemove) {
case TAMED:
if (e instanceof Tameable && ((Tameable) e).isTamed()) {
e.remove();
removed++;
}
break;
case NAMED:
if (e instanceof LivingEntity && e.getCustomName() != null) {
e.remove();
removed++;
}
break;
case DROPS:
if (e instanceof Item) {
e.remove();
removed++;
}
break;
case ARROWS:
if (e instanceof Projectile) {
e.remove();
removed++;
}
break;
case BOATS:
if (e instanceof Boat) {
e.remove();
removed++;
}
break;
case MINECARTS:
if (e instanceof Minecart) {
e.remove();
removed++;
}
break;
case XP:
if (e instanceof ExperienceOrb) {
e.remove();
removed++;
}
break;
case PAINTINGS:
if (e instanceof Painting) {
e.remove();
removed++;
}
break;
case ITEMFRAMES:
if (e instanceof ItemFrame) {
e.remove();
removed++;
}
break;
case ENDERCRYSTALS:
if (e instanceof EnderCrystal) {
e.remove();
removed++;
}
break;
case AMBIENT:
if (e instanceof Flying) {
e.remove();
removed++;
}
break;
case HOSTILE:
case MONSTERS:
if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime) {
e.remove();
removed++;
}
break;
case PASSIVE:
case ANIMALS:
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient) {
e.remove();
removed++;
}
break;
case MOBS:
if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient) {
e.remove();
removed++;
}
break;
case ENTITIES:
case ALL:
e.remove();
removed++;
break;
case CUSTOM:
for (final Mob type : customRemoveTypes) {
if (e.getType() == type.getType()) {
e.remove();
removed++;
}
}
break;
}
}
}
}
sender.sendMessage(tl("removed", removed));
}
use of org.bukkit.entity.Boat in project solinia3-core by mixxit.
the class EntityManager method doNPCCheckForEnemies.
@Override
public void doNPCCheckForEnemies() {
List<UUID> completedLivingEntities = new ArrayList<UUID>();
List<UUID> entitiesNearPlayers = new ArrayList<UUID>();
List<UUID> foundInvalidLivingEntity = new ArrayList<UUID>();
for (Player player : Bukkit.getOnlinePlayers()) {
for (Entity entity : player.getNearbyEntities(25, 25, 25)) {
try {
if (entity instanceof Player)
continue;
if (entity instanceof Boat) {
EntityUtils.despawnBoatIfNotNearWater((Boat) entity);
}
if (!(entity instanceof LivingEntity))
continue;
LivingEntity le = (LivingEntity) entity;
if (!EntityUtils.isLivingEntityNPC(le)) {
// get rid of them..
if (le instanceof Skeleton)
if (!foundInvalidLivingEntity.contains(le.getUniqueId()))
foundInvalidLivingEntity.add(le.getUniqueId());
continue;
}
if (!EntityUtils.ValidatePet(le)) {
continue;
}
if (!entitiesNearPlayers.contains(le.getUniqueId()))
entitiesNearPlayers.add(le.getUniqueId());
try {
ISoliniaLivingEntity solle = SoliniaLivingEntityAdapter.Adapt(le);
if (completedLivingEntities.contains(le.getUniqueId()))
continue;
completedLivingEntities.add(le.getUniqueId());
solle.doCheckForEnemies();
} catch (CoreStateInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
// This cleans up mobs that have 'lost' their NPC identity
for (UUID invalidEntity : foundInvalidLivingEntity) {
try {
Entity ent = Bukkit.getEntity(invalidEntity);
if (ent instanceof Animals || ent instanceof Vehicle)
continue;
if (ent != null)
EntityUtils.RemoveEntity(ent, "doNPCCheckForEnemies");
} catch (Exception e) {
}
}
// Clear and reset all entities that are not near players
EntityUtils.ClearHateAndResetNpcsNotInList(entitiesNearPlayers);
}
use of org.bukkit.entity.Boat in project askyblock by tastybento.
the class GridManager method homeTeleport.
/**
* Teleport player to a home location. If one cannot be found a search is done to
* find a safe place.
* @param player player object
* @param number - home location to do to
* @return true if successful, false if not
*/
@SuppressWarnings("deprecation")
public void homeTeleport(final Player player, int number) {
Location home = null;
// plugin.getLogger().info("home teleport called for #" + number);
home = getSafeHomeLocation(player.getUniqueId(), number);
// Check if the player is a passenger in a boat
if (player.isInsideVehicle()) {
Entity boat = player.getVehicle();
if (boat instanceof Boat) {
player.leaveVehicle();
// Remove the boat so they don't lie around everywhere
boat.remove();
player.getInventory().addItem(new ItemStack(Material.BOAT, 1));
player.updateInventory();
}
}
if (home == null) {
// plugin.getLogger().info("Fixing home location using safe spot teleport");
// Try to fix this teleport location and teleport the player if possible
new SafeTeleportBuilder(plugin).entity(player).location(plugin.getPlayers().getHomeLocation(player.getUniqueId(), number)).homeNumber(number).build();
return;
}
// plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting");
// home.getChunk().load();
IslandPreTeleportEvent event = new IslandPreTeleportEvent(player, IslandPreTeleportEvent.Type.HOME, home);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
player.teleport(event.getLocation());
// player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
if (number == 1) {
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandteleport);
} else {
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandteleport + " #" + number);
}
}
plugin.getPlayers().setInTeleport(player.getUniqueId(), false);
}
use of org.bukkit.entity.Boat in project askyblock by tastybento.
the class SafeBoat method onClick.
/**
* @param e - event
* This event check throws the boat at a player when they hit it
* unless someone is in it
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onClick(VehicleDamageEvent e) {
// plugin.getLogger().info("Damage event " + e.getDamage());
// Find out what block is being clicked
Vehicle boat = e.getVehicle();
if (!(boat instanceof Boat)) {
return;
}
if (!boat.isEmpty()) {
return;
}
final World playerWorld = boat.getWorld();
if (!playerWorld.getName().equalsIgnoreCase(Settings.worldName)) {
// Not the right world
return;
}
// Find out who is doing the clicking
if (!(e.getAttacker() instanceof Player)) {
// If a creeper blows up the boat, tough cookies!
return;
}
Player p = (Player) e.getAttacker();
if (p == null) {
return;
}
// Try to remove the boat and throw it at the player
Location boatSpot = new Location(boat.getWorld(), boat.getLocation().getX(), boat.getLocation().getY() + 2, boat.getLocation().getZ());
Location throwTo = new Location(boat.getWorld(), p.getLocation().getX(), p.getLocation().getY() + 1, p.getLocation().getZ());
ItemStack newBoat = new ItemStack(Material.BOAT, 1);
// Find the direction the boat should move in
Vector dir = throwTo.toVector().subtract(boatSpot.toVector()).normalize();
dir = dir.multiply(0.5);
Entity newB = boat.getWorld().dropItem(boatSpot, newBoat);
newB.setVelocity(dir);
boat.remove();
e.setCancelled(true);
}
Aggregations