Skip to content

Commit

Permalink
fix bukkit error message NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Badbird5907 committed Jun 20, 2022
1 parent 85adf6b commit b8696d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
public class BukkitCommander {
public static BukkitHelpService HELP_SERVICE = BukkitHelpService.INSTANCE;
public static Commander getCommander(Plugin plugin) {
Commander impl = new CommanderImpl(new BukkitPlatform(plugin))
BukkitPlatform platform = new BukkitPlatform(plugin);
Commander impl = new CommanderImpl(platform)
.init()
.registerProvider(Player.class, new PlayerProvider())
.registerProvider(OfflinePlayer.class, new OfflinePlayerProvider())
Expand All @@ -48,6 +49,7 @@ public static Commander getCommander(Plugin plugin) {
}
}
});
platform.setCommander(impl);
impl.getResponseHandler().addBundle(ResourceBundle.getBundle("bukkit", impl.getResponseHandler().getLocale()));
return impl;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package net.octopvp.commander.bukkit;

import com.google.common.collect.ImmutableSet;
import lombok.Getter;
import lombok.Setter;
import net.octopvp.commander.Commander;
import net.octopvp.commander.annotation.Sender;
import net.octopvp.commander.bukkit.impl.BukkitCommandSenderImpl;
import net.octopvp.commander.bukkit.impl.BukkitCommandWrapper;
Expand All @@ -10,8 +13,10 @@
import net.octopvp.commander.exception.CommandException;
import net.octopvp.commander.help.HelpService;
import net.octopvp.commander.lang.LocalizedCommandException;
import net.octopvp.commander.lang.ResponseHandler;
import net.octopvp.commander.platform.CommanderPlatform;
import net.octopvp.commander.sender.CoreCommandSender;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
Expand All @@ -27,8 +32,11 @@
import java.util.HashSet;
import java.util.Set;

@Getter
@Setter
public class BukkitPlatform implements CommanderPlatform {
private final Plugin plugin;
private Commander commander;
private CommandMap commandMap;

public BukkitPlatform(Plugin plugin) {
Expand Down Expand Up @@ -65,7 +73,13 @@ public void handleCommandException(CommandContext ctx, CommandException e) {
@Override
public void handleCommandException(CommandInfo info, CoreCommandSender sender, CommandException e) {
if (e instanceof LocalizedCommandException) {
sender.sendMessage(ChatColor.RED + info.getCommander().getResponseHandler().getMessage(e));
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;
}
sender.sendMessage(ChatColor.RED + handler.getMessage(lce, lce.getPlaceholders()));
}
sender.sendMessage(ChatColor.RED + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import lombok.Setter;
import net.octopvp.commander.exception.CommandException;

import java.util.Arrays;

@Getter
@Setter
public class LocalizedCommandException extends CommandException {
Expand Down Expand Up @@ -36,7 +34,6 @@ public static void checkResponseHandlerNull(Exception e, ResponseHandler respons

@Override
public String getLocalizedMessage() {
System.out.println("Placeholders: " + Arrays.toString(this.placeholders));
if (responseHandler != null) {
return responseHandler.getMessage(this, placeholders);
}
Expand Down

0 comments on commit b8696d4

Please sign in to comment.