raid cooldown

This commit is contained in:
Aubri Seebauer committed 2023-04-10 19:46:42 -04:00
1 parent 10908764d3
commit 65e1624581
5 files changed
+71 -21

No files matched your search

@@ -4,6 +4,7 @@ import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException; import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.*; import com.palmergames.bukkit.towny.object.*;
import com.palmergames.bukkit.towny.object.metadata.LongDataField;
import me.ShermansWorld.AlathraWar.commands.RaidCommands; import me.ShermansWorld.AlathraWar.commands.RaidCommands;
import me.ShermansWorld.AlathraWar.data.RaidData; import me.ShermansWorld.AlathraWar.data.RaidData;
import me.ShermansWorld.AlathraWar.data.RaidPhase; import me.ShermansWorld.AlathraWar.data.RaidPhase;
@@ -51,8 +52,7 @@ v/ No teleporting by raiders
v/ Points management v/ Points management
v/ Raider death is negative score v/ Raider death is negative score
v/ Defender death is positive score v/ Defender death is positive score
- Raiders can loot townblocks for extra score v/ Raiders can loot townblocks for extra score
- TODO Raiders gain points for
v/ Raiders on death are teleported to their town spawn. v/ Raiders on death are teleported to their town spawn.
*/ */
@@ -149,6 +149,10 @@ public class Raid {
e.printStackTrace(); e.printStackTrace();
} }
//set the last raided time to now
raidedTown.addMetaData(new LongDataField("lastRaided", (System.currentTimeMillis() / 1000)));
war.setLastRaidTime((System.currentTimeMillis() / 1000));
// Creates 10 second looping function for Raid // Creates 10 second looping function for Raid
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(), this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(),
(Runnable) new Runnable() { (Runnable) new Runnable() {
@@ -22,6 +22,8 @@ public class War {
// References // References
private ArrayList<Siege> sieges = new ArrayList<Siege>(); private ArrayList<Siege> sieges = new ArrayList<Siege>();
private ArrayList<Raid> raids = new ArrayList<Raid>(); private ArrayList<Raid> raids = new ArrayList<Raid>();
private Long lastRaidTime;
/** /**
* War Constructor * War Constructor
@@ -204,4 +206,12 @@ public class War {
return returnList; return returnList;
} }
public void setLastRaidTime(Long lastRaidTime) {
this.lastRaidTime = lastRaidTime;
}
public Long getLastRaidTime() {
return this.lastRaidTime;
}
} }
@@ -4,6 +4,7 @@ import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException; import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.*; import com.palmergames.bukkit.towny.object.*;
import com.palmergames.bukkit.towny.object.metadata.LongDataField;
import me.ShermansWorld.AlathraWar.*; import me.ShermansWorld.AlathraWar.*;
import me.ShermansWorld.AlathraWar.data.RaidPhase; import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.data.WarData; import me.ShermansWorld.AlathraWar.data.WarData;
@@ -108,7 +109,7 @@ public class RaidCommands implements CommandExecutor {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!"); p.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()) + "Thi town was raided too recently!"); p.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()) + "This town is already being raided at this time!"); p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
@@ -130,7 +131,7 @@ public class RaidCommands implements CommandExecutor {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!"); p.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()) + "Thi town was raided too recently!"); p.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()) + "This town is already being raided at this time!"); p.sendMessage(String.valueOf(Helper.Chatlabel()) + "This town is already being raided at this time!");
@@ -4,6 +4,9 @@ import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.object.Coord; import com.palmergames.bukkit.towny.object.Coord;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.WorldCoord; 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.Main;
import me.ShermansWorld.AlathraWar.Raid; import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.War; import me.ShermansWorld.AlathraWar.War;
@@ -58,7 +61,7 @@ public class RaidData {
} }
public static void removeRaid(Raid raid) { public static void removeRaid(Raid raid) {
// raid.getWar().getRaids().remove(raid); //TODO remove from war raid.getWar().getRaids().remove(raid);
raids.remove(raid); raids.remove(raid);
//deleteRaid(raid); //deleteRaid(raid);
@@ -123,16 +126,18 @@ public class RaidData {
war.save(); war.save();
} }
//TODO Delete raid /**
private static void deleteRaid(War war) { * deletes raid, unused
File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter); */
// private static void deleteRaid(War war) {
for (File file : files) { // File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
if (file.getName().startsWith(war.getName())) { //
file.delete(); // for (File file : files) {
} // if (file.getName().startsWith(war.getName())) {
} // file.delete();
} // }
// }
// }
/** /**
* Turns a raid into a map * Turns a raid into a map
@@ -186,25 +191,53 @@ public class RaidData {
return returnMap; return returnMap;
} }
//TODO raid time check
/** /**
* @Isaac this is for getting when the last raid was on a town * @Isaac this is for getting when the last raid was on a town
* *
* @return * @return
*/ */
public static int whenTownLastRaided() { public static long whenTownLastRaided(Town town) {
return 0; if(town.hasMeta("lastRaided")) {
CustomDataField field = town.getMetadata("lastRaided");
if(field != null) {
if (field instanceof IntegerDataField) {
return ((IntegerDataField) field).getValue();
}
}
return -1L;
} else {
town.addMetaData(new LongDataField("lastRaided", 0L));
}
return -1L;
} }
//TODO raid validity check
/** /**
* @Isaac this is for getting if a town can be raided, return (-1, 0, 1, 2) based on status * @Isaac this is for getting if a town can be raided, return (-1, 0, 1, 2) based on status
* (24 hours town cooldown, 6 hour nation cooldown, valid time to raid, town being raided already) * (24 hours town cooldown, 6 hour war cooldown, valid time to raid, town being raided already)
* *
* @return * @return
*/ */
public static int isValidRaid(War war, Town town) { public static int isValidRaid(War war, Town town) {
return 0; long townTime = whenTownLastRaided(town);
//24 hours town cooldown
if((System.currentTimeMillis() / 1000) - townTime <= 86400) {
return -1;
}
//6 hour raid cooldown for war
if((System.currentTimeMillis() / 1000) - war.getLastRaidTime() <= 21600) {
return 0;
}
//check if being raided
for (Raid raid : war.getRaids()) {
if (raid.getRaidedTown().getName().equals(town.getName())) {
return 2;
}
}
return 1;
} }
} }
@@ -98,6 +98,7 @@ public class WarData
war.setSide1Towns((ArrayList<String>) fileData.get("side1Towns")); war.setSide1Towns((ArrayList<String>) fileData.get("side1Towns"));
war.setSide2Towns((ArrayList<String>) fileData.get("side2Towns")); war.setSide2Towns((ArrayList<String>) fileData.get("side2Towns"));
war.setLastRaidTime((Long) fileData.get("lastRaidTime"));
return war; return war;
} }
@@ -119,6 +120,7 @@ public class WarData
sHashMap.put("sieges", SiegeData.getSiegeMap(war)); sHashMap.put("sieges", SiegeData.getSiegeMap(war));
sHashMap.put("raids", RaidData.getRaidMap(war)); sHashMap.put("raids", RaidData.getRaidMap(war));
sHashMap.put("lastRaidTime", war.getLastRaidTime());
DataManager.saveData("wars" + File.separator + war.getName() + ".yml", sHashMap); DataManager.saveData("wars" + File.separator + war.getName() + ".yml", sHashMap);