mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
Aubri test raiders (#12)
* gitignore * Raid Template * Raid commands and Data loader * Spelling Mistakes --------- Co-authored-by: Aubri Seebauer <[email protected]>
This commit is contained in:
1 parent
e91d80fec9
commit
e5e9bbe899
6 files changed
+676
-4
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.commands.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -8,10 +10,6 @@ import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.commands.SiegeCommands;
|
||||
import me.ShermansWorld.AlathraWar.commands.SiegeTabCompletion;
|
||||
import me.ShermansWorld.AlathraWar.commands.WarCommands;
|
||||
import me.ShermansWorld.AlathraWar.commands.WarTabCompletion;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.hooks.TABHook;
|
||||
@@ -32,6 +30,7 @@ public class Main extends JavaPlugin {
|
||||
|
||||
public static WarData warData;
|
||||
public static SiegeData siegeData;
|
||||
public static RaidData raidData;
|
||||
public static Main instance;
|
||||
public static Economy econ;
|
||||
public static AlathraWarLogger warLogger;
|
||||
@@ -110,6 +109,41 @@ public class Main extends JavaPlugin {
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("NULL when initializing sieges");
|
||||
}
|
||||
|
||||
//TODO: Raids
|
||||
try {
|
||||
Set<String> raidSet = (Set<String>) raidData.getConfig().getConfigurationSection("Raids").getKeys(false);
|
||||
Iterator<String> it2 = raidSet.iterator();
|
||||
ArrayList<String> raidsTempList = new ArrayList<String>();
|
||||
while (it2.hasNext()) {
|
||||
raidsTempList.add(it2.next());
|
||||
}
|
||||
for (int i = 0; i < raidsTempList.size(); ++i) {
|
||||
War raidWar = null;
|
||||
Town raidTown = null;
|
||||
for (final War war2 : WarCommands.wars) {
|
||||
if (raidData.getConfig().getString("Raids." + raidsTempList.get(i) + ".war")
|
||||
.equalsIgnoreCase(war2.getName())) {
|
||||
raidWar = war2;
|
||||
}
|
||||
}
|
||||
List<Town> townList = TownyAPI.getInstance().getTowns();
|
||||
for (final Town town : townList) {
|
||||
if (town.getName().equalsIgnoreCase(
|
||||
siegeData.getConfig().getString("Raids." + raidsTempList.get(i) + ".town"))) {
|
||||
raidTown = town;
|
||||
}
|
||||
}
|
||||
Raid raid = new Raid(Integer.parseInt(raidsTempList.get(i)), raidWar, raidTown,
|
||||
siegeData.getConfig().getString("Raids." + raidsTempList.get(i) + ".raiders"),
|
||||
siegeData.getConfig().getString("Raids." + raidsTempList.get(i) + ".defenders"),
|
||||
siegeData.getConfig().getBoolean("Raids." + raidsTempList.get(i) + ".side1areraiders"),
|
||||
siegeData.getConfig().getBoolean("Raids." + raidsTempList.get(i) + ".side2areraiders"));
|
||||
raid.start();
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
Bukkit.getLogger().info("NULL when initializing raids");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -156,10 +190,13 @@ public class Main extends JavaPlugin {
|
||||
instance = this;
|
||||
warData = new WarData(this);
|
||||
siegeData = new SiegeData(this);
|
||||
raidData = new RaidData(this);
|
||||
new WarCommands(this);
|
||||
new SiegeCommands(this);
|
||||
new RaidCommands(this);
|
||||
getCommand("war").setTabCompleter(new WarTabCompletion());
|
||||
getCommand("siege").setTabCompleter(new SiegeTabCompletion());
|
||||
getCommand("raid").setTabCompleter(new RaidTabCompletion());
|
||||
getServer().getPluginManager().registerEvents((Listener) new KillsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new JoinListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new BlockBreakListener(), (Plugin) this);
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* This is based on the existing Siege Class
|
||||
*/
|
||||
public class Raid {
|
||||
|
||||
private War war;
|
||||
private Town town;
|
||||
private String raiders;
|
||||
private String defenders;
|
||||
private boolean side1AreRaiders;
|
||||
private boolean side2AreRaiders;
|
||||
private int id;
|
||||
private int raiderPoints;
|
||||
private int defenderPoints;
|
||||
private int MAXRAIDTICKS;
|
||||
private Player owner;
|
||||
private int raidTicks;
|
||||
private TownBlock homeBlock;
|
||||
private Location townSpawn;
|
||||
int[] bukkitId;
|
||||
public ArrayList<String> raiderPlayers;
|
||||
public ArrayList<String> defenderPlayers;
|
||||
|
||||
public Raid(final int id, final War war, final Town town, final String raiders, final String defenders,
|
||||
final boolean side1AreRaiders, final boolean side2AreRaiders) {
|
||||
this.raidTicks = 0;
|
||||
this.bukkitId = new int[1];
|
||||
this.raiderPlayers = new ArrayList<String>();
|
||||
this.defenderPlayers = new ArrayList<String>();
|
||||
this.war = war;
|
||||
this.town = town;
|
||||
this.raiders = raiders;
|
||||
this.defenders = defenders;
|
||||
this.side1AreRaiders = side1AreRaiders;
|
||||
this.side2AreRaiders = side2AreRaiders;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.raiderPoints = Main.raidData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".raiderpoints");
|
||||
this.defenderPoints = Main.raidData.getConfig().getInt("Raids." + String.valueOf(this.id) + ".defenderpoints");
|
||||
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.MAXRAIDTICKS = 108000;
|
||||
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();
|
||||
} else {
|
||||
this.raiderPlayers = this.war.getSide2Players();
|
||||
this.defenderPlayers = this.war.getSide1Players();
|
||||
}
|
||||
try {
|
||||
homeBlock = town.getHomeBlock();
|
||||
townSpawn = town.getSpawn();
|
||||
} catch (TownyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Tick Loop sorta (runs every 10 seconds afaik)
|
||||
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(),
|
||||
(Runnable) new Runnable() {
|
||||
int homeBlockControl = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (homeBlock != null) {
|
||||
town.setHomeBlock(homeBlock);
|
||||
town.setSpawn(townSpawn);
|
||||
}
|
||||
if (Raid.this.side1AreRaiders) {
|
||||
Raid.this.raiderPlayers = Raid.this.war.getSide1Players();
|
||||
Raid.this.defenderPlayers = Raid.this.war.getSide2Players();
|
||||
} else {
|
||||
Raid.this.raiderPlayers = Raid.this.war.getSide2Players();
|
||||
Raid.this.defenderPlayers = Raid.this.war.getSide1Players();
|
||||
}
|
||||
if (Raid.this.raidTicks >= Raid.this.MAXRAIDTICKS) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(Raid.this.bukkitId[0]);
|
||||
if (Raid.this.raiderPoints > Raid.this.defenderPoints) {
|
||||
Raid.this.raidersWin(Raid.this.owner);
|
||||
} else {
|
||||
Raid.this.defendersWin();
|
||||
}
|
||||
} else {
|
||||
final Raid this$0 = Raid.this;
|
||||
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();
|
||||
|
||||
|
||||
if (Raid.this.raidTicks % 6000 == 0) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the raid of "
|
||||
+ Raid.this.town.getName() + ":");
|
||||
Bukkit.broadcastMessage(
|
||||
"Raider Points - " + String.valueOf(Raid.this.raiderPoints));
|
||||
Bukkit.broadcastMessage(
|
||||
"Defender Points - " + String.valueOf(Raid.this.defenderPoints));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0L, 200L);
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
|
||||
RaidCommands.raids.remove(this); //im not making this rn -Aubri
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(this.id), (Object) null);
|
||||
Main.raidData.saveConfig();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Need to add call to KillsListener (defined seperate from Siege)
|
||||
*/
|
||||
public void raiderKilled() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Need to add call to KillsListener (defined seperate from Siege)
|
||||
*/
|
||||
public void defenderKilled() {
|
||||
|
||||
}
|
||||
|
||||
public void raidersWin(final Player owner) {
|
||||
|
||||
}
|
||||
|
||||
public void defendersWin() {
|
||||
|
||||
}
|
||||
|
||||
public void addPointsToRaiders(final int points) {
|
||||
this.raiderPoints += points;
|
||||
}
|
||||
|
||||
public void addPointsToDefenders(final int points) {
|
||||
this.defenderPoints += points;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setID(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public War getWar() {
|
||||
return this.war;
|
||||
}
|
||||
|
||||
public void setWar(final War war) {
|
||||
this.war = war;
|
||||
}
|
||||
|
||||
public Town getTown() {
|
||||
return this.town;
|
||||
}
|
||||
|
||||
public void setTown(final Town town) {
|
||||
this.town = town;
|
||||
}
|
||||
|
||||
public String getRaiders() {
|
||||
return this.raiders;
|
||||
}
|
||||
|
||||
public void setRaiders(final String raiders) {
|
||||
this.raiders = raiders;
|
||||
}
|
||||
|
||||
public String getDefenders() {
|
||||
return this.defenders;
|
||||
}
|
||||
|
||||
public void setDefenders(final String defenders) {
|
||||
this.raiders = defenders;
|
||||
}
|
||||
|
||||
public int getRaiderPoints() {
|
||||
return this.raiderPoints;
|
||||
}
|
||||
|
||||
public void raiderPoints(final int raiderPointsPoints) {
|
||||
this.raiderPoints = raiderPoints;
|
||||
}
|
||||
|
||||
public int getDefenderPoints() {
|
||||
return this.defenderPoints;
|
||||
}
|
||||
|
||||
public void defenderPoints(final int defenderPoints) {
|
||||
this.defenderPoints = this.raiderPoints;
|
||||
}
|
||||
|
||||
public boolean getSide1AreRaiders() {
|
||||
return this.side1AreRaiders;
|
||||
}
|
||||
|
||||
public void setSide1AreRaiders(final boolean side1AreRaiders) {
|
||||
this.side1AreRaiders = side1AreRaiders;
|
||||
}
|
||||
|
||||
public boolean getSide2AreRaiders() {
|
||||
return this.side2AreRaiders;
|
||||
}
|
||||
|
||||
public void setSide2AreRaiders(final boolean side2AreRaiders) {
|
||||
this.side2AreRaiders = side2AreRaiders;
|
||||
}
|
||||
|
||||
public ArrayList<String> getRaiderPlayers() {
|
||||
return this.raiderPlayers;
|
||||
}
|
||||
|
||||
public void setRaiderPlayer(final ArrayList<String> raiderPlayers) {
|
||||
this.raiderPlayers = raiderPlayers;
|
||||
}
|
||||
|
||||
public ArrayList<String> getDefenderPlayers() {
|
||||
return this.defenderPlayers;
|
||||
}
|
||||
|
||||
public void setDefenderPlayer(final ArrayList<String> defenderPlayers) {
|
||||
this.defenderPlayers = this.defenderPlayers;
|
||||
}
|
||||
|
||||
static /* synthetic */ void access$7(final Raid raid, final int raidTicks) {
|
||||
raid.raidTicks = raidTicks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyWorld;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RaidCommands implements CommandExecutor
|
||||
{
|
||||
public static ArrayList<Town> towns;
|
||||
public static ArrayList<Raid> raids;
|
||||
public static int maxID;
|
||||
|
||||
static {
|
||||
RaidCommands.towns = new ArrayList<Town>();
|
||||
RaidCommands.raids = new ArrayList<Raid>();
|
||||
RaidCommands.maxID = Main.raidData.getConfig().getInt("MaxID");
|
||||
}
|
||||
|
||||
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;
|
||||
if (args.length == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
}
|
||||
else if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
if (RaidCommands.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("ID: " + String.valueOf(raid.getID()));
|
||||
p.sendMessage("War: " + raid.getWar().getName());
|
||||
p.sendMessage("Town: " + raid.getTown().getName());
|
||||
p.sendMessage("Raiders: " + raid.getRaiders());
|
||||
p.sendMessage("Defenders: " + raid.getDefenders());
|
||||
p.sendMessage("Raider Points: " + String.valueOf(raid.getRaiderPoints()));
|
||||
p.sendMessage("Defender Points: " + String.valueOf(raid.getDefenderPoints()));
|
||||
p.sendMessage("Time Left: " + String.valueOf((108000 - Main.raidData.getConfig().getInt("Raids." + String.valueOf(String.valueOf(raid.getID()) + ".raidticks"))) / 1200) + " minutes");
|
||||
p.sendMessage("-=-=-=-=-=-=-=-=-=-=-=-");
|
||||
}
|
||||
} 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 abandon [id]");
|
||||
p.sendMessage(Helper.Chatlabel() + "/raid list");
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
}
|
||||
|
||||
}
|
||||
else if (args.length == 2) {
|
||||
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 (RaidCommands.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 < RaidCommands.raids.size(); ++i) {
|
||||
if (String.valueOf(RaidCommands.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 at " + RaidCommands.raids.get(i).getTown().getName() + " has been cancelled by an admin");
|
||||
RaidCommands.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 < RaidCommands.raids.size(); ++j) {
|
||||
if (String.valueOf(RaidCommands.raids.get(j).getID()).equalsIgnoreCase(args[1])) {
|
||||
found2 = true;
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid at " + RaidCommands.raids.get(j).getTown().getName() + " has been abandoned by " + RaidCommands.raids.get(j).getRaiders());
|
||||
Main.warLogger.log(p.getName() + " abandoned the raid they started at " + RaidCommands.raids.get(j).getTown().getName());
|
||||
RaidCommands.raids.get(j).defendersWin();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found2) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Only the player who started the raid can abandon it");
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
//TODO: This needs to change
|
||||
//needs to have be in raiders town to delcare raid added
|
||||
//so that surprise raids arent a thing, ill leave that to someone else
|
||||
for (final String entry : townyWorld.getTowns().keySet()) {
|
||||
final Town town = townyWorld.getTowns().get(entry);
|
||||
RaidCommands.towns.add(town);
|
||||
if (town.getName().equalsIgnoreCase(args[2])) {
|
||||
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, town, 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) + ".town", (Object)town.getName());
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".raiders", (Object)war.getSide1());
|
||||
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) + ".raiderpoints", (Object)0);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".defenderpoints", (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, town, 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) + ".town", (Object)town.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) + ".raiderpoints", (Object)0);
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID) + ".defenderpoints", (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 : town.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 the town's claim to begin a raid");
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID), (Object)null);
|
||||
Main.raidData.saveConfig();
|
||||
return false;
|
||||
}
|
||||
if (!currentTown.equals(town)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within the town's claim to begin a raid");
|
||||
Main.raidData.getConfig().set("Raids." + String.valueOf(RaidCommands.maxID), (Object)null);
|
||||
Main.raidData.saveConfig();
|
||||
return false;
|
||||
}
|
||||
for (final Raid raidEntry : RaidCommands.raids) {
|
||||
if (raidEntry.getTown().getName().equalsIgnoreCase(town.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;
|
||||
}
|
||||
}
|
||||
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 $20,000 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.0);
|
||||
RaidCommands.raids.add(raid2);
|
||||
raid2.start();
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "As part of " + war.getName() + ", forces from " + raid2.getRaiders() + " are raiding the town of " + town.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 " + town.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]");
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RaidTabCompletion implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
Player p = (Player)sender;
|
||||
if (args.length == 1) {
|
||||
if (p.hasPermission("AlathraWar.admin")) {
|
||||
completions.add("stop");
|
||||
}
|
||||
completions.add("start");
|
||||
completions.add("abandon");
|
||||
completions.add("list");
|
||||
completions.add("help");
|
||||
return completions;
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
if (!WarCommands.wars.isEmpty()) {
|
||||
for (War war : WarCommands.wars) {
|
||||
completions.add(war.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("abandon")) {
|
||||
if (!RaidCommands.raids.isEmpty()) {
|
||||
for (Raid raid : RaidCommands.raids) {
|
||||
completions.add(String.valueOf(raid.getID()));
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
if (!TownyAPI.getInstance().getTowns().isEmpty()) {
|
||||
for (Town town : TownyAPI.getInstance().getTowns()) {
|
||||
completions.add(town.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class RaidData {
|
||||
private Main plugin;
|
||||
private FileConfiguration dataConfig;
|
||||
private File configFile;
|
||||
|
||||
public RaidData(final Main plugin) {
|
||||
this.dataConfig = null;
|
||||
this.configFile = null;
|
||||
this.plugin = plugin;
|
||||
this.saveDefaultConfig();
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "raids.yml");
|
||||
}
|
||||
this.dataConfig = (FileConfiguration) YamlConfiguration.loadConfiguration(this.configFile);
|
||||
final InputStream defaultStream = this.plugin.getResource("raids.yml");
|
||||
if (defaultStream != null) {
|
||||
final YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration((Reader)new InputStreamReader(defaultStream));
|
||||
this.dataConfig.setDefaults((Configuration)defaultConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (this.dataConfig == null) {
|
||||
this.reloadConfig();
|
||||
}
|
||||
return this.dataConfig;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (this.dataConfig == null || this.configFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.getConfig().save(this.configFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "raids.yml");
|
||||
}
|
||||
if (!this.configFile.exists()) {
|
||||
this.plugin.saveResource("raids.yml", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user