Skip to content

Commit

Permalink
Merge pull request #159 from Goosius1/siege_points_rename
Browse files Browse the repository at this point in the history
Siege points rename
  • Loading branch information
Goosius1 authored Feb 27, 2021
2 parents 183ebfc + 7de1232 commit 2ecf37b
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 245 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/gmail/goosius/siegewar/SiegeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public static void saveSiege(Siege siege) {
+ "!" + siege.getFlagLocation().getX()
+ "!" + siege.getFlagLocation().getY()
+ "!" + siege.getFlagLocation().getZ());
SiegeMetaDataController.setStatus(town, siege.getStatus().toString());
SiegeMetaDataController.setPoints(town, siege.getSiegePoints());
SiegeMetaDataController.setSiegeStatus(town, siege.getStatus().toString());
SiegeMetaDataController.setSiegeBalance(town, siege.getSiegeBalance());
SiegeMetaDataController.setWarChestAmount(town, siege.getWarChestAmount());
SiegeMetaDataController.setTownPlundered(town, siege.getTownPlundered());
SiegeMetaDataController.setTownInvaded(town, siege.getTownInvaded());
Expand Down Expand Up @@ -155,11 +155,11 @@ public static boolean loadSiege(Siege siege) {
Location loc = new Location(world, x, y, z);
siege.setFlagLocation(loc);

if (SiegeMetaDataController.getStatus(town).isEmpty())
if (SiegeMetaDataController.getSiegeStatus(town).isEmpty())
return false;
siege.setStatus(SiegeStatus.parseString(SiegeMetaDataController.getStatus(town)));
siege.setStatus(SiegeStatus.parseString(SiegeMetaDataController.getSiegeStatus(town)));

siege.setSiegePoints(SiegeMetaDataController.getPoints(town));
siege.setSiegeBalance(SiegeMetaDataController.getSiegeBalance(town));
siege.setWarChestAmount(SiegeMetaDataController.getWarChestAmount(town));
siege.setTownPlundered(SiegeMetaDataController.townPlundered(town));
siege.setTownInvaded(SiegeMetaDataController.townInvaded(town));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SiegeWarAdminCommand implements CommandExecutor, TabCompleter {

private static final List<String> siegewaradminTabCompletes = Arrays.asList("immunity","reload","siege","town","nation");
private static final List<String> siegewaradminImmunityTabCompletes = Arrays.asList("town","nation","alltowns");
private static final List<String> siegewaradminSiegeTabCompletes = Arrays.asList("setpoints","end","setplundered","remove");
private static final List<String> siegewaradminSiegeTabCompletes = Arrays.asList("setbalance","end","setplundered","remove");
private static final List<String> siegewaradminTownTabCompletes = Arrays.asList("setcaptured");
private static final List<String> siegewaradminNationTabCompletes = Arrays.asList("setplundergained","setplunderlost","settownsgained","settownslost","setnationdefeats");

Expand Down Expand Up @@ -151,7 +151,7 @@ private void showHelp(CommandSender sender) {
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "immunity town [town_name] [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "immunity nation [nation_name] [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "immunity alltowns [hours]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] setpoints [points]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] setbalance [points]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] end", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] setplundered [true/false]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] remove", ""));
Expand All @@ -167,7 +167,7 @@ private void showImmunityHelp(CommandSender sender) {

private void showSiegeHelp(CommandSender sender) {
sender.sendMessage(ChatTools.formatTitle("/swa siege"));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] setpoints [points]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] setbalance [points]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] end", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] setplundered [true/false]", ""));
sender.sendMessage(ChatTools.formatCommand("Eg", "/swa", "siege [town_name] remove", ""));
Expand Down Expand Up @@ -268,7 +268,7 @@ private void parseSiegeWarSiegeCommand(CommandSender sender, String[] args) {
}

