Skip to content

Commit

Permalink
fix: catches exceptions from external commands
Browse files Browse the repository at this point in the history
  • Loading branch information
RoinujNosde committed Apr 19, 2024
1 parent f590fcc commit 77ea34c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/me/roinujnosde/titansbattle/BaseGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.roinujnosde.titansbattle.events.*;
import me.roinujnosde.titansbattle.exceptions.CommandNotSupportedException;
import me.roinujnosde.titansbattle.hooks.papi.PlaceholderHook;
import me.roinujnosde.titansbattle.managers.CommandManager;
import me.roinujnosde.titansbattle.managers.GameManager;
import me.roinujnosde.titansbattle.managers.GroupManager;
import me.roinujnosde.titansbattle.types.Group;
Expand Down Expand Up @@ -523,10 +524,10 @@ protected void runCommands(@NotNull Collection<Warrior> warriors, @Nullable Coll
continue;
}
if (!command.contains("%player%")) { // Runs the command once when %player% is not used
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), hook.parse((OfflinePlayer) null, command));
CommandManager.dispatchCommand(Bukkit.getConsoleSender(), hook.parse((OfflinePlayer) null, command));
break;
}
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), hook.parse(warrior, command,
CommandManager.dispatchCommand(Bukkit.getConsoleSender(), hook.parse(warrior, command,
"%player%", warrior.getName()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
import me.roinujnosde.titansbattle.commands.conditions.*;
import me.roinujnosde.titansbattle.commands.contexts.*;
import me.roinujnosde.titansbattle.dao.ConfigurationDao;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;

import java.util.Locale;
import java.util.Set;
import java.util.logging.Level;

public class CommandManager extends PaperCommandManager {

Expand All @@ -36,6 +40,14 @@ public TitansBattle getPlugin() {
return (TitansBattle) plugin;
}

public static void dispatchCommand(@NotNull CommandSender sender, @NotNull String commandLine) {
try {
Bukkit.dispatchCommand(sender, commandLine);
} catch (Exception exception) {
TitansBattle.getInstance().getLogger().log(Level.SEVERE, String.format("Error executing command: %s", commandLine), exception);
}
}

private void setDefaultLocale() {
BukkitLocales locales = getLocales();
Locale defaultLocale = new Locale(getPlugin().getConfigManager().getLanguage().split("_")[0]);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/me/roinujnosde/titansbattle/types/Prizes.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.roinujnosde.titansbattle.types;

import me.roinujnosde.titansbattle.TitansBattle;
import me.roinujnosde.titansbattle.managers.CommandManager;
import me.roinujnosde.titansbattle.serialization.ConfigUtils;
import me.roinujnosde.titansbattle.serialization.Path;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -109,7 +110,7 @@ private void runCommandsOnPlayers(TitansBattle plugin, List<Player> players, Lis
for (String command : commands) {
command = plugin.getPlaceholderHook().parse(player, command,
"%player%", player.getName(), "%some_number%", Double.toString(someNumber));
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
CommandManager.dispatchCommand(Bukkit.getConsoleSender(), command);
}
}
}
Expand Down

0 comments on commit 77ea34c

Please sign in to comment.