Search in sources :

Example 1 with NPC

use of org.bukkit.entity.NPC in project Essentials by drtshock.

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 2 with NPC

use of org.bukkit.entity.NPC 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 3 with NPC

use of org.bukkit.entity.NPC in project InteractionVisualizer by LOOHP.

the class VillagerDisplay method onVillageTrade.

@EventHandler(priority = EventPriority.MONITOR)
public void onVillageTrade(InventoryClickEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (VanishUtils.isVanished((Player) event.getWhoClicked())) {
        return;
    }
    if (!(event.getView().getTopInventory() instanceof MerchantInventory)) {
        return;
    }
    if (event.getRawSlot() != 2) {
        return;
    }
    if (event.getCurrentItem() == null) {
        return;
    }
    if (event.getCurrentItem().getType().equals(Material.AIR)) {
        return;
    }
    if (event.getCursor() != null) {
        if (!event.getCursor().getType().equals(Material.AIR)) {
            if (event.getCursor().getAmount() >= event.getCursor().getType().getMaxStackSize()) {
                return;
            }
        }
    }
    if (event.isShiftClick()) {
        if (!InventoryUtils.stillHaveSpace(event.getWhoClicked().getInventory(), event.getView().getItem(2).getType())) {
            return;
        }
    }
    ItemStack item0 = null;
    if (event.getView().getItem(0) != null) {
        if (!event.getView().getItem(0).getType().equals(Material.AIR)) {
            item0 = event.getView().getItem(0).clone();
        }
    }
    ItemStack item1 = null;
    if (event.getView().getItem(1) != null) {
        if (!event.getView().getItem(1).getType().equals(Material.AIR)) {
            item1 = event.getView().getItem(1).clone();
        }
    }
    ItemStack item2 = event.getCurrentItem().clone();
    Player player = (Player) event.getWhoClicked();
    MerchantInventory tradeinv = (MerchantInventory) event.getView().getTopInventory();
    if (InteractionVisualizer.version.isNewerOrEqualTo(MCVersion.V1_14)) {
        if (!(tradeinv.getHolder() instanceof org.bukkit.entity.AbstractVillager)) {
            return;
        }
    } else {
        if (!(tradeinv.getHolder() instanceof Villager)) {
            return;
        }
    }
    NPC villager = (NPC) tradeinv.getHolder();
    Vector lift = new Vector(0.0, 0.20, 0.0);
    if (item0 != null) {
        Item in = new Item(player.getEyeLocation());
        Vector vector = villager.getEyeLocation().add(0.0, -0.5, 0.0).toVector().subtract(player.getEyeLocation().toVector()).multiply(0.12).add(lift);
        in.setItemStack(item0);
        in.setGravity(true);
        in.setVelocity(vector);
        PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), in);
        PacketManager.updateItem(in);
        Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), in), 14);
    }
    ItemStack item1final = item1;
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        if (item1final != null) {
            Item in = new Item(player.getEyeLocation());
            Vector vector = villager.getEyeLocation().add(0.0, -0.5, 0.0).toVector().subtract(player.getEyeLocation().toVector()).multiply(0.12).add(lift);
            in.setItemStack(item1final);
            in.setGravity(true);
            in.setVelocity(vector);
            PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), in);
            PacketManager.updateItem(in);
            Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), in), 14);
        }
    }, 8);
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        Item out = new Item(villager.getEyeLocation());
        Vector vector = player.getEyeLocation().add(0.0, -0.5, 0.0).toVector().subtract(villager.getEyeLocation().toVector()).multiply(0.10).add(lift);
        out.setItemStack(item2);
        out.setGravity(true);
        out.setVelocity(vector);
        PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), out);
        PacketManager.updateItem(out);
        Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), out), 12);
    }, 40);
}
Also used : NPC(org.bukkit.entity.NPC) Item(com.loohp.interactionvisualizer.entityholders.Item) Player(org.bukkit.entity.Player) MerchantInventory(org.bukkit.inventory.MerchantInventory) Villager(org.bukkit.entity.Villager) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Aggregations

NPC (org.bukkit.entity.NPC)3 Player (org.bukkit.entity.Player)3 Mob (com.earth2me.essentials.Mob)2 ArrayList (java.util.ArrayList)2 Chunk (org.bukkit.Chunk)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 Ambient (org.bukkit.entity.Ambient)2 Animals (org.bukkit.entity.Animals)2 Boat (org.bukkit.entity.Boat)2 ComplexLivingEntity (org.bukkit.entity.ComplexLivingEntity)2 EnderCrystal (org.bukkit.entity.EnderCrystal)2 Entity (org.bukkit.entity.Entity)2 ExperienceOrb (org.bukkit.entity.ExperienceOrb)2 Flying (org.bukkit.entity.Flying)2 HumanEntity (org.bukkit.entity.HumanEntity)2 Item (org.bukkit.entity.Item)2 ItemFrame (org.bukkit.entity.ItemFrame)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Minecart (org.bukkit.entity.Minecart)2 Monster (org.bukkit.entity.Monster)2