/
minecraftbackup
/
AnarchyExploitFixes
Обзор
Документация
Войти
/
minecraftbackup
/
AnarchyExploitFixes
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/misc/JoinLeaveMessages.java
84 строки
4 KB
Ginko
2.7.2 release (#233)
13 авг 2024, 08:21
Не верифицирован
13 авг 2024, 08:21
d20da6e
Код
Авторство
О чём код?
package me.xginko.aef.modules.misc; import me.xginko.aef.AnarchyExploitFixes; import me.xginko.aef.enums.AEFPermission; import me.xginko.aef.modules.AEFModule; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; public class JoinLeaveMessages extends AEFModule implements Listener { private final boolean showInConsole, firstJoinEnabled; public JoinLeaveMessages() { super("misc.join-leave-messages"); config.addComment(configPath + ".enable", "If you want to hide yourself or someone else when logging\n" + "into the game, use these permissions:\n" + AEFPermission.SILENT_JOIN.string() + ", " + AEFPermission.SILENT_LEAVE.string()); this.showInConsole = config.getBoolean(configPath + ".show-in-console", false); this.firstJoinEnabled = config.getBoolean(configPath + ".first-join-messages.enable", false); } @Override public void enable() { plugin.getServer().getPluginManager().registerEvents(this, plugin); } @Override public boolean shouldEnable() { return config.getBoolean(configPath + ".enable", true); } @Override public void disable() { HandlerList.unregisterAll(this); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerJoinEvent(PlayerJoinEvent event) { event.setJoinMessage(null); final Player joiningPlayer = event.getPlayer(); if (joiningPlayer.hasPermission(AEFPermission.SILENT_JOIN.string())) return; if (firstJoinEnabled && !joiningPlayer.hasPlayedBefore()) return; for (final Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { AnarchyExploitFixes.getDatastore().getJoinLeaveEnabled(onlinePlayer.getUniqueId()).thenAccept(enabled -> { if (enabled) { onlinePlayer.sendMessage(AnarchyExploitFixes.getLang(onlinePlayer.getLocale()).misc_joinMessage .replace("%player%", joiningPlayer.getName())); } }); } if (showInConsole) AnarchyExploitFixes.unprefixedLogger().info("{} ({})", AnarchyExploitFixes.getLang(joiningPlayer.getLocale()).misc_joinMessage .replace("%player%", joiningPlayer.getName()), joiningPlayer.getLocale()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerLeaveEvent(PlayerQuitEvent event) { event.setQuitMessage(null); final Player leavingPlayer = event.getPlayer(); if (leavingPlayer.hasPermission(AEFPermission.SILENT_LEAVE.string())) return; for (final Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { if (onlinePlayer.getUniqueId().equals(leavingPlayer.getUniqueId())) continue; AnarchyExploitFixes.getDatastore().getJoinLeaveEnabled(onlinePlayer.getUniqueId()).thenAccept(enabled -> { if (enabled) { onlinePlayer.sendMessage(AnarchyExploitFixes.getLang(onlinePlayer.getLocale()).misc_leaveMessage .replace("%player%", leavingPlayer.getName())); } }); } if (showInConsole) AnarchyExploitFixes.unprefixedLogger().info("{} ({})", AnarchyExploitFixes.getLang(leavingPlayer.getLocale()).misc_leaveMessage .replace("%player%", leavingPlayer.getName()), leavingPlayer.getLocale()); } }