Java Code Examples for org.spongepowered.api.event.Order#LAST

The following examples show how to use org.spongepowered.api.event.Order#LAST . 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: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order= Order.LAST)
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
    final Player player = event.getTargetEntity();
    if (!SpongeImpl.getServer().isServerRunning() || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }

    GDTimings.PLAYER_QUIT_EVENT.startTimingIfSync();
    UUID playerID = player.getUniqueId();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID);

    if (this.worldEditProvider != null) {
        this.worldEditProvider.revertVisuals(player, playerData, null);
        this.worldEditProvider.removePlayer(player);
    }

    playerData.onDisconnect();
    PaginationUtil.getInstance().removeActivePageData(player.getUniqueId());
    if (playerData.getClaims().isEmpty()) {
        this.dataStore.clearCachedPlayerData(player.getWorld().getUniqueId(), playerID);
    }
    GDCallbackHolder.getInstance().onPlayerDisconnect(player);
    GDTimings.PLAYER_QUIT_EVENT.stopTimingIfSync();
}
 
Example 2
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.LAST, beforeModifications = true)
public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
    if (!GDFlags.ITEM_PICKUP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_PICKUP.getName(), event.getTargetEntity(), player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.startTimingIfSync();
    final World world = player.getWorld();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, player.getUniqueId());
    Location<World> location = player.getLocation();
    GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_PICKUP, player, event.getTargetEntity(), player, true) == Tristate.FALSE) {
        event.setCancelled(true);
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
}
 
Example 3
Source File: HuskyUI.java    From HuskyUI-Plugin with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handler for ActionableElement actions.
 *
 * @param event When a player interacts with an item with their secondary mouse button.
 */
@Listener(order= Order.LAST)
public void onElementInteract(InteractItemEvent event){
    Optional<Element> ele = registry.getElementFromItemStack(event.getItemStack().createStack());
    if(ele.isPresent()){
        if(event instanceof InteractItemEvent.Secondary) {
            if (ele.get() instanceof ActionableElement) {
                ActionableElement aElement = ((ActionableElement) ele.get()).copy(registry);
                aElement.getAction().setObserver((Player) event.getCause().root());
                aElement.getAction().runAction("",null);
            }
        }

        event.setCancelled(true);
    }
}
 
Example 4
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 5
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 6 votes vote down vote up
@Listener(order = Order.LAST)
public void onPlayerRespawn(RespawnPlayerEvent event) {
    GPTimings.PLAYER_RESPAWN_EVENT.startTimingIfSync();
    Player player = event.getTargetEntity();
    if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        GPTimings.PLAYER_RESPAWN_EVENT.stopTimingIfSync();
        return;
    }

    GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    playerData.lastSpawn = Calendar.getInstance().getTimeInMillis();
    playerData.lastPvpTimestamp = 0; // no longer in pvp combat

    // also send him any messaged from grief prevention he would have
    // received while dead
    if (playerData.messageOnRespawn != null) {
        // color is already embedded inmessage in this case
        GriefPreventionPlugin.sendMessage(player, Text.of(playerData.messageOnRespawn), 40L);
        playerData.messageOnRespawn = null;
    }

    GriefPreventionPlugin.instance.checkPvpProtectionNeeded(player);
    GPTimings.PLAYER_RESPAWN_EVENT.stopTimingIfSync();
}
 
Example 6
Source File: VanishListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onJoin(ClientConnectionEvent.Join event) {
    Player p = event.getTargetEntity();
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    if (up.get(VanishKeys.VANISH).get()) {
        p.offer(Keys.VANISH, true);
        p.offer(Keys.VANISH_PREVENTS_TARGETING, true);
        p.offer(Keys.VANISH_IGNORES_COLLISION, true);
        p.offer(Keys.IS_SILENT, true);
        Messages.send(p, "vanish.onjoin");
    }
}
 
Example 7
Source File: AfkSwitchListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onAfkSwitch(DataOfferEvent<Boolean> event) {
    if (event.getKey().equals(AfkKeys.IS_AFK) && event.getValue().isPresent()) {
        Player player = event.getCause().first(Player.class).orElse(null);
        if (player == null) {
            Messages.log("Invalid DataOfferEvent! (No player found)");
            return;
        }
        UltimateUser user = UltimateCore.get().getUserService().getUser(player);
        CommentedConfigurationNode config = Modules.AFK.get().getConfig().get().get();
        if (config.getNode("title", "enabled").getBoolean(true)) {
            if (event.getValue().get()) {
                //Player went afk
                Text title = Messages.getFormatted("afk.title.title");
                Text subtitle;
                if (player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get())) {
                    subtitle = Messages.getFormatted("afk.title.subtitle.exempt");
                } else if (config.getNode("title", "subtitle-show-seconds").getBoolean(true)) {
                    subtitle = Messages.getFormatted("afk.title.subtitle.kick", "%time%", TimeUtil.format(config.getNode("time", "kicktime").getInt() * 1000, 3, null));
                } else {
                    subtitle = Messages.getFormatted("afk.title.subtitle.kick", "%time%", TimeUtil.format(config.getNode("time", "kicktime").getInt() * 1000, 3, 11));
                }
                if (config.getNode("title", "subtitle").getBoolean(false) && (!player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get()) || config.getNode("title", "subtitle-exempt").getBoolean(false))) {
                    //Show subtitle
                    player.sendTitle(Title.builder().title(title).subtitle(subtitle).fadeIn(20).fadeOut(20).stay(config.getNode("title", "subtitle-refresh").getInt()).build());
                } else {
                    //Don't show subtitle
                    //TODO refresh?
                    player.sendTitle(Title.builder().title(title).fadeIn(20).fadeOut(20).stay(config.getNode("title", "subtitle-refresh").getInt()).build());
                }
            }
        }
    }
}
 
Example 8
Source File: UnknowncommandListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onCommand(SendCommandEvent event) {
    CommandSource p = event.getCause().first(CommandSource.class).orElse(null);
    if (p == null) return;
    CommandManager cm = Sponge.getCommandManager();
    if (cm.get(event.getCommand()).isPresent()) return;

    //Send message
    event.setCancelled(true);
    Messages.send(p, "unknowncommand.message");
}
 
Example 9
Source File: GriefPreventionPlugin.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onGameReload(GameReloadEvent event) {
    this.loadConfig();
    if (event.getSource() instanceof CommandSource) {
        sendMessage((CommandSource) event.getSource(), this.messageData.pluginReload.toText());
    }
}
 
Example 10
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onPlayerKicked(KickPlayerEvent event) {
    final Player player = event.getTargetEntity();
    if (!SpongeImpl.getServer().isServerRunning() || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_KICK_EVENT.startTimingIfSync();
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    playerData.wasKicked = true;
    GPTimings.PLAYER_KICK_EVENT.stopTimingIfSync();
}
 
Example 11
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 12
Source File: WorldCalculator.java    From LuckPerms with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onWorldChange(MoveEntityEvent.Teleport e) {
    Entity targetEntity = e.getTargetEntity();
    if (!(targetEntity instanceof Player)) {
        return;
    }

    if (e.getFromTransform().getExtent().equals(e.getToTransform().getExtent())) {
        return;
    }

    Player player = (Player) targetEntity;
    this.plugin.getContextManager().signalContextUpdate(player);
}
 
Example 13
Source File: DeathListener.java    From ViaVersion with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onDeath(DestructEntityEvent.Death e) {
    if (!(e.getTargetEntity() instanceof Player))
        return;

    Player p = (Player) e.getTargetEntity();
    if (isOnPipe(p.getUniqueId()) && Via.getConfig().isShowNewDeathMessages() && checkGamerule(p.getWorld())) {
        sendPacket(p, e.getMessage().toPlain());
    }
}
 
Example 14
Source File: GriefDefenderPlugin.java    From GriefDefender with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onGameReload(GameReloadEvent event) {
    this.loadConfig();
    if (event.getSource() instanceof CommandSource) {
        sendMessage((CommandSource) event.getSource(), MessageCache.getInstance().PLUGIN_RELOAD);
    }
}
 
Example 15
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Listener(order= Order.LAST)
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
    final Player player = event.getTargetEntity();
    if (!SpongeImpl.getServer().isServerRunning() || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_QUIT_EVENT.startTimingIfSync();
    UUID playerID = player.getUniqueId();
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID);
    boolean isBanned = false;
    if (playerData.wasKicked) {
        isBanned = this.banService.isBanned(player.getProfile()) || (playerData.ipAddress != null && this.banService.isBanned(playerData.ipAddress));
    }

    // if banned, add IP to the temporary IP ban list
    if (isBanned && playerData.ipAddress != null) {
        long now = Calendar.getInstance().getTimeInMillis();
        this.tempBannedIps.add(new IpBanInfo(playerData.ipAddress, now + this.MILLISECONDS_IN_DAY, player.getName()));
    }

    // silence notifications when they're coming too fast, or the player is banned
    if (this.shouldSilenceNotification() || isBanned) {
        event.setMessage(Text.of());
    } else {
        // make sure his data is all saved - he might have accrued some claim
        // blocks while playing that were not saved immediately
        playerData.saveAllData();
    }

    // FEATURE: players in pvp combat when they log out will die
    if (GriefPreventionPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().pvp.punishPvpLogout && playerData.inPvpCombat(player.getWorld())) {
        player.offer(Keys.HEALTH, 0d);
    }

    if (this.worldEditProvider != null) {
        this.worldEditProvider.revertVisuals(player, playerData, null);
        this.worldEditProvider.removePlayer(player);
    }

    playerData.onDisconnect();
    PaginationUtils.removeActivePageData(player.getUniqueId());
    if (playerData.getClaims().isEmpty()) {
        this.dataStore.clearCachedPlayerData(player.getWorld().getProperties(), playerID);
    }

    // reduce count of players with that player's IP address
    // TODO: re-enable when achievement data is implemented
    /*if (GriefPrevention.instance.config_ipLimit > 0 && !player.getAchievementData().achievements().contains(Achievements.MINE_WOOD)) {
        InetAddress ipAddress = playerData.ipAddress;
        if (ipAddress != null) {
            String ipAddressString = ipAddress.toString();
            Integer count = this.ipCountHash.get(ipAddressString);
            if (count == null)
                count = 1;
            this.ipCountHash.put(ipAddressString, count - 1);
        }
    }*/
    GPTimings.PLAYER_QUIT_EVENT.stopTimingIfSync();
}
 
