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

The following examples show how to use org.bukkit.event.player.PlayerQuitEvent#getQuitMessage() . 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: 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 2
Source File: NickNamerPlugin.java    From NickNamer with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void on(final PlayerQuitEvent event) {
	if (PlayerQuitReplacementEvent.getHandlerList().getRegisteredListeners().length > 0) {
		final String message = event.getQuitMessage();
		Set<String> nickedPlayerNames = NickNamerAPI.getNickedPlayerNames();
		String replacedMessage = NickNamerAPI.replaceNames(message, nickedPlayerNames, new NameReplacer() {
			@Override
			public String replace(String original) {
				Player player = Bukkit.getPlayer(original);
				if (player != null) {
					PlayerQuitReplacementEvent replacementEvent = new PlayerQuitReplacementEvent(player, Bukkit.getOnlinePlayers(), message, original, original);
					Bukkit.getPluginManager().callEvent(replacementEvent);
					if (replacementEvent.isCancelled()) { return original; }
					return replacementEvent.getReplacement();
				}
				return original;
			}
		}, true);
		event.setQuitMessage(replacedMessage);
	}
}
 
Example 3
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 4
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);
    }
}