Search in sources :

Example 6 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class BlockController method onEntityChangeBlockEvent.

@EventHandler(ignoreCancelled = true)
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof FallingBlock) {
        EntityData entityData = controller.getMob(entity);
        if (entityData != null && !entityData.isTransformable()) {
            event.setCancelled(true);
            return;
        }
        if (event.getTo() == Material.AIR) {
            // Block is falling, register it
            controller.registerFallingBlock(entity, event.getBlock());
        } else {
            // Block is landing, convert it
            UndoList blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
            if (blockList != null) {
                com.elmakers.mine.bukkit.api.action.CastContext context = blockList.getContext();
                if (context != null && !context.hasBuildPermission(entity.getLocation().getBlock())) {
                    event.setCancelled(true);
                } else {
                    Block block = event.getBlock();
                    blockList.convert(entity, block);
                    if (!blockList.getApplyPhysics()) {
                        FallingBlock falling = (FallingBlock) entity;
                        CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
                        Material material = compatibilityUtils.getMaterial(falling);
                        String blockData = compatibilityUtils.getBlockData(falling);
                        if (blockData != null) {
                            compatibilityUtils.setBlockData(block, blockData);
                        } else {
                            byte data = CompatibilityLib.getCompatibilityUtils().getLegacyBlockData(falling);
                            CompatibilityLib.getDeprecatedUtils().setTypeAndData(block, material, data, false);
                        }
                        entity.remove();
                        event.setCancelled(true);
                    }
                }
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) EntityData(com.elmakers.mine.bukkit.api.entity.EntityData) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Material(org.bukkit.Material) FallingBlock(org.bukkit.entity.FallingBlock) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) EventHandler(org.bukkit.event.EventHandler)

Example 7 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class ShrinkEntityAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity targetEntity = context.getTargetEntity();
    MageController controller = context.getController();
    if (controller.isElemental(targetEntity)) {
        double elementalSize = controller.getElementalScale(targetEntity);
        if (elementalSize < 0.1) {
            return super.perform(context);
        }
        elementalSize /= 2;
        controller.setElementalScale(targetEntity, elementalSize);
        return SpellResult.CAST;
    }
    if (!(targetEntity instanceof LivingEntity))
        return SpellResult.NO_TARGET;
    LivingEntity li = (LivingEntity) targetEntity;
    boolean alreadyDead = li.isDead() || li.getHealth() <= 0;
    String itemName = CompatibilityLib.getDeprecatedUtils().getDisplayName(li) + " Head";
    EntityType replaceType = null;
    boolean handled = true;
    CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
    if (li instanceof Player) {
        super.perform(context);
        if (li.isDead() && !alreadyDead && dropSkull) {
            dropHead(context, targetEntity, itemName);
        }
    } else if (li.getType() == EntityType.GIANT) {
        replaceType = EntityType.ZOMBIE;
    } else if (li instanceof Ageable && ((Ageable) li).isAdult()) {
        context.registerModified(li);
        ((Ageable) li).setBaby();
    } else if (li instanceof Zombie && compatibilityUtils.isAdult((Zombie) li)) {
        context.registerModified(li);
        compatibilityUtils.setBaby((Zombie) li);
    } else if (li instanceof Slime && ((Slime) li).getSize() > 1) {
        context.registerModified(li);
        Slime slime = (Slime) li;
        slime.setSize(slime.getSize() - 1);
    } else if (li instanceof Slime && ((Slime) li).getSize() > 1) {
        context.registerModified(li);
        Slime slime = (Slime) li;
        slime.setSize(slime.getSize() - 1);
    } else if (li.getType().name().equals("WITHER_SKELETON") && skeletons) {
        replaceType = EntityType.SKELETON;
    } else if (li.getType().name().equals("PHANTOM")) {
        int size = compatibilityUtils.getPhantomSize(li);
        if (size > 1) {
            compatibilityUtils.setPhantomSize(li, size - 1);
        } else {
            handled = false;
        }
    } else {
        handled = false;
    }
    if (!handled) {
        super.perform(context);
        if ((li.isDead() || li.getHealth() == 0) && !alreadyDead && dropSkull) {
            dropHead(context, targetEntity, itemName);
        }
    }
    if (replaceType != null) {
        UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
        context.registerModified(li);
        Entity replacement = controller.replaceMob(li, new EntityData(controller, replaceType), true, CreatureSpawnEvent.SpawnReason.CUSTOM);
        if (replacement == null) {
            return SpellResult.FAIL;
        }
        if (replacement instanceof Zombie) {
            compatibilityUtils.setAdult((Zombie) replacement);
        }
        context.registerForUndo(replacement);
        if (spawnedList != null) {
            spawnedList.add(replacement);
        }
    }
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Zombie(org.bukkit.entity.Zombie) EntityData(com.elmakers.mine.bukkit.entity.EntityData) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) LivingEntity(org.bukkit.entity.LivingEntity) EntityType(org.bukkit.entity.EntityType) MageController(com.elmakers.mine.bukkit.api.magic.MageController) UndoList(com.elmakers.mine.bukkit.api.block.UndoList)

