mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
refactor: wip update 5 (sieges working)
This commit is contained in:
70 files changed
+2359
-1077
No files matched your search
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars;
|
||||
package com.github.alathra.AlathranWars;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
+35
-15
@@ -1,9 +1,14 @@
|
||||
package me.ShermansWorld.AlathranWars;
|
||||
package com.github.alathra.AlathranWars;
|
||||
|
||||
import me.ShermansWorld.AlathranWars.commands.CommandManager;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.hooks.HookManager;
|
||||
import me.ShermansWorld.AlathranWars.items.WarItemRegistry;
|
||||
import com.github.alathra.AlathranWars.commands.CommandManager;
|
||||
import com.github.alathra.AlathranWars.data.ConfigManager;
|
||||
import com.github.alathra.AlathranWars.data.DataManager;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.github.alathra.AlathranWars.hooks.HookManager;
|
||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||
import com.github.alathra.AlathranWars.listeners.ListenerHandler;
|
||||
import com.github.alathra.AlathranWars.utility.DB;
|
||||
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -19,7 +24,10 @@ public class Main extends JavaPlugin {
|
||||
econ = null;
|
||||
}
|
||||
|
||||
private ConfigManager configManager;
|
||||
private DataManager dataManager;
|
||||
private CommandManager commandManager;
|
||||
private ListenerHandler listenerHandler;
|
||||
private HookManager hookManager;
|
||||
|
||||
@NotNull
|
||||
@@ -74,10 +82,16 @@ public class Main extends JavaPlugin {
|
||||
public void onLoad() {
|
||||
Main.instance = this;
|
||||
WarManager.getInstance();
|
||||
commandManager = new CommandManager(Main.getInstance());
|
||||
configManager = new ConfigManager(getInstance());
|
||||
dataManager = new DataManager(getInstance());
|
||||
commandManager = new CommandManager(getInstance());
|
||||
listenerHandler = new ListenerHandler(getInstance());
|
||||
hookManager = new HookManager();
|
||||
|
||||
configManager.onLoad();
|
||||
dataManager.onLoad();
|
||||
commandManager.onLoad();
|
||||
listenerHandler.onLoad();
|
||||
hookManager.onLoad();
|
||||
}
|
||||
|
||||
@@ -89,12 +103,6 @@ public class Main extends JavaPlugin {
|
||||
//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);
|
||||
|
||||
// //run first
|
||||
new WarItemRegistry();
|
||||
// //run second
|
||||
@@ -104,17 +112,29 @@ public class Main extends JavaPlugin {
|
||||
setupEconomy();
|
||||
// initLogs();
|
||||
|
||||
configManager.onEnable();
|
||||
dataManager.onEnable();
|
||||
commandManager.onEnable();
|
||||
listenerHandler.onEnable();
|
||||
hookManager.onEnable();
|
||||
WarManager.getInstance().loadAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
SQLQueries.saveAll();
|
||||
configManager.onDisable();
|
||||
commandManager.onDisable();
|
||||
listenerHandler.onDisable();
|
||||
hookManager.onDisable();
|
||||
dataManager.onDisable();
|
||||
}
|
||||
|
||||
// for (OldWar oldWar : WarData.getWars()) {
|
||||
// oldWar.save();
|
||||
// }
|
||||
public ConfigManager getConfigManager() {
|
||||
return configManager;
|
||||
}
|
||||
|
||||
public DataManager getDataManager() {
|
||||
return dataManager;
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,5 +1,9 @@
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
package com.github.alathra.AlathranWars.commands;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||
@@ -7,12 +11,8 @@ import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.*;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.conflict.Side;
|
||||
import me.ShermansWorld.AlathranWars.enums.AdminCommandFailEnum;
|
||||
import me.ShermansWorld.AlathranWars.items.WarItemRegistry;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.enums.AdminCommandFailEnum;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
package com.github.alathra.AlathranWars.commands;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.CommandAPIBukkitConfig;
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
|
||||
public class CommandManager {
|
||||
private final Main instance;
|
||||
+9
-9
@@ -1,5 +1,12 @@
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
package com.github.alathra.AlathranWars.commands;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.github.alathra.AlathranWars.hooks.TownyHook;
|
||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
@@ -10,14 +17,7 @@ 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.AlathranWars.Main;
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.conflict.Side;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.siege.Siege;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.hooks.TownyHook;
|
||||
import me.ShermansWorld.AlathranWars.items.WarItemRegistry;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.Player;
|
||||
+35
-27
@@ -1,5 +1,12 @@
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
package com.github.alathra.AlathranWars.commands;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.data.DataManager;
|
||||
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
@@ -9,16 +16,13 @@ import dev.jorel.commandapi.arguments.BooleanArgument;
|
||||
import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.conflict.Side;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.siege.Siege;
|
||||
import me.ShermansWorld.AlathranWars.enums.BattleTeam;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -41,6 +45,7 @@ public class SiegeCommand {
|
||||
|
||||
public static CommandAPICommand commandStart() {
|
||||
return new CommandAPICommand("start")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument(
|
||||
"war",
|
||||
@@ -52,7 +57,7 @@ public class SiegeCommand {
|
||||
"town",
|
||||
"war",
|
||||
false,
|
||||
false
|
||||
true
|
||||
),
|
||||
new PlayerArgument("leader")
|
||||
.setOptional(true)
|
||||
@@ -149,12 +154,12 @@ public class SiegeCommand {
|
||||
}*/
|
||||
|
||||
if (!war.isTownInWar(leaderTown)) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You are not in this war.");
|
||||
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You are not in this war.");
|
||||
siegeOwner.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You are not in this war.").build());
|
||||
if (admin) sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You are not in this war.").build());
|
||||
return;
|
||||
} else if (side.isTownSurrendered(leaderTown)) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
|
||||
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
|
||||
siegeOwner.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You are under occupation.").build());
|
||||
if (admin) sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You are under occupation.").build());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -198,26 +203,23 @@ public class SiegeCommand {
|
||||
|
||||
// Attacking own side
|
||||
if (side.isTownOnSide(town)) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
|
||||
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
|
||||
siegeOwner.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
|
||||
if (admin) sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
|
||||
return;
|
||||
}
|
||||
|
||||
Siege siege = new Siege(war, town, siegeOwner);
|
||||
war.addSiege(siege);
|
||||
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide() + "!");
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide() + "!").build());
|
||||
|
||||
if (admin)
|
||||
sender.sendMessage("<red>Forcefully started siege from the console.");
|
||||
sender.sendMessage(new ColorParser("<red>Forcefully started siege from the console.").build());
|
||||
|
||||
siege.start();
|
||||
// TODO Debug logs...
|
||||
// Main.warLogger.log("Attacked Town: " + town.getName().toLowerCase());
|
||||
// sender.sendMessage("Attacked Town: " + town.getName().toLowerCase());
|
||||
|
||||
// war.save();
|
||||
// siege.start();
|
||||
}
|
||||
|
||||
private static void siegeStop(Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
@@ -227,16 +229,14 @@ public class SiegeCommand {
|
||||
if (!(args.get("town") instanceof final Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
|
||||
|
||||
final Set<Siege> sieges = war.getSieges();
|
||||
if (sieges.isEmpty())
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>There are currently no sieges in progress!").build());
|
||||
|
||||
for (Siege siege : sieges) {
|
||||
if (siege.getTown().getUUID().equals(town.getUUID()) && siege.getWar().equals(war)) {
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "siege cancelled").build());
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "siege cancelled.").build());
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin.").build());
|
||||
//siege.clearBeacon();
|
||||
siege.stop();
|
||||
return;
|
||||
}
|
||||
@@ -293,11 +293,19 @@ public class SiegeCommand {
|
||||
|
||||
final String color = (siege.getSide1AreAttackers() && (war.getTownSide(siege.getTown()).getTeam().equals(BattleTeam.SIDE_1))) ? "<red>" : "<blue>";
|
||||
|
||||
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.getMaxSiegeTicks() - siege.getSiegeTicks()) / 1200 + " minutes").build());
|
||||
sender.sendMessage(new ColorParser("-=-=-=-=-=-=-=-=-=-=-=-").build());
|
||||
sender.sendMessage(
|
||||
new ColorParser(
|
||||
color + siege.getTown().getName() + " <gray>- Progress: <progress> - Time: <time>min"
|
||||
)
|
||||
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(siege.getSiegeProgressPercentage() * 100))
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , siege.getEndTime()).toMinutes()))
|
||||
.build()
|
||||
);
|
||||
// sender.sendMessage(new ColorParser(war.getName() + " - " + color + siege.getTown().getName().toLowerCase()).build()); // TODO Fix info
|
||||
// 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.getMaxSiegeTicks() - siege.getSiegeTicks()) / 1200 + " minutes").build());
|
||||
// sender.sendMessage(new ColorParser("-=-=-=-=-=-=-=-=-=-=-=-").build());
|
||||
}
|
||||
}
|
||||
|
||||
+16
-5
@@ -1,5 +1,10 @@
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
package com.github.alathra.AlathranWars.commands;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
@@ -12,10 +17,8 @@ import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.conflict.Side;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -192,6 +195,14 @@ public class WarCommand {
|
||||
|
||||
argPlayer.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You have joined the war.").build());
|
||||
side.addPlayer(argPlayer);
|
||||
PlayerJoinListener.checkPlayer(argPlayer);
|
||||
for (Siege siege : war.getSieges()) {
|
||||
if (siege.getAttackerSide().equals(side)) {
|
||||
siege.addPlayer(argPlayer, BattleSide.ATTACKER);
|
||||
} else {
|
||||
siege.addPlayer(argPlayer, BattleSide.DEFENDER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict;
|
||||
package com.github.alathra.AlathranWars.conflict;
|
||||
|
||||
public class Conflict {
|
||||
private ConflictType conflictType;
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.alathra.AlathranWars.conflict;
|
||||
|
||||
public enum ConflictType {
|
||||
WAR
|
||||
}
|
||||
+98
-62
@@ -1,12 +1,13 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict;
|
||||
package com.github.alathra.AlathranWars.conflict;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathranWars.enums.BattleSide;
|
||||
import me.ShermansWorld.AlathranWars.enums.BattleTeam;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.listeners.JoinListener;
|
||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -17,10 +18,11 @@ import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Side {
|
||||
private UUID warUUID;
|
||||
private UUID uuid;
|
||||
private final UUID warUUID;
|
||||
private final UUID uuid;
|
||||
private final BattleSide side;
|
||||
private final BattleTeam team;
|
||||
private final String name; // A town name
|
||||
@@ -31,7 +33,6 @@ public class Side {
|
||||
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;
|
||||
@@ -39,14 +40,53 @@ public class Side {
|
||||
|
||||
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 Instant siegeGrace = Instant.now().minus(SIEGE_COOLDOWN); // The time after which this side can be besieged
|
||||
private Instant raidGrace = Instant.now().minus(RAID_COOLDOWN); // The time after which this side can be raided
|
||||
|
||||
private int score = 0;
|
||||
|
||||
public Side(UUID warUUID, Town town, BattleSide side, BattleTeam team) {
|
||||
// Create object from DB
|
||||
public Side(
|
||||
UUID warUUID,
|
||||
UUID uuid,
|
||||
Town town,
|
||||
BattleSide side,
|
||||
BattleTeam team,
|
||||
String name,
|
||||
Set<Town> towns,
|
||||
Set<Nation> nations,
|
||||
Set<UUID> playersIncludingOffline,
|
||||
Set<Town> surrenderedTowns,
|
||||
Set<Nation> surrenderedNations,
|
||||
Set<UUID> surrenderedPlayersIncludingOffline,
|
||||
Instant siegeGrace,
|
||||
Instant raidGrace
|
||||
) {
|
||||
this.warUUID = warUUID;
|
||||
this.uuid = generateUUID();
|
||||
this.uuid = uuid;
|
||||
this.side = side;
|
||||
this.team = team;
|
||||
this.town = town;
|
||||
this.name = name;
|
||||
|
||||
this.towns = towns;
|
||||
this.nations = nations;
|
||||
this.playersIncludingOffline = playersIncludingOffline;
|
||||
this.players = new HashSet<>();
|
||||
|
||||
this.surrenderedTowns = surrenderedTowns;
|
||||
this.surrenderedNations = surrenderedNations;
|
||||
this.surrenderedPlayersIncludingOffline = surrenderedPlayersIncludingOffline;
|
||||
|
||||
this.siegeGrace = siegeGrace;
|
||||
this.raidGrace = raidGrace;
|
||||
|
||||
calculateOnlinePlayers();
|
||||
}
|
||||
|
||||
public Side(UUID warUUID, UUID uuid, Town town, BattleSide side, BattleTeam team) {
|
||||
this.warUUID = warUUID;
|
||||
this.uuid = uuid;
|
||||
this.side = side;
|
||||
this.team = team;
|
||||
this.town = town;
|
||||
@@ -66,9 +106,9 @@ public class Side {
|
||||
calculateOnlinePlayers();
|
||||
}
|
||||
|
||||
public Side(UUID warUUID, Nation nation, BattleSide side, BattleTeam team) {
|
||||
public Side(UUID warUUID, UUID uuid, Nation nation, BattleSide side, BattleTeam team) {
|
||||
this.warUUID = warUUID;
|
||||
this.uuid = generateUUID();
|
||||
this.uuid = uuid;
|
||||
this.side = side;
|
||||
this.team = team;
|
||||
this.town = nation.getCapital();
|
||||
@@ -215,48 +255,51 @@ public class Side {
|
||||
}
|
||||
|
||||
public void addPlayer(Player p) {
|
||||
if (isPlayerOnSide(p)) return;
|
||||
|
||||
playersIncludingOffline.add(p.getUniqueId());
|
||||
calculateOnlinePlayers();
|
||||
addPlayer(p.getUniqueId());
|
||||
}
|
||||
|
||||
public void addPlayer(OfflinePlayer offlinePlayer) {
|
||||
if (offlinePlayer.isOnline())
|
||||
addPlayer(offlinePlayer.getPlayer());
|
||||
|
||||
if (offlinePlayer.hasPlayedBefore()) {
|
||||
if (isPlayerOnSide(offlinePlayer.getUniqueId())) return;
|
||||
playersIncludingOffline.add(offlinePlayer.getUniqueId());
|
||||
calculateOnlinePlayers();
|
||||
}
|
||||
if (offlinePlayer.hasPlayedBefore())
|
||||
addPlayer(offlinePlayer.getUniqueId());
|
||||
}
|
||||
|
||||
public void addPlayer(UUID uuid) {
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
if (isPlayerOnSide(uuid)) return;
|
||||
|
||||
addPlayer(offlinePlayer);
|
||||
}
|
||||
playersIncludingOffline.add(uuid);
|
||||
|
||||
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();
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
final Player p = Bukkit.getPlayer(uuid);
|
||||
addOnlinePlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
public void addOnlinePlayer(Player p) {
|
||||
players.add(p);
|
||||
}
|
||||
|
||||
removePlayer(offlinePlayer);
|
||||
public void removePlayer(Player p) {
|
||||
removePlayer(p.getUniqueId());
|
||||
}
|
||||
|
||||
public void removePlayer(OfflinePlayer offlinePlayer) {
|
||||
if (offlinePlayer.hasPlayedBefore())
|
||||
removePlayer(offlinePlayer.getUniqueId());
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
if (!isPlayerOnSide(uuid)) return;
|
||||
|
||||
playersIncludingOffline.remove(uuid);
|
||||
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
final Player p = Bukkit.getPlayer(uuid);
|
||||
removeOnlinePlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOnlinePlayer(Player p) {
|
||||
players.remove(p);
|
||||
}
|
||||
|
||||
public void surrenderPlayer(Player p) {
|
||||
@@ -268,18 +311,14 @@ public class Side {
|
||||
|
||||
removePlayer(uuid);
|
||||
surrenderedPlayersIncludingOffline.add(uuid);
|
||||
calculateOnlinePlayers();
|
||||
applyNameTags();
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
final Set<Player> onlinePlayers = getPlayersIncludingOffline().stream()
|
||||
.filter(uuid -> Bukkit.getOfflinePlayer(uuid).isOnline())
|
||||
.map(Bukkit::getPlayer)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
this.players.clear();
|
||||
this.players.addAll(onlinePlayers);
|
||||
@@ -288,17 +327,14 @@ public class Side {
|
||||
}
|
||||
|
||||
public void applyNameTags() {
|
||||
players.forEach(JoinListener::checkPlayer);
|
||||
players.forEach(PlayerJoinListener::checkPlayer);
|
||||
surrenderedPlayersIncludingOffline.stream()
|
||||
.filter((UUID uuid) -> Bukkit.getPlayer(uuid) != null)
|
||||
.map(Bukkit::getPlayer)
|
||||
.toList()
|
||||
.forEach(JoinListener::checkPlayer);
|
||||
.forEach(PlayerJoinListener::checkPlayer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Graces
|
||||
|
||||
public Instant getSiegeGrace() {
|
||||
@@ -349,10 +385,6 @@ public class Side {
|
||||
|
||||
// Comparators & UUID
|
||||
|
||||
private UUID generateUUID() {
|
||||
return UUID.randomUUID(); // There's only ever two sides anyways
|
||||
}
|
||||
|
||||
public boolean equals(UUID uuid) {
|
||||
return this.uuid.equals(uuid);
|
||||
}
|
||||
@@ -392,6 +424,10 @@ public class Side {
|
||||
return nations.isEmpty() && towns.isEmpty();
|
||||
}
|
||||
|
||||
public Town getTown() {
|
||||
return town;
|
||||
}
|
||||
|
||||
// TODO Make object serializable
|
||||
/*private void writeObject(ObjectOutputStream oos)
|
||||
throws IOException {
|
||||
+79
-46
@@ -1,17 +1,19 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict;
|
||||
package com.github.alathra.AlathranWars.conflict;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
|
||||
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
||||
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
||||
import com.github.alathra.AlathranWars.utility.UUIDUtil;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
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.AlathranWars.conflict.battle.raid.Raid;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.siege.Siege;
|
||||
import me.ShermansWorld.AlathranWars.enums.BattleSide;
|
||||
import me.ShermansWorld.AlathranWars.enums.BattleTeam;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.listeners.JoinListener;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -38,12 +40,33 @@ public class War extends Conflict {
|
||||
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<>();
|
||||
private Set<Siege> sieges = new HashSet<>();
|
||||
private Set<Raid> raids = new HashSet<>();
|
||||
|
||||
// Merged utility data from Side's
|
||||
// private Set<Player> players = new HashSet<>();
|
||||
// private Set<UUID> playersIncludingOffline = new HashSet<>();
|
||||
public War(
|
||||
UUID uuid,
|
||||
String name,
|
||||
String label,
|
||||
Side side1,
|
||||
Side side2,
|
||||
Set<Siege> sieges,
|
||||
Set<Raid> raids
|
||||
) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
|
||||
this.side1 = side1;
|
||||
this.side2 = side2;
|
||||
|
||||
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
||||
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
||||
|
||||
this.sieges = sieges;
|
||||
this.raids = raids;
|
||||
|
||||
resume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new New war.
|
||||
@@ -53,99 +76,89 @@ public class War extends Conflict {
|
||||
* @param victim the side 2
|
||||
*/
|
||||
public War(final String label, Town aggressor, Town victim) throws WrapperCommandSyntaxException {
|
||||
this.uuid = generateUUID();
|
||||
this.uuid = UUIDUtil.generateWarUUID();
|
||||
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() + "<red>A 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);
|
||||
final UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
this.side1 = new Side(this.uuid, side1UUID, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
|
||||
this.side2 = new Side(this.uuid, side2UUID, 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();
|
||||
|
||||
WarManager.getInstance().addWar(this);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
public War(final String label, Nation aggressor, Nation victim) throws WrapperCommandSyntaxException {
|
||||
this.uuid = generateUUID();
|
||||
this.uuid = UUIDUtil.generateWarUUID();
|
||||
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() + "<red>A 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);
|
||||
final UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
this.side1 = new Side(this.uuid, side1UUID, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
|
||||
this.side2 = new Side(this.uuid, side2UUID, 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();
|
||||
|
||||
WarManager.getInstance().addWar(this);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
public War(final String label, Town aggressor, Nation victim) throws WrapperCommandSyntaxException {
|
||||
this.uuid = generateUUID();
|
||||
this.uuid = UUIDUtil.generateWarUUID();
|
||||
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() + "<red>A 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);
|
||||
final UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
this.side1 = new Side(this.uuid, side1UUID, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
|
||||
this.side2 = new Side(this.uuid, side2UUID, 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();
|
||||
|
||||
WarManager.getInstance().addWar(this);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
public War(final String label, Nation aggressor, Town victim) throws WrapperCommandSyntaxException {
|
||||
this.uuid = generateUUID();
|
||||
this.uuid = UUIDUtil.generateWarUUID();
|
||||
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() + "<red>A 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);
|
||||
final UUID side1UUID = UUIDUtil.generateSideUUID(null);
|
||||
final UUID side2UUID = UUIDUtil.generateSideUUID(side1UUID);
|
||||
this.side1 = new Side(this.uuid, side1UUID, aggressor, BattleSide.ATTACKER, BattleTeam.SIDE_1);
|
||||
this.side2 = new Side(this.uuid, side2UUID, 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();
|
||||
|
||||
WarManager.getInstance().addWar(this);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
private UUID generateUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
while (WarManager.getInstance().getWar(uuid) != null) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets uuid.
|
||||
*
|
||||
@@ -280,6 +293,16 @@ public class War extends Conflict {
|
||||
return sieges;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Siege getSiege(UUID uuid) {
|
||||
for (Siege siege : sieges) {
|
||||
if (siege.equals(uuid))
|
||||
return siege;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add siege.
|
||||
*
|
||||
@@ -289,6 +312,10 @@ public class War extends Conflict {
|
||||
sieges.add(siege);
|
||||
}
|
||||
|
||||
public void removeSiege(Siege siege) {
|
||||
sieges.remove(siege);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets raids.
|
||||
*
|
||||
@@ -443,8 +470,13 @@ public class War extends Conflict {
|
||||
.build()
|
||||
);
|
||||
|
||||
side1.calculateOnlinePlayers();
|
||||
side2.calculateOnlinePlayers();
|
||||
side1.applyNameTags();
|
||||
side2.applyNameTags();
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
side1.applyNameTags();
|
||||
side2.applyNameTags();
|
||||
}
|
||||
|
||||
public void end() {
|
||||
@@ -452,10 +484,11 @@ public class War extends Conflict {
|
||||
getSieges().forEach(Siege::stop);
|
||||
// getRaids().forEach(Raid::stop);
|
||||
|
||||
SQLQueries.deleteWar(this);
|
||||
WarManager.getInstance().removeWar(this);
|
||||
|
||||
// Run check after war is removed to cleanup player tags
|
||||
this.getPlayers().forEach(JoinListener::checkPlayer);
|
||||
this.getPlayers().forEach(PlayerJoinListener::checkPlayer);
|
||||
}
|
||||
|
||||
public void defeat(Side loserSide) {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict.battle;
|
||||
package com.github.alathra.AlathranWars.conflict.battle;
|
||||
|
||||
public class Battle {
|
||||
private int attackerPoints;
|
||||
/*private int attackerPoints;
|
||||
private int defenderPoints;
|
||||
|
||||
public int getAttackerPoints() {
|
||||
@@ -26,5 +26,5 @@ public class Battle {
|
||||
|
||||
public void addPointsToDefenders(final int points) {
|
||||
this.defenderPoints += points;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.github.alathra.AlathranWars.conflict.battle.raid;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.battle.Battle;
|
||||
|
||||
public class Raid extends Battle {
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.github.alathra.AlathranWars.conflict.battle.siege;
|
||||
|
||||
public enum CaptureProgressDirection {
|
||||
UP,
|
||||
NONE,
|
||||
UNCONTESTED,
|
||||
DOWN
|
||||
}
|
||||
@@ -0,0 +1,541 @@
|
||||
package com.github.alathra.AlathranWars.conflict.battle.siege;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.Battle;
|
||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
||||
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
||||
import com.github.alathra.AlathranWars.utility.UUIDUtil;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
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.TownBlock;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Siege extends Battle {
|
||||
public static final int MAX_SIEGE_TICKS = 72000; // 60 minute tick constant
|
||||
public static final Duration SIEGE_DURATION = Duration.ofMinutes(60);
|
||||
private static final int MAX_SIEGE_PROGRESS_MINUTES = 8;
|
||||
public static final int MAX_SIEGE_PROGRESS = 60 * MAX_SIEGE_PROGRESS_MINUTES; // On reaching this, the attackers win. 1 point is added per second
|
||||
public static final Duration ATTACKERS_MUST_TOUCH_END = Duration.ofMinutes(40); // If point is not touched in this much time, defenders win
|
||||
public static final Duration ATTACKERS_MUST_TOUCH_REVERT = Duration.ofMinutes(2); // If point is not touched in this much time, siege progress reverts
|
||||
public static final int BATTLEFIELD_RANGE = 300;
|
||||
|
||||
private final UUID uuid;
|
||||
private final Set<Player> attackers = new HashSet<>(); // Players inside battlefield
|
||||
private final Set<Player> defenders = new HashSet<>(); // Players inside battlefield
|
||||
private final Set<Player> attackerPlayers = new HashSet<>();
|
||||
private final Set<Player> defenderPlayers = new HashSet<>();
|
||||
private final Set<UUID> attackerPlayersIncludingOffline = new HashSet<>();
|
||||
private final Set<UUID> defenderPlayersIncludingOffline = new HashSet<>();
|
||||
|
||||
private Instant endTime;
|
||||
private int siegeProgress = 0;
|
||||
private Instant lastTouched;
|
||||
|
||||
private SiegeRunnable siegeRunnable;
|
||||
|
||||
private War war; // War which siege belongs to
|
||||
private Town town; // Town of the siege
|
||||
private boolean side1AreAttackers; // bool of if side1 being attacker
|
||||
|
||||
private OfflinePlayer siegeLeader;
|
||||
private @Nullable TownBlock homeBlock = null;
|
||||
private @Nullable Location townSpawn = null;
|
||||
private @Nullable BossBar activeBossBar = null;
|
||||
|
||||
public Siege(final War war, final Town town, Player siegeLeader) {
|
||||
uuid = UUIDUtil.generateSiegeUUID();
|
||||
|
||||
endTime = Instant.now().plus(SIEGE_DURATION);
|
||||
lastTouched = Instant.now();
|
||||
|
||||
this.war = war;
|
||||
this.town = town;
|
||||
this.siegeLeader = siegeLeader;
|
||||
|
||||
side1AreAttackers = war.getTownSide(town).getTeam().equals(BattleTeam.SIDE_2);
|
||||
|
||||
if (getSide1AreAttackers()) {
|
||||
attackerPlayersIncludingOffline.addAll(getWar().getSide1().getPlayersIncludingOffline());
|
||||
defenderPlayersIncludingOffline.addAll(getWar().getSide2().getPlayersIncludingOffline());
|
||||
} else {
|
||||
attackerPlayersIncludingOffline.addAll(getWar().getSide2().getPlayersIncludingOffline());
|
||||
defenderPlayersIncludingOffline.addAll(getWar().getSide1().getPlayersIncludingOffline());
|
||||
}
|
||||
calculateOnlinePlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a siege
|
||||
*/
|
||||
public void start() {
|
||||
siegeRunnable = new SiegeRunnable(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resumes a siege (after a server restart e.t.c.)
|
||||
*/
|
||||
public void resume(int resumeTick) {
|
||||
siegeRunnable = new SiegeRunnable(this, resumeTick);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops a siege
|
||||
*/
|
||||
public void stop() {
|
||||
siegeRunnable.cancel();
|
||||
SQLQueries.deleteSiege(this);
|
||||
war.removeSiege(this);
|
||||
}
|
||||
|
||||
public void attackersWin(final OfflinePlayer siegeLeader) {
|
||||
final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
|
||||
Nation nation = null;
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The attackers have won the siege of " + town.getName() + "!").build());
|
||||
|
||||
try {
|
||||
nation = resident.getTown().getNation();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
if (nation != null) {
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The town of " + town.getName()
|
||||
+ " has been placed under occupation by " + nation.getName() + "!").build());
|
||||
}
|
||||
|
||||
// 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");
|
||||
// } else {
|
||||
// if (this.town.getAccount().getHoldingBalance() < 2500.0) {
|
||||
// amt = this.town.getAccount().getHoldingBalance();
|
||||
// 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");
|
||||
// amt = 2500.0;
|
||||
// }
|
||||
|
||||
/*Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
||||
+ ", valuing $" + amt);*/
|
||||
Bukkit.broadcast(new ColorParser("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide().getName() + "!").build());
|
||||
// Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
||||
// + ", valuing $" + amt);
|
||||
// Main.econ.depositPlayer(siegeLeader, amt);
|
||||
|
||||
if (side1AreAttackers) {
|
||||
war.getSide1().addScore(50);
|
||||
} else {
|
||||
war.getSide2().addScore(50);
|
||||
}
|
||||
|
||||
stop();
|
||||
//clearBeacon();
|
||||
}
|
||||
|
||||
public void defendersWin() {
|
||||
// this.town.getAccount().deposit(2500.0, "War chest");
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The defenders have won the siege of " + this.town.getName() + "!").build());
|
||||
// Bukkit.broadcastMessage(UtilsChat.getPrefix() + this.town.getName()
|
||||
// + " has recovered the attackers' war chest, valued at $2,500");
|
||||
// Main.warLogger
|
||||
// .log(war.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
|
||||
|
||||
if (side1AreAttackers) {
|
||||
war.getSide2().addScore(50);
|
||||
} else {
|
||||
war.getSide1().addScore(50);
|
||||
}
|
||||
|
||||
stop();
|
||||
//clearBeacon();
|
||||
}
|
||||
|
||||
/**
|
||||
* No winner declared
|
||||
*/
|
||||
public void noWinner() {
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The siege of " + this.town.getName() + " has ended in a draw!").build());
|
||||
// Bukkit.broadcastMessage(UtilsChat.getPrefix() + "No money has been recovered.");
|
||||
// Main.warLogger
|
||||
// .log(war.getName() + ": No one won the siege of " + this.town.getName() + "!");
|
||||
stop();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Instant getLastTouched() {
|
||||
return lastTouched;
|
||||
}
|
||||
|
||||
public void setLastTouched(Instant lastTouched) {
|
||||
this.lastTouched = lastTouched;
|
||||
}
|
||||
|
||||
public int getSiegeProgress() {
|
||||
return siegeProgress;
|
||||
}
|
||||
|
||||
public float getSiegeProgressPercentage() {
|
||||
return (getSiegeProgress() * 1.0f) / MAX_SIEGE_PROGRESS;
|
||||
}
|
||||
|
||||
public void setSiegeProgress(int siegeProgress) {
|
||||
this.siegeProgress = siegeProgress;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public War getWar() {
|
||||
return war;
|
||||
}
|
||||
|
||||
public void setWar(final War war) {
|
||||
this.war = war;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Town getTown() {
|
||||
return town;
|
||||
}
|
||||
|
||||
public void setTown(final Town town) {
|
||||
this.town = town;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets attacker name string
|
||||
*/
|
||||
@NotNull
|
||||
public Side getAttackerSide() {
|
||||
return side1AreAttackers ? war.getSide1() : war.getSide2();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets defender name string
|
||||
*/
|
||||
@NotNull
|
||||
public Side getDefenderSide() {
|
||||
return side1AreAttackers ? war.getSide2() : war.getSide1();
|
||||
}
|
||||
|
||||
public void updateDisplayBar(CaptureProgressDirection progressDirection) {
|
||||
if (activeBossBar == null)
|
||||
createNewDisplayBar();
|
||||
|
||||
/*for (BossBarViewer viewer : activeBossBar.viewers()) { // TODO Better perf
|
||||
|
||||
}*/
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
activeBossBar.removeViewer(p);
|
||||
}
|
||||
|
||||
for (Player p : this.getAttackers()) {
|
||||
if (p != null)
|
||||
p.showBossBar(activeBossBar);
|
||||
}
|
||||
|
||||
for (Player p : this.getDefenders()) {
|
||||
if (p != null)
|
||||
p.showBossBar(activeBossBar);
|
||||
}
|
||||
|
||||
String color = "<yellow>";
|
||||
|
||||
switch (progressDirection) {
|
||||
case UP -> {
|
||||
if (getAttackerSide().getSide().equals(BattleSide.ATTACKER)) {
|
||||
activeBossBar.color(BossBar.Color.RED);
|
||||
color = "<red>";
|
||||
} else {
|
||||
activeBossBar.color(BossBar.Color.BLUE);
|
||||
color = "<blue>";
|
||||
}
|
||||
}
|
||||
case NONE -> activeBossBar.color(BossBar.Color.YELLOW);
|
||||
case DOWN -> {
|
||||
if (getAttackerSide().getSide().equals(BattleSide.ATTACKER)) {
|
||||
activeBossBar.color(BossBar.Color.BLUE);
|
||||
color = "<blue>";
|
||||
} else {
|
||||
activeBossBar.color(BossBar.Color.RED);
|
||||
color = "<red>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Instant.now().isBefore(getEndTime())) {
|
||||
activeBossBar.name(
|
||||
new ColorParser("<gray>Capture Progress: %s<progress> <gray>Time: %s<time>min".formatted(color, color))
|
||||
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(getSiegeProgressPercentage() * 100))
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , getEndTime()).toMinutes()))
|
||||
.build()
|
||||
);
|
||||
} else {
|
||||
activeBossBar.name(
|
||||
new ColorParser("%sOVERTIME".formatted(color)).build()
|
||||
);
|
||||
}
|
||||
activeBossBar.progress(getSiegeProgressPercentage());
|
||||
}
|
||||
|
||||
public void createNewDisplayBar() {
|
||||
final Component text = new ColorParser("<gray>Capture Progress: <yellow><progress> <gray>Time: <yellow><time>min")
|
||||
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(getSiegeProgressPercentage() * 100))
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , getEndTime()).toMinutesPart()))
|
||||
.build();
|
||||
|
||||
this.activeBossBar = BossBar.bossBar(text, 0, BossBar.Color.YELLOW, BossBar.Overlay.NOTCHED_10);
|
||||
}
|
||||
|
||||
public void deleteDisplayBar() {
|
||||
if (activeBossBar != null) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
activeBossBar.removeViewer(p);
|
||||
}
|
||||
|
||||
activeBossBar = null;
|
||||
}
|
||||
}
|
||||
|
||||
// SECTION UUID
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals boolean.
|
||||
*
|
||||
* @param uuid the uuid
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean equals(UUID uuid) {
|
||||
return getUUID().equals(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals boolean.
|
||||
*
|
||||
* @param siege the siege
|
||||
* @return the boolean
|
||||
*/
|
||||
public boolean equals(Siege siege) {
|
||||
return getUUID().equals(siege.getUUID());
|
||||
}
|
||||
|
||||
// Accessors & Getters
|
||||
|
||||
@Nullable
|
||||
public TownBlock getHomeBlock() {
|
||||
return homeBlock;
|
||||
}
|
||||
|
||||
public void setHomeBlock(TownBlock homeBlock) {
|
||||
this.homeBlock = homeBlock;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Location getTownSpawn() {
|
||||
return townSpawn;
|
||||
}
|
||||
|
||||
public void setTownSpawn(Location townSpawn) {
|
||||
this.townSpawn = townSpawn;
|
||||
}
|
||||
|
||||
public boolean getSide1AreAttackers() {
|
||||
return this.side1AreAttackers;
|
||||
}
|
||||
|
||||
public void setSide1AreAttackers(final boolean side1AreAttackers) {
|
||||
this.side1AreAttackers = side1AreAttackers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Player> getAttackers() {
|
||||
return this.attackers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Player> getDefenders() {
|
||||
return this.defenders;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Player> getAttackerPlayers() {
|
||||
return this.attackerPlayers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Player> getDefenderPlayers() {
|
||||
return this.defenderPlayers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public OfflinePlayer getSiegeLeader() {
|
||||
return siegeLeader;
|
||||
}
|
||||
|
||||
public void setSiegeLeader(OfflinePlayer siegeLeader) {
|
||||
this.siegeLeader = siegeLeader;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return this.getWar().getName() + "-" + this.getTown();
|
||||
}
|
||||
|
||||
// SECTION Time management
|
||||
|
||||
public void setEndTime(Instant time) {
|
||||
endTime = time;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Instant getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
// SECTION Player management
|
||||
|
||||
public boolean isPlayerInSiege(UUID uuid) {
|
||||
return attackerPlayersIncludingOffline.contains(uuid) || defenderPlayersIncludingOffline.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean isPlayerInSiege(Player p) {
|
||||
return isPlayerInSiege(p.getUniqueId());
|
||||
}
|
||||
|
||||
public BattleSide getPlayerSideInSiege(UUID uuid) {
|
||||
if (attackerPlayersIncludingOffline.contains(uuid))
|
||||
return BattleSide.ATTACKER;
|
||||
|
||||
if (defenderPlayersIncludingOffline.contains(uuid))
|
||||
return BattleSide.DEFENDER;
|
||||
|
||||
return BattleSide.SPECTATOR;
|
||||
}
|
||||
|
||||
public BattleSide getPlayerSideInSiege(Player p) {
|
||||
return getPlayerSideInSiege(p.getUniqueId());
|
||||
}
|
||||
|
||||
public void addPlayer(Player p, BattleSide side) {
|
||||
addPlayer(p.getUniqueId(), side);
|
||||
}
|
||||
|
||||
public void addPlayer(OfflinePlayer offlinePlayer, BattleSide side) {
|
||||
if (offlinePlayer.hasPlayedBefore())
|
||||
addPlayer(offlinePlayer.getUniqueId(), side);
|
||||
}
|
||||
|
||||
public void addPlayer(UUID uuid, BattleSide side) {
|
||||
if (isPlayerInSiege(uuid)) return;
|
||||
|
||||
switch (side) {
|
||||
case ATTACKER -> attackerPlayersIncludingOffline.add(uuid);
|
||||
case DEFENDER -> defenderPlayersIncludingOffline.add(uuid);
|
||||
}
|
||||
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
final Player p = Bukkit.getPlayer(uuid);
|
||||
addOnlinePlayer(p, side);
|
||||
}
|
||||
}
|
||||
|
||||
public void addOnlinePlayer(Player p, BattleSide side) {
|
||||
switch (side) {
|
||||
case ATTACKER -> attackerPlayers.add(p);
|
||||
case DEFENDER -> defenderPlayers.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(Player p) {
|
||||
removePlayer(p.getUniqueId());
|
||||
}
|
||||
|
||||
public void removePlayer(OfflinePlayer offlinePlayer) {
|
||||
if (offlinePlayer.hasPlayedBefore())
|
||||
removePlayer(offlinePlayer.getUniqueId());
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
if (!isPlayerInSiege(uuid)) return;
|
||||
|
||||
final BattleSide side = getPlayerSideInSiege(uuid);
|
||||
|
||||
switch (side) {
|
||||
case ATTACKER -> attackerPlayersIncludingOffline.remove(uuid);
|
||||
case DEFENDER -> defenderPlayersIncludingOffline.remove(uuid);
|
||||
}
|
||||
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
final Player p = Bukkit.getPlayer(uuid);
|
||||
removeOnlinePlayer(p, side);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOnlinePlayer(Player p, BattleSide side) {
|
||||
switch (side) {
|
||||
case ATTACKER -> attackerPlayers.remove(p);
|
||||
case DEFENDER -> defenderPlayers.remove(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateOnlinePlayers() {
|
||||
final Set<Player> onlineAttackers = attackerPlayersIncludingOffline.stream()
|
||||
.filter(uuid1 -> Bukkit.getOfflinePlayer(uuid1).isOnline())
|
||||
.map(Bukkit::getPlayer)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
attackerPlayers.clear();
|
||||
attackerPlayers.addAll(onlineAttackers);
|
||||
|
||||
final Set<Player> onlineDefenders = defenderPlayersIncludingOffline.stream()
|
||||
.filter(uuid1 -> Bukkit.getOfflinePlayer(uuid1).isOnline())
|
||||
.map(Bukkit::getPlayer)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
defenderPlayers.clear();
|
||||
defenderPlayers.addAll(onlineDefenders);
|
||||
}
|
||||
|
||||
public void calculateBattlefieldPlayers(Location location) {
|
||||
final Set<Player> attackersOnBattlefield = attackerPlayers.stream()
|
||||
.filter(p -> p.isOnline() && location.distance(p.getLocation()) < BATTLEFIELD_RANGE)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
attackers.clear();
|
||||
attackers.addAll(attackersOnBattlefield);
|
||||
|
||||
final Set<Player> defendersOnBattlefield = defenderPlayers.stream()
|
||||
.filter(p -> p.isOnline() && location.distance(p.getLocation()) < BATTLEFIELD_RANGE)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
defenders.clear();
|
||||
defenders.addAll(defendersOnBattlefield);
|
||||
}
|
||||
}
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
package com.github.alathra.AlathranWars.conflict.battle.siege;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
import fr.skytasul.guardianbeam.Laser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import static com.github.alathra.AlathranWars.conflict.battle.siege.Siege.*;
|
||||
|
||||
public class SiegeRunnable implements Runnable{
|
||||
private static final Duration ANNOUNCEMENT_COOLDOWN = Duration.ofMinutes(5);
|
||||
|
||||
private CaptureProgressDirection oldProgressDirection = CaptureProgressDirection.NONE;
|
||||
private Instant nextAnnouncement;
|
||||
private int taskId = -1;
|
||||
private final Siege siege;
|
||||
private Laser beam;
|
||||
|
||||
/**
|
||||
* Start a siege
|
||||
*
|
||||
* @param siege the siege
|
||||
*/
|
||||
public SiegeRunnable(Siege siege) {
|
||||
this.siege = siege;
|
||||
|
||||
siege.setSiegeProgress(0);
|
||||
|
||||
siege.setHomeBlock(siege.getTown().getHomeBlockOrNull());
|
||||
siege.setTownSpawn(siege.getTown().getSpawnOrNull());
|
||||
|
||||
nextAnnouncement = Instant.now().plus(ANNOUNCEMENT_COOLDOWN);
|
||||
|
||||
taskId = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), this, 0L, 20L);
|
||||
|
||||
siege.updateDisplayBar(CaptureProgressDirection.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resume a siege at tick
|
||||
*
|
||||
* @param siege the siege
|
||||
* @param siegeProgress the siege ticks
|
||||
*/
|
||||
public SiegeRunnable(Siege siege, int siegeProgress) {
|
||||
this.siege = siege;
|
||||
|
||||
siege.setSiegeProgress(siegeProgress);
|
||||
|
||||
siege.setHomeBlock(siege.getTown().getHomeBlockOrNull());
|
||||
siege.setTownSpawn(siege.getTown().getSpawnOrNull());
|
||||
|
||||
nextAnnouncement = Instant.now().plus(ANNOUNCEMENT_COOLDOWN);
|
||||
|
||||
taskId = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), this, 0L, 20L);
|
||||
|
||||
siege.updateDisplayBar(CaptureProgressDirection.NONE);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
stopBeam();
|
||||
if (taskId == -1) return;
|
||||
|
||||
try {
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskId);
|
||||
siege.deleteDisplayBar();
|
||||
} finally {
|
||||
taskId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final Town town = siege.getTown();
|
||||
final TownBlock homeBlock = siege.getHomeBlock();
|
||||
final Location townSpawn = siege.getTownSpawn();
|
||||
|
||||
if (homeBlock != null && townSpawn != null) {
|
||||
town.setHomeBlock(homeBlock);
|
||||
town.setSpawn(townSpawn);
|
||||
}
|
||||
|
||||
// Render beam
|
||||
startBeam();
|
||||
|
||||
// Calculate battlefield players
|
||||
siege.calculateBattlefieldPlayers(townSpawn.toCenterLocation());
|
||||
|
||||
// Progress the siege
|
||||
final CaptureProgressDirection progressDirection = getSiegeProgressDirection(town, townSpawn);
|
||||
|
||||
// Siege is past max time or attackers haven't touched in time, defenders won
|
||||
if (
|
||||
!progressDirection.equals(CaptureProgressDirection.UP) &&
|
||||
(Instant.now().isAfter(siege.getEndTime()) ||
|
||||
Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_END)))
|
||||
) {
|
||||
cancel();
|
||||
siege.defendersWin();
|
||||
return;
|
||||
}
|
||||
|
||||
// Attackers captured the town
|
||||
if (siege.getSiegeProgress() >= MAX_SIEGE_PROGRESS) {
|
||||
cancel();
|
||||
siege.attackersWin(siege.getSiegeLeader());
|
||||
return;
|
||||
}
|
||||
|
||||
switch (progressDirection) {
|
||||
case UP -> siege.setSiegeProgress(siege.getSiegeProgress() + 1);
|
||||
case DOWN -> siege.setSiegeProgress(siege.getSiegeProgress() - 1);
|
||||
}
|
||||
|
||||
if (oldProgressDirection != progressDirection) {
|
||||
switch (progressDirection) {
|
||||
case UP -> {
|
||||
siege.getAttackers().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The Attackers are capturing the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
siege.getDefenders().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The Attackers are capturing the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
}
|
||||
case NONE -> {
|
||||
/*if ()
|
||||
siege.getAttackers().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The home block is being contested.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
siege.getDefenders().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The home block is being contested.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));*/
|
||||
}
|
||||
case DOWN -> {
|
||||
siege.getAttackers().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The Defenders re-secured the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
siege.getDefenders().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>The Defenders re-secured the home block.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.build()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oldProgressDirection = progressDirection;
|
||||
|
||||
/*Bukkit.broadcast(
|
||||
new ColorParser("<prefix>Progress: <progress> <progress2> <test> <score>")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(siege.getSiegeProgressPercentage() * 100))
|
||||
.parseMinimessagePlaceholder("progress2", String.valueOf(siege.getSiegeProgressPercentage()))
|
||||
.parseMinimessagePlaceholder("test", progressDirection.name())
|
||||
.parseMinimessagePlaceholder("score", String.valueOf(siege.getSiegeProgress()))
|
||||
.build()
|
||||
);*/
|
||||
|
||||
if (Instant.now().isAfter(nextAnnouncement)) {
|
||||
nextAnnouncement = Instant.now().plus(ANNOUNCEMENT_COOLDOWN);
|
||||
|
||||
siege.getAttackers().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>Siege time remaining: <time> minutes.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , siege.getEndTime()).toMinutesPart()))
|
||||
.build()
|
||||
));
|
||||
siege.getDefenders().forEach(p -> p.sendMessage(
|
||||
new ColorParser("<prefix>Siege time remaining: <time> minutes.")
|
||||
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
|
||||
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , siege.getEndTime()).toMinutesPart()))
|
||||
.build()
|
||||
));
|
||||
}
|
||||
|
||||
siege.updateDisplayBar(progressDirection);
|
||||
}
|
||||
|
||||
private final static int CAPTURE_MAX_ELEVATION = 10;
|
||||
private final static int CAPTURE_RANGE = 10;
|
||||
|
||||
public int getPeopleOnPoint(Town town, Location townSpawn, BattleSide battleSide) {
|
||||
int onPoint = 0;
|
||||
|
||||
for (final Player p : (battleSide.equals(BattleSide.ATTACKER) ? siege.getAttackers() : siege.getDefenders())) {
|
||||
// WorldCoord wc = WorldCoord.parseWorldCoord(p);
|
||||
// if (!Objects.equals(wc.getTownOrNull(), town))
|
||||
// continue;
|
||||
|
||||
// @Nullable TownBlock homeBlock = town.getHomeBlockOrNull();
|
||||
// if (homeBlock == null)
|
||||
// continue;
|
||||
|
||||
if (/*!homeBlock.getWorldCoord().equals(wc) || */p.isDead())
|
||||
continue;
|
||||
|
||||
if (townSpawn.distance(p.getLocation()) <= CAPTURE_RANGE) {
|
||||
onPoint += 1;
|
||||
}
|
||||
// if ((Math.abs(p.getLocation().getBlockY() - townSpawn.getBlockY())) < CAPTURE_MAX_ELEVATION) {
|
||||
// onPoint += 1;
|
||||
// }
|
||||
}
|
||||
|
||||
return onPoint;
|
||||
}
|
||||
|
||||
public CaptureProgressDirection getSiegeProgressDirection(Town town, Location townSpawn) {
|
||||
int attackersOnPoint = getPeopleOnPoint(town, townSpawn, BattleSide.ATTACKER);
|
||||
int defendersOnPoint = getPeopleOnPoint(town, townSpawn, BattleSide.DEFENDER);
|
||||
final boolean attackersAreOnPoint = attackersOnPoint > 0;
|
||||
final boolean defendersAreOnPoint = defendersOnPoint > 0;
|
||||
|
||||
if (attackersAreOnPoint)
|
||||
siege.setLastTouched(Instant.now());
|
||||
|
||||
if (attackersAreOnPoint && defendersAreOnPoint) {
|
||||
return CaptureProgressDirection.NONE;
|
||||
} else if (attackersAreOnPoint && !defendersAreOnPoint) {
|
||||
if (siege.getSiegeProgress() == MAX_SIEGE_PROGRESS)
|
||||
return CaptureProgressDirection.NONE;
|
||||
|
||||
return CaptureProgressDirection.UP;
|
||||
} /*else if (!attackersAreOnPoint && !defendersAreOnPoint) {
|
||||
return CaptureProgressDirection.UNCONTESTED;
|
||||
}*/ else {
|
||||
if (siege.getSiegeProgress() == 0)
|
||||
return CaptureProgressDirection.NONE;
|
||||
|
||||
// If the attackers haven't touched in a while, begin reverting progress
|
||||
if (Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_REVERT))) {
|
||||
return CaptureProgressDirection.DOWN;
|
||||
} else {
|
||||
return CaptureProgressDirection.NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startBeam() {
|
||||
if (beam != null)
|
||||
return;
|
||||
|
||||
try {
|
||||
Location loc1 = siege.getTownSpawn();
|
||||
Location loc2 = new Location(loc1.getWorld(), loc1.getX(), loc1.getY() + 350D, loc1.getZ());
|
||||
|
||||
beam = new Laser.CrystalLaser(loc1, loc2, -1, BATTLEFIELD_RANGE);
|
||||
|
||||
if (beam != null)
|
||||
beam.start(Main.getInstance());
|
||||
} catch (ReflectiveOperationException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private void stopBeam() {
|
||||
if (beam != null) {
|
||||
beam.stop();
|
||||
beam = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.github.alathra.AlathranWars.data;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import de.leonhard.storage.Config;
|
||||
|
||||
public class ConfigManager {
|
||||
private Main instance;
|
||||
private Config cfg;
|
||||
|
||||
public ConfigManager(Main instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
cfg = new Config("config", instance.getDataFolder().getPath(), instance.getResource("config.yml"));
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return cfg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.github.alathra.AlathranWars.data;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.utility.Config;
|
||||
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.mariadb.jdbc.MariaDbDataSource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DataManager {
|
||||
private Main instance;
|
||||
// private static DataManager instance;
|
||||
private HikariConfig hikariConfig;
|
||||
private HikariDataSource hikariDataSource;
|
||||
|
||||
public DataManager(Main instance) {
|
||||
/*if (instance != null)
|
||||
Bukkit.getServer().getLogger().warning("Tried to re-initialize singleton");
|
||||
|
||||
main = Main.getInstance();*/
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
/*@NotNull
|
||||
public static DataManager getInstance() {
|
||||
if (instance == null)
|
||||
instance = new DataManager();
|
||||
|
||||
return instance;
|
||||
}*/
|
||||
|
||||
public void onLoad() {
|
||||
openConnection();
|
||||
SQLQueries.initDB();
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
closeDatabaseConnection();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Connection getConnection() throws SQLException {
|
||||
if (hikariDataSource == null)
|
||||
throw new SQLException("Unable to get a connection from the pool. (hikariDataSource is null)");
|
||||
|
||||
Connection connection = hikariDataSource.getConnection();
|
||||
if (connection == null)
|
||||
throw new SQLException("Unable to get a connection from the pool. (HikariDataSource#getConnection returned null)");
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public HikariDataSource getDataSource() {
|
||||
return hikariDataSource;
|
||||
}
|
||||
|
||||
public void openConnection() {
|
||||
if (hikariDataSource != null)
|
||||
return;
|
||||
|
||||
hikariConfig = new HikariConfig();
|
||||
|
||||
final boolean mysqlEnabled = Config.get().getBoolean("mysql.enabled");
|
||||
|
||||
if (mysqlEnabled) {
|
||||
hikariConfig.setDataSourceClassName("org.mariadb.jdbc.MariaDbDataSource");
|
||||
hikariConfig.setJdbcUrl("jdbc:mariadb://%s/%s".formatted(
|
||||
Config.get().get("mysql.host", "127.0.0.1:3306"),
|
||||
Config.get().get("mysql.database", "database")
|
||||
));
|
||||
hikariConfig.addDataSourceProperty("url", "jdbc:mariadb://%s/%s".formatted(
|
||||
Config.get().get("mysql.host", "127.0.0.1:3306"),
|
||||
Config.get().get("mysql.database", "database")
|
||||
));
|
||||
hikariConfig.setUsername(Config.get().get("mysql.user", "username"));
|
||||
hikariConfig.setPassword(Config.get().get("mysql.pass", "123"));
|
||||
hikariConfig.setConnectionTimeout(5000);
|
||||
hikariConfig.setKeepaliveTime(0);
|
||||
} else {
|
||||
File dataFolder = new File(instance.getDataFolder(), "database.db");
|
||||
|
||||
if (!dataFolder.exists()) {
|
||||
try {
|
||||
if (!dataFolder.createNewFile())
|
||||
instance.getLogger().severe("File write error: database.db (1)");
|
||||
} catch (IOException e) {
|
||||
instance.getLogger().severe("File write error: database.db (2) - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
hikariConfig.setJdbcUrl("jdbc:sqlite:" + dataFolder);
|
||||
hikariConfig.setConnectionInitSql("PRAGMA journal_mode=WAL; PRAGMA busy_timeout=30000");
|
||||
hikariConfig.setConnectionTimeout(30000);
|
||||
}
|
||||
|
||||
hikariConfig.setPoolName("althranwars-hikari");
|
||||
hikariConfig.setMaximumPoolSize(10);
|
||||
hikariConfig.setMinimumIdle(10);
|
||||
hikariConfig.setInitializationFailTimeout(-1); // We try to create tables after this anyways which will error if no connection
|
||||
// hikariConfig.addDataSourceProperty("characterEncoding", "UTF-8");
|
||||
|
||||
// General optimizations (https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration)
|
||||
// hikariConfig.addDataSourceProperty("cachePrepStmts", "true");
|
||||
// hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
// hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
// hikariConfig.addDataSourceProperty("useServerPrepStmts", "true");
|
||||
// hikariConfig.addDataSourceProperty("useLocalSessionState", "true");
|
||||
// hikariConfig.addDataSourceProperty("rewriteBatchedStatements", "true");
|
||||
// hikariConfig.addDataSourceProperty("cacheServerConfiguration", "true");
|
||||
// hikariConfig.addDataSourceProperty("maintainTimeStats", "false");
|
||||
// hikariConfig.addDataSourceProperty("allowPublicKeyRetrieval", "true");
|
||||
// hikariConfig.addDataSourceProperty("useSSL", "false");
|
||||
|
||||
hikariDataSource = new HikariDataSource(hikariConfig);
|
||||
}
|
||||
|
||||
public void closeDatabaseConnection() {
|
||||
instance.getLogger().info("Closing database connection...");
|
||||
|
||||
if (hikariDataSource != null) {
|
||||
if (!hikariDataSource.isClosed()) {
|
||||
try {
|
||||
hikariDataSource.close();
|
||||
} catch (Exception e) {
|
||||
instance.getLogger().severe("Error closing database connections:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
instance.getLogger().info("Skipped closing database connection: connection is already closed.");
|
||||
}
|
||||
} else {
|
||||
instance.getLogger().severe("Skipped closing database connection because the data source is null. Was there a previous error which needs to be fixed? Check your console logs!");
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.data;
|
||||
package com.github.alathra.AlathranWars.data;
|
||||
|
||||
public enum RaidPhase {
|
||||
START(0, 0),
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.enums;
|
||||
package com.github.alathra.AlathranWars.enums;
|
||||
|
||||
public enum AdminCommandFailEnum {
|
||||
PERMISSIONS,
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.enums;
|
||||
package com.github.alathra.AlathranWars.enums;
|
||||
|
||||
public enum BattleSide {
|
||||
ATTACKER,
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.enums;
|
||||
package com.github.alathra.AlathranWars.enums;
|
||||
|
||||
public enum BattleTeam {
|
||||
SIDE_1,
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.enums;
|
||||
package com.github.alathra.AlathranWars.enums;
|
||||
|
||||
public enum TownWarState {
|
||||
NOT_PARTICIPANT,
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.events;
|
||||
package com.github.alathra.AlathranWars.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.events;
|
||||
package com.github.alathra.AlathranWars.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.events;
|
||||
package com.github.alathra.AlathranWars.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.events;
|
||||
package com.github.alathra.AlathranWars.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.github.alathra.AlathranWars.events.battle;
|
||||
|
||||
public class PreSiegeEndEvent {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.github.alathra.AlathranWars.events.battle;
|
||||
|
||||
public class PreSiegeStartEvent {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.github.alathra.AlathranWars.events.battle;
|
||||
|
||||
public class SiegeEndEvent {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.github.alathra.AlathranWars.events.battle;
|
||||
|
||||
public class SiegeStartEvent {
|
||||
}
|
||||
+61
-12
@@ -1,26 +1,25 @@
|
||||
package me.ShermansWorld.AlathranWars.holder;
|
||||
package com.github.alathra.AlathranWars.holder;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
|
||||
import com.github.alathra.AlathranWars.utility.SQLQueries;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.raid.Raid;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.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.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class WarManager {
|
||||
private static WarManager instance;
|
||||
private final Set<War> wars = new HashSet<>();
|
||||
private Set<War> wars = new HashSet<>();
|
||||
|
||||
private WarManager() {
|
||||
if (instance != null)
|
||||
@@ -35,6 +34,10 @@ public class WarManager {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void loadAll() {
|
||||
wars = SQLQueries.loadAll();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<War> getWars() {
|
||||
return wars;
|
||||
@@ -56,6 +59,22 @@ public class WarManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Side getSide(UUID uuid) {
|
||||
for (War war : wars)
|
||||
if (war.getSide(uuid) != null) return war.getSide(uuid);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Siege getSiege(UUID uuid) {
|
||||
for (War war : wars)
|
||||
if (war.getSiege(uuid) != null) return war.getSiege(uuid);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addWar(War war) {
|
||||
wars.add(war);
|
||||
}
|
||||
@@ -67,7 +86,7 @@ public class WarManager {
|
||||
public boolean isPlayerInAnyWars(UUID uuid) {
|
||||
for (War war : wars) {
|
||||
if (war.isPlayerInWar(uuid)) return true;
|
||||
};
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -78,14 +97,14 @@ public class WarManager {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -122,4 +141,34 @@ public class WarManager {
|
||||
|
||||
return raids;
|
||||
}
|
||||
|
||||
public boolean isPlayerInAnySiege(Player p) {
|
||||
return isPlayerInAnySiege(p.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean isPlayerInAnySiege(UUID uuid) {
|
||||
for (Siege siege : getSieges()) {
|
||||
if (siege.isPlayerInSiege(uuid)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Set<Siege> getPlayerSieges(Player p) {
|
||||
return getPlayerSieges(p.getUniqueId());
|
||||
}
|
||||
|
||||
public Set<Siege> getPlayerSieges(UUID uuid) {
|
||||
if (!isPlayerInAnySiege(uuid))
|
||||
return Collections.emptySet();
|
||||
|
||||
Set<Siege> sieges = new HashSet<>();
|
||||
|
||||
for (Siege siege : getSieges()) {
|
||||
if (siege.isPlayerInSiege(uuid))
|
||||
sieges.add(siege);
|
||||
}
|
||||
|
||||
return sieges;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.hooks;
|
||||
package com.github.alathra.AlathranWars.hooks;
|
||||
|
||||
public class HookManager {
|
||||
public HookManager() {
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
package me.ShermansWorld.AlathranWars.hooks;
|
||||
package com.github.alathra.AlathranWars.hooks;
|
||||
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.listeners.JoinListener;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import me.neznamy.tab.api.TabAPI;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.api.event.EventBus;
|
||||
@@ -34,7 +34,7 @@ public class TABHook {
|
||||
eventBus.register(PlayerLoadEvent.class, e -> {
|
||||
TabPlayer tabPlayer = e.getPlayer();
|
||||
if (tabPlayer.getPlayer() instanceof Player p)
|
||||
JoinListener.checkPlayer(p);
|
||||
PlayerJoinListener.checkPlayer(p);
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.hooks;
|
||||
package com.github.alathra.AlathranWars.hooks;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.items;
|
||||
package com.github.alathra.AlathranWars.items;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package me.ShermansWorld.AlathranWars.items;
|
||||
package com.github.alathra.AlathranWars.items;
|
||||
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
import me.ShermansWorld.AlathranWars.items.item.RamItem;
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.items.item.RamItem;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package me.ShermansWorld.AlathranWars.items;
|
||||
package com.github.alathra.AlathranWars.items;
|
||||
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.HashMap;
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
package me.ShermansWorld.AlathranWars.items.item;
|
||||
package com.github.alathra.AlathranWars.items.item;
|
||||
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
import me.ShermansWorld.AlathranWars.items.IWarItem;
|
||||
import me.ShermansWorld.AlathranWars.items.WarItemRegistry;
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||
import com.github.alathra.AlathranWars.items.IWarItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Tag;
|
||||
+7
-10
@@ -1,9 +1,6 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
package com.github.alathra.AlathranWars.listeners;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.siege.Siege;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -40,21 +37,21 @@ public class BlockBreakListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
/*for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.beaconLocations.contains(block.getLocation())) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
/*for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
e.getPlayer().sendMessage(new ColorParser("<red>You can not break blocks during sieges").parseLegacy().build());
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/*for (final OldRaid oldRaid : RaidData.getRaids()) {
|
||||
if (oldRaid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
@@ -82,13 +79,13 @@ public class BlockBreakListener implements Listener {
|
||||
}
|
||||
|
||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
/*for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(new ColorParser("<red>You can not place blocks during sieges").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/*for (final OldRaid oldRaid : RaidData.getRaids()) {
|
||||
if (oldRaid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
+7
-5
@@ -1,14 +1,16 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
package com.github.alathra.AlathranWars.listeners;
|
||||
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.siege.Siege;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class CommandsListener implements Listener {
|
||||
|
||||
final static String[] PREFIXES = new String[]{
|
||||
@@ -150,7 +152,7 @@ public class CommandsListener implements Listener {
|
||||
*/
|
||||
for (Siege siege : WarManager.getInstance().getSieges()) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
if (siege.getSiegeTicks() > 0) {
|
||||
if (siege.getEndTime().isAfter(Instant.now())) {
|
||||
//only do for active raiders and any defenders
|
||||
if (siege.getAttackerPlayers().contains(p) || siege.getDefenderPlayers().contains(p)) {
|
||||
//set spawn and properties
|
||||
+8
-8
@@ -1,14 +1,14 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
package com.github.alathra.AlathranWars.listeners;
|
||||
|
||||
import com.github.alathra.AlathranWars.utility.Utils;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
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.AlathranWars.conflict.battle.siege.Siege;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.utility.Utils;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -32,7 +32,7 @@ public final class KillsListener implements Listener {
|
||||
boolean playerCloseToHomeBlockSiege = false;
|
||||
boolean playerCloseToHomeBlockRaid = false;
|
||||
|
||||
try {
|
||||
// try {
|
||||
//OldRaid logic
|
||||
/*for (final OldRaid oldRaid : RaidData.getRaids()) {
|
||||
final int homeBlockXCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
|
||||
@@ -87,7 +87,7 @@ public final class KillsListener implements Listener {
|
||||
}
|
||||
|
||||
*/
|
||||
if (killer == null) return;
|
||||
/*if (killer == null) return;
|
||||
|
||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
final int homeBlockXCoord = siege.getTown().getHomeBlock().getCoord().getX() * 16;
|
||||
@@ -147,7 +147,7 @@ public final class KillsListener implements Listener {
|
||||
}
|
||||
} catch (NullPointerException | TownyException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.github.alathra.AlathranWars.listeners;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.listeners.siege.BlockBreakPlaceListener;
|
||||
import com.github.alathra.AlathranWars.listeners.siege.PlayerDeathListener;
|
||||
import com.github.alathra.AlathranWars.listeners.siege.PlayerQuitListener;
|
||||
import com.github.alathra.AlathranWars.listeners.war.NationListener;
|
||||
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
|
||||
import com.github.alathra.AlathranWars.listeners.war.TownListener;
|
||||
|
||||
/**
|
||||
* A class to handle registration of event listeners.
|
||||
*/
|
||||
public class ListenerHandler {
|
||||
private final Main instance;
|
||||
|
||||
public ListenerHandler(Main instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void onLoad() {
|
||||
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
// Sieges
|
||||
instance.getServer().getPluginManager().registerEvents(new com.github.alathra.AlathranWars.listeners.siege.PlayerJoinListener(), instance);
|
||||
instance.getServer().getPluginManager().registerEvents(new PlayerQuitListener(), instance);
|
||||
instance.getServer().getPluginManager().registerEvents(new BlockBreakPlaceListener(), instance);
|
||||
instance.getServer().getPluginManager().registerEvents(new PlayerDeathListener(), instance);
|
||||
|
||||
// Wars
|
||||
instance.getServer().getPluginManager().registerEvents(new NationListener(), instance);
|
||||
instance.getServer().getPluginManager().registerEvents(new TownListener(), instance);
|
||||
instance.getServer().getPluginManager().registerEvents(new TownListener(), instance);
|
||||
instance.getServer().getPluginManager().registerEvents(new PlayerJoinListener(), instance);
|
||||
instance.getServer().getPluginManager().registerEvents(new com.github.alathra.AlathranWars.listeners.war.PlayerQuitListener(), instance);
|
||||
|
||||
// instance.getServer().getPluginManager().registerEvents(new BlockBreakListener(), instance);
|
||||
instance.getServer().getPluginManager().registerEvents(new CommandsListener(), instance);
|
||||
// instance.getServer().getPluginManager().registerEvents(new KillsListener(), instance);
|
||||
instance.getServer().getPluginManager().registerEvents(new PlayerInteractListener(), instance);
|
||||
//instance.getServer().getPluginManager().registerEvents(new PlayerJoinListener(instance), instance);
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,13 +1,13 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
package com.github.alathra.AlathranWars.listeners;
|
||||
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.siege.Siege;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.items.WarItemRegistry;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.github.alathra.AlathranWars.items.WarItemRegistry;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.github.alathra.AlathranWars.listeners.siege;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockBreakPlaceListener implements Listener {
|
||||
private final static Set<Material> allowedBlocks = Set.of(
|
||||
Material.TNT,
|
||||
// Mortar & Cannons
|
||||
Material.IRON_BLOCK,
|
||||
Material.HEAVY_WEIGHTED_PRESSURE_PLATE,
|
||||
Material.TORCH,
|
||||
Material.STONE_BUTTON,
|
||||
Material.BLACK_WOOL
|
||||
);
|
||||
|
||||
@EventHandler
|
||||
private void onBlockBreak(BlockBreakEvent e) {
|
||||
final Block block = e.getBlock();
|
||||
|
||||
if (allowedBlocks.contains(block.getType()))
|
||||
return;
|
||||
|
||||
if (e.getPlayer().hasPermission("AlathranWars.break"))
|
||||
return;
|
||||
|
||||
final @Nullable Town town = WorldCoord.parseWorldCoord(block).getTownOrNull();
|
||||
|
||||
if (town == null)
|
||||
return;
|
||||
|
||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getTown().equals(town)) {
|
||||
e.getPlayer().sendMessage(new ColorParser("<red>You can not break blocks during sieges.").build());
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
final Block block = e.getBlock();
|
||||
|
||||
if (allowedBlocks.contains(block.getType()))
|
||||
return;
|
||||
|
||||
if (e.getPlayer().hasPermission("AlathranWars.place"))
|
||||
return;
|
||||
|
||||
final @Nullable Town town = WorldCoord.parseWorldCoord(block).getTownOrNull();
|
||||
|
||||
if (town == null)
|
||||
return;
|
||||
|
||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
if (siege.getTown().equals(town)) {
|
||||
e.getPlayer().sendMessage(new ColorParser("<red>You can not place blocks during sieges.").build());
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package com.github.alathra.AlathranWars.listeners.siege;
|
||||
|
||||
import com.github.alathra.AlathranWars.utility.Utils;
|
||||
import com.github.alathra.AlathranWars.utility.UtilsChat;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PlayerDeathListener implements Listener {
|
||||
private final static int BATTLE_RADIUS = 300;
|
||||
private final static int KILL_POINTS_OFF = 20; // Point for an offensive kill
|
||||
private final static int KILL_POINTS_DEF = 20; // Point for a defensive kill
|
||||
|
||||
/*@EventHandler
|
||||
private void onPlayerDeath(PlayerDeathEvent e) {
|
||||
final Player victim = e.getPlayer();
|
||||
final Player attacker = e.getPlayer().getKiller();
|
||||
|
||||
if (attacker == null)
|
||||
return;
|
||||
|
||||
final @Nullable Town town = WorldCoord.parseWorldCoord(victim).getTownOrNull();
|
||||
|
||||
for (Siege siege : WarManager.getInstance().getSieges()) {
|
||||
boolean isPlayerInCombatZone = false;
|
||||
|
||||
final TownBlock homeBlock = siege.getTown().getHomeBlockOrNull();
|
||||
if (homeBlock == null)
|
||||
continue;
|
||||
|
||||
final int homeBlockXCoord = homeBlock.getCoord().getX() * 16;
|
||||
final int homeBlockZCoord = homeBlock.getCoord().getZ() * 16;
|
||||
|
||||
if (victim.getLocation().distance(new Location(victim.getWorld(), homeBlockXCoord, victim.getLocation().getBlockY(), homeBlockZCoord)) <= BATTLE_RADIUS) {
|
||||
// if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoord) <= BATTLE_RADIUS && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoord) <= BATTLE_RADIUS) {
|
||||
isPlayerInCombatZone = true;
|
||||
}
|
||||
|
||||
if (siege.getAttackerPlayers().contains(attacker) && (siege.getTown().equals(town) || isPlayerInCombatZone)) {
|
||||
if (siege.getDefenderPlayers().contains(victim)) {
|
||||
siege.addPointsToAttackers(KILL_POINTS_OFF);
|
||||
|
||||
for (final Player p : siege.getAttackerPlayers()) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Defender killed! + "+KILL_POINTS_OFF+" Attacker Points.").build());
|
||||
}
|
||||
for (final Player p : siege.getDefenderPlayers()) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Defender killed! + "+KILL_POINTS_OFF+" Attacker Points.").build());
|
||||
}
|
||||
}
|
||||
|
||||
this.siegeKill(victim, e);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (siege.getDefenderPlayers().contains(attacker) && (siege.getTown().equals(town) || isPlayerInCombatZone)) {
|
||||
if (siege.getAttackerPlayers().contains(victim)) {
|
||||
siege.addPointsToDefenders(KILL_POINTS_DEF);
|
||||
|
||||
for (final Player p : siege.getAttackerPlayers()) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Attacker killed! + "+KILL_POINTS_DEF+" Defender Points.").build());
|
||||
}
|
||||
for (final Player p : siege.getDefenderPlayers()) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Attacker killed! + "+KILL_POINTS_DEF+" Defender Points.").build());
|
||||
}
|
||||
}
|
||||
|
||||
this.siegeKill(victim, e);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ((siege.getTown().equals(town) || isPlayerInCombatZone)) {
|
||||
this.oocKill(victim, e);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Damage all gear held by the player (and then send them to spawn?)
|
||||
* They don't lose items from death.
|
||||
*
|
||||
* @param victim killed player
|
||||
* @param e event
|
||||
*/
|
||||
private void siegeKill(Player victim, PlayerDeathEvent e) {
|
||||
//Helper
|
||||
Utils.damageAllGear(victim);
|
||||
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + victim.getName()); // TODO Re enable?
|
||||
e.setKeepInventory(true);
|
||||
e.getDrops().clear();
|
||||
e.setKeepLevel(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dont damage items held by the player
|
||||
* They don't lose items from death.
|
||||
*
|
||||
* @param victim killed player
|
||||
* @param e event
|
||||
*/
|
||||
private void oocKill(Player victim, PlayerDeathEvent e) {
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + victim.getName()); // TODO Re enable?
|
||||
e.setKeepInventory(true);
|
||||
e.getDrops().clear();
|
||||
e.setKeepLevel(true);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.github.alathra.AlathranWars.listeners.siege;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerExampleListener implements Listener {
|
||||
@EventHandler
|
||||
private void onPlayerJoin(PlayerJoinEvent e) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.github.alathra.AlathranWars.listeners.siege;
|
||||
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
@EventHandler
|
||||
private void onPlayerJoin(PlayerJoinEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
if (WarManager.getInstance().isPlayerInAnySiege(p)) {
|
||||
for (Siege siege : WarManager.getInstance().getPlayerSieges(p)) {
|
||||
final BattleSide side = siege.getPlayerSideInSiege(p);
|
||||
siege.addOnlinePlayer(p, side);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.github.alathra.AlathranWars.listeners.siege;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerQuitListener implements Listener {
|
||||
@EventHandler
|
||||
private void onPlayerQuit(PlayerQuitEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
if (WarManager.getInstance().isPlayerInAnySiege(p)) {
|
||||
for (Siege siege : WarManager.getInstance().getPlayerSieges(p)) {
|
||||
final BattleSide side = siege.getPlayerSideInSiege(p);
|
||||
siege.removeOnlinePlayer(p, side);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
package com.github.alathra.AlathranWars.listeners.war;
|
||||
|
||||
import com.palmergames.bukkit.towny.event.nation.NationKingChangeEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -12,9 +12,10 @@ public class NationListener implements Listener {
|
||||
* NationPreRenameEvent
|
||||
*
|
||||
*
|
||||
* NationTownJoin (add to war)
|
||||
* NationTownLeave (add to war)
|
||||
*
|
||||
* */
|
||||
|
||||
// TODO Prevent nation rename during war, siege, raid
|
||||
|
||||
/*@EventHandler
|
||||
+18
-7
@@ -1,8 +1,9 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
package com.github.alathra.AlathranWars.listeners.war;
|
||||
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.hooks.TABHook;
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.github.alathra.AlathranWars.hooks.TABHook;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -10,7 +11,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
public class PlayerJoinListener implements Listener {
|
||||
public static void checkPlayer(Player p) {
|
||||
final UUID uuid = p.getUniqueId();
|
||||
|
||||
@@ -30,7 +31,17 @@ public class JoinListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final Player p = event.getPlayer();
|
||||
private void onPlayerJoin(PlayerJoinEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
if (WarManager.getInstance().isPlayerInAnyWars(p)) {
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
if (war.isPlayerInWar(p)) {
|
||||
Side side = war.getPlayerSide(p);
|
||||
if (side != null) {
|
||||
side.addOnlinePlayer(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.github.alathra.AlathranWars.listeners.war;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerQuitListener implements Listener {
|
||||
@EventHandler
|
||||
private void onPlayerQuit(PlayerQuitEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
if (WarManager.getInstance().isPlayerInAnyWars(p)) {
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
if (war.isPlayerInWar(p)) {
|
||||
Side side = war.getPlayerSide(p);
|
||||
if (side != null) {
|
||||
side.removeOnlinePlayer(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
package com.github.alathra.AlathranWars.listeners.war;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -15,5 +15,8 @@ public class TownListener implements Listener {
|
||||
TownPreRuinedEvent
|
||||
TownPreRenameEvent
|
||||
TownRemoveResidentEvent
|
||||
|
||||
PlayerJoinTown (add to war)
|
||||
PlayerLeaveTown (add to war)
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.github.alathra.AlathranWars.utility;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
|
||||
public class Config {
|
||||
public static de.leonhard.storage.Config get() {
|
||||
return Main.getInstance().getConfigManager().getConfig();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.github.alathra.AlathranWars.utility;
|
||||
|
||||
import com.github.alathra.AlathranWars.Main;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public abstract class DB {
|
||||
public static Connection get() throws SQLException {
|
||||
return Main.getInstance().getDataManager().getConnection();
|
||||
}
|
||||
|
||||
public static HikariDataSource getDataSource() {
|
||||
return Main.getInstance().getDataManager().getDataSource();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,496 @@
|
||||
package com.github.alathra.AlathranWars.utility;
|
||||
|
||||
import com.github.alathra.AlathranWars.conflict.Side;
|
||||
import com.github.alathra.AlathranWars.conflict.War;
|
||||
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
|
||||
import com.github.alathra.AlathranWars.enums.BattleSide;
|
||||
import com.github.alathra.AlathranWars.enums.BattleTeam;
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SQLQueries {
|
||||
public static void initDB() {
|
||||
try (final Statement statement = DB.get().createStatement()) {
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_list` (
|
||||
`uuid` uuid NOT NULL DEFAULT uuid(),
|
||||
`name` tinytext NOT NULL,
|
||||
`label` tinytext NOT NULL,
|
||||
`side1` uuid NOT NULL DEFAULT uuid(),
|
||||
`side2` uuid NOT NULL DEFAULT uuid(),
|
||||
PRIMARY KEY (`uuid`),
|
||||
KEY `side2` (`side2`),
|
||||
KEY `side1` (`side1`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sides` (
|
||||
`war` uuid NOT NULL,
|
||||
`uuid` uuid NOT NULL,
|
||||
`side` tinytext NOT NULL,
|
||||
`team` tinytext NOT NULL,
|
||||
`name` tinytext NOT NULL,
|
||||
`town` uuid NOT NULL,
|
||||
`siegeGrace` timestamp NOT NULL,
|
||||
`raidGrace` timestamp NOT NULL,
|
||||
PRIMARY KEY (`uuid`),
|
||||
KEY `town` (`town`),
|
||||
KEY `war` (`war`),
|
||||
CONSTRAINT `war` FOREIGN KEY (`war`) REFERENCES `wars_list` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sides_nations` (
|
||||
`side` uuid NOT NULL,
|
||||
`nation` uuid NOT NULL,
|
||||
KEY `side_nations` (`side`),
|
||||
CONSTRAINT `side_nations` FOREIGN KEY (`side`) REFERENCES `wars_sides` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sides_nations_surrendered` (
|
||||
`side` uuid NOT NULL,
|
||||
`nation` uuid NOT NULL,
|
||||
KEY `side_nations_surrendered` (`side`),
|
||||
CONSTRAINT `side_nations_surrendered` FOREIGN KEY (`side`) REFERENCES `wars_sides` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sides_players` (
|
||||
`side` uuid NOT NULL,
|
||||
`player` uuid NOT NULL,
|
||||
KEY `side_players` (`side`),
|
||||
CONSTRAINT `side_players` FOREIGN KEY (`side`) REFERENCES `wars_sides` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sides_players_surrendered` (
|
||||
`side` uuid NOT NULL,
|
||||
`player` uuid NOT NULL,
|
||||
KEY `side_players_surrendered` (`side`),
|
||||
CONSTRAINT `side_players_surrendered` FOREIGN KEY (`side`) REFERENCES `wars_sides` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sides_towns` (
|
||||
`side` uuid NOT NULL,
|
||||
`town` uuid NOT NULL,
|
||||
KEY `side_towns` (`side`),
|
||||
CONSTRAINT `side_towns` FOREIGN KEY (`side`) REFERENCES `wars_sides` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sides_towns_surrendered` (
|
||||
`side` uuid NOT NULL,
|
||||
`town` uuid NOT NULL,
|
||||
KEY `side_towns_surrendered` (`side`),
|
||||
CONSTRAINT `side_towns_surrendered` FOREIGN KEY (`side`) REFERENCES `wars_sides` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sieges` (
|
||||
`war` uuid NOT NULL,
|
||||
`uuid` uuid NOT NULL,
|
||||
`town` uuid NOT NULL,
|
||||
`siegeLeader` uuid NOT NULL,
|
||||
`endTime` timestamp NOT NULL,
|
||||
`siegeProgress` int(11) NOT NULL,
|
||||
PRIMARY KEY (`uuid`),
|
||||
KEY `siege_war` (`war`),
|
||||
CONSTRAINT `siege_war` FOREIGN KEY (`war`) REFERENCES `wars_list` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sieges_players_attackers` (
|
||||
`siege` uuid NOT NULL,
|
||||
`player` uuid NOT NULL,
|
||||
KEY `siege_players_attackers` (`siege`),
|
||||
CONSTRAINT `siege_players_attackers` FOREIGN KEY (`siege`) REFERENCES `wars_sieges` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.addBatch("""
|
||||
CREATE TABLE IF NOT EXISTS `wars_sieges_players_defenders` (
|
||||
`siege` uuid NOT NULL,
|
||||
`player` uuid NOT NULL,
|
||||
KEY `siege_players_defenders` (`siege`),
|
||||
CONSTRAINT `siege_players_defenders` FOREIGN KEY (`siege`) REFERENCES `wars_sieges` (`uuid`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
""");
|
||||
|
||||
statement.executeLargeBatch();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveAll() {
|
||||
try (
|
||||
Connection con = DB.get();
|
||||
PreparedStatement warStatement = con.prepareStatement("INSERT INTO `wars_list` (`uuid`, `name`, `label`, `side1`, `side2`) VALUES (?, ?, ?, ?, ?) "
|
||||
+ "ON DUPLICATE KEY UPDATE `name` = ?, `label` = ?, `side1` = ?, `side2` = ?")
|
||||
) {
|
||||
// Save wars
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
// Insert
|
||||
warStatement.setString(1, war.getUUID().toString());
|
||||
warStatement.setString(2, war.getName());
|
||||
warStatement.setString(3, war.getLabel());
|
||||
warStatement.setString(4, war.getSide1().getUUID().toString());
|
||||
warStatement.setString(5, war.getSide2().getUUID().toString());
|
||||
|
||||
// Update
|
||||
warStatement.setString(6, war.getName());
|
||||
warStatement.setString(7, war.getLabel());
|
||||
warStatement.setString(8, war.getSide1().getUUID().toString());
|
||||
warStatement.setString(9, war.getSide2().getUUID().toString());
|
||||
|
||||
warStatement.executeUpdate();
|
||||
|
||||
// Save sides
|
||||
for (Side side : war.getSides()) {
|
||||
saveSide(con, side);
|
||||
}
|
||||
|
||||
// TODO Save sieges
|
||||
// for (Siege siege : war.getSieges()) {
|
||||
//
|
||||
// }
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSide(Connection con, Side side) throws SQLException {
|
||||
try (
|
||||
PreparedStatement sideStatement = con.prepareStatement("INSERT INTO `wars_sides` (`war`, `uuid`, `side`, `team`, `name`, `town`, `siegeGrace`, `raidGrace`) VALUES (?, ?, ?, ?, ?, ?, ?, ?) "
|
||||
+ "ON DUPLICATE KEY UPDATE `side` = ?, `team` = ?, `name` = ?, `town` = ?, `siegeGrace` = ?, `raidGrace` = ?");
|
||||
)
|
||||
{
|
||||
// Insert
|
||||
sideStatement.setString(1, side.getWar().getUUID().toString());
|
||||
sideStatement.setString(2, side.getUUID().toString());
|
||||
sideStatement.setString(3, side.getSide().toString());
|
||||
sideStatement.setString(4, side.getTeam().toString());
|
||||
sideStatement.setString(5, side.getName());
|
||||
sideStatement.setString(6, side.getTown().getUUID().toString());
|
||||
sideStatement.setTimestamp(7, Timestamp.from(side.getSiegeGrace()));
|
||||
sideStatement.setTimestamp(8, Timestamp.from(side.getRaidGrace()));
|
||||
|
||||
// Update
|
||||
sideStatement.setString(9, side.getSide().toString());
|
||||
sideStatement.setString(10, side.getTeam().toString());
|
||||
sideStatement.setString(11, side.getName());
|
||||
sideStatement.setString(12, side.getTown().getUUID().toString());
|
||||
sideStatement.setTimestamp(13, Timestamp.from(side.getSiegeGrace()));
|
||||
sideStatement.setTimestamp(14, Timestamp.from(side.getRaidGrace()));
|
||||
|
||||
sideStatement.executeUpdate();
|
||||
|
||||
saveSideNations(con, side, false);
|
||||
saveSideNations(con, side, true);
|
||||
saveSideTowns(con, side, false);
|
||||
saveSideTowns(con, side, true);
|
||||
saveSidePlayers(con, side, false);
|
||||
saveSidePlayers(con, side, true);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSideNations(Connection con, Side side, boolean surrendered) throws SQLException {
|
||||
try (
|
||||
PreparedStatement deleteStatement = con.prepareStatement("DELETE FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_nations_surrendered" : "wars_sides_nations"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`side`, `nation`) VALUES (?, ?)".formatted(surrendered ? "wars_sides_nations_surrendered" : "wars_sides_nations"));
|
||||
) {
|
||||
try {
|
||||
// Transaction start
|
||||
con.setAutoCommit(false);
|
||||
|
||||
// Delete old
|
||||
deleteStatement.setString(1, side.getUUID().toString());
|
||||
deleteStatement.executeUpdate();
|
||||
|
||||
// Insert new
|
||||
for (Nation nation : (surrendered ? side.getSurrenderedNations() : side.getNations())) {
|
||||
insertStatement.setString(1, side.getUUID().toString());
|
||||
insertStatement.setString(2, nation.getUUID().toString());
|
||||
insertStatement.executeUpdate();
|
||||
}
|
||||
|
||||
// Transaction end
|
||||
con.commit();
|
||||
} catch(Exception e) {
|
||||
con.rollback();
|
||||
} finally {
|
||||
con.setAutoCommit(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSideTowns(Connection con, Side side, boolean surrendered) throws SQLException {
|
||||
try (
|
||||
PreparedStatement deleteStatement = con.prepareStatement("DELETE FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_towns_surrendered" : "wars_sides_towns"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`side`, `town`) VALUES (?, ?)".formatted(surrendered ? "wars_sides_towns_surrendered" : "wars_sides_towns"));
|
||||
) {
|
||||
try {
|
||||
// Transaction start
|
||||
con.setAutoCommit(false);
|
||||
|
||||
// Delete old
|
||||
deleteStatement.setString(1, side.getUUID().toString());
|
||||
deleteStatement.executeUpdate();
|
||||
|
||||
// Insert new
|
||||
for (Town town : (surrendered ? side.getSurrenderedTowns() : side.getTowns())) {
|
||||
insertStatement.setString(1, side.getUUID().toString());
|
||||
insertStatement.setString(2, town.getUUID().toString());
|
||||
insertStatement.executeUpdate();
|
||||
}
|
||||
|
||||
// Transaction end
|
||||
con.commit();
|
||||
} catch(Exception e) {
|
||||
con.rollback();
|
||||
} finally {
|
||||
con.setAutoCommit(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void saveSidePlayers(Connection con, Side side, boolean surrendered) throws SQLException {
|
||||
try (
|
||||
PreparedStatement deleteStatement = con.prepareStatement("DELETE FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_players_surrendered" : "wars_sides_players"));
|
||||
PreparedStatement insertStatement = con.prepareStatement("INSERT INTO `%s` (`side`, `player`) VALUES (?, ?)".formatted(surrendered ? "wars_sides_players_surrendered" : "wars_sides_players"));
|
||||
) {
|
||||
try {
|
||||
// Transaction start
|
||||
con.setAutoCommit(false);
|
||||
|
||||
// Delete old
|
||||
deleteStatement.setString(1, side.getUUID().toString());
|
||||
deleteStatement.executeUpdate();
|
||||
|
||||
// Insert new
|
||||
for (UUID uuid : (surrendered ? side.getSurrenderedPlayersIncludingOffline() : side.getPlayersIncludingOffline())) {
|
||||
insertStatement.setString(1, side.getUUID().toString());
|
||||
insertStatement.setString(2, uuid.toString());
|
||||
insertStatement.executeUpdate();
|
||||
}
|
||||
|
||||
// Transaction end
|
||||
con.commit();
|
||||
} catch(Exception e) {
|
||||
con.rollback();
|
||||
} finally {
|
||||
con.setAutoCommit(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<War> loadAll() {
|
||||
Set<War> wars = new HashSet<>();
|
||||
|
||||
try (
|
||||
Connection con = DB.get();
|
||||
PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `wars_list`")
|
||||
) {
|
||||
// Load all wars
|
||||
ResultSet warsResult = warStatement.executeQuery();
|
||||
|
||||
if (warsResult == null)
|
||||
throw new SQLException("Failed to get wars from DB");
|
||||
|
||||
while (warsResult.next()) {
|
||||
// War data
|
||||
UUID uuid = UUID.fromString(warsResult.getString("uuid"));
|
||||
String name = warsResult.getString("name");
|
||||
String label = warsResult.getString("label");
|
||||
UUID side1UUID = UUID.fromString(warsResult.getString("side1"));
|
||||
UUID side2UUID = UUID.fromString(warsResult.getString("side2"));
|
||||
Side side1 = loadSide(con, uuid, side1UUID);
|
||||
Side side2 = loadSide(con, uuid, side2UUID);
|
||||
|
||||
// TODO Siege data
|
||||
|
||||
wars.add(new War(
|
||||
uuid,
|
||||
name,
|
||||
label,
|
||||
side1,
|
||||
side2,
|
||||
new HashSet<>(),
|
||||
new HashSet<>()
|
||||
));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return wars;
|
||||
}
|
||||
|
||||
public static Side loadSide(Connection con, UUID warUUID, UUID uuid) {
|
||||
try (PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `wars_sides` WHERE `war` = ? AND `uuid` = ?")) {
|
||||
// Load side
|
||||
warStatement.setString(1, warUUID.toString());
|
||||
warStatement.setString(2, uuid.toString());
|
||||
ResultSet sideResult = warStatement.executeQuery();
|
||||
|
||||
if (sideResult == null)
|
||||
throw new SQLException("Failed to get side from DB");
|
||||
|
||||
sideResult.next();
|
||||
|
||||
// Side data
|
||||
BattleSide side = BattleSide.valueOf(sideResult.getString("side"));
|
||||
BattleTeam team = BattleTeam.valueOf(sideResult.getString("team"));
|
||||
String name = sideResult.getString("name");
|
||||
Town town = TownyAPI.getInstance().getTown(UUID.fromString(sideResult.getString("town")));
|
||||
Instant siegeGrace = sideResult.getTimestamp("siegeGrace").toInstant();
|
||||
Instant raidGrace = sideResult.getTimestamp("raidGrace").toInstant();
|
||||
|
||||
Set<UUID> players = loadSidePlayers(con, uuid, false);
|
||||
Set<UUID> playersSurrendered = loadSidePlayers(con, uuid, true);
|
||||
Set<Nation> nations = loadSideNations(con, uuid, false);
|
||||
Set<Nation> nationsSurrendered = loadSideNations(con, uuid, true);
|
||||
Set<Town> towns = loadSideTowns(con, uuid, false);
|
||||
Set<Town> townsSurrendered = loadSideTowns(con, uuid, true);
|
||||
|
||||
return new Side(
|
||||
warUUID,
|
||||
uuid,
|
||||
town,
|
||||
side,
|
||||
team,
|
||||
name,
|
||||
towns,
|
||||
nations,
|
||||
players,
|
||||
townsSurrendered,
|
||||
nationsSurrendered,
|
||||
playersSurrendered,
|
||||
siegeGrace,
|
||||
raidGrace
|
||||
);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<UUID> loadSidePlayers(Connection con, UUID sideUUID, boolean surrendered) {
|
||||
Set<UUID> players = new HashSet<>();
|
||||
|
||||
try (PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_players_surrendered" : "wars_sides_players"))) {
|
||||
warStatement.setString(1, sideUUID.toString());
|
||||
ResultSet warsResult = warStatement.executeQuery();
|
||||
|
||||
if (warsResult == null)
|
||||
throw new SQLException("Failed to get players from DB");
|
||||
|
||||
while (warsResult.next()) {
|
||||
players.add(UUID.fromString(warsResult.getString("player")));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return players;
|
||||
}
|
||||
|
||||
public static Set<Nation> loadSideNations(Connection con, UUID sideUUID, boolean surrendered) {
|
||||
Set<Nation> nations = new HashSet<>();
|
||||
|
||||
try (PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_nations_surrendered" : "wars_sides_nations"))) {
|
||||
warStatement.setString(1, sideUUID.toString());
|
||||
ResultSet warsResult = warStatement.executeQuery();
|
||||
|
||||
if (warsResult == null)
|
||||
throw new SQLException("Failed to get nations from DB");
|
||||
|
||||
while (warsResult.next()) {
|
||||
final UUID uuid = UUID.fromString(warsResult.getString("nation"));
|
||||
|
||||
@Nullable Nation nation = TownyAPI.getInstance().getNation(uuid);
|
||||
if (nation == null) continue;
|
||||
|
||||
nations.add(nation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return nations;
|
||||
}
|
||||
|
||||
public static Set<Town> loadSideTowns(Connection con, UUID sideUUID, boolean surrendered) {
|
||||
Set<Town> towns = new HashSet<>();
|
||||
|
||||
try (PreparedStatement warStatement = con.prepareStatement("SELECT * FROM `%s` WHERE `side` = ?".formatted(surrendered ? "wars_sides_towns_surrendered" : "wars_sides_towns"))) {
|
||||
warStatement.setString(1, sideUUID.toString());
|
||||
ResultSet warsResult = warStatement.executeQuery();
|
||||
|
||||
if (warsResult == null)
|
||||
throw new SQLException("Failed to get towns from DB");
|
||||
|
||||
while (warsResult.next()) {
|
||||
final UUID uuid = UUID.fromString(warsResult.getString("town"));
|
||||
|
||||
@Nullable Town town = TownyAPI.getInstance().getTown(uuid);
|
||||
if (town == null) continue;
|
||||
|
||||
towns.add(town);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return towns;
|
||||
}
|
||||
|
||||
public static void deleteWar(War war) {
|
||||
try (
|
||||
Connection con = DB.get();
|
||||
PreparedStatement warStatement = con.prepareStatement("DELETE FROM `wars_list` WHERE `uuid` = ?");
|
||||
) {
|
||||
// Delete war data
|
||||
warStatement.setString(1, war.getUUID().toString());
|
||||
warStatement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteSiege(Siege siege) {
|
||||
try (
|
||||
Connection con = DB.get();
|
||||
PreparedStatement siegesStatement = con.prepareStatement("DELETE FROM `wars_sieges` WHERE `uuid` = ?");
|
||||
) {
|
||||
// Delete siege data
|
||||
siegesStatement.setString(1, siege.getUUID().toString());
|
||||
siegesStatement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.github.alathra.AlathranWars.utility;
|
||||
|
||||
import com.github.alathra.AlathranWars.holder.WarManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDUtil {
|
||||
public static UUID generateWarUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
while (WarManager.getInstance().getWar(uuid) != null) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public static UUID generateSideUUID(@Nullable UUID previousSideUUID) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
while (WarManager.getInstance().getSide(uuid) != null || uuid == previousSideUUID) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public static UUID generateSiegeUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
while (WarManager.getInstance().getSiege(uuid) != null) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
return uuid;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.utility;
|
||||
package com.github.alathra.AlathranWars.utility;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import org.bukkit.Material;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.utility;
|
||||
package com.github.alathra.AlathranWars.utility;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict;
|
||||
|
||||
public enum ConflictType {
|
||||
WAR
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict.battle.raid;
|
||||
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.Battle;
|
||||
|
||||
public class Raid extends Battle {
|
||||
}
|
||||
@@ -1,598 +0,0 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict.battle.siege;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.*;
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.Battle;
|
||||
import me.ShermansWorld.AlathranWars.conflict.Side;
|
||||
import me.ShermansWorld.AlathranWars.enums.BattleTeam;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Siege extends Battle {
|
||||
public static final int MAX_SIEGE_TICKS = 72000; // 60 minute tick constant
|
||||
|
||||
public Set<Player> attackerPlayers = new HashSet<>();
|
||||
public Set<Player> defenderPlayers = new HashSet<>();
|
||||
public Set<UUID> attackerPlayersIncludingOffline = new HashSet<>();
|
||||
public Set<UUID> defenderPlayersIncludingOffline = new HashSet<>();
|
||||
// TODO On join during siege, if part of list re-add to battle
|
||||
// TODO On leave during siege, if part clean up misc data
|
||||
|
||||
public ArrayList<Location> beaconLocations;
|
||||
|
||||
int[] bukkitId = new int[1];
|
||||
private int siegeTicks = 0;
|
||||
|
||||
private War war; // War which siege belongs to
|
||||
private Town town; // Town of the siege
|
||||
private boolean side1AreAttackers; // bool of if side1 being attacker
|
||||
|
||||
private OfflinePlayer siegeLeader;
|
||||
private TownBlock homeBlock;
|
||||
private Location townSpawn;
|
||||
private BossBar activeBossBar = null;
|
||||
|
||||
public Siege(final War war, final Town town, Player siegeLeader) {
|
||||
this.beaconLocations = new ArrayList<>();
|
||||
|
||||
this.war = war;
|
||||
this.town = town;
|
||||
|
||||
this.siegeLeader = siegeLeader;
|
||||
|
||||
side1AreAttackers = war.getTownSide(town).getTeam().equals(BattleTeam.SIDE_2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a siege
|
||||
*/
|
||||
public void start() {
|
||||
super.setAttackerPoints(0);
|
||||
super.setDefenderPoints(0);
|
||||
this.siegeTicks = 0;
|
||||
homeBlock = town.getHomeBlockOrNull();
|
||||
townSpawn = town.getSpawnOrNull();
|
||||
|
||||
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), getTickLoop(), 0L, 200L);
|
||||
|
||||
setupDisplayBar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resumes a siege (after a server restart e.t.c.)
|
||||
*/
|
||||
public void resume(int resumeTick) {
|
||||
siegeTicks = resumeTick;
|
||||
|
||||
homeBlock = town.getHomeBlockOrNull();
|
||||
townSpawn = town.getSpawnOrNull();
|
||||
|
||||
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), getTickLoop(), 0L, 200L);
|
||||
|
||||
setupDisplayBar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops a siege
|
||||
*/
|
||||
public void stop() {
|
||||
deleteDisplayBar();
|
||||
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
|
||||
this.war.getSieges().remove(this);
|
||||
}
|
||||
|
||||
private Runnable getTickLoop() {
|
||||
return new Runnable() {
|
||||
int homeBlockControl = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (homeBlock != null) {
|
||||
town.setHomeBlock(homeBlock);
|
||||
town.setSpawn(townSpawn);
|
||||
}
|
||||
|
||||
// LMFAO Who cares about performance anyways
|
||||
if (Siege.this.side1AreAttackers) {
|
||||
Siege.this.attackerPlayers = Siege.this.war.getSide1().getPlayers();
|
||||
Siege.this.defenderPlayers = Siege.this.war.getSide2().getPlayers();
|
||||
} else {
|
||||
Siege.this.attackerPlayers = Siege.this.war.getSide2().getPlayers();
|
||||
Siege.this.defenderPlayers = Siege.this.war.getSide1().getPlayers();
|
||||
}
|
||||
|
||||
if (Siege.this.siegeTicks >= MAX_SIEGE_TICKS) {
|
||||
|
||||
Bukkit.getServer().getScheduler().cancelTask(Siege.this.bukkitId[0]);
|
||||
|
||||
Siege.this.war.getSieges().remove(Siege.this);
|
||||
if (Siege.super.getAttackerPoints() > Siege.super.getDefenderPoints()) {
|
||||
Siege.this.attackersWin(Siege.this.siegeLeader);
|
||||
} else {
|
||||
Siege.this.defendersWin();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
boolean attackersAreOnHomeBlock = false;
|
||||
boolean defendersAreOnHomeBlock = false;
|
||||
siegeTicks = siegeTicks + 200;
|
||||
for (final Player pl : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
if (pl != null) {
|
||||
WorldCoord wc = WorldCoord.parseWorldCoord(pl);
|
||||
if (wc.getTownBlock().getTown().equals(town)) {
|
||||
if (town.getHomeBlockOrNull() != null) {
|
||||
if (town.getHomeBlockOrNull().getWorldCoord().equals(wc)) {
|
||||
if (!pl.isDead()) {
|
||||
if ((Math.abs(pl.getLocation().getBlockY() - townSpawn.getBlockY())) < 10) {
|
||||
attackersAreOnHomeBlock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NotRegisteredException ignored) {
|
||||
// Main.warLogger.log(UtilsChat.getPrefix() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
|
||||
}
|
||||
}
|
||||
for (final Player pl : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
if (pl != null) {
|
||||
WorldCoord wc = WorldCoord.parseWorldCoord(pl);
|
||||
if (wc.getTownBlock().getTown().equals(town)) {
|
||||
if (town.getHomeBlockOrNull() != null) {
|
||||
if (town.getHomeBlockOrNull().getWorldCoord().equals(wc)) {
|
||||
if (!pl.isDead()) {
|
||||
if ((Math.abs(pl.getLocation().getBlockY() - townSpawn.getBlockY())) <= 10) {
|
||||
defendersAreOnHomeBlock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NotRegisteredException ignored) {
|
||||
// Main.warLogger.log(UtilsChat.getPrefix() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
|
||||
}
|
||||
}
|
||||
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) { // Contested
|
||||
|
||||
if (this.homeBlockControl != 1) {
|
||||
for (final Player pl : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
for (final Player pl : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.homeBlockControl = 1;
|
||||
|
||||
} else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) { // Attackers
|
||||
|
||||
if (this.homeBlockControl != 2) {
|
||||
for (final Player pl : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "Attackers have captured the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
for (final Player pl : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "Attackers have captured the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.homeBlockControl = 2;
|
||||
Siege.this.addPointsToAttackers(10);
|
||||
|
||||
} else { // Defenders / None
|
||||
|
||||
if (this.homeBlockControl != 3) {
|
||||
for (final Player pl : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "Defenders retain control of the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Defender Points per second");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
for (final Player pl : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "Defenders retain control of the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Defender Points per second");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Siege.this.addPointsToDefenders(10);
|
||||
this.homeBlockControl = 3;
|
||||
|
||||
}
|
||||
|
||||
if (Siege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "Report on the siege of "
|
||||
+ Siege.this.town.getName() + ":");
|
||||
Bukkit.broadcastMessage(
|
||||
"Attacker Points - " + Siege.super.getAttackerPoints());
|
||||
Bukkit.broadcastMessage(
|
||||
"Defender Points - " + Siege.super.getDefenderPoints());
|
||||
}
|
||||
|
||||
/*if (siegeTicks % 1200 == 0) { // Saves every minute
|
||||
save();
|
||||
}*/
|
||||
}
|
||||
|
||||
updateDisplayBar();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void attackersWin(final OfflinePlayer siegeLeader) {
|
||||
final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
|
||||
Nation nation = null;
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The attackers have won the siege of " + this.town.getName() + "!");
|
||||
try {
|
||||
nation = resident.getTown().getNation();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
if (nation != null) {
|
||||
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");
|
||||
// } else {
|
||||
// if (this.town.getAccount().getHoldingBalance() < 2500.0) {
|
||||
// amt = this.town.getAccount().getHoldingBalance();
|
||||
// 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");
|
||||
// amt = 2500.0;
|
||||
// }
|
||||
/*Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
||||
+ ", valuing $" + amt);*/
|
||||
Bukkit.broadcastMessage("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide() + "!");
|
||||
// Main.warLogger.log("The town of " + this.town.getName() + " has been sacked by " + this.getAttackerSide()
|
||||
// + ", valuing $" + amt);
|
||||
// Main.econ.depositPlayer(siegeLeader, amt);
|
||||
|
||||
if (side1AreAttackers) {
|
||||
war.getSide1().addScore(50);
|
||||
} else {
|
||||
war.getSide2().addScore(50);
|
||||
}
|
||||
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
public void defendersWin() {
|
||||
// this.town.getAccount().deposit(2500.0, "War 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' war chest, valued at $2,500");
|
||||
// Main.warLogger
|
||||
// .log(war.getName() + ": The defenders have won the siege of " + this.town.getName() + "!");
|
||||
|
||||
if (side1AreAttackers) {
|
||||
war.getSide2().addScore(50);
|
||||
} else {
|
||||
war.getSide1().addScore(50);
|
||||
}
|
||||
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
/**
|
||||
* No winnder declared
|
||||
*/
|
||||
public void noWinner() {
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The siege of " + this.town.getName() + " has ended in 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() + "!");
|
||||
stop();
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
public void createBeacon() {
|
||||
try {
|
||||
World world = town.getWorld();
|
||||
int homeBlockX = this.town.getHomeBlock().getX() * 16;
|
||||
int homeBlockZ = (this.town.getHomeBlock().getZ() + 1) * 16;
|
||||
if (homeBlockX > 0) {
|
||||
homeBlockX -= 8;
|
||||
}
|
||||
if (homeBlockZ > 0) {
|
||||
homeBlockZ -= 8;
|
||||
}
|
||||
if (homeBlockX < 0) {
|
||||
homeBlockX += 8;
|
||||
}
|
||||
if (homeBlockZ < 0) {
|
||||
homeBlockZ += 8;
|
||||
}
|
||||
int homeBlockY = 253;
|
||||
final Location beaconLoc = new Location(this.town.getWorld(), homeBlockX,
|
||||
homeBlockY - 2, homeBlockZ);
|
||||
while (beaconLoc.getBlock().getType().equals(Material.AIR)) {
|
||||
--homeBlockY;
|
||||
beaconLoc.setY(homeBlockY);
|
||||
}
|
||||
homeBlockY += 2;
|
||||
this.beaconLocations.add(new Location(world, homeBlockX, homeBlockY, homeBlockZ));
|
||||
this.beaconLocations
|
||||
.add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ));
|
||||
this.beaconLocations
|
||||
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocations.add(
|
||||
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocations.add(
|
||||
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocations.add(
|
||||
new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1));
|
||||
this.beaconLocations.add(
|
||||
new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1));
|
||||
this.beaconLocations.add(new Location(world, homeBlockX + 1, homeBlockY - 1,
|
||||
homeBlockZ + 1));
|
||||
this.beaconLocations.add(new Location(world, homeBlockX + 1, homeBlockY - 1,
|
||||
homeBlockZ - 1));
|
||||
this.beaconLocations.add(new Location(world, homeBlockX - 1, homeBlockY - 1,
|
||||
homeBlockZ + 1));
|
||||
this.beaconLocations.add(new Location(world, homeBlockX - 1, homeBlockY - 1,
|
||||
homeBlockZ - 1));
|
||||
for (int i = 2; i < this.beaconLocations.size(); ++i) {
|
||||
if (this.beaconLocations.get(i).getBlock().getType() != Material.AIR) {
|
||||
i = 1;
|
||||
homeBlockY++;
|
||||
for (final Location loc : this.beaconLocations) {
|
||||
loc.setY(loc.getY() + 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.beaconLocations.get(0).getBlock().setType(Material.BEACON);
|
||||
this.beaconLocations.get(1).getBlock().setType(Material.RED_STAINED_GLASS);
|
||||
for (int i = 2; i < this.beaconLocations.size(); ++i) {
|
||||
this.beaconLocations.get(i).getBlock().setType(Material.IRON_BLOCK);
|
||||
}
|
||||
// save();
|
||||
} catch (TownyException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public void resetBeacon(World world, int homeBlockX, int homeBlockY, int homeBlockZ) {
|
||||
this.beaconLocations.add(new Location(world, homeBlockX, homeBlockY, homeBlockZ));
|
||||
this.beaconLocations.add(new Location(world, homeBlockX, homeBlockY + 1, homeBlockZ));
|
||||
this.beaconLocations.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocations
|
||||
.add(new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocations
|
||||
.add(new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ));
|
||||
this.beaconLocations
|
||||
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ + 1));
|
||||
this.beaconLocations
|
||||
.add(new Location(world, homeBlockX, homeBlockY - 1, homeBlockZ - 1));
|
||||
this.beaconLocations.add(
|
||||
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ + 1));
|
||||
this.beaconLocations.add(
|
||||
new Location(world, homeBlockX + 1, homeBlockY - 1, homeBlockZ - 1));
|
||||
this.beaconLocations.add(
|
||||
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ + 1));
|
||||
this.beaconLocations.add(
|
||||
new Location(world, homeBlockX - 1, homeBlockY - 1, homeBlockZ - 1));
|
||||
}
|
||||
|
||||
public void clearBeacon() {
|
||||
for (final Location loc : this.beaconLocations) {
|
||||
loc.getBlock().setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public War getWar() {
|
||||
return this.war;
|
||||
}
|
||||
|
||||
public void setWar(final War war) {
|
||||
this.war = war;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Town getTown() {
|
||||
return this.town;
|
||||
}
|
||||
|
||||
public void setTown(final Town town) {
|
||||
this.town = town;
|
||||
}
|
||||
|
||||
public OfflinePlayer getSiegeOwner() {
|
||||
return siegeLeader;
|
||||
}
|
||||
|
||||
public void setSiegeOwner(OfflinePlayer siegeOwner) {
|
||||
this.siegeLeader = siegeOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets attacker name string
|
||||
*/
|
||||
public @NotNull Side getAttackerSide() {
|
||||
return side1AreAttackers ? war.getSide1() : war.getSide2();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets defender name string
|
||||
*/
|
||||
public @NotNull Side getDefenderSide() {
|
||||
return side1AreAttackers ? war.getSide2() : war.getSide1();
|
||||
}
|
||||
|
||||
public void updateDisplayBar() {
|
||||
if (activeBossBar == null)
|
||||
createNewDisplayBar();
|
||||
|
||||
activeBossBar.name(
|
||||
new ColorParser("<score1> -- Attackers -Siege Score- Defenders -- <score2>")
|
||||
.parseMinimessagePlaceholder("score1", String.valueOf(super.getAttackerPoints()))
|
||||
.parseMinimessagePlaceholder("score2", String.valueOf(super.getDefenderPoints()))
|
||||
.build()
|
||||
);
|
||||
activeBossBar.progress((float) ((super.getAttackerPoints() + 0.5D) / ((super.getAttackerPoints() + super.getDefenderPoints()) + 1.0D)));
|
||||
}
|
||||
|
||||
public void setupDisplayBar() {
|
||||
if (activeBossBar == null)
|
||||
createNewDisplayBar();
|
||||
|
||||
for (Player p : this.getAttackerPlayers()) {
|
||||
if (p != null) {
|
||||
p.showBossBar(activeBossBar);
|
||||
// bossBar.addViewer(p);
|
||||
// bossBar.addPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
for (Player p : this.getDefenderPlayers()) {
|
||||
if (p != null) {
|
||||
p.showBossBar(activeBossBar);
|
||||
// bossBar.addViewer(p);
|
||||
// bossBar.addPlayer(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void createNewDisplayBar() {
|
||||
final Component text = new ColorParser("<score1> -- Attackers -Siege Score- Defenders -- <score2>")
|
||||
.parseMinimessagePlaceholder("score1", String.valueOf(super.getAttackerPoints()))
|
||||
.parseMinimessagePlaceholder("score2", String.valueOf(super.getDefenderPoints()))
|
||||
.build();
|
||||
|
||||
this.activeBossBar = BossBar.bossBar(text, 0, BossBar.Color.YELLOW, BossBar.Overlay.NOTCHED_6);
|
||||
}
|
||||
|
||||
public void deleteDisplayBar() {
|
||||
if (activeBossBar != null) {
|
||||
for (Player p : this.getAttackerPlayers()) {
|
||||
if (p != null) {
|
||||
activeBossBar.removeViewer(p);
|
||||
}
|
||||
}
|
||||
|
||||
for (Player p : this.getDefenderPlayers()) {
|
||||
if (p != null) {
|
||||
activeBossBar.removeViewer(p);
|
||||
}
|
||||
}
|
||||
|
||||
activeBossBar = null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxSiegeTicks() {
|
||||
return MAX_SIEGE_TICKS;
|
||||
}
|
||||
|
||||
public TownBlock getHomeBlock() {
|
||||
return homeBlock;
|
||||
}
|
||||
|
||||
public void setHomeBlock(TownBlock homeBlock) {
|
||||
this.homeBlock = homeBlock;
|
||||
}
|
||||
|
||||
public Location getTownSpawn() {
|
||||
return townSpawn;
|
||||
}
|
||||
|
||||
public void setTownSpawn(Location townSpawn) {
|
||||
this.townSpawn = townSpawn;
|
||||
}
|
||||
|
||||
public boolean getSide1AreAttackers() {
|
||||
return this.side1AreAttackers;
|
||||
}
|
||||
|
||||
public void setSide1AreAttackers(final boolean side1AreAttackers) {
|
||||
this.side1AreAttackers = side1AreAttackers;
|
||||
}
|
||||
|
||||
public Set<Player> getAttackerPlayers() {
|
||||
return this.attackerPlayers;
|
||||
}
|
||||
|
||||
public void setAttackerPlayer(final Set<Player> attackerPlayers) {
|
||||
this.attackerPlayers = attackerPlayers;
|
||||
}
|
||||
|
||||
public Set<Player> getDefenderPlayers() {
|
||||
return this.defenderPlayers;
|
||||
}
|
||||
|
||||
public void setDefenderPlayer(final Set<Player> defenderPlayers) {
|
||||
this.defenderPlayers = this.attackerPlayers;
|
||||
}
|
||||
|
||||
public int getSiegeTicks() {
|
||||
return siegeTicks;
|
||||
}
|
||||
|
||||
public void setSiegeTicks(int siegeTicks) {
|
||||
this.siegeTicks = siegeTicks;
|
||||
}
|
||||
|
||||
public OfflinePlayer getSiegeLeader() {
|
||||
return siegeLeader;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
// SiegeData.saveSiege(this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.getWar().getName() + "-" + this.getTown();
|
||||
}
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict.battle.siege;
|
||||
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/*
|
||||
public class SiegeRunnable implements Runnable{
|
||||
*/
|
||||
/**
|
||||
* When an object implementing interface {@code Runnable} is used
|
||||
* to create a thread, starting the thread causes the object's
|
||||
* {@code run} method to be called in that separately executing
|
||||
* thread.
|
||||
* <p>
|
||||
* The general contract of the method {@code run} is that it may
|
||||
* take any action whatsoever.
|
||||
*
|
||||
* @see Thread#run()
|
||||
*//*
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (homeBlock != null) {
|
||||
town.setHomeBlock(homeBlock);
|
||||
town.setSpawn(townSpawn);
|
||||
}
|
||||
|
||||
// LMFAO Who cares about performance anyways
|
||||
if (Siege.this.side1AreAttackers) {
|
||||
Siege.this.attackerPlayers = Siege.this.war.getSide1().getPlayers();
|
||||
Siege.this.defenderPlayers = Siege.this.war.getSide2().getPlayers();
|
||||
} else {
|
||||
Siege.this.attackerPlayers = Siege.this.war.getSide2().getPlayers();
|
||||
Siege.this.defenderPlayers = Siege.this.war.getSide1().getPlayers();
|
||||
}
|
||||
|
||||
if (Siege.this.siegeTicks >= MAX_SIEGE_TICKS) {
|
||||
|
||||
Bukkit.getServer().getScheduler().cancelTask(Siege.this.bukkitId[0]);
|
||||
|
||||
Siege.this.war.getSieges().remove(Siege.this);
|
||||
if (Siege.this.attackerPoints > Siege.this.defenderPoints) {
|
||||
Siege.this.attackersWin(Siege.this.siegeLeader);
|
||||
} else {
|
||||
Siege.this.defendersWin();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
boolean attackersAreOnHomeBlock = false;
|
||||
boolean defendersAreOnHomeBlock = false;
|
||||
siegeTicks = siegeTicks + 200;
|
||||
for (final Player pl : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
if (pl != null) {
|
||||
WorldCoord wc = WorldCoord.parseWorldCoord(pl);
|
||||
if (wc.getTownBlock().getTown().equals(town)) {
|
||||
if (town.getHomeBlockOrNull() != null) {
|
||||
if (town.getHomeBlockOrNull().getWorldCoord().equals(wc)) {
|
||||
if (!pl.isDead()) {
|
||||
if ((Math.abs(pl.getLocation().getBlockY() - townSpawn.getBlockY())) < 10) {
|
||||
attackersAreOnHomeBlock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NotRegisteredException ignored) {
|
||||
// Main.warLogger.log(UtilsChat.getPrefix() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
|
||||
}
|
||||
}
|
||||
for (final Player pl : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
if (pl != null) {
|
||||
WorldCoord wc = WorldCoord.parseWorldCoord(pl);
|
||||
if (wc.getTownBlock().getTown().equals(town)) {
|
||||
if (town.getHomeBlockOrNull() != null) {
|
||||
if (town.getHomeBlockOrNull().getWorldCoord().equals(wc)) {
|
||||
if (!pl.isDead()) {
|
||||
if ((Math.abs(pl.getLocation().getBlockY() - townSpawn.getBlockY())) <= 10) {
|
||||
defendersAreOnHomeBlock = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NotRegisteredException ignored) {
|
||||
// Main.warLogger.log(UtilsChat.getPrefix() + "Attempting to look for town at " + WorldCoord.parseWorldCoord(pl));
|
||||
}
|
||||
}
|
||||
if (attackersAreOnHomeBlock && defendersAreOnHomeBlock) { // Contested
|
||||
|
||||
if (this.homeBlockControl != 1) {
|
||||
for (final Player pl : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
for (final Player pl : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "HomeBlock at " + Siege.this.town.getName() + " contested!");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.homeBlockControl = 1;
|
||||
|
||||
} else if (attackersAreOnHomeBlock && !defendersAreOnHomeBlock) { // Attackers
|
||||
|
||||
if (this.homeBlockControl != 2) {
|
||||
for (final Player pl : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "Attackers have captured the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
for (final Player pl : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "Attackers have captured the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Attacker Points per second");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.homeBlockControl = 2;
|
||||
Siege.this.addPointsToAttackers(10);
|
||||
|
||||
} else { // Defenders / None
|
||||
|
||||
if (this.homeBlockControl != 3) {
|
||||
for (final Player pl : Siege.this.attackerPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "Defenders retain control of the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Defender Points per second");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
for (final Player pl : Siege.this.defenderPlayers) {
|
||||
try {
|
||||
pl.sendMessage(UtilsChat.getPrefix()
|
||||
+ "Defenders retain control of the HomeBlock at "
|
||||
+ Siege.this.town.getName() + "! +1 Defender Points per second");
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Siege.this.addPointsToDefenders(10);
|
||||
this.homeBlockControl = 3;
|
||||
|
||||
}
|
||||
|
||||
if (Siege.this.siegeTicks % 6000 == 0) { // Updates every 5 minutes
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "Report on the siege of "
|
||||
+ Siege.this.town.getName() + ":");
|
||||
Bukkit.broadcastMessage(
|
||||
"Attacker Points - " + Siege.this.attackerPoints);
|
||||
Bukkit.broadcastMessage(
|
||||
"Defender Points - " + Siege.this.defenderPoints);
|
||||
}
|
||||
|
||||
if (siegeTicks % 1200 == 0) { // Saves every minute
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
refreshDisplayBar();
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,4 +0,0 @@
|
||||
package me.ShermansWorld.AlathranWars.events.battle;
|
||||
|
||||
public class PreSiegeEndEvent {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package me.ShermansWorld.AlathranWars.events.battle;
|
||||
|
||||
public class PreSiegeStartEvent {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package me.ShermansWorld.AlathranWars.events.battle;
|
||||
|
||||
public class SiegeEndEvent {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package me.ShermansWorld.AlathranWars.events.battle;
|
||||
|
||||
public class SiegeStartEvent {
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user