Java Code Examples for org.bukkit.event.player.PlayerQuitEvent#getPlayer()

The following examples show how to use org.bukkit.event.player.PlayerQuitEvent#getPlayer() . 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
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerQuit(PlayerQuitEvent event) {
    final Player player = event.getPlayer();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }

    GDTimings.PLAYER_QUIT_EVENT.startTiming();
    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().getUID(), playerID);
    }
    GDCallbackHolder.getInstance().onPlayerDisconnect(player);
    GDTimings.PLAYER_QUIT_EVENT.stopTiming();
}
 
Example 2
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 3
Source File: LugolsIodineDisplay.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();

    BossBar bossBar = this.displayMap.get(player.getUniqueId());
    if (bossBar != null) {
        bossBar.removePlayer(player);
    }
}
 
Example 4
Source File: ReferenceCleanup.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
	final Player player = event.getPlayer();
	if (plugin.getConfig().getBoolean("optimizations.cleanupreferences.player", false)) {
		executor.schedule(new Runnable() {
			@Override
			public void run() {
				nullFields(player);
			}
		}, 1, TimeUnit.SECONDS);
	}
}
 
Example 5
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes temporary perms when the player log out
 * @param event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerLeave(PlayerQuitEvent event){
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Removing fly and all temp perms");
    Player player = event.getPlayer();

    if(temporaryPerms.containsKey(player.getUniqueId())){
        for(String perm : temporaryPerms.get(player.getUniqueId())){
            VaultHelper.removePerm(player, perm, ASkyBlock.getIslandWorld());
            if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
                VaultHelper.removePerm(player, perm, ASkyBlock.getNetherWorld());
            }
        }
        temporaryPerms.remove(player.getUniqueId());
    }
    if(VaultHelper.checkPerm(player, Settings.PERMPREFIX + "islandfly")) {
        if (player.getGameMode().equals(GameMode.SURVIVAL)) {
            player.setAllowFlight(false);
            player.setFlying(false);
        }
    }
    final Island island = plugin.getGrid().getProtectedIslandAt(event.getPlayer().getLocation());
    if (island != null) {
        // Fire exit event
        final IslandExitEvent e = new IslandExitEvent(event.getPlayer().getUniqueId(), island, event.getPlayer().getLocation());
        plugin.getServer().getPluginManager().callEvent(e);
    }
}
 
Example 6
Source File: HoloListener.java    From HoloAPI with 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 7
Source File: SitListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler
public void onQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    Entity vehicle = player.getVehicle();
    if (safeLocations.containsKey(player.getUniqueId()) && player.isInsideVehicle() && vehicle instanceof ArmorStand) {
        safeLocations.remove(player.getUniqueId());
        player.leaveVehicle();
        vehicle.remove();
    }
}
 
Example 8
Source File: QuitEvent.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onQuit(PlayerQuitEvent event){
    Player player = event.getPlayer();
    if(player.hasMetadata(GlobalValues.STICK_MODE)){
        player.removeMetadata(GlobalValues.STICK_MODE, sm);
        player.removeMetadata(GlobalValues.SELECTED_ENTITY, sm);
        player.removeMetadata(GlobalValues.WAITING_FOR_INPUT, sm);
    }
}
 
Example 9
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 10
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler @SuppressWarnings("unused")
public void onCivilianQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    UUID uuid = player.getUniqueId();
    Civilian civilian = CivilianManager.getInstance().getCivilian(uuid);

    if (civilian.isInCombat() && ConfigManager.getInstance().getCombatLogPenalty() > 0) {
        int penalty = (int) (player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() *
                ConfigManager.getInstance().getCombatLogPenalty() / 100);
        if (civilian.getLastDamager() != null) {
            Player damager = Bukkit.getPlayer(civilian.getLastDamager());
            if (damager != null && damager.isOnline()) {
                player.damage(penalty);
            }
        } else {
            player.damage(penalty);
        }
    }
    CivilianManager.getInstance().unloadCivilian(player);
    CommonScheduler.getLastRegion().remove(uuid);
    CommonScheduler.getLastTown().remove(uuid);
    CommonScheduler.removeLastAnnouncement(uuid);
    MenuManager.clearHistory(uuid);
    MenuManager.clearData(uuid);
    TownManager.getInstance().clearInvite(uuid);
    AnnouncementUtil.clearPlayer(uuid);
    StructureUtil.removeBoundingBox(uuid);
}
 
Example 11
Source File: PetOwnerListener.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
    Player p = event.getPlayer();
    // NOTE: Remove all pets
    IPet pi = EchoPet.getManager().getPet(p);
    if (pi != null) {
        //ec.PH.saveFileData("autosave", pi);
        EchoPet.getManager().saveFileData("autosave", pi);
        EchoPet.getSqlManager().saveToDatabase(pi, false);
        EchoPet.getManager().removePet(pi, true);
    }
}
 
Example 12
Source File: PlayerListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onQuit(PlayerQuitEvent pqe) {
  Player player = pqe.getPlayer();

  if (BedwarsRel.getInstance().isBungee()) {
    pqe.setQuitMessage(null);
  }

  // Remove holographs
  if (BedwarsRel.getInstance().isHologramsEnabled()
      && BedwarsRel.getInstance().getHolographicInteractor() != null && BedwarsRel.getInstance()
      .getHolographicInteractor().getType().equalsIgnoreCase("HolographicDisplays")) {
    BedwarsRel.getInstance().getHolographicInteractor().unloadAllHolograms(player);
  }

  if (BedwarsRel.getInstance().statisticsEnabled()) {
    BedwarsRel.getInstance().getPlayerStatisticManager().unloadStatistic(player);
  }

  Game g = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (g == null) {
    return;
  }

  g.playerLeave(player, false);
}
 
