use of com.sk89q.worldedit.util.eventbus.Subscribe 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());
}
use of com.sk89q.worldedit.util.eventbus.Subscribe in project RN-Parkour by xxBennny.
the class SelectionListener method onPaste.
@Subscribe(priority = EventHandler.Priority.VERY_EARLY)
public void onPaste(PasteEvent event) {
com.sk89q.worldedit.entity.Player wePlayer = event.getPlayer();
Player player = Bukkit.getPlayer(wePlayer.getName());
if (player != null && player.getWorld().getName().equalsIgnoreCase(Parkour.getSettingsManager().player_submitted_world)) {
// if opped and bypassing plots, return
if (player.isOp() && Parkour.getStatsManager().get(player).isBypassingPlots())
return;
try {
// get session and clipboard holder of session
LocalSession session = WorldEdit.getInstance().getSessionManager().findByName(player.getName());
ClipboardHolder holder = session.getClipboard();
/*
this is a complicated part because the location of
the min/max of the new paste is not stored, so we have to do hacky math
how it is done
1) first we get the offset of the clipboard by subtracting the minimum point of the current clipboard
by the origin
2) we then apply that offset to the holder's transform (rotation, position etc) and add that
to the position (gives us the new max)
3) finally, we apply the max clipboard point subtracted by the min and then apply that to the transform,
and add that to the max point, giving us the min
*/
Vector clipboardOffset = event.getClipboard().getMinimumPoint().subtract(event.getClipboard().getOrigin());
Vector max = event.getPosition().add(holder.getTransform().apply(clipboardOffset));
Vector min = max.add(holder.getTransform().apply(event.getClipboard().getMaximumPoint().subtract(event.getClipboard().getMinimumPoint())));
if (checkSelection(min, max, player)) {
event.setCancelled(true);
// send bypass info if opped
String messageToSend = "&cYour paste 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 (EmptyClipboardException e) {
// dont print stack track so we dont spam console with simple error
}
}
}
use of com.sk89q.worldedit.util.eventbus.Subscribe 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.util.eventbus.Subscribe in project buildinggame by stefvanschie.
the class WorldEditBoundaryAssertion method onEditSession.
/**
* Cancels any edits being made for blocks outside the plot the actor is (possibly) on.
*
* @param event the event fired when a session is being edited
* @since 5.8.0
*/
@Subscribe
public void onEditSession(EditSessionEvent event) {
if (event.getActor() == null || !event.getActor().isPlayer())
return;
var player = Bukkit.getPlayer(event.getActor().getUniqueId());
var arena = ArenaManager.getInstance().getArena(player);
// don't do anything if the player isn't in an arena
if (arena == null)
return;
event.setExtent(new AbstractDelegateExtent(event.getExtent()) {
@Override
public boolean setBlock(BlockVector3 vector, BlockStateHolder block) throws WorldEditException {
var world = Bukkit.getWorld(event.getWorld().getName());
var loc = new Location(world, vector.getX(), vector.getY(), vector.getZ());
if (!arena.getPlot(player).getBoundary().isInside(loc)) {
return false;
}
return super.setBlock(vector, block);
}
});
}
Aggregations