Search in sources :

Example 21 with Actor

use of com.sk89q.worldedit.extension.platform.Actor in project FastAsyncWorldEdit by IntellectualSites.

the class ConfirmHandler method beforeCall.

@Override
public void beforeCall(Method method, CommandParameters parameters) {
    Confirm confirmAnnotation = method.getAnnotation(Confirm.class);
    if (confirmAnnotation == null) {
        return;
    }
    Optional<Actor> actorOpt = parameters.injectedValue(Key.of(Actor.class));
    if (!actorOpt.isPresent()) {
        return;
    }
    Actor actor = actorOpt.get();
    // don't check confirmation if actor doesn't need to confirm
    if (!Settings.settings().getLimit(actor).CONFIRM_LARGE) {
        return;
    }
    if (!confirmAnnotation.value().passes(actor, parameters, 1)) {
        throw new StopExecutionException(TextComponent.empty());
    }
}
Also used : StopExecutionException(org.enginehub.piston.exception.StopExecutionException) Actor(com.sk89q.worldedit.extension.platform.Actor)

Example 22 with Actor

use of com.sk89q.worldedit.extension.platform.Actor in project FastAsyncWorldEdit by IntellectualSites.

the class PreloadHandler method beforeCall.

@Override
public void beforeCall(Method method, CommandParameters parameters) {
    Preload preloadAnnotation = method.getAnnotation(Preload.class);
    if (preloadAnnotation == null) {
        return;
    }
    Optional<Actor> actorOpt = parameters.injectedValue(Key.of(Actor.class));
    Optional<EditSession> editSessionOpt = parameters.injectedValue(Key.of(EditSession.class));
    if (actorOpt.isEmpty() || editSessionOpt.isEmpty()) {
        return;
    }
    Actor actor = actorOpt.get();
    // Don't attempt to preload if effectively disabled
    if (Settings.settings().QUEUE.PRELOAD_CHUNK_COUNT <= 1) {
        return;
    }
    preloadAnnotation.value().preload(actor, parameters);
}
Also used : Actor(com.sk89q.worldedit.extension.platform.Actor) EditSession(com.sk89q.worldedit.EditSession)

Example 23 with Actor

use of com.sk89q.worldedit.extension.platform.Actor in project RN-Parkour by xxBennny.

the class SelectionListener method onSelection.

