use of com.sk89q.worldedit.util.eventbus.Subscribe in project Prism-Bukkit by prism.
the class PrismBlockEditHandler method wrapForLogging.
/**
* Wrap and edit session so it can be logged.
*
* @param event EditSessionEvent
*/
@Subscribe
public void wrapForLogging(EditSessionEvent event) {
if (event.getStage().equals(EditSession.Stage.BEFORE_CHANGE)) {
Actor actor = event.getActor();
org.bukkit.World world = Bukkit.getWorld(event.getWorld().getName());
if (actor != null && actor.isPlayer() && world != null) {
event.setExtent(new PrismWorldEditLogger(actor, event.getExtent(), world));
}
}
}
use of com.sk89q.worldedit.util.eventbus.Subscribe in project CoreProtect by PlayPro.
the class CoreProtectEditSessionEvent method wrapForLogging.
@Subscribe
public void wrapForLogging(EditSessionEvent event) {
Actor actor = event.getActor();
World world = event.getWorld();
if (actor != null && event.getStage() == (isFAWE ? Stage.BEFORE_HISTORY : Stage.BEFORE_CHANGE)) {
event.setExtent(new CoreProtectLogger(actor, world, event.getExtent()));
}
}
use of com.sk89q.worldedit.util.eventbus.Subscribe in project FastAsyncWorldEdit by IntellectualSites.
the class SessionManager method onSessionIdle.
@Subscribe
public void onSessionIdle(final SessionIdleEvent event) {
SessionHolder holder = this.sessions.get(getKey(event.getKey()));
if (holder != null && !holder.sessionIdle) {
holder.sessionIdle = true;
LocalSession session = holder.session;
// Perform any session cleanup for data that should not be persisted.
session.onIdle();
}
}
use of com.sk89q.worldedit.util.eventbus.Subscribe in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformCommandManager method handleCommandSuggestion.
@Subscribe
public void handleCommandSuggestion(CommandSuggestionEvent event) {
try {
String rawArgs = event.getArguments();
// FAWE start
// Increase the resulting positions by 1 if we remove a leading `/`
final int posOffset = rawArgs.startsWith("/") ? 1 : 0;
String arguments = rawArgs.startsWith("/") ? rawArgs.substring(1) : rawArgs;
// FAWE end
List<Substring> split = parseArgs(arguments).collect(Collectors.toList());
List<String> argStrings = split.stream().map(Substring::getSubstring).collect(Collectors.toList());
// FAWE start - event & suggestion
MemoizingValueAccess access = initializeInjectedValues(() -> arguments, event.getActor(), event, true);
// FAWE end
ImmutableSet<Suggestion> suggestions;
try {
suggestions = commandManager.getSuggestions(access, argStrings);
} catch (Throwable t) {
// catch errors which are *not* command exceptions generated by parsers/suggesters
if (!(t instanceof InputParseException) && !(t instanceof CommandException)) {
Throwable cause = t;
// These exceptions can be very nested, and should not be printed as they are not an actual error.
boolean printError = true;
while ((cause = cause.getCause()) != null) {
if (cause instanceof InputParseException || cause instanceof CommandException) {
printError = false;
break;
}
}
if (printError) {
LOGGER.error("Unexpected error occurred while generating suggestions for input: {}", arguments, t);
return;
}
}
return;
}
event.setSuggestions(suggestions.stream().map(suggestion -> {
int noSlashLength = arguments.length();
Substring original = suggestion.getReplacedArgument() == split.size() ? Substring.from(arguments, noSlashLength, noSlashLength) : split.get(suggestion.getReplacedArgument());
return Substring.wrap(suggestion.getSuggestion(), original.getStart() + posOffset, original.getEnd() + posOffset);
}).collect(Collectors.toList()));
} catch (ConditionFailedException e) {
if (e.getCondition() instanceof PermissionCondition) {
event.setSuggestions(new ArrayList<>());
}
}
}
use of com.sk89q.worldedit.util.eventbus.Subscribe in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformManager method handlePlayerInput.
// FAWE end
@Subscribe
public void handlePlayerInput(PlayerInputEvent event) {
// Create a proxy actor with a potentially different world for
// making changes to the world
Player player = createProxyActor(event.getPlayer());
LocalSession session = worldEdit.getSessionManager().get(player);
try {
switch(event.getInputType()) {
case PRIMARY:
{
Tool tool = session.getTool(player);
if (tool instanceof DoubleActionTraceTool && tool.canUse(player)) {
// FAWE start - run async
player.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session));
// FAWE end
event.setCancelled(true);
return;
}
break;
}
case SECONDARY:
{
Tool tool = session.getTool(player);
if (tool instanceof TraceTool && tool.canUse(player)) {
// FAWE start - run async
// todo this needs to be fixed so the event is canceled after actPrimary is used and returns true
player.runAction(() -> reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session), false, true);
// FAWE end
event.setCancelled(true);
return;
}
break;
}
}
// FAWE start - add own message
} catch (Throwable e) {
FaweException faweException = FaweException.get(e);
if (faweException != null) {
player.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
} else {
player.print(Caption.of("worldedit.command.error.report"));
player.print(TextComponent.of(e.getClass().getName() + ": " + e.getMessage()));
e.printStackTrace();
}
// FAWE end
} finally {
Request.reset();
}
}
Aggregations