refactor: wip update 3

This commit is contained in:
darksaid98 committed 2023-07-02 16:00:22 +02:00
1 parent 4bfa85ce4e
commit 5e8e47934f
51 files changed
+3700 -2053

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@
.mtj.tmp/
*.class
*.jar
*.war
*.oldWar
*.ear
*.nar
hs_err_pid*
+5 -5
View File
@@ -1,13 +1,13 @@
# AlathraWar Version: 1.3.1
## A unique Towny war system for the AlathraMC server
## A unique Towny oldWar system for the AlathraMC server
### Dependencies: Vault, Towny, SiegeWar, TAB
### Commands
+ /war - war commands
+ /siege - siege commands
+ /oldWar - oldWar commands
+ /oldSiege - oldSiege commands
## Siege Point system
@@ -21,6 +21,6 @@ Sieges last 90 minutes. After this time is up the side with the most points wins
## Siege Cost
The attackers must put down $20,000 to start a siege. If they win they get this $20,000 back as well as 1/4th the bank
of the town OR $20,000, whichever is higher. If the defenders win they sieze the $20,000 initially put down on the siege
The attackers must put down $20,000 to start a oldSiege. If they win they get this $20,000 back as well as 1/4th the bank
of the town OR $20,000, whichever is higher. If the defenders win they sieze the $20,000 initially put down on the oldSiege
by the attackers
+10 -27
View File
@@ -7,7 +7,7 @@ plugins {
}
group = "me.ShermansWorld.AlathraWar"
version = "2.1.0"
version = "3.0.0-SNAPSHOT"
description = ""
java {
@@ -47,13 +47,13 @@ repositories {
dependencies {
implementation("org.jetbrains:annotations:24.0.1")
compileOnly("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
implementation("com.github.milkdrinkers:colorparser:1.0.5")
implementation("com.github.milkdrinkers:colorparser:1.0.7")
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
compileOnly("com.palmergames.bukkit.towny:towny:0.98.6.0")
compileOnly("com.palmergames.bukkit.towny:towny:0.99.2.5")
compileOnly("me.neznamy:tab-api:4.0.0")
@@ -61,6 +61,8 @@ dependencies {
compileOnly("dev.jorel:commandapi-annotations:9.0.3")
annotationProcessor("dev.jorel:commandapi-annotations:9.0.3")
compileOnly("com.zaxxer:HikariCP:5.0.1")
compileOnly("me.clip:placeholderapi:2.11.3")
}
@@ -91,11 +93,12 @@ tasks {
fun reloc(originPkg: String, targetPkg: String) = relocate(originPkg, "${project.group}.${targetPkg}")
reloc("dev.jorel.commandapi", "commandapi")
reloc("com.zaxxer.hikari", "hikaricp")
}
runServer {
// Configure the Minecraft version for our task.
minecraftVersion("1.19.3")
minecraftVersion("1.19.4")
}
}
@@ -108,32 +111,12 @@ bukkit {
prefix = "AlathraWar"
version = "${project.version}"
description = "${project.description}"
authors = listOf("ShermansWorld", "NinjaMandalorian", "AubriTheHuman")
contributors = listOf("darksaid98")
authors = listOf("ShermansWorld", "NinjaMandalorian", "AubriTheHuman", "darksaid98")
contributors = listOf()
apiVersion = "1.19"
// Misc properties
load = net.minecrell.pluginyml.bukkit.BukkitPluginDescription.PluginLoadOrder.POSTWORLD // STARTUP or POSTWORLD
depend = listOf("Vault", "Towny")
softDepend = listOf("TAB")
commands {
register("war") {
description = "Used to create, delete, join and leave wars"
usage = "Just use /war!"
}
register("siege") {
description = "Used to start, end, and view sieges"
usage = "Just use /siege!"
}
register("raid") {
description = "Used to start, end, and view raids"
usage = "Just use /raid!"
}
register("alathrawaradmin") {
description = "Used to administrate wars and modify existing events"
usage = "Just use /alathrawaradmin!"
aliases = listOf("awa")
}
}
}
@@ -1,4 +1,4 @@
package me.ShermansWorld.AlathraWar.commands;
package me.ShermansWorld.AlathraWar.deprecated;
import com.palmergames.bukkit.towny.utils.NameUtil;
import org.bukkit.command.Command;
@@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
@Deprecated
public class AdminTabCompletion implements TabCompleter {
List<String> base = List.of("create",
@@ -1,4 +1,4 @@
package me.ShermansWorld.AlathraWar.commands;
package me.ShermansWorld.AlathraWar.deprecated;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
@@ -10,6 +10,9 @@ import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
import org.bukkit.Bukkit;
import org.bukkit.Statistic;
@@ -21,6 +24,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
@Deprecated
public class CommandHelper {
/**
@@ -30,7 +34,7 @@ public class CommandHelper {
*/
public static List<String> getWarNames() {
List<String> out = new ArrayList<>();
for (War w : WarData.getWars()) {
for (OldWar w : WarData.getWars()) {
out.add(w.getName());
}
return out;
@@ -43,7 +47,7 @@ public class CommandHelper {
*/
public static List<String> getSieges() {
List<String> out = new ArrayList<>();
for (Siege s : SiegeData.getSieges()) {
for (OldSiege s : SiegeData.getSieges()) {
out.add(s.getName());
}
return out;
@@ -56,7 +60,7 @@ public class CommandHelper {
*/
public static List<String> getRaids() {
List<String> out = new ArrayList<>();
for (Raid r : RaidData.getRaids()) {
for (OldRaid r : RaidData.getRaids()) {
out.add(r.getName());
}
return out;
@@ -70,7 +74,7 @@ public class CommandHelper {
*/
public static List<String> getWarSides(String name) {
List<String> out = new ArrayList<>();
for (War w : WarData.getWars()) {
for (OldWar w : WarData.getWars()) {
if (w.getName().equalsIgnoreCase(name)) {
out.add(w.getSide1());
out.add(w.getSide2());
@@ -81,7 +85,7 @@ public class CommandHelper {
}
/**
* get list of all towny towns
* getInstance list of all towny towns
*
* @return list of all towns
*/
@@ -94,13 +98,13 @@ public class CommandHelper {
}
/**
* get list of all towny towns in a war
* getInstance list of all towny towns in a war
*
* @return list of all towns in a war
*/
public static List<String> getTownyWarTowns(String war) {
List<String> out = new ArrayList<>();
War w = WarData.getWar(war);
OldWar w = WarData.getWar(war);
if (w == null) return Collections.emptyList();
for (Town t : TownyAPI.getInstance().getTowns()) {
if (w.getSide2Towns().contains(t.getName().toLowerCase()) || w.getSide1Towns().contains(t.getName().toLowerCase())) {
@@ -111,13 +115,13 @@ public class CommandHelper {
}
/**
* get list of all towny towns in a war
* getInstance list of all towny towns in a war
*
* @return list of all nations in a war
*/
public static List<String> getTownyWarNations(String war) {
List<String> out = new ArrayList<>();
War w = WarData.getWar(war);
OldWar w = WarData.getWar(war);
if (w == null) return Collections.emptyList();
for (Town t : TownyAPI.getInstance().getTowns()) {
if (w.getSide2Towns().contains(t.getName().toLowerCase()) || w.getSide1Towns().contains(t.getName().toLowerCase())) {
@@ -134,13 +138,13 @@ public class CommandHelper {
}
/**
* get list of all towny towns on a side in a war
* getInstance list of all towny towns on a side in a war
*
* @return list of all towns in a side of a war
*/
public static List<String> getTownyWarTowns(String war, String side) {
List<String> out = new ArrayList<>();
War w = WarData.getWar(war);
OldWar w = WarData.getWar(war);
if (w == null) return Collections.emptyList();
for (Town t : TownyAPI.getInstance().getTowns()) {
if (side.equalsIgnoreCase(w.getSide1())) {
@@ -163,7 +167,7 @@ public class CommandHelper {
*/
public static List<String> getRaidTowns() {
List<String> out = new ArrayList<>();
for (Raid r : RaidData.getRaids()) {
for (OldRaid r : RaidData.getRaids()) {
out.add(r.getRaidedTown().getName());
}
return out;
@@ -176,14 +180,14 @@ public class CommandHelper {
*/
public static List<String> getSiegeTowns() {
List<String> out = new ArrayList<>();
for (Siege r : SiegeData.getSieges()) {
for (OldSiege r : SiegeData.getSieges()) {
out.add(r.getTown().getName());
}
return out;
}
/**
* get list of all towny nations
* getInstance list of all towny nations
*
* @return list of all nations
*/
@@ -201,7 +205,7 @@ public class CommandHelper {
}
/**
* get a list of all online players
* getInstance a list of all online players
*
* @return list of all players online
*/
@@ -215,7 +219,7 @@ public class CommandHelper {
}
/**
* get a list of all raid phases
* getInstance a list of all raid phases
*
* @return list of all raid phases
*/
@@ -234,7 +238,7 @@ public class CommandHelper {
public static int isPlayerMinuteman(String player) {
Resident res = TownyAPI.getInstance().getResident(player);
if (res != null) {
//get registration time
//getInstance registration time
long regTime = res.getRegistered();
int playTicks = Bukkit.getPlayer(res.getUUID()).getStatistic(Statistic.PLAY_ONE_MINUTE);
int out = 0;
@@ -267,7 +271,7 @@ public class CommandHelper {
for (String s : args) {
log.append(" ").append(s);
}
Main.warLogger.log(Helper.chatLabel() + sender.getName() + " ran command: " + log);
Main.warLogger.log(UtilsChat.getPrefix() + sender.getName() + " ran command: " + log);
}
/**
@@ -13,6 +13,7 @@ import java.util.logging.Level;
/**
* Manages file IO & Deletion for other data classes.
*/
@Deprecated
public class DataManager {
private static final String dataFolder = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
private static DumperOptions options;
@@ -1,12 +1,14 @@
package me.ShermansWorld.AlathraWar;
package me.ShermansWorld.AlathraWar.deprecated;
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 com.palmergames.bukkit.towny.object.metadata.LongDataField;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.utility.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
@@ -35,13 +37,13 @@ They then gain plunder in the form of money from the town's bank,
and then leave.
Raids require at least one person from a town to be online, can only be
done every 24 hours per raided town, every 6 hours in a war per side,
done every 24 hours per raided town, every 6 hours in a oldWar per side,
and raided players may run out of the town, forfeiting the cost of the raid.
The raid is split into two phases:
- STAGING PHASE
v/ Raiders collect at raiding town, joining raid through command
v/ Defenders are given time to get to the town. (travel is announced way in ahead)
v/ Defenders are given time to getInstance to the town. (travel is announced way in ahead)
- COMBAT PHASE
v/ Raiders go to town
v/ Combat occurs
@@ -64,19 +66,20 @@ v/ Raiders on death are teleported to their town spawn.
* @author NinjaMandalorian
* @author ShermansWorld
*/
public class Raid {
@Deprecated
public class OldRaid {
//Ticks between activity, this is lower than siege because more activity is occuring in a raid
private static final int incremental = 40;
final int[] bukkitId;
private final String name;
public final NamespacedKey bossBarKey = new NamespacedKey(Main.getInstance(), "raidBar." + Raid.this.getName());
public final NamespacedKey bossBarKey = new NamespacedKey(Main.getInstance(), "raidBar." + OldRaid.this.getName());
private final String defenders;
public ArrayList<String> activeRaiders = new ArrayList<>();
public ArrayList<String> raiderPlayers = new ArrayList<>();
public ArrayList<String> defenderPlayers = new ArrayList<>();
public Map<WorldCoord, LootBlock> lootedChunks;
private War war;
private OldWar oldWar;
private Town raidedTown;
private Town gatherTown;
private String raiders;
@@ -94,29 +97,29 @@ public class Raid {
/**
* Constructs raid for staging phase
*
* @param war
* @param oldWar
* @param raidedTown
* @param gatherTown
* @param side1AreRaiders
* @param raidTicks
*/
public Raid(final War war, final Town raidedTown, final Town gatherTown,
final boolean side1AreRaiders, final int raidTicks, OfflinePlayer owner) {
public OldRaid(final OldWar oldWar, final Town raidedTown, final Town gatherTown,
final boolean side1AreRaiders, final int raidTicks, OfflinePlayer owner) {
this.bukkitId = new int[1];
this.war = war;
this.oldWar = oldWar;
this.raidTicks = raidTicks;
this.raidedTown = raidedTown;
this.gatherTown = gatherTown;
this.owner = owner;
this.side1AreRaiders = side1AreRaiders;
this.raiders = side1AreRaiders ? war.getSide1() : war.getSide2();
this.defenders = !side1AreRaiders ? war.getSide1() : war.getSide2();
this.raiders = side1AreRaiders ? oldWar.getSide1() : oldWar.getSide2();
this.defenders = !side1AreRaiders ? oldWar.getSide1() : oldWar.getSide2();
this.raiderScore = 0;
this.defenderScore = 0;
//AttackSide-Town
this.name = war.getName() + "-" + raidedTown.getName().toLowerCase();
this.name = oldWar.getName() + "-" + raidedTown.getName().toLowerCase();
this.lootedChunks = new HashMap<>();
}
@@ -124,7 +127,7 @@ public class Raid {
/**
* IDK why this constructor exists but it does
*
* @param war
* @param oldWar
* @param raidedTown
* @param gatherTown
* @param side1AreRaiders
@@ -132,8 +135,8 @@ public class Raid {
* @param activeRaiders
* @param phase
*/
public Raid(final War war, final Town raidedTown, final Town gatherTown, final boolean side1AreRaiders, final int raidTicks, ArrayList<String> activeRaiders, RaidPhase phase, OfflinePlayer owner) {
this(war, raidedTown, gatherTown, side1AreRaiders, raidTicks, owner);
public OldRaid(final OldWar oldWar, final Town raidedTown, final Town gatherTown, final boolean side1AreRaiders, final int raidTicks, ArrayList<String> activeRaiders, RaidPhase phase, OfflinePlayer owner) {
this(oldWar, raidedTown, gatherTown, side1AreRaiders, raidTicks, owner);
this.activeRaiders = activeRaiders;
this.setRaidPhase(phase);
}
@@ -142,33 +145,33 @@ public class Raid {
/**
* Initial Constructor
*
* @param war
* @param oldWar
* @param raidedTown
* @param gatherTown
* @param side1AreRaiders
*/
public Raid(final War war, final Town raidedTown, final Town gatherTown,
final boolean side1AreRaiders, OfflinePlayer owner) {
public OldRaid(final OldWar oldWar, final Town raidedTown, final Town gatherTown,
final boolean side1AreRaiders, OfflinePlayer owner) {
this.bukkitId = new int[1];
// this.activeRaiders = activeRaiders == null ? new ArrayList<>() : activeRaiders;
this.war = war;
this.oldWar = oldWar;
this.raidTicks = 0;
this.raidedTown = raidedTown;
this.gatherTown = gatherTown;
this.owner = owner;
this.side1AreRaiders = side1AreRaiders;
this.raiders = side1AreRaiders ? war.getSide1() : war.getSide2();
this.defenders = !side1AreRaiders ? war.getSide1() : war.getSide2();
this.raiders = side1AreRaiders ? oldWar.getSide1() : oldWar.getSide2();
this.defenders = !side1AreRaiders ? oldWar.getSide1() : oldWar.getSide2();
this.raiderScore = 0;
this.defenderScore = 0;
//AttackSide-Town
this.name = war.getName() + "-" + raidedTown.getName().toLowerCase();
this.name = oldWar.getName() + "-" + raidedTown.getName().toLowerCase();
this.lootedChunks = new HashMap<>();
}
static /* synthetic */ void access$7(final Raid raid, final int raidTicks) {
raid.raidTicks = raidTicks;
static /* synthetic */ void access$7(final OldRaid oldRaid, final int raidTicks) {
oldRaid.raidTicks = raidTicks;
}
/**
@@ -180,11 +183,11 @@ public class Raid {
this.phase = RaidPhase.START;
if (this.side1AreRaiders) {
this.raiderPlayers = this.war.getSide1Players();
this.defenderPlayers = this.war.getSide2Players();
this.raiderPlayers = this.oldWar.getSide1Players();
this.defenderPlayers = this.oldWar.getSide2Players();
} else {
this.raiderPlayers = this.war.getSide2Players();
this.defenderPlayers = this.war.getSide1Players();
this.raiderPlayers = this.oldWar.getSide2Players();
this.defenderPlayers = this.oldWar.getSide1Players();
}
// Sets homeBlock and spawn for town. (So no mid-raid changes.)
@@ -199,15 +202,15 @@ public class Raid {
//set the last raided time to now
raidedTown.addMetaData(new LongDataField("lastRaided", (System.currentTimeMillis() / 1000)));
if (war.getSide1Players().contains(owner.getName())) {
war.setLastRaidTimeSide1((int) (System.currentTimeMillis() / 1000));
} else if (war.getSide2Players().contains(owner.getName())) {
war.setLastRaidTimeSide2((int) (System.currentTimeMillis() / 1000));
if (oldWar.getSide1Players().contains(owner.getName())) {
oldWar.setLastRaidTimeSide1((int) (System.currentTimeMillis() / 1000));
} else if (oldWar.getSide2Players().contains(owner.getName())) {
oldWar.setLastRaidTimeSide2((int) (System.currentTimeMillis() / 1000));
}
setupDisplayBar();
// Creates 10 second looping function for Raid
// Creates 10 second looping function for OldRaid
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(),
getTickLoop(), 0L, incremental);
@@ -218,15 +221,15 @@ public class Raid {
}
/**
* Resumes a Raid (after a server restart e.t.c.)
* Resumes a OldRaid (after a server restart e.t.c.)
*/
public void resume() {
if (this.side1AreRaiders) {
this.raiderPlayers = this.war.getSide1Players();
this.defenderPlayers = this.war.getSide2Players();
this.raiderPlayers = this.oldWar.getSide1Players();
this.defenderPlayers = this.oldWar.getSide2Players();
} else {
this.raiderPlayers = this.war.getSide2Players();
this.defenderPlayers = this.war.getSide1Players();
this.raiderPlayers = this.oldWar.getSide2Players();
this.defenderPlayers = this.oldWar.getSide1Players();
}
// Sets homeBlock and spawn for town. (So no mid-raid changes.)
@@ -241,7 +244,7 @@ public class Raid {
setupDisplayBar();
// Creates 2 second looping function for Raid, restarting this!
// Creates 2 second looping function for OldRaid, restarting this!
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(),
getTickLoop(), 0L, incremental);
@@ -285,12 +288,12 @@ public class Raid {
for (String s : activeRaiders) {
Player pl = Bukkit.getPlayer(s);
if (pl != null)
pl.sendMessage(Helper.chatLabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
pl.sendMessage(UtilsChat.getPrefix() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
}
for (String s : defenderPlayers) {
Player pl = Bukkit.getPlayer(s);
if (pl != null)
pl.sendMessage(Helper.chatLabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
pl.sendMessage(UtilsChat.getPrefix() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
}
this.save();
@@ -301,12 +304,12 @@ public class Raid {
for (String s : activeRaiders) {
Player pl = Bukkit.getPlayer(s);
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Raiders have started looting a town block!");
pl.sendMessage(UtilsChat.getPrefix() + "Raiders have started looting a town block!");
}
for (String s : defenderPlayers) {
Player pl = Bukkit.getPlayer(s);
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Raiders have started looting a town block!");
pl.sendMessage(UtilsChat.getPrefix() + "Raiders have started looting a town block!");
}
}
@@ -316,33 +319,33 @@ public class Raid {
* Begin the Gather phase of the raid
*/
private void startGather() {
Raid.this.phase = RaidPhase.GATHER;
OldRaid.this.phase = RaidPhase.GATHER;
}
/**
* Begin the Travel phase of the raid
*/
private void startTravel() {
Raid.this.phase = RaidPhase.TRAVEL;
Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
OldRaid.this.phase = RaidPhase.TRAVEL;
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The Raiders of "
+ (side1AreRaiders ? OldRaid.this.oldWar.getSide1() : OldRaid.this.oldWar.getSide2())
+ " are coming to raid "
+ Raid.this.getRaidedTown().getName() + "!");
+ OldRaid.this.getRaidedTown().getName() + "!");
//in the case were not at that stage already, if this happens we have an issue
Raid.this.raidTicks = RaidPhase.TRAVEL.startTick;
OldRaid.this.raidTicks = RaidPhase.TRAVEL.startTick;
}
/**
* Begin the combat phase of the raid
*/
private void startCombat() {
Raid.this.phase = RaidPhase.COMBAT;
Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
OldRaid.this.phase = RaidPhase.COMBAT;
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The Raiders of "
+ (side1AreRaiders ? OldRaid.this.oldWar.getSide1() : OldRaid.this.oldWar.getSide2())
+ " have arrived at "
+ Raid.this.getRaidedTown().getName() + " and the fighting has begun!");
+ OldRaid.this.getRaidedTown().getName() + " and the fighting has begun!");
//in the case were not at that stage already
Raid.this.raidTicks = RaidPhase.COMBAT.startTick;
OldRaid.this.raidTicks = RaidPhase.COMBAT.startTick;
}
/**
@@ -354,11 +357,11 @@ public class Raid {
this.addPointsToDefenderScore(40);
for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName);
if (pl != null) pl.sendMessage(Helper.chatLabel() + "Raider killed! -40 Raid Score");
if (pl != null) pl.sendMessage(UtilsChat.getPrefix() + "Raider killed! -40 OldRaid Score");
}
for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName);
if (pl != null) pl.sendMessage(Helper.chatLabel() + "Raider killed! -40 Raid Score");
if (pl != null) pl.sendMessage(UtilsChat.getPrefix() + "Raider killed! -40 OldRaid Score");
}
}
@@ -369,18 +372,18 @@ public class Raid {
this.addPointsToRaiderScore(20);
for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName);
if (pl != null) pl.sendMessage(Helper.chatLabel() + "Defender killed! +20 Raid Score");
if (pl != null) pl.sendMessage(UtilsChat.getPrefix() + "Defender killed! +20 OldRaid Score");
}
for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName);
if (pl != null) pl.sendMessage(Helper.chatLabel() + "Defender killed! +20 Raid Score");
if (pl != null) pl.sendMessage(UtilsChat.getPrefix() + "Defender killed! +20 OldRaid Score");
}
// //tp to raid town spawn
// final Player killed = event.getEntity();
// if (this.getActiveRaiders().contains(killed.getName())) {
// // killed.teleport(this.getGatherTown().getSpawn());
//// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died raiding and have been teleported back to your town's spawn.");
//// killed.sendMessage(String.valueOf(UtilsChat.getPrefix()) + "You died raiding and have been teleported back to your town's spawn.");
// }
}
@@ -393,12 +396,12 @@ public class Raid {
for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName);
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Raider killed before combat, no points awarded and death treated normally.");
pl.sendMessage(UtilsChat.getPrefix() + "Raider killed before combat, no points awarded and death treated normally.");
}
for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName);
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Raider killed before combat, no points awarded and death treated normally.");
pl.sendMessage(UtilsChat.getPrefix() + "Raider killed before combat, no points awarded and death treated normally.");
}
//
// //tp to gather town spawn
@@ -415,7 +418,7 @@ public class Raid {
if (this.getDefenderSide().contains(killed.getKiller().getName())) {
try {
killed.getKiller().teleport(this.getRaidedTown().getSpawn());
killed.getKiller().sendMessage(Helper.chatLabel() + "You killed a raider before the raid began and have been teleported back to the defending town.");
killed.getKiller().sendMessage(UtilsChat.getPrefix() + "You killed a raider before the raid began and have been teleported back to the defending town.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
@@ -430,19 +433,19 @@ public class Raid {
for (final String playerName : this.getActiveRaiders()) {
Player pl = Bukkit.getPlayer(playerName);
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Defender killed before combat, no points awarded and death treated normally.");
pl.sendMessage(UtilsChat.getPrefix() + "Defender killed before combat, no points awarded and death treated normally.");
}
for (final String playerName : this.getDefenderPlayers()) {
Player pl = Bukkit.getPlayer(playerName);
if (pl != null)
pl.sendMessage(Helper.chatLabel() + "Defender killed before combat, no points awarded and death treated normally.");
pl.sendMessage(UtilsChat.getPrefix() + "Defender killed before combat, no points awarded and death treated normally.");
}
//tp to raid town spawn
final Player killed = event.getEntity();
// if (this.getDefenders().contains(killed.getName())) {
//// killed.teleport(this.getGatherTown().getSpawn());
//// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before being raided and have been teleported back to the defending town's spawn.");
//// killed.sendMessage(String.valueOf(UtilsChat.getPrefix()) + "You died before being raided and have been teleported back to the defending town's spawn.");
// }
//teleport the killer back to the gather towns spawn
@@ -450,7 +453,7 @@ public class Raid {
if (this.getActiveRaiders().contains(killed.getKiller().getName())) {
try {
killed.getKiller().teleport(this.getGatherTown().getSpawn());
killed.getKiller().sendMessage(Helper.chatLabel() + "You killed a defender before the raid began and have been teleported back to the gather town.");
killed.getKiller().sendMessage(UtilsChat.getPrefix() + "You killed a defender before the raid began and have been teleported back to the gather town.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
@@ -472,7 +475,7 @@ public class Raid {
if (factor > 3.0) factor = 3.0;
if (factor < 0) factor = 0.0;
Bukkit.broadcastMessage(Helper.chatLabel() + "The raiders from " + this.raiders
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The raiders from " + this.raiders
+ " have successfully raided " + this.raidedTown.getName() + "!");
/*
@@ -499,20 +502,20 @@ public class Raid {
//cap based on town bank
if (this.raidedTown.getAccount().getHoldingBalance() > 10000) {
//large towns get raided for alot more, cap at 1/10th the town holdings
//large towns getInstance raided for alot more, cap at 1/10th the town holdings
double maxVal = Math.floor(this.raidedTown.getAccount().getHoldingBalance()) / 10.0;
if (amt > maxVal) amt = maxVal;
this.raidedTown.getAccount().withdraw(amt, "war loot");
this.raidedTown.getAccount().withdraw(amt, "oldWar loot");
} else if (this.raidedTown.getAccount().getHoldingBalance() < 1000) {
//generate $1000 if the town doesnt have it
double maxVal = 1000;
if (amt > maxVal) amt = maxVal;
this.raidedTown.getAccount().withdraw(this.raidedTown.getAccount().getHoldingBalance(), "war loot");
this.raidedTown.getAccount().withdraw(this.raidedTown.getAccount().getHoldingBalance(), "oldWar loot");
} else {
//give $1000 for the raid win
double maxVal = 1000;
if (amt > maxVal) amt = maxVal;
this.raidedTown.getAccount().withdraw(amt, "war loot");
this.raidedTown.getAccount().withdraw(amt, "oldWar loot");
}
//broadcast victory
@@ -532,9 +535,9 @@ public class Raid {
Main.econ.depositPlayer(offlinePlayer, amt);
if (this.side1AreRaiders) {
war.addSide1Points(15);
oldWar.addSide1Points(15);
} else {
war.addSide2Points(15);
oldWar.addSide2Points(15);
}
stop();
@@ -546,7 +549,7 @@ public class Raid {
public void defendersWin(int raiderScore, int defenderScore) {
//TODO finalize payout
/*
If defenders win, they get the 1000 deposit.
If defenders win, they getInstance the 1000 deposit.
*/
//at a raid score of 699.9999, this results in 0, 700 is considered raider victory
@@ -559,35 +562,35 @@ public class Raid {
if (factor < 0) factor = 0.0;
if (factor <= 0.5) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The defenders from " + this.defenders
+ " have barely pushed back the raiders of " + this.raiders + ". More has been lost than gained.");
Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName()
Bukkit.broadcastMessage(UtilsChat.getPrefix() + this.raidedTown.getName()
+ " has recovered part of the attackers' raid chest, valued at $500");
Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(500, "Raid chest");
this.raidedTown.getAccount().deposit(500, "OldRaid chest");
} else if (factor <= 1.5) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The defenders from " + this.defenders
+ " have fended off the raiders of " + this.raiders + "!");
Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName()
Bukkit.broadcastMessage(UtilsChat.getPrefix() + this.raidedTown.getName()
+ " has recovered the attackers' raid chest, valued at $1000");
Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(1000, "Raid chest");
this.raidedTown.getAccount().deposit(1000, "OldRaid chest");
} else if (factor <= 3.0) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The defenders from " + this.defenders
+ " have wholly defeated the raiders of " + this.raiders + "! They barely broke the walls.");
Bukkit.broadcastMessage(Helper.chatLabel() + this.raidedTown.getName()
Bukkit.broadcastMessage(UtilsChat.getPrefix() + this.raidedTown.getName()
+ " has recovered the attackers' raid chest, valued at $1000.");
Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(1000, "Raid chest");
this.raidedTown.getAccount().deposit(1000, "OldRaid chest");
}
if (this.side1AreRaiders) {
war.addSide2Points(15);
oldWar.addSide2Points(15);
} else {
war.addSide1Points(15);
oldWar.addSide1Points(15);
}
stop();
@@ -599,7 +602,7 @@ public class Raid {
public void noWinner() {
//TODO finalize payout
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders from " + this.defenders
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The defenders from " + this.defenders
+ " didn't push back the raiders of " + this.raiders + ". Yet no loot was taken, raid considered a draw.");
Main.warLogger
.log("No one won the raid of " + this.raidedTown.getName() + "!");
@@ -646,12 +649,12 @@ public class Raid {
return this.name;
}
public War getWar() {
return this.war;
public OldWar getWar() {
return this.oldWar;
}
public void setWar(final War war) {
this.war = war;
public void setWar(final OldWar oldWar) {
this.oldWar = oldWar;
}
public Town getRaidedTown() {
@@ -802,51 +805,51 @@ public class Raid {
gatherTown.setHomeBlock(homeBlockGather);
gatherTown.setSpawn(townSpawnGather);
}
if (Raid.this.side1AreRaiders) {
Raid.this.raiderPlayers = Raid.this.war.getSide1Players();
Raid.this.defenderPlayers = Raid.this.war.getSide2Players();
if (OldRaid.this.side1AreRaiders) {
OldRaid.this.raiderPlayers = OldRaid.this.oldWar.getSide1Players();
OldRaid.this.defenderPlayers = OldRaid.this.oldWar.getSide2Players();
} else {
Raid.this.raiderPlayers = Raid.this.war.getSide2Players();
Raid.this.defenderPlayers = Raid.this.war.getSide1Players();
OldRaid.this.raiderPlayers = OldRaid.this.oldWar.getSide2Players();
OldRaid.this.defenderPlayers = OldRaid.this.oldWar.getSide1Players();
}
raidTicks += incremental;
//check for end
if (Raid.this.raidTicks >= RaidPhase.END.startTick && Raid.this.phase == RaidPhase.COMBAT) {
Raid.this.phase = RaidPhase.END;
if (OldRaid.this.raidTicks >= RaidPhase.END.startTick && OldRaid.this.phase == RaidPhase.COMBAT) {
OldRaid.this.phase = RaidPhase.END;
}
//check and start travel phase
if (Raid.this.raidTicks >= RaidPhase.TRAVEL.startTick && Raid.this.phase == RaidPhase.GATHER) {
if (OldRaid.this.raidTicks >= RaidPhase.TRAVEL.startTick && OldRaid.this.phase == RaidPhase.GATHER) {
startTravel();
}
//check and start combat phase
if (Raid.this.raidTicks >= RaidPhase.COMBAT.startTick && Raid.this.phase == RaidPhase.TRAVEL) {
if (OldRaid.this.raidTicks >= RaidPhase.COMBAT.startTick && OldRaid.this.phase == RaidPhase.TRAVEL) {
startCombat();
}
//check and start gather phase
if (Raid.this.raidTicks >= RaidPhase.GATHER.startTick && Raid.this.phase == RaidPhase.START) {
if (OldRaid.this.raidTicks >= RaidPhase.GATHER.startTick && OldRaid.this.phase == RaidPhase.START) {
startGather();
}
if (Raid.this.phase == RaidPhase.END) {
if (OldRaid.this.phase == RaidPhase.END) {
//TODO: fix raid scoring
//for raiders to win enough money, they need a significant up from the defenders, tie given to defender
if (Raid.this.raiderScore > Raid.this.defenderScore) {
Raid.this.raidersWin(Raid.this.owner, Raid.this.raiderScore, Raid.this.defenderScore);
if (OldRaid.this.raiderScore > OldRaid.this.defenderScore) {
OldRaid.this.raidersWin(OldRaid.this.owner, OldRaid.this.raiderScore, OldRaid.this.defenderScore);
} else {
Raid.this.defendersWin(Raid.this.raiderScore, Raid.this.defenderScore);
OldRaid.this.defendersWin(OldRaid.this.raiderScore, OldRaid.this.defenderScore);
}
}
//Raid gather phase behavior
if (Raid.this.phase == RaidPhase.GATHER) {
//OldRaid gather phase behavior
if (OldRaid.this.phase == RaidPhase.GATHER) {
//Broadcast
if (raidTicks % 6000 == 0) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of "
+ Raid.this.getRaidedTown().getName() + " will begin in " + ((RaidPhase.TRAVEL.startTick - raidTicks) / 20 / 60) + " minutes!");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The raid of "
+ OldRaid.this.getRaidedTown().getName() + " will begin in " + ((RaidPhase.TRAVEL.startTick - raidTicks) / 20 / 60) + " minutes!");
Bukkit.broadcastMessage(
"The Raiders are gathering at " + getGatherTown().getName() + " before making the journey over!");
}
@@ -857,16 +860,16 @@ public class Raid {
try {
Player p = Bukkit.getPlayer(playerName);
if (p != null) {
ArrayList<WorldCoord> cluster = Helper.getCluster(Raid.this.getGatherTown().getHomeBlock().getWorldCoord());
ArrayList<WorldCoord> cluster = Utils.getCluster(OldRaid.this.getGatherTown().getHomeBlock().getWorldCoord());
if (!cluster.contains(WorldCoord.parseWorldCoord(p))) {
if (p.equals(owner)) {
p.teleport(gatherTown.getSpawn());
p.sendMessage(Helper.chatLabel() + "You cannot leave the gather town. As raid party leader, you have remained in the party. To stop the raid type /raid abandon");
p.sendMessage(Helper.chatLabel() + "You have been teleported to the gather town's spawn.");
p.sendMessage(UtilsChat.getPrefix() + "You cannot leave the gather town. As raid party leader, you have remained in the party. To stop the raid type /raid abandon");
p.sendMessage(UtilsChat.getPrefix() + "You have been teleported to the gather town's spawn.");
} else {
Raid.this.removeActiveRaider(p.getName());
p.sendMessage(Helper.chatLabel() + "By leaving the gathering town you have left the raid on " + Raid.this.getRaidedTown().getName() + "!");
p.sendMessage(Helper.chatLabel() + "To rejoin, do /raid join [war] [town]");
OldRaid.this.removeActiveRaider(p.getName());
p.sendMessage(UtilsChat.getPrefix() + "By leaving the gathering town you have left the raid on " + OldRaid.this.getRaidedTown().getName() + "!");
p.sendMessage(UtilsChat.getPrefix() + "To rejoin, do /raid join [oldWar] [town]");
}
}
}
@@ -876,23 +879,23 @@ public class Raid {
}
}
//Raid Travel phase behavior
else if (Raid.this.phase == RaidPhase.TRAVEL) {
//OldRaid Travel phase behavior
else if (OldRaid.this.phase == RaidPhase.TRAVEL) {
//Report
if (raidTicks % 2400 == 0) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The Raiders of "
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The Raiders of "
+ (side1AreRaiders ? OldRaid.this.oldWar.getSide1() : OldRaid.this.oldWar.getSide2())
+ " are on their way to raid "
+ Raid.this.getRaidedTown().getName() + "!");
+ OldRaid.this.getRaidedTown().getName() + "!");
}
//Check if a player has arrived at the town (in it, or within 200 blocks) and if so start combat
for (String player : activeRaiders) {
try {
boolean playerCloseToHomeBlockRaid = false;
final int homeBlockXCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
final int homeBlockZCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
final int homeBlockXCoordRaided = OldRaid.this.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
final int homeBlockZCoordRaided = OldRaid.this.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
Player p = Bukkit.getPlayer(player);
if (p != null) {
//Carryover from sieges
@@ -901,7 +904,7 @@ public class Raid {
}
WorldCoord playercoord = WorldCoord.parseWorldCoord(Bukkit.getPlayer(player));
if (Raid.this.getRaidedTown().hasTownBlock(playercoord) || playerCloseToHomeBlockRaid) {
if (OldRaid.this.getRaidedTown().hasTownBlock(playercoord) || playerCloseToHomeBlockRaid) {
startCombat();
}
}
@@ -911,40 +914,40 @@ public class Raid {
}
}
//Raid combat phase behavior
else if (Raid.this.phase == RaidPhase.COMBAT) {
//OldRaid combat phase behavior
else if (OldRaid.this.phase == RaidPhase.COMBAT) {
//Report
if (Raid.this.raidTicks % 6000 == 0) {
Bukkit.broadcastMessage(Helper.chatLabel() + "Report on the raid of "
+ Raid.this.getRaidedTown().getName() + ":");
if (OldRaid.this.raidTicks % 6000 == 0) {
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "Report on the raid of "
+ OldRaid.this.getRaidedTown().getName() + ":");
Bukkit.broadcastMessage(
"Raider Score - " + Raid.this.raiderScore);
"Raider Score - " + OldRaid.this.raiderScore);
Bukkit.broadcastMessage(
"Defender Score - " + Raid.this.defenderScore);
"Defender Score - " + OldRaid.this.defenderScore);
Bukkit.broadcastMessage(
"Chunks Looted - " + Raid.this.lootedChunks.size() + "/" + raidedTown.getTownBlocks().size());
"Chunks Looted - " + OldRaid.this.lootedChunks.size() + "/" + raidedTown.getTownBlocks().size());
}
//Looting chunks
for (String name : Raid.this.getActiveRaiders()) {
for (String name : OldRaid.this.getActiveRaiders()) {
Player p = Bukkit.getPlayer(name);
if (p != null) {
WorldCoord wc = WorldCoord.parseWorldCoord(p);
if (p.isSneaking()) {
//check if our chunk is looted, if so skip this player
//Idk if thisll work but if it do then ye
if (Raid.this.lootedChunks.containsKey(wc)) {
if (Raid.this.lootedChunks.get(wc).finished) {
p.sendMessage(Helper.chatLabel() + "This chunk is already looted, try another.");
if (OldRaid.this.lootedChunks.containsKey(wc)) {
if (OldRaid.this.lootedChunks.get(wc).finished) {
p.sendMessage(UtilsChat.getPrefix() + "This chunk is already looted, try another.");
} else {
doLootAt(p, wc);
}
} else {
if (Raid.this.getRaidedTown().hasTownBlock(wc)) {
if (OldRaid.this.getRaidedTown().hasTownBlock(wc)) {
doLootAt(p, wc);
} else {
p.sendMessage(Helper.chatLabel() + "This space is not part of the raided town, you cannot loot this area.");
p.sendMessage(UtilsChat.getPrefix() + "This space is not part of the raided town, you cannot loot this area.");
}
}
}
@@ -961,17 +964,17 @@ public class Raid {
BossBar bossBar = Bukkit.getBossBar(bossBarKey);
if (bossBar == null) bossBar = createNewDisplayBar();
bossBar.setTitle(String.format("%d -- Raiders -Raid Score- Defenders -- %d", Raid.this.raiderScore, Raid.this.defenderScore));
bossBar.setProgress((Raid.this.raiderScore + 0.5D) / ((Raid.this.raiderScore + Raid.this.defenderScore) + 1.0D));
bossBar.setTitle(String.format("%d -- Raiders -OldRaid Score- Defenders -- %d", OldRaid.this.raiderScore, OldRaid.this.defenderScore));
bossBar.setProgress((OldRaid.this.raiderScore + 0.5D) / ((OldRaid.this.raiderScore + OldRaid.this.defenderScore) + 1.0D));
for (String s : Raid.this.getActiveRaiders()) {
for (String s : OldRaid.this.getActiveRaiders()) {
Player p = Bukkit.getPlayer(s);
if (p != null) {
if (!bossBar.getPlayers().contains(p)) bossBar.addPlayer(p);
}
}
for (String s : Raid.this.getDefenderPlayers()) {
for (String s : OldRaid.this.getDefenderPlayers()) {
Player p = Bukkit.getPlayer(s);
if (p != null) {
if (!bossBar.getPlayers().contains(p)) bossBar.addPlayer(p);
@@ -983,14 +986,14 @@ public class Raid {
BossBar bossBar = Bukkit.getBossBar(bossBarKey);
if (bossBar == null) bossBar = createNewDisplayBar();
for (String s : Raid.this.getActiveRaiders()) {
for (String s : OldRaid.this.getActiveRaiders()) {
Player p = Bukkit.getPlayer(s);
if (p != null) {
bossBar.addPlayer(p);
}
}
for (String s : Raid.this.getDefenderPlayers()) {
for (String s : OldRaid.this.getDefenderPlayers()) {
Player p = Bukkit.getPlayer(s);
if (p != null) bossBar.addPlayer(p);
}
@@ -1006,7 +1009,7 @@ public class Raid {
}
public BossBar createNewDisplayBar() {
return Bukkit.createBossBar(bossBarKey, String.format("%d -- Raiders -Raid Score- Defenders -- %d", Raid.this.raiderScore, Raid.this.defenderScore), BarColor.RED, BarStyle.SOLID);
return Bukkit.createBossBar(bossBarKey, String.format("%d -- Raiders -OldRaid Score- Defenders -- %d", OldRaid.this.raiderScore, OldRaid.this.defenderScore), BarColor.RED, BarStyle.SOLID);
}
public void save() {
@@ -1,10 +1,11 @@
package me.ShermansWorld.AlathraWar;
package me.ShermansWorld.AlathraWar.deprecated;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.*;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import org.bukkit.*;
@@ -15,7 +16,8 @@ import org.bukkit.entity.Player;
import java.util.ArrayList;
public class Siege {
@Deprecated
public class OldSiege {
public static final int maxSiegeTicks = 72000; // 60 minute tick constant
public final NamespacedKey bossBarKey;
@@ -23,7 +25,7 @@ public class Siege {
public ArrayList<String> defenderPlayers;
public ArrayList<Location> beaconLocs;
int[] bukkitId;
private War war; // War which siege belongs to
private OldWar oldWar; // OldWar which siege belongs to
private Town town; // Town of the siege
private boolean side1AreAttackers; // bool of if side1 being attacker
private int attackerPoints;
@@ -34,19 +36,19 @@ public class Siege {
private Location townSpawn;
public Siege(final War war, final Town town, OfflinePlayer siegeLeader) {
public OldSiege(final OldWar oldWar, final Town town, OfflinePlayer siegeLeader) {
this.siegeTicks = 0;
this.bukkitId = new int[1];
this.attackerPlayers = new ArrayList<>();
this.defenderPlayers = new ArrayList<>();
this.beaconLocs = new ArrayList<>();
this.war = war;
this.oldWar = oldWar;
this.town = town;
this.siegeLeader = siegeLeader;
bossBarKey = new NamespacedKey(Main.getInstance(), "siegeBar." + this.getName());
side1AreAttackers = war.getState(town.getName()) == TownWarState.SIDE2;
side1AreAttackers = oldWar.getState(town.getName()) == TownWarState.SIDE2;
}
/**
@@ -85,7 +87,7 @@ public class Siege {
public void stop() {
deleteDisplayBar();
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
this.war.getSieges().remove(this);
this.oldWar.getSieges().remove(this);
SiegeData.removeSiege(this);
}
@@ -100,26 +102,26 @@ public class Siege {
town.setHomeBlock(homeBlock);
town.setSpawn(townSpawn);
}
if (Siege.this.side1AreAttackers) {
Siege.this.attackerPlayers = Siege.this.war.getSide1Players();
Siege.this.defenderPlayers = Siege.this.war.getSide2Players();
if (OldSiege.this.side1AreAttackers) {
OldSiege.this.attackerPlayers = OldSiege.this.oldWar.getSide1Players();
OldSiege.this.defenderPlayers = OldSiege.this.oldWar.getSide2Players();
} else {
Siege.this.attackerPlayers = Siege.this.war.getSide2Players();
Siege.this.defenderPlayers = Siege.this.war.getSide1Players();
OldSiege.this.attackerPlayers = OldSiege.this.oldWar.getSide2Players();
OldSiege.this.defenderPlayers = OldSiege.this.oldWar.getSide1Players();
}
if (Siege.this.siegeTicks >= maxSiegeTicks) {
Bukkit.getServer().getScheduler().cancelTask(Siege.this.bukkitId[0]);
SiegeData.removeSiege(Siege.this);
if (Siege.this.attackerPoints > Siege.this.defenderPoints) {
Siege.this.attackersWin(Siege.this.siegeLeader);
if (OldSiege.this.siegeTicks >= maxSiegeTicks) {
Bukkit.getServer().getScheduler().cancelTask(OldSiege.this.bukkitId[0]);
SiegeData.removeSiege(OldSiege.this);
if (OldSiege.this.attackerPoints > OldSiege.this.defenderPoints) {
OldSiege.this.attackersWin(OldSiege.this.siegeLeader);
} else {
Siege.this.defendersWin();
OldSiege.this.defendersWin();
}
} else {
boolean attackersAreOnHomeBlock = false;
boolean defendersAreOnHomeBlock = false;
siegeTicks = siegeTicks + 200;
for (final String playerName : Siege.this.attackerPlayers) {
for (final String playerName : OldSiege.this.attackerPlayers) {
Player pl = Main.getInstance().getServer().getPlayer(playerName);
try {
if (pl != null) {
@@ -138,10 +140,10 @@ public class Siege {
}
}
} catch (NotRegisteredException ignored) {
Main.warLogger.log(Helper.chatLabel() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
Main.warLogger.log(UtilsChat.getPrefix() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
}
}
for (final String playerName : Siege.this.defenderPlayers) {
for (final String playerName : OldSiege.this.defenderPlayers) {
Player pl = Main.getInstance().getServer().getPlayer(playerName);
try {
if (pl != null) {
@@ -160,22 +162,22 @@ public class Siege {
}
}
} catch (NotRegisteredException ignored) {
Main.warLogger.log(Helper.chatLabel() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
Main.warLogger.log(UtilsChat.getPrefix() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
}
}
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) { // Contested
if (this.homeBlockControl != 1) {
for (final String playerName : Siege.this.attackerPlayers) {
for (final String playerName : OldSiege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
+ "HomeBlock at " + OldSiege.this.town.getName() + " contested!");
} catch (NullPointerException ex5) {
}
}
for (final String playerName : Siege.this.defenderPlayers) {
for (final String playerName : OldSiege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
+ "HomeBlock at " + OldSiege.this.town.getName() + " contested!");
} catch (NullPointerException ex6) {
}
}
@@ -183,54 +185,54 @@ public class Siege {
this.homeBlockControl = 1;
} else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) { // Attackers
if (this.homeBlockControl != 2) {
for (final String playerName : Siege.this.attackerPlayers) {
for (final String playerName : OldSiege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
+ "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
+ OldSiege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex7) {
}
}
for (final String playerName : Siege.this.defenderPlayers) {
for (final String playerName : OldSiege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
+ "Attackers have captured the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
+ OldSiege.this.town.getName() + "! +1 Attacker Points per second");
} catch (NullPointerException ex8) {
}
}
}
this.homeBlockControl = 2;
Siege.this.addPointsToAttackers(10);
OldSiege.this.addPointsToAttackers(10);
} else { // Defenders / None
if (this.homeBlockControl != 3) {
for (final String playerName : Siege.this.attackerPlayers) {
for (final String playerName : OldSiege.this.attackerPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
+ "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second");
+ OldSiege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex9) {
}
}
for (final String playerName : Siege.this.defenderPlayers) {
for (final String playerName : OldSiege.this.defenderPlayers) {
try {
Bukkit.getPlayer(playerName).sendMessage(Helper.chatLabel()
Bukkit.getPlayer(playerName).sendMessage(UtilsChat.getPrefix()
+ "Defenders retain control of the HomeBlock at "
+ Siege.this.town.getName() + "! +1 Defender Points per second");
+ OldSiege.this.town.getName() + "! +1 Defender Points per second");
} catch (NullPointerException ex10) {
}
}
}
Siege.this.addPointsToDefenders(10);
OldSiege.this.addPointsToDefenders(10);
this.homeBlockControl = 3;
}
if (Siege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes
Bukkit.broadcastMessage(Helper.chatLabel() + "Report on the siege of "
+ Siege.this.town.getName() + ":");
if (OldSiege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "Report on the siege of "
+ OldSiege.this.town.getName() + ":");
Bukkit.broadcastMessage(
"Attacker Points - " + Siege.this.attackerPoints);
"Attacker Points - " + OldSiege.this.attackerPoints);
Bukkit.broadcastMessage(
"Defender Points - " + Siege.this.defenderPoints);
"Defender Points - " + OldSiege.this.defenderPoints);
}
if (siegeTicks % 1200 == 0) { // Saves every minute
save();
@@ -247,30 +249,30 @@ public class Siege {
public void attackersWin(final OfflinePlayer siegeLeader) {
final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
Nation nation = null;
Bukkit.broadcastMessage(Helper.chatLabel() + "The attackers have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The attackers have won the siege of " + this.town.getName() + "!");
try {
nation = resident.getTown().getNation();
} catch (Exception e) {
}
if (nation != null) {
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + this.town.getName()
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + this.town.getName()
+ " has been placed under occupation by " + nation.getName() + "!");
}
Main.econ.depositPlayer(siegeLeader, 2500.0);
double amt = 0.0;
if (this.town.getAccount().getHoldingBalance() > 10000.0) {
amt = Math.floor(this.town.getAccount().getHoldingBalance()) / 4.0;
this.town.getAccount().withdraw(amt, "war loot");
this.town.getAccount().withdraw(amt, "oldWar loot");
} else {
if (this.town.getAccount().getHoldingBalance() < 2500.0) {
amt = this.town.getAccount().getHoldingBalance();
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + this.town.getName()
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + this.town.getName()
+ " has been destroyed by " + this.getAttackerSide() + "!");
TownyUniverse.getInstance().getDataSource().deleteTown(this.town);
Main.econ.depositPlayer(siegeLeader, amt);
return;
}
this.town.getAccount().withdraw(2500.0, "war loot");
this.town.getAccount().withdraw(2500.0, "oldWar loot");
amt = 2500.0;
}
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
@@ -280,9 +282,9 @@ public class Siege {
Main.econ.depositPlayer(siegeLeader, amt);
if (side1AreAttackers) {
war.addSide1Points(50);
oldWar.addSide1Points(50);
} else {
war.addSide2Points(50);
oldWar.addSide2Points(50);
}
stop();
@@ -290,17 +292,17 @@ public class Siege {
}
public void defendersWin() {
this.town.getAccount().deposit(2500.0, "War chest");
Bukkit.broadcastMessage(Helper.chatLabel() + "The defenders have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(Helper.chatLabel() + this.town.getName()
+ " has recovered the attackers' war chest, valued at $2,500");
this.town.getAccount().deposit(2500.0, "OldWar chest");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The defenders have won the siege of " + this.town.getName() + "!");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + this.town.getName()
+ " has recovered the attackers' oldWar chest, valued at $2,500");
Main.warLogger
.log(war.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
.log(oldWar.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
if (side1AreAttackers) {
war.addSide2Points(50);
oldWar.addSide2Points(50);
} else {
war.addSide1Points(50);
oldWar.addSide1Points(50);
}
stop();
@@ -311,10 +313,10 @@ public class Siege {
* No winnder declared
*/
public void noWinner() {
Bukkit.broadcastMessage(Helper.chatLabel() + "The siege of " + this.town.getName() + " was a draw!");
Bukkit.broadcastMessage(Helper.chatLabel() + "No money has been recovered.");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The siege of " + this.town.getName() + " was a draw!");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "No money has been recovered.");
Main.warLogger
.log(war.getName() + ": No one won the siege of " + this.town.getName() + "!");
.log(oldWar.getName() + ": No one won the siege of " + this.town.getName() + "!");
stop();
clearBeacon();
}
@@ -420,12 +422,12 @@ public class Siege {
this.defenderPoints += points;
}
public War getWar() {
return this.war;
public OldWar getWar() {
return this.oldWar;
}
public void setWar(final War war) {
this.war = war;
public void setWar(final OldWar oldWar) {
this.oldWar = oldWar;
}
public Town getTown() {
@@ -449,9 +451,9 @@ public class Siege {
*/
public String getAttackerSide() {
if (side1AreAttackers) {
return war.getSide1();
return oldWar.getSide1();
} else {
return war.getSide2();
return oldWar.getSide2();
}
}
@@ -460,9 +462,9 @@ public class Siege {
*/
public String getDefenderSide() {
if (side1AreAttackers) {
return war.getSide2();
return oldWar.getSide2();
} else {
return war.getSide1();
return oldWar.getSide1();
}
}
@@ -470,7 +472,7 @@ public class Siege {
BossBar bossBar = Bukkit.getBossBar(bossBarKey);
if (bossBar == null) bossBar = createNewDisplayBar();
bossBar.setTitle(String.format("%d -- Attackers -Siege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints));
bossBar.setTitle(String.format("%d -- Attackers -OldSiege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints));
bossBar.setProgress((this.attackerPoints + 0.5D) / ((this.attackerPoints + this.defenderPoints) + 1.0D));
for (String s : this.getAttackerPlayers()) {
@@ -516,7 +518,7 @@ public class Siege {
public BossBar createNewDisplayBar() {
return Bukkit.createBossBar(bossBarKey, String.format("%d -- Attackers -Siege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints), BarColor.YELLOW, BarStyle.SOLID);
return Bukkit.createBossBar(bossBarKey, String.format("%d -- Attackers -OldSiege Score- Defenders -- %d", this.attackerPoints, this.defenderPoints), BarColor.YELLOW, BarStyle.SOLID);
}
public int getAttackerPoints() {
@@ -1,10 +1,10 @@
package me.ShermansWorld.AlathraWar;
package me.ShermansWorld.AlathraWar.deprecated;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.commands.CommandHelper;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.data.DataManager;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
@@ -14,11 +14,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class War {
@Deprecated
public class OldWar {
// References
private final ArrayList<Siege> sieges = new ArrayList<>();
private final ArrayList<Raid> raids = new ArrayList<>();
private final ArrayList<OldSiege> oldSieges = new ArrayList<>();
private final ArrayList<OldRaid> oldRaids = new ArrayList<>();
// Object Fields
private final UUID uuid; // TODO Actually convert to using UUID for identifying this war
private String name;
@@ -33,13 +34,13 @@ public class War {
private int lastRaidTimeSide2 = 0;
/**
* War Constructor
* OldWar Constructor
*
* @param name - Name of war
* @param side1 - Side 1 name
* @param side2 - Side 2 name
*/
public War(final String name, final String side1, final String side2) {
public OldWar(final String name, final String side1, final String side2) {
this.uuid = generateUUID();
this.name = name;
this.side1 = side1;
@@ -52,7 +53,7 @@ public class War {
Town town = TownyAPI.getInstance().getTown(townString);
if (town != null) {
for (Resident res : town.getResidents()) {
//Minuteman countermeasure! if they are they get skipped
//Minuteman countermeasure! if they are they getInstance skipped
if (CommandHelper.isPlayerMinuteman(res.getName()) == 0) {
returnList.add(res.getName());
}
@@ -252,20 +253,20 @@ public class War {
surrenderedTowns = towns;
}
public ArrayList<Siege> getSieges() {
return sieges;
public ArrayList<OldSiege> getSieges() {
return oldSieges;
}
public void addSiege(Siege siege) {
sieges.add(siege);
public void addSiege(OldSiege oldSiege) {
oldSieges.add(oldSiege);
}
public ArrayList<Raid> getRaids() {
return raids;
public ArrayList<OldRaid> getRaids() {
return oldRaids;
}
public void addRaid(Raid raid) {
raids.add(raid);
public void addRaid(OldRaid oldRaid) {
oldRaids.add(oldRaid);
}
/**
@@ -329,8 +330,8 @@ public class War {
side2Points += points;
}
public boolean equals(War war) {
return getUUID().equals(war.getUUID());
public boolean equals(OldWar oldWar) {
return getUUID().equals(oldWar.getUUID());
}
public boolean equals(UUID uuid) {
@@ -7,8 +7,8 @@ import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.object.metadata.CustomDataField;
import com.palmergames.bukkit.towny.object.metadata.LongDataField;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.War;
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
@@ -17,18 +17,19 @@ import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull;
import java.util.*;
@Deprecated
public class RaidData {
// Static Raid list for all active raids
private static final ArrayList<Raid> raids = new ArrayList<>();
// Static OldRaid list for all active OLD_RAIDS
private static final ArrayList<OldRaid> OLD_RAIDS = new ArrayList<>();
public static ArrayList<Raid> getRaids() {
return raids;
public static ArrayList<OldRaid> getRaids() {
return OLD_RAIDS;
}
public static void setRaids(ArrayList<Raid> raids) {
for (Raid raid : raids) {
addRaid(raid);
public static void setRaids(ArrayList<OldRaid> oldRaids) {
for (OldRaid oldRaid : oldRaids) {
addRaid(oldRaid);
}
}
@@ -36,38 +37,38 @@ public class RaidData {
* Gets a raid with a specific name
*
* @param name - Name to check
* @return Raid or Null
* @return OldRaid or Null
*/
public static @Nullable Raid getRaid(String name) {
for (Raid raid : raids) {
if (raid.getName().equalsIgnoreCase(name)) return raid;
public static @Nullable OldRaid getRaid(String name) {
for (OldRaid oldRaid : OLD_RAIDS) {
if (oldRaid.getName().equalsIgnoreCase(name)) return oldRaid;
}
return null;
}
public static void addRaid(Raid raid) {
if (raid == null) {
Main.warLogger.log("Attempted to add NULL to raid list.");
public static void addRaid(OldRaid oldRaid) {
if (oldRaid == null) {
Main.warLogger.log("Attempted to add NULL to oldRaid list.");
return;
}
raids.add(raid);
OLD_RAIDS.add(oldRaid);
}
public static void removeRaid(Raid raid) {
raid.getWar().getRaids().remove(raid);
raids.remove(raid);
public static void removeRaid(OldRaid oldRaid) {
oldRaid.getWar().getRaids().remove(oldRaid);
OLD_RAIDS.remove(oldRaid);
//deleteRaid(raid);
//deleteRaid(oldRaid);
}
/**
* Creates a raid object from a provided HashMap
*
* @param fileData
* @return Raid object
* @return OldRaid object
*/
@SuppressWarnings("unchecked")
public static Raid fromMap(War war, HashMap<String, Object> fileData) {
public static OldRaid fromMap(OldWar oldWar, HashMap<String, Object> fileData) {
if (fileData.get("raidedTown") == null || fileData.get("gatherTown") == null || fileData.get("side1AreRaiders") == null) {
return null;
@@ -82,17 +83,17 @@ public class RaidData {
if (raidedTown == null || gatherTown == null) {
return null;
}
Raid raid = new Raid(war, raidedTown, gatherTown, attackBoolean, offlinePlayer);
OldRaid oldRaid = new OldRaid(oldWar, raidedTown, gatherTown, attackBoolean, offlinePlayer);
//Extra properties, if any are missing the raid doesnt exist yet
//Extra properties, if any are missing the oldRaid doesnt exist yet
if (fileData.get("raiderScore") != null && fileData.get("defenderScore") != null && fileData.get("raidTicks") != null && fileData.get("raidPhase") != null && fileData.get("activeRaiders") != null && fileData.get("lootedChunks") != null && fileData.get("side1AreRaiders") != null) {
//active properties
raid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase")));
raid.setRaidTicks((int) fileData.get("raidTicks"));
raid.setActiveRaiders((ArrayList<String>) fileData.get("activeRaiders"));
raid.setRaiderScore((int) fileData.get("raiderScore"));
raid.setDefenderScore((int) fileData.get("defenderScore"));
raid.setSide1AreRaiders(Boolean.parseBoolean((String) fileData.get("side1AreRaiders")));
oldRaid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase")));
oldRaid.setRaidTicks((int) fileData.get("raidTicks"));
oldRaid.setActiveRaiders((ArrayList<String>) fileData.get("activeRaiders"));
oldRaid.setRaiderScore((int) fileData.get("raiderScore"));
oldRaid.setDefenderScore((int) fileData.get("defenderScore"));
oldRaid.setSide1AreRaiders(Boolean.parseBoolean((String) fileData.get("side1AreRaiders")));
//looted chunks
ArrayList<Object> o = (ArrayList<Object>) fileData.get("lootedChunks");
@@ -109,24 +110,24 @@ public class RaidData {
boolean finished = (boolean) chunk.get("finished");
//put
Raid.LootBlock lb = new Raid.LootBlock(worldCoordc, ticks, value, finished);
raid.getLootedChunks().put(worldCoordc, lb);
OldRaid.LootBlock lb = new OldRaid.LootBlock(worldCoordc, ticks, value, finished);
oldRaid.getLootedChunks().put(worldCoordc, lb);
}
}
return raid;
return oldRaid;
}
public static ArrayList<Raid> createRaids(War war, Collection<HashMap<String, Object>> raidMaps) {
ArrayList<Raid> returnList = new ArrayList<>();
public static ArrayList<OldRaid> createRaids(OldWar oldWar, Collection<HashMap<String, Object>> raidMaps) {
ArrayList<OldRaid> returnList = new ArrayList<>();
for (HashMap<String, Object> map : raidMaps) {
Town town = TownyAPI.getInstance().getTown((String) map.get("raidedTown"));
if (town == null) continue;
Raid raid = fromMap(war, map);
returnList.add(raid);
RaidData.addRaid(raid);
raid.resume();
OldRaid oldRaid = fromMap(oldWar, map);
returnList.add(oldRaid);
RaidData.addRaid(oldRaid);
oldRaid.resume();
}
return returnList;
}
@@ -135,17 +136,17 @@ public class RaidData {
/**
* Saves the war into files.
*
* @param raid - War to be saved.
* @param oldRaid - OldWar to be saved.
*/
public static void saveRaid(Raid raid) {
War war = raid.getWar();
war.save();
public static void saveRaid(OldRaid oldRaid) {
OldWar oldWar = oldRaid.getWar();
oldWar.save();
}
// /**
// * deletes raid, unused
// */
// private static void deleteRaid(War war) {
// private static void deleteRaid(OldWar war) {
// File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
//
// for (File file : files) {
@@ -156,28 +157,28 @@ public class RaidData {
// }
/**
* Turns a raid into a map
* Turns a oldRaid into a map
*
* @param raid - Raid
* @param oldRaid - OldRaid
* @return Map
*/
public static HashMap<String, Object> raidToMap(Raid raid) {
public static HashMap<String, Object> raidToMap(OldRaid oldRaid) {
HashMap<String, Object> returnMap = new HashMap<>();
// Shoves everything into a map.
returnMap.put("name", raid.getName());
returnMap.put("raidedTown", raid.getRaidedTown().getName());
returnMap.put("gatherTown", raid.getGatherTown().getName());
returnMap.put("raidTicks", raid.getRaidTicks());
returnMap.put("raidPhase", raid.getPhase().name());
returnMap.put("raiderScore", raid.getRaiderScore());
returnMap.put("defenderScore", raid.getDefenderScore());
returnMap.put("side1AreRaiders", Boolean.toString(raid.getSide1AreRaiders()));
returnMap.put("activeRaiders", raid.getActiveRaiders());
returnMap.put("name", oldRaid.getName());
returnMap.put("raidedTown", oldRaid.getRaidedTown().getName());
returnMap.put("gatherTown", oldRaid.getGatherTown().getName());
returnMap.put("raidTicks", oldRaid.getRaidTicks());
returnMap.put("raidPhase", oldRaid.getPhase().name());
returnMap.put("raiderScore", oldRaid.getRaiderScore());
returnMap.put("defenderScore", oldRaid.getDefenderScore());
returnMap.put("side1AreRaiders", Boolean.toString(oldRaid.getSide1AreRaiders()));
returnMap.put("activeRaiders", oldRaid.getActiveRaiders());
//THIS MAY OR MAY NOT WORK
returnMap.put("owner", raid.getOwner().getUniqueId().toString());
returnMap.put("owner", oldRaid.getOwner().getUniqueId().toString());
//create a list from the looted chunks
final List<Object> chunkList = getChunkList(raid);
final List<Object> chunkList = getChunkList(oldRaid);
returnMap.put("lootedChunks", chunkList);
@@ -185,9 +186,9 @@ public class RaidData {
}
@NotNull
private static List<Object> getChunkList(Raid raid) {
private static List<Object> getChunkList(OldRaid oldRaid) {
List<Object> chunkList = new ArrayList<>();
for (Raid.LootBlock b : raid.getLootedChunks().values()) {
for (OldRaid.LootBlock b : oldRaid.getLootedChunks().values()) {
HashMap<String, Object> blockMap = new HashMap<>();
//worldcoord
HashMap<String, Object> wcMap = new HashMap<>();
@@ -207,13 +208,13 @@ public class RaidData {
/**
* Creates a map of raid maps
*
* @param war - War to map
* @param oldWar - OldWar to map
* @return Map of Maps
*/
public static HashMap<String, Object> getRaidMap(War war) {
public static HashMap<String, Object> getRaidMap(OldWar oldWar) {
HashMap<String, Object> returnMap = new HashMap<>();
for (Raid raid : war.getRaids()) {
returnMap.put(raid.getRaidedTown().getName(), raidToMap(raid));
for (OldRaid oldRaid : oldWar.getRaids()) {
returnMap.put(oldRaid.getRaidedTown().getName(), raidToMap(oldRaid));
}
return returnMap;
}
@@ -241,9 +242,9 @@ public class RaidData {
/**
* @return
* @Isaac this is for getting if a town can be raided, return (-2, -1, 0, 1, 2) based on status
* (no players online, 24 hours town cooldown, 6 hour war cooldown, town being raided already, valid time to raid)
* (no players online, 24 hours town cooldown, 6 hour oldWar cooldown, town being raided already, valid time to raid)
*/
public static int isValidRaid(War war, String side, @Nonnull Town town) {
public static int isValidRaid(OldWar oldWar, String side, @Nonnull Town town) {
long townTime = whenTownLastRaided(town);
//24 hours town cooldown
@@ -251,8 +252,8 @@ public class RaidData {
return -1;
}
//6 hour raid cooldown for war
if ((System.currentTimeMillis() / 1000) - (side.equalsIgnoreCase(war.getSide1()) ? war.getLastRaidTimeSide1() : war.getLastRaidTimeSide2()) <= 21600) {
//6 hour raid cooldown for oldWar
if ((System.currentTimeMillis() / 1000) - (side.equalsIgnoreCase(oldWar.getSide1()) ? oldWar.getLastRaidTimeSide1() : oldWar.getLastRaidTimeSide2()) <= 21600) {
return 0;
}
@@ -266,8 +267,8 @@ public class RaidData {
if (!onlinePlayer) return -2;
//check if being raided
for (Raid raid : war.getRaids()) {
if (raid.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
for (OldRaid oldRaid : oldWar.getRaids()) {
if (oldRaid.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
return 1;
}
+133
View File
@@ -0,0 +1,133 @@
package me.ShermansWorld.AlathraWar.data;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import java.util.*;
@Deprecated
public class SiegeData {
// Static OldSiege list for all active OLD_SIEGES
private static final HashSet<OldSiege> OLD_SIEGES = new HashSet<>();
public static HashSet<OldSiege> getSieges() {
return OLD_SIEGES;
}
public static void setSieges(ArrayList<OldSiege> oldSieges) {
for (OldSiege oldSiege : oldSieges) {
addSiege(oldSiege);
}
}
/**
* Gets a siege with a specific name
*
* @param name - Name to check
* @return OldSiege or Null
*/
public static OldSiege getSiege(String name) {
for (OldSiege oldSiege : OLD_SIEGES) {
if (oldSiege.getTown().getName().equalsIgnoreCase(name)) return oldSiege;
}
return null;
}
public static void addSiege(OldSiege oldSiege) {
if (oldSiege == null) {
Main.warLogger.log("Attempted to add NULL to oldSiege list.");
return;
}
OLD_SIEGES.add(oldSiege);
}
public static void removeSiege(OldSiege oldSiege) {
OLD_SIEGES.remove(oldSiege);
//deleteSiege(oldSiege);d
}
/**
* Creates a siege object from a provided HashMap
*
* @param fileData data
* @return OldSiege object
*/
private static OldSiege fromMap(OldWar oldWar, HashMap<String, Object> fileData) {
if (fileData.get("town") == null || fileData.get("side1AreAttackers") == null) {
return null;
}
Town town = TownyAPI.getInstance().getTown((String) fileData.get("town"));
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString((String) fileData.get("siegeLeader")));
return new OldSiege(oldWar, town, offlinePlayer);
}
/**
* Saves the war into files.
*
* @param oldSiege - OldSiege to be saved.
*/
public static void saveSiege(OldSiege oldSiege) {
OldWar oldWar = oldSiege.getWar();
oldWar.save();
}
/**
* Turns a oldSiege into a map
*
* @param oldSiege - OldSiege
* @return Map
*/
public static HashMap<String, Object> siegeToMap(OldSiege oldSiege) {
HashMap<String, Object> returnMap = new HashMap<>();
// Shoves everything into a map.
returnMap.put("town", oldSiege.getTown().getName());
returnMap.put("siegeTicks", oldSiege.getSiegeTicks());
returnMap.put("attackerPoints", oldSiege.getAttackerPoints());
returnMap.put("defenderPoints", oldSiege.getDefenderPoints());
returnMap.put("side1AreAttackers", Boolean.toString(oldSiege.getSide1AreAttackers()));
returnMap.put("siegeLeader", oldSiege.getSiegeLeader().getUniqueId().toString());
return returnMap;
}
/**
* Creates a map of siege maps
*
* @param oldWar - OldWar to map
* @return Map of Maps
*/
public static HashMap<String, Object> getSiegeMap(OldWar oldWar) {
HashMap<String, Object> returnMap = new HashMap<>();
for (OldSiege oldSiege : oldWar.getSieges()) {
returnMap.put(oldSiege.getTown().getName(), siegeToMap(oldSiege));
}
return returnMap;
}
public static ArrayList<OldSiege> createSieges(OldWar oldWar, Collection<HashMap<String, Object>> siegeMaps) {
ArrayList<OldSiege> returnList = new ArrayList<>();
for (HashMap<String, Object> map : siegeMaps) {
Town town = TownyAPI.getInstance().getTown((String) map.get("town"));
if (town == null) continue;
OldSiege oldSiege = fromMap(oldWar, map);
oldSiege.addPointsToAttackers((int) map.get("attackerPoints"));
oldSiege.addPointsToDefenders((int) map.get("defenderPoints"));
oldSiege.resume((int) map.get("siegeTicks"));
oldSiege.setWar(oldWar);
returnList.add(oldSiege);
}
return returnList;
}
}
+185
View File
@@ -0,0 +1,185 @@
package me.ShermansWorld.AlathraWar.data;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
import java.io.File;
import java.io.FilenameFilter;
import java.util.*;
@Deprecated
public class WarData {
private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
// Filter for only accessing yml files
private static final FilenameFilter ymlFilter = (dir, name) -> name.endsWith(".yml");
// Static OldWar list for all active oldWars
private static ArrayList<OldWar> oldWars = new ArrayList<>();
// Constructor used to initialise folder.
public WarData(final Main plugin) {
File userDataFolder = new File(dataFolderPath + File.separator + "oldWars");
if (!userDataFolder.exists()) {
userDataFolder.mkdirs();
}
}
public static ArrayList<OldWar> getWars() {
return oldWars;
}
public static void setWars(ArrayList<OldWar> oldWars) {
WarData.oldWars = oldWars;
}
public static Collection<String> getWarsNames() {
List<String> warNames = new ArrayList<>();
for (OldWar oldWar : getWars()) {
warNames.add(oldWar.getName());
}
Collections.sort(warNames);
return warNames;
}
/**
* Gets a war with a specific name
*
* @param name - Name to check
* @return OldWar or Null
*/
public static OldWar getWar(String name) {
for (OldWar oldWar : oldWars) {
if (oldWar.getName().equalsIgnoreCase(name)) return oldWar;
}
return null;
}
public static OldWar getWar(UUID uuid) {
for (OldWar oldWar : oldWars) {
if (oldWar.getUUID().equals(uuid)) return oldWar;
}
return null;
}
public static void addWar(OldWar oldWar) {
if (oldWar == null) {
Main.warLogger.log("Attempted to add NULL to oldWar list.");
return;
}
oldWars.add(oldWar);
}
public static void removeWar(OldWar oldWar) {
oldWars.remove(oldWar);
deleteWar(oldWar);
}
/**
* Gets the oldWars currently saved in files as an ArrayList of OldWar Objects
*
* @return OldWar Object ArrayList
*/
public static ArrayList<OldWar> createWars() {
File[] files = new File(dataFolderPath + File.separator + "oldWars").listFiles(ymlFilter);
ArrayList<OldWar> returnList = new ArrayList<>();
for (File file : files) {
try {
HashMap<String, Object> fileData = DataManager.getData(file);
OldWar fileOldWar = fromMap(fileData);
returnList.add(fileOldWar);
} catch (Exception e) {
Main.warLogger.log("Failed to load " + file.getName());
e.printStackTrace();
}
}
return returnList;
}
/**
* Creates a war object from a provided HashMap
*
* @param fileData
* @return OldWar object
*/
@SuppressWarnings("unchecked")
public static OldWar fromMap(HashMap<String, Object> fileData) {
OldWar oldWar = new OldWar((String) fileData.get("name"),
(String) fileData.get("side1"),
(String) fileData.get("side2")
);
oldWar.setSide1Towns((ArrayList<String>) fileData.get("side1Towns"));
oldWar.setSide2Towns((ArrayList<String>) fileData.get("side2Towns"));
oldWar.setSurrenderedTowns((ArrayList<String>) fileData.get("surrenderedTowns"));
oldWar.addSide1Points((int) fileData.get("side1Points"));
oldWar.addSide2Points((int) fileData.get("side2Points"));
if (fileData.get("lastRaidTimeSide1") != null && fileData.get("lastRaidTimeSide2") != null) {
oldWar.setLastRaidTimeSide1((int) fileData.get("lastRaidTimeSide1"));
oldWar.setLastRaidTimeSide2((int) fileData.get("lastRaidTimeSide2"));
}
// OldSiege adding from map.
Collection<HashMap<String, Object>> siegeMaps = ((HashMap<String, HashMap<String, Object>>) fileData.get("oldSieges")).values();
ArrayList<OldSiege> oldSieges = SiegeData.createSieges(oldWar, siegeMaps);
for (OldSiege oldSiege : oldSieges) {
oldWar.addSiege(oldSiege);
SiegeData.addSiege(oldSiege);
}
// OldRaid adding from map.
Collection<HashMap<String, Object>> raidMaps = ((HashMap<String, HashMap<String, Object>>) fileData.get("oldRaids")).values();
ArrayList<OldRaid> oldRaids = RaidData.createRaids(oldWar, raidMaps);
for (OldRaid oldRaid : oldRaids) {
oldWar.addRaid(oldRaid);
}
return oldWar;
}
/**
* Saves the oldWar into files.
*
* @param oldWar - OldWar to be saved.
*/
public static void saveWar(OldWar oldWar) {
HashMap<String, Object> sHashMap = new HashMap<>();
// Shoves everything into a map.
sHashMap.put("name", oldWar.getName());
sHashMap.put("side1", oldWar.getSide1());
sHashMap.put("side2", oldWar.getSide2());
sHashMap.put("side1Towns", oldWar.getSide1Towns());
sHashMap.put("side2Towns", oldWar.getSide2Towns());
sHashMap.put("surrenderedTowns", oldWar.getSurrenderedTowns());
sHashMap.put("side1Points", oldWar.getSide1Points());
sHashMap.put("side2Points", oldWar.getSide2Points());
sHashMap.put("sieges", SiegeData.getSiegeMap(oldWar));
sHashMap.put("raids", RaidData.getRaidMap(oldWar));
sHashMap.put("lastRaidTimeSide1", oldWar.getLastRaidTimeSide1());
sHashMap.put("lastRaidTimeSide2", oldWar.getLastRaidTimeSide2());
DataManager.saveData("oldWars" + File.separator + oldWar.getName() + ".yml", sHashMap);
}
private static void deleteWar(OldWar oldWar) {
File[] files = new File(dataFolderPath + File.separator + "oldWars").listFiles(ymlFilter);
for (File file : files) {
if (file.getName().startsWith(oldWar.getName())) {
file.delete();
}
}
}
}
@@ -1,220 +0,0 @@
package me.ShermansWorld.AlathraWar;
import com.palmergames.bukkit.towny.object.WorldCoord;
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 org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
public class Helper {
public static String color(final String input) {
return ChatColor.translateAlternateColorCodes('&', input);
}
public static String chatLabel() {
return color("&6[&4AlathraWar&6]&r ");
}
/**
* 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)) {
final ItemMeta meta = getItemMeta(is);
is.setItemMeta(meta);
}
}
final ItemStack[] armor = p.getInventory().getArmorContents();
for (ItemStack itemStack : armor) {
if (itemStack != null) {
if (itemStack.getType() == Material.NETHERITE_HELMET || itemStack.getType() == Material.NETHERITE_CHESTPLATE || itemStack.getType() == Material.NETHERITE_LEGGINGS || itemStack.getType() == Material.NETHERITE_BOOTS || itemStack.getType() == Material.DIAMOND_HELMET || itemStack.getType() == Material.DIAMOND_CHESTPLATE || itemStack.getType() == Material.DIAMOND_LEGGINGS || itemStack.getType() == Material.NETHERITE_BOOTS || itemStack.getType() == Material.IRON_HELMET || itemStack.getType() == Material.IRON_CHESTPLATE || itemStack.getType() == Material.IRON_LEGGINGS || itemStack.getType() == Material.IRON_BOOTS) {
final ItemMeta meta2 = getItemMeta2(itemStack);
itemStack.setItemMeta(meta2);
}
}
}
}
@Nullable
private static ItemMeta getItemMeta2(ItemStack is2) {
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 = damageable2;
return meta2;
}
@Nullable
private static ItemMeta getItemMeta(ItemStack is) {
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);
}
} else if (is.getType() == Material.TRIDENT) {
damageable.setDamage(damageable.getDamage() + 62);
if (damageable.getDamage() > 200) {
damageable.setDamage(249);
}
}
meta = damageable;
return meta;
}
/**
* @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.isEmpty()) {
// 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)) {
// If in to-search list, ignore
} else if (SearchList.contains(cell)) {
// 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,9 +2,8 @@ package me.ShermansWorld.AlathraWar;
import me.ShermansWorld.AlathraWar.commands.CommandManager;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.hooks.TABHook;
import me.ShermansWorld.AlathraWar.hooks.HookManager;
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
import me.ShermansWorld.AlathraWar.listeners.*;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
@@ -25,6 +24,7 @@ public class Main extends JavaPlugin {
}
private final CommandManager commandManager = new CommandManager(Main.getInstance());
private final HookManager hookManager = new HookManager();
@NotNull
public static Main getInstance() {
@@ -60,10 +60,6 @@ public class Main extends JavaPlugin {
warLogger = new AlathraWarLogger();
}
private static void initAPIs() {
TABHook.init();
}
@SuppressWarnings("rawtypes")
private boolean setupEconomy() {
if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
@@ -82,6 +78,7 @@ public class Main extends JavaPlugin {
public void onLoad() {
Main.instance = this;
commandManager.onLoad();
hookManager.onLoad();
}
@Override
@@ -89,33 +86,35 @@ public class Main extends JavaPlugin {
this.saveDefaultConfig();
initLogs();
new WarData(this);
//new WarData(this);
// new TimeoutData(this);
getServer().getPluginManager().registerEvents(new KillsListener(), this);
getServer().getPluginManager().registerEvents(new CommandsListener(), this);
getServer().getPluginManager().registerEvents(new JoinListener(), this);
getServer().getPluginManager().registerEvents(new BlockBreakListener(), this);
getServer().getPluginManager().registerEvents(new PlayerInteractListener(), this);
// getServer().getPluginManager().registerEvents(new KillsListener(), this);
// getServer().getPluginManager().registerEvents(new CommandsListener(), this);
// getServer().getPluginManager().registerEvents(new JoinListener(), this);
// getServer().getPluginManager().registerEvents(new BlockBreakListener(), this);
// getServer().getPluginManager().registerEvents(new PlayerInteractListener(), this);
// //run first
new WarItemRegistry();
// //run second
// new WarRecipeRegistry();
commandManager.onEnable();
initData();
initAPIs();
setupEconomy();
initLogs();
commandManager.onEnable();
hookManager.onEnable();
}
@Override
public void onDisable() {
commandManager.onDisable();
hookManager.onDisable();
for (War war : WarData.getWars()) {
war.save();
}
// for (OldWar oldWar : WarData.getWars()) {
// oldWar.save();
// }
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,445 @@
package me.ShermansWorld.AlathraWar.commands;
import com.github.milkdrinkers.colorparser.ColorParser;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyObject;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
import dev.jorel.commandapi.arguments.CustomArgument;
import dev.jorel.commandapi.arguments.StringArgument;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.conflict.War;
import me.ShermansWorld.AlathraWar.conflict.battle.Side;
import me.ShermansWorld.AlathraWar.holder.WarManager;
import me.ShermansWorld.AlathraWar.hooks.TownyHook;
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
import me.ShermansWorld.AlathraWar.utility.UtilsChat;
import org.bukkit.Bukkit;
import org.bukkit.Statistic;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class CommandUtil {
/*public Argument<World> customWorldArgument(String nodeName) {
// Construct our CustomArgument that takes in a String input and returns a World object
return new CustomArgument<World, String>(new StringArgument(nodeName), info -> {
// Parse the world from our input
World world = Bukkit.getWorld(info.input());
if (world == null) {
throw CustomArgumentException.fromMessageBuilder(new MessageBuilder("Unknown world: ").appendArgInput());
} else {
return world;
}
}).replaceSuggestions(ArgumentSuggestions.strings(info ->
// List of world names on the server
Bukkit.getWorlds().stream().map(World::getName).toArray(String[]::new))
);
}*/
static public Argument<Nation> customNationArgument(String nodeName) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
final String argNationName = info.input();
if (TownyAPI.getInstance().getNation(argNationName) == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation does not exist!").parseLegacy().build());
return TownyAPI.getInstance().getNation(argNationName);
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final List<String> nationNames = TownyHook.getNations()
.stream()
.map(Nation::getName)
.sorted()
.collect(Collectors.toList());
return nationNames;
}));
}
static public Argument<Town> customTownArgument(String nodeName) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
final String argTownName = info.input();
if (TownyAPI.getInstance().getTown(argTownName) == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town does not exist!").parseLegacy().build());
return TownyAPI.getInstance().getTown(argTownName);
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final List<String> townNames = TownyHook.getTowns()
.stream()
.map(Town::getName)
.sorted()
.collect(Collectors.toList());
return townNames;
}));
}
static public Argument<Nation> customNationNotInWarArgument(String nodeName, String warNodeName, boolean hideNationsInWar) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
final String argNationName = info.input();
if (TownyAPI.getInstance().getNation(argNationName) == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation does not exist!").parseLegacy().build());
if (!hideNationsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
return TownyAPI.getInstance().getNation(argNationName);
Nation nation = TownyAPI.getInstance().getNation(argNationName);
if (war.getNations().contains(nation) || war.getSurrenderedNations().contains(nation))
return nation;
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation is already at war!").parseLegacy().build());
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final List<String> nationNames = TownyHook.getNations()
.stream()
.map(Nation::getName)
.sorted()
.collect(Collectors.toList());
final List<String> townNames = TownyHook.getTowns()
.stream()
.map(Town::getName)
.sorted()
.collect(Collectors.toList());
nationNames.addAll(townNames);
// Only proceed after this if we want to remove town already in the specified war
if (!hideNationsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
return nationNames;
final List<String> removeNames = Stream.concat( // Create a list of all nations in war
war.getNations().stream().map(Nation::getName),
war.getSurrenderedNations().stream().map(Nation::getName)
).toList();
nationNames.removeAll(removeNames);
return nationNames;
}));
}
static public Argument<Town> customTownNotInWarArgument(String nodeName, String warNodeName, boolean hideTownsInWar) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
final String argTownName = info.input();
if (TownyAPI.getInstance().getTown(argTownName) == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town does not exist!").parseLegacy().build());
if (!hideTownsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
return TownyAPI.getInstance().getTown(argTownName);
Town town = TownyAPI.getInstance().getTown(argTownName);
if (war.getTowns().contains(town) || war.getSurrenderedTowns().contains(town))
return town;
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town is already at war!").parseLegacy().build());
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final List<String> townNames = TownyHook.getTowns()
.stream()
.map(Town::getName)
.sorted()
.collect(Collectors.toList());
// Only proceed after this if we want to remove town already in the specified war
if (!hideTownsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
return townNames;
final List<String> removeNames = Stream.concat( // Create a list of all nations & towns in war
war.getTowns().stream().map(Town::getName),
war.getSurrenderedTowns().stream().map(Town::getName)
).toList();
townNames.removeAll(removeNames);
return townNames;
}));
}
static public Argument<Nation> customNationInWarArgument(String nodeName, String warNodeName) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
if (!(info.previousArgs().get(warNodeName) instanceof War war))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe war does not exist!").parseLegacy().build());
Nation nation = TownyAPI.getInstance().getNation(info.input());
if (nation == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation does not exist!").parseLegacy().build());
if (!war.isNationInWar(nation))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation is not in that war!").parseLegacy().build());
return nation;
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
if (!(info.previousArgs().get(warNodeName) instanceof War war))
return Collections.emptyList();
return Stream.concat( // Create a list of all nations & towns in war
war.getNations().stream().map(Nation::getName),
war.getSurrenderedNations().stream().map(Nation::getName)
).sorted().toList();
}));
}
static public Argument<Town> customTownInWarArgument(String nodeName, String warNodeName) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
if (!(info.previousArgs().get(warNodeName) instanceof War war))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe war does not exist!").parseLegacy().build());
Town town = TownyAPI.getInstance().getTown(info.input());
if (town == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town does not exist!").parseLegacy().build());
if (!war.isTownInWar(town))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town is not in that war!").parseLegacy().build());
return town;
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
if (!(info.previousArgs().get(warNodeName) instanceof War war))
return Collections.emptyList();
return Stream.concat( // Create a list of all nations & towns in war
war.getTowns().stream().map(Town::getName),
war.getSurrenderedTowns().stream().map(Town::getName)
).sorted().toList();
}));
}
static public Argument<String> customTownAndNationsArgument(String nodeName, String warNodeName, boolean hideTownsInWar) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
final String argTownOrNationName = info.input();
if (TownyAPI.getInstance().getTown(argTownOrNationName) != null)
return TownyAPI.getInstance().getTown(argTownOrNationName).getName();
if (TownyAPI.getInstance().getNation(argTownOrNationName) != null)
return TownyAPI.getInstance().getNation(argTownOrNationName).getName();
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town or nation does not exist!").parseLegacy().build());
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final List<String> nationNames = TownyHook.getNations()
.stream()
.map(Nation::getName)
.sorted()
.collect(Collectors.toList());
final List<String> townNames = TownyHook.getTowns()
.stream()
.map(Town::getName)
.sorted()
.collect(Collectors.toList());
nationNames.addAll(townNames);
// Only proceed after this if we want to remove town already in the specified war
if (!hideTownsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
return nationNames;
final List<String> removeNames = Stream.concat( // Create a list of all nations & towns in war
war.getNations().stream().map(Nation::getName),
Stream.concat(
war.getSurrenderedNations().stream().map(Nation::getName),
Stream.concat(
war.getTowns().stream().map(Town::getName),
war.getSurrenderedTowns().stream().map(Town::getName)
)
)
).toList();
nationNames.removeAll(removeNames);
return nationNames;
}));
}
/*static public Argument<String> warSideCreateArgument(String nodeName) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
final String argSideName = info.input();
return argSideName;
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final List<Nation> nations = TownyHook.getNations();
final List<Town> towns = TownyHook.getTowns();
final List<String> nationNames = new ArrayList<>();
final List<String> townNames = new ArrayList<>();
for (Nation nation : nations)
nationNames.add(nation.getName());
for (Town town : towns)
townNames.add(town.getName());
Collections.sort(nationNames);
Collections.sort(townNames);
nationNames.addAll(townNames);
return nationNames;
}));
}*/
public static Argument<War> warWarArgument(String nodeName, final boolean isAdmin, final boolean checkIfIn, final String playerNodeName) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
final String argWarName = info.input();
final War war = WarManager.getInstance().getWar(argWarName);
if (war == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe war <war> does not exist!").parseLegacy().parseMinimessagePlaceholder("war", argWarName).build());
if (checkIfIn) {
if (isAdmin) {
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe player does not exist!").parseLegacy().build());
if (war.isPlayerInWar(player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe player is already in that war.").parseLegacy().build());
} else {
if (!(info.sender() instanceof Player player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cOnly players can execute this command!").parseLegacy().build());
if (war.isPlayerInWar(player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou are already in this war.").parseLegacy().build());
}
}
return war;
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
final List<String> warNames = new ArrayList<>();
if (checkIfIn) {
if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
for (String name : WarManager.getInstance().getWarNames()) {
if (WarManager.getInstance().getWar(name) != null && !WarManager.getInstance().getWar(name).isPlayerInWar(player))
warNames.add(name);
}
}
} else {
if (info.sender() instanceof Player player) {
for (String name : WarManager.getInstance().getWarNames()) {
if (WarManager.getInstance().getWar(name) != null && !WarManager.getInstance().getWar(name).isPlayerInWar(player))
warNames.add(name);
}
}
}
} else {
warNames.addAll(WarManager.getInstance().getWarNames());
}
return warNames;
}));
}
public static Argument<Side> warSideCreateArgument(final String nodeName, final String warNodeName, final boolean isAdmin, final boolean checkIfIn, final String playerNodeName) {
return new CustomArgument<>(new StringArgument(nodeName), info -> {
if (!(info.previousArgs().get(warNodeName) instanceof War war))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war.").parseLegacy().build());
final String argSideName = info.input();
if (!war.isSideValid(argSideName))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe side does not exist.").parseLegacy().build());
final Side side = war.getSide(argSideName);
if (side == null)
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe side is invalid.").parseLegacy().build());
if (checkIfIn) {
if (isAdmin) {
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe player does not exist!").parseLegacy().build());
if (side.getPlayers().contains(player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe player is already on that side.").parseLegacy().build());
} else {
if (!(info.sender() instanceof Player player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cOnly players can execute this command!").parseLegacy().build());
if (side.getPlayers().contains(player))
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou are already on that side.").parseLegacy().build());
}
}
return side;
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
if (!(info.previousArgs().get(warNodeName) instanceof War war))
return Collections.emptyList();
final List<String> sideNames = new ArrayList<>();
if (checkIfIn) {
if (isAdmin) {
if (info.previousArgs().get(playerNodeName) instanceof Player player) {
for (Side side : war.getSides()) {
if (!side.getPlayers().contains(player))
sideNames.add(side.getName());
}
}
} else {
if (info.sender() instanceof Player player) {
for (Side side : war.getSides()) {
if (!side.getPlayers().contains(player))
sideNames.add(side.getName());
}
}
}
} else {
sideNames.add(war.getSide1().getName());
sideNames.add(war.getSide2().getName());
}
return sideNames;
}
));
}
/**
* @param player player to check
* @return 0, 1, 2 (good to go, insufficient join, insufficient playtime)
*/
public static int isPlayerMinuteman(String player) {
Resident res = TownyAPI.getInstance().getResident(player);
if (res != null) {
//getInstance registration time
long regTime = res.getRegistered();
int playTicks = Bukkit.getPlayer(res.getUUID()).getStatistic(Statistic.PLAY_ONE_MINUTE);
int out = 0;
if (Main.getInstance().getConfig().getInt("minimumPlayerAge") > 0) {
//compare the join date, if they joined less that min age ago it is true
if ((System.currentTimeMillis() - regTime) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge"))
out = 1;
}
if (Main.getInstance().getConfig().getInt("minimumPlayTime") > 0) {
//check playtime, if its less than min its true
if (playTicks < (Main.getInstance().getConfig().getInt("minimumPlayTime") * (60 * 60 * 20))) out = 2;
}
return out;
}
//if the player doesnt exist just return true
return 0;
}
/**
* return list of all alathrawar items with namespace
*
* @return list of all alathrawar items namespaced
*/
public static List<String> getWarItems() {
return new ArrayList<>(WarItemRegistry.getInstance().getItemRegistry().keySet());
}
}
@@ -20,7 +20,12 @@ import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.deprecated.CommandHelper;
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import me.ShermansWorld.AlathraWar.utility.Utils;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@@ -47,7 +52,7 @@ public class RaidCommand {
)
.executesPlayer((sender, args) -> {
if (args.count() == 0)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid Arguments. /siege help").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /siege help").build());
})
.register();
}
@@ -123,13 +128,13 @@ public class RaidCommand {
new StringArgument("side")
.replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> {
final String raidname = (String) info.previousArgs().get("raid");
final String raidname = (String) info.previousArgs().get("oldRaid");
final Raid raid = RaidData.getRaid(raidname);
final OldRaid oldRaid = RaidData.getRaid(raidname);
if (raid == null) return Collections.emptyList();
if (oldRaid == null) return Collections.emptyList();
return List.of(raid.getRaiderSide(), raid.getDefenderSide());
return List.of(oldRaid.getRaiderSide(), oldRaid.getDefenderSide());
})
),
new PlayerArgument("player")
@@ -207,28 +212,28 @@ public class RaidCommand {
boolean townExists = false;
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cUsage: /alathrawaradmin create raid [war] [raidTown] (gatherTown/\"defaultCode\") (owner) (override)").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cUsage: /alathrawaradmin create raid [war] [raidTown] (gatherTown/\"defaultCode\") (owner) (override)").build());
for (final War war : WarData.getWars()) {
if (war.getName().equalsIgnoreCase(argWarName)) {
for (final OldWar oldWar : WarData.getWars()) {
if (oldWar.getName().equalsIgnoreCase(argWarName)) {
warFound = true;
final Player raidOwner = (Player) args.getOptional("leader").orElse(p);
if (raidOwner == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Raid Owner is Null").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("OldRaid Owner is Null").build());
}
TownyWorld townyWorld;
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
String side;
if (war.getSide1Players().contains(raidOwner.getName())) {
side = war.getSide1();
} else if (war.getSide2Players().contains(raidOwner.getName())) {
side = war.getSide2();
if (oldWar.getSide1Players().contains(raidOwner.getName())) {
side = oldWar.getSide1();
} else if (oldWar.getSide2Players().contains(raidOwner.getName())) {
side = oldWar.getSide2();
} else {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You are not in this oldWar! Type /oldWar join [oldWar] [side]").build());
}
//Minuteman countermeasures
@@ -272,8 +277,8 @@ public class RaidCommand {
gatherTown = TownyAPI.getInstance().getTown(argGatherTown);
} else {
if (admin)
p.sendMessage(Helper.chatLabel() + "No valid town set for gather town, defaulting to current location");
raidOwner.sendMessage(Helper.chatLabel() + "No valid town set for gather town, defaulting to current location");
p.sendMessage(UtilsChat.getPrefix() + "No valid town set for gather town, defaulting to current location");
raidOwner.sendMessage(UtilsChat.getPrefix() + "No valid town set for gather town, defaulting to current location");
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
}
} else {
@@ -281,14 +286,14 @@ public class RaidCommand {
}
} catch (NotRegisteredException e2) {
if (admin)
p.sendMessage(Helper.chatLabel() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(Helper.chatLabel() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
p.sendMessage(UtilsChat.getPrefix() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(UtilsChat.getPrefix() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
return;
}
if (gatherTown == null) {
if (admin)
p.sendMessage(Helper.chatLabel() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(Helper.chatLabel() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
p.sendMessage(UtilsChat.getPrefix() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
raidOwner.sendMessage(UtilsChat.getPrefix() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
return;
}
@@ -301,104 +306,104 @@ public class RaidCommand {
Main.warLogger.log("Raided town: " + raidedTown.getName());
Main.warLogger.log("Gather town: " + gatherTown.getName());
Main.warLogger.log("Raid Owner: " + raidOwner.getName());
Main.warLogger.log("OldRaid Owner: " + raidOwner.getName());
p.sendMessage("Raided town: " + raidedTown.getName());
p.sendMessage("Gather town: " + gatherTown.getName());
p.sendMessage("Raid Owner: " + raidOwner.getName());
p.sendMessage("OldRaid Owner: " + raidOwner.getName());
//DEBUG PRINT
for (String t : war.getSide1Towns()) {
for (String t : oldWar.getSide1Towns()) {
Main.warLogger.log("Side1 town: " + t);
p.sendMessage("Side1 town: " + t);
}
for (String t : war.getSide2Towns()) {
for (String t : oldWar.getSide2Towns()) {
Main.warLogger.log("Side2 town: " + t);
p.sendMessage("Side2 town: " + t);
}
//check if the town were attempting to raid is in the war
if (!war.getSide1Towns().contains(raidedTown.getName().toLowerCase()) && !war.getSide2Towns().contains(raidedTown.getName().toLowerCase())) {
if (war.getSurrenderedTowns().contains(raidedTown.getName().toLowerCase())) {
//check if the town were attempting to raid is in the oldWar
if (!oldWar.getSide1Towns().contains(raidedTown.getName().toLowerCase()) && !oldWar.getSide2Towns().contains(raidedTown.getName().toLowerCase())) {
if (oldWar.getSurrenderedTowns().contains(raidedTown.getName().toLowerCase())) {
if (admin)
p.sendMessage(Helper.chatLabel() + "The town you are trying to raid has already surrendered!");
raidOwner.sendMessage(Helper.chatLabel() + "The town you are trying to raid has already surrendered!");
p.sendMessage(UtilsChat.getPrefix() + "The town you are trying to raid has already surrendered!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "The town you are trying to raid has already surrendered!");
return;
}
if (admin)
p.sendMessage(Helper.chatLabel() + "The town you are trying to raid is not part of the war!");
raidOwner.sendMessage(Helper.chatLabel() + "The town you are trying to raid is not part of the war!");
p.sendMessage(UtilsChat.getPrefix() + "The town you are trying to raid is not part of the oldWar!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "The town you are trying to raid is not part of the oldWar!");
return;
}
// Is being sieged check
for (Siege s : SiegeData.getSieges()) {
for (OldSiege s : SiegeData.getSieges()) {
if (s.getTown().getName().equalsIgnoreCase(raidedTown.getName())) {
raidOwner.sendMessage(Helper.chatLabel() + "That town is already currently being sieged! Cannot raid at this time!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "That town is already currently being sieged! Cannot raid at this time!");
if (admin)
p.sendMessage(Helper.chatLabel() + "That town is already currently being sieged! Cannot raid at this time!");
p.sendMessage(UtilsChat.getPrefix() + "That town is already currently being sieged! Cannot raid at this time!");
}
}
townExists = true;
Raid raid2;
if (war.getSide1Players().contains(raidOwner.getName())) {
OldRaid oldRaid2;
if (oldWar.getSide1Players().contains(raidOwner.getName())) {
//Time and raid activity validity check
int c = RaidData.isValidRaid(war, side, raidedTown);
int c = RaidData.isValidRaid(oldWar, side, raidedTown);
if (c == 2) {
//if were admin, see if an owner arg exists, and if so then use it
raid2 = new Raid(war, raidedTown, gatherTown, true, raidOwner);
oldRaid2 = new OldRaid(oldWar, raidedTown, gatherTown, true, raidOwner);
} else if (c == 1) {
if (admin)
p.sendMessage(Helper.chatLabel() + "This town is already being raided at this time!");
raidOwner.sendMessage(Helper.chatLabel() + "This town is already being raided at this time!");
p.sendMessage(UtilsChat.getPrefix() + "This town is already being raided at this time!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "This town is already being raided at this time!");
return;
} else if (c == 0) {
if (admin)
p.sendMessage(Helper.chatLabel() + "Your side has raided too recently!");
raidOwner.sendMessage(Helper.chatLabel() + "Your side has raided too recently!");
p.sendMessage(UtilsChat.getPrefix() + "Your side has raided too recently!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "Your side has raided too recently!");
return;
} else if (c == -1) {
if (admin)
p.sendMessage(Helper.chatLabel() + "This town was raided too recently!");
raidOwner.sendMessage(Helper.chatLabel() + "This town was raided too recently!");
p.sendMessage(UtilsChat.getPrefix() + "This town was raided too recently!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "This town was raided too recently!");
return;
} else if (c == -2) {
if (admin)
p.sendMessage(Helper.chatLabel() + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(Helper.chatLabel() + "At least on member of the raided town must be online to defend it!");
p.sendMessage(UtilsChat.getPrefix() + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "At least on member of the raided town must be online to defend it!");
return;
} else {
throw new IllegalArgumentException();
}
} else {
//Something broke if this runs
if (!war.getSide2Players().contains(raidOwner.getName())) {
Bukkit.getLogger().info("Unable to find player declaring raid in the war");
if (!oldWar.getSide2Players().contains(raidOwner.getName())) {
Bukkit.getLogger().info("Unable to find player declaring raid in the oldWar");
return;
}
//Time and raid activity validity check
int c = RaidData.isValidRaid(war, side, raidedTown);
int c = RaidData.isValidRaid(oldWar, side, raidedTown);
if (c == 2) {
raid2 = new Raid(war, raidedTown, gatherTown, false, raidOwner);
oldRaid2 = new OldRaid(oldWar, raidedTown, gatherTown, false, raidOwner);
} else if (c == 1) {
if (admin)
p.sendMessage(Helper.chatLabel() + "This town is already being raided at this time!");
raidOwner.sendMessage(Helper.chatLabel() + "This town is already being raided at this time!");
p.sendMessage(UtilsChat.getPrefix() + "This town is already being raided at this time!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "This town is already being raided at this time!");
return;
} else if (c == 0) {
if (admin)
p.sendMessage(Helper.chatLabel() + "Your side has raided too recently!");
raidOwner.sendMessage(Helper.chatLabel() + "Your side has raided too recently!");
p.sendMessage(UtilsChat.getPrefix() + "Your side has raided too recently!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "Your side has raided too recently!");
return;
} else if (c == -1) {
if (admin)
p.sendMessage(Helper.chatLabel() + "This town was raided too recently!");
raidOwner.sendMessage(Helper.chatLabel() + "This town was raided too recently!");
p.sendMessage(UtilsChat.getPrefix() + "This town was raided too recently!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "This town was raided too recently!");
return;
} else if (c == -2) {
if (admin)
p.sendMessage(Helper.chatLabel() + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(Helper.chatLabel() + "At least on member of the raided town must be online to defend it!");
p.sendMessage(UtilsChat.getPrefix() + "At least on member of the raided town must be online to defend it!");
raidOwner.sendMessage(UtilsChat.getPrefix() + "At least on member of the raided town must be online to defend it!");
return;
} else {
throw new IllegalArgumentException();
@@ -407,21 +412,21 @@ public class RaidCommand {
// Player participance check
Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull();
TownWarState sideR = war.getState(leaderTown.getName().toLowerCase());
TownWarState sideR = oldWar.getState(leaderTown.getName().toLowerCase());
if (sideR == TownWarState.NOT_PARTICIPANT) {
if (admin) p.sendMessage(Helper.chatLabel() + "You are not in this war.");
raidOwner.sendMessage(Helper.chatLabel() + "You are not in this war.");
if (admin) p.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar.");
raidOwner.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar.");
return;
} else if (sideR == TownWarState.SURRENDERED) {
if (admin) p.sendMessage(Helper.chatLabel() + "You have surrendered.");
raidOwner.sendMessage(Helper.chatLabel() + "You have surrendered.");
if (admin) p.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
raidOwner.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
return;
}
// Attacking own side
if (war.getState(raidedTown) == sideR) {
if (admin) p.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
raidOwner.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
if (oldWar.getState(raidedTown) == sideR) {
if (admin) p.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
raidOwner.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
return;
}
@@ -429,24 +434,24 @@ public class RaidCommand {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(raidOwner.getUniqueId());
if (Main.econ.getBalance(offlinePlayer) <= 1000.0) {
if (admin)
p.sendMessage(Helper.chatLabel() + "You must have at least $1000 to put up to start a raid.");
raidOwner.sendMessage(Helper.chatLabel() + "You must have at least $1000 to put up to start a raid.");
p.sendMessage(UtilsChat.getPrefix() + "You must have at least $1000 to put up to start a raid.");
raidOwner.sendMessage(UtilsChat.getPrefix() + "You must have at least $1000 to put up to start a raid.");
return;
}
//publish raid
Main.econ.withdrawPlayer(offlinePlayer, 1000);
raid2.addActiveRaider(raidOwner.getName());
RaidData.addRaid(raid2);
raid2.start(); //funny funny method haha
WarData.saveWar(raid2.getWar());
oldRaid2.addActiveRaider(raidOwner.getName());
RaidData.addRaid(oldRaid2);
oldRaid2.start(); //funny funny method haha
WarData.saveWar(oldRaid2.getWar());
//broadcast
Bukkit.broadcastMessage(Helper.chatLabel() + "As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!");
Bukkit.broadcastMessage(Helper.chatLabel() + "All players from the defending side have been drafted for the town's defense.");
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of "
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "As part of " + oldWar.getName() + ", forces from " + oldRaid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "All players from the defending side have been drafted for the town's defense.");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The raid of "
+ raidedTown.getName() + " will begin in " + (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!");
Bukkit.broadcastMessage(Helper.chatLabel() +
Bukkit.broadcastMessage(UtilsChat.getPrefix() +
"The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
Main.warLogger.log(raidOwner.getName() + " started a raid.");
@@ -454,18 +459,18 @@ public class RaidCommand {
Main.warLogger.log(raidOwner.getName() + " started a raid from admin interference.");
p.sendMessage(Helper.color("&cForcefully started raid from the console."));
}
Main.warLogger.log("As part of " + war.getName() + ", forces from " + raid2.getRaiderSide() + " are raiding the town of " + raidedTown.getName() + "!");
Main.warLogger.log("As part of " + oldWar.getName() + ", forces from " + oldRaid2.getRaiderSide() + " are raiding the town of " + raidedTown.getName() + "!");
Main.warLogger.log("The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
}
}
}
}
if (!warFound) {
p.sendMessage(Helper.chatLabel() + "That war does not exist! /raid start [war] [town]");
p.sendMessage(UtilsChat.getPrefix() + "That war does not exist! /raid start [war] [town]");
return;
}
if (!townExists) {
p.sendMessage(Helper.chatLabel() + "That town does not exist! /raid start [war] [town]");
p.sendMessage(UtilsChat.getPrefix() + "That town does not exist! /raid start [war] [town]");
}
}
@@ -477,10 +482,10 @@ public class RaidCommand {
*/
private static void raidStop(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name!").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name!").build());
if (!(args.get("town") instanceof final String argTown))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a town name!").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a town name!").build());
//are there even any raids
@@ -488,32 +493,32 @@ public class RaidCommand {
fail(p, args, "noRaids");
}
//find our desired raid and stop it
Raid raid = RaidData.getRaid(argWarName + "-" + argTown);
//find our desired oldRaid and stop it
OldRaid oldRaid = RaidData.getRaid(argWarName + "-" + argTown);
if (raid != null) {
p.sendMessage(Helper.chatLabel() + "raid cancelled");
Bukkit.broadcastMessage(Helper.chatLabel() + "The raid of " + raid.getRaidedTown().getName() + " has been cancelled by an admin");
raid.stop(); //this purges itself from raids
if (oldRaid != null) {
p.sendMessage(UtilsChat.getPrefix() + "oldRaid cancelled");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The oldRaid of " + oldRaid.getRaidedTown().getName() + " has been cancelled by an admin");
oldRaid.stop(); //this purges itself from raids
} else {
fail(p, args, "badName");
}
}
protected static void raidJoin(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
if (!(args.get("raid") instanceof final String argRaidName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a raid name!").build());
if (!(args.get("oldRaid") instanceof final String argRaidName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a oldRaid name!").build());
if (!(args.get("side") instanceof final String argSide))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a side!").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a side!").build());
final Raid raid = RaidData.getRaid(argRaidName);
if (raid == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThat raid does not exist!").build());
final OldRaid oldRaid = RaidData.getRaid(argRaidName);
if (oldRaid == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThat oldRaid does not exist!").build());
final War war = raid.getWar();
if (war == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThe war does not exist!").build());
final OldWar oldWar = oldRaid.getWar();
if (oldWar == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe oldWar does not exist!").build());
final Player joiner = (Player) args.getOptional("player").orElse(p);
if (joiner == null)
@@ -522,28 +527,28 @@ public class RaidCommand {
if (admin) {
if (argSide != null) {
if (argSide.equalsIgnoreCase(raid.getDefenderSide())) {
if (!raid.getDefenderPlayers().contains(joiner.getName()))
raid.getDefenderPlayers().add(joiner.getName());
if (argSide.equalsIgnoreCase(oldRaid.getDefenderSide())) {
if (!oldRaid.getDefenderPlayers().contains(joiner.getName()))
oldRaid.getDefenderPlayers().add(joiner.getName());
p.sendMessage(Helper.chatLabel() + "Player " + joiner.getName() + " added to defender side.");
p.sendMessage(UtilsChat.getPrefix() + "Player " + joiner.getName() + " added to defender side.");
Main.warLogger.log("Player " + joiner.getName() + " added to defender side.");
joiner.sendMessage(Helper.chatLabel() + "You were forcefully added to the defender side against the raid party on " + raid.getRaidedTown() + " by an admin.");
joiner.sendMessage(UtilsChat.getPrefix() + "You were forcefully added to the defender side against the oldRaid party on " + oldRaid.getRaidedTown() + " by an admin.");
return;
} else {
if (!raid.getRaiderPlayers().contains(joiner.getName()))
raid.getRaiderPlayers().add(joiner.getName());
if (!oldRaid.getRaiderPlayers().contains(joiner.getName()))
oldRaid.getRaiderPlayers().add(joiner.getName());
p.sendMessage(Helper.chatLabel() + "Player " + joiner.getName() + " added to raider side.");
p.sendMessage(UtilsChat.getPrefix() + "Player " + joiner.getName() + " added to raider side.");
Main.warLogger.log("Player " + joiner.getName() + " added to raider side.");
joiner.sendMessage(Helper.chatLabel() + "You were forcefully added to the raid party on " + raid.getRaidedTown() + " by an admin. Leaving the gather town will remove you from the raid party.");
joiner.sendMessage(UtilsChat.getPrefix() + "You were forcefully added to the oldRaid party on " + oldRaid.getRaidedTown() + " by an admin. Leaving the gather town will remove you from the oldRaid party.");
}
}
}
if (!raid.getWar().getSide1Players().contains(joiner.getName()) && !raid.getWar().getSide2Players().contains(joiner.getName())) {
joiner.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
if (!oldRaid.getWar().getSide1Players().contains(joiner.getName()) && !oldRaid.getWar().getSide2Players().contains(joiner.getName())) {
joiner.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar! Type /oldWar join [oldWar] [side]");
}
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
@@ -560,14 +565,14 @@ public class RaidCommand {
if (minuteman == 1) {
//player has joined to recently
if (admin)
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
joiner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a oldRaid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
joiner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a oldRaid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
return;
} else if (minuteman == 2) {
//player has played too little
if (admin)
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
joiner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a oldRaid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
joiner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a oldRaid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
return;
}
}
@@ -575,44 +580,44 @@ public class RaidCommand {
//check if gather phase
if (!admin) {
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
if (oldRaid.getPhase() == RaidPhase.GATHER || oldRaid.getPhase() == RaidPhase.START) {
try {
//check if the player is in the gather town
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
ArrayList<WorldCoord> cluster = Utils.getCluster(oldRaid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
raid.addActiveRaider(joiner.getName());
joiner.sendMessage(Helper.chatLabel() + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(Helper.chatLabel() + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
oldRaid.addActiveRaider(joiner.getName());
joiner.sendMessage(UtilsChat.getPrefix() + "You have joined the oldRaid on " + oldRaid.getRaidedTown().getName() + "!");
joiner.sendMessage(UtilsChat.getPrefix() + "Leaving " + oldRaid.getGatherTown().getName() + " will cause you to leave the oldRaid party.");
} else {
joiner.sendMessage(Helper.chatLabel() + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
joiner.sendMessage(UtilsChat.getPrefix() + "You must be in the gathering town to join the oldRaid on " + oldRaid.getRaidedTown().getName() + ".");
}
} catch (TownyException e) {
throw new RuntimeException(e);
}
} else {
joiner.sendMessage(Helper.chatLabel() + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
joiner.sendMessage(UtilsChat.getPrefix() + "You cannot join the oldRaid on " + oldRaid.getRaidedTown().getName() + "! It has already started!");
}
} else {
try {
//check if the player is in the gather town
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
ArrayList<WorldCoord> cluster = Utils.getCluster(oldRaid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
raid.addActiveRaider(joiner.getName());
joiner.sendMessage(Helper.chatLabel() + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
joiner.sendMessage(Helper.chatLabel() + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
oldRaid.addActiveRaider(joiner.getName());
joiner.sendMessage(UtilsChat.getPrefix() + "You have joined the oldRaid on " + oldRaid.getRaidedTown().getName() + "!");
joiner.sendMessage(UtilsChat.getPrefix() + "Leaving " + oldRaid.getGatherTown().getName() + " will cause you to leave the oldRaid party.");
} else {
joiner.sendMessage(Helper.chatLabel() + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
joiner.sendMessage(UtilsChat.getPrefix() + "You must be in the gathering town to join the oldRaid on " + oldRaid.getRaidedTown().getName() + ".");
}
} catch (TownyException e) {
throw new RuntimeException(e);
}
}
raid.save();
oldRaid.save();
}
protected static void raidLeave(Player player, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
//Get raid!
//Get oldRaid!
final Player p = (Player) args.getOptional("player").orElse(player);
if (p == null) {
@@ -620,41 +625,41 @@ public class RaidCommand {
}
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name!").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name!").build());
if (!(args.get("town") instanceof final String argTown))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a town name!").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a town name!").build());
Raid raid = RaidData.getRaid(argWarName + "-" + argTown);
if (raid == null) {
p.sendMessage(Helper.chatLabel() + "No raid is gathering in this town or this town does not exist!");
OldRaid oldRaid = RaidData.getRaid(argWarName + "-" + argTown);
if (oldRaid == null) {
p.sendMessage(UtilsChat.getPrefix() + "No oldRaid is gathering in this town or this town does not exist!");
if (admin)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "No raid is gathering in this town or this town does not exist!").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No oldRaid is gathering in this town or this town does not exist!").build());
}
if (raid.getWar().getName().equalsIgnoreCase(argWarName)) {
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
p.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
if (oldRaid.getWar().getName().equalsIgnoreCase(argWarName)) {
if (!oldRaid.getWar().getSide1Players().contains(p.getName()) && !oldRaid.getWar().getSide2Players().contains(p.getName())) {
p.sendMessage(UtilsChat.getPrefix() + "You are not in this war! Type /war join [war] [side]");
if (admin)
player.sendMessage(Helper.chatLabel() + "You are not in this war! Type /war join [war] [side]");
player.sendMessage(UtilsChat.getPrefix() + "You are not in this war! Type /war join [war] [side]");
}
//check if gather phase
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START) {
if (oldRaid.getPhase() == RaidPhase.GATHER || oldRaid.getPhase() == RaidPhase.START) {
try {
//check if player is in gather town
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
ArrayList<WorldCoord> cluster = Utils.getCluster(oldRaid.getGatherTown().getHomeBlock().getWorldCoord());
if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
raid.removeActiveRaider(p.getName());
p.sendMessage(Helper.chatLabel() + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
oldRaid.removeActiveRaider(p.getName());
p.sendMessage(UtilsChat.getPrefix() + "You have left the oldRaid on " + oldRaid.getRaidedTown().getName() + "!");
if (admin)
player.sendMessage(Helper.chatLabel() + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
player.sendMessage(UtilsChat.getPrefix() + "You have left the oldRaid on " + oldRaid.getRaidedTown().getName() + "!");
} else {
p.sendMessage(Helper.chatLabel() + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
p.sendMessage(UtilsChat.getPrefix() + "You cannot leave the oldRaid on " + oldRaid.getRaidedTown().getName() + "! It has already started!");
if (admin)
player.sendMessage(Helper.chatLabel() + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
player.sendMessage(UtilsChat.getPrefix() + "You cannot leave the oldRaid on " + oldRaid.getRaidedTown().getName() + "! It has already started!");
}
} catch (TownyException e) {
throw new RuntimeException(e);
@@ -662,12 +667,12 @@ public class RaidCommand {
}
if (admin) {
player.sendMessage(Helper.chatLabel() + "Forced player " + p.getName() + " to leave raid on " + raid.getRaidedTown().getName() + " in war " + argWarName);
Main.warLogger.log("Forced player " + p.getName() + " to leave raid on " + raid.getRaidedTown().getName() + " in war " + argWarName);
player.sendMessage(UtilsChat.getPrefix() + "Forced player " + p.getName() + " to leave oldRaid on " + oldRaid.getRaidedTown().getName() + " in war " + argWarName);
Main.warLogger.log("Forced player " + p.getName() + " to leave oldRaid on " + oldRaid.getRaidedTown().getName() + " in war " + argWarName);
}
}
raid.save();
oldRaid.save();
}
/**
@@ -678,33 +683,33 @@ public class RaidCommand {
*/
private static void raidAbandon(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name!").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name!").build());
if (!(args.get("town") instanceof final String argTown))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a town name!").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a town name!").build());
//Get raid
Raid raid = RaidData.getRaid(argWarName + "-" + argTown);
//Get oldRaid
OldRaid oldRaid = RaidData.getRaid(argWarName + "-" + argTown);
if (raid == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThis raid does not exist!").build());
if (oldRaid == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThis oldRaid does not exist!").build());
if (raid.getWar().getName().equalsIgnoreCase(argWarName)) {
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou are not in this war! Type /war join [war] [side]").build());
if (oldRaid.getWar().getName().equalsIgnoreCase(argWarName)) {
if (!oldRaid.getWar().getSide1Players().contains(p.getName()) && !oldRaid.getWar().getSide2Players().contains(p.getName())) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou are not in this war! Type /war join [war] [side]").build());
}
if (raid.getOwner().getName().equalsIgnoreCase(p.getName())) {
if (oldRaid.getOwner().getName().equalsIgnoreCase(p.getName())) {
//check if gather phase
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.COMBAT) {
if (oldRaid.getPhase() == RaidPhase.GATHER || oldRaid.getPhase() == RaidPhase.START || oldRaid.getPhase() == RaidPhase.TRAVEL || oldRaid.getPhase() == RaidPhase.COMBAT) {
//force defender victory
Bukkit.broadcast(new ColorParser(Helper.chatLabel() + "The raid on " + raid.getRaidedTown().getName() + " has been abandoned by " + raid.getRaiderSide()).build());
Main.warLogger.log(p.getName() + " abandoned the raid on " + raid.getRaidedTown().getName() + " they started at " + raid.getGatherTown().getName());
raid.defendersWin(raid.getRaiderScore(), raid.getDefenderScore());
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The oldRaid on " + oldRaid.getRaidedTown().getName() + " has been abandoned by " + oldRaid.getRaiderSide()).build());
Main.warLogger.log(p.getName() + " abandoned the oldRaid on " + oldRaid.getRaidedTown().getName() + " they started at " + oldRaid.getGatherTown().getName());
oldRaid.defendersWin(oldRaid.getRaiderScore(), oldRaid.getDefenderScore());
} else {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou cannot abandon the raid on " + raid.getRaidedTown().getName() + "! It has a problem!").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou cannot abandon the oldRaid on " + oldRaid.getRaidedTown().getName() + "! It has a problem!").build());
}
} else {
fail(p, args, "owner");
@@ -714,52 +719,52 @@ public class RaidCommand {
private static void raidsList(Player p, CommandArguments args) {
if (RaidData.getRaids().isEmpty()) {
p.sendMessage(new ColorParser(Helper.chatLabel() + "There are currently no Raids in progress").build());
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "There are currently no Raids in progress").build());
return;
}
p.sendMessage(new ColorParser(Helper.chatLabel() + "Raids currently in progress:").build());
for (final Raid raid : RaidData.getRaids()) {
p.sendMessage(new ColorParser("Name: " + raid.getName()).build());
p.sendMessage(new ColorParser("War: " + raid.getWar().getName()).build());
p.sendMessage(new ColorParser("Owner: " + raid.getOwner().getName()).build());
p.sendMessage(new ColorParser("Raiding: " + raid.getRaidedTown().getName().toLowerCase()).build());
p.sendMessage(new ColorParser("Gathering In: " + raid.getGatherTown().getName().toLowerCase()).build());
p.sendMessage(new ColorParser("Raiders: " + raid.getRaiderSide()).build());
p.sendMessage(new ColorParser("Defenders: " + raid.getDefenderSide()).build());
p.sendMessage(new ColorParser("Raider Score: " + raid.getRaiderScore()).build());
p.sendMessage(new ColorParser("Defender Score: " + raid.getDefenderScore()).build());
p.sendMessage(new ColorParser("Raid Phase: " + raid.getPhase().name()).build());
p.sendMessage(new ColorParser("Time Left: " + (RaidPhase.END.startTick - raid.getRaidTicks()) / 1200 + " minutes").build());
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Raids currently in progress:").build());
for (final OldRaid oldRaid : RaidData.getRaids()) {
p.sendMessage(new ColorParser("Name: " + oldRaid.getName()).build());
p.sendMessage(new ColorParser("OldWar: " + oldRaid.getWar().getName()).build());
p.sendMessage(new ColorParser("Owner: " + oldRaid.getOwner().getName()).build());
p.sendMessage(new ColorParser("Raiding: " + oldRaid.getRaidedTown().getName().toLowerCase()).build());
p.sendMessage(new ColorParser("Gathering In: " + oldRaid.getGatherTown().getName().toLowerCase()).build());
p.sendMessage(new ColorParser("Raiders: " + oldRaid.getRaiderSide()).build());
p.sendMessage(new ColorParser("Defenders: " + oldRaid.getDefenderSide()).build());
p.sendMessage(new ColorParser("Raider Score: " + oldRaid.getRaiderScore()).build());
p.sendMessage(new ColorParser("Defender Score: " + oldRaid.getDefenderScore()).build());
p.sendMessage(new ColorParser("OldRaid Phase: " + oldRaid.getPhase().name()).build());
p.sendMessage(new ColorParser("Time Left: " + (RaidPhase.END.startTick - oldRaid.getRaidTicks()) / 1200 + " minutes").build());
p.sendMessage(new ColorParser("-=-=-=-=-=-=-=-=-=-=-=-").build());
}
}
private static void raidHelp(Player p, CommandArguments args) {
if (p.hasPermission("AlathraWar.admin")) {
p.sendMessage(new ColorParser(Helper.chatLabel() + "/raid stop [name]").build());
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid stop [name]").build());
}
p.sendMessage(new ColorParser(Helper.chatLabel() + "/raid start [war] [town]").build());
p.sendMessage(new ColorParser(Helper.chatLabel() + "/raid join [war] [town]").build());
p.sendMessage(new ColorParser(Helper.chatLabel() + "/raid leave [war] [town]").build());
p.sendMessage(new ColorParser(Helper.chatLabel() + "/raid abandon [war] [town]").build());
p.sendMessage(new ColorParser(Helper.chatLabel() + "/raid list").build());
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid start [war] [town]").build());
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid join [war] [town]").build());
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid leave [war] [town]").build());
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid abandon [war] [town]").build());
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid list").build());
}
private static void fail(CommandSender p, CommandArguments args, String type) throws WrapperCommandSyntaxException {
switch (type) {
case "permissions" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou do not have permission to do this.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou do not have permission to do this.").build());
case "syntax" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cInvalid Syntax. /raid help").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cInvalid Syntax. /raid help").build());
case "noRaids" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThere are currently no Raids in progress.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThere are currently no Raids in progress.").build());
case "badName" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cA raid could not be found with this Name! Type /raid list to view current raids.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA raid could not be found with this Name! Type /raid list to view current raids.").build());
case "owner" ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cOnly the player who started the raid can abandon it.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cOnly the player who started the raid can abandon it.").build());
default ->
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cInvalid Arguments. /raid help").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cInvalid Arguments. /raid help").build());
}
}
}
@@ -15,6 +15,10 @@ import me.ShermansWorld.AlathraWar.*;
import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.deprecated.CommandHelper;
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
@@ -35,7 +39,7 @@ public class SiegeCommand {
)
.executesPlayer((sender, args) -> {
if (args.count() == 0)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid Arguments. /siege help").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /siege help").build());
})
.register();
}
@@ -120,7 +124,7 @@ public class SiegeCommand {
protected static void siegeStart(Player sender, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cUsage: /alathrawaradmin create siege [war] [town] (owner) (force).").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cUsage: /alathrawaradmin create oldSiege [oldWar] [town] (owner) (force).").build());
//if this is admin mode use the forth arg instad of sender.
//if player is null after this then force end
@@ -131,46 +135,46 @@ public class SiegeCommand {
/*if (args.length < 3) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "/war siege [war] [town]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/oldWar oldSiege [oldWar] [town]").build());
}*/
// War check
War war = WarData.getWar(argWarName);
if (war == null) {
siegeOwner.sendMessage(Helper.chatLabel() + "That war does not exist! /siege start [war] [town]");
// OldWar check
OldWar oldWar = WarData.getWar(argWarName);
if (oldWar == null) {
siegeOwner.sendMessage(UtilsChat.getPrefix() + "That oldWar does not exist! /oldSiege start [oldWar] [town]");
if (admin)
sender.sendMessage(Helper.chatLabel() + "That war does not exist! /siege start [war] [town]");
sender.sendMessage(UtilsChat.getPrefix() + "That oldWar does not exist! /oldSiege start [oldWar] [town]");
return;
}
// Player participance check
Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
TownWarState side = war.getState(leaderTown.getName().toLowerCase());
TownWarState side = oldWar.getState(leaderTown.getName().toLowerCase());
// TODO DEBUG PRINT
Main.warLogger.log("Leader Town: " + leaderTown.getName());
Main.warLogger.log("Siege Owner: " + siegeOwner.getName());
Main.warLogger.log("OldSiege Owner: " + siegeOwner.getName());
sender.sendMessage("Leader Town: " + leaderTown.getName());
sender.sendMessage("Siege Owner: " + siegeOwner.getName());
sender.sendMessage("OldSiege Owner: " + siegeOwner.getName());
// TODO DEBUG PRINT
for (String t : war.getSide1Towns()) {
for (String t : oldWar.getSide1Towns()) {
Main.warLogger.log("Side1 town: " + t);
sender.sendMessage("Side1 town: " + t);
}
for (String t : war.getSide2Towns()) {
for (String t : oldWar.getSide2Towns()) {
Main.warLogger.log("Side2 town: " + t);
sender.sendMessage("Side2 town: " + t);
}
if (side == TownWarState.NOT_PARTICIPANT) {
siegeOwner.sendMessage(Helper.chatLabel() + "You are not in this war.");
if (admin) sender.sendMessage(Helper.chatLabel() + "You are not in this war.");
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar.");
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar.");
return;
} else if (side == TownWarState.SURRENDERED) {
siegeOwner.sendMessage(Helper.chatLabel() + "You have surrendered.");
if (admin) sender.sendMessage(Helper.chatLabel() + "You have surrendered.");
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
return;
}
@@ -203,142 +207,142 @@ public class SiegeCommand {
}
if (!(args.get("town") instanceof final String argTownName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Specify a town! /siege start [war] [town]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Specify a town! /oldSiege start [oldWar] [town]").build());
// Town check
Town town = TownyAPI.getInstance().getTown(argTownName);
if (town == null) {
siegeOwner.sendMessage(Helper.chatLabel() + "That town does not exist! /siege start [war] [town]");
siegeOwner.sendMessage(UtilsChat.getPrefix() + "That town does not exist! /oldSiege start [oldWar] [town]");
if (admin)
sender.sendMessage(Helper.chatLabel() + "That town does not exist! /siege start [war] [town]");
sender.sendMessage(UtilsChat.getPrefix() + "That town does not exist! /oldSiege start [oldWar] [town]");
return;
}
// Is being raided check
for (Raid r : RaidData.getRaids()) {
for (OldRaid r : RaidData.getRaids()) {
if (r.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
siegeOwner.sendMessage(Helper.chatLabel() + "That town is already currently being raided! Cannot siege at this time!");
siegeOwner.sendMessage(UtilsChat.getPrefix() + "That town is already currently being raided! Cannot oldSiege at this time!");
if (admin)
sender.sendMessage(Helper.chatLabel() + "That town is already currently being raided! Cannot siege at this time!");
sender.sendMessage(UtilsChat.getPrefix() + "That town is already currently being raided! Cannot oldSiege at this time!");
return;
}
}
// Attacking own side
if (war.getState(town) == side) {
siegeOwner.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
if (admin) sender.sendMessage(Helper.chatLabel() + "You cannot attack your own towns.");
if (oldWar.getState(town) == side) {
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
return;
}
Siege siege = new Siege(war, town, siegeOwner);
SiegeData.addSiege(siege);
war.addSiege(siege);
OldSiege oldSiege = new OldSiege(oldWar, town, siegeOwner);
SiegeData.addSiege(oldSiege);
oldWar.addSiege(oldSiege);
Bukkit.broadcastMessage(Helper.chatLabel() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide() + "!");
Bukkit.broadcastMessage(UtilsChat.getPrefix() + oldSiege.getTown() + " has been put to oldSiege by " + oldSiege.getAttackerSide() + "!");
if (admin)
sender.sendMessage(Helper.color("&cForcefully started siege from the console."));
sender.sendMessage(Helper.color("&cForcefully started oldSiege from the console."));
// TODO Debug logs...
Main.warLogger.log("Attacked Town: " + town.getName().toLowerCase());
sender.sendMessage("Attacked Town: " + town.getName().toLowerCase());
war.save();
siege.start();
oldWar.save();
oldSiege.start();
}
private static void siegeStop(Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
final HashSet<Siege> sieges = SiegeData.getSieges();
if (sieges.isEmpty()) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "There are currently no sieges in progress").build());
final HashSet<OldSiege> oldSieges = SiegeData.getSieges();
if (oldSieges.isEmpty()) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "There are currently no oldSieges in progress").build());
}
if (args.count() < 2) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "/siege stop [town]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/siege stop [town]").build());
}
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "No war name supplied. /siege stop [war] [town]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No oldWar name supplied. /siege stop [oldWar] [town]").build());
// War check
War war = WarData.getWar(argWarName);
if (war == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "That war does not exist! /siege stop [war] [town]").build());
// OldWar check
OldWar oldWar = WarData.getWar(argWarName);
if (oldWar == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "That oldWar does not exist! /siege stop [oldWar] [town]").build());
}
if (!(args.get("town") instanceof final String argTownName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "No war name supplied. /siege stop [war] [town]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No oldWar name supplied. /siege stop [oldWar] [town]").build());
for (Siege siege : sieges) {
if (siege.getTown().getName().equalsIgnoreCase(argTownName) && siege.getWar().equals(war)) {
sender.sendMessage(new ColorParser(Helper.chatLabel() + "siege cancelled").build());
Bukkit.broadcast(new ColorParser(Helper.chatLabel() + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin.").build());
//siege.clearBeacon();
siege.stop();
for (OldSiege oldSiege : oldSieges) {
if (oldSiege.getTown().getName().equalsIgnoreCase(argTownName) && oldSiege.getWar().equals(oldWar)) {
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "oldSiege cancelled").build());
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The oldSiege at " + oldSiege.getTown().getName() + " has been cancelled by an admin.").build());
//oldSiege.clearBeacon();
oldSiege.stop();
return;
}
}
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "A siege could not be found with this town name! Type /siege list to view current sieges").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "A siege could not be found with this town name! Type /siege list to view current oldSieges").build());
}
private static void siegeAbandon(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
if (args.count() < 2) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "/siege abandon [town]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/oldSiege abandon [town]").build());
}
// War check
// OldWar check
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "No war name supplied. /siege stop [war] [town]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No oldWar name supplied. /oldSiege stop [oldWar] [town]").build());
// War check
War war = WarData.getWar(argWarName);
if (war == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "That war does not exist! /siege abandon [war] [town]").build());
// OldWar check
OldWar oldWar = WarData.getWar(argWarName);
if (oldWar == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "That oldWar does not exist! /oldSiege abandon [oldWar] [town]").build());
}
if (!(args.get("town") instanceof final String argTown))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "No town name supplied. /siege stop [war] [town]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No town name supplied. /oldSiege stop [oldWar] [town]").build());
Siege siege = SiegeData.getSiege(argTown);
if (siege == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid siege").build());
OldSiege oldSiege = SiegeData.getSiege(argTown);
if (oldSiege == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid oldSiege").build());
}
OfflinePlayer oPlayer = siege.getSiegeLeader();
OfflinePlayer oPlayer = oldSiege.getSiegeLeader();
if (oPlayer != p) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "You are not the leader of this siege.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You are not the leader of this oldSiege.").build());
}
Bukkit.broadcast(new ColorParser(Helper.chatLabel() + "The siege at " + siege.getTown().getName() + " has been abandoned.").build());
Main.warLogger.log(p.getName() + " abandoned the siege they started at " + siege.getTown().getName());
siege.defendersWin();
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The oldSiege at " + oldSiege.getTown().getName() + " has been abandoned.").build());
Main.warLogger.log(p.getName() + " abandoned the oldSiege they started at " + oldSiege.getTown().getName());
oldSiege.defendersWin();
}
private static void siegeList(Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
HashSet<Siege> sieges = SiegeData.getSieges();
if (sieges.isEmpty())
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "There are currently no sieges in progress").build());
HashSet<OldSiege> oldSieges = SiegeData.getSieges();
if (oldSieges.isEmpty())
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "There are currently no oldSieges in progress").build());
sender.sendMessage(new ColorParser(Helper.chatLabel() + "Sieges currently in progress:").build());
for (Siege siege : sieges) {
War war = siege.getWar();
String color = (siege.getSide1AreAttackers() && (war.getState(siege.getTown().getName().toLowerCase()) == TownWarState.SIDE1)) ? "&c" : "&9";
sender.sendMessage(new ColorParser(war.getName() + " - " + color + siege.getTown().getName().toLowerCase()).build());
sender.sendMessage(new ColorParser(war.getSide1() + " - " + (siege.getSide1AreAttackers() ? siege.getAttackerPoints() : siege.getDefenderPoints())).build());
sender.sendMessage(new ColorParser(war.getSide2() + " - " + (siege.getSide1AreAttackers() ? siege.getDefenderPoints() : siege.getAttackerPoints())).build());
sender.sendMessage(new ColorParser("Time Left: " + (Siege.maxSiegeTicks - siege.getSiegeTicks()) / 1200 + " minutes").build());
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Sieges currently in progress:").build());
for (OldSiege oldSiege : oldSieges) {
OldWar oldWar = oldSiege.getWar();
String color = (oldSiege.getSide1AreAttackers() && (oldWar.getState(oldSiege.getTown().getName().toLowerCase()) == TownWarState.SIDE1)) ? "&c" : "&9";
sender.sendMessage(new ColorParser(oldWar.getName() + " - " + color + oldSiege.getTown().getName().toLowerCase()).build());
sender.sendMessage(new ColorParser(oldWar.getSide1() + " - " + (oldSiege.getSide1AreAttackers() ? oldSiege.getAttackerPoints() : oldSiege.getDefenderPoints())).build());
sender.sendMessage(new ColorParser(oldWar.getSide2() + " - " + (oldSiege.getSide1AreAttackers() ? oldSiege.getDefenderPoints() : oldSiege.getAttackerPoints())).build());
sender.sendMessage(new ColorParser("Time Left: " + (OldSiege.maxSiegeTicks - oldSiege.getSiegeTicks()) / 1200 + " minutes").build());
sender.sendMessage(new ColorParser("-=-=-=-=-=-=-=-=-=-=-=-").build());
}
}
private static void siegeHelp(Player sender, CommandArguments args) {
if (sender.hasPermission("AlathraWar.admin")) {
sender.sendMessage(new ColorParser(Helper.chatLabel() + "/siege stop [war] [town]").build());
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege stop [war] [town]").build());
}
sender.sendMessage(new ColorParser(Helper.chatLabel() + "/siege start [war] [town]").build());
sender.sendMessage(new ColorParser(Helper.chatLabel() + "/siege abandon [war] [town]").build());
sender.sendMessage(new ColorParser(Helper.chatLabel() + "/siege list").build());
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege start [war] [town]").build());
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege abandon [war] [town]").build());
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege list").build());
}
}
@@ -11,9 +11,14 @@ import dev.jorel.commandapi.arguments.PlayerArgument;
import dev.jorel.commandapi.arguments.StringArgument;
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
import dev.jorel.commandapi.executors.CommandArguments;
import me.ShermansWorld.AlathraWar.*;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.conflict.War;
import me.ShermansWorld.AlathraWar.conflict.battle.Side;
import me.ShermansWorld.AlathraWar.enums.BattleSide;
import me.ShermansWorld.AlathraWar.enums.BattleTeam;
import me.ShermansWorld.AlathraWar.enums.TownWarState;
import me.ShermansWorld.AlathraWar.holder.WarManager;
import me.ShermansWorld.AlathraWar.utility.UtilsChat;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@@ -38,7 +43,7 @@ public class WarCommand {
)
.executesPlayer((sender, args) -> {
if (args.count() == 0)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid Arguments. /war help").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /war help").build());
})
.register();
}
@@ -86,7 +91,7 @@ public class WarCommand {
.withArguments(
new StringArgument("war")
.replaceSuggestions(
ArgumentSuggestions.stringCollection(info -> WarData.getWarsNames())
ArgumentSuggestions.stringCollection(info -> WarManager.getInstance().getWarsNames())
)
)
.executesPlayer(WarCommand::warDelete);
@@ -104,7 +109,7 @@ public class WarCommand {
ArgumentSuggestions.stringCollection(info -> {
final String warname = (String) info.previousArgs().get("war");
final War war = WarData.getWar(warname);
final War war = WarManager.getInstance().getWar(warname);
if (war == null) return Collections.emptyList();
@@ -149,65 +154,70 @@ public class WarCommand {
}
protected static void warCreate(CommandSender p, CommandArguments args) throws WrapperCommandSyntaxException {
if (args.count() >= 3) {
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name.").build());
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name.").build());
if (WarData.getWar(argWarName) != null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cA war already exists with that name.").build());
if (WarManager.getInstance().getWar(argWarName) != null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name.").build());
if (!(args.get("side1") instanceof final String argSide1))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a side.").build());
if (!(args.get("side1") instanceof final String argSide1))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a side.").build());
if (!(args.get("side2") instanceof final String argSide2))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a side.").build());
if (!(args.get("side2") instanceof final String argSide2))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a side.").build());
if (argSide1.contains(argSide2))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cCannot declare war on oneself.").build());
if (argSide1.contains(argSide2))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cCannot declare war on oneself.").build());
// TODO Ensure side1 valid
// TODO Ensure side2 valid
// TODO Deep Check if war exists where the same sides are fighting???
// TODO Ensure side1 valid
// TODO Ensure side2 valid
// TODO Deep Check if war exists where the same sides are fighting???
// TODO Add checks here for wether the towns/nations names are valid
War war = new War(argWarName, argSide1, argSide2);
WarData.addWar(war);
war.save();
// Check if side1 is nation or town
// Check if side2 is nation or town
Bukkit.broadcastMessage(Helper.chatLabel() + "War created with the name " + argWarName + ", "
+ argSide1 + " vs. " + argSide2);
Main.warLogger.log(p.getName() + " created a new war with the name " + argWarName + ", " + argSide1
+ " vs. " + argSide2);
} else {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
+ "Invalid Arguments. /war create [name] [side1] [side2]").build());
}
// Check if opposing factions are already at war?
// TODO Add checks here for wether the towns/nations names are valid
Side side1 = new Side(BattleSide.ATTACKER, BattleTeam.SIDE_1, argSide1);
Side side2 = new Side(BattleSide.DEFENDER, BattleTeam.SIDE_2, argSide1);
// TODO Add relevant towns/nations/players to sides
War war = new War(argWarName, side1, side2);
WarManager.getInstance().addWar(war);
war.save();
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "War created with the name " + argWarName + ", "
+ argSide1 + " vs. " + argSide2);
Main.warLogger.log(p.getName() + " created a new war with the name " + argWarName + ", " + argSide1
+ " vs. " + argSide2);
}
private static void warDelete(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
if (args.count() >= 1) {
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name.").build());
War war = WarData.getWar(argWarName);
War war = WarManager.getInstance().getWar(argWarName);
if (war == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cWar not found. Type /war list to view current wars.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cWar not found. Type /war list to view current wars.").build());
for (Siege s : war.getSieges()) {
for (OldSiege s : war.getSieges()) {
s.stop();
}
for (Raid r : war.getRaids()) {
for (OldRaid r : war.getRaids()) {
r.stop();
}
WarData.removeWar(war);
WarManager.getInstance().removeWar(war);
Bukkit.broadcast(new ColorParser(Helper.chatLabel() + "War " + argWarName + " deleted.").build());
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "War " + argWarName + " deleted.").build());
Main.warLogger.log(p.getName() + " deleted " + argWarName);
} else {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix()
+ "Invalid Arguments. /war delete [name]").build());
}
}
@@ -220,25 +230,25 @@ public class WarCommand {
protected static void warJoin(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
// Sufficient args check
if (args.count() < 2)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix()
+ "/war join [name] [side], type /war list to view current wars").build());
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name.").build());
War war = WarData.getWar(argWarName);
War war = WarManager.getInstance().getWar(argWarName);
if (war == null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cWar not found. /war join [name] [side], type /war list to view current wars.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cWar not found. /war join [name] [side], type /war list to view current wars.").build());
if (!(args.get("side") instanceof final String argSide))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a side.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a side.").build());
if (!war.isSideValid(argSide))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cThat side does not exist in that war.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThat side does not exist in that war.").build());
if (!(args.getOptional("player").orElse(null) instanceof @Nullable Player argPlayer))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cPlayer not found.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cPlayer not found.").build());
if (argPlayer == null) {
argPlayer = p;
@@ -283,10 +293,10 @@ public class WarCommand {
// Side checks
final TownWarState side = war.getState(town.getName().toLowerCase());
if (side == TownWarState.SURRENDERED) {
argPlayer.sendMessage(Helper.chatLabel() + "You've already surrendered!");
argPlayer.sendMessage(UtilsChat.getPrefix() + "You've already surrendered!");
return;
} else if (side != TownWarState.NOT_PARTICIPANT) {
argPlayer.sendMessage(Helper.chatLabel() + "You're already in this war!");
argPlayer.sendMessage(UtilsChat.getPrefix() + "You're already in this war!");
return;
}
@@ -294,25 +304,25 @@ public class WarCommand {
if (res.getPlayer().hasPermission("AlathraWar.nationjoin") || res.isKing()) {
// Has nation declaration permission
war.addNation(res.getNationOrNull(), argSide);
res.getPlayer().sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getNationOrNull().getName());
p.sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getNationOrNull().getName());
Bukkit.broadcastMessage(Helper.chatLabel() + "The nation of " + res.getNationOrNull().getName() + " has joined the war on the side of " + argSide + "!");
res.getPlayer().sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getNationOrNull().getName());
p.sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getNationOrNull().getName());
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The nation of " + res.getNationOrNull().getName() + " has joined the war on the side of " + argSide + "!");
war.save();
} else {
// Cannot declare nation involvement
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "You cannot declare war for your nation.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot declare war for your nation.").build());
}
} else if (res.hasTown()) {
if (res.getPlayer().hasPermission("AlathraWar.townjoin") || res.isMayor()) {
// Is in indepdenent town & has declaration perms
war.addTown(res.getTownOrNull(), argSide);
res.getPlayer().sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getTownOrNull().getName());
p.sendMessage(Helper.chatLabel() + "You have joined the war for " + res.getTownOrNull().getName());
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + res.getTownOrNull().getName() + " has joined the war on the side of " + argSide + "!");
res.getPlayer().sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getTownOrNull().getName());
p.sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getTownOrNull().getName());
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + res.getTownOrNull().getName() + " has joined the war on the side of " + argSide + "!");
war.save();
} else {
// No perms
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "You cannot declare war for your town.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot declare war for your town.").build());
}
}
}
@@ -320,25 +330,25 @@ public class WarCommand {
protected static void warSurrender(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
// Sufficient args check
if (args.count() < 1) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix()
+ "/war surrender [name], type /war list to view current wars").build());
}
if (!(args.get("war") instanceof final String argWarName))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a war name.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name.").build());
// War check
War war = WarData.getWar(argWarName);
War war = WarManager.getInstance().getWar(argWarName);
if (war == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel()
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix()
+ "War not found. Type /war list to view current wars").build());
}
if (!(args.get("reason") instanceof final String argReason))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cYou need to specify a reason.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a reason.").build());
if (!(args.getOptional("player").orElse(null) instanceof @Nullable Player argPlayer))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "&cPlayer not found.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cPlayer not found.").build());
if (argPlayer == null) {
argPlayer = p;
@@ -357,35 +367,35 @@ public class WarCommand {
if (p.hasPermission("AlathraWar.nationsurrender") || res.isKing() || admin) {
// Has nation surrender permission
war.surrenderNation(res.getNationOrNull());
argPlayer.sendMessage(Helper.chatLabel() + "You have surrendered the war for " + res.getNationOrNull().getName());
Bukkit.broadcastMessage(Helper.chatLabel() + "The nation of " + res.getNationOrNull().getName() + " has surrendered! They were fighting for " + argReason + ".");
argPlayer.sendMessage(UtilsChat.getPrefix() + "You have surrendered the war for " + res.getNationOrNull().getName());
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The nation of " + res.getNationOrNull().getName() + " has surrendered! They were fighting for " + argReason + ".");
war.save();
} else {
// Cannot surrender nation involvement
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "You cannot surrender war for your nation.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot surrender war for your nation.").build());
}
} else if (res.hasTown()) {
if (p.hasPermission("AlathraWar.townsurrender") || res.isMayor() || admin) {
// Is in indepdenent town & has surrender perms
war.surrenderTown(res.getTownOrNull().getName());
argPlayer.sendMessage(Helper.chatLabel() + "You have surrendered the war for " + res.getTownOrNull().getName());
Bukkit.broadcastMessage(Helper.chatLabel() + "The town of " + res.getTownOrNull().getName() + " has surrendered! They were fighting for " + argReason + ".");
argPlayer.sendMessage(UtilsChat.getPrefix() + "You have surrendered the war for " + res.getTownOrNull().getName());
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + res.getTownOrNull().getName() + " has surrendered! They were fighting for " + argReason + ".");
war.save();
} else {
// No perms
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "You cannot surrender war for your town.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot surrender war for your town.").build());
}
}
}
private static void warList(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
ArrayList<War> wars = WarData.getWars();
ArrayList<War> wars = WarManager.getInstance().getWars();
if (wars.isEmpty()) {
p.sendMessage("There are no current wars.");
} else {
p.sendMessage(Helper.chatLabel() + "Wars:");
p.sendMessage(UtilsChat.getPrefix() + "Wars:");
for (War war : wars) {
p.sendMessage(war.getName() + " - " + war.getSide1() + " (" + war.getSide1Points() + ") vs. " + war.getSide2() + " (" + war.getSide2Points() + ")");
@@ -395,7 +405,7 @@ public class WarCommand {
private static void warInfo(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
if (args.count() < 1) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "/war info [Player]").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/war info [Player]").build());
}
if (!(args.get("player") instanceof Player argsPlayer))
@@ -403,11 +413,11 @@ public class WarCommand {
Resident res = TownyAPI.getInstance().getResident(argsPlayer);
if (res == null || res.getTownOrNull() == null) {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(Helper.chatLabel() + "Invalid town resident.").build());
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid town resident.").build());
}
p.sendMessage(new ColorParser(Helper.chatLabel() + p.getName() + "'s wars:").build());
for (War war : WarData.getWars()) {
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + p.getName() + "'s wars:").build());
for (War war : WarManager.getInstance().getWars()) {
TownWarState side = war.getState(res.getTownOrNull());
if (side != TownWarState.NOT_PARTICIPANT) {
if (side == TownWarState.SURRENDERED) {
@@ -434,9 +444,9 @@ public class WarCommand {
// private static void consoleCommand(CommandSender sender, CommandArguments args) {
// if (args.length < 1) return;
// if (args[0].equalsIgnoreCase("list")) {
// ArrayList<War> warList = WarData.getWars();
// ArrayList<War> warList = WarManager.getInstance().getWars();
// sender.sendMessage("Wars: " + warList.size());
// for (War war : WarData.getWars()) {
// for (War war : WarManager.getInstance().getWars()) {
// if (war == null) continue;
// sender.sendMessage(war.toString());
// }
@@ -0,0 +1,5 @@
package me.ShermansWorld.AlathraWar.conflict;
public class Conflict {
private ConflictType conflictType;
}
@@ -0,0 +1,5 @@
package me.ShermansWorld.AlathraWar.conflict;
public enum ConflictType {
WAR
}
@@ -0,0 +1,448 @@
package me.ShermansWorld.AlathraWar.conflict;
import com.github.milkdrinkers.colorparser.ColorParser;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town;
import dev.jorel.commandapi.CommandAPIBukkit;
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
import me.ShermansWorld.AlathraWar.conflict.battle.Raid;
import me.ShermansWorld.AlathraWar.conflict.battle.Side;
import me.ShermansWorld.AlathraWar.conflict.battle.Siege;
import me.ShermansWorld.AlathraWar.enums.BattleSide;
import me.ShermansWorld.AlathraWar.enums.BattleTeam;
import me.ShermansWorld.AlathraWar.holder.WarManager;
import me.ShermansWorld.AlathraWar.utility.UtilsChat;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
/**
* The type New war.
*/
public class War extends Conflict {
private final UUID uuid;
private final String name; // Used in commands and such, like "TidalHaven.vs.Meme"
private final String label;
private final ConflictType conflictType = ConflictType.WAR;
private final Side side1;
private final Side side2;
private final Side attacker; // Reference variable to side1 or side2
private final Side defender; // Reference variable to side1 or side2
private final Set<Siege> sieges = new HashSet<>();
private final Set<Raid> raids = new HashSet<>();
// Merged utility data from Side's
private Set<Player> players = new HashSet<>();
private Set<UUID> playersIncludingOffline = new HashSet<>();
/**
* Instantiates a new New war.
*
* @param label the name
* @param aggressor the side 1
* @param victim the side 2
*/
public War(final String label, Town aggressor, Town victim) throws WrapperCommandSyntaxException {
this.uuid = generateUUID();
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
this.label = label;
if (WarManager.getInstance().getWar(this.name) != null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name!").build());
this.side1 = new Side(this.uuid, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
this.side2 = new Side(this.uuid, victim, BattleSide.DEFENDER, BattleTeam.SIDE_2);
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
recalculatePlayers();
}
public War(final String label, Nation aggressor, Nation victim) throws WrapperCommandSyntaxException {
this.uuid = generateUUID();
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
this.label = label;
if (WarManager.getInstance().getWar(this.name) != null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name!").build());
this.side1 = new Side(this.uuid, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
this.side2 = new Side(this.uuid, victim, BattleSide.DEFENDER, BattleTeam.SIDE_2);
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
recalculatePlayers();
}
public War(final String label, Town aggressor, Nation victim) throws WrapperCommandSyntaxException {
this.uuid = generateUUID();
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
this.label = label;
if (WarManager.getInstance().getWar(this.name) != null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name!").build());
this.side1 = new Side(this.uuid, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
this.side2 = new Side(this.uuid, victim, BattleSide.DEFENDER, BattleTeam.SIDE_2);
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
recalculatePlayers();
}
public War(final String label, Nation aggressor, Town victim) throws WrapperCommandSyntaxException {
this.uuid = generateUUID();
this.name = "%s.vs.%s".formatted(aggressor.getName(), victim.getName());
this.label = label;
if (WarManager.getInstance().getWar(this.name) != null)
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name!").build());
this.side1 = new Side(this.uuid, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
this.side2 = new Side(this.uuid, victim, BattleSide.DEFENDER, BattleTeam.SIDE_2);
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
recalculatePlayers();
}
private UUID generateUUID() {
UUID uuid = UUID.randomUUID();
while (WarManager.getInstance().getWar(uuid) != null) {
uuid = UUID.randomUUID();
}
return UUID.randomUUID();
}
/**
* Gets uuid.
*
* @return the uuid
*/
public UUID getUUID() {
return this.uuid;
}
/**
* Gets name.
*
* @return the name
*/
@NotNull
public String getName() {
return name;
}
@NotNull
public String getLabel() {
return label;
}
/**
* Equals boolean.
*
* @param uuid the uuid
* @return the boolean
*/
public boolean equals(UUID uuid) {
return this.uuid.equals(uuid);
}
/**
* Equals boolean.
*
* @param war the war
* @return the boolean
*/
public boolean equals(War war) {
return this.uuid.equals(war.getUUID());
}
/**
* Equals boolean.
*
* @param warName the war name
* @return the boolean
*/
public boolean equals(String warName) {
return this.name.equals(warName);
}
/**
* Gets side 1.
*
* @return the side 1
*/
@NotNull
public Side getSide1() {
return side1;
}
/**
* Gets side 2.
*
* @return the side 2
*/
@NotNull
public Side getSide2() {
return side2;
}
@NotNull
public Set<Side> getSides() {
final Set<Side> sides = new HashSet<>();
sides.add(getSide1());
sides.add(getSide2());
return sides;
}
/**
* Gets attacker.
*
* @return the attacker
*/
@NotNull
public Side getAttacker() {
return attacker;
}
/**
* Gets defender.
*
* @return the defender
*/
@NotNull
public Side getDefender() {
return defender;
}
@Nullable
public Side getSide(String name) {
if (getSide1().equals(name))
return getSide1();
if (getSide2().equals(name))
return getSide2();
return null;
}
@Nullable
public Side getSide(UUID uuid) {
if (getSide1().equals(uuid))
return getSide1();
if (getSide2().equals(uuid))
return getSide2();
return null;
}
/**
* Gets surrendered.
*
* @return the surrendered
*/
// public Set<UUID> getSurrenderedPlayers() {
// return surrendered;
// }
/**
* Gets sieges.
*
* @return the sieges
*/
@NotNull
public Set<Siege> getSieges() {
return sieges;
}
/**
* Add siege.
*
* @param siege the siege
*/
public void addSiege(Siege siege) {
sieges.add(siege);
}
/**
* Gets raids.
*
* @return the raids
*/
@NotNull
public Set<Raid> getRaids() {
return raids;
}
/**
* Add raid.
*
* @param raid the raid
*/
public void addRaid(Raid raid) {
raids.add(raid);
}
/**
* Gets all players in the war, including offline players.
*
* @return the all players
*/
@NotNull
public Set<OfflinePlayer> getPlayersIncludingOffline() {
final Set<OfflinePlayer> playersIncludingOffline = new HashSet<>();
for (UUID uuid : this.playersIncludingOffline)
playersIncludingOffline.add(Bukkit.getOfflinePlayer(uuid));
return playersIncludingOffline;
}
/**
* Gets all players in the war, including offline players.
*
* @return the all players
*/
@NotNull
public Set<Player> getPlayers() {
return players;
}
public void recalculatePlayers() {
final Set<UUID> newPlayersIncludingOffline = new HashSet<>();
newPlayersIncludingOffline.addAll(side1.getPlayersIncludingOffline());
newPlayersIncludingOffline.addAll(side2.getPlayersIncludingOffline());
playersIncludingOffline = newPlayersIncludingOffline;
final Set<Player> newPlayers = new HashSet<>();
newPlayers.addAll(side1.getPlayers());
newPlayers.addAll(side2.getPlayers());
players = newPlayers;
}
public boolean isPlayerInWar(Player p) {
return side1.isPlayerOnSide(p) || side2.isPlayerOnSide(p);
}
public boolean isPlayerInWar(UUID uuid) {
return side1.isPlayerOnSide(uuid) || side2.isPlayerOnSide(uuid);
}
@Nullable
public Side getPlayerSide(Player p) {
if (side1.isPlayerOnSide(p))
return getSide1();
if (side2.isPlayerOnSide(p))
return getSide2();
return null;
}
@Nullable
public Side getPlayerSide(UUID uuid) {
if (side1.isPlayerOnSide(uuid))
return getSide1();
if (side2.isPlayerOnSide(uuid))
return getSide2();
return null;
}
public boolean isTownInWar(Town town) {
return side1.isTownOnSide(town) || side2.isTownOnSide(town);
}
@Nullable
public Side getTownSide(Town town) {
if (side1.isTownOnSide(town))
return getSide1();
if (side2.isTownOnSide(town))
return getSide2();
return null;
}
public boolean isNationInWar(Nation nation) {
return side1.isNationOnSide(nation) || side2.isNationOnSide(nation);
}
@Nullable
public Side getNationSide(Nation nation) {
if (side1.isNationOnSide(nation))
return getSide1();
if (side2.isNationOnSide(nation))
return getSide2();
return null;
}
public boolean isSideValid(String sideName) {
return getSide1().equals(sideName) || getSide2().equals(sideName);
}
@NotNull
public Set<Town> getTowns() {
Set<Town> towns = new HashSet<>();
towns.addAll(side1.getTowns());
towns.addAll(side2.getTowns());
return towns;
}
@NotNull
public Set<Nation> getNations() {
Set<Nation> nations = new HashSet<>();
nations.addAll(side1.getNations());
nations.addAll(side2.getNations());
return nations;
}
@NotNull
public Set<Town> getSurrenderedTowns() {
Set<Town> towns = new HashSet<>();
towns.addAll(side1.getSurrenderedTowns());
towns.addAll(side2.getSurrenderedTowns());
return towns;
}
@NotNull
public Set<Nation> getSurrenderedNations() {
Set<Nation> nations = new HashSet<>();
nations.addAll(side1.getSurrenderedNations());
nations.addAll(side2.getSurrenderedNations());
return nations;
}
public void start() {
}
public void end() {
}
}
@@ -0,0 +1,4 @@
package me.ShermansWorld.AlathraWar.conflict.battle;
public class Battle {
}
@@ -0,0 +1,4 @@
package me.ShermansWorld.AlathraWar.conflict.battle;
public class Raid extends Battle {
}
@@ -0,0 +1,389 @@
package me.ShermansWorld.AlathraWar.conflict.battle;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.conflict.War;
import me.ShermansWorld.AlathraWar.enums.BattleSide;
import me.ShermansWorld.AlathraWar.enums.BattleTeam;
import me.ShermansWorld.AlathraWar.holder.WarManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.time.Duration;
import java.time.Instant;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class Side {
private UUID warUUID;
private UUID uuid;
private final BattleSide side;
private final BattleTeam team;
private final String name; // A town or nation name
// TODO Use Town & Nation UUID's when saving to config
private final Town town; // The initiating town or capital of the nation
private final Set<Town> towns; // A list of participating Towns
private final Set<Nation> nations; // A list of participating Nations
private final Set<UUID> playersIncludingOffline; // A list of all participating player UUID, (Online & Offline)
private final Set<Player> players; // A list of the players who are currently online
// TODO Figure out how to work this stuff, FYI Towns and Nations have UUID's
private final Set<Town> surrenderedTowns;
private final Set<Nation> surrenderedNations;
private final Set<UUID> surrenderedPlayersIncludingOffline;
private static final Duration SIEGE_COOLDOWN = Duration.ofMinutes(120);
private static final Duration RAID_COOLDOWN = Duration.ofMinutes(30);
private Instant siegeGrace = Instant.EPOCH; // The time after which this side can be besieged
private Instant raidGrace = Instant.EPOCH; // The time after which this side can be raided
private int score = 0;
public Side(UUID warUUID, Town town, BattleSide side, BattleTeam team) {
this.warUUID = warUUID;
this.side = side;
this.team = team;
this.town = town;
this.name = this.town.getName();
this.towns = new HashSet<>();
this.nations = new HashSet<>();
this.playersIncludingOffline = new HashSet<>();
this.players = new HashSet<>();
this.surrenderedTowns = new HashSet<>();
this.surrenderedNations = new HashSet<>();
this.surrenderedPlayersIncludingOffline = new HashSet<>();
addTown(this.town);
calculateOnlinePlayers();
}
public Side(UUID warUUID, Nation nation, BattleSide side, BattleTeam team) {
this.warUUID = warUUID;
this.side = side;
this.team = team;
this.town = nation.getCapital();
this.name = this.town.getName();
this.towns = new HashSet<>();
this.nations = new HashSet<>();
this.playersIncludingOffline = new HashSet<>();
this.players = new HashSet<>();
this.surrenderedTowns = new HashSet<>();
this.surrenderedNations = new HashSet<>();
this.surrenderedPlayersIncludingOffline = new HashSet<>();
addNation(nation);
calculateOnlinePlayers();
}
public BattleSide getSide() {
return side;
}
public BattleTeam getTeam() {
return team;
}
public String getName() {
return name;
}
public Set<Nation> getNations() {
return nations;
}
public Set<Town> getTowns() {
return towns;
}
public Set<UUID> getPlayersIncludingOffline() {
return playersIncludingOffline;
}
public Set<Player> getPlayers() {
return players;
}
public Set<Town> getSurrenderedTowns() {
return surrenderedTowns;
}
public Set<Nation> getSurrenderedNations() {
return surrenderedNations;
}
public Set<UUID> getSurrenderedPlayersIncludingOffline() {
return surrenderedPlayersIncludingOffline;
}
// Participant management
public boolean isTownOnSide(Town town) {
return towns.contains(town) || surrenderedTowns.contains(town);
}
public boolean isNationOnSide(Nation nation) {
return nations.contains(nation) || surrenderedNations.contains(nation);
}
public boolean isTownSurrendered(Town town) {
return surrenderedTowns.contains(town);
}
public boolean isNationSurrendered(Nation nation) {
return surrenderedNations.contains(nation);
}
public void addTown(Town town) {
if (isTownOnSide(town)) return;
towns.add(town);
town.getResidents().forEach((Resident resident) -> addPlayer(resident.getUUID()));
}
public void addNation(Nation nation) {
if (isNationOnSide(nation)) return;
nations.add(nation);
nation.getTowns().forEach(this::addTown);
}
public void removeTown(Town town) {
if (!isTownOnSide(town)) return;
towns.remove(town);
town.getResidents().forEach((Resident resident) -> removePlayer(resident.getUUID()));
}
public void removeNation(Nation nation) {
if (!isNationOnSide(nation)) return;
nations.remove(nation);
nation.getTowns().forEach(this::removeTown);
}
public void surrenderTown(Town town) {
if (isTownSurrendered(town)) return;
towns.remove(town);
town.getResidents().forEach((Resident resident) -> surrenderPlayer(resident.getUUID()));
surrenderedTowns.add(town);
}
public void surrenderNation(Nation nation) {
if (isNationSurrendered(nation)) return;
nations.remove(nation);
nation.getTowns().forEach(this::surrenderTown);
surrenderedNations.add(nation);
}
public boolean isPlayerOnSide(Player p) {
return isPlayerOnSide(p.getUniqueId());
}
public boolean isPlayerOnSide(UUID uuid) {
return playersIncludingOffline.contains(uuid) || surrenderedPlayersIncludingOffline.contains(uuid);
}
public boolean isPlayerSurrendered(Player p) {
return isPlayerSurrendered(p.getUniqueId());
}
public boolean isPlayerSurrendered(UUID uuid) {
return surrenderedPlayersIncludingOffline.contains(uuid);
}
public void addPlayer(Player p) {
if (isPlayerOnSide(p)) return;
playersIncludingOffline.add(p.getUniqueId());
calculateOnlinePlayers();
}
public void addPlayer(OfflinePlayer offlinePlayer) {
if (offlinePlayer.isOnline())
addPlayer(offlinePlayer.getPlayer());
if (offlinePlayer.hasPlayedBefore()) {
if (isPlayerOnSide(offlinePlayer.getUniqueId())) return;
playersIncludingOffline.add(offlinePlayer.getUniqueId());
calculateOnlinePlayers();
}
}
public void addPlayer(UUID uuid) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
addPlayer(offlinePlayer);
}
public void removePlayer(Player p) {
playersIncludingOffline.remove(p.getUniqueId());
calculateOnlinePlayers();
}
public void removePlayer(OfflinePlayer offlinePlayer) {
if (offlinePlayer.isOnline())
removePlayer(offlinePlayer.getPlayer());
if (offlinePlayer.hasPlayedBefore()) {
playersIncludingOffline.remove(offlinePlayer.getUniqueId());
calculateOnlinePlayers();
}
}
public void removePlayer(UUID uuid) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
removePlayer(offlinePlayer);
}
public void surrenderPlayer(Player p) {
surrenderPlayer(p.getUniqueId());
}
public void surrenderPlayer(UUID uuid) {
if (isPlayerSurrendered(uuid)) return;
removePlayer(uuid);
surrenderedPlayersIncludingOffline.add(uuid);
}
public void calculateOnlinePlayers() {
final Set<UUID> players = getPlayersIncludingOffline();
final Set<Player> onlinePlayers = new HashSet<>();
for (UUID uuid : players) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
if (offlinePlayer.isOnline())
onlinePlayers.add(offlinePlayer.getPlayer());
}
this.players.clear();
this.players.addAll(onlinePlayers);
}
// Graces
public Instant getSiegeGrace() {
return this.siegeGrace;
}
public void setSiegeGrace() {
this.siegeGrace = Instant.now().plus(SIEGE_COOLDOWN);
}
public boolean isSiegeGraceActive() {
return this.siegeGrace.isAfter(Instant.now());
}
public Duration getSiegeGraceCooldown() {
return Duration.between(Instant.now(), this.siegeGrace);
}
public Instant getRaidGrace() {
return this.raidGrace;
}
public void setRaidGrace() {
this.raidGrace = Instant.now().plus(RAID_COOLDOWN);
}
public boolean isRaidGraceActive() {
return this.raidGrace.isAfter(Instant.now());
}
public Duration getRaidGraceCooldown() {
return Duration.between(Instant.now(), this.raidGrace);
}
// Score
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public void addScore(int add) {
this.score += add;
}
// Comparators & UUID
private UUID generateUUID() {
UUID uuid = UUID.randomUUID();
while (getWar().getSide(uuid) != null) {
uuid = UUID.randomUUID();
}
return UUID.randomUUID();
}
public boolean equals(UUID uuid) {
return this.uuid.equals(uuid);
}
public boolean equals(War war) {
return this.warUUID.equals(war.getUUID());
}
public boolean equals(Side side) {
return this.uuid.equals(side.getUUID());
}
public boolean equals(String sideName) {
return this.name.equals(sideName);
}
public UUID getUUID() {
return this.uuid;
}
@NotNull
@SuppressWarnings({"all"})
public War getWar() {
return WarManager.getInstance().getWar(warUUID); // The war must exist, or this object wouldn't
}
// TODO Make object serializable
/*private void writeObject(ObjectOutputStream oos)
throws IOException {
oos.defaultWriteObject();
oos.writeObject(address.getHouseNumber());
}
private void readObject(ObjectInputStream ois)
throws ClassNotFoundException, IOException {
ois.defaultReadObject();
Integer houseNumber = (Integer) ois.readObject();
Address a = new Address();
a.setHouseNumber(houseNumber);
this.setAddress(a);
}*/
}
@@ -0,0 +1,4 @@
package me.ShermansWorld.AlathraWar.conflict.battle;
public class Siege extends Battle {
}
@@ -7,7 +7,7 @@ public enum RaidPhase {
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
//Start phase starts when the command to start a raid is ran, it allows the raiders to join, and for people to getInstance 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,
@@ -1,132 +0,0 @@
package me.ShermansWorld.AlathraWar.data;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.War;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import java.util.*;
public class SiegeData {
// Static Siege list for all active sieges
private static final HashSet<Siege> sieges = new HashSet<>();
public static HashSet<Siege> getSieges() {
return sieges;
}
public static void setSieges(ArrayList<Siege> sieges) {
for (Siege siege : sieges) {
addSiege(siege);
}
}
/**
* Gets a siege with a specific name
*
* @param name - Name to check
* @return Siege or Null
*/
public static Siege getSiege(String name) {
for (Siege siege : sieges) {
if (siege.getTown().getName().equalsIgnoreCase(name)) return siege;
}
return null;
}
public static void addSiege(Siege siege) {
if (siege == null) {
Main.warLogger.log("Attempted to add NULL to siege list.");
return;
}
sieges.add(siege);
}
public static void removeSiege(Siege siege) {
sieges.remove(siege);
//deleteSiege(siege);d
}
/**
* Creates a siege object from a provided HashMap
*
* @param fileData data
* @return Siege object
*/
private static Siege fromMap(War war, HashMap<String, Object> fileData) {
if (fileData.get("town") == null || fileData.get("side1AreAttackers") == null) {
return null;
}
Town town = TownyAPI.getInstance().getTown((String) fileData.get("town"));
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString((String) fileData.get("siegeLeader")));
return new Siege(war, town, offlinePlayer);
}
/**
* Saves the war into files.
*
* @param siege - Siege to be saved.
*/
public static void saveSiege(Siege siege) {
War war = siege.getWar();
war.save();
}
/**
* Turns a siege into a map
*
* @param siege - Siege
* @return Map
*/
public static HashMap<String, Object> siegeToMap(Siege siege) {
HashMap<String, Object> returnMap = new HashMap<>();
// Shoves everything into a map.
returnMap.put("town", siege.getTown().getName());
returnMap.put("siegeTicks", siege.getSiegeTicks());
returnMap.put("attackerPoints", siege.getAttackerPoints());
returnMap.put("defenderPoints", siege.getDefenderPoints());
returnMap.put("side1AreAttackers", Boolean.toString(siege.getSide1AreAttackers()));
returnMap.put("siegeLeader", siege.getSiegeLeader().getUniqueId().toString());
return returnMap;
}
/**
* Creates a map of siege maps
*
* @param war - War to map
* @return Map of Maps
*/
public static HashMap<String, Object> getSiegeMap(War war) {
HashMap<String, Object> returnMap = new HashMap<>();
for (Siege siege : war.getSieges()) {
returnMap.put(siege.getTown().getName(), siegeToMap(siege));
}
return returnMap;
}
public static ArrayList<Siege> createSieges(War war, Collection<HashMap<String, Object>> siegeMaps) {
ArrayList<Siege> returnList = new ArrayList<>();
for (HashMap<String, Object> map : siegeMaps) {
Town town = TownyAPI.getInstance().getTown((String) map.get("town"));
if (town == null) continue;
Siege siege = fromMap(war, map);
siege.addPointsToAttackers((int) map.get("attackerPoints"));
siege.addPointsToDefenders((int) map.get("defenderPoints"));
siege.resume((int) map.get("siegeTicks"));
siege.setWar(war);
returnList.add(siege);
}
return returnList;
}
}
@@ -1,184 +0,0 @@
package me.ShermansWorld.AlathraWar.data;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.War;
import java.io.File;
import java.io.FilenameFilter;
import java.util.*;
public class WarData {
private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
// Filter for only accessing yml files
private static final FilenameFilter ymlFilter = (dir, name) -> name.endsWith(".yml");
// Static War list for all active wars
private static ArrayList<War> wars = new ArrayList<>();
// Constructor used to initialise folder.
public WarData(final Main plugin) {
File userDataFolder = new File(dataFolderPath + File.separator + "wars");
if (!userDataFolder.exists()) {
userDataFolder.mkdirs();
}
}
public static ArrayList<War> getWars() {
return wars;
}
public static void setWars(ArrayList<War> wars) {
WarData.wars = wars;
}
public static Collection<String> getWarsNames() {
List<String> warNames = new ArrayList<>();
for (War war : getWars()) {
warNames.add(war.getName());
}
Collections.sort(warNames);
return warNames;
}
/**
* Gets a war with a specific name
*
* @param name - Name to check
* @return War or Null
*/
public static War getWar(String name) {
for (War war : wars) {
if (war.getName().equalsIgnoreCase(name)) return war;
}
return null;
}
public static War getWar(UUID uuid) {
for (War war : wars) {
if (war.getUUID().equals(uuid)) return war;
}
return null;
}
public static void addWar(War war) {
if (war == null) {
Main.warLogger.log("Attempted to add NULL to war list.");
return;
}
wars.add(war);
}
public static void removeWar(War war) {
wars.remove(war);
deleteWar(war);
}
/**
* Gets the wars currently saved in files as an ArrayList of War Objects
*
* @return War Object ArrayList
*/
public static ArrayList<War> createWars() {
File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
ArrayList<War> returnList = new ArrayList<>();
for (File file : files) {
try {
HashMap<String, Object> fileData = DataManager.getData(file);
War fileWar = fromMap(fileData);
returnList.add(fileWar);
} catch (Exception e) {
Main.warLogger.log("Failed to load " + file.getName());
e.printStackTrace();
}
}
return returnList;
}
/**
* Creates a war object from a provided HashMap
*
* @param fileData
* @return War object
*/
@SuppressWarnings("unchecked")
public static War fromMap(HashMap<String, Object> fileData) {
War war = new War((String) fileData.get("name"),
(String) fileData.get("side1"),
(String) fileData.get("side2")
);
war.setSide1Towns((ArrayList<String>) fileData.get("side1Towns"));
war.setSide2Towns((ArrayList<String>) fileData.get("side2Towns"));
war.setSurrenderedTowns((ArrayList<String>) fileData.get("surrenderedTowns"));
war.addSide1Points((int) fileData.get("side1Points"));
war.addSide2Points((int) fileData.get("side2Points"));
if (fileData.get("lastRaidTimeSide1") != null && fileData.get("lastRaidTimeSide2") != null) {
war.setLastRaidTimeSide1((int) fileData.get("lastRaidTimeSide1"));
war.setLastRaidTimeSide2((int) fileData.get("lastRaidTimeSide2"));
}
// Siege adding from map.
Collection<HashMap<String, Object>> siegeMaps = ((HashMap<String, HashMap<String, Object>>) fileData.get("sieges")).values();
ArrayList<Siege> sieges = SiegeData.createSieges(war, siegeMaps);
for (Siege siege : sieges) {
war.addSiege(siege);
SiegeData.addSiege(siege);
}
// Raid adding from map.
Collection<HashMap<String, Object>> raidMaps = ((HashMap<String, HashMap<String, Object>>) fileData.get("raids")).values();
ArrayList<Raid> raids = RaidData.createRaids(war, raidMaps);
for (Raid raid : raids) {
war.addRaid(raid);
}
return war;
}
/**
* Saves the war into files.
*
* @param war - War to be saved.
*/
public static void saveWar(War war) {
HashMap<String, Object> sHashMap = new HashMap<>();
// Shoves everything into a map.
sHashMap.put("name", war.getName());
sHashMap.put("side1", war.getSide1());
sHashMap.put("side2", war.getSide2());
sHashMap.put("side1Towns", war.getSide1Towns());
sHashMap.put("side2Towns", war.getSide2Towns());
sHashMap.put("surrenderedTowns", war.getSurrenderedTowns());
sHashMap.put("side1Points", war.getSide1Points());
sHashMap.put("side2Points", war.getSide2Points());
sHashMap.put("sieges", SiegeData.getSiegeMap(war));
sHashMap.put("raids", RaidData.getRaidMap(war));
sHashMap.put("lastRaidTimeSide1", war.getLastRaidTimeSide1());
sHashMap.put("lastRaidTimeSide2", war.getLastRaidTimeSide2());
DataManager.saveData("wars" + File.separator + war.getName() + ".yml", sHashMap);
}
private static void deleteWar(War war) {
File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
for (File file : files) {
if (file.getName().startsWith(war.getName())) {
file.delete();
}
}
}
}
@@ -0,0 +1,7 @@
package me.ShermansWorld.AlathraWar.enums;
public enum BattleSide {
ATTACKER,
DEFENDER,
SPECTATOR,
}
@@ -0,0 +1,8 @@
package me.ShermansWorld.AlathraWar.enums;
public enum BattleTeam {
SIDE_1,
SIDE_2,
SURRENDERED,
NEUTRAL, // Not Participating
}
@@ -0,0 +1,38 @@
package me.ShermansWorld.AlathraWar.events;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PreWarCreateEvent extends Event implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancelled;
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
@Override
public boolean isCancelled() {
return this.cancelled;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins.
*
* @param cancelled true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
}
@@ -0,0 +1,38 @@
package me.ShermansWorld.AlathraWar.events;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class PreWarDeleteEvent extends Event implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancelled;
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
@Override
public boolean isCancelled() {
return this.cancelled;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins.
*
* @param cancelled true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
}
@@ -0,0 +1,38 @@
package me.ShermansWorld.AlathraWar.events;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class WarCreateEvent extends Event implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancelled;
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
@Override
public boolean isCancelled() {
return this.cancelled;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins.
*
* @param cancelled true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
}
@@ -0,0 +1,38 @@
package me.ShermansWorld.AlathraWar.events;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class WarDeleteEvent extends Event implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancelled;
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
@Override
public boolean isCancelled() {
return this.cancelled;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins.
*
* @param cancelled true if you wish to cancel this event
*/
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLER_LIST;
}
}
@@ -0,0 +1,4 @@
package me.ShermansWorld.AlathraWar.holder;
public class Holder {
}
@@ -0,0 +1,122 @@
package me.ShermansWorld.AlathraWar.holder;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.conflict.War;
import me.ShermansWorld.AlathraWar.conflict.battle.Raid;
import me.ShermansWorld.AlathraWar.conflict.battle.Siege;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.inject.Singleton;
import java.util.*;
@Singleton
public class WarManager {
private static WarManager instance;
private final Set<War> wars = new HashSet<>();
private WarManager() {
if (instance != null)
Bukkit.getServer().getLogger().warning("Tried to re-initialize singleton");
}
@NotNull
public static WarManager getInstance() {
if (instance == null) new WarManager();
return instance;
}
@NotNull
public Set<War> getWars() {
return wars;
}
@Nullable
public War getWar(String warName) {
for (War war : wars)
if (war.equals(warName)) return war;
return null;
}
@Nullable
public War getWar(UUID uuid) {
for (War war : wars)
if (war.equals(uuid)) return war;
return null;
}
public void addWar(War war) {
wars.add(war);
}
public void removeWar(War war) {
wars.remove(war);
}
public boolean isPlayerInAnyWars(UUID uuid) {
for (War war : wars) {
if (war.isPlayerInWar(uuid)) return true;
};
return false;
}
public boolean isPlayerInAnyWars(Player p) {
for (War war : wars) {
if (war.isPlayerInWar(p)) return true;
};
return false;
}
public boolean isTownInAnyWars(Town town) {
for (War war : wars) {
if (war.isTownInWar(town)) return true;
};
return false;
}
public boolean isNationInAnyWars(Nation nation) {
for (War war : wars) {
if (war.isNationInWar(nation)) return true;
};
return false;
}
@NotNull
public List<String> getWarNames() {
final List<String> names = new ArrayList<>();
wars.forEach((War war) -> names.add(war.getName()));
names.sort(String::compareToIgnoreCase);
return names;
}
@NotNull
public List<String> getWarLabels() {
final List<String> labels = new ArrayList<>();
wars.forEach((War war) -> labels.add(war.getLabel()));
labels.sort(String::compareToIgnoreCase);
return labels;
}
@NotNull
public Set<Siege> getSieges() {
final Set<Siege> sieges = new HashSet<>();
wars.forEach((War war) -> sieges.addAll(war.getSieges()));
return sieges;
}
@NotNull
public Set<Raid> getRaids() {
final Set<Raid> raids = new HashSet<>();
wars.forEach((War war) -> raids.addAll(war.getRaids()));
return raids;
}
}
@@ -0,0 +1,21 @@
package me.ShermansWorld.AlathraWar.hooks;
public class HookManager {
public HookManager() {
}
public void onLoad() {
}
public void onEnable() {
TABHook.init();
TownyHook.init();
}
public void onDisable() {
}
}
@@ -1,7 +1,7 @@
package me.ShermansWorld.AlathraWar.hooks;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.War;
import com.github.milkdrinkers.colorparser.ColorParser;
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
import me.ShermansWorld.AlathraWar.listeners.JoinListener;
import me.neznamy.tab.api.TabAPI;
import me.neznamy.tab.api.TabPlayer;
@@ -12,8 +12,8 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class TABHook {
public static boolean enabled = false;
public static TabAPI tabAPI;
private static boolean enabled = false;
private static TabAPI tabAPI;
public static void init() {
if (enabled) return;
@@ -37,7 +37,7 @@ public class TABHook {
});
}
public static void assignSide1WarSuffix(Player p, War war) {
public static void assignSide1WarSuffix(Player p, OldWar oldWar) {
if (!enabled) return;
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
@@ -45,21 +45,20 @@ public class TABHook {
if (tabAPI.getTabListFormatManager() == null) return;
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
Helper.color(" &c[") + war.getSide1() + "]&r");
new ColorParser(" &c[" + oldWar.getSide1() + "]&r").parseLegacy().build());
}
public static void assignSide2WarSuffix(Player p, War war) {
public static void assignSide2WarSuffix(Player p, OldWar oldWar) {
if (!enabled) return;
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
if (tabAPI.getTabListFormatManager() == null) return;
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
Helper.color(" &9[") + war.getSide2() + "]&r");
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, Helper.color(" &9[") + oldWar.getSide2() + "]&r");
}
public static void assignSide1WarSuffixMerc(Player p, War war) {
public static void assignSide1WarSuffixMerc(Player p, OldWar oldWar) {
if (!enabled) return;
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
@@ -67,10 +66,10 @@ public class TABHook {
if (tabAPI.getTabListFormatManager() == null) return;
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
Helper.color(" &a[M]&c[") + war.getSide1() + "]&r");
Helper.color(" &a[M]&c[") + oldWar.getSide1() + "]&r");
}
public static void assignSide2WarSuffixMerc(Player p, War war) {
public static void assignSide2WarSuffixMerc(Player p, OldWar oldWar) {
if (!enabled) return;
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
@@ -78,7 +77,7 @@ public class TABHook {
if (tabAPI.getTabListFormatManager() == null) return;
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
Helper.color(" &a[M]&9[") + war.getSide2() + "]&r");
Helper.color(" &a[M]&9[") + oldWar.getSide2() + "]&r");
}
public static void resetSuffix(Player p) {
@@ -0,0 +1,27 @@
package me.ShermansWorld.AlathraWar.hooks;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town;
import java.util.List;
public class TownyHook {
private static boolean enabled = false;
private static TownyAPI townyAPI;
public static void init() {
if (enabled) return;
townyAPI = TownyAPI.getInstance();
enabled = true;
}
public static List<Town> getTowns() {
return townyAPI.getTowns();
}
public static List<Nation> getNations() {
return townyAPI.getNations();
}
}
@@ -1,6 +1,5 @@
package me.ShermansWorld.AlathraWar.items;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.items.item.RamItem;
import org.bukkit.inventory.ItemStack;
@@ -22,13 +21,13 @@ public class WarItemRegistry {
public WarItemRegistry() {
instance = this;
Main.warLogger.log(Helper.chatLabel() + "Registering AlathraWar items.");
Main.warLogger.log(UtilsChat.getPrefix() + "Registering AlathraWar items.");
itemRegistry.put(registryName("ram"), new RamItem());
//THIS BREAKS EVERYTHING???? TODO
// Bukkit.getServer().addRecipe(new RamItem().getRecipe());
Main.warLogger.log(Helper.chatLabel() + "Registered AlathraWar items.");
Main.warLogger.log(UtilsChat.getPrefix() + "Registered AlathraWar items.");
}
public static WarItemRegistry getInstance() {
@@ -1,6 +1,5 @@
package me.ShermansWorld.AlathraWar.items;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Main;
import org.bukkit.inventory.Recipe;
@@ -15,11 +14,11 @@ public class WarRecipeRegistry {
public WarRecipeRegistry() {
instance = this;
Main.warLogger.log(Helper.chatLabel() + "Registering AlathraWar recipes.");
Main.warLogger.log(UtilsChat.getPrefix() + "Registering AlathraWar recipes.");
// register(WarItemRegistry.registryName("ram"), new RamItem().getRecipes());
Main.warLogger.log(Helper.chatLabel() + "Registered AlathraWar recipes.");
Main.warLogger.log(UtilsChat.getPrefix() + "Registered AlathraWar recipes.");
}
public static WarRecipeRegistry getInstance() {
@@ -1,9 +1,8 @@
package me.ShermansWorld.AlathraWar.listeners;
import com.palmergames.bukkit.towny.object.WorldCoord;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import org.bukkit.Material;
@@ -32,8 +31,8 @@ public class BlockBreakListener implements Listener {
if (SiegeData.getSieges().isEmpty() && RaidData.getRaids().isEmpty()) {
return;
}
for (final Siege siege : SiegeData.getSieges()) {
if (siege.beaconLocs.contains(block.getLocation())) {
for (final OldSiege oldSiege : SiegeData.getSieges()) {
if (oldSiege.beaconLocs.contains(block.getLocation())) {
event.setCancelled(true);
return;
}
@@ -46,16 +45,16 @@ public class BlockBreakListener implements Listener {
return;
}
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
for (final Siege siege : SiegeData.getSieges()) {
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
for (final OldSiege oldSiege : SiegeData.getSieges()) {
if (oldSiege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
p.sendMessage(Helper.color("&cYou can not break blocks during sieges"));
event.setCancelled(true);
return;
}
}
for (final Raid raid : RaidData.getRaids()) {
if (raid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
for (final OldRaid oldRaid : RaidData.getRaids()) {
if (oldRaid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
p.sendMessage(Helper.color("&cYou can not break blocks during raids"));
event.setCancelled(true);
return;
@@ -78,16 +77,16 @@ public class BlockBreakListener implements Listener {
return;
}
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
for (final Siege siege : SiegeData.getSieges()) {
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
for (final OldSiege oldSiege : SiegeData.getSieges()) {
if (oldSiege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
p.sendMessage(Helper.color("&cYou can not place blocks during sieges"));
event.setCancelled(true);
return;
}
}
for (final Raid raid : RaidData.getRaids()) {
if (raid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
for (final OldRaid oldRaid : RaidData.getRaids()) {
if (oldRaid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
p.sendMessage(Helper.color("&cYou can not place blocks during raids"));
event.setCancelled(true);
return;
@@ -1,8 +1,7 @@
package me.ShermansWorld.AlathraWar.listeners;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.data.SiegeData;
@@ -61,11 +60,11 @@ public class CommandsListener implements Listener {
allow n spawn and t spawn for defenders trapped in spawn
*/
for (Raid raid : RaidData.getRaids()) {
for (OldRaid oldRaid : RaidData.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) {
if (oldRaid.getPhase() == RaidPhase.COMBAT || oldRaid.getPhase() == RaidPhase.TRAVEL || oldRaid.getPhase() == RaidPhase.GATHER) {
//only do for active raiders and any defenders
if (raid.getActiveRaiders().contains(p.getName()) || raid.getDefenderPlayers().contains(p.getName())) {
if (oldRaid.getActiveRaiders().contains(p.getName()) || oldRaid.getDefenderPlayers().contains(p.getName())) {
//set spawn and properties
if (args.length >= 3) {
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
@@ -73,7 +72,7 @@ public class CommandsListener implements Listener {
//payment check
for (String cmd : blacklistedXLong) {
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot modify this property during a raid!"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot modify this property during a oldRaid!"));
event.setCancelled(true);
return;
}
@@ -89,7 +88,7 @@ public class CommandsListener implements Listener {
for (String cmd : payment) {
//check for each prefix
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot withdraw money whilst in a raid!"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot withdraw money whilst in a oldRaid!"));
event.setCancelled(true);
return;
}
@@ -104,17 +103,17 @@ public class CommandsListener implements Listener {
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
return;
}
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(Helper.chatLabel() + Helper.color("&eUse /t spawn, or /n spawn"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eUse /t spawn, or /n spawn"));
event.setCancelled(true);
return;
}
//else
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot teleport whilst in a raid!"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot teleport whilst in a oldRaid!"));
event.setCancelled(true);
return;
}
@@ -131,13 +130,13 @@ public class CommandsListener implements Listener {
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
//spawn world check
if (p.getWorld().getName().equalsIgnoreCase("world")) {
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(Helper.chatLabel() + Helper.color("&eUse /t spawn, or /n spawn"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eUse /t spawn, or /n spawn"));
event.setCancelled(true);
return;
}
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot teleport whilst in a raid!"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot teleport whilst in a oldRaid!"));
event.setCancelled(true);
return;
}
@@ -151,11 +150,11 @@ public class CommandsListener implements Listener {
/*
Prevent players from teleporting during a siege
*/
for (Siege siege : SiegeData.getSieges()) {
for (OldSiege oldSiege : SiegeData.getSieges()) {
//Only do this during regular phases, start and end ignored in case something breaks
if (siege.getSiegeTicks() > 0) {
if (oldSiege.getSiegeTicks() > 0) {
//only do for active raiders and any defenders
if (siege.getAttackerPlayers().contains(p.getName()) || siege.getDefenderPlayers().contains(p.getName())) {
if (oldSiege.getAttackerPlayers().contains(p.getName()) || oldSiege.getDefenderPlayers().contains(p.getName())) {
//set spawn and properties
if (args.length >= 3) {
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
@@ -163,7 +162,7 @@ public class CommandsListener implements Listener {
//payment check
for (String cmd : blacklistedXLong) {
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot modify this property during a siege!"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot modify this property during a oldSiege!"));
event.setCancelled(true);
return;
}
@@ -179,7 +178,7 @@ public class CommandsListener implements Listener {
for (String cmd : payment) {
//check for each prefix
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot withdraw money whilst in a siege!"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot withdraw money whilst in a oldSiege!"));
event.setCancelled(true);
return;
}
@@ -194,17 +193,17 @@ public class CommandsListener implements Listener {
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
return;
}
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(Helper.chatLabel() + Helper.color("&eUse /t spawn, or /n spawn"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eUse /t spawn, or /n spawn"));
event.setCancelled(true);
return;
}
//else
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot teleport whilst in a siege!"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot teleport whilst in a oldSiege!"));
event.setCancelled(true);
return;
}
@@ -221,13 +220,13 @@ public class CommandsListener implements Listener {
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
//spawn world check
if (p.getWorld().getName().equalsIgnoreCase("world")) {
p.sendMessage(Helper.chatLabel() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(Helper.chatLabel() + Helper.color("&eUse /t spawn, or /n spawn"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eUse /t spawn, or /n spawn"));
event.setCancelled(true);
return;
}
p.sendMessage(Helper.chatLabel() + Helper.color("&cYou cannot teleport whilst in a siege!"));
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot teleport whilst in a oldSiege!"));
event.setCancelled(true);
return;
}
@@ -3,7 +3,7 @@ package me.ShermansWorld.AlathraWar.listeners;
import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import me.ShermansWorld.AlathraWar.War;
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
import me.ShermansWorld.AlathraWar.data.WarData;
import me.ShermansWorld.AlathraWar.hooks.TABHook;
import org.bukkit.entity.Player;
@@ -22,12 +22,12 @@ public class JoinListener implements Listener {
String townName = town.getName();
boolean inWar = false;
for (final War war : WarData.getWars()) {
if (war.getSide1Towns().contains(townName.toLowerCase())) {
TABHook.assignSide1WarSuffix(p, war);
for (final OldWar oldWar : WarData.getWars()) {
if (oldWar.getSide1Towns().contains(townName.toLowerCase())) {
TABHook.assignSide1WarSuffix(p, oldWar);
inWar = true;
} else if (war.getSide2Towns().contains(townName.toLowerCase())) {
TABHook.assignSide2WarSuffix(p, war);
} else if (oldWar.getSide2Towns().contains(townName.toLowerCase())) {
TABHook.assignSide2WarSuffix(p, oldWar);
inWar = true;
}
}
@@ -4,12 +4,12 @@ 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.WorldCoord;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.utility.Utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -23,7 +23,7 @@ import java.util.UUID;
public final class KillsListener implements Listener {
public static final HashMap<UUID, Raid> respawnQueue = new HashMap<>();
public static final HashMap<UUID, OldRaid> respawnQueue = new HashMap<>();
@EventHandler
public void onPlayerKilled(final PlayerDeathEvent event) {
@@ -40,54 +40,54 @@ public final class KillsListener implements Listener {
boolean playerCloseToHomeBlockRaid = false;
try {
//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;
//OldRaid logic
for (final OldRaid oldRaid : RaidData.getRaids()) {
final int homeBlockXCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
final int homeBlockZCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
// final int homeBlockXCoordGather = oldRaid.getGatherTown().getHomeBlock().getCoord().getX() * 16;
// final int homeBlockZCoordGather = oldRaid.getGatherTown().getHomeBlock().getCoord().getZ() * 16;
//Carryover from sieges
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoordRaided) <= 200 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 200) {
playerCloseToHomeBlockRaid = true;
}
if (raid.getDefenderPlayers().contains(killed.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
if (oldRaid.getDefenderPlayers().contains(killed.getName()) && ((town != null && town.equals(oldRaid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
//There is seperate behavior if combat hasnt started
if (raid.getPhase() == RaidPhase.COMBAT && killer != null) {
if (raid.getActiveRaiders().contains(killer.getName())) {
if (oldRaid.getPhase() == RaidPhase.COMBAT && killer != null) {
if (oldRaid.getActiveRaiders().contains(killer.getName())) {
this.raidKill(killed, event);
raid.defenderKilledInCombat(event);
oldRaid.defenderKilledInCombat(event);
return;
}
}
//teleport back to raided spawn, without damaged gear
this.oocKill(killed, event);
raid.defenderKilledOutofCombat(event);
oldRaid.defenderKilledOutofCombat(event);
return;
}
if (raid.getActiveRaiders().contains(killed.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
if (oldRaid.getActiveRaiders().contains(killed.getName()) && ((town != null && town.equals(oldRaid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
//There is seperate behavior if combat hasnt started
if (raid.getPhase() == RaidPhase.COMBAT && killer != null) {
if (raid.getDefenderPlayers().contains(killer.getName())) {
if (oldRaid.getPhase() == RaidPhase.COMBAT && killer != null) {
if (oldRaid.getDefenderPlayers().contains(killer.getName())) {
this.raidKill(killed, event);
raid.raiderKilledInCombat(event);
respawnQueue.put(killed.getUniqueId(), raid);
oldRaid.raiderKilledInCombat(event);
respawnQueue.put(killed.getUniqueId(), oldRaid);
return;
}
} else if (raid.getPhase() != RaidPhase.COMBAT && killer != null) {
} else if (oldRaid.getPhase() != RaidPhase.COMBAT && killer != null) {
this.oocKill(killed, event);
raid.raiderKilledOutofCombat(event);
respawnQueue.put(killed.getUniqueId(), raid);
oldRaid.raiderKilledOutofCombat(event);
respawnQueue.put(killed.getUniqueId(), oldRaid);
return;
}
//teleport back to gather town spawn, without damaged gear
//this is to disincentive people prekilling
this.oocKill(killed, event);
raid.raiderKilledOutofCombat(event);
respawnQueue.put(killed.getUniqueId(), raid);
oldRaid.raiderKilledOutofCombat(event);
respawnQueue.put(killed.getUniqueId(), oldRaid);
return;
}
if ((town != null && town.equals(raid.getRaidedTown()) || playerCloseToHomeBlockRaid)) {
if ((town != null && town.equals(oldRaid.getRaidedTown()) || playerCloseToHomeBlockRaid)) {
this.raidKill(killed, event);
return;
}
@@ -96,29 +96,29 @@ public final class KillsListener implements Listener {
if (killer == null) return;
for (final Siege siege : SiegeData.getSieges()) {
final int homeBlockXCoord = siege.getTown().getHomeBlock().getCoord().getX() * 16;
final int homeBlockZCoord = siege.getTown().getHomeBlock().getCoord().getZ() * 16;
for (final OldSiege oldSiege : SiegeData.getSieges()) {
final int homeBlockXCoord = oldSiege.getTown().getHomeBlock().getCoord().getX() * 16;
final int homeBlockZCoord = oldSiege.getTown().getHomeBlock().getCoord().getZ() * 16;
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoord) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoord) <= 300) {
playerCloseToHomeBlockSiege = true;
}
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()) {
if (oldSiege.getAttackerPlayers().contains(killer.getName()) && ((town != null && town.equals(oldSiege.getTown())) || playerCloseToHomeBlockSiege)) {
if (oldSiege.getDefenderPlayers().contains(killed.getName())) {
oldSiege.addPointsToAttackers(20);
for (final String playerName : oldSiege.getAttackerPlayers()) {
try {
Player p = Bukkit.getPlayer(playerName);
if (p != null)
p.sendMessage(Helper.chatLabel() + "Defender killed! + 20 Attacker Points");
p.sendMessage(UtilsChat.getPrefix() + "Defender killed! + 20 Attacker Points");
} catch (NullPointerException ignored) {
ignored.printStackTrace();
}
}
for (final String playerName : siege.getDefenderPlayers()) {
for (final String playerName : oldSiege.getDefenderPlayers()) {
try {
Player p = Bukkit.getPlayer(playerName);
if (p != null)
p.sendMessage(Helper.chatLabel() + "Defender killed! + 20 Attacker Points");
p.sendMessage(UtilsChat.getPrefix() + "Defender killed! + 20 Attacker Points");
} catch (NullPointerException ignored) {
ignored.printStackTrace();
}
@@ -127,23 +127,23 @@ public final class KillsListener implements Listener {
this.siegeKill(killed, event);
return;
}
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()) {
if (oldSiege.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(oldSiege.getTown())) || playerCloseToHomeBlockSiege)) {
if (oldSiege.getAttackerPlayers().contains(killed.getName())) {
oldSiege.addPointsToDefenders(20);
for (final String playerName : oldSiege.getAttackerPlayers()) {
try {
Player p = Bukkit.getPlayer(playerName);
if (p != null)
p.sendMessage(Helper.chatLabel() + "Attacker killed! + 20 Defender Points");
p.sendMessage(UtilsChat.getPrefix() + "Attacker killed! + 20 Defender Points");
} catch (NullPointerException ex3) {
ex3.printStackTrace();
}
}
for (final String playerName : siege.getDefenderPlayers()) {
for (final String playerName : oldSiege.getDefenderPlayers()) {
try {
Player p = Bukkit.getPlayer(playerName);
if (p != null)
p.sendMessage(Helper.chatLabel() + "Attacker killed! + 20 Defender Points");
p.sendMessage(UtilsChat.getPrefix() + "Attacker killed! + 20 Defender Points");
} catch (NullPointerException ex4) {
ex4.printStackTrace();
}
@@ -152,7 +152,7 @@ public final class KillsListener implements Listener {
this.siegeKill(killed, event);
return;
}
if ((town != null && town.equals(siege.getTown()) || playerCloseToHomeBlockSiege)) {
if ((town != null && town.equals(oldSiege.getTown()) || playerCloseToHomeBlockSiege)) {
this.siegeKill(killed, event);
}
}
@@ -170,17 +170,17 @@ public final class KillsListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onRespawn(PlayerRespawnEvent event) {
if (respawnQueue.containsKey(event.getPlayer().getUniqueId())) {
Raid raid = respawnQueue.get(event.getPlayer().getUniqueId());
if (raid == null) return;
if (raid.getActiveRaiders().contains(event.getPlayer().getName())) {
OldRaid oldRaid = respawnQueue.get(event.getPlayer().getUniqueId());
if (oldRaid == null) return;
if (oldRaid.getActiveRaiders().contains(event.getPlayer().getName())) {
//do raider respawn
try {
event.setRespawnLocation(raid.getGatherTown().getSpawn());
event.getPlayer().sendMessage(Helper.chatLabel() + "You died " + (raid.getPhase().equals(RaidPhase.COMBAT) ? "raiding" : "before combat") + " and have been teleported back to the gather point.");
event.setRespawnLocation(oldRaid.getGatherTown().getSpawn());
event.getPlayer().sendMessage(UtilsChat.getPrefix() + "You died " + (oldRaid.getPhase().equals(RaidPhase.COMBAT) ? "raiding" : "before combat") + " and have been teleported back to the gather point.");
} catch (TownyException e) {
throw new RuntimeException(e);
}
} else if (raid.getDefenderSide().contains(event.getPlayer().getName())) {
} else if (oldRaid.getDefenderSide().contains(event.getPlayer().getName())) {
//do defender respawn ?
} else {
//invalid code
@@ -199,9 +199,9 @@ public final class KillsListener implements Listener {
*/
private void siegeKill(final Player killed, final PlayerDeathEvent event) {
//Helper
Helper.damageAllGear(killed);
Utils.damageAllGear(killed);
//Siege specific
//OldSiege specific
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + killed.getName());
event.setKeepInventory(true);
event.getDrops().clear();
@@ -217,9 +217,9 @@ public final class KillsListener implements Listener {
*/
private void raidKill(final Player killed, final PlayerDeathEvent event) {
//Helper
Helper.damageAllGear(killed);
Utils.damageAllGear(killed);
//Siege specific
//OldSiege specific
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
event.setKeepInventory(true);
event.getDrops().clear();
@@ -234,7 +234,7 @@ public final class KillsListener implements Listener {
* @param event event
*/
private void oocKill(final Player killed, final PlayerDeathEvent event) {
//Siege specific
//OldSiege specific
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
event.setKeepInventory(true);
event.getDrops().clear();
@@ -2,10 +2,9 @@ package me.ShermansWorld.AlathraWar.listeners;
import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.WorldCoord;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
@@ -70,7 +69,7 @@ public class PlayerInteractListener implements Listener {
if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) {
boolean inSiegeOrRaid = false;
//siege check
for (Siege s : SiegeData.getSieges()) {
for (OldSiege s : SiegeData.getSieges()) {
for (TownBlock townBlock : s.getTown().getTownBlocks()) {
if (WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
// if we find one, just end no need to continue
@@ -82,7 +81,7 @@ public class PlayerInteractListener implements Listener {
//if it wasnt in a siege, then
if (!inSiegeOrRaid) {
for (Raid r : RaidData.getRaids()) {
for (OldRaid r : RaidData.getRaids()) {
for (TownBlock townBlock : r.getRaidedTown().getTownBlocks()) {
if (WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
// if we find one, just end no need to continue
@@ -97,18 +96,18 @@ public class PlayerInteractListener implements Listener {
// Returns if already broken.
if (doorBroken(clicked, door)) {
player.sendMessage(Helper.chatLabel() + Helper.color("&cThe door is already broken!"));
player.sendMessage(UtilsChat.getPrefix() + Helper.color("&cThe door is already broken!"));
event.setCancelled(true);
return;
}
player.sendMessage(Helper.chatLabel() + Helper.color("&eBreak it down alright!"));
player.sendMessage(UtilsChat.getPrefix() + Helper.color("&eBreak it down alright!"));
brokenDoors.put(getDoorPos(clicked, door), System.currentTimeMillis() + (1000L * Main.getInstance().getConfig().getInt("batteringRamEffectiveness")));
door.setOpen(!door.isOpen());
clicked.setBlockData(door);
player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);
Main.warLogger.log("User " + player.getName() + " has broken down door" + clicked.getLocation());
} else {
player.sendMessage(Helper.chatLabel() + Helper.color("&cThis item can only be used in a siege or raid!"));
player.sendMessage(UtilsChat.getPrefix() + Helper.color("&cThis item can only be used in a siege or raid!"));
}
event.setCancelled(true);
}
@@ -142,7 +141,7 @@ public class PlayerInteractListener implements Listener {
if (doors.contains(clicked.getType())) {
Door door = (Door) clicked.getBlockData();
if (doorBroken(clicked, door)) {
player.sendMessage(Helper.chatLabel() + Helper.color("Door is broken!"));
player.sendMessage(UtilsChat.getPrefix() + Helper.color("Door is broken!"));
event.setCancelled(true);
return;
@@ -0,0 +1,252 @@
package me.ShermansWorld.AlathraWar.utility;
import com.palmergames.bukkit.towny.object.WorldCoord;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Utils {
/**
* Damages all gear in a players inventory
*
* @param p
* @author ShermansWorld
*/
public static void damageAllGear(Player p) {
for (ItemStack itemStack : p.getInventory().getContents()) {
if (itemStack == null)
continue;
if (weaponList.contains(itemStack.getType())) {
setWeaponDurability(itemStack);
}
}
final ItemStack[] armor = p.getInventory().getArmorContents();
for (ItemStack itemStack : armor) {
if (itemStack == null)
continue;
if (armorList.contains(itemStack.getType())) {
setArmorDurability(itemStack);
}
}
}
private static final ArrayList<Material> weaponList = new ArrayList<>(List.of(
Material.NETHERITE_SWORD,
Material.NETHERITE_AXE,
Material.DIAMOND_SWORD,
Material.DIAMOND_AXE,
Material.IRON_SWORD,
Material.IRON_AXE
));
private static final ArrayList<Material> armorList = new ArrayList<>(List.of(
Material.NETHERITE_HELMET,
Material.NETHERITE_CHESTPLATE,
Material.NETHERITE_LEGGINGS,
Material.NETHERITE_BOOTS,
Material.DIAMOND_HELMET,
Material.DIAMOND_CHESTPLATE,
Material.DIAMOND_LEGGINGS,
Material.DIAMOND_BOOTS,
Material.IRON_HELMET,
Material.IRON_CHESTPLATE,
Material.IRON_LEGGINGS,
Material.IRON_BOOTS
));
private static void setArmorDurability(@Nullable ItemStack itemStack) {
if (itemStack == null)
return;
ItemMeta meta = itemStack.getItemMeta();
if (meta == null)
return;
if (!(meta instanceof Damageable damageable))
return;
switch (itemStack.getType()) {
case NETHERITE_HELMET -> {
damageable.setDamage(damageable.getDamage() + 101);
if (damageable.getDamage() > 400) {
damageable.setDamage(406);
}
}
case NETHERITE_CHESTPLATE -> {
damageable.setDamage(damageable.getDamage() + 148);
if (damageable.getDamage() > 450) {
damageable.setDamage(591);
}
}
case NETHERITE_LEGGINGS -> {
damageable.setDamage(damageable.getDamage() + 138);
if (damageable.getDamage() > 420) {
damageable.setDamage(554);
}
}
case NETHERITE_BOOTS -> {
damageable.setDamage(damageable.getDamage() + 120);
if (damageable.getDamage() > 370) {
damageable.setDamage(480);
}
}
case DIAMOND_HELMET -> {
damageable.setDamage(damageable.getDamage() + 90);
if (damageable.getDamage() > 280) {
damageable.setDamage(362);
}
}
case DIAMOND_CHESTPLATE -> {
damageable.setDamage(damageable.getDamage() + 132);
if (damageable.getDamage() > 410) {
damageable.setDamage(527);
}
}
case DIAMOND_LEGGINGS -> {
damageable.setDamage(damageable.getDamage() + 123);
if (damageable.getDamage() > 380) {
damageable.setDamage(494);
}
}
case DIAMOND_BOOTS -> {
damageable.setDamage(damageable.getDamage() + 107);
if (damageable.getDamage() > 330) {
damageable.setDamage(428);
}
}
case IRON_HELMET -> {
damageable.setDamage(damageable.getDamage() + 41);
if (damageable.getDamage() > 125) {
damageable.setDamage(164);
}
}
case IRON_CHESTPLATE -> {
damageable.setDamage(damageable.getDamage() + 60);
if (damageable.getDamage() > 190) {
damageable.setDamage(239);
}
}
case IRON_LEGGINGS -> {
damageable.setDamage(damageable.getDamage() + 56);
if (damageable.getDamage() > 180) {
damageable.setDamage(224);
}
}
case IRON_BOOTS -> {
damageable.setDamage(damageable.getDamage() + 48);
if (damageable.getDamage() > 150) {
damageable.setDamage(194);
}
}
}
itemStack.setItemMeta(damageable);
}
private static void setWeaponDurability(@Nullable ItemStack itemStack) {
if (itemStack == null)
return;
ItemMeta meta = itemStack.getItemMeta();
if (meta == null)
return;
if (!(meta instanceof Damageable damageable))
return;
switch (itemStack.getType()) {
case NETHERITE_SWORD, NETHERITE_AXE -> {
damageable.setDamage(damageable.getDamage() + 507);
if (damageable.getDamage() > 2000) {
damageable.setDamage(2030);
}
}
case DIAMOND_SWORD, DIAMOND_AXE -> {
damageable.setDamage(damageable.getDamage() + 390);
if (damageable.getDamage() > 1500) {
damageable.setDamage(1560);
}
}
case IRON_SWORD, IRON_AXE, TRIDENT -> {
damageable.setDamage(damageable.getDamage() + 62);
if (damageable.getDamage() > 200) {
damageable.setDamage(249);
}
}
}
itemStack.setItemMeta(damageable);
}
/**
* @param worldCoord worldCoord
* @return List of connected chunks
* @author NinjaMandalorian
*/
private static ArrayList<WorldCoord> getAdjCells(WorldCoord worldCoord) {
ArrayList<WorldCoord> worldCoords = 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
worldCoords.add(tCoord);
}
}
return worldCoords;
}
/**
* Gets all adjacently connected townblocks
*
* @param chunkCoord - WorldCoord to check at
* @return List of WorldCoords
* @author NinjaMandalorian
*/
public static ArrayList<WorldCoord> getCluster(WorldCoord chunkCoord) {
// worldCoords is the returning array, searchList is the to-search list.
ArrayList<WorldCoord> worldCoords = new ArrayList<>();
ArrayList<WorldCoord> searchList = new ArrayList<>(Collections.singletonList(chunkCoord)); // Adds 1st chunk to list
// Iterates through searchList, to create a full list of every adjacent cell.
while (!searchList.isEmpty()) {
WorldCoord toSearch = searchList.get(0); // Gets WorldCoord
ArrayList<WorldCoord> adjCells = getAdjCells(toSearch); // Gets adjacent cells
for (WorldCoord cell : adjCells) {
if (worldCoords.contains(cell)) continue; // If in final list, ignore.
if (searchList.contains(cell)) continue; // If in to-search list, ignore
// Otherwise, add to search-list.
searchList.add(cell);
}
// Removes from search list and adds to finished list. After checking all adjacent chunks.
searchList.remove(toSearch);
worldCoords.add(toSearch);
}
return worldCoords; // Returns list
}
}
@@ -0,0 +1,7 @@
package me.ShermansWorld.AlathraWar.utility;
public class UtilsChat {
public static String getPrefix() {
return "<dark_gray>[<gradient:#D72A09:#B01F03>War<dark_gray>] ";
}
}
+1
View File
@@ -0,0 +1 @@
* Ignore all cannon block placements so engineers can build them and destroy during oldSieges