/tc <message> doesnt work

This commit is contained in:
grng 2024-07-25 11:16:52 +01:00
parent 160677ff82
commit 6dec52a317

View file

@ -10,7 +10,9 @@ import net.md_5.bungee.api.ChatColor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import rip.iwakura.civilcore.Utils; import rip.iwakura.civilcore.Utils;
import rip.iwakura.civilcore.CivilCore; import rip.iwakura.civilcore.CivilCore;
import rip.iwakura.civilcore.types.DbPlayer;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class TeamChatCommand implements CommandExecutor { public class TeamChatCommand implements CommandExecutor {
@ -20,6 +22,14 @@ public class TeamChatCommand implements CommandExecutor {
this.civilCore = civilCore; this.civilCore = civilCore;
} }
private String getPrefix(String name, boolean inTeamChat) {
DbPlayer dbPlayer = civilCore.db.getPlayerByName(name);
return (inTeamChat ? ChatColor.DARK_GREEN + "TEAM >" + ChatColor.RESET : "")
+ (dbPlayer.team.prefix == null ?
"" :
ChatColor.translateAlternateColorCodes('&', inTeamChat ? "" : "[" + dbPlayer.team.prefix + "]"));
}
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
args = Objects.requireNonNull(Utils.parser(args)).toArray(new String[0]); args = Objects.requireNonNull(Utils.parser(args)).toArray(new String[0]);
@ -37,18 +47,52 @@ public class TeamChatCommand implements CommandExecutor {
} }
String message = String.join(" ", args); String message = String.join(" ", args);
if (civilCore.teamChatRegister.contains(p)) {
String player_name = p.getName();
boolean inTeamChat = civilCore.teamChatRegister.contains(p);
DbPlayer dbPlayer = civilCore.db.getPlayerByName(player_name);
/*String prefix = (inTeamChat ? ChatColor.DARK_GREEN + "TEAM >" + ChatColor.RESET : "")
+ (dbPlayer.team.prefix == null ?
"" :
ChatColor.translateAlternateColorCodes('&', inTeamChat ? "" : "[" + dbPlayer.team.prefix + "]"));*/
/*if (civilCore.teamChatRegister.contains(p)) {
civilCore.teamChatRegister.remove(p); civilCore.teamChatRegister.remove(p);
Bukkit.broadcastMessage(ChatColor.DARK_GREEN + "TEAM > " + ChatColor.GREEN + p.getName() + ": " + message); // Bukkit.broadcastMessage(ChatColor.DARK_GREEN + "TEAM > " + ChatColor.GREEN + p.getName() + ": " + message);
String formatted = String.format("%s%s: %s", getPrefix(player_name, inTeamChat) + " ", player_name, message);
Bukkit.broadcastMessage(formatted);
civilCore.teamChatRegister.add(p); civilCore.teamChatRegister.add(p);
} else { } else {
civilCore.teamChatRegister.add(p); civilCore.teamChatRegister.add(p);
Bukkit.broadcastMessage(p.getName() + ": " + message); String formatted = String.format("%s%s: %s", getPrefix(player_name, inTeamChat) + " ", player_name, message);
Bukkit.broadcastMessage(formatted);
civilCore.teamChatRegister.remove(p);
}*/
String formatted = String.format("%s%s: %s", getPrefix(player_name, inTeamChat) + " ", player_name, message);
if (!inTeamChat) {
civilCore.teamChatRegister.remove(p);
Bukkit.broadcastMessage(formatted);
civilCore.teamChatRegister.add(p);
} else {
civilCore.teamChatRegister.add(p);
List<DbPlayer> players = civilCore.db.getPlayersInTeam(dbPlayer.team.name);
if (players == null) return true;
for (DbPlayer team_dbp : players) {
Player team_p = Bukkit.getPlayer(team_dbp.name);
if (team_p == null) continue;
team_p.sendMessage(message);
}
civilCore.teamChatRegister.remove(p); civilCore.teamChatRegister.remove(p);
} }
return true; return true;
} }
} }