mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-02 06:28:52 +00:00
Merge pull request #14 from ShermansWorld/aubri-test-raiding
feature/raids
This commit is contained in:
15 files changed
+1936
-488
No files matched your search
+2
-1
@@ -4,4 +4,5 @@
|
||||
.classpath
|
||||
.project
|
||||
/.idea/
|
||||
/.vscode/
|
||||
/.vscode/
|
||||
AlathraWar.iml
|
||||
@@ -0,0 +1,3 @@
|
||||
MaxID: 0
|
||||
|
||||
Raids:
|
||||
@@ -0,0 +1 @@
|
||||
id:
|
||||
@@ -1,7 +1,16 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Helper
|
||||
{
|
||||
@@ -16,4 +25,188 @@ public class Helper
|
||||
public static void testMsg() {
|
||||
Bukkit.broadcastMessage("test message");
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages all gear in a players inventory
|
||||
*
|
||||
* @param p
|
||||
* @author ShermansWorld
|
||||
*/
|
||||
public static void damageAllGear(Player p) {
|
||||
final Inventory inv = p.getInventory();
|
||||
for (int i = 0; i < inv.getSize(); ++i) {
|
||||
final ItemStack is = inv.getItem(i);
|
||||
if (is != null && (is.getType() == Material.NETHERITE_AXE || is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.DIAMOND_AXE || is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.IRON_AXE || is.getType() == Material.IRON_SWORD)) {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
final Damageable damageable = (Damageable)meta;
|
||||
if (is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.NETHERITE_AXE) {
|
||||
damageable.setDamage(damageable.getDamage() + 507);
|
||||
if (damageable.getDamage() > 2000) {
|
||||
damageable.setDamage(2030);
|
||||
}
|
||||
}
|
||||
else if (is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.DIAMOND_AXE) {
|
||||
damageable.setDamage(damageable.getDamage() + 390);
|
||||
if (damageable.getDamage() > 1500) {
|
||||
damageable.setDamage(1560);
|
||||
}
|
||||
}
|
||||
else if (is.getType() == Material.IRON_SWORD || is.getType() == Material.IRON_AXE) {
|
||||
damageable.setDamage(damageable.getDamage() + 62);
|
||||
if (damageable.getDamage() > 200) {
|
||||
damageable.setDamage(249);
|
||||
}
|
||||
}
|
||||
meta = (ItemMeta)damageable;
|
||||
is.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
final ItemStack[] armor = p.getInventory().getArmorContents();
|
||||
for (int j = 0; j < armor.length; ++j) {
|
||||
if (armor[j] != null) {
|
||||
final ItemStack is2 = armor[j];
|
||||
if (is2.getType() == Material.NETHERITE_HELMET || is2.getType() == Material.NETHERITE_CHESTPLATE || is2.getType() == Material.NETHERITE_LEGGINGS || is2.getType() == Material.NETHERITE_BOOTS || is2.getType() == Material.DIAMOND_HELMET || is2.getType() == Material.DIAMOND_CHESTPLATE || is2.getType() == Material.DIAMOND_LEGGINGS || is2.getType() == Material.NETHERITE_BOOTS || is2.getType() == Material.IRON_HELMET || is2.getType() == Material.IRON_CHESTPLATE || is2.getType() == Material.IRON_LEGGINGS || is2.getType() == Material.IRON_BOOTS) {
|
||||
ItemMeta meta2 = is2.getItemMeta();
|
||||
final Damageable damageable2 = (Damageable)meta2;
|
||||
if (is2.getType() == Material.NETHERITE_HELMET) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 101);
|
||||
if (damageable2.getDamage() > 400) {
|
||||
damageable2.setDamage(406);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.NETHERITE_CHESTPLATE) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 148);
|
||||
if (damageable2.getDamage() > 450) {
|
||||
damageable2.setDamage(591);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.NETHERITE_LEGGINGS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 138);
|
||||
if (damageable2.getDamage() > 420) {
|
||||
damageable2.setDamage(554);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.NETHERITE_BOOTS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 120);
|
||||
if (damageable2.getDamage() > 370) {
|
||||
damageable2.setDamage(480);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_HELMET) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 90);
|
||||
if (damageable2.getDamage() > 280) {
|
||||
damageable2.setDamage(362);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_CHESTPLATE) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 132);
|
||||
if (damageable2.getDamage() > 410) {
|
||||
damageable2.setDamage(527);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_LEGGINGS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 123);
|
||||
if (damageable2.getDamage() > 380) {
|
||||
damageable2.setDamage(494);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_BOOTS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 107);
|
||||
if (damageable2.getDamage() > 330) {
|
||||
damageable2.setDamage(428);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_HELMET) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 41);
|
||||
if (damageable2.getDamage() > 125) {
|
||||
damageable2.setDamage(164);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_CHESTPLATE) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 60);
|
||||
if (damageable2.getDamage() > 190) {
|
||||
damageable2.setDamage(239);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_LEGGINGS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 56);
|
||||
if (damageable2.getDamage() > 180) {
|
||||
damageable2.setDamage(224);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_BOOTS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 48);
|
||||
if (damageable2.getDamage() > 150) {
|
||||
damageable2.setDamage(194);
|
||||
}
|
||||
}
|
||||
meta2 = (ItemMeta)damageable2;
|
||||
is2.setItemMeta(meta2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param worldCoord worldCoord
|
||||
* @return List of connected chunks
|
||||
* @author NinjaMandalorian
|
||||
*/
|
||||
private static ArrayList<WorldCoord> getAdjCells(WorldCoord worldCoord) {
|
||||
ArrayList<WorldCoord> ReturnList = new ArrayList<>();
|
||||
|
||||
int[][] XZarray = new int[][]{
|
||||
{-1, 0},
|
||||
{1, 0},
|
||||
{0, -1},
|
||||
{0, 1}
|
||||
}; // Array that contains relative orthogonal shifts from origin
|
||||
for ( int[] pair: XZarray) {
|
||||
// Constructs new WorldCoord for comparison
|
||||
WorldCoord tCoord = new WorldCoord(worldCoord.getWorldName(), worldCoord.getX() + pair[0], worldCoord.getZ() + pair[1]);
|
||||
if (tCoord.getTownOrNull() != null && tCoord.getTownOrNull() == worldCoord.getTownOrNull()) {
|
||||
// If in town, and in same town, adds to return list
|
||||
ReturnList.add(tCoord);
|
||||
}
|
||||
}
|
||||
return ReturnList;
|
||||
}
|
||||
|
||||
/** Gets all adjacently connected townblocks
|
||||
* @param chunkCoord - WorldCoord to check at
|
||||
* @return List of WorldCoords
|
||||
* @author NinjaMandalorian
|
||||
*/
|
||||
public static ArrayList<WorldCoord> getCluster(WorldCoord chunkCoord){
|
||||
// WCoordList is the returning array, SearchList is the to-search list.
|
||||
ArrayList<WorldCoord> WCoordList = new ArrayList<>();
|
||||
ArrayList<WorldCoord> SearchList = new ArrayList<>();
|
||||
SearchList.add(chunkCoord); // Adds 1st chunk to list
|
||||
|
||||
// Iterates through SearchList, to create a full list of every adjacent cell.
|
||||
while (SearchList.size() > 0) {
|
||||
// Gets WorldCoord
|
||||
WorldCoord toSearch = SearchList.get(0);
|
||||
// Gets adjacent cells
|
||||
ArrayList<WorldCoord> adjCells = getAdjCells(toSearch);
|
||||
for (WorldCoord cell : adjCells) {
|
||||
// If in final list, ignore.
|
||||
if (WCoordList.contains(cell)) {
|
||||
continue;
|
||||
// If in to-search list, ignore
|
||||
} else if (SearchList.contains(cell)) {
|
||||
continue;
|
||||
// Otherwise, add to search-list.
|
||||
} else {
|
||||
SearchList.add(cell);
|
||||
}
|
||||
}
|
||||
// Removes from search list and adds to finished list. After checking all adjacent chunks.
|
||||
SearchList.remove(toSearch);
|
||||
WCoordList.add(toSearch);
|
||||
}
|
||||
|
||||
return WCoordList; // Returns list
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.commands.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.listeners.CommandsListener;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@@ -27,7 +28,6 @@ import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
public static Main instance;
|
||||
public static Economy econ;
|
||||
public static AlathraWarLogger warLogger;
|
||||
@@ -98,6 +98,7 @@ public class Main extends JavaPlugin {
|
||||
getCommand("siege").setTabCompleter(new SiegeTabCompletion());
|
||||
//getCommand("raid").setTabCompleter(new RaidTabCompletion());
|
||||
getServer().getPluginManager().registerEvents((Listener) new KillsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new CommandsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new JoinListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new BlockBreakListener(), (Plugin) this);
|
||||
initData();
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -22,6 +22,7 @@ public class War {
|
||||
// References
|
||||
private ArrayList<Siege> sieges = new ArrayList<Siege>();
|
||||
private ArrayList<Raid> raids = new ArrayList<Raid>();
|
||||
private Long lastRaidTime;
|
||||
|
||||
/**
|
||||
* War Constructor
|
||||
@@ -204,4 +205,11 @@ public class War {
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public void setLastRaidTime(Long lastRaidTime) {
|
||||
this.lastRaidTime = lastRaidTime;
|
||||
}
|
||||
|
||||
public Long getLastRaidTime() {
|
||||
return this.lastRaidTime;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
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 com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.*;
|
||||
import com.palmergames.bukkit.towny.object.metadata.LongDataField;
|
||||
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,8 +18,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
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;
|
||||
@@ -31,230 +33,367 @@ public class RaidCommands implements CommandExecutor
|
||||
}
|
||||
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||
/*final Player p = (Player)sender;
|
||||
final Player p = (Player) sender;
|
||||
if (args.length == 0) {
|
||||
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 (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("-=-=-=-=-=-=-=-=-=-=-=-");
|
||||
}
|
||||
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 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 (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");
|
||||
}
|
||||
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();
|
||||
}
|
||||
startRaid(p, args);
|
||||
} else if (args[0].equalsIgnoreCase("join")) {
|
||||
joinRaid(p, args);
|
||||
} else if (args[0].equalsIgnoreCase("leave")) {
|
||||
leaveRaid(p, args);
|
||||
} else if (args[0].equalsIgnoreCase("abandon")) {
|
||||
abandonRaid(p, args);
|
||||
} else {
|
||||
fail(p, args, "syntax");
|
||||
}
|
||||
} else {
|
||||
fail(p, args, "syntax");
|
||||
}
|
||||
return false;
|
||||
|
||||
//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() + "!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a raid
|
||||
*
|
||||
* @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();
|
||||
|
||||
//check if in a town
|
||||
//takes the command runners town as the gather point
|
||||
Town gatherTown = null;
|
||||
try {
|
||||
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(p.getLocation()).getTownBlock());
|
||||
} 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 (gatherTown == null) {
|
||||
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;
|
||||
}
|
||||
|
||||
//parse the argunment for town
|
||||
for (final String entry : townyWorld.getTowns().keySet()) {
|
||||
final Town raidedTown = townyWorld.getTowns().get(entry);
|
||||
|
||||
if (raidedTown.getName().equalsIgnoreCase(args[2]) && gatherTown != null) {
|
||||
townExists = true;
|
||||
boolean attackingOwnSide = false;
|
||||
Raid raid2;
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
//Time and raid activity validity check
|
||||
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()) + "This 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 {
|
||||
//Something broke if this runs
|
||||
if (!war.getSide2Players().contains(p.getName())) {
|
||||
Bukkit.getLogger().info("Unable to find player declaring raid in the war");
|
||||
return;
|
||||
}
|
||||
//Time and raid activity validity check
|
||||
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()) + "This 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();
|
||||
}
|
||||
}
|
||||
|
||||
//validity check over attacking own towns
|
||||
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;
|
||||
}
|
||||
|
||||
//check player balance
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUniqueId());
|
||||
if (Main.econ.getBalance(offlinePlayer) <= 1000.0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $1000 to put up to start a raid.");
|
||||
return;
|
||||
}
|
||||
|
||||
//publish raid
|
||||
Main.econ.withdrawPlayer(offlinePlayer, 1000);
|
||||
RaidData.addRaid(raid2);
|
||||
raid2.start(); //funny funny method haha
|
||||
WarData.saveWar(raid2.getWar());
|
||||
|
||||
//broadcast
|
||||
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]");
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
}*/
|
||||
return false;
|
||||
|
||||
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]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the current raid by admins
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
private static void stopRaid(Player p, String[] args) {
|
||||
//admin check
|
||||
if (!p.hasPermission("AlathraWar.admin")) {
|
||||
fail(p, args, "permission");
|
||||
return;
|
||||
}
|
||||
|
||||
//are there even any raids
|
||||
if (RaidData.getRaids().isEmpty()) {
|
||||
fail(p, args, "noRaids");
|
||||
return;
|
||||
}
|
||||
boolean found = false;
|
||||
|
||||
//find our desired raid and stop it
|
||||
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(); //this purges itself from raids
|
||||
} else {
|
||||
fail(p, args, "badName");
|
||||
}
|
||||
}
|
||||
|
||||
private static void joinRaid(Player p, String[] args) {
|
||||
//Grab raid!
|
||||
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
|
||||
if (raid != null) {
|
||||
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
|
||||
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
|
||||
try {
|
||||
//check if the player is in the gather town
|
||||
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) {
|
||||
//Get raid!
|
||||
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
|
||||
if (raid != null) {
|
||||
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
|
||||
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
|
||||
try {
|
||||
//check if player is in gather town
|
||||
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) {
|
||||
//Get raid
|
||||
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
|
||||
if (raid != null) {
|
||||
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
|
||||
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
|
||||
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))) {
|
||||
//force defender victory
|
||||
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");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
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.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
@@ -28,19 +30,42 @@ public class RaidTabCompletion implements TabCompleter {
|
||||
completions.add("abandon");
|
||||
completions.add("list");
|
||||
completions.add("help");
|
||||
completions.add("join");
|
||||
completions.add("leave");
|
||||
return completions;
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
if (!WarCommands.wars.isEmpty()) {
|
||||
for (War war : WarCommands.wars) {
|
||||
if (!WarData.getWars().isEmpty()) {
|
||||
for (War war : WarData.getWars()) {
|
||||
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()));
|
||||
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||
if (!RaidData.getRaids().isEmpty()) {
|
||||
for (Raid raid : RaidData.getRaids()) {
|
||||
completions.add(String.valueOf(raid.getName()));
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("join")) {
|
||||
if (!WarData.getWars().isEmpty()) {
|
||||
for (War war : WarData.getWars()) {
|
||||
completions.add(war.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("abandon")) {
|
||||
if (!WarData.getWars().isEmpty()) {
|
||||
for (War war : WarData.getWars()) {
|
||||
completions.add(war.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("leave")) {
|
||||
if (!WarData.getWars().isEmpty()) {
|
||||
for (War war : WarData.getWars()) {
|
||||
completions.add(war.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
@@ -53,6 +78,27 @@ public class RaidTabCompletion implements TabCompleter {
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("join")) {
|
||||
if (!TownyAPI.getInstance().getTowns().isEmpty()) {
|
||||
for (Town town : TownyAPI.getInstance().getTowns()) {
|
||||
completions.add(town.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("abandon")) {
|
||||
if (!TownyAPI.getInstance().getTowns().isEmpty()) {
|
||||
for (Town town : TownyAPI.getInstance().getTowns()) {
|
||||
completions.add(town.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("leave")) {
|
||||
if (!TownyAPI.getInstance().getTowns().isEmpty()) {
|
||||
for (Town town : TownyAPI.getInstance().getTowns()) {
|
||||
completions.add(town.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -1,64 +1,244 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import com.palmergames.bukkit.towny.object.metadata.CustomDataField;
|
||||
import com.palmergames.bukkit.towny.object.metadata.IntegerDataField;
|
||||
import com.palmergames.bukkit.towny.object.metadata.LongDataField;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class RaidData {
|
||||
private Main plugin;
|
||||
private FileConfiguration dataConfig;
|
||||
private File configFile;
|
||||
// Static Raid list for all active raids
|
||||
private static ArrayList<Raid> raids = new ArrayList<Raid>();
|
||||
private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
|
||||
|
||||
public RaidData(final Main plugin) {
|
||||
this.dataConfig = null;
|
||||
this.configFile = null;
|
||||
this.plugin = plugin;
|
||||
this.saveDefaultConfig();
|
||||
// Filter for only accessing yml files
|
||||
private static FilenameFilter ymlFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".yml");
|
||||
}
|
||||
};
|
||||
|
||||
public static ArrayList<Raid> getRaids() {
|
||||
return raids;
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "raids.yml");
|
||||
/**
|
||||
* Gets a raid with a specific name
|
||||
*
|
||||
* @param name - Name to check
|
||||
* @return Raid or Null
|
||||
*/
|
||||
public static Raid getRaidOrNull(String name) {
|
||||
for (Raid raid : raids) {
|
||||
if (raid.getName().equals(name)) return raid;
|
||||
}
|
||||
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);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setRaids(ArrayList<Raid> raids) {
|
||||
for (Raid raid : raids) {
|
||||
addRaid(raid);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (this.dataConfig == null) {
|
||||
this.reloadConfig();
|
||||
}
|
||||
return this.dataConfig;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (this.dataConfig == null || this.configFile == null) {
|
||||
public static void addRaid(Raid raid) {
|
||||
if (raid == null) {
|
||||
Main.warLogger.log("Attempted to add NULL to raid list.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.getConfig().save(this.configFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
raids.add(raid);
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (this.configFile == null) {
|
||||
this.configFile = new File(this.plugin.getDataFolder(), "raids.yml");
|
||||
public static void removeRaid(Raid raid) {
|
||||
raid.getWar().getRaids().remove(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;
|
||||
}
|
||||
if (!this.configFile.exists()) {
|
||||
this.plugin.saveResource("raids.yml", false);
|
||||
|
||||
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);
|
||||
|
||||
//Extra properties, if any are missing the raid doesnt exist yet
|
||||
if (fileData.get("raidTicks") != null && fileData.get("raidPhase") != null && fileData.get("activeRaiders") != null && fileData.get("lootedChunks") != null) {
|
||||
//active properties
|
||||
raid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase")));
|
||||
raid.setRaidTicks((Integer) fileData.get("raidTicks"));
|
||||
raid.setActiveRaiders((ArrayList<String>) fileData.get("activeRaiders"));
|
||||
|
||||
//looted chunks
|
||||
HashMap<String, Object> o = (HashMap<String, Object>) fileData.get("lootedChunks");
|
||||
for (String s : o.keySet()) {
|
||||
//grab the chunk
|
||||
HashMap<String, Object> chunk = (HashMap<String, Object>) o.get(s);
|
||||
|
||||
//grab data for this chunk
|
||||
//worldcoord is its own map
|
||||
HashMap<String, Object> wc = (HashMap<String, Object>) chunk.get("worldCoord");
|
||||
WorldCoord worldCoordc = WorldCoord.parseWorldCoord((String) wc.get("world"), ((Integer) wc.get("x")), ((Integer) wc.get("z")));
|
||||
int ticks = (int) chunk.get("ticks");
|
||||
double value = (double) chunk.get("value");
|
||||
boolean finished = (boolean) chunk.get("finished");
|
||||
|
||||
//put
|
||||
Raid.LootBlock lb = new Raid.LootBlock(worldCoordc, ticks, value, finished);
|
||||
raid.getLootedChunks().put(worldCoordc, lb);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes raid, unused
|
||||
*/
|
||||
// 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();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Turns a raid into a map
|
||||
*
|
||||
* @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("name", raid.getName());
|
||||
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());
|
||||
|
||||
//create a list from the looted chunks
|
||||
List<Object> chunkList = new ArrayList<Object>();
|
||||
for (Raid.LootBlock b : raid.getLootedChunks().values()) {
|
||||
HashMap<String, Object> blockMap = new HashMap<String, Object>();
|
||||
//worldcoord
|
||||
HashMap<String, Object> wcMap = new HashMap<String, Object>();
|
||||
wcMap.put("world", b.worldCoord.getWorldName());
|
||||
wcMap.put("x", b.worldCoord.getCoord().getX());
|
||||
wcMap.put("z", b.worldCoord.getCoord().getZ());
|
||||
blockMap.put("worldCoord", wcMap);
|
||||
//properties
|
||||
blockMap.put("ticks", b.ticks);
|
||||
blockMap.put("value", b.value);
|
||||
blockMap.put("finished", b.finished);
|
||||
chunkList.add(blockMap);
|
||||
}
|
||||
|
||||
returnMap.put("lootedChunks", chunkList);
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @Isaac this is for getting when the last raid was on a town
|
||||
*/
|
||||
public static long whenTownLastRaided(Town town) {
|
||||
if (town.hasMeta("lastRaided")) {
|
||||
CustomDataField field = town.getMetadata("lastRaided");
|
||||
if (field != null) {
|
||||
if (field instanceof IntegerDataField) {
|
||||
return ((IntegerDataField) field).getValue();
|
||||
}
|
||||
}
|
||||
return -1L;
|
||||
} else {
|
||||
town.addMetaData(new LongDataField("lastRaided", 0L));
|
||||
}
|
||||
return -1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @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 war cooldown, valid time to raid, town being raided already)
|
||||
*/
|
||||
public static int isValidRaid(War war, Town town) {
|
||||
long townTime = whenTownLastRaided(town);
|
||||
|
||||
//24 hours town cooldown
|
||||
if ((System.currentTimeMillis() / 1000) - townTime <= 86400) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//6 hour raid cooldown for war
|
||||
if ((System.currentTimeMillis() / 1000) - war.getLastRaidTime() <= 21600) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//check if being raided
|
||||
for (Raid raid : war.getRaids()) {
|
||||
if (raid.getRaidedTown().getName().equals(town.getName())) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Object getRaidMap(War war) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
public enum RaidPhase {
|
||||
START(0, 0),
|
||||
GATHER(1, 1),
|
||||
TRAVEL(2, 18000),
|
||||
COMBAT(3, 24000),
|
||||
END(4, 72000);
|
||||
|
||||
//Start phase starts when the command to start a raid is ran, it allows the raiders to join, and for people to get geared up
|
||||
//after 15 minutes travel phase begins, where the raiders start travelling and moving to the new town.
|
||||
//no killing can occur during these two phases.
|
||||
//Once at least one player has stepped into the defending town, or 5 min have passed during the travel phase,
|
||||
//the combat begins and lasts 40 minutes.
|
||||
|
||||
public final int id;
|
||||
public final int startTick;
|
||||
|
||||
private RaidPhase(int id, int startTick) {
|
||||
this.id = id;
|
||||
this.startTick = startTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the phase by name, ignores case
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static RaidPhase getByName(String name) {
|
||||
for(RaidPhase p : RaidPhase.values()) {
|
||||
if(p.name().equalsIgnoreCase(name)) return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs phase by id number for easy storage reading
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static RaidPhase getByID(int id) {
|
||||
for(RaidPhase p : RaidPhase.values()) {
|
||||
if(p.id == id) return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,8 @@ public class SiegeData
|
||||
|
||||
/**
|
||||
* Saves the war into files.
|
||||
* @param war - War to be saved.
|
||||
|
||||
* @param siege - Siege to be saved.
|
||||
*/
|
||||
public static void saveSiege(Siege siege) {
|
||||
War war = siege.getWar();
|
||||
|
||||
@@ -98,6 +98,7 @@ public class WarData
|
||||
war.setSide1Towns((ArrayList<String>) fileData.get("side1Towns"));
|
||||
war.setSide2Towns((ArrayList<String>) fileData.get("side2Towns"));
|
||||
|
||||
war.setLastRaidTime((Long) fileData.get("lastRaidTime"));
|
||||
|
||||
return war;
|
||||
}
|
||||
@@ -119,6 +120,7 @@ public class WarData
|
||||
|
||||
sHashMap.put("sieges", SiegeData.getSiegeMap(war));
|
||||
sHashMap.put("raids", RaidData.getRaidMap(war));
|
||||
sHashMap.put("lastRaidTime", war.getLastRaidTime());
|
||||
|
||||
|
||||
DataManager.saveData("wars" + File.separator + war.getName() + ".yml", sHashMap);
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandsListener implements Listener {
|
||||
|
||||
final static String[] prefixes = new String[]{
|
||||
"", "towny", "essentials", "wild", "minecraft"
|
||||
};
|
||||
final static String[] blacklistedLong = new String[]{
|
||||
"n spawn", "nat spawn", "nation spawn",
|
||||
"t spawn", "town spawn"
|
||||
};
|
||||
final static String[] blacklistedShort = new String[]{
|
||||
"home", "homes", "warp", "warps",
|
||||
"wild", "rtp", "spawn", "wilderness", "wildtp",
|
||||
"tpa", "tpahere", "tpaccept", "tpacancel",
|
||||
"etpa", "etpahere", "etpaccept", "etpacancel",
|
||||
"ehome", "ehomes", "ewarp", "ewarps"
|
||||
|
||||
};
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onCommandSend(final PlayerCommandPreprocessEvent event) {
|
||||
|
||||
Player p = event.getPlayer();
|
||||
|
||||
//if player is admin, ignore this behavior
|
||||
if (p.hasPermission("!AlathraWar.admin")) return;
|
||||
|
||||
String[] args = event.getMessage().split(" ");
|
||||
/*
|
||||
Prevent any teleport command events from occuring
|
||||
If using PlayerTeleportEvent, it breaks the death logic
|
||||
|
||||
allow n spawn and t spawn for defenders trapped in spawn
|
||||
*/
|
||||
for (War war : WarData.getWars()) {
|
||||
for (Raid raid : war.getRaids()) {
|
||||
//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) {
|
||||
//only do for active raiders and any defenders
|
||||
if (raid.getActiveRaiders().contains(p.getName()) || raid.getDefenders().contains(p.getName())) {
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
//check if in spawn
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
if (parse.equals("n spawn") || parse.equals("nat spawn") || parse.equals("nation spawn")
|
||||
|| parse.equals("t spawn") || parse.equals("town spawn")
|
||||
|| parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn")
|
||||
|| parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and are allowed to teleport to your town or nation.");
|
||||
return;
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and are allowed to teleport to your town or nation.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Prevent players from teleporting during a siege
|
||||
*/
|
||||
for (Siege siege : war.getSieges()) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
if (siege.getSiegeTicks() > 0) {
|
||||
//only do for active raiders and any defenders
|
||||
if (siege.getAttackerPlayers().contains(p.getName()) || siege.getDefenders().contains(p.getName())) {
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
//check if in spawn
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
if (parse.equals("n spawn") || parse.equals("nat spawn") || parse.equals("nation spawn")
|
||||
|| parse.equals("t spawn") || parse.equals("town spawn")
|
||||
|| parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn")
|
||||
|| parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and allowed to teleport to your town or nation!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -37,17 +41,18 @@ public final class KillsListener implements Listener
|
||||
town = WorldCoord.parseWorldCoord((Entity)killed).getTownBlock().getTown();
|
||||
}
|
||||
catch (NotRegisteredException ex2) {}
|
||||
boolean playerCloseToHomeBlock = false;
|
||||
boolean playerCloseToHomeBlockSiege = false;
|
||||
boolean playerCloseToHomeBlockRaid = false;
|
||||
try {
|
||||
for (final Siege siege : SiegeData.getSieges()) {
|
||||
final int homeBlockXCoord = siege.getTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoord = siege.getTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoord) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoord) <= 300) {
|
||||
playerCloseToHomeBlock = true;
|
||||
playerCloseToHomeBlockSiege = true;
|
||||
}
|
||||
if (siege.getAttackerPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlock)) {
|
||||
if (siege.getDefenderPlayers().contains(killed.getName())) {
|
||||
siege.addPointsToAttackers(20);
|
||||
if (siege.getAttackerPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
|
||||
if (siege.getDefenderPlayers().contains(killed.getName())) {
|
||||
siege.addPointsToAttackers(20);
|
||||
for (final String playerName : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! + 20 Attacker Points");
|
||||
@@ -60,13 +65,13 @@ public final class KillsListener implements Listener
|
||||
}
|
||||
catch (NullPointerException ex6) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
}
|
||||
if (siege.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlock)) {
|
||||
if (siege.getAttackerPlayers().contains(killed.getName())) {
|
||||
siege.addPointsToDefenders(20);
|
||||
if (siege.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
|
||||
if (siege.getAttackerPlayers().contains(killed.getName())) {
|
||||
siege.addPointsToDefenders(20);
|
||||
for (final String playerName : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attacker killed! + 20 Defender Points");
|
||||
@@ -79,12 +84,52 @@ public final class KillsListener implements Listener
|
||||
}
|
||||
catch (NullPointerException ex4) {}
|
||||
}
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
}
|
||||
if ( (town != null && town.equals(siege.getTown()) || playerCloseToHomeBlock) ) {
|
||||
this.siegeKill(killed, event);
|
||||
if ( (town != null && town.equals(siege.getTown()) || playerCloseToHomeBlockSiege) ) {
|
||||
this.siegeKill(killed, event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Raid logic
|
||||
for (final Raid raid : RaidData.getRaids()) {
|
||||
final int homeBlockXCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
// final int homeBlockXCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getX() * 16;
|
||||
// final int homeBlockZCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoordRaided) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 300) {
|
||||
playerCloseToHomeBlockRaid = true;
|
||||
}
|
||||
if (raid.getActiveRaiders().contains(killer.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
||||
|
||||
if(raid.getPhase() == RaidPhase.COMBAT) {
|
||||
if (raid.getDefenderPlayers().contains(killed.getName())) {
|
||||
raid.defenderKilledInCombat(event);
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
} else {
|
||||
raid.defenderKilledOutofCombat(event);
|
||||
}
|
||||
}
|
||||
if (raid.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
||||
|
||||
if(raid.getPhase() == RaidPhase.COMBAT) {
|
||||
if (raid.getActiveRaiders().contains(killed.getName())) {
|
||||
raid.raiderKilledInCombat(event);
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
} else {
|
||||
raid.raiderKilledOutofCombat(event);
|
||||
}
|
||||
|
||||
}
|
||||
if ( (town != null && town.equals(raid.getRaidedTown()) || playerCloseToHomeBlockRaid) ) {
|
||||
this.siegeKill(killed, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,120 +137,18 @@ public final class KillsListener implements Listener
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Damage all gear held by the player (and then send them to spawn?)
|
||||
* They don't lose items from death.
|
||||
* @param killed
|
||||
* @param event
|
||||
*/
|
||||
private void siegeKill(final Player killed, final PlayerDeathEvent event) {
|
||||
final Inventory inv = (Inventory)killed.getInventory();
|
||||
for (int i = 0; i < inv.getSize(); ++i) {
|
||||
final ItemStack is = inv.getItem(i);
|
||||
if (is != null && (is.getType() == Material.NETHERITE_AXE || is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.DIAMOND_AXE || is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.IRON_AXE || is.getType() == Material.IRON_SWORD)) {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
final Damageable damageable = (Damageable)meta;
|
||||
if (is.getType() == Material.NETHERITE_SWORD || is.getType() == Material.NETHERITE_AXE) {
|
||||
damageable.setDamage(damageable.getDamage() + 507);
|
||||
if (damageable.getDamage() > 2000) {
|
||||
damageable.setDamage(2030);
|
||||
}
|
||||
}
|
||||
else if (is.getType() == Material.DIAMOND_SWORD || is.getType() == Material.DIAMOND_AXE) {
|
||||
damageable.setDamage(damageable.getDamage() + 390);
|
||||
if (damageable.getDamage() > 1500) {
|
||||
damageable.setDamage(1560);
|
||||
}
|
||||
}
|
||||
else if (is.getType() == Material.IRON_SWORD || is.getType() == Material.IRON_AXE) {
|
||||
damageable.setDamage(damageable.getDamage() + 62);
|
||||
if (damageable.getDamage() > 200) {
|
||||
damageable.setDamage(249);
|
||||
}
|
||||
}
|
||||
meta = (ItemMeta)damageable;
|
||||
is.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
final ItemStack[] armor = killed.getInventory().getArmorContents();
|
||||
for (int j = 0; j < armor.length; ++j) {
|
||||
if (armor[j] != null) {
|
||||
final ItemStack is2 = armor[j];
|
||||
if (is2.getType() == Material.NETHERITE_HELMET || is2.getType() == Material.NETHERITE_CHESTPLATE || is2.getType() == Material.NETHERITE_LEGGINGS || is2.getType() == Material.NETHERITE_BOOTS || is2.getType() == Material.DIAMOND_HELMET || is2.getType() == Material.DIAMOND_CHESTPLATE || is2.getType() == Material.DIAMOND_LEGGINGS || is2.getType() == Material.NETHERITE_BOOTS || is2.getType() == Material.IRON_HELMET || is2.getType() == Material.IRON_CHESTPLATE || is2.getType() == Material.IRON_LEGGINGS || is2.getType() == Material.IRON_BOOTS) {
|
||||
ItemMeta meta2 = is2.getItemMeta();
|
||||
final Damageable damageable2 = (Damageable)meta2;
|
||||
if (is2.getType() == Material.NETHERITE_HELMET) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 101);
|
||||
if (damageable2.getDamage() > 400) {
|
||||
damageable2.setDamage(406);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.NETHERITE_CHESTPLATE) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 148);
|
||||
if (damageable2.getDamage() > 450) {
|
||||
damageable2.setDamage(591);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.NETHERITE_LEGGINGS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 138);
|
||||
if (damageable2.getDamage() > 420) {
|
||||
damageable2.setDamage(554);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.NETHERITE_BOOTS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 120);
|
||||
if (damageable2.getDamage() > 370) {
|
||||
damageable2.setDamage(480);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_HELMET) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 90);
|
||||
if (damageable2.getDamage() > 280) {
|
||||
damageable2.setDamage(362);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_CHESTPLATE) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 132);
|
||||
if (damageable2.getDamage() > 410) {
|
||||
damageable2.setDamage(527);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_LEGGINGS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 123);
|
||||
if (damageable2.getDamage() > 380) {
|
||||
damageable2.setDamage(494);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.DIAMOND_BOOTS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 107);
|
||||
if (damageable2.getDamage() > 330) {
|
||||
damageable2.setDamage(428);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_HELMET) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 41);
|
||||
if (damageable2.getDamage() > 125) {
|
||||
damageable2.setDamage(164);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_CHESTPLATE) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 60);
|
||||
if (damageable2.getDamage() > 190) {
|
||||
damageable2.setDamage(239);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_LEGGINGS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 56);
|
||||
if (damageable2.getDamage() > 180) {
|
||||
damageable2.setDamage(224);
|
||||
}
|
||||
}
|
||||
if (is2.getType() == Material.IRON_BOOTS) {
|
||||
damageable2.setDamage(damageable2.getDamage() + 48);
|
||||
if (damageable2.getDamage() > 150) {
|
||||
damageable2.setDamage(194);
|
||||
}
|
||||
}
|
||||
meta2 = (ItemMeta)damageable2;
|
||||
is2.setItemMeta(meta2);
|
||||
}
|
||||
}
|
||||
}
|
||||
//Helper
|
||||
Helper.damageAllGear(killed);
|
||||
|
||||
//Siege specific
|
||||
Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
|
||||
Reference in new issue
Block a user