use of com.sk89q.worldedit.session.SessionKey in project FastAsyncWorldEdit by IntellectualSites.
the class BukkitBlockCommandSender method getSessionKey.
@Override
public SessionKey getSessionKey() {
return new SessionKey() {
private volatile boolean active = true;
private void updateActive() {
Block block = sender.getBlock();
if (!block.getWorld().isChunkLoaded(block.getX() >> 4, block.getZ() >> 4)) {
active = false;
return;
}
Material type = block.getType();
active = type == Material.COMMAND_BLOCK || type == Material.CHAIN_COMMAND_BLOCK || type == Material.REPEATING_COMMAND_BLOCK;
}
@Override
public String getName() {
return sender.getName();
}
@Override
public boolean isActive() {
if (Bukkit.isPrimaryThread()) {
// we can update eagerly
updateActive();
} else {
// we should update it eventually
Bukkit.getScheduler().callSyncMethod(plugin, () -> {
updateActive();
return null;
});
}
return active;
}
@Override
public boolean isPersistent() {
return true;
}
@Override
public UUID getUniqueId() {
return uuid;
}
};
}
use of com.sk89q.worldedit.session.SessionKey in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformCommandManager method handleCommand.
@Subscribe
public void handleCommand(CommandEvent event) {
Request.reset();
Actor actor = event.getActor();
String args = event.getArguments();
TaskManager.taskManager().taskNow(() -> {
if (!Fawe.isMainThread()) {
Thread.currentThread().setName("FAWE Thread for player: " + actor.getName());
}
int space0 = args.indexOf(' ');
String arg0 = space0 == -1 ? args : args.substring(0, space0);
Optional<Command> optional = commandManager.getCommand(arg0);
if (!optional.isPresent()) {
return;
}
Command cmd = optional.get();
PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null);
if (queued != null && !queued.isQueued()) {
handleCommandOnCurrentThread(event);
return;
} else {
actor.decline();
}
actor.runAction(() -> {
SessionKey key = actor.getSessionKey();
if (key.isActive()) {
PlatformCommandManager.this.handleCommandOnCurrentThread(event);
}
}, false, true);
}, Fawe.isMainThread());
}
Aggregations