Search in sources :

Example 16 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class MagicLogger method log.

@Override
public void log(LogRecord record) {
    if (silent)
        return;
    if (!capture || (!record.getLevel().equals(Level.WARNING) && !record.getLevel().equals(Level.SEVERE)) || record.getThrown() != null) {
        super.log(record);
    }
    Server server = Bukkit.getServer();
    CompatibilityUtils compatibility = CompatibilityLib.isInitialized() ? CompatibilityLib.getCompatibilityUtils() : null;
    String message = record.getMessage();
    if (message != null) {
        message = message.replace("[Magic] ", "");
    }
    LogMessage logMessage = new LogMessage(context, message);
    if (record.getLevel().equals(Level.WARNING)) {
        synchronized (warnings) {
            pendingWarningCount++;
            warnings.add(logMessage);
            if (server != null) {
                MagicWarningEvent event = new MagicWarningEvent(record, context, pendingWarningCount, capture);
                if (compatibility != null && compatibility.isPrimaryThread()) {
                    server.getPluginManager().callEvent(event);
                } else if (plugin != null && plugin.isEnabled()) {
                    server.getScheduler().runTask(plugin, new CallEventTask(event));
                }
            }
        }
    } else if (record.getLevel().equals(Level.SEVERE)) {
        synchronized (errors) {
            pendingErrorCount++;
            errors.add(logMessage);
            if (server != null) {
                MagicErrorEvent event = new MagicErrorEvent(record, context, pendingErrorCount, capture);
                if (compatibility != null && compatibility.isPrimaryThread()) {
                    server.getPluginManager().callEvent(event);
                } else if (plugin != null && plugin.isEnabled()) {
                    server.getScheduler().runTask(plugin, new CallEventTask(event));
                }
            }
        }
    }
}
Also used : MagicWarningEvent(com.elmakers.mine.bukkit.api.event.MagicWarningEvent) CallEventTask(com.elmakers.mine.bukkit.tasks.CallEventTask) Server(org.bukkit.Server) MagicErrorEvent(com.elmakers.mine.bukkit.api.event.MagicErrorEvent) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils)

Example 17 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class MagicItemCommandExecutor method onItemRemoveEnchant.

public boolean onItemRemoveEnchant(CommandSender sender, Player player, ItemStack item, String enchantName) {
    Enchantment enchantment = null;
    ItemMeta itemMeta = item.getItemMeta();
    CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
    if (enchantName == null) {
        Map<Enchantment, Integer> enchants = itemMeta.getEnchants();
        if (enchants == null || enchants.size() == 0) {
            sender.sendMessage(api.getMessages().get("item.no_enchants"));
            return true;
        }
        enchantment = enchants.keySet().iterator().next();
    } else {
        try {
            enchantment = compatibilityUtils.getEnchantmentByKey(enchantName);
        } catch (Exception ex) {
            sender.sendMessage(ChatColor.RED + "Error adding enchantment: " + ChatColor.WHITE + enchantName);
            controller.getLogger().log(Level.SEVERE, "Error adding enchantment ", ex);
            return true;
        }
        if (enchantment == null) {
            sender.sendMessage(ChatColor.RED + "Invalid enchantment: " + ChatColor.WHITE + enchantName);
            return true;
        }
    }
    if (!itemMeta.hasEnchant(enchantment)) {
        sender.sendMessage(api.getMessages().get("item.no_enchant").replace("$enchant", compatibilityUtils.getEnchantmentKey(enchantment)));
    } else {
        itemMeta.removeEnchant(enchantment);
        item.setItemMeta(itemMeta);
        sender.sendMessage(api.getMessages().get("item.enchant_removed").replace("$enchant", compatibilityUtils.getEnchantmentKey(enchantment)));
    }
    return true;
}
Also used : CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta) IOException(java.io.IOException)

Example 18 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class MagicItemCommandExecutor method onItemAddEnchant.

public boolean onItemAddEnchant(CommandSender sender, Player player, ItemStack item, String enchantName, String enchantValue) {
    Enchantment enchantment = null;
    CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
    try {
        enchantment = compatibilityUtils.getEnchantmentByKey(enchantName);
    } catch (Exception ex) {
        sender.sendMessage(ChatColor.RED + "Error adding enchantment: " + ChatColor.WHITE + enchantName);
        controller.getLogger().log(Level.SEVERE, "Error adding enchantment ", ex);
        return true;
    }
    if (enchantment == null) {
        sender.sendMessage(ChatColor.RED + "Invalid enchantment: " + ChatColor.WHITE + enchantName);
        return true;
    }
    int level = 0;
    try {
        level = Integer.parseInt(enchantValue);
    } catch (Exception ex) {
        sender.sendMessage(ChatColor.RED + "Invalid enchantment level: " + ChatColor.WHITE + enchantValue);
        return true;
    }
    if (!player.hasPermission("magic.item.enchant.extreme")) {
        if (level < 0 || level > 10) {
            sender.sendMessage(ChatColor.RED + "Invalid enchantment level: " + ChatColor.WHITE + enchantValue);
            return true;
        }
    }
    ItemMeta itemMeta = item.getItemMeta();
    boolean allowUnsafe = player.hasPermission("magic.item.enchant.unsafe");
    if (itemMeta.addEnchant(enchantment, level, allowUnsafe)) {
        item.setItemMeta(itemMeta);
        sender.sendMessage(api.getMessages().get("item.enchant_added").replace("$enchant", compatibilityUtils.getEnchantmentKey(enchantment)));
    } else {
        if (!allowUnsafe && level > 5) {
            sender.sendMessage(api.getMessages().get("item.enchant_unsafe"));
        } else {
            sender.sendMessage(api.getMessages().get("item.enchant_not_added").replace("$enchant", compatibilityUtils.getEnchantmentKey(enchantment)));
        }
    }
    return true;
}
Also used : CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Enchantment(org.bukkit.enchantments.Enchantment) IOException(java.io.IOException) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

CompatibilityUtils (com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils)18 Enchantment (org.bukkit.enchantments.Enchantment)9 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)4 Entity (org.bukkit.entity.Entity)4 ItemMeta (org.bukkit.inventory.meta.ItemMeta)4 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)3 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 HashMap (java.util.HashMap)3 Block (org.bukkit.block.Block)3 LivingEntity (org.bukkit.entity.LivingEntity)3 EntityData (com.elmakers.mine.bukkit.entity.EntityData)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 Material (org.bukkit.Material)2 Ageable (org.bukkit.entity.Ageable)2 EntityType (org.bukkit.entity.EntityType)2 Player (org.bukkit.entity.Player)2 Slime (org.bukkit.entity.Slime)2 Zombie (org.bukkit.entity.Zombie)2