// listen very early to be ahead of normal fawe
@Subscribe(priority = EventHandler.Priority.VERY_EARLY)
public void onSelection(EditSessionEvent event) {
    Actor actor = event.getActor();
    /*
           there are 3 stages, so only listen to before anything happens (avoid 3 event fires),
           make sure the player is the person executing and the world is the plot world
         */
    if (event.getStage().toString().equalsIgnoreCase("BEFORE_CHANGE") && actor != null && actor.isPlayer() && event.getWorld().getName().equalsIgnoreCase(Parkour.getSettingsManager().player_submitted_world)) {
        // get bukkit player from name
        Player player = Bukkit.getPlayer(actor.getName());
        // only continue if not opped
        if (player != null) {
            // if opped and bypassing plots, return
            if (player.isOp() && Parkour.getStatsManager().get(player).isBypassingPlots())
                return;
            // try catch for incomplete regions
            try {
                // get their session, the region from that selection, and the min/max points
                LocalSession session = WorldEdit.getInstance().getSessionManager().findByName(player.getName());
                Region region = session.getSelection(event.getWorld());
                if (checkSelection(region.getMinimumPoint(), region.getMaximumPoint(), player)) {
                    // use FAWE api to cancel and send message
                    event.setCancelled(true);
                    // send bypass info if opped
                    String messageToSend = "&cThis WorldEdit selection is out of where you can build";
                    if (player.isOp())
                        messageToSend += " &7You can bypass this with &c/plot bypass";
                    player.sendMessage(Utils.translate(messageToSend));
                }
            } catch (IncompleteRegionException e) {
            // dont print stack track so we dont spam console with simple error
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Actor(com.sk89q.worldedit.extension.platform.Actor) Region(com.sk89q.worldedit.regions.Region) Subscribe(com.sk89q.worldedit.util.eventbus.Subscribe)

Example 24 with Actor

use of com.sk89q.worldedit.extension.platform.Actor in project WorldGuard by EngineHub.

the class BukkitStringMatcher method matchPlayers.

@Override
public Iterable<? extends LocalPlayer> matchPlayers(Actor source, String filter) throws CommandException {
    if (Bukkit.getServer().getOnlinePlayers().isEmpty()) {
        throw new CommandException("No players matched query.");
    }
    List<LocalPlayer> wgPlayers = Bukkit.getServer().getOnlinePlayers().stream().map(player -> WorldGuardPlugin.inst().wrapPlayer(player)).collect(Collectors.toList());
    if (filter.equals("*")) {
        return checkPlayerMatch(wgPlayers);
    }
    // Handle special hash tag groups
    if (filter.charAt(0) == '#') {
        // calling source
        if (filter.equalsIgnoreCase("#world")) {
            List<LocalPlayer> players = new ArrayList<>();
            LocalPlayer sourcePlayer = WorldGuard.getInstance().checkPlayer(source);
            World sourceWorld = sourcePlayer.getWorld();
            for (LocalPlayer player : wgPlayers) {
                if (player.getWorld().equals(sourceWorld)) {
                    players.add(player);
                }
            }
            return checkPlayerMatch(players);
        // Handle #near, which is for nearby players.
        } else if (filter.equalsIgnoreCase("#near")) {
            List<LocalPlayer> players = new ArrayList<>();
            LocalPlayer sourcePlayer = WorldGuard.getInstance().checkPlayer(source);
            World sourceWorld = sourcePlayer.getWorld();
            Vector3 sourceVector = sourcePlayer.getLocation().toVector();
            for (LocalPlayer player : wgPlayers) {
                if (player.getWorld().equals(sourceWorld) && player.getLocation().toVector().distanceSq(sourceVector) < 900) {
                    players.add(player);
                }
            }
            return checkPlayerMatch(players);
        } else {
            throw new CommandException("Invalid group '" + filter + "'.");
        }
    }
    List<LocalPlayer> players = matchPlayerNames(filter);
    return checkPlayerMatch(players);
}
Also used : StringMatcher(com.sk89q.worldguard.internal.platform.StringMatcher) Collection(java.util.Collection) World(com.sk89q.worldedit.world.World) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CommandException(com.sk89q.minecraft.util.commands.CommandException) Actor(com.sk89q.worldedit.extension.platform.Actor) List(java.util.List) BukkitAdapter(com.sk89q.worldedit.bukkit.BukkitAdapter) Capability(com.sk89q.worldedit.extension.platform.Capability) Vector3(com.sk89q.worldedit.math.Vector3) WorldGuard(com.sk89q.worldguard.WorldGuard) WorldEdit(com.sk89q.worldedit.WorldEdit) Bukkit(org.bukkit.Bukkit) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Vector3(com.sk89q.worldedit.math.Vector3) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World)

Example 25 with Actor

use of com.sk89q.worldedit.extension.platform.Actor in project WorldGuard by EngineHub.

the class WorldGuardCommands method profile.

@Command(aliases = { "profile" }, usage = "[-p] [-i <interval>] [-t <thread filter>] [<minutes>]", desc = "Profile the CPU usage of the server", min = 0, max = 1, flags = "t:i:p")
@CommandPermissions("worldguard.profile")
public void profile(final CommandContext args, final Actor sender) throws CommandException, AuthorizationException {
    Predicate<ThreadInfo> threadFilter;
    String threadName = args.getFlag('t');
    final boolean pastebin;
    if (args.hasFlag('p')) {
        sender.checkPermission("worldguard.report.pastebin");
        pastebin = true;
    } else {
        pastebin = false;
    }
    if (threadName == null) {
        threadFilter = new ThreadIdFilter(Thread.currentThread().getId());
    } else if (threadName.equals("*")) {
        threadFilter = thread -> true;
    } else {
        threadFilter = new ThreadNameFilter(threadName);
    }
    int minutes;
    if (args.argsLength() == 0) {
        minutes = 5;
    } else {
        minutes = args.getInteger(0);
        if (minutes < 1) {
            throw new CommandException("You must run the profile for at least 1 minute.");
        } else if (minutes > 10) {
            throw new CommandException("You can profile for, at maximum, 10 minutes.");
        }
    }
    int interval = 20;
    if (args.hasFlag('i')) {
        interval = args.getFlagInteger('i');
        if (interval < 1 || interval > 100) {
            throw new CommandException("Interval must be between 1 and 100 (in milliseconds)");
        }
        if (interval < 10) {
            sender.printDebug("Note: A low interval may cause additional slowdown during profiling.");
        }
    }
    Sampler sampler;
    synchronized (this) {
        if (activeSampler != null) {
            throw new CommandException("A profile is currently in progress! Please use /wg stopprofile to cancel the current profile.");
        }
        SamplerBuilder builder = new SamplerBuilder();
        builder.setThreadFilter(threadFilter);
        builder.setRunTime(minutes, TimeUnit.MINUTES);
        builder.setInterval(interval);
        sampler = activeSampler = builder.start();
    }
    sender.print(TextComponent.of("Starting CPU profiling. Results will be available in " + minutes + " minutes.", TextColor.LIGHT_PURPLE).append(TextComponent.newline()).append(TextComponent.of("Use ", TextColor.GRAY)).append(TextComponent.of("/wg stopprofile", TextColor.AQUA).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/wg stopprofile"))).append(TextComponent.of(" at any time to cancel CPU profiling.", TextColor.GRAY)));
    worldGuard.getSupervisor().monitor(FutureForwardingTask.create(sampler.getFuture(), "CPU profiling for " + minutes + " minutes", sender));
    sampler.getFuture().addListener(() -> {
        synchronized (WorldGuardCommands.this) {
            activeSampler = null;
        }
    }, MoreExecutors.directExecutor());
    Futures.addCallback(sampler.getFuture(), new FutureCallback<>() {

        @Override
        public void onSuccess(Sampler result) {
            String output = result.toString();
            try {
                File dest = new File(worldGuard.getPlatform().getConfigDir().toFile(), "profile.txt");
                Files.write(output, dest, StandardCharsets.UTF_8);
                sender.print("CPU profiling data written to " + dest.getAbsolutePath());
            } catch (IOException e) {
                sender.printError("Failed to write CPU profiling data: " + e.getMessage());
            }
            if (pastebin) {
                ActorCallbackPaste.pastebin(worldGuard.getSupervisor(), sender, output, "Profile result: %s.profile");
            }
        }

        @Override
        public void onFailure(Throwable throwable) {
        }
    }, MoreExecutors.directExecutor());
}
Also used : Sampler(com.sk89q.worldguard.util.profiler.SamplerBuilder.Sampler) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions) FutureForwardingTask(com.sk89q.worldedit.util.task.FutureForwardingTask) SystemInfoReport(com.sk89q.worldedit.util.report.SystemInfoReport) World(com.sk89q.worldedit.world.World) ActorCallbackPaste(com.sk89q.worldedit.util.paste.ActorCallbackPaste) SamplerBuilder(com.sk89q.worldguard.util.profiler.SamplerBuilder) Level(java.util.logging.Level) CommandException(com.sk89q.minecraft.util.commands.CommandException) Task(com.sk89q.worldedit.util.task.Task) ApplicableRegionsReport(com.sk89q.worldguard.util.report.ApplicableRegionsReport) ThreadInfo(java.lang.management.ThreadInfo) AuthorizationException(com.sk89q.worldedit.util.auth.AuthorizationException) Files(com.google.common.io.Files) TextColor(com.sk89q.worldedit.util.formatting.text.format.TextColor) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) WorldGuard(com.sk89q.worldguard.WorldGuard) NestedCommand(com.sk89q.minecraft.util.commands.NestedCommand) ConfigReport(com.sk89q.worldguard.util.report.ConfigReport) WorldEdit(com.sk89q.worldedit.WorldEdit) ReportList(com.sk89q.worldedit.util.report.ReportList) Nullable(javax.annotation.Nullable) TaskStateComparator(com.sk89q.worldedit.util.task.TaskStateComparator) ThreadNameFilter(com.sk89q.worldguard.util.profiler.ThreadNameFilter) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Predicate(java.util.function.Predicate) LoggerToChatHandler(com.sk89q.worldguard.util.logging.LoggerToChatHandler) ThreadIdFilter(com.sk89q.worldguard.util.profiler.ThreadIdFilter) LocalPlayer(com.sk89q.worldguard.LocalPlayer) IOException(java.io.IOException) MessageBox(com.sk89q.worldedit.util.formatting.component.MessageBox) Logger(java.util.logging.Logger) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Actor(com.sk89q.worldedit.extension.platform.Actor) TimeUnit(java.util.concurrent.TimeUnit) TextComponentProducer(com.sk89q.worldedit.util.formatting.component.TextComponentProducer) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Capability(com.sk89q.worldedit.extension.platform.Capability) CommandContext(com.sk89q.minecraft.util.commands.CommandContext) Command(com.sk89q.minecraft.util.commands.Command) ThreadNameFilter(com.sk89q.worldguard.util.profiler.ThreadNameFilter) ThreadIdFilter(com.sk89q.worldguard.util.profiler.ThreadIdFilter) CommandException(com.sk89q.minecraft.util.commands.CommandException) IOException(java.io.IOException) SamplerBuilder(com.sk89q.worldguard.util.profiler.SamplerBuilder) ThreadInfo(java.lang.management.ThreadInfo) Sampler(com.sk89q.worldguard.util.profiler.SamplerBuilder.Sampler) File(java.io.File) NestedCommand(com.sk89q.minecraft.util.commands.NestedCommand) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Aggregations

Actor (com.sk89q.worldedit.extension.platform.Actor)25 World (com.sk89q.worldedit.world.World)10 List (java.util.List)8 Player (com.sk89q.worldedit.entity.Player)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 Subscribe (com.sk89q.worldedit.util.eventbus.Subscribe)6 ArrayList (java.util.ArrayList)6 WorldEdit (com.sk89q.worldedit.WorldEdit)5 Location (com.sk89q.worldedit.util.Location)5 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)5 Collectors (java.util.stream.Collectors)5 Caption (com.fastasyncworldedit.core.configuration.Caption)4 LocalSession (com.sk89q.worldedit.LocalSession)4 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)4 Capability (com.sk89q.worldedit.extension.platform.Capability)4 Locatable (com.sk89q.worldedit.extension.platform.Locatable)4 Mask (com.sk89q.worldedit.function.mask.Mask)4 ResettableExtent (com.fastasyncworldedit.core.extent.ResettableExtent)3 NoMatchException (com.sk89q.worldedit.extension.input.NoMatchException)3 Region (com.sk89q.worldedit.regions.Region)3