diff --git a/src/main/java/me/ShermansWorld/AlathraWar/Helper.java b/src/main/java/me/ShermansWorld/AlathraWar/Helper.java index 0678dba..77c3876 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/Helper.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/Helper.java @@ -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 "); } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/Raid.java b/src/main/java/me/ShermansWorld/AlathraWar/Raid.java index a6e7a52..e461a1f 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/Raid.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/Raid.java @@ -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."); } } } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/Siege.java b/src/main/java/me/ShermansWorld/AlathraWar/Siege.java index 99b8685..2cf9fd2 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/Siege.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/Siege.java @@ -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(); diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminCommands.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminCommands.java index 38813d6..3e92afe 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminCommands.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminCommands.java @@ -14,13 +14,18 @@ import me.ShermansWorld.AlathraWar.data.SiegeData; import me.ShermansWorld.AlathraWar.data.WarData; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.boss.BossBar; +import org.bukkit.boss.KeyedBossBar; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Boss; import org.bukkit.entity.Player; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Random; @@ -106,31 +111,80 @@ public class AdminCommands implements CommandExecutor { */ @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - final Player p = (Player) sender; - if (!p.hasPermission("AlathraWar.admin")) { - return fail(p, args, "permissions"); + if (!sender.hasPermission("AlathraWar.admin")) { + return fail(sender, args, "permissions"); } if (args.length == 0) { - return fail(p, args, "syntax"); + return fail(sender, args, "syntax"); } else if (args.length >= 1) { if (args[0].equalsIgnoreCase("create")) { - return create(p, args); + return create(sender, args); } else if (args[0].equalsIgnoreCase("force")) { - return force(p, args); + return force(sender, args); } else if (args[0].equalsIgnoreCase("help")) { - return help(p, args); + return help(sender, args); } else if (args[0].equalsIgnoreCase("info")) { - return info(p, args); + return info(sender, args); } else if (args[0].equalsIgnoreCase("modify")) { - return modify(p, args); + return modify(sender, args); } else if (args[0].equalsIgnoreCase("awa")) { - return awa(p, args); + return awa(sender, args); + } else if (args[0].equalsIgnoreCase("purgebars")) { + return purgebars(sender, args); + } else if (args[0].equalsIgnoreCase("save")) { + return save(sender, args); + } else if (args[0].equalsIgnoreCase("save-all")) { + return saveAll(sender, args); + } else if (args[0].equalsIgnoreCase("load")) { + return load(sender, args); + } else if (args[0].equalsIgnoreCase("load-all")) { + return loadAll(sender, args); } } return true; } + private static boolean purgebars(CommandSender sender, String[] args) { + for (Iterator it = Bukkit.getBossBars(); it.hasNext(); ) { + KeyedBossBar b = it.next(); + if(b.getKey().getKey().contains(Main.getInstance().getName())) { + b.setVisible(false); + b.removeAll(); + Bukkit.removeBossBar(b.getKey()); + } + } + + sender.sendMessage(Helper.chatLabel() + Helper.color("&cCleared all boss bars that have been registered with AlathraWar.")); + sender.sendMessage(Helper.chatLabel() + Helper.color("&cNote: If any remain, please contact the plugin author or open an issue on GitHub. The data can be found under the tag CustomBossEvents: in level.dat! You will need an NBT Editing program to delete it manually.")); + + return saveAll(sender, args); + } + + private static boolean save(CommandSender sender, String[] args) { + //TODO save + sender.sendMessage(Helper.chatLabel() + Helper.color("&csave Unimplemented!")); + return true; + } + + private static boolean saveAll(CommandSender sender, String[] args) { + //TODO save-all + sender.sendMessage(Helper.chatLabel() + Helper.color("&csave-all Unimplemented!")); + return true; + } + + private static boolean load(CommandSender sender, String[] args) { + //TODO load + sender.sendMessage(Helper.chatLabel() + Helper.color("&cload Unimplemented!")); + return true; + } + + private static boolean loadAll(CommandSender sender, String[] args) { + //TODO load-all + sender.sendMessage(Helper.chatLabel() + Helper.color("&cload-all Unimplemented!")); + return true; + } + /** * //force make event or war, if owner isn't defined, idk haven't decided @@ -138,18 +192,20 @@ public class AdminCommands implements CommandExecutor { * -create raid [war] [raidTown] [gatherTown] (owner) * -create war [name] [side1] [side2] */ - private static boolean create(Player p, String[] args) { + private static boolean create(CommandSender p, String[] args) { if (args.length >= 2) { if (args[1].equalsIgnoreCase("raid")) { if (args.length >= 4) { //specific behavior exists if an admin ran this //using same method so that this doesnt get fucked up if we go back and change original implementation RaidCommands.startRaid(p, args, true); + p.sendMessage(Helper.color("&cForcefully started raid from the console.")); + return true; } else { //defaultCode will bypass the custom gather town to force set owner p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create raid [war] [raidTown] (gatherTown/\"defaultCode\") (owner)")); + return true; } - return true; } else if (args[1].equalsIgnoreCase("siege")) { //this exists to force a seige with a new owner if (args.length >= 4) { @@ -157,10 +213,13 @@ public class AdminCommands implements CommandExecutor { "start", args[2], args[3], - args[4] + args[4], + args[5] }; SiegeCommands.siegeStart(p, adjusted, true); - p.sendMessage(Helper.Chatlabel() + "Try again later!"); +// p.sendMessage(Helper.Chatlabel() + "Try again later!"); + p.sendMessage(Helper.color("&cForcefully started siege from the console.")); + return true; } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create siege [war] [town] (owner)")); return true; @@ -176,6 +235,8 @@ public class AdminCommands implements CommandExecutor { args[4] }; WarCommands.warCreate(p, adjusted); + p.sendMessage(Helper.color("&cForcefully started war from the console.")); + return true; } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create war [name] [side1] [side2]")); return true; @@ -203,7 +264,7 @@ public class AdminCommands implements CommandExecutor { * @param args args * @return result */ - private static boolean force(Player p, String[] args) { + private static boolean force(CommandSender p, String[] args) { if (args.length >= 2) { if (args[1].equalsIgnoreCase("end")) { if (args.length >= 3) { @@ -214,12 +275,12 @@ public class AdminCommands implements CommandExecutor { if (r.getSide1AreRaiders()) { if (args[5].equals(r.getWar().getSide1())) { r.raidersWin(r.getOwner(), r.getRaiderScore(), r.getDefenderScore()); - p.sendMessage(Helper.Chatlabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (raiders) declared as victor."); + p.sendMessage(Helper.chatLabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (raiders) declared as victor."); Main.warLogger.log("Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (raiders) declared as victor."); return true; } else if (args[5].equals(r.getWar().getSide2())) { r.defendersWin(r.getRaiderScore(), r.getDefenderScore()); - p.sendMessage(Helper.Chatlabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (defenders) declared as victor."); + p.sendMessage(Helper.chatLabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (defenders) declared as victor."); Main.warLogger.log("Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (defenders) declared as victor."); return true; } else { @@ -229,12 +290,12 @@ public class AdminCommands implements CommandExecutor { } else { if (args[5].equals(r.getWar().getSide1())) { r.defendersWin(r.getRaiderScore(), r.getDefenderScore()); - p.sendMessage(Helper.Chatlabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (defenders) declared as victor."); + p.sendMessage(Helper.chatLabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (defenders) declared as victor."); Main.warLogger.log("Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (defenders) declared as victor."); return true; } else if (args[5].equals(r.getWar().getSide2())) { r.raidersWin(r.getOwner(), r.getRaiderScore(), r.getDefenderScore()); - p.sendMessage(Helper.Chatlabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (raiders) declared as victor."); + p.sendMessage(Helper.chatLabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (raiders) declared as victor."); Main.warLogger.log("Raid forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[5] + " (raiders) declared as victor."); return true; } else { @@ -246,7 +307,7 @@ public class AdminCommands implements CommandExecutor { } else if (args.length == 5) { if (r.getWar().getName().equals(args[3]) && r.getRaidedTown().getName().equals(args[4])) { r.noWinner(); - p.sendMessage(Helper.Chatlabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with no victor."); + p.sendMessage(Helper.chatLabel() + "Raid forcefully ended on " + args[4] + " in war " + args[3] + " with no victor."); Main.warLogger.log("Raid forcefully ended on " + args[4] + " in war " + args[3] + " with no victor."); return true; } @@ -265,12 +326,12 @@ public class AdminCommands implements CommandExecutor { if (s.getSide1AreAttackers()) { if (args[5].equals(s.getWar().getSide1())) { s.attackersWin(s.getSiegeOwner()); - p.sendMessage(Helper.Chatlabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (attackers) declared as victor."); + p.sendMessage(Helper.chatLabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (attackers) declared as victor."); Main.warLogger.log("Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (attackers) declared as victor."); return true; } else if (args[5].equals(s.getWar().getSide2())) { s.defendersWin(); - p.sendMessage(Helper.Chatlabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (defenders) declared as victor."); + p.sendMessage(Helper.chatLabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (defenders) declared as victor."); Main.warLogger.log("Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (defenders) declared as victor."); return true; } else { @@ -280,12 +341,12 @@ public class AdminCommands implements CommandExecutor { } else { if (args[5].equals(s.getWar().getSide1())) { s.defendersWin(); - p.sendMessage(Helper.Chatlabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (defenders) declared as victor."); + p.sendMessage(Helper.chatLabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (defenders) declared as victor."); Main.warLogger.log("Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (defenders) declared as victor."); return true; } else if (args[5].equals(s.getWar().getSide2())) { s.attackersWin(s.getSiegeOwner()); - p.sendMessage(Helper.Chatlabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (attackers) declared as victor."); + p.sendMessage(Helper.chatLabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (attackers) declared as victor."); Main.warLogger.log("Siege forcefully ended on " + args[4] + " in war " + args[3] + " with " + args[6] + " (attackers) declared as victor."); return true; } else { @@ -297,7 +358,7 @@ public class AdminCommands implements CommandExecutor { } else if (args.length == 5) { if (s.getWar().getName().equals(args[3]) && s.getTown().getName().equals(args[4])) { s.noWinner(); - p.sendMessage(Helper.Chatlabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with no victor."); + p.sendMessage(Helper.chatLabel() + "Siege forcefully ended on " + args[4] + " in war " + args[3] + " with no victor."); Main.warLogger.log("Siege forcefully ended on " + args[4] + " in war " + args[3] + " with no victor."); return true; } @@ -392,7 +453,7 @@ public class AdminCommands implements CommandExecutor { args[5] }; RaidCommands.leaveRaid(p, fixed, true); - p.sendMessage(Helper.Chatlabel() + "Forced player " + args[5] + " to leave raid on " + args[4] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Forced player " + args[5] + " to leave raid on " + args[4] + " in war " + args[3]); Main.warLogger.log("Forced player " + args[5] + " to leave raid on " + args[4] + " in war " + args[3]); return finalizeRaid(r); } else { @@ -429,12 +490,12 @@ public class AdminCommands implements CommandExecutor { return fail(p, args, "syntax"); } - private static boolean help(Player p, String[] args) { - p.sendMessage(Helper.Chatlabel() + "/alathrawaradmin create"); - p.sendMessage(Helper.Chatlabel() + "/alathrawaradmin force"); - p.sendMessage(Helper.Chatlabel() + "/alathrawaradmin help"); - p.sendMessage(Helper.Chatlabel() + "/alathrawaradmin info"); - p.sendMessage(Helper.Chatlabel() + "/alathrawaradmin modify"); + private static boolean help(CommandSender p, String[] args) { + p.sendMessage(Helper.chatLabel() + "/alathrawaradmin create"); + p.sendMessage(Helper.chatLabel() + "/alathrawaradmin force"); + p.sendMessage(Helper.chatLabel() + "/alathrawaradmin help"); + p.sendMessage(Helper.chatLabel() + "/alathrawaradmin info"); + p.sendMessage(Helper.chatLabel() + "/alathrawaradmin modify"); return true; } @@ -450,22 +511,22 @@ public class AdminCommands implements CommandExecutor { * @param args args * @return result */ - private static boolean info(Player p, String[] args) { + private static boolean info(CommandSender p, String[] args) { if (args.length >= 2) { if (args[1].equalsIgnoreCase("war")) { if (args.length >= 3) { for (War w : WarData.getWars()) { if (w.getName().equals(args[2])) { - p.sendMessage(Helper.Chatlabel() + "Info dump for war: " + w.getName()); - p.sendMessage(Helper.Chatlabel() + "oOo------------===------------oOo"); - p.sendMessage(Helper.Chatlabel() + "Name: " + w.getName()); - p.sendMessage(Helper.Chatlabel() + "Side 1: " + w.getSide1()); - p.sendMessage(Helper.Chatlabel() + "Side 2: " + w.getSide2()); - p.sendMessage(Helper.Chatlabel() + "Side 1 Score: " + w.getSide1Points()); - p.sendMessage(Helper.Chatlabel() + "Side 2 Score: " + w.getSide2Points()); - p.sendMessage(Helper.Chatlabel() + "Last Raid for Side 1: " + new Timestamp(((long) w.getLastRaidTimeSide1()) * 1000L)); - p.sendMessage(Helper.Chatlabel() + "Last Raid for Side 2: " + new Timestamp(((long) w.getLastRaidTimeSide2()) * 1000L)); - p.sendMessage(Helper.Chatlabel() + "oOo------------===------------oOo"); + p.sendMessage(Helper.chatLabel() + "Info dump for war: " + w.getName()); + p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo"); + p.sendMessage(Helper.chatLabel() + "Name: " + w.getName()); + p.sendMessage(Helper.chatLabel() + "Side 1: " + w.getSide1()); + p.sendMessage(Helper.chatLabel() + "Side 2: " + w.getSide2()); + p.sendMessage(Helper.chatLabel() + "Side 1 Score: " + w.getSide1Points()); + p.sendMessage(Helper.chatLabel() + "Side 2 Score: " + w.getSide2Points()); + p.sendMessage(Helper.chatLabel() + "Last Raid for Side 1: " + new Timestamp(((long) w.getLastRaidTimeSide1()) * 1000L)); + p.sendMessage(Helper.chatLabel() + "Last Raid for Side 2: " + new Timestamp(((long) w.getLastRaidTimeSide2()) * 1000L)); + p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo"); StringBuilder side1Towns = new StringBuilder(); StringBuilder side1Players = new StringBuilder(); for (String t : w.getSide1Towns()) { @@ -479,10 +540,10 @@ public class AdminCommands implements CommandExecutor { //cut off last two characters if(side1Towns.length() > 2) side1Towns = new StringBuilder(side1Towns.substring(0, side1Towns.length() - 2)); if(side1Players.length() > 2) side1Players = new StringBuilder(side1Players.substring(0, side1Players.length() - 2)); - p.sendMessage(Helper.Chatlabel() + w.getSide1() + " Towns: " + side1Towns); - p.sendMessage(Helper.Chatlabel() + w.getSide1() + " Players: " + side1Players); + p.sendMessage(Helper.chatLabel() + w.getSide1() + " Towns: " + side1Towns); + p.sendMessage(Helper.chatLabel() + w.getSide1() + " Players: " + side1Players); - p.sendMessage(Helper.Chatlabel() + "oOo------------===------------oOo"); + p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo"); StringBuilder side2Towns = new StringBuilder(); StringBuilder side2Players = new StringBuilder(); for (String t : w.getSide2Towns()) { @@ -496,10 +557,10 @@ public class AdminCommands implements CommandExecutor { //cut off last two characters if(side2Towns.length() > 2) side2Towns = new StringBuilder(side2Towns.substring(0, side2Towns.length() - 2)); if(side2Players.length() > 2) side2Players = new StringBuilder(side2Players.substring(0, side2Players.length() - 2)); - p.sendMessage(Helper.Chatlabel() + w.getSide2() + " Towns: " + side2Towns); - p.sendMessage(Helper.Chatlabel() + w.getSide2() + " Players: " + side2Players); + p.sendMessage(Helper.chatLabel() + w.getSide2() + " Towns: " + side2Towns); + p.sendMessage(Helper.chatLabel() + w.getSide2() + " Players: " + side2Players); - p.sendMessage(Helper.Chatlabel() + "oOo------------===------------oOo"); + p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo"); StringBuilder surrenderedTowns = new StringBuilder(); for (String t : w.getSurrenderedTowns()) { surrenderedTowns.append(t); @@ -507,7 +568,7 @@ public class AdminCommands implements CommandExecutor { } //cut off last two characters if(surrenderedTowns.length() > 2) surrenderedTowns = new StringBuilder(surrenderedTowns.substring(0, surrenderedTowns.length() - 2)); - p.sendMessage(Helper.Chatlabel() + "Surrendered Towns: " + surrenderedTowns); + p.sendMessage(Helper.chatLabel() + "Surrendered Towns: " + surrenderedTowns); return true; } } @@ -520,23 +581,23 @@ public class AdminCommands implements CommandExecutor { if (args.length >= 4) { for (Raid r : RaidData.getRaids()) { if (r.getWar().getName().equals(args[2]) && r.getRaidedTown().getName().equals(args[3])) { - p.sendMessage(Helper.Chatlabel() + "Info dump for raid: " + r.getName()); - p.sendMessage(Helper.Chatlabel() + "oOo------------===------------oOo"); - p.sendMessage(Helper.Chatlabel() + "Name: " + r.getName()); - p.sendMessage(Helper.Chatlabel() + "Raiders: " + r.getRaiderSide()); - p.sendMessage(Helper.Chatlabel() + "Defenders: " + r.getDefenderSide()); - p.sendMessage(Helper.Chatlabel() + "Side1Raiders: " + r.getSide1AreRaiders()); - p.sendMessage(Helper.Chatlabel() + "Raider Score: " + r.getRaiderScore()); - p.sendMessage(Helper.Chatlabel() + "Defender Score: " + r.getDefenderScore()); - p.sendMessage(Helper.Chatlabel() + "War: " + r.getWar().getName()); - p.sendMessage(Helper.Chatlabel() + "Raided Town: " + r.getRaidedTown().getName()); - p.sendMessage(Helper.Chatlabel() + "Gather Town: " + r.getGatherTown().getName()); - p.sendMessage(Helper.Chatlabel() + "Current Phase: " + r.getPhase().name()); - p.sendMessage(Helper.Chatlabel() + "Tick progress: " + r.getRaidTicks()); - p.sendMessage(Helper.Chatlabel() + "Owner: " + r.getOwner().getName()); - p.sendMessage(Helper.Chatlabel() + "Gather Homeblock: " + (r.getHomeBlockGather() == null ? "NONE" : r.getHomeBlockGather().toString())); - p.sendMessage(Helper.Chatlabel() + "Raided Homeblock: " + (r.getHomeBlockRaided() == null ? "NONE" : r.getHomeBlockRaided().toString())); - p.sendMessage(Helper.Chatlabel() + "oOo------------===------------oOo"); + p.sendMessage(Helper.chatLabel() + "Info dump for raid: " + r.getName()); + p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo"); + p.sendMessage(Helper.chatLabel() + "Name: " + r.getName()); + p.sendMessage(Helper.chatLabel() + "Raiders: " + r.getRaiderSide()); + p.sendMessage(Helper.chatLabel() + "Defenders: " + r.getDefenderSide()); + p.sendMessage(Helper.chatLabel() + "Side1Raiders: " + r.getSide1AreRaiders()); + p.sendMessage(Helper.chatLabel() + "Raider Score: " + r.getRaiderScore()); + p.sendMessage(Helper.chatLabel() + "Defender Score: " + r.getDefenderScore()); + p.sendMessage(Helper.chatLabel() + "War: " + r.getWar().getName()); + p.sendMessage(Helper.chatLabel() + "Raided Town: " + r.getRaidedTown().getName()); + p.sendMessage(Helper.chatLabel() + "Gather Town: " + r.getGatherTown().getName()); + p.sendMessage(Helper.chatLabel() + "Current Phase: " + r.getPhase().name()); + p.sendMessage(Helper.chatLabel() + "Tick progress: " + r.getRaidTicks()); + p.sendMessage(Helper.chatLabel() + "Owner: " + r.getOwner().getName()); + p.sendMessage(Helper.chatLabel() + "Gather Homeblock: " + (r.getHomeBlockGather() == null ? "NONE" : r.getHomeBlockGather().toString())); + p.sendMessage(Helper.chatLabel() + "Raided Homeblock: " + (r.getHomeBlockRaided() == null ? "NONE" : r.getHomeBlockRaided().toString())); + p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo"); StringBuilder activeRaiders = new StringBuilder(); for (String pl : r.getActiveRaiders()) { activeRaiders.append(pl); @@ -544,9 +605,9 @@ public class AdminCommands implements CommandExecutor { } //cut off last two characters if(activeRaiders.length() > 2) activeRaiders = new StringBuilder(activeRaiders.substring(0, activeRaiders.length() - 2)); - p.sendMessage(Helper.Chatlabel() + "Raiding Players: " + activeRaiders); + p.sendMessage(Helper.chatLabel() + "Raiding Players: " + activeRaiders); - p.sendMessage(Helper.Chatlabel() + "oOo------------===------------oOo"); + p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo"); StringBuilder defenderPlayers = new StringBuilder(); for (String pl : r.getDefenderPlayers()) { defenderPlayers.append(pl); @@ -554,7 +615,7 @@ public class AdminCommands implements CommandExecutor { } //cut off last two characters if(defenderPlayers.length() > 2) defenderPlayers = new StringBuilder(defenderPlayers.substring(0, defenderPlayers.length() - 2)); - p.sendMessage(Helper.Chatlabel() + "Defending Players: " + defenderPlayers); + p.sendMessage(Helper.chatLabel() + "Defending Players: " + defenderPlayers); return true; } } @@ -567,20 +628,20 @@ public class AdminCommands implements CommandExecutor { if (args.length >= 4) { for (Siege s : SiegeData.getSieges()) { if (s.getWar().getName().equals(args[2]) && s.getTown().getName().equals(args[3])) { - p.sendMessage(Helper.Chatlabel() + "Info dump for siege: " + s.getName()); - p.sendMessage(Helper.Chatlabel() + "oOo------------===------------oOo"); - p.sendMessage(Helper.Chatlabel() + "Name: " + s.getName()); - p.sendMessage(Helper.Chatlabel() + "Attackers: " + s.getAttackerSide()); - p.sendMessage(Helper.Chatlabel() + "Defenders: " + s.getDefenderSide()); - p.sendMessage(Helper.Chatlabel() + "Attacker points: " + s.getAttackerPoints()); - p.sendMessage(Helper.Chatlabel() + "Defender points: " + s.getDefenderPoints()); - p.sendMessage(Helper.Chatlabel() + "War: " + s.getWar().getName()); - p.sendMessage(Helper.Chatlabel() + "Attacked Town: " + s.getTown().getName()); - p.sendMessage(Helper.Chatlabel() + "Max Ticks: " + s.getMaxSiegeTicks()); - p.sendMessage(Helper.Chatlabel() + "Tick progress: " + s.getSiegeTicks()); - p.sendMessage(Helper.Chatlabel() + "Owner: " + s.getSiegeOwner()); - p.sendMessage(Helper.Chatlabel() + "Homeblock: " + s.getHomeBlock().toString()); - p.sendMessage(Helper.Chatlabel() + "oOo------------===------------oOo"); + p.sendMessage(Helper.chatLabel() + "Info dump for siege: " + s.getName()); + p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo"); + p.sendMessage(Helper.chatLabel() + "Name: " + s.getName()); + p.sendMessage(Helper.chatLabel() + "Attackers: " + s.getAttackerSide()); + p.sendMessage(Helper.chatLabel() + "Defenders: " + s.getDefenderSide()); + p.sendMessage(Helper.chatLabel() + "Attacker points: " + s.getAttackerPoints()); + p.sendMessage(Helper.chatLabel() + "Defender points: " + s.getDefenderPoints()); + p.sendMessage(Helper.chatLabel() + "War: " + s.getWar().getName()); + p.sendMessage(Helper.chatLabel() + "Attacked Town: " + s.getTown().getName()); + p.sendMessage(Helper.chatLabel() + "Max Ticks: " + s.getMaxSiegeTicks()); + p.sendMessage(Helper.chatLabel() + "Tick progress: " + s.getSiegeTicks()); + p.sendMessage(Helper.chatLabel() + "Owner: " + s.getSiegeOwner()); + p.sendMessage(Helper.chatLabel() + "Homeblock: " + s.getHomeBlock().toString()); + p.sendMessage(Helper.chatLabel() + "oOo------------===------------oOo"); StringBuilder attackers = new StringBuilder(); for (String pl : s.getAttackerPlayers()) { attackers.append(pl); @@ -588,7 +649,7 @@ public class AdminCommands implements CommandExecutor { } //cut off last two characters if(attackers.length() > 2) attackers = new StringBuilder(attackers.substring(0, attackers.length() - 2)); - p.sendMessage(Helper.Chatlabel() + "Attacking Players: " + attackers); + p.sendMessage(Helper.chatLabel() + "Attacking Players: " + attackers); StringBuilder defenders = new StringBuilder(); for (String pl : s.getDefenderPlayers()) { defenders.append(pl); @@ -596,7 +657,7 @@ public class AdminCommands implements CommandExecutor { } //cut off last two characters if(defenders.length() > 2) defenders = new StringBuilder(defenders.substring(0, defenders.length() - 2)); - p.sendMessage(Helper.Chatlabel() + "Defending Players: " + defenders); + p.sendMessage(Helper.chatLabel() + "Defending Players: " + defenders); return true; } } @@ -643,7 +704,7 @@ public class AdminCommands implements CommandExecutor { * @param args args * @return result */ - private static boolean modify(Player p, String[] args) { + private static boolean modify(CommandSender p, String[] args) { if (args.length >= 2) { if (args[1].equalsIgnoreCase("raid")) { if (args.length >= 3) { @@ -655,17 +716,17 @@ public class AdminCommands implements CommandExecutor { if(r.getSide1AreRaiders()) { if (args[5].equalsIgnoreCase("add")) { r.addPointsToRaiderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("subtract")) { r.subtractPointsFromRaiderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("set")) { r.setRaiderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else { @@ -675,17 +736,17 @@ public class AdminCommands implements CommandExecutor { } else { if (args[5].equalsIgnoreCase("add")) { r.addPointsToDefenderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("subtract")) { r.subtractPointsFromDefenderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("set")) { r.setDefenderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else { @@ -697,17 +758,17 @@ public class AdminCommands implements CommandExecutor { if(!r.getSide1AreRaiders()) { if (args[5].equalsIgnoreCase("add")) { r.addPointsToRaiderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("subtract")) { r.subtractPointsFromRaiderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("set")) { r.setRaiderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else { @@ -717,17 +778,17 @@ public class AdminCommands implements CommandExecutor { } else { if (args[5].equalsIgnoreCase("add")) { r.addPointsToDefenderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Added " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("subtract")) { r.subtractPointsFromDefenderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Subtracted " + args[7] + " points to the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("set")) { r.setDefenderScore(Integer.parseInt(args[7])); - p.sendMessage(Helper.Chatlabel() + "Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); + p.sendMessage(Helper.chatLabel() + "Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); Main.warLogger.log("Set " + args[7] + " points as the raid score in the war " + args[3] + " on town " + args[4]); return finalizeRaid(r); } else { @@ -741,7 +802,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cRaid cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cRaid cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify raid score [war] [town] [add/subtract/set] [side] [value]")); } @@ -756,15 +817,19 @@ public class AdminCommands implements CommandExecutor { } Town t = r.getRaidedTown(); if (args.length >= 8) { - if (p.getWorld() == t.getWorld()) { + if(!(p instanceof Player runner)) { + p.sendMessage(Helper.chatLabel() + "This command cannot be run through console!"); + return true; + } + if (runner.getWorld() == t.getWorld()) { try { - WorldCoord tb = WorldCoord.parseWorldCoord(p.getWorld().getName(), (int) Double.parseDouble(args[5]), (int) Double.parseDouble(args[7])); + WorldCoord tb = WorldCoord.parseWorldCoord(runner.getWorld().getName(), (int) Double.parseDouble(args[5]), (int) Double.parseDouble(args[7])); if (t.hasTownBlock(tb)) { t.setHomeBlock(tb.getTownBlock()); - t.setSpawn(new Location(p.getWorld(), Double.parseDouble(args[5]), Double.parseDouble(args[6]), Double.parseDouble(args[7]))); + t.setSpawn(new Location(runner.getWorld(), Double.parseDouble(args[5]), Double.parseDouble(args[6]), Double.parseDouble(args[7]))); r.setHomeBlockRaided(tb.getTownBlock()); r.setTownSpawnRaided(t.getSpawn()); - p.sendMessage(Helper.Chatlabel() + "Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + p.getLocation().toString()); + p.sendMessage(Helper.chatLabel() + "Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString()); Main.warLogger.log("Set town spawn for raided town " + args[4] + " in war " + args[3] + " to [" + args[5] + "," + args[6] + "," + args[7] + "]"); return finalizeRaid(r); } else { @@ -783,19 +848,23 @@ public class AdminCommands implements CommandExecutor { return true; } } else { - if (p.getWorld() == t.getWorld()) { + if(!(p instanceof Player runner)) { + p.sendMessage(Helper.chatLabel() + "This command cannot be run through console!"); + return true; + } + if (runner.getWorld() == t.getWorld()) { try { - WorldCoord tb = WorldCoord.parseWorldCoord(p.getWorld().getName(), (int) p.getLocation().getX(), (int) p.getLocation().getZ()); + WorldCoord tb = WorldCoord.parseWorldCoord(runner.getWorld().getName(), (int) runner.getLocation().getX(), (int) runner.getLocation().getZ()); if (t.hasTownBlock(tb)) { t.setHomeBlock(tb.getTownBlock()); - t.setSpawn(p.getLocation()); + t.setSpawn(runner.getLocation()); r.setHomeBlockRaided(tb.getTownBlock()); r.setTownSpawnRaided(t.getSpawn()); - p.sendMessage(Helper.Chatlabel() + "Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + p.getLocation().toString()); - Main.warLogger.log("Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + p.getLocation().toString()); + p.sendMessage(Helper.chatLabel() + "Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString()); + Main.warLogger.log("Set town spawn for raided town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString()); return finalizeRaid(r); } else { - p.sendMessage(Helper.color("&cTown does not contain town block at your location [" + (int) p.getLocation().getX() + "," + (int) p.getLocation().getZ() + "]")); + p.sendMessage(Helper.color("&cTown does not contain town block at your location [" + (int) runner.getLocation().getX() + "," + (int) runner.getLocation().getZ() + "]")); return true; } } catch (NotRegisteredException e) { @@ -811,7 +880,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cRaid cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cRaid cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify raid homeblock [war] [town] (x) (Z)")); } @@ -827,10 +896,10 @@ public class AdminCommands implements CommandExecutor { r.setTownSpawnGather(t.getSpawn()); r.setHomeBlockGather(t.getHomeBlock()); } catch (TownyException e) { - p.sendMessage(Helper.Chatlabel() + "Error!"); + p.sendMessage(Helper.chatLabel() + "Error!"); throw new RuntimeException(e); } - p.sendMessage(Helper.Chatlabel() + "Set town new gather town " + t.getName() + " for raid against " + args[4] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Set town new gather town " + t.getName() + " for raid against " + args[4] + " in war " + args[3]); Main.warLogger.log("Set town new gather town " + t.getName() + " for raid against " + args[4] + " in war " + args[3]); return finalizeRaid(r); } else { @@ -839,7 +908,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cRaid cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cRaid cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify raid gather [war] [town] [town]")); } @@ -861,7 +930,7 @@ public class AdminCommands implements CommandExecutor { r.setPhase(ph); r.setRaidTicks(ph.startTick); - p.sendMessage(Helper.Chatlabel() + "Set phase for raid against " + args[4] + " in war " + args[3] + " to " + ph.name()); + p.sendMessage(Helper.chatLabel() + "Set phase for raid against " + args[4] + " in war " + args[3] + " to " + ph.name()); Main.warLogger.log("Set phase for raid against " + args[4] + " in war " + args[3] + " to " + ph.name()); return finalizeRaid(r); } else { @@ -870,7 +939,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cRaid cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cRaid cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify raid phase [war] [town] [phase]")); } @@ -880,50 +949,55 @@ public class AdminCommands implements CommandExecutor { for (Raid r : RaidData.getRaids()) { if (r.getWar().getName().equals(args[3]) && r.getRaidedTown().getName().equals(args[4])) { //parse phase - if (!p.getWorld().equals(r.getRaidedTown().getWorld())) { - p.sendMessage(Helper.Chatlabel() + "Error wrong world"); + if(!(p instanceof Player runner)) { + p.sendMessage(Helper.chatLabel() + "This command cannot be run through console!"); + return true; + } + + if (!runner.getWorld().equals(r.getRaidedTown().getWorld())) { + p.sendMessage(Helper.chatLabel() + "Error wrong world"); return true; } if (args.length >= 9) { if (args[5].equalsIgnoreCase("value")) { - WorldCoord wc = WorldCoord.parseWorldCoord(p.getWorld().getName(), (int) Double.parseDouble(args[7]), (int) Double.parseDouble(args[8])); + WorldCoord wc = WorldCoord.parseWorldCoord(runner.getWorld().getName(), (int) Double.parseDouble(args[7]), (int) Double.parseDouble(args[8])); Raid.LootBlock lb = r.getLootedChunks().get(wc); if(lb == null) { r.addLootedChunk(wc); lb = r.getLootedChunks().get(wc); - p.sendMessage(Helper.Chatlabel() + "Created empty loot chunk data to modify"); + p.sendMessage(Helper.chatLabel() + "Created empty loot chunk data to modify"); } lb.value = Double.parseDouble(args[6]); - p.sendMessage(Helper.Chatlabel() + "Set value for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set value for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); Main.warLogger.log("Set value for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("looted")) { - WorldCoord wc = WorldCoord.parseWorldCoord(p.getWorld().getName(), (int) Double.parseDouble(args[7]), (int) Double.parseDouble(args[8])); + WorldCoord wc = WorldCoord.parseWorldCoord(runner.getWorld().getName(), (int) Double.parseDouble(args[7]), (int) Double.parseDouble(args[8])); Raid.LootBlock lb = r.getLootedChunks().get(wc); //The base value can be abjusted if(!lb.finished && Boolean.parseBoolean(args[6])) { lb.value = new Random().nextDouble() * 100; //score for looting r.addPointsToRaiderScore(10); - p.sendMessage(Helper.Chatlabel() + "Gave value and score because flag was false before."); + p.sendMessage(Helper.chatLabel() + "Gave value and score because flag was false before."); Main.warLogger.log("Gave value and score because flag was false before."); } lb.finished = Boolean.parseBoolean(args[6]); - p.sendMessage(Helper.Chatlabel() + "Set finished flag for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set finished flag for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); Main.warLogger.log("Set finished flag for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("ticks")) { - WorldCoord wc = WorldCoord.parseWorldCoord(p.getWorld().getName(), (int) Double.parseDouble(args[7]), (int) Double.parseDouble(args[8])); + WorldCoord wc = WorldCoord.parseWorldCoord(runner.getWorld().getName(), (int) Double.parseDouble(args[7]), (int) Double.parseDouble(args[8])); Raid.LootBlock lb = r.getLootedChunks().get(wc); lb.ticks = Integer.parseInt(args[6]); - p.sendMessage(Helper.Chatlabel() + "Set ticks for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set ticks for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); Main.warLogger.log("Set ticks for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("reset")) { - WorldCoord wc = WorldCoord.parseWorldCoord(p.getWorld().getName(), (int) Double.parseDouble(args[6]), (int) Double.parseDouble(args[7])); + WorldCoord wc = WorldCoord.parseWorldCoord(runner.getWorld().getName(), (int) Double.parseDouble(args[6]), (int) Double.parseDouble(args[7])); r.getLootedChunks().remove(wc); - p.sendMessage(Helper.Chatlabel() + "Reset loot for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Reset loot for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3]); Main.warLogger.log("Reset loot for a chunk [" + args[7] + "," + args[8] + "] in raid against " + args[4] + " in war " + args[3]); return finalizeRaid(r); } else { @@ -935,31 +1009,31 @@ public class AdminCommands implements CommandExecutor { return true; } else { if (args[5].equalsIgnoreCase("value")) { - WorldCoord wc = WorldCoord.parseWorldCoord(p.getLocation()); + WorldCoord wc = WorldCoord.parseWorldCoord(runner.getLocation()); Raid.LootBlock lb = r.getLootedChunks().get(wc); lb.value = Integer.parseInt(args[6]); - p.sendMessage(Helper.Chatlabel() + "Set value for a chunk [" + p.getLocation().getX() + "," + p.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); - Main.warLogger.log("Set value for a chunk [" + p.getLocation().getX() + "," + p.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set value for a chunk [" + runner.getLocation().getX() + "," + runner.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + Main.warLogger.log("Set value for a chunk [" + runner.getLocation().getX() + "," + runner.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("looted")) { - WorldCoord wc = WorldCoord.parseWorldCoord(p.getLocation()); + WorldCoord wc = WorldCoord.parseWorldCoord(runner.getLocation()); Raid.LootBlock lb = r.getLootedChunks().get(wc); lb.finished = Boolean.parseBoolean(args[6]); - p.sendMessage(Helper.Chatlabel() + "Set looted status for a chunk [" + p.getLocation().getX() + "," + p.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); - Main.warLogger.log("Set looted status for a chunk [" + p.getLocation().getX() + "," + p.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set looted status for a chunk [" + runner.getLocation().getX() + "," + runner.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + Main.warLogger.log("Set looted status for a chunk [" + runner.getLocation().getX() + "," + runner.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("ticks")) { - WorldCoord wc = WorldCoord.parseWorldCoord(p.getLocation()); + WorldCoord wc = WorldCoord.parseWorldCoord(runner.getLocation()); Raid.LootBlock lb = r.getLootedChunks().get(wc); lb.ticks = Integer.parseInt(args[6]); - p.sendMessage(Helper.Chatlabel() + "Set ticks for a chunk [" + p.getLocation().getX() + "," + p.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); - Main.warLogger.log("Set ticks for a chunk [" + p.getLocation().getX() + "," + p.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set ticks for a chunk [" + runner.getLocation().getX() + "," + runner.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + Main.warLogger.log("Set ticks for a chunk [" + runner.getLocation().getX() + "," + runner.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("reset")) { - WorldCoord wc = WorldCoord.parseWorldCoord(p.getLocation()); + WorldCoord wc = WorldCoord.parseWorldCoord(runner.getLocation()); r.getLootedChunks().remove(wc); - p.sendMessage(Helper.Chatlabel() + "Reset loot for a chunk [" + p.getLocation().getX() + "," + p.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3]); - Main.warLogger.log("Reset Loot for a chunk [" + p.getLocation().getX() + "," + p.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Reset loot for a chunk [" + runner.getLocation().getX() + "," + runner.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3]); + Main.warLogger.log("Reset Loot for a chunk [" + runner.getLocation().getX() + "," + runner.getLocation().getZ() + "] in raid against " + args[4] + " in war " + args[3]); return finalizeRaid(r); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify raid loot [war] [town] [value,looted,ticks,reset] [amt] (x) (z)")); @@ -968,7 +1042,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cRaid cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cRaid cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify raid loot [war] [town] [value,looted,ticks,reset] [amt] (x) (z)")); } @@ -980,18 +1054,18 @@ public class AdminCommands implements CommandExecutor { //parse phase if (args[5].equalsIgnoreCase("add")) { r.setRaidTicks(r.getRaidTicks() + Integer.parseInt(args[6])); - p.sendMessage(Helper.Chatlabel() + "Set time for raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set time for raid against " + args[4] + " in war " + args[3] + " to " + args[6]); Main.warLogger.log("Set time for raid against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeRaid(r); } else if (args[5].equalsIgnoreCase("set")) { int t = Integer.parseInt(args[6]); if (t >= r.getPhase().startTick) { r.setRaidTicks(t); - p.sendMessage(Helper.Chatlabel() + "Set time for raid against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set time for raid against " + args[4] + " in war " + args[3] + " to " + args[6]); Main.warLogger.log("Set time for raid against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeRaid(r); } else { - p.sendMessage(Helper.Chatlabel() + Helper.color("&cTime set before current phase, use \"/alathrawaradmin modify raid phase\" instead")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cTime set before current phase, use \"/alathrawaradmin modify raid phase\" instead")); return true; } } else { @@ -1000,7 +1074,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cRaid cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cRaid cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify raid time [war] [town] [add/set] [value]")); } @@ -1013,11 +1087,11 @@ public class AdminCommands implements CommandExecutor { if (own != null) { if(r.getActiveRaiders().contains(own.getName())) { r.setOwner(own); - p.sendMessage(Helper.Chatlabel() + "Set owner of raid against " + args[4] + " in war " + args[3] + " to " + own.getName()); + p.sendMessage(Helper.chatLabel() + "Set owner of raid against " + args[4] + " in war " + args[3] + " to " + own.getName()); Main.warLogger.log("Set owner of raid against " + args[4] + " in war " + args[3] + " to " + own.getName()); return finalizeRaid(r); } else { - p.sendMessage(Helper.Chatlabel() + "Player is not an active raider!"); + p.sendMessage(Helper.chatLabel() + "Player is not an active raider!"); return true; } } else { @@ -1026,7 +1100,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cRaid cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cRaid cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify raid owner [war] [town] [player]")); } @@ -1060,7 +1134,7 @@ public class AdminCommands implements CommandExecutor { } else { s.addPointsToDefenders(Integer.parseInt(args[7])); } - p.sendMessage(Helper.Chatlabel() + "Added " + args[7] + " points to side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Added " + args[7] + " points to side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); Main.warLogger.log("Added " + args[7] + " points to side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); return finalizeSiege(s); } else if (s.getWar().getSide2().equals(args[6])) { @@ -1069,7 +1143,7 @@ public class AdminCommands implements CommandExecutor { } else { s.addPointsToAttackers(Integer.parseInt(args[7])); } - p.sendMessage(Helper.Chatlabel() + "Added " + args[7] + " points to side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Added " + args[7] + " points to side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); Main.warLogger.log("Added " + args[7] + " points to side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); return finalizeSiege(s); } else { @@ -1083,7 +1157,7 @@ public class AdminCommands implements CommandExecutor { } else { s.setDefenderPoints(Integer.parseInt(args[7])); } - p.sendMessage(Helper.Chatlabel() + "Set " + args[7] + " points for side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Set " + args[7] + " points for side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); Main.warLogger.log("Set " + args[7] + " points for side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); return finalizeSiege(s); } else if (s.getWar().getSide2().equals(args[6])) { @@ -1092,7 +1166,7 @@ public class AdminCommands implements CommandExecutor { } else { s.setAttackerPoints(Integer.parseInt(args[7])); } - p.sendMessage(Helper.Chatlabel() + "Set " + args[7] + " points for side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Set " + args[7] + " points for side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); Main.warLogger.log("Set " + args[7] + " points for side " + args[6] + " in sige on " + args[4] + " in war " + args[3]); return finalizeSiege(s); } else { @@ -1108,7 +1182,7 @@ public class AdminCommands implements CommandExecutor { return true; } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cSiege cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cSiege cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify siege score [war] [town] [add/set] [side] [amt]")); } @@ -1123,15 +1197,19 @@ public class AdminCommands implements CommandExecutor { } Town t = s.getTown(); if (args.length >= 8) { - if (p.getWorld() == t.getWorld()) { + if(!(p instanceof Player runner)) { + p.sendMessage(Helper.chatLabel() + "This command cannot be run through console!"); + return true; + } + if (runner.getWorld() == t.getWorld()) { try { - WorldCoord tb = WorldCoord.parseWorldCoord(p.getWorld().getName(), (int) Double.parseDouble(args[5]), (int) Double.parseDouble(args[7])); + WorldCoord tb = WorldCoord.parseWorldCoord(runner.getWorld().getName(), (int) Double.parseDouble(args[5]), (int) Double.parseDouble(args[7])); if (t.hasTownBlock(tb)) { t.setHomeBlock(tb.getTownBlock()); - t.setSpawn(new Location(p.getWorld(), (int) Double.parseDouble(args[5]), (int) Double.parseDouble(args[6]), (int) Double.parseDouble(args[7]))); + t.setSpawn(new Location(runner.getWorld(), (int) Double.parseDouble(args[5]), (int) Double.parseDouble(args[6]), (int) Double.parseDouble(args[7]))); s.setHomeBlock(tb.getTownBlock()); s.setTownSpawn(t.getSpawn()); - p.sendMessage(Helper.Chatlabel() + "Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + p.getLocation().toString()); + p.sendMessage(Helper.chatLabel() + "Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString()); Main.warLogger.log("Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to [" + args[5] + "," + args[6] + "," + args[7] + "]"); return finalizeSiege(s); } else { @@ -1150,19 +1228,24 @@ public class AdminCommands implements CommandExecutor { return true; } } else { - if (p.getWorld() == t.getWorld()) { + + if(!(p instanceof Player runner)) { + p.sendMessage(Helper.chatLabel() + "This command cannot be run through console!"); + return true; + } + if (runner.getWorld() == t.getWorld()) { try { - WorldCoord tb = WorldCoord.parseWorldCoord(p.getWorld().getName(), (int) p.getLocation().getX(), (int) p.getLocation().getZ()); + WorldCoord tb = WorldCoord.parseWorldCoord(runner.getWorld().getName(), (int) runner.getLocation().getX(), (int) runner.getLocation().getZ()); if (t.hasTownBlock(tb)) { t.setHomeBlock(tb.getTownBlock()); - t.setSpawn(p.getLocation()); + t.setSpawn(runner.getLocation()); s.setHomeBlock(tb.getTownBlock()); s.setTownSpawn(t.getSpawn()); - p.sendMessage(Helper.Chatlabel() + "Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + p.getLocation().toString()); - Main.warLogger.log("Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + p.getLocation().toString()); + p.sendMessage(Helper.chatLabel() + "Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString()); + Main.warLogger.log("Set town spawn for sieged town " + args[4] + " in war " + args[3] + " to " + runner.getLocation().toString()); return finalizeSiege(s); } else { - p.sendMessage(Helper.color("&cTown does not contain town block at your location [" + (int) p.getLocation().getX() + "," + (int) p.getLocation().getZ() + "]")); + p.sendMessage(Helper.color("&cTown does not contain town block at your location [" + (int) runner.getLocation().getX() + "," + (int) runner.getLocation().getZ() + "]")); return true; } } catch (NotRegisteredException e) { @@ -1179,7 +1262,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cSiege cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cSiege cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify siege townspawn [war] [town] (x) (y) (Z)")); } @@ -1191,12 +1274,12 @@ public class AdminCommands implements CommandExecutor { //parse phase if (args[5].equalsIgnoreCase("add")) { s.setSiegeTicks(s.getSiegeTicks() + Integer.parseInt(args[6])); - p.sendMessage(Helper.Chatlabel() + "Set time for siege against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set time for siege against " + args[4] + " in war " + args[3] + " to " + args[6]); Main.warLogger.log("Set time for siege against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeSiege(s); } else if (args[5].equalsIgnoreCase("set")) { s.setSiegeTicks(Integer.parseInt(args[6])); - p.sendMessage(Helper.Chatlabel() + "Set time for siege against " + args[4] + " in war " + args[3] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set time for siege against " + args[4] + " in war " + args[3] + " to " + args[6]); Main.warLogger.log("Set time for siege against " + args[4] + " in war " + args[3] + " to " + args[6]); return finalizeSiege(s); } else { @@ -1205,7 +1288,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cSiege cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cSiege cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify siege time [war] [town] [add/set/max] [value]")); } @@ -1218,7 +1301,7 @@ public class AdminCommands implements CommandExecutor { if (own != null) { if (s.attackerPlayers.contains(own.getName())) { s.setSiegeOwner(own); - p.sendMessage(Helper.Chatlabel() + "Set owner of siege against " + args[4] + " in war " + args[3] + " to " + own.getName()); + p.sendMessage(Helper.chatLabel() + "Set owner of siege against " + args[4] + " in war " + args[3] + " to " + own.getName()); Main.warLogger.log("Set owner of siege against " + args[4] + " in war " + args[3] + " to " + own.getName()); return finalizeSiege(s); } else { @@ -1231,7 +1314,7 @@ public class AdminCommands implements CommandExecutor { } } } - p.sendMessage(Helper.Chatlabel() + Helper.color("&cSiege cannot be found.")); + p.sendMessage(Helper.chatLabel() + Helper.color("&cSiege cannot be found.")); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify siege owner [war] [town] [newOwner]")); } @@ -1257,17 +1340,17 @@ public class AdminCommands implements CommandExecutor { if(args[4].equals(w.getSide1())) { if (args[5].equalsIgnoreCase("add")) { w.addSide1Points(Integer.parseInt(args[6])); - p.sendMessage(Helper.Chatlabel() + "Added " + args[6] + " points to the raid war in the war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Added " + args[6] + " points to the raid war in the war " + args[3] + " on side " + args[4]); Main.warLogger.log("Added " + args[6] + " points to the raid war in the war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else if (args[5].equalsIgnoreCase("subtract")) { w.addSide1Points(- Integer.parseInt(args[6])); - p.sendMessage(Helper.Chatlabel() + "Subtracted " + args[6] + " points to the war score in the war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Subtracted " + args[6] + " points to the war score in the war " + args[3] + " on side " + args[4]); Main.warLogger.log("Subtracted " + args[6] + " points to the raid war in the war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else if (args[5].equalsIgnoreCase("set")) { w.setSide1Points(Integer.parseInt(args[6])); - p.sendMessage(Helper.Chatlabel() + "Set " + args[6] + " points as the war score in the war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Set " + args[6] + " points as the war score in the war " + args[3] + " on side " + args[4]); Main.warLogger.log("Set " + args[6] + " points as the war score in the war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else { @@ -1277,17 +1360,17 @@ public class AdminCommands implements CommandExecutor { } else if(args[4].equals(w.getSide2())) { if (args[5].equalsIgnoreCase("add")) { w.addSide2Points(Integer.parseInt(args[6])); - p.sendMessage(Helper.Chatlabel() + "Added " + args[6] + " points to the war score in the war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Added " + args[6] + " points to the war score in the war " + args[3] + " on side " + args[4]); Main.warLogger.log("Added " + args[6] + " points to the war score in the war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else if (args[5].equalsIgnoreCase("subtract")) { w.addSide2Points(- Integer.parseInt(args[6])); - p.sendMessage(Helper.Chatlabel() + "Subtracted " + args[6] + " points to the war score in the war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Subtracted " + args[6] + " points to the war score in the war " + args[3] + " on side " + args[4]); Main.warLogger.log("Subtracted " + args[6] + " points to the war score in the war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else if (args[5].equalsIgnoreCase("set")) { w.setSide2Points(Integer.parseInt(args[6])); - p.sendMessage(Helper.Chatlabel() + "Set " + args[6] + " points as the war score in the war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Set " + args[6] + " points as the war score in the war " + args[3] + " on side " + args[4]); Main.warLogger.log("Set " + args[6] + " points as the war score in the war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else { @@ -1312,14 +1395,14 @@ public class AdminCommands implements CommandExecutor { if (w.getSide1().equals(args[4])) { w.setSide1(args[5]); w.save(); - p.sendMessage(Helper.Chatlabel() + "Set side " + args[4] + " to " + args[5] + " in war " + args[3]); - Main.warLogger.log(Helper.Chatlabel() + "Set side " + args[4] + " to " + args[5] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Set side " + args[4] + " to " + args[5] + " in war " + args[3]); + Main.warLogger.log(Helper.chatLabel() + "Set side " + args[4] + " to " + args[5] + " in war " + args[3]); return finalizeWar(w); } else if (w.getSide2().equals(args[4])) { w.setSide2(args[5]); w.save(); - p.sendMessage(Helper.Chatlabel() + "Set side " + args[4] + " to " + args[5] + " in war " + args[3]); - Main.warLogger.log(Helper.Chatlabel() + "Set side " + args[4] + " to " + args[5] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Set side " + args[4] + " to " + args[5] + " in war " + args[3]); + Main.warLogger.log(Helper.chatLabel() + "Set side " + args[4] + " to " + args[5] + " in war " + args[3]); return finalizeWar(w); } else { p.sendMessage(Helper.color("&cError: Side not found!")); @@ -1337,8 +1420,8 @@ public class AdminCommands implements CommandExecutor { for (War w : WarData.getWars()) { if (w.getName().equals(args[3])) { w.setName(args[4]); - p.sendMessage(Helper.Chatlabel() + "Set name of war " + args[3] + " to " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Set name of war " + args[3] + " to " + args[4]); + p.sendMessage(Helper.chatLabel() + "Set name of war " + args[3] + " to " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Set name of war " + args[3] + " to " + args[4]); return finalizeWar(w); } } @@ -1366,18 +1449,18 @@ public class AdminCommands implements CommandExecutor { //if we already have surrendered if(w.getSurrenderedTowns().contains(args[6])) { w.unSurrenderTown(args[6]); - p.sendMessage(Helper.Chatlabel() + "Un-surrendered town " + args[6]); - Main.warLogger.log(Helper.Chatlabel() + "Un-surrendered town " + args[6]); + p.sendMessage(Helper.chatLabel() + "Un-surrendered town " + args[6]); + Main.warLogger.log(Helper.chatLabel() + "Un-surrendered town " + args[6]); } if(w.getSide1().equals(args[4])) { if(w.getSide2Towns().remove(args[6])) { - p.sendMessage(Helper.Chatlabel() + "Removed town " + args[6] + " from side " + w.getSide2()); - Main.warLogger.log(Helper.Chatlabel() + "Un-surrendered town " + args[6]); + p.sendMessage(Helper.chatLabel() + "Removed town " + args[6] + " from side " + w.getSide2()); + Main.warLogger.log(Helper.chatLabel() + "Un-surrendered town " + args[6]); } } else if(w.getSide2().equals(args[4])) { if(w.getSide1Towns().remove(args[6])) { - p.sendMessage(Helper.Chatlabel() + "Removed town " + args[6] + " from side " + w.getSide2()); - Main.warLogger.log(Helper.Chatlabel() + "Un-surrendered town " + args[6]); + p.sendMessage(Helper.chatLabel() + "Removed town " + args[6] + " from side " + w.getSide2()); + Main.warLogger.log(Helper.chatLabel() + "Un-surrendered town " + args[6]); } } } @@ -1385,16 +1468,16 @@ public class AdminCommands implements CommandExecutor { // Side checks int side = w.getSide(t.getName().toLowerCase()); if (side == -1) { - p.sendMessage(Helper.Chatlabel() + "Town already surrendered!"); + p.sendMessage(Helper.chatLabel() + "Town already surrendered!"); return true; } else if (side > 0) { - p.sendMessage(Helper.Chatlabel() + "Town already in this war!"); + p.sendMessage(Helper.chatLabel() + "Town already in this war!"); return true; } w.addTown(t, args[4]); - p.sendMessage(Helper.Chatlabel() + "Forcefully added town " + args[6] + " war " + args[3] + " on side " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Forcefully added town " + args[6] + " war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Forcefully added town " + args[6] + " war " + args[3] + " on side " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Forcefully added town " + args[6] + " war " + args[3] + " on side " + args[4]); return true; } else { p.sendMessage(Helper.color("&cError: Town not found!")); @@ -1410,18 +1493,18 @@ public class AdminCommands implements CommandExecutor { for(Town t : n.getTowns()) { if(w.getSurrenderedTowns().contains(t.getName())) { w.unSurrenderTown(t.getName()); - p.sendMessage(Helper.Chatlabel() + "Unsurrendered town " + t.getName()); - Main.warLogger.log(Helper.Chatlabel() + "Unsurrendered town " + t.getName()); + p.sendMessage(Helper.chatLabel() + "Unsurrendered town " + t.getName()); + Main.warLogger.log(Helper.chatLabel() + "Unsurrendered town " + t.getName()); } if(w.getSide1().equals(args[4])) { if(w.getSide2Towns().remove(t.getName())) { - p.sendMessage(Helper.Chatlabel() + "Removed town " + t.getName() + " from side " + w.getSide2()); - Main.warLogger.log(Helper.Chatlabel() + "Un-surrendered town " + t.getName()); + p.sendMessage(Helper.chatLabel() + "Removed town " + t.getName() + " from side " + w.getSide2()); + Main.warLogger.log(Helper.chatLabel() + "Un-surrendered town " + t.getName()); } } else if(w.getSide2().equals(args[4])) { if(w.getSide1Towns().remove(t.getName())) { - p.sendMessage(Helper.Chatlabel() + "Removed town " + t.getName() + " from side " + w.getSide2()); - Main.warLogger.log(Helper.Chatlabel() + "Un-surrendered town " + t.getName()); + p.sendMessage(Helper.chatLabel() + "Removed town " + t.getName() + " from side " + w.getSide2()); + Main.warLogger.log(Helper.chatLabel() + "Un-surrendered town " + t.getName()); } } } @@ -1432,17 +1515,17 @@ public class AdminCommands implements CommandExecutor { // Side checks int side = w.getSide(t.getName().toLowerCase()); if (side == -1) { - p.sendMessage(Helper.Chatlabel() + "Town " + t.getName() + " already surrendered!"); + p.sendMessage(Helper.chatLabel() + "Town " + t.getName() + " already surrendered!"); continue; } else if (side > 0) { - p.sendMessage(Helper.Chatlabel() + "Town " + t.getName() + " already in this war!"); + p.sendMessage(Helper.chatLabel() + "Town " + t.getName() + " already in this war!"); continue; } w.addTown(t, args[4]); } - p.sendMessage(Helper.Chatlabel() + "Forcefully added nation " + args[6] + " war " + args[3] + " on side " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Forcefully added nation " + args[6] + " war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Forcefully added nation " + args[6] + " war " + args[3] + " on side " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Forcefully added nation " + args[6] + " war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else { p.sendMessage(Helper.color("&cError: Nation not found!")); @@ -1470,13 +1553,13 @@ public class AdminCommands implements CommandExecutor { if (t != null) { if(w.getSurrenderedTowns().contains(args[5])) { w.unSurrenderTown(args[5]); - p.sendMessage(Helper.Chatlabel() + "Un-surrendered town " + args[5]); - Main.warLogger.log(Helper.Chatlabel() + "Un-surrendered town " + args[5]); + p.sendMessage(Helper.chatLabel() + "Un-surrendered town " + args[5]); + Main.warLogger.log(Helper.chatLabel() + "Un-surrendered town " + args[5]); p.sendMessage(Helper.color("&cTo re-add, use: /alathrawaradmin modify war add, or have the town loader join.")); return true; } - p.sendMessage(Helper.Chatlabel() + "Town " + args[5] + " not already surrendered, ignoring."); - Main.warLogger.log(Helper.Chatlabel() + "Town " + args[5] + " not already surrendered, ignoring."); + p.sendMessage(Helper.chatLabel() + "Town " + args[5] + " not already surrendered, ignoring."); + Main.warLogger.log(Helper.chatLabel() + "Town " + args[5] + " not already surrendered, ignoring."); return true; } else { p.sendMessage(Helper.color("&cError: Town not found!")); @@ -1488,13 +1571,13 @@ public class AdminCommands implements CommandExecutor { for(Town t : n.getTowns()) { if (w.getSurrenderedTowns().contains(t.getName())) { w.unSurrenderTown(t.getName()); - p.sendMessage(Helper.Chatlabel() + "Un-surrendered town " + t.getName()); - Main.warLogger.log(Helper.Chatlabel() + "Un-surrendered town " + t.getName()); + p.sendMessage(Helper.chatLabel() + "Un-surrendered town " + t.getName()); + Main.warLogger.log(Helper.chatLabel() + "Un-surrendered town " + t.getName()); } } - p.sendMessage(Helper.Chatlabel() + "Un-surrendered nation " + args[5] + " in war " + args[3]); - Main.warLogger.log(Helper.Chatlabel() + "Un-surrendered nation " + args[5] + " in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Un-surrendered nation " + args[5] + " in war " + args[3]); + Main.warLogger.log(Helper.chatLabel() + "Un-surrendered nation " + args[5] + " in war " + args[3]); p.sendMessage(Helper.color("&cTo re-add, use: /alathrawaradmin modify war add, or have the nation loader join.")); return finalizeWar(w); } else { @@ -1528,22 +1611,22 @@ public class AdminCommands implements CommandExecutor { if (t != null) { if(w.getSide1Towns().contains(t.getName()) && w.getSide1().equals(args[4])) { w.surrenderTown(t.getName()); - p.sendMessage(Helper.Chatlabel() + "Forcefully surrendered town " + args[6] + " war " + args[3] + " on side " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Forcefully surrendered town " + args[6] + " war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Forcefully surrendered town " + args[6] + " war " + args[3] + " on side " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Forcefully surrendered town " + args[6] + " war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else if(w.getSide2Towns().contains(t.getName()) && w.getSide2().equals(args[4])) { w.surrenderTown(t.getName()); - p.sendMessage(Helper.Chatlabel() + "Forcefully surrendered town " + args[6] + " war " + args[3] + " on side " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Forcefully surrendered town " + args[6] + " war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Forcefully surrendered town " + args[6] + " war " + args[3] + " on side " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Forcefully surrendered town " + args[6] + " war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else { if (w.getSide1().equals(args[4]) || w.getSide2().equals(args[4])) { - p.sendMessage(Helper.Chatlabel() + "Town " + args[5] + " is not on either side of the war!"); - Main.warLogger.log(Helper.Chatlabel() + "Town " + args[5] + " is not on either side of the war!"); + p.sendMessage(Helper.chatLabel() + "Town " + args[5] + " is not on either side of the war!"); + Main.warLogger.log(Helper.chatLabel() + "Town " + args[5] + " is not on either side of the war!"); return true; } - p.sendMessage(Helper.Chatlabel() + "Town " + args[5] + " is on a side but side not correct! ERROR!"); - Main.warLogger.log(Helper.Chatlabel() + "Town " + args[5] + " is on a side but side not correct! ERROR!"); + p.sendMessage(Helper.chatLabel() + "Town " + args[5] + " is on a side but side not correct! ERROR!"); + Main.warLogger.log(Helper.chatLabel() + "Town " + args[5] + " is on a side but side not correct! ERROR!"); return true; } } else { @@ -1556,27 +1639,27 @@ public class AdminCommands implements CommandExecutor { for (Town t : n.getTowns()) { if(w.getSide1Towns().contains(t.getName()) && w.getSide1().equals(args[4])) { w.surrenderTown(t.getName()); - p.sendMessage(Helper.Chatlabel() + "Forcefully surrendered town " + t.getName() + " war " + args[3] + " on side " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Forcefully surrendered town " + t.getName() + " war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Forcefully surrendered town " + t.getName() + " war " + args[3] + " on side " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Forcefully surrendered town " + t.getName() + " war " + args[3] + " on side " + args[4]); } else if(w.getSide2Towns().contains(t.getName()) && w.getSide2().equals(args[4])) { w.surrenderTown(t.getName()); - p.sendMessage(Helper.Chatlabel() + "Forcefully surrendered town " + t.getName() + " war " + args[3] + " on side " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Forcefully surrendered town " + t.getName() + " war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Forcefully surrendered town " + t.getName() + " war " + args[3] + " on side " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Forcefully surrendered town " + t.getName() + " war " + args[3] + " on side " + args[4]); } else { if (w.getSide1().equals(args[4]) || w.getSide2().equals(args[4])) { - p.sendMessage(Helper.Chatlabel() + "Town " + t.getName() + " is not on either side of the war!"); - Main.warLogger.log(Helper.Chatlabel() + "Town " + t.getName() + " is not on either side of the war!"); + p.sendMessage(Helper.chatLabel() + "Town " + t.getName() + " is not on either side of the war!"); + Main.warLogger.log(Helper.chatLabel() + "Town " + t.getName() + " is not on either side of the war!"); return true; } - p.sendMessage(Helper.Chatlabel() + "Town " + t.getName() + " is on a side but side not correct! ERROR!"); - Main.warLogger.log(Helper.Chatlabel() + "Town " + t.getName() + " is on a side but side not correct! ERROR!"); + p.sendMessage(Helper.chatLabel() + "Town " + t.getName() + " is on a side but side not correct! ERROR!"); + Main.warLogger.log(Helper.chatLabel() + "Town " + t.getName() + " is on a side but side not correct! ERROR!"); return true; } } - p.sendMessage(Helper.Chatlabel() + "Surrendered nation " + args[6] + " war " + args[3] + " on side " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Surrendered nation " + args[6] + " war " + args[3] + " on side " + args[4]); + p.sendMessage(Helper.chatLabel() + "Surrendered nation " + args[6] + " war " + args[3] + " on side " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Surrendered nation " + args[6] + " war " + args[3] + " on side " + args[4]); return finalizeWar(w); } else { p.sendMessage(Helper.color("&cError: Nation not found!")); @@ -1601,13 +1684,13 @@ public class AdminCommands implements CommandExecutor { if (args.length >= 7) { if (args[6].equals(w.getSide1())) { w.setLastRaidTimeSide1(w.getLastRaidTimeSide1() + Integer.parseInt(args[5])); - p.sendMessage(Helper.Chatlabel() + "Added " + args[6] + " to last raid time in war " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Added " + args[6] + " to last raid time in war " + args[4]); + p.sendMessage(Helper.chatLabel() + "Added " + args[6] + " to last raid time in war " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Added " + args[6] + " to last raid time in war " + args[4]); return finalizeWar(w); } else if (args[6].equals(w.getSide2())) { w.setLastRaidTimeSide2(w.getLastRaidTimeSide2() + Integer.parseInt(args[5])); - p.sendMessage(Helper.Chatlabel() + "Added " + args[6] + " to last raid time in war " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Added " + args[6] + " to last raid time in war " + args[4]); + p.sendMessage(Helper.chatLabel() + "Added " + args[6] + " to last raid time in war " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Added " + args[6] + " to last raid time in war " + args[4]); return finalizeWar(w); } else { p.sendMessage(Helper.color("&cSide not found!")); @@ -1621,13 +1704,13 @@ public class AdminCommands implements CommandExecutor { if (args.length >= 7) { if (args[6].equals(w.getSide1())) { w.setLastRaidTimeSide1(Integer.parseInt(args[5])); - p.sendMessage(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]); - Main.warLogger.log(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set last raid time in war " + args[4] + " to " + args[6]); + Main.warLogger.log(Helper.chatLabel() + "Set last raid time in war " + args[4] + " to " + args[6]); return finalizeWar(w); } else if (args[6].equals(w.getSide2())) { w.setLastRaidTimeSide2(Integer.parseInt(args[5])); - p.sendMessage(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]); - Main.warLogger.log(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set last raid time in war " + args[4] + " to " + args[6]); + Main.warLogger.log(Helper.chatLabel() + "Set last raid time in war " + args[4] + " to " + args[6]); return finalizeWar(w); } else { p.sendMessage(Helper.color("&cSide not found!")); @@ -1642,13 +1725,13 @@ public class AdminCommands implements CommandExecutor { if (args.length >= 6) { if (args[5].equals(w.getSide1())) { w.setLastRaidTimeSide1(0); - p.sendMessage(Helper.Chatlabel() + "Reset last raid time in war " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Reset last raid time in war " + args[4]); + p.sendMessage(Helper.chatLabel() + "Reset last raid time in war " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Reset last raid time in war " + args[4]); return finalizeWar(w); } else if (args[5].equals(w.getSide2())) { w.setLastRaidTimeSide2(0); - p.sendMessage(Helper.Chatlabel() + "Reset last raid time in war " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Reset last raid time in war " + args[4]); + p.sendMessage(Helper.chatLabel() + "Reset last raid time in war " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Reset last raid time in war " + args[4]); return finalizeWar(w); } else { p.sendMessage(Helper.color("&cSide not found!")); @@ -1681,8 +1764,8 @@ public class AdminCommands implements CommandExecutor { } else { t.addMetaData(new LongDataField("lastRaided", Long.parseLong(args[6]))); } - p.sendMessage(Helper.Chatlabel() + "Added " + args[6] + " to last raid time in war " + args[3]); - Main.warLogger.log(Helper.Chatlabel() + "Added " + args[6] + " to last raid time in war " + args[3]); + p.sendMessage(Helper.chatLabel() + "Added " + args[6] + " to last raid time in war " + args[3]); + Main.warLogger.log(Helper.chatLabel() + "Added " + args[6] + " to last raid time in war " + args[3]); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify war raidTimeTown [add,set,reset] [town/war] [amt] [side]")); } @@ -1690,16 +1773,16 @@ public class AdminCommands implements CommandExecutor { } else if (args[3].equalsIgnoreCase("set")) { if (args.length >= 6) { t.addMetaData(new LongDataField("lastRaided", Long.parseLong(args[6]))); - p.sendMessage(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]); - Main.warLogger.log(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]); + p.sendMessage(Helper.chatLabel() + "Set last raid time in war " + args[4] + " to " + args[6]); + Main.warLogger.log(Helper.chatLabel() + "Set last raid time in war " + args[4] + " to " + args[6]); } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify war raidTimeTown [add,set,reset] [town/war] [amt] [side]")); } return true; } else if (args[3].equalsIgnoreCase("reset")) { t.addMetaData(new LongDataField("lastRaided", 0L)); - p.sendMessage(Helper.Chatlabel() + "Reset last raid time in town " + args[4]); - Main.warLogger.log(Helper.Chatlabel() + "Reset last raid time in war " + args[4]); + p.sendMessage(Helper.chatLabel() + "Reset last raid time in town " + args[4]); + Main.warLogger.log(Helper.chatLabel() + "Reset last raid time in war " + args[4]); return true; } else { p.sendMessage(Helper.color("&cUsage: /alathrawaradmin modify war raidTimeTown [add,set,reset] [town] [amt]")); @@ -1726,32 +1809,34 @@ public class AdminCommands implements CommandExecutor { return true; } - private static boolean awa(Player sender, String[] args) { + private static boolean awa(CommandSender sender, String[] args) { + if (args.length > 1) { Player p = Bukkit.getPlayer(args[1]); if (p == null) { - sender.sendMessage(Helper.Chatlabel() + Helper.color("&cPlayer not found!")); + sender.sendMessage(Helper.chatLabel() + Helper.color("&cPlayer not found!")); return true; } p.chat("awa awa! ^.^ UwU"); return true; } - sender.chat("awa awa! ^.^ UwU"); + if(sender instanceof Player) + ((Player) sender).chat("awa awa! ^.^ UwU"); return true; } - private static boolean fail(Player p, String[] args, String type) { + private static boolean fail(CommandSender p, String[] args, String type) { switch (type) { case "permissions" -> { - p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this.")); + p.sendMessage(String.valueOf(Helper.chatLabel()) + Helper.color("&cYou do not have permission to do this.")); return true; } case "syntax" -> { - p.sendMessage(Helper.Chatlabel() + "Invalid Arguments. /alathrawaradmin help"); + p.sendMessage(Helper.chatLabel() + "Invalid Arguments. /alathrawaradmin help"); return true; } default -> { - p.sendMessage(Helper.Chatlabel() + "Something wrong. /alathrawaradmin help"); + p.sendMessage(Helper.chatLabel() + "Something wrong. /alathrawaradmin help"); return true; } } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminTabCompletion.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminTabCompletion.java index c14573c..7547e1c 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminTabCompletion.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/AdminTabCompletion.java @@ -15,7 +15,12 @@ public class AdminTabCompletion implements TabCompleter { "force", "help", "info", - "modify" + "modify", + "purgebars", + "load", + "load-all", + "save", + "save-all" }); List 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" -> { diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java index d3a6aaa..1925a33 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/RaidCommands.java @@ -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 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 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 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"); } } } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/SiegeCommands.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/SiegeCommands.java index 1399406..910fdb2 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/SiegeCommands.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/SiegeCommands.java @@ -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 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 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"); } } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java b/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java index 0f8f275..b19d75e 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java @@ -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 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) { diff --git a/src/main/java/me/ShermansWorld/AlathraWar/data/RaidData.java b/src/main/java/me/ShermansWorld/AlathraWar/data/RaidData.java index dcdf0e1..79d7cfd 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/data/RaidData.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/data/RaidData.java @@ -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 raids = new ArrayList(); + + + public static ArrayList getRaids() { return raids; } + /** * Gets a raid with a specific name * diff --git a/src/main/java/me/ShermansWorld/AlathraWar/data/SiegeData.java b/src/main/java/me/ShermansWorld/AlathraWar/data/SiegeData.java index c8d9fe7..aac95c9 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/data/SiegeData.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/data/SiegeData.java @@ -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 diff --git a/src/main/java/me/ShermansWorld/AlathraWar/listeners/CommandsListener.java b/src/main/java/me/ShermansWorld/AlathraWar/listeners/CommandsListener.java index c15f846..ad3e73b 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/listeners/CommandsListener.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/listeners/CommandsListener.java @@ -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; } diff --git a/src/main/java/me/ShermansWorld/AlathraWar/listeners/KillsListener.java b/src/main/java/me/ShermansWorld/AlathraWar/listeners/KillsListener.java index a58fbda..d0f4f59 100644 --- a/src/main/java/me/ShermansWorld/AlathraWar/listeners/KillsListener.java +++ b/src/main/java/me/ShermansWorld/AlathraWar/listeners/KillsListener.java @@ -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); }