raid purges self on completion, polishes

This commit is contained in:
Aubri Seebauer committed 2023-04-20 20:45:38 -04:00
1 parent 40061cf40a
commit 6586d92046
7 files changed
+104 -114

No files matched your search

@@ -100,7 +100,7 @@ public class Raid {
* @param raidTicks
*/
public Raid(final War war, final Town raidedTown, final Town gatherTown,
final boolean side1AreRaiders, final int raidTicks, Player owner) {
final boolean side1AreRaiders, final int raidTicks, OfflinePlayer owner) {
this.bukkitId = new int[1];
this.war = war;
@@ -129,7 +129,7 @@ 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, Player owner) {
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);
@@ -145,7 +145,7 @@ public class Raid {
* @param side1AreRaiders
*/
public Raid(final War war, final Town raidedTown, final Town gatherTown,
final boolean side1AreRaiders, Player owner) {
final boolean side1AreRaiders, OfflinePlayer owner) {
this.bukkitId = new int[1];
this.activeRaiders = activeRaiders == null ? new ArrayList<>() : activeRaiders;
this.war = war;
@@ -191,9 +191,9 @@ public class Raid {
//set the last raided time to now
raidedTown.addMetaData(new LongDataField("lastRaided", (System.currentTimeMillis() / 1000)));
if(war.getSide1Players().contains(owner.getName())) {
war.setLastRaidTimeSide1((System.currentTimeMillis() / 1000));
war.setLastRaidTimeSide1((int) (System.currentTimeMillis() / 1000));
} else if(war.getSide2Players().contains(owner.getName())) {
war.setLastRaidTimeSide2((System.currentTimeMillis() / 1000));
war.setLastRaidTimeSide2((int) (System.currentTimeMillis() / 1000));
} else {
}
@@ -273,10 +273,12 @@ public class Raid {
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 $%.2f 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 $%.2f 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();
@@ -285,10 +287,12 @@ public class Raid {
//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!");
}
}
@@ -335,16 +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) {
}
Player pl = Bukkit.getPlayer(playerName);
if(pl != null) pl.sendMessage(String.valueOf(Helper.Chatlabel()) + "Raider killed! -40 Raid Score");
}
//tp to gather town spawn
@@ -365,16 +365,12 @@ 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
@@ -392,16 +388,12 @@ 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
@@ -416,12 +408,14 @@ public class Raid {
}
//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);
}
}
}
}
@@ -431,16 +425,12 @@ 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
@@ -451,7 +441,7 @@ public class Raid {
}
//teleport the killer back to the gather towns spawn
if (killed.getKiller() instanceof Player) {
if (killed.getKiller() != null) {
if (this.getActiveRaiders().contains(killed.getKiller().getName())) {
try {
killed.getKiller().teleport(this.getGatherTown().getSpawn());
@@ -824,23 +814,21 @@ public class Raid {
for (String playerName : getActiveRaiders()) {
try {
Player p = Bukkit.getPlayer(playerName);
ArrayList<WorldCoord> cluster = Helper.getCluster(Raid.this.getGatherTown().getHomeBlock().getWorldCoord());
if (!cluster.contains(WorldCoord.parseWorldCoord(p))) {
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]");
if(p != null) {
ArrayList<WorldCoord> cluster = Helper.getCluster(Raid.this.getGatherTown().getHomeBlock().getWorldCoord());
if (!cluster.contains(WorldCoord.parseWorldCoord(p))) {
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) {
} catch (NullPointerException | TownyException e) {
e.printStackTrace();
}
}
@@ -888,40 +876,35 @@ public class Raid {
+ 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);
WorldCoord wc = WorldCoord.parseWorldCoord(p);
if (p.isSneaking()) {
//check if our chunk is looted, if so skip this player
//Idk if thisll work but if it do then ye
if (Raid.this.lootedChunks.containsKey(wc)) {
if (Raid.this.lootedChunks.get(wc).finished) {
p.sendMessage(Helper.Chatlabel() + "This chunk is already looted, try another.");
if(p != null) {
WorldCoord wc = WorldCoord.parseWorldCoord(p);
if (p.isSneaking()) {
//check if our chunk is looted, if so skip this player
//Idk if thisll work but if it do then ye
if (Raid.this.lootedChunks.containsKey(wc)) {
if (Raid.this.lootedChunks.get(wc).finished) {
p.sendMessage(Helper.Chatlabel() + "This chunk is already looted, try another.");
} else {
doLootAt(p, wc);
}
} else {
doLootAt(p, wc);
}
} else {
if (Raid.this.getRaidedTown().hasTownBlock(wc)) {
doLootAt(p, wc);
} else {
p.sendMessage(Helper.Chatlabel() + "This space is not part of the raided town, you cannot loot this area.");
if (Raid.this.getRaidedTown().hasTownBlock(wc)) {
doLootAt(p, wc);
} else {
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;
// }
// }
}
}
}
}
};
}
@@ -24,8 +24,8 @@ public class War {
// References
private ArrayList<Siege> sieges = new ArrayList<Siege>();
private ArrayList<Raid> raids = new ArrayList<Raid>();
private long lastRaidTimeSide1 = 0;
private long lastRaidTimeSide2 = 0;
private int lastRaidTimeSide1 = 0;
private int lastRaidTimeSide2 = 0;
/**
* War Constructor
@@ -226,19 +226,19 @@ public class War {
return returnList;
}
public void setLastRaidTimeSide1(long lastRaidTime) {
public void setLastRaidTimeSide1(int lastRaidTime) {
this.lastRaidTimeSide1 = lastRaidTime;
}
public long getLastRaidTimeSide1() {
public int getLastRaidTimeSide1() {
return this.lastRaidTimeSide1;
}
public void setLastRaidTimeSide2(long lastRaidTime) {
public void setLastRaidTimeSide2(int lastRaidTime) {
this.lastRaidTimeSide2 = lastRaidTime;
}
public long getLastRaidTimeSide2() {
public int getLastRaidTimeSide2() {
return this.lastRaidTimeSide2;
}
}
@@ -1338,12 +1338,12 @@ public class AdminCommands implements CommandExecutor {
} else if (args[3].equalsIgnoreCase("set")) {
if (args.length >= 7) {
if (args[6].equals(w.getSide1())) {
w.setLastRaidTimeSide1(Long.parseLong(args[6]));
w.setLastRaidTimeSide1(Integer.parseInt(args[6]));
p.sendMessage(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]);
Main.warLogger.log(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]);
return finalizeWar(w);
} else if (args[6].equals(w.getSide2())) {
w.setLastRaidTimeSide2(Long.parseLong(args[6]));
w.setLastRaidTimeSide2(Integer.parseInt(args[6]));
p.sendMessage(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]);
Main.warLogger.log(Helper.Chatlabel() + "Set last raid time in war " + args[4] + " to " + args[6]);
return finalizeWar(w);
@@ -1359,12 +1359,12 @@ public class AdminCommands implements CommandExecutor {
if (args.length >= 6) {
if (args[5].equals(w.getSide1())) {
w.setLastRaidTimeSide1(0L);
w.setLastRaidTimeSide1(0);
p.sendMessage(Helper.Chatlabel() + "Reset last raid time in war " + args[4]);
Main.warLogger.log(Helper.Chatlabel() + "Reset last raid time in war " + args[4]);
return finalizeWar(w);
} else if (args[5].equals(w.getSide2())) {
w.setLastRaidTimeSide2(0L);
w.setLastRaidTimeSide2(0);
p.sendMessage(Helper.Chatlabel() + "Reset last raid time in war " + args[4]);
Main.warLogger.log(Helper.Chatlabel() + "Reset last raid time in war " + args[4]);
return finalizeWar(w);
@@ -577,7 +577,7 @@ public class AdminTabCompletion implements TabCompleter {
if (args.length > 6) {
return empty;
} else {
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[6]);
return NameUtil.filterByStart(CommandHelper.getWarSides(args[4]), args[5]);
}
} else {
if (args.length > 6) {
@@ -129,6 +129,14 @@ public class RaidCommands implements CommandExecutor {
//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;
Raid raid2;
@@ -5,23 +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.Siege;
import me.ShermansWorld.AlathraWar.War;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import javax.annotation.Nonnull;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.*;
public class RaidData {
// Static Raid list for all active raids
@@ -91,27 +85,30 @@ public class RaidData {
Town gatherTown = TownyAPI.getInstance().getTown((String) fileData.get("gatherTown"));
boolean attackBoolean = Boolean.parseBoolean((String) fileData.get("side1AreRaiders"));
//THIS MAY OR MAY NOT WORK
OfflinePlayer p = Bukkit.getOfflinePlayer((String) fileData.get("owner"));
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString((String) fileData.get("owner")));
Raid raid = new Raid(war, raidedTown, gatherTown, attackBoolean, p.getPlayer());
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");
@@ -133,7 +130,8 @@ public class RaidData {
Raid raid = fromMap(war, map);
returnList.add(raid);
RaidData.addRaid(raid);
raid.resume();
}
return returnList;
}
@@ -83,6 +83,7 @@ public class WarData
returnList.add(fileWar);
} catch (Exception e) {
Main.warLogger.log("Failed to load " + file.getName());
e.printStackTrace();
}
}
@@ -107,8 +108,8 @@ public class WarData
if(fileData.get("lastRaidTimeSide1") != null && fileData.get("lastRaidTimeSide2") != null) {
war.setLastRaidTimeSide1((long) fileData.get("lastRaidTimeSide1"));
war.setLastRaidTimeSide2((long) fileData.get("lastRaidTimeSide2"));
war.setLastRaidTimeSide1((int) fileData.get("lastRaidTimeSide1"));
war.setLastRaidTimeSide2((int) fileData.get("lastRaidTimeSide2"));
}