mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 22:14:45 +00:00
fix town metadata read
This commit is contained in:
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(),
|
||||
getTickLoop(), 0L, incremental);
|
||||
|
||||
// this.getWar().addRaid(this); todo FIX
|
||||
this.getWar().addRaid(this); //todo FIX
|
||||
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.");
|
||||
}
|
||||
|
||||
//teleport the killer back to the raided towns spawn
|
||||
//teleport the killer back to the gather towns spawn
|
||||
if (killed.getKiller() instanceof Player) {
|
||||
if (this.getActiveRaiders().contains(killed.getKiller().getName())) {
|
||||
try {
|
||||
@@ -554,7 +554,7 @@ public class Raid {
|
||||
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");
|
||||
@@ -562,7 +562,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");
|
||||
@@ -570,7 +570,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");
|
||||
|
||||
@@ -487,8 +487,8 @@ public class AdminCommands implements CommandExecutor {
|
||||
side1Players += ", ";
|
||||
}
|
||||
//cut off last two characters
|
||||
side1Towns = side1Towns.substring(0, side1Towns.length() - 3);
|
||||
side1Players = side1Players.substring(0, side1Players.length() - 3);
|
||||
side1Towns = side1Towns.substring(0, side1Towns.length() - 2);
|
||||
side1Players = side1Players.substring(0, side1Players.length() - 2);
|
||||
p.sendMessage(Helper.Chatlabel() + w.getSide1() + " Towns: " + side1Towns);
|
||||
p.sendMessage(Helper.Chatlabel() + w.getSide1() + " Players: " + side1Players);
|
||||
p.sendMessage(Helper.Chatlabel() + "oOo-----------------===-----------------oOo");
|
||||
@@ -503,8 +503,8 @@ public class AdminCommands implements CommandExecutor {
|
||||
side2Players += ", ";
|
||||
}
|
||||
//cut off last two characters
|
||||
side2Towns = side2Towns.substring(0, side2Towns.length() - 3);
|
||||
side2Players = side2Players.substring(0, side2Players.length() - 3);
|
||||
side2Towns = side2Towns.substring(0, side2Towns.length() - 2);
|
||||
side2Players = side2Players.substring(0, side2Players.length() - 2);
|
||||
p.sendMessage(Helper.Chatlabel() + w.getSide2() + " Towns: " + side2Towns);
|
||||
p.sendMessage(Helper.Chatlabel() + w.getSide2() + " Players: " + side2Players);
|
||||
return true;
|
||||
@@ -575,7 +575,7 @@ public class AdminCommands implements CommandExecutor {
|
||||
attackers += ", ";
|
||||
}
|
||||
//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);
|
||||
String defenders = "";
|
||||
for (String pl : s.getAttackerPlayers()) {
|
||||
@@ -583,7 +583,7 @@ public class AdminCommands implements CommandExecutor {
|
||||
defenders += ", ";
|
||||
}
|
||||
//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);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,16 @@ public class RaidCommands implements CommandExecutor {
|
||||
if (war.getName().equalsIgnoreCase(args[1 + (admin ? 1 : 0)])) {
|
||||
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 = "";
|
||||
if (war.getSide1Players().contains(p.getName())) {
|
||||
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]");
|
||||
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
|
||||
//takes the command runners town as the gather point
|
||||
@@ -101,22 +101,22 @@ public class RaidCommands implements CommandExecutor {
|
||||
if(admin && args.length >= 5) {
|
||||
if(args[4].equalsIgnoreCase("defaultCode")) {
|
||||
//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) {
|
||||
gatherTown = TownyAPI.getInstance().getTown(args[4]);
|
||||
} else {
|
||||
p.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());
|
||||
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(p.getLocation()).getTownBlock());
|
||||
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.");
|
||||
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.");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -127,8 +127,6 @@ 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) {
|
||||
townExists = true;
|
||||
boolean attackingOwnSide = false;
|
||||
|
||||
|
||||
Raid raid2;
|
||||
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
|
||||
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!");
|
||||
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!");
|
||||
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!");
|
||||
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!");
|
||||
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();
|
||||
@@ -163,50 +161,43 @@ public class RaidCommands implements CommandExecutor {
|
||||
if (c == 2) {
|
||||
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!");
|
||||
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!");
|
||||
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!");
|
||||
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!");
|
||||
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) {
|
||||
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()) {
|
||||
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) {
|
||||
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.");
|
||||
raidOwner.sendMessage(String.valueOf(Helper.Chatlabel()) + "You must have at least $1000 to put up to start a raid.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -225,8 +216,8 @@ public class RaidCommands implements CommandExecutor {
|
||||
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) +
|
||||
"The Raiders are gathering at " + gatherTown.getName() + " before making the journey over!");
|
||||
|
||||
Main.warLogger.log(p.getName() + " started a raid.");
|
||||
if(admin) Main.warLogger.log(p.getName() + " started a raid using admin methods.");
|
||||
Main.warLogger.log(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!");
|
||||
}
|
||||
|
||||
@@ -157,8 +157,8 @@ 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());
|
||||
@@ -211,8 +211,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;
|
||||
|
||||
Reference in new issue
Block a user