Use one PermissibleBase for all command blocks
Inspired by Spigot commit 4bd27f7d0f8dcffab0062741416a612ea258dc68 by FrozenBrain.
This commit is contained in:
parent
5876cca442
commit
f90ce621ef
@ -7,16 +7,32 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.permissions.PermissibleBase;
|
||||
import org.bukkit.permissions.ServerOperator;
|
||||
|
||||
/**
|
||||
* Represents input from a command block
|
||||
*/
|
||||
public class CraftBlockCommandSender extends ServerCommandSender implements BlockCommandSender {
|
||||
|
||||
// For performance reasons, use one PermissibleBase for all command blocks.
|
||||
private static final PermissibleBase SHARED_PERM = new PermissibleBase(new ServerOperator() {
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
throw new UnsupportedOperationException("Cannot change operator status of a block");
|
||||
}
|
||||
});
|
||||
private final CommandListenerWrapper block;
|
||||
private final TileEntity tile;
|
||||
|
||||
public CraftBlockCommandSender(CommandListenerWrapper commandBlockListenerAbstract, TileEntity tile) {
|
||||
super();
|
||||
super(SHARED_PERM);
|
||||
this.block = commandBlockListenerAbstract;
|
||||
this.tile = tile;
|
||||
}
|
||||
@ -47,12 +63,12 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return true;
|
||||
return SHARED_PERM.isOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
throw new UnsupportedOperationException("Cannot change operator status of a block");
|
||||
SHARED_PERM.setOp(value);
|
||||
}
|
||||
|
||||
public CommandListenerWrapper getWrapper() {
|
||||
|
@ -12,9 +12,14 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class ServerCommandSender implements CommandSender {
|
||||
private final PermissibleBase perm = new PermissibleBase(this);
|
||||
private final PermissibleBase perm;
|
||||
|
||||
public ServerCommandSender() {
|
||||
protected ServerCommandSender() {
|
||||
this.perm = new PermissibleBase(this);
|
||||
}
|
||||
|
||||
protected ServerCommandSender(PermissibleBase perm) {
|
||||
this.perm = perm;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user