org.bukkit.event.player.PlayerQuitEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerQuitEvent. 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: PlayerListenerTest.java    From AuthMeReloaded with 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 File: PGMListener.java    From PGM with 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 #3
Source File: PlayerListenerTest.java    From AuthMeReloaded with 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 #4
Source File: JoinLeaveEvents.java    From askyblock with 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 #5
Source File: PlayerOnlineListener.java    From Plan with 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 #6
Source File: Metadata.java    From helper with 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 File: EventExecutor.java    From PlayerSQL with 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 #8
Source File: PlayerStreamListener.java    From EnchantmentsEnhance with 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 #9
Source File: EventListener.java    From iDisguise with 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 #10
Source File: LoginListener.java    From NovaGuilds with 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 #11
Source File: PlayerProfileListener.java    From Slimefun4 with 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 #12
Source File: MouseRecorder.java    From Hawk with 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 #13
Source File: SpectateListener.java    From SkyWarsReloaded with 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 #14
Source File: PlayerContainerLoader.java    From TabooLib with 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 #15
Source File: BukkitEventListener.java    From BungeePerms with 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 #16
Source File: CrateControl.java    From Crazy-Crates with 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 #17
Source File: ScopeTest.java    From mcspring-boot with 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 #18
Source File: PlayerOnlineListener.java    From Plan with 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 #19
Source File: PlayerListener.java    From ProjectAres with 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 #20
Source File: ExprMessage.java    From Skript with 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 #21
Source File: TabManager.java    From ProjectAres with 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 #22
Source File: PlayerServerChanger.java    From ProjectAres with 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 #23
Source File: JoinMessageAnnouncer.java    From ProjectAres with 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 #24
Source File: TitleRespawn.java    From CardinalPGM with 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());
}
 
Example #25
Source File: BukkitPlugin.java    From ServerListPlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerDisconnect(PlayerQuitEvent event) {
    if (core == null) return; // Too early, we haven't finished initializing yet

    UUID uuid = null;
    try { uuid = event.getPlayer().getUniqueId(); } catch (NoSuchMethodError ignored) {}
    core.updateClient(event.getPlayer().getAddress().getAddress(), uuid, event.getPlayer().getName());
}
 
Example #26
Source File: ConnectionListener.java    From FastLogin with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent quitEvent) {
    Player player = quitEvent.getPlayer();

    removeBlacklistStatus(player);
    plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
    plugin.getPremiumPlayers().remove(player.getUniqueId());
    plugin.getBungeeManager().cleanup(player);
}
 
Example #27
Source File: PlayerTracker.java    From MineCloud with ISC License 5 votes vote down vote up
@EventHandler
public void playerQuit(PlayerQuitEvent event) {
    Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
        Server server = plugin.server();

        server.removePlayer(event.getPlayer().getUniqueId());
        plugin.updatePlayers(server);
        plugin.mongo().repositoryBy(Server.class).save(server);
    });
}
 
Example #28
Source File: Conversation.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onQuit(PlayerQuitEvent event) {
    // if player quits, end conversation (why keep listeners running?)
    if (event.getPlayer().equals(player)) {
        if (isMovementBlock()) {
            suspend();
        } else {
            endConversation();
        }
    }
}
 
Example #29
Source File: PermissionEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
    if (Civs.perm == null) {
        return;
    }
    Player player = event.getPlayer();
    HashSet<String> permissions = permissionMap.get(player.getUniqueId());
    if (permissions == null) {
        return;
    }
    for (String permission : permissions) {
        Civs.perm.playerRemove(player, permission);
    }
    permissionMap.remove(event.getPlayer().getUniqueId());
}
 
Example #30
Source File: FaweBukkit.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    String name = player.getName();
    FawePlayer fp = Fawe.get().getCachedPlayer(name);
    if (fp != null) {
        fp.unregister();
        Fawe.get().unregister(name);
    }
}