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);
}
public static String Chatlabel() {
public static String chatLabel() {
return color("&6[&4AlathraWar&6]&r ");
}
@@ -285,11 +285,11 @@ public class Raid {
//Broadcast to the whole raid
for (String s : activeRaiders) {
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) {
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();
@@ -299,11 +299,11 @@ public class Raid {
this.addLootedChunk(wc);
for (String s : activeRaiders) {
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) {
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() {
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())
+ " are coming to raid "
+ Raid.this.getRaidedTown().getName() + "!");
@@ -334,7 +334,7 @@ public class Raid {
*/
private void startCombat() {
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())
+ " have arrived at "
+ Raid.this.getRaidedTown().getName() + " and the fighting has begun!");
@@ -351,11 +351,11 @@ public class Raid {
this.addPointsToDefenderScore(40);
for (final String playerName : this.getActiveRaiders()) {
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()) {
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);
for (final String playerName : this.getActiveRaiders()) {
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()) {
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
@@ -389,11 +389,11 @@ public class Raid {
//award negative score
for (final String playerName : this.getActiveRaiders()) {
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()) {
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
@@ -410,7 +410,7 @@ public class Raid {
if (this.getDefenderSide().contains(killed.getKiller().getName())) {
try {
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) {
throw new RuntimeException(e);
}
@@ -424,11 +424,11 @@ public class Raid {
public void defenderKilledOutofCombat(PlayerDeathEvent event) {
for (final String playerName : this.getActiveRaiders()) {
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()) {
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
@@ -443,7 +443,7 @@ public class Raid {
if (this.getActiveRaiders().contains(killed.getKiller().getName())) {
try {
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) {
throw new RuntimeException(e);
}
@@ -466,7 +466,7 @@ public class Raid {
if (factor > 3.0) factor = 3.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() + "!");
/*
@@ -554,25 +554,25 @@ public class Raid {
if (factor < 0) factor = 0.0;
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.");
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");
Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(500, "Raid chest");
} 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 + "!");
Bukkit.broadcastMessage(Helper.Chatlabel() + this.raidedTown.getName()
Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName()
+ " has recovered the attackers' raid chest, valued at $1000");
Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(1000, "Raid chest");
} 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.");
Bukkit.broadcastMessage(Helper.Chatlabel() + this.raidedTown.getName()
Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName()
+ " has recovered the attackers' raid chest, valued at $1000.");
Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
@@ -594,7 +594,7 @@ public class Raid {
public void noWinner() {
//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.");
Main.warLogger
.log("No one won the raid of " + this.raidedTown.getName() + "!");
@@ -837,7 +837,7 @@ public class Raid {
if (Raid.this.phase == RaidPhase.GATHER) {
//Broadcast
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!");
Bukkit.broadcastMessage(
"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 (p.equals(owner)) {
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 have been teleported to the gather town's spawn.");
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.");
} else {
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()) + "To rejoin, do /raid join [war] [town]");
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]");
}
}
}
@@ -873,7 +873,7 @@ public class Raid {
//Report
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())
+ " are on their way to raid "
+ Raid.this.getRaidedTown().getName() + "!");
@@ -908,7 +908,7 @@ public class Raid {
//Report
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() + ":");
Bukkit.broadcastMessage(
"Raider Score - " + Raid.this.raiderScore);
@@ -928,7 +928,7 @@ public class Raid {
//Idk if thisll work but if it do then ye
if (Raid.this.lootedChunks.containsKey(wc)) {
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 {
doLootAt(p, wc);
}
@@ -936,7 +936,7 @@ public class Raid {
if (Raid.this.getRaidedTown().hasTownBlock(wc)) {
doLootAt(p, wc);
} 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) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
} catch (NullPointerException ex5) {
}
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
} catch (NullPointerException ex6) {
}
@@ -152,7 +152,7 @@ public class Siege {
if (this.homeBlockControl != 2) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
+ "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex7) {
@@ -160,7 +160,7 @@ public class Siege {
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
+ "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex8) {
@@ -173,7 +173,7 @@ public class Siege {
if (this.homeBlockControl != 3) {
for (final String playerName : Siege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
+ "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex9) {
@@ -181,7 +181,7 @@ public class Siege {
}
for (final String playerName : Siege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel())
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.chatLabel())
+ "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex10) {
@@ -192,7 +192,7 @@ public class Siege {
this.homeBlockControl = 3;
}
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() + ":");
Bukkit.broadcastMessage(
"Attacker Points - " + String.valueOf(Siege.this.attackerPoints));
@@ -232,12 +232,12 @@ public class Siege {
public void attackersWin(final OfflinePlayer siegeLeader) {
final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
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 {
nation = resident.getTown().getNation();
} catch (Exception e) {}
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() + "!");
}
Main.econ.depositPlayer(siegeLeader, 2500.0);
@@ -248,7 +248,7 @@ public class Siege {
} else {
if (this.town.getAccount().getHoldingBalance() < 2500.0) {
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() + "!");
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
Main.econ.depositPlayer(siegeLeader, amt);
@@ -275,8 +275,8 @@ public class Siege {
public void defendersWin() {
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()) + 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()
+ " has recovered the attackers' war chest, valued at $2,500");
Main.warLogger
.log(war.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
@@ -295,8 +295,8 @@ public class Siege {
* No winnder declared
*/
public void noWinner() {
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()) + "The siege of " + this.town.getName() + " was a draw!");
Bukkit.broadcastMessage(String.valueOf(Helper.chatLabel()) + "No money has been recovered.");
Main.warLogger
.log(war.getName() + ": No one won the siege of " + this.town.getName() + "!");
stop();
File diff suppressed because it is too large. Load diff
@@ -15,7 +15,12 @@ public class AdminTabCompletion implements TabCompleter {
"force",
"help",
"info",
"modify"
"modify",
"purgebars",
"load",
"load-all",
"save",
"save-all"
});
List<String> type = List.of(new String[]{
@@ -186,7 +191,26 @@ public class AdminTabCompletion implements TabCompleter {
} else if (args.length == 1) {
return NameUtil.filterByStart(base, args[0]);
} 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) {
switch (args[1]) {
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) {
final Player p = (Player) sender;
// final Player p = (Player) sender;
if (args.length == 0) {
fail(p, args, "syntax");
fail(sender, args, "syntax");
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("list")) {
listRaids(p, args);
listRaids(sender, args);
} else if (args[0].equalsIgnoreCase("help")) {
raidHelp(p, args);
raidHelp(sender, args);
} else {
fail(p, args, "syntax");
fail(sender, args, "syntax");
}
}else if (args.length == 3) {
if (args[0].equalsIgnoreCase("start")) {
startRaid(p, args, false);
startRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("stop")) {
stopRaid(p, args);
stopRaid(sender, args);
} else if (args[0].equalsIgnoreCase("join")) {
joinRaid(p, args, false);
joinRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("leave")) {
leaveRaid(p, args, false);
leaveRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("abandon")) {
abandonRaid(p, args);
abandonRaid(sender, args);
} else {
fail(p, args, "syntax");
fail(sender, args, "syntax");
}
} else {
fail(p, args, "syntax");
fail(sender, args, "syntax");
}
return true;
}
@@ -63,7 +63,7 @@ public class RaidCommands implements CommandExecutor {
* @param p
* @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 townExists = false;
for (final War war : WarData.getWars()) {
@@ -71,29 +71,34 @@ public class RaidCommands implements CommandExecutor {
if (war.getName().equalsIgnoreCase(args[1 + (admin ? 1 : 0)])) {
warFound = true;
Player raidOwner = p;
TownyWorld townyWorld;
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
Player raidOwner = null;
if((p instanceof Player)) {
raidOwner = (Player) p;
}
if(admin && args.length >= 6) {
raidOwner = Bukkit.getPlayer(args[5]);
if(raidOwner == null) {
raidOwner = p;
p.sendMessage("Player Does not exist");
return;
}
}
TownyWorld townyWorld;
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
String side = "";
if (war.getSide1Players().contains(p.getName())) {
if (war.getSide1Players().contains(raidOwner.getName())) {
side = war.getSide1();
} else if (war.getSide2Players().contains(p.getName())) {
} else if (war.getSide2Players().contains(raidOwner.getName())) {
side = war.getSide2();
} 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;
}
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
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) {
//player has joined to recently
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
@@ -105,7 +110,7 @@ public class RaidCommands implements CommandExecutor {
}
}
} 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
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return;
@@ -124,21 +129,21 @@ public class RaidCommands implements CommandExecutor {
} else if(TownyAPI.getInstance().getTown(args[4]) != null) {
gatherTown = TownyAPI.getInstance().getTown(args[4]);
} else {
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");
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");
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
}
} else {
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
}
} 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.");
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.");
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.");
return;
}
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.");
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.");
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.");
return;
}
@@ -152,54 +157,54 @@ public class RaidCommands implements CommandExecutor {
//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.getSurrenderedTowns().contains(raidedTown.getName())) {
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!");
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!");
return;
}
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!");
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!");
return;
}
// Is being sieged check
for (Siege s : SiegeData.getSieges()) {
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!");
if(admin) p.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!");
}
}
townExists = true;
Raid raid2;
if (war.getSide1Players().contains(p.getName())) {
if (war.getSide1Players().contains(raidOwner.getName())) {
//Time and raid activity validity check
int c = RaidData.isValidRaid(war, side, raidedTown);
if (c == 2) {
//if were admin, see if an owner arg exists, and if so then use it
raid2 = new Raid(war, raidedTown, gatherTown, true, raidOwner);
} else if (c == 1) {
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!");
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!");
return;
} else if (c == 0) {
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!");
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!");
return;
} else if (c == -1) {
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!");
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!");
return;
} 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!");
raidOwner.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!");
return;
} else {
throw new IllegalArgumentException();
}
} else {
//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");
return;
}
@@ -208,20 +213,20 @@ public class RaidCommands implements CommandExecutor {
if (c == 2) {
raid2 = new Raid(war, raidedTown, gatherTown, false, raidOwner);
} else if (c == 1) {
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!");
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!");
return;
} else if (c == 0) {
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!");
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!");
return;
} else if (c == -1) {
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!");
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!");
return;
} 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!");
raidOwner.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!");
return;
} else {
throw new IllegalArgumentException();
@@ -232,27 +237,27 @@ public class RaidCommands implements CommandExecutor {
Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull();
int sideR = war.getSide(leaderTown.getName());
if (sideR == 0) {
if (admin) p.sendMessage(Helper.Chatlabel() + "You are not in this war.");
raidOwner.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.");
return;
} else if (sideR == -1) {
if (admin) p.sendMessage(Helper.Chatlabel() + "You have surrendered.");
raidOwner.sendMessage(Helper.Chatlabel() + "You have surrendered.");
if (admin) p.sendMessage(Helper.chatLabel() + "You have surrendered.");
raidOwner.sendMessage(Helper.chatLabel() + "You have surrendered.");
return;
}
// Attacking own side
if (war.getSide(raidedTown) == sideR) {
if (admin) p.sendMessage(Helper.Chatlabel() + "You cannot attack your own towns.");
raidOwner.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.");
return;
}
//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 (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.");
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.");
return;
}
@@ -264,11 +269,11 @@ public class RaidCommands implements CommandExecutor {
WarData.saveWar(raid2.getWar());
//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()) + "All players from the defending side have been drafted for the town's defense.");
Bukkit.broadcastMessage(Helper.Chatlabel() + "The raid of "
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(Helper.chatLabel() + "The raid of "
+ 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!");
Main.warLogger.log(raidOwner.getName() + " started a raid.");
@@ -280,11 +285,11 @@ public class RaidCommands implements CommandExecutor {
}
}
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;
}
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 args
*/
private static void stopRaid(Player p, String[] args) {
private static void stopRaid(CommandSender p, String[] args) {
//admin check
if (!p.hasPermission("AlathraWar.admin")) {
fail(p, args, "permission");
@@ -311,20 +316,24 @@ public class RaidCommands implements CommandExecutor {
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
if (raid != null) {
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");
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");
raid.stop(); //this purges itself from raids
} else {
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!
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
if (raid != null) {
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
Player joiner = p;
Player joiner = null;
if(p instanceof Player) {
joiner = (Player) p;
}
if (admin) {
joiner = Bukkit.getPlayer(args[3]);
@@ -333,26 +342,31 @@ public class RaidCommands implements CommandExecutor {
if (args[4].equals(raid.getDefenderSide())) {
if (!raid.getDefenderPlayers().contains(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.");
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;
} else {
if (!raid.getRaiderPlayers().contains(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.");
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 {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Player " + args[3] + " not found!");
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Player " + args[3] + " not found!");
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())) {
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
@@ -376,7 +390,7 @@ public class RaidCommands implements CommandExecutor {
}
}
} 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
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return;
@@ -391,16 +405,16 @@ public class RaidCommands implements CommandExecutor {
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
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()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
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.");
} 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) {
throw new RuntimeException(e);
}
} 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 {
try {
@@ -408,10 +422,10 @@ public class RaidCommands implements CommandExecutor {
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
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()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
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.");
} 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) {
throw new RuntimeException(e);
@@ -421,27 +435,30 @@ public class RaidCommands implements CommandExecutor {
raid.save();
}
} 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!
Player p = player;
Player p = null;
if (admin) {
p = Bukkit.getPlayer(args[3]);
if (p == null) {
player.sendMessage(String.valueOf(Helper.Chatlabel()) + "Error: player not found!");
player.sendMessage(String.valueOf(Helper.chatLabel()) + "Error: player not found!");
return;
}
}
if(p == null) {
p = (Player) player;
}
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
if (raid != null) {
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
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]");
if (admin) player.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]");
}
//check if gather phase
@@ -451,12 +468,12 @@ public class RaidCommands implements CommandExecutor {
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
raid.removeActiveRaider(p.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() + "!");
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() + "!");
} else {
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!");
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!");
}
} catch (TownyException e) {
throw new RuntimeException(e);
@@ -466,8 +483,8 @@ public class RaidCommands implements CommandExecutor {
raid.save();
} else {
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!");
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!");
}
}
@@ -477,13 +494,13 @@ public class RaidCommands implements CommandExecutor {
* @param p
* @param args
*/
private static void abandonRaid(Player p, String[] args) {
private static void abandonRaid(CommandSender p, String[] args) {
//Get raid
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
if (raid != null) {
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
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;
}
@@ -491,11 +508,11 @@ public class RaidCommands implements CommandExecutor {
//check if gather phase
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.COMBAT) {
//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());
raid.defendersWin(raid.getRaiderScore(), raid.getDefenderScore());
} 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 {
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()) {
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;
}
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()) {
p.sendMessage("Name: " + raid.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")) {
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 join [war] [town]");
p.sendMessage(Helper.Chatlabel() + "/raid leave [war] [town]");
p.sendMessage(Helper.Chatlabel() + "/raid abandon [war] [town]");
p.sendMessage(Helper.Chatlabel() + "/raid list");
p.sendMessage(Helper.chatLabel() + "/raid start [war] [town]");
p.sendMessage(Helper.chatLabel() + "/raid join [war] [town]");
p.sendMessage(Helper.chatLabel() + "/raid leave [war] [town]");
p.sendMessage(Helper.chatLabel() + "/raid abandon [war] [town]");
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) {
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 "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 "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");
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 "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 "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");
}
}
}
@@ -24,7 +24,7 @@ public class SiegeCommands implements CommandExecutor {
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
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;
}
@@ -60,44 +60,50 @@ public class SiegeCommands implements CommandExecutor {
}
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 player is null after this then force end
Player player = !admin ? (Player) sender : args.length >= 4 ? Bukkit.getPlayer(args[3]) : null;
if(player == null) {
sender.sendMessage("Forced owner not found!");
return;
Player siegeOwner = null;
if((sender instanceof Player)) {
siegeOwner = (Player) sender;
}
if(admin && args.length >= 5) {
siegeOwner = Bukkit.getPlayer(args[3]);
if(siegeOwner == null) {
sender.sendMessage("Player Does not exist");
return;
}
}
if (args.length < 3) {
sender.sendMessage(Helper.Chatlabel() + "/war siege [war] [town]");
sender.sendMessage(Helper.chatLabel() + "/war siege [war] [town]");
return;
}
// War check
War war = WarData.getWar(args[1]);
if (war == null) {
player.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]");
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]");
return;
}
// Player participance check
Town leaderTown = TownyAPI.getInstance().getResident(player).getTownOrNull();
Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
int side = war.getSide(leaderTown.getName());
if (side == 0) {
player.sendMessage(Helper.Chatlabel() + "You are not in this war.");
if(admin) sender.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.");
return;
} else if (side == -1) {
player.sendMessage(Helper.Chatlabel() + "You have surrendered.");
if(admin) sender.sendMessage(Helper.Chatlabel() + "You have surrendered.");
siegeOwner.sendMessage(Helper.chatLabel() + "You have surrendered.");
if(admin) sender.sendMessage(Helper.chatLabel() + "You have surrendered.");
return;
}
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
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 (Boolean.parseBoolean(args[4])) {
//player has joined to recently
@@ -105,20 +111,20 @@ public class SiegeCommands implements CommandExecutor {
} else {
//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.");
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;
}
} else {
//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.");
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;
}
}
} 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.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;
}
}
@@ -126,31 +132,32 @@ public class SiegeCommands implements CommandExecutor {
// Town check
Town town = TownyAPI.getInstance().getTown(args[2]);
if (town == null) {
player.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]");
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]");
return;
}
// Is being raided check
for ( Raid r : RaidData.getRaids()) {
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!");
if(admin) sender.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!");
return;
}
}
// Attacking own side
if (war.getSide(town) == side) {
player.sendMessage(Helper.Chatlabel() + "You cannot attack your own towns.");
if(admin) sender.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.");
return;
}
Siege siege = new Siege(war, town, player);
Siege siege = new Siege(war, town, siegeOwner);
SiegeData.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();
siege.start();
@@ -158,37 +165,37 @@ public class SiegeCommands implements CommandExecutor {
private static void siegeStop(CommandSender sender, String[] args) {
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;
}
HashSet<Siege> sieges = SiegeData.getSieges();
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;
}
if (args.length < 3) {
sender.sendMessage(Helper.Chatlabel() + "/siege stop [town]");
sender.sendMessage(Helper.chatLabel() + "/siege stop [town]");
return;
}
// War check
War war = WarData.getWar(args[1]);
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;
}
for (Siege siege : sieges) {
if (siege.getTown().getName().equalsIgnoreCase(args[2])) {
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");
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");
//siege.clearBeacon();
siege.stop();
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) {
@@ -196,30 +203,30 @@ public class SiegeCommands implements CommandExecutor {
final Player p = (Player) sender;
if (args.length < 3) {
sender.sendMessage(Helper.Chatlabel() + "/siege abandon [town]");
sender.sendMessage(Helper.chatLabel() + "/siege abandon [town]");
return;
}
// War check
War war = WarData.getWar(args[1]);
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;
}
Siege siege = SiegeData.getSiege(args[2]);
if (siege == null) {
p.sendMessage(Helper.Chatlabel() + "Invalid siege");
p.sendMessage(Helper.chatLabel() + "Invalid siege");
return;
}
OfflinePlayer oPlayer = siege.getSiegeLeader();
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;
}
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());
siege.defendersWin();
@@ -228,11 +235,11 @@ public class SiegeCommands implements CommandExecutor {
private static void siegeList(CommandSender sender, String[] args) {
HashSet<Siege> sieges = SiegeData.getSieges();
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;
}
sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "Sieges currently in progress:");
sender.sendMessage(String.valueOf(Helper.chatLabel()) + "Sieges currently in progress:");
for (Siege siege : sieges) {
War war = siege.getWar();
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) {
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 abandon [town]");
sender.sendMessage(Helper.Chatlabel() + "/siege list");
sender.sendMessage(Helper.chatLabel() + "/siege start [war] [town]");
sender.sendMessage(Helper.chatLabel() + "/siege abandon [town]");
sender.sendMessage(Helper.chatLabel() + "/siege list");
}
}
@@ -32,7 +32,7 @@ public class WarCommands implements CommandExecutor {
final Player p = (Player) sender;
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;
} else if (args.length >= 1) {
@@ -59,7 +59,7 @@ public class WarCommands implements CommandExecutor {
warHelp(p, args);
return true;
default:
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war help");
p.sendMessage(String.valueOf(Helper.chatLabel()) + "Invalid Arguments. /war help");
return true;
}
@@ -67,7 +67,7 @@ public class WarCommands implements CommandExecutor {
return false;
}
protected static void warCreate(Player p, String[] args) {
protected static void warCreate(CommandSender p, String[] args) {
if (!p.hasPermission("AlathraWar.admin")) {
p.sendMessage("You do not have permission to run this command.");
return;
@@ -77,13 +77,13 @@ public class WarCommands implements CommandExecutor {
WarData.addWar(war);
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]);
Main.warLogger.log(p.getName() + " created a new war with the name " + args[1] + ", " + args[2]
+ " vs. " + args[3]);
return;
} else {
p.sendMessage(String.valueOf(Helper.Chatlabel())
p.sendMessage(String.valueOf(Helper.chatLabel())
+ "Invalid Arguments. /war create [name] [side1] [side2]");
}
@@ -100,18 +100,18 @@ public class WarCommands implements CommandExecutor {
// War Check
if (war == null) {
p.sendMessage(Helper.Chatlabel()
p.sendMessage(Helper.chatLabel()
+ "War not found. Type /war list to view current wars.");
return;
}
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]);
return;
} else {
p.sendMessage(String.valueOf(Helper.Chatlabel())
p.sendMessage(String.valueOf(Helper.chatLabel())
+ "Invalid Arguments. /war delete [name]");
}
}
@@ -122,10 +122,10 @@ public class WarCommands implements CommandExecutor {
* @param args
* @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
if (args.length < 3) {
p.sendMessage(Helper.Chatlabel()
p.sendMessage(Helper.chatLabel()
+ "/war join [name] [side], type /war list to view current wars");
return;
}
@@ -133,13 +133,26 @@ public class WarCommands implements CommandExecutor {
// War check
War war = WarData.getWar(args[1]);
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");
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
Resident res = TownyAPI.getInstance().getResident(admin ? Bukkit.getPlayer(args[3]) : p);
Resident res = TownyAPI.getInstance().getResident(player);
// Town check
Town town = res.getTownOrNull();
@@ -179,10 +192,10 @@ public class WarCommands implements CommandExecutor {
// Side checks
int side = war.getSide(town.getName().toLowerCase());
if (side == -1) {
p.sendMessage(Helper.Chatlabel() + "You've already surrendered!");
p.sendMessage(Helper.chatLabel() + "You've already surrendered!");
return;
} 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;
}
@@ -190,26 +203,26 @@ public class WarCommands implements CommandExecutor {
if(res.getPlayer().hasPermission("AlathraWar.nationjoin" )|| res.isKing()) {
// Has nation declaration permission
war.addNation(res.getNationOrNull(), args[2]);
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());
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());
war.save();
return;
} else {
// 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;
}
} else if (res.hasTown()) {
if (res.getPlayer().hasPermission("AlathraWar.townjoin") || res.isMayor()) {
// Is in indepdenent town & has declaration perms
war.addTown(res.getTownOrNull(), args[2]);
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());
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());
war.save();
return;
} else {
// 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;
}
}
@@ -218,7 +231,7 @@ public class WarCommands implements CommandExecutor {
protected static void warSurrender(Player p, String[] args, boolean admin) {
// Sufficient args check
if (args.length < 2) {
p.sendMessage(Helper.Chatlabel()
p.sendMessage(Helper.chatLabel()
+ "/war surrender [name], type /war list to view current wars");
return;
}
@@ -226,7 +239,7 @@ public class WarCommands implements CommandExecutor {
// War check
War war = WarData.getWar(args[1]);
if (war == null) {
p.sendMessage(Helper.Chatlabel()
p.sendMessage(Helper.chatLabel()
+ "War not found. Type /war list to view current wars");
return;
}
@@ -245,24 +258,24 @@ public class WarCommands implements CommandExecutor {
if(p.hasPermission("AlathraWar.nationsurrender" )|| res.isKing()) {
// Has nation surrender permission
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();
return;
} else {
// 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;
}
} else if (res.hasTown()) {
if (p.hasPermission("AlathraWar.townsurrender") || res.isMayor()) {
// Is in indepdenent town & has surrender perms
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();
return;
} else {
// 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;
}
}
@@ -270,7 +283,7 @@ public class WarCommands implements CommandExecutor {
}
private static void warList(Player p, String[] args) {
p.sendMessage(Helper.Chatlabel()+ "Wars:");
p.sendMessage(Helper.chatLabel()+ "Wars:");
ArrayList<War> wars = WarData.getWars();
if (wars.size() < 1) {
p.sendMessage("There are no current wars.");
@@ -283,15 +296,15 @@ public class WarCommands implements CommandExecutor {
private static void warInfo(Player p, String[] args) {
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]);
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()) {
int side = war.getSide(args[1]);
if (side != 0) {
@@ -10,6 +10,7 @@ import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.War;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import javax.annotation.Nonnull;
@@ -19,10 +20,14 @@ public class RaidData {
// Static Raid list for all active raids
private static ArrayList<Raid> raids = new ArrayList<Raid>();
public static ArrayList<Raid> getRaids() {
return raids;
}
/**
* Gets a raid with a specific name
*
@@ -1,12 +1,9 @@
package me.ShermansWorld.AlathraWar.data;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
import java.util.*;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import com.palmergames.bukkit.towny.TownyAPI;
@@ -26,6 +23,8 @@ public class SiegeData
return sieges;
}
/**
* Gets a siege with a specific name
* @param name - Name to check
@@ -74,7 +74,7 @@ public class CommandsListener implements Listener {
//payment check
for (String cmd : blacklistedXLong) {
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);
return;
}
@@ -90,7 +90,7 @@ public class CommandsListener implements Listener {
for (String cmd : payment) {
//check for each prefix
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);
return;
}
@@ -105,17 +105,17 @@ public class CommandsListener implements Listener {
|| 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: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;
}
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("&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"));
event.setCancelled(true);
return;
}
//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);
return;
}
@@ -132,13 +132,13 @@ public class CommandsListener implements Listener {
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
//spawn world check
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("&eUse /t spawn, or /n 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("&eUse /t spawn, or /n spawn"));
event.setCancelled(true);
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);
return;
}
@@ -164,7 +164,7 @@ public class CommandsListener implements Listener {
//payment check
for (String cmd : blacklistedXLong) {
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);
return;
}
@@ -180,7 +180,7 @@ public class CommandsListener implements Listener {
for (String cmd : payment) {
//check for each prefix
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);
return;
}
@@ -195,17 +195,17 @@ public class CommandsListener implements Listener {
|| 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: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;
}
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("&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"));
event.setCancelled(true);
return;
}
//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);
return;
}
@@ -222,13 +222,13 @@ public class CommandsListener implements Listener {
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
//spawn world check
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("&eUse /t spawn, or /n 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("&eUse /t spawn, or /n spawn"));
event.setCancelled(true);
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);
return;
}
@@ -110,7 +110,7 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getAttackerPlayers()) {
try {
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) {
ignored.printStackTrace();
@@ -119,7 +119,7 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getDefenderPlayers()) {
try {
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) {
ignored.printStackTrace();
@@ -135,7 +135,7 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getAttackerPlayers()) {
try {
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) {
ex3.printStackTrace();
@@ -144,7 +144,7 @@ public final class KillsListener implements Listener
for (final String playerName : siege.getDefenderPlayers()) {
try {
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) {
ex4.printStackTrace();
@@ -179,7 +179,7 @@ public final class KillsListener implements Listener
//do raider respawn
try {
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) {
throw new RuntimeException(e);
}