Search in sources :

Example 11 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class DisguiseAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    if (entity == null) {
        return SpellResult.NO_TARGET;
    }
    MageController controller = context.getController();
    if (disguiseConfig == null && !controller.isDisguised(entity)) {
        return SpellResult.NO_TARGET;
    } else if (disguiseConfig != null && controller.isDisguised(entity)) {
        return SpellResult.NO_TARGET;
    }
    controller.disguise(entity, disguiseConfig);
    context.registerForUndo(new UndoDisguise(controller, entity));
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController)

Example 12 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class EntitySelectAction method start.

@Override
public SpellResult start(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    final Location location = context.getLocation();
    List<Entity> allEntities = new ArrayList<>(location.getWorld().getNearbyEntities(location, radius, radius, radius));
    entities.clear();
    Collections.sort(allEntities, new Comparator<Entity>() {

        @Override
        public int compare(Entity entity1, Entity entity2) {
            return Double.compare(location.distanceSquared(entity1.getLocation()), location.distanceSquared(entity2.getLocation()));
        }
    });
    int index = 0;
    for (Entity targetEntity : allEntities) {
        if (!context.getTargetsCaster() && targetEntity == player)
            continue;
        if (targetEntity instanceof LivingEntity && ((LivingEntity) targetEntity).hasPotionEffect(PotionEffectType.INVISIBILITY))
            continue;
        if (!context.canTarget(targetEntity))
            continue;
        entities.put(index++, new WeakReference<>(targetEntity));
        if (entities.size() >= limit)
            break;
    }
    if (entities.size() == 0)
        return SpellResult.NO_TARGET;
    String inventoryTitle = context.getMessage("title", "Select Target");
    int invSize = ((entities.size() + 9) / 9) * 9;
    Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
    for (Map.Entry<Integer, WeakReference<Entity>> entry : entities.entrySet()) {
        Entity targetEntity = entry.getValue().get();
        if (targetEntity == null)
            continue;
        String displayName = DeprecatedUtils.getDisplayName(targetEntity);
        ItemStack skull = controller.getSkull(targetEntity, displayName);
        displayInventory.setItem(entry.getKey(), skull);
    }
    active = true;
    mage.activateGUI(this, displayInventory);
    return SpellResult.NO_ACTION;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) WeakReference(java.lang.ref.WeakReference) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) Inventory(org.bukkit.inventory.Inventory) Location(org.bukkit.Location)

Example 13 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class MountArmorStandAction method mountNewArmorStand.

protected boolean mountNewArmorStand(CastContext context) {
    Mage mage = context.getMage();
    Entity entity = context.getEntity();
    ArmorStand armorStand = CompatibilityUtils.createArmorStand(mage.getLocation());
    if (armorStandInvisible) {
        CompatibilityUtils.setInvisible(armorStand, true);
    }
    if (armorStandMarker) {
        armorStand.setMarker(true);
    }
    if (!armorStandGravity) {
        armorStand.setGravity(false);
    }
    CompatibilityUtils.setDisabledSlots(armorStand, 2039552);
    if (armorStandSmall) {
        armorStand.setSmall(true);
    }
    MageController controller = context.getController();
    controller.setForceSpawn(true);
    try {
        CompatibilityUtils.addToWorld(entity.getWorld(), armorStand, armorStandSpawnReason);
    } catch (Exception ex) {
        ex.printStackTrace();
        return false;
    }
    controller.setForceSpawn(false);
    if (mountWand) {
        armorStand.setHelmet(item);
    } else if (helmetItem != null) {
        armorStand.setHelmet(helmetItem);
    }
    if (mountName != null && !mountName.isEmpty()) {
        armorStand.setCustomName(mountName);
    }
    context.setTargetEntity(armorStand);
    return true;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) ArmorStand(org.bukkit.entity.ArmorStand) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 14 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class PlayerSelectAction method start.

@Override
public SpellResult start(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    List<Player> allPlayers = null;
    players.clear();
    if (allowCrossWorld) {
        allPlayers = new ArrayList<>(controller.getPlugin().getServer().getOnlinePlayers());
    } else {
        allPlayers = context.getLocation().getWorld().getPlayers();
    }
    Collections.sort(allPlayers, new Comparator<Player>() {

        @Override
        public int compare(Player p1, Player p2) {
            return p1.getDisplayName().compareTo(p2.getDisplayName());
        }
    });
    int index = 0;
    for (Player targetPlayer : allPlayers) {
        if (!context.getTargetsCaster() && targetPlayer == player)
            continue;
        if (targetPlayer.hasPotionEffect(PotionEffectType.INVISIBILITY))
            continue;
        if (!context.canTarget(targetPlayer))
            continue;
        players.put(index++, new WeakReference<>(targetPlayer));
    }
    if (players.size() == 0)
        return SpellResult.NO_TARGET;
    String inventoryTitle = context.getMessage("title", "Select Player");
    int invSize = ((players.size() + 9) / 9) * 9;
    Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
    for (Map.Entry<Integer, WeakReference<Player>> entry : players.entrySet()) {
        Player targetPlayer = entry.getValue().get();
        if (targetPlayer == null)
            continue;
        String name = targetPlayer.getName();
        String displayName = targetPlayer.getDisplayName();
        @SuppressWarnings("deprecation") ItemStack playerItem = new ItemStack(Material.SKULL_ITEM, 1, (short) 0, (byte) 3);
        ItemMeta meta = playerItem.getItemMeta();
        meta.setDisplayName(displayName);
        if (meta instanceof SkullMeta) {
            SkullMeta skullData = (SkullMeta) meta;
            skullData.setOwner(name);
        }
        if (!name.equals(displayName)) {
            List<String> lore = new ArrayList<>();
            lore.add(name);
            meta.setLore(lore);
        }
        playerItem.setItemMeta(meta);
        displayInventory.setItem(entry.getKey(), playerItem);
    }
    active = true;
    mage.activateGUI(this, displayInventory);
    return SpellResult.NO_ACTION;
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) SkullMeta(org.bukkit.inventory.meta.SkullMeta) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) WeakReference(java.lang.ref.WeakReference) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) Inventory(org.bukkit.inventory.Inventory) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 15 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.

the class FallProtectionAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity targetEntity = context.getTargetEntity();
    MageController controller = context.getController();
    Mage targetMage = targetEntity != null && controller.isMage(targetEntity) ? controller.getMage(targetEntity) : null;
    if (targetMage == null) {
        return SpellResult.NO_TARGET;
    }
    targetMage.enableFallProtection(fallProtection, fallProtectionCount, context.getSpell());
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Aggregations

MageController (com.elmakers.mine.bukkit.api.magic.MageController)76 Mage (com.elmakers.mine.bukkit.api.magic.Mage)45 Entity (org.bukkit.entity.Entity)27 Player (org.bukkit.entity.Player)26 Location (org.bukkit.Location)16 ItemStack (org.bukkit.inventory.ItemStack)16 Wand (com.elmakers.mine.bukkit.api.wand.Wand)14 Block (org.bukkit.block.Block)11 LivingEntity (org.bukkit.entity.LivingEntity)11 ArrayList (java.util.ArrayList)10 Inventory (org.bukkit.inventory.Inventory)9 ItemMeta (org.bukkit.inventory.meta.ItemMeta)8 Spell (com.elmakers.mine.bukkit.api.spell.Spell)5 MagicController (com.elmakers.mine.bukkit.magic.MagicController)5 Nullable (javax.annotation.Nullable)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 ItemData (com.elmakers.mine.bukkit.api.item.ItemData)4 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)4 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)4 File (java.io.File)4