org.spongepowered.api.event.filter.IsCancelled Java Examples

The following examples show how to use org.spongepowered.api.event.filter.IsCancelled. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FactionKickListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(value = Tristate.FALSE)
public void onPlayerFactionKick(final FactionKickEvent event)
{
    final Faction faction = event.getFaction();
    final FactionPlayer kickedPlayer = event.getKickedPlayer();

    final List<Player> onlineFactionPlayers = super.getPlugin().getFactionLogic().getOnlinePlayers(faction);
    for(final Player player : onlineFactionPlayers)
    {
        if (player.equals(event.getCreator()))
            continue;

        if(player.getName().equals(kickedPlayer.getName()))
            continue;

        player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, "Player " + kickedPlayer.getName() + " has been kicked from the faction."));
    }
}
 
Example #2
Source File: SpongeConnectionListener.java    From LuckPerms with MIT License 6 votes vote down vote up
@Listener(order = Order.LAST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientAuthMonitor(ClientConnectionEvent.Auth e) {
    /* Listen to see if the event was cancelled after we initially handled the connection
       If the connection was cancelled here, we need to do something to clean up the data that was loaded. */

    // Check to see if this connection was denied at LOW.
    if (this.deniedAsyncLogin.remove(e.getProfile().getUniqueId())) {

        // This is a problem, as they were denied at low priority, but are now being allowed.
        if (e.isCancelled()) {
            this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId());
            e.setCancelled(true);
        }
    }
}
 
Example #3
Source File: FactionJoinListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(value = Tristate.FALSE)
public void onFactionJoin(final FactionJoinEvent event, @Root final Player player)
{
	//Notify other faction members about someone joining the faction.
	final Faction faction = event.getFaction();
	final List<Player> factionPlayers = super.getPlugin().getFactionLogic().getOnlinePlayers(faction);
	for (final Player factionPlayer : factionPlayers)
	{
		if (factionPlayer.getName().equals(player.getName()))
			continue;
		factionPlayer.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, player.getName(), TextColors.AQUA, " joined your faction."));
	}
}
 
Example #4
Source File: FactionLeaveListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(value = Tristate.FALSE)
public void onFactionLeave(final FactionLeaveEvent event, @Root final Player player)
{
    //Notify other faction members about someone leaving the faction
    final Faction faction = event.getFaction();
    final List<Player> factionPlayers = super.getPlugin().getFactionLogic().getOnlinePlayers(faction);
    for (final Player factionPlayer : factionPlayers)
    {
        if (factionPlayer.getName().equals(player.getName()))
            continue;
        factionPlayer.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, player.getName(), TextColors.AQUA, " left your faction."));
    }
}
 
Example #5
Source File: ChatUILib.java    From ChatUI with MIT License 5 votes vote down vote up
@Listener(order = Order.PRE, beforeModifications = true)
@IsCancelled(Tristate.UNDEFINED)
public void onIncomingMessage(MessageChannelEvent.Chat event, @Root Player player) {
    if (getView(player).handleIncoming(event.getRawMessage())) {
        // No plugins should interpret this as chat
        event.setCancelled(true);
        event.setChannel(MessageChannel.TO_NONE);
    }
}
 
Example #6
Source File: SpongeConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientLogin(ClientConnectionEvent.Login e) {
    /* Called when the player starts logging into the server.
       At this point, the users data should be present and loaded.
       Listening on LOW priority to allow plugins to further modify data here. (auth plugins, etc.) */

    final GameProfile profile = e.getProfile();

    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing login event for " + profile.getUniqueId() + " - " + profile.getName());
    }

    final User user = this.plugin.getUserManager().getIfLoaded(profile.getUniqueId());

    /* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
    if (user == null) {
        this.deniedLogin.add(profile.getUniqueId());

        if (!getUniqueConnections().contains(profile.getUniqueId())) {
            this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() +
                    " doesn't have data pre-loaded, they have never been processed during pre-login in this session." +
                    " - denying login.");
        } else {
            this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() +
                    " doesn't currently have data pre-loaded, but they have been processed before in this session." +
                    " - denying login.");
        }

        e.setCancelled(true);
        e.setMessageCancelled(false);
        //noinspection deprecation
        e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager())));
    }
}
 
Example #7
Source File: SpongeConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientLoginMonitor(ClientConnectionEvent.Login e) {
    /* Listen to see if the event was cancelled after we initially handled the login
       If the connection was cancelled here, we need to do something to clean up the data that was loaded. */

    // Check to see if this connection was denied at LOW. Even if it was denied at LOW, their data will still be present.
    if (this.deniedLogin.remove(e.getProfile().getUniqueId())) {
        // This is a problem, as they were denied at low priority, but are now being allowed.
        if (!e.isCancelled()) {
            this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId());
            e.setCancelled(true);
        }
    }
}
 
