fix town metadata read

This commit is contained in:
Aubri Seebauer committed 2023-04-18 20:25:37 -04:00
1 parent 341ba1a4af
commit 844c44f56b
4 files changed
+54 -63

No files matched your search

@@ -201,7 +201,7 @@ public class Raid {
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(), this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(),
getTickLoop(), 0L, incremental); getTickLoop(), 0L, incremental);
// this.getWar().addRaid(this); todo FIX this.getWar().addRaid(this); //todo FIX
this.save(); this.save();
} }
@@ -446,7 +446,7 @@ public class Raid {
// killed.sendMessage(String.valueOf(Helper.Chatlabel()) + "You died before being raided and have been teleported back to the defending town's spawn."); // 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 //teleport the killer back to the gather towns spawn
if (killed.getKiller() instanceof Player) { if (killed.getKiller() instanceof Player) {
if (this.getActiveRaiders().contains(killed.getKiller().getName())) { if (this.getActiveRaiders().contains(killed.getKiller().getName())) {
try { try {
@@ -554,7 +554,7 @@ public class Raid {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders 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."); + " have barely pushed back the raiders of " + this.raiders + ". More has been lost than gained.");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.raidedTown.getName() 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 Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!"); .log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(500, "Raid chest"); this.raidedTown.getAccount().deposit(500, "Raid chest");
@@ -562,7 +562,7 @@ public class Raid {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders
+ " have fended off the raiders of " + this.raiders + "!"); + " have fended off the raiders of " + this.raiders + "!");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.raidedTown.getName() 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 Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!"); .log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(1000, "Raid chest"); this.raidedTown.getAccount().deposit(1000, "Raid chest");
@@ -570,7 +570,7 @@ public class Raid {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + "The defenders from " + this.defenders
+ " have wholly defeated the raiders of " + this.raiders + "! They barely broke the walls."); + " have wholly defeated the raiders of " + this.raiders + "! They barely broke the walls.");
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + this.raidedTown.getName() 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 Main.warLogger
.log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!"); .log("The defenders from " + this.defenders + " have won the raid of " + this.raidedTown.getName() + "!");
this.raidedTown.getAccount().deposit(1000, "Raid chest"); this.raidedTown.getAccount().deposit(1000, "Raid chest");
@@ -487,8 +487,8 @@ public class AdminCommands implements CommandExecutor {
side1Players += ", "; side1Players += ", ";
} }
//cut off last two characters //cut off last two characters
side1Towns = side1Towns.substring(0, side1Towns.length() - 3); side1Towns = side1Towns.substring(0, side1Towns.length() - 2);
side1Players = side1Players.substring(0, side1Players.length() - 3); side1Players = side1Players.substring(0, side1Players.length() - 2);
p.sendMessage(Helper.Chatlabel() + w.getSide1() + " Towns: " + side1Towns); p.sendMessage(Helper.Chatlabel() + w.getSide1() + " Towns: " + side1Towns);
p.sendMessage(Helper.Chatlabel() + w.getSide1() + " Players: " + side1Players); p.sendMessage(Helper.Chatlabel() + w.getSide1() + " Players: " + side1Players);
p.sendMessage(Helper.Chatlabel() + "oOo-----------------===-----------------oOo"); p.sendMessage(Helper.Chatlabel() + "oOo-----------------===-----------------oOo");
@@ -503,8 +503,8 @@ public class AdminCommands implements CommandExecutor {
side2Players += ", "; side2Players += ", ";
} }
//cut off last two characters //cut off last two characters
side2Towns = side2Towns.substring(0, side2Towns.length() - 3); side2Towns = side2Towns.substring(0, side2Towns.length() - 2);
side2Players = side2Players.substring(0, side2Players.length() - 3); side2Players = side2Players.substring(0, side2Players.length() - 2);
p.sendMessage(Helper.Chatlabel() + w.getSide2() + " Towns: " + side2Towns); p.sendMessage(Helper.Chatlabel() + w.getSide2() + " Towns: " + side2Towns);
p.sendMessage(Helper.Chatlabel() + w.getSide2() + " Players: " + side2Players); p.sendMessage(Helper.Chatlabel() + w.getSide2() + " Players: " + side2Players);
return true; return true;
@@ -575,7 +575,7 @@ public class AdminCommands implements CommandExecutor {
attackers += ", "; attackers += ", ";
} }
//cut off last two characters //cut off last two characters
attackers = attackers.substring(0, attackers.length() - 3); attackers = attackers.substring(0, attackers.length() - 2);
p.sendMessage(Helper.Chatlabel() + "Attacking Players: " + attackers); p.sendMessage(Helper.Chatlabel() + "Attacking Players: " + attackers);
String defenders = ""; String defenders = "";
for (String pl : s.getAttackerPlayers()) { for (String pl : s.getAttackerPlayers()) {
@@ -583,7 +583,7 @@ public class AdminCommands implements CommandExecutor {
defenders += ", "; defenders += ", ";
} }
//cut off last two characters //cut off last two characters
defenders = defenders.substring(0, defenders.length() - 3); defenders = defenders.substring(0, defenders.length() - 2);
p.sendMessage(Helper.Chatlabel() + "Defending Players: " + defenders); p.sendMessage(Helper.Chatlabel() + "Defending Players: " + defenders);
return true; return true;
} }
@@ -73,6 +73,16 @@ public class RaidCommands implements CommandExecutor {
if (war.getName().equalsIgnoreCase(args[1 + (admin ? 1 : 0)])) { if (war.getName().equalsIgnoreCase(args[1 + (admin ? 1 : 0)])) {
warFound = true; warFound = true;
Player raidOwner = p;
TownyWorld townyWorld;
townyWorld = WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownyWorld();
if(admin && args.length >= 6) {
raidOwner = Bukkit.getPlayer(args[5]);
if(raidOwner == null) {
raidOwner = p;
}
}
String side = ""; String side = "";
if (war.getSide1Players().contains(p.getName())) { if (war.getSide1Players().contains(p.getName())) {
side = war.getSide1(); side = war.getSide1();
@@ -82,16 +92,6 @@ public class RaidCommands implements CommandExecutor {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]"); p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are not in this war! Type /war join [war] [side]");
return; return;
} }
TownyWorld townyWorld;
townyWorld = WorldCoord.parseWorldCoord(p.getLocation()).getTownyWorld();
Player raidOwner = p;
if(admin && args.length >= 6) {
raidOwner = Bukkit.getOfflinePlayer(args[5]).getPlayer();
if(raidOwner == null) {
raidOwner = p;
}
}
//check if in a town //check if in a town
//takes the command runners town as the gather point //takes the command runners town as the gather point
@@ -101,22 +101,22 @@ public class RaidCommands implements CommandExecutor {
if(admin && args.length >= 5) { if(admin && args.length >= 5) {
if(args[4].equalsIgnoreCase("defaultCode")) { if(args[4].equalsIgnoreCase("defaultCode")) {
//use default behavior //use default behavior
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(p.getLocation()).getTownBlock()); gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
} else if(TownyAPI.getInstance().getTown(args[4]) != null) { } else if(TownyAPI.getInstance().getTown(args[4]) != null) {
gatherTown = TownyAPI.getInstance().getTown(args[4]); gatherTown = TownyAPI.getInstance().getTown(args[4]);
} else { } else {
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(p.getLocation()).getTownBlock()); gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
} }
} else { } else {
gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(p.getLocation()).getTownBlock()); gatherTown = TownyAPI.getInstance().getTownOrNull(WorldCoord.parseWorldCoord(raidOwner.getLocation()).getTownBlock());
} }
} catch (NotRegisteredException e2) { } 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."); 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; return;
} }
if (gatherTown == null) { 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."); 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; return;
} }
@@ -127,8 +127,6 @@ public class RaidCommands implements CommandExecutor {
//if this is run as admin, shift our check forward a slot //if this is run as admin, shift our check forward a slot
if (raidedTown.getName().equalsIgnoreCase(args[2 + (admin ? 1 : 0)]) && gatherTown != null) { if (raidedTown.getName().equalsIgnoreCase(args[2 + (admin ? 1 : 0)]) && gatherTown != null) {
townExists = true; townExists = true;
boolean attackingOwnSide = false;
Raid raid2; Raid raid2;
if (war.getSide1Players().contains(p.getName())) { if (war.getSide1Players().contains(p.getName())) {
@@ -138,16 +136,16 @@ public class RaidCommands implements CommandExecutor {
//if were admin, see if an owner arg exists, and if so then use it //if were admin, see if an owner arg exists, and if so then use it
raid2 = new Raid(war, raidedTown, gatherTown, true, raidOwner); raid2 = new Raid(war, raidedTown, gatherTown, true, raidOwner);
} else if (c == 1) { } else if (c == 1) {
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; return;
} else if (c == 0) { } else if (c == 0) {
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; return;
} else if (c == -1) { } else if (c == -1) {
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; return;
} else if (c == -2) { } else if (c == -2) {
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; return;
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@@ -163,50 +161,43 @@ public class RaidCommands implements CommandExecutor {
if (c == 2) { if (c == 2) {
raid2 = new Raid(war, raidedTown, gatherTown, false, raidOwner); raid2 = new Raid(war, raidedTown, gatherTown, false, raidOwner);
} else if (c == 1) { } else if (c == 1) {
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; return;
} else if (c == 0) { } else if (c == 0) {
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; return;
} else if (c == -1) { } else if (c == -1) {
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; return;
} else if (c == -2) { } else if (c == -2) {
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; return;
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
} }
//validity check over attacking own towns // Player participance check
final ArrayList<String> residentNames = new ArrayList<String>(); Town leaderTown = TownyAPI.getInstance().getResident(raidOwner).getTownOrNull();
for (final Resident resident : raidedTown.getResidents()) { int sideR = war.getSide(leaderTown.getName());
residentNames.add(resident.getName()); if (sideR == 0) {
raidOwner.sendMessage(Helper.Chatlabel() + "You are not in this war.");
return;
} else if (sideR == -1) {
raidOwner.sendMessage(Helper.Chatlabel() + "You have surrendered.");
return;
} }
if (raid2.getSide1AreRaiders()) { // Attacking own side
for (final String playerName : war.getSide1Players()) { if (war.getSide(raidedTown) == sideR) {
if (residentNames.contains(playerName)) { raidOwner.sendMessage(Helper.Chatlabel() + "You cannot attack your own towns.");
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!");
return; return;
} }
//check player balance //check player balance
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUniqueId()); final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(p.getUniqueId());
if (Main.econ.getBalance(offlinePlayer) <= 1000.0) { 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."); raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $1000 to put up to start a raid.");
return; return;
} }
@@ -225,8 +216,8 @@ public class RaidCommands implements CommandExecutor {
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) +
"The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!"); "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(p.getName() + " started a raid using admin methods."); 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("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!"); Main.warLogger.log("The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
} }
@@ -157,8 +157,8 @@ public class RaidData {
HashMap<String, Object> returnMap = new HashMap<String, Object>(); HashMap<String, Object> returnMap = new HashMap<String, Object>();
// Shoves everything into a map. // Shoves everything into a map.
returnMap.put("name", raid.getName()); returnMap.put("name", raid.getName());
returnMap.put("raidedTown", raid.getRaidedTown()); returnMap.put("raidedTown", raid.getRaidedTown().getName());
returnMap.put("gatherTown", raid.getRaidedTown()); returnMap.put("gatherTown", raid.getGatherTown().getName());
returnMap.put("raidTicks", raid.getRaidTicks()); returnMap.put("raidTicks", raid.getRaidTicks());
returnMap.put("raidPhase", raid.getPhase().name()); returnMap.put("raidPhase", raid.getPhase().name());
returnMap.put("raidScore", raid.getRaidScore()); returnMap.put("raidScore", raid.getRaidScore());
@@ -211,8 +211,8 @@ public class RaidData {
if (town.hasMeta("lastRaided")) { if (town.hasMeta("lastRaided")) {
CustomDataField field = town.getMetadata("lastRaided"); CustomDataField field = town.getMetadata("lastRaided");
if (field != null) { if (field != null) {
if (field instanceof IntegerDataField) { if (field instanceof LongDataField) {
return ((IntegerDataField) field).getValue(); return ((LongDataField) field).getValue();
} }
} }
return -1L; return -1L;