Skip to content

Commit

Permalink
Final Tweaks for Admin/Display
Browse files Browse the repository at this point in the history
  • Loading branch information
AubriTheHuman committed Apr 27, 2023
1 parent 2dbfcdb commit 395e374
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/main/java/me/ShermansWorld/AlathraWar/Raid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
81 changes: 75 additions & 6 deletions src/main/java/me/ShermansWorld/AlathraWar/Siege.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -38,6 +38,8 @@ public class Siege {
public ArrayList<String> attackerPlayers;
public ArrayList<String> defenderPlayers;
public ArrayList<Location> beaconLocs;
public final NamespacedKey bossBarKey;


public Siege(final War war, final Town town, OfflinePlayer siegeLeader) {
this.siegeTicks = 0;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public static ArrayList<Siege> createSieges(War war, Collection<HashMap<String,
siege.addPointsToAttackers((int) map.get("attackerPoints"));
siege.addPointsToDefenders((int) map.get("defenderPoints"));
siege.resume((int) map.get("siegeTicks"));
siege.setWar(war);
returnList.add(siege);

}
Expand Down

0 comments on commit 395e374

Please sign in to comment.