switch(args[1].toLowerCase()) {
case "setpoints":
case "setbalance":
if (args.length < 3) {
showSiegeHelp(sender);
}
Expand All @@ -280,13 +280,13 @@ private void parseSiegeWarSiegeCommand(CommandSender sender, String[] args) {
}

int newPoints = Integer.parseInt(args[2]);
siege.setSiegePoints(newPoints);
siege.setSiegeBalance(newPoints);
SiegeController.saveSiege(siege);
Messaging.sendMsg(sender, Translation.of("msg_swa_set_points_success", newPoints, town.getName()));
Messaging.sendMsg(sender, Translation.of("msg_swa_set_siege_balance_success", newPoints, town.getName()));
return;

case "end":
if (siege.getSiegePoints() < 1)
if (siege.getSiegeBalance() < 1)
DefenderWin.defenderWin(siege, siege.getDefendingTown());
else
AttackerWin.attackerWin(siege, siege.getAttackingNation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
*/
public enum SiegeWarPermissionNodes {

SIEGEWAR_NATION_SIEGE_POINTS("siegewar.nation.siege.points"),
//This permission affects battle points, but the perm currently has the older name of siege points
SIEGEWAR_NATION_BATTLE_POINTS("siegewar.nation.siege.points"),
SIEGEWAR_NATION_SIEGE_LEADERSHIP("siegewar.nation.siege.leadership"),
SIEGEWAR_NATION_SIEGE_ATTACK("siegewar.nation.siege.attack"),
SIEGEWAR_NATION_SIEGE_ABANDON("siegewar.nation.siege.abandon"),
SIEGEWAR_NATION_SIEGE_INVADE("siegewar.nation.siege.invade"),
SIEGEWAR_NATION_SIEGE_PLUNDER("siegewar.nation.siege.plunder"),
SIEGEWAR_TOWN_SIEGE_POINTS("siegewar.town.siege.points"),
//This permission affects battle points, but the perm currently has the older name of siege points
SIEGEWAR_TOWN_BATTLE_POINTS("siegewar.town.siege.points"),
SIEGEWAR_TOWN_SIEGE_SURRENDER("siegewar.town.siege.surrender"),
SIEGEWAR_TOWN_SIEGE_START_CANNON_SESSION("siegewar.town.siege.startcannonsession"),
// Siegewar related war sickness immunities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import com.gmail.goosius.siegewar.objects.Siege;
import com.gmail.goosius.siegewar.SiegeWar;
import com.gmail.goosius.siegewar.hud.SiegeWarHud;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -40,7 +39,7 @@ public static void toggleOff(Player player) {

public static void updateHUDs() {
for (Entry<Player, Siege> entry : warHudUsers.entrySet()) {
if (entry.getKey().getScoreboard().getTeam("points") == null) {
if (entry.getKey().getScoreboard().getTeam("balance") == null) {
warHudUsers.remove(entry.getKey());
continue;
} else
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/gmail/goosius/siegewar/hud/SiegeWarHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public static void updateInfo(Player p, Siege siege) {
board.getObjective("WAR_HUD_OBJ").setDisplayName(SiegeHUDManager.checkLength(Colors.Gold + "§l" + siege.getDefendingTown().getName()) + " " + Translation.of("hud_title"));
board.getTeam("attackers").setSuffix(SiegeHUDManager.checkLength(siege.getAttackingNation().getName()));
board.getTeam("defenders").setSuffix(SiegeHUDManager.checkLength(siege.getDefendingTown().getName()));
board.getTeam("points").setSuffix(siege.getSiegePoints().toString());
board.getTeam("balance").setSuffix(siege.getSiegeBalance().toString());
board.getTeam("timeRemaining").setSuffix(siege.getTimeRemaining());
board.getTeam("bannerControl").setSuffix(siege.getBannerControllingSide().name().charAt(0) + siege.getBannerControllingSide().name().substring(1).toLowerCase());
board.getTeam("batAttackerScore").setSuffix(siege.getFormattedAttackerBattleScore());
board.getTeam("batDefenderScore").setSuffix(siege.getFormattedDefenderBattleScore());
board.getTeam("batTimeRemaining").setSuffix(siege.getFormattedBattleTimeRemaining());
board.getTeam("btAttackerPoints").setSuffix(siege.getFormattedAttackerBattlePoints());
board.getTeam("btDefenderPoints").setSuffix(siege.getFormattedDefenderBattlePoints());
board.getTeam("btTimeRemaining").setSuffix(siege.getFormattedBattleTimeRemaining());
}

public static void toggleOn(Player p, Siege siege) {
Expand All @@ -36,25 +36,25 @@ public static void toggleOn(Player p, Siege siege) {

Team attackers = board.registerNewTeam("attackers"),
defenders = board.registerNewTeam("defenders"),
points = board.registerNewTeam("points"),
balance = board.registerNewTeam("balance"),
timeRemaining = board.registerNewTeam("timeRemaining"),
bannerControl = board.registerNewTeam("bannerControl"),
battleAttackerScore = board.registerNewTeam("batAttackerScore"),
battleDefenderScore = board.registerNewTeam("batDefenderScore"),
battleTimeRemaining = board.registerNewTeam("batTimeRemaining");
battleAttackerScore = board.registerNewTeam("btAttackerPoints"),
battleDefenderScore = board.registerNewTeam("btDefenderPoints"),
battleTimeRemaining = board.registerNewTeam("btTimeRemaining");

String attackers_entry = Colors.LightGray + Translation.of("hud_attackers"),
defenders_entry = Colors.LightGray + Translation.of("hud_defenders"),
points_entry = Colors.LightGray + Translation.of("hud_points"),
balance_entry = Colors.LightGray + Translation.of("hud_siege_balance"),
timeRemaining_entry = Colors.LightGray + Translation.of("hud_time_remaining"),
bannerControl_entry = Colors.LightGray + Translation.of("hud_banner_control"),
battleAttackerScore_entry = Colors.LightGray + Translation.of("hud_battle_attacker_score"),
battleDefenderScore_entry = Colors.LightGray + Translation.of("hud_battle_defender_score"),
battleAttackerScore_entry = Colors.LightGray + Translation.of("hud_battle_attacker_points"),
battleDefenderScore_entry = Colors.LightGray + Translation.of("hud_battle_defender_points"),
battleTimeRemaining_entry = Colors.LightGray + Translation.of("hud_battle_time_remaining");

attackers.addEntry(attackers_entry);
defenders.addEntry(defenders_entry);
points.addEntry(points_entry);
balance.addEntry(balance_entry);
bannerControl.addEntry(bannerControl_entry);
timeRemaining.addEntry(timeRemaining_entry);
battleDefenderScore.addEntry(battleDefenderScore_entry);
Expand All @@ -63,7 +63,7 @@ public static void toggleOn(Player p, Siege siege) {

objective.getScore(attackers_entry).setScore(8);
objective.getScore(defenders_entry).setScore(7);
objective.getScore(points_entry).setScore(6);
objective.getScore(balance_entry).setScore(6);
objective.getScore(timeRemaining_entry).setScore(5);
objective.getScore(bannerControl_entry).setScore(4);
objective.getScore(battleAttackerScore_entry).setScore(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void onNationRankGivenToPlayer(NationRankAddEvent event) {
//In Siegewar, if target town is peaceful, can't add military rank
if(SiegeWarSettings.getWarSiegeEnabled()
&& SiegeWarSettings.getWarCommonPeacefulTownsEnabled()
&& PermissionUtil.doesNationRankAllowPermissionNode(event.getRank(), SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_POINTS)
&& PermissionUtil.doesNationRankAllowPermissionNode(event.getRank(), SiegeWarPermissionNodes.SIEGEWAR_NATION_BATTLE_POINTS)
&& TownyAPI.getInstance().getResidentTownOrNull(event.getResident()).isNeutral()) { // We know that the resident's town will not be null based on the tests already done.
event.setCancelled(true);
event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_war_siege_cannot_add_nation_military_rank_to_peaceful_resident"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void onTownToggleNeutral(TownToggleNeutralEvent event) {
//Remove any military nation ranks of residents
for(Resident peacefulTownResident: town.getResidents()) {
for (String nationRank : new ArrayList<>(peacefulTownResident.getNationRanks())) {
if (PermissionUtil.doesNationRankAllowPermissionNode(nationRank, SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_POINTS)) {
if (PermissionUtil.doesNationRankAllowPermissionNode(nationRank, SiegeWarPermissionNodes.SIEGEWAR_NATION_BATTLE_POINTS)) {
try {
peacefulTownResident.removeNationRank(nationRank);
} catch (NotRegisteredException ignored) {}
Expand Down Expand Up @@ -314,9 +314,9 @@ public void onTownStatusScreen(TownStatusScreenEvent event) {
out.add(Translation.of("status_town_siege_status_besieger", siege.getAttackingNation().getFormattedName()));

// > Points: +530
int pointsInt = siege.getSiegePoints();
int pointsInt = siege.getSiegeBalance();
String pointsString = pointsInt > 0 ? "+" + pointsInt : "" + pointsInt;
out.add(Translation.of("status_town_siege_status_points", pointsString));
out.add(Translation.of("status_town_siege_status_siege_balance", pointsString));

// > Banner XYZ: {2223,82,9877}
out.add(
Expand All @@ -335,8 +335,8 @@ public void onTownStatusScreen(TownStatusScreenEvent event) {
out.add(Translation.of("status_town_siege_status_warchest", warChest));

if(BattleSession.getBattleSession().isActive()
&& (siege.getAttackerBattleScore() > 0
|| siege.getDefenderBattleScore() > 0
&& (siege.getAttackerBattlePoints() > 0
|| siege.getDefenderBattlePoints() > 0
|| siege.getBannerControllingSide() != SiegeSide.NOBODY
|| siege.getBannerControlSessions().size() > 0)) {

Expand All @@ -359,7 +359,7 @@ public void onTownStatusScreen(TownStatusScreenEvent event) {
}

// > Score: +90 / -220
out.add(Translation.of("status_town_siege_battle_score", siege.getFormattedAttackerBattleScore(), siege.getFormattedDefenderBattleScore()));
out.add(Translation.of("status_town_siege_battle_score", siege.getFormattedAttackerBattlePoints(), siege.getFormattedDefenderBattlePoints()));

// > Time Remaining: 22 minutes
out.add(Translation.of("status_town_siege_battle_time_remaining", BattleSession.getBattleSession().getFormattedTimeRemainingUntilBattleSessionEnds()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onNewDay(PreNewDayEvent event) {
@EventHandler
public void onNewHour(NewHourEvent event) {
if(SiegeWarSettings.getWarSiegeEnabled()) {
SiegeWarTimerTaskController.updatePopulationBasedSiegePointModifiers();
SiegeWarTimerTaskController.updatePopulationBasedBattlePointModifiers();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class SiegeMetaDataController {
private static StringDataField siegeTownUUID = new StringDataField("siegewar_townUUID", "");
private static StringDataField siegeFlagLocation = new StringDataField("siegewar_flagLocation", "");
private static StringDataField siegeStatus = new StringDataField("siegewar_status", "");
private static IntegerDataField siegePoints = new IntegerDataField("siegewar_points", 0);
//In metadata, siegeBalance still uses the old name of points
private static IntegerDataField siegeBalance = new IntegerDataField("siegewar_points", 0);
private static DecimalDataField siegeWarChestAmount = new DecimalDataField("siegewar_warChestAmount", 0.0);
private static BooleanDataField townPlundered = new BooleanDataField("siegewar_townPlundered", false);
private static BooleanDataField townInvaded = new BooleanDataField("siegewar_townInvaded", false);
Expand Down Expand Up @@ -128,30 +129,30 @@ public static void setFlagLocation(Town town, String loc) {
}

@Nullable
public static String getStatus(Town town) {
public static String getSiegeStatus(Town town) {
StringDataField sdf = (StringDataField) siegeStatus.clone();
if (town.hasMeta(sdf.getKey()))
return MetaDataUtil.getString(town, sdf);
return null;
}

public static void setStatus(Town town, String status) {
public static void setSiegeStatus(Town town, String status) {
StringDataField sdf = (StringDataField) siegeStatus.clone();
if (town.hasMeta(sdf.getKey()))
MetaDataUtil.setString(town, sdf, status);
else
town.addMetaData(new StringDataField("siegewar_status", status));
}

public static int getPoints(Town town) {
IntegerDataField idf = (IntegerDataField) siegePoints.clone();
public static int getSiegeBalance(Town town) {
IntegerDataField idf = (IntegerDataField) siegeBalance.clone();
if (town.hasMeta(idf.getKey()))
return MetaDataUtil.getInt(town, idf);
return 0;
}

public static void setPoints(Town town, int num) {
IntegerDataField idf = (IntegerDataField) siegePoints.clone();
public static void setSiegeBalance(Town town, int num) {
IntegerDataField idf = (IntegerDataField) siegeBalance.clone();
if (town.hasMeta(idf.getKey()))
MetaDataUtil.setInt(town, idf, num);
else
Expand Down Expand Up @@ -268,7 +269,7 @@ public static void removeSiegeMeta (Town town) {
if (town.hasMeta(sdf.getKey()))
town.removeMetaData(sdf);

IntegerDataField idf = (IntegerDataField) siegePoints.clone();
IntegerDataField idf = (IntegerDataField) siegeBalance.clone();
if (town.hasMeta(idf.getKey()))
town.removeMetaData(idf);

Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/gmail/goosius/siegewar/objects/BattleSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
* A battle session is period of time, typically 50 minutes,
* in which individual "battles" take place at each siege.
*
* During a battle, siege points can be gained/lost.
* During a battle, battle points can be gained/lost by either side.
*
* At the end of a battle session:
* - The winner of each battle is declared
* - either the "Attacker" or the "Defender", or "Draw"
* - If nobody contested a battle, no winner is declared.
* - All scoreboards will show that the winner won +1 "battle".
* - Siege points are reset to 0
* - Plunder is awarded to any soldiers on the winning side,
* who gained banner control during the battle.
* (Attackers steal from the town, defenders steals from the war chest)
* When a battle ends:
* - The winner depends on who scores the most battle points.
* - It will be Attacker, Defender, or a Draw
* - If nobody contested a battle, no winner is declared.
* - If there is a winner, their battle points are applied to the siege balance.
*
* Until the next battle session starts:
* - This period is known as a "break", and typically lasts 10 minutes.
* - During this period, siege points remain at 0, and banner control is not possible.
* After a battle ends
* - Battle points are reset to 0
* - All banner control is wiped
* - There is a break (defualt 10 mins) until the next battle session starts
* ... during the break, no battle points gains or banner control are possible.
*
* At the normal end of a siege, whoever has won the most battles, wins the siege.
* FYI
* In the context of the overall Siege, the siege balance determines the winner
* (not the battle points)
*
* @author Goosius
*/
Expand Down
Loading

0 comments on commit 2ecf37b

Please sign in to comment.