use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils 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;
EntityType replaceType = null;
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
context.registerModified(li);
((Ageable) li).setAdult();
} else if (li instanceof Zombie) {
Zombie zombie = (Zombie) li;
if (compatibilityUtils.isAdult(zombie)) {
replaceType = EntityType.GIANT;
} else {
context.registerModified(li);
compatibilityUtils.setAdult((Zombie) li);
}
} else if (li instanceof Slime) {
context.registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() + 1);
} else if (li instanceof Skeleton && skeletons) {
try {
replaceType = EntityType.valueOf("WITHER_SKELETON");
} catch (Exception ex) {
return SpellResult.NO_TARGET;
}
} else if (li.getType().name().equals("PHANTOM")) {
int size = compatibilityUtils.getPhantomSize(li);
compatibilityUtils.setPhantomSize(li, size + 1);
} else {
return SpellResult.NO_TARGET;
}
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;
}
context.registerForUndo(replacement);
if (spawnedList != null) {
spawnedList.add(replacement);
}
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class CheckInventoryAction method parseEnchantmentList.
@Nullable
private Collection<Enchantment> parseEnchantmentList(CastContext context, ConfigurationSection parameters, String key) {
Collection<Enchantment> enchantments = null;
List<String> keys = parameters.getStringList(key);
if (keys != null && !keys.isEmpty()) {
enchantments = new ArrayList<>();
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
for (String enchantmentKey : keys) {
Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantmentKey);
if (enchantment != null) {
enchantments.add(enchantment);
} else {
context.getLogger().warning("Invalid enchantment in CheckInventory action " + key + ": " + enchantmentKey);
}
}
}
return enchantments;
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class InventoryUtilsBase method addEnchantments.
@Override
public boolean addEnchantments(ItemStack item, ConfigurationSection enchantConfig) {
if (item == null)
return false;
ItemMeta meta = item.getItemMeta();
if (meta == null)
return false;
boolean addedAny = false;
if (enchantConfig != null) {
CompatibilityUtils compatibilityUtils = platform.getCompatibilityUtils();
Collection<String> enchantKeys = enchantConfig.getKeys(false);
for (String enchantKey : enchantKeys) {
try {
Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantKey);
if (enchantment == null) {
platform.getLogger().warning("Invalid enchantment: " + enchantKey);
continue;
}
int level = enchantConfig.getInt(enchantKey);
if (meta.getEnchantLevel(enchantment) >= level)
continue;
if (!meta.hasEnchant(enchantment) && meta.hasConflictingEnchant(enchantment))
continue;
if (meta.addEnchant(enchantment, level, false)) {
addedAny = true;
}
} catch (Exception ex) {
platform.getLogger().log(Level.SEVERE, "Error adding enchantment to item " + item.getType() + ": " + enchantKey, ex);
}
}
}
if (addedAny) {
item.setItemMeta(meta);
}
return addedAny;
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class InventoryUtilsBase method applyEnchantments.
@Override
public void applyEnchantments(ItemStack item, ConfigurationSection enchantConfig) {
if (item == null)
return;
Set<Enchantment> keep = null;
if (enchantConfig != null) {
keep = new HashSet<>();
CompatibilityUtils compatibilityUtils = platform.getCompatibilityUtils();
Collection<String> enchantKeys = enchantConfig.getKeys(false);
for (String enchantKey : enchantKeys) {
try {
Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantKey);
if (enchantment == null) {
platform.getLogger().warning("Invalid enchantment: " + enchantKey);
continue;
}
item.addUnsafeEnchantment(enchantment, enchantConfig.getInt(enchantKey));
keep.add(enchantment);
} catch (Exception ex) {
platform.getLogger().log(Level.SEVERE, "Error adding enchantment to item " + item.getType() + ": " + enchantKey, ex);
}
}
}
Collection<Enchantment> existing = new ArrayList<>(item.getEnchantments().keySet());
for (Enchantment enchantment : existing) {
if (keep == null || !keep.contains(enchantment)) {
item.removeEnchantment(enchantment);
}
}
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class EntityItemFrameData method canCycle.
@Override
public boolean canCycle(Entity entity) {
if (!(entity instanceof ItemFrame)) {
return false;
}
ItemFrame itemFrame = (ItemFrame) entity;
ItemStack frameItem = itemFrame.getItem();
CompatibilityUtils compatibilityUtils = PlatformInterpreter.getPlatform().getCompatibilityUtils();
if (frameItem == null || !compatibilityUtils.isFilledMap(frameItem.getType())) {
return false;
}
return true;
}
Aggregations