mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 22:14:45 +00:00
Merge pull request #17 from ShermansWorld/feature/admin-command
Feature/admin command merge
This commit is contained in:
19 files changed
+3565
-466
No files matched your search
+25
-25
@@ -1,25 +1,25 @@
|
||||
name: AlathraWar
|
||||
version: 1.3.2
|
||||
api-version: 1.19
|
||||
author: ShermansWorld
|
||||
main: me.ShermansWorld.AlathraWar.Main
|
||||
depend: [Vault, Towny, TAB]
|
||||
|
||||
commands:
|
||||
war:
|
||||
description: used to create, delete, join and leave wars
|
||||
softdepend: [Vault, Towny, TAB]
|
||||
usage: /war
|
||||
siege:
|
||||
description: used to start, end, and view sieges
|
||||
softdepend: [Vault, Towny]
|
||||
usage: /siege
|
||||
raid:
|
||||
description: used to start, end, and view raids
|
||||
softdepend: [Vault, Towny]
|
||||
usage: /raid
|
||||
alathrawaradmin:
|
||||
description: used to administrate wars and modify existing events
|
||||
softdepend: [Vault, Towny, TAB]
|
||||
usage: /alathrawaradmin
|
||||
aliases: [awa]
|
||||
name: AlathraWar
|
||||
version: 1.3.2
|
||||
api-version: 1.19
|
||||
author: ShermansWorld
|
||||
main: me.ShermansWorld.AlathraWar.Main
|
||||
depend: [Vault, Towny, TAB]
|
||||
|
||||
commands:
|
||||
war:
|
||||
description: used to create, delete, join and leave wars
|
||||
softdepend: [Vault, Towny, TAB]
|
||||
usage: /war
|
||||
siege:
|
||||
description: used to start, end, and view sieges
|
||||
softdepend: [Vault, Towny]
|
||||
usage: /siege
|
||||
raid:
|
||||
description: used to start, end, and view raids
|
||||
softdepend: [Vault, Towny]
|
||||
usage: /raid
|
||||
alathrawaradmin:
|
||||
description: used to administrate wars and modify existing events
|
||||
softdepend: [Vault, Towny, TAB]
|
||||
usage: /alathrawaradmin
|
||||
aliases: [awa]
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.commands.*;
|
||||
import me.ShermansWorld.AlathraWar.data.TimeoutData;
|
||||
import me.ShermansWorld.AlathraWar.listeners.CommandsListener;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
@@ -81,12 +82,15 @@ public class Main extends JavaPlugin {
|
||||
initLogs();
|
||||
|
||||
new WarData(this);
|
||||
// new TimeoutData(this);
|
||||
new WarCommands(this);
|
||||
new SiegeCommands(this);
|
||||
new RaidCommands(this);
|
||||
new AdminCommands(this);
|
||||
getCommand("war").setTabCompleter(new WarTabCompletion());
|
||||
getCommand("siege").setTabCompleter(new SiegeTabCompletion());
|
||||
getCommand("raid").setTabCompleter(new RaidTabCompletion());
|
||||
getCommand("alathrawaradmin").setTabCompleter(new AdminTabCompletion());
|
||||
getServer().getPluginManager().registerEvents((Listener) new KillsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new CommandsListener(), (Plugin) this);
|
||||
getServer().getPluginManager().registerEvents((Listener) new JoinListener(), (Plugin) this);
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import com.palmergames.bukkit.towny.object.metadata.LongDataField;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -76,7 +77,7 @@ public class Raid {
|
||||
private String defenders;
|
||||
private boolean side1AreRaiders;
|
||||
private int raidScore;
|
||||
private Player owner;
|
||||
private OfflinePlayer owner;
|
||||
private int raidTicks;
|
||||
private TownBlock homeBlockRaided;
|
||||
private TownBlock homeBlockGather;
|
||||
@@ -84,9 +85,9 @@ public class Raid {
|
||||
private Location townSpawnRaided;
|
||||
private Location townSpawnGather;
|
||||
int[] bukkitId;
|
||||
public ArrayList<String> activeRaiders;
|
||||
public ArrayList<String> raiderPlayers;
|
||||
public ArrayList<String> defenderPlayers;
|
||||
public ArrayList<String> activeRaiders = new ArrayList<>();
|
||||
public ArrayList<String> raiderPlayers = new ArrayList<>();
|
||||
public ArrayList<String> defenderPlayers = new ArrayList<>();
|
||||
public Map<WorldCoord, LootBlock> lootedChunks;
|
||||
|
||||
/**
|
||||
@@ -99,17 +100,20 @@ public class Raid {
|
||||
* @param raidTicks
|
||||
*/
|
||||
public Raid(final War war, final Town raidedTown, final Town gatherTown,
|
||||
final boolean side1AreRaiders, final int raidTicks) {
|
||||
final boolean side1AreRaiders, final int raidTicks, OfflinePlayer owner) {
|
||||
|
||||
this.bukkitId = new int[1];
|
||||
// this.activeRaiders = activeRaiders == null ? new ArrayList<>() : activeRaiders;
|
||||
this.war = war;
|
||||
this.raidTicks = raidTicks;
|
||||
this.raidedTown = raidedTown;
|
||||
this.gatherTown = gatherTown;
|
||||
this.owner = owner;
|
||||
this.raiders = side1AreRaiders ? war.getSide1() : war.getSide2();
|
||||
this.defenders = !side1AreRaiders ? war.getSide1() : war.getSide2();
|
||||
this.raidScore = 500;
|
||||
|
||||
//AttackSide-Town
|
||||
this.name = (side1AreRaiders ? war.getSide1() : war.getSide2()).toLowerCase() + "-" + raidedTown.getName().toLowerCase();
|
||||
this.name = war.getName() + "-" + raidedTown.getName().toLowerCase();
|
||||
this.lootedChunks = new HashMap<>();
|
||||
|
||||
}
|
||||
@@ -125,8 +129,8 @@ public class Raid {
|
||||
* @param activeRaiders
|
||||
* @param phase
|
||||
*/
|
||||
public Raid(final War war, final Town raidedTown, final Town gatherTown, final boolean side1AreRaiders, final int raidTicks, ArrayList<String> activeRaiders, RaidPhase phase) {
|
||||
this(war, raidedTown, gatherTown, side1AreRaiders, raidTicks);
|
||||
public Raid(final War war, final Town raidedTown, final Town gatherTown, final boolean side1AreRaiders, final int raidTicks, ArrayList<String> activeRaiders, RaidPhase phase, OfflinePlayer owner) {
|
||||
this(war, raidedTown, gatherTown, side1AreRaiders, raidTicks, owner);
|
||||
this.activeRaiders = activeRaiders;
|
||||
this.setRaidPhase(phase);
|
||||
}
|
||||
@@ -141,16 +145,20 @@ public class Raid {
|
||||
* @param side1AreRaiders
|
||||
*/
|
||||
public Raid(final War war, final Town raidedTown, final Town gatherTown,
|
||||
final boolean side1AreRaiders) {
|
||||
final boolean side1AreRaiders, OfflinePlayer owner) {
|
||||
this.bukkitId = new int[1];
|
||||
// this.activeRaiders = activeRaiders == null ? new ArrayList<>() : activeRaiders;
|
||||
this.war = war;
|
||||
this.raidTicks = 0;
|
||||
this.raidedTown = raidedTown;
|
||||
this.gatherTown = gatherTown;
|
||||
this.owner = owner;
|
||||
this.raiders = side1AreRaiders ? war.getSide1() : war.getSide2();
|
||||
this.defenders = !side1AreRaiders ? war.getSide1() : war.getSide2();
|
||||
this.raidScore = 500;
|
||||
|
||||
//AttackSide-Town
|
||||
this.name = (side1AreRaiders ? war.getSide1() : war.getSide2()).toLowerCase() + "-" + raidedTown.getName().toLowerCase();
|
||||
this.name = war.getName() + "-" + raidedTown.getName().toLowerCase();
|
||||
this.lootedChunks = new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -182,13 +190,22 @@ public class Raid {
|
||||
|
||||
//set the last raided time to now
|
||||
raidedTown.addMetaData(new LongDataField("lastRaided", (System.currentTimeMillis() / 1000)));
|
||||
war.setLastRaidTime((int) (System.currentTimeMillis() / 1000));
|
||||
if(war.getSide1Players().contains(owner.getName())) {
|
||||
war.setLastRaidTimeSide1((int) (System.currentTimeMillis() / 1000));
|
||||
} else if(war.getSide2Players().contains(owner.getName())) {
|
||||
war.setLastRaidTimeSide2((int) (System.currentTimeMillis() / 1000));
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
// Creates 10 second looping function for Raid
|
||||
|
||||
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(),
|
||||
getTickLoop(), 0L, incremental);
|
||||
|
||||
this.getWar().addRaid(this);
|
||||
this.save();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -221,12 +238,10 @@ public class Raid {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* End of raid
|
||||
*/
|
||||
public void stop() {
|
||||
this.phase = RaidPhase.END;
|
||||
Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
|
||||
RaidData.removeRaid(this);
|
||||
}
|
||||
@@ -238,7 +253,7 @@ public class Raid {
|
||||
* @param p
|
||||
* @param wc
|
||||
*/
|
||||
private synchronized void doLootAt(Player p, WorldCoord wc) {
|
||||
public synchronized void doLootAt(Player p, WorldCoord wc) {
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 60, 0, true, false, true));
|
||||
|
||||
//check if this loot is in progress
|
||||
@@ -255,23 +270,29 @@ public class Raid {
|
||||
//score for looting
|
||||
this.addPointsToRaidScore(10);
|
||||
|
||||
Main.warLogger.log(String.format("A townblock has been looted for $%.2d", lb.value));
|
||||
Main.warLogger.log(String.format("A townblock has been looted for $%.2f", lb.value));
|
||||
//Broadcast to the whole raid
|
||||
for (String s : activeRaiders) {
|
||||
Bukkit.getPlayer(s).sendMessage(Helper.Chatlabel() + String.format("A townblock has been looted for $%.2d and +10 points. (Added to pool)", lb.value));
|
||||
Player pl = Bukkit.getPlayer(s);
|
||||
if(pl != null) pl.sendMessage(Helper.Chatlabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
|
||||
}
|
||||
for (String s : defenderPlayers) {
|
||||
Bukkit.getPlayer(s).sendMessage(Helper.Chatlabel() + String.format("A townblock has been looted for $%.2d and +10 points. (Added to pool)", lb.value));
|
||||
Player pl = Bukkit.getPlayer(s);
|
||||
if(pl != null) pl.sendMessage(Helper.Chatlabel() + String.format("A townblock has been looted for $%.2f and +10 points. (Added to pool)", lb.value));
|
||||
}
|
||||
|
||||
this.save();
|
||||
}
|
||||
} else {
|
||||
//if not make a new property for it
|
||||
this.addLootedChunk(wc);
|
||||
for (String s : activeRaiders) {
|
||||
Bukkit.getPlayer(s).sendMessage(Helper.Chatlabel() + "Raiders have started looting a town block!");
|
||||
Player pl = Bukkit.getPlayer(s);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raiders have started looting a town block!");
|
||||
}
|
||||
for (String s : defenderPlayers) {
|
||||
Bukkit.getPlayer(s).sendMessage(Helper.Chatlabel() + "Raiders have started looting a town block!");
|
||||
Player pl = Bukkit.getPlayer(s);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raiders have started looting a town block!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,27 +339,12 @@ public class Raid {
|
||||
//award negative score
|
||||
this.subtractPointsFromRaidScore(40);
|
||||
for (final String playerName : this.getActiveRaiders()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score");
|
||||
} catch (NullPointerException ex3) {
|
||||
}
|
||||
Player pl = Bukkit.getPlayer(playerName);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score");
|
||||
}
|
||||
for (final String playerName : this.getDefenderPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score");
|
||||
} catch (NullPointerException ex4) {
|
||||
}
|
||||
}
|
||||
|
||||
//tp to gather town spawn
|
||||
final Player killed = event.getEntity();
|
||||
if (this.getActiveRaiders().contains(killed.getName())) {
|
||||
try {
|
||||
killed.teleport(this.getGatherTown().getSpawn());
|
||||
killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died raiding and have been teleported back to the gather point.");
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Player pl = Bukkit.getPlayer(playerName);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,24 +354,20 @@ public class Raid {
|
||||
public void defenderKilledInCombat(PlayerDeathEvent event) {
|
||||
this.addPointsToRaidScore(20);
|
||||
for (final String playerName : this.getActiveRaiders()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
|
||||
} catch (NullPointerException ex5) {
|
||||
}
|
||||
Player pl = Bukkit.getPlayer(playerName);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
|
||||
}
|
||||
for (final String playerName : this.getDefenderPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
|
||||
} catch (NullPointerException ex6) {
|
||||
}
|
||||
Player pl = Bukkit.getPlayer(playerName);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! +20 Raid Score");
|
||||
}
|
||||
|
||||
//tp to raid town spawn
|
||||
final Player killed = event.getEntity();
|
||||
if (this.getActiveRaiders().contains(killed.getName())) {
|
||||
// killed.teleport(this.getGatherTown().getSpawn());
|
||||
// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died raiding and have been teleported back to your town's spawn.");
|
||||
}
|
||||
// //tp to raid town spawn
|
||||
// final Player killed = event.getEntity();
|
||||
// if (this.getActiveRaiders().contains(killed.getName())) {
|
||||
// // killed.teleport(this.getGatherTown().getSpawn());
|
||||
//// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died raiding and have been teleported back to your town's spawn.");
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -375,36 +377,32 @@ public class Raid {
|
||||
|
||||
//award negative score
|
||||
for (final String playerName : this.getActiveRaiders()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
|
||||
} catch (NullPointerException ex3) {
|
||||
}
|
||||
Player pl = Bukkit.getPlayer(playerName);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
|
||||
}
|
||||
for (final String playerName : this.getDefenderPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
|
||||
} catch (NullPointerException ex4) {
|
||||
}
|
||||
Player pl = Bukkit.getPlayer(playerName);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed before combat, no points awarded and death treated normally.");
|
||||
}
|
||||
|
||||
//tp to gather town spawn
|
||||
//
|
||||
// //tp to gather town spawn
|
||||
final Player killed = event.getEntity();
|
||||
if (this.getActiveRaiders().contains(killed.getName())) {
|
||||
try {
|
||||
killed.teleport(this.getGatherTown().getSpawn());
|
||||
killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before raiding and have been teleported back to the gather point.");
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// if (this.getActiveRaiders().contains(killed.getName())) {
|
||||
// try {
|
||||
// } catch (TownyException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
//teleport the killer back to the raided towns spawn
|
||||
if (this.getDefenders().contains(killed.getKiller().getName())) {
|
||||
try {
|
||||
killed.getKiller().teleport(this.getRaidedTown().getSpawn());
|
||||
killed.getKiller().sendMessage(String.valueOf(Helper.Chatlabel()) + "You killed a raider before the raid began and have been teleported back to the defending town.");
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
if(killed.getKiller() != null) {
|
||||
if (this.getDefenders().contains(killed.getKiller().getName())) {
|
||||
try {
|
||||
killed.getKiller().teleport(this.getRaidedTown().getSpawn());
|
||||
killed.getKiller().sendMessage(String.valueOf(Helper.Chatlabel()) + "You killed a raider before the raid began and have been teleported back to the defending town.");
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -414,27 +412,23 @@ public class Raid {
|
||||
*/
|
||||
public void defenderKilledOutofCombat(PlayerDeathEvent event) {
|
||||
for (final String playerName : this.getActiveRaiders()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
|
||||
} catch (NullPointerException ex5) {
|
||||
}
|
||||
Player pl = Bukkit.getPlayer(playerName);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
|
||||
}
|
||||
for (final String playerName : this.getDefenderPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
|
||||
} catch (NullPointerException ex6) {
|
||||
}
|
||||
Player pl = Bukkit.getPlayer(playerName);
|
||||
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed before combat, no points awarded and death treated normally.");
|
||||
}
|
||||
|
||||
//tp to raid town spawn
|
||||
final Player killed = event.getEntity();
|
||||
if (this.getDefenders().contains(killed.getName())) {
|
||||
// killed.teleport(this.getGatherTown().getSpawn());
|
||||
// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before being raided and have been teleported back to the defending town's spawn.");
|
||||
}
|
||||
// if (this.getDefenders().contains(killed.getName())) {
|
||||
//// killed.teleport(this.getGatherTown().getSpawn());
|
||||
//// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before being raided and have been teleported back to the defending town's spawn.");
|
||||
// }
|
||||
|
||||
//teleport the killer back to the raided towns spawn
|
||||
if (killed.getKiller() instanceof Player) {
|
||||
//teleport the killer back to the gather towns spawn
|
||||
if (killed.getKiller() != null) {
|
||||
if (this.getActiveRaiders().contains(killed.getKiller().getName())) {
|
||||
try {
|
||||
killed.getKiller().teleport(this.getGatherTown().getSpawn());
|
||||
@@ -452,7 +446,7 @@ public class Raid {
|
||||
* @param owner
|
||||
* @param raidScore
|
||||
*/
|
||||
public void raidersWin(final Player owner, int raidScore) {
|
||||
public void raidersWin(final OfflinePlayer owner, int raidScore) {
|
||||
//TODO finalize payout
|
||||
|
||||
//Calc win factor
|
||||
@@ -461,8 +455,9 @@ public class Raid {
|
||||
//factor is 0.5 -> 3
|
||||
double factor = ((raidScore - 800.0) / 100) + 0.5;
|
||||
if (factor > 3.0) factor = 3.0;
|
||||
if (factor < 0) factor = 0.0;
|
||||
|
||||
final Resident resident = TownyAPI.getInstance().getResident(owner);
|
||||
final Resident resident = TownyAPI.getInstance().getResident(owner.getUniqueId());
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raiders from " + this.raiders
|
||||
+ " have successfully raided " + this.raidedTown.getName() + "!");
|
||||
|
||||
@@ -535,13 +530,14 @@ public class Raid {
|
||||
|
||||
double factor = (3 - ((raidScore) / 200.0) - 0.5);
|
||||
if (factor > 3.0) factor = 3.0;
|
||||
if (factor < 0) factor = 0.0;
|
||||
|
||||
String statement = "raided";
|
||||
if (factor <= 0.5) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders
|
||||
+ " have barely pushed back the raiders of " + this.raiders + ". More has been lost than gained.");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.raidedTown.getName()
|
||||
+ " has recovered part of the attackers' raid chest, valued at $625");
|
||||
+ " has recovered part of the attackers' raid chest, valued at $500");
|
||||
Main.warLogger
|
||||
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
|
||||
this.raidedTown.getAccount().deposit(500, "Raid chest");
|
||||
@@ -549,7 +545,7 @@ public class Raid {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders
|
||||
+ " have fended off the raiders of " + this.raiders + "!");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.raidedTown.getName()
|
||||
+ " has recovered the attackers' raid chest, valued at $1,250");
|
||||
+ " has recovered the attackers' raid chest, valued at $1000");
|
||||
Main.warLogger
|
||||
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
|
||||
this.raidedTown.getAccount().deposit(1000, "Raid chest");
|
||||
@@ -557,7 +553,7 @@ public class Raid {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders
|
||||
+ " have wholly defeated the raiders of " + this.raiders + "! They barely broke the walls.");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.raidedTown.getName()
|
||||
+ " has recovered the attackers' raid chest, valued at $1,250.");
|
||||
+ " has recovered the attackers' raid chest, valued at $1000.");
|
||||
Main.warLogger
|
||||
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
|
||||
this.raidedTown.getAccount().deposit(1000, "Raid chest");
|
||||
@@ -566,6 +562,20 @@ public class Raid {
|
||||
stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* No winner declared
|
||||
*/
|
||||
public void noWinner() {
|
||||
//TODO finalize payout
|
||||
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders
|
||||
+ " didn't push back the raiders of " + this.raiders + ". Yet no loot was taken, raid considered a draw.");
|
||||
Main.warLogger
|
||||
.log("No one won the raid of " + this.raidedTown.getName() + "!");
|
||||
|
||||
stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Positively impact the raid score
|
||||
*
|
||||
@@ -575,6 +585,7 @@ public class Raid {
|
||||
this.raidScore += points;
|
||||
//cap
|
||||
if (raidScore > 1200) this.raidScore = 1200;
|
||||
if (raidScore < 0) this.raidScore = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -585,6 +596,7 @@ public class Raid {
|
||||
public void subtractPointsFromRaidScore(final int points) {
|
||||
this.raidScore -= points;
|
||||
//cap
|
||||
if (raidScore > 1200) this.raidScore = 1200;
|
||||
if (raidScore < 0) this.raidScore = 0;
|
||||
}
|
||||
|
||||
@@ -617,11 +629,11 @@ public class Raid {
|
||||
this.gatherTown = town;
|
||||
}
|
||||
|
||||
public Player getOwner() {
|
||||
public OfflinePlayer getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public void setOwner(Player owner) {
|
||||
public void setOwner(OfflinePlayer owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@@ -744,9 +756,29 @@ public class Raid {
|
||||
Raid.this.raiderPlayers = Raid.this.war.getSide2Players();
|
||||
Raid.this.defenderPlayers = Raid.this.war.getSide1Players();
|
||||
}
|
||||
if (Raid.this.raidTicks >= RaidPhase.END.startTick) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(Raid.this.bukkitId[0]);
|
||||
raidTicks += incremental;
|
||||
|
||||
//check for end
|
||||
if (Raid.this.raidTicks >= RaidPhase.END.startTick && Raid.this.phase == RaidPhase.COMBAT) {
|
||||
Raid.this.phase = RaidPhase.END;
|
||||
}
|
||||
|
||||
//check and start travel phase
|
||||
if (Raid.this.raidTicks >= RaidPhase.TRAVEL.startTick && Raid.this.phase == RaidPhase.GATHER) {
|
||||
startTravel();
|
||||
}
|
||||
|
||||
//check and start combat phase
|
||||
if (Raid.this.raidTicks >= RaidPhase.COMBAT.startTick && Raid.this.phase == RaidPhase.TRAVEL) {
|
||||
startCombat();
|
||||
}
|
||||
|
||||
//check and start gather phase
|
||||
if (Raid.this.raidTicks >= RaidPhase.GATHER.startTick && Raid.this.phase == RaidPhase.START) {
|
||||
startGather();
|
||||
}
|
||||
|
||||
if (Raid.this.phase == RaidPhase.END) {
|
||||
//TODO: fix raid scoring
|
||||
//for raiders to win, they need a significant up from the defenders
|
||||
if (Raid.this.raidScore > 800) {
|
||||
@@ -754,68 +786,62 @@ public class Raid {
|
||||
} else {
|
||||
Raid.this.defendersWin(Raid.this.raidScore);
|
||||
}
|
||||
} else {
|
||||
raidTicks += incremental;
|
||||
}
|
||||
|
||||
//check and start travel phase
|
||||
if (Raid.this.raidTicks >= RaidPhase.TRAVEL.startTick && Raid.this.phase == RaidPhase.GATHER) {
|
||||
startTravel();
|
||||
//Raid gather phase behavior
|
||||
if (Raid.this.phase == RaidPhase.GATHER) {
|
||||
//Broadcast
|
||||
if (raidTicks % 6000 == 0) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of "
|
||||
+ Raid.this.getRaidedTown().getName() + " will begin in " + (int) ((RaidPhase.TRAVEL.startTick - raidTicks) / 20 / 60) + " minutes!");
|
||||
Bukkit.broadcastMessage(
|
||||
"The Raiders are gathering at " + getGatherTown().getName() + " before making the journey over!");
|
||||
}
|
||||
|
||||
//check and start combat phase
|
||||
if (Raid.this.raidTicks >= RaidPhase.COMBAT.startTick && Raid.this.phase == RaidPhase.TRAVEL) {
|
||||
startCombat();
|
||||
}
|
||||
|
||||
//Raid gather phase behavior
|
||||
if (Raid.this.phase == RaidPhase.GATHER) {
|
||||
//Broadcast
|
||||
if (raidTicks % 6000 == 0) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of "
|
||||
+ Raid.this.getRaidedTown().getName() + " will begin in " + (int) (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!");
|
||||
Bukkit.broadcastMessage(
|
||||
"The Raiders are gathering at " + getGatherTown().getName() + " before making the journey over!");
|
||||
}
|
||||
|
||||
|
||||
//Prevent players from leaving gather town prematurely
|
||||
for (String playerName : getActiveRaiders()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
//Prevent players from leaving gather town prematurely, if player is raid owner, dont do that
|
||||
for (String playerName : getActiveRaiders()) {
|
||||
try {
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if(p != null) {
|
||||
ArrayList<WorldCoord> cluster = Helper.getCluster(Raid.this.getGatherTown().getHomeBlock().getWorldCoord());
|
||||
if (!cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
Raid.this.removeActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "By leaving the gathering town you have left the raid on " + Raid.this.getRaidedTown().getName() + "!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "To rejoin, do /raid join [war] [town]");
|
||||
if (p.equals(owner)) {
|
||||
p.teleport(gatherTown.getSpawn());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot leave the gather town. As raid party leader, you have remained in the party. To stop the raid type /raid abandon");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have been teleported to the gather town's spawn.");
|
||||
} else {
|
||||
Raid.this.removeActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "By leaving the gathering town you have left the raid on " + Raid.this.getRaidedTown().getName() + "!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "To rejoin, do /raid join [war] [town]");
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NotRegisteredException e) {
|
||||
e.printStackTrace();
|
||||
} catch (TownyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (NullPointerException | TownyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Raid Travel phase behavior
|
||||
else if (Raid.this.phase == RaidPhase.TRAVEL) {
|
||||
//Raid Travel phase behavior
|
||||
else if (Raid.this.phase == RaidPhase.TRAVEL) {
|
||||
|
||||
//Report
|
||||
if (raidTicks % 2400 == 0) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The Raiders of "
|
||||
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
|
||||
+ " are on their way to raid "
|
||||
+ Raid.this.getRaidedTown().getName() + "!");
|
||||
}
|
||||
//Report
|
||||
if (raidTicks % 2400 == 0) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The Raiders of "
|
||||
+ (side1AreRaiders ? Raid.this.war.getSide1() : Raid.this.war.getSide2())
|
||||
+ " are on their way to raid "
|
||||
+ Raid.this.getRaidedTown().getName() + "!");
|
||||
}
|
||||
|
||||
//Check if a player has arrived at the town (in it, or within 200 blocks) and if so start combat
|
||||
for (String player : activeRaiders) {
|
||||
try {
|
||||
boolean playerCloseToHomeBlockRaid = false;
|
||||
final int homeBlockXCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
//Check if a player has arrived at the town (in it, or within 200 blocks) and if so start combat
|
||||
for (String player : activeRaiders) {
|
||||
try {
|
||||
boolean playerCloseToHomeBlockRaid = false;
|
||||
final int homeBlockXCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoordRaided = Raid.this.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
if(p != null) {
|
||||
//Carryover from sieges
|
||||
if (Math.abs(p.getLocation().getBlockX() - homeBlockXCoordRaided) <= 200 && Math.abs(p.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 200) {
|
||||
playerCloseToHomeBlockRaid = true;
|
||||
@@ -825,26 +851,30 @@ public class Raid {
|
||||
if (Raid.this.getRaidedTown().hasTownBlock(playercoord) || playerCloseToHomeBlockRaid) {
|
||||
startCombat();
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Raid combat phase behavior
|
||||
else if (Raid.this.phase == RaidPhase.COMBAT) {
|
||||
//Raid combat phase behavior
|
||||
else if (Raid.this.phase == RaidPhase.COMBAT) {
|
||||
|
||||
//Report
|
||||
if (Raid.this.raidTicks % 6000 == 0) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the raid of "
|
||||
+ Raid.this.getRaidedTown().getName() + ":");
|
||||
Bukkit.broadcastMessage(
|
||||
"Raid Score - " + String.valueOf(Raid.this.raidScore));
|
||||
}
|
||||
//Report
|
||||
if (Raid.this.raidTicks % 6000 == 0) {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "Report on the raid of "
|
||||
+ Raid.this.getRaidedTown().getName() + ":");
|
||||
Bukkit.broadcastMessage(
|
||||
"Raid Score - " + String.valueOf(Raid.this.raidScore));
|
||||
Bukkit.broadcastMessage(
|
||||
"Chunks Looted - " + String.valueOf(Raid.this.lootedChunks.size()) + "/" + raidedTown.getTownBlocks().size());
|
||||
}
|
||||
|
||||
//Looting chunks
|
||||
for (String name : Raid.this.getActiveRaiders()) {
|
||||
Player p = Bukkit.getPlayer(name);
|
||||
//Looting chunks
|
||||
for (String name : Raid.this.getActiveRaiders()) {
|
||||
Player p = Bukkit.getPlayer(name);
|
||||
if(p != null) {
|
||||
WorldCoord wc = WorldCoord.parseWorldCoord(p);
|
||||
if (p.isSneaking()) {
|
||||
//check if our chunk is looted, if so skip this player
|
||||
@@ -862,14 +892,6 @@ public class Raid {
|
||||
p.sendMessage(Helper.Chatlabel() + "This space is not part of the raided town, you cannot loot this area.");
|
||||
}
|
||||
}
|
||||
// for (LootBlock c : Raid.this.lootedChunks.values()) {
|
||||
// if (c.worldCoord.equals(wc)) {
|
||||
// looted = true;
|
||||
// p.sendMessage(Helper.Chatlabel() + "This chunk is already looted, try another.");
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -878,6 +900,53 @@ public class Raid {
|
||||
};
|
||||
}
|
||||
|
||||
public void save() {
|
||||
RaidData.saveRaid(this);
|
||||
}
|
||||
|
||||
public TownBlock getHomeBlockRaided() {
|
||||
return homeBlockRaided;
|
||||
}
|
||||
|
||||
public void setHomeBlockRaided(TownBlock homeBlockRaided) {
|
||||
this.homeBlockRaided = homeBlockRaided;
|
||||
}
|
||||
|
||||
public TownBlock getHomeBlockGather() {
|
||||
return homeBlockGather;
|
||||
}
|
||||
|
||||
public void setHomeBlockGather(TownBlock homeBlockGather) {
|
||||
this.homeBlockGather = homeBlockGather;
|
||||
}
|
||||
|
||||
public void setPhase(RaidPhase phase) {
|
||||
this.phase = phase;
|
||||
if(phase == RaidPhase.GATHER) {
|
||||
startGather();
|
||||
} else if(phase == RaidPhase.TRAVEL) {
|
||||
startTravel();
|
||||
} else if(phase == RaidPhase.COMBAT) {
|
||||
startCombat();
|
||||
}
|
||||
}
|
||||
|
||||
public Location getTownSpawnRaided() {
|
||||
return townSpawnRaided;
|
||||
}
|
||||
|
||||
public void setTownSpawnRaided(Location townSpawnRaided) {
|
||||
this.townSpawnRaided = townSpawnRaided;
|
||||
}
|
||||
|
||||
public Location getTownSpawnGather() {
|
||||
return townSpawnGather;
|
||||
}
|
||||
|
||||
public void setTownSpawnGather(Location townSpawnGather) {
|
||||
this.townSpawnGather = townSpawnGather;
|
||||
}
|
||||
|
||||
public static class LootBlock {
|
||||
|
||||
public WorldCoord worldCoord;
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
@@ -94,13 +95,13 @@ public class Siege {
|
||||
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().isHomeBlock()
|
||||
&& WorldCoord
|
||||
.parseWorldCoord(
|
||||
Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().getTown().equals(town)
|
||||
.parseWorldCoord(
|
||||
Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().getTown().equals(town)
|
||||
&& !Bukkit.getPlayer(playerName).isDead()
|
||||
&& (Math.abs(
|
||||
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
|
||||
- townSpawn.getBlockY())) < 10) {
|
||||
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
|
||||
- townSpawn.getBlockY())) < 10) {
|
||||
attackersAreOnHomeBlock = true;
|
||||
}
|
||||
} catch (NotRegisteredException ex) {
|
||||
@@ -112,13 +113,13 @@ public class Siege {
|
||||
if (WorldCoord.parseWorldCoord(Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().isHomeBlock()
|
||||
&& WorldCoord
|
||||
.parseWorldCoord(
|
||||
Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().getTown().equals(town)
|
||||
.parseWorldCoord(
|
||||
Main.getInstance().getServer().getPlayer(playerName))
|
||||
.getTownBlock().getTown().equals(town)
|
||||
&& !Bukkit.getPlayer(playerName).isDead()
|
||||
&& (Math.abs(
|
||||
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
|
||||
- townSpawn.getBlockY())) < 10) {
|
||||
Bukkit.getServer().getPlayer(playerName).getLocation().getBlockY()
|
||||
- townSpawn.getBlockY())) < 10) {
|
||||
defendersAreOnHomeBlock = true;
|
||||
}
|
||||
} catch (NotRegisteredException ex3) {
|
||||
@@ -279,6 +280,18 @@ public class Siege {
|
||||
clearBeacon();
|
||||
}
|
||||
|
||||
/**
|
||||
* No winnder declared
|
||||
*/
|
||||
public void noWinner() {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The siege of " + this.town.getName() + " was a draw!");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "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();
|
||||
@@ -396,6 +409,14 @@ public class Siege {
|
||||
this.town = town;
|
||||
}
|
||||
|
||||
public OfflinePlayer getSiegeOwner() {
|
||||
return siegeLeader;
|
||||
}
|
||||
|
||||
public void setSiegeOwner(OfflinePlayer siegeOwner) {
|
||||
this.siegeLeader = siegeOwner;
|
||||
}
|
||||
|
||||
/** Gets attacker name string */
|
||||
public String getAttackers() {
|
||||
if (side1AreAttackers) {
|
||||
@@ -422,6 +443,38 @@ public class Siege {
|
||||
return this.defenderPoints;
|
||||
}
|
||||
|
||||
public int getMaxSiegeTicks() {
|
||||
return maxSiegeTicks;
|
||||
}
|
||||
|
||||
public void setSiegeTicks(int siegeTicks) {
|
||||
this.siegeTicks = siegeTicks;
|
||||
}
|
||||
|
||||
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 void setAttackerPoints(int points) {
|
||||
this.attackerPoints = points;
|
||||
}
|
||||
|
||||
public void setDefenderPoints(int points) {
|
||||
this.defenderPoints = points;
|
||||
}
|
||||
|
||||
public boolean getSide1AreAttackers() {
|
||||
return this.side1AreAttackers;
|
||||
}
|
||||
@@ -457,4 +510,8 @@ public class Siege {
|
||||
public void save() {
|
||||
SiegeData.saveSiege(this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.getWar().getName() + "-" + this.getTown();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.ShermansWorld.AlathraWar;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
@@ -7,6 +8,7 @@ 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.data.DataManager;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
|
||||
public class War {
|
||||
@@ -22,7 +24,8 @@ public class War {
|
||||
// References
|
||||
private ArrayList<Siege> sieges = new ArrayList<Siege>();
|
||||
private ArrayList<Raid> raids = new ArrayList<Raid>();
|
||||
private int lastRaidTime = 0;
|
||||
private int lastRaidTimeSide1 = 0;
|
||||
private int lastRaidTimeSide2 = 0;
|
||||
|
||||
/**
|
||||
* War Constructor
|
||||
@@ -83,8 +86,10 @@ public class War {
|
||||
* @param nation - Nation to surrender
|
||||
*/
|
||||
public void surrenderNation(Nation nation) {
|
||||
for (Town town : nation.getTowns()) {
|
||||
surrenderTown(town.getName());
|
||||
if(nation != null) {
|
||||
for (Town town : nation.getTowns()) {
|
||||
surrenderTown(town.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +103,24 @@ public class War {
|
||||
surrenderedTowns.add(town);
|
||||
}
|
||||
|
||||
/**
|
||||
* unsurrender town, perfidy time
|
||||
* @param nation - Nation to unsurrender
|
||||
*/
|
||||
public void unSurrenderNation(Nation nation) {
|
||||
for (Town town : nation.getTowns()) {
|
||||
unSurrenderTown(town.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unsurrender town, perfidy time
|
||||
* @param town - Town to unsurrender
|
||||
*/
|
||||
public void unSurrenderTown(String town) {
|
||||
surrenderedTowns.remove(town);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets side of town
|
||||
* -1 - Surrendered
|
||||
@@ -125,7 +148,7 @@ public class War {
|
||||
public int getSide(Town town) {
|
||||
return getSide(town.getName());
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
@@ -158,6 +181,9 @@ public class War {
|
||||
return surrenderedTowns;
|
||||
}
|
||||
|
||||
public void setSurrenderedTowns(ArrayList<String> towns) {
|
||||
surrenderedTowns = towns;
|
||||
}
|
||||
|
||||
public ArrayList<Siege> getSieges() {
|
||||
return sieges;
|
||||
@@ -175,6 +201,20 @@ public class War {
|
||||
raids.add(raid);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
DataManager.deleteFile("wars" + File.separator + this.getName() + ".yml");
|
||||
this.name = name;
|
||||
this.save();
|
||||
}
|
||||
|
||||
public void setSide1(String side1) {
|
||||
this.side1 = side1;
|
||||
}
|
||||
|
||||
public void setSide2(String side2) {
|
||||
this.side2 = side2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the war into .yml file folders.
|
||||
*/
|
||||
@@ -209,11 +249,19 @@ public class War {
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public void setLastRaidTime(int lastRaidTime) {
|
||||
this.lastRaidTime = lastRaidTime;
|
||||
public void setLastRaidTimeSide1(int lastRaidTime) {
|
||||
this.lastRaidTimeSide1 = lastRaidTime;
|
||||
}
|
||||
|
||||
public int getLastRaidTime() {
|
||||
return this.lastRaidTime;
|
||||
public int getLastRaidTimeSide1() {
|
||||
return this.lastRaidTimeSide1;
|
||||
}
|
||||
|
||||
public void setLastRaidTimeSide2(int lastRaidTime) {
|
||||
this.lastRaidTimeSide2 = lastRaidTime;
|
||||
}
|
||||
|
||||
public int getLastRaidTimeSide2() {
|
||||
return this.lastRaidTimeSide2;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,724 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.utils.NameUtil;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AdminTabCompletion implements TabCompleter {
|
||||
|
||||
List<String> base = List.of(new String[]{
|
||||
"create",
|
||||
"force",
|
||||
"help",
|
||||
"info",
|
||||
"modify"
|
||||
});
|
||||
|
||||
List<String> type = List.of(new String[]{
|
||||
"raid",
|
||||
"siege",
|
||||
"war"
|
||||
});
|
||||
|
||||
List<String> raidModify = List.of(new String[]{
|
||||
"score",
|
||||
"townspawn",
|
||||
"gather",
|
||||
"phase",
|
||||
"loot",
|
||||
"time",
|
||||
"owner"
|
||||
// ,
|
||||
// "move"
|
||||
// ,
|
||||
// "clearActive"
|
||||
});
|
||||
|
||||
List<String> siegeModify = List.of(new String[]{
|
||||
"score",
|
||||
"townspawn",
|
||||
"time",
|
||||
"owner"
|
||||
// ,
|
||||
// "move"
|
||||
});
|
||||
|
||||
List<String> warModify = List.of(new String[]{
|
||||
"score",
|
||||
"side",
|
||||
"name",
|
||||
"add",
|
||||
"surrender",
|
||||
"unsurrender",
|
||||
"raidTimeWar",
|
||||
"raidTimeTown"
|
||||
});
|
||||
|
||||
List<String> force = List.of(new String[]{
|
||||
"end",
|
||||
"join",
|
||||
"leave"
|
||||
});
|
||||
|
||||
List<String> addSet = List.of(new String[]{
|
||||
"add",
|
||||
"set"
|
||||
});
|
||||
|
||||
|
||||
List<String> boolSet = List.of(new String[]{
|
||||
"true",
|
||||
"false"
|
||||
});
|
||||
|
||||
|
||||
List<String> addSetReset = List.of(new String[]{
|
||||
"add",
|
||||
"set",
|
||||
"reset"
|
||||
});
|
||||
|
||||
List<String> nationTown = List.of(new String[]{
|
||||
"town",
|
||||
"nation"
|
||||
});
|
||||
|
||||
List<String> lootSet = List.of(new String[]{
|
||||
"value",
|
||||
"looted",
|
||||
"ticks",
|
||||
"reset"
|
||||
});
|
||||
|
||||
List<String> empty = List.of(new String[]{
|
||||
""
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* //done
|
||||
* //edit war/event in real time, side can be "both" to effect both
|
||||
* -modify raid score [war] [town] [add/set] [value]
|
||||
* -modify raid townspawn [war] [town] (x) (y) (Z)
|
||||
* -modify raid gather [war] [town] [town]
|
||||
* -modify raid phase [war] [town] [phase] //"next" to move to next phase
|
||||
* -modify raid loot [war] [town] [value,looted,ticks,reset] [amt] (x) (z) //no coords just does current chunk, reset deletes it from the list
|
||||
* -modify raid time [war] [town] [add/set] [value]
|
||||
* -modify raid owner [war] [town] [player]
|
||||
* -modify raid move [war] [town] [newWar] //low priority, moves raid to other war/ town
|
||||
* -modify raid clearActive [war] [town] //low priority
|
||||
* <p>
|
||||
* -modify siege score [war] [town] [side] [amt]
|
||||
* -modify siege townspawn [war] [town] (x) (Z)
|
||||
* -modify siege time [war] [town] [add/set/max] [value] //max modified the max length
|
||||
* -modify siege owner [war] [town] [add/set] [value]
|
||||
* -modify siege move [war] [town] [newWar] //low priority, moves siege to other war/town
|
||||
* <p>
|
||||
* -modify war score [war] [side] [amt]
|
||||
* -modify war side [war] [side] [name]
|
||||
* -modify war name [war] [name]
|
||||
* -modify war add town [war] [town]
|
||||
* -modify war add nation [war] [nation]
|
||||
* -modify war surrender town [war] [town] //adds town to surrender list
|
||||
* -modify war surrender nation [war] [town] //adds all towns to surrender list
|
||||
* -modify war raidTime [add,set,reset] [war] [town] [amt] //set when last raid was
|
||||
* <p>
|
||||
* // low priority idea
|
||||
* -info war score [war]
|
||||
* -info war surrenderedTowns [war]
|
||||
* -info war raids [war]
|
||||
* -info war sieges [war]
|
||||
* -info war towns [war]
|
||||
* -info war lastRaidTime [war]
|
||||
* <p>
|
||||
* -info raid homeblock [war] [town]
|
||||
* -info raid lootedTownBlocks [war] [town]
|
||||
* -info raid timeSinceLastRaid [town]
|
||||
* <p>
|
||||
* -info siege homeblock [war] [town]
|
||||
* <p>
|
||||
* //done
|
||||
* //force make event or war, if owner isn't defined, IDK haven't decided
|
||||
* -create siege [war] [town] (owner)
|
||||
* -create raid [war] [raidTown] (gatherTown) (owner)
|
||||
* -create war [name] [side1] [side2]
|
||||
* <p>
|
||||
* //force end a war/event, can declare winner side, or no winner
|
||||
* -force end war [war] (side/victor)
|
||||
* -force end siege [war] [town] (side/victor)
|
||||
* -force end raid [war] [town] (side/victor)
|
||||
* <p>
|
||||
* //done
|
||||
* //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)
|
||||
* <p>
|
||||
* //done
|
||||
* -force leave raid [war] [town] [player] (timeout) //kicks from raid party
|
||||
*
|
||||
* @param sender Source of the command. For players tab-completing a
|
||||
* command inside a command block, this will be the player, not
|
||||
* the command block.
|
||||
* @param command Command which was executed
|
||||
* @param label Alias of the command which was used
|
||||
* @param args The arguments passed to the command, including final
|
||||
* partial argument to be completed
|
||||
* @return list of options
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
final Player p = (Player) sender;
|
||||
if (!p.hasPermission("AlathraWar.admin")) {
|
||||
return empty;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
return base;
|
||||
} else if (args.length == 1) {
|
||||
return NameUtil.filterByStart(base, args[0]);
|
||||
} else {
|
||||
if (args[0].equalsIgnoreCase("create")) {
|
||||
if (args.length > 2) {
|
||||
switch (args[1]) {
|
||||
case "raid" -> {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
}
|
||||
case "siege" -> {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("force")) {
|
||||
if (args.length > 2) {
|
||||
if (args[1].equalsIgnoreCase("end")) {
|
||||
if (args.length > 3) {
|
||||
if (args[2].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("siege")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("war")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("join")) {
|
||||
if (args.length > 3) {
|
||||
if (args[2].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[6]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]);
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("siege")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[6]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]);
|
||||
}
|
||||
} else if (args[2].equalsIgnoreCase("war")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[3]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("leave")) {
|
||||
if (args.length > 3) {
|
||||
if (args[2].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(List.of(new String[]{"raid"}), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(List.of(new String[]{"raid"}), args[2]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(force, args[1]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(force, args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("help")) {
|
||||
return empty;
|
||||
} else if (args[0].equalsIgnoreCase("info")) {
|
||||
if (args.length > 2) {
|
||||
if (args[1].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("siege")) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("war")) {
|
||||
if (args.length > 3) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[2]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("modify")) {
|
||||
if (args.length > 2) {
|
||||
if (args[1].equalsIgnoreCase("raid")) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
switch (args[2]) {
|
||||
/*
|
||||
* -modify raid score [war] [town] [add/set] [value]
|
||||
* -modify raid townspawn [war] [town] (x) (y) (Z)
|
||||
* -modify raid gather [war] [town] [town]
|
||||
* -modify raid phase [war] [town] [phase] //"next" to move to next phase
|
||||
* -modify raid loot [war] [town] [value,looted,ticks,reset] [amt] (x) (z) //no coords just does current chunk, reset deletes it from the list
|
||||
* -modify raid time [war] [town] [add/set] [value]
|
||||
* -modify raid owner [war] [town] [player]
|
||||
* -modify raid move [war] [town] [newWar] //low priority, moves raid to other war/ town
|
||||
* -modify raid clearActive [war] [town] //low priority
|
||||
*/
|
||||
case "score", "time" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSet, args[5]);
|
||||
}
|
||||
}
|
||||
case "townspawn" -> {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
return empty;
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(p.getLocation().getZ())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(p.getLocation().getY())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(p.getLocation().getX())});
|
||||
}
|
||||
}
|
||||
case "gather" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[5]);
|
||||
}
|
||||
}
|
||||
case "phase" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getRaidPhases(), args[5]);
|
||||
}
|
||||
}
|
||||
case "loot" -> {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
if (args.length > 9) {
|
||||
return empty;
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(p.getLocation().getZ())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(p.getLocation().getX())});
|
||||
}
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(lootSet, args[5]);
|
||||
}
|
||||
}
|
||||
case "owner" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(raidModify, args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("siege")) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
switch (args[2]) {
|
||||
case "score", "time" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSet, args[5]);
|
||||
}
|
||||
}
|
||||
case "townspawn" -> {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
return empty;
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(p.getLocation().getZ())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(p.getLocation().getY())});
|
||||
}
|
||||
} else {
|
||||
return List.of(new String[]{String.valueOf(p.getLocation().getX())});
|
||||
}
|
||||
}
|
||||
case "owner" -> {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getPlayers(), args[5]);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(siegeModify, args[2]);
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("war")) {
|
||||
if (args.length > 3) {
|
||||
switch (args[2]) {
|
||||
/*
|
||||
* -modify war score [war] [side] [amt]
|
||||
* -modify war side [war] [side] [name]
|
||||
* -modify war name [war] [name]
|
||||
* -modify war add [war] [side] [town/nation] [town/nation]
|
||||
* -modify war add nation [war] [nation]
|
||||
* -modify war surrender town [war] [town] //adds town to surrender list
|
||||
* -modify war surrender nation [war] [town] //adds all towns to surrender list
|
||||
* -modify war unsurrender [war] town/nation [town/nation]
|
||||
* -modify war unsurrender [war] town/nation [town/nation]
|
||||
* -modify war raidTimeTown [add,set,reset] [war] [town] [amt] //set when last raid was
|
||||
*/
|
||||
case "score" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSet, args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
//alathrawaradmin modify war raidTimeTown [add,set,reset] [town/war] [amt] [side]
|
||||
case "raidTimeTown" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSetReset, args[3]);
|
||||
}
|
||||
}
|
||||
//alathrawaradmin modify war raidTimeWar [add,set,reset] [war] [amt] [side]
|
||||
case "raidTimeWar" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if(args[3].equalsIgnoreCase("reset")) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[5]);
|
||||
}
|
||||
} else {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[6]);
|
||||
}
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(addSetReset, args[3]);
|
||||
|
||||
}
|
||||
}
|
||||
case "side" -> {
|
||||
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
case "name" -> {
|
||||
if (args.length > 4) {
|
||||
return empty;
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
case "add" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
if (args.length > 8) {
|
||||
return empty;
|
||||
} else {
|
||||
return boolSet;
|
||||
}
|
||||
} else {
|
||||
if (args[5].equalsIgnoreCase("town")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[6]);
|
||||
} else if (args[5].equalsIgnoreCase("nation")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyNations(), args[6]);
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(nationTown, args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
case "surrender" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
if (args.length > 7) {
|
||||
return empty;
|
||||
} else {
|
||||
if (args[5].equalsIgnoreCase("town")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[6]);
|
||||
} else if (args[5].equalsIgnoreCase("nation")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyNations(), args[6]);
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(nationTown, args[5]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarSides(args[3]), args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
case "unsurrender" -> {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 5) {
|
||||
if (args.length > 6) {
|
||||
return empty;
|
||||
} else {
|
||||
if (args[4].equalsIgnoreCase("town")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyTowns(), args[5]);
|
||||
} else if (args[4].equalsIgnoreCase("nation")) {
|
||||
return NameUtil.filterByStart(CommandHelper.getTownyNations(), args[5]);
|
||||
} else {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(nationTown, args[4]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(CommandHelper.getWarNames(), args[3]);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return NameUtil.filterByStart(warModify, args[2]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(type, args[1]);
|
||||
}
|
||||
} else {
|
||||
return NameUtil.filterByStart(base, args[0]);
|
||||
}
|
||||
}
|
||||
return NameUtil.filterByStart(base, args[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package me.ShermansWorld.AlathraWar.commands;
|
||||
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandHelper {
|
||||
|
||||
/**
|
||||
* Grabs list of all war names
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getWarNames() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (War w : WarData.getWars()) {
|
||||
out.add(w.getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs first matching war and lists the sides
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getWarSides(String name) {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (War w : WarData.getWars()) {
|
||||
if(w.getName().equals(name)) {
|
||||
out.add(w.getSide1());
|
||||
out.add(w.getSide2());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* get list of all towny towns
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getTownyTowns() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (Town t : TownyAPI.getInstance().getTowns()) {
|
||||
out.add(t.getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* get list of all towny nations
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getTownyNations() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (Town t : TownyAPI.getInstance().getTowns()) {
|
||||
Nation n = t.getNationOrNull();
|
||||
if(n != null) {
|
||||
if(!out.contains(n.getName())) {
|
||||
out.add(n.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a list of all online players
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getPlayers() {
|
||||
Collection<? extends Player> players = Bukkit.getOnlinePlayers();
|
||||
List<String> out = new ArrayList<>();
|
||||
for (Player p : players) {
|
||||
out.add(p.getName());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a list of all raid phases
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getRaidPhases() {
|
||||
List<String> out = new ArrayList<>();
|
||||
for (RaidPhase ph : RaidPhase.values()) {
|
||||
out.add(ph.name());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -44,11 +43,11 @@ public class RaidCommands implements CommandExecutor {
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("start")) {
|
||||
startRaid(p, args);
|
||||
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 {
|
||||
@@ -57,8 +56,7 @@ public class RaidCommands implements CommandExecutor {
|
||||
} else {
|
||||
fail(p, args, "syntax");
|
||||
}
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,29 +65,61 @@ public class RaidCommands implements CommandExecutor {
|
||||
* @param p
|
||||
* @param args
|
||||
*/
|
||||
private static void startRaid(Player p, String[] args) {
|
||||
protected static void startRaid(Player p, String[] args, boolean admin) {
|
||||
boolean warFound = false;
|
||||
boolean townExists = false;
|
||||
for (final War war : WarData.getWars()) {
|
||||
if (war.getName().equalsIgnoreCase(args[1])) {
|
||||
//if this is run as admin, shift our check forward a slot
|
||||
if (war.getName().equalsIgnoreCase(args[1 + (admin ? 1 : 0)])) {
|
||||
warFound = true;
|
||||
if (!war.getSide1Players().contains(p.getName()) && !war.getSide2Players().contains(p.getName())) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
|
||||
Player raidOwner = p;
|
||||
TownyWorld townyWorld;
|
||||
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
|
||||
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
|
||||
if(admin && args.length >= 6) {
|
||||
raidOwner = Bukkit.getPlayer(args[5]);
|
||||
if(raidOwner == null) {
|
||||
raidOwner = p;
|
||||
}
|
||||
}
|
||||
|
||||
String side = "";
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
side = war.getSide1();
|
||||
} else if (war.getSide2Players().contains(p.getName())) {
|
||||
side = war.getSide2();
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
return;
|
||||
}
|
||||
|
||||
//check if in a town
|
||||
//takes the command runners town as the gather point
|
||||
Town gatherTown = null;
|
||||
try {
|
||||
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(p.getLocation()).getTownBlock());
|
||||
//if admin, and we have a gather town argument, use it
|
||||
if(admin && args.length >= 5) {
|
||||
if(args[4].equalsIgnoreCase("defaultCode")) {
|
||||
//use default behavior
|
||||
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
|
||||
} else if(TownyAPI.getInstance().getTown(args[4]) != null) {
|
||||
gatherTown = TownyAPI.getInstance().getTown(args[4]);
|
||||
} else {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No valid town set for gather town, defaulting to current location");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "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) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "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) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must be within a town's claim to begin a raid. That town you are in will be the gathering town.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,26 +127,40 @@ public class RaidCommands implements CommandExecutor {
|
||||
for (final String entry : townyWorld.getTowns().keySet()) {
|
||||
final Town raidedTown = townyWorld.getTowns().get(entry);
|
||||
|
||||
if (raidedTown.getName().equalsIgnoreCase(args[2]) && gatherTown != null) {
|
||||
//if this is run as admin, shift our check forward a slot
|
||||
if (raidedTown.getName().equalsIgnoreCase(args[2 + (admin ? 1 : 0)]) && gatherTown != null) {
|
||||
|
||||
//check if the town were attempting to raid is in the war
|
||||
if(!war.getSide1Towns().contains(raidedTown.getName()) && !war.getSide2Towns().contains(raidedTown.getName())) {
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "The town you are trying to raid is not part of the war!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "The town you are trying to raid is not part of the war!");
|
||||
return;
|
||||
}
|
||||
|
||||
townExists = true;
|
||||
boolean attackingOwnSide = false;
|
||||
|
||||
Raid raid2;
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
//Time and raid activity validity check
|
||||
int c = RaidData.isValidRaid(war, raidedTown);
|
||||
int c = RaidData.isValidRaid(war, side, raidedTown);
|
||||
if (c == 2) {
|
||||
raid2 = new Raid(war, raidedTown, gatherTown, true);
|
||||
//if were admin, see if an owner arg exists, and if so then use it
|
||||
raid2 = new Raid(war, raidedTown, gatherTown, true, raidOwner);
|
||||
} else if (c == 1) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
|
||||
return;
|
||||
} else if (c == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!");
|
||||
return;
|
||||
} else if (c == -1) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!");
|
||||
return;
|
||||
} else if (c == -2) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town has no online players to defend it!");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!");
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
@@ -128,59 +172,61 @@ public class RaidCommands implements CommandExecutor {
|
||||
return;
|
||||
}
|
||||
//Time and raid activity validity check
|
||||
int c = RaidData.isValidRaid(war, raidedTown);
|
||||
int c = RaidData.isValidRaid(war, side, raidedTown);
|
||||
if (c == 2) {
|
||||
raid2 = new Raid(war, raidedTown, gatherTown, false);
|
||||
raid2 = new Raid(war, raidedTown, gatherTown, false, raidOwner);
|
||||
} else if (c == 1) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
|
||||
return;
|
||||
} else if (c == 0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!");
|
||||
return;
|
||||
} else if (c == -1) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town was raided too recently!");
|
||||
return;
|
||||
} else if (c == -2) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "At least on member of the raided town must be online to defend it!");
|
||||
return;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
//validity check over attacking own towns
|
||||
final ArrayList<String> residentNames = new ArrayList<String>();
|
||||
for (final Resident resident : raidedTown.getResidents()) {
|
||||
residentNames.add(resident.getName());
|
||||
// Player participance check
|
||||
Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull();
|
||||
int sideR = war.getSide(leaderTown.getName());
|
||||
if (sideR == 0) {
|
||||
if (admin) p.sendMessage(Helper.Chatlabel() + "You are not in this war.");
|
||||
raidOwner.sendMessage(Helper.Chatlabel() + "You are not in this war.");
|
||||
return;
|
||||
} else if (sideR == -1) {
|
||||
if (admin) p.sendMessage(Helper.Chatlabel() + "You have surrendered.");
|
||||
raidOwner.sendMessage(Helper.Chatlabel() + "You have surrendered.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (raid2.getSide1AreRaiders()) {
|
||||
for (final String playerName : war.getSide1Players()) {
|
||||
if (residentNames.contains(playerName)) {
|
||||
attackingOwnSide = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (final String playerName : war.getSide2Players()) {
|
||||
if (residentNames.contains(playerName)) {
|
||||
attackingOwnSide = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (attackingOwnSide) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot raid a town with members on your side of the war!");
|
||||
// Attacking own side
|
||||
if (war.getSide(raidedTown) == sideR) {
|
||||
if (admin) p.sendMessage(Helper.Chatlabel() + "You cannot attack your own towns.");
|
||||
raidOwner.sendMessage(Helper.Chatlabel() + "You cannot attack your own towns.");
|
||||
return;
|
||||
}
|
||||
|
||||
//check player balance
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUniqueId());
|
||||
if (Main.econ.getBalance(offlinePlayer) <= 1000.0) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $1000 to put up to start a raid.");
|
||||
if (admin) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $1000 to put up to start a raid.");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $1000 to put up to start a raid.");
|
||||
return;
|
||||
}
|
||||
|
||||
//publish raid
|
||||
Main.econ.withdrawPlayer(offlinePlayer, 1000);
|
||||
raid2.addActiveRaider(raidOwner.getName());
|
||||
RaidData.addRaid(raid2);
|
||||
raid2.start(); //funny funny method haha
|
||||
WarData.saveWar(raid2.getWar());
|
||||
@@ -188,12 +234,13 @@ public class RaidCommands implements CommandExecutor {
|
||||
//broadcast
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "As part of " + war.getName() + ", forces from " + raid2.getRaiders() + " are gathering to raid the town of " + raidedTown.getName() + "!");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "All players from the defending side have been drafted for the town's defense.");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid of "
|
||||
Bukkit.broadcastMessage(Helper.Chatlabel() + "The raid of "
|
||||
+ raidedTown.getName() + " will begin in " + (int) (RaidPhase.TRAVEL.startTick / 20 / 60) + " minutes!");
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) +
|
||||
Bukkit.broadcastMessage(Helper.Chatlabel() +
|
||||
"The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
|
||||
|
||||
Main.warLogger.log(p.getName() + " started a raid.");
|
||||
Main.warLogger.log(raidOwner.getName() + " started a raid.");
|
||||
if(admin) Main.warLogger.log(raidOwner.getName() + " started a raid from admin interference.");
|
||||
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!");
|
||||
}
|
||||
@@ -201,11 +248,11 @@ public class RaidCommands implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
if (!warFound) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That war does not exist! /raid start [war] [town]");
|
||||
p.sendMessage(Helper.Chatlabel() + "That war does not exist! /raid start [war] [town]");
|
||||
return;
|
||||
}
|
||||
if (!townExists) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /raid start [war] [town]");
|
||||
p.sendMessage(Helper.Chatlabel() + "That town does not exist! /raid start [war] [town]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,13 +287,39 @@ 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.getPlayer(args[3]);
|
||||
|
||||
if(joiner != null) {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Player " + args[3] + " not found!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
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
|
||||
@@ -254,32 +327,44 @@ 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!");
|
||||
}
|
||||
|
||||
raid.save();
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town or this town does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void leaveRaid(Player p, String[] args) {
|
||||
protected static void leaveRaid(Player player, String[] args, boolean admin) {
|
||||
//Get raid!
|
||||
Player p = player;
|
||||
if (admin) {
|
||||
p = Bukkit.getPlayer(args[3]);
|
||||
if (p == null) {
|
||||
player.sendMessage(String.valueOf(Helper.Chatlabel()) + "Error: player not found!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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]");
|
||||
if (admin) player.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
|
||||
}
|
||||
|
||||
//check if gather phase
|
||||
@@ -290,17 +375,22 @@ public class RaidCommands implements CommandExecutor {
|
||||
if (cluster.contains(WorldCoord.parseWorldCoord(p))) {
|
||||
raid.removeActiveRaider(p.getName());
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
if (admin) player.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the raid on " + raid.getRaidedTown().getName() + "!");
|
||||
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
if (admin) player.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot leave the raid on " + raid.getRaidedTown().getName() + "! It has already started!");
|
||||
}
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
raid.save();
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town or this town does not exist!");
|
||||
if (admin) player.sendMessage(String.valueOf(Helper.Chatlabel()) + "No raid is gathering in this town or this town does not exist!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,17 +407,16 @@ public class RaidCommands implements CommandExecutor {
|
||||
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]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!raid.getOwner().getName().equals(p.getName())) {
|
||||
if (raid.getOwner().getName().equals(p.getName())) {
|
||||
//check if gather phase
|
||||
if (raid.getPhase() == RaidPhase.GATHER || raid.getPhase() == RaidPhase.START || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.COMBAT) {
|
||||
if (raid.getGatherTown().hasTownBlock(WorldCoord.parseWorldCoord(p))) {
|
||||
//force defender victory
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid on " + raid.getRaidedTown().getName() + " has been abandoned by " + raid.getRaiders());
|
||||
Main.warLogger.log(p.getName() + " abandoned the raid on " + raid.getRaidedTown().getName() + " they started at " + raid.getGatherTown().getName());
|
||||
raid.defendersWin(raid.getRaidScore());
|
||||
}
|
||||
//force defender victory
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The raid on " + raid.getRaidedTown().getName() + " has been abandoned by " + raid.getRaiders());
|
||||
Main.warLogger.log(p.getName() + " abandoned the raid on " + raid.getRaidedTown().getName() + " they started at " + raid.getGatherTown().getName());
|
||||
raid.defendersWin(raid.getRaidScore());
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You cannot abandon the raid on " + raid.getRaidedTown().getName() + "! It has a problem!");
|
||||
}
|
||||
@@ -336,9 +425,8 @@ public class RaidCommands implements CommandExecutor {
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This raid does not exist!");
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This raid does not exist!");
|
||||
}
|
||||
|
||||
private static void listRaids(Player p, String[] args) {
|
||||
@@ -375,30 +463,12 @@ public class RaidCommands implements CommandExecutor {
|
||||
|
||||
private static void fail(Player p, String[] args, String type) {
|
||||
switch (type) {
|
||||
case "permissions": {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this"));
|
||||
return;
|
||||
}
|
||||
case "syntax": {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
return;
|
||||
}
|
||||
case "noRaids": {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no Raids in progress");
|
||||
return;
|
||||
}
|
||||
case "badName": {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "A raid could not be found with this Name! Type /raid list to view current raids");
|
||||
return;
|
||||
}
|
||||
case "owner": {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Only the player who started the raid can abandon it.");
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
|
||||
}
|
||||
case "permissions" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "&cYou do not have permission to do this");
|
||||
case "syntax" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Syntax. /raid help");
|
||||
case "noRaids" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "There are currently no Raids in progress");
|
||||
case "badName" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "A raid could not be found with this Name! Type /raid list to view current raids");
|
||||
case "owner" -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Only the player who started the raid can abandon it.");
|
||||
default -> p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Invalid Arguments. /raid help");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class SiegeCommands implements CommandExecutor {
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "start":
|
||||
siegeStart(sender, args);
|
||||
siegeStart(sender, args, false);
|
||||
return true;
|
||||
case "stop":
|
||||
siegeStop(sender, args);
|
||||
@@ -58,9 +58,15 @@ public class SiegeCommands implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void siegeStart(CommandSender sender, String[] args) {
|
||||
protected static void siegeStart(CommandSender sender, String[] args, boolean admin) {
|
||||
if (!(sender instanceof Player)) return;
|
||||
final Player player = (Player) sender;
|
||||
//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;
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage(Helper.Chatlabel() + "/war siege [war] [town]");
|
||||
@@ -71,6 +77,7 @@ public class SiegeCommands implements CommandExecutor {
|
||||
War war = WarData.getWar(args[1]);
|
||||
if (war == null) {
|
||||
player.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;
|
||||
}
|
||||
|
||||
@@ -79,9 +86,11 @@ public class SiegeCommands implements CommandExecutor {
|
||||
int side = war.getSide(leaderTown.getName());
|
||||
if (side == 0) {
|
||||
player.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.");
|
||||
if(admin) sender.sendMessage(Helper.Chatlabel() + "You have surrendered.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -89,18 +98,23 @@ public class SiegeCommands implements CommandExecutor {
|
||||
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]");
|
||||
if(admin) sender.sendMessage(String.valueOf(Helper.Chatlabel()) + "That town does not exist! /siege start [war] [town]");
|
||||
return;
|
||||
}
|
||||
|
||||
// Attacking own side
|
||||
if (war.getSide(town) == side) {
|
||||
player.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);
|
||||
SiegeData.addSiege(siege);
|
||||
war.addSiege(siege);
|
||||
|
||||
Bukkit.broadcastMessage(Helper.Chatlabel() + "A siege has been laid on " + siege.getTown() + " by " + siege.getAttackers() + "!");
|
||||
|
||||
war.save();
|
||||
siege.start();
|
||||
}
|
||||
|
||||
@@ -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,10 +44,10 @@ 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);
|
||||
warSurrender(p, args, false);
|
||||
return true;
|
||||
case "list":
|
||||
warList(p, args);
|
||||
@@ -62,11 +63,11 @@ public class WarCommands implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private 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;
|
||||
@@ -178,7 +187,7 @@ public class WarCommands implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private static void warSurrender(Player p, String[] args) {
|
||||
protected static void warSurrender(Player p, String[] args, boolean admin) {
|
||||
// Sufficient args check
|
||||
if (args.length < 2) {
|
||||
p.sendMessage(Helper.Chatlabel()
|
||||
|
||||
@@ -5,18 +5,17 @@ import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import com.palmergames.bukkit.towny.object.metadata.CustomDataField;
|
||||
import com.palmergames.bukkit.towny.object.metadata.IntegerDataField;
|
||||
import com.palmergames.bukkit.towny.object.metadata.LongDataField;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class RaidData {
|
||||
// Static Raid list for all active raids
|
||||
@@ -85,26 +84,31 @@ public class RaidData {
|
||||
Town raidedTown = TownyAPI.getInstance().getTown((String) fileData.get("raidedTown"));
|
||||
Town gatherTown = TownyAPI.getInstance().getTown((String) fileData.get("gatherTown"));
|
||||
boolean attackBoolean = Boolean.parseBoolean((String) fileData.get("side1AreRaiders"));
|
||||
//THIS MAY OR MAY NOT WORK
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString((String) fileData.get("owner")));
|
||||
|
||||
Raid raid = new Raid(war, raidedTown, gatherTown, attackBoolean);
|
||||
if(raidedTown == null || gatherTown == null) {
|
||||
return null;
|
||||
}
|
||||
Raid raid = new Raid(war, raidedTown, gatherTown, attackBoolean, offlinePlayer);
|
||||
|
||||
//Extra properties, if any are missing the raid doesnt exist yet
|
||||
if (fileData.get("raidTicks") != null && fileData.get("raidPhase") != null && fileData.get("activeRaiders") != null && fileData.get("lootedChunks") != null) {
|
||||
//active properties
|
||||
raid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase")));
|
||||
raid.setRaidTicks((Integer) fileData.get("raidTicks"));
|
||||
raid.setRaidTicks((int) fileData.get("raidTicks"));
|
||||
raid.setActiveRaiders((ArrayList<String>) fileData.get("activeRaiders"));
|
||||
|
||||
//looted chunks
|
||||
HashMap<String, Object> o = (HashMap<String, Object>) fileData.get("lootedChunks");
|
||||
for (String s : o.keySet()) {
|
||||
ArrayList<Object> o = (ArrayList<Object>) fileData.get("lootedChunks");
|
||||
for (Object hm : o) {
|
||||
//grab the chunk
|
||||
HashMap<String, Object> chunk = (HashMap<String, Object>) o.get(s);
|
||||
HashMap<String, Object> chunk = (HashMap<String, Object>) hm;
|
||||
|
||||
//grab data for this chunk
|
||||
//worldcoord is its own map
|
||||
HashMap<String, Object> wc = (HashMap<String, Object>) chunk.get("worldCoord");
|
||||
WorldCoord worldCoordc = WorldCoord.parseWorldCoord((String) wc.get("world"), ((Integer) wc.get("x")), ((Integer) wc.get("z")));
|
||||
WorldCoord worldCoordc = WorldCoord.parseWorldCoord((String) wc.get("world"), ((int) wc.get("x")), ((int) wc.get("z")));
|
||||
int ticks = (int) chunk.get("ticks");
|
||||
double value = (double) chunk.get("value");
|
||||
boolean finished = (boolean) chunk.get("finished");
|
||||
@@ -118,6 +122,20 @@ public class RaidData {
|
||||
return raid;
|
||||
}
|
||||
|
||||
public static ArrayList<Raid> createRaids(War war, Collection<HashMap<String, Object>> raidMaps) {
|
||||
ArrayList<Raid> returnList = new ArrayList<Raid>();
|
||||
for (HashMap<String, Object> map : raidMaps) {
|
||||
Town town = TownyAPI.getInstance().getTown((String) map.get("raidedTown"));
|
||||
if (town == null) continue;
|
||||
|
||||
Raid raid = fromMap(war, map);
|
||||
returnList.add(raid);
|
||||
RaidData.addRaid(raid);
|
||||
raid.resume();
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the war into files.
|
||||
@@ -152,13 +170,15 @@ public class RaidData {
|
||||
HashMap<String, Object> returnMap = new HashMap<String, Object>();
|
||||
// Shoves everything into a map.
|
||||
returnMap.put("name", raid.getName());
|
||||
returnMap.put("raidedTown", raid.getRaidedTown());
|
||||
returnMap.put("gatherTown", raid.getRaidedTown());
|
||||
returnMap.put("raidedTown", raid.getRaidedTown().getName());
|
||||
returnMap.put("gatherTown", raid.getGatherTown().getName());
|
||||
returnMap.put("raidTicks", raid.getRaidTicks());
|
||||
returnMap.put("raidPhase", raid.getPhase().name());
|
||||
returnMap.put("raidScore", raid.getRaidScore());
|
||||
returnMap.put("side1AreRaiders", Boolean.toString(raid.getSide1AreRaiders()));
|
||||
returnMap.put("activeRaiders", raid.getActiveRaiders());
|
||||
//THIS MAY OR MAY NOT WORK
|
||||
returnMap.put("owner", raid.getOwner().getUniqueId().toString());
|
||||
|
||||
//create a list from the looted chunks
|
||||
List<Object> chunkList = new ArrayList<Object>();
|
||||
@@ -204,8 +224,8 @@ public class RaidData {
|
||||
if (town.hasMeta("lastRaided")) {
|
||||
CustomDataField field = town.getMetadata("lastRaided");
|
||||
if (field != null) {
|
||||
if (field instanceof IntegerDataField) {
|
||||
return ((IntegerDataField) field).getValue();
|
||||
if (field instanceof LongDataField) {
|
||||
return ((LongDataField) field).getValue();
|
||||
}
|
||||
}
|
||||
return -1L;
|
||||
@@ -220,7 +240,7 @@ public class RaidData {
|
||||
* @Isaac this is for getting if a town can be raided, return (-2, -1, 0, 1, 2) based on status
|
||||
* (no players online, 24 hours town cooldown, 6 hour war cooldown, town being raided already, valid time to raid)
|
||||
*/
|
||||
public static int isValidRaid(War war, @Nonnull Town town) {
|
||||
public static int isValidRaid(War war, String side, @Nonnull Town town) {
|
||||
long townTime = whenTownLastRaided(town);
|
||||
|
||||
//24 hours town cooldown
|
||||
@@ -230,7 +250,7 @@ public class RaidData {
|
||||
|
||||
long lastRaidTime = war.getLastRaidTime();
|
||||
//6 hour raid cooldown for war
|
||||
if ((System.currentTimeMillis() / 1000) - lastRaidTime <= 21600) {
|
||||
if ((System.currentTimeMillis() / 1000) - (side.equals(war.getSide1()) ? war.getLastRaidTimeSide1() : war.getLastRaidTimeSide2()) <= 21600) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
public enum RaidPhase {
|
||||
START(0, 0),
|
||||
GATHER(1, 1),
|
||||
GATHER(1, 0),
|
||||
TRAVEL(2, 18000),
|
||||
COMBAT(3, 24000),
|
||||
END(4, 72000);
|
||||
@@ -44,4 +44,24 @@ public enum RaidPhase {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RaidPhase getNext(RaidPhase phase) {
|
||||
switch (phase) {
|
||||
case START: {
|
||||
return GATHER;
|
||||
}
|
||||
case GATHER: {
|
||||
return TRAVEL;
|
||||
}
|
||||
case TRAVEL: {
|
||||
return COMBAT;
|
||||
}
|
||||
case COMBAT: {
|
||||
return END;
|
||||
}
|
||||
default: {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class SiegeData
|
||||
|
||||
public static void removeSiege(Siege siege) {
|
||||
sieges.remove(siege);
|
||||
//deleteSiege(siege);
|
||||
//deleteSiege(siege);d
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TimeoutData {
|
||||
// // Static War list for all active wars
|
||||
// private static HashMap<UUID, Integer> timeouts = new HashMap<UUID, Integer>();
|
||||
// private final static String dataFolderPath = "plugins" + File.separator + "AlathraWar" + File.separator + "data";
|
||||
// private static File timeoutData = new File(dataFolderPath + File.separator + "timeOutData.yml");
|
||||
//
|
||||
//// // Filter for only accessing yml files
|
||||
//// private static FilenameFilter ymlFilter = new FilenameFilter() {
|
||||
//// @Override
|
||||
//// public boolean accept(File dir, String name) {
|
||||
//// return name.endsWith(".yml");
|
||||
//// }
|
||||
//// };
|
||||
//
|
||||
// // Constructor used to initialise folder.
|
||||
// public TimeoutData(final Main plugin) {
|
||||
// if (!timeoutData.exists()) {
|
||||
// try {
|
||||
// timeoutData.createNewFile();
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static HashMap<UUID, Integer> getWars() {
|
||||
// return timeouts;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets a timeout for the player name, if failed to find return -1
|
||||
// *
|
||||
// * @param name - name to check
|
||||
// * @return timeout or -1
|
||||
// */
|
||||
// public static int getTimeout(String name) {
|
||||
// for (UUID uuid : timeouts.keySet()) {
|
||||
// if (Bukkit.getPlayer(name).getUniqueId().compareTo(uuid) == 0) return timeouts.get(uuid);
|
||||
// }
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets a timeout for the player uuid, if failed to find return -1
|
||||
// *
|
||||
// * @param uuidIN - UUID to check
|
||||
// * @return timeout or -1
|
||||
// */
|
||||
// public static int getTimeout(UUID uuidIN) {
|
||||
// for (UUID uuid : timeouts.keySet()) {
|
||||
// if (uuidIN.compareTo(uuid) == 0) return timeouts.get(uuid);
|
||||
// }
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// public static void setTimeouts(HashMap<UUID, Integer> timeouts) {
|
||||
// TimeoutData.timeouts = timeouts;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * add player timeout (in seconds)
|
||||
// * @param player
|
||||
// * @param time
|
||||
// */
|
||||
// public static void addTimeout(Player player, int time) {
|
||||
// if (player == null) {
|
||||
// Main.warLogger.log("Attempted to add NULL to timeout list.");
|
||||
// return;
|
||||
// }
|
||||
// timeouts.put(player.getUniqueId(), time);
|
||||
// }
|
||||
//
|
||||
// public static void removeTimeout(Player player) {
|
||||
// timeouts.remove(player.getUniqueId());
|
||||
//// deleteWar(war);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the wars currently saved in files as an ArrayList of War Objects
|
||||
// *
|
||||
// * @return War Object ArrayList
|
||||
// */
|
||||
// public static HashMap<UUID, Integer> createTimoutMap() {
|
||||
//
|
||||
// HashMap<String, Object> fileData = DataManager.getData(timeoutData);
|
||||
// HashMap<String, Object> list = (HashMap<String, Object>) fileData.get("timeouts");
|
||||
//
|
||||
// HashMap<UUID, Integer> out = new HashMap<>();
|
||||
// for (String s : list.keySet()) {
|
||||
// out.put(UUID.fromString(s), (Integer) list.get(s));
|
||||
// }
|
||||
//
|
||||
// return out;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Saves the war into files.
|
||||
// *
|
||||
// * @param war - War to be saved.
|
||||
// */
|
||||
// public static void saveWar(War war) {
|
||||
// HashMap<String, Object> sHashMap = new HashMap<String, Object>();
|
||||
//
|
||||
// HashMap<String, Object> list = new HashMap<>();
|
||||
//
|
||||
// for(UUID uuid : timeouts.keySet()) {
|
||||
// list.put(uuid.toString(), timeouts.get(uuid));
|
||||
// }
|
||||
// // Shoves everything into a map.
|
||||
// sHashMap.put("timeouts", list);
|
||||
//
|
||||
// DataManager.saveData("timeOutData.yml", sHashMap);
|
||||
// }
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import me.ShermansWorld.AlathraWar.Main;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
|
||||
@@ -81,7 +82,8 @@ public class WarData
|
||||
War fileWar = fromMap(fileData);
|
||||
returnList.add(fileWar);
|
||||
} catch (Exception e) {
|
||||
Main.warLogger.log("Failed to load " + file.getName() + " " + e.getMessage());
|
||||
Main.warLogger.log("Failed to load " + file.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +105,12 @@ public class WarData
|
||||
|
||||
war.setSide1Towns((ArrayList<String>) fileData.get("side1Towns"));
|
||||
war.setSide2Towns((ArrayList<String>) fileData.get("side2Towns"));
|
||||
war.setSurrenderedTowns((ArrayList<String>) fileData.get("surrenderedTowns"));
|
||||
|
||||
war.setLastRaidTime((int) fileData.get("lastRaidTime"));
|
||||
if(fileData.get("lastRaidTimeSide1") != null && fileData.get("lastRaidTimeSide2") != null) {
|
||||
war.setLastRaidTimeSide1((int) fileData.get("lastRaidTimeSide1"));
|
||||
war.setLastRaidTimeSide2((int) fileData.get("lastRaidTimeSide2"));
|
||||
}
|
||||
|
||||
|
||||
// Siege adding from map.
|
||||
@@ -114,6 +120,13 @@ public class WarData
|
||||
war.addSiege(siege);
|
||||
}
|
||||
|
||||
// Raid adding from map.
|
||||
Collection<HashMap<String, Object>> raidMaps = ((HashMap<String,HashMap<String, Object>>) fileData.get("raids")).values();
|
||||
ArrayList<Raid> raids = RaidData.createRaids(war, raidMaps);
|
||||
for (Raid raid : raids) {
|
||||
war.addRaid(raid);
|
||||
}
|
||||
|
||||
return war;
|
||||
}
|
||||
|
||||
@@ -134,15 +147,14 @@ public class WarData
|
||||
|
||||
sHashMap.put("sieges", SiegeData.getSiegeMap(war));
|
||||
sHashMap.put("raids", RaidData.getRaidMap(war));
|
||||
sHashMap.put("lastRaidTime", war.getLastRaidTime());
|
||||
|
||||
sHashMap.put("lastRaidTimeSide1", war.getLastRaidTimeSide1());
|
||||
sHashMap.put("lastRaidTimeSide2", war.getLastRaidTimeSide2());
|
||||
|
||||
DataManager.saveData("wars" + File.separator + war.getName() + ".yml", sHashMap);
|
||||
}
|
||||
|
||||
private static void deleteWar(War war) {
|
||||
File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
|
||||
|
||||
for (File file : files) {
|
||||
if (file.getName().startsWith(war.getName())) {
|
||||
file.delete();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -48,6 +50,15 @@ public class BlockBreakListener implements Listener {
|
||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not break blocks during sieges"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (final Raid raid : RaidData.getRaids()) {
|
||||
if (raid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not break blocks during raids"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,6 +79,15 @@ public class BlockBreakListener implements Listener {
|
||||
if (siege.getTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not place blocks during sieges"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (final Raid raid : RaidData.getRaids()) {
|
||||
if (raid.getRaidedTown() == WorldCoord.parseWorldCoord(block).getTownOrNull()) {
|
||||
p.sendMessage(Helper.color("&cYou can not place blocks during raids"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.War;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import me.ShermansWorld.AlathraWar.data.WarData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -17,9 +18,24 @@ public class CommandsListener implements Listener {
|
||||
final static String[] prefixes = new String[]{
|
||||
"", "towny", "essentials", "wild", "minecraft"
|
||||
};
|
||||
final static String[] prefixesTowny = new String[]{
|
||||
"", "towny"
|
||||
};
|
||||
final static String[] blacklistedXLong = 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[]{
|
||||
"n spawn", "nat spawn", "nation spawn",
|
||||
"t spawn", "town spawn"
|
||||
"t spawn", "town spawn",
|
||||
"t outpost", "town outpost"
|
||||
};
|
||||
final static String[] payment = new String[]{
|
||||
"n withdraw", "nat withdraw", "nation withdraw",
|
||||
"t withdraw", "town withdraw"
|
||||
};
|
||||
final static String[] blacklistedShort = new String[]{
|
||||
"home", "homes", "warp", "warps",
|
||||
@@ -31,17 +47,18 @@ public class CommandsListener implements Listener {
|
||||
};
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
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("!AlathraWar.admin")) return;
|
||||
|
||||
String[] args = event.getMessage().split(" ");
|
||||
|
||||
/*
|
||||
Prevent any teleport command events from occuring
|
||||
Prevent any teleport command events from occurring
|
||||
If using PlayerTeleportEvent, it breaks the death logic
|
||||
|
||||
allow n spawn and t spawn for defenders trapped in spawn
|
||||
@@ -52,43 +69,78 @@ public class CommandsListener implements Listener {
|
||||
if (raid.getPhase() == RaidPhase.COMBAT || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.GATHER) {
|
||||
//only do for active raiders and any defenders
|
||||
if (raid.getActiveRaiders().contains(p.getName()) || raid.getDefenders().contains(p.getName())) {
|
||||
//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) {
|
||||
//payment check
|
||||
for (String cmd : blacklistedXLong) {
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot modify this property during a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixes) {
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : payment) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot withdraw money whilst in a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//check if in spawn
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
if (parse.equals("n spawn") || parse.equals("nat spawn") || parse.equals("nation spawn")
|
||||
|| parse.equals("t spawn") || parse.equals("town spawn")
|
||||
|| parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn")
|
||||
|| parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and are allowed to teleport to your town or nation.");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
return;
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and are allowed to teleport to your town or nation.");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 1) {
|
||||
}
|
||||
//random tp commands
|
||||
if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0];
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
for (String cmd : blacklistedShort) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//spawn world check
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a raid!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@@ -107,40 +159,78 @@ public class CommandsListener implements Listener {
|
||||
if (siege.getSiegeTicks() > 0) {
|
||||
//only do for active raiders and any defenders
|
||||
if (siege.getAttackerPlayers().contains(p.getName()) || siege.getDefenders().contains(p.getName())) {
|
||||
//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) {
|
||||
//payment check
|
||||
for (String cmd : blacklistedXLong) {
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot modify this property during a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//n spawn and t spawn
|
||||
if (args.length >= 2) {
|
||||
//parse what we have, remove the starting sslash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixes) {
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1) : args[0]) + " " + args[1];
|
||||
for (String prefix : prefixesTowny) {
|
||||
//payment check
|
||||
for (String cmd : payment) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot withdraw money whilst in a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (String cmd : blacklistedLong) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//check if in spawn
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
if (parse.equals("n spawn") || parse.equals("nat spawn") || parse.equals("nation spawn")
|
||||
|| parse.equals("t spawn") || parse.equals("town spawn")
|
||||
|| parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn")
|
||||
|| parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and allowed to teleport to your town or nation!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
return;
|
||||
}
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//else
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (args.length >= 1) {
|
||||
}
|
||||
//random tp commands
|
||||
if (args.length >= 1) {
|
||||
//parse what we have, remove the starting slash
|
||||
String parse = (args[0].charAt(0) == '/' ? args[0].substring(1, args[0].length() - 1) : args[0]) + " " + args[1];
|
||||
String parse = args[0].charAt(0) == '/' ? args[0].substring(1) : args[0];
|
||||
for (String prefix : prefixes) {
|
||||
for (String cmd : blacklistedLong) {
|
||||
for (String cmd : blacklistedShort) {
|
||||
//check for each prefix
|
||||
if (parse.equals(prefix + ":" + cmd)) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("c") + "You cannot teleport whilst in a raid!");
|
||||
if (parse.equals(prefix + (prefix.isEmpty() ? "" : ":") + cmd)) {
|
||||
//spawn world check
|
||||
if (p.getWorld().getName().equals("world")) {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eYou are stuck in spawn and are allowed to teleport to your town or nation."));
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&eUse /t spawn, or /n spawn"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou cannot teleport whilst in a siege!"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,49 +1,96 @@
|
||||
package me.ShermansWorld.AlathraWar.listeners;
|
||||
|
||||
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.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.UUIDFetcher;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.exceptions.TownyException;
|
||||
import org.bukkit.Bukkit;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import org.bukkit.entity.Entity;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
|
||||
import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
import me.ShermansWorld.AlathraWar.commands.SiegeCommands;
|
||||
import me.ShermansWorld.AlathraWar.data.SiegeData;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class KillsListener implements Listener
|
||||
{
|
||||
|
||||
public static final HashMap<UUID, Raid> respawnqueue = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKilled(final PlayerDeathEvent event) {
|
||||
if (event.getEntity().getPlayer() == null || !(event.getEntity().getKiller() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player killed = event.getEntity();
|
||||
final Player killer = event.getEntity().getKiller();
|
||||
Town town = null;
|
||||
try {
|
||||
town = WorldCoord.parseWorldCoord((Entity)killed).getTownBlock().getTown();
|
||||
town = WorldCoord.parseWorldCoord(killed).getTownBlock().getTown();
|
||||
}
|
||||
catch (NotRegisteredException ex2) {}
|
||||
boolean playerCloseToHomeBlockSiege = false;
|
||||
boolean playerCloseToHomeBlockRaid = false;
|
||||
|
||||
try {
|
||||
//Raid logic
|
||||
for (final Raid raid : RaidData.getRaids()) {
|
||||
final int homeBlockXCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
// final int homeBlockXCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getX() * 16;
|
||||
// final int homeBlockZCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
//Carryover from sieges
|
||||
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoordRaided) <= 200 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 200) {
|
||||
playerCloseToHomeBlockRaid = true;
|
||||
}
|
||||
|
||||
if (raid.getDefenders().contains(killed.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
||||
//There is seperate behavior if combat hasnt started
|
||||
if (raid.getPhase() == RaidPhase.COMBAT && killer != null) {
|
||||
if (raid.getActiveRaiders().contains(killer.getName())) {
|
||||
this.raidKill(killed, event);
|
||||
raid.defenderKilledInCombat(event);
|
||||
}
|
||||
}
|
||||
//teleport back to raided spawn, without damaged gear
|
||||
this.oocKill(killed, event);
|
||||
raid.defenderKilledOutofCombat(event);
|
||||
return;
|
||||
}
|
||||
if (raid.getActiveRaiders().contains(killed.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
||||
//There is seperate behavior if combat hasnt started
|
||||
if (raid.getPhase() == RaidPhase.COMBAT && killer != null) {
|
||||
if (raid.getDefenders().contains(killer.getName())) {
|
||||
this.raidKill(killed, event);
|
||||
raid.raiderKilledInCombat(event);
|
||||
respawnqueue.put(killed.getUniqueId(), raid);
|
||||
}
|
||||
}
|
||||
//teleport back to gather town spawn, without damaged gear
|
||||
//this is to disincentive people prekilling
|
||||
this.oocKill(killed, event);
|
||||
raid.raiderKilledOutofCombat(event);
|
||||
respawnqueue.put(killed.getUniqueId(), raid);
|
||||
return;
|
||||
}
|
||||
if ( (town != null && town.equals(raid.getRaidedTown()) || playerCloseToHomeBlockRaid) ) {
|
||||
this.siegeKill(killed, event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(killer == null) return;
|
||||
|
||||
for (final Siege siege : SiegeData.getSieges()) {
|
||||
final int homeBlockXCoord = siege.getTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoord = siege.getTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
@@ -55,15 +102,17 @@ public final class KillsListener implements Listener
|
||||
siege.addPointsToAttackers(20);
|
||||
for (final String playerName : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! + 20 Attacker Points");
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! + 20 Attacker Points");
|
||||
}
|
||||
catch (NullPointerException ex5) {}
|
||||
catch (NullPointerException ignored) {}
|
||||
}
|
||||
for (final String playerName : siege.getDefenderPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! + 20 Attacker Points");
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Defender killed! + 20 Attacker Points");
|
||||
}
|
||||
catch (NullPointerException ex6) {}
|
||||
catch (NullPointerException ignored) {}
|
||||
}
|
||||
}
|
||||
this.siegeKill(killed, event);
|
||||
@@ -74,13 +123,15 @@ public final class KillsListener implements Listener
|
||||
siege.addPointsToDefenders(20);
|
||||
for (final String playerName : siege.getAttackerPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attacker killed! + 20 Defender Points");
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Attacker killed! + 20 Defender Points");
|
||||
}
|
||||
catch (NullPointerException ex3) {}
|
||||
}
|
||||
for (final String playerName : siege.getDefenderPlayers()) {
|
||||
try {
|
||||
Bukkit.getPlayer(playerName).sendMessage(String.valueOf(Helper.Chatlabel()) + "Attacker killed! + 20 Defender Points");
|
||||
Player p = Bukkit.getPlayer(playerName);
|
||||
if (p != null) p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Attacker killed! + 20 Defender Points");
|
||||
}
|
||||
catch (NullPointerException ex4) {}
|
||||
}
|
||||
@@ -93,71 +144,70 @@ public final class KillsListener implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Raid logic
|
||||
for (final Raid raid : RaidData.getRaids()) {
|
||||
final int homeBlockXCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getX() * 16;
|
||||
final int homeBlockZCoordRaided = raid.getRaidedTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
// final int homeBlockXCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getX() * 16;
|
||||
// final int homeBlockZCoordGather = raid.getGatherTown().getHomeBlock().getCoord().getZ() * 16;
|
||||
//Carryover from sieges
|
||||
if (Math.abs(killed.getLocation().getBlockX() - homeBlockXCoordRaided) <= 300 && Math.abs(killed.getLocation().getBlockZ() - homeBlockZCoordRaided) <= 300) {
|
||||
playerCloseToHomeBlockRaid = true;
|
||||
}
|
||||
if (raid.getActiveRaiders().contains(killer.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
||||
//There is seperate behavior if combat hasnt started
|
||||
if(raid.getPhase() == RaidPhase.COMBAT) {
|
||||
this.siegeKill(killed, event);
|
||||
if (raid.getDefenderPlayers().contains(killed.getName())) {
|
||||
raid.defenderKilledInCombat(event);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
//teleport back to raided spawn, without damaged gear
|
||||
this.oocKill(killed, event);
|
||||
raid.defenderKilledOutofCombat(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (raid.getDefenderPlayers().contains(killer.getName()) && ((town != null && town.equals(raid.getRaidedTown())) || playerCloseToHomeBlockRaid)) {
|
||||
//There is seperate behavior if combat hasnt started
|
||||
if(raid.getPhase() == RaidPhase.COMBAT) {
|
||||
this.siegeKill(killed, event);
|
||||
if (raid.getActiveRaiders().contains(killed.getName())) {
|
||||
raid.raiderKilledInCombat(event);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
//teleport back to gather town spawn, without damaged gear
|
||||
//this is to disincentive people prekilling
|
||||
this.oocKill(killed, event);
|
||||
raid.raiderKilledOutofCombat(event);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if ( (town != null && town.equals(raid.getRaidedTown()) || playerCloseToHomeBlockRaid) ) {
|
||||
this.siegeKill(killed, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NullPointerException | TownyException ex7) {
|
||||
catch (NullPointerException | TownyException ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs last so that it overrides everyone else!
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
if(respawnqueue.containsKey(event.getPlayer().getUniqueId())) {
|
||||
Raid raid = respawnqueue.get(event.getPlayer().getUniqueId());
|
||||
if (raid == null) return;
|
||||
if(raid.getActiveRaiders().contains(event.getPlayer().getName())) {
|
||||
//do raider respawn
|
||||
try {
|
||||
event.setRespawnLocation(raid.getGatherTown().getSpawn());
|
||||
event.getPlayer().sendMessage(String.valueOf(Helper.Chatlabel()) + "You died " + (raid.getPhase().equals(RaidPhase.COMBAT) ? "raiding" : "before combat") + " and have been teleported back to the gather point.");
|
||||
} catch (TownyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else if(raid.getDefenders().contains(event.getPlayer().getName())) {
|
||||
//do defender respawn ?
|
||||
} else {
|
||||
//invalid code
|
||||
}
|
||||
respawnqueue.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Damage all gear held by the player (and then send them to spawn?)
|
||||
* They don't lose items from death.
|
||||
* @param killed
|
||||
* @param event
|
||||
* @param killed killed player
|
||||
* @param event event
|
||||
*/
|
||||
private void siegeKill(final Player killed, final PlayerDeathEvent event) {
|
||||
//Helper
|
||||
Helper.damageAllGear(killed);
|
||||
|
||||
//Siege specific
|
||||
Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Damage all gear held by the player (and then send them to spawn?)
|
||||
* They don't lose items from death.
|
||||
*
|
||||
* @param killed killed player
|
||||
* @param event event
|
||||
*/
|
||||
private void raidKill(final Player killed, final PlayerDeathEvent event) {
|
||||
//Helper
|
||||
Helper.damageAllGear(killed);
|
||||
|
||||
//Siege specific
|
||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
@@ -166,12 +216,13 @@ public final class KillsListener implements Listener
|
||||
/**
|
||||
* Dont damage items held by the player
|
||||
* They don't lose items from death.
|
||||
* @param killed
|
||||
* @param event
|
||||
*
|
||||
* @param killed killed player
|
||||
* @param event event
|
||||
*/
|
||||
private void oocKill(final Player killed, final PlayerDeathEvent event) {
|
||||
//Siege specific
|
||||
Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
// Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), "spawn " + killed.getName());
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
|
||||
Reference in new issue
Block a user