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