diff --git a/src/main/java/com/github/kristianvld/angeltrophies/CommandHandler.java b/src/main/java/com/github/kristianvld/angeltrophies/CommandHandler.java index 7b61428..f995537 100644 --- a/src/main/java/com/github/kristianvld/angeltrophies/CommandHandler.java +++ b/src/main/java/com/github/kristianvld/angeltrophies/CommandHandler.java @@ -40,9 +40,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } return true; } else if (args[0].equalsIgnoreCase("reload")) { - if (hasPermission(sender, permissionDeniedMessage)) { - Main.getInstance().reload(); - C.main(sender, "Reloaded {0}.", Main.getInstance().getDescription().getName()); + if (hasPermission(sender, reloadPermission)) { + Main.getInstance().reload(sender); } return true; } else if (!(sender instanceof Player)) { diff --git a/src/main/java/com/github/kristianvld/angeltrophies/Main.java b/src/main/java/com/github/kristianvld/angeltrophies/Main.java index be63aff..3987441 100644 --- a/src/main/java/com/github/kristianvld/angeltrophies/Main.java +++ b/src/main/java/com/github/kristianvld/angeltrophies/Main.java @@ -6,7 +6,9 @@ import com.github.kristianvld.angeltrophies.skin.SkinManager; import com.github.kristianvld.angeltrophies.trophy.Trophy; import com.github.kristianvld.angeltrophies.trophy.TrophyManager; +import com.github.kristianvld.angeltrophies.util.C; import org.bukkit.Material; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.HandlerList; @@ -49,12 +51,21 @@ public void onEnable() { } } - public void reload() { - HandlerList.unregisterAll(skinManager); - HandlerList.unregisterAll(trophyManager); - getLogger().info("Reloading..."); - loadManagers(); - getLogger().info("Done Reloading."); + public void reload(CommandSender sender) { + try { + HandlerList.unregisterAll(skinManager); + HandlerList.unregisterAll(trophyManager); + getLogger().info("Reloading..."); + loadManagers(); + getLogger().info("Done Reloading."); + C.main(sender, "Reloaded {0}.", Main.getInstance().getDescription().getName()); + } catch (Exception e) { + getLogger().log(Level.SEVERE, "Error while reloading:", e); + getLogger().severe("An error occurred while enabling AngelTrophies, disabling..."); + C.error(sender, "An error occurred while reload {0}.", Main.getInstance().getDescription().getName()); + C.error(sender, "Disabling the plugin..."); + setEnabled(false); + } } private void loadManagers() { diff --git a/src/main/java/com/github/kristianvld/angeltrophies/couch/CouchUtil.java b/src/main/java/com/github/kristianvld/angeltrophies/couch/CouchUtil.java index 0fa9d33..b11669d 100644 --- a/src/main/java/com/github/kristianvld/angeltrophies/couch/CouchUtil.java +++ b/src/main/java/com/github/kristianvld/angeltrophies/couch/CouchUtil.java @@ -18,6 +18,7 @@ public class CouchUtil { private static final Map, Trophy> trophies = new HashMap<>(); public static void buildCache(Collection trophies) { + CouchUtil.trophies.clear(); Set groups = new HashSet<>(); for (Trophy t : trophies) { if (t.getCouchRole() != null) { diff --git a/src/main/java/com/github/kristianvld/angeltrophies/skin/Skin.java b/src/main/java/com/github/kristianvld/angeltrophies/skin/Skin.java index da6f67d..aa17168 100644 --- a/src/main/java/com/github/kristianvld/angeltrophies/skin/Skin.java +++ b/src/main/java/com/github/kristianvld/angeltrophies/skin/Skin.java @@ -34,7 +34,7 @@ public Skin(Material sourceType, int sourceID, String target, String sticker) { public Skin(String source, String target, String sticker) { if (!OraxenItems.exists(source)) { - throw new IllegalArgumentException("Source is not a valid Oraxen item!"); + throw new IllegalArgumentException("Source is not a valid Oraxen item for Skin '" + sticker + "'. '" + source + "' was not found."); } ItemStack sourceItem = OraxenItems.getItemById(source).build(); init(sourceItem.getType(), getModelData(sourceItem), target, sticker); @@ -46,14 +46,14 @@ private void init(Material sourceType, int sourceID, String target, String stick material = sourceType; this.sourceID = sourceID; if (!OraxenItems.exists(target)) { - throw new IllegalArgumentException("Target is not a valid Oraxen item!"); + throw new IllegalArgumentException("Target is not a valid Oraxen item for the Skin '" + sticker + "', target: '" + target + "'!"); } if (!OraxenItems.exists(sticker)) { - throw new IllegalArgumentException("Sticker is not a valid Oraxen item!"); + throw new IllegalArgumentException("Skin is not a valid Oraxen item for the Skin '" + sticker + "'!"); } ItemStack targetItem = OraxenItems.getItemById(target).build(); if (targetItem.getType() != sourceType) { - throw new IllegalArgumentException("Source and Target needs to be of the same material!"); + throw new IllegalArgumentException("Source and Target needs to be of the same material for the Skin '" + sticker + "'. Provided target: " + targetItem.getType() + ", provided source: " + sourceType + "!"); } targetID = getModelData(targetItem); targetName = target; diff --git a/src/main/java/com/github/kristianvld/angeltrophies/trophy/Trophy.java b/src/main/java/com/github/kristianvld/angeltrophies/trophy/Trophy.java index 12c0773..919aea3 100644 --- a/src/main/java/com/github/kristianvld/angeltrophies/trophy/Trophy.java +++ b/src/main/java/com/github/kristianvld/angeltrophies/trophy/Trophy.java @@ -57,7 +57,7 @@ public Trophy(String item, boolean floor, boolean floorSmall, double floorOffset itemName = item; exampleItem = OraxenItems.exists(item) ? OraxenItems.getItemById(item).build() : null; if (exampleItem == null || exampleItem.getAmount() <= 0) { - throw new IllegalArgumentException("Invalid Oraxen item provided for trophy."); + throw new IllegalArgumentException("Invalid Oraxen item provided for trophy '" + item + "'."); } this.floor = floor; this.floorSmall = floorSmall; @@ -70,7 +70,7 @@ public Trophy(String item, boolean floor, boolean floorSmall, double floorOffset this.couchGroup = couchGroup; this.couchRole = couchRole; if ((couchGroup == null || couchRole == null) && (couchGroup != null || couchRole != null)) { - throw new IllegalArgumentException("Both CouchGroup and CouchRole needs to be define, not just one."); + throw new IllegalArgumentException("Both CouchGroup and CouchRole needs to be define, not just one for the trophy '" + item + "'."); } } diff --git a/src/main/java/com/github/kristianvld/angeltrophies/util/C.java b/src/main/java/com/github/kristianvld/angeltrophies/util/C.java index ac79b32..bcaf3b7 100644 --- a/src/main/java/com/github/kristianvld/angeltrophies/util/C.java +++ b/src/main/java/com/github/kristianvld/angeltrophies/util/C.java @@ -28,11 +28,17 @@ public static String prefix(String prefix, String colorBody, String msg, Object. } public static void main(CommandSender receiver, String msg, Object... objs) { + if (receiver == null) { + return; + } String message = prefix(prefixMain, colorBodyMain, msg, objs); receiver.sendMessage(message); } public static void error(CommandSender receiver, String msg, Object... objs) { + if (receiver == null) { + return; + } String message = prefix(prefixError, colorBodyError, msg, objs); receiver.sendMessage(message); }