Skip to content

Commit

Permalink
fix responsehandler "npe"
Browse files Browse the repository at this point in the history
  • Loading branch information
Badbird5907 committed Jul 18, 2022
1 parent 4f89338 commit 2fc3314
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

package net.octopvp.commander.bukkit;

import com.google.common.collect.ImmutableSet;
import lombok.Getter;
import lombok.Setter;
import net.octopvp.commander.Commander;
Expand Down Expand Up @@ -101,8 +100,7 @@ public void handleCommandException(CommandInfo info, CoreCommandSender sender, C
LocalizedCommandException lce = (LocalizedCommandException) e;
ResponseHandler handler = lce.getResponseHandler();
if (handler == null) {
Bukkit.getLogger().severe("Could not find a instance of ResponseHandler to handle command exception: " + e.getClass().getName());
return;
throw new NullPointerException("Could not find a instance of ResponseHandler to handle command exception: " + e.getClass().getName());
}
sender.sendMessage(ChatColor.RED + handler.getMessage(lce, lce.getPlaceholders()));
} else sender.sendMessage(ChatColor.RED + e.getMessage());
Expand Down Expand Up @@ -164,6 +162,6 @@ public Collection<Class<?>> getClassesInPackage(String packageName) {
dir.close();
}
}
return ImmutableSet.copyOf(classes);
return classes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,11 @@ private void executeInternally(CoreCommandSender sender, String label, String[]
try {
result = context.getCommandInfo().getMethod().invoke(context.getCommandInfo().getInstance(), arguments);
} catch (IllegalAccessException | IllegalArgumentException e) {
LocalizedCommandException.checkResponseHandlerNull(e, getResponseHandler());
e.printStackTrace();
} catch (InvocationTargetException e) {
if (e.getCause() != null && e.getCause() instanceof CommandException) {
LocalizedCommandException.checkResponseHandlerNull((Exception) e.getCause(), getResponseHandler());
platform.handleCommandException(context, (CommandException) e.getCause());
}
}
Expand All @@ -521,6 +523,7 @@ private void executeInternally(CoreCommandSender sender, String label, String[]
platform.handleCommandException(context, e);
} catch (Exception e) {
System.err.println("An error occurred while executing command \"" + label + "\"");
LocalizedCommandException.checkResponseHandlerNull(e, getResponseHandler());
e.printStackTrace();
}
} catch (CommandException e) {
Expand Down

0 comments on commit 2fc3314

Please sign in to comment.