Search in sources :

Example 1 with CustomEntityHelper

use of com.denizenscript.denizen.nms.interfaces.CustomEntityHelper in project Denizen-For-Bukkit by DenizenScript.

the class DenizenEntityType method spawnNewEntity.

public Entity spawnNewEntity(Location location, ArrayList<Mechanism> mechanisms, String scriptName) {
    try {
        if (name.equals("DROPPED_ITEM")) {
            ItemStack itemStack = new ItemStack(Material.STONE);
            for (Mechanism mechanism : mechanisms) {
                if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
                    itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
                    break;
                }
            }
            return location.getWorld().dropItem(location, itemStack);
        } else if (!isCustom()) {
            return SpawnEntityHelper.spawn(location, bukkitEntityType, mechanisms, scriptName);
        } else {
            CustomEntityHelper customEntityHelper = NMSHandler.getCustomEntityHelper();
            switch(customEntityType) {
                case FAKE_ARROW:
                    return customEntityHelper.spawnFakeArrow(location);
                case FAKE_PLAYER:
                    if (Settings.packetInterception()) {
                        String name = null;
                        String skin = null;
                        for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
                            if (mechanism.matches("name")) {
                                name = mechanism.getValue().asString();
                                mechanisms.remove(mechanism);
                            } else if (mechanism.matches("skin")) {
                                skin = mechanism.getValue().asString();
                                mechanisms.remove(mechanism);
                            }
                            if (name != null && skin != null) {
                                break;
                            }
                        }
                        NetworkInterceptHelper.enable();
                        return customEntityHelper.spawnFakePlayer(location, name, skin);
                    }
                    break;
                case ITEM_PROJECTILE:
                    Deprecations.itemProjectile.warn();
                    ItemStack itemStack = new ItemStack(Material.STONE);
                    for (Mechanism mechanism : mechanisms) {
                        if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
                            itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
                        }
                    }
                    return customEntityHelper.spawnItemProjectile(location, itemStack);
            }
        }
    } catch (Exception e) {
        Debug.echoError(e);
    }
    return null;
}
Also used : CustomEntityHelper(com.denizenscript.denizen.nms.interfaces.CustomEntityHelper) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag) Mechanism(com.denizenscript.denizencore.objects.Mechanism)

Aggregations

CustomEntityHelper (com.denizenscript.denizen.nms.interfaces.CustomEntityHelper)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 Mechanism (com.denizenscript.denizencore.objects.Mechanism)1 ItemStack (org.bukkit.inventory.ItemStack)1