Skip to content

Commit

Permalink
Fixed Clan chat commands
Browse files Browse the repository at this point in the history
  • Loading branch information
778b committed Nov 26, 2022
1 parent 3e584be commit f204277
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 32 deletions.
36 changes: 26 additions & 10 deletions src/main/java/io/github/lofrol/UselessClan/ClanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class ClanManager {

private final UselessClan OwnerPlugin;

private final Map<Player, OnlinePlayerClan> OnlineClanPlayers;
private final Map<String, OnlinePlayerClan> OnlineClanPlayers;
private final Map<String, Clan> ServerClans;

public ClanManager(UselessClan owner) {
Expand All @@ -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();
Expand Down Expand Up @@ -126,7 +137,7 @@ private File checkPluginFolderOrCreate() {
public Map<String, Clan> getServerClans() {
return ServerClans;
}
public Map<Player, OnlinePlayerClan> getOnlineClanPlayers() {
public Map<String, OnlinePlayerClan> getOnlineClanPlayers() {
return OnlineClanPlayers;
}
public Clan getClanByName(String nameOfClan) {
Expand Down Expand Up @@ -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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> "";
};
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit f204277

Please sign in to comment.