From f204277ff86adad2910bd7ae0b19354655e3cdf8 Mon Sep 17 00:00:00 2001 From: 778b Date: Sun, 27 Nov 2022 03:19:40 +0400 Subject: [PATCH] Fixed Clan chat commands --- .../lofrol/UselessClan/ClanManager.java | 36 +++++++++++++------ .../UselessClan/ClanObjects/ClanMember.java | 9 ----- .../ClanObjects/OnlinePlayerClan.java | 9 ++++- .../External/UselessClanPlaceholder.java | 2 +- .../Listeners/UselessListeners.java | 2 +- .../UselessClan/commands/ClanChatCommand.java | 17 ++++----- 6 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanManager.java b/src/main/java/io/github/lofrol/UselessClan/ClanManager.java index 0f2365d..76112e2 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanManager.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanManager.java @@ -8,6 +8,7 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitTask; import java.io.File; import java.io.FileFilter; @@ -36,7 +37,7 @@ public class ClanManager { private final UselessClan OwnerPlugin; - private final Map OnlineClanPlayers; + private final Map OnlineClanPlayers; private final Map ServerClans; public ClanManager(UselessClan owner) { @@ -46,6 +47,16 @@ public ClanManager(UselessClan owner) { OwnerPlugin = owner; } + public static String ClanRoleSolver(ClanRole role) { + return switch (role) { + case ROOKIE -> "/"; + case MEMBER -> "//"; + case OFFICER -> "+"; + case LEADER -> "#"; + default -> ""; + }; + } + public void LoadClans() { try { File tempDir = checkPluginFolderOrCreate(); @@ -126,7 +137,7 @@ private File checkPluginFolderOrCreate() { public Map getServerClans() { return ServerClans; } - public Map getOnlineClanPlayers() { + public Map getOnlineClanPlayers() { return OnlineClanPlayers; } public Clan getClanByName(String nameOfClan) { @@ -161,24 +172,29 @@ public void OnPlayerJoin(Player player) { ClanMember tempMember = new ClanMember(playerRole, player.getName()); tempClan.getOnlineMembers().put(player, tempMember); - OnlinePlayerClan tempClanPlayer = new OnlinePlayerClan(tempClan); - OnlineClanPlayers.put(player, tempClanPlayer); + OnlinePlayerClan tempClanPlayer = new OnlinePlayerClan(tempClan, player); + OnlineClanPlayers.put(player.getName(), tempClanPlayer); - if (playerRole == ClanRole.LEADER || playerRole == ClanRole.OFFICER) { - ChatSender.MessageTo(player,"UselessClan", - String.format("Your clan have %d requests for join! ./clan requests", tempClan.getRequestCount())); + getServer().getScheduler().runTaskLater(OwnerPlugin, new Runnable() { + @Override + public void run() { + if (playerRole == ClanRole.LEADER || playerRole == ClanRole.OFFICER) { + ChatSender.MessageTo(player,"UselessClan", + String.format("Your clan have %d requests for join! ./clan requests", tempClan.getRequestCount())); + } + } } - + , 200); OwnerPlugin.getLogger().log(Level.INFO, String.format( "Clan member %s Join to server, his clan is %s", player.getName(), tempClan.getNameClan())); } public void OnPlayerLeave(Player player) { - OnlinePlayerClan tempOnlinePlayer = OnlineClanPlayers.get(player); + OnlinePlayerClan tempOnlinePlayer = OnlineClanPlayers.get(player.getName()); if (tempOnlinePlayer == null) return; tempOnlinePlayer.getPlayerClan().getOnlineMembers().remove(player); - OnlineClanPlayers.remove(player); + OnlineClanPlayers.remove(player.getName()); OwnerPlugin.getLogger().log(Level.INFO, String.format("Clan member %s leaved from server", player.getName())); } diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanObjects/ClanMember.java b/src/main/java/io/github/lofrol/UselessClan/ClanObjects/ClanMember.java index c7340ce..fbbb13c 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanObjects/ClanMember.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanObjects/ClanMember.java @@ -39,13 +39,4 @@ public void addGeneralPlayerDeposit(Double generalPlayerDeposit) { GeneralPlayerDeposit += generalPlayerDeposit; } - public static String ClanRoleSolver(ClanRole role) { - return switch (role) { - case ROOKIE -> "-"; - case MEMBER -> "="; - case OFFICER -> "+"; - case LEADER -> "++"; - default -> ""; - }; - } } diff --git a/src/main/java/io/github/lofrol/UselessClan/ClanObjects/OnlinePlayerClan.java b/src/main/java/io/github/lofrol/UselessClan/ClanObjects/OnlinePlayerClan.java index 45c5b40..96cc23c 100644 --- a/src/main/java/io/github/lofrol/UselessClan/ClanObjects/OnlinePlayerClan.java +++ b/src/main/java/io/github/lofrol/UselessClan/ClanObjects/OnlinePlayerClan.java @@ -1,15 +1,22 @@ package io.github.lofrol.UselessClan.ClanObjects; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; public class OnlinePlayerClan { private Clan PlayerClan = null; + private Player PlayerObj = null; - public OnlinePlayerClan(@NotNull Clan playerClan) { + public OnlinePlayerClan(@NotNull Clan playerClan, @NotNull Player player) { PlayerClan = playerClan; + PlayerObj = player; } public Clan getPlayerClan() { return PlayerClan; } + + public Player getPlayerObj() { + return PlayerObj; + } } diff --git a/src/main/java/io/github/lofrol/UselessClan/External/UselessClanPlaceholder.java b/src/main/java/io/github/lofrol/UselessClan/External/UselessClanPlaceholder.java index 369996e..9273bd4 100644 --- a/src/main/java/io/github/lofrol/UselessClan/External/UselessClanPlaceholder.java +++ b/src/main/java/io/github/lofrol/UselessClan/External/UselessClanPlaceholder.java @@ -58,7 +58,7 @@ else if (params.equalsIgnoreCase("role")) { Clan tempClan = OwnerPlugin.getMainManager().FindClanToPlayer(player.getName()); if (tempClan == null) return ""; ClanMember tempMember = tempClan.getClanMember(player.getName()); - return String.format("&r[&6%s&r]", ClanMember.ClanRoleSolver(tempMember.getMemberRole())); + return String.format("&r[&6%s&r]", ClanManager.ClanRoleSolver(tempMember.getMemberRole())); } else if (params.equalsIgnoreCase("clanlevel")) { Clan tempClan = OwnerPlugin.getMainManager().FindClanToPlayer(player.getName()); diff --git a/src/main/java/io/github/lofrol/UselessClan/Listeners/UselessListeners.java b/src/main/java/io/github/lofrol/UselessClan/Listeners/UselessListeners.java index 9d335c7..7ae2ae4 100644 --- a/src/main/java/io/github/lofrol/UselessClan/Listeners/UselessListeners.java +++ b/src/main/java/io/github/lofrol/UselessClan/Listeners/UselessListeners.java @@ -25,7 +25,7 @@ public UselessListeners(UselessClan owner) { @EventHandler(priority = EventPriority.MONITOR) public void PlayerJoin(PlayerJoinEvent event) { - getServer().getScheduler().runTaskLater(OwnerPlugin, bukkitTask -> OwnerPlugin.getMainManager().OnPlayerJoin(event.getPlayer()), 200); + OwnerPlugin.getMainManager().OnPlayerJoin(event.getPlayer()); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/src/main/java/io/github/lofrol/UselessClan/commands/ClanChatCommand.java b/src/main/java/io/github/lofrol/UselessClan/commands/ClanChatCommand.java index 5f7a034..62b9461 100644 --- a/src/main/java/io/github/lofrol/UselessClan/commands/ClanChatCommand.java +++ b/src/main/java/io/github/lofrol/UselessClan/commands/ClanChatCommand.java @@ -43,30 +43,27 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab int size = args.length; if (size == 0) return false; - OnlinePlayerClan SenderClan = ManagerPtr.getOnlineClanPlayers().get(tempPlayer); + OnlinePlayerClan SenderClan = ManagerPtr.getOnlineClanPlayers().get(tempPlayer.getName()); if (SenderClan.getPlayerClan().getOnlineMembers().size() < 2) { - tempPlayer.sendMessage(ChatColor.GOLD + "0 Players in your clan."); + tempPlayer.sendMessage(ChatColor.GOLD + "0 Online Players in your clan."); return false; } // Only $maxLength length of message alloyed - String MegaString = ""; + StringBuilder MegaString = new StringBuilder(); int currentLength = 0; int maxLength = 200; for (String tempString : args) { currentLength += tempString.length(); if (currentLength > maxLength) { int rest = currentLength - maxLength; - MegaString += " " + tempString.substring(0, rest); + MegaString.append(" " ).append(tempString, 0, rest); break; } - MegaString += " " + tempString; + MegaString.append(" " ).append(tempString); } - for (Player OutputPlayer: SenderClan.getPlayerClan().getOnlineMembers().keySet()) { - OutputPlayer.sendMessage(ChatColor.GOLD + MegaString); - } - - + SenderClan.getPlayerClan().SendMessageForOnlinePlayers( + String.format("&6%s &2->&b %s",tempPlayer.getName() ,MegaString.toString())); return true; } }