Search in sources :

Example 1 with SessionKey

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;
        }
    };
}
Also used : SessionKey(com.sk89q.worldedit.session.SessionKey) Block(org.bukkit.block.Block) Material(org.bukkit.Material)

Example 2 with SessionKey

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());
}
Also used : Command(org.enginehub.piston.Command) PermissionCondition(com.sk89q.worldedit.command.util.PermissionCondition) SubCommandPermissionCondition(com.sk89q.worldedit.command.util.SubCommandPermissionCondition) SessionKey(com.sk89q.worldedit.session.SessionKey) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Aggregations

SessionKey (com.sk89q.worldedit.session.SessionKey)2 PermissionCondition (com.sk89q.worldedit.command.util.PermissionCondition)1 SubCommandPermissionCondition (com.sk89q.worldedit.command.util.SubCommandPermissionCondition)1 Subscribe (com.sk89q.worldedit.util.eventbus.Subscribe)1 Material (org.bukkit.Material)1 Block (org.bukkit.block.Block)1 Command (org.enginehub.piston.Command)1