mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-03 22:15:24 +00:00
Fixups after the reckoning (INCOMPLETE)
This commit is contained in:
1 parent
840ea44ebc
commit
7eb677f8af
6 files changed
+201
-126
No files matched your search
@@ -5,6 +5,7 @@ import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
|||||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||||
import com.palmergames.bukkit.towny.object.*;
|
import com.palmergames.bukkit.towny.object.*;
|
||||||
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
||||||
|
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -13,6 +14,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/* RAID EXPLANATION
|
/* RAID EXPLANATION
|
||||||
@@ -50,7 +52,7 @@ v/ Raiders on death are teleported to their town spawn.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is based on the existing Siege Class
|
* Implementation of Raids for alathrawar
|
||||||
*
|
*
|
||||||
* @author AubriTheHuman
|
* @author AubriTheHuman
|
||||||
* @author NinjaMandalorian
|
* @author NinjaMandalorian
|
||||||
@@ -64,8 +66,6 @@ public class Raid {
|
|||||||
private String raiders;
|
private String raiders;
|
||||||
private String defenders;
|
private String defenders;
|
||||||
private boolean side1AreRaiders;
|
private boolean side1AreRaiders;
|
||||||
private boolean side2AreRaiders;
|
|
||||||
private int id;
|
|
||||||
private int raidScore;
|
private int raidScore;
|
||||||
private Player owner;
|
private Player owner;
|
||||||
private int raidTicks;
|
private int raidTicks;
|
||||||
@@ -75,39 +75,52 @@ public class Raid {
|
|||||||
private Location townSpawnRaided;
|
private Location townSpawnRaided;
|
||||||
private Location townSpawnGather;
|
private Location townSpawnGather;
|
||||||
int[] bukkitId;
|
int[] bukkitId;
|
||||||
|
public ArrayList<String> activeRaiders;
|
||||||
public ArrayList<String> raiderPlayers;
|
public ArrayList<String> raiderPlayers;
|
||||||
public ArrayList<String> defenderPlayers;
|
public ArrayList<String> defenderPlayers;
|
||||||
public ArrayList<String> activeRaiders;
|
|
||||||
|
|
||||||
// Constructs raid for staging phase
|
// Constructs raid for staging phase
|
||||||
public Raid(final int id, final War war, final Town raidedTown, final Town gatherTown, final String raiders, final String defenders,
|
public Raid(final War war, final Town raidedTown, final Town gatherTown,
|
||||||
final boolean side1AreRaiders, final boolean side2AreRaiders) {
|
final boolean side1AreRaiders, final int raidTicks) {
|
||||||
|
|
||||||
this.raidTicks = 0;
|
|
||||||
this.bukkitId = new int[1];
|
this.bukkitId = new int[1];
|
||||||
this.raiderPlayers = new ArrayList<String>();
|
this.activeRaiders = activeRaiders == null ? new ArrayList<>() : activeRaiders;
|
||||||
this.defenderPlayers = new ArrayList<String>();
|
|
||||||
this.activeRaiders = new ArrayList<String>();
|
|
||||||
this.war = war;
|
this.war = war;
|
||||||
|
this.raidTicks = raidTicks;
|
||||||
this.raidedTown = raidedTown;
|
this.raidedTown = raidedTown;
|
||||||
this.gatherTown = gatherTown;
|
this.gatherTown = gatherTown;
|
||||||
this.raiders = raiders;
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Raid(final War war, final Town raidedTown, final Town gatherTown, final boolean side1AreRaiders, final int raidTicks, ArrayList<String> activeRaiders, RaidPhase phase) {
|
||||||
|
this(war, raidedTown, gatherTown, side1AreRaiders, raidTicks);
|
||||||
|
this.activeRaiders = activeRaiders;
|
||||||
|
this.setRaidPhase(phase);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Raid(final War war, final Town raidedTown, final Town gatherTown,
|
||||||
|
final boolean side1AreRaiders) {
|
||||||
|
this.bukkitId = new int[1];
|
||||||
|
this.activeRaiders = activeRaiders == null ? new ArrayList<>() : activeRaiders;
|
||||||
|
this.war = war;
|
||||||
|
this.raidTicks = 0;
|
||||||
|
this.raidedTown = raidedTown;
|
||||||
|
this.gatherTown = gatherTown;
|
||||||
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
|
|
||||||
//start
|
//start
|
||||||
this.phase = RaidPhase.START;
|
this.phase = RaidPhase.START;
|
||||||
|
|
||||||
this.raidScore = Main.siegeData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".raidscore");
|
// this.raidScore = Main.raidData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".raidscore");
|
||||||
this.side1AreRaiders = Main.siegeData.getConfig()
|
// this.side1AreRaiders = Main.raidData.getConfig()
|
||||||
.getBoolean("Raids." + String.valueOf(this.id) + ".side1areraiders");
|
// .getBoolean("Raids." + String.valueOf(this.id) + ".side1areraiders");
|
||||||
this.side2AreRaiders = Main.siegeData.getConfig()
|
// this.side2AreRaiders = Main.raidData.getConfig()
|
||||||
.getBoolean("Raids." + String.valueOf(this.id) + ".side2areraiders");
|
// .getBoolean("Raids." + String.valueOf(this.id) + ".side2areraiders");
|
||||||
this.raidTicks = Main.siegeData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".raidticks");
|
// this.raidTicks = Main.raidData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".raidticks");
|
||||||
this.owner = Bukkit.getPlayer(Main.siegeData.getConfig().getString("Raids." + String.valueOf(this.id) + ".owner"));
|
// this.owner = Bukkit.getPlayer(Main.raidData.getConfig().getString("Raids." + String.valueOf(this.id) + ".owner"));
|
||||||
|
|
||||||
if (this.side1AreRaiders) {
|
if (this.side1AreRaiders) {
|
||||||
this.raiderPlayers = this.war.getSide1Players();
|
this.raiderPlayers = this.war.getSide1Players();
|
||||||
@@ -159,12 +172,7 @@ public class Raid {
|
|||||||
Raid.this.defendersWin(Raid.this.raidScore);
|
Raid.this.defendersWin(Raid.this.raidScore);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final Raid this$0 = Raid.this;
|
raidTicks += 200;
|
||||||
Raid.access$7(this$0, this$0.raidTicks + 200);
|
|
||||||
Main.raidData.getConfig().set("Raids." + String.valueOf(Raid.this.id) + ".raidticks",
|
|
||||||
(Object) Raid.this.raidTicks);
|
|
||||||
Main.raidData.saveConfig();
|
|
||||||
|
|
||||||
|
|
||||||
//check and start travel phase
|
//check and start travel phase
|
||||||
if (Raid.this.raidTicks >= RaidPhase.TRAVEL.startTick && Raid.this.phase != RaidPhase.TRAVEL) {
|
if (Raid.this.raidTicks >= RaidPhase.TRAVEL.startTick && Raid.this.phase != RaidPhase.TRAVEL) {
|
||||||
@@ -176,7 +184,6 @@ public class Raid {
|
|||||||
startCombat();
|
startCombat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Raid start phase behavior
|
//Raid start phase behavior
|
||||||
if (Raid.this.phase == RaidPhase.GATHER) {
|
if (Raid.this.phase == RaidPhase.GATHER) {
|
||||||
//Broadcast
|
//Broadcast
|
||||||
@@ -244,13 +251,18 @@ public class Raid {
|
|||||||
}, 0L, 200L);
|
}, 0L, 200L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resumes a Raid (after a server restart e.t.c.)
|
||||||
|
*/
|
||||||
|
public void resume() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// End of raid
|
// End of raid
|
||||||
public void stop() {
|
public void stop() {
|
||||||
this.phase = RaidPhase.END;
|
this.phase = RaidPhase.END;
|
||||||
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
|
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
|
||||||
RaidCommands.raids.remove(this);
|
RaidData.removeRaid(this);
|
||||||
Main.raidData.getConfig().set("Raids." + String.valueOf(this.id), (Object) null);
|
|
||||||
Main.raidData.saveConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -296,14 +308,14 @@ public class Raid {
|
|||||||
for (final String playerName : this.getActiveRaiders()) {
|
for (final String playerName : this.getActiveRaiders()) {
|
||||||
try {
|
try {
|
||||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score");
|
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score");
|
||||||
|
} catch (NullPointerException ex3) {
|
||||||
}
|
}
|
||||||
catch (NullPointerException ex3) {}
|
|
||||||
}
|
}
|
||||||
for (final String playerName : this.getDefenderPlayers()) {
|
for (final String playerName : this.getDefenderPlayers()) {
|
||||||
try {
|
try {
|
||||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -20 Raid Score");
|
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -20 Raid Score");
|
||||||
|
} catch (NullPointerException ex4) {
|
||||||
}
|
}
|
||||||
catch (NullPointerException ex4) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//tp to gather town spawn
|
//tp to gather town spawn
|
||||||
@@ -326,14 +338,14 @@ public class Raid {
|
|||||||
for (final String playerName : this.getActiveRaiders()) {
|
for (final String playerName : this.getActiveRaiders()) {
|
||||||
try {
|
try {
|
||||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
|
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
|
||||||
|
} catch (NullPointerException ex5) {
|
||||||
}
|
}
|
||||||
catch (NullPointerException ex5) {}
|
|
||||||
}
|
}
|
||||||
for (final String playerName : this.getDefenderPlayers()) {
|
for (final String playerName : this.getDefenderPlayers()) {
|
||||||
try {
|
try {
|
||||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
|
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
|
||||||
|
} catch (NullPointerException ex6) {
|
||||||
}
|
}
|
||||||
catch (NullPointerException ex6) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//tp to raid town spawn
|
//tp to raid town spawn
|
||||||
@@ -353,14 +365,14 @@ public class Raid {
|
|||||||
for (final String playerName : this.getActiveRaiders()) {
|
for (final String playerName : this.getActiveRaiders()) {
|
||||||
try {
|
try {
|
||||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
|
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
|
||||||
|
} catch (NullPointerException ex3) {
|
||||||
}
|
}
|
||||||
catch (NullPointerException ex3) {}
|
|
||||||
}
|
}
|
||||||
for (final String playerName : this.getDefenderPlayers()) {
|
for (final String playerName : this.getDefenderPlayers()) {
|
||||||
try {
|
try {
|
||||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
|
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
|
||||||
|
} catch (NullPointerException ex4) {
|
||||||
}
|
}
|
||||||
catch (NullPointerException ex4) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//tp to gather town spawn
|
//tp to gather town spawn
|
||||||
@@ -382,14 +394,14 @@ public class Raid {
|
|||||||
for (final String playerName : this.getActiveRaiders()) {
|
for (final String playerName : this.getActiveRaiders()) {
|
||||||
try {
|
try {
|
||||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
|
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
|
||||||
|
} catch (NullPointerException ex5) {
|
||||||
}
|
}
|
||||||
catch (NullPointerException ex5) {}
|
|
||||||
}
|
}
|
||||||
for (final String playerName : this.getDefenderPlayers()) {
|
for (final String playerName : this.getDefenderPlayers()) {
|
||||||
try {
|
try {
|
||||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
|
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
|
||||||
|
} catch (NullPointerException ex6) {
|
||||||
}
|
}
|
||||||
catch (NullPointerException ex6) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//tp to raid town spawn
|
//tp to raid town spawn
|
||||||
@@ -514,14 +526,6 @@ public class Raid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getID() {
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setID(final int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public War getWar() {
|
public War getWar() {
|
||||||
return this.war;
|
return this.war;
|
||||||
}
|
}
|
||||||
@@ -578,14 +582,6 @@ public class Raid {
|
|||||||
this.side1AreRaiders = side1AreRaiders;
|
this.side1AreRaiders = side1AreRaiders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getSide2AreRaiders() {
|
|
||||||
return this.side2AreRaiders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSide2AreRaiders(final boolean side2AreRaiders) {
|
|
||||||
this.side2AreRaiders = side2AreRaiders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getRaiderPlayers() {
|
public ArrayList<String> getRaiderPlayers() {
|
||||||
return this.raiderPlayers;
|
return this.raiderPlayers;
|
||||||
}
|
}
|
||||||
@@ -602,6 +598,12 @@ public class Raid {
|
|||||||
this.defenderPlayers = defenderPlayers;
|
this.defenderPlayers = defenderPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRaidTicks() {
|
||||||
|
return this.raidTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRaidTicks(int ticks) { this.raidTicks = ticks; }
|
||||||
|
|
||||||
static /* synthetic */ void access$7(final Raid raid, final int raidTicks) {
|
static /* synthetic */ void access$7(final Raid raid, final int raidTicks) {
|
||||||
raid.raidTicks = raidTicks;
|
raid.raidTicks = raidTicks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,33 +17,27 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class RaidCommands implements CommandExecutor
|
public class RaidCommands implements CommandExecutor
|
||||||
{
|
{
|
||||||
public static ArrayList<Town> towns;
|
|
||||||
public static ArrayList<Raid> raids;
|
|
||||||
public static int maxID;
|
public static int maxID;
|
||||||
|
|
||||||
static {
|
|
||||||
RaidCommands.towns = new ArrayList<Town>();
|
|
||||||
RaidCommands.raids = new ArrayList<Raid>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RaidCommands(final Main plugin) {
|
public RaidCommands(final Main plugin) {
|
||||||
//plugin.getCommand("raid").setExecutor((CommandExecutor)this);
|
//plugin.getCommand("raid").setExecutor((CommandExecutor)this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||||
/*final Player p = (Player)sender;
|
final Player p = (Player)sender;
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||||
}
|
}
|
||||||
else if (args.length == 1) {
|
else if (args.length == 1) {
|
||||||
if (args[0].equalsIgnoreCase("list")) {
|
if (args[0].equalsIgnoreCase("list")) {
|
||||||
if (RaidCommands.raids.isEmpty()) {
|
if (RaidData.raids.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 false;
|
return false;
|
||||||
}
|
}
|
||||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raids currently in progress:");
|
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raids currently in progress:");
|
||||||
for (final Raid raid : RaidCommands.raids) {
|
for (final Raid raid : RaidCommands.raids) {
|
||||||
p.sendMessage("ID: " + String.valueOf(raid.getID()));
|
p.sendMessage("Name: " + raid.getName());
|
||||||
p.sendMessage("War: " + raid.getWar().getName());
|
p.sendMessage("War: " + raid.getWar().getName());
|
||||||
p.sendMessage("Raiding: " + raid.getRaidedTown().getName());
|
p.sendMessage("Raiding: " + raid.getRaidedTown().getName());
|
||||||
p.sendMessage("Gathering In: " + raid.getGatherTown().getName());
|
p.sendMessage("Gathering In: " + raid.getGatherTown().getName());
|
||||||
@@ -51,7 +45,7 @@ public class RaidCommands implements CommandExecutor
|
|||||||
p.sendMessage("Defenders: " + raid.getDefenders());
|
p.sendMessage("Defenders: " + raid.getDefenders());
|
||||||
p.sendMessage("Raid Score: " + String.valueOf(raid.getRaidScore()));
|
p.sendMessage("Raid Score: " + String.valueOf(raid.getRaidScore()));
|
||||||
p.sendMessage("Raid Phase: " + raid.getPhase().name());
|
p.sendMessage("Raid Phase: " + raid.getPhase().name());
|
||||||
p.sendMessage("Time Left: " + String.valueOf((72000 - Main.raidData.getConfig().getInt("Raids." + String.valueOf(String.valueOf(raid.getID()) + ".raidticks"))) / 1200) + " minutes");
|
p.sendMessage("Time Left: " + String.valueOf((RaidPhase.END.startTick - raid.getRaidTicks()) / 1200) + " minutes");
|
||||||
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
|
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
|
||||||
}
|
}
|
||||||
} else if (args[0].equalsIgnoreCase("help")) {
|
} else if (args[0].equalsIgnoreCase("help")) {
|
||||||
@@ -74,17 +68,17 @@ public class RaidCommands implements CommandExecutor
|
|||||||
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 false;
|
return false;
|
||||||
}
|
}
|
||||||
if (RaidCommands.raids.isEmpty()) {
|
if (RaidData.raids.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 false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (int i = 0; i < RaidCommands.raids.size(); ++i) {
|
for (int i = 0; i < RaidData.raids.size(); ++i) {
|
||||||
if (String.valueOf(RaidCommands.raids.get(i).getID()).equalsIgnoreCase(args[1])) {
|
if (String.valueOf(RaidData.raids.get(i).getID()).equalsIgnoreCase(args[1])) {
|
||||||
found = true;
|
found = true;
|
||||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "raid cancelled");
|
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "raid cancelled");
|
||||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of " + RaidCommands.raids.get(i).getRaidedTown().getName() + " has been cancelled by an admin");
|
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of " + RaidData.raids.get(i).getRaidedTown().getName() + " has been cancelled by an admin");
|
||||||
RaidCommands.raids.get(i).stop();
|
RaidData.raids.get(i).stop();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,12 +95,12 @@ public class RaidCommands implements CommandExecutor
|
|||||||
}
|
}
|
||||||
final String configOwner = Main.raidData.getConfig().getString("Raids." + args[1] + ".owner");
|
final String configOwner = Main.raidData.getConfig().getString("Raids." + args[1] + ".owner");
|
||||||
if (configOwner.equalsIgnoreCase(p.getName())) {
|
if (configOwner.equalsIgnoreCase(p.getName())) {
|
||||||
for (int j = 0; j < RaidCommands.raids.size(); ++j) {
|
for (int j = 0; j < RaidData.raids.size(); ++j) {
|
||||||
if (String.valueOf(RaidCommands.raids.get(j).getID()).equalsIgnoreCase(args[1])) {
|
if (String.valueOf(RaidCommands.raids.get(j).getID()).equalsIgnoreCase(args[1])) {
|
||||||
found2 = true;
|
found2 = true;
|
||||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid on " + RaidCommands.raids.get(j).getRaidedTown().getName() + " has been abandoned by " + RaidCommands.raids.get(j).getRaiders());
|
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 " + RaidCommands.raids.get(j).getRaidedTown().getName() + " they started at " + RaidCommands.raids.get(j).getGatherTown().getName());
|
Main.warLogger.log(p.getName() + " abandoned the raid on " + RaidData.raids.get(j).getRaidedTown().getName() + " they started at " + RaidCommands.raids.get(j).getGatherTown().getName());
|
||||||
RaidCommands.raids.get(j).defendersWin(raids.get(j).getRaidScore());
|
RaidData.raids.get(j).defendersWin(raids.get(j).getRaidScore());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,7 +119,7 @@ public class RaidCommands implements CommandExecutor
|
|||||||
for (final War war : WarCommands.wars) {
|
for (final War war : WarCommands.wars) {
|
||||||
if (war.getName().equalsIgnoreCase(args[1])) {
|
if (war.getName().equalsIgnoreCase(args[1])) {
|
||||||
warFound = true;
|
warFound = true;
|
||||||
/*if (!war.getSide1Players().contains(p.getName()) && !war.getSide2Players().contains(p.getName())) {
|
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]");
|
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||||
}
|
}
|
||||||
TownyWorld townyWorld;
|
TownyWorld townyWorld;
|
||||||
@@ -376,7 +370,7 @@ public class RaidCommands implements CommandExecutor
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||||
}*/
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.palmergames.bukkit.towny.TownyAPI;
|
|||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import me.ShermansWorld.AlathraWar.Raid;
|
import me.ShermansWorld.AlathraWar.Raid;
|
||||||
import me.ShermansWorld.AlathraWar.War;
|
import me.ShermansWorld.AlathraWar.War;
|
||||||
|
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||||
|
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
@@ -32,29 +34,29 @@ public class RaidTabCompletion implements TabCompleter {
|
|||||||
return completions;
|
return completions;
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
if (args[0].equalsIgnoreCase("start")) {
|
if (args[0].equalsIgnoreCase("start")) {
|
||||||
if (!WarCommands.wars.isEmpty()) {
|
if (!WarData.getWars().isEmpty()) {
|
||||||
for (War war : WarCommands.wars) {
|
for (War war : WarData.getWars()) {
|
||||||
completions.add(war.getName());
|
completions.add(war.getName());
|
||||||
}
|
}
|
||||||
return completions;
|
return completions;
|
||||||
}
|
}
|
||||||
} else if (args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("abandon")) {
|
} else if (args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("abandon")) {
|
||||||
if (!RaidCommands.raids.isEmpty()) {
|
if (!RaidData.getRaids().isEmpty()) {
|
||||||
for (Raid raid : RaidCommands.raids) {
|
for (Raid raid : RaidCommands.raids) {
|
||||||
completions.add(String.valueOf(raid.getID()));
|
completions.add(String.valueOf(raid.getID()));
|
||||||
}
|
}
|
||||||
return completions;
|
return completions;
|
||||||
}
|
}
|
||||||
} else if (args[0].equalsIgnoreCase("join")) {
|
} else if (args[0].equalsIgnoreCase("join")) {
|
||||||
if (!WarCommands.wars.isEmpty()) {
|
if (!WarData.getWars().isEmpty()) {
|
||||||
for (War war : WarCommands.wars) {
|
for (War war : WarData.getWars()) {
|
||||||
completions.add(war.getName());
|
completions.add(war.getName());
|
||||||
}
|
}
|
||||||
return completions;
|
return completions;
|
||||||
}
|
}
|
||||||
} else if (args[0].equalsIgnoreCase("leave")) {
|
} else if (args[0].equalsIgnoreCase("leave")) {
|
||||||
if (!WarCommands.wars.isEmpty()) {
|
if (!WarData.getWars().isEmpty()) {
|
||||||
for (War war : WarCommands.wars) {
|
for (War war : WarData.getWars()) {
|
||||||
completions.add(war.getName());
|
completions.add(war.getName());
|
||||||
}
|
}
|
||||||
return completions;
|
return completions;
|
||||||
|
|||||||
@@ -1,65 +1,141 @@
|
|||||||
package me.ShermansWorld.AlathraWar.data;
|
package me.ShermansWorld.AlathraWar.data;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.TownyAPI;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import me.ShermansWorld.AlathraWar.Main;
|
import me.ShermansWorld.AlathraWar.Main;
|
||||||
|
import me.ShermansWorld.AlathraWar.Raid;
|
||||||
import me.ShermansWorld.AlathraWar.War;
|
import me.ShermansWorld.AlathraWar.War;
|
||||||
|
|
||||||
import org.bukkit.configuration.Configuration;
|
import java.io.File;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import java.io.FilenameFilter;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class RaidData {
|
public class RaidData {
|
||||||
private Main plugin;
|
// Static Raid list for all active raids
|
||||||
private FileConfiguration dataConfig;
|
private static ArrayList<Raid> raids = new ArrayList<Raid>();
|
||||||
private File configFile;
|
private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
|
||||||
|
|
||||||
public RaidData(final Main plugin) {
|
// Filter for only accessing yml files
|
||||||
this.dataConfig = null;
|
private static FilenameFilter ymlFilter = new FilenameFilter() {
|
||||||
this.configFile = null;
|
@Override
|
||||||
this.plugin = plugin;
|
public boolean accept(File dir, String name) {
|
||||||
this.saveDefaultConfig();
|
return name.endsWith(".yml");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static ArrayList<Raid> getRaids() {
|
||||||
|
return raids;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadConfig() {
|
/**
|
||||||
if (this.configFile == null) {
|
* Gets a raid with a specific name
|
||||||
this.configFile = new File(this.plugin.getDataFolder(), "raids.yml");
|
* @param name - Name to check
|
||||||
|
* @return Raid or Null
|
||||||
|
*/
|
||||||
|
public static Raid getRaid(String name) {
|
||||||
|
for (Raid raid : raids) {
|
||||||
|
|
||||||
}
|
}
|
||||||
this.dataConfig = (FileConfiguration) YamlConfiguration.loadConfiguration(this.configFile);
|
return null;
|
||||||
final InputStream defaultStream = this.plugin.getResource("raids.yml");
|
}
|
||||||
if (defaultStream != null) {
|
|
||||||
final YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration((Reader)new InputStreamReader(defaultStream));
|
public static void setRaids(ArrayList<Raid> raids) {
|
||||||
this.dataConfig.setDefaults((Configuration)defaultConfig);
|
for (Raid raid : raids) {
|
||||||
|
addRaid(raid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getConfig() {
|
public static void addRaid(Raid raid) {
|
||||||
if (this.dataConfig == null) {
|
if (raid == null) {
|
||||||
this.reloadConfig();
|
Main.warLogger.log("Attempted to add NULL to raid list.");
|
||||||
}
|
|
||||||
return this.dataConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveConfig() {
|
|
||||||
if (this.dataConfig == null || this.configFile == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
raids.add(raid);
|
||||||
this.getConfig().save(this.configFile);
|
}
|
||||||
|
|
||||||
|
public static void removeRaid(Raid raid) {
|
||||||
|
raids.remove(raid);
|
||||||
|
//deleteRaid(raid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a raid object from a provided HashMap
|
||||||
|
* @param fileData
|
||||||
|
* @return Raid object
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Raid fromMap(War war, HashMap<String, Object> fileData) {
|
||||||
|
|
||||||
|
if (fileData.get("raidedTown") == null || fileData.get("gatherTown") == null || fileData.get("side1AreRaiders") == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Town raidedTown = TownyAPI.getInstance().getTown((String) fileData.get("raidedTown"));
|
||||||
|
Town gatherTown = TownyAPI.getInstance().getTown((String) fileData.get("gatherTown"));
|
||||||
|
boolean attackBoolean = Boolean.parseBoolean((String) fileData.get("side1AreRaiders"));
|
||||||
|
|
||||||
|
Raid raid = new Raid(war, raidedTown, gatherTown, attackBoolean);
|
||||||
|
|
||||||
|
if(fileData.get("raidTicks") != null && fileData.get("raidPhase") != null && fileData.get("activeRaiders") != null) {
|
||||||
|
raid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase")));
|
||||||
|
raid.setRaidTicks((Integer) fileData.get("raidTicks"));
|
||||||
|
raid.setActiveRaiders((ArrayList<String>) fileData.get("activeRaiders"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return raid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the war into files.
|
||||||
|
* @param raid - War to be saved.
|
||||||
|
*/
|
||||||
|
public static void saveRaid(Raid raid) {
|
||||||
|
War war = raid.getWar();
|
||||||
|
war.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO Delete raid
|
||||||
|
private static void deleteRaid(War war) {
|
||||||
|
File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
|
||||||
|
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.getName().startsWith(war.getName())) {
|
||||||
|
file.delete();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveDefaultConfig() {
|
/**
|
||||||
if (this.configFile == null) {
|
* Turns a raid into a map
|
||||||
this.configFile = new File(this.plugin.getDataFolder(), "raids.yml");
|
* @param raid - Raid
|
||||||
|
* @return Map
|
||||||
|
*/
|
||||||
|
public static HashMap<String, Object> raidToMap(Raid raid) {
|
||||||
|
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||||
|
// Shoves everything into a map.
|
||||||
|
returnMap.put("raidedTown", raid.getRaidedTown());
|
||||||
|
returnMap.put("gatherTown", raid.getRaidedTown());
|
||||||
|
returnMap.put("raidTicks", raid.getRaidTicks());
|
||||||
|
returnMap.put("raidPhase", raid.getPhase().name());
|
||||||
|
returnMap.put("raidScore", raid.getRaidScore());
|
||||||
|
returnMap.put("side1AreRaiders", Boolean.toString(raid.getSide1AreRaiders()));
|
||||||
|
returnMap.put("activeRaiders", raid.getActiveRaiders());
|
||||||
|
|
||||||
|
return returnMap;
|
||||||
}
|
}
|
||||||
if (!this.configFile.exists()) {
|
|
||||||
this.plugin.saveResource("raids.yml", false);
|
/**
|
||||||
|
* Creates a map of raid maps
|
||||||
|
* @param war - War to map
|
||||||
|
* @return Map of Maps
|
||||||
|
*/
|
||||||
|
public static HashMap<String, Object> getRaidMap(War war) {
|
||||||
|
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||||
|
for (Raid raid : war.getRaids()) {
|
||||||
|
returnMap.put(raid.getRaidedTown().getName(), raidToMap(raid));
|
||||||
}
|
}
|
||||||
|
return returnMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO raid time check
|
//TODO raid time check
|
||||||
@@ -83,7 +159,4 @@ public class RaidData {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object getRaidMap(War war) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ public class SiegeData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the war into files.
|
* Saves the war into files.
|
||||||
* @param war - War to be saved.
|
* @param siege - War to be saved.
|
||||||
*/
|
*/
|
||||||
public static void saveSiege(Siege siege) {
|
public static void saveSiege(Siege siege) {
|
||||||
War war = siege.getWar();
|
War war = siege.getWar();
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ package me.ShermansWorld.AlathraWar.listeners;
|
|||||||
import me.ShermansWorld.AlathraWar.Helper;
|
import me.ShermansWorld.AlathraWar.Helper;
|
||||||
import me.ShermansWorld.AlathraWar.Raid;
|
import me.ShermansWorld.AlathraWar.Raid;
|
||||||
import me.ShermansWorld.AlathraWar.Siege;
|
import me.ShermansWorld.AlathraWar.Siege;
|
||||||
|
import me.ShermansWorld.AlathraWar.War;
|
||||||
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
||||||
import me.ShermansWorld.AlathraWar.commands.SiegeCommands;
|
import me.ShermansWorld.AlathraWar.commands.SiegeCommands;
|
||||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||||
|
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@@ -52,7 +54,8 @@ public class CommandsListener implements Listener
|
|||||||
|
|
||||||
allow n spawn and t spawn for defenders trapped in spawn
|
allow n spawn and t spawn for defenders trapped in spawn
|
||||||
*/
|
*/
|
||||||
for(Raid raid : RaidCommands.raids) {
|
for(War war : WarData.getWars()) {
|
||||||
|
for(Raid raid : war.getRaids()) {
|
||||||
//Only do this during regular phases, start and end ignored in case something breaks
|
//Only do this during regular phases, start and end ignored in case something breaks
|
||||||
if (raid.getPhase() == RaidPhase.COMBAT || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.GATHER) {
|
if (raid.getPhase() == RaidPhase.COMBAT || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.GATHER) {
|
||||||
//only do for active raiders and any defenders
|
//only do for active raiders and any defenders
|
||||||
@@ -104,7 +107,7 @@ public class CommandsListener implements Listener
|
|||||||
/*
|
/*
|
||||||
Prevent players from teleporting during a siege
|
Prevent players from teleporting during a siege
|
||||||
*/
|
*/
|
||||||
for(Siege siege : SiegeCommands.sieges) {
|
for(Siege siege : war.getSieges()) {
|
||||||
//Only do this during regular phases, start and end ignored in case something breaks
|
//Only do this during regular phases, start and end ignored in case something breaks
|
||||||
if (siege.getSiegeTicks() > 0) {
|
if (siege.getSiegeTicks() > 0) {
|
||||||
//only do for active raiders and any defenders
|
//only do for active raiders and any defenders
|
||||||
@@ -154,3 +157,4 @@ public class CommandsListener implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user