mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
Repair Raid from data changes, commands, and data switch
This commit is contained in:
1 parent
7eb677f8af
commit
b60a551914
3 files changed
+360
-353
No files matched your search
@@ -61,6 +61,7 @@ v/ Raiders on death are teleported to their town spawn.
|
||||
public class Raid {
|
||||
|
||||
private War war;
|
||||
private final String name;
|
||||
private Town raidedTown;
|
||||
private Town gatherTown;
|
||||
private String raiders;
|
||||
@@ -90,6 +91,9 @@ public class Raid {
|
||||
this.raidedTown = raidedTown;
|
||||
this.gatherTown = gatherTown;
|
||||
|
||||
//AttackSide-Town
|
||||
this.name = (side1AreRaiders ? war.getSide1() : war.getSide2()).toLowerCase() + "-" + raidedTown.getName().toLowerCase();
|
||||
|
||||
}
|
||||
|
||||
public Raid(final War war, final Town raidedTown, final Town gatherTown, final boolean side1AreRaiders, final int raidTicks, ArrayList<String> activeRaiders, RaidPhase phase) {
|
||||
@@ -106,7 +110,9 @@ public class Raid {
|
||||
this.war = war;
|
||||
this.raidTicks = 0;
|
||||
this.raidedTown = raidedTown;
|
||||
this.gatherTown = gatherTown;
|
||||
|
||||
//AttackSide-Town
|
||||
this.name = (side1AreRaiders ? war.getSide1() : war.getSide2()).toLowerCase() + "-" + raidedTown.getName().toLowerCase();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@@ -114,14 +120,6 @@ public class Raid {
|
||||
//start
|
||||
this.phase = RaidPhase.START;
|
||||
|
||||
// this.raidScore = Main.raidData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".raidscore");
|
||||
// this.side1AreRaiders = Main.raidData.getConfig()
|
||||
// .getBoolean("Raids." + String.valueOf(this.id) + ".side1areraiders");
|
||||
// this.side2AreRaiders = Main.raidData.getConfig()
|
||||
// .getBoolean("Raids." + String.valueOf(this.id) + ".side2areraiders");
|
||||
// this.raidTicks = Main.raidData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".raidticks");
|
||||
// this.owner = Bukkit.getPlayer(Main.raidData.getConfig().getString("Raids." + String.valueOf(this.id) + ".owner"));
|
||||
|
||||
if (this.side1AreRaiders) {
|
||||
this.raiderPlayers = this.war.getSide1Players();
|
||||
this.defenderPlayers = this.war.getSide2Players();
|
||||
@@ -525,6 +523,10 @@ public class Raid {
|
||||
if (raidScore < 0) this.raidScore = 0;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
public War getWar() {
|
||||
return this.war;
|
||||
@@ -550,6 +552,14 @@ public class Raid {
|
||||
this.gatherTown = town;
|
||||
}
|
||||
|
||||
public Player getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public void setOwner(Player owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getRaiders() {
|
||||
return this.raiders;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.*;
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -15,363 +17,357 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RaidCommands implements CommandExecutor
|
||||
{
|
||||
public static int maxID;
|
||||
|
||||
|
||||
public class RaidCommands implements CommandExecutor {
|
||||
public RaidCommands(final Main plugin) {
|
||||
//plugin.getCommand("raid").setExecutor((CommandExecutor)this);
|
||||
}
|
||||
|
||||
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) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
}
|
||||
else if (args.length == 1) {
|
||||
fail(p, args, "syntax");
|
||||
} else if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
if (RaidData.raids.isEmpty()) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no Raids in progress");
|
||||
return false;
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raids currently in progress:");
|
||||
for (final Raid raid : RaidCommands.raids) {
|
||||
p.sendMessage("Name: " + raid.getName());
|
||||
p.sendMessage("War: " + raid.getWar().getName());
|
||||
p.sendMessage("Raiding: " + raid.getRaidedTown().getName());
|
||||
p.sendMessage("Gathering In: " + raid.getGatherTown().getName());
|
||||
p.sendMessage("Raiders: " + raid.getRaiders());
|
||||
p.sendMessage("Defenders: " + raid.getDefenders());
|
||||
p.sendMessage("Raid Score: " + String.valueOf(raid.getRaidScore()));
|
||||
p.sendMessage("Raid Phase: " + raid.getPhase().name());
|
||||
p.sendMessage("Time Left: " + String.valueOf((RaidPhase.END.startTick - raid.getRaidTicks()) / 1200) + " minutes");
|
||||
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
|
||||
}
|
||||
listRaids(p, args);
|
||||
} else if (args[0].equalsIgnoreCase("help")) {
|
||||
if (p.hasPermission("!AlathraWar.admin")) {
|
||||
p.sendMessage(Helper.Chatlabel() + "/raid stop [id]");
|
||||
}
|
||||
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 [id]");
|
||||
p.sendMessage(Helper.Chatlabel() + "/raid list");
|
||||
raidHelp(p, args);
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
fail(p, args, "syntax");
|
||||
}
|
||||
|
||||
}
|
||||
else if (args.length == 2) {
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("stop")) {
|
||||
if (!p.hasPermission("AlathraWar.admin")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this"));
|
||||
return false;
|
||||
}
|
||||
if (RaidData.raids.isEmpty()) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no Raids in progress");
|
||||
return false;
|
||||
}
|
||||
boolean found = false;
|
||||
for (int i = 0; i < RaidData.raids.size(); ++i) {
|
||||
if (String.valueOf(RaidData.raids.get(i).getID()).equalsIgnoreCase(args[1])) {
|
||||
found = true;
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "raid cancelled");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of " + RaidData.raids.get(i).getRaidedTown().getName() + " has been cancelled by an admin");
|
||||
RaidData.raids.get(i).stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "A raid could not be found with this ID! Type /raid list to view current raids");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("abandon")) {
|
||||
boolean found2 = false;
|
||||
if (Main.raidData.getConfig().getString("Raids." + args[1] + ".owner") == null) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raid not found! Usage: /raid abandon [raid id]");
|
||||
return false;
|
||||
}
|
||||
final String configOwner = Main.raidData.getConfig().getString("Raids." + args[1] + ".owner");
|
||||
if (configOwner.equalsIgnoreCase(p.getName())) {
|
||||
for (int j = 0; j < RaidData.raids.size(); ++j) {
|
||||
if (String.valueOf(RaidCommands.raids.get(j).getID()).equalsIgnoreCase(args[1])) {
|
||||
found2 = true;
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid on " + RaidData.raids.get(j).getRaidedTown().getName() + " has been abandoned by " + RaidCommands.raids.get(j).getRaiders());
|
||||
Main.warLogger.log(p.getName() + " abandoned the raid on " + RaidData.raids.get(j).getRaidedTown().getName() + " they started at " + RaidCommands.raids.get(j).getGatherTown().getName());
|
||||
RaidData.raids.get(j).defendersWin(raids.get(j).getRaidScore());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found2) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Only the player who started the raid can abandon it");
|
||||
}
|
||||
stopRaid(p, args);
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
fail(p, args, "syntax");
|
||||
}
|
||||
}
|
||||
else if (args.length == 3) {
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
boolean warFound = false;
|
||||
boolean townExists = false;
|
||||
for (final War war : WarCommands.wars) {
|
||||
if (war.getName().equalsIgnoreCase(args[1])) {
|
||||
warFound = true;
|
||||
if (!war.getSide1Players().contains(p.getName()) && !war.getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
TownyWorld townyWorld;
|
||||
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
|
||||
if (!RaidCommands.towns.isEmpty()) {
|
||||
RaidCommands.towns.clear();
|
||||
}
|
||||
|
||||
for (final String entry : townyWorld.getTowns().keySet()) {
|
||||
final Town raidedTown = townyWorld.getTowns().get(entry);
|
||||
//takes the command runners town
|
||||
final Town gatherTown = TownyAPI.getInstance().getTown(p.getLocation());
|
||||
RaidCommands.towns.add(raidedTown);
|
||||
if (raidedTown.getName().equalsIgnoreCase(args[2]) && gatherTown != null) {
|
||||
townExists = true;
|
||||
boolean attackingOwnSide = false;
|
||||
++RaidCommands.maxID;
|
||||
Main.raidData.getConfig().set("MaxID", (Object)RaidCommands.maxID);
|
||||
Main.raidData.saveConfig();
|
||||
Raid raid2;
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
raid2 = new Raid(RaidCommands.maxID, war, raidedTown, gatherTown, war.getSide1(), war.getSide2(), true, false);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".war", (Object)war.getName());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".raidedTown", (Object)raidedTown.getName());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".gatherTown", (Object)gatherTown.getName());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".raiders", (Object)war.getSide1());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".activeRaiders", raid2.getActiveRaiders());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".defenders", (Object)war.getSide2());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".side1areraiders", (Object)true);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".side2areraiders", (Object)false);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".raidticks", (Object)0);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".raidScore", (Object)0);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".owner", (Object)p.getName());
|
||||
Main.raidData.saveConfig();
|
||||
}
|
||||
else {
|
||||
if (!war.getSide2Players().contains(p.getName())) {
|
||||
Bukkit.getLogger().info("Unable to find player declaring raid in the war");
|
||||
return false;
|
||||
}
|
||||
raid2 = new Raid(RaidCommands.maxID, war, raidedTown, gatherTown, war.getSide2(), war.getSide1(), false, true);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".war", (Object)war.getName());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".raidedTown", (Object)raidedTown.getName());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".gatherTown", (Object)gatherTown.getName());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".raiders", (Object)war.getSide2());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".defenders", (Object)war.getSide1());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".side1areraiders", (Object)false);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".side2areraiders", (Object)true);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".raidticks", (Object)0);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".raidScore", (Object)0);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".owner", (Object)p.getName());
|
||||
Main.raidData.saveConfig();
|
||||
}
|
||||
final ArrayList<String> residentNames = new ArrayList<String>();
|
||||
for (final Resident resident : raidedTown.getResidents()) {
|
||||
residentNames.add(resident.getName());
|
||||
}
|
||||
if (raid2.getSide1AreRaiders()) {
|
||||
for (final String playerName : war.getSide1Players()) {
|
||||
if (residentNames.contains(playerName)) {
|
||||
attackingOwnSide = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (final String playerName : war.getSide2Players()) {
|
||||
if (residentNames.contains(playerName)) {
|
||||
attackingOwnSide = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (attackingOwnSide) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot raid a town with members on your side of the war!");
|
||||
return false;
|
||||
}
|
||||
Town currentTown;
|
||||
try {
|
||||
currentTown = WorldCoord.parseWorldCoord(p.getLocation()).getTownBlock().getTown();
|
||||
}
|
||||
catch (NotRegisteredException e2) {
|
||||
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.");
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID), (Object)null);
|
||||
Main.raidData.saveConfig();
|
||||
return false;
|
||||
}
|
||||
if (!currentTown.equals(gatherTown)) {
|
||||
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.");
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID), (Object)null);
|
||||
Main.raidData.saveConfig();
|
||||
return false;
|
||||
}
|
||||
for (final Raid raidEntry : RaidCommands.raids) {
|
||||
if (raidEntry.getRaidedTown().getName().equalsIgnoreCase(raidedTown.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already under raid by your side!");
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID), (Object)null);
|
||||
Main.raidData.saveConfig();
|
||||
return false;
|
||||
}
|
||||
//TODO check when last raid was
|
||||
int valid = Main.raidData.isValidRaid(raidEntry.getRaidedTown());
|
||||
if (valid <= -1) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town has been raided too recently! (24 hour cooldown)");
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID), (Object)null);
|
||||
Main.raidData.saveConfig();
|
||||
return false;
|
||||
} else if (valid == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently! (6 hour cooldown)");
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID), (Object)null);
|
||||
Main.raidData.saveConfig();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUniqueId());
|
||||
if (Main.econ.getBalance(offlinePlayer) <= 2500.0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $2500 to put up to start a raid.");
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID), (Object)null);
|
||||
Main.raidData.saveConfig();
|
||||
return false;
|
||||
}
|
||||
Main.econ.withdrawPlayer(offlinePlayer, 2500);
|
||||
RaidCommands.raids.add(raid2);
|
||||
raid2.start();
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "As part of " + war.getName() + ", forces from " + raid2.getRaiders() + " are gathering to raid the town of " + raidedTown.getName() + "!");
|
||||
Main.warLogger.log(p.getName() + " started a raid.");
|
||||
Main.warLogger.log("As part of " + war.getName() + ", forces from " + raid2.getRaiders() + " are raiding the town of " + raidedTown.getName() + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!warFound) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /raid start [war] [town]");
|
||||
return false;
|
||||
}
|
||||
if (!townExists) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /raid start [war] [town]");
|
||||
}
|
||||
startRaid(p, args);
|
||||
} else if (args[0].equalsIgnoreCase("join")) {
|
||||
boolean warFound = false;
|
||||
boolean townExists = false;
|
||||
boolean raidFound = false;
|
||||
for (final War war : WarCommands.wars) {
|
||||
if (war.getName().equalsIgnoreCase(args[1])) {
|
||||
warFound = true;
|
||||
if (!war.getSide1Players().contains(p.getName()) && !war.getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
TownyWorld townyWorld;
|
||||
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
|
||||
if (!RaidCommands.towns.isEmpty()) {
|
||||
RaidCommands.towns.clear();
|
||||
}
|
||||
|
||||
//find the associated raid
|
||||
Raid raid = null;
|
||||
for(Raid r : raids) {
|
||||
if(r.getWar().getId() == war.getId()) {
|
||||
raidFound = true;
|
||||
raid = r;
|
||||
}
|
||||
}
|
||||
|
||||
//if we find the raid
|
||||
if(raidFound) {
|
||||
//check if gather phase
|
||||
if(raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
|
||||
try {
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if(cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
raid.addActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!warFound) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /raid start [war] [town]");
|
||||
return false;
|
||||
}
|
||||
if (!townExists) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /raid start [war] [town]");
|
||||
}
|
||||
if (!raidFound) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town!");
|
||||
return false;
|
||||
}
|
||||
joinRaid(p, args);
|
||||
} else if (args[0].equalsIgnoreCase("leave")) {
|
||||
boolean warFound = false;
|
||||
boolean townExists = false;
|
||||
boolean raidFound = false;
|
||||
for (final War war : WarCommands.wars) {
|
||||
if (war.getName().equalsIgnoreCase(args[1])) {
|
||||
warFound = true;
|
||||
if (!war.getSide1Players().contains(p.getName()) && !war.getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
TownyWorld townyWorld;
|
||||
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
|
||||
if (!RaidCommands.towns.isEmpty()) {
|
||||
RaidCommands.towns.clear();
|
||||
}
|
||||
|
||||
//find the associated raid
|
||||
Raid raid = null;
|
||||
for(Raid r : raids) {
|
||||
if(r.getWar().getId() == war.getId()) {
|
||||
raidFound = true;
|
||||
raid = r;
|
||||
}
|
||||
}
|
||||
|
||||
//if we find the raid
|
||||
if(raidFound) {
|
||||
//check if gather phase
|
||||
if(raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
|
||||
if(raid.getGatherTown().hasTownBlock(WorldCoord.parseWorldCoord(p))) {
|
||||
raid.removeActiveRaider(p.getName());
|
||||
p.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 (!warFound) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /raid start [war] [town]");
|
||||
return false;
|
||||
}
|
||||
if (!townExists) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /raid start [war] [town]");
|
||||
}
|
||||
if (!raidFound) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town!");
|
||||
return false;
|
||||
}
|
||||
leaveRaid(p, args);
|
||||
} else if (args[0].equalsIgnoreCase("abandon")) {
|
||||
abandonRaid(p, args);
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
fail(p, args, "syntax");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
} else {
|
||||
fail(p, args, "syntax");
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* //TODO FIXUP
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
private static void startRaid(Player p, String[] args) {
|
||||
boolean warFound = false;
|
||||
boolean townExists = false;
|
||||
for (final War war : WarData.getWars()) {
|
||||
if (war.getName().equalsIgnoreCase(args[1])) {
|
||||
warFound = true;
|
||||
if (!war.getSide1Players().contains(p.getName()) && !war.getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
TownyWorld townyWorld;
|
||||
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
|
||||
|
||||
final Town gatherTown = TownyAPI.getInstance().getTown(p.getLocation());
|
||||
|
||||
for (final String entry : townyWorld.getTowns().keySet()) {
|
||||
final Town raidedTown = townyWorld.getTowns().get(entry);
|
||||
|
||||
//takes the command runners town
|
||||
|
||||
if (raidedTown.getName().equalsIgnoreCase(args[2]) && gatherTown != null) {
|
||||
townExists = true;
|
||||
boolean attackingOwnSide = false;
|
||||
Raid raid2;
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
int c = RaidData.isValidRaid(war, raidedTown);
|
||||
if (c == 1) {
|
||||
raid2 = new Raid(war, raidedTown, gatherTown, true);
|
||||
} else if (c == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!");
|
||||
return;
|
||||
} else if (c == -1) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Thi town was raided too recently!");
|
||||
return;
|
||||
} else if (c == 2) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
} else {
|
||||
if (!war.getSide2Players().contains(p.getName())) {
|
||||
Bukkit.getLogger().info("Unable to find player declaring raid in the war");
|
||||
return;
|
||||
}
|
||||
int c = RaidData.isValidRaid(war, raidedTown);
|
||||
if (c == 1) {
|
||||
raid2 = new Raid(war, raidedTown, gatherTown, false);
|
||||
} else if (c == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!");
|
||||
return;
|
||||
} else if (c == -1) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Thi town was raided too recently!");
|
||||
return;
|
||||
} else if (c == 2) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
final ArrayList<String> residentNames = new ArrayList<String>();
|
||||
for (final Resident resident : raidedTown.getResidents()) {
|
||||
residentNames.add(resident.getName());
|
||||
}
|
||||
|
||||
if (raid2.getSide1AreRaiders()) {
|
||||
for (final String playerName : war.getSide1Players()) {
|
||||
if (residentNames.contains(playerName)) {
|
||||
attackingOwnSide = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (final String playerName : war.getSide2Players()) {
|
||||
if (residentNames.contains(playerName)) {
|
||||
attackingOwnSide = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (attackingOwnSide) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot raid a town with members on your side of the war!");
|
||||
return;
|
||||
}
|
||||
|
||||
Town currentTown;
|
||||
try {
|
||||
currentTown = WorldCoord.parseWorldCoord(p.getLocation()).getTownBlock().getTown();
|
||||
} catch (NotRegisteredException e2) {
|
||||
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.");
|
||||
return;
|
||||
}
|
||||
if (!currentTown.equals(gatherTown)) {
|
||||
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.");
|
||||
return;
|
||||
}
|
||||
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUniqueId());
|
||||
if (Main.econ.getBalance(offlinePlayer) <= 2500.0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $2500 to put up to start a raid.");
|
||||
return;
|
||||
}
|
||||
Main.econ.withdrawPlayer(offlinePlayer, 2500);
|
||||
RaidData.addRaid(raid2);
|
||||
raid2.start();
|
||||
WarData.saveWar(raid2.getWar());
|
||||
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "As part of " + war.getName() + ", forces from " + raid2.getRaiders() + " are gathering to raid the town of " + raidedTown.getName() + "!");
|
||||
Main.warLogger.log(p.getName() + " started a raid.");
|
||||
Main.warLogger.log("As part of " + war.getName() + ", forces from " + raid2.getRaiders() + " are raiding the town of " + raidedTown.getName() + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!warFound) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /raid start [war] [town]");
|
||||
return;
|
||||
}
|
||||
if (!townExists) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /raid start [war] [town]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stopes the current raid by admins
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
private static void stopRaid(Player p, String[] args) {
|
||||
if (!p.hasPermission("AlathraWar.admin")) {
|
||||
fail(p, args, "permission");
|
||||
return;
|
||||
}
|
||||
if (RaidData.getRaids().isEmpty()) {
|
||||
fail(p, args, "noRaids");
|
||||
return;
|
||||
}
|
||||
boolean found = false;
|
||||
|
||||
Raid raid = RaidData.getRaidOrNull(args[1]);
|
||||
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");
|
||||
raid.stop();
|
||||
} else {
|
||||
fail(p, args, "badName");
|
||||
}
|
||||
}
|
||||
|
||||
private static void joinRaid(Player p, String[] args) {
|
||||
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]");
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
|
||||
try {
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
raid.addActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
|
||||
} else {
|
||||
p.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 {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town or this town does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void leaveRaid(Player p, String[] args) {
|
||||
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]");
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
|
||||
try {
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
raid.removeActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
|
||||
} else {
|
||||
p.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town or this town does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abandons the raid
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
private static void abandonRaid(Player p, String[] args) {
|
||||
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 (!raid.getOwner().getName().equals(p.getName())) {
|
||||
//check if gather phase
|
||||
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.COMBAT) {
|
||||
if (raid.getGatherTown().hasTownBlock(WorldCoord.parseWorldCoord(p))) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid on " + raid.getRaidedTown().getName() + " has been abandoned by " + raid.getRaiders());
|
||||
Main.warLogger.log(p.getName() + " abandoned the raid on " + raid.getRaidedTown().getName() + " they started at " + raid.getGatherTown().getName());
|
||||
raid.defendersWin(raid.getRaidScore());
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot abandon the raid on " + raid.getRaidedTown().getName() + "! It has a problem!");
|
||||
}
|
||||
} else {
|
||||
fail(p, args, "owner");
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This raid does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void listRaids(Player p, String[] args) {
|
||||
if (RaidData.getRaids().isEmpty()) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no Raids in progress");
|
||||
return;
|
||||
}
|
||||
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());
|
||||
p.sendMessage("Owner: " + raid.getOwner().getName());
|
||||
p.sendMessage("Raiding: " + raid.getRaidedTown().getName());
|
||||
p.sendMessage("Gathering In: " + raid.getGatherTown().getName());
|
||||
p.sendMessage("Raiders: " + raid.getRaiders());
|
||||
p.sendMessage("Defenders: " + raid.getDefenders());
|
||||
p.sendMessage("Raid Score: " + String.valueOf(raid.getRaidScore()));
|
||||
p.sendMessage("Raid Phase: " + raid.getPhase().name());
|
||||
p.sendMessage("Time Left: " + String.valueOf((RaidPhase.END.startTick - raid.getRaidTicks()) / 1200) + " minutes");
|
||||
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
|
||||
}
|
||||
}
|
||||
|
||||
private static void raidHelp(Player p, String[] args) {
|
||||
if (p.hasPermission("!AlathraWar.admin")) {
|
||||
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");
|
||||
}
|
||||
|
||||
private static void fail(Player 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"));
|
||||
return;
|
||||
}
|
||||
case "syntax": {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
return;
|
||||
}
|
||||
case "noRaids": {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no Raids in progress");
|
||||
return;
|
||||
}
|
||||
case "badName": {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "A raid could not be found with this Name! Type /raid list to view current raids");
|
||||
return;
|
||||
}
|
||||
case "owner": {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Only the player who started the raid can abandon it.");
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,9 @@ public class RaidData {
|
||||
* @param name - Name to check
|
||||
* @return Raid or Null
|
||||
*/
|
||||
public static Raid getRaid(String name) {
|
||||
public static Raid getRaidOrNull(String name) {
|
||||
for (Raid raid : raids) {
|
||||
|
||||
if(raid.getName().equals(name)) return raid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -114,6 +114,7 @@ public class RaidData {
|
||||
public static HashMap<String, Object> raidToMap(Raid raid) {
|
||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||
// Shoves everything into a map.
|
||||
returnMap.put("name", raid.getName());
|
||||
returnMap.put("raidedTown", raid.getRaidedTown());
|
||||
returnMap.put("gatherTown", raid.getRaidedTown());
|
||||
returnMap.put("raidTicks", raid.getRaidTicks());
|
||||
@@ -144,18 +145,18 @@ public class RaidData {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int whenTownLastRaided() {
|
||||
public static int whenTownLastRaided() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO raid validity check
|
||||
/**
|
||||
* @Isaac this is for getting if a town can be raided, return (-1, 0, 1) based on status
|
||||
* (24 hours town cooldown, 6 hour nation cooldown, valid time to raid)
|
||||
* @Isaac this is for getting if a town can be raided, return (-1, 0, 1, 2) based on status
|
||||
* (24 hours town cooldown, 6 hour nation cooldown, valid time to raid, town being raided already)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int isValidRaid(Town t) {
|
||||
public static int isValidRaid(War war, Town town) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user