From bcec9aab9b9b2848b9de412b6265b8d4ff9d03a7 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 27 Jan 2021 17:50:02 +0100 Subject: [PATCH] Add Tablist support --- src/de/steamwar/misslewars/Config.java | 8 +++++++ src/de/steamwar/misslewars/MWTeam.java | 23 +++++++++++-------- .../listener/ConnectionListener.java | 3 +++ .../misslewars/listener/JoinListener.java | 4 ++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/de/steamwar/misslewars/Config.java b/src/de/steamwar/misslewars/Config.java index b56c7cc..dbd5fff 100644 --- a/src/de/steamwar/misslewars/Config.java +++ b/src/de/steamwar/misslewars/Config.java @@ -54,6 +54,8 @@ public class Config { public static final UUID BlueLeader; public static final UUID RedLeader; + private static final int EventKampfID; + static { File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); if (!configfile.exists()) { @@ -98,10 +100,16 @@ public class Config { RedLeader = UUID.fromString(redLeader); else RedLeader = null; + + EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); } public static boolean isChallenge() { return BlueLeader != null && RedLeader != null; } + public static boolean test(){ + return EventKampfID == -1; + } + } diff --git a/src/de/steamwar/misslewars/MWTeam.java b/src/de/steamwar/misslewars/MWTeam.java index e2042b1..25a2656 100644 --- a/src/de/steamwar/misslewars/MWTeam.java +++ b/src/de/steamwar/misslewars/MWTeam.java @@ -19,10 +19,9 @@ package de.steamwar.misslewars; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import de.steamwar.comms.packets.TablistNamePacket; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.*; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -57,7 +56,7 @@ public class MWTeam { private final LinkedList players = new LinkedList<>(); private final Set openInvitations = new HashSet<>(); - + MWTeam(ChatColor color, Location spawn, String teamName, int portalZ) { this.teamName = teamName; this.color = color; @@ -122,8 +121,11 @@ public class MWTeam { p.setDisplayName(color + p.getName()); if (MissileWars.getFightState() == FightState.WAITING && !enemy().players.isEmpty()) MissileWars.startRound(); + + if (!Config.test()) + Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(p.getUniqueId()).getId(), color + p.getName()).send(p), 5); } - + public void leave(Player p) { if (!players.contains(p)) return; @@ -132,6 +134,9 @@ public class MWTeam { sbteam.removePlayer(p); if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING) MissileWars.end(WinReasons.NO_ENEMY, enemy()); + + if (!Config.test()) + new TablistNamePacket(SteamwarUser.get(p.getUniqueId()).getId(), "§7§o" + p.getName()).send(p); } public void invitePlayer(Player p) { @@ -143,18 +148,18 @@ public class MWTeam { removeInvitations(p); join(p); } - + private MWTeam enemy() { if (this == MissileWars.getRedTeam()) return MissileWars.getBlueTeam(); return MissileWars.getRedTeam(); } - + public String getColorCode(){ return "§" + color.getChar(); } - + public boolean hasPlayer(Player p) { return players.contains(p); } diff --git a/src/de/steamwar/misslewars/listener/ConnectionListener.java b/src/de/steamwar/misslewars/listener/ConnectionListener.java index 7e42772..aa3205b 100644 --- a/src/de/steamwar/misslewars/listener/ConnectionListener.java +++ b/src/de/steamwar/misslewars/listener/ConnectionListener.java @@ -19,9 +19,12 @@ package de.steamwar.misslewars.listener; +import de.steamwar.comms.packets.TablistNamePacket; +import de.steamwar.misslewars.Config; import de.steamwar.misslewars.FightState; import de.steamwar.misslewars.MWTeam; import de.steamwar.misslewars.MissileWars; +import de.steamwar.sql.SteamwarUser; import org.bukkit.GameMode; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; diff --git a/src/de/steamwar/misslewars/listener/JoinListener.java b/src/de/steamwar/misslewars/listener/JoinListener.java index 96a5b53..ecac885 100644 --- a/src/de/steamwar/misslewars/listener/JoinListener.java +++ b/src/de/steamwar/misslewars/listener/JoinListener.java @@ -19,9 +19,11 @@ package de.steamwar.misslewars.listener; +import de.steamwar.comms.packets.TablistNamePacket; import de.steamwar.misslewars.Config; import de.steamwar.misslewars.FightState; import de.steamwar.misslewars.MissileWars; +import de.steamwar.sql.SteamwarUser; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerJoinEvent; @@ -37,6 +39,8 @@ public class JoinListener extends BasicListener { @EventHandler(priority = EventPriority.HIGHEST) public void onJoin(PlayerJoinEvent e){ e.setJoinMessage("§a» " + e.getPlayer().getDisplayName()); + if (!Config.test()) + new TablistNamePacket(SteamwarUser.get(e.getPlayer().getUniqueId()).getId(), "§7" + e.getPlayer().getName()).send(e.getPlayer()); if (Config.isChallenge()) { if (Config.RedLeader.equals(e.getPlayer().getUniqueId())) { MissileWars.getRedTeam().join(e.getPlayer());