refactor: wip update 2

This commit is contained in:
darksaid98 committed 2023-06-27 12:15:01 +02:00
1 parent 31e5289b7f
commit 96c9ce1230
26 files changed
+1918 -654

No files matched your search

@@ -15,7 +15,7 @@ public class AlathraWarLogger {
public AlathraWarLogger() { public AlathraWarLogger() {
logsFolder = new File("plugins" + File.separator + "AlathraWar" + File.separator + "logs"); logsFolder = new File("plugins" + File.separator + "AlathraWar" + File.separator + "logs");
log = new File( log = new File(
"plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt"); "plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt");
} }
public boolean checkFiles() { public boolean checkFiles() {
@@ -36,8 +36,8 @@ public class AlathraWarLogger {
// init file writer // init file writer
try { try {
FileWriter fw = new FileWriter( FileWriter fw = new FileWriter(
"plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt", "plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt",
true); true);
BufferedWriter bw = new BufferedWriter(fw); BufferedWriter bw = new BufferedWriter(fw);
output = new PrintWriter(bw); output = new PrintWriter(bw);
} catch (IOException e1) { } catch (IOException e1) {
@@ -1,7 +1,6 @@
package me.ShermansWorld.AlathraWar; package me.ShermansWorld.AlathraWar;
import com.palmergames.bukkit.towny.object.WorldCoord; import com.palmergames.bukkit.towny.object.WorldCoord;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -22,10 +21,6 @@ public class Helper {
return color("&6[&4AlathraWar&6]&r "); return color("&6[&4AlathraWar&6]&r ");
} }
public static void testMsg() {
Bukkit.broadcastMessage("test message");
}
/** /**
* Damages all gear in a players inventory * Damages all gear in a players inventory
* *
@@ -170,10 +165,10 @@ public class Helper {
ArrayList<WorldCoord> ReturnList = new ArrayList<>(); ArrayList<WorldCoord> ReturnList = new ArrayList<>();
int[][] XZarray = new int[][]{ int[][] XZarray = new int[][]{
{-1, 0}, {-1, 0},
{1, 0}, {1, 0},
{0, -1}, {0, -1},
{0, 1} {0, 1}
}; // Array that contains relative orthogonal shifts from origin }; // Array that contains relative orthogonal shifts from origin
for (int[] pair : XZarray) { for (int[] pair : XZarray) {
// Constructs new WorldCoord for comparison // Constructs new WorldCoord for comparison
@@ -49,7 +49,7 @@ public class Main extends JavaPlugin {
logsFolder.mkdirs(); logsFolder.mkdirs();
} }
File log = new File( File log = new File(
"plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt"); "plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt");
if (!log.exists()) { if (!log.exists()) {
try { try {
log.createNewFile(); log.createNewFile();
@@ -70,7 +70,7 @@ public class Main extends JavaPlugin {
return false; return false;
} }
@SuppressWarnings("unchecked") final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>) this.getServer() @SuppressWarnings("unchecked") final RegisteredServiceProvider<Economy> rsp = (RegisteredServiceProvider<Economy>) this.getServer()
.getServicesManager().getRegistration((Class) Economy.class); .getServicesManager().getRegistration((Class) Economy.class);
if (rsp == null) { if (rsp == null) {
return false; return false;
} }
@@ -92,7 +92,6 @@ public class Main extends JavaPlugin {
new WarData(this); new WarData(this);
// new TimeoutData(this); // new TimeoutData(this);
getServer().getPluginManager().registerEvents(new KillsListener(), this); getServer().getPluginManager().registerEvents(new KillsListener(), this);
getServer().getPluginManager().registerEvents(new CommandsListener(), this); getServer().getPluginManager().registerEvents(new CommandsListener(), this);
getServer().getPluginManager().registerEvents(new JoinListener(), this); getServer().getPluginManager().registerEvents(new JoinListener(), this);
@@ -210,7 +210,7 @@ public class Raid {
// Creates 10 second looping function for Raid // Creates 10 second looping function for Raid
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(),
getTickLoop(), 0L, incremental); getTickLoop(), 0L, incremental);
this.getWar().addRaid(this); this.getWar().addRaid(this);
this.save(); this.save();
@@ -243,7 +243,7 @@ public class Raid {
// Creates 2 second looping function for Raid, restarting this! // Creates 2 second looping function for Raid, restarting this!
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(),
getTickLoop(), 0L, incremental); getTickLoop(), 0L, incremental);
} }
@@ -325,9 +325,9 @@ public class Raid {
private void startTravel() { private void startTravel() {
Raid.this.phase = RaidPhase.TRAVEL; Raid.this.phase = RaidPhase.TRAVEL;
Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of " Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2()) + (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
+ " are coming to raid " + " are coming to raid "
+ Raid.this.getRaidedTown().getName() + "!"); + Raid.this.getRaidedTown().getName() + "!");
//in the case were not at that stage already, if this happens we have an issue //in the case were not at that stage already, if this happens we have an issue
Raid.this.raidTicks = RaidPhase.TRAVEL.startTick; Raid.this.raidTicks = RaidPhase.TRAVEL.startTick;
} }
@@ -338,9 +338,9 @@ public class Raid {
private void startCombat() { private void startCombat() {
Raid.this.phase = RaidPhase.COMBAT; Raid.this.phase = RaidPhase.COMBAT;
Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of " Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2()) + (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
+ " have arrived at " + " have arrived at "
+ Raid.this.getRaidedTown().getName() + " and the fighting has begun!"); + Raid.this.getRaidedTown().getName() + " and the fighting has begun!");
//in the case were not at that stage already //in the case were not at that stage already
Raid.this.raidTicks = RaidPhase.COMBAT.startTick; Raid.this.raidTicks = RaidPhase.COMBAT.startTick;
} }
@@ -473,7 +473,7 @@ public class Raid {
if (factor < 0) factor = 0.0; if (factor < 0) factor = 0.0;
Bukkit.broadcastMessage(Helper.chatLabel() + "The raiders from " + this.raiders Bukkit.broadcastMessage(Helper.chatLabel() + "The raiders from " + this.raiders
+ " have successfully raided " + this.raidedTown.getName() + "!"); + " have successfully raided " + this.raidedTown.getName() + "!");
/* /*
if town has more than 10k, 1/10th of its valuables times the factor is taken if town has more than 10k, 1/10th of its valuables times the factor is taken
@@ -526,9 +526,9 @@ public class Raid {
} }
Bukkit.broadcastMessage("The town of " + this.raidedTown.getName() + " has been " + statement + " by " + this.getRaiderSide() Bukkit.broadcastMessage("The town of " + this.raidedTown.getName() + " has been " + statement + " by " + this.getRaiderSide()
+ " in a raid for " + String.format("$%.2f", amt)); + " in a raid for " + String.format("$%.2f", amt));
Main.warLogger.log("The town of " + this.raidedTown.getName() + " has been " + statement + " by " + this.getRaiderSide() Main.warLogger.log("The town of " + this.raidedTown.getName() + " has been " + statement + " by " + this.getRaiderSide()
+ " in a raid for " + String.format("$%.2f", amt)); + " in a raid for " + String.format("$%.2f", amt));
Main.econ.depositPlayer(offlinePlayer, amt); Main.econ.depositPlayer(offlinePlayer, amt);
if (this.side1AreRaiders) { if (this.side1AreRaiders) {
@@ -560,27 +560,27 @@ public class Raid {
if (factor <= 0.5) { if (factor <= 0.5) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders
+ " have barely pushed back the raiders of " + this.raiders + ". More has been lost than gained."); + " have barely pushed back the raiders of " + this.raiders + ". More has been lost than gained.");
Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName() Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName()
+ " has recovered part of the attackers' raid chest, valued at $500"); + " has recovered part of the attackers' raid chest, valued at $500");
Main.warLogger Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!"); .log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(500, "Raid chest"); this.raidedTown.getAccount().deposit(500, "Raid chest");
} else if (factor <= 1.5) { } else if (factor <= 1.5) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders
+ " have fended off the raiders of " + this.raiders + "!"); + " have fended off the raiders of " + this.raiders + "!");
Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName() Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName()
+ " has recovered the attackers' raid chest, valued at $1000"); + " has recovered the attackers' raid chest, valued at $1000");
Main.warLogger Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!"); .log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(1000, "Raid chest"); this.raidedTown.getAccount().deposit(1000, "Raid chest");
} else if (factor <= 3.0) { } else if (factor <= 3.0) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders
+ " have wholly defeated the raiders of " + this.raiders + "! They barely broke the walls."); + " have wholly defeated the raiders of " + this.raiders + "! They barely broke the walls.");
Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName() Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName()
+ " has recovered the attackers' raid chest, valued at $1000."); + " has recovered the attackers' raid chest, valued at $1000.");
Main.warLogger Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!"); .log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(1000, "Raid chest"); this.raidedTown.getAccount().deposit(1000, "Raid chest");
} }
@@ -600,9 +600,9 @@ public class Raid {
//TODO finalize payout //TODO finalize payout
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders
+ " didn't push back the raiders of " + this.raiders + ". Yet no loot was taken, raid considered a draw."); + " didn't push back the raiders of " + this.raiders + ". Yet no loot was taken, raid considered a draw.");
Main.warLogger Main.warLogger
.log("No one won the raid of " + this.raidedTown.getName() + "!"); .log("No one won the raid of " + this.raidedTown.getName() + "!");
stop(); stop();
} }
@@ -846,9 +846,9 @@ public class Raid {
//Broadcast //Broadcast
if (raidTicks % 6000 == 0) { if (raidTicks % 6000 == 0) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of " Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of "
+ Raid.this.getRaidedTown().getName() + " will begin in " + ((RaidPhase.TRAVEL.startTick - raidTicks) / 20 / 60) + " minutes!"); + Raid.this.getRaidedTown().getName() + " will begin in " + ((RaidPhase.TRAVEL.startTick - raidTicks) / 20 / 60) + " minutes!");
Bukkit.broadcastMessage( Bukkit.broadcastMessage(
"The Raiders are gathering at " + getGatherTown().getName() + " before making the journey over!"); "The Raiders are gathering at " + getGatherTown().getName() + " before making the journey over!");
} }
@@ -882,9 +882,9 @@ public class Raid {
//Report //Report
if (raidTicks % 2400 == 0) { if (raidTicks % 2400 == 0) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of " Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2()) + (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
+ " are on their way to raid " + " are on their way to raid "
+ Raid.this.getRaidedTown().getName() + "!"); + Raid.this.getRaidedTown().getName() + "!");
} }
//Check if a player has arrived at the town (in it, or within 200 blocks) and if so start combat //Check if a player has arrived at the town (in it, or within 200 blocks) and if so start combat
@@ -917,13 +917,13 @@ public class Raid {
//Report //Report
if (Raid.this.raidTicks % 6000 == 0) { if (Raid.this.raidTicks % 6000 == 0) {
Bukkit.broadcastMessage(Helper.chatLabel() + "Report on the raid of " Bukkit.broadcastMessage(Helper.chatLabel() + "Report on the raid of "
+ Raid.this.getRaidedTown().getName() + ":"); + Raid.this.getRaidedTown().getName() + ":");
Bukkit.broadcastMessage( Bukkit.broadcastMessage(
"Raider Score - " + Raid.this.raiderScore); "Raider Score - " + Raid.this.raiderScore);
Bukkit.broadcastMessage( Bukkit.broadcastMessage(
"Defender Score - " + Raid.this.defenderScore); "Defender Score - " + Raid.this.defenderScore);
Bukkit.broadcastMessage( Bukkit.broadcastMessage(
"Chunks Looted - " + Raid.this.lootedChunks.size() + "/" + raidedTown.getTownBlocks().size()); "Chunks Looted - " + Raid.this.lootedChunks.size() + "/" + raidedTown.getTownBlocks().size());
} }
//Looting chunks //Looting chunks
@@ -6,6 +6,7 @@ import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException; import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.*; import com.palmergames.bukkit.towny.object.*;
import me.ShermansWorld.AlathraWar.data.SiegeData; import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.boss.BarColor; import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle; import org.bukkit.boss.BarStyle;
@@ -45,7 +46,7 @@ public class Siege {
bossBarKey = new NamespacedKey(Main.getInstance(), "siegeBar." + this.getName()); bossBarKey = new NamespacedKey(Main.getInstance(), "siegeBar." + this.getName());
side1AreAttackers = war.getSide(town.getName()) == 2; side1AreAttackers = war.getState(town.getName()) == TownWarState.SIDE2;
} }
/** /**
@@ -167,14 +168,14 @@ public class Siege {
for (final String playerName : Siege.this.attackerPlayers) { for (final String playerName : Siege.this.attackerPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel() Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "HomeBlock at " + Siege.this.town.getName() + " contested!"); + "HomeBlock at " + Siege.this.town.getName() + " contested!");
} catch (NullPointerException ex5) { } catch (NullPointerException ex5) {
} }
} }
for (final String playerName : Siege.this.defenderPlayers) { for (final String playerName : Siege.this.defenderPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel() Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "HomeBlock at " + Siege.this.town.getName() + " contested!"); + "HomeBlock at " + Siege.this.town.getName() + " contested!");
} catch (NullPointerException ex6) { } catch (NullPointerException ex6) {
} }
} }
@@ -185,16 +186,16 @@ public class Siege {
for (final String playerName : Siege.this.attackerPlayers) { for (final String playerName : Siege.this.attackerPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel() Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "Attackers have captured the HomeBlock at " + "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second"); + Siege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex7) { } catch (NullPointerException ex7) {
} }
} }
for (final String playerName : Siege.this.defenderPlayers) { for (final String playerName : Siege.this.defenderPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel() Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "Attackers have captured the HomeBlock at " + "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second"); + Siege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex8) { } catch (NullPointerException ex8) {
} }
} }
@@ -206,16 +207,16 @@ public class Siege {
for (final String playerName : Siege.this.attackerPlayers) { for (final String playerName : Siege.this.attackerPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel() Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "Defenders retain control of the HomeBlock at " + "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second"); + Siege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex9) { } catch (NullPointerException ex9) {
} }
} }
for (final String playerName : Siege.this.defenderPlayers) { for (final String playerName : Siege.this.defenderPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel() Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "Defenders retain control of the HomeBlock at " + "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second"); + Siege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex10) { } catch (NullPointerException ex10) {
} }
} }
@@ -225,11 +226,11 @@ public class Siege {
} }
if (Siege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes if (Siege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes
Bukkit.broadcastMessage(Helper.chatLabel() + "Report on the siege of " Bukkit.broadcastMessage(Helper.chatLabel() + "Report on the siege of "
+ Siege.this.town.getName() + ":"); + Siege.this.town.getName() + ":");
Bukkit.broadcastMessage( Bukkit.broadcastMessage(
"Attacker Points - " + Siege.this.attackerPoints); "Attacker Points - " + Siege.this.attackerPoints);
Bukkit.broadcastMessage( Bukkit.broadcastMessage(
"Defender Points - " + Siege.this.defenderPoints); "Defender Points - " + Siege.this.defenderPoints);
} }
if (siegeTicks % 1200 == 0) { // Saves every minute if (siegeTicks % 1200 == 0) { // Saves every minute
save(); save();
@@ -253,7 +254,7 @@ public class Siege {
} }
if (nation != null) { if (nation != null) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + this.town.getName() Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + this.town.getName()
+ " has been placed under occupation by " + nation.getName() + "!"); + " has been placed under occupation by " + nation.getName() + "!");
} }
Main.econ.depositPlayer(siegeLeader, 2500.0); Main.econ.depositPlayer(siegeLeader, 2500.0);
double amt = 0.0; double amt = 0.0;
@@ -264,7 +265,7 @@ public class Siege {
if (this.town.getAccount().getHoldingBalance() < 2500.0) { if (this.town.getAccount().getHoldingBalance() < 2500.0) {
amt = this.town.getAccount().getHoldingBalance(); amt = this.town.getAccount().getHoldingBalance();
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + this.town.getName() Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + this.town.getName()
+ " has been destroyed by " + this.getAttackerSide() + "!"); + " has been destroyed by " + this.getAttackerSide() + "!");
TownyUniverse.getInstance().getDataSource().deleteTown(this.town); TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
Main.econ.depositPlayer(siegeLeader, amt); Main.econ.depositPlayer(siegeLeader, amt);
return; return;
@@ -273,9 +274,9 @@ public class Siege {
amt = 2500.0; amt = 2500.0;
} }
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide() Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
+ ", valuing $" + amt); + ", valuing $" + amt);
Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide() Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
+ ", valuing $" + amt); + ", valuing $" + amt);
Main.econ.depositPlayer(siegeLeader, amt); Main.econ.depositPlayer(siegeLeader, amt);
if (side1AreAttackers) { if (side1AreAttackers) {
@@ -292,9 +293,9 @@ public class Siege {
this.town.getAccount().deposit(2500.0, "War chest"); this.town.getAccount().deposit(2500.0, "War chest");
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders have won the siege of " + this.town.getName() + "!"); Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(Helper.chatLabel() + this.town.getName() Bukkit.broadcastMessage(Helper.chatLabel() + this.town.getName()
+ " has recovered the attackers' war chest, valued at $2,500"); + " has recovered the attackers' war chest, valued at $2,500");
Main.warLogger Main.warLogger
.log(war.getName() + ": The defenders have won the siege of " + this.town.getName() + "!"); .log(war.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
if (side1AreAttackers) { if (side1AreAttackers) {
war.addSide2Points(50); war.addSide2Points(50);
@@ -313,7 +314,7 @@ public class Siege {
Bukkit.broadcastMessage(Helper.chatLabel() + "The siege of " + this.town.getName() + " was a draw!"); Bukkit.broadcastMessage(Helper.chatLabel() + "The siege of " + this.town.getName() + " was a draw!");
Bukkit.broadcastMessage(Helper.chatLabel() + "No money has been recovered."); Bukkit.broadcastMessage(Helper.chatLabel() + "No money has been recovered.");
Main.warLogger Main.warLogger
.log(war.getName() + ": No one won the siege of " + this.town.getName() + "!"); .log(war.getName() + ": No one won the siege of " + this.town.getName() + "!");
stop(); stop();
clearBeacon(); clearBeacon();
} }
@@ -337,7 +338,7 @@ public class Siege {
} }
int homeBlockY = 253; int homeBlockY = 253;
final Location beaconLoc = new Location(this.town.getWorld(), homeBlockX, final Location beaconLoc = new Location(this.town.getWorld(), homeBlockX,
homeBlockY - 2, homeBlockZ); homeBlockY - 2, homeBlockZ);
while (beaconLoc.getBlock().getType().equals(Material.AIR)) { while (beaconLoc.getBlock().getType().equals(Material.AIR)) {
--homeBlockY; --homeBlockY;
beaconLoc.setY(homeBlockY); beaconLoc.setY(homeBlockY);
@@ -345,25 +346,25 @@ public class Siege {
homeBlockY += 2; homeBlockY += 2;
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY, homeBlockZ)); this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY, homeBlockZ));
this.beaconLocs this.beaconLocs
.add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ)); .add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ));
this.beaconLocs this.beaconLocs
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ)); .add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ));
this.beaconLocs.add( this.beaconLocs.add(
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ)); new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ));
this.beaconLocs.add( this.beaconLocs.add(
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ)); new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ));
this.beaconLocs.add( this.beaconLocs.add(
new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1)); new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1));
this.beaconLocs.add( this.beaconLocs.add(
new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1)); new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1));
this.beaconLocs.add(new Location(world, homeBlockX + 1, homeBlockY - 1, this.beaconLocs.add(new Location(world, homeBlockX + 1, homeBlockY - 1,
homeBlockZ + 1)); homeBlockZ + 1));
this.beaconLocs.add(new Location(world, homeBlockX + 1, homeBlockY - 1, this.beaconLocs.add(new Location(world, homeBlockX + 1, homeBlockY - 1,
homeBlockZ - 1)); homeBlockZ - 1));
this.beaconLocs.add(new Location(world, homeBlockX - 1, homeBlockY - 1, this.beaconLocs.add(new Location(world, homeBlockX - 1, homeBlockY - 1,
homeBlockZ + 1)); homeBlockZ + 1));
this.beaconLocs.add(new Location(world, homeBlockX - 1, homeBlockY - 1, this.beaconLocs.add(new Location(world, homeBlockX - 1, homeBlockY - 1,
homeBlockZ - 1)); homeBlockZ - 1));
for (int i = 2; i < this.beaconLocs.size(); ++i) { for (int i = 2; i < this.beaconLocs.size(); ++i) {
if (this.beaconLocs.get(i).getBlock().getType() != Material.AIR) { if (this.beaconLocs.get(i).getBlock().getType() != Material.AIR) {
i = 1; i = 1;
@@ -388,21 +389,21 @@ public class Siege {
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ)); this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ));
this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ)); this.beaconLocs.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ));
this.beaconLocs this.beaconLocs
.add(new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ)); .add(new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ));
this.beaconLocs this.beaconLocs
.add(new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ)); .add(new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ));
this.beaconLocs this.beaconLocs
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1)); .add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1));
this.beaconLocs this.beaconLocs
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1)); .add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1));
this.beaconLocs.add( this.beaconLocs.add(
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ + 1)); new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ + 1));
this.beaconLocs.add( this.beaconLocs.add(
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ - 1)); new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ - 1));
this.beaconLocs.add( this.beaconLocs.add(
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ + 1)); new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ + 1));
this.beaconLocs.add( this.beaconLocs.add(
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ - 1)); new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ - 1));
} }
public void clearBeacon() { public void clearBeacon() {
@@ -7,6 +7,7 @@ import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.commands.CommandHelper; import me.ShermansWorld.AlathraWar.commands.CommandHelper;
import me.ShermansWorld.AlathraWar.data.DataManager; import me.ShermansWorld.AlathraWar.data.DataManager;
import me.ShermansWorld.AlathraWar.data.WarData; import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@@ -174,23 +175,27 @@ public class War {
* @param string town * @param string town
* @return result * @return result
*/ */
public int getSide(String string) { public TownWarState getState(String string) {
for (String str : surrenderedTowns) { for (String str : surrenderedTowns) {
if (str.equalsIgnoreCase(string)) return -1; if (str.equalsIgnoreCase(string)) return TownWarState.SURRENDERED;
} }
for (String str : side1Towns) { for (String str : side1Towns) {
if (str.equalsIgnoreCase(string)) return 1; if (str.equalsIgnoreCase(string)) return TownWarState.SIDE1;
} }
for (String str : side2Towns) { for (String str : side2Towns) {
if (str.equalsIgnoreCase(string)) return 2; if (str.equalsIgnoreCase(string)) return TownWarState.SIDE2;
} }
return 0; return TownWarState.NOT_PARTICIPANT;
} }
public int getSide(Town town) { public TownWarState getState(Town town) {
return getSide(town.getName()); return getState(town.getName());
}
public boolean isSideValid(String side) {
return getSides().contains(side);
} }
public String getName() { public String getName() {
@@ -272,8 +277,8 @@ public class War {
public String toString() { public String toString() {
return name + "[" + side1 + "." + side2 + "](" return name + "[" + side1 + "." + side2 + "]("
+ side1Towns.size() + "/" + side2Towns.size() + "/" + + side1Towns.size() + "/" + side2Towns.size() + "/" +
surrenderedTowns.size() + ")"; surrenderedTowns.size() + ")";
} }
public ArrayList<String> getSide1Players() { public ArrayList<String> getSide1Players() {
File diff suppressed because it is too large. Load diff
@@ -12,6 +12,7 @@ import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.RaidPhase; import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.data.SiegeData; import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.data.WarData; import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import me.ShermansWorld.AlathraWar.items.WarItemRegistry; import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@@ -202,7 +203,7 @@ public class AdminCommands implements CommandExecutor {
if (args.length >= 4) { if (args.length >= 4) {
//specific behavior exists if an admin ran this //specific behavior exists if an admin ran this
//using same method so that this doesnt get fucked up if we go back and change original implementation //using same method so that this doesnt get fucked up if we go back and change original implementation
RaidCommands.startRaid(p, args, true); RaidCommand.raidStart(p, args, true);
p.sendMessage(Helper.color("&cForcefully started raid from the console.")); p.sendMessage(Helper.color("&cForcefully started raid from the console."));
} else { } else {
//defaultCode will bypass the custom gather town to force set owner //defaultCode will bypass the custom gather town to force set owner
@@ -218,7 +219,7 @@ public class AdminCommands implements CommandExecutor {
l.add(args[3]); l.add(args[3]);
if (args.length >= 5) l.add(args[4]); if (args.length >= 5) l.add(args[4]);
if (args.length >= 6) l.add(args[5]); if (args.length >= 6) l.add(args[5]);
SiegeCommands.siegeStart(p, l.toArray(new String[]{}), true); SiegeCommand.siegeStart(p, l.toArray(new String[]{}), true);
// p.sendMessage(Helper.Chatlabel() + "Try again later!"); // p.sendMessage(Helper.Chatlabel() + "Try again later!");
p.sendMessage(Helper.color("&cForcefully started siege from the console.")); p.sendMessage(Helper.color("&cForcefully started siege from the console."));
} else { } else {
@@ -230,12 +231,12 @@ public class AdminCommands implements CommandExecutor {
if (args.length == 5) { if (args.length == 5) {
//should purge the first argument; //should purge the first argument;
String[] adjusted = new String[]{ String[] adjusted = new String[]{
args[1], args[1],
args[2], args[2],
args[3], args[3],
args[4] args[4]
}; };
WarCommands.warCreate(p, adjusted); WarCommand.warCreate(p, adjusted);
p.sendMessage(Helper.color("&cForcefully started war from the console.")); p.sendMessage(Helper.color("&cForcefully started war from the console."));
} else { } else {
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create war [name] [side1] [side2]")); p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create war [name] [side1] [side2]"));
@@ -393,7 +394,7 @@ public class AdminCommands implements CommandExecutor {
adjusted.add(args[3]); adjusted.add(args[3]);
adjusted.add(args[6]); adjusted.add(args[6]);
adjusted.add(args[7]); adjusted.add(args[7]);
RaidCommands.joinRaid(p, adjusted.toArray(new String[6]), true); RaidCommand.raidJoin(p, adjusted.toArray(new String[6]), true);
return true; return true;
} else { } else {
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin force join raid [player] [war] [town] [side] (ignoreIssues)")); p.sendMessage(Helper.color("&cUsage: /alathrawaradmin force join raid [player] [war] [town] [side] (ignoreIssues)"));
@@ -411,11 +412,11 @@ public class AdminCommands implements CommandExecutor {
if (args.length >= 7) { if (args.length >= 7) {
//fix args to match //fix args to match
String[] adjusted = new String[]{ String[] adjusted = new String[]{
args[1], args[1],
args[4], args[4],
args[5], args[5],
args[3], args[3],
args[6] args[6]
}; };
if (Bukkit.getPlayer(args[3]) != null) { if (Bukkit.getPlayer(args[3]) != null) {
} else { } else {
@@ -423,7 +424,7 @@ public class AdminCommands implements CommandExecutor {
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin force join war [player] [war] [side]")); p.sendMessage(Helper.color("&cUsage: /alathrawaradmin force join war [player] [war] [side]"));
return true; return true;
} }
WarCommands.warJoin(p, adjusted, true); WarCommand.warJoin(p, adjusted, true);
p.sendMessage(Helper.color("&cForced " + args[3] + " to join the war " + args[4] + " on side " + args[5])); p.sendMessage(Helper.color("&cForced " + args[3] + " to join the war " + args[4] + " on side " + args[5]));
Main.warLogger.log("Forced " + args[3] + " to join the war " + args[4] + " on side " + args[5]); Main.warLogger.log("Forced " + args[3] + " to join the war " + args[4] + " on side " + args[5]);
} else { } else {
@@ -446,12 +447,12 @@ public class AdminCommands implements CommandExecutor {
if (r.getWar().getName().equalsIgnoreCase(args[3]) && r.getRaidedTown().getName().equalsIgnoreCase(args[4])) { if (r.getWar().getName().equalsIgnoreCase(args[3]) && r.getRaidedTown().getName().equalsIgnoreCase(args[4])) {
if (Bukkit.getPlayer(args[5]) != null) { if (Bukkit.getPlayer(args[5]) != null) {
String[] fixed = new String[]{ String[] fixed = new String[]{
args[1], args[1],
args[3], args[3],
args[4], args[4],
args[5] args[5]
}; };
RaidCommands.leaveRaid(p, fixed, true); RaidCommand.raidLeave(p, fixed, true);
p.sendMessage(Helper.chatLabel() + "Forced player " + args[5] + " to leave raid on " + args[4] + " in war " + args[3]); p.sendMessage(Helper.chatLabel() + "Forced player " + args[5] + " to leave raid on " + args[4] + " in war " + args[3]);
Main.warLogger.log("Forced player " + args[5] + " to leave raid on " + args[4] + " in war " + args[3]); Main.warLogger.log("Forced player " + args[5] + " to leave raid on " + args[4] + " in war " + args[3]);
return finalizeRaid(r); return finalizeRaid(r);
@@ -1497,11 +1498,11 @@ public class AdminCommands implements CommandExecutor {
} }
} }
// Side checks // Side checks
int side = w.getSide(t.getName().toLowerCase()); TownWarState side = w.getState(t.getName().toLowerCase());
if (side == -1) { if (side == TownWarState.SURRENDERED) {
p.sendMessage(Helper.chatLabel() + "Town already surrendered!"); p.sendMessage(Helper.chatLabel() + "Town already surrendered!");
return true; return true;
} else if (side > 0) { } else if (side != TownWarState.NOT_PARTICIPANT) {
p.sendMessage(Helper.chatLabel() + "Town already in this war!"); p.sendMessage(Helper.chatLabel() + "Town already in this war!");
return true; return true;
} }
@@ -1544,11 +1545,11 @@ public class AdminCommands implements CommandExecutor {
for (Town t : n.getTowns()) { for (Town t : n.getTowns()) {
// Side checks // Side checks
int side = w.getSide(t.getName().toLowerCase()); TownWarState side = w.getState(t.getName().toLowerCase());
if (side == -1) { if (side == TownWarState.SURRENDERED) {
p.sendMessage(Helper.chatLabel() + "Town " + t.getName() + " already surrendered!"); p.sendMessage(Helper.chatLabel() + "Town " + t.getName() + " already surrendered!");
continue; continue;
} else if (side > 0) { } else if (side != TownWarState.NOT_PARTICIPANT) {
p.sendMessage(Helper.chatLabel() + "Town " + t.getName() + " already in this war!"); p.sendMessage(Helper.chatLabel() + "Town " + t.getName() + " already in this war!");
continue; continue;
} }
@@ -1873,19 +1874,16 @@ public class AdminCommands implements CommandExecutor {
} }
} }
private static boolean finalizeRaid(Raid r) { private static void finalizeRaid(Raid r) {
r.save(); r.save();
return true;
} }
private static boolean finalizeSiege(Siege s) { private static void finalizeSiege(Siege s) {
s.save(); s.save();
return true;
} }
private static boolean finalizeWar(War w) { private static void finalizeWar(War w) {
w.save(); w.save();
return true;
} }
/** /**
@@ -12,31 +12,31 @@ import java.util.List;
public class AdminTabCompletion implements TabCompleter { public class AdminTabCompletion implements TabCompleter {
List<String> base = List.of("create", List<String> base = List.of("create",
"force", "force",
"help", "help",
"info", "info",
"modify", "modify",
"purgebars", "purgebars",
"load", "load",
"load-all", "load-all",
"save", "save",
"save-all", "save-all",
"item"); "item");
List<String> type = List.of(new String[]{ List<String> type = List.of(new String[]{
"raid", "raid",
"siege", "siege",
"war" "war"
}); });
List<String> raidModify = List.of(new String[]{ List<String> raidModify = List.of(new String[]{
"score", "score",
"townspawn", "townspawn",
"gather", "gather",
"phase", "phase",
"loot", "loot",
"time", "time",
"owner" "owner"
// , // ,
// "move" // "move"
// , // ,
@@ -44,64 +44,64 @@ public class AdminTabCompletion implements TabCompleter {
}); });
List<String> siegeModify = List.of(new String[]{ List<String> siegeModify = List.of(new String[]{
"score", "score",
"townspawn", "townspawn",
"time", "time",
"owner" "owner"
// , // ,
// "move" // "move"
}); });
List<String> warModify = List.of(new String[]{ List<String> warModify = List.of(new String[]{
"score", "score",
"side", "side",
"name", "name",
"add", "add",
"surrender", "surrender",
"unsurrender", "unsurrender",
"raidTimeWar", "raidTimeWar",
"raidTimeTown" "raidTimeTown"
}); });
List<String> force = List.of(new String[]{ List<String> force = List.of(new String[]{
"end", "end",
"join", "join",
"leave" "leave"
}); });
List<String> addSet = List.of(new String[]{ List<String> addSet = List.of(new String[]{
"add", "add",
"set" "set"
}); });
List<String> addSubSet = List.of(new String[]{ List<String> addSubSet = List.of(new String[]{
"add", "add",
"subtract", "subtract",
"set" "set"
}); });
List<String> boolSet = List.of(new String[]{ List<String> boolSet = List.of(new String[]{
"true", "true",
"false" "false"
}); });
List<String> addSetReset = List.of(new String[]{ List<String> addSetReset = List.of(new String[]{
"add", "add",
"set", "set",
"reset" "reset"
}); });
List<String> nationTown = List.of(new String[]{ List<String> nationTown = List.of(new String[]{
"town", "town",
"nation" "nation"
}); });
List<String> lootSet = List.of(new String[]{ List<String> lootSet = List.of(new String[]{
"value", "value",
"looted", "looted",
"ticks", "ticks",
"reset" "reset"
}); });
List<String> empty = Collections.emptyList(); List<String> empty = Collections.emptyList();
@@ -36,6 +36,32 @@ public class CommandHelper {
return out; return out;
} }
/**
* Grabs list of all sieges
*
* @return list of wars
*/
public static List<String> getSieges() {
List<String> out = new ArrayList<>();
for (Siege s : SiegeData.getSieges()) {
out.add(s.getName());
}
return out;
}
/**
* Grabs list of all raids
*
* @return list of wars
*/
public static List<String> getRaids() {
List<String> out = new ArrayList<>();
for (Raid r : RaidData.getRaids()) {
out.add(r.getName());
}
return out;
}
/** /**
* Grabs first matching war and lists the sides * Grabs first matching war and lists the sides
* *
@@ -22,8 +22,7 @@ public class CommandManager {
new WarCommand(); new WarCommand();
new SiegeCommand(); new SiegeCommand();
new RaidCommand(); new RaidCommand();
new AdminCommands(instance); new AdminCommand();
// getCommand("alathrawaradmin").setTabCompleter(new AdminTabCompletion());
} }
public void onDisable() { public void onDisable() {
@@ -20,6 +20,7 @@ import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.RaidPhase; import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.data.SiegeData; import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.data.WarData; import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@@ -29,177 +30,170 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List;
public class RaidCommand { public class RaidCommand {
public RaidCommand() { public RaidCommand() {
new CommandAPICommand("raid") new CommandAPICommand("raid")
.withSubcommands( .withSubcommands(
commandRaid(), commandRaid(),
commandStop(), commandStop(),
commandJoin(), commandJoin(),
commandLeave(), commandLeave(),
commandAbandon(), commandAbandon(),
commandList(), commandList(),
commandHelp() commandHelp()
) )
.executesPlayer((sender, args) -> { .executesPlayer((sender, args) -> {
if (args.count() == 0) if (args.count() == 0)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid Arguments. /siege help").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid Arguments. /siege help").build());
}) })
.register(); .register();
} }
public static CommandAPICommand commandRaid() { public static CommandAPICommand commandRaid() {
return new CommandAPICommand("raid") return new CommandAPICommand("raid")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.strings( ArgumentSuggestions.strings(
WarData.getWarsNames() WarData.getWarsNames()
) )
), ),
new StringArgument("target") new StringArgument("target")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final String warname = (String) info.previousArgs().get("warname"); final String warname = (String) info.previousArgs().get("warname");
return CommandHelper.getTownyWarTowns(warname); return CommandHelper.getTownyWarTowns(warname);
} }
) )
), ),
new StringArgument("gathertown") new StringArgument("gathertown")
.setOptional(true) .setOptional(true)
.withPermission("AlathraWar.admin") .withPermission("AlathraWar.admin")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { // TODO Make getHostileTowns method where we reverse from list ArgumentSuggestions.stringCollection(info -> { // TODO Make getHostileTowns method where we reverse from list
final String warname = (String) info.previousArgs().get("warname"); final String warname = (String) info.previousArgs().get("warname");
return CommandHelper.getTownyWarTowns(warname); return CommandHelper.getTownyWarTowns(warname);
} }
) )
), ),
new PlayerArgument("leader") new PlayerArgument("leader")
.setOptional(true) .setOptional(true)
.withPermission("AlathraWar.admin"), .withPermission("AlathraWar.admin"),
new BooleanArgument("minutemen") new BooleanArgument("minutemen")
.setOptional(true) .setOptional(true)
.withPermission("AlathraWar.admin") .withPermission("AlathraWar.admin")
) )
.executesPlayer((Player p, CommandArguments args) -> raidStart(p, args, false)); .executesPlayer((Player p, CommandArguments args) -> raidStart(p, args, false));
} }
public static CommandAPICommand commandStop() { public static CommandAPICommand commandStop() {
return new CommandAPICommand("stop") return new CommandAPICommand("stop")
.withPermission("AlathraWar.admin") .withPermission("AlathraWar.admin")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> ArgumentSuggestions.stringCollection(info ->
WarData.getWarsNames() WarData.getWarsNames()
) )
), ),
new StringArgument("town") new StringArgument("town")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final String warname = (String) info.previousArgs().get("warname"); final String warname = (String) info.previousArgs().get("warname");
return CommandHelper.getTownyWarTowns(warname); return CommandHelper.getTownyWarTowns(warname);
}) })
) )
) )
.executesPlayer(RaidCommand::raidStop); .executesPlayer(RaidCommand::raidStop);
} }
public static CommandAPICommand commandJoin() { public static CommandAPICommand commandJoin() {
return new CommandAPICommand("join") return new CommandAPICommand("join")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("raidname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> ArgumentSuggestions.strings(
WarData.getWarsNames() CommandHelper.getRaids()
) )
), ),
new StringArgument("town") new StringArgument("side")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final String warname = (String) info.previousArgs().get("warname"); final String raidname = (String) info.previousArgs().get("raidname");
return CommandHelper.getTownyWarTowns(warname);
})
),
new PlayerArgument("player")
.setOptional(true)
.withPermission("AlathraWar.admin"),
new StringArgument("side")
.replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> {
String warName = (String) info.previousArgs().get("warname");
War war = WarData.getWar(warName); final Raid raid = RaidData.getRaid(raidname);
if (war != null) {
return war.getSides();
}
return Collections.emptyList(); if (raid == null) return Collections.emptyList();
})
),
new BooleanArgument("minutemen")
.setOptional(true)
.withPermission("AlathraWar.admin")
) return List.of(raid.getRaiderSide(), raid.getDefenderSide());
.executesPlayer((Player p, CommandArguments args) -> raidJoin(p, args, false)); })
),
new PlayerArgument("player")
.setOptional(true)
.withPermission("AlathraWar.admin"),
new BooleanArgument("minutemen")
.setOptional(true)
.withPermission("AlathraWar.admin")
)
.executesPlayer((Player p, CommandArguments args) -> raidJoin(p, args, false));
} }
public static CommandAPICommand commandLeave() { public static CommandAPICommand commandLeave() {
return new CommandAPICommand("leave") return new CommandAPICommand("leave")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> ArgumentSuggestions.stringCollection(info ->
WarData.getWarsNames() WarData.getWarsNames()
) )
), ),
new StringArgument("town") new StringArgument("town")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final String warname = (String) info.previousArgs().get("warname"); final String warname = (String) info.previousArgs().get("warname");
return CommandHelper.getTownyWarTowns(warname); return CommandHelper.getTownyWarTowns(warname);
}) })
), ),
new PlayerArgument("player") new PlayerArgument("player")
.setOptional(true) .setOptional(true)
.withPermission("AlathraWar.admin") .withPermission("AlathraWar.admin")
) )
.executesPlayer((Player p, CommandArguments args) -> raidLeave(p, args, false)); .executesPlayer((Player p, CommandArguments args) -> raidLeave(p, args, false));
} }
public static CommandAPICommand commandAbandon() { public static CommandAPICommand commandAbandon() {
return new CommandAPICommand("abandon") return new CommandAPICommand("abandon")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> ArgumentSuggestions.stringCollection(info ->
WarData.getWarsNames() WarData.getWarsNames()
) )
), ),
new StringArgument("town") new StringArgument("town")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final String warname = (String) info.previousArgs().get("warname"); final String warname = (String) info.previousArgs().get("warname");
return CommandHelper.getTownyWarTowns(warname); return CommandHelper.getTownyWarTowns(warname);
}) })
) )
) )
.executesPlayer(RaidCommand::raidAbandon); .executesPlayer(RaidCommand::raidAbandon);
} }
public static CommandAPICommand commandList() { public static CommandAPICommand commandList() {
return new CommandAPICommand("list") return new CommandAPICommand("list")
.executesPlayer(RaidCommand::raidsList); .executesPlayer(RaidCommand::raidsList);
} }
public static CommandAPICommand commandHelp() { public static CommandAPICommand commandHelp() {
return new CommandAPICommand("help") return new CommandAPICommand("help")
.executesPlayer(RaidCommand::raidHelp); .executesPlayer(RaidCommand::raidHelp);
} }
/** /**
@@ -213,7 +207,7 @@ public class RaidCommand {
boolean townExists = false; boolean townExists = false;
if (!(args.get("warname") instanceof final String argWarName)) if (!(args.get("warname") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cUsage: /alathrawaradmin create raid [war] [raidTown] (gatherTown/\"defaultCode\") (owner) (override)").build());
for (final War war : WarData.getWars()) { for (final War war : WarData.getWars()) {
if (war.getName().equalsIgnoreCase(argWarName)) { if (war.getName().equalsIgnoreCase(argWarName)) {
@@ -413,19 +407,19 @@ public class RaidCommand {
// Player participance check // Player participance check
Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull(); Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull();
int sideR = war.getSide(leaderTown.getName().toLowerCase()); TownWarState sideR = war.getState(leaderTown.getName().toLowerCase());
if (sideR == 0) { if (sideR == TownWarState.NOT_PARTICIPANT) {
if (admin) p.sendMessage(Helper.chatLabel() + "You are not in this war."); if (admin) p.sendMessage(Helper.chatLabel() + "You are not in this war.");
raidOwner.sendMessage(Helper.chatLabel() + "You are not in this war."); raidOwner.sendMessage(Helper.chatLabel() + "You are not in this war.");
return; return;
} else if (sideR == -1) { } else if (sideR == TownWarState.SURRENDERED) {
if (admin) p.sendMessage(Helper.chatLabel() + "You have surrendered."); if (admin) p.sendMessage(Helper.chatLabel() + "You have surrendered.");
raidOwner.sendMessage(Helper.chatLabel() + "You have surrendered."); raidOwner.sendMessage(Helper.chatLabel() + "You have surrendered.");
return; return;
} }
// Attacking own side // Attacking own side
if (war.getSide(raidedTown) == sideR) { if (war.getState(raidedTown) == sideR) {
if (admin) p.sendMessage(Helper.chatLabel() + "You cannot attack your own towns."); if (admin) p.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
raidOwner.sendMessage(Helper.chatLabel() + "You cannot attack your own towns."); raidOwner.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
return; return;
@@ -451,12 +445,15 @@ public class RaidCommand {
Bukkit.broadcastMessage(Helper.chatLabel() + "As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!"); Bukkit.broadcastMessage(Helper.chatLabel() + "As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!");
Bukkit.broadcastMessage(Helper.chatLabel() + "All players from the defending side have been drafted for the town's defense."); Bukkit.broadcastMessage(Helper.chatLabel() + "All players from the defending side have been drafted for the town's defense.");
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of " Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of "
+ raidedTown.getName() + " will begin in " + (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!"); + raidedTown.getName() + " will begin in " + (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!");
Bukkit.broadcastMessage(Helper.chatLabel() + Bukkit.broadcastMessage(Helper.chatLabel() +
"The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!"); "The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
Main.warLogger.log(raidOwner.getName() + " started a raid."); Main.warLogger.log(raidOwner.getName() + " started a raid.");
if (admin) Main.warLogger.log(raidOwner.getName() + " started a raid from admin interference."); if (admin) {
Main.warLogger.log(raidOwner.getName() + " started a raid from admin interference.");
p.sendMessage(Helper.color("&cForcefully started raid from the console."));
}
Main.warLogger.log("As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are raiding the town of " + raidedTown.getName() + "!"); Main.warLogger.log("As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are raiding the town of " + raidedTown.getName() + "!");
Main.warLogger.log("The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!"); Main.warLogger.log("The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
} }
@@ -492,7 +489,7 @@ public class RaidCommand {
} }
//find our desired raid and stop it //find our desired raid and stop it
Raid raid = RaidData.getRaidOrNull(argWarName + "-" + argTown); Raid raid = RaidData.getRaid(argWarName + "-" + argTown);
if (raid != null) { if (raid != null) {
p.sendMessage(Helper.chatLabel() + "raid cancelled"); p.sendMessage(Helper.chatLabel() + "raid cancelled");
@@ -504,101 +501,81 @@ public class RaidCommand {
} }
protected static void raidJoin(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException { protected static void raidJoin(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
if (!(args.get("warname") instanceof final String argWarName)) if (!(args.get("raidname") instanceof final String argRaidName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name!").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a raid name!").build());
if (!(args.get("town") instanceof final String argTown)) if (!(args.get("side") instanceof final String argSide))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a town name!").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a side!").build());
//Grab raid!
Raid raid = RaidData.getRaidOrNull(argWarName + "-" + argTown);
final Raid raid = RaidData.getRaid(argRaidName);
if (raid == null) if (raid == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "No raid is gathering in this town or this town does not exist!").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThat raid does not exist!").build());
if (raid.getWar().getName().equalsIgnoreCase(argWarName)) { final War war = raid.getWar();
final Player joiner = (Player) args.getOptional("player").orElse(p); if (war == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThe war does not exist!").build());
if (joiner == null) { final Player joiner = (Player) args.getOptional("player").orElse(p);
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Joiner is Null").build()); if (joiner == null)
} throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Joiner is Null").build());
if (!(args.get("side") instanceof final String argSide))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a side!").build());
if (admin) { if (admin) {
if (argSide != null) { if (argSide != null) {
if (argSide.equalsIgnoreCase(raid.getDefenderSide())) { if (argSide.equalsIgnoreCase(raid.getDefenderSide())) {
if (!raid.getDefenderPlayers().contains(joiner.getName())) if (!raid.getDefenderPlayers().contains(joiner.getName()))
raid.getDefenderPlayers().add(joiner.getName()); raid.getDefenderPlayers().add(joiner.getName());
p.sendMessage(Helper.chatLabel() + "Player " + joiner.getName() + " added to defender side."); p.sendMessage(Helper.chatLabel() + "Player " + joiner.getName() + " added to defender side.");
Main.warLogger.log("Player " + joiner.getName() + " added to defender side."); Main.warLogger.log("Player " + joiner.getName() + " added to defender side.");
joiner.sendMessage(Helper.chatLabel() + "You were forcefully added to the defender side against the raid party on " + raid.getRaidedTown() + " by an admin."); joiner.sendMessage(Helper.chatLabel() + "You were forcefully added to the defender side against the raid party on " + raid.getRaidedTown() + " by an admin.");
return; return;
} else {
if (!raid.getRaiderPlayers().contains(joiner.getName()))
raid.getRaiderPlayers().add(joiner.getName());
p.sendMessage(Helper.chatLabel() + "Player " + joiner.getName() + " added to raider side.");
Main.warLogger.log("Player " + joiner.getName() + " added to raider side.");
joiner.sendMessage(Helper.chatLabel() + "You were forcefully added to the raid party on " + raid.getRaidedTown() + " by an admin. Leaving the gather town will remove you from the raid party.");
}
}
}
if (!raid.getWar().getSide1Players().contains(joiner.getName()) && !raid.getWar().getSide2Players().contains(joiner.getName())) {
joiner.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
}
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
//also 12 hours min platim by default
int minuteman = CommandHelper.isPlayerMinuteman(joiner.getName());
boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
if (minuteManOverride) {
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
}
if (!minuteManOverride) {
if (minuteman != 0) {
if (minuteman == 1) {
//player has joined to recently
if (admin)
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
joiner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
return;
} else if (minuteman == 2) {
//player has played too little
if (admin)
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
joiner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
return;
}
}
}
//check if gather phase
if (!admin) {
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
try {
//check if the player is in the gather town
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
raid.addActiveRaider(joiner.getName());
joiner.sendMessage(Helper.chatLabel() + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(Helper.chatLabel() + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
} else {
joiner.sendMessage(Helper.chatLabel() + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
}
} catch (TownyException e) {
throw new RuntimeException(e);
}
} else { } else {
joiner.sendMessage(Helper.chatLabel() + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!"); if (!raid.getRaiderPlayers().contains(joiner.getName()))
raid.getRaiderPlayers().add(joiner.getName());
p.sendMessage(Helper.chatLabel() + "Player " + joiner.getName() + " added to raider side.");
Main.warLogger.log("Player " + joiner.getName() + " added to raider side.");
joiner.sendMessage(Helper.chatLabel() + "You were forcefully added to the raid party on " + raid.getRaidedTown() + " by an admin. Leaving the gather town will remove you from the raid party.");
} }
} else { }
}
if (!raid.getWar().getSide1Players().contains(joiner.getName()) && !raid.getWar().getSide2Players().contains(joiner.getName())) {
joiner.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
}
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
//also 12 hours min platim by default
int minuteman = CommandHelper.isPlayerMinuteman(joiner.getName());
boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
if (minuteManOverride) {
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
}
if (!minuteManOverride) {
if (minuteman != 0) {
if (minuteman == 1) {
//player has joined to recently
if (admin)
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
joiner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
return;
} else if (minuteman == 2) {
//player has played too little
if (admin)
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
joiner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
return;
}
}
}
//check if gather phase
if (!admin) {
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
try { try {
//check if the player is in the gather town //check if the player is in the gather town
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord()); ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
@@ -612,18 +589,34 @@ public class RaidCommand {
} catch (TownyException e) { } catch (TownyException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} else {
joiner.sendMessage(Helper.chatLabel() + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
}
} else {
try {
//check if the player is in the gather town
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
raid.addActiveRaider(joiner.getName());
joiner.sendMessage(Helper.chatLabel() + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(Helper.chatLabel() + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
} else {
joiner.sendMessage(Helper.chatLabel() + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
}
} catch (TownyException e) {
throw new RuntimeException(e);
} }
raid.save();
} }
raid.save();
} }
protected static void raidLeave(Player player, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException { protected static void raidLeave(Player player, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
//Get raid! //Get raid!
final Player p = (Player) args.getOptional("leader").orElse(player); final Player p = (Player) args.getOptional("player").orElse(player);
if (p == null) { if (p == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Raided is Null").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Raider is Null").build());
} }
if (!(args.get("warname") instanceof final String argWarName)) if (!(args.get("warname") instanceof final String argWarName))
@@ -633,7 +626,7 @@ public class RaidCommand {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a town name!").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a town name!").build());
Raid raid = RaidData.getRaidOrNull(argWarName + "-" + argTown); Raid raid = RaidData.getRaid(argWarName + "-" + argTown);
if (raid == null) { if (raid == null) {
p.sendMessage(Helper.chatLabel() + "No raid is gathering in this town or this town does not exist!"); p.sendMessage(Helper.chatLabel() + "No raid is gathering in this town or this town does not exist!");
if (admin) if (admin)
@@ -667,6 +660,11 @@ public class RaidCommand {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
if (admin) {
player.sendMessage(Helper.chatLabel() + "Forced player " + p.getName() + " to leave raid on " + raid.getRaidedTown().getName() + " in war " + argWarName);
Main.warLogger.log("Forced player " + p.getName() + " to leave raid on " + raid.getRaidedTown().getName() + " in war " + argWarName);
}
} }
raid.save(); raid.save();
@@ -687,7 +685,7 @@ public class RaidCommand {
//Get raid //Get raid
Raid raid = RaidData.getRaidOrNull(argWarName + "-" + argTown); Raid raid = RaidData.getRaid(argWarName + "-" + argTown);
if (raid == null) if (raid == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThis raid does not exist!").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThis raid does not exist!").build());
@@ -751,17 +749,17 @@ public class RaidCommand {
private static void fail(CommandSender p, CommandArguments args, String type) throws WrapperCommandSyntaxException { private static void fail(CommandSender p, CommandArguments args, String type) throws WrapperCommandSyntaxException {
switch (type) { switch (type) {
case "permissions" -> case "permissions" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou do not have permission to do this.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou do not have permission to do this.").build());
case "syntax" -> case "syntax" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cInvalid Syntax. /raid help").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cInvalid Syntax. /raid help").build());
case "noRaids" -> case "noRaids" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThere are currently no Raids in progress.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThere are currently no Raids in progress.").build());
case "badName" -> case "badName" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cA raid could not be found with this Name! Type /raid list to view current raids.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cA raid could not be found with this Name! Type /raid list to view current raids.").build());
case "owner" -> case "owner" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cOnly the player who started the raid can abandon it.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cOnly the player who started the raid can abandon it.").build());
default -> default ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cInvalid Arguments. /raid help").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cInvalid Arguments. /raid help").build());
} }
} }
} }
@@ -15,6 +15,7 @@ import me.ShermansWorld.AlathraWar.*;
import me.ShermansWorld.AlathraWar.data.RaidData; import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.SiegeData; import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.data.WarData; import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@@ -25,111 +26,109 @@ import java.util.HashSet;
public class SiegeCommand { public class SiegeCommand {
public SiegeCommand() { public SiegeCommand() {
new CommandAPICommand("siege") new CommandAPICommand("siege")
.withSubcommands( .withSubcommands(
commandStart(), commandStart(),
commandStop(), commandStop(),
commandAbandon(), commandAbandon(),
commandList(), commandList(),
commandHelp() commandHelp()
) )
.executesPlayer((sender, args) -> { .executesPlayer((sender, args) -> {
if (args.count() == 0) if (args.count() == 0)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid Arguments. /siege help").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid Arguments. /siege help").build());
}) })
.register(); .register();
} }
public static CommandAPICommand commandStart() { public static CommandAPICommand commandStart() {
return new CommandAPICommand("start") return new CommandAPICommand("start")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.strings( ArgumentSuggestions.strings(
WarData.getWarsNames() WarData.getWarsNames()
) )
), ),
new StringArgument("target") new StringArgument("town")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final String warname = (String) info.previousArgs().get("warname"); final String warname = (String) info.previousArgs().get("warname");
return CommandHelper.getTownyWarTowns(warname); return CommandHelper.getTownyWarTowns(warname);
}) })
), ),
new PlayerArgument("leader") new PlayerArgument("leader")
.setOptional(true) .setOptional(true)
.withPermission("AlathraWar.admin"), .withPermission("AlathraWar.admin"),
new BooleanArgument("minutemen") new BooleanArgument("minutemen")
.setOptional(true) .setOptional(true)
.withPermission("AlathraWar.admin") .withPermission("AlathraWar.admin")
) )
.executesPlayer((Player p, CommandArguments args) -> siegeStart(p, args, false)); .executesPlayer((Player p, CommandArguments args) -> siegeStart(p, args, false));
} }
public static CommandAPICommand commandStop() { public static CommandAPICommand commandStop() {
return new CommandAPICommand("stop") return new CommandAPICommand("stop")
.withPermission("AlathraWar.admin") .withPermission("AlathraWar.admin")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> ArgumentSuggestions.stringCollection(info ->
WarData.getWarsNames() WarData.getWarsNames()
) )
), ),
new StringArgument("town") new StringArgument("town")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final String warname = (String) info.previousArgs().get("warname"); final String warname = (String) info.previousArgs().get("warname");
return CommandHelper.getTownyWarTowns(warname); return CommandHelper.getTownyWarTowns(warname);
}) })
) )
) )
.executesPlayer(SiegeCommand::siegeStop); .executesPlayer(SiegeCommand::siegeStop);
} }
public static CommandAPICommand commandAbandon() { public static CommandAPICommand commandAbandon() {
return new CommandAPICommand("abandon") return new CommandAPICommand("abandon")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> ArgumentSuggestions.stringCollection(info ->
WarData.getWarsNames() WarData.getWarsNames()
) )
), ),
new StringArgument("town") new StringArgument("town")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final String warname = (String) info.previousArgs().get("warname"); final String warname = (String) info.previousArgs().get("warname");
return CommandHelper.getTownyWarTowns(warname); return CommandHelper.getTownyWarTowns(warname);
}) })
) )
) )
.executesPlayer(SiegeCommand::siegeAbandon); .executesPlayer(SiegeCommand::siegeAbandon);
} }
public static CommandAPICommand commandList() { public static CommandAPICommand commandList() {
return new CommandAPICommand("list") return new CommandAPICommand("list")
.executesPlayer(SiegeCommand::siegeList); .executesPlayer(SiegeCommand::siegeList);
} }
public static CommandAPICommand commandHelp() { public static CommandAPICommand commandHelp() {
return new CommandAPICommand("help") return new CommandAPICommand("help")
.executesPlayer(SiegeCommand::siegeHelp); .executesPlayer(SiegeCommand::siegeHelp);
} }
protected static void siegeStart(Player sender, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException { protected static void siegeStart(Player sender, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
// if (!(sender instanceof Player)) return;
if (!(args.get("warname") instanceof final String argWarName)) if (!(args.get("warname") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cUsage: /alathrawaradmin create siege [war] [town] (owner) (force).").build());
//if this is admin mode use the forth arg instad of sender. //if this is admin mode use the forth arg instad of sender.
//if player is null after this then force end //if player is null after this then force end
final Player siegeOwner = (Player) args.getOptional("leader").orElse(sender); final Player siegeOwner = (Player) args.getOptional("leader").orElse(sender);
if (siegeOwner == null) { if (siegeOwner == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Owner is Null").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("You need to pick a valid leader.").build());
}
/*if (args.length < 3) { /*if (args.length < 3) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "/war siege [war] [town]").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "/war siege [war] [town]").build());
@@ -147,14 +146,15 @@ public class SiegeCommand {
// Player participance check // Player participance check
Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull(); Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
int side = war.getSide(leaderTown.getName().toLowerCase()); TownWarState side = war.getState(leaderTown.getName().toLowerCase());
//DEBUG PRINT // TODO DEBUG PRINT
Main.warLogger.log("Leader Town: " + leaderTown.getName()); Main.warLogger.log("Leader Town: " + leaderTown.getName());
Main.warLogger.log("Siege Owner: " + siegeOwner.getName()); Main.warLogger.log("Siege Owner: " + siegeOwner.getName());
sender.sendMessage("Leader Town: " + leaderTown.getName()); sender.sendMessage("Leader Town: " + leaderTown.getName());
sender.sendMessage("Siege Owner: " + siegeOwner.getName()); sender.sendMessage("Siege Owner: " + siegeOwner.getName());
//DEBUG PRINT // TODO DEBUG PRINT
for (String t : war.getSide1Towns()) { for (String t : war.getSide1Towns()) {
Main.warLogger.log("Side1 town: " + t); Main.warLogger.log("Side1 town: " + t);
sender.sendMessage("Side1 town: " + t); sender.sendMessage("Side1 town: " + t);
@@ -164,11 +164,11 @@ public class SiegeCommand {
sender.sendMessage("Side2 town: " + t); sender.sendMessage("Side2 town: " + t);
} }
if (side == 0) { if (side == TownWarState.NOT_PARTICIPANT) {
siegeOwner.sendMessage(Helper.chatLabel() + "You are not in this war."); siegeOwner.sendMessage(Helper.chatLabel() + "You are not in this war.");
if (admin) sender.sendMessage(Helper.chatLabel() + "You are not in this war."); if (admin) sender.sendMessage(Helper.chatLabel() + "You are not in this war.");
return; return;
} else if (side == -1) { } else if (side == TownWarState.SURRENDERED) {
siegeOwner.sendMessage(Helper.chatLabel() + "You have surrendered."); siegeOwner.sendMessage(Helper.chatLabel() + "You have surrendered.");
if (admin) sender.sendMessage(Helper.chatLabel() + "You have surrendered."); if (admin) sender.sendMessage(Helper.chatLabel() + "You have surrendered.");
return; return;
@@ -202,7 +202,7 @@ public class SiegeCommand {
} }
} }
if (!(args.get("target") instanceof final String argTownName)) if (!(args.get("town") instanceof final String argTownName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Specify a town! /siege start [war] [town]").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Specify a town! /siege start [war] [town]").build());
// Town check // Town check
@@ -213,8 +213,6 @@ public class SiegeCommand {
sender.sendMessage(Helper.chatLabel() + "That town does not exist! /siege start [war] [town]"); sender.sendMessage(Helper.chatLabel() + "That town does not exist! /siege start [war] [town]");
return; return;
} }
Main.warLogger.log("Attacked Town: " + town.getName().toLowerCase());
sender.sendMessage("Attacked Town: " + town.getName().toLowerCase());
// Is being raided check // Is being raided check
for (Raid r : RaidData.getRaids()) { for (Raid r : RaidData.getRaids()) {
@@ -227,7 +225,7 @@ public class SiegeCommand {
} }
// Attacking own side // Attacking own side
if (war.getSide(town) == side) { if (war.getState(town) == side) {
siegeOwner.sendMessage(Helper.chatLabel() + "You cannot attack your own towns."); siegeOwner.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
if (admin) sender.sendMessage(Helper.chatLabel() + "You cannot attack your own towns."); if (admin) sender.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
return; return;
@@ -237,7 +235,14 @@ public class SiegeCommand {
SiegeData.addSiege(siege); SiegeData.addSiege(siege);
war.addSiege(siege); war.addSiege(siege);
Bukkit.broadcastMessage(Helper.chatLabel() + "A siege has been laid on " + siege.getTown() + " by " + siege.getAttackerSide() + "!"); Bukkit.broadcastMessage(Helper.chatLabel() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide() + "!");
if (admin)
sender.sendMessage(Helper.color("&cForcefully started siege from the console."));
// TODO Debug logs...
Main.warLogger.log("Attacked Town: " + town.getName().toLowerCase());
sender.sendMessage("Attacked Town: " + town.getName().toLowerCase());
war.save(); war.save();
siege.start(); siege.start();
@@ -319,7 +324,7 @@ public class SiegeCommand {
sender.sendMessage(new ColorParser(Helper.chatLabel() + "Sieges currently in progress:").build()); sender.sendMessage(new ColorParser(Helper.chatLabel() + "Sieges currently in progress:").build());
for (Siege siege : sieges) { for (Siege siege : sieges) {
War war = siege.getWar(); War war = siege.getWar();
String color = (siege.getSide1AreAttackers() && (war.getSide(siege.getTown().getName().toLowerCase()) == 1)) ? "&c" : "&9"; String color = (siege.getSide1AreAttackers() && (war.getState(siege.getTown().getName().toLowerCase()) == TownWarState.SIDE1)) ? "&c" : "&9";
sender.sendMessage(new ColorParser(war.getName() + " - " + color + siege.getTown().getName().toLowerCase()).build()); sender.sendMessage(new ColorParser(war.getName() + " - " + color + siege.getTown().getName().toLowerCase()).build());
sender.sendMessage(new ColorParser(war.getSide1() + " - " + (siege.getSide1AreAttackers() ? siege.getAttackerPoints() : siege.getDefenderPoints())).build()); sender.sendMessage(new ColorParser(war.getSide1() + " - " + (siege.getSide1AreAttackers() ? siege.getAttackerPoints() : siege.getDefenderPoints())).build());
sender.sendMessage(new ColorParser(war.getSide2() + " - " + (siege.getSide1AreAttackers() ? siege.getDefenderPoints() : siege.getAttackerPoints())).build()); sender.sendMessage(new ColorParser(war.getSide2() + " - " + (siege.getSide1AreAttackers() ? siege.getDefenderPoints() : siege.getAttackerPoints())).build());
@@ -13,6 +13,7 @@ import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
import dev.jorel.commandapi.executors.CommandArguments; import dev.jorel.commandapi.executors.CommandArguments;
import me.ShermansWorld.AlathraWar.*; import me.ShermansWorld.AlathraWar.*;
import me.ShermansWorld.AlathraWar.data.WarData; import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -26,126 +27,125 @@ import java.util.List;
public class WarCommand { public class WarCommand {
public WarCommand() { public WarCommand() {
new CommandAPICommand("war") new CommandAPICommand("war")
.withSubcommands( .withSubcommands(
commandCreate(), commandCreate(),
commandDelete(), commandDelete(),
commandJoin(), commandJoin(),
commandSurrender(), commandSurrender(),
commandList(), commandList(),
commandInfo(), commandInfo(),
commandHelp() commandHelp()
) )
.executesPlayer((sender, args) -> { .executesPlayer((sender, args) -> {
if (args.count() == 0) if (args.count() == 0)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid Arguments. /war help").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid Arguments. /war help").build());
}) })
.register(); .register();
} }
public static CommandAPICommand commandCreate() { public static CommandAPICommand commandCreate() {
return new CommandAPICommand("create") return new CommandAPICommand("create")
.withPermission("AlathraWar.admin") .withPermission("AlathraWar.admin")
.withArguments( .withArguments(
new StringArgument("warname"), new StringArgument("warname"),
new StringArgument("side1") new StringArgument("side1")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final List<String> nations = CommandHelper.getTownyNations(); final List<String> nations = CommandHelper.getTownyNations();
final List<String> towns = CommandHelper.getTownyTowns(); final List<String> towns = CommandHelper.getTownyTowns();
Collections.sort(nations); Collections.sort(nations);
Collections.sort(towns); Collections.sort(towns);
nations.addAll(towns); nations.addAll(towns);
return nations; return nations;
}) })
), ),
new StringArgument("side2") new StringArgument("side2")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
final List<String> nations = CommandHelper.getTownyNations(); final List<String> nations = CommandHelper.getTownyNations();
final List<String> towns = CommandHelper.getTownyTowns(); final List<String> towns = CommandHelper.getTownyTowns();
Collections.sort(nations); Collections.sort(nations);
Collections.sort(towns); Collections.sort(towns);
nations.addAll(towns); nations.addAll(towns);
return nations; return nations;
}) })
) )
) )
.executesPlayer(WarCommand::warCreate); .executesPlayer(WarCommand::warCreate);
} }
public static CommandAPICommand commandDelete() { public static CommandAPICommand commandDelete() {
return new CommandAPICommand("delete") return new CommandAPICommand("delete")
.withPermission("AlathraWar.admin") .withPermission("AlathraWar.admin")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> WarData.getWarsNames()) ArgumentSuggestions.stringCollection(info -> WarData.getWarsNames())
) )
) )
.executesPlayer(WarCommand::warDelete); .executesPlayer(WarCommand::warDelete);
} }
public static CommandAPICommand commandJoin() { public static CommandAPICommand commandJoin() {
return new CommandAPICommand("join") return new CommandAPICommand("join")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> CommandHelper.getWarNames()) ArgumentSuggestions.stringCollection(info -> CommandHelper.getWarNames())
), ),
new StringArgument("side") new StringArgument("side")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> { ArgumentSuggestions.stringCollection(info -> {
String warName = (String) info.previousArgs().get("warname"); final String warname = (String) info.previousArgs().get("warname");
War war = WarData.getWar(warName); final War war = WarData.getWar(warname);
if (war != null) {
return war.getSides();
}
return Collections.emptyList(); if (war == null) return Collections.emptyList();
})
), return war.getSides();
new PlayerArgument("player").setOptional(true).withPermission("AlathraWar.admin") })
) ),
.executesPlayer((Player p, CommandArguments args) -> warJoin(p, args, false)); new PlayerArgument("player").setOptional(true).withPermission("AlathraWar.admin")
)
.executesPlayer((Player p, CommandArguments args) -> warJoin(p, args, false));
} }
public static CommandAPICommand commandSurrender() { public static CommandAPICommand commandSurrender() {
return new CommandAPICommand("surrender") return new CommandAPICommand("surrender")
.withArguments( .withArguments(
new StringArgument("warname") new StringArgument("warname")
.replaceSuggestions( .replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> CommandHelper.getWarNames()) ArgumentSuggestions.stringCollection(info -> CommandHelper.getWarNames())
), ),
new PlayerArgument("player") new PlayerArgument("player")
.setOptional(true) .setOptional(true)
.withPermission("AlathraWar.admin") .withPermission("AlathraWar.admin")
) )
.executesPlayer((Player p, CommandArguments args) -> warSurrender(p, args, false)); .executesPlayer((Player p, CommandArguments args) -> warSurrender(p, args, false));
} }
public static CommandAPICommand commandList() { public static CommandAPICommand commandList() {
return new CommandAPICommand("list") return new CommandAPICommand("list")
.executesPlayer(WarCommand::warList); .executesPlayer(WarCommand::warList);
} }
public static CommandAPICommand commandInfo() { public static CommandAPICommand commandInfo() {
return new CommandAPICommand("info") return new CommandAPICommand("info")
.withArguments( .withArguments(
new PlayerArgument("player") new PlayerArgument("player")
) )
.executesPlayer(WarCommand::warInfo); .executesPlayer(WarCommand::warInfo);
} }
public static CommandAPICommand commandHelp() { public static CommandAPICommand commandHelp() {
return new CommandAPICommand("help") return new CommandAPICommand("help")
.executesPlayer(WarCommand::warHelp); .executesPlayer(WarCommand::warHelp);
} }
protected static void warCreate(CommandSender p, CommandArguments args) throws WrapperCommandSyntaxException { protected static void warCreate(CommandSender p, CommandArguments args) throws WrapperCommandSyntaxException {
@@ -175,12 +175,12 @@ public class WarCommand {
war.save(); war.save();
Bukkit.broadcastMessage(Helper.chatLabel() + "War created with the name " + argWarName + ", " Bukkit.broadcastMessage(Helper.chatLabel() + "War created with the name " + argWarName + ", "
+ argSide1 + " vs. " + argSide2); + argSide1 + " vs. " + argSide2);
Main.warLogger.log(p.getName() + " created a new war with the name " + argWarName + ", " + argSide1 Main.warLogger.log(p.getName() + " created a new war with the name " + argWarName + ", " + argSide1
+ " vs. " + argSide2); + " vs. " + argSide2);
} else { } else {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
+ "Invalid Arguments. /war create [name] [side1] [side2]").build()); + "Invalid Arguments. /war create [name] [side1] [side2]").build());
} }
} }
@@ -208,7 +208,7 @@ public class WarCommand {
Main.warLogger.log(p.getName() + " deleted " + argWarName); Main.warLogger.log(p.getName() + " deleted " + argWarName);
} else { } else {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
+ "Invalid Arguments. /war delete [name]").build()); + "Invalid Arguments. /war delete [name]").build());
} }
} }
@@ -221,7 +221,7 @@ public class WarCommand {
// Sufficient args check // Sufficient args check
if (args.count() < 2) if (args.count() < 2)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
+ "/war join [name] [side], type /war list to view current wars").build()); + "/war join [name] [side], type /war list to view current wars").build());
if (!(args.get("warname") instanceof final String argWarName)) if (!(args.get("warname") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name.").build());
@@ -234,6 +234,9 @@ public class WarCommand {
if (!(args.get("side") instanceof final String argSide)) if (!(args.get("side") instanceof final String argSide))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a side.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a side.").build());
if (!war.isSideValid(argSide))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThat side does not exist in that war.").build());
if (!(args.getOptional("player").orElse(null) instanceof @Nullable Player argPlayer)) if (!(args.getOptional("player").orElse(null) instanceof @Nullable Player argPlayer))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cPlayer not found.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cPlayer not found.").build());
@@ -278,11 +281,11 @@ public class WarCommand {
} }
// Side checks // Side checks
final int side = war.getSide(town.getName().toLowerCase()); final TownWarState side = war.getState(town.getName().toLowerCase());
if (side == -1) { if (side == TownWarState.SURRENDERED) {
argPlayer.sendMessage(Helper.chatLabel() + "You've already surrendered!"); argPlayer.sendMessage(Helper.chatLabel() + "You've already surrendered!");
return; return;
} else if (side > 0) { } else if (side != TownWarState.NOT_PARTICIPANT) {
argPlayer.sendMessage(Helper.chatLabel() + "You're already in this war!"); argPlayer.sendMessage(Helper.chatLabel() + "You're already in this war!");
return; return;
} }
@@ -318,7 +321,7 @@ public class WarCommand {
// Sufficient args check // Sufficient args check
if (args.count() < 1) { if (args.count() < 1) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
+ "/war surrender [name], type /war list to view current wars").build()); + "/war surrender [name], type /war list to view current wars").build());
} }
if (!(args.get("warname") instanceof final String argWarName)) if (!(args.get("warname") instanceof final String argWarName))
@@ -328,7 +331,7 @@ public class WarCommand {
War war = WarData.getWar(argWarName); War war = WarData.getWar(argWarName);
if (war == null) { if (war == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
+ "War not found. Type /war list to view current wars").build()); + "War not found. Type /war list to view current wars").build());
} }
if (!(args.get("reason") instanceof final String argReason)) if (!(args.get("reason") instanceof final String argReason))
@@ -405,13 +408,13 @@ public class WarCommand {
p.sendMessage(new ColorParser(Helper.chatLabel() + p.getName() + "'s wars:").build()); p.sendMessage(new ColorParser(Helper.chatLabel() + p.getName() + "'s wars:").build());
for (War war : WarData.getWars()) { for (War war : WarData.getWars()) {
int side = war.getSide(res.getTownOrNull()); TownWarState side = war.getState(res.getTownOrNull());
if (side != 0) { if (side != TownWarState.NOT_PARTICIPANT) {
if (side == -1) { if (side == TownWarState.SURRENDERED) {
p.sendMessage(war.getName() + " - Surrendered"); p.sendMessage(war.getName() + " - Surrendered");
} else if (side == 1) { } else if (side == TownWarState.SIDE1) {
p.sendMessage(war.getName() + " - " + war.getSide1()); p.sendMessage(war.getName() + " - " + war.getSide1());
} else if (side == 2) { } else if (side == TownWarState.SIDE2) {
p.sendMessage(war.getName() + " - " + war.getSide2()); p.sendMessage(war.getName() + " - " + war.getSide2());
} }
} }
@@ -38,7 +38,7 @@ public class RaidData {
* @param name - Name to check * @param name - Name to check
* @return Raid or Null * @return Raid or Null
*/ */
public static @Nullable Raid getRaidOrNull(String name) { public static @Nullable Raid getRaid(String name) {
for (Raid raid : raids) { for (Raid raid : raids) {
if (raid.getName().equalsIgnoreCase(name)) return raid; if (raid.getName().equalsIgnoreCase(name)) return raid;
} }
@@ -111,8 +111,8 @@ public class WarData {
public static War fromMap(HashMap<String, Object> fileData) { public static War fromMap(HashMap<String, Object> fileData) {
War war = new War((String) fileData.get("name"), War war = new War((String) fileData.get("name"),
(String) fileData.get("side1"), (String) fileData.get("side1"),
(String) fileData.get("side2") (String) fileData.get("side2")
); );
war.setSide1Towns((ArrayList<String>) fileData.get("side1Towns")); war.setSide1Towns((ArrayList<String>) fileData.get("side1Towns"));
@@ -0,0 +1,7 @@
package me.ShermansWorld.AlathraWar.enums;
public enum AdminCommandFailEnum {
PERMISSIONS,
SYNTAX,
HELP
}
@@ -0,0 +1,8 @@
package me.ShermansWorld.AlathraWar.enums;
public enum TownWarState {
NOT_PARTICIPANT,
SURRENDERED,
SIDE1,
SIDE2,
}
@@ -2,8 +2,11 @@ package me.ShermansWorld.AlathraWar.hooks;
import me.ShermansWorld.AlathraWar.Helper; import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.War; import me.ShermansWorld.AlathraWar.War;
import me.ShermansWorld.AlathraWar.listeners.JoinListener;
import me.neznamy.tab.api.TabAPI; import me.neznamy.tab.api.TabAPI;
import me.neznamy.tab.api.TabPlayer; import me.neznamy.tab.api.TabPlayer;
import me.neznamy.tab.api.event.EventBus;
import me.neznamy.tab.api.event.player.PlayerLoadEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -17,6 +20,21 @@ public class TABHook {
tabAPI = TabAPI.getInstance(); tabAPI = TabAPI.getInstance();
enabled = true; enabled = true;
registerPlayerLoadListener();
}
private static void registerPlayerLoadListener() {
if (!enabled) return;
EventBus eventBus = tabAPI.getEventBus();
if (eventBus == null) return;
eventBus.register(PlayerLoadEvent.class, e -> {
TabPlayer tabPlayer = e.getPlayer();
if (tabPlayer.getPlayer() instanceof Player p)
JoinListener.checkPlayer(p);
});
} }
public static void assignSide1WarSuffix(Player p, War war) { public static void assignSide1WarSuffix(Player p, War war) {
@@ -27,7 +45,7 @@ public class TABHook {
if (tabAPI.getTabListFormatManager() == null) return; if (tabAPI.getTabListFormatManager() == null) return;
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
Helper.color(" &c[") + war.getSide1() + "]&r"); Helper.color(" &c[") + war.getSide1() + "]&r");
} }
public static void assignSide2WarSuffix(Player p, War war) { public static void assignSide2WarSuffix(Player p, War war) {
@@ -38,7 +56,7 @@ public class TABHook {
if (tabAPI.getTabListFormatManager() == null) return; if (tabAPI.getTabListFormatManager() == null) return;
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
Helper.color(" &9[") + war.getSide2() + "]&r"); Helper.color(" &9[") + war.getSide2() + "]&r");
} }
public static void assignSide1WarSuffixMerc(Player p, War war) { public static void assignSide1WarSuffixMerc(Player p, War war) {
@@ -49,7 +67,7 @@ public class TABHook {
if (tabAPI.getTabListFormatManager() == null) return; if (tabAPI.getTabListFormatManager() == null) return;
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
Helper.color(" &a[M]&c[") + war.getSide1() + "]&r"); Helper.color(" &a[M]&c[") + war.getSide1() + "]&r");
} }
public static void assignSide2WarSuffixMerc(Player p, War war) { public static void assignSide2WarSuffixMerc(Player p, War war) {
@@ -60,7 +78,7 @@ public class TABHook {
if (tabAPI.getTabListFormatManager() == null) return; if (tabAPI.getTabListFormatManager() == null) return;
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
Helper.color(" &a[M]&9[") + war.getSide2() + "]&r"); Helper.color(" &a[M]&9[") + war.getSide2() + "]&r");
} }
public static void resetSuffix(Player p) { public static void resetSuffix(Player p) {
@@ -47,11 +47,11 @@ public class WarItemRegistry {
public Map<String, ItemStack> getItemRegistry() { public Map<String, ItemStack> getItemRegistry() {
return itemRegistry.entrySet() return itemRegistry.entrySet()
.stream() .stream()
.filter(v -> v.getValue() != null) .filter(v -> v.getValue() != null)
.collect(Collectors.toMap( .collect(Collectors.toMap(
Map.Entry::getKey, Map.Entry::getKey,
v -> v.getValue().getItemStack())); v -> v.getValue().getItemStack()));
} }
/** /**
@@ -14,33 +14,33 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class CommandsListener implements Listener { public class CommandsListener implements Listener {
final static String[] prefixes = new String[]{ final static String[] prefixes = new String[]{
"", "towny", "essentials", "wild", "minecraft" "", "towny", "essentials", "wild", "minecraft"
}; };
final static String[] prefixesTowny = new String[]{ final static String[] prefixesTowny = new String[]{
"", "towny" "", "towny"
}; };
final static String[] blacklistedXLong = new String[]{ final static String[] blacklistedXLong = new String[]{
"n set spawn", "nat set spawn", "nation set spawn", "n set spawn", "nat set spawn", "nation set spawn",
"t set spawn", "town set spawn", "t set spawn", "town set spawn",
"t set homeblock", "town set homeblock", "t set homeblock", "town set homeblock",
"t set name", "town set name", "t set name", "town set name",
"n set name", "nat set name", "nation set name" "n set name", "nat set name", "nation set name"
}; };
final static String[] blacklistedLong = new String[]{ final static String[] blacklistedLong = new String[]{
"n spawn", "nat spawn", "nation spawn", "n spawn", "nat spawn", "nation spawn",
"t spawn", "town spawn", "t spawn", "town spawn",
"t outpost", "town outpost" "t outpost", "town outpost"
}; };
final static String[] payment = new String[]{ final static String[] payment = new String[]{
"n withdraw", "nat withdraw", "nation withdraw", "n withdraw", "nat withdraw", "nation withdraw",
"t withdraw", "town withdraw" "t withdraw", "town withdraw"
}; };
final static String[] blacklistedShort = new String[]{ final static String[] blacklistedShort = new String[]{
"home", "homes", "warp", "warps", "home", "homes", "warp", "warps",
"wild", "rtp", "spawn", "wilderness", "wildtp", "wild", "rtp", "spawn", "wilderness", "wildtp",
"tpa", "tpahere", "tpaccept", "tpacancel", "tpa", "tpahere", "tpaccept", "tpacancel",
"etpa", "etpahere", "etpaccept", "etpacancel", "etpa", "etpahere", "etpaccept", "etpacancel",
"ehome", "ehomes", "ewarp", "ewarps" "ehome", "ehomes", "ewarp", "ewarps"
}; };
@@ -101,9 +101,9 @@ public class CommandsListener implements Listener {
//check if in spawn //check if in spawn
if (p.getWorld().getName().equalsIgnoreCase("world")) { if (p.getWorld().getName().equalsIgnoreCase("world")) {
if (parse.equalsIgnoreCase("n spawn") || parse.equalsIgnoreCase("nat spawn") || parse.equalsIgnoreCase("nation spawn") if (parse.equalsIgnoreCase("n spawn") || parse.equalsIgnoreCase("nat spawn") || parse.equalsIgnoreCase("nation spawn")
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn") || parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn") || parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) { || parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation.")); p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
return; return;
} }
@@ -191,9 +191,9 @@ public class CommandsListener implements Listener {
//check if in spawn //check if in spawn
if (p.getWorld().getName().equalsIgnoreCase("world")) { if (p.getWorld().getName().equalsIgnoreCase("world")) {
if (parse.equalsIgnoreCase("n spawn") || parse.equalsIgnoreCase("nat spawn") || parse.equalsIgnoreCase("nation spawn") if (parse.equalsIgnoreCase("n spawn") || parse.equalsIgnoreCase("nat spawn") || parse.equalsIgnoreCase("nation spawn")
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn") || parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn") || parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) { || parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation.")); p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
return; return;
} }
@@ -1,12 +1,11 @@
package me.ShermansWorld.AlathraWar.listeners; package me.ShermansWorld.AlathraWar.listeners;
import com.palmergames.bukkit.towny.TownyAPI; import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.War; import me.ShermansWorld.AlathraWar.War;
import me.ShermansWorld.AlathraWar.data.WarData; import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.hooks.TABHook; import me.ShermansWorld.AlathraWar.hooks.TABHook;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -14,10 +13,15 @@ import org.bukkit.event.player.PlayerJoinEvent;
public class JoinListener implements Listener { public class JoinListener implements Listener {
public static void checkPlayer(Player p) { public static void checkPlayer(Player p) {
Town town = TownyAPI.getInstance().getResident(p).getTownOrNull(); Resident resident = TownyAPI.getInstance().getResident(p);
if (resident == null) return;
Town town = resident.getTownOrNull();
if (town == null) return; if (town == null) return;
String townName = town.getName(); String townName = town.getName();
boolean inWar = false; boolean inWar = false;
for (final War war : WarData.getWars()) { for (final War war : WarData.getWars()) {
if (war.getSide1Towns().contains(townName.toLowerCase())) { if (war.getSide1Towns().contains(townName.toLowerCase())) {
TABHook.assignSide1WarSuffix(p, war); TABHook.assignSide1WarSuffix(p, war);
@@ -27,6 +31,7 @@ public class JoinListener implements Listener {
inWar = true; inWar = true;
} }
} }
if (!inWar) { if (!inWar) {
TABHook.resetPrefix(p); TABHook.resetPrefix(p);
} }
@@ -35,6 +40,5 @@ public class JoinListener implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(final PlayerJoinEvent event) { public void onPlayerJoin(final PlayerJoinEvent event) {
final Player p = event.getPlayer(); final Player p = event.getPlayer();
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> checkPlayer(p), 60L); // 20 Tick (1 Second) delay before run() is called
} }
} }
@@ -23,7 +23,7 @@ import java.util.UUID;
public final class KillsListener implements Listener { public final class KillsListener implements Listener {
public static final HashMap<UUID, Raid> respawnqueue = new HashMap<>(); public static final HashMap<UUID, Raid> respawnQueue = new HashMap<>();
@EventHandler @EventHandler
public void onPlayerKilled(final PlayerDeathEvent event) { public void onPlayerKilled(final PlayerDeathEvent event) {
@@ -71,20 +71,20 @@ public final class KillsListener implements Listener {
if (raid.getDefenderPlayers().contains(killer.getName())) { if (raid.getDefenderPlayers().contains(killer.getName())) {
this.raidKill(killed, event); this.raidKill(killed, event);
raid.raiderKilledInCombat(event); raid.raiderKilledInCombat(event);
respawnqueue.put(killed.getUniqueId(), raid); respawnQueue.put(killed.getUniqueId(), raid);
return; return;
} }
} else if (raid.getPhase() != RaidPhase.COMBAT && killer != null) { } else if (raid.getPhase() != RaidPhase.COMBAT && killer != null) {
this.oocKill(killed, event); this.oocKill(killed, event);
raid.raiderKilledOutofCombat(event); raid.raiderKilledOutofCombat(event);
respawnqueue.put(killed.getUniqueId(), raid); respawnQueue.put(killed.getUniqueId(), raid);
return; return;
} }
//teleport back to gather town spawn, without damaged gear //teleport back to gather town spawn, without damaged gear
//this is to disincentive people prekilling //this is to disincentive people prekilling
this.oocKill(killed, event); this.oocKill(killed, event);
raid.raiderKilledOutofCombat(event); raid.raiderKilledOutofCombat(event);
respawnqueue.put(killed.getUniqueId(), raid); respawnQueue.put(killed.getUniqueId(), raid);
return; return;
} }
if ((town != null && town.equals(raid.getRaidedTown()) || playerCloseToHomeBlockRaid)) { if ((town != null && town.equals(raid.getRaidedTown()) || playerCloseToHomeBlockRaid)) {
@@ -169,8 +169,8 @@ public final class KillsListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onRespawn(PlayerRespawnEvent event) { public void onRespawn(PlayerRespawnEvent event) {
if (respawnqueue.containsKey(event.getPlayer().getUniqueId())) { if (respawnQueue.containsKey(event.getPlayer().getUniqueId())) {
Raid raid = respawnqueue.get(event.getPlayer().getUniqueId()); Raid raid = respawnQueue.get(event.getPlayer().getUniqueId());
if (raid == null) return; if (raid == null) return;
if (raid.getActiveRaiders().contains(event.getPlayer().getName())) { if (raid.getActiveRaiders().contains(event.getPlayer().getName())) {
//do raider respawn //do raider respawn
@@ -185,7 +185,7 @@ public final class KillsListener implements Listener {
} else { } else {
//invalid code //invalid code
} }
respawnqueue.remove(event.getPlayer().getUniqueId()); respawnQueue.remove(event.getPlayer().getUniqueId());
} }
} }
@@ -0,0 +1,25 @@
package me.ShermansWorld.AlathraWar.listeners;
import com.palmergames.bukkit.towny.event.nation.NationKingChangeEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class NationListener implements Listener {
/*
* NationPreTownLeaveEvent, NationPreTownKickEvent, NationPreMergeEvent
*
* NationKingChangeEvent
* NationPreRenameEvent
*
*
*
* */
// TODO Prevent nation rename during war, siege, raid
@EventHandler
private void onNationKingChange(NationKingChangeEvent e) {
e.setCancelMessage("");
e.setCancelled(true);
}
}
@@ -153,10 +153,10 @@ public class PlayerInteractListener implements Listener {
if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) { if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) {
if (clicked != null) { if (clicked != null) {
if (clicked.getType().name().equals("GRASS_BLOCK") if (clicked.getType().name().equals("GRASS_BLOCK")
|| clicked.getType().name().equals("DIRT") || clicked.getType().name().equals("DIRT")
|| clicked.getType().name().equals("COARSE_DIRT") || clicked.getType().name().equals("COARSE_DIRT")
|| clicked.getType().name().equals("ROOTED_DIRT") || clicked.getType().name().equals("ROOTED_DIRT")
|| clicked.getType().name().equals("DIRT_PATH")) { || clicked.getType().name().equals("DIRT_PATH")) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@@ -0,0 +1,19 @@
package me.ShermansWorld.AlathraWar.listeners;
import org.bukkit.event.Listener;
public class TownListener implements Listener {
// TODO On town ruin, bow town out of any active wars, if leader of war surrender
// TODO On town ruin, leave or cancel sieges where the town is present
// TODO On town ruin, leave or cancel raids where the town is present
// TODO Prevent town rename during war, siege, raid
/*
TownMayorChangeEvent
TownLeaveEvent
TownPreMergeEvent
TownPreRuinedEvent
TownPreRenameEvent
TownRemoveResidentEvent
*/
}