9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 04:19:27 +00:00

添加以op身份执行

This commit is contained in:
XiaoMoMi
2025-08-25 16:05:51 +08:00
parent 1469f87690
commit 0049b1c421
5 changed files with 24 additions and 11 deletions

View File

@@ -34,7 +34,6 @@ import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.util.concurrent.Callable;
import java.util.function.BiConsumer;
import java.util.function.Function;
public final class BlockGenerator {

View File

@@ -956,8 +956,20 @@ public class BukkitServerPlayer extends Player {
}
@Override
public void performCommand(String command) {
platformPlayer().performCommand(command);
public void performCommand(String command, boolean asOp) {
org.bukkit.entity.Player player = platformPlayer();
if (asOp) {
boolean isOp = player.isOp();
player.setOp(true);
try {
player.performCommand(command);
} catch (Throwable t) {
this.plugin.logger().warn("Failed to perform command '" + command + "' for " + this.name() + " as operator", t);
}
player.setOp(isOp);
} else {
player.performCommand(command);
}
}
@Override

View File

@@ -18,9 +18,7 @@ import net.momirealms.craftengine.core.world.ExistingBlock;
import net.momirealms.craftengine.core.world.World;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;