Example 13
Source File: PlayerQuit.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onJoin(PlayerQuitEvent event)
{
	Player player = event.getPlayer();
	
	manageUser(player);
	modeCoordinator.removeMode(player);
	vanishHandler.removeVanish(player);
	ticketHandler.removeTicket(ticketHandler.getTicketByUuid(player.getUniqueId()), "", TicketCloseReason.QUIT);
}
 
Example 14
Source File: Trade.java    From TradePlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onQuit(PlayerQuitEvent event) {
  Player p = event.getPlayer();
  if (p.equals(player1) || p.equals(player2)) {
    p.closeInventory();
  }
}
 
Example 15
Source File: PlayerListener.java    From WorldEditSelectionVisualizer with MIT License 4 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
    Player player = e.getPlayer();

    plugin.unloadPlayer(player);
}
 
Example 16
Source File: CreativeModeListener.java    From ShopChest with MIT License 4 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
    // Reset game mode on quit if SelectClickType is set
    Player p = e.getPlayer();
    ClickType.removePlayerClickType(p);
}
 
Example 17
Source File: GUIListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onQuit(PlayerQuitEvent e) {
    Player player = e.getPlayer();
    String playerName = player.getName();
    GUIManager.getMap().remove(playerName);
}
 
Example 18
Source File: PlayerJoinLeaveListener.java    From DiscordSRV with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler //priority needs to be different to MONITOR to avoid problems with permissions check when PEX is used
public void PlayerQuitEvent(PlayerQuitEvent event) {
    MessageFormat messageFormat = DiscordSRV.getPlugin().getMessageFromConfiguration("MinecraftPlayerLeaveMessage");

    // make sure quit messages enabled
    if (messageFormat == null) return;

    final Player player = event.getPlayer();
    final String name = player.getName();

    // no quit message, user shouldn't have one from permission
    if (GamePermissionUtil.hasPermission(event.getPlayer(), "discordsrv.silentquit")) {
        DiscordSRV.info(LangUtil.InternalMessage.SILENT_QUIT.toString()
                .replace("{player}", name)
        );
        return;
    }

    final String displayName = StringUtils.isNotBlank(player.getDisplayName()) ? player.getDisplayName() : "";
    final String message = StringUtils.isNotBlank(event.getQuitMessage()) ? event.getQuitMessage() : "";

    String avatarUrl = DiscordSRV.getPlugin().getEmbedAvatarUrl(event.getPlayer());
    String botAvatarUrl = DiscordUtil.getJda().getSelfUser().getEffectiveAvatarUrl();
    String botName = DiscordSRV.getPlugin().getMainGuild() != null ? DiscordSRV.getPlugin().getMainGuild().getSelfMember().getEffectiveName() : DiscordUtil.getJda().getSelfUser().getName();

    BiFunction<String, Boolean, String> translator = (content, needsEscape) -> {
        if (content == null) return null;
        content = content
                .replaceAll("%time%|%date%", TimeUtil.timeStamp())
                .replace("%message%", DiscordUtil.strip(needsEscape ? DiscordUtil.escapeMarkdown(message) : message))
                .replace("%username%", DiscordUtil.strip(needsEscape ? DiscordUtil.escapeMarkdown(name) : name))
                .replace("%displayname%", DiscordUtil.strip(needsEscape ? DiscordUtil.escapeMarkdown(displayName) : displayName))
                .replace("%embedavatarurl%", avatarUrl)
                .replace("%botavatarurl%", botAvatarUrl)
                .replace("%botname%", botName);
        content = PlaceholderUtil.replacePlaceholdersToDiscord(content, player);
        return content;
    };

    Message discordMessage = DiscordSRV.getPlugin().translateMessage(messageFormat, translator);
    if (discordMessage == null) return;

    String webhookName = translator.apply(messageFormat.getWebhookName(), true);
    String webhookAvatarUrl = translator.apply(messageFormat.getWebhookAvatarUrl(), true);

    // player doesn't have silent quit, show quit message
    if (messageFormat.isUseWebhooks()) {
        WebhookUtil.deliverMessage(DiscordSRV.getPlugin().getMainTextChannel(), webhookName, webhookAvatarUrl,
                discordMessage.getContentRaw(), discordMessage.getEmbeds().stream().findFirst().orElse(null));
    } else {
        DiscordUtil.queueMessage(DiscordSRV.getPlugin().getMainTextChannel(), discordMessage);
    }
}
 
Example 19
Source File: StatsMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
  Player player = event.getPlayer();
  if (allPlayerStats.containsKey(player.getUniqueId()))
    cachedUsernames.put(player.getUniqueId(), player.getName());
}
 
Example 20
Source File: ListenerUntagger.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority=EventPriority.LOWEST, ignoreCancelled=true)
public void onQuit(PlayerQuitEvent e) {
    Player player = e.getPlayer();
    ICombatManager combatManager = this.plugin.getCombatManager();
    combatManager.untag(player, PlayerUntagEvent.UntagReason.QUIT);
}