Search in sources :

Example 61 with Listener

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();
        }
    });
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) User(me.lucko.luckperms.common.model.User) Listener(org.spongepowered.api.event.Listener) AbstractConnectionListener(me.lucko.luckperms.common.listener.AbstractConnectionListener)

Example 62 with Listener

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");
}
Also used : SimpleFacetMessage(com.ichorpowered.guardian.launch.message.SimpleFacetMessage) GuardianSequenceListener(com.ichorpowered.guardian.sequence.GuardianSequenceListener) GuardianListener(com.ichorpowered.guardianapi.event.GuardianListener) Listener(org.spongepowered.api.event.Listener)

Example 63 with Listener

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));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiStartupException(org.cubeengine.module.apiserver.exception.ApiStartupException) Listener(org.spongepowered.api.event.Listener)

Example 64 with Listener

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));
}
Also used : AfkCommand(org.cubeengine.module.chat.command.AfkCommand) ChatCommands(org.cubeengine.module.chat.command.ChatCommands) ChatFormatListener(org.cubeengine.module.chat.listener.ChatFormatListener) ModuleListener(org.cubeengine.libcube.service.event.ModuleListener) Listener(org.spongepowered.api.event.Listener)

Example 65 with Listener

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);
    }
}
Also used : HashMap(java.util.HashMap) Text(org.spongepowered.api.text.Text) ExecutionException(java.util.concurrent.ExecutionException) Subject(org.spongepowered.api.service.permission.Subject) Listener(org.spongepowered.api.event.Listener)

Aggregations

Listener (org.spongepowered.api.event.Listener)360 Player (org.spongepowered.api.entity.living.player.Player)118 World (org.spongepowered.api.world.World)97 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)65 Entity (org.spongepowered.api.entity.Entity)58 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)46 Text (org.spongepowered.api.text.Text)46 ItemStack (org.spongepowered.api.item.inventory.ItemStack)45 Location (org.spongepowered.api.world.Location)45 Sponge (org.spongepowered.api.Sponge)22 BlockType (org.spongepowered.api.block.BlockType)22 Task (org.spongepowered.api.scheduler.Task)17 IOException (java.io.IOException)16 Optional (java.util.Optional)16 Living (org.spongepowered.api.entity.living.Living)15 ItemType (org.spongepowered.api.item.ItemType)15 UUID (java.util.UUID)14 Monster (org.spongepowered.api.entity.living.monster.Monster)14 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)14 Map (java.util.Map)13