finalize creation of events through console

This commit is contained in:
Aubri Seebauer committed 2023-04-28 18:31:36 -04:00
1 parent 6c6828f7fa
commit 95175f1057
4 files changed
+63 -45

No files matched your search

@@ -144,6 +144,7 @@ public class AdminCommands implements CommandExecutor {
//specific behavior exists if an admin ran this
//using same method so that this doesnt get fucked up if we go back and change original implementation
RaidCommands.startRaid(p, args, true);
p.sendMessage(Helper.color("&cForcefully started raid from the console."));
return true;
} else {
//defaultCode will bypass the custom gather town to force set owner
@@ -157,10 +158,12 @@ public class AdminCommands implements CommandExecutor {
"start",
args[2],
args[3],
args[4]
args[4],
args[5]
};
SiegeCommands.siegeStart(p, adjusted, true);
p.sendMessage(Helper.Chatlabel() + "Try again later!");
// p.sendMessage(Helper.Chatlabel() + "Try again later!");
p.sendMessage(Helper.color("&cForcefully started siege from the console."));
return true;
} else {
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create siege [war] [town] (owner)"));
@@ -177,6 +180,7 @@ public class AdminCommands implements CommandExecutor {
args[4]
};
WarCommands.warCreate(p, adjusted);
p.sendMessage(Helper.color("&cForcefully started war from the console."));
return true;
} else {
p.sendMessage(Helper.color("&cUsage: /alathrawaradmin create war [name] [side1] [side2]"));
@@ -26,33 +26,33 @@ public class RaidCommands implements CommandExecutor {
}
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
final Player p = (Player) sender;
// final Player p = (Player) sender;
if (args.length == 0) {
fail(p, args, "syntax");
fail(sender, args, "syntax");
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("list")) {
listRaids(p, args);
listRaids(sender, args);
} else if (args[0].equalsIgnoreCase("help")) {
raidHelp(p, args);
raidHelp(sender, args);
} else {
fail(p, args, "syntax");
fail(sender, args, "syntax");
}
}else if (args.length == 3) {
if (args[0].equalsIgnoreCase("start")) {
startRaid(p, args, false);
startRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("stop")) {
stopRaid(p, args);
stopRaid(sender, args);
} else if (args[0].equalsIgnoreCase("join")) {
joinRaid(p, args, false);
joinRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("leave")) {
leaveRaid(p, args, false);
leaveRaid(sender, args, false);
} else if (args[0].equalsIgnoreCase("abandon")) {
abandonRaid(p, args);
abandonRaid(sender, args);
} else {
fail(p, args, "syntax");
fail(sender, args, "syntax");
}
} else {
fail(p, args, "syntax");
fail(sender, args, "syntax");
}
return true;
}
@@ -72,14 +72,9 @@ public class RaidCommands implements CommandExecutor {
warFound = true;
Player raidOwner = null;
if(p instanceof Player) {
if((p instanceof Player)) {
raidOwner = (Player) p;
} else {
p.sendMessage("Running this from the console requires a Player Argument!");
return;
}
TownyWorld townyWorld;
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
if(admin && args.length >= 6) {
raidOwner = Bukkit.getPlayer(args[5]);
if(raidOwner == null) {
@@ -88,10 +83,13 @@ public class RaidCommands implements CommandExecutor {
}
}
TownyWorld townyWorld;
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
String side = "";
if (war.getSide1Players().contains(p.getName())) {
if (war.getSide1Players().contains(raidOwner.getName())) {
side = war.getSide1();
} else if (war.getSide2Players().contains(p.getName())) {
} else if (war.getSide2Players().contains(raidOwner.getName())) {
side = war.getSide2();
} else {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
@@ -100,7 +98,7 @@ public class RaidCommands implements CommandExecutor {
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
if (admin) {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(args[3]) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(raidOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
if(args.length >= 5) {
//player has joined to recently
p.sendMessage(ChatColor.RED + "Warning! Ignoring Minuteman Countermeasure!");
@@ -112,7 +110,7 @@ public class RaidCommands implements CommandExecutor {
}
}
} else {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(p.getName()) < 86400000 * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(raidOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
//player has joined to recently
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return;
@@ -179,7 +177,7 @@ public class RaidCommands implements CommandExecutor {
townExists = true;
Raid raid2;
if (war.getSide1Players().contains(p.getName())) {
if (war.getSide1Players().contains(raidOwner.getName())) {
//Time and raid activity validity check
int c = RaidData.isValidRaid(war, side, raidedTown);
if (c == 2) {
@@ -206,7 +204,7 @@ public class RaidCommands implements CommandExecutor {
}
} else {
//Something broke if this runs
if (!war.getSide2Players().contains(p.getName())) {
if (!war.getSide2Players().contains(raidOwner.getName())) {
Bukkit.getLogger().info("Unable to find player declaring raid in the war");
return;
}
@@ -392,7 +390,7 @@ public class RaidCommands implements CommandExecutor {
}
}
} else {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(p.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(joiner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
//player has joined to recently
p.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return;
@@ -60,13 +60,19 @@ public class SiegeCommands implements CommandExecutor {
}
protected static void siegeStart(CommandSender sender, String[] args, boolean admin) {
if (!(sender instanceof Player)) return;
// if (!(sender instanceof Player)) return;
//if this is admin mode use the forth arg instad of sender.
//if player is null after this then force end
Player player = !admin ? (Player) sender : args.length >= 4 ? Bukkit.getPlayer(args[3]) : null;
if(player == null) {
sender.sendMessage("Forced owner not found!");
return;
Player siegeOwner = null;
if((sender instanceof Player)) {
siegeOwner = (Player) sender;
}
if(admin && args.length >= 5) {
siegeOwner = Bukkit.getPlayer(args[3]);
if(siegeOwner == null) {
sender.sendMessage("Player Does not exist");
return;
}
}
if (args.length < 3) {
@@ -77,27 +83,27 @@ public class SiegeCommands implements CommandExecutor {
// War check
War war = WarData.getWar(args[1]);
if (war == null) {
player.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /siege start [war] [town]");
siegeOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /siege start [war] [town]");
if(admin) sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /siege start [war] [town]");
return;
}
// Player participance check
Town leaderTown = TownyAPI.getInstance().getResident(player).getTownOrNull();
Town leaderTown = TownyAPI.getInstance().getResident(siegeOwner).getTownOrNull();
int side = war.getSide(leaderTown.getName());
if (side == 0) {
player.sendMessage(Helper.Chatlabel() + "You are not in this war.");
siegeOwner.sendMessage(Helper.Chatlabel() + "You are not in this war.");
if(admin) sender.sendMessage(Helper.Chatlabel() + "You are not in this war.");
return;
} else if (side == -1) {
player.sendMessage(Helper.Chatlabel() + "You have surrendered.");
siegeOwner.sendMessage(Helper.Chatlabel() + "You have surrendered.");
if(admin) sender.sendMessage(Helper.Chatlabel() + "You have surrendered.");
return;
}
//Minutemen countermeasures, 86400 * 4 time. 86400 seconds in a day, 4 days min playtime
if (admin) {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(args[3]) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(siegeOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
if(args.length >= 5) {
if (Boolean.parseBoolean(args[4])) {
//player has joined to recently
@@ -105,20 +111,20 @@ public class SiegeCommands implements CommandExecutor {
} else {
//player has joined to recently
sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
player.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
siegeOwner.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return;
}
} else {
//player has joined to recently
sender.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
player.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
siegeOwner.getPlayer().sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return;
}
}
} else {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(player.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
if (System.currentTimeMillis() - CommandHelper.getPlayerJoinDate(siegeOwner.getName()) < 86400000L * Main.getInstance().getConfig().getInt("minimumPlayerAge") ) {
//player has joined to recently
player.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
siegeOwner.sendMessage(ChatColor.RED + "You have joined the server too recently! You can only join a war after 4 days from joining.");
return;
}
}
@@ -126,7 +132,7 @@ public class SiegeCommands implements CommandExecutor {
// Town check
Town town = TownyAPI.getInstance().getTown(args[2]);
if (town == null) {
player.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /siege start [war] [town]");
siegeOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /siege start [war] [town]");
if(admin) sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /siege start [war] [town]");
return;
}
@@ -134,19 +140,20 @@ public class SiegeCommands implements CommandExecutor {
// Is being raided check
for ( Raid r : RaidData.getRaids()) {
if(r.getRaidedTown().getName().equals(town.getName())) {
player.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town is already currently being raided! Cannot siege at this time!");
siegeOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town is already currently being raided! Cannot siege at this time!");
if(admin) sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town is already currently being raided! Cannot siege at this time!");
return;
}
}
// Attacking own side
if (war.getSide(town) == side) {
player.sendMessage(Helper.Chatlabel() + "You cannot attack your own towns.");
siegeOwner.sendMessage(Helper.Chatlabel() + "You cannot attack your own towns.");
if(admin) sender.sendMessage(Helper.Chatlabel() + "You cannot attack your own towns.");
return;
}
Siege siege = new Siege(war, town, player);
Siege siege = new Siege(war, town, siegeOwner);
SiegeData.addSiege(siege);
war.addSiege(siege);
@@ -10,6 +10,7 @@ import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.War;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import javax.annotation.Nonnull;
@@ -19,10 +20,18 @@ public class RaidData {
// Static Raid list for all active raids
private static ArrayList<Raid> raids = new ArrayList<Raid>();
private static Set<NamespacedKey> raidBars = new HashSet<>();
public static Set<NamespacedKey> getRaidBars() {
return raidBars;
}
public static ArrayList<Raid> getRaids() {
return raids;
}
/**
* Gets a raid with a specific name
*