use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class OrientAction method perform.
@Override
public SpellResult perform(CastContext context) {
Mage mage = context.getMage();
Entity entity = mage.getEntity();
if (entity == null) {
return SpellResult.ENTITY_REQUIRED;
}
context.registerMoved(entity);
Location location = entity.getLocation();
if (pitch != null || yaw != null) {
if (pitch != null) {
location.setPitch(pitch);
}
if (yaw != null) {
location.setYaw(yaw);
}
}
if (pitchOffset != null || yawOffset != null) {
if (pitchOffset != null) {
location.setPitch(location.getPitch() + pitchOffset);
}
if (yawOffset != null) {
location.setYaw(location.getYaw() + yawOffset);
}
}
if (pitchOffset == null && yawOffset == null && yaw == null && pitch == null) {
Entity targetEntity = context.getTargetEntity();
if (targetEntity == null) {
return SpellResult.NO_TARGET;
}
Location direction = targetEntity.getLocation().subtract(location);
location.setDirection(direction.toVector());
}
entity.teleport(location);
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage 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.Mage 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;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class FillWandAction method perform.
@Override
public SpellResult perform(CastContext context) {
Mage mage = context.getMage();
Wand wand = context.getWand();
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
if (wand == null) {
context.showMessage("no_wand", "You must be holding a wand!");
return SpellResult.FAIL;
}
wand.fill(player, maxLevel);
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class FireworkAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
Random rand = context.getRandom();
power = rand.nextInt(2) + 1;
Mage mage = context.getMage();
// Configuration overrides
power = parameters.getInt("power", power);
if (parameters.contains("color")) {
color1 = getColor(parameters.getString("color"));
} else if (mage.getEffectColor() != null) {
color1 = mage.getEffectColor();
}
if (parameters.contains("color2")) {
color2 = getColor(parameters.getString("color2"));
}
if (parameters.contains("firework")) {
fireworkType = getType(parameters.getString("firework"));
}
flicker = parameters.getBoolean("flicker");
trail = parameters.getBoolean("trail");
launch = parameters.getBoolean("launch", false);
silent = parameters.getBoolean("silent", false);
startDistance = parameters.getInt("start", 0);
speed = parameters.getDouble("speed", 0.1);
dyOffset = parameters.getDouble("dy_offset", 0);
if (parameters.contains("ticks_flown")) {
ticksFlown = parameters.getInt("ticks_flown");
} else {
ticksFlown = null;
}
if (parameters.contains("expected_lifespan")) {
expectedLifespan = parameters.getInt("expected_lifespan");
} else {
expectedLifespan = null;
}
}
Aggregations