mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
refactor: wip update 4 (wars working)
This commit is contained in:
71 files changed
+2403
-1553
No files matched your search
@@ -1,770 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
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.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyWorld;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||
import dev.jorel.commandapi.arguments.BooleanArgument;
|
||||
import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.CommandHelper;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
|
||||
import me.ShermansWorld.AlathraWar.enums.TownWarState;
|
||||
import me.ShermansWorld.AlathraWar.utility.Utils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RaidCommand {
|
||||
|
||||
public RaidCommand() {
|
||||
new CommandAPICommand("raid")
|
||||
.withSubcommands(
|
||||
commandRaid(),
|
||||
commandStop(),
|
||||
commandJoin(),
|
||||
commandLeave(),
|
||||
commandAbandon(),
|
||||
commandList(),
|
||||
commandHelp()
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /siege help").build());
|
||||
})
|
||||
.register();
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandRaid() {
|
||||
return new CommandAPICommand("raid")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.strings(
|
||||
WarData.getWarsNames()
|
||||
)
|
||||
),
|
||||
new StringArgument("town")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
return CommandHelper.getTownyWarTowns(warname);
|
||||
}
|
||||
)
|
||||
),
|
||||
new StringArgument("gathertown")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> { // TODO Make getHostileTowns method where we reverse from list
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
return CommandHelper.getTownyWarTowns(warname);
|
||||
}
|
||||
)
|
||||
),
|
||||
new PlayerArgument("leader")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin"),
|
||||
new BooleanArgument("minutemen")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin")
|
||||
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> raidStart(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandStop() {
|
||||
return new CommandAPICommand("stop")
|
||||
.withPermission("AlathraWar.admin")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info ->
|
||||
WarData.getWarsNames()
|
||||
)
|
||||
),
|
||||
new StringArgument("town")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
return CommandHelper.getTownyWarTowns(warname);
|
||||
})
|
||||
)
|
||||
)
|
||||
.executesPlayer(RaidCommand::raidStop);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandJoin() {
|
||||
return new CommandAPICommand("join")
|
||||
.withArguments(
|
||||
new StringArgument("raid")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.strings(
|
||||
CommandHelper.getRaids()
|
||||
)
|
||||
),
|
||||
new StringArgument("side")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final String raidname = (String) info.previousArgs().get("oldRaid");
|
||||
|
||||
final OldRaid oldRaid = RaidData.getRaid(raidname);
|
||||
|
||||
if (oldRaid == null) return Collections.emptyList();
|
||||
|
||||
return List.of(oldRaid.getRaiderSide(), oldRaid.getDefenderSide());
|
||||
})
|
||||
),
|
||||
new PlayerArgument("player")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin"),
|
||||
new BooleanArgument("minutemen")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin")
|
||||
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> raidJoin(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandLeave() {
|
||||
return new CommandAPICommand("leave")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info ->
|
||||
WarData.getWarsNames()
|
||||
)
|
||||
),
|
||||
new StringArgument("town")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
return CommandHelper.getTownyWarTowns(warname);
|
||||
})
|
||||
),
|
||||
new PlayerArgument("player")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> raidLeave(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandAbandon() {
|
||||
return new CommandAPICommand("abandon")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info ->
|
||||
WarData.getWarsNames()
|
||||
)
|
||||
),
|
||||
new StringArgument("town")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
return CommandHelper.getTownyWarTowns(warname);
|
||||
})
|
||||
)
|
||||
)
|
||||
.executesPlayer(RaidCommand::raidAbandon);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandList() {
|
||||
return new CommandAPICommand("list")
|
||||
.executesPlayer(RaidCommand::raidsList);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandHelp() {
|
||||
return new CommandAPICommand("help")
|
||||
.executesPlayer(RaidCommand::raidHelp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a raid
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
protected static void raidStart(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
boolean warFound = false;
|
||||
boolean townExists = false;
|
||||
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cUsage: /alathrawaradmin create raid [war] [raidTown] (gatherTown/\"defaultCode\") (owner) (override)").build());
|
||||
|
||||
for (final OldWar oldWar : WarData.getWars()) {
|
||||
if (oldWar.getName().equalsIgnoreCase(argWarName)) {
|
||||
warFound = true;
|
||||
|
||||
final Player raidOwner = (Player) args.getOptional("leader").orElse(p);
|
||||
|
||||
if (raidOwner == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("OldRaid Owner is Null").build());
|
||||
}
|
||||
|
||||
TownyWorld townyWorld;
|
||||
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
|
||||
|
||||
String side;
|
||||
if (oldWar.getSide1Players().contains(raidOwner.getName())) {
|
||||
side = oldWar.getSide1();
|
||||
} else if (oldWar.getSide2Players().contains(raidOwner.getName())) {
|
||||
side = oldWar.getSide2();
|
||||
} else {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You are not in this oldWar! Type /oldWar join [oldWar] [side]").build());
|
||||
}
|
||||
|
||||
//Minuteman countermeasures
|
||||
int minuteman = CommandHelper.isPlayerMinuteman(raidOwner.getName());
|
||||
boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
|
||||
|
||||
if (minuteManOverride) {
|
||||
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
}
|
||||
|
||||
//minuteManOverride?
|
||||
if (!minuteManOverride) {
|
||||
if (minuteman != 0) {
|
||||
if (minuteman == 1) {
|
||||
//player has joined to recently
|
||||
if (admin)
|
||||
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
raidOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
return;
|
||||
} else if (minuteman == 2) {
|
||||
//player has played too little
|
||||
if (admin)
|
||||
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
raidOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check if in a town
|
||||
//takes the command runners town as the gather point
|
||||
Town gatherTown;
|
||||
try {
|
||||
@Nullable String argGatherTown = (String) args.getOptional("gathertown").orElse(null);
|
||||
|
||||
if (admin && argGatherTown != null) {
|
||||
if (argGatherTown.equalsIgnoreCase("defaultCode")) {
|
||||
//use default behavior
|
||||
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
|
||||
} else if (TownyAPI.getInstance().getTown(argGatherTown) != null) {
|
||||
gatherTown = TownyAPI.getInstance().getTown(argGatherTown);
|
||||
} else {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "No valid town set for gather town, defaulting to current location");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "No valid town set for gather town, defaulting to current location");
|
||||
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
|
||||
}
|
||||
} else {
|
||||
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
|
||||
}
|
||||
} catch (NotRegisteredException e2) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
return;
|
||||
}
|
||||
if (gatherTown == null) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
return;
|
||||
}
|
||||
|
||||
//parse the argunment for town
|
||||
for (final String entry : townyWorld.getTowns().keySet()) {
|
||||
final Town raidedTown = townyWorld.getTowns().get(entry);
|
||||
|
||||
//if this is run as admin, shift our check forward a slot
|
||||
if (raidedTown.getName().equalsIgnoreCase((String) args.get("town")) && gatherTown != null) {
|
||||
|
||||
Main.warLogger.log("Raided town: " + raidedTown.getName());
|
||||
Main.warLogger.log("Gather town: " + gatherTown.getName());
|
||||
Main.warLogger.log("OldRaid Owner: " + raidOwner.getName());
|
||||
p.sendMessage("Raided town: " + raidedTown.getName());
|
||||
p.sendMessage("Gather town: " + gatherTown.getName());
|
||||
p.sendMessage("OldRaid Owner: " + raidOwner.getName());
|
||||
//DEBUG PRINT
|
||||
for (String t : oldWar.getSide1Towns()) {
|
||||
Main.warLogger.log("Side1 town: " + t);
|
||||
p.sendMessage("Side1 town: " + t);
|
||||
}
|
||||
for (String t : oldWar.getSide2Towns()) {
|
||||
Main.warLogger.log("Side2 town: " + t);
|
||||
p.sendMessage("Side2 town: " + t);
|
||||
}
|
||||
|
||||
//check if the town were attempting to raid is in the oldWar
|
||||
if (!oldWar.getSide1Towns().contains(raidedTown.getName().toLowerCase()) && !oldWar.getSide2Towns().contains(raidedTown.getName().toLowerCase())) {
|
||||
if (oldWar.getSurrenderedTowns().contains(raidedTown.getName().toLowerCase())) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "The town you are trying to raid has already surrendered!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "The town you are trying to raid has already surrendered!");
|
||||
return;
|
||||
}
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "The town you are trying to raid is not part of the oldWar!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "The town you are trying to raid is not part of the oldWar!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Is being sieged check
|
||||
for (OldSiege s : SiegeData.getSieges()) {
|
||||
if (s.getTown().getName().equalsIgnoreCase(raidedTown.getName())) {
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "That town is already currently being sieged! Cannot raid at this time!");
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "That town is already currently being sieged! Cannot raid at this time!");
|
||||
}
|
||||
}
|
||||
|
||||
townExists = true;
|
||||
|
||||
OldRaid oldRaid2;
|
||||
if (oldWar.getSide1Players().contains(raidOwner.getName())) {
|
||||
//Time and raid activity validity check
|
||||
int c = RaidData.isValidRaid(oldWar, side, raidedTown);
|
||||
if (c == 2) {
|
||||
//if were admin, see if an owner arg exists, and if so then use it
|
||||
oldRaid2 = new OldRaid(oldWar, raidedTown, gatherTown, true, raidOwner);
|
||||
} else if (c == 1) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "This town is already being raided at this time!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "This town is already being raided at this time!");
|
||||
return;
|
||||
} else if (c == 0) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Your side has raided too recently!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "Your side has raided too recently!");
|
||||
return;
|
||||
} else if (c == -1) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "This town was raided too recently!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "This town was raided too recently!");
|
||||
return;
|
||||
} else if (c == -2) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "At least on member of the raided town must be online to defend it!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "At least on member of the raided town must be online to defend it!");
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
} else {
|
||||
//Something broke if this runs
|
||||
if (!oldWar.getSide2Players().contains(raidOwner.getName())) {
|
||||
Bukkit.getLogger().info("Unable to find player declaring raid in the oldWar");
|
||||
return;
|
||||
}
|
||||
//Time and raid activity validity check
|
||||
int c = RaidData.isValidRaid(oldWar, side, raidedTown);
|
||||
if (c == 2) {
|
||||
oldRaid2 = new OldRaid(oldWar, raidedTown, gatherTown, false, raidOwner);
|
||||
} else if (c == 1) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "This town is already being raided at this time!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "This town is already being raided at this time!");
|
||||
return;
|
||||
} else if (c == 0) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Your side has raided too recently!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "Your side has raided too recently!");
|
||||
return;
|
||||
} else if (c == -1) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "This town was raided too recently!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "This town was raided too recently!");
|
||||
return;
|
||||
} else if (c == -2) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "At least on member of the raided town must be online to defend it!");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "At least on member of the raided town must be online to defend it!");
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
// Player participance check
|
||||
Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull();
|
||||
TownWarState sideR = oldWar.getState(leaderTown.getName().toLowerCase());
|
||||
if (sideR == TownWarState.NOT_PARTICIPANT) {
|
||||
if (admin) p.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar.");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar.");
|
||||
return;
|
||||
} else if (sideR == TownWarState.SURRENDERED) {
|
||||
if (admin) p.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Attacking own side
|
||||
if (oldWar.getState(raidedTown) == sideR) {
|
||||
if (admin) p.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
|
||||
return;
|
||||
}
|
||||
|
||||
//check player balance
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(raidOwner.getUniqueId());
|
||||
if (Main.econ.getBalance(offlinePlayer) <= 1000.0) {
|
||||
if (admin)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You must have at least $1000 to put up to start a raid.");
|
||||
raidOwner.sendMessage(UtilsChat.getPrefix() + "You must have at least $1000 to put up to start a raid.");
|
||||
return;
|
||||
}
|
||||
|
||||
//publish raid
|
||||
Main.econ.withdrawPlayer(offlinePlayer, 1000);
|
||||
oldRaid2.addActiveRaider(raidOwner.getName());
|
||||
RaidData.addRaid(oldRaid2);
|
||||
oldRaid2.start(); //funny funny method haha
|
||||
WarData.saveWar(oldRaid2.getWar());
|
||||
|
||||
//broadcast
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "As part of " + oldWar.getName() + ", forces from " + oldRaid2.getRaiderSide() + " are gathering to raid the town of " + raidedTown.getName() + "!");
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "All players from the defending side have been drafted for the town's defense.");
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The raid of "
|
||||
+ raidedTown.getName() + " will begin in " + (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!");
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() +
|
||||
"The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
|
||||
|
||||
Main.warLogger.log(raidOwner.getName() + " started a raid.");
|
||||
if (admin) {
|
||||
Main.warLogger.log(raidOwner.getName() + " started a raid from admin interference.");
|
||||
p.sendMessage(Helper.color("&cForcefully started raid from the console."));
|
||||
}
|
||||
Main.warLogger.log("As part of " + oldWar.getName() + ", forces from " + oldRaid2.getRaiderSide() + " are raiding the town of " + raidedTown.getName() + "!");
|
||||
Main.warLogger.log("The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!warFound) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + "That war does not exist! /raid start [war] [town]");
|
||||
return;
|
||||
}
|
||||
if (!townExists) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + "That town does not exist! /raid start [war] [town]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the current raid by admins
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
private static void raidStop(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name!").build());
|
||||
|
||||
if (!(args.get("town") instanceof final String argTown))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a town name!").build());
|
||||
|
||||
|
||||
//are there even any raids
|
||||
if (RaidData.getRaids().isEmpty()) {
|
||||
fail(p, args, "noRaids");
|
||||
}
|
||||
|
||||
//find our desired oldRaid and stop it
|
||||
OldRaid oldRaid = RaidData.getRaid(argWarName + "-" + argTown);
|
||||
|
||||
if (oldRaid != null) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + "oldRaid cancelled");
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The oldRaid of " + oldRaid.getRaidedTown().getName() + " has been cancelled by an admin");
|
||||
oldRaid.stop(); //this purges itself from raids
|
||||
} else {
|
||||
fail(p, args, "badName");
|
||||
}
|
||||
}
|
||||
|
||||
protected static void raidJoin(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("oldRaid") instanceof final String argRaidName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a oldRaid name!").build());
|
||||
|
||||
if (!(args.get("side") instanceof final String argSide))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a side!").build());
|
||||
|
||||
final OldRaid oldRaid = RaidData.getRaid(argRaidName);
|
||||
if (oldRaid == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThat oldRaid does not exist!").build());
|
||||
|
||||
final OldWar oldWar = oldRaid.getWar();
|
||||
if (oldWar == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe oldWar does not exist!").build());
|
||||
|
||||
final Player joiner = (Player) args.getOptional("player").orElse(p);
|
||||
if (joiner == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Joiner is Null").build());
|
||||
|
||||
|
||||
if (admin) {
|
||||
if (argSide != null) {
|
||||
if (argSide.equalsIgnoreCase(oldRaid.getDefenderSide())) {
|
||||
if (!oldRaid.getDefenderPlayers().contains(joiner.getName()))
|
||||
oldRaid.getDefenderPlayers().add(joiner.getName());
|
||||
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Player " + joiner.getName() + " added to defender side.");
|
||||
Main.warLogger.log("Player " + joiner.getName() + " added to defender side.");
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "You were forcefully added to the defender side against the oldRaid party on " + oldRaid.getRaidedTown() + " by an admin.");
|
||||
return;
|
||||
} else {
|
||||
if (!oldRaid.getRaiderPlayers().contains(joiner.getName()))
|
||||
oldRaid.getRaiderPlayers().add(joiner.getName());
|
||||
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Player " + joiner.getName() + " added to raider side.");
|
||||
Main.warLogger.log("Player " + joiner.getName() + " added to raider side.");
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "You were forcefully added to the oldRaid party on " + oldRaid.getRaidedTown() + " by an admin. Leaving the gather town will remove you from the oldRaid party.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!oldRaid.getWar().getSide1Players().contains(joiner.getName()) && !oldRaid.getWar().getSide2Players().contains(joiner.getName())) {
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar! Type /oldWar join [oldWar] [side]");
|
||||
}
|
||||
|
||||
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
|
||||
//also 12 hours min platim by default
|
||||
int minuteman = CommandHelper.isPlayerMinuteman(joiner.getName());
|
||||
boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
|
||||
|
||||
if (minuteManOverride) {
|
||||
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
}
|
||||
|
||||
if (!minuteManOverride) {
|
||||
if (minuteman != 0) {
|
||||
if (minuteman == 1) {
|
||||
//player has joined to recently
|
||||
if (admin)
|
||||
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a oldRaid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
joiner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a oldRaid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
return;
|
||||
} else if (minuteman == 2) {
|
||||
//player has played too little
|
||||
if (admin)
|
||||
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a oldRaid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
joiner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a oldRaid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
if (!admin) {
|
||||
if (oldRaid.getPhase() == RaidPhase.GATHER || oldRaid.getPhase() == RaidPhase.START) {
|
||||
try {
|
||||
//check if the player is in the gather town
|
||||
ArrayList<WorldCoord> cluster = Utils.getCluster(oldRaid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
|
||||
oldRaid.addActiveRaider(joiner.getName());
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "You have joined the oldRaid on " + oldRaid.getRaidedTown().getName() + "!");
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "Leaving " + oldRaid.getGatherTown().getName() + " will cause you to leave the oldRaid party.");
|
||||
} else {
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "You must be in the gathering town to join the oldRaid on " + oldRaid.getRaidedTown().getName() + ".");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "You cannot join the oldRaid on " + oldRaid.getRaidedTown().getName() + "! It has already started!");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
//check if the player is in the gather town
|
||||
ArrayList<WorldCoord> cluster = Utils.getCluster(oldRaid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
|
||||
oldRaid.addActiveRaider(joiner.getName());
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "You have joined the oldRaid on " + oldRaid.getRaidedTown().getName() + "!");
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "Leaving " + oldRaid.getGatherTown().getName() + " will cause you to leave the oldRaid party.");
|
||||
} else {
|
||||
joiner.sendMessage(UtilsChat.getPrefix() + "You must be in the gathering town to join the oldRaid on " + oldRaid.getRaidedTown().getName() + ".");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
oldRaid.save();
|
||||
}
|
||||
|
||||
protected static void raidLeave(Player player, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
//Get oldRaid!
|
||||
final Player p = (Player) args.getOptional("player").orElse(player);
|
||||
|
||||
if (p == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Raider is Null").build());
|
||||
}
|
||||
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name!").build());
|
||||
|
||||
if (!(args.get("town") instanceof final String argTown))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a town name!").build());
|
||||
|
||||
|
||||
OldRaid oldRaid = RaidData.getRaid(argWarName + "-" + argTown);
|
||||
if (oldRaid == null) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + "No oldRaid is gathering in this town or this town does not exist!");
|
||||
if (admin)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No oldRaid is gathering in this town or this town does not exist!").build());
|
||||
}
|
||||
|
||||
if (oldRaid.getWar().getName().equalsIgnoreCase(argWarName)) {
|
||||
if (!oldRaid.getWar().getSide1Players().contains(p.getName()) && !oldRaid.getWar().getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You are not in this war! Type /war join [war] [side]");
|
||||
if (admin)
|
||||
player.sendMessage(UtilsChat.getPrefix() + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
if (oldRaid.getPhase() == RaidPhase.GATHER || oldRaid.getPhase() == RaidPhase.START) {
|
||||
try {
|
||||
//check if player is in gather town
|
||||
ArrayList<WorldCoord> cluster = Utils.getCluster(oldRaid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
oldRaid.removeActiveRaider(p.getName());
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You have left the oldRaid on " + oldRaid.getRaidedTown().getName() + "!");
|
||||
if (admin)
|
||||
player.sendMessage(UtilsChat.getPrefix() + "You have left the oldRaid on " + oldRaid.getRaidedTown().getName() + "!");
|
||||
|
||||
} else {
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You cannot leave the oldRaid on " + oldRaid.getRaidedTown().getName() + "! It has already started!");
|
||||
if (admin)
|
||||
player.sendMessage(UtilsChat.getPrefix() + "You cannot leave the oldRaid on " + oldRaid.getRaidedTown().getName() + "! It has already started!");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (admin) {
|
||||
player.sendMessage(UtilsChat.getPrefix() + "Forced player " + p.getName() + " to leave oldRaid on " + oldRaid.getRaidedTown().getName() + " in war " + argWarName);
|
||||
Main.warLogger.log("Forced player " + p.getName() + " to leave oldRaid on " + oldRaid.getRaidedTown().getName() + " in war " + argWarName);
|
||||
}
|
||||
}
|
||||
|
||||
oldRaid.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Abandons the raid
|
||||
*
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
private static void raidAbandon(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name!").build());
|
||||
|
||||
if (!(args.get("town") instanceof final String argTown))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a town name!").build());
|
||||
|
||||
|
||||
//Get oldRaid
|
||||
OldRaid oldRaid = RaidData.getRaid(argWarName + "-" + argTown);
|
||||
|
||||
if (oldRaid == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThis oldRaid does not exist!").build());
|
||||
|
||||
|
||||
if (oldRaid.getWar().getName().equalsIgnoreCase(argWarName)) {
|
||||
if (!oldRaid.getWar().getSide1Players().contains(p.getName()) && !oldRaid.getWar().getSide2Players().contains(p.getName())) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou are not in this war! Type /war join [war] [side]").build());
|
||||
}
|
||||
|
||||
if (oldRaid.getOwner().getName().equalsIgnoreCase(p.getName())) {
|
||||
//check if gather phase
|
||||
if (oldRaid.getPhase() == RaidPhase.GATHER || oldRaid.getPhase() == RaidPhase.START || oldRaid.getPhase() == RaidPhase.TRAVEL || oldRaid.getPhase() == RaidPhase.COMBAT) {
|
||||
//force defender victory
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The oldRaid on " + oldRaid.getRaidedTown().getName() + " has been abandoned by " + oldRaid.getRaiderSide()).build());
|
||||
Main.warLogger.log(p.getName() + " abandoned the oldRaid on " + oldRaid.getRaidedTown().getName() + " they started at " + oldRaid.getGatherTown().getName());
|
||||
oldRaid.defendersWin(oldRaid.getRaiderScore(), oldRaid.getDefenderScore());
|
||||
} else {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou cannot abandon the oldRaid on " + oldRaid.getRaidedTown().getName() + "! It has a problem!").build());
|
||||
}
|
||||
} else {
|
||||
fail(p, args, "owner");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void raidsList(Player p, CommandArguments args) {
|
||||
if (RaidData.getRaids().isEmpty()) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "There are currently no Raids in progress").build());
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Raids currently in progress:").build());
|
||||
for (final OldRaid oldRaid : RaidData.getRaids()) {
|
||||
p.sendMessage(new ColorParser("Name: " + oldRaid.getName()).build());
|
||||
p.sendMessage(new ColorParser("OldWar: " + oldRaid.getWar().getName()).build());
|
||||
p.sendMessage(new ColorParser("Owner: " + oldRaid.getOwner().getName()).build());
|
||||
p.sendMessage(new ColorParser("Raiding: " + oldRaid.getRaidedTown().getName().toLowerCase()).build());
|
||||
p.sendMessage(new ColorParser("Gathering In: " + oldRaid.getGatherTown().getName().toLowerCase()).build());
|
||||
p.sendMessage(new ColorParser("Raiders: " + oldRaid.getRaiderSide()).build());
|
||||
p.sendMessage(new ColorParser("Defenders: " + oldRaid.getDefenderSide()).build());
|
||||
p.sendMessage(new ColorParser("Raider Score: " + oldRaid.getRaiderScore()).build());
|
||||
p.sendMessage(new ColorParser("Defender Score: " + oldRaid.getDefenderScore()).build());
|
||||
p.sendMessage(new ColorParser("OldRaid Phase: " + oldRaid.getPhase().name()).build());
|
||||
p.sendMessage(new ColorParser("Time Left: " + (RaidPhase.END.startTick - oldRaid.getRaidTicks()) / 1200 + " minutes").build());
|
||||
p.sendMessage(new ColorParser("-=-=-=-=-=-=-=-=-=-=-=-").build());
|
||||
}
|
||||
}
|
||||
|
||||
private static void raidHelp(Player p, CommandArguments args) {
|
||||
if (p.hasPermission("AlathraWar.admin")) {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid stop [name]").build());
|
||||
}
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid start [war] [town]").build());
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid join [war] [town]").build());
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid leave [war] [town]").build());
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid abandon [war] [town]").build());
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/raid list").build());
|
||||
}
|
||||
|
||||
private static void fail(CommandSender p, CommandArguments args, String type) throws WrapperCommandSyntaxException {
|
||||
switch (type) {
|
||||
case "permissions" ->
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou do not have permission to do this.").build());
|
||||
case "syntax" ->
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cInvalid Syntax. /raid help").build());
|
||||
case "noRaids" ->
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThere are currently no Raids in progress.").build());
|
||||
case "badName" ->
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA raid could not be found with this Name! Type /raid list to view current raids.").build());
|
||||
case "owner" ->
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cOnly the player who started the raid can abandon it.").build());
|
||||
default ->
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cInvalid Arguments. /raid help").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,348 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||
import dev.jorel.commandapi.arguments.BooleanArgument;
|
||||
import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.CommandHelper;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
|
||||
import me.ShermansWorld.AlathraWar.enums.TownWarState;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class SiegeCommand {
|
||||
public SiegeCommand() {
|
||||
new CommandAPICommand("siege")
|
||||
.withSubcommands(
|
||||
commandStart(),
|
||||
commandStop(),
|
||||
commandAbandon(),
|
||||
commandList(),
|
||||
commandHelp()
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /siege help").build());
|
||||
})
|
||||
.register();
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandStart() {
|
||||
return new CommandAPICommand("start")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.strings(
|
||||
WarData.getWarsNames()
|
||||
)
|
||||
),
|
||||
new StringArgument("town")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
return CommandHelper.getTownyWarTowns(warname);
|
||||
})
|
||||
),
|
||||
new PlayerArgument("leader")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin"),
|
||||
new BooleanArgument("minutemen")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> siegeStart(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandStop() {
|
||||
return new CommandAPICommand("stop")
|
||||
.withPermission("AlathraWar.admin")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info ->
|
||||
WarData.getWarsNames()
|
||||
)
|
||||
),
|
||||
new StringArgument("town")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
return CommandHelper.getTownyWarTowns(warname);
|
||||
})
|
||||
)
|
||||
)
|
||||
.executesPlayer(SiegeCommand::siegeStop);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandAbandon() {
|
||||
return new CommandAPICommand("abandon")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info ->
|
||||
WarData.getWarsNames()
|
||||
)
|
||||
),
|
||||
new StringArgument("town")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
return CommandHelper.getTownyWarTowns(warname);
|
||||
})
|
||||
)
|
||||
)
|
||||
.executesPlayer(SiegeCommand::siegeAbandon);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandList() {
|
||||
return new CommandAPICommand("list")
|
||||
.executesPlayer(SiegeCommand::siegeList);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandHelp() {
|
||||
return new CommandAPICommand("help")
|
||||
.executesPlayer(SiegeCommand::siegeHelp);
|
||||
}
|
||||
|
||||
|
||||
protected static void siegeStart(Player sender, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cUsage: /alathrawaradmin create oldSiege [oldWar] [town] (owner) (force).").build());
|
||||
|
||||
//if this is admin mode use the forth arg instad of sender.
|
||||
//if player is null after this then force end
|
||||
final Player siegeOwner = (Player) args.getOptional("leader").orElse(sender);
|
||||
|
||||
if (siegeOwner == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("You need to pick a valid leader.").build());
|
||||
|
||||
|
||||
/*if (args.length < 3) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/oldWar oldSiege [oldWar] [town]").build());
|
||||
}*/
|
||||
|
||||
// OldWar check
|
||||
OldWar oldWar = WarData.getWar(argWarName);
|
||||
if (oldWar == null) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "That oldWar does not exist! /oldSiege start [oldWar] [town]");
|
||||
if (admin)
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "That oldWar does not exist! /oldSiege start [oldWar] [town]");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Player participance check
|
||||
Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
|
||||
TownWarState side = oldWar.getState(leaderTown.getName().toLowerCase());
|
||||
|
||||
// TODO DEBUG PRINT
|
||||
Main.warLogger.log("Leader Town: " + leaderTown.getName());
|
||||
Main.warLogger.log("OldSiege Owner: " + siegeOwner.getName());
|
||||
sender.sendMessage("Leader Town: " + leaderTown.getName());
|
||||
sender.sendMessage("OldSiege Owner: " + siegeOwner.getName());
|
||||
|
||||
// TODO DEBUG PRINT
|
||||
for (String t : oldWar.getSide1Towns()) {
|
||||
Main.warLogger.log("Side1 town: " + t);
|
||||
sender.sendMessage("Side1 town: " + t);
|
||||
}
|
||||
for (String t : oldWar.getSide2Towns()) {
|
||||
Main.warLogger.log("Side2 town: " + t);
|
||||
sender.sendMessage("Side2 town: " + t);
|
||||
}
|
||||
|
||||
if (side == TownWarState.NOT_PARTICIPANT) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar.");
|
||||
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You are not in this oldWar.");
|
||||
return;
|
||||
} else if (side == TownWarState.SURRENDERED) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
|
||||
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
|
||||
//Minuteman countermeasures
|
||||
int minuteman = CommandHelper.isPlayerMinuteman(siegeOwner.getName());
|
||||
boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
|
||||
|
||||
if (minuteManOverride) {
|
||||
sender.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
}
|
||||
|
||||
//override?
|
||||
if (!minuteManOverride) {
|
||||
if (minuteman != 0) {
|
||||
if (minuteman == 1) {
|
||||
//player has joined to recently
|
||||
if (admin)
|
||||
sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
siegeOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
return;
|
||||
} else if (minuteman == 2) {
|
||||
//player has played too little
|
||||
if (admin)
|
||||
sender.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
siegeOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(args.get("town") instanceof final String argTownName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Specify a town! /oldSiege start [oldWar] [town]").build());
|
||||
|
||||
// Town check
|
||||
Town town = TownyAPI.getInstance().getTown(argTownName);
|
||||
if (town == null) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "That town does not exist! /oldSiege start [oldWar] [town]");
|
||||
if (admin)
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "That town does not exist! /oldSiege start [oldWar] [town]");
|
||||
return;
|
||||
}
|
||||
|
||||
// Is being raided check
|
||||
for (OldRaid r : RaidData.getRaids()) {
|
||||
if (r.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "That town is already currently being raided! Cannot oldSiege at this time!");
|
||||
if (admin)
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "That town is already currently being raided! Cannot oldSiege at this time!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Attacking own side
|
||||
if (oldWar.getState(town) == side) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
|
||||
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You cannot attack your own towns.");
|
||||
return;
|
||||
}
|
||||
|
||||
OldSiege oldSiege = new OldSiege(oldWar, town, siegeOwner);
|
||||
SiegeData.addSiege(oldSiege);
|
||||
oldWar.addSiege(oldSiege);
|
||||
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + oldSiege.getTown() + " has been put to oldSiege by " + oldSiege.getAttackerSide() + "!");
|
||||
|
||||
if (admin)
|
||||
sender.sendMessage(Helper.color("&cForcefully started oldSiege from the console."));
|
||||
|
||||
// TODO Debug logs...
|
||||
Main.warLogger.log("Attacked Town: " + town.getName().toLowerCase());
|
||||
sender.sendMessage("Attacked Town: " + town.getName().toLowerCase());
|
||||
|
||||
oldWar.save();
|
||||
oldSiege.start();
|
||||
}
|
||||
|
||||
private static void siegeStop(Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
final HashSet<OldSiege> oldSieges = SiegeData.getSieges();
|
||||
if (oldSieges.isEmpty()) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "There are currently no oldSieges in progress").build());
|
||||
}
|
||||
|
||||
if (args.count() < 2) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/siege stop [town]").build());
|
||||
}
|
||||
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No oldWar name supplied. /siege stop [oldWar] [town]").build());
|
||||
|
||||
// OldWar check
|
||||
OldWar oldWar = WarData.getWar(argWarName);
|
||||
if (oldWar == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "That oldWar does not exist! /siege stop [oldWar] [town]").build());
|
||||
}
|
||||
|
||||
if (!(args.get("town") instanceof final String argTownName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No oldWar name supplied. /siege stop [oldWar] [town]").build());
|
||||
|
||||
for (OldSiege oldSiege : oldSieges) {
|
||||
if (oldSiege.getTown().getName().equalsIgnoreCase(argTownName) && oldSiege.getWar().equals(oldWar)) {
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "oldSiege cancelled").build());
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The oldSiege at " + oldSiege.getTown().getName() + " has been cancelled by an admin.").build());
|
||||
//oldSiege.clearBeacon();
|
||||
oldSiege.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "A siege could not be found with this town name! Type /siege list to view current oldSieges").build());
|
||||
}
|
||||
|
||||
private static void siegeAbandon(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (args.count() < 2) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/oldSiege abandon [town]").build());
|
||||
}
|
||||
|
||||
// OldWar check
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No oldWar name supplied. /oldSiege stop [oldWar] [town]").build());
|
||||
|
||||
// OldWar check
|
||||
OldWar oldWar = WarData.getWar(argWarName);
|
||||
if (oldWar == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "That oldWar does not exist! /oldSiege abandon [oldWar] [town]").build());
|
||||
}
|
||||
|
||||
if (!(args.get("town") instanceof final String argTown))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "No town name supplied. /oldSiege stop [oldWar] [town]").build());
|
||||
|
||||
OldSiege oldSiege = SiegeData.getSiege(argTown);
|
||||
if (oldSiege == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid oldSiege").build());
|
||||
}
|
||||
|
||||
OfflinePlayer oPlayer = oldSiege.getSiegeLeader();
|
||||
if (oPlayer != p) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You are not the leader of this oldSiege.").build());
|
||||
}
|
||||
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The oldSiege at " + oldSiege.getTown().getName() + " has been abandoned.").build());
|
||||
Main.warLogger.log(p.getName() + " abandoned the oldSiege they started at " + oldSiege.getTown().getName());
|
||||
oldSiege.defendersWin();
|
||||
}
|
||||
|
||||
private static void siegeList(Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
HashSet<OldSiege> oldSieges = SiegeData.getSieges();
|
||||
if (oldSieges.isEmpty())
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "There are currently no oldSieges in progress").build());
|
||||
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Sieges currently in progress:").build());
|
||||
for (OldSiege oldSiege : oldSieges) {
|
||||
OldWar oldWar = oldSiege.getWar();
|
||||
String color = (oldSiege.getSide1AreAttackers() && (oldWar.getState(oldSiege.getTown().getName().toLowerCase()) == TownWarState.SIDE1)) ? "&c" : "&9";
|
||||
sender.sendMessage(new ColorParser(oldWar.getName() + " - " + color + oldSiege.getTown().getName().toLowerCase()).build());
|
||||
sender.sendMessage(new ColorParser(oldWar.getSide1() + " - " + (oldSiege.getSide1AreAttackers() ? oldSiege.getAttackerPoints() : oldSiege.getDefenderPoints())).build());
|
||||
sender.sendMessage(new ColorParser(oldWar.getSide2() + " - " + (oldSiege.getSide1AreAttackers() ? oldSiege.getDefenderPoints() : oldSiege.getAttackerPoints())).build());
|
||||
sender.sendMessage(new ColorParser("Time Left: " + (OldSiege.maxSiegeTicks - oldSiege.getSiegeTicks()) / 1200 + " minutes").build());
|
||||
sender.sendMessage(new ColorParser("-=-=-=-=-=-=-=-=-=-=-=-").build());
|
||||
}
|
||||
}
|
||||
|
||||
private static void siegeHelp(Player sender, CommandArguments args) {
|
||||
if (sender.hasPermission("AlathraWar.admin")) {
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege stop [war] [town]").build());
|
||||
}
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege start [war] [town]").build());
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege abandon [war] [town]").build());
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege list").build());
|
||||
}
|
||||
}
|
||||
@@ -1,455 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||
import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import dev.jorel.commandapi.executors.CommandArguments;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.conflict.War;
|
||||
import me.ShermansWorld.AlathraWar.conflict.battle.Side;
|
||||
import me.ShermansWorld.AlathraWar.enums.BattleSide;
|
||||
import me.ShermansWorld.AlathraWar.enums.BattleTeam;
|
||||
import me.ShermansWorld.AlathraWar.enums.TownWarState;
|
||||
import me.ShermansWorld.AlathraWar.holder.WarManager;
|
||||
import me.ShermansWorld.AlathraWar.utility.UtilsChat;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class WarCommand {
|
||||
public WarCommand() {
|
||||
new CommandAPICommand("war")
|
||||
.withSubcommands(
|
||||
commandCreate(),
|
||||
commandDelete(),
|
||||
commandJoin(),
|
||||
commandSurrender(),
|
||||
commandList(),
|
||||
commandInfo(),
|
||||
commandHelp()
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /war help").build());
|
||||
})
|
||||
.register();
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandCreate() {
|
||||
return new CommandAPICommand("create")
|
||||
.withPermission("AlathraWar.admin")
|
||||
.withArguments(
|
||||
new StringArgument("war"),
|
||||
new StringArgument("side1")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> nations = CommandHelper.getTownyNations();
|
||||
final List<String> towns = CommandHelper.getTownyTowns();
|
||||
|
||||
Collections.sort(nations);
|
||||
Collections.sort(towns);
|
||||
|
||||
nations.addAll(towns);
|
||||
|
||||
return nations;
|
||||
})
|
||||
),
|
||||
new StringArgument("side2")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> nations = CommandHelper.getTownyNations();
|
||||
final List<String> towns = CommandHelper.getTownyTowns();
|
||||
|
||||
Collections.sort(nations);
|
||||
Collections.sort(towns);
|
||||
|
||||
nations.addAll(towns);
|
||||
|
||||
return nations;
|
||||
})
|
||||
)
|
||||
)
|
||||
.executesPlayer(WarCommand::warCreate);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandDelete() {
|
||||
return new CommandAPICommand("delete")
|
||||
.withPermission("AlathraWar.admin")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> WarManager.getInstance().getWarsNames())
|
||||
)
|
||||
)
|
||||
.executesPlayer(WarCommand::warDelete);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandJoin() {
|
||||
return new CommandAPICommand("join")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> CommandHelper.getWarNames())
|
||||
),
|
||||
new StringArgument("side")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> {
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
|
||||
final War war = WarManager.getInstance().getWar(warname);
|
||||
|
||||
if (war == null) return Collections.emptyList();
|
||||
|
||||
return war.getSides();
|
||||
})
|
||||
),
|
||||
new PlayerArgument("player").setOptional(true).withPermission("AlathraWar.admin")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> warJoin(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandSurrender() {
|
||||
return new CommandAPICommand("surrender")
|
||||
.withArguments(
|
||||
new StringArgument("war")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> CommandHelper.getWarNames())
|
||||
),
|
||||
new PlayerArgument("player")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> warSurrender(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandList() {
|
||||
return new CommandAPICommand("list")
|
||||
.executesPlayer(WarCommand::warList);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandInfo() {
|
||||
return new CommandAPICommand("info")
|
||||
.withArguments(
|
||||
new PlayerArgument("player")
|
||||
)
|
||||
.executesPlayer(WarCommand::warInfo);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandHelp() {
|
||||
return new CommandAPICommand("help")
|
||||
.executesPlayer(WarCommand::warHelp);
|
||||
}
|
||||
|
||||
protected static void warCreate(CommandSender p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name.").build());
|
||||
|
||||
if (WarManager.getInstance().getWar(argWarName) != null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name.").build());
|
||||
|
||||
if (!(args.get("side1") instanceof final String argSide1))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a side.").build());
|
||||
|
||||
if (!(args.get("side2") instanceof final String argSide2))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a side.").build());
|
||||
|
||||
if (argSide1.contains(argSide2))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cCannot declare war on oneself.").build());
|
||||
|
||||
// TODO Ensure side1 valid
|
||||
// TODO Ensure side2 valid
|
||||
// TODO Deep Check if war exists where the same sides are fighting???
|
||||
|
||||
// Check if side1 is nation or town
|
||||
// Check if side2 is nation or town
|
||||
|
||||
// Check if opposing factions are already at war?
|
||||
|
||||
// TODO Add checks here for wether the towns/nations names are valid
|
||||
Side side1 = new Side(BattleSide.ATTACKER, BattleTeam.SIDE_1, argSide1);
|
||||
Side side2 = new Side(BattleSide.DEFENDER, BattleTeam.SIDE_2, argSide1);
|
||||
|
||||
// TODO Add relevant towns/nations/players to sides
|
||||
|
||||
War war = new War(argWarName, side1, side2);
|
||||
WarManager.getInstance().addWar(war);
|
||||
war.save();
|
||||
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "War created with the name " + argWarName + ", "
|
||||
+ argSide1 + " vs. " + argSide2);
|
||||
Main.warLogger.log(p.getName() + " created a new war with the name " + argWarName + ", " + argSide1
|
||||
+ " vs. " + argSide2);
|
||||
|
||||
}
|
||||
|
||||
private static void warDelete(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (args.count() >= 1) {
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name.").build());
|
||||
|
||||
War war = WarManager.getInstance().getWar(argWarName);
|
||||
|
||||
if (war == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cWar not found. Type /war list to view current wars.").build());
|
||||
|
||||
for (OldSiege s : war.getSieges()) {
|
||||
s.stop();
|
||||
}
|
||||
for (OldRaid r : war.getRaids()) {
|
||||
r.stop();
|
||||
}
|
||||
|
||||
WarManager.getInstance().removeWar(war);
|
||||
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "War " + argWarName + " deleted.").build());
|
||||
Main.warLogger.log(p.getName() + " deleted " + argWarName);
|
||||
} else {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix()
|
||||
+ "Invalid Arguments. /war delete [name]").build());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param p - executor
|
||||
* @param args
|
||||
* @param admin - admin behavior
|
||||
*/
|
||||
protected static void warJoin(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
// Sufficient args check
|
||||
if (args.count() < 2)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix()
|
||||
+ "/war join [name] [side], type /war list to view current wars").build());
|
||||
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name.").build());
|
||||
|
||||
War war = WarManager.getInstance().getWar(argWarName);
|
||||
|
||||
if (war == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cWar not found. /war join [name] [side], type /war list to view current wars.").build());
|
||||
|
||||
if (!(args.get("side") instanceof final String argSide))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a side.").build());
|
||||
|
||||
if (!war.isSideValid(argSide))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThat side does not exist in that war.").build());
|
||||
|
||||
if (!(args.getOptional("player").orElse(null) instanceof @Nullable Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cPlayer not found.").build());
|
||||
|
||||
if (argPlayer == null) {
|
||||
argPlayer = p;
|
||||
}
|
||||
|
||||
// Towny Resident Object, if admin then dont use command runner, use declared player
|
||||
Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||
|
||||
// Town check
|
||||
Town town = res.getTownOrNull();
|
||||
if (town == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(ChatColor.RED + "You are not in a town.").build());
|
||||
}
|
||||
|
||||
//Minuteman countermeasures
|
||||
final int minuteman = CommandHelper.isPlayerMinuteman(argPlayer.getName());
|
||||
final boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
|
||||
|
||||
if (minuteManOverride) {
|
||||
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
}
|
||||
|
||||
//override?
|
||||
if (!minuteManOverride) {
|
||||
if (minuteman != 0) {
|
||||
if (minuteman == 1) {
|
||||
//player has joined to recently
|
||||
if (admin)
|
||||
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
argPlayer.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
return;
|
||||
} else if (minuteman == 2) {
|
||||
//player has played too little
|
||||
if (admin)
|
||||
p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
argPlayer.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Side checks
|
||||
final TownWarState side = war.getState(town.getName().toLowerCase());
|
||||
if (side == TownWarState.SURRENDERED) {
|
||||
argPlayer.sendMessage(UtilsChat.getPrefix() + "You've already surrendered!");
|
||||
return;
|
||||
} else if (side != TownWarState.NOT_PARTICIPANT) {
|
||||
argPlayer.sendMessage(UtilsChat.getPrefix() + "You're already in this war!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.hasNation()) {
|
||||
if (res.getPlayer().hasPermission("AlathraWar.nationjoin") || res.isKing()) {
|
||||
// Has nation declaration permission
|
||||
war.addNation(res.getNationOrNull(), argSide);
|
||||
res.getPlayer().sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getNationOrNull().getName());
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getNationOrNull().getName());
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The nation of " + res.getNationOrNull().getName() + " has joined the war on the side of " + argSide + "!");
|
||||
war.save();
|
||||
} else {
|
||||
// Cannot declare nation involvement
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot declare war for your nation.").build());
|
||||
}
|
||||
} else if (res.hasTown()) {
|
||||
if (res.getPlayer().hasPermission("AlathraWar.townjoin") || res.isMayor()) {
|
||||
// Is in indepdenent town & has declaration perms
|
||||
war.addTown(res.getTownOrNull(), argSide);
|
||||
res.getPlayer().sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getTownOrNull().getName());
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getTownOrNull().getName());
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + res.getTownOrNull().getName() + " has joined the war on the side of " + argSide + "!");
|
||||
war.save();
|
||||
} else {
|
||||
// No perms
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot declare war for your town.").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void warSurrender(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
// Sufficient args check
|
||||
if (args.count() < 1) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix()
|
||||
+ "/war surrender [name], type /war list to view current wars").build());
|
||||
}
|
||||
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name.").build());
|
||||
|
||||
// War check
|
||||
War war = WarManager.getInstance().getWar(argWarName);
|
||||
if (war == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix()
|
||||
+ "War not found. Type /war list to view current wars").build());
|
||||
}
|
||||
|
||||
if (!(args.get("reason") instanceof final String argReason))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a reason.").build());
|
||||
|
||||
if (!(args.getOptional("player").orElse(null) instanceof @Nullable Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cPlayer not found.").build());
|
||||
|
||||
if (argPlayer == null) {
|
||||
argPlayer = p;
|
||||
}
|
||||
|
||||
// Towny Resident Object
|
||||
Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||
|
||||
// Town check
|
||||
Town town = res.getTownOrNull();
|
||||
if (town == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(ChatColor.RED + "You are not in a town.").build());
|
||||
}
|
||||
|
||||
if (res.hasNation()) {
|
||||
if (p.hasPermission("AlathraWar.nationsurrender") || res.isKing() || admin) {
|
||||
// Has nation surrender permission
|
||||
war.surrenderNation(res.getNationOrNull());
|
||||
argPlayer.sendMessage(UtilsChat.getPrefix() + "You have surrendered the war for " + res.getNationOrNull().getName());
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The nation of " + res.getNationOrNull().getName() + " has surrendered! They were fighting for " + argReason + ".");
|
||||
war.save();
|
||||
} else {
|
||||
// Cannot surrender nation involvement
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot surrender war for your nation.").build());
|
||||
}
|
||||
} else if (res.hasTown()) {
|
||||
if (p.hasPermission("AlathraWar.townsurrender") || res.isMayor() || admin) {
|
||||
// Is in indepdenent town & has surrender perms
|
||||
war.surrenderTown(res.getTownOrNull().getName());
|
||||
argPlayer.sendMessage(UtilsChat.getPrefix() + "You have surrendered the war for " + res.getTownOrNull().getName());
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + res.getTownOrNull().getName() + " has surrendered! They were fighting for " + argReason + ".");
|
||||
war.save();
|
||||
} else {
|
||||
// No perms
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot surrender war for your town.").build());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void warList(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
ArrayList<War> wars = WarManager.getInstance().getWars();
|
||||
|
||||
if (wars.isEmpty()) {
|
||||
p.sendMessage("There are no current wars.");
|
||||
} else {
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Wars:");
|
||||
|
||||
for (War war : wars) {
|
||||
p.sendMessage(war.getName() + " - " + war.getSide1() + " (" + war.getSide1Points() + ") vs. " + war.getSide2() + " (" + war.getSide2Points() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void warInfo(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (args.count() < 1) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/war info [Player]").build());
|
||||
}
|
||||
|
||||
if (!(args.get("player") instanceof Player argsPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Specify a player.").build());
|
||||
|
||||
Resident res = TownyAPI.getInstance().getResident(argsPlayer);
|
||||
if (res == null || res.getTownOrNull() == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid town resident.").build());
|
||||
}
|
||||
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + p.getName() + "'s wars:").build());
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
TownWarState side = war.getState(res.getTownOrNull());
|
||||
if (side != TownWarState.NOT_PARTICIPANT) {
|
||||
if (side == TownWarState.SURRENDERED) {
|
||||
p.sendMessage(war.getName() + " - Surrendered");
|
||||
} else if (side == TownWarState.SIDE1) {
|
||||
p.sendMessage(war.getName() + " - " + war.getSide1());
|
||||
} else if (side == TownWarState.SIDE2) {
|
||||
p.sendMessage(war.getName() + " - " + war.getSide2());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void warHelp(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for console access
|
||||
*
|
||||
* @param sender
|
||||
* @param args
|
||||
*/
|
||||
// private static void consoleCommand(CommandSender sender, CommandArguments args) {
|
||||
// if (args.length < 1) return;
|
||||
// if (args[0].equalsIgnoreCase("list")) {
|
||||
// ArrayList<War> warList = WarManager.getInstance().getWars();
|
||||
// sender.sendMessage("Wars: " + warList.size());
|
||||
// for (War war : WarManager.getInstance().getWars()) {
|
||||
// if (war == null) continue;
|
||||
// sender.sendMessage(war.toString());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.conflict;
|
||||
|
||||
public enum ConflictType {
|
||||
WAR
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.conflict.battle;
|
||||
|
||||
public class Battle {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.conflict.battle;
|
||||
|
||||
public class Raid extends Battle {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.conflict.battle;
|
||||
|
||||
public class Siege extends Battle {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.holder;
|
||||
|
||||
public class Holder {
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockBreakListener implements Listener {
|
||||
|
||||
private static final Set<Material> allowedBlocks = new HashSet<>();
|
||||
|
||||
static {
|
||||
allowedBlocks.add(Material.TNT);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(final BlockBreakEvent event) {
|
||||
|
||||
final Block block = event.getBlock();
|
||||
if (SiegeData.getSieges().isEmpty() && RaidData.getRaids().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (final OldSiege oldSiege : SiegeData.getSieges()) {
|
||||
if (oldSiege.beaconLocs.contains(block.getLocation())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (allowedBlocks.contains(block.getType())) {
|
||||
return;
|
||||
}
|
||||
Player p = event.getPlayer();
|
||||
if (p.hasPermission("AlathraWar.break")) {
|
||||
return;
|
||||
}
|
||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
||||
for (final OldSiege oldSiege : SiegeData.getSieges()) {
|
||||
if (oldSiege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not break blocks during sieges"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (final OldRaid oldRaid : RaidData.getRaids()) {
|
||||
if (oldRaid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not break blocks during raids"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
final Block block = event.getBlock();
|
||||
if (SiegeData.getSieges().isEmpty() && RaidData.getRaids().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (allowedBlocks.contains(block.getType())) {
|
||||
return;
|
||||
}
|
||||
Player p = event.getPlayer();
|
||||
if (p.hasPermission("AlathraWar.place")) {
|
||||
return;
|
||||
}
|
||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
||||
for (final OldSiege oldSiege : SiegeData.getSieges()) {
|
||||
if (oldSiege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not place blocks during sieges"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (final OldRaid oldRaid : RaidData.getRaids()) {
|
||||
if (oldRaid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not place blocks during raids"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.hooks.TABHook;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
public static void checkPlayer(Player p) {
|
||||
Resident resident = TownyAPI.getInstance().getResident(p);
|
||||
if (resident == null) return;
|
||||
|
||||
Town town = resident.getTownOrNull();
|
||||
if (town == null) return;
|
||||
|
||||
String townName = town.getName();
|
||||
boolean inWar = false;
|
||||
|
||||
for (final OldWar oldWar : WarData.getWars()) {
|
||||
if (oldWar.getSide1Towns().contains(townName.toLowerCase())) {
|
||||
TABHook.assignSide1WarSuffix(p, oldWar);
|
||||
inWar = true;
|
||||
} else if (oldWar.getSide2Towns().contains(townName.toLowerCase())) {
|
||||
TABHook.assignSide2WarSuffix(p, oldWar);
|
||||
inWar = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inWar) {
|
||||
TABHook.resetPrefix(p);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final Player p = event.getPlayer();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package me.ShermansWorld.AlathraWar.utility;
|
||||
|
||||
public class UtilsChat {
|
||||
public static String getPrefix() {
|
||||
return "<dark_gray>[<gradient:#D72A09:#B01F03>War<dark_gray>] ";
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
package me.ShermansWorld.AlathranWars;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -6,26 +6,26 @@ import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class AlathraWarLogger {
|
||||
public class AlathranWarsLogger {
|
||||
|
||||
final File logsFolder;
|
||||
final File log;
|
||||
PrintWriter output = null;
|
||||
|
||||
public AlathraWarLogger() {
|
||||
logsFolder = new File("plugins" + File.separator + "AlathraWar" + File.separator + "logs");
|
||||
public AlathranWarsLogger() {
|
||||
logsFolder = new File("plugins" + File.separator + "AlathranWars" + File.separator + "logs");
|
||||
log = new File(
|
||||
"plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt");
|
||||
"plugins" + File.separator + "AlathranWars" + File.separator + "logs" + File.separator + "log.txt");
|
||||
}
|
||||
|
||||
public boolean checkFiles() {
|
||||
if (!logsFolder.exists()) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Error in AlathraWarLogger - could not find logs directory");
|
||||
Bukkit.getLogger().warning("[AlathranWars] Error in AlathranWarsLogger - could not find logs directory");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!log.exists()) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Error in AlathraWarLogger - could not find log.txt");
|
||||
Bukkit.getLogger().warning("[AlathranWars] Error in AlathranWarsLogger - could not find log.txt");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -36,12 +36,12 @@ public class AlathraWarLogger {
|
||||
// init file writer
|
||||
try {
|
||||
FileWriter fw = new FileWriter(
|
||||
"plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt",
|
||||
"plugins" + File.separator + "AlathranWars" + File.separator + "logs" + File.separator + "log.txt",
|
||||
true);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
output = new PrintWriter(bw);
|
||||
} catch (IOException e1) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Error in AlathraWarLogger - could not initialize file writer");
|
||||
Bukkit.getLogger().warning("[AlathranWars] Error in AlathranWarsLogger - could not initialize file writer");
|
||||
}
|
||||
}
|
||||
|
||||
+22
-22
@@ -1,21 +1,17 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
package me.ShermansWorld.AlathranWars;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.commands.CommandManager;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import me.ShermansWorld.AlathraWar.hooks.HookManager;
|
||||
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
|
||||
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 net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
public static Economy econ;
|
||||
public static AlathraWarLogger warLogger;
|
||||
public static AlathranWarsLogger warLogger;
|
||||
private static Main instance;
|
||||
|
||||
static {
|
||||
@@ -23,8 +19,8 @@ public class Main extends JavaPlugin {
|
||||
econ = null;
|
||||
}
|
||||
|
||||
private final CommandManager commandManager = new CommandManager(Main.getInstance());
|
||||
private final HookManager hookManager = new HookManager();
|
||||
private CommandManager commandManager;
|
||||
private HookManager hookManager;
|
||||
|
||||
@NotNull
|
||||
public static Main getInstance() {
|
||||
@@ -34,8 +30,8 @@ public class Main extends JavaPlugin {
|
||||
/**
|
||||
* Dangerous if done at the wrong time!
|
||||
*/
|
||||
public static void initData() {
|
||||
File userDataFolder = new File("plugins" + File.separator + "AlathraWar" + File.separator + "userdata");
|
||||
/*public static void initData() {
|
||||
File userDataFolder = new File("plugins" + File.separator + "AlathranWars" + File.separator + "userdata");
|
||||
if (!userDataFolder.exists()) {
|
||||
userDataFolder.mkdirs();
|
||||
}
|
||||
@@ -44,21 +40,21 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static void initLogs() {
|
||||
File logsFolder = new File("plugins" + File.separator + "AlathraWar" + File.separator + "logs");
|
||||
File logsFolder = new File("plugins" + File.separator + "AlathranWars" + File.separator + "logs");
|
||||
if (!logsFolder.exists()) {
|
||||
logsFolder.mkdirs();
|
||||
}
|
||||
File log = new File(
|
||||
"plugins" + File.separator + "AlathraWar" + File.separator + "logs" + File.separator + "log.txt");
|
||||
"plugins" + File.separator + "AlathranWars" + File.separator + "logs" + File.separator + "log.txt");
|
||||
if (!log.exists()) {
|
||||
try {
|
||||
log.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().warning("[AlathraWar] Encountered error when creating log file!");
|
||||
Bukkit.getLogger().warning("[AlathranWars] Encountered error when creating log file!");
|
||||
}
|
||||
}
|
||||
warLogger = new AlathraWarLogger();
|
||||
}
|
||||
warLogger = new AlathranWarsLogger();
|
||||
}*/
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private boolean setupEconomy() {
|
||||
@@ -77,6 +73,10 @@ public class Main extends JavaPlugin {
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Main.instance = this;
|
||||
WarManager.getInstance();
|
||||
commandManager = new CommandManager(Main.getInstance());
|
||||
hookManager = new HookManager();
|
||||
|
||||
commandManager.onLoad();
|
||||
hookManager.onLoad();
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class Main extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.saveDefaultConfig();
|
||||
initLogs();
|
||||
// initLogs();
|
||||
|
||||
//new WarData(this);
|
||||
// new TimeoutData(this);
|
||||
@@ -100,9 +100,9 @@ public class Main extends JavaPlugin {
|
||||
// //run second
|
||||
// new WarRecipeRegistry();
|
||||
|
||||
initData();
|
||||
// initData();
|
||||
setupEconomy();
|
||||
initLogs();
|
||||
// initLogs();
|
||||
|
||||
commandManager.onEnable();
|
||||
hookManager.onEnable();
|
||||
+54
-57
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
@@ -7,21 +7,18 @@ 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.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.conflict.War;
|
||||
import me.ShermansWorld.AlathraWar.conflict.battle.Side;
|
||||
import me.ShermansWorld.AlathraWar.enums.AdminCommandFailEnum;
|
||||
import me.ShermansWorld.AlathraWar.holder.WarManager;
|
||||
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
|
||||
import me.ShermansWorld.AlathraWar.utility.UtilsChat;
|
||||
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 net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AdminCommand {
|
||||
@@ -101,9 +98,9 @@ public class AdminCommand {
|
||||
* @param args Passed command arguments
|
||||
* @return Valid command
|
||||
*/
|
||||
new CommandAPICommand("alathrawaradmin")
|
||||
new CommandAPICommand("alathranwarsadmin")
|
||||
.withAliases("awa")
|
||||
.withPermission("AlathraWar.admin")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withSubcommands(
|
||||
commandItem(),
|
||||
// commandPurgeBars(),
|
||||
@@ -166,13 +163,13 @@ public class AdminCommand {
|
||||
private static boolean fail(CommandSender p, CommandArguments args, AdminCommandFailEnum type) throws WrapperCommandSyntaxException {
|
||||
switch (type) {
|
||||
case PERMISSIONS -> {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou do not have permission to do this.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You do not have permission to do this.").build());
|
||||
}
|
||||
case SYNTAX -> {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /alathrawaradmin help").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /alathranwarsadmin help").build());
|
||||
}
|
||||
default -> {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Something wrong. /alathrawaradmin help").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Something wrong. /alathranwarsadmin help").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,7 +202,7 @@ public class AdminCommand {
|
||||
.executesPlayer((Player sender, CommandArguments args) -> {
|
||||
// Parse item
|
||||
if (!(args.get("item") instanceof String argItem))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cInvalid item argument.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Invalid item argument.").build());
|
||||
|
||||
ItemStack stack;
|
||||
if (argItem.contains(Main.getInstance().getName().toLowerCase())) {
|
||||
@@ -215,7 +212,7 @@ public class AdminCommand {
|
||||
}
|
||||
|
||||
if (stack == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe item is not an AlathraWar item.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The item is not an AlathranWars item.").build());
|
||||
|
||||
// Parse amount
|
||||
int argAmount = (int) args.getOptional("amount").orElse(1);
|
||||
@@ -252,8 +249,8 @@ public class AdminCommand {
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "&cCleared all boss bars that have been registered with AlathraWar.");
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "&cNote: If any remain, please contact the plugin author or open an issue on GitHub. The data can be found under the tag CustomBossEvents: in level.dat! You will need an NBT Editing program to delete it manually.");
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "<red>Cleared all boss bars that have been registered with AlathranWars.");
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "<red>Note: If any remain, please contact the plugin author or open an issue on GitHub. The data can be found under the tag CustomBossEvents: in level.dat! You will need an NBT Editing program to delete it manually.");
|
||||
|
||||
saveAll(sender, args);
|
||||
});
|
||||
@@ -271,17 +268,17 @@ public class AdminCommand {
|
||||
)
|
||||
.executes((CommandSender sender, CommandArguments args) -> {
|
||||
if (!(args.get("war") instanceof final String argWarName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war name.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war name.").build());
|
||||
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
if (war.getName().equalsIgnoreCase(argWarName)) {
|
||||
WarManager.getInstance().saveWar(war);
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "&cForced Save of war: " + war.getName());
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "<red>Forced Save of war: " + war.getName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "&cWar does not exist!");
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "<red>War does not exist!");
|
||||
});
|
||||
}*/
|
||||
|
||||
@@ -289,14 +286,14 @@ public class AdminCommand {
|
||||
return new CommandAPICommand("save-all")
|
||||
.executes((CommandSender sender, CommandArguments args) -> {
|
||||
for (War war : WarManager.getInstance().getWars()) WarManager.getInstance().saveWar(war);
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "&cForced Save of all wars");
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "<red>Forced Save of all wars");
|
||||
});
|
||||
}*/
|
||||
|
||||
private CommandAPICommand commandLoad() {
|
||||
return new CommandAPICommand("load")
|
||||
.executes((CommandSender sender, CommandArguments args) -> {
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "&cSupport for loading wars individually is currently unimplemented. Use /awa load-all instead").build());
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>Support for loading wars individually is currently unimplemented. Use /awa load-all instead").build());
|
||||
});
|
||||
|
||||
/*if (args.length >= 3) {
|
||||
@@ -317,12 +314,12 @@ public class AdminCommand {
|
||||
WarManager.getInstance().getWars().remove(war);
|
||||
}
|
||||
if(index < 0) {
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "&cError! Failed to delete war, forcing end."));
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "<red>Error! Failed to delete war, forcing end."));
|
||||
return true;
|
||||
}
|
||||
//reload data
|
||||
;
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "&cForcefully Reloaded all Wars!"));
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "<red>Forcefully Reloaded all Wars!"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -353,7 +350,7 @@ public class AdminCommand {
|
||||
|
||||
//reload data
|
||||
Main.initData();
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "&cForcefully Reloaded all Wars!");
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "<red>Forcefully Reloaded all Wars!");
|
||||
}
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "Are you sure you want to do this?");
|
||||
@@ -383,7 +380,7 @@ public class AdminCommand {
|
||||
),
|
||||
new StringArgument("gathertown")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> { // TODO Make getHostileTowns method where we reverse from list
|
||||
final String warname = (String) info.previousArgs().get("war");
|
||||
@@ -393,10 +390,10 @@ public class AdminCommand {
|
||||
),
|
||||
new PlayerArgument("leader")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin"),
|
||||
.withPermission("AlathranWars.admin"),
|
||||
new BooleanArgument("minutemen")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin")
|
||||
.withPermission("AlathranWars.admin")
|
||||
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> RaidCommand.raidStart(p, args, true)),*/
|
||||
@@ -406,16 +403,16 @@ public class AdminCommand {
|
||||
CommandUtil.customTownInWarArgument("town", "war"),
|
||||
new PlayerArgument("leader")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin"),
|
||||
.withPermission("AlathranWars.admin"),
|
||||
new BooleanArgument("minutemen")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathraWar.admin")
|
||||
.withPermission("AlathranWars.admin")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> SiegeCommand.siegeStart(p, args, true)),
|
||||
new CommandAPICommand("war")
|
||||
.withArguments(
|
||||
CommandUtil.warSideCreateArgument("side1", "war", true, false, ""),
|
||||
CommandUtil.warSideCreateArgument("side2", "war", true, false, ""),
|
||||
CommandUtil.customTownAndNationsArgument("side1", "war", true),
|
||||
CommandUtil.customTownAndNationsArgument("side2", "war", true),
|
||||
new GreedyStringArgument("warlabel")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> List.of(
|
||||
@@ -444,7 +441,7 @@ public class AdminCommand {
|
||||
.setOptional(true)
|
||||
).executesPlayer((Player sender, CommandArguments args) -> {
|
||||
//TODO determine if needed
|
||||
sender.sendMessage("&cUnused! use /war delete");
|
||||
sender.sendMessage("<red>Unused! use /war delete");
|
||||
})/*,
|
||||
new CommandAPICommand("siege") // TODO Very needed
|
||||
.withArguments(
|
||||
@@ -471,15 +468,15 @@ public class AdminCommand {
|
||||
|
||||
).executesPlayer((Player sender, CommandArguments args) -> {
|
||||
if (!(args.get("oldSiege") instanceof final String argSiegeName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a oldSiege!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a oldSiege!").build());
|
||||
|
||||
final Siege oldSiege = SiegeData.getSiege(argSiegeName);
|
||||
if (oldSiege == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThat oldSiege does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That oldSiege does not exist!").build());
|
||||
|
||||
final War war = oldSiege.getWar();
|
||||
if (war == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe war does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").build());
|
||||
|
||||
final String argSide = (String) args.getOptional("victor").orElse("none");
|
||||
|
||||
@@ -540,15 +537,15 @@ public class AdminCommand {
|
||||
)
|
||||
).executesPlayer((Player sender, CommandArguments args) -> {
|
||||
if (!(args.get("oldRaid") instanceof final String argRaidName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a oldRaid name!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a oldRaid name!").build());
|
||||
|
||||
final OldRaid oldRaid = RaidData.getRaid(argRaidName);
|
||||
if (oldRaid == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThat oldRaid does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That oldRaid does not exist!").build());
|
||||
|
||||
final War war = oldRaid.getWar();
|
||||
if (war == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe war does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").build());
|
||||
|
||||
final String argSide = (String) args.getOptional("victor").orElse("none");
|
||||
|
||||
@@ -618,7 +615,7 @@ public class AdminCommand {
|
||||
return war.getSides();
|
||||
})
|
||||
)*/
|
||||
).executesPlayer((Player sender, CommandArguments args) -> WarCommand.warJoin(sender, args, true))/*,
|
||||
).executesPlayer((Player sender, CommandArguments args) -> WarCommand.warJoinPlayer(sender, args, true))/*,
|
||||
new CommandAPICommand("siege") // TODO Very needed
|
||||
.withArguments(
|
||||
new PlayerArgument("player"),
|
||||
@@ -642,7 +639,7 @@ public class AdminCommand {
|
||||
})
|
||||
)
|
||||
).executesPlayer((Player sender, CommandArguments args) -> {
|
||||
sender.sendMessage("&cError! Unimplemented!");
|
||||
sender.sendMessage("<red>Error! Unimplemented!");
|
||||
// TODO implement siege force joining?
|
||||
})*/ /*,
|
||||
new CommandAPICommand("raid")
|
||||
@@ -734,11 +731,11 @@ public class AdminCommand {
|
||||
)
|
||||
.executes((CommandSender sender, CommandArguments args) -> {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war!").build());
|
||||
|
||||
// final War war = WarManager.getInstance().getWar(argWarName);
|
||||
// if (war == null)
|
||||
// throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThat war does not exist!").build());
|
||||
// throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That war does not exist!").build());
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "Info dump for war: " + war.getName());
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "oOo------------===------------oOo");
|
||||
@@ -807,11 +804,11 @@ public class AdminCommand {
|
||||
)
|
||||
.executes((CommandSender sender, CommandArguments args) -> { // TODO Needed
|
||||
if (!(args.get("oldSiege") instanceof final String argSiegeName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a oldSiege!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a oldSiege!").build());
|
||||
|
||||
final Siege oldSiege = SiegeData.getSiege(argSiegeName);
|
||||
if (oldSiege == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThat oldSiege does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That oldSiege does not exist!").build());
|
||||
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "Info dump for oldSiege: " + oldSiege.getName());
|
||||
@@ -858,11 +855,11 @@ public class AdminCommand {
|
||||
)
|
||||
.executes((CommandSender sender, CommandArguments args) -> {
|
||||
if (!(args.get("oldRaid") instanceof final String argRaidName))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a oldRaid name!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a oldRaid name!").build());
|
||||
|
||||
final OldRaid oldRaid = RaidData.getRaid(argRaidName);
|
||||
if (oldRaid == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThat oldRaid does not exist!").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>That oldRaid does not exist!").build());
|
||||
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "Info dump for oldRaid: " + oldRaid.getName());
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "oOo------------===------------oOo");
|
||||
@@ -895,7 +892,7 @@ public class AdminCommand {
|
||||
/*private void saveAll(CommandSender sender, CommandArguments args) {
|
||||
for (War war : WarManager.getInstance().getWars())
|
||||
WarManager.getInstance().saveWar(war);
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "&cForced Save of all wars.");
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "<red>Forced Save of all wars.");
|
||||
}*/
|
||||
|
||||
/**
|
||||
@@ -951,16 +948,16 @@ public class AdminCommand {
|
||||
new IntegerArgument("amount", 1, 10000)
|
||||
).executesPlayer((Player p, CommandArguments args) -> {
|
||||
if (!(args.get("action") instanceof final String argAction))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify an action.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify an action.").build());
|
||||
|
||||
if (!List.of("add", "subtract", "set").contains(argAction))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cInvalid action.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Invalid action.").build());
|
||||
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe 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))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe side does not exist.").build());
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The side does not exist.").build());
|
||||
|
||||
final int amount = (int) args.get("amount");
|
||||
|
||||
@@ -973,7 +970,7 @@ public class AdminCommand {
|
||||
}
|
||||
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Added " + amount + " points to the war in the war " + war.getName() + " on side " + side);
|
||||
Main.warLogger.log("Added " + amount + " points to the war in the war " + war.getName() + " on side " + side);
|
||||
// Main.warLogger.log("Added " + amount + " points to the war in the war " + war.getName() + " on side " + side);
|
||||
}
|
||||
case "subtract" -> {
|
||||
if (war.getSide1().equals(side)) {
|
||||
@@ -983,7 +980,7 @@ public class AdminCommand {
|
||||
}
|
||||
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Subtracted " + amount + " points to the war score in the war " + war.getName() + " on side " + side);
|
||||
Main.warLogger.log("Subtracted " + amount + " points to the war score in the war " + war.getName() + " on side " + side);
|
||||
// Main.warLogger.log("Subtracted " + amount + " points to the war score in the war " + war.getName() + " on side " + side);
|
||||
}
|
||||
case "set" -> {
|
||||
if (war.getSide1().equals(side)) {
|
||||
@@ -993,7 +990,7 @@ public class AdminCommand {
|
||||
}
|
||||
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Set " + amount + " points as the war score in the war " + war.getName() + " on side " + side);
|
||||
Main.warLogger.log("Set " + amount + " points as the war score in the war " + war.getName() + " on side " + side);
|
||||
// Main.warLogger.log("Set " + amount + " points as the war score in the war " + war.getName() + " on side " + side);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import dev.jorel.commandapi.CommandAPIBukkitConfig;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
|
||||
public class CommandManager {
|
||||
private final Main instance;
|
||||
@@ -21,7 +21,7 @@ public class CommandManager {
|
||||
// Register commands
|
||||
new WarCommand();
|
||||
new SiegeCommand();
|
||||
new RaidCommand();
|
||||
// new RaidCommand();
|
||||
new AdminCommand();
|
||||
}
|
||||
|
||||
+103
-39
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
@@ -10,13 +10,14 @@ import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||
import dev.jorel.commandapi.arguments.CustomArgument;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.conflict.War;
|
||||
import me.ShermansWorld.AlathraWar.conflict.battle.Side;
|
||||
import me.ShermansWorld.AlathraWar.holder.WarManager;
|
||||
import me.ShermansWorld.AlathraWar.hooks.TownyHook;
|
||||
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
|
||||
import me.ShermansWorld.AlathraWar.utility.UtilsChat;
|
||||
import 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 org.bukkit.Bukkit;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -51,7 +52,7 @@ public class CommandUtil {
|
||||
final String argNationName = info.input();
|
||||
|
||||
if (TownyAPI.getInstance().getNation(argNationName) == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
|
||||
|
||||
return TownyAPI.getInstance().getNation(argNationName);
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
@@ -70,7 +71,7 @@ public class CommandUtil {
|
||||
final String argTownName = info.input();
|
||||
|
||||
if (TownyAPI.getInstance().getTown(argTownName) == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
|
||||
return TownyAPI.getInstance().getTown(argTownName);
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
@@ -89,7 +90,7 @@ public class CommandUtil {
|
||||
final String argNationName = info.input();
|
||||
|
||||
if (TownyAPI.getInstance().getNation(argNationName) == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
|
||||
|
||||
if (!hideNationsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return TownyAPI.getInstance().getNation(argNationName);
|
||||
@@ -99,7 +100,7 @@ public class CommandUtil {
|
||||
if (war.getNations().contains(nation) || war.getSurrenderedNations().contains(nation))
|
||||
return nation;
|
||||
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation is already at war!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation is already at war!").parseLegacy().build());
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> nationNames = TownyHook.getNations()
|
||||
.stream()
|
||||
@@ -134,7 +135,7 @@ public class CommandUtil {
|
||||
final String argTownName = info.input();
|
||||
|
||||
if (TownyAPI.getInstance().getTown(argTownName) == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
|
||||
if (!hideTownsInWar || !(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return TownyAPI.getInstance().getTown(argTownName);
|
||||
@@ -144,7 +145,7 @@ public class CommandUtil {
|
||||
if (war.getTowns().contains(town) || war.getSurrenderedTowns().contains(town))
|
||||
return town;
|
||||
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town is already at war!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town is already at war!").parseLegacy().build());
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> townNames = TownyHook.getTowns()
|
||||
.stream()
|
||||
@@ -170,15 +171,15 @@ public class CommandUtil {
|
||||
static public Argument<Nation> customNationInWarArgument(String nodeName, String warNodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe war does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").parseLegacy().build());
|
||||
|
||||
Nation nation = TownyAPI.getInstance().getNation(info.input());
|
||||
|
||||
if (nation == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation does not exist!").parseLegacy().build());
|
||||
|
||||
if (!war.isNationInWar(nation))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe nation is not in that war!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The nation is not in that war!").parseLegacy().build());
|
||||
|
||||
return nation;
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
@@ -195,15 +196,15 @@ public class CommandUtil {
|
||||
static public Argument<Town> customTownInWarArgument(String nodeName, String warNodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe war does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").parseLegacy().build());
|
||||
|
||||
Town town = TownyAPI.getInstance().getTown(info.input());
|
||||
|
||||
if (town == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
|
||||
if (!war.isTownInWar(town))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town is not in that war!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town is not in that war!").parseLegacy().build());
|
||||
|
||||
return town;
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
@@ -217,17 +218,29 @@ public class CommandUtil {
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Accepts all towns and nations as argument. Returns a string.
|
||||
*
|
||||
* @param nodeName the node name
|
||||
* @param warNodeName the war node name
|
||||
* @param hideTownsInWar the hide towns in war
|
||||
* @return the argument
|
||||
*/
|
||||
static public Argument<String> customTownAndNationsArgument(String nodeName, String warNodeName, boolean hideTownsInWar) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
final String argTownOrNationName = info.input();
|
||||
|
||||
if (TownyAPI.getInstance().getTown(argTownOrNationName) != null)
|
||||
return TownyAPI.getInstance().getTown(argTownOrNationName).getName();
|
||||
@Nullable Town town = TownyAPI.getInstance().getTown(argTownOrNationName);
|
||||
|
||||
if (TownyAPI.getInstance().getNation(argTownOrNationName) != null)
|
||||
return TownyAPI.getInstance().getNation(argTownOrNationName).getName();
|
||||
if (town != null)
|
||||
return town.getName();
|
||||
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe town or nation does not exist!").parseLegacy().build());
|
||||
@Nullable Nation nation = TownyAPI.getInstance().getNation(argTownOrNationName);
|
||||
if (nation != null)
|
||||
return nation.getName();
|
||||
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town or nation does not exist!").parseLegacy().build());
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
final List<String> nationNames = TownyHook.getNations()
|
||||
.stream()
|
||||
@@ -289,6 +302,57 @@ public class CommandUtil {
|
||||
}));
|
||||
}*/
|
||||
|
||||
public static Argument<Town> customSiegeAttackableTownArgument(String nodeName, String warNodeName, final boolean checkIfIn, final boolean checkIfSieged) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war does not exist!").parseLegacy().build());
|
||||
|
||||
Town town = TownyAPI.getInstance().getTown(info.input());
|
||||
|
||||
if (town == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town does not exist!").parseLegacy().build());
|
||||
|
||||
if (!war.isTownInWar(town))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town is not in that war!").parseLegacy().build());
|
||||
|
||||
if (checkIfSieged) {
|
||||
for (War war2 : WarManager.getInstance().getWars()) {
|
||||
for (Siege siege : war2.getSieges()) {
|
||||
if (siege.getTown().getUUID() == town.getUUID())
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The town is already under siege!").parseLegacy().build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return town;
|
||||
}).replaceSuggestions(ArgumentSuggestions.stringCollection(info -> {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
return Collections.emptyList();
|
||||
|
||||
final List<String> townNames = new ArrayList<>();
|
||||
|
||||
if (info.sender() instanceof Player p) {
|
||||
if (war.getSide1().isPlayerOnSide(p)) {
|
||||
townNames.addAll(war.getSide2().getTowns()
|
||||
.stream()
|
||||
.map(TownyObject::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
} else if (war.getSide2().isPlayerOnSide(p)) {
|
||||
townNames.addAll(war.getSide1().getTowns()
|
||||
.stream()
|
||||
.map(TownyObject::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return townNames;
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
public static Argument<War> warWarArgument(String nodeName, final boolean isAdmin, final boolean checkIfIn, final String playerNodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
@@ -296,21 +360,21 @@ public class CommandUtil {
|
||||
|
||||
final War war = WarManager.getInstance().getWar(argWarName);
|
||||
if (war == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe war <war> does not exist!").parseLegacy().parseMinimessagePlaceholder("war", argWarName).build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The war <war> does not exist!").parseLegacy().parseMinimessagePlaceholder("war", argWarName).build());
|
||||
|
||||
if (checkIfIn) {
|
||||
if (isAdmin) {
|
||||
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe player does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The player does not exist!").parseLegacy().build());
|
||||
|
||||
if (war.isPlayerInWar(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe player is already in that war.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The player is already in that war.").parseLegacy().build());
|
||||
} else {
|
||||
if (!(info.sender() instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cOnly players can execute this command!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Only players can execute this command!").parseLegacy().build());
|
||||
|
||||
if (war.isPlayerInWar(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou are already in this war.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You are already in this war.").parseLegacy().build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,31 +410,31 @@ public class CommandUtil {
|
||||
public static Argument<Side> warSideCreateArgument(final String nodeName, final String warNodeName, final boolean isAdmin, final boolean checkIfIn, final String playerNodeName) {
|
||||
return new CustomArgument<>(new StringArgument(nodeName), info -> {
|
||||
if (!(info.previousArgs().get(warNodeName) instanceof War war))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou need to specify a war.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war.").parseLegacy().build());
|
||||
|
||||
final String argSideName = info.input();
|
||||
|
||||
if (!war.isSideValid(argSideName))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe side does not exist.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The side does not exist.").parseLegacy().build());
|
||||
|
||||
final Side side = war.getSide(argSideName);
|
||||
|
||||
if (side == null)
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe side is invalid.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The side is invalid.").parseLegacy().build());
|
||||
|
||||
if (checkIfIn) {
|
||||
if (isAdmin) {
|
||||
if (!(info.previousArgs().get(playerNodeName) instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe player does not exist!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The player does not exist!").parseLegacy().build());
|
||||
|
||||
if (side.getPlayers().contains(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cThe player is already on that side.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>The player is already on that side.").parseLegacy().build());
|
||||
} else {
|
||||
if (!(info.sender() instanceof Player player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cOnly players can execute this command!").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Only players can execute this command!").parseLegacy().build());
|
||||
|
||||
if (side.getPlayers().contains(player))
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cYou are already on that side.").parseLegacy().build());
|
||||
throw CustomArgument.CustomArgumentException.fromAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You are already on that side.").parseLegacy().build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,9 +499,9 @@ public class CommandUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* return list of all alathrawar items with namespace
|
||||
* return list of all alathranwars items with namespace
|
||||
*
|
||||
* @return list of all alathrawar items namespaced
|
||||
* @return list of all alathranwars items namespaced
|
||||
*/
|
||||
public static List<String> getWarItems() {
|
||||
return new ArrayList<>(WarItemRegistry.getInstance().getItemRegistry().keySet());
|
||||
@@ -0,0 +1,312 @@
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
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 java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class SiegeCommand {
|
||||
public SiegeCommand() {
|
||||
new CommandAPICommand("siege")
|
||||
.withSubcommands(
|
||||
commandStart(),
|
||||
commandStop(),
|
||||
commandAbandon(),
|
||||
commandList(),
|
||||
commandHelp()
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /siege help").build());
|
||||
})
|
||||
.register();
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandStart() {
|
||||
return new CommandAPICommand("start")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument(
|
||||
"war",
|
||||
false,
|
||||
false,
|
||||
""
|
||||
),
|
||||
CommandUtil.customSiegeAttackableTownArgument(
|
||||
"town",
|
||||
"war",
|
||||
false,
|
||||
false
|
||||
),
|
||||
new PlayerArgument("leader")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathranWars.admin"),
|
||||
new BooleanArgument("minutemen")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathranWars.admin")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> siegeStart(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandStop() {
|
||||
return new CommandAPICommand("stop")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument(
|
||||
"war",
|
||||
false,
|
||||
false,
|
||||
""
|
||||
),
|
||||
CommandUtil.customSiegeAttackableTownArgument(
|
||||
"town",
|
||||
"war",
|
||||
false,
|
||||
false
|
||||
)
|
||||
)
|
||||
.executesPlayer(SiegeCommand::siegeStop);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandAbandon() {
|
||||
return new CommandAPICommand("abandon")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument(
|
||||
"war",
|
||||
false,
|
||||
false,
|
||||
""
|
||||
),
|
||||
CommandUtil.customSiegeAttackableTownArgument(
|
||||
"town",
|
||||
"war",
|
||||
false,
|
||||
false
|
||||
)
|
||||
)
|
||||
.executesPlayer(SiegeCommand::siegeAbandon);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandList() {
|
||||
return new CommandAPICommand("list")
|
||||
.executesPlayer(SiegeCommand::siegeList);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandHelp() {
|
||||
return new CommandAPICommand("help")
|
||||
.executesPlayer(SiegeCommand::siegeHelp);
|
||||
}
|
||||
|
||||
|
||||
protected static void siegeStart(Player sender, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
|
||||
if (!(args.get("town") instanceof final Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
|
||||
//if this is admin mode use the forth arg instad of sender.
|
||||
//if player is null after this then force end
|
||||
final Player siegeOwner = (Player) args.getOptional("leader").orElse(sender);
|
||||
|
||||
if (siegeOwner == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("You need to pick a valid leader.").build());
|
||||
|
||||
// Player participance check
|
||||
Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
|
||||
Side side = war.getTownSide(leaderTown);
|
||||
|
||||
// TODO DEBUG PRINT
|
||||
// Main.warLogger.log("Leader Town: " + leaderTown.getName());
|
||||
// Main.warLogger.log("Siege Owner: " + siegeOwner.getName());
|
||||
// sender.sendMessage("Leader Town: " + leaderTown.getName());
|
||||
// sender.sendMessage("Siege Owner: " + siegeOwner.getName());
|
||||
|
||||
// TODO DEBUG PRINT
|
||||
/*for (String t : war.getSide1Towns()) {
|
||||
Main.warLogger.log("Side1 town: " + t);
|
||||
sender.sendMessage("Side1 town: " + t);
|
||||
}
|
||||
for (String t : war.getSide2Towns()) {
|
||||
Main.warLogger.log("Side2 town: " + t);
|
||||
sender.sendMessage("Side2 town: " + t);
|
||||
}*/
|
||||
|
||||
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.");
|
||||
return;
|
||||
} else if (side.isTownSurrendered(leaderTown)) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
|
||||
if (admin) sender.sendMessage(UtilsChat.getPrefix() + "You have surrendered.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
|
||||
//Minuteman countermeasures
|
||||
/*int minuteman = CommandHelper.isPlayerMinuteman(siegeOwner.getName());
|
||||
boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
|
||||
|
||||
if (minuteManOverride) {
|
||||
sender.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
}
|
||||
|
||||
//override?
|
||||
if (!minuteManOverride) {
|
||||
if (minuteman != 0) {
|
||||
if (minuteman == 1) {
|
||||
//player has joined to recently
|
||||
if (admin)
|
||||
sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
siegeOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
return;
|
||||
} else if (minuteman == 2) {
|
||||
//player has played too little
|
||||
if (admin)
|
||||
sender.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
siegeOwner.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// Is being raided check
|
||||
/*for (OldRaid r : RaidData.getRaids()) {
|
||||
if (r.getRaidedTown().getName().equalsIgnoreCase(town.getName())) {
|
||||
siegeOwner.sendMessage(UtilsChat.getPrefix() + "That town is already currently being raided! Cannot siege at this time!");
|
||||
if (admin)
|
||||
sender.sendMessage(UtilsChat.getPrefix() + "That town is already currently being raided! Cannot siege at this time!");
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
// 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.");
|
||||
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() + "!");
|
||||
|
||||
if (admin)
|
||||
sender.sendMessage("<red>Forcefully started siege from the console.");
|
||||
|
||||
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 {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
|
||||
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());
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The siege at " + siege.getTown().getName() + " has been cancelled by an admin.").build());
|
||||
//siege.clearBeacon();
|
||||
siege.stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "A siege could not be found with this town name! Type /siege list to view current sieges").build());
|
||||
}
|
||||
|
||||
private static void siegeAbandon(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war.").build());
|
||||
|
||||
if (!(args.get("town") instanceof final Town town))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a town.").build());
|
||||
|
||||
Siege siege = null;
|
||||
|
||||
for (Siege siegeVar : war.getSieges()) {
|
||||
if (siegeVar.getTown().getUUID().equals(town.getUUID())) {
|
||||
siege = siegeVar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (siege == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid siege").build());
|
||||
|
||||
OfflinePlayer oPlayer = siege.getSiegeLeader();
|
||||
if (oPlayer != p) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You are not the leader of this siege.").build());
|
||||
}
|
||||
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The siege at " + siege.getTown().getName() + " has been abandoned.").build());
|
||||
// Main.warLogger.log(p.getName() + " abandoned the siege they started at " + siege.getTown().getName());
|
||||
siege.defendersWin();
|
||||
}
|
||||
|
||||
private static void siegeList(Player sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
Set<War> wars = WarManager.getInstance().getWars();
|
||||
|
||||
Set<Siege> sieges = new HashSet<>();
|
||||
|
||||
for (War war : wars) {
|
||||
sieges.addAll(war.getSieges());
|
||||
}
|
||||
|
||||
if (sieges.isEmpty())
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>There are currently no sieges in progress.").build());
|
||||
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Sieges currently in progress:").build());
|
||||
|
||||
for (Siege siege : sieges) {
|
||||
War war = siege.getWar();
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
private static void siegeHelp(Player sender, CommandArguments args) {
|
||||
if (sender.hasPermission("AlathranWars.admin")) {
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege stop [war] [town]").build());
|
||||
}
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege start [war] [town]").build());
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege abandon [war] [town]").build());
|
||||
sender.sendMessage(new ColorParser(UtilsChat.getPrefix() + "/siege list").build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
package me.ShermansWorld.AlathranWars.commands;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||
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 net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class WarCommand {
|
||||
public WarCommand() {
|
||||
new CommandAPICommand("war")
|
||||
.withSubcommands(
|
||||
commandCreate(),
|
||||
commandDelete(),
|
||||
commandJoin(),
|
||||
commandSurrender(),
|
||||
commandList(),
|
||||
// commandInfo(),
|
||||
commandHelp()
|
||||
)
|
||||
.executesPlayer((sender, args) -> {
|
||||
if (args.count() == 0)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid Arguments. /war help").build());
|
||||
})
|
||||
.register();
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandCreate() {
|
||||
return new CommandAPICommand("create")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withArguments(
|
||||
CommandUtil.customTownAndNationsArgument("side1", "war", false),
|
||||
CommandUtil.customTownAndNationsArgument("side2", "war", false),
|
||||
new GreedyStringArgument("warlabel")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.stringCollection(info -> List.of(
|
||||
"Nations War of Conquest",
|
||||
"Nations War for Survival",
|
||||
"Nations War of Liberation"
|
||||
))
|
||||
)
|
||||
)
|
||||
.executesPlayer(WarCommand::warCreate);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandDelete() {
|
||||
return new CommandAPICommand("delete")
|
||||
.withPermission("AlathranWars.admin")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument("war", false, false, "")
|
||||
)
|
||||
.executesPlayer(WarCommand::warDelete);
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandJoin() {
|
||||
return new CommandAPICommand("join")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument("war", false, true, ""),
|
||||
CommandUtil.warSideCreateArgument("side", "war", false, true, ""),
|
||||
new PlayerArgument("player").setOptional(true).withPermission("AlathranWars.admin")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> warJoinPlayer(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandSurrender() {
|
||||
return new CommandAPICommand("surrender")
|
||||
.withArguments(
|
||||
CommandUtil.warWarArgument("war", false, false, "player"),
|
||||
new PlayerArgument("player")
|
||||
.setOptional(true)
|
||||
.withPermission("AlathranWars.admin")
|
||||
)
|
||||
.executesPlayer((Player p, CommandArguments args) -> warSurrender(p, args, false));
|
||||
}
|
||||
|
||||
public static CommandAPICommand commandList() {
|
||||
return new CommandAPICommand("list")
|
||||
.executesPlayer(WarCommand::warList);
|
||||
}
|
||||
|
||||
/*public static CommandAPICommand commandInfo() {
|
||||
return new CommandAPICommand("info")
|
||||
.withArguments(
|
||||
new PlayerArgument("player")
|
||||
)
|
||||
.executesPlayer(WarCommand::warInfo);
|
||||
}*/
|
||||
|
||||
public static CommandAPICommand commandHelp() {
|
||||
return new CommandAPICommand("help")
|
||||
.executesPlayer(WarCommand::warHelp);
|
||||
}
|
||||
|
||||
protected static void warCreate(CommandSender p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("warlabel") instanceof final String argLabel))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war label.").build());
|
||||
|
||||
if (Objects.equals(args.get("side1"), args.get("side2")))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Cannot declare war on oneself.").build());
|
||||
|
||||
String townName1 = (String) args.get("side1");
|
||||
String townName2 = (String) args.get("side2");
|
||||
|
||||
// Create new war depending on what argument was specified
|
||||
@Nullable Town town1 = TownyAPI.getInstance().getTown(townName1);
|
||||
@Nullable Town town2 = TownyAPI.getInstance().getTown(townName2);
|
||||
@Nullable Nation nation1 = TownyAPI.getInstance().getNation(townName1);
|
||||
@Nullable Nation nation2 = TownyAPI.getInstance().getNation(townName2);
|
||||
|
||||
// Automatically elevate town wars to nation level if possible (This may be undesirable in terms of allowing civil wars etc)
|
||||
if (town1 != null && town1.getNationOrNull() != null) {
|
||||
nation1 = town1.getNationOrNull();
|
||||
}
|
||||
|
||||
if (town2 != null && town2.getNationOrNull() != null) {
|
||||
nation2 = town2.getNationOrNull();
|
||||
}
|
||||
|
||||
// TODO Ensure side1 valid
|
||||
// TODO Ensure side2 valid
|
||||
// TODO Deep Check if war exists where the same sides are fighting???
|
||||
|
||||
// Create war depending on what args have been passed, attempt to create nation wars first
|
||||
if (nation1 != null) {
|
||||
if (nation2 != null) {
|
||||
new War(argLabel, nation1, nation2);
|
||||
} else if (town2 != null) {
|
||||
new War(argLabel, nation1, town2);
|
||||
}
|
||||
} else if (town1 != null) {
|
||||
if (town2 != null) {
|
||||
new War(argLabel, town1, town2);
|
||||
} else if (nation2 != null) {
|
||||
new War(argLabel, town1, nation2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*for (War war1 : WarManager.getInstance().getWars()) {
|
||||
war.
|
||||
}*/
|
||||
|
||||
|
||||
// Check if side1 is nation or town
|
||||
// Check if side2 is nation or town
|
||||
// Check if opposing factions are already at war?
|
||||
|
||||
/*Main.warLogger.log(p.getName() + " created a new war with the name " + argWarName + ", " + argSide1
|
||||
+ " vs. " + argSide2);*/
|
||||
|
||||
}
|
||||
|
||||
private static void warDelete(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
War war = (War) args.get("war");
|
||||
|
||||
war.draw();
|
||||
// Main.warLogger.log(p.getName() + " deleted " + argWarName);
|
||||
}
|
||||
|
||||
protected static void warJoinPlayer(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war name.").build());
|
||||
|
||||
if (!(args.get("side") instanceof final Side side))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a side.").build());
|
||||
|
||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
|
||||
if (war.isPlayerInWar(argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You are already in this war.").build());
|
||||
|
||||
argPlayer.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You have joined the war.").build());
|
||||
side.addPlayer(argPlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param p - executor
|
||||
* @param args
|
||||
* @param admin - admin behavior
|
||||
*/
|
||||
protected static void warJoin(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
if (!(args.get("war") instanceof final War war))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a war name.").build());
|
||||
|
||||
if (!(args.get("side") instanceof final Side side))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>You need to specify a side.").build());
|
||||
|
||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
|
||||
// Towny Resident Object, if admin then dont use command runner, use declared player
|
||||
Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||
|
||||
// Town check
|
||||
Town town = res.getTownOrNull();
|
||||
if (town == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(ChatColor.RED + "You are not in a town.").build());
|
||||
}
|
||||
|
||||
//Minuteman countermeasures
|
||||
// final int minuteman = CommandHelper.isPlayerMinuteman(argPlayer.getName());
|
||||
// final boolean minuteManOverride = (boolean) args.getOptional("minutemen").orElse(false);
|
||||
//
|
||||
// if (minuteManOverride) {
|
||||
// p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
|
||||
// }
|
||||
//
|
||||
// //override?
|
||||
// if (!minuteManOverride) {
|
||||
// if (minuteman != 0) {
|
||||
// if (minuteman == 1) {
|
||||
// //player has joined to recently
|
||||
// if (admin)
|
||||
// p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
// argPlayer.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayerAge") + " days from joining.");
|
||||
// return;
|
||||
// } else if (minuteman == 2) {
|
||||
// //player has played too little
|
||||
// if (admin)
|
||||
// p.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
// argPlayer.sendMessage(ChatColor.RED + "You have not played enough! You can only join a raid after " + Main.getInstance().getConfig().getInt("minimumPlayTime") + " hours of play.");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Side checks
|
||||
if (war.getSurrenderedTowns().contains(town)) {
|
||||
argPlayer.sendMessage(UtilsChat.getPrefix() + "You've already surrendered!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.hasNation()) {
|
||||
if (res.getPlayer().hasPermission("AlathranWars.nationjoin") || res.isKing()) {
|
||||
// Has nation declaration permission
|
||||
side.addNation(res.getNationOrNull());
|
||||
res.getPlayer().sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getNationOrNull().getName());
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getNationOrNull().getName());
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The nation of " + res.getNationOrNull().getName() + " has joined the war on the side of " + side.getName() + "!");
|
||||
} else {
|
||||
// Cannot declare nation involvement
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot declare war for your nation.").build());
|
||||
}
|
||||
} else if (res.hasTown()) {
|
||||
if (res.getPlayer().hasPermission("AlathranWars.townjoin") || res.isMayor()) {
|
||||
// Is in indepdenent town & has declaration perms
|
||||
side.addTown(res.getTownOrNull());
|
||||
res.getPlayer().sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getTownOrNull().getName());
|
||||
p.sendMessage(UtilsChat.getPrefix() + "You have joined the war for " + res.getTownOrNull().getName());
|
||||
Bukkit.broadcastMessage(UtilsChat.getPrefix() + "The town of " + res.getTownOrNull().getName() + " has joined the war on the side of " + side.getName() + "!");
|
||||
} else {
|
||||
// No perms
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot declare war for your town.").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void warSurrender(Player p, CommandArguments args, boolean admin) throws WrapperCommandSyntaxException {
|
||||
War war = (War) args.get("war");
|
||||
|
||||
if (!(args.getOptional("player").orElse(p) instanceof Player argPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "<red>Player not found.").build());
|
||||
|
||||
// Towny Resident Object
|
||||
Resident res = TownyAPI.getInstance().getResident(argPlayer);
|
||||
if (res == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("<red>Resident invalid.").build());
|
||||
|
||||
// Town check
|
||||
Town town = res.getTownOrNull();
|
||||
if (town == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("<red>You are not in a town.").build());
|
||||
|
||||
Side side = war.getTownSide(town);
|
||||
if (side == null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("<red>You are not in the war.").build());
|
||||
|
||||
final Nation resNation = res.getNationOrNull();
|
||||
final Town resTown = res.getTownOrNull();
|
||||
|
||||
if (resNation != null) {
|
||||
if (p.hasPermission("AlathranWars.nationsurrender") || res.isKing() || admin) {
|
||||
// Has nation surrender permission
|
||||
argPlayer.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You have surrendered the war for " + resNation.getName() + ".").build());
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The nation of " + resNation.getName() + " has surrendered!").build());
|
||||
side.surrenderNation(resNation);
|
||||
side.processSurrenders();
|
||||
} else {
|
||||
// Cannot surrender nation involvement
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot surrender war for your nation.").build());
|
||||
}
|
||||
} else if (resTown != null) {
|
||||
if (p.hasPermission("AlathranWars.townsurrender") || res.isMayor() || admin) {
|
||||
// Is in indepdenent town & has surrender perms
|
||||
argPlayer.sendMessage(new ColorParser(UtilsChat.getPrefix() + "You have surrendered the war for " + resTown.getName() + ".").build());
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The town of " + resTown.getName() + " has surrendered!").build());
|
||||
side.surrenderTown(resTown);
|
||||
side.processSurrenders();
|
||||
} else {
|
||||
// No perms
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "You cannot surrender war for your town.").build());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void warList(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
Set<War> wars = WarManager.getInstance().getWars();
|
||||
|
||||
if (wars.isEmpty()) {
|
||||
p.sendMessage(new ColorParser("There are no wars at the moment, the world is at peace.").build());
|
||||
} else {
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Wars:").build());
|
||||
|
||||
for (War war : wars) {
|
||||
p.sendMessage(new ColorParser(war.getName() + " - " + war.getSide1().getName() + " (" + war.getSide1().getScore() + ") vs. " + war.getSide2().getName() + " (" + war.getSide2().getScore() + ")").build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*private static void warInfo(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
if (args.count() < 1) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "/war info [Player]").build());
|
||||
}
|
||||
|
||||
if (!(args.get("player") instanceof Player argsPlayer))
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser("Specify a player.").build());
|
||||
|
||||
Resident res = TownyAPI.getInstance().getResident(argsPlayer);
|
||||
if (res == null || res.getTownOrNull() == null) {
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "Invalid town resident.").build());
|
||||
}
|
||||
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + p.getName() + "'s wars:").build());
|
||||
for (War war : WarManager.getInstance().getWars()) {
|
||||
TownWarState side = war.getState(res.getTownOrNull());
|
||||
if (side != TownWarState.NOT_PARTICIPANT) {
|
||||
if (side == TownWarState.SURRENDERED) {
|
||||
p.sendMessage(war.getName() + " - Surrendered");
|
||||
} else if (side == TownWarState.SIDE1) {
|
||||
p.sendMessage(war.getName() + " - " + war.getSide1());
|
||||
} else if (side == TownWarState.SIDE2) {
|
||||
p.sendMessage(war.getName() + " - " + war.getSide2());
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
private static void warHelp(Player p, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for console access
|
||||
*
|
||||
* @param sender
|
||||
* @param args
|
||||
*/
|
||||
// private static void consoleCommand(CommandSender sender, CommandArguments args) {
|
||||
// if (args.length < 1) return;
|
||||
// if (args[0].equalsIgnoreCase("list")) {
|
||||
// ArrayList<War> warList = WarManager.getInstance().getWars();
|
||||
// sender.sendMessage("Wars: " + warList.size());
|
||||
// for (War war : WarManager.getInstance().getWars()) {
|
||||
// if (war == null) continue;
|
||||
// sender.sendMessage(war.toString());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.conflict;
|
||||
package me.ShermansWorld.AlathranWars.conflict;
|
||||
|
||||
public class Conflict {
|
||||
private ConflictType conflictType;
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict;
|
||||
|
||||
public enum ConflictType {
|
||||
WAR
|
||||
}
|
||||
+41
-20
@@ -1,12 +1,12 @@
|
||||
package me.ShermansWorld.AlathraWar.conflict.battle;
|
||||
package me.ShermansWorld.AlathranWars.conflict;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.conflict.War;
|
||||
import me.ShermansWorld.AlathraWar.enums.BattleSide;
|
||||
import me.ShermansWorld.AlathraWar.enums.BattleTeam;
|
||||
import me.ShermansWorld.AlathraWar.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.enums.BattleSide;
|
||||
import me.ShermansWorld.AlathranWars.enums.BattleTeam;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.listeners.JoinListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -23,7 +23,7 @@ public class Side {
|
||||
private UUID uuid;
|
||||
private final BattleSide side;
|
||||
private final BattleTeam team;
|
||||
private final String name; // A town or nation name
|
||||
private final String name; // A town name
|
||||
|
||||
// TODO Use Town & Nation UUID's when saving to config
|
||||
private final Town town; // The initiating town or capital of the nation
|
||||
@@ -46,6 +46,7 @@ public class Side {
|
||||
|
||||
public Side(UUID warUUID, Town town, BattleSide side, BattleTeam team) {
|
||||
this.warUUID = warUUID;
|
||||
this.uuid = generateUUID();
|
||||
this.side = side;
|
||||
this.team = team;
|
||||
this.town = town;
|
||||
@@ -67,6 +68,7 @@ public class Side {
|
||||
|
||||
public Side(UUID warUUID, Nation nation, BattleSide side, BattleTeam team) {
|
||||
this.warUUID = warUUID;
|
||||
this.uuid = generateUUID();
|
||||
this.side = side;
|
||||
this.team = team;
|
||||
this.town = nation.getCapital();
|
||||
@@ -179,21 +181,21 @@ public class Side {
|
||||
public void surrenderTown(Town town) {
|
||||
if (isTownSurrendered(town)) return;
|
||||
|
||||
towns.remove(town);
|
||||
|
||||
town.getResidents().forEach((Resident resident) -> surrenderPlayer(resident.getUUID()));
|
||||
removeTown(town);
|
||||
|
||||
surrenderedTowns.add(town);
|
||||
|
||||
town.getResidents().forEach((Resident resident) -> surrenderPlayer(resident.getUUID()));
|
||||
}
|
||||
|
||||
public void surrenderNation(Nation nation) {
|
||||
if (isNationSurrendered(nation)) return;
|
||||
|
||||
nations.remove(nation);
|
||||
|
||||
nation.getTowns().forEach(this::surrenderTown);
|
||||
removeNation(nation);
|
||||
|
||||
surrenderedNations.add(nation);
|
||||
|
||||
nation.getTowns().forEach(this::surrenderTown);
|
||||
}
|
||||
|
||||
public boolean isPlayerOnSide(Player p) {
|
||||
@@ -266,6 +268,7 @@ public class Side {
|
||||
|
||||
removePlayer(uuid);
|
||||
surrenderedPlayersIncludingOffline.add(uuid);
|
||||
calculateOnlinePlayers();
|
||||
}
|
||||
|
||||
public void calculateOnlinePlayers() {
|
||||
@@ -280,6 +283,17 @@ public class Side {
|
||||
|
||||
this.players.clear();
|
||||
this.players.addAll(onlinePlayers);
|
||||
|
||||
applyNameTags();
|
||||
}
|
||||
|
||||
public void applyNameTags() {
|
||||
players.forEach(JoinListener::checkPlayer);
|
||||
surrenderedPlayersIncludingOffline.stream()
|
||||
.filter((UUID uuid) -> Bukkit.getPlayer(uuid) != null)
|
||||
.map(Bukkit::getPlayer)
|
||||
.toList()
|
||||
.forEach(JoinListener::checkPlayer);
|
||||
}
|
||||
|
||||
|
||||
@@ -336,13 +350,7 @@ public class Side {
|
||||
// Comparators & UUID
|
||||
|
||||
private UUID generateUUID() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
while (getWar().getSide(uuid) != null) {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
return UUID.randomUUID();
|
||||
return UUID.randomUUID(); // There's only ever two sides anyways
|
||||
}
|
||||
|
||||
public boolean equals(UUID uuid) {
|
||||
@@ -354,7 +362,7 @@ public class Side {
|
||||
}
|
||||
|
||||
public boolean equals(Side side) {
|
||||
return this.uuid.equals(side.getUUID());
|
||||
return getUUID().equals(side.getUUID());
|
||||
}
|
||||
|
||||
public boolean equals(String sideName) {
|
||||
@@ -371,6 +379,19 @@ public class Side {
|
||||
return WarManager.getInstance().getWar(warUUID); // The war must exist, or this object wouldn't
|
||||
}
|
||||
|
||||
public void processSurrenders() {
|
||||
if (shouldSurrender())
|
||||
surrenderWar();
|
||||
}
|
||||
|
||||
private void surrenderWar() {
|
||||
getWar().defeat(this);
|
||||
}
|
||||
|
||||
private boolean shouldSurrender() {
|
||||
return nations.isEmpty() && towns.isEmpty();
|
||||
}
|
||||
|
||||
// TODO Make object serializable
|
||||
/*private void writeObject(ObjectOutputStream oos)
|
||||
throws IOException {
|
||||
+119
-83
@@ -1,24 +1,28 @@
|
||||
package me.ShermansWorld.AlathraWar.conflict;
|
||||
package me.ShermansWorld.AlathranWars.conflict;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import me.ShermansWorld.AlathraWar.conflict.battle.Raid;
|
||||
import me.ShermansWorld.AlathraWar.conflict.battle.Side;
|
||||
import me.ShermansWorld.AlathraWar.conflict.battle.Siege;
|
||||
import me.ShermansWorld.AlathraWar.enums.BattleSide;
|
||||
import me.ShermansWorld.AlathraWar.enums.BattleTeam;
|
||||
import me.ShermansWorld.AlathraWar.holder.WarManager;
|
||||
import me.ShermansWorld.AlathraWar.utility.UtilsChat;
|
||||
import 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 org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* The type New war.
|
||||
@@ -38,8 +42,8 @@ public class War extends Conflict {
|
||||
private final Set<Raid> raids = new HashSet<>();
|
||||
|
||||
// Merged utility data from Side's
|
||||
private Set<Player> players = new HashSet<>();
|
||||
private Set<UUID> playersIncludingOffline = new HashSet<>();
|
||||
// private Set<Player> players = new HashSet<>();
|
||||
// private Set<UUID> playersIncludingOffline = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new New war.
|
||||
@@ -54,7 +58,7 @@ public class War extends Conflict {
|
||||
this.label = label;
|
||||
|
||||
if (WarManager.getInstance().getWar(this.name) != null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name!").build());
|
||||
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);
|
||||
@@ -62,7 +66,11 @@ public class War extends Conflict {
|
||||
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
||||
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
||||
|
||||
recalculatePlayers();
|
||||
// recalculatePlayers();
|
||||
|
||||
WarManager.getInstance().addWar(this);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
public War(final String label, Nation aggressor, Nation victim) throws WrapperCommandSyntaxException {
|
||||
@@ -71,7 +79,7 @@ public class War extends Conflict {
|
||||
this.label = label;
|
||||
|
||||
if (WarManager.getInstance().getWar(this.name) != null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name!").build());
|
||||
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);
|
||||
@@ -79,7 +87,11 @@ public class War extends Conflict {
|
||||
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
||||
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
||||
|
||||
recalculatePlayers();
|
||||
// recalculatePlayers();
|
||||
|
||||
WarManager.getInstance().addWar(this);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
public War(final String label, Town aggressor, Nation victim) throws WrapperCommandSyntaxException {
|
||||
@@ -88,7 +100,7 @@ public class War extends Conflict {
|
||||
this.label = label;
|
||||
|
||||
if (WarManager.getInstance().getWar(this.name) != null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name!").build());
|
||||
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);
|
||||
@@ -96,7 +108,11 @@ public class War extends Conflict {
|
||||
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
||||
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
||||
|
||||
recalculatePlayers();
|
||||
// recalculatePlayers();
|
||||
|
||||
WarManager.getInstance().addWar(this);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
public War(final String label, Nation aggressor, Town victim) throws WrapperCommandSyntaxException {
|
||||
@@ -105,7 +121,7 @@ public class War extends Conflict {
|
||||
this.label = label;
|
||||
|
||||
if (WarManager.getInstance().getWar(this.name) != null)
|
||||
throw CommandAPIBukkit.failWithAdventureComponent(new ColorParser(UtilsChat.getPrefix() + "&cA war already exists with that name!").build());
|
||||
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);
|
||||
@@ -113,7 +129,11 @@ public class War extends Conflict {
|
||||
this.attacker = side1.getSide().equals(BattleSide.ATTACKER) ? this.side1 : this.side2;
|
||||
this.defender = side1.getSide().equals(BattleSide.DEFENDER) ? this.side1 : this.side2;
|
||||
|
||||
recalculatePlayers();
|
||||
// recalculatePlayers();
|
||||
|
||||
WarManager.getInstance().addWar(this);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
private UUID generateUUID() {
|
||||
@@ -123,7 +143,7 @@ public class War extends Conflict {
|
||||
uuid = UUID.randomUUID();
|
||||
}
|
||||
|
||||
return UUID.randomUUID();
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,15 +270,6 @@ public class War extends Conflict {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets surrendered.
|
||||
*
|
||||
* @return the surrendered
|
||||
*/
|
||||
// public Set<UUID> getSurrenderedPlayers() {
|
||||
// return surrendered;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Gets sieges.
|
||||
*
|
||||
@@ -297,41 +308,31 @@ public class War extends Conflict {
|
||||
raids.add(raid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all players in the war, including offline players.
|
||||
*
|
||||
* @return the all players
|
||||
*/
|
||||
@NotNull
|
||||
public Set<OfflinePlayer> getPlayersIncludingOffline() {
|
||||
final Set<OfflinePlayer> playersIncludingOffline = new HashSet<>();
|
||||
|
||||
for (UUID uuid : this.playersIncludingOffline)
|
||||
playersIncludingOffline.add(Bukkit.getOfflinePlayer(uuid));
|
||||
|
||||
return playersIncludingOffline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all players in the war, including offline players.
|
||||
*
|
||||
* @return the all players
|
||||
*/
|
||||
@NotNull
|
||||
public Set<Player> getPlayers() {
|
||||
return players;
|
||||
return Stream.concat(
|
||||
getSide1().getPlayers().stream(),
|
||||
getSide2().getPlayers().stream()
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public void recalculatePlayers() {
|
||||
final Set<UUID> newPlayersIncludingOffline = new HashSet<>();
|
||||
newPlayersIncludingOffline.addAll(side1.getPlayersIncludingOffline());
|
||||
newPlayersIncludingOffline.addAll(side2.getPlayersIncludingOffline());
|
||||
playersIncludingOffline = newPlayersIncludingOffline;
|
||||
@NotNull
|
||||
public Set<OfflinePlayer> getPlayersIncludingOffline() {
|
||||
return Stream.concat(
|
||||
getSide1().getPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer),
|
||||
getSide2().getPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer)
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
final Set<Player> newPlayers = new HashSet<>();
|
||||
newPlayers.addAll(side1.getPlayers());
|
||||
newPlayers.addAll(side2.getPlayers());
|
||||
players = newPlayers;
|
||||
@NotNull
|
||||
public Set<OfflinePlayer> getSurrenderedPlayers() {
|
||||
return Stream.concat(
|
||||
getSide1().getSurrenderedPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer),
|
||||
getSide2().getSurrenderedPlayersIncludingOffline().stream().map(Bukkit::getOfflinePlayer)
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public boolean isPlayerInWar(Player p) {
|
||||
@@ -400,49 +401,84 @@ public class War extends Conflict {
|
||||
|
||||
@NotNull
|
||||
public Set<Town> getTowns() {
|
||||
Set<Town> towns = new HashSet<>();
|
||||
|
||||
towns.addAll(side1.getTowns());
|
||||
towns.addAll(side2.getTowns());
|
||||
|
||||
return towns;
|
||||
return Stream.concat(
|
||||
getSide1().getTowns().stream(),
|
||||
getSide2().getTowns().stream()
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Nation> getNations() {
|
||||
Set<Nation> nations = new HashSet<>();
|
||||
|
||||
nations.addAll(side1.getNations());
|
||||
nations.addAll(side2.getNations());
|
||||
|
||||
return nations;
|
||||
return Stream.concat(
|
||||
getSide1().getNations().stream(),
|
||||
getSide2().getNations().stream()
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Town> getSurrenderedTowns() {
|
||||
Set<Town> towns = new HashSet<>();
|
||||
|
||||
towns.addAll(side1.getSurrenderedTowns());
|
||||
towns.addAll(side2.getSurrenderedTowns());
|
||||
|
||||
return towns;
|
||||
return Stream.concat(
|
||||
getSide1().getSurrenderedTowns().stream(),
|
||||
getSide2().getSurrenderedTowns().stream()
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Nation> getSurrenderedNations() {
|
||||
Set<Nation> nations = new HashSet<>();
|
||||
|
||||
nations.addAll(side1.getSurrenderedNations());
|
||||
nations.addAll(side2.getSurrenderedNations());
|
||||
|
||||
return nations;
|
||||
return Stream.concat(
|
||||
getSide1().getSurrenderedNations().stream(),
|
||||
getSide2().getSurrenderedNations().stream()
|
||||
)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The war of <war> has started between <attacker> and <defender>.")
|
||||
.parseMinimessagePlaceholder("war", getLabel())
|
||||
.parseMinimessagePlaceholder("attacker", getAttacker().getName())
|
||||
.parseMinimessagePlaceholder("defender", getDefender().getName())
|
||||
.build()
|
||||
);
|
||||
|
||||
side1.calculateOnlinePlayers();
|
||||
side2.calculateOnlinePlayers();
|
||||
}
|
||||
|
||||
public void end() {
|
||||
// TODO Stop battles
|
||||
getSieges().forEach(Siege::stop);
|
||||
// getRaids().forEach(Raid::stop);
|
||||
|
||||
WarManager.getInstance().removeWar(this);
|
||||
|
||||
// Run check after war is removed to cleanup player tags
|
||||
this.getPlayers().forEach(JoinListener::checkPlayer);
|
||||
}
|
||||
|
||||
public void defeat(Side loserSide) {
|
||||
Side loser = loserSide.equals(getSide1()) ? getSide1() : getSide2();
|
||||
Side winner = loserSide.equals(getSide1()) ? getSide2() : getSide1();
|
||||
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The war of <war> has ended. <red><winner> <reset>has triumphed against <red><loser><reset>.")
|
||||
.parseMinimessagePlaceholder("war", getLabel())
|
||||
.parseMinimessagePlaceholder("winner", winner.getName())
|
||||
.parseMinimessagePlaceholder("loser", loser.getName())
|
||||
.build()
|
||||
);
|
||||
|
||||
end();
|
||||
}
|
||||
|
||||
// White defeat/force end war
|
||||
public void draw() {
|
||||
Bukkit.broadcast(new ColorParser(UtilsChat.getPrefix() + "The war of <war> has ended with a white peace.")
|
||||
.parseMinimessagePlaceholder("war", getLabel())
|
||||
.build()
|
||||
);
|
||||
|
||||
end();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict.battle;
|
||||
|
||||
public class Battle {
|
||||
private int attackerPoints;
|
||||
private int defenderPoints;
|
||||
|
||||
public int getAttackerPoints() {
|
||||
return this.attackerPoints;
|
||||
}
|
||||
|
||||
public void setAttackerPoints(int points) {
|
||||
this.attackerPoints = points;
|
||||
}
|
||||
|
||||
public int getDefenderPoints() {
|
||||
return this.defenderPoints;
|
||||
}
|
||||
|
||||
public void setDefenderPoints(int points) {
|
||||
this.defenderPoints = points;
|
||||
}
|
||||
|
||||
public void addPointsToAttackers(final int points) {
|
||||
this.attackerPoints += points;
|
||||
}
|
||||
|
||||
public void addPointsToDefenders(final int points) {
|
||||
this.defenderPoints += points;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package me.ShermansWorld.AlathranWars.conflict.battle.raid;
|
||||
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.Battle;
|
||||
|
||||
public class Raid extends Battle {
|
||||
}
|
||||
@@ -0,0 +1,598 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
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
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
package me.ShermansWorld.AlathranWars.data;
|
||||
|
||||
public enum RaidPhase {
|
||||
START(0, 0),
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.enums;
|
||||
package me.ShermansWorld.AlathranWars.enums;
|
||||
|
||||
public enum AdminCommandFailEnum {
|
||||
PERMISSIONS,
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.enums;
|
||||
package me.ShermansWorld.AlathranWars.enums;
|
||||
|
||||
public enum BattleSide {
|
||||
ATTACKER,
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.enums;
|
||||
package me.ShermansWorld.AlathranWars.enums;
|
||||
|
||||
public enum BattleTeam {
|
||||
SIDE_1,
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.enums;
|
||||
package me.ShermansWorld.AlathranWars.enums;
|
||||
|
||||
public enum TownWarState {
|
||||
NOT_PARTICIPANT,
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.events;
|
||||
package me.ShermansWorld.AlathranWars.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.events;
|
||||
package me.ShermansWorld.AlathranWars.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.events;
|
||||
package me.ShermansWorld.AlathranWars.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.events;
|
||||
package me.ShermansWorld.AlathranWars.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -0,0 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.events.battle;
|
||||
|
||||
public class PreSiegeEndEvent {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.events.battle;
|
||||
|
||||
public class PreSiegeStartEvent {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.events.battle;
|
||||
|
||||
public class SiegeEndEvent {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package me.ShermansWorld.AlathranWars.events.battle;
|
||||
|
||||
public class SiegeStartEvent {
|
||||
}
|
||||
+21
-18
@@ -1,17 +1,21 @@
|
||||
package me.ShermansWorld.AlathraWar.holder;
|
||||
package me.ShermansWorld.AlathranWars.holder;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.conflict.War;
|
||||
import me.ShermansWorld.AlathraWar.conflict.battle.Raid;
|
||||
import me.ShermansWorld.AlathraWar.conflict.battle.Siege;
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.conflict.battle.raid.Raid;
|
||||
import me.ShermansWorld.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.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Singleton
|
||||
public class WarManager {
|
||||
@@ -25,7 +29,9 @@ public class WarManager {
|
||||
|
||||
@NotNull
|
||||
public static WarManager getInstance() {
|
||||
if (instance == null) new WarManager();
|
||||
if (instance == null)
|
||||
instance = new WarManager();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -66,10 +72,7 @@ public class WarManager {
|
||||
}
|
||||
|
||||
public boolean isPlayerInAnyWars(Player p) {
|
||||
for (War war : wars) {
|
||||
if (war.isPlayerInWar(p)) return true;
|
||||
};
|
||||
return false;
|
||||
return isPlayerInAnyWars(p.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean isTownInAnyWars(Town town) {
|
||||
@@ -88,18 +91,18 @@ public class WarManager {
|
||||
|
||||
@NotNull
|
||||
public List<String> getWarNames() {
|
||||
final List<String> names = new ArrayList<>();
|
||||
wars.forEach((War war) -> names.add(war.getName()));
|
||||
names.sort(String::compareToIgnoreCase);
|
||||
return names;
|
||||
return wars.stream()
|
||||
.map(War::getName)
|
||||
.sorted(String::compareToIgnoreCase)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getWarLabels() {
|
||||
final List<String> labels = new ArrayList<>();
|
||||
wars.forEach((War war) -> labels.add(war.getLabel()));
|
||||
labels.sort(String::compareToIgnoreCase);
|
||||
return labels;
|
||||
return wars.stream()
|
||||
.map(War::getLabel)
|
||||
.sorted(String::compareToIgnoreCase)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.hooks;
|
||||
package me.ShermansWorld.AlathranWars.hooks;
|
||||
|
||||
public class HookManager {
|
||||
public HookManager() {
|
||||
+29
-15
@@ -1,12 +1,13 @@
|
||||
package me.ShermansWorld.AlathraWar.hooks;
|
||||
package me.ShermansWorld.AlathranWars.hooks;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldWar;
|
||||
import me.ShermansWorld.AlathraWar.listeners.JoinListener;
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.listeners.JoinListener;
|
||||
import me.ShermansWorld.AlathranWars.utility.UtilsChat;
|
||||
import me.neznamy.tab.api.TabAPI;
|
||||
import me.neznamy.tab.api.TabPlayer;
|
||||
import me.neznamy.tab.api.event.EventBus;
|
||||
import me.neznamy.tab.api.event.player.PlayerLoadEvent;
|
||||
import me.neznamy.tab.api.nametag.UnlimitedNameTagManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -37,7 +38,7 @@ public class TABHook {
|
||||
});
|
||||
}
|
||||
|
||||
public static void assignSide1WarSuffix(Player p, OldWar oldWar) {
|
||||
public static void assignSide1WarSuffix(Player p, War war) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@@ -45,20 +46,29 @@ public class TABHook {
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
|
||||
new ColorParser(" &c[" + oldWar.getSide1() + "]&r").parseLegacy().build());
|
||||
UtilsChat.color(" <red>[" + war.getSide1().getName() + "]<reset>")
|
||||
);
|
||||
|
||||
if (TabAPI.getInstance().getNameTagManager() instanceof UnlimitedNameTagManager unm) {
|
||||
unm.setPrefix(tabPlayer, "<red>");
|
||||
}
|
||||
}
|
||||
|
||||
public static void assignSide2WarSuffix(Player p, OldWar oldWar) {
|
||||
public static void assignSide2WarSuffix(Player p, War war) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, Helper.color(" &9[") + oldWar.getSide2() + "]&r");
|
||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, UtilsChat.color(" <blue>[") + war.getSide2().getName() + "]<reset>");
|
||||
|
||||
if (TabAPI.getInstance().getNameTagManager() instanceof UnlimitedNameTagManager unm) {
|
||||
unm.setPrefix(tabPlayer, "<blue>");
|
||||
}
|
||||
}
|
||||
|
||||
public static void assignSide1WarSuffixMerc(Player p, OldWar oldWar) {
|
||||
public static void assignSide1WarSuffixMerc(Player p, War war) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@@ -66,10 +76,10 @@ public class TABHook {
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
|
||||
Helper.color(" &a[M]&c[") + oldWar.getSide1() + "]&r");
|
||||
UtilsChat.color(" <green>[M]<red>[") + war.getSide1() + "]<reset>");
|
||||
}
|
||||
|
||||
public static void assignSide2WarSuffixMerc(Player p, OldWar oldWar) {
|
||||
public static void assignSide2WarSuffixMerc(Player p, War war) {
|
||||
if (!enabled) return;
|
||||
|
||||
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
|
||||
@@ -77,7 +87,7 @@ public class TABHook {
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer,
|
||||
Helper.color(" &a[M]&9[") + oldWar.getSide2() + "]&r");
|
||||
UtilsChat.color(" <green>[M]<blue>[") + war.getSide2() + "]<reset>");
|
||||
}
|
||||
|
||||
public static void resetSuffix(Player p) {
|
||||
@@ -104,7 +114,7 @@ public class TABHook {
|
||||
|
||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, null);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +126,10 @@ public class TABHook {
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, null);
|
||||
|
||||
if (TabAPI.getInstance().getNameTagManager() instanceof UnlimitedNameTagManager unm) {
|
||||
unm.setPrefix(tabPlayer, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetPrefix(String playername) {
|
||||
@@ -131,7 +145,7 @@ public class TABHook {
|
||||
|
||||
tabAPI.getTabListFormatManager().setSuffix(tabPlayer, null);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +166,7 @@ public class TABHook {
|
||||
|
||||
if (tabAPI.getTabListFormatManager() == null) return;
|
||||
|
||||
tabAPI.getTabListFormatManager().setPrefix(tabPlayer, Helper.color(prefix));
|
||||
tabAPI.getTabListFormatManager().setPrefix(tabPlayer, UtilsChat.color(prefix));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.hooks;
|
||||
package me.ShermansWorld.AlathranWars.hooks;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.items;
|
||||
package me.ShermansWorld.AlathranWars.items;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package me.ShermansWorld.AlathraWar.items;
|
||||
package me.ShermansWorld.AlathranWars.items;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.items.item.RamItem;
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
import me.ShermansWorld.AlathranWars.items.item.RamItem;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -21,13 +21,13 @@ public class WarItemRegistry {
|
||||
public WarItemRegistry() {
|
||||
instance = this;
|
||||
|
||||
Main.warLogger.log(UtilsChat.getPrefix() + "Registering AlathraWar items.");
|
||||
// Main.warLogger.log(UtilsChat.getPrefix() + "Registering AlathranWars items.");
|
||||
|
||||
itemRegistry.put(registryName("ram"), new RamItem());
|
||||
//THIS BREAKS EVERYTHING???? TODO
|
||||
// Bukkit.getServer().addRecipe(new RamItem().getRecipe());
|
||||
|
||||
Main.warLogger.log(UtilsChat.getPrefix() + "Registered AlathraWar items.");
|
||||
// Main.warLogger.log(UtilsChat.getPrefix() + "Registered AlathranWars items.");
|
||||
}
|
||||
|
||||
public static WarItemRegistry getInstance() {
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
package me.ShermansWorld.AlathraWar.items;
|
||||
package me.ShermansWorld.AlathranWars.items;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -14,11 +14,11 @@ public class WarRecipeRegistry {
|
||||
public WarRecipeRegistry() {
|
||||
instance = this;
|
||||
|
||||
Main.warLogger.log(UtilsChat.getPrefix() + "Registering AlathraWar recipes.");
|
||||
// Main.warLogger.log(UtilsChat.getPrefix() + "Registering AlathranWars recipes.");
|
||||
|
||||
// register(WarItemRegistry.registryName("ram"), new RamItem().getRecipes());
|
||||
|
||||
Main.warLogger.log(UtilsChat.getPrefix() + "Registered AlathraWar recipes.");
|
||||
// Main.warLogger.log(UtilsChat.getPrefix() + "Registered AlathranWars recipes.");
|
||||
}
|
||||
|
||||
public static WarRecipeRegistry getInstance() {
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
package me.ShermansWorld.AlathraWar.items.item;
|
||||
package me.ShermansWorld.AlathranWars.items.item;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.items.IWarItem;
|
||||
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
|
||||
import me.ShermansWorld.AlathranWars.Main;
|
||||
import me.ShermansWorld.AlathranWars.items.IWarItem;
|
||||
import me.ShermansWorld.AlathranWars.items.WarItemRegistry;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Tag;
|
||||
@@ -0,0 +1,102 @@
|
||||
package me.ShermansWorld.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;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockBreakListener 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
|
||||
public void onBlockBreak(final BlockBreakEvent e) {
|
||||
final Block block = e.getBlock();
|
||||
/*if (SiegeData.getSieges().isEmpty() *//*&& RaidData.getRaids().isEmpty()*//*) {
|
||||
return;
|
||||
}*/
|
||||
|
||||
if (allowedBlocks.contains(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getPlayer().hasPermission("AlathranWars.break")) {
|
||||
return;
|
||||
}
|
||||
|
||||
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()) {
|
||||
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()) {
|
||||
p.sendMessage(Helper.color("<red>You can not break blocks during raids"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
final Block block = event.getBlock();
|
||||
/*if (SiegeData.getSieges().isEmpty() && RaidData.getRaids().isEmpty()) {
|
||||
return;
|
||||
}*/
|
||||
if (allowedBlocks.contains(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = event.getPlayer();
|
||||
if (p.hasPermission("AlathranWars.place")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (WorldCoord.parseWorldCoord(block).getTownOrNull() != null) {
|
||||
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()) {
|
||||
p.sendMessage(Helper.color("<red>You can not place blocks during raids"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
-48
@@ -1,10 +1,9 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import 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 org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -12,29 +11,29 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class CommandsListener implements Listener {
|
||||
|
||||
final static String[] prefixes = new String[]{
|
||||
final static String[] PREFIXES = new String[]{
|
||||
"", "towny", "essentials", "wild", "minecraft"
|
||||
};
|
||||
final static String[] prefixesTowny = new String[]{
|
||||
final static String[] PREFIXES_TOWNY = new String[]{
|
||||
"", "towny"
|
||||
};
|
||||
final static String[] blacklistedXLong = new String[]{
|
||||
final static String[] BLACKLISTED_X_LONG = new String[]{
|
||||
"n set spawn", "nat set spawn", "nation set spawn",
|
||||
"t set spawn", "town set spawn",
|
||||
"t set homeblock", "town set homeblock",
|
||||
"t set name", "town set name",
|
||||
"n set name", "nat set name", "nation set name"
|
||||
};
|
||||
final static String[] blacklistedLong = new String[]{
|
||||
final static String[] BLACKLISTED_LONG = new String[]{
|
||||
"n spawn", "nat spawn", "nation spawn",
|
||||
"t spawn", "town spawn",
|
||||
"t outpost", "town outpost"
|
||||
};
|
||||
final static String[] payment = new String[]{
|
||||
final static String[] PAYMENT = new String[]{
|
||||
"n withdraw", "nat withdraw", "nation withdraw",
|
||||
"t withdraw", "town withdraw"
|
||||
};
|
||||
final static String[] blacklistedShort = new String[]{
|
||||
final static String[] BLACKLISTED_SHORT = new String[]{
|
||||
"home", "homes", "warp", "warps",
|
||||
"wild", "rtp", "spawn", "wilderness", "wildtp",
|
||||
"tpa", "tpahere", "tpaccept", "tpacancel",
|
||||
@@ -43,14 +42,13 @@ public class CommandsListener implements Listener {
|
||||
|
||||
};
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onCommandSend(final PlayerCommandPreprocessEvent event) {
|
||||
|
||||
Player p = event.getPlayer();
|
||||
|
||||
//if player is admin, ignore this behavior
|
||||
// if (p.hasPermission("!AlathraWar.admin")) return;
|
||||
// if (p.hasPermission("!AlathranWars.admin")) return;
|
||||
|
||||
String[] args = event.getMessage().split(" ");
|
||||
|
||||
@@ -60,7 +58,7 @@ public class CommandsListener implements Listener {
|
||||
|
||||
allow n spawn and t spawn for defenders trapped in spawn
|
||||
*/
|
||||
for (OldRaid oldRaid : RaidData.getRaids()) {
|
||||
/*for (OldRaid oldRaid : RaidData.getRaids()) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
if (oldRaid.getPhase() == RaidPhase.COMBAT || oldRaid.getPhase() == RaidPhase.TRAVEL || oldRaid.getPhase() == RaidPhase.GATHER) {
|
||||
//only do for active raiders and any defenders
|
||||
@@ -72,7 +70,7 @@ public class CommandsListener implements Listener {
|
||||
//payment check
|
||||
for (String cmd : blacklistedXLong) {
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot modify this property during a oldRaid!"));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("<red>You cannot modify this property during a oldRaid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -88,7 +86,7 @@ public class CommandsListener implements Listener {
|
||||
for (String cmd : payment) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot withdraw money whilst in a oldRaid!"));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("<red>You cannot withdraw money whilst in a oldRaid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -103,17 +101,17 @@ public class CommandsListener implements Listener {
|
||||
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|
||||
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|
||||
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("<yellow>You are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
return;
|
||||
}
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("<yellow>You are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("<yellow>Use /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot teleport whilst in a oldRaid!"));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("<red>You cannot teleport whilst in a oldRaid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -130,13 +128,13 @@ public class CommandsListener implements Listener {
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//spawn world check
|
||||
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("<yellow>You are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("<yellow>Use /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot teleport whilst in a oldRaid!"));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("<red>You cannot teleport whilst in a oldRaid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -146,23 +144,23 @@ public class CommandsListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Prevent players from teleporting during a siege
|
||||
*/
|
||||
for (OldSiege oldSiege : SiegeData.getSieges()) {
|
||||
*/
|
||||
/*
|
||||
Prevent players from teleporting during a siege
|
||||
*/
|
||||
for (Siege siege : WarManager.getInstance().getSieges()) {
|
||||
//Only do this during regular phases, start and end ignored in case something breaks
|
||||
if (oldSiege.getSiegeTicks() > 0) {
|
||||
if (siege.getSiegeTicks() > 0) {
|
||||
//only do for active raiders and any defenders
|
||||
if (oldSiege.getAttackerPlayers().contains(p.getName()) || oldSiege.getDefenderPlayers().contains(p.getName())) {
|
||||
if (siege.getAttackerPlayers().contains(p) || siege.getDefenderPlayers().contains(p)) {
|
||||
//set spawn and properties
|
||||
if (args.length >= 3) {
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1] + " " + args[2];
|
||||
for (String prefix : prefixesTowny) {
|
||||
for (String prefix : PREFIXES_TOWNY) {
|
||||
//payment check
|
||||
for (String cmd : blacklistedXLong) {
|
||||
for (String cmd : BLACKLISTED_X_LONG) {
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot modify this property during a oldSiege!"));
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>You cannot modify this property during a oldSiege!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -173,18 +171,18 @@ public class CommandsListener implements Listener {
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixesTowny) {
|
||||
for (String prefix : PREFIXES_TOWNY) {
|
||||
//payment check
|
||||
for (String cmd : payment) {
|
||||
for (String cmd : PAYMENT) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot withdraw money whilst in a oldSiege!"));
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>You cannot withdraw money whilst in a oldSiege!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (String cmd : blacklistedLong) {
|
||||
for (String cmd : BLACKLISTED_LONG) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//check if in spawn
|
||||
@@ -193,17 +191,17 @@ public class CommandsListener implements Listener {
|
||||
|| parse.equalsIgnoreCase("t spawn") || parse.equalsIgnoreCase("town spawn")
|
||||
|| parse.equalsIgnoreCase("towny:n spawn") || parse.equalsIgnoreCase("towny:nat spawn") || parse.equalsIgnoreCase("towny:nation spawn")
|
||||
|| parse.equalsIgnoreCase("towny:t spawn") || parse.equalsIgnoreCase("towny:town spawn")) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
||||
return;
|
||||
}
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<yellow>Use /t spawn, or /n spawn").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot teleport whilst in a oldSiege!"));
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -214,19 +212,19 @@ public class CommandsListener implements Listener {
|
||||
if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedShort) {
|
||||
for (String prefix : PREFIXES) {
|
||||
for (String cmd : BLACKLISTED_SHORT) {
|
||||
//check for each prefix
|
||||
if (parse.equalsIgnoreCase(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//spawn world check
|
||||
if (p.getWorld().getName().equalsIgnoreCase("world")) {
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<yellow>You are stuck in spawn and are allowed to teleport to your town or nation.").parseLegacy().build());
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<yellow>Use /t spawn, or /n spawn").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(UtilsChat.getPrefix() + Helper.color("&cYou cannot teleport whilst in a oldSiege!"));
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>You cannot teleport whilst in a oldSiege!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -235,7 +233,6 @@ public class CommandsListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
|
||||
import me.ShermansWorld.AlathranWars.conflict.War;
|
||||
import me.ShermansWorld.AlathranWars.holder.WarManager;
|
||||
import me.ShermansWorld.AlathranWars.hooks.TABHook;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
public static void checkPlayer(Player p) {
|
||||
final UUID uuid = p.getUniqueId();
|
||||
|
||||
if (WarManager.getInstance().isPlayerInAnyWars(uuid)) {
|
||||
for (final War war : WarManager.getInstance().getWars()) {
|
||||
if (war.getSide1().isPlayerOnSide(uuid) && !war.getSide1().isPlayerSurrendered(uuid)) {
|
||||
TABHook.assignSide1WarSuffix(p, war);
|
||||
} else if (war.getSide2().isPlayerOnSide(uuid) && !war.getSide2().isPlayerSurrendered(uuid)) {
|
||||
TABHook.assignSide2WarSuffix(p, war);
|
||||
} else if (war.getSide1().isPlayerSurrendered(uuid) || war.getSide2().isPlayerSurrendered(uuid)) {
|
||||
TABHook.resetPrefix(p);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TABHook.resetPrefix(p);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final Player p = event.getPlayer();
|
||||
}
|
||||
}
|
||||
+30
-42
@@ -1,29 +1,22 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
|
||||
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.AlathraWar.deprecated.OldRaid;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.utility.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import 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 org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class KillsListener implements Listener {
|
||||
|
||||
public static final HashMap<UUID, OldRaid> respawnQueue = new HashMap<>();
|
||||
// public static final HashMap<UUID, OldRaid> respawnQueue = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKilled(final PlayerDeathEvent event) {
|
||||
@@ -41,7 +34,7 @@ public final class KillsListener implements Listener {
|
||||
|
||||
try {
|
||||
//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 homeBlockZCoordRaided = oldRaid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
// final int homeBlockXCoordGather = oldRaid.getGatherTown().getHomeBlock().getCoord().getX() * 16;
|
||||
@@ -93,30 +86,28 @@ public final class KillsListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
if (killer == null) return;
|
||||
|
||||
for (final OldSiege oldSiege : SiegeData.getSieges()) {
|
||||
final int homeBlockXCoord = oldSiege.getTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoord = oldSiege.getTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
for (final Siege siege : WarManager.getInstance().getSieges()) {
|
||||
final int homeBlockXCoord = siege.getTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoord = siege.getTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoord) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoord) <= 300) {
|
||||
playerCloseToHomeBlockSiege = true;
|
||||
}
|
||||
if (oldSiege.getAttackerPlayers().contains(killer.getName()) && ((town != null && town.equals(oldSiege.getTown())) || playerCloseToHomeBlockSiege)) {
|
||||
if (oldSiege.getDefenderPlayers().contains(killed.getName())) {
|
||||
oldSiege.addPointsToAttackers(20);
|
||||
for (final String playerName : oldSiege.getAttackerPlayers()) {
|
||||
if (siege.getAttackerPlayers().contains(killer) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
|
||||
if (siege.getDefenderPlayers().contains(killed)) {
|
||||
siege.addPointsToAttackers(20);
|
||||
for (final Player p : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Defender killed! + 20 Attacker Points");
|
||||
p.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Defender killed! + 20 Attacker Points").parseLegacy().build());
|
||||
} catch (NullPointerException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
for (final String playerName : oldSiege.getDefenderPlayers()) {
|
||||
for (final Player p : siege.getDefenderPlayers()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Defender killed! + 20 Attacker Points");
|
||||
} catch (NullPointerException ignored) {
|
||||
@@ -127,21 +118,19 @@ public final class KillsListener implements Listener {
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
}
|
||||
if (oldSiege.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(oldSiege.getTown())) || playerCloseToHomeBlockSiege)) {
|
||||
if (oldSiege.getAttackerPlayers().contains(killed.getName())) {
|
||||
oldSiege.addPointsToDefenders(20);
|
||||
for (final String playerName : oldSiege.getAttackerPlayers()) {
|
||||
if (siege.getDefenderPlayers().contains(killer) && ((town != null && town.equals(siege.getTown())) || playerCloseToHomeBlockSiege)) {
|
||||
if (siege.getAttackerPlayers().contains(killed)) {
|
||||
siege.addPointsToDefenders(20);
|
||||
for (final Player p : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Attacker killed! + 20 Defender Points");
|
||||
} catch (NullPointerException ex3) {
|
||||
ex3.printStackTrace();
|
||||
}
|
||||
}
|
||||
for (final String playerName : oldSiege.getDefenderPlayers()) {
|
||||
for (final Player p : siege.getDefenderPlayers()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null)
|
||||
p.sendMessage(UtilsChat.getPrefix() + "Attacker killed! + 20 Defender Points");
|
||||
} catch (NullPointerException ex4) {
|
||||
@@ -152,11 +141,10 @@ public final class KillsListener implements Listener {
|
||||
this.siegeKill(killed, event);
|
||||
return;
|
||||
}
|
||||
if ((town != null && town.equals(oldSiege.getTown()) || playerCloseToHomeBlockSiege)) {
|
||||
if ((town != null && town.equals(siege.getTown()) || playerCloseToHomeBlockSiege)) {
|
||||
this.siegeKill(killed, event);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (NullPointerException | TownyException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
@@ -167,7 +155,7 @@ public final class KillsListener implements Listener {
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
/*@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
if (respawnQueue.containsKey(event.getPlayer().getUniqueId())) {
|
||||
OldRaid oldRaid = respawnQueue.get(event.getPlayer().getUniqueId());
|
||||
@@ -187,7 +175,7 @@ public final class KillsListener implements Listener {
|
||||
}
|
||||
respawnQueue.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
@@ -201,8 +189,8 @@ public final class KillsListener implements Listener {
|
||||
//Helper
|
||||
Utils.damageAllGear(killed);
|
||||
|
||||
//OldSiege specific
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + killed.getName()); // TODO Re enable?
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
@@ -219,7 +207,7 @@ public final class KillsListener implements Listener {
|
||||
//Helper
|
||||
Utils.damageAllGear(killed);
|
||||
|
||||
//OldSiege specific
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
@@ -234,7 +222,7 @@ public final class KillsListener implements Listener {
|
||||
* @param event event
|
||||
*/
|
||||
private void oocKill(final Player killed, final PlayerDeathEvent event) {
|
||||
//OldSiege specific
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
|
||||
import com.palmergames.bukkit.towny.event.nation.NationKingChangeEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -17,9 +17,9 @@ public class NationListener implements Listener {
|
||||
|
||||
// TODO Prevent nation rename during war, siege, raid
|
||||
|
||||
@EventHandler
|
||||
/*@EventHandler
|
||||
private void onNationKingChange(NationKingChangeEvent e) {
|
||||
e.setCancelMessage("");
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
+15
-14
@@ -1,13 +1,13 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import com.palmergames.bukkit.towny.object.TownBlock;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldRaid;
|
||||
import me.ShermansWorld.AlathraWar.deprecated.OldSiege;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import me.ShermansWorld.AlathraWar.items.WarItemRegistry;
|
||||
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 org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -69,7 +69,7 @@ public class PlayerInteractListener implements Listener {
|
||||
if (item.equals(WarItemRegistry.getInstance().getOrNull("ram"))) {
|
||||
boolean inSiegeOrRaid = false;
|
||||
//siege check
|
||||
for (OldSiege s : SiegeData.getSieges()) {
|
||||
for (Siege s : WarManager.getInstance().getSieges()) {
|
||||
for (TownBlock townBlock : s.getTown().getTownBlocks()) {
|
||||
if (WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
|
||||
// if we find one, just end no need to continue
|
||||
@@ -79,8 +79,9 @@ public class PlayerInteractListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if it wasnt in a siege, then
|
||||
if (!inSiegeOrRaid) {
|
||||
/*if (!inSiegeOrRaid) {
|
||||
for (OldRaid r : RaidData.getRaids()) {
|
||||
for (TownBlock townBlock : r.getRaidedTown().getTownBlocks()) {
|
||||
if (WorldCoord.parseWorldCoord(clicked).equals(townBlock.getWorldCoord())) {
|
||||
@@ -90,24 +91,24 @@ public class PlayerInteractListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (inSiegeOrRaid) {
|
||||
|
||||
// Returns if already broken.
|
||||
if (doorBroken(clicked, door)) {
|
||||
player.sendMessage(UtilsChat.getPrefix() + Helper.color("&cThe door is already broken!"));
|
||||
player.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>The door is already broken!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
player.sendMessage(UtilsChat.getPrefix() + Helper.color("&eBreak it down alright!"));
|
||||
player.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<yellow>Break it down alright!").parseLegacy().build());
|
||||
brokenDoors.put(getDoorPos(clicked, door), System.currentTimeMillis() + (1000L * Main.getInstance().getConfig().getInt("batteringRamEffectiveness")));
|
||||
door.setOpen(!door.isOpen());
|
||||
clicked.setBlockData(door);
|
||||
player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);
|
||||
Main.warLogger.log("User " + player.getName() + " has broken down door" + clicked.getLocation());
|
||||
} else {
|
||||
player.sendMessage(UtilsChat.getPrefix() + Helper.color("&cThis item can only be used in a siege or raid!"));
|
||||
player.sendMessage(new ColorParser(UtilsChat.getPrefix() + "<red>This item can only be used in a siege or raid!").parseLegacy().build());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -141,7 +142,7 @@ public class PlayerInteractListener implements Listener {
|
||||
if (doors.contains(clicked.getType())) {
|
||||
Door door = (Door) clicked.getBlockData();
|
||||
if (doorBroken(clicked, door)) {
|
||||
player.sendMessage(UtilsChat.getPrefix() + Helper.color("Door is broken!"));
|
||||
player.sendMessage(new ColorParser(UtilsChat.getPrefix() + "Door is broken!").parseLegacy().build());
|
||||
event.setCancelled(true);
|
||||
|
||||
return;
|
||||
@@ -0,0 +1,7 @@
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
package me.ShermansWorld.AlathranWars.listeners;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.ShermansWorld.AlathraWar.utility;
|
||||
package me.ShermansWorld.AlathranWars.utility;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import org.bukkit.Material;
|
||||
@@ -0,0 +1,13 @@
|
||||
package me.ShermansWorld.AlathranWars.utility;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class UtilsChat {
|
||||
public static String getPrefix() {
|
||||
return "<dark_gray>[<gradient:#D72A09:#B01F03>War<dark_gray>]<reset> ";
|
||||
}
|
||||
|
||||
public static String color(final String input) {
|
||||
return ChatColor.translateAlternateColorCodes('&', input);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user