fix: 修复指令执行时可能导致的权限问题

This commit is contained in:
2024-01-21 22:35:16 +08:00
parent 63f5af4d19
commit 35c7bf2161

View File

@@ -14,7 +14,6 @@ import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandException;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
@@ -391,30 +390,29 @@ public final class CoreBukkitUtils {
command = PlaceholderAPI.setPlaceholders(player, command);
}
String[] split = command.split(":", 2);
try {
switch (split[0]) {
case "player": {
Bukkit.dispatchCommand(player, split[1]);
break;
}
case "console": {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), split[1]);
break;
}
case "op": {
boolean op = player.isOp();
player.setOp(true);
Bukkit.dispatchCommand(player, split[1]);
player.setOp(op);
break;
}
default: {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
break;
}
switch (split[0]) {
case "player": {
Bukkit.dispatchCommand(player, split[1]);
break;
}
case "console": {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), split[1]);
break;
}
case "op": {
boolean op = player.isOp();
player.setOp(true);
try {
Bukkit.dispatchCommand(player, split[1]);
} finally {
player.setOp(op);
}
break;
}
default: {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
break;
}
} catch (CommandException e) {
e.printStackTrace();
}
}