Example #8
Source File: ChatLoggerListener.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(Tristate.TRUE)
public void onPostCommand(SendCommandEvent commandEvent) {
    String command = commandEvent.getCommand();
    if (isOurCommand(command)) {
        //re-enable it
        commandEvent.getContext();
        commandEvent.setCancelled(false);
    }
}
 
Example #9
Source File: SpongeConnectionListener.java    From LuckPerms with MIT License 4 votes vote down vote up
@Listener(order = Order.EARLY)
@IsCancelled(Tristate.UNDEFINED)
public void onClientAuth(ClientConnectionEvent.Auth e) {
    /* Called when the player first attempts a connection with the server.
       Listening on AFTER_PRE priority to allow plugins to modify username / UUID data here. (auth plugins)
       Also, give other plugins a chance to cancel the event. */

    final GameProfile profile = e.getProfile();
    final String username = profile.getName().orElseThrow(() -> new RuntimeException("No username present for user " + profile.getUniqueId()));

    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing auth event for " + profile.getUniqueId() + " - " + profile.getName());
    }

    if (e.isCancelled()) {
        // another plugin has disallowed the login.
        this.plugin.getLogger().info("Another plugin has cancelled the connection for " + profile.getUniqueId() + " - " + username + ". No permissions data will be loaded.");
        this.deniedAsyncLogin.add(profile.getUniqueId());
        return;
    }

    /* Actually process the login for the connection.
       We do this here to delay the login until the data is ready.
       If the login gets cancelled later on, then this will be cleaned up.

       This includes:
       - loading uuid data
       - loading permissions
       - creating a user instance in the UserManager for this connection.
       - setting up cached data. */
    try {
        User user = loadUser(profile.getUniqueId(), username);
        recordConnection(profile.getUniqueId());
        this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(profile.getUniqueId(), username, user);
    } catch (Exception ex) {
        this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName());
        ex.printStackTrace();

        this.deniedAsyncLogin.add(profile.getUniqueId());

        e.setCancelled(true);
        e.setMessageCancelled(false);
        //noinspection deprecation
        e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager())));
        this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(profile.getUniqueId(), username, null);
    }
}
 
Example #10
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {

    for (Entity e : event.getEntities()) {
        if (e == null || (RedProtect.get().rm.getTopRegion(e.getLocation(), this.getClass().getName()) != null &&
                RedProtect.get().config.globalFlagsRoot().worlds.get(e.getWorld().getName()).spawn_allow_on_regions)) {
            continue;
        }

        //blacklist
        List<String> blacklist = RedProtect.get().config.globalFlagsRoot().worlds.get(e.getWorld().getName()).spawn_blacklist;
        if (e instanceof Monster && blacklist.contains("MONSTERS")) {
            RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of BLACKLISTED Monster " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        if ((e instanceof Animal || e instanceof Villager || e instanceof Ambient || e instanceof Golem) && blacklist.contains("PASSIVES")) {
            RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of BLACKLISTED Animal " + e.getType().getName());
            event.setCancelled(true);
            return;
        }
        if (blacklist.stream().anyMatch(e.getType().getName()::matches)) {
            RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of BLACKLISTED " + e.getType().getName());
            event.setCancelled(true);
            return;
        }

        //whitelist
        List<String> wtl = RedProtect.get().config.globalFlagsRoot().worlds.get(e.getWorld().getName()).spawn_whitelist;
        if (!wtl.isEmpty()) {
            if (e instanceof Monster && !wtl.contains("MONSTERS")) {
                RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of NON WHITELISTED Monster " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
            if ((e instanceof Animal || e instanceof Villager || e instanceof Ambient || e instanceof Golem) && !wtl.contains("PASSIVES")) {
                RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of NON WHITELISTED Animal " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
            if (wtl.stream().noneMatch(e.getType().getName()::matches)) {
                RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Cancelled spawn of NON WHITELISTED " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
        }
        RedProtect.get().logger.debug(LogLevel.SPAWN, "GlobalListener - Spawn mob " + e.getType().getName());
    }
}