Example 16
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Listener(order = Order.LAST, beforeModifications = true)
public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
    if (!GPFlags.ITEM_PICKUP || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
        return;
    }
    if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_PICKUP.toString(), event.getTargetEntity(), player.getWorld().getProperties())) {
        return;
    }

    GPTimings.PLAYER_PICKUP_ITEM_EVENT.startTimingIfSync();
    final World world = player.getWorld();
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, player.getUniqueId());
    Location<World> location = player.getLocation();
    GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
    if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_PICKUP, player, event.getTargetEntity(), player, TrustType.ACCESSOR, true) == Tristate.FALSE) {
        event.setCancelled(true);
        GPTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
        return;
    }

    // the rest of this code is specific to pvp worlds
    if (claim.pvpRulesApply()) {
        // if we're preventing spawn camping and the player was previously empty handed...
        if (GriefPreventionPlugin.getActiveConfig(world.getProperties()).getConfig().pvp.protectFreshSpawns && PlayerUtils.hasItemInOneHand(player, ItemTypes.NONE)) {
            // if that player is currently immune to pvp
            if (playerData.pvpImmune) {
                // if it's been less than 10 seconds since the last time he spawned, don't pick up the item
                long now = Calendar.getInstance().getTimeInMillis();
                long elapsedSinceLastSpawn = now - playerData.lastSpawn;
                if (elapsedSinceLastSpawn < 10000) {
                    event.setCancelled(true);
                    GPTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
                    return;
                }

                // otherwise take away his immunity. he may be armed now. at least, he's worth killing for some loot
                playerData.pvpImmune = false;
                GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.pvpImmunityEnd.toText());
            }
        }
    }
    GPTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
}
 
Example 17
Source File: GDBootstrap.java    From GriefDefender with MIT License 4 votes vote down vote up
@Listener(order = Order.LAST)
public void onPreInit(GamePreInitializationEvent event) {
    instance = this;
    final JSONParser parser = new JSONParser();
    String bukkitJsonVersion = null;
    this.getLogger().info("Loading libraries...");
    final MinecraftVersion version = Sponge.getPlatform().getMinecraftVersion();
    if (Sponge.getPlatform().getMinecraftVersion().getName().contains("1.12.2")) {
        bukkitJsonVersion = "1.12.2";
    } else {
        this.getLogger().error("Detected unsupported version '" + version.getName() + "'. GriefDefender only supports 1.12.2 on Sponge. GriefDefender will NOT load.");
        return;
    }
    try {
        final InputStream in = getClass().getResourceAsStream("/" + bukkitJsonVersion + ".json");
        final BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        final JSONObject a = (JSONObject) parser.parse(reader);
        final JSONArray libraries = (JSONArray) a.get("libraries");
        if (libraries == null) {
            this.getLogger().error("Resource " + bukkitJsonVersion + ".json is corrupted!. Please contact author for assistance.");
            return;
        }
        final Path LIB_ROOT_PATH = instance.configPath.resolve("lib");
        final Iterator<JSONObject> iterator = libraries.iterator();
        while (iterator.hasNext()) {
            JSONObject lib = iterator.next();
            final String name = (String) lib.get("name");
            final String sha1 = (String) lib.get("sha1");
            final String path = (String) lib.get("path");
            final String relocate = (String) lib.get("relocate");
            final String url = (String) lib.get("url");
            final Path libPath = LIB_ROOT_PATH.resolve(path);
            downloadLibrary(name, relocate, sha1, url, libPath);
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
    // Inject jar-relocator and asm debug
    injectRelocatorDeps();
    // Relocate all GD dependencies and inject
    GDRelocator.getInstance().relocateJars(this.jarMap);
    // Boot GD
    GriefDefenderPlugin.getInstance().onPreInit(event, this.logger, this.configPath, this.pluginContainer);
    //Sponge.getEventManager().registerListeners(GriefDefenderPlugin.getInstance(), GriefDefenderPlugin.getInstance());
}