Java Code Examples for org.spongepowered.api.event.network.ClientConnectionEvent#Disconnect

The following examples show how to use org.spongepowered.api.event.network.ClientConnectionEvent#Disconnect . 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: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void actOnQuitEvent(ClientConnectionEvent.Disconnect event) {
    long time = System.currentTimeMillis();
    Player player = event.getTargetEntity();
    String playerName = player.getName();
    UUID playerUUID = player.getUniqueId();
    UUID serverUUID = serverInfo.getServerUUID();
    JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
    JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);

    SpongeAFKListener.AFK_TRACKER.loggedOut(playerUUID, time);

    nicknameCache.removeDisplayName(playerUUID);

    boolean banned = isBanned(player.getProfile());
    dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, () -> banned));

    sessionCache.endSession(playerUUID, time)
            .ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));

    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
 
Example 3
Source File: UCListener.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onQuit(ClientConnectionEvent.Disconnect e, @Getter("getTargetEntity") Player p) {
    if (!UChat.get().getConfig().root().general.persist_channels) {
        UChat.get().getPlayerChannel(p).removeMember(p);
    }

    UChat.get().tellPlayers.remove(p.getName());
    UChat.get().tellPlayers.entrySet().removeIf(k -> k.getValue().equals(p.getName()));
    UChat.get().tempTellPlayers.remove(p.getName());
    UChat.get().tempTellPlayers.entrySet().removeIf(k -> k.getValue().equals(p.getName()));
    UChat.get().respondTell.remove(p.getName());
    UChat.get().respondTell.entrySet().removeIf(k -> k.getValue().equals(p.getName()));
    UChat.get().tempChannels.remove(p.getName());
    UChat.get().tempChannels.entrySet().removeIf(k -> k.getValue().equals(p.getName()));
    UChat.get().command.remove(p.getName());

    if (UChat.get().getUCJDA() != null && UChat.get().getUCJDA().JDAAvailable() && !p.hasPermission(UChat.get().getConfig().root().discord.vanish_perm)) {
        Task.builder().async().execute(() ->
                UChat.get().getUCJDA().sendRawToDiscord(UChat.get().getLang().get("discord.leave").replace("{player}", p.getName())));
    }
}
 
Example 4
Source File: EntityListener.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Saves event records when a player disconnects.
 *
 * @param event ClientConnectionEvent.Disconnect
 */
@Listener(order = Order.POST)
public void onClientConnectionDisconnect(ClientConnectionEvent.Disconnect event, @Getter("getTargetEntity") Player player) {
    if (!Prism.getInstance().getConfig().getEventCategory().isPlayerDisconnect()) {
        return;
    }

    PrismRecord.create()
            .player(player)
            .event(PrismEvents.PLAYER_DISCONNECT)
            .location(player.getLocation())
            .buildAndSave();
}
 
Example 5
Source File: MobFlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onPlayerLogout(ClientConnectionEvent.Disconnect event) {
    Player p = event.getTargetEntity();
    if (p.getName().equals(this.player.getName())) {
        close(true);
    }
}
 
Example 6
Source File: FlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onPlayerLogout(ClientConnectionEvent.Disconnect event) {
    Player p = event.getTargetEntity();
    if (p.getName().equals(this.player.getName())) {
        close(true);
    }
}
 
Example 7
Source File: ItemFlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onPlayerLogout(ClientConnectionEvent.Disconnect event) {
    Player p = event.getTargetEntity();
    if (p.getName().equals(this.player.getName())) {
        close(true);
    }
}
 
Example 8
Source File: SpongeMain.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onQuit(ClientConnectionEvent.Disconnect event) {
    Player player = event.getTargetEntity();
    FawePlayer fp = FawePlayer.wrap(player);
    fp.unregister();
    Fawe.get().unregister(player.getName());
}
 
Example 9
Source File: DefaultListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener(order = Order.LATE)
public void onDisconnect(ClientConnectionEvent.Disconnect event) {
    Player p = event.getTargetEntity();
    UltimateUser user = UltimateCore.get().getUserService().getUser(p);
    for (String key : UltimateUser.onlinekeys) {
        user.datas.remove(key);
    }
}
 
Example 10
Source File: PlayerDisconnectListener.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Listener
public void onPlayerDisconnect(ClientConnectionEvent.Disconnect event)
{
	Player player = event.getTargetEntity();
	String disconnectMessage = Utils.getDisconnectMessage();

	if (disconnectMessage != null && !disconnectMessage.equals(""))
	{
		if (disconnectMessage.equals("none"))
		{
			event.setMessageCancelled(true);
		}
		else
		{
			disconnectMessage = disconnectMessage.replaceAll("@p", player.getName());
			Text newMessage = TextSerializers.formattingCode('&').deserialize(disconnectMessage);
			event.setMessage(newMessage);
		}
	}

	if (EssentialCmds.afkList.containsKey(player.getUniqueId()))
	{
		EssentialCmds.afkList.remove(player.getUniqueId());
	}

	Utils.savePlayerInventory(player, player.getWorld().getUniqueId());
}
 
Example 11
Source File: TablistListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onQuit(ClientConnectionEvent.Disconnect event) {
    TablistModule module = (TablistModule) Modules.TABLIST.get();
    NamesHandler runnable = module.getRunnable();
    runnable.removeCache(event.getTargetEntity().getUniqueId());
    Sponge.getScheduler().createTaskBuilder().delayTicks(20L).execute(runnable::update).submit(UltimateCore.get());
}
 
Example 12
Source File: ChatUILib.java    From ChatUI with MIT License 5 votes vote down vote up
@Listener
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
    PlayerChatView view = this.playerViewMap.remove(event.getTargetEntity().getUniqueId());
    view.onRemove();
    LibConfig.saveConfig();
    this.languageManager.decrementLocale(event.getTargetEntity().getLocale());
}
 
Example 13
Source File: SpawnListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onQuit(ClientConnectionEvent.Disconnect event) {
    Player p = event.getTargetEntity();
    ModuleConfig config = Modules.SPAWN.get().getConfig().get();
    if (config.get().getNode("spawn-on-join").getBoolean(false)) {
        SerializableTransform loc = SpawnUtil.getSpawnLocation(p);
        if (!loc.isPresent()) return;
        Teleportation tp = UltimateCore.get().getTeleportService().createTeleportation(p, Arrays.asList(p), loc.get(), tel -> {
        }, (tel, reason) -> {
        }, false, true);
        tp.start();
    }
}
 
Example 14
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.DEFAULT)
public void beforeQuit(ClientConnectionEvent.Disconnect event) {
    Player player = event.getTargetEntity();
    UUID playerUUID = player.getUniqueId();
    String playerName = player.getName();
    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_LEAVE));
}
 
Example 15
Source File: FlyListeners.java    From UltimateCore with MIT License 4 votes vote down vote up
@Listener
public void onLeave(ClientConnectionEvent.Disconnect event) {
    UltimateUser user = UltimateCore.get().getUserService().getUser(event.getTargetEntity());
    user.offer(FlyKeys.FLY, event.getTargetEntity().get(Keys.CAN_FLY).orElse(false));
}
 
Example 16
Source File: SpongePlugin.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
@Listener
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
    core.updateClient(event.getTargetEntity().getConnection().getAddress().getAddress(),
            event.getTargetEntity().getUniqueId(), event.getTargetEntity().getName());
}
 
Example 17
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 18
Source File: SpongeConnectionListener.java    From LuckPerms with MIT License 4 votes vote down vote up
@Listener(order = Order.POST)
public void onClientLeave(ClientConnectionEvent.Disconnect e) {
    handleDisconnect(e.getTargetEntity().getUniqueId());
}
 
Example 19
Source File: SpongePingCounter.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Listener
public void onPlayerQuit(ClientConnectionEvent.Disconnect quitEvent) {
    removePlayer(quitEvent.getTargetEntity());
}
 
Example 20
Source File: SpongeAFKListener.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.POST)
public void onLeave(ClientConnectionEvent.Disconnect event) {
    ignorePermissionInfo.remove(event.getTargetEntity().getUniqueId());
}