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());
}
}
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);
}
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
}
}
}
}
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);
}
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());
}
Aggregations