refactor: wip update 6 (fixed 1.19.4)

This commit is contained in:
darksaid98 committed 2023-07-17 04:31:26 +02:00
1 parent 1c751decb3
commit 03cb3a4d1c
23 files changed
+146 -185

No files matched your search

+2 -2
View File
@@ -7,7 +7,7 @@ plugins {
} }
group = "com.github.alathra.AlathranWars" group = "com.github.alathra.AlathranWars"
version = "3.0.0-SNAPSHOT" version = "3.0.1-SNAPSHOT"
description = "" description = ""
java { java {
@@ -47,7 +47,7 @@ repositories {
dependencies { dependencies {
implementation("org.jetbrains:annotations:24.0.1") implementation("org.jetbrains:annotations:24.0.1")
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
implementation("com.github.milkdrinkers:simplixstorage:3.2.7") implementation("com.github.milkdrinkers:simplixstorage:3.2.7")
implementation("com.github.milkdrinkers:colorparser:1.0.7") implementation("com.github.milkdrinkers:colorparser:1.0.7")
@@ -7,7 +7,6 @@ import com.github.alathra.AlathranWars.holder.WarManager;
import com.github.alathra.AlathranWars.hooks.HookManager; import com.github.alathra.AlathranWars.hooks.HookManager;
import com.github.alathra.AlathranWars.items.WarItemRegistry; import com.github.alathra.AlathranWars.items.WarItemRegistry;
import com.github.alathra.AlathranWars.listeners.ListenerHandler; import com.github.alathra.AlathranWars.listeners.ListenerHandler;
import com.github.alathra.AlathranWars.utility.DB;
import com.github.alathra.AlathranWars.utility.SQLQueries; import com.github.alathra.AlathranWars.utility.SQLQueries;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
@@ -63,7 +62,6 @@ public class Main extends JavaPlugin {
} }
warLogger = new AlathranWarsLogger(); warLogger = new AlathranWarsLogger();
}*/ }*/
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private boolean setupEconomy() { private boolean setupEconomy() {
if (this.getServer().getPluginManager().getPlugin("Vault") == null) { if (this.getServer().getPluginManager().getPlugin("Vault") == null) {
@@ -2,6 +2,8 @@ package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.Main; import com.github.alathra.AlathranWars.Main;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.enums.AdminCommandFailEnum;
import com.github.alathra.AlathranWars.items.WarItemRegistry; import com.github.alathra.AlathranWars.items.WarItemRegistry;
import com.github.alathra.AlathranWars.utility.UtilsChat; import com.github.alathra.AlathranWars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser; import com.github.milkdrinkers.colorparser.ColorParser;
@@ -11,8 +13,6 @@ import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.arguments.*; import dev.jorel.commandapi.arguments.*;
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
import dev.jorel.commandapi.executors.CommandArguments; import dev.jorel.commandapi.executors.CommandArguments;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.enums.AdminCommandFailEnum;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -954,7 +954,7 @@ public class AdminCommand {
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Invalid action.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Invalid action.").build());
if (!(args.get("war") instanceof final War war)) if (!(args.get("war") instanceof final War war))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").build());
if (!(args.get("side") instanceof final Side side)) if (!(args.get("side") instanceof final Side side))
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The side does not exist.").build()); throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The side does not exist.").build());
@@ -3,6 +3,7 @@ package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.Main; import com.github.alathra.AlathranWars.Main;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.holder.WarManager; import com.github.alathra.AlathranWars.holder.WarManager;
import com.github.alathra.AlathranWars.hooks.TownyHook; import com.github.alathra.AlathranWars.hooks.TownyHook;
import com.github.alathra.AlathranWars.items.WarItemRegistry; import com.github.alathra.AlathranWars.items.WarItemRegistry;
@@ -17,13 +18,14 @@ import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.ArgumentSuggestions; import dev.jorel.commandapi.arguments.ArgumentSuggestions;
import dev.jorel.commandapi.arguments.CustomArgument; import dev.jorel.commandapi.arguments.CustomArgument;
import dev.jorel.commandapi.arguments.StringArgument; import dev.jorel.commandapi.arguments.StringArgument;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Statistic; import org.bukkit.Statistic;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -260,15 +262,15 @@ public class CommandUtil {
return nationNames; return nationNames;
final List<String> removeNames = Stream.concat( // Create a list of all nations & towns in war final List<String> removeNames = Stream.concat( // Create a list of all nations & towns in war
war.getNations().stream().map(Nation::getName), war.getNations().stream().map(Nation::getName),
Stream.concat(
war.getSurrenderedNations().stream().map(Nation::getName),
Stream.concat( Stream.concat(
war.getSurrenderedNations().stream().map(Nation::getName), war.getTowns().stream().map(Town::getName),
Stream.concat( war.getSurrenderedTowns().stream().map(Town::getName)
war.getTowns().stream().map(Town::getName),
war.getSurrenderedTowns().stream().map(Town::getName)
)
) )
).toList(); )
).toList();
nationNames.removeAll(removeNames); nationNames.removeAll(removeNames);
@@ -440,7 +442,7 @@ public class CommandUtil {
return side; return side;
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> { }).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
if (!(info.previousArgs().get(warNodeName) instanceof War war)) if (!(info.previousArgs().get(warNodeName) instanceof War war))
return Collections.emptyList(); return Collections.emptyList();
final List<String> sideNames = new ArrayList<>(); final List<String> sideNames = new ArrayList<>();
@@ -3,7 +3,6 @@ package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; 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.enums.BattleTeam;
import com.github.alathra.AlathranWars.holder.WarManager; import com.github.alathra.AlathranWars.holder.WarManager;
import com.github.alathra.AlathranWars.utility.UtilsChat; import com.github.alathra.AlathranWars.utility.UtilsChat;
@@ -19,7 +18,6 @@ import dev.jorel.commandapi.executors.CommandArguments;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
@@ -204,14 +202,15 @@ public class SiegeCommand {
// Attacking own side // Attacking own side
if (side.isTownOnSide(town)) { if (side.isTownOnSide(town)) {
siegeOwner.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You cannot attack your own towns.").build()); 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()); if (admin)
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You cannot attack your own towns.").build());
return; return;
} }
Siege siege = new Siege(war, town, siegeOwner); Siege siege = new Siege(war, town, siegeOwner);
war.addSiege(siege); war.addSiege(siege);
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide() + "!").build()); Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + siege.getTown() + " has been put to siege by " + siege.getAttackerSide().getName() + "!").build());
if (admin) if (admin)
sender.sendMessage(new ColorParser("<red>Forcefully started siege from the console.").build()); sender.sendMessage(new ColorParser("<red>Forcefully started siege from the console.").build());
@@ -295,10 +294,10 @@ public class SiegeCommand {
sender.sendMessage( sender.sendMessage(
new ColorParser( new ColorParser(
color + siege.getTown().getName() + " <gray>- Progress: <progress> - Time: <time>min" color + siege.getTown().getName() + " <gray>- Progress: <progress> - Time: <time>min"
) )
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(siege.getSiegeProgressPercentage() * 100)) .parseMinimessagePlaceholder("progress", "%.0f%%".formatted(siege.getSiegeProgressPercentage() * 100))
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , siege.getEndTime()).toMinutes())) .parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), siege.getEndTime()).toMinutes()))
.build() .build()
); );
// sender.sendMessage(new ColorParser(war.getName() + " - " + color + siege.getTown().getName().toLowerCase()).build()); // TODO Fix info // sender.sendMessage(new ColorParser(war.getName() + " - " + color + siege.getTown().getName().toLowerCase()).build()); // TODO Fix info
@@ -1,8 +1,10 @@
package com.github.alathra.AlathranWars.commands; package com.github.alathra.AlathranWars.commands;
import com.github.alathra.AlathranWars.conflict.Side; 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.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.BattleSide; import com.github.alathra.AlathranWars.enums.BattleSide;
import com.github.alathra.AlathranWars.holder.WarManager;
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener; import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
import com.github.alathra.AlathranWars.utility.UtilsChat; import com.github.alathra.AlathranWars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser; import com.github.milkdrinkers.colorparser.ColorParser;
@@ -17,8 +19,6 @@ import dev.jorel.commandapi.arguments.GreedyStringArgument;
import dev.jorel.commandapi.arguments.PlayerArgument; import dev.jorel.commandapi.arguments.PlayerArgument;
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
import dev.jorel.commandapi.executors.CommandArguments; import dev.jorel.commandapi.executors.CommandArguments;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.holder.WarManager;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -80,7 +80,7 @@ public class WarCommand {
.withArguments( .withArguments(
CommandUtil.warWarArgument("war", false, true, ""), CommandUtil.warWarArgument("war", false, true, ""),
CommandUtil.warSideCreateArgument("side", "war", false, true, ""), CommandUtil.warSideCreateArgument("side", "war", false, true, ""),
new PlayerArgument("player").setOptional(true).withPermission("AlathranWars.admin") new PlayerArgument("player").setOptional(true).withPermission("AlathranWars.admin.join")
) )
.executesPlayer((Player p, CommandArguments args) -> warJoinPlayer(p, args, false)); .executesPlayer((Player p, CommandArguments args) -> warJoinPlayer(p, args, false));
} }
@@ -1,13 +1,12 @@
package com.github.alathra.AlathranWars.conflict; package com.github.alathra.AlathranWars.conflict;
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.github.alathra.AlathranWars.listeners.war.PlayerJoinListener; import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -21,25 +20,22 @@ import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Side { public class Side {
private static final Duration SIEGE_COOLDOWN = Duration.ofMinutes(120);
private static final Duration RAID_COOLDOWN = Duration.ofMinutes(30);
private final UUID warUUID; private final UUID warUUID;
private final UUID uuid; private final UUID uuid;
private final BattleSide side; private final BattleSide side;
private final BattleTeam team; private final BattleTeam team;
private final String name; // A town name private final String name; // A town name
// TODO Use Town & Nation UUID's when saving to config // TODO Use Town & Nation UUID's when saving to config
private final Town town; // The initiating town or capital of the nation private final Town town; // The initiating town or capital of the nation
private final Set<Town> towns; // A list of participating Towns private final Set<Town> towns; // A list of participating Towns
private final Set<Nation> nations; // A list of participating Nations 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<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 private final Set<Player> players; // A list of the players who are currently online
private final Set<Town> surrenderedTowns; private final Set<Town> surrenderedTowns;
private final Set<Nation> surrenderedNations; private final Set<Nation> surrenderedNations;
private final Set<UUID> surrenderedPlayersIncludingOffline; private final Set<UUID> surrenderedPlayersIncludingOffline;
private static final Duration SIEGE_COOLDOWN = Duration.ofMinutes(120);
private static final Duration RAID_COOLDOWN = Duration.ofMinutes(30);
private Instant siegeGrace = Instant.now().minus(SIEGE_COOLDOWN); // The time after which this side can be besieged 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 Instant raidGrace = Instant.now().minus(RAID_COOLDOWN); // The time after which this side can be raided
@@ -1,6 +1,10 @@
package com.github.alathra.AlathranWars.conflict; package com.github.alathra.AlathranWars.conflict;
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid; import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
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.github.alathra.AlathranWars.listeners.war.PlayerJoinListener; import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
import com.github.alathra.AlathranWars.utility.SQLQueries; import com.github.alathra.AlathranWars.utility.SQLQueries;
import com.github.alathra.AlathranWars.utility.UUIDUtil; import com.github.alathra.AlathranWars.utility.UUIDUtil;
@@ -10,10 +14,6 @@ import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import dev.jorel.commandapi.CommandAPIBukkit; import dev.jorel.commandapi.CommandAPIBukkit;
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -71,9 +71,9 @@ public class War extends Conflict {
/** /**
* Instantiates a new New war. * Instantiates a new New war.
* *
* @param label the name * @param label the name
* @param aggressor the side 1 * @param aggressor the side 1
* @param victim the side 2 * @param victim the side 2
*/ */
public War(final String label, Town aggressor, Town victim) throws WrapperCommandSyntaxException { public War(final String label, Town aggressor, Town victim) throws WrapperCommandSyntaxException {
this.uuid = UUIDUtil.generateWarUUID(); this.uuid = UUIDUtil.generateWarUUID();
@@ -338,28 +338,28 @@ public class War extends Conflict {
@NotNull @NotNull
public Set<Player> getPlayers() { public Set<Player> getPlayers() {
return Stream.concat( return Stream.concat(
getSide1().getPlayers().stream(), getSide1().getPlayers().stream(),
getSide2().getPlayers().stream() getSide2().getPlayers().stream()
) )
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
@NotNull @NotNull
public Set<OfflinePlayer> getPlayersIncludingOffline() { public Set<OfflinePlayer> getPlayersIncludingOffline() {
return Stream.concat( return Stream.concat(
getSide1().getPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer), getSide1().getPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer),
getSide2().getPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer) getSide2().getPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer)
) )
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
@NotNull @NotNull
public Set<OfflinePlayer> getSurrenderedPlayers() { public Set<OfflinePlayer> getSurrenderedPlayers() {
return Stream.concat( return Stream.concat(
getSide1().getSurrenderedPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer), getSide1().getSurrenderedPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer),
getSide2().getSurrenderedPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer) getSide2().getSurrenderedPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer)
) )
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
public boolean isPlayerInWar(Player p) { public boolean isPlayerInWar(Player p) {
@@ -33,7 +33,7 @@ import java.util.stream.Collectors;
public class Siege extends Battle { public class Siege extends Battle {
public static final int MAX_SIEGE_TICKS = 72000; // 60 minute tick constant public static final int MAX_SIEGE_TICKS = 72000; // 60 minute tick constant
public static final Duration SIEGE_DURATION = Duration.ofMinutes(60); 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_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 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_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 Duration ATTACKERS_MUST_TOUCH_REVERT = Duration.ofMinutes(2); // If point is not touched in this much time, siege progress reverts
@@ -107,7 +107,7 @@ public class Siege extends Battle {
war.removeSiege(this); war.removeSiege(this);
} }
public void attackersWin(final OfflinePlayer siegeLeader) { public void attackersWin(final OfflinePlayer siegeLeader) {
final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId()); final Resident resident = TownyAPI.getInstance().getResident(siegeLeader.getUniqueId());
Nation nation = null; Nation nation = null;
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The attackers have won the siege of " + town.getName() + "!").build()); Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The attackers have won the siege of " + town.getName() + "!").build());
@@ -199,14 +199,14 @@ public class Siege extends Battle {
return siegeProgress; return siegeProgress;
} }
public float getSiegeProgressPercentage() {
return (getSiegeProgress() * 1.0f) / MAX_SIEGE_PROGRESS;
}
public void setSiegeProgress(int siegeProgress) { public void setSiegeProgress(int siegeProgress) {
this.siegeProgress = siegeProgress; this.siegeProgress = siegeProgress;
} }
public float getSiegeProgressPercentage() {
return (getSiegeProgress() * 1.0f) / MAX_SIEGE_PROGRESS;
}
@NotNull @NotNull
public War getWar() { public War getWar() {
return war; return war;
@@ -241,6 +241,8 @@ public class Siege extends Battle {
return side1AreAttackers ? war.getSide2() : war.getSide1(); return side1AreAttackers ? war.getSide2() : war.getSide1();
} }
// SECTION Display Bar
public void updateDisplayBar(CaptureProgressDirection progressDirection) { public void updateDisplayBar(CaptureProgressDirection progressDirection) {
if (activeBossBar == null) if (activeBossBar == null)
createNewDisplayBar(); createNewDisplayBar();
@@ -249,7 +251,7 @@ public class Siege extends Battle {
}*/ }*/
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
activeBossBar.removeViewer(p); p.hideBossBar(activeBossBar);
} }
for (Player p : this.getAttackers()) { for (Player p : this.getAttackers()) {
@@ -290,7 +292,7 @@ public class Siege extends Battle {
activeBossBar.name( activeBossBar.name(
new ColorParser("<gray>Capture Progress: %s<progress> <gray>Time: %s<time>min".formatted(color, color)) new ColorParser("<gray>Capture Progress: %s<progress> <gray>Time: %s<time>min".formatted(color, color))
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(getSiegeProgressPercentage() * 100)) .parseMinimessagePlaceholder("progress", "%.0f%%".formatted(getSiegeProgressPercentage() * 100))
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , getEndTime()).toMinutes())) .parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), getEndTime()).toMinutes()))
.build() .build()
); );
} else { } else {
@@ -304,7 +306,7 @@ public class Siege extends Battle {
public void createNewDisplayBar() { public void createNewDisplayBar() {
final Component text = new ColorParser("<gray>Capture Progress: <yellow><progress> <gray>Time: <yellow><time>min") final Component text = new ColorParser("<gray>Capture Progress: <yellow><progress> <gray>Time: <yellow><time>min")
.parseMinimessagePlaceholder("progress", "%.0f%%".formatted(getSiegeProgressPercentage() * 100)) .parseMinimessagePlaceholder("progress", "%.0f%%".formatted(getSiegeProgressPercentage() * 100))
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , getEndTime()).toMinutesPart())) .parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), getEndTime()).toMinutesPart()))
.build(); .build();
this.activeBossBar = BossBar.bossBar(text, 0, BossBar.Color.YELLOW, BossBar.Overlay.NOTCHED_10); this.activeBossBar = BossBar.bossBar(text, 0, BossBar.Color.YELLOW, BossBar.Overlay.NOTCHED_10);
@@ -313,7 +315,7 @@ public class Siege extends Battle {
public void deleteDisplayBar() { public void deleteDisplayBar() {
if (activeBossBar != null) { if (activeBossBar != null) {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
activeBossBar.removeViewer(p); p.hideBossBar(activeBossBar);
} }
activeBossBar = null; activeBossBar = null;
@@ -346,7 +348,7 @@ public class Siege extends Battle {
return getUUID().equals(siege.getUUID()); return getUUID().equals(siege.getUUID());
} }
// Accessors & Getters // SECTION Accessors & Getters
@Nullable @Nullable
public TownBlock getHomeBlock() { public TownBlock getHomeBlock() {
@@ -367,7 +369,7 @@ public class Siege extends Battle {
} }
public boolean getSide1AreAttackers() { public boolean getSide1AreAttackers() {
return this.side1AreAttackers; return side1AreAttackers;
} }
public void setSide1AreAttackers(final boolean side1AreAttackers) { public void setSide1AreAttackers(final boolean side1AreAttackers) {
@@ -376,22 +378,22 @@ public class Siege extends Battle {
@NotNull @NotNull
public Set<Player> getAttackers() { public Set<Player> getAttackers() {
return this.attackers; return attackers;
} }
@NotNull @NotNull
public Set<Player> getDefenders() { public Set<Player> getDefenders() {
return this.defenders; return defenders;
} }
@NotNull @NotNull
public Set<Player> getAttackerPlayers() { public Set<Player> getAttackerPlayers() {
return this.attackerPlayers; return attackerPlayers;
} }
@NotNull @NotNull
public Set<Player> getDefenderPlayers() { public Set<Player> getDefenderPlayers() {
return this.defenderPlayers; return defenderPlayers;
} }
@NotNull @NotNull
@@ -404,21 +406,21 @@ public class Siege extends Battle {
} }
@NotNull @NotNull
public String getName() { public String getName() { // TODO Make better siegenames
return this.getWar().getName() + "-" + this.getTown(); return getWar().getName() + "-" + getTown();
} }
// SECTION Time management // SECTION Time management
public void setEndTime(Instant time) {
endTime = time;
}
@NotNull @NotNull
public Instant getEndTime() { public Instant getEndTime() {
return endTime; return endTime;
} }
public void setEndTime(Instant time) {
endTime = time;
}
// SECTION Player management // SECTION Player management
public boolean isPlayerInSiege(UUID uuid) { public boolean isPlayerInSiege(UUID uuid) {
@@ -525,14 +527,18 @@ public class Siege extends Battle {
public void calculateBattlefieldPlayers(Location location) { public void calculateBattlefieldPlayers(Location location) {
final Set<Player> attackersOnBattlefield = attackerPlayers.stream() final Set<Player> attackersOnBattlefield = attackerPlayers.stream()
.filter(p -> p.isOnline() && location.distance(p.getLocation()) < BATTLEFIELD_RANGE) .filter(OfflinePlayer::isOnline)
.filter(p -> location.getWorld().equals(p.getLocation().getWorld()))
.filter(p -> location.distance(p.getLocation()) < BATTLEFIELD_RANGE)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
attackers.clear(); attackers.clear();
attackers.addAll(attackersOnBattlefield); attackers.addAll(attackersOnBattlefield);
final Set<Player> defendersOnBattlefield = defenderPlayers.stream() final Set<Player> defendersOnBattlefield = defenderPlayers.stream()
.filter(p -> p.isOnline() && location.distance(p.getLocation()) < BATTLEFIELD_RANGE) .filter(OfflinePlayer::isOnline)
.filter(p -> location.getWorld().equals(p.getLocation().getWorld()))
.filter(p -> location.distance(p.getLocation()) < BATTLEFIELD_RANGE)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
defenders.clear(); defenders.clear();
@@ -16,13 +16,16 @@ import java.time.Instant;
import static com.github.alathra.AlathranWars.conflict.battle.siege.Siege.*; import static com.github.alathra.AlathranWars.conflict.battle.siege.Siege.*;
public class SiegeRunnable implements Runnable{ public class SiegeRunnable implements Runnable {
// Settings
private static final Duration ANNOUNCEMENT_COOLDOWN = Duration.ofMinutes(5); private static final Duration ANNOUNCEMENT_COOLDOWN = Duration.ofMinutes(5);
private final static int CAPTURE_MAX_ELEVATION = 10;
private final static int CAPTURE_RANGE = 10;
private final Siege siege;
// Variables
private CaptureProgressDirection oldProgressDirection = CaptureProgressDirection.NONE; private CaptureProgressDirection oldProgressDirection = CaptureProgressDirection.NONE;
private Instant nextAnnouncement; private Instant nextAnnouncement;
private int taskId = -1; private int taskId = -1;
private final Siege siege;
private Laser beam; private Laser beam;
/** /**
@@ -48,7 +51,7 @@ public class SiegeRunnable implements Runnable{
/** /**
* Resume a siege at tick * Resume a siege at tick
* *
* @param siege the siege * @param siege the siege
* @param siegeProgress the siege ticks * @param siegeProgress the siege ticks
*/ */
public SiegeRunnable(Siege siege, int siegeProgress) { public SiegeRunnable(Siege siege, int siegeProgress) {
@@ -96,13 +99,13 @@ public class SiegeRunnable implements Runnable{
siege.calculateBattlefieldPlayers(townSpawn.toCenterLocation()); siege.calculateBattlefieldPlayers(townSpawn.toCenterLocation());
// Progress the siege // Progress the siege
final CaptureProgressDirection progressDirection = getSiegeProgressDirection(town, townSpawn); final CaptureProgressDirection progressDirection = getSiegeProgressDirection(townSpawn);
// Siege is past max time or attackers haven't touched in time, defenders won // Siege is past max time or attackers haven't touched in time, defenders won
if ( if (
!progressDirection.equals(CaptureProgressDirection.UP) && !progressDirection.equals(CaptureProgressDirection.UP) &&
(Instant.now().isAfter(siege.getEndTime()) || (Instant.now().isAfter(siege.getEndTime()) ||
Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_END))) Instant.now().isAfter(siege.getLastTouched().plus(ATTACKERS_MUST_TOUCH_END)))
) { ) {
cancel(); cancel();
siege.defendersWin(); siege.defendersWin();
@@ -163,17 +166,6 @@ public class SiegeRunnable implements Runnable{
} }
} }
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)) { if (Instant.now().isAfter(nextAnnouncement)) {
nextAnnouncement = Instant.now().plus(ANNOUNCEMENT_COOLDOWN); nextAnnouncement = Instant.now().plus(ANNOUNCEMENT_COOLDOWN);
@@ -181,52 +173,42 @@ public class SiegeRunnable implements Runnable{
siege.getAttackers().forEach(p -> p.sendMessage( siege.getAttackers().forEach(p -> p.sendMessage(
new ColorParser("<prefix>Siege time remaining: <time> minutes.") new ColorParser("<prefix>Siege time remaining: <time> minutes.")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix()) .parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , siege.getEndTime()).toMinutesPart())) .parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), siege.getEndTime()).toMinutesPart()))
.build() .build()
)); ));
siege.getDefenders().forEach(p -> p.sendMessage( siege.getDefenders().forEach(p -> p.sendMessage(
new ColorParser("<prefix>Siege time remaining: <time> minutes.") new ColorParser("<prefix>Siege time remaining: <time> minutes.")
.parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix()) .parseMinimessagePlaceholder("prefix", UtilsChat.getPrefix())
.parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now() , siege.getEndTime()).toMinutesPart())) .parseMinimessagePlaceholder("time", String.valueOf(Duration.between(Instant.now(), siege.getEndTime()).toMinutesPart()))
.build() .build()
)); ));
} }
siege.updateDisplayBar(progressDirection); siege.updateDisplayBar(progressDirection);
oldProgressDirection = progressDirection;
} }
private final static int CAPTURE_MAX_ELEVATION = 10; public int getPeopleOnPoint(Location townSpawn, BattleSide battleSide) {
private final static int CAPTURE_RANGE = 10;
public int getPeopleOnPoint(Town town, Location townSpawn, BattleSide battleSide) {
int onPoint = 0; int onPoint = 0;
for (final Player p : (battleSide.equals(BattleSide.ATTACKER) ? siege.getAttackers() : siege.getDefenders())) { for (final Player p : (battleSide.equals(BattleSide.ATTACKER) ? siege.getAttackers() : siege.getDefenders())) {
// WorldCoord wc = WorldCoord.parseWorldCoord(p); if (p.isDead())
// if (!Objects.equals(wc.getTownOrNull(), town)) continue;
// continue;
// @Nullable TownBlock homeBlock = town.getHomeBlockOrNull(); if (townSpawn.getWorld().equals(p.getLocation().getWorld()))
// if (homeBlock == null)
// continue;
if (/*!homeBlock.getWorldCoord().equals(wc) || */p.isDead())
continue; continue;
if (townSpawn.distance(p.getLocation()) <= CAPTURE_RANGE) { if (townSpawn.distance(p.getLocation()) <= CAPTURE_RANGE) {
onPoint += 1; onPoint += 1;
} }
// if ((Math.abs(p.getLocation().getBlockY() - townSpawn.getBlockY())) < CAPTURE_MAX_ELEVATION) {
// onPoint += 1;
// }
} }
return onPoint; return onPoint;
} }
public CaptureProgressDirection getSiegeProgressDirection(Town town, Location townSpawn) { public CaptureProgressDirection getSiegeProgressDirection(Location townSpawn) {
int attackersOnPoint = getPeopleOnPoint(town, townSpawn, BattleSide.ATTACKER); int attackersOnPoint = getPeopleOnPoint(townSpawn, BattleSide.ATTACKER);
int defendersOnPoint = getPeopleOnPoint(town, townSpawn, BattleSide.DEFENDER); int defendersOnPoint = getPeopleOnPoint(townSpawn, BattleSide.DEFENDER);
final boolean attackersAreOnPoint = attackersOnPoint > 0; final boolean attackersAreOnPoint = attackersOnPoint > 0;
final boolean defendersAreOnPoint = defendersOnPoint > 0; final boolean defendersAreOnPoint = defendersOnPoint > 0;
@@ -263,10 +245,8 @@ public class SiegeRunnable implements Runnable{
Location loc1 = siege.getTownSpawn(); Location loc1 = siege.getTownSpawn();
Location loc2 = new Location(loc1.getWorld(), loc1.getX(), loc1.getY() + 350D, loc1.getZ()); Location loc2 = new Location(loc1.getWorld(), loc1.getX(), loc1.getY() + 350D, loc1.getZ());
beam = new Laser.CrystalLaser(loc1, loc2, -1, BATTLEFIELD_RANGE); beam = new Laser.CrystalLaser(loc1, loc2, -1, -1);
beam.start(Main.getInstance());
if (beam != null)
beam.start(Main.getInstance());
} catch (ReflectiveOperationException ignored) { } catch (ReflectiveOperationException ignored) {
} }
} }
@@ -6,7 +6,6 @@ import com.github.alathra.AlathranWars.utility.SQLQueries;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.mariadb.jdbc.MariaDbDataSource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -15,7 +14,7 @@ import java.sql.SQLException;
public class DataManager { public class DataManager {
private Main instance; private Main instance;
// private static DataManager instance; // private static DataManager instance;
private HikariConfig hikariConfig; private HikariConfig hikariConfig;
private HikariDataSource hikariDataSource; private HikariDataSource hikariDataSource;
@@ -3,10 +3,10 @@ package com.github.alathra.AlathranWars.holder;
import com.github.alathra.AlathranWars.conflict.Side; import com.github.alathra.AlathranWars.conflict.Side;
import com.github.alathra.AlathranWars.conflict.War; import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.conflict.battle.raid.Raid; import com.github.alathra.AlathranWars.conflict.battle.raid.Raid;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.utility.SQLQueries; import com.github.alathra.AlathranWars.utility.SQLQueries;
import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.hooks; package com.github.alathra.AlathranWars.hooks;
import com.github.alathra.AlathranWars.conflict.War;
import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener; import com.github.alathra.AlathranWars.listeners.war.PlayerJoinListener;
import com.github.alathra.AlathranWars.utility.UtilsChat; 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.TabAPI;
import me.neznamy.tab.api.TabPlayer; import me.neznamy.tab.api.TabPlayer;
import me.neznamy.tab.api.event.EventBus; import me.neznamy.tab.api.event.EventBus;
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.items.item; package com.github.alathra.AlathranWars.items.item;
import com.github.alathra.AlathranWars.Main; import com.github.alathra.AlathranWars.Main;
import com.github.alathra.AlathranWars.items.WarItemRegistry;
import com.github.alathra.AlathranWars.items.IWarItem; import com.github.alathra.AlathranWars.items.IWarItem;
import com.github.alathra.AlathranWars.items.WarItemRegistry;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Tag; import org.bukkit.Tag;
@@ -1,9 +1,9 @@
package com.github.alathra.AlathranWars.listeners; package com.github.alathra.AlathranWars.listeners;
import com.github.alathra.AlathranWars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.holder.WarManager; import com.github.alathra.AlathranWars.holder.WarManager;
import com.github.alathra.AlathranWars.utility.UtilsChat;
import com.github.milkdrinkers.colorparser.ColorParser;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -1,14 +1,9 @@
package com.github.alathra.AlathranWars.listeners; package com.github.alathra.AlathranWars.listeners;
import com.github.alathra.AlathranWars.utility.Utils; 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.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.WorldCoord; 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.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -33,7 +28,7 @@ public final class KillsListener implements Listener {
boolean playerCloseToHomeBlockRaid = false; boolean playerCloseToHomeBlockRaid = false;
// try { // try {
//OldRaid logic //OldRaid logic
/*for (final OldRaid oldRaid : RaidData.getRaids()) { /*for (final OldRaid oldRaid : RaidData.getRaids()) {
final int homeBlockXCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getX() * 16; final int homeBlockXCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
final int homeBlockZCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16; final int homeBlockZCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
@@ -1,13 +1,13 @@
package com.github.alathra.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 com.github.alathra.AlathranWars.Main; import com.github.alathra.AlathranWars.Main;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege; import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.holder.WarManager; import com.github.alathra.AlathranWars.holder.WarManager;
import com.github.alathra.AlathranWars.items.WarItemRegistry; 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.TownBlock;
import com.palmergames.bukkit.towny.object.WorldCoord;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@@ -1,10 +1,10 @@
package com.github.alathra.AlathranWars.listeners.siege; package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.holder.WarManager;
import com.github.milkdrinkers.colorparser.ColorParser; import com.github.milkdrinkers.colorparser.ColorParser;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.WorldCoord; 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.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -1,19 +1,9 @@
package com.github.alathra.AlathranWars.listeners.siege; package com.github.alathra.AlathranWars.listeners.siege;
import com.github.alathra.AlathranWars.utility.Utils; 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.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.jetbrains.annotations.Nullable;
public class PlayerDeathListener implements Listener { public class PlayerDeathListener implements Listener {
private final static int BATTLE_RADIUS = 300; private final static int BATTLE_RADIUS = 300;
@@ -90,7 +80,7 @@ public class PlayerDeathListener implements Listener {
* They don't lose items from death. * They don't lose items from death.
* *
* @param victim killed player * @param victim killed player
* @param e event * @param e event
*/ */
private void siegeKill(Player victim, PlayerDeathEvent e) { private void siegeKill(Player victim, PlayerDeathEvent e) {
//Helper //Helper
@@ -108,7 +98,7 @@ public class PlayerDeathListener implements Listener {
* They don't lose items from death. * They don't lose items from death.
* *
* @param victim killed player * @param victim killed player
* @param e event * @param e event
*/ */
private void oocKill(Player victim, PlayerDeathEvent e) { private void oocKill(Player victim, PlayerDeathEvent e) {
//Siege specific //Siege specific
@@ -1,8 +1,8 @@
package com.github.alathra.AlathranWars.listeners.siege; 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.conflict.battle.siege.Siege;
import com.github.alathra.AlathranWars.enums.BattleSide; import com.github.alathra.AlathranWars.enums.BattleSide;
import com.github.alathra.AlathranWars.holder.WarManager;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -1,7 +1,5 @@
package com.github.alathra.AlathranWars.listeners.war; package com.github.alathra.AlathranWars.listeners.war;
import com.palmergames.bukkit.towny.event.nation.NationKingChangeEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
public class NationListener implements Listener { public class NationListener implements Listener {
@@ -146,7 +146,7 @@ public class SQLQueries {
try ( try (
Connection con = DB.get(); Connection con = DB.get();
PreparedStatement warStatement = con.prepareStatement("INSERT INTO `wars_list` (`uuid`, `name`, `label`, `side1`, `side2`) VALUES (?, ?, ?, ?, ?) " PreparedStatement warStatement = con.prepareStatement("INSERT INTO `wars_list` (`uuid`, `name`, `label`, `side1`, `side2`) VALUES (?, ?, ?, ?, ?) "
+ "ON DUPLICATE KEY UPDATE `name` = ?, `label` = ?, `side1` = ?, `side2` = ?") + "ON DUPLICATE KEY UPDATE `name` = ?, `label` = ?, `side1` = ?, `side2` = ?")
) { ) {
// Save wars // Save wars
for (War war : WarManager.getInstance().getWars()) { for (War war : WarManager.getInstance().getWars()) {
@@ -184,8 +184,7 @@ public class SQLQueries {
try ( try (
PreparedStatement sideStatement = con.prepareStatement("INSERT INTO `wars_sides` (`war`, `uuid`, `side`, `team`, `name`, `town`, `siegeGrace`, `raidGrace`) VALUES (?, ?, ?, ?, ?, ?, ?, ?) " 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` = ?"); + "ON DUPLICATE KEY UPDATE `side` = ?, `team` = ?, `name` = ?, `town` = ?, `siegeGrace` = ?, `raidGrace` = ?");
) ) {
{
// Insert // Insert
sideStatement.setString(1, side.getWar().getUUID().toString()); sideStatement.setString(1, side.getWar().getUUID().toString());
sideStatement.setString(2, side.getUUID().toString()); sideStatement.setString(2, side.getUUID().toString());
@@ -239,7 +238,7 @@ public class SQLQueries {
// Transaction end // Transaction end
con.commit(); con.commit();
} catch(Exception e) { } catch (Exception e) {
con.rollback(); con.rollback();
} finally { } finally {
con.setAutoCommit(true); con.setAutoCommit(true);
@@ -269,7 +268,7 @@ public class SQLQueries {
// Transaction end // Transaction end
con.commit(); con.commit();
} catch(Exception e) { } catch (Exception e) {
con.rollback(); con.rollback();
} finally { } finally {
con.setAutoCommit(true); con.setAutoCommit(true);
@@ -299,7 +298,7 @@ public class SQLQueries {
// Transaction end // Transaction end
con.commit(); con.commit();
} catch(Exception e) { } catch (Exception e) {
con.rollback(); con.rollback();
} finally { } finally {
con.setAutoCommit(true); con.setAutoCommit(true);
@@ -13,6 +13,29 @@ import java.util.Collections;
import java.util.List; import java.util.List;
public class Utils { public class Utils {
private static final ArrayList<Material> weaponList = new ArrayList<>(List.of(
Material.NETHERITE_SWORD,
Material.NETHERITE_AXE,
Material.DIAMOND_SWORD,
Material.DIAMOND_AXE,
Material.IRON_SWORD,
Material.IRON_AXE
));
private static final ArrayList<Material> armorList = new ArrayList<>(List.of(
Material.NETHERITE_HELMET,
Material.NETHERITE_CHESTPLATE,
Material.NETHERITE_LEGGINGS,
Material.NETHERITE_BOOTS,
Material.DIAMOND_HELMET,
Material.DIAMOND_CHESTPLATE,
Material.DIAMOND_LEGGINGS,
Material.DIAMOND_BOOTS,
Material.IRON_HELMET,
Material.IRON_CHESTPLATE,
Material.IRON_LEGGINGS,
Material.IRON_BOOTS
));
/** /**
* Damages all gear in a players inventory * Damages all gear in a players inventory
* *
@@ -41,30 +64,6 @@ public class Utils {
} }
} }
private static final ArrayList<Material> weaponList = new ArrayList<>(List.of(
Material.NETHERITE_SWORD,
Material.NETHERITE_AXE,
Material.DIAMOND_SWORD,
Material.DIAMOND_AXE,
Material.IRON_SWORD,
Material.IRON_AXE
));
private static final ArrayList<Material> armorList = new ArrayList<>(List.of(
Material.NETHERITE_HELMET,
Material.NETHERITE_CHESTPLATE,
Material.NETHERITE_LEGGINGS,
Material.NETHERITE_BOOTS,
Material.DIAMOND_HELMET,
Material.DIAMOND_CHESTPLATE,
Material.DIAMOND_LEGGINGS,
Material.DIAMOND_BOOTS,
Material.IRON_HELMET,
Material.IRON_CHESTPLATE,
Material.IRON_LEGGINGS,
Material.IRON_BOOTS
));
private static void setArmorDurability(@Nullable ItemStack itemStack) { private static void setArmorDurability(@Nullable ItemStack itemStack) {
if (itemStack == null) if (itemStack == null)
return; return;
@@ -168,7 +167,7 @@ public class Utils {
return; return;
switch (itemStack.getType()) { switch (itemStack.getType()) {
case NETHERITE_SWORD, NETHERITE_AXE -> { case NETHERITE_SWORD, NETHERITE_AXE -> {
damageable.setDamage(damageable.getDamage() + 507); damageable.setDamage(damageable.getDamage() + 507);
if (damageable.getDamage() > 2000) { if (damageable.getDamage() > 2000) {
damageable.setDamage(2030); damageable.setDamage(2030);