Example 8 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class PowerBlockAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Block block = context.getTargetBlock();
    if (!context.hasBuildPermission(block)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (!context.isDestructible(block)) {
        return SpellResult.NO_TARGET;
    }
    context.getUndoList().setApplyPhysics(true);
    CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
    if (compatibilityUtils.canToggleBlockPower(block)) {
        context.registerForUndo(block);
        compatibilityUtils.toggleBlockPower(block);
    } else {
        Material material = block.getType();
        BlockState blockState = block.getState();
        MageController controller = context.getController();
        boolean updateBlockState = false;
        if (material == Material.REDSTONE_BLOCK) {
            context.registerForUndo(block);
            block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, material);
            controller.getRedstoneReplacement().modify(block, applyPhysics);
        } else if (material == Material.TNT) {
            context.registerForUndo(block);
            block.setType(Material.AIR);
            // Kaboomy time!
            context.registerForUndo(block.getLocation().getWorld().spawnEntity(block.getLocation(), EntityType.PRIMED_TNT));
        }
        if (updateBlockState) {
            blockState.update();
        }
    }
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Material(org.bukkit.Material)

Example 9 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class EntityAnimationAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity target = context.getTargetEntity();
    if (!(target instanceof LivingEntity)) {
        return SpellResult.LIVING_ENTITY_REQUIRED;
    }
    CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
    LivingEntity targetEntity = (LivingEntity) target;
    switch(animationType) {
        case SWING_MAIN_HAND:
            compatibilityUtils.swingMainHand(targetEntity);
            break;
        case SWING_OFF_HAND:
            compatibilityUtils.swingOffhand(targetEntity);
            break;
    }
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils)

Example 10 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class EquipAction method initialize.

@Override
public void initialize(Spell spell, ConfigurationSection parameters) {
    super.initialize(spell, parameters);
    if (parameters.contains("enchantments")) {
        enchantments = new HashMap<>();
        ConfigurationSection enchantConfig = ConfigurationUtils.getConfigurationSection(parameters, "enchantments");
        CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
        Collection<String> enchantKeys = enchantConfig.getKeys(false);
        for (String enchantKey : enchantKeys) {
            Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantKey);
            if (enchantment == null) {
                spell.getController().getLogger().warning("Invalid enchantment in equip action: " + enchantKey);
            } else {
                enchantments.put(enchantment, enchantConfig.getInt(enchantKey));
            }
        }
    }
}
Also used : CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Enchantment(org.bukkit.enchantments.Enchantment) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

CompatibilityUtils (com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils)18 Enchantment (org.bukkit.enchantments.Enchantment)9 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)4 Entity (org.bukkit.entity.Entity)4 ItemMeta (org.bukkit.inventory.meta.ItemMeta)4 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)3 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 HashMap (java.util.HashMap)3 Block (org.bukkit.block.Block)3 LivingEntity (org.bukkit.entity.LivingEntity)3 EntityData (com.elmakers.mine.bukkit.entity.EntityData)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 Material (org.bukkit.Material)2 Ageable (org.bukkit.entity.Ageable)2 EntityType (org.bukkit.entity.EntityType)2 Player (org.bukkit.entity.Player)2 Slime (org.bukkit.entity.Slime)2 Zombie (org.bukkit.entity.Zombie)2