Improved addon loading error reporting

Fixed a bug in the team invite error strings.
This commit is contained in:
tastybento 2018-07-29 16:56:14 -07:00
parent 6d22f199ee
commit f2831c7258
4 changed files with 19 additions and 21 deletions

View File

@ -14,7 +14,6 @@ import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.InvalidDescriptionException;
import org.bukkit.util.permissions.DefaultPermissions; import org.bukkit.util.permissions.DefaultPermissions;
import world.bentobox.bbox.BentoBox;
import world.bentobox.bbox.api.addons.AddonDescription.AddonDescriptionBuilder; import world.bentobox.bbox.api.addons.AddonDescription.AddonDescriptionBuilder;
import world.bentobox.bbox.api.addons.exception.InvalidAddonFormatException; import world.bentobox.bbox.api.addons.exception.InvalidAddonFormatException;
import world.bentobox.bbox.api.addons.exception.InvalidAddonInheritException; import world.bentobox.bbox.api.addons.exception.InvalidAddonInheritException;
@ -45,12 +44,12 @@ public class AddonClassLoader extends URLClassLoader {
try { try {
String mainClass = data.getString("main"); String mainClass = data.getString("main");
javaClass = Class.forName(mainClass, true, this); javaClass = Class.forName(mainClass, true, this);
if(mainClass.contains("us.tastybento")){ if(mainClass.startsWith("world.bentobox")){
throw new InvalidAddonFormatException("Packages declaration cannot start with 'us.tastybento'"); throw new InvalidAddonFormatException("Packages declaration cannot start with 'world.bentobox'");
} }
} catch (ClassNotFoundException e) { } catch (Exception e) {
BentoBox.getInstance().logError("Could not load '" + path.getName() + "' in folder '" + path.getParent() + "' - invalid addon.yml"); e.printStackTrace();
throw new InvalidDescriptionException("Invalid addon.yml"); throw new InvalidDescriptionException("Could not load '" + path.getName() + "' in folder '" + path.getParent() + "' - " + e.getMessage());
} }
Class<? extends Addon> addonClass; Class<? extends Addon> addonClass;

View File

@ -71,19 +71,19 @@ public class IslandTeamInviteCommand extends CompositeCommand {
} }
// Player cannot invite themselves // Player cannot invite themselves
if (playerUUID.equals(invitedPlayerUUID)) { if (playerUUID.equals(invitedPlayerUUID)) {
user.sendMessage("commands.island.team.invite.cannot-invite-self"); user.sendMessage("commands.island.team.invite.errors.cannot-invite-self");
return false; return false;
} }
// Check if this player can be invited to this island, or // Check if this player can be invited to this island, or
// whether they are still on cooldown // whether they are still on cooldown
long time = getPlayers().getInviteCoolDownTime(invitedPlayerUUID, getIslands().getIslandLocation(getWorld(), playerUUID)); long time = getPlayers().getInviteCoolDownTime(invitedPlayerUUID, getIslands().getIslandLocation(getWorld(), playerUUID));
if (time > 0 && !user.isOp()) { if (time > 0 && !user.isOp()) {
user.sendMessage("commands.island.team.invite.cooldown", TextVariables.NUMBER, String.valueOf(time)); user.sendMessage("commands.island.team.invite.errors.cooldown", TextVariables.NUMBER, String.valueOf(time));
return false; return false;
} }
// Player cannot invite someone already on a team // Player cannot invite someone already on a team
if (getIslands().inTeam(getWorld(), invitedPlayerUUID)) { if (getIslands().inTeam(getWorld(), invitedPlayerUUID)) {
user.sendMessage("commands.island.team.invite.already-on-team"); user.sendMessage("commands.island.team.invite.errors.already-on-team");
return false; return false;
} }
return invite(user,invitedPlayer); return invite(user,invitedPlayer);

View File

@ -92,8 +92,7 @@ public class AddonsManager {
// Obtain the addon.yml file // Obtain the addon.yml file
JarEntry entry = jar.getJarEntry("addon.yml"); JarEntry entry = jar.getJarEntry("addon.yml");
if (entry == null) { if (entry == null) {
throw new InvalidAddonFormatException("Addon doesn't contains description file"); throw new InvalidAddonFormatException("Addon '" + f.getName() + "' doesn't contains addon.yml file");
} }
// Open a reader to the jar // Open a reader to the jar
BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry))); BufferedReader reader = new BufferedReader(new InputStreamReader(jar.getInputStream(entry)));

View File

@ -190,7 +190,7 @@ public class IslandTeamInviteCommandTest {
String[] name = {"tastybento"}; String[] name = {"tastybento"};
when(pm.getUUID(Mockito.any())).thenReturn(uuid); when(pm.getUUID(Mockito.any())).thenReturn(uuid);
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.cannot-invite-self")); Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.errors.cannot-invite-self"));
} }
@ -207,7 +207,7 @@ public class IslandTeamInviteCommandTest {
when(pm.getUUID(Mockito.any())).thenReturn(notUUID); when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.already-on-team")); Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.errors.already-on-team"));
} }
} }