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