This commit is contained in:
Isaac committed 2023-04-29 01:26:34 +01:00
commit 11a0d019fd
12 files changed
+675 -525

No files matched your search

@@ -18,7 +18,7 @@ public class Helper
return ChatColor.translateAlternateColorCodes('&', input); return ChatColor.translateAlternateColorCodes('&', input);
} }
public static String Chatlabel() { public static String chatLabel() {
return color("&6[&4AlathraWar&6]&r "); return color("&6[&4AlathraWar&6]&r ");
} }
@@ -285,11 +285,11 @@ public class Raid {
//Broadcast to the whole raid //Broadcast to the whole raid
for (String s : activeRaiders) { for (String s : activeRaiders) {
Player pl = Bukkit.getPlayer(s); Player pl = Bukkit.getPlayer(s);
if(pl != null) pl.sendMessage(Helper.Chatlabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value)); if(pl != null) pl.sendMessage(Helper.chatLabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
} }
for (String s : defenderPlayers) { for (String s : defenderPlayers) {
Player pl = Bukkit.getPlayer(s); Player pl = Bukkit.getPlayer(s);
if(pl != null) pl.sendMessage(Helper.Chatlabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value)); if(pl != null) pl.sendMessage(Helper.chatLabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
} }
this.save(); this.save();
@@ -299,11 +299,11 @@ public class Raid {
this.addLootedChunk(wc); this.addLootedChunk(wc);
for (String s : activeRaiders) { for (String s : activeRaiders) {
Player pl = Bukkit.getPlayer(s); Player pl = Bukkit.getPlayer(s);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raiders have started looting a town block!"); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raiders have started looting a town block!");
} }
for (String s : defenderPlayers) { for (String s : defenderPlayers) {
Player pl = Bukkit.getPlayer(s); Player pl = Bukkit.getPlayer(s);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raiders have started looting a town block!"); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raiders have started looting a town block!");
} }
} }
@@ -321,7 +321,7 @@ public class Raid {
*/ */
private void startTravel() { private void startTravel() {
Raid.this.phase = RaidPhase.TRAVEL; Raid.this.phase = RaidPhase.TRAVEL;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The Raiders of " Bukkit.broadcastMessage(String.valueOf(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() + "!");
@@ -334,7 +334,7 @@ public class Raid {
*/ */
private void startCombat() { private void startCombat() {
Raid.this.phase = RaidPhase.COMBAT; Raid.this.phase = RaidPhase.COMBAT;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The Raiders of " Bukkit.broadcastMessage(String.valueOf(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!");
@@ -351,11 +351,11 @@ public class Raid {
this.addPointsToDefenderScore(40); this.addPointsToDefenderScore(40);
for (final String playerName : this.getActiveRaiders()) { for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName); Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score"); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raider killed! -40 Raid Score");
} }
for (final String playerName : this.getDefenderPlayers()) { for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName); Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score"); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raider killed! -40 Raid Score");
} }
} }
@@ -366,11 +366,11 @@ public class Raid {
this.addPointsToRaiderScore(20); this.addPointsToRaiderScore(20);
for (final String playerName : this.getActiveRaiders()) { for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName); Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score"); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! +20 Raid Score");
} }
for (final String playerName : this.getDefenderPlayers()) { for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName); Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score"); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! +20 Raid Score");
} }
// //tp to raid town spawn // //tp to raid town spawn
@@ -389,11 +389,11 @@ public class Raid {
//award negative score //award negative score
for (final String playerName : this.getActiveRaiders()) { for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName); Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally."); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raider killed before combat, no points awarded and death treated normally.");
} }
for (final String playerName : this.getDefenderPlayers()) { for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName); Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally."); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Raider killed before combat, no points awarded and death treated normally.");
} }
// //
// //tp to gather town spawn // //tp to gather town spawn
@@ -410,7 +410,7 @@ public class Raid {
if (this.getDefenderSide().contains(killed.getKiller().getName())) { if (this.getDefenderSide().contains(killed.getKiller().getName())) {
try { try {
killed.getKiller().teleport(this.getRaidedTown().getSpawn()); killed.getKiller().teleport(this.getRaidedTown().getSpawn());
killed.getKiller().sendMessage(String.valueOf(Helper.Chatlabel()) + "You killed a raider before the raid began and have been teleported back to the defending town."); killed.getKiller().sendMessage(String.valueOf(Helper.chatLabel()) + "You killed a raider before the raid began and have been teleported back to the defending town.");
} catch (TownyException e) { } catch (TownyException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -424,11 +424,11 @@ public class Raid {
public void defenderKilledOutofCombat(PlayerDeathEvent event) { public void defenderKilledOutofCombat(PlayerDeathEvent event) {
for (final String playerName : this.getActiveRaiders()) { for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName); Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally."); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed before combat, no points awarded and death treated normally.");
} }
for (final String playerName : this.getDefenderPlayers()) { for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName); Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally."); if(pl != null) pl.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed before combat, no points awarded and death treated normally.");
} }
//tp to raid town spawn //tp to raid town spawn
@@ -443,7 +443,7 @@ public class Raid {
if (this.getActiveRaiders().contains(killed.getKiller().getName())) { if (this.getActiveRaiders().contains(killed.getKiller().getName())) {
try { try {
killed.getKiller().teleport(this.getGatherTown().getSpawn()); killed.getKiller().teleport(this.getGatherTown().getSpawn());
killed.getKiller().sendMessage(String.valueOf(Helper.Chatlabel()) + "You killed a defender before the raid began and have been teleported back to the gather town."); killed.getKiller().sendMessage(String.valueOf(Helper.chatLabel()) + "You killed a defender before the raid began and have been teleported back to the gather town.");
} catch (TownyException e) { } catch (TownyException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -466,7 +466,7 @@ public class Raid {
if (factor > 3.0) factor = 3.0; if (factor > 3.0) factor = 3.0;
if (factor < 0) factor = 0.0; if (factor < 0) factor = 0.0;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raiders from " + this.raiders Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raiders from " + this.raiders
+ " have successfully raided " + this.raidedTown.getName() + "!"); + " have successfully raided " + this.raidedTown.getName() + "!");
/* /*
@@ -554,25 +554,25 @@ public class Raid {
if (factor < 0) factor = 0.0; if (factor < 0) factor = 0.0;
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() + "!");
@@ -594,7 +594,7 @@ public class Raid {
public void noWinner() { public void noWinner() {
//TODO finalize payout //TODO finalize payout
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders Bukkit.broadcastMessage(String.valueOf(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() + "!");
@@ -837,7 +837,7 @@ public class Raid {
if (Raid.this.phase == RaidPhase.GATHER) { if (Raid.this.phase == RaidPhase.GATHER) {
//Broadcast //Broadcast
if (raidTicks % 6000 == 0) { if (raidTicks % 6000 == 0) {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of " Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raid of "
+ Raid.this.getRaidedTown().getName() + " will begin in " + (int) ((RaidPhase.TRAVEL.startTick - raidTicks) / 20 / 60) + " minutes!"); + Raid.this.getRaidedTown().getName() + " will begin in " + (int) ((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!");
@@ -853,12 +853,12 @@ public class Raid {
if (!cluster.contains(WorldCoord.parseWorldCoord(p))) { if (!cluster.contains(WorldCoord.parseWorldCoord(p))) {
if (p.equals(owner)) { if (p.equals(owner)) {
p.teleport(gatherTown.getSpawn()); p.teleport(gatherTown.getSpawn());
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot leave the gather town. As raid party leader, you have remained in the party. To stop the raid type /raid abandon"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot leave the gather town. As raid party leader, you have remained in the party. To stop the raid type /raid abandon");
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have been teleported to the gather town's spawn."); p.sendMessage(String.valueOf(Helper.chatLabel()) + "You have been teleported to the gather town's spawn.");
} else { } else {
Raid.this.removeActiveRaider(p.getName()); Raid.this.removeActiveRaider(p.getName());
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "By leaving the gathering town you have left the raid on " + Raid.this.getRaidedTown().getName() + "!"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "By leaving the gathering town you have left the raid on " + Raid.this.getRaidedTown().getName() + "!");
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "To rejoin, do /raid join [war] [town]"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "To rejoin, do /raid join [war] [town]");
} }
} }
} }
@@ -873,7 +873,7 @@ public class Raid {
//Report //Report
if (raidTicks % 2400 == 0) { if (raidTicks % 2400 == 0) {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The Raiders of " Bukkit.broadcastMessage(String.valueOf(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() + "!");
@@ -908,7 +908,7 @@ 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);
@@ -928,7 +928,7 @@ public class Raid {
//Idk if thisll work but if it do then ye //Idk if thisll work but if it do then ye
if (Raid.this.lootedChunks.containsKey(wc)) { if (Raid.this.lootedChunks.containsKey(wc)) {
if (Raid.this.lootedChunks.get(wc).finished) { if (Raid.this.lootedChunks.get(wc).finished) {
p.sendMessage(Helper.Chatlabel() + "This chunk is already looted, try another."); p.sendMessage(Helper.chatLabel() + "This chunk is already looted, try another.");
} else { } else {
doLootAt(p, wc); doLootAt(p, wc);
} }
@@ -936,7 +936,7 @@ public class Raid {
if (Raid.this.getRaidedTown().hasTownBlock(wc)) { if (Raid.this.getRaidedTown().hasTownBlock(wc)) {
doLootAt(p, wc); doLootAt(p, wc);
} else { } else {
p.sendMessage(Helper.Chatlabel() + "This space is not part of the raided town, you cannot loot this area."); p.sendMessage(Helper.chatLabel() + "This space is not part of the raided town, you cannot loot this area.");
} }
} }
} }
@@ -134,14 +134,14 @@ public class Siege {
if (this.homeBlockControl != 1) { if (this.homeBlockControl != 1) {
for (final String playerName : Siege.this.attackerPlayers) { for (final String playerName : Siege.this.attackerPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) Bukkit.getPlayer(playerName).sendMessage(String.valueOf(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(String.valueOf(Helper.Chatlabel()) Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
+ "HomeBlock at " + Siege.this.town.getName() + " contested!"); + "HomeBlock at " + Siege.this.town.getName() + " contested!");
} catch (NullPointerException ex6) { } catch (NullPointerException ex6) {
} }
@@ -152,7 +152,7 @@ public class Siege {
if (this.homeBlockControl != 2) { if (this.homeBlockControl != 2) {
for (final String playerName : Siege.this.attackerPlayers) { for (final String playerName : Siege.this.attackerPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) Bukkit.getPlayer(playerName).sendMessage(String.valueOf(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) {
@@ -160,7 +160,7 @@ public class Siege {
} }
for (final String playerName : Siege.this.defenderPlayers) { for (final String playerName : Siege.this.defenderPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) Bukkit.getPlayer(playerName).sendMessage(String.valueOf(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) {
@@ -173,7 +173,7 @@ public class Siege {
if (this.homeBlockControl != 3) { if (this.homeBlockControl != 3) {
for (final String playerName : Siege.this.attackerPlayers) { for (final String playerName : Siege.this.attackerPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) Bukkit.getPlayer(playerName).sendMessage(String.valueOf(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) {
@@ -181,7 +181,7 @@ public class Siege {
} }
for (final String playerName : Siege.this.defenderPlayers) { for (final String playerName : Siege.this.defenderPlayers) {
try { try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) Bukkit.getPlayer(playerName).sendMessage(String.valueOf(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) {
@@ -192,7 +192,7 @@ public class Siege {
this.homeBlockControl = 3; this.homeBlockControl = 3;
} }
if (Siege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes if (Siege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the siege of " Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "Report on the siege of "
+ Siege.this.town.getName() + ":"); + Siege.this.town.getName() + ":");
Bukkit.broadcastMessage( Bukkit.broadcastMessage(
"Attacker Points - " + String.valueOf(Siege.this.attackerPoints)); "Attacker Points - " + String.valueOf(Siege.this.attackerPoints));
@@ -232,12 +232,12 @@ public class Siege {
public void attackersWin(final OfflinePlayer siegeLeader) { public void attackersWin(final OfflinePlayer siegeLeader) {
final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId()); final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
Nation nation = null; Nation nation = null;
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The attackers have won the siege of " + this.town.getName() + "!"); Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The attackers have won the siege of " + this.town.getName() + "!");
try { try {
nation = resident.getTown().getNation(); nation = resident.getTown().getNation();
} catch (Exception e) {} } catch (Exception e) {}
if (nation != null) { if (nation != null) {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() Bukkit.broadcastMessage(String.valueOf(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);
@@ -248,7 +248,7 @@ public class Siege {
} else { } else {
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(String.valueOf(Helper.Chatlabel()) + "The town of " + this.town.getName() Bukkit.broadcastMessage(String.valueOf(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);
@@ -275,8 +275,8 @@ public class Siege {
public void defendersWin() { public void defendersWin() {
this.town.getAccount().deposit(2500.0, "War chest"); this.town.getAccount().deposit(2500.0, "War chest");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders have won the siege of " + this.town.getName() + "!"); Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The defenders have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.town.getName() Bukkit.broadcastMessage(String.valueOf(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() + "!");
@@ -295,8 +295,8 @@ public class Siege {
* No winnder declared * No winnder declared
*/ */
public void noWinner() { public void noWinner() {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The siege of " + this.town.getName() + " was a draw!"); Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The siege of " + this.town.getName() + " was a draw!");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "No money has been recovered."); Bukkit.broadcastMessage(String.valueOf(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();
File diff suppressed because it is too large. Load diff
@@ -15,7 +15,12 @@ public class AdminTabCompletion implements TabCompleter {
"force", "force",
"help", "help",
"info", "info",
"modify" "modify",
"purgebars",
"load",
"load-all",
"save",
"save-all"
}); });
List<String> type = List.of(new String[]{ List<String> type = List.of(new String[]{
@@ -186,7 +191,26 @@ public class AdminTabCompletion implements TabCompleter {
} else if (args.length == 1) { } else if (args.length == 1) {
return NameUtil.filterByStart(base, args[0]); return NameUtil.filterByStart(base, args[0]);
} else { } else {
if (args[0].equalsIgnoreCase("create")) {
if (args[0].equalsIgnoreCase("purgebars")) {
return empty;
} else if (args[0].equalsIgnoreCase("save")) {
if(args.length > 2) {
return empty;
} else {
return CommandHelper.getWarNames();
}
} else if (args[0].equalsIgnoreCase("save-all")) {
return empty;
} else if (args[0].equalsIgnoreCase("load")) {
if(args.length > 2) {
return empty;
} else {
return CommandHelper.getWarNames();
}
} else if (args[0].equalsIgnoreCase("load-all")) {
return empty;
} else if (args[0].equalsIgnoreCase("create")) {
if (args.length > 2) { if (args.length > 2) {
switch (args[1]) { switch (args[1]) {
case "raid" -> { case "raid" -> {
@@ -26,33 +26,33 @@ public class RaidCommands implements CommandExecutor {
} }
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
final Player p = (Player) sender; // final Player p = (Player) sender;
if (args.length == 0) { if (args.length == 0) {
fail(p, args, "syntax"); fail(sender, args, "syntax");
} else if (args.length == 1) { } else if (args.length == 1) {
if (args[0].equalsIgnoreCase("list")) { if (args[0].equalsIgnoreCase("list")) {
listRaids(p, args); listRaids(sender, args);
} else if (args[0].equalsIgnoreCase("help")) { } else if (args[0].equalsIgnoreCase("help")) {
raidHelp(p, args); raidHelp(sender, args);
} else { } else {
fail(p, args, "syntax"); fail(sender, args, "syntax");
} }
}else if (args.length == 3) { }else if (args.length == 3) {
if (args[0].equalsIgnoreCase("start")) { if (args[0].equalsIgnoreCase("start")) {
startRaid(p, args, false); startRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("stop")) { } else if (args[0].equalsIgnoreCase("stop")) {
stopRaid(p, args); stopRaid(sender, args);
} else if (args[0].equalsIgnoreCase("join")) { } else if (args[0].equalsIgnoreCase("join")) {
joinRaid(p, args, false); joinRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("leave")) { } else if (args[0].equalsIgnoreCase("leave")) {
leaveRaid(p, args, false); leaveRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("abandon")) { } else if (args[0].equalsIgnoreCase("abandon")) {
abandonRaid(p, args); abandonRaid(sender, args);
} else { } else {
fail(p, args, "syntax"); fail(sender, args, "syntax");
} }
} else { } else {
fail(p, args, "syntax"); fail(sender, args, "syntax");
} }
return true; return true;
} }
@@ -63,7 +63,7 @@ public class RaidCommands implements CommandExecutor {
* @param p * @param p
* @param args * @param args
*/ */
protected static void startRaid(Player p, String[] args, boolean admin) { protected static void startRaid(CommandSender p, String[] args, boolean admin) {
boolean warFound = false; boolean warFound = false;
boolean townExists = false; boolean townExists = false;
for (final War war : WarData.getWars()) { for (final War war : WarData.getWars()) {
@@ -71,29 +71,34 @@ public class RaidCommands implements CommandExecutor {
if (war.getName().equalsIgnoreCase(args[1 + (admin ? 1 : 0)])) { if (war.getName().equalsIgnoreCase(args[1 + (admin ? 1 : 0)])) {
warFound = true; warFound = true;
Player raidOwner = p; Player raidOwner = null;
TownyWorld townyWorld; if((p instanceof Player)) {
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld(); raidOwner = (Player) p;
}
if(admin && args.length >= 6) { if(admin && args.length >= 6) {
raidOwner = Bukkit.getPlayer(args[5]); raidOwner = Bukkit.getPlayer(args[5]);
if(raidOwner == null) { if(raidOwner == null) {
raidOwner = p; p.sendMessage("Player Does not exist");
return;
} }
} }
TownyWorld townyWorld;
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
String side = ""; String side = "";
if (war.getSide1Players().contains(p.getName())) { if (war.getSide1Players().contains(raidOwner.getName())) {
side = war.getSide1(); side = war.getSide1();
} else if (war.getSide2Players().contains(p.getName())) { } else if (war.getSide2Players().contains(raidOwner.getName())) {
side = war.getSide2(); side = war.getSide2();
} else { } else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
return; return;
} }
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime //Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
if (admin) { if (admin) {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(args[3]) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(raidOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
if(args.length >= 5) { if(args.length >= 5) {
//player has joined to recently //player has joined to recently
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!"); p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
@@ -105,7 +110,7 @@ public class RaidCommands implements CommandExecutor {
} }
} }
} else { } else {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(p.getName()) < 86400000 * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(raidOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
//player has joined to recently //player has joined to recently
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return; return;
@@ -124,21 +129,21 @@ public class RaidCommands implements CommandExecutor {
} else if(TownyAPI.getInstance().getTown(args[4]) != null) { } else if(TownyAPI.getInstance().getTown(args[4]) != null) {
gatherTown = TownyAPI.getInstance().getTown(args[4]); gatherTown = TownyAPI.getInstance().getTown(args[4]);
} else { } else {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No valid town set for gather town, defaulting to current location"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "No valid town set for gather town, defaulting to current location");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "No valid town set for gather town, defaulting to current location"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "No valid town set for gather town, defaulting to current location");
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock()); gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
} }
} else { } else {
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock()); gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
} }
} catch (NotRegisteredException e2) { } catch (NotRegisteredException e2) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town."); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town."); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
return; return;
} }
if (gatherTown == null) { if (gatherTown == null) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town."); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town."); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
return; return;
} }
@@ -152,54 +157,54 @@ public class RaidCommands implements CommandExecutor {
//check if the town were attempting to raid is in the war //check if the town were attempting to raid is in the war
if(!war.getSide1Towns().contains(raidedTown.getName()) && !war.getSide2Towns().contains(raidedTown.getName())) { if(!war.getSide1Towns().contains(raidedTown.getName()) && !war.getSide2Towns().contains(raidedTown.getName())) {
if (war.getSurrenderedTowns().contains(raidedTown.getName())) { if (war.getSurrenderedTowns().contains(raidedTown.getName())) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "The town you are trying to raid has already surrendered!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid has already surrendered!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "The town you are trying to raid has already surrendered!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid has already surrendered!");
return; return;
} }
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "The town you are trying to raid is not part of the war!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid is not part of the war!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "The town you are trying to raid is not part of the war!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "The town you are trying to raid is not part of the war!");
return; return;
} }
// Is being sieged check // Is being sieged check
for (Siege s : SiegeData.getSieges()) { for (Siege s : SiegeData.getSieges()) {
if(s.getTown().getName().equals(raidedTown.getName())) { if(s.getTown().getName().equals(raidedTown.getName())) {
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town is already currently being sieged! Cannot raid at this time!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being sieged! Cannot raid at this time!");
if(admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town is already currently being sieged! Cannot raid at this time!"); if(admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being sieged! Cannot raid at this time!");
} }
} }
townExists = true; townExists = true;
Raid raid2; Raid raid2;
if (war.getSide1Players().contains(p.getName())) { if (war.getSide1Players().contains(raidOwner.getName())) {
//Time and raid activity validity check //Time and raid activity validity check
int c = RaidData.isValidRaid(war, side, raidedTown); int c = RaidData.isValidRaid(war, side, raidedTown);
if (c == 2) { if (c == 2) {
//if were admin, see if an owner arg exists, and if so then use it //if were admin, see if an owner arg exists, and if so then use it
raid2 = new Raid(war, raidedTown, gatherTown, true, raidOwner); raid2 = new Raid(war, raidedTown, gatherTown, true, raidOwner);
} else if (c == 1) { } else if (c == 1) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
return; return;
} else if (c == 0) { } else if (c == 0) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
return; return;
} else if (c == -1) { } else if (c == -1) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
return; return;
} else if (c == -2) { } else if (c == -2) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
return; return;
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
} else { } else {
//Something broke if this runs //Something broke if this runs
if (!war.getSide2Players().contains(p.getName())) { if (!war.getSide2Players().contains(raidOwner.getName())) {
Bukkit.getLogger().info("Unable to find player declaring raid in the war"); Bukkit.getLogger().info("Unable to find player declaring raid in the war");
return; return;
} }
@@ -208,20 +213,20 @@ public class RaidCommands implements CommandExecutor {
if (c == 2) { if (c == 2) {
raid2 = new Raid(war, raidedTown, gatherTown, false, raidOwner); raid2 = new Raid(war, raidedTown, gatherTown, false, raidOwner);
} else if (c == 1) { } else if (c == 1) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town is already being raided at this time!");
return; return;
} else if (c == 0) { } else if (c == 0) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "Your side has raided too recently!");
return; return;
} else if (c == -1) { } else if (c == -1) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "This town was raided too recently!");
return; return;
} else if (c == -2) { } else if (c == -2) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!"); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!"); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "At least on member of the raided town must be online to defend it!");
return; return;
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@@ -232,27 +237,27 @@ public class RaidCommands implements CommandExecutor {
Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull(); Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull();
int sideR = war.getSide(leaderTown.getName()); int sideR = war.getSide(leaderTown.getName());
if (sideR == 0) { if (sideR == 0) {
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 == -1) {
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.getSide(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;
} }
//check player balance //check player balance
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUniqueId()); final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(raidOwner.getUniqueId());
if (Main.econ.getBalance(offlinePlayer) <= 1000.0) { if (Main.econ.getBalance(offlinePlayer) <= 1000.0) {
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $1000 to put up to start a raid."); if (admin) p.sendMessage(String.valueOf(Helper.chatLabel()) + "You must have at least $1000 to put up to start a raid.");
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $1000 to put up to start a raid."); raidOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must have at least $1000 to put up to start a raid.");
return; return;
} }
@@ -264,11 +269,11 @@ public class RaidCommands implements CommandExecutor {
WarData.saveWar(raid2.getWar()); WarData.saveWar(raid2.getWar());
//broadcast //broadcast
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!"); Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "All players from the defending side have been drafted for the town's defense."); Bukkit.broadcastMessage(String.valueOf(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 " + (int) (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!"); + raidedTown.getName() + " will begin in " + (int) (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.");
@@ -280,11 +285,11 @@ public class RaidCommands implements CommandExecutor {
} }
} }
if (!warFound) { if (!warFound) {
p.sendMessage(Helper.Chatlabel() + "That war does not exist! /raid start [war] [town]"); p.sendMessage(Helper.chatLabel() + "That war does not exist! /raid start [war] [town]");
return; return;
} }
if (!townExists) { if (!townExists) {
p.sendMessage(Helper.Chatlabel() + "That town does not exist! /raid start [war] [town]"); p.sendMessage(Helper.chatLabel() + "That town does not exist! /raid start [war] [town]");
} }
} }
@@ -294,7 +299,7 @@ public class RaidCommands implements CommandExecutor {
* @param p * @param p
* @param args * @param args
*/ */
private static void stopRaid(Player p, String[] args) { private static void stopRaid(CommandSender p, String[] args) {
//admin check //admin check
if (!p.hasPermission("AlathraWar.admin")) { if (!p.hasPermission("AlathraWar.admin")) {
fail(p, args, "permission"); fail(p, args, "permission");
@@ -311,20 +316,24 @@ public class RaidCommands implements CommandExecutor {
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]); Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
if (raid != null) { if (raid != null) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "raid cancelled"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "raid cancelled");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of " + raid.getRaidedTown().getName() + " has been cancelled by an admin"); Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raid of " + raid.getRaidedTown().getName() + " has been cancelled by an admin");
raid.stop(); //this purges itself from raids raid.stop(); //this purges itself from raids
} else { } else {
fail(p, args, "badName"); fail(p, args, "badName");
} }
} }
protected static void joinRaid(Player p, String[] args, boolean admin) { protected static void joinRaid(CommandSender p, String[] args, boolean admin) {
//Grab raid! //Grab raid!
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]); Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
if (raid != null) { if (raid != null) {
if (raid.getWar().getName().equalsIgnoreCase(args[1])) { if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
Player joiner = p; Player joiner = null;
if(p instanceof Player) {
joiner = (Player) p;
}
if (admin) { if (admin) {
joiner = Bukkit.getPlayer(args[3]); joiner = Bukkit.getPlayer(args[3]);
@@ -333,26 +342,31 @@ public class RaidCommands implements CommandExecutor {
if (args[4].equals(raid.getDefenderSide())) { if (args[4].equals(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(String.valueOf(Helper.Chatlabel()) + "Player " + joiner.getName() + " added to defender side."); p.sendMessage(String.valueOf(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(String.valueOf(Helper.Chatlabel()) + "You were forcefully added to the defender side against the raid party on " + raid.getRaidedTown() + " by an admin."); joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You were forcefully added to the defender side against the raid party on " + raid.getRaidedTown() + " by an admin.");
return; return;
} else { } else {
if (!raid.getRaiderPlayers().contains(joiner.getName())) if (!raid.getRaiderPlayers().contains(joiner.getName()))
raid.getRaiderPlayers().add(joiner.getName()); raid.getRaiderPlayers().add(joiner.getName());
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Player " + joiner.getName() + " added to raider side."); p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player " + joiner.getName() + " added to raider side.");
Main.warLogger.log("Player " + joiner.getName() + " added to raider side."); Main.warLogger.log("Player " + joiner.getName() + " added to raider side.");
joiner.sendMessage(String.valueOf(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."); joiner.sendMessage(String.valueOf(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 { } else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Player " + args[3] + " not found!"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player " + args[3] + " not found!");
return; return;
} }
} }
if(joiner == null) {
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player not found! Is something broken?");
return;
}
if (!raid.getWar().getSide1Players().contains(joiner.getName()) && !raid.getWar().getSide2Players().contains(joiner.getName())) { if (!raid.getWar().getSide1Players().contains(joiner.getName()) && !raid.getWar().getSide2Players().contains(joiner.getName())) {
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]"); joiner.sendMessage(String.valueOf(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 //Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
@@ -376,7 +390,7 @@ public class RaidCommands implements CommandExecutor {
} }
} }
} else { } else {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(p.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(joiner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
//player has joined to recently //player has joined to recently
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return; return;
@@ -391,16 +405,16 @@ public class RaidCommands implements CommandExecutor {
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord()); ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) { if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
raid.addActiveRaider(joiner.getName()); raid.addActiveRaider(joiner.getName());
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!"); joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party."); joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
} else { } else {
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + "."); joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
} }
} catch (TownyException e) { } catch (TownyException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} else { } else {
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!"); joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
} }
} else { } else {
try { try {
@@ -408,10 +422,10 @@ public class RaidCommands implements CommandExecutor {
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord()); ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) { if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
raid.addActiveRaider(joiner.getName()); raid.addActiveRaider(joiner.getName());
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!"); joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party."); joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
} else { } else {
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + "."); joiner.sendMessage(String.valueOf(Helper.chatLabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
} }
} catch (TownyException e) { } catch (TownyException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@@ -421,27 +435,30 @@ public class RaidCommands implements CommandExecutor {
raid.save(); raid.save();
} }
} else { } else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town or this town does not exist!"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "No raid is gathering in this town or this town does not exist!");
} }
} }
protected static void leaveRaid(Player player, String[] args, boolean admin) { protected static void leaveRaid(CommandSender player, String[] args, boolean admin) {
//Get raid! //Get raid!
Player p = player; Player p = null;
if (admin) { if (admin) {
p = Bukkit.getPlayer(args[3]); p = Bukkit.getPlayer(args[3]);
if (p == null) { if (p == null) {
player.sendMessage(String.valueOf(Helper.Chatlabel()) + "Error: player not found!"); player.sendMessage(String.valueOf(Helper.chatLabel()) + "Error: player not found!");
return; return;
} }
} }
if(p == null) {
p = (Player) player;
}
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]); Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
if (raid != null) { if (raid != null) {
if (raid.getWar().getName().equalsIgnoreCase(args[1])) { if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) { if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
if (admin) player.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]"); if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
} }
//check if gather phase //check if gather phase
@@ -451,12 +468,12 @@ public class RaidCommands implements CommandExecutor {
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord()); ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(p))) { if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
raid.removeActiveRaider(p.getName()); raid.removeActiveRaider(p.getName());
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
if (admin) player.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!"); if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
} else { } else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
if (admin) player.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!"); if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
} }
} catch (TownyException e) { } catch (TownyException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@@ -466,8 +483,8 @@ public class RaidCommands implements CommandExecutor {
raid.save(); raid.save();
} else { } else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town or this town does not exist!"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "No raid is gathering in this town or this town does not exist!");
if (admin) player.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town or this town does not exist!"); if (admin) player.sendMessage(String.valueOf(Helper.chatLabel()) + "No raid is gathering in this town or this town does not exist!");
} }
} }
@@ -477,13 +494,13 @@ public class RaidCommands implements CommandExecutor {
* @param p * @param p
* @param args * @param args
*/ */
private static void abandonRaid(Player p, String[] args) { private static void abandonRaid(CommandSender p, String[] args) {
//Get raid //Get raid
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]); Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
if (raid != null) { if (raid != null) {
if (raid.getWar().getName().equalsIgnoreCase(args[1])) { if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) { if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "You are not in this war! Type /war join [war] [side]");
return; return;
} }
@@ -491,11 +508,11 @@ public class RaidCommands implements CommandExecutor {
//check if gather phase //check if gather phase
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.COMBAT) { if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.COMBAT) {
//force defender victory //force defender victory
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid on " + raid.getRaidedTown().getName() + " has been abandoned by " + raid.getRaiderSide()); Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The raid on " + raid.getRaidedTown().getName() + " has been abandoned by " + raid.getRaiderSide());
Main.warLogger.log(p.getName() + " abandoned the raid on " + raid.getRaidedTown().getName() + " they started at " + raid.getGatherTown().getName()); Main.warLogger.log(p.getName() + " abandoned the raid on " + raid.getRaidedTown().getName() + " they started at " + raid.getGatherTown().getName());
raid.defendersWin(raid.getRaiderScore(), raid.getDefenderScore()); raid.defendersWin(raid.getRaiderScore(), raid.getDefenderScore());
} else { } else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot abandon the raid on " + raid.getRaidedTown().getName() + "! It has a problem!"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "You cannot abandon the raid on " + raid.getRaidedTown().getName() + "! It has a problem!");
} }
} else { } else {
fail(p, args, "owner"); fail(p, args, "owner");
@@ -503,15 +520,15 @@ public class RaidCommands implements CommandExecutor {
} }
} }
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This raid does not exist!"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "This raid does not exist!");
} }
private static void listRaids(Player p, String[] args) { private static void listRaids(CommandSender p, String[] args) {
if (RaidData.getRaids().isEmpty()) { if (RaidData.getRaids().isEmpty()) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no Raids in progress"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no Raids in progress");
return; return;
} }
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raids currently in progress:"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "Raids currently in progress:");
for (final Raid raid : RaidData.getRaids()) { for (final Raid raid : RaidData.getRaids()) {
p.sendMessage("Name: " + raid.getName()); p.sendMessage("Name: " + raid.getName());
p.sendMessage("War: " + raid.getWar().getName()); p.sendMessage("War: " + raid.getWar().getName());
@@ -528,25 +545,25 @@ public class RaidCommands implements CommandExecutor {
} }
} }
private static void raidHelp(Player p, String[] args) { private static void raidHelp(CommandSender p, String[] args) {
if (p.hasPermission("!AlathraWar.admin")) { if (p.hasPermission("!AlathraWar.admin")) {
p.sendMessage(Helper.Chatlabel() + "/raid stop [name]"); p.sendMessage(Helper.chatLabel() + "/raid stop [name]");
} }
p.sendMessage(Helper.Chatlabel() + "/raid start [war] [town]"); p.sendMessage(Helper.chatLabel() + "/raid start [war] [town]");
p.sendMessage(Helper.Chatlabel() + "/raid join [war] [town]"); p.sendMessage(Helper.chatLabel() + "/raid join [war] [town]");
p.sendMessage(Helper.Chatlabel() + "/raid leave [war] [town]"); p.sendMessage(Helper.chatLabel() + "/raid leave [war] [town]");
p.sendMessage(Helper.Chatlabel() + "/raid abandon [war] [town]"); p.sendMessage(Helper.chatLabel() + "/raid abandon [war] [town]");
p.sendMessage(Helper.Chatlabel() + "/raid list"); p.sendMessage(Helper.chatLabel() + "/raid list");
} }
private static void fail(Player p, String[] args, String type) { private static void fail(CommandSender p, String[] args, String type) {
switch (type) { switch (type) {
case "permissions" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "&cYou do not have permission to do this"); case "permissions" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "&cYou do not have permission to do this");
case "syntax" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Syntax. /raid help"); case "syntax" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Syntax. /raid help");
case "noRaids" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no Raids in progress"); case "noRaids" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no Raids in progress");
case "badName" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "A raid could not be found with this Name! Type /raid list to view current raids"); case "badName" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "A raid could not be found with this Name! Type /raid list to view current raids");
case "owner" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Only the player who started the raid can abandon it."); case "owner" -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "Only the player who started the raid can abandon it.");
default -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help"); default -> p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /raid help");
} }
} }
} }
@@ -24,7 +24,7 @@ public class SiegeCommands implements CommandExecutor {
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (args.length == 0) { if (args.length == 0) {
sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /siege help"); sender.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /siege help");
return true; return true;
} }
@@ -60,44 +60,50 @@ public class SiegeCommands implements CommandExecutor {
} }
protected static void siegeStart(CommandSender sender, String[] args, boolean admin) { protected static void siegeStart(CommandSender sender, String[] args, boolean admin) {
if (!(sender instanceof Player)) return; // if (!(sender instanceof Player)) return;
//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
Player player = !admin ? (Player) sender : args.length >= 4 ? Bukkit.getPlayer(args[3]) : null; Player siegeOwner = null;
if(player == null) { if((sender instanceof Player)) {
sender.sendMessage("Forced owner not found!"); siegeOwner = (Player) sender;
return; }
if(admin && args.length >= 5) {
siegeOwner = Bukkit.getPlayer(args[3]);
if(siegeOwner == null) {
sender.sendMessage("Player Does not exist");
return;
}
} }
if (args.length < 3) { if (args.length < 3) {
sender.sendMessage(Helper.Chatlabel() + "/war siege [war] [town]"); sender.sendMessage(Helper.chatLabel() + "/war siege [war] [town]");
return; return;
} }
// War check // War check
War war = WarData.getWar(args[1]); War war = WarData.getWar(args[1]);
if (war == null) { if (war == null) {
player.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /siege start [war] [town]"); siegeOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege start [war] [town]");
if(admin) sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /siege start [war] [town]"); if(admin) sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege start [war] [town]");
return; return;
} }
// Player participance check // Player participance check
Town leaderTown = TownyAPI.getInstance().getResident(player).getTownOrNull(); Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
int side = war.getSide(leaderTown.getName()); int side = war.getSide(leaderTown.getName());
if (side == 0) { if (side == 0) {
player.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 == -1) {
player.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;
} }
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime //Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
if (admin) { if (admin) {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(args[3]) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(siegeOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
if(args.length >= 5) { if(args.length >= 5) {
if (Boolean.parseBoolean(args[4])) { if (Boolean.parseBoolean(args[4])) {
//player has joined to recently //player has joined to recently
@@ -105,20 +111,20 @@ public class SiegeCommands implements CommandExecutor {
} else { } else {
//player has joined to recently //player has joined to recently
sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
player.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); siegeOwner.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return; return;
} }
} else { } else {
//player has joined to recently //player has joined to recently
sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
player.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); siegeOwner.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return; return;
} }
} }
} else { } else {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(player.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) { if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(siegeOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
//player has joined to recently //player has joined to recently
player.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining."); siegeOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return; return;
} }
} }
@@ -126,31 +132,32 @@ public class SiegeCommands implements CommandExecutor {
// Town check // Town check
Town town = TownyAPI.getInstance().getTown(args[2]); Town town = TownyAPI.getInstance().getTown(args[2]);
if (town == null) { if (town == null) {
player.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /siege start [war] [town]"); siegeOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That town does not exist! /siege start [war] [town]");
if(admin) sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /siege start [war] [town]"); if(admin) sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That town does not exist! /siege start [war] [town]");
return; return;
} }
// Is being raided check // Is being raided check
for ( Raid r : RaidData.getRaids()) { for ( Raid r : RaidData.getRaids()) {
if(r.getRaidedTown().getName().equals(town.getName())) { if(r.getRaidedTown().getName().equals(town.getName())) {
player.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town is already currently being raided! Cannot siege at this time!"); siegeOwner.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being raided! Cannot siege at this time!");
if(admin) sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town is already currently being raided! Cannot siege at this time!"); if(admin) sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That town is already currently being raided! Cannot siege at this time!");
return;
} }
} }
// Attacking own side // Attacking own side
if (war.getSide(town) == side) { if (war.getSide(town) == side) {
player.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;
} }
Siege siege = new Siege(war, town, player); Siege siege = new Siege(war, town, siegeOwner);
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() + "A siege has been laid on " + siege.getTown() + " by " + siege.getAttackerSide() + "!");
war.save(); war.save();
siege.start(); siege.start();
@@ -158,37 +165,37 @@ public class SiegeCommands implements CommandExecutor {
private static void siegeStop(CommandSender sender, String[] args) { private static void siegeStop(CommandSender sender, String[] args) {
if (!sender.hasPermission("AlathraWar.admin")) { if (!sender.hasPermission("AlathraWar.admin")) {
sender.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this")); sender.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou do not have permission to do this"));
return; return;
} }
HashSet<Siege> sieges = SiegeData.getSieges(); HashSet<Siege> sieges = SiegeData.getSieges();
if (sieges.isEmpty()) { if (sieges.isEmpty()) {
sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no sieges in progress"); sender.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no sieges in progress");
return; return;
} }
if (args.length < 3) { if (args.length < 3) {
sender.sendMessage(Helper.Chatlabel() + "/siege stop [town]"); sender.sendMessage(Helper.chatLabel() + "/siege stop [town]");
return; return;
} }
// War check // War check
War war = WarData.getWar(args[1]); War war = WarData.getWar(args[1]);
if (war == null) { if (war == null) {
sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /siege stop [war] [town]"); sender.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege stop [war] [town]");
return; return;
} }
for (Siege siege : sieges) { for (Siege siege : sieges) {
if (siege.getTown().getName().equalsIgnoreCase(args[2])) { if (siege.getTown().getName().equalsIgnoreCase(args[2])) {
sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "siege cancelled"); sender.sendMessage(String.valueOf(Helper.chatLabel()) + "siege cancelled");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin"); Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin");
//siege.clearBeacon(); //siege.clearBeacon();
siege.stop(); siege.stop();
return; return;
} }
} }
sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "A siege could not be found with this town name! Type /siege list to view current sieges"); sender.sendMessage(String.valueOf(Helper.chatLabel()) + "A siege could not be found with this town name! Type /siege list to view current sieges");
} }
private static void siegeAbandon(CommandSender sender, String[] args) { private static void siegeAbandon(CommandSender sender, String[] args) {
@@ -196,30 +203,30 @@ public class SiegeCommands implements CommandExecutor {
final Player p = (Player) sender; final Player p = (Player) sender;
if (args.length < 3) { if (args.length < 3) {
sender.sendMessage(Helper.Chatlabel() + "/siege abandon [town]"); sender.sendMessage(Helper.chatLabel() + "/siege abandon [town]");
return; return;
} }
// War check // War check
War war = WarData.getWar(args[1]); War war = WarData.getWar(args[1]);
if (war == null) { if (war == null) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /siege abandon [war] [town]"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "That war does not exist! /siege abandon [war] [town]");
return; return;
} }
Siege siege = SiegeData.getSiege(args[2]); Siege siege = SiegeData.getSiege(args[2]);
if (siege == null) { if (siege == null) {
p.sendMessage(Helper.Chatlabel() + "Invalid siege"); p.sendMessage(Helper.chatLabel() + "Invalid siege");
return; return;
} }
OfflinePlayer oPlayer = siege.getSiegeLeader(); OfflinePlayer oPlayer = siege.getSiegeLeader();
if (oPlayer != (OfflinePlayer) p) { if (oPlayer != (OfflinePlayer) p) {
p.sendMessage(Helper.Chatlabel() + "You are not the leader of this siege."); p.sendMessage(Helper.chatLabel() + "You are not the leader of this siege.");
return; return;
} }
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The siege at " + siege.getTown().getName() + " has been abandoned."); Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "The siege at " + siege.getTown().getName() + " has been abandoned.");
Main.warLogger.log(p.getName() + " abandoned the siege they started at " + siege.getTown().getName()); Main.warLogger.log(p.getName() + " abandoned the siege they started at " + siege.getTown().getName());
siege.defendersWin(); siege.defendersWin();
@@ -228,11 +235,11 @@ public class SiegeCommands implements CommandExecutor {
private static void siegeList(CommandSender sender, String[] args) { private static void siegeList(CommandSender sender, String[] args) {
HashSet<Siege> sieges = SiegeData.getSieges(); HashSet<Siege> sieges = SiegeData.getSieges();
if (sieges.isEmpty()) { if (sieges.isEmpty()) {
sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no sieges in progress"); sender.sendMessage(String.valueOf(Helper.chatLabel()) + "There are currently no sieges in progress");
return; return;
} }
sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "Sieges currently in progress:"); sender.sendMessage(String.valueOf(Helper.chatLabel()) + "Sieges currently in progress:");
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()) == 1) ) ? "§c" : "§9"; String color = (siege.getSide1AreAttackers() && (war.getSide(siege.getTown().getName()) == 1) ) ? "§c" : "§9";
@@ -247,10 +254,10 @@ public class SiegeCommands implements CommandExecutor {
private static void siegeHelp(CommandSender sender, String[] args) { private static void siegeHelp(CommandSender sender, String[] args) {
if (sender.hasPermission("AlathraWar.admin")) { if (sender.hasPermission("AlathraWar.admin")) {
sender.sendMessage(Helper.Chatlabel() + "/siege stop [town]"); sender.sendMessage(Helper.chatLabel() + "/siege stop [town]");
} }
sender.sendMessage(Helper.Chatlabel() + "/siege start [war] [town]"); sender.sendMessage(Helper.chatLabel() + "/siege start [war] [town]");
sender.sendMessage(Helper.Chatlabel() + "/siege abandon [town]"); sender.sendMessage(Helper.chatLabel() + "/siege abandon [town]");
sender.sendMessage(Helper.Chatlabel() + "/siege list"); sender.sendMessage(Helper.chatLabel() + "/siege list");
} }
} }
@@ -32,7 +32,7 @@ public class WarCommands implements CommandExecutor {
final Player p = (Player) sender; final Player p = (Player) sender;
if (args.length == 0) { if (args.length == 0) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war help"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /war help");
return true; return true;
} else if (args.length >= 1) { } else if (args.length >= 1) {
@@ -59,7 +59,7 @@ public class WarCommands implements CommandExecutor {
warHelp(p, args); warHelp(p, args);
return true; return true;
default: default:
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war help"); p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /war help");
return true; return true;
} }
@@ -67,7 +67,7 @@ public class WarCommands implements CommandExecutor {
return false; return false;
} }
protected static void warCreate(Player p, String[] args) { protected static void warCreate(CommandSender p, String[] args) {
if (!p.hasPermission("AlathraWar.admin")) { if (!p.hasPermission("AlathraWar.admin")) {
p.sendMessage("You do not have permission to run this command."); p.sendMessage("You do not have permission to run this command.");
return; return;
@@ -77,13 +77,13 @@ public class WarCommands implements CommandExecutor {
WarData.addWar(war); WarData.addWar(war);
war.save(); war.save();
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1] + ", " p.sendMessage(String.valueOf(Helper.chatLabel()) + "War created with the name " + args[1] + ", "
+ args[2] + " vs. " + args[3]); + args[2] + " vs. " + args[3]);
Main.warLogger.log(p.getName() + " created a new war with the name " + args[1] + ", " + args[2] Main.warLogger.log(p.getName() + " created a new war with the name " + args[1] + ", " + args[2]
+ " vs. " + args[3]); + " vs. " + args[3]);
return; return;
} else { } else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) p.sendMessage(String.valueOf(Helper.chatLabel())
+ "Invalid Arguments. /war create [name] [side1] [side2]"); + "Invalid Arguments. /war create [name] [side1] [side2]");
} }
@@ -100,18 +100,18 @@ public class WarCommands implements CommandExecutor {
// War Check // War Check
if (war == null) { if (war == null) {
p.sendMessage(Helper.Chatlabel() p.sendMessage(Helper.chatLabel()
+ "War not found. Type /war list to view current wars."); + "War not found. Type /war list to view current wars.");
return; return;
} }
WarData.removeWar(war); WarData.removeWar(war);
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War " + args[1] + " deleted."); p.sendMessage(String.valueOf(Helper.chatLabel()) + "War " + args[1] + " deleted.");
Main.warLogger.log(p.getName() + " deleted " + args[1]); Main.warLogger.log(p.getName() + " deleted " + args[1]);
return; return;
} else { } else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) p.sendMessage(String.valueOf(Helper.chatLabel())
+ "Invalid Arguments. /war delete [name]"); + "Invalid Arguments. /war delete [name]");
} }
} }
@@ -122,10 +122,10 @@ public class WarCommands implements CommandExecutor {
* @param args * @param args
* @param admin - admin behavior * @param admin - admin behavior
*/ */
protected static void warJoin(Player p, String[] args, boolean admin) { protected static void warJoin(CommandSender p, String[] args, boolean admin) {
// Sufficient args check // Sufficient args check
if (args.length < 3) { if (args.length < 3) {
p.sendMessage(Helper.Chatlabel() p.sendMessage(Helper.chatLabel()
+ "/war join [name] [side], type /war list to view current wars"); + "/war join [name] [side], type /war list to view current wars");
return; return;
} }
@@ -133,13 +133,26 @@ public class WarCommands implements CommandExecutor {
// War check // War check
War war = WarData.getWar(args[1]); War war = WarData.getWar(args[1]);
if (war == null) { if (war == null) {
p.sendMessage(Helper.Chatlabel() p.sendMessage(Helper.chatLabel()
+ "War not found. /war join [name] [side], type /war list to view current wars"); + "War not found. /war join [name] [side], type /war list to view current wars");
return; return;
} }
Player player = null;
if (admin){
player = Bukkit.getPlayer(args[3]);
if(player == null) {
p.sendMessage(Helper.chatLabel() + "Player " + args[3] + " not found!");
return;
}
}
if(player == null) {
player = (Player) p;
}
// Towny Resident Object, if admin then dont use command runner, use declared player // Towny Resident Object, if admin then dont use command runner, use declared player
Resident res = TownyAPI.getInstance().getResident(admin ? Bukkit.getPlayer(args[3]) : p); Resident res = TownyAPI.getInstance().getResident(player);
// Town check // Town check
Town town = res.getTownOrNull(); Town town = res.getTownOrNull();
@@ -179,10 +192,10 @@ public class WarCommands implements CommandExecutor {
// Side checks // Side checks
int side = war.getSide(town.getName().toLowerCase()); int side = war.getSide(town.getName().toLowerCase());
if (side == -1) { if (side == -1) {
p.sendMessage(Helper.Chatlabel() + "You've already surrendered!"); p.sendMessage(Helper.chatLabel() + "You've already surrendered!");
return; return;
} else if (side > 0) { } else if (side > 0) {
p.sendMessage(Helper.Chatlabel() + "You're already in this war!"); p.sendMessage(Helper.chatLabel() + "You're already in this war!");
return; return;
} }
@@ -190,26 +203,26 @@ public class WarCommands implements CommandExecutor {
if(res.getPlayer().hasPermission("AlathraWar.nationjoin" )|| res.isKing()) { if(res.getPlayer().hasPermission("AlathraWar.nationjoin" )|| res.isKing()) {
// Has nation declaration permission // Has nation declaration permission
war.addNation(res.getNationOrNull(), args[2]); war.addNation(res.getNationOrNull(), args[2]);
res.getPlayer().sendMessage(Helper.Chatlabel() + "You have joined the war for " + res.getNationOrNull().getName()); res.getPlayer().sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getNationOrNull().getName());
p.sendMessage(Helper.Chatlabel() + "You have joined the war for " + res.getNationOrNull().getName()); p.sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getNationOrNull().getName());
war.save(); war.save();
return; return;
} else { } else {
// Cannot declare nation involvement // Cannot declare nation involvement
p.sendMessage(Helper.Chatlabel() + "You cannot declare war for your nation."); p.sendMessage(Helper.chatLabel() + "You cannot declare war for your nation.");
return; return;
} }
} else if (res.hasTown()) { } else if (res.hasTown()) {
if (res.getPlayer().hasPermission("AlathraWar.townjoin") || res.isMayor()) { if (res.getPlayer().hasPermission("AlathraWar.townjoin") || res.isMayor()) {
// Is in indepdenent town & has declaration perms // Is in indepdenent town & has declaration perms
war.addTown(res.getTownOrNull(), args[2]); war.addTown(res.getTownOrNull(), args[2]);
res.getPlayer().sendMessage(Helper.Chatlabel() + "You have joined the war for " + res.getTownOrNull().getName()); res.getPlayer().sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getTownOrNull().getName());
p.sendMessage(Helper.Chatlabel() + "You have joined the war for " + res.getTownOrNull().getName()); p.sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getTownOrNull().getName());
war.save(); war.save();
return; return;
} else { } else {
// No perms // No perms
p.sendMessage(Helper.Chatlabel() + "You cannot declare war for your town."); p.sendMessage(Helper.chatLabel() + "You cannot declare war for your town.");
return; return;
} }
} }
@@ -218,7 +231,7 @@ public class WarCommands implements CommandExecutor {
protected static void warSurrender(Player p, String[] args, boolean admin) { protected static void warSurrender(Player p, String[] args, boolean admin) {
// Sufficient args check // Sufficient args check
if (args.length < 2) { if (args.length < 2) {
p.sendMessage(Helper.Chatlabel() p.sendMessage(Helper.chatLabel()
+ "/war surrender [name], type /war list to view current wars"); + "/war surrender [name], type /war list to view current wars");
return; return;
} }
@@ -226,7 +239,7 @@ public class WarCommands implements CommandExecutor {
// War check // War check
War war = WarData.getWar(args[1]); War war = WarData.getWar(args[1]);
if (war == null) { if (war == null) {
p.sendMessage(Helper.Chatlabel() p.sendMessage(Helper.chatLabel()
+ "War not found. Type /war list to view current wars"); + "War not found. Type /war list to view current wars");
return; return;
} }
@@ -245,24 +258,24 @@ public class WarCommands implements CommandExecutor {
if(p.hasPermission("AlathraWar.nationsurrender" )|| res.isKing()) { if(p.hasPermission("AlathraWar.nationsurrender" )|| res.isKing()) {
// Has nation surrender permission // Has nation surrender permission
war.surrenderNation(res.getNationOrNull()); war.surrenderNation(res.getNationOrNull());
p.sendMessage(Helper.Chatlabel() + "You have surrendered the war for " + res.getNationOrNull().getName()); p.sendMessage(Helper.chatLabel() + "You have surrendered the war for " + res.getNationOrNull().getName());
war.save(); war.save();
return; return;
} else { } else {
// Cannot surrender nation involvement // Cannot surrender nation involvement
p.sendMessage(Helper.Chatlabel() + "You cannot surrender war for your nation."); p.sendMessage(Helper.chatLabel() + "You cannot surrender war for your nation.");
return; return;
} }
} else if (res.hasTown()) { } else if (res.hasTown()) {
if (p.hasPermission("AlathraWar.townsurrender") || res.isMayor()) { if (p.hasPermission("AlathraWar.townsurrender") || res.isMayor()) {
// Is in indepdenent town & has surrender perms // Is in indepdenent town & has surrender perms
war.surrenderTown(res.getTownOrNull().getName()); war.surrenderTown(res.getTownOrNull().getName());
p.sendMessage(Helper.Chatlabel() + "You have surrendered the war for " + res.getTownOrNull().getName()); p.sendMessage(Helper.chatLabel() + "You have surrendered the war for " + res.getTownOrNull().getName());
war.save(); war.save();
return; return;
} else { } else {
// No perms // No perms
p.sendMessage(Helper.Chatlabel() + "You cannot surrender war for your town."); p.sendMessage(Helper.chatLabel() + "You cannot surrender war for your town.");
return; return;
} }
} }
@@ -270,7 +283,7 @@ public class WarCommands implements CommandExecutor {
} }
private static void warList(Player p, String[] args) { private static void warList(Player p, String[] args) {
p.sendMessage(Helper.Chatlabel()+ "Wars:"); p.sendMessage(Helper.chatLabel()+ "Wars:");
ArrayList<War> wars = WarData.getWars(); ArrayList<War> wars = WarData.getWars();
if (wars.size() < 1) { if (wars.size() < 1) {
p.sendMessage("There are no current wars."); p.sendMessage("There are no current wars.");
@@ -283,15 +296,15 @@ public class WarCommands implements CommandExecutor {
private static void warInfo(Player p, String[] args) { private static void warInfo(Player p, String[] args) {
if (args.length < 2) { if (args.length < 2) {
p.sendMessage(Helper.Chatlabel() + "/war info [Player]"); p.sendMessage(Helper.chatLabel() + "/war info [Player]");
} }
Resident res = TownyAPI.getInstance().getResident(args[1]); Resident res = TownyAPI.getInstance().getResident(args[1]);
if (res == null || res.getTownOrNull() == null) { if (res == null || res.getTownOrNull() == null) {
p.sendMessage(Helper.Chatlabel() + "Invalid town resident."); p.sendMessage(Helper.chatLabel() + "Invalid town resident.");
} }
p.sendMessage(Helper.Chatlabel() + p.getName() + "'s wars:"); p.sendMessage(Helper.chatLabel() + p.getName() + "'s wars:");
for (War war : WarData.getWars()) { for (War war : WarData.getWars()) {
int side = war.getSide(args[1]); int side = war.getSide(args[1]);
if (side != 0) { if (side != 0) {
@@ -10,6 +10,7 @@ import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.Raid; import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.War; import me.ShermansWorld.AlathraWar.War;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@@ -19,10 +20,14 @@ public class RaidData {
// Static Raid list for all active raids // Static Raid list for all active raids
private static ArrayList<Raid> raids = new ArrayList<Raid>(); private static ArrayList<Raid> raids = new ArrayList<Raid>();
public static ArrayList<Raid> getRaids() { public static ArrayList<Raid> getRaids() {
return raids; return raids;
} }
/** /**
* Gets a raid with a specific name * Gets a raid with a specific name
* *
@@ -1,12 +1,9 @@
package me.ShermansWorld.AlathraWar.data; package me.ShermansWorld.AlathraWar.data;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import com.palmergames.bukkit.towny.TownyAPI; import com.palmergames.bukkit.towny.TownyAPI;
@@ -26,6 +23,8 @@ public class SiegeData
return sieges; return sieges;
} }
/** /**
* Gets a siege with a specific name * Gets a siege with a specific name
* @param name - Name to check * @param name - Name to check
@@ -74,7 +74,7 @@ public class CommandsListener implements Listener {
//payment check //payment check
for (String cmd : blacklistedXLong) { for (String cmd : blacklistedXLong) {
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) { if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot modify this property during a raid!")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot modify this property during a raid!"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -90,7 +90,7 @@ public class CommandsListener implements Listener {
for (String cmd : payment) { for (String cmd : payment) {
//check for each prefix //check for each prefix
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) { if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot withdraw money whilst in a raid!")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot withdraw money whilst in a raid!"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -105,17 +105,17 @@ public class CommandsListener implements Listener {
|| parse.equals("t spawn") || parse.equals("town spawn") || parse.equals("t spawn") || parse.equals("town spawn")
|| parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn") || parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn")
|| parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) { || parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation.")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
return; return;
} }
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation.")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
//else //else
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a raid!")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot teleport whilst in a raid!"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -132,13 +132,13 @@ public class CommandsListener implements Listener {
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) { if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
//spawn world check //spawn world check
if (p.getWorld().getName().equals("world")) { if (p.getWorld().getName().equals("world")) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation.")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a raid!")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot teleport whilst in a raid!"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -164,7 +164,7 @@ public class CommandsListener implements Listener {
//payment check //payment check
for (String cmd : blacklistedXLong) { for (String cmd : blacklistedXLong) {
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) { if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot modify this property during a siege!")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot modify this property during a siege!"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -180,7 +180,7 @@ public class CommandsListener implements Listener {
for (String cmd : payment) { for (String cmd : payment) {
//check for each prefix //check for each prefix
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) { if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot withdraw money whilst in a siege!")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot withdraw money whilst in a siege!"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -195,17 +195,17 @@ public class CommandsListener implements Listener {
|| parse.equals("t spawn") || parse.equals("town spawn") || parse.equals("t spawn") || parse.equals("town spawn")
|| parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn") || parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn")
|| parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) { || parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation.")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
return; return;
} }
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation.")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
//else //else
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a siege!")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot teleport whilst in a siege!"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -222,13 +222,13 @@ public class CommandsListener implements Listener {
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) { if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
//spawn world check //spawn world check
if (p.getWorld().getName().equals("world")) { if (p.getWorld().getName().equals("world")) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation.")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a siege!")); p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou cannot teleport whilst in a siege!"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -110,7 +110,7 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getAttackerPlayers()) { for (final String playerName : siege.getAttackerPlayers()) {
try { try {
Player p = Bukkit.getPlayer(playerName); Player p = Bukkit.getPlayer(playerName);
if (p != null) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! + 20 Attacker Points"); if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! + 20 Attacker Points");
} }
catch (NullPointerException ignored) { catch (NullPointerException ignored) {
ignored.printStackTrace(); ignored.printStackTrace();
@@ -119,7 +119,7 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getDefenderPlayers()) { for (final String playerName : siege.getDefenderPlayers()) {
try { try {
Player p = Bukkit.getPlayer(playerName); Player p = Bukkit.getPlayer(playerName);
if (p != null) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! + 20 Attacker Points"); if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Defender killed! + 20 Attacker Points");
} }
catch (NullPointerException ignored) { catch (NullPointerException ignored) {
ignored.printStackTrace(); ignored.printStackTrace();
@@ -135,7 +135,7 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getAttackerPlayers()) { for (final String playerName : siege.getAttackerPlayers()) {
try { try {
Player p = Bukkit.getPlayer(playerName); Player p = Bukkit.getPlayer(playerName);
if (p != null) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Attacker killed! + 20 Defender Points"); if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Attacker killed! + 20 Defender Points");
} }
catch (NullPointerException ex3) { catch (NullPointerException ex3) {
ex3.printStackTrace(); ex3.printStackTrace();
@@ -144,7 +144,7 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getDefenderPlayers()) { for (final String playerName : siege.getDefenderPlayers()) {
try { try {
Player p = Bukkit.getPlayer(playerName); Player p = Bukkit.getPlayer(playerName);
if (p != null) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Attacker killed! + 20 Defender Points"); if (p != null) p.sendMessage(String.valueOf(Helper.chatLabel()) + "Attacker killed! + 20 Defender Points");
} }
catch (NullPointerException ex4) { catch (NullPointerException ex4) {
ex4.printStackTrace(); ex4.printStackTrace();
@@ -179,7 +179,7 @@ public final class KillsListener implements Listener
//do raider respawn //do raider respawn
try { try {
event.setRespawnLocation(raid.getGatherTown().getSpawn()); event.setRespawnLocation(raid.getGatherTown().getSpawn());
event.getPlayer().sendMessage(String.valueOf(Helper.Chatlabel()) + "You died " + (raid.getPhase().equals(RaidPhase.COMBAT) ? "raiding" : "before combat") + " and have been teleported back to the gather point."); event.getPlayer().sendMessage(String.valueOf(Helper.chatLabel()) + "You died " + (raid.getPhase().equals(RaidPhase.COMBAT) ? "raiding" : "before combat") + " and have been teleported back to the gather point.");
} catch (TownyException e) { } catch (TownyException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }