use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class DoorAction method perform.
@Override
public SpellResult perform(CastContext context) {
Block targetBlock = context.getTargetBlock();
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
Block[] doorBlocks = compatibilityUtils.getDoorBlocks(targetBlock);
if (doorBlocks == null) {
return SpellResult.NO_TARGET;
}
for (Block doorBlock : doorBlocks) {
if (!context.hasBuildPermission(doorBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (!context.isDestructible(doorBlock)) {
return SpellResult.NO_TARGET;
}
}
if (!compatibilityUtils.checkDoorAction(doorBlocks, actionType)) {
return SpellResult.NO_TARGET;
}
for (Block doorBlock : doorBlocks) {
context.registerForUndo(doorBlock);
}
if (!CompatibilityLib.getCompatibilityUtils().performDoorAction(doorBlocks, actionType)) {
return SpellResult.NO_TARGET;
}
context.setTargetLocation(doorBlocks[0].getLocation());
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class Wand method getEnchantments.
@Override
@Nonnull
public Map<Enchantment, Integer> getEnchantments() {
Map<Enchantment, Integer> enchantMap = new HashMap<>();
ConfigurationSection enchantConfig = getConfigurationSection("enchantments");
if (enchantConfig != null) {
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
Collection<String> enchantKeys = enchantConfig.getKeys(false);
for (String enchantKey : enchantKeys) {
try {
Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantKey);
if (enchantment == null) {
controller.getLogger().warning("Invalid enchantment in wand " + getTemplateKey() + ": " + enchantKey);
} else {
enchantMap.put(enchantment, enchantConfig.getInt(enchantKey));
}
} catch (Exception ex) {
controller.getLogger().log(Level.SEVERE, "Could not add enchantment: " + enchantKey + " to wand " + getTemplateKey(), ex);
}
}
}
return enchantMap;
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class Wand method addEnchantments.
@Override
public boolean addEnchantments(Map<Enchantment, Integer> enchants) {
if (enchants == null || item == null) {
return false;
}
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
List<String> enchantmentsAllowed = getStringList("allowed_enchantments");
Set<Enchantment> allowed = null;
if (enchantmentsAllowed != null && !enchantmentsAllowed.isEmpty()) {
allowed = new HashSet<>();
for (String enchantmentKey : enchantmentsAllowed) {
Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantmentKey);
if (enchantment != null) {
allowed.add(enchantment);
}
}
}
ConfigurationSection enchantments = ConfigurationUtils.newSection(configuration);
for (Map.Entry<Enchantment, Integer> entry : enchants.entrySet()) {
Enchantment enchantment = entry.getKey();
if (allowed != null && !allowed.contains(enchantment))
continue;
enchantments.set(compatibilityUtils.getEnchantmentKey(enchantment), entry.getValue());
}
if (enchantments.getKeys(false).isEmpty()) {
return false;
}
if (CompatibilityLib.getInventoryUtils().addEnchantments(item, enchantments)) {
enchantments = ConfigurationUtils.newSection(configuration);
Map<Enchantment, Integer> newEnchants = item.getItemMeta().getEnchants();
for (Map.Entry<Enchantment, Integer> entry : newEnchants.entrySet()) {
enchantments.set(compatibilityUtils.getEnchantmentKey(entry.getKey()), entry.getValue());
}
setProperty("enchantments", enchantments);
saveState();
findAndUpdateLore();
return true;
}
return false;
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class Wand method setEnchantments.
@Override
public void setEnchantments(Map<Enchantment, Integer> enchants) {
if (enchants == null) {
setProperty("enchantments", null);
if (item != null) {
ItemMeta meta = item.getItemMeta();
if (meta != null) {
meta.getEnchants().clear();
item.setItemMeta(meta);
}
}
} else {
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
ConfigurationSection enchantments = ConfigurationUtils.newSection(configuration);
for (Map.Entry<Enchantment, Integer> entry : enchants.entrySet()) {
enchantments.set(compatibilityUtils.getEnchantmentKey(entry.getKey()), entry.getValue());
}
setProperty("enchantments", enchantments);
if (item != null) {
CompatibilityLib.getInventoryUtils().applyEnchantments(item, enchantments);
}
saveState();
findAndUpdateLore();
}
}
use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.
the class MagicWarp method checkMarker.
public void checkMarker(MagicController controller) {
if (markerIcon != null) {
CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
String cleanName = ChatColor.stripColor(compatibilityUtils.translateColors(getName()));
String cleanDescription = description;
if (cleanDescription != null) {
cleanDescription = ChatColor.stripColor(compatibilityUtils.translateColors(cleanDescription));
}
controller.addMarker("warp-" + key, markerIcon, getMarkerSet(), cleanName, getLocation(), cleanDescription);
} else {
removeMarker(controller);
}
}
Aggregations