use of org.spongepowered.api.event.Listener in project LuckPerms by lucko.
the class SpongeConnectionListener method onClientLeave.
@Listener(order = Order.POST)
public void onClientLeave(ClientConnectionEvent.Disconnect e) {
Player player = e.getTargetEntity();
// Register with the housekeeper, so the User's instance will stick
// around for a bit after they disconnect
this.plugin.getUserManager().getHouseKeeper().registerUsage(player.getUniqueId());
// force a clear of transient nodes
this.plugin.getBootstrap().getScheduler().doAsync(() -> {
User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
if (user != null) {
user.clearTransientNodes();
}
});
}
use of org.spongepowered.api.event.Listener in project guardian by ichorpowered.
the class GuardianPlugin method onGameReload.
// PLUGIN RELOAD
@Listener
public void onGameReload(GameReloadEvent event) {
this.facetBootstrap.send(FacetBootstrap.FacetRequest.RESTART, new SimpleFacetMessage(System.currentTimeMillis(), "Game Reload", this), "game");
this.facetBootstrap.send(FacetBootstrap.FacetRequest.RESTART, new SimpleFacetMessage(System.currentTimeMillis(), "Game Reload", this), "common");
}
use of org.spongepowered.api.event.Listener in project modules-extra by CubeEngine.
the class ApiServer method onEnable.
@Listener
public void onEnable(GamePostInitializationEvent event) {
reflector.getDefaultConverterManager().registerConverter(new InetAddressConverter(), InetAddress.class);
this.configure(reflector.load(ApiConfig.class, moduleFolder.resolve("webapi.yml").toFile()));
try {
this.start();
final ObjectMapper mapper = new ObjectMapper();
LoggerUtil.attachCallback(null, (f, a, t, msg) -> {
ObjectNode node = mapper.createObjectNode();
node.put("msg", msg);
this.fireEvent("console", node);
});
} catch (ApiStartupException ex) {
this.logger.error(ex, "The web API will not be available as the server failed to start properly...");
}
this.registerApiHandlers(ApiServer.class, new CommandController(i18n, tm, cm));
}
use of org.spongepowered.api.event.Listener in project modules-extra by CubeEngine.
the class Chat method onEnable.
@Listener
public void onEnable(GamePreInitializationEvent event) {
AfkCommand afkCmd = new AfkCommand(this, config.autoAfk.after.toMillis(), config.autoAfk.check.toMillis(), bc, tm, em);
cm.addCommands(this, afkCmd);
cm.addCommands(this, new ChatCommands(this, i18n, bc, afkCmd));
}
use of org.spongepowered.api.event.Listener in project modules-extra by CubeEngine.
the class ChatFormatListener method onPlayerChat.
@Listener(order = Order.EARLY)
public void onPlayerChat(MessageChannelEvent.Chat event, @Root Player player) {
// TODO format on the messagechannel instead
String msg = event.getRawMessage().toPlain();
if (!msg.equals("+") && msg.endsWith("+") && player.hasPermission(module.perms().LONGER.getId())) {
msg = accumulated.getOrDefault(player.getUniqueId(), "") + msg.substring(0, msg.length() - 1);
msg = msg.substring(0, Math.min(msg.length(), 50 * 20));
module.getI18n().send(ChatTypes.ACTION_BAR, player, NEUTRAL, "{amount} characters in buffer.", msg.length());
accumulated.put(player.getUniqueId(), msg);
event.setCancelled(true);
return;
}
msg = accumulated.getOrDefault(player.getUniqueId(), "") + msg;
accumulated.remove(player.getUniqueId());
msg = msg.substring(0, Math.min(msg.length(), 50 * 20));
if (module.getConfig().allowColors) {
if (!player.hasPermission(module.perms().COLOR.getId())) {
msg = chatColors.matcher(msg).replaceAll("");
}
}
if (player.hasPermission(module.perms().NEWLINE.getId())) {
msg = msg.replace("\\n", "\n");
}
try {
Subject subject = module.getPermissionService().getUserSubjects().loadSubject(player.getUniqueId().toString()).get();
Map<String, Text> replacements = new HashMap<>();
String name = player.getName();
replacements.put("{NAME}", Text.of(name));
Text displayName = player.get(DisplayNameData.class).isPresent() ? player.getDisplayNameData().displayName().get() : Text.of(name);
if (!displayName.toPlain().equals(name)) {
displayName = Text.builder().append(displayName).onHover(TextActions.showText(Text.of(DARK_GREEN, name))).build();
}
replacements.put("{DISPLAY_NAME}", displayName);
replacements.put("{WORLD}", Text.of(player.getWorld().getName()));
replacements.put("{MESSAGE}", fromLegacy(msg, '&'));
replacements.put("{PREFIX}", Text.of());
replacements.put("{SUFFIX}", Text.of());
replacements.put("{PREFIX}", fromLegacy(subject.getOption("chat-prefix").orElse(""), '&'));
replacements.put("{SUFFIX}", fromLegacy(subject.getOption("chat-suffix").orElse(""), '&'));
event.setMessage(fromLegacy(this.getFormat(subject), replacements, '&'));
} catch (ExecutionException | InterruptedException e) {
throw new IllegalStateException(e);
}
}
Aggregations