diff --git a/src/main/java/me/ShermansWorld/AlathraWar/Raid.java b/src/main/java/me/ShermansWorld/AlathraWar/Raid.java index bfeb0c2..787df9c 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/Raid.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/Raid.java @@ -979,7 +979,12 @@ public void setupDisplayBar() { } public void deleteDisplayBar() { + BossBar bossBar = Bukkit.getBossBar(bossBarKey); + if (bossBar != null) { + bossBar.removeAll(); + } Bukkit.removeBossBar(bossBarKey); + } public BossBar createNewDisplayBar() { diff --git a/src/main/java/me/ShermansWorld/AlathraWar/Siege.java b/src/main/java/me/ShermansWorld/AlathraWar/Siege.java index cf7aa80..6e409ca 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/Siege.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/Siege.java @@ -1,22 +1,22 @@ package me.ShermansWorld.AlathraWar; import com.palmergames.bukkit.towny.exceptions.TownyException; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; +import org.bukkit.*; import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.TownyUniverse; import com.palmergames.bukkit.towny.TownyAPI; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.object.WorldCoord; import me.ShermansWorld.AlathraWar.data.SiegeData; -import org.bukkit.Bukkit; -import org.bukkit.Location; import java.util.ArrayList; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownBlock; @@ -38,6 +38,8 @@ public class Siege { public ArrayList attackerPlayers; public ArrayList defenderPlayers; public ArrayList beaconLocs; + public final NamespacedKey bossBarKey; + public Siege(final War war, final Town town, OfflinePlayer siegeLeader) { this.siegeTicks = 0; @@ -48,6 +50,9 @@ public Siege(final War war, final Town town, OfflinePlayer siegeLeader) { this.war = war; this.town = town; this.siegeLeader = siegeLeader; + + bossBarKey = new NamespacedKey(Main.getInstance(), "siegeBar." + this.getName()); + if (war.getSide(town.getName()) == 2) side1AreAttackers = true; else side1AreAttackers = false; } @@ -198,19 +203,30 @@ public void run() { save(); } } + + refreshDisplayBar(); } + + }, 0L, 200L); + + setupDisplayBar(); } /** Resumes a siege (after a server restart e.t.c.)*/ public void resume(int resumeTick) { - siegeTicks = resumeTick; + + siegeTicks = resumeTick; + + setupDisplayBar(); } /** Stops a siege */ public void stop() { + deleteDisplayBar(); Bukkit.getScheduler().cancelTask(this.bukkitId[0]); SiegeData.removeSiege(this); + } public void attackersWin(final OfflinePlayer siegeLeader) { @@ -434,6 +450,59 @@ public String getDefenderSide() { } } + public void refreshDisplayBar() { + BossBar bossBar = Bukkit.getBossBar(bossBarKey); + if(bossBar == null) bossBar = createNewDisplayBar(); + + bossBar.setTitle(String.format("%d -- Attackers -Siege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints)); + bossBar.setProgress((double) (this.attackerPoints + 0.5D) / ((this.attackerPoints + this.defenderPoints) + 1.0D)); + + for (String s : this.getAttackerPlayers()) { + Player p = Bukkit.getPlayer(s); + if (p != null) { + if(!bossBar.getPlayers().contains(p)) bossBar.addPlayer(p); + } + } + + for (String s : this.getDefenderPlayers()) { + Player p = Bukkit.getPlayer(s); + if (p != null) { + if(!bossBar.getPlayers().contains(p)) bossBar.addPlayer(p); + } + } + } + + public void setupDisplayBar() { + BossBar bossBar = Bukkit.getBossBar(bossBarKey); + if(bossBar == null) bossBar = createNewDisplayBar(); + + for (String s : this.getAttackerPlayers()) { + Player p = Bukkit.getPlayer(s); + if (p != null) { + bossBar.addPlayer(p); + } + } + + for (String s : this.getDefenderPlayers()) { + Player p = Bukkit.getPlayer(s); + if (p != null) bossBar.addPlayer(p); + } + } + + public void deleteDisplayBar() { + BossBar bossBar = Bukkit.getBossBar(bossBarKey); + if (bossBar != null) { + bossBar.removeAll(); + } + Bukkit.removeBossBar(bossBarKey); + + } + + + public BossBar createNewDisplayBar() { + return Bukkit.createBossBar(bossBarKey, String.format("%d -- Attackers -Siege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints), BarColor.YELLOW, BarStyle.SOLID); + } + public int getAttackerPoints() { return this.attackerPoints; } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminCommands.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminCommands.java index 4e65a2c..ce3c812 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminCommands.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminCommands.java @@ -588,7 +588,7 @@ private static boolean info(Player p, String[] args) { if(attackers.length() > 2) attackers = new StringBuilder(attackers.substring(0, attackers.length() - 2)); p.sendMessage(Helper.Chatlabel() + "Attacking Players: " + attackers); StringBuilder defenders = new StringBuilder(); - for (String pl : s.getAttackerPlayers()) { + for (String pl : s.getDefenderPlayers()) { defenders.append(pl); defenders.append(", "); } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/data/SiegeData.java b/src/main/java/me/ShermansWorld/AlathraWar/data/SiegeData.java index e2913ce..c8d9fe7 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/data/SiegeData.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/data/SiegeData.java @@ -127,6 +127,7 @@ public static ArrayList createSieges(War war, Collection