Search in sources :

Example 11 with Boat

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);
    }
}
Also used : Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Hanging(org.bukkit.entity.Hanging) Minecart(org.bukkit.entity.Minecart) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EnderCrystal(org.bukkit.entity.EnderCrystal) Projectile(org.bukkit.entity.Projectile) Location(org.bukkit.Location) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Example 12 with Boat

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));
}
Also used : NPC(org.bukkit.entity.NPC) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ArrayList(java.util.ArrayList) Minecart(org.bukkit.entity.Minecart) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) ItemFrame(org.bukkit.entity.ItemFrame) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Item(org.bukkit.entity.Item) Monster(org.bukkit.entity.Monster) HumanEntity(org.bukkit.entity.HumanEntity) OfflinePlayer(org.bukkit.OfflinePlayer) WaterMob(org.bukkit.entity.WaterMob) Mob(com.earth2me.essentials.Mob) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) Tameable(org.bukkit.entity.Tameable) ExperienceOrb(org.bukkit.entity.ExperienceOrb) EnderCrystal(org.bukkit.entity.EnderCrystal) Chunk(org.bukkit.Chunk) Slime(org.bukkit.entity.Slime) Projectile(org.bukkit.entity.Projectile) Painting(org.bukkit.entity.Painting) WaterMob(org.bukkit.entity.WaterMob) Flying(org.bukkit.entity.Flying) Animals(org.bukkit.entity.Animals) Ambient(org.bukkit.entity.Ambient) Snowman(org.bukkit.entity.Snowman) Boat(org.bukkit.entity.Boat)

Example 13 with Boat

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);
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ArrayList(java.util.ArrayList) InvalidMobTypeException(io.lumine.xikage.mythicmobs.api.exceptions.InvalidMobTypeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DisguiseParseException(me.libraryaddict.disguise.utilities.parser.DisguiseParseException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) SoliniaLivingEntity(com.solinia.solinia.Models.SoliniaLivingEntity) Vehicle(org.bukkit.entity.Vehicle) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Animals(org.bukkit.entity.Animals) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Skeleton(org.bukkit.entity.Skeleton) UUID(java.util.UUID) Boat(org.bukkit.entity.Boat)

Example 14 with Boat

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);
}
Also used : Entity(org.bukkit.entity.Entity) SafeTeleportBuilder(com.wasteofplastic.askyblock.util.teleport.SafeTeleportBuilder) IslandPreTeleportEvent(com.wasteofplastic.askyblock.events.IslandPreTeleportEvent) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) Boat(org.bukkit.entity.Boat)

Example 15 with Boat

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);
}
Also used : Vehicle(org.bukkit.entity.Vehicle) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) World(org.bukkit.World) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Boat(org.bukkit.entity.Boat) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Boat (org.bukkit.entity.Boat)16 Location (org.bukkit.Location)12 Player (org.bukkit.entity.Player)11 Entity (org.bukkit.entity.Entity)10 EventHandler (org.bukkit.event.EventHandler)8 Minecart (org.bukkit.entity.Minecart)7 Animals (org.bukkit.entity.Animals)5 LivingEntity (org.bukkit.entity.LivingEntity)5 Vehicle (org.bukkit.entity.Vehicle)5 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)4 EnderCrystal (org.bukkit.entity.EnderCrystal)4 Projectile (org.bukkit.entity.Projectile)4 ArrayList (java.util.ArrayList)3 Material (org.bukkit.Material)3 ItemFrame (org.bukkit.entity.ItemFrame)3 Painting (org.bukkit.entity.Painting)3 ItemStack (org.bukkit.inventory.ItemStack)3 Mob (com.earth2me.essentials.Mob)2 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)2 PvPlayer (me.NoChance.PvPManager.PvPlayer)2