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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations