done (untested code)

This commit is contained in:
grng 2024-07-25 00:41:36 +01:00
parent 08cfd82d09
commit d10e195b35
2 changed files with 10 additions and 32 deletions

View file

@ -15,7 +15,7 @@ import rip.iwakura.civilcore.types.DbPlayer;
public class PlayerHandler implements Listener { public class PlayerHandler implements Listener {
private CivilCore civilCore = null; private final CivilCore civilCore;
public PlayerHandler(CivilCore civilCore) { public PlayerHandler(CivilCore civilCore) {
this.civilCore = civilCore; this.civilCore = civilCore;
@ -33,7 +33,7 @@ public class PlayerHandler implements Listener {
String prefix = (inTeamChat ? ChatColor.DARK_BLUE + "TC " + ChatColor.RESET : "") String prefix = (inTeamChat ? ChatColor.DARK_BLUE + "TC " + ChatColor.RESET : "")
+ (dbPlayer.team.prefix == null ? + (dbPlayer.team.prefix == null ?
"" : "" :
ChatColor.translateAlternateColorCodes('&', dbPlayer.team.prefix) + " "); ChatColor.translateAlternateColorCodes('&', "[" + dbPlayer.team.prefix + "]") + " ");
String message = String.format("%s%s: %s", prefix, player_name, e.getMessage()); String message = String.format("%s%s: %s", prefix, player_name, e.getMessage());
if (!inTeamChat) { if (!inTeamChat) {

View file

@ -1,61 +1,39 @@
package rip.iwakura.civilcore.commands; package rip.iwakura.civilcore.commands;
import java.sql.SQLException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerEvent;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
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 rip.iwakura.civilcore.types.Team; import java.util.Objects;
public class TeamChatCommand implements CommandExecutor { public class TeamChatCommand implements CommandExecutor {
private CivilCore civilCore = null; private final CivilCore civilCore;
public TeamChatCommand(CivilCore civilCore) { public TeamChatCommand(CivilCore civilCore) {
this.civilCore = civilCore; this.civilCore = civilCore;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
args = Utils.parser(args).toArray(new String[0]); args = Objects.requireNonNull(Utils.parser(args)).toArray(new String[0]);
if (!(sender instanceof Player)) return true;
Player p = (Player) sender;
/*if (civilCore.teamChatRegister.contains(p)) {
civilCore.teamChatRegister.remove(p);
p.sendMessage(ChatColor.GREEN + "You are now in the " + ChatColor.GOLD + "GLOBAL" + ChatColor.GREEN + " channel");
return true;
}
if (civilCore.db.getPlayerByName(p.getName()).team.name == null) {
p.sendMessage(ChatColor.RED + "You aren't in a team :(");
return true;
}
civilCore.teamChatRegister.add(p);
p.sendMessage(ChatColor.GREEN + "You are now in the " + ChatColor.GOLD + "TEAM" + ChatColor.GREEN + " channel");*/
// /c [msg] -> if team chat toggled: broadcast to global chat, if global chat toggled send to team
// /tc or /c -> switch between global chat & team chat
if (!(sender instanceof Player p)) return true;
if (args.length == 0) { if (args.length == 0) {
if (civilCore.teamChatRegister.contains(p)) { if (civilCore.teamChatRegister.contains(p)) {
civilCore.teamChatRegister.remove(p); civilCore.teamChatRegister.remove(p);
p.sendMessage(ChatColor.GREEN + "You are now in the " + ChatColor.GOLD + "GLOBAL" + ChatColor.GREEN + " channel"); p.sendMessage(ChatColor.GREEN + "You are now in the " + ChatColor.GOLD + "GLOBAL" + ChatColor.GREEN + " channel");
return true;
} else { } else {
civilCore.teamChatRegister.add(p); civilCore.teamChatRegister.add(p);
p.sendMessage(ChatColor.GREEN + "You are now in the " + ChatColor.GOLD + "TEAM" + ChatColor.GREEN + " channel"); p.sendMessage(ChatColor.GREEN + "You are now in the " + ChatColor.GOLD + "TEAM" + ChatColor.GREEN + " channel");
return true;
} }
return true;
} }
String message = String.join(" ", args); String message = String.join(" ", args);