mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 22:14:45 +00:00
force join raid/war
This commit is contained in:
1 parent
9a49325c36
commit
ab1ce3d70f
3 files changed
+143
-34
No files matched your search
@@ -3,6 +3,7 @@ package me.ShermansWorld.AlathraWar.commands;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -194,7 +195,7 @@ public class AdminCommands implements CommandExecutor {
|
||||
* //force player into or out of a war/event
|
||||
* -force join war [player] [war] [side]
|
||||
* -force join siege [player] [war] [town] (side)
|
||||
* -force join raid [player] [war] [town] (side)
|
||||
* -force join raid [player] [war] [town] (side) //TODO time until must be in gather?
|
||||
* -force leave war [war] [player] (timeout)
|
||||
* -force leave siege [war] [player] (timeout)
|
||||
* -force leave raid [war] [player] (timeout) //kicks from raid party
|
||||
@@ -206,11 +207,89 @@ public class AdminCommands implements CommandExecutor {
|
||||
private static boolean force(Player p, String[] args) {
|
||||
if(args.length >= 2) {
|
||||
if(args[1].equalsIgnoreCase("end")) {
|
||||
if(args.length >= 3) {
|
||||
if(args[2].equalsIgnoreCase("raid")) {
|
||||
|
||||
} else if(args[2].equalsIgnoreCase("siege")) {
|
||||
|
||||
} else if(args[2].equalsIgnoreCase("war")) {
|
||||
|
||||
} else {
|
||||
p.sendMessage(Helper.color("c") + "Usage: /alathrawaradmin force end [raid/siege/war]");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(Helper.color("c") + "Usage: /alathrawaradmin force end [raid/siege/war]");
|
||||
return false;
|
||||
}
|
||||
} else if(args[1].equalsIgnoreCase("join")) {
|
||||
|
||||
if(args.length >= 3) {
|
||||
if(args[2].equalsIgnoreCase("raid")) {
|
||||
if(args.length >= 6) {
|
||||
//fix args
|
||||
String[] adjusted = new String[] {
|
||||
args[1], //join
|
||||
args[4], //war
|
||||
args[5], //town
|
||||
args[3], //player
|
||||
args.length >= 7 ? args[6] : null //side
|
||||
};
|
||||
RaidCommands.joinRaid(p, adjusted, true);
|
||||
return true;
|
||||
} else {
|
||||
p.sendMessage(Helper.color("c") + "Usage: /alathrawaradmin force join raid [player] [war] [town] (side)");
|
||||
return false;
|
||||
}
|
||||
} else if(args[2].equalsIgnoreCase("siege")) {
|
||||
//TODO when siege commands are done
|
||||
} else if(args[2].equalsIgnoreCase("war")) {
|
||||
if(args.length >= 6) {
|
||||
//fix args to match
|
||||
String[] adjusted = new String[] {
|
||||
args[1],
|
||||
args[4],
|
||||
args[5],
|
||||
args[3]
|
||||
};
|
||||
//find the player
|
||||
if(Bukkit.getPlayer(args[3]) != null) {
|
||||
p = Bukkit.getPlayer(args[3]);
|
||||
} else {
|
||||
p.sendMessage(Helper.color("c") + args[3] + " does not exist!");
|
||||
p.sendMessage(Helper.color("c") + "Usage: /alathrawaradmin force join war [player] [war] [side]");
|
||||
return false;
|
||||
}
|
||||
WarCommands.warJoin(p, adjusted, true);
|
||||
p.sendMessage(Helper.color("c") + "Forced " + args[3] + " to join the war " + args[4] + " on side " + args[5]);
|
||||
Main.warLogger.log("Forced " + args[3] + " to join the war " + args[4] + " on side " + args[5]);
|
||||
} else {
|
||||
p.sendMessage(Helper.color("c") + "Usage: /alathrawaradmin force join war [player] [war] [side]");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(Helper.color("c") + "Usage: /alathrawaradmin force join [raid/siege/war]");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(Helper.color("c") + "Usage: /alathrawaradmin force join [raid/siege/war]");
|
||||
return false;
|
||||
}
|
||||
} else if(args[1].equalsIgnoreCase("leave")) {
|
||||
if(args.length >= 3) {
|
||||
if(args[2].equalsIgnoreCase("raid")) {
|
||||
|
||||
} else if(args[2].equalsIgnoreCase("siege")) {
|
||||
|
||||
} else if(args[2].equalsIgnoreCase("war")) {
|
||||
|
||||
} else {
|
||||
p.sendMessage(Helper.color("c") + "Usage: /alathrawaradmin force leave [raid/siege/war]");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(Helper.color("c") + "Usage: /alathrawaradmin force leave [raid/siege/war]");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return fail(p, args, "syntax");
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ 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 com.palmergames.bukkit.towny.object.metadata.LongDataField;
|
||||
import me.ShermansWorld.AlathraWar.*;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
@@ -46,9 +45,9 @@ public class RaidCommands implements CommandExecutor {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
startRaid(p, args, false);
|
||||
} else if (args[0].equalsIgnoreCase("join")) {
|
||||
joinRaid(p, args);
|
||||
joinRaid(p, args, false);
|
||||
} else if (args[0].equalsIgnoreCase("leave")) {
|
||||
leaveRaid(p, args);
|
||||
leaveRaid(p, args, false);
|
||||
} else if (args[0].equalsIgnoreCase("abandon")) {
|
||||
abandonRaid(p, args);
|
||||
} else {
|
||||
@@ -67,7 +66,7 @@ public class RaidCommands implements CommandExecutor {
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
public static void startRaid(Player p, String[] args, boolean admin) {
|
||||
protected static void startRaid(Player p, String[] args, boolean admin) {
|
||||
boolean warFound = false;
|
||||
boolean townExists = false;
|
||||
for (final War war : WarData.getWars()) {
|
||||
@@ -218,6 +217,7 @@ public class RaidCommands implements CommandExecutor {
|
||||
"The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
|
||||
|
||||
Main.warLogger.log(p.getName() + " started a raid.");
|
||||
if(admin) Main.warLogger.log(p.getName() + " started a raid using admin methods.");
|
||||
Main.warLogger.log("As part of " + war.getName() + ", forces from " + raid2.getRaiders() + " are raiding the town of " + raidedTown.getName() + "!");
|
||||
Main.warLogger.log("The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
|
||||
}
|
||||
@@ -264,13 +264,34 @@ public class RaidCommands implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private static void joinRaid(Player p, String[] args) {
|
||||
protected static void joinRaid(Player p, String[] args, boolean admin) {
|
||||
//Grab raid!
|
||||
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
|
||||
if (raid != null) {
|
||||
if (raid.getWar().getName().equalsIgnoreCase(args[1])) {
|
||||
if (!raid.getWar().getSide1Players().contains(p.getName()) && !raid.getWar().getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
Player joiner = p;
|
||||
if (admin) {
|
||||
joiner = Bukkit.getOfflinePlayer(args[3]).getPlayer();
|
||||
|
||||
if(args[4] != null) {
|
||||
if(args[4].equals(raid.getDefenders())) {
|
||||
if(!raid.getDefenderPlayers().contains(joiner.getName()))
|
||||
raid.getDefenderPlayers().add(joiner.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Player " + joiner.getName() + " added to defender side.");
|
||||
Main.warLogger.log("Player " + joiner.getName() + " added to defender side.");
|
||||
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You were forcefully added to the defender side against the raid party on " + raid.getRaidedTown() + " by an admin.");
|
||||
return;
|
||||
} else {
|
||||
if(!raid.getRaiderPlayers().contains(joiner.getName()))
|
||||
raid.getRaiderPlayers().add(joiner.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Player " + joiner.getName() + " added to raider side.");
|
||||
Main.warLogger.log("Player " + joiner.getName() + " added to raider side.");
|
||||
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You were forcefully added to the raid party on " + raid.getRaidedTown() + " by an admin. Leaving the gather town will remove you from the raid party.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!raid.getWar().getSide1Players().contains(joiner.getName()) && !raid.getWar().getSide2Players().contains(joiner.getName())) {
|
||||
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
@@ -278,18 +299,18 @@ public class RaidCommands implements CommandExecutor {
|
||||
try {
|
||||
//check if the player is in the gather town
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(raid.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
raid.addActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(joiner))) {
|
||||
raid.addActiveRaider(joiner.getName());
|
||||
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "Leaving " + raid.getGatherTown().getName() + " will cause you to leave the raid party.");
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
|
||||
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be in the gathering town to join the raid on " + raid.getRaidedTown().getName() + ".");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
joiner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot join the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -297,7 +318,7 @@ public class RaidCommands implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private static void leaveRaid(Player p, String[] args) {
|
||||
protected static void leaveRaid(Player p, String[] args, boolean admin) {
|
||||
//Get raid!
|
||||
Raid raid = RaidData.getRaidOrNull(args[1] + "-" + args[2]);
|
||||
if (raid != null) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
@@ -19,21 +20,21 @@ import org.bukkit.command.CommandExecutor;
|
||||
|
||||
public class WarCommands implements CommandExecutor {
|
||||
|
||||
public WarCommands(final Main plugin) {
|
||||
plugin.getCommand("war").setExecutor((CommandExecutor) this);
|
||||
}
|
||||
public WarCommands(final Main plugin) {
|
||||
plugin.getCommand("war").setExecutor((CommandExecutor) this);
|
||||
}
|
||||
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
consoleCommand(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player p = (Player) sender;
|
||||
if (args.length == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war help");
|
||||
final Player p = (Player) sender;
|
||||
if (args.length == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /war help");
|
||||
return true;
|
||||
} else if (args.length >= 1) {
|
||||
} else if (args.length >= 1) {
|
||||
|
||||
switch(args[0].toLowerCase()) {
|
||||
case "create":
|
||||
@@ -43,7 +44,7 @@ public class WarCommands implements CommandExecutor {
|
||||
warDelete(p, args);
|
||||
return true;
|
||||
case "join":
|
||||
warJoin(p, args);
|
||||
warJoin(p, args, false);
|
||||
return true;
|
||||
case "surrender":
|
||||
warSurrender(p, args);
|
||||
@@ -62,11 +63,11 @@ public class WarCommands implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void warCreate(Player p, String[] args) {
|
||||
protected static void warCreate(Player p, String[] args) {
|
||||
if (!p.hasPermission("AlathraWar.admin")) {
|
||||
p.sendMessage("You do not have permission to run this command.");
|
||||
return;
|
||||
@@ -115,7 +116,13 @@ public class WarCommands implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private static void warJoin(Player p, String[] args) {
|
||||
/**
|
||||
*
|
||||
* @param p - executor
|
||||
* @param args
|
||||
* @param admin - admin behavior
|
||||
*/
|
||||
protected static void warJoin(Player p, String[] args, boolean admin) {
|
||||
// Sufficient args check
|
||||
if (args.length < 3) {
|
||||
p.sendMessage(Helper.Chatlabel()
|
||||
@@ -131,8 +138,8 @@ public class WarCommands implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
|
||||
// Towny Resident Object
|
||||
Resident res = TownyAPI.getInstance().getResident(p);
|
||||
// Towny Resident Object, if admin then dont use command runner, use declared player
|
||||
Resident res = TownyAPI.getInstance().getResident(admin ? Bukkit.getPlayer(args[3]) : p);
|
||||
|
||||
// Town check
|
||||
Town town = res.getTownOrNull();
|
||||
@@ -152,9 +159,10 @@ public class WarCommands implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (res.hasNation()) {
|
||||
if(p.hasPermission("AlathraWar.nationjoin" )|| res.isKing()) {
|
||||
if(res.getPlayer().hasPermission("AlathraWar.nationjoin" )|| res.isKing()) {
|
||||
// Has nation declaration permission
|
||||
war.addNation(res.getNationOrNull(), args[2]);
|
||||
res.getPlayer().sendMessage(Helper.Chatlabel() + "You have joined the war for " + res.getNationOrNull().getName());
|
||||
p.sendMessage(Helper.Chatlabel() + "You have joined the war for " + res.getNationOrNull().getName());
|
||||
war.save();
|
||||
return;
|
||||
@@ -164,9 +172,10 @@ public class WarCommands implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
} else if (res.hasTown()) {
|
||||
if (p.hasPermission("AlathraWar.townjoin") || res.isMayor()) {
|
||||
if (res.getPlayer().hasPermission("AlathraWar.townjoin") || res.isMayor()) {
|
||||
// Is in indepdenent town & has declaration perms
|
||||
war.addTown(res.getTownOrNull(), args[2]);
|
||||
res.getPlayer().sendMessage(Helper.Chatlabel() + "You have joined the war for " + res.getTownOrNull().getName());
|
||||
p.sendMessage(Helper.Chatlabel() + "You have joined the war for " + res.getTownOrNull().getName());
|
||||
war.save();
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user