Java Code Examples for org.bukkit.event.player.PlayerQuitEvent

The following examples show how to use org.bukkit.event.player.PlayerQuitEvent. These examples are extracted from open source projects. 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 Project: AuthMeReloaded   Author: AuthMe   File: PlayerListenerTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldRemoveMessageOnQuit() {
    // given
    given(settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)).willReturn(true);
    given(antiBotService.wasPlayerKicked(anyString())).willReturn(false);
    Player player = mockPlayerWithName("Billy");
    PlayerQuitEvent event = new PlayerQuitEvent(player, "Player has quit the server");

    // when
    listener.onPlayerQuit(event);

    // then
    assertThat(event.getQuitMessage(), nullValue());
    verify(antiBotService).wasPlayerKicked("Billy");
    verify(management).performQuit(player);
}
 
Example #2
Source Project: Plan   Author: plan-player-analytics   File: PlayerOnlineListener.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private void actOnQuitEvent(PlayerQuitEvent event) {
    long time = System.currentTimeMillis();
    Player player = event.getPlayer();
    String playerName = player.getName();
    UUID playerUUID = player.getUniqueId();
    UUID serverUUID = serverInfo.getServerUUID();
    JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
    JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);

    BukkitAFKListener.AFK_TRACKER.loggedOut(playerUUID, time);

    nicknameCache.removeDisplayName(playerUUID);

    dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, player::isBanned));

    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 Project: PGM   Author: PGMDev   File: PGMListener.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void removePlayerOnDisconnect(PlayerQuitEvent event) {
  Match match = this.mm.getMatch(event.getWorld());
  if (match == null) return;

  if (event.getQuitMessage() != null) {
    MatchPlayer player = match.getPlayer(event.getPlayer());
    if (player != null) {
      if (!vm.isVanished(player.getId())) {
        announceJoinOrLeave(player, false, false);
      } else {
        // Announce actual staff quit
        announceJoinOrLeave(player, false, true);
      }
    }
    event.setQuitMessage(null);
  }

  match.removePlayer(event.getPlayer());
  PGM.get().getPrefixRegistry().removePlayer(event.getPlayer().getUniqueId());
}
 
Example #4
Source Project: PlayerSQL   Author: caoli5288   File: EventExecutor.java    License: GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = MONITOR)
public void handle(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    UUID id = player.getUniqueId();
    Lifecycle lifecycle = handled.remove(id);
    if (manager.isNotLocked(id)) {
        manager.cancelTimerSaver(id);
        manager.lockUser(player);// Lock user if not in bungee enchant mode
        PlayerData data = (lifecycle == Lifecycle.DATA_SENT)
                ? (PlayerData) pending.get(id)
                : manager.getUserData(id, true);
        if (data == null) {
            main.run(() -> manager.unlockUser(player));// Err? unlock next tick
        } else {
            runAsync(() -> manager.saveUser(data, false)).thenRun(() -> main.run(() -> manager.unlockUser(player)));
        }
    } else {
    	UUID guid = GuidResolveService.getService().getGuid(player);
        runAsync(() -> manager.updateDataLock(guid, false)).thenRun(() -> main.run(() -> manager.unlockUser(player)));
    }
    pending.remove(id);
    LocalDataMgr.quit(player);
}
 
Example #5
Source Project: iDisguise   Author: robingrether   File: EventListener.java    License: Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
	Player player = event.getPlayer();
	if(plugin.getConfiguration().MODIFY_MESSAGE_LEAVE) {
		if(event.getQuitMessage() != null && DisguiseManager.isDisguised(player)) {
			if(DisguiseManager.getDisguise(player) instanceof PlayerDisguise) {
				event.setQuitMessage(event.getQuitMessage().replace(player.getName(), ((PlayerDisguise)DisguiseManager.getDisguise(player)).getDisplayName()));
			} else {
				event.setQuitMessage(null);
			}
		}
	}
	if(!plugin.getConfiguration().KEEP_DISGUISE_LEAVE) {
		if(DisguiseManager.isDisguised(player)) {
			DisguiseManager.undisguise(player);
		}
	}
	ChannelInjector.remove(player);
	EntityIdList.removeEntity(player);
}
 
Example #6
Source Project: helper   Author: lucko   File: Metadata.java    License: MIT License 6 votes vote down vote up
private static void ensureSetup() {
    if (SETUP.get()) {
        return;
    }

    if (!SETUP.getAndSet(true)) {

        // remove player metadata when they leave the server
        Events.subscribe(PlayerQuitEvent.class, EventPriority.MONITOR)
                .handler(e -> StandardMetadataRegistries.PLAYER.remove(e.getPlayer().getUniqueId()));

        // cache housekeeping task
        Schedulers.builder()
                .async()
                .afterAndEvery(1, TimeUnit.MINUTES)
                .run(() -> {
                    for (MetadataRegistry<?> registry : StandardMetadataRegistries.values()) {
                        registry.cleanup();
                    }
                });
    }
}
 
Example #7
Source Project: AuthMeReloaded   Author: AuthMe   File: PlayerListenerTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldRemoveMessageForUnloggedUser() {
    // given
    given(settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)).willReturn(false);
    given(settings.getProperty(RegistrationSettings.REMOVE_UNLOGGED_LEAVE_MESSAGE)).willReturn(true);
    String name = "Joel";
    given(antiBotService.wasPlayerKicked(name)).willReturn(true);
    Player player = mockPlayerWithName(name);
    PlayerQuitEvent event = new PlayerQuitEvent(player, "Joel exits the party");
    given(listenerService.shouldCancelEvent(event)).willReturn(true);

    // when
    listener.onPlayerQuit(event);

    // then
    assertThat(event.getQuitMessage(), nullValue());
    verify(antiBotService).wasPlayerKicked(name);
    verifyNoInteractions(management);
}
 
Example #8
Source Project: askyblock   Author: tastybento   File: JoinLeaveEvents.java    License: GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuit(final PlayerQuitEvent event) {
    // Remove from TopTen if the player has the permission
    if (!event.getPlayer().hasPermission(Settings.PERMPREFIX + "intopten")) {
        plugin.getTopTen().topTenRemoveEntry(event.getPlayer().getUniqueId());
    }
    // Remove from coop list
    if (!Settings.persistantCoops) {
        CoopPlay.getInstance().clearMyCoops(event.getPlayer());
        CoopPlay.getInstance().clearMyInvitedCoops(event.getPlayer());
    }
    plugin.getChatListener().unSetPlayer(event.getPlayer().getUniqueId());
    // CoopPlay.getInstance().returnAllInventories(event.getPlayer());
    // plugin.setMessage(event.getPlayer().getUniqueId(),
    // "Hello! This is a test. You logged out");
    players.removeOnlinePlayer(event.getPlayer().getUniqueId());
}
 
Example #9
Source Project: EnchantmentsEnhance   Author: weihao   File: PlayerStreamListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * When a player leaves the server, listener saves a player's data from
 * hashmap to file, but will not write to disk.
 *
 * @param e
 */
@EventHandler(priority = EventPriority.MONITOR)
public void onQuit(PlayerQuitEvent e) {
    String playername = e.getPlayer().getName();
    PlayerStat playerstat = PlayerStatsManager.getPlayerStats(playername);
    if (playerstat != null) {
        new BukkitRunnable() {
            @Override
            public void run() {
                try {
                    DataStorage.get().saveStats(playerstat);
                    PlayerStatsManager.removePlayerStats(playername);
                } catch (Exception ex) {
                    // Unexpected Error.
                    ex.printStackTrace();
                }
            }
        }.runTaskLater(Main.getMain(), 20L);
    }
}
 
Example #10
Source Project: Skript   Author: SkriptLang   File: ExprMessage.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
String get(final Event e) {
	if (e instanceof PlayerKickEvent)
		return ((PlayerKickEvent) e).getLeaveMessage();
	else
		return ((PlayerQuitEvent) e).getQuitMessage();
}
 
Example #11
Source Project: mcspring-boot   Author: Alan-Gomes   File: ScopeTest.java    License: MIT License 5 votes vote down vote up
@Test
@SneakyThrows
public void shouldClearScopeAfterPlayerQuit() {
    context.runWithSender(player1, () -> counterService.setCounter(2));
    context.runWithSender(player2, () -> counterService.setCounter(3));

    PlayerQuitEvent event = new PlayerQuitEvent(player1, "");
    eventExecutor.execute(senderContextScope, event);

    Integer counter1 = context.runWithSender(player1, counterService::getCounter);
    Integer counter2 = context.runWithSender(player2, counterService::getCounter);
    assertEquals(Integer.valueOf(0), counter1);
    assertEquals(Integer.valueOf(3), counter2);
}
 
Example #12
Source Project: ScoreboardStats   Author: games647   File: StatsListener.java    License: MIT License 5 votes vote down vote up
/**
 * Saves the stats to database if the player leaves
 *
 * @param quitEvent leave event
 * @see Database
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onQuit(PlayerQuitEvent quitEvent) {
    Player player = quitEvent.getPlayer();

    database.getStats(player).ifPresent(database::saveAsync);

    //just remove our metadata to prevent memory leaks
    player.removeMetadata("player_stats", plugin);
}
 
Example #13
Source Project: Plan   Author: plan-player-analytics   File: PlayerOnlineListener.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
    try {
        actOnQuitEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #14
Source Project: HoloAPI   Author: DSH105   File: HoloListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    for (Hologram h : HoloAPI.getManager().getAllHolograms().keySet()) {
        if (h.getLocationFor(player) != null) {
            h.clear(player);
        }
    }
}
 
Example #15
Source Project: Slimefun4   Author: TheBusyBiscuit   File: TestPlayerProfileListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testPlayerLeave() throws InterruptedException {
    Player player = server.addPlayer();
    PlayerProfile profile = TestUtilities.awaitProfile(player);
    PlayerQuitEvent event = new PlayerQuitEvent(player, "bye");
    listener.onDisconnect(event);

    Assertions.assertTrue(profile.isMarkedForDeletion());
}
 
Example #16
Source Project: Assemble   Author: ThatKawaiiSam   File: AssembleListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
	AssembleBoardDestroyEvent destroyEvent = new AssembleBoardDestroyEvent(event.getPlayer());

	Bukkit.getPluginManager().callEvent(destroyEvent);
	if (destroyEvent.isCancelled()) {
		return;
	}

	getAssemble().getBoards().remove(event.getPlayer().getUniqueId());
	event.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
}
 
Example #17
Source Project: GlobalWarming   Author: nsporillo   File: PlayerListener.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * When players leave:
 * - Remove them from the scoreboard
 */
@EventHandler(ignoreCancelled = true)
public void onPlayerQuit(PlayerQuitEvent event) {
    if (gw.getConf().isScoreboardEnabled()) {
        PlayerTable playerTable = gw.getTableManager().getPlayerTable();
        GPlayer gPlayer = playerTable.getPlayers().get(event.getPlayer().getUniqueId());
        gw.getScoreboard().disconnect(gPlayer);
    }
}
 
Example #18
Source Project: TabooLib   Author: TabooLib   File: PlayerContainerLoader.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onQuit(PlayerQuitEvent e) {
    pluginContainer.values().stream().flatMap(Collection::stream).forEach(container -> {
        if (container.getContainer() instanceof Map) {
            ((Map) container.getContainer()).remove(container.isUniqueId() ? e.getPlayer().getUniqueId() : e.getPlayer().getName());
        } else if (container.getContainer() instanceof Collection) {
            ((Collection) container.getContainer()).remove(container.isUniqueId() ? e.getPlayer().getUniqueId() : e.getPlayer().getName());
        } else {
            TLogger.getGlobalLogger().error("Invalid Container: " + container.getContainer().getClass().getSimpleName());
        }
    });
}
 
Example #19
Source Project: Hawk   Author: HawkAnticheat   File: MouseRecorder.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onQuit(PlayerQuitEvent e) {
    if(e.getPlayer().equals(target)) {
        if(admin != null) {
            admin.sendMessage(ChatColor.GOLD + "Recording progress for " + target.getName() + " interrupted because of disconnection.");
        }
        hawkListeners.remove(this);
        HandlerList.unregisterAll(this);
        render(this);
    }

}
 
Example #20
Source Project: Slimefun4   Author: TheBusyBiscuit   File: PlayerProfileListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onDisconnect(PlayerQuitEvent e) {
    Optional<PlayerProfile> profile = PlayerProfile.find(e.getPlayer());

    // if we still have a profile of this Player in memory, delete it
    if (profile.isPresent()) {
        profile.get().markForDeletion();
    }
}
 
Example #21
Source Project: SkyWarsReloaded   Author: walrusone   File: SpectateListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
	final Player player = e.getPlayer();
	final GameMap gameMap = MatchManager.get().getSpectatorMap(player);
	if (gameMap == null) {
		return;
	}
	gameMap.getSpectators().remove(player.getUniqueId());
	MatchManager.get().removeSpectator(player);
}
 
Example #22
Source Project: BungeePerms   Author: weaondara   File: BukkitEventListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onQuit(PlayerQuitEvent e)
{
    //todo delay by one tick
    //uninject permissible
    Injector.uninject(e.getPlayer());

    User u = config.isUseUUIDs() ? pm().getUser(e.getPlayer().getUniqueId()) : pm().getUser(e.getPlayer().getName());
    pm().removeUserFromCache(u);
}
 
Example #23
Source Project: Crazy-Crates   Author: badbones69   File: CrateControl.java    License: MIT License 5 votes vote down vote up
@EventHandler
public void onLeave(PlayerQuitEvent e) {
    Player player = e.getPlayer();
    if (cc.hasCrateTask(player)) {
        cc.endCrate(player);
    }
    if (cc.hasQuadCrateTask(player)) {
        cc.endQuadCrate(player);
    }
    if (cc.isInOpeningList(player)) {
        cc.removePlayerFromOpeningList(player);
    }
}
 
Example #24
Source Project: Plan   Author: plan-player-analytics   File: PlayerOnlineListener.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void beforePlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    UUID playerUUID = player.getUniqueId();
    String playerName = player.getName();
    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_LEAVE));
}
 
Example #25
Source Project: ProjectAres   Author: OvercastNetwork   File: PlayerListener.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void leave(final PlayerQuitEvent event) {
    int count = lobby.getServer().getOnlinePlayers().size();
    if(lobby.getServer().getOnlinePlayers().contains(event.getPlayer())) count--;
    minecraftService.updateLocalServer(new SignUpdate(count));

    if(count == 0 && restartDeferral != null) {
        final RequestRestartEvent.Deferral deferral = restartDeferral;
        restartDeferral = null;
        deferral.resume();
    }
}
 
Example #26
Source Project: NovaGuilds   Author: MarcinWieczorek   File: LoginListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
	NovaPlayer nPlayer = PlayerManager.getPlayer(event.getPlayer());

	if(nPlayer.isAtRegion()) {
		plugin.getRegionManager().playerExitedRegion(nPlayer.getPlayer());
	}

	//Guild inactive time
	if(nPlayer.hasGuild()) {
		nPlayer.getGuild().updateInactiveTime();
	}
}
 
Example #27
Source Project: ProjectAres   Author: OvercastNetwork   File: TabManager.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onQuit(PlayerQuitEvent event) {
    TabView view = this.getViewOrNull(event.getPlayer());
    if(view != null) {
        view.disable();
        this.removeView(view);
    }
    this.removePlayerEntry(event.getPlayer());
}
 
Example #28
Source Project: ProjectAres   Author: OvercastNetwork   File: PlayerServerChanger.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onQuit(PlayerQuitEvent event) {
    final MetadataValue future = event.getPlayer().getMetadata(METADATA_KEY, plugin);
    if(future != null) {
        ((SettableFuture) future.value()).set(null);
    }
}
 
Example #29
Source Project: ProjectAres   Author: OvercastNetwork   File: JoinMessageAnnouncer.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onQuit(PlayerQuitEvent event) throws EventException {
    event.setQuitMessage(null);
    final User user = userStore.getUser(event.getPlayer());
    final SessionChange change = pendingQuits.getIfPresent(user);

    event.yield();

    if(change != null) {
        pendingQuits.invalidate(user);
        announce(change);
    }
}
 
Example #30
Source Project: CardinalPGM   Author: twizmwazin   File: TitleRespawn.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPlayerLeave(PlayerQuitEvent event) {
    Optional<TeamModule> team = Teams.getTeamByPlayer(event.getPlayer());
    if (!team.isPresent() || !team.get().isObserver()) dropInventory(event.getPlayer());
    this.deadPlayers.remove(event.getPlayer().getUniqueId());
    this.hasLeftClicked.remove(event.getPlayer().getUniqueId());
}