From 4d7b5374e57cb757f38ed1cb511054eae27ca8b9 Mon Sep 17 00:00:00 2001 From: Tastybento Date: Thu, 28 Dec 2017 17:11:49 -0800 Subject: [PATCH] Bolstered error reporting for malformed addon.yml files. --- .../us/tastybento/bskyblock/api/addons/Addon.java | 2 -- .../bskyblock/api/addons/AddonClassLoader.java | 8 ++++++-- .../us/tastybento/bskyblock/api/panels/Panel.java | 12 ++++++++++++ .../tastybento/bskyblock/managers/AddonsManager.java | 6 +++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/api/addons/Addon.java b/src/main/java/us/tastybento/bskyblock/api/addons/Addon.java index 8a1531953..58fbae2d1 100644 --- a/src/main/java/us/tastybento/bskyblock/api/addons/Addon.java +++ b/src/main/java/us/tastybento/bskyblock/api/addons/Addon.java @@ -186,8 +186,6 @@ public abstract class Addon implements AddonInterface { } out.close(); in.close(); - } else { - getLogger().warning("Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists."); } jar.close(); } catch (IOException ex) { diff --git a/src/main/java/us/tastybento/bskyblock/api/addons/AddonClassLoader.java b/src/main/java/us/tastybento/bskyblock/api/addons/AddonClassLoader.java index fcc9f42eb..d94610cb1 100644 --- a/src/main/java/us/tastybento/bskyblock/api/addons/AddonClassLoader.java +++ b/src/main/java/us/tastybento/bskyblock/api/addons/AddonClassLoader.java @@ -7,6 +7,9 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.Map; +import org.bukkit.plugin.InvalidDescriptionException; + +import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.addons.AddonDescription.AddonDescriptionBuilder; import us.tastybento.bskyblock.api.addons.exception.InvalidAddonFormatException; import us.tastybento.bskyblock.api.addons.exception.InvalidAddonInheritException; @@ -18,7 +21,7 @@ public class AddonClassLoader extends URLClassLoader { public Addon addon; - public AddonClassLoader(Mapdata, File path, BufferedReader reader, ClassLoader loaders) throws InvalidAddonInheritException, MalformedURLException, InvalidAddonFormatException { + public AddonClassLoader(Mapdata, File path, BufferedReader reader, ClassLoader loaders) throws InvalidAddonInheritException, MalformedURLException, InvalidAddonFormatException, InvalidDescriptionException { super(new URL[]{path.toURI().toURL()}, loaders); Addon addon = null; @@ -35,7 +38,8 @@ public class AddonClassLoader extends URLClassLoader { throw new InvalidAddonFormatException("Packages declaration cannot start with 'us.tastybento'"); } } catch (ClassNotFoundException e) { - e.printStackTrace(); + BSkyBlock.getInstance().getLogger().severe("Could not load '" + path.getName() + "' in folder '" + path.getParent() + "'"); + throw new InvalidDescriptionException("Invalid addon.yml"); } Class addonClass; diff --git a/src/main/java/us/tastybento/bskyblock/api/panels/Panel.java b/src/main/java/us/tastybento/bskyblock/api/panels/Panel.java index 4e410002d..7dc908522 100644 --- a/src/main/java/us/tastybento/bskyblock/api/panels/Panel.java +++ b/src/main/java/us/tastybento/bskyblock/api/panels/Panel.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.listeners.PanelListener; public class Panel { @@ -45,4 +46,15 @@ public class Panel { PanelListener.openPanels.put(player.getUniqueId(), this); } } + + /** + * Open the inventory panel + * @param users + */ + public void open(User... users) { + for (User user : users) { + user.getPlayer().openInventory(inventory); + PanelListener.openPanels.put(user.getUniqueId(), this); + } + } } diff --git a/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java b/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java index cbac2e6fe..fcdd4eb30 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/AddonsManager.java @@ -12,6 +12,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; import org.bukkit.Bukkit; +import org.bukkit.plugin.InvalidDescriptionException; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.addons.Addon; @@ -36,6 +37,7 @@ public final class AddonsManager { /** * Loads all the addons from the addons folder + * @throws InvalidDescriptionException */ public void enableAddons() { File f = new File(BSkyBlock.getInstance().getDataFolder(), "addons"); @@ -49,6 +51,8 @@ public final class AddonsManager { e.printStackTrace(); } catch (InvalidAddonInheritException e) { e.printStackTrace(); + } catch (InvalidDescriptionException e) { + e.printStackTrace(); } } } @@ -83,7 +87,7 @@ public final class AddonsManager { return null; } - private void loadAddon(File f) throws InvalidAddonFormatException, InvalidAddonInheritException { + private void loadAddon(File f) throws InvalidAddonFormatException, InvalidAddonInheritException, InvalidDescriptionException { try { Addon addon = null;