Search in sources :

Example 11 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class DropAction method perform.

@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
    Block block = context.getTargetBlock();
    if (!context.hasBreakPermission(block)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (!context.isDestructible(block)) {
        return SpellResult.NO_TARGET;
    }
    // Don't allow dropping temporary blocks
    UndoList blockUndoList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(block.getLocation());
    if (blockUndoList != null && blockUndoList.isScheduled()) {
        return SpellResult.NO_TARGET;
    }
    if (dropCount < 0 || drops.size() < dropCount) {
        drops.addAll(block.getDrops());
    } else if (falling) {
        Location blockLocation = block.getLocation();
        FallingBlock falling = block.getWorld().spawnFallingBlock(blockLocation, block.getType(), block.getData());
        falling.setDropItem(false);
    }
    block.setType(Material.AIR);
    return SpellResult.CAST;
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) Location(org.bukkit.Location)

Example 12 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class GrowEntityAction 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);
        elementalSize *= 1.2;
        controller.setElementalScale(targetEntity, elementalSize);
        return SpellResult.CAST;
    }
    if (!(targetEntity instanceof LivingEntity))
        return SpellResult.NO_TARGET;
    LivingEntity li = (LivingEntity) targetEntity;
    if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
        context.registerModified(li);
        ((Ageable) li).setAdult();
    } else if (li instanceof Zombie) {
        context.registerModified(li);
        Zombie zombie = (Zombie) li;
        if (!zombie.isBaby()) {
            UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
            Location targetLocation = li.getLocation();
            li.remove();
            Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
            context.registerForUndo(giant);
            if (spawnedList != null) {
                spawnedList.add(giant);
            }
        } else {
            ((Zombie) li).setBaby(false);
        }
    } else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
        context.registerModified(li);
        ((PigZombie) li).setBaby(false);
    } else if (li instanceof Slime) {
        context.registerModified(li);
        Slime slime = (Slime) li;
        slime.setSize(slime.getSize() + 1);
    } else if (li instanceof Skeleton && skeletons && ((Skeleton) li).getSkeletonType() == Skeleton.SkeletonType.NORMAL) {
        context.registerModified(li);
        Skeleton skeleton = (Skeleton) li;
        skeleton.setSkeletonType(Skeleton.SkeletonType.WITHER);
    } else {
        return SpellResult.NO_TARGET;
    }
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PigZombie(org.bukkit.entity.PigZombie) Skeleton(org.bukkit.entity.Skeleton) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) Location(org.bukkit.Location)

Example 13 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class ActionBatch method finish.

@Override
public void finish() {
    if (!finished) {
        handler.cancel(context);
        handler.finish(context);
        context.finish();
        // Shouldn't need this anymore
        UndoList undoList = context.getUndoList();
        if (undoList != null) {
            undoList.setBatch(null);
        }
        finished = true;
    }
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList)

Example 14 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class ConfigurationMageDataStore method save.

public static void save(MageController controller, MageData mage, ConfigurationSection saveFile) {
    saveFile.set("id", mage.getId());
    saveFile.set("name", mage.getName());
    saveFile.set("last_cast", mage.getLastCast());
    saveFile.set("cooldown_expiration", mage.getCooldownExpiration());
    saveFile.set("last_death_location", ConfigurationUtils.fromLocation(mage.getLastDeathLocation()));
    Location location = mage.getLocation();
    if (location != null) {
        saveFile.set("location", ConfigurationUtils.fromLocation(location));
    }
    saveFile.set("destination_warp", mage.getDestinationWarp());
    saveFile.set("fall_protection_count", mage.getFallProtectionCount());
    saveFile.set("fall_protection", mage.getFallProtectionDuration());
    BrushData brush = mage.getBrushData();
    if (brush != null) {
        ConfigurationSection brushNode = saveFile.createSection("brush");
        try {
            Location cloneSource = brush.getCloneLocation();
            if (cloneSource != null) {
                brushNode.set("clone_location", ConfigurationUtils.fromLocation(cloneSource));
            }
            Location cloneTarget = brush.getCloneTarget();
            if (cloneTarget != null) {
                brushNode.set("clone_target", ConfigurationUtils.fromLocation(cloneTarget));
            }
            Location materialTarget = brush.getMaterialTarget();
            if (materialTarget != null) {
                brushNode.set("material_target", ConfigurationUtils.fromLocation(materialTarget));
            }
            brushNode.set("map_id", brush.getMapId());
            brushNode.set("material", ConfigurationUtils.fromMaterial(brush.getMaterial()));
            brushNode.set("data", brush.getMaterialData());
            brushNode.set("schematic", brush.getSchematicName());
            brushNode.set("scale", brush.getScale());
            brushNode.set("erase", brush.isFillWithAir());
        } catch (Exception ex) {
            controller.getLogger().warning("Failed to save brush data: " + ex.getMessage());
            ex.printStackTrace();
        }
    }
    UndoData undoData = mage.getUndoData();
    if (undoData != null) {
        List<Map<String, Object>> nodeList = new ArrayList<>();
        List<UndoList> undoList = undoData.getBlockList();
        for (UndoList list : undoList) {
            MemoryConfiguration listNode = new MemoryConfiguration();
            list.save(listNode);
            nodeList.add(listNode.getValues(true));
        }
        saveFile.set("undo", nodeList);
    }
    ConfigurationSection spellNode = saveFile.createSection("spells");
    Collection<SpellData> spellData = mage.getSpellData();
    if (spellData != null) {
        for (SpellData spell : spellData) {
            ConfigurationSection node = spellNode.createSection(spell.getKey().getKey());
            node.set("cast_count", spell.getCastCount());
            node.set("last_cast", spell.getLastCast());
            node.set("last_earn", spell.getLastEarn());
            node.set("cooldown_expiration", spell.getCooldownExpiration());
            node.set("active", spell.isActive() ? true : null);
            ConfigurationSection extra = spell.getExtraData();
            if (extra != null) {
                ConfigurationUtils.addConfigurations(node, extra);
            }
        }
    }
    Map<String, ItemStack> boundWands = mage.getBoundWands();
    if (boundWands != null && boundWands.size() > 0) {
        ConfigurationSection wandSection = saveFile.createSection("wands");
        for (Map.Entry<String, ItemStack> wandEntry : boundWands.entrySet()) {
            String key = wandEntry.getKey();
            if (key == null || key.isEmpty())
                continue;
            controller.serialize(wandSection, key, wandEntry.getValue());
        }
    }
    Map<Integer, ItemStack> respawnArmor = mage.getRespawnArmor();
    if (respawnArmor != null) {
        ConfigurationSection armorSection = saveFile.createSection("respawn_armor");
        for (Map.Entry<Integer, ItemStack> entry : respawnArmor.entrySet()) {
            controller.serialize(armorSection, Integer.toString(entry.getKey()), entry.getValue());
        }
    }
    Map<Integer, ItemStack> respawnInventory = mage.getRespawnInventory();
    if (respawnInventory != null) {
        ConfigurationSection inventorySection = saveFile.createSection("respawn_inventory");
        for (Map.Entry<Integer, ItemStack> entry : respawnInventory.entrySet()) {
            controller.serialize(inventorySection, Integer.toString(entry.getKey()), entry.getValue());
        }
    }
    List<ItemStack> storedInventory = mage.getStoredInventory();
    if (storedInventory != null) {
        saveFile.set("inventory", storedInventory);
    }
    saveFile.set("experience", mage.getStoredExperience());
    saveFile.set("level", mage.getStoredLevel());
    saveFile.set("open_wand", mage.isOpenWand());
    saveFile.set("gave_welcome_wand", mage.getGaveWelcomeWand());
    ConfigurationSection extraData = mage.getExtraData();
    if (extraData != null) {
        ConfigurationSection dataSection = saveFile.createSection("data");
        ConfigurationUtils.addConfigurations(dataSection, extraData);
    }
    ConfigurationSection properties = mage.getProperties();
    if (properties != null) {
        ConfigurationSection propertiesSection = saveFile.createSection("properties");
        ConfigurationUtils.addConfigurations(propertiesSection, properties);
    }
    Map<String, ConfigurationSection> classProperties = mage.getClassProperties();
    if (classProperties != null) {
        ConfigurationSection classesSection = saveFile.createSection("classes");
        for (Map.Entry<String, ConfigurationSection> entry : classProperties.entrySet()) {
            ConfigurationSection classSection = classesSection.createSection(entry.getKey());
            ConfigurationUtils.addConfigurations(classSection, entry.getValue());
        }
    }
    saveFile.set("active_class", mage.getActiveClass());
}
Also used : ArrayList(java.util.ArrayList) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) SpellData(com.elmakers.mine.bukkit.api.data.SpellData) UndoData(com.elmakers.mine.bukkit.api.data.UndoData) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) BrushData(com.elmakers.mine.bukkit.api.data.BrushData) Location(org.bukkit.Location) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 15 with UndoList

use of com.elmakers.mine.bukkit.api.block.UndoList in project MagicPlugin by elBukkit.

the class GrowSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (!target.hasEntity()) {
        return SpellResult.NO_TARGET;
    }
    Entity targetEntity = target.getEntity();
    if (controller.isElemental(targetEntity)) {
        double elementalSize = controller.getElementalScale(targetEntity);
        elementalSize *= 1.2;
        controller.setElementalScale(targetEntity, elementalSize);
        return SpellResult.CAST;
    }
    if (!(targetEntity instanceof LivingEntity))
        return SpellResult.NO_TARGET;
    LivingEntity li = (LivingEntity) targetEntity;
    if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
        registerModified(li);
        ((Ageable) li).setAdult();
    } else if (li instanceof Zombie) {
        registerModified(li);
        Zombie zombie = (Zombie) li;
        if (!zombie.isBaby()) {
            UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
            Location targetLocation = li.getLocation();
            li.remove();
            Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
            registerForUndo(giant);
            if (spawnedList != null) {
                spawnedList.add(giant);
            }
        } else {
            ((Zombie) li).setBaby(false);
        }
    } else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
        registerModified(li);
        ((PigZombie) li).setBaby(false);
    } else if (li instanceof Slime) {
        registerModified(li);
        Slime slime = (Slime) li;
        slime.setSize(slime.getSize() + 1);
    } else {
        return SpellResult.NO_TARGET;
    }
    registerForUndo();
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Player(org.bukkit.entity.Player) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Zombie(org.bukkit.entity.Zombie) PigZombie(org.bukkit.entity.PigZombie) PigZombie(org.bukkit.entity.PigZombie) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) Location(org.bukkit.Location)

Aggregations

UndoList (com.elmakers.mine.bukkit.api.block.UndoList)36 EventHandler (org.bukkit.event.EventHandler)15 Entity (org.bukkit.entity.Entity)14 Block (org.bukkit.block.Block)13 Location (org.bukkit.Location)10 FallingBlock (org.bukkit.entity.FallingBlock)10 Mage (com.elmakers.mine.bukkit.api.magic.Mage)8 LivingEntity (org.bukkit.entity.LivingEntity)6 Player (org.bukkit.entity.Player)6 ItemStack (org.bukkit.inventory.ItemStack)6 Ageable (org.bukkit.entity.Ageable)4 PigZombie (org.bukkit.entity.PigZombie)4 Slime (org.bukkit.entity.Slime)4 Zombie (org.bukkit.entity.Zombie)4 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)3 Target (com.elmakers.mine.bukkit.utility.Target)3 Nullable (javax.annotation.Nullable)3 BlockFace (org.bukkit.block.BlockFace)3 Skeleton (org.bukkit.entity.Skeleton)3