mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
raid cooldown
This commit is contained in:
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.TownyException;
|
||||
import com.palmergames.bukkit.towny.object.*;
|
||||
import com.palmergames.bukkit.towny.object.metadata.LongDataField;
|
||||
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidData;
|
||||
import me.ShermansWorld.AlathraWar.data.RaidPhase;
|
||||
@@ -51,8 +52,7 @@ v/ No teleporting by raiders
|
||||
v/ Points management
|
||||
v/ Raider death is negative score
|
||||
v/ Defender death is positive score
|
||||
- Raiders can loot townblocks for extra score
|
||||
- TODO Raiders gain points for
|
||||
v/ Raiders can loot townblocks for extra score
|
||||
v/ Raiders on death are teleported to their town spawn.
|
||||
|
||||
*/
|
||||
@@ -149,6 +149,10 @@ public class Raid {
|
||||
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
|
||||
this.bukkitId[0] = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) Main.getInstance(),
|
||||
(Runnable) new Runnable() {
|
||||
|
||||
@@ -22,6 +22,8 @@ public class War {
|
||||
// References
|
||||
private ArrayList<Siege> sieges = new ArrayList<Siege>();
|
||||
private ArrayList<Raid> raids = new ArrayList<Raid>();
|
||||
private Long lastRaidTime;
|
||||
|
||||
|
||||
/**
|
||||
* War Constructor
|
||||
@@ -204,4 +206,12 @@ public class War {
|
||||
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.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;
|
||||
@@ -108,7 +109,7 @@ public class RaidCommands implements CommandExecutor {
|
||||
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "Your side has raided too recently!");
|
||||
return;
|
||||
} 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;
|
||||
} else if (c == 2) {
|
||||
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!");
|
||||
return;
|
||||
} 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;
|
||||
} else if (c == 2) {
|
||||
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.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;
|
||||
@@ -58,7 +61,7 @@ public class RaidData {
|
||||
}
|
||||
|
||||
public static void removeRaid(Raid raid) {
|
||||
// raid.getWar().getRaids().remove(raid); //TODO remove from war
|
||||
raid.getWar().getRaids().remove(raid);
|
||||
raids.remove(raid);
|
||||
|
||||
//deleteRaid(raid);
|
||||
@@ -123,16 +126,18 @@ public class RaidData {
|
||||
war.save();
|
||||
}
|
||||
|
||||
//TODO Delete raid
|
||||
private static void deleteRaid(War war) {
|
||||
File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
|
||||
|
||||
for (File file : files) {
|
||||
if (file.getName().startsWith(war.getName())) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* deletes raid, unused
|
||||
*/
|
||||
// private static void deleteRaid(War war) {
|
||||
// File[] files = new File(dataFolderPath + File.separator + "wars").listFiles(ymlFilter);
|
||||
//
|
||||
// for (File file : files) {
|
||||
// if (file.getName().startsWith(war.getName())) {
|
||||
// file.delete();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Turns a raid into a map
|
||||
@@ -186,25 +191,53 @@ public class RaidData {
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
//TODO raid time check
|
||||
/**
|
||||
* @Isaac this is for getting when the last raid was on a town
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int whenTownLastRaided() {
|
||||
return 0;
|
||||
public static long whenTownLastRaided(Town town) {
|
||||
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
|
||||
* (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
|
||||
*/
|
||||
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.setSide2Towns((ArrayList<String>) fileData.get("side2Towns"));
|
||||
|
||||
war.setLastRaidTime((Long) fileData.get("lastRaidTime"));
|
||||
|
||||
return war;
|
||||
}
|
||||
@@ -119,6 +120,7 @@ public class WarData
|
||||
|
||||
sHashMap.put("sieges", SiegeData.getSiegeMap(war));
|
||||
sHashMap.put("raids", RaidData.getRaidMap(war));
|
||||
sHashMap.put("lastRaidTime", war.getLastRaidTime());
|
||||
|
||||
|
||||
DataManager.saveData("wars" + File.separator + war.getName() + ".yml", sHashMap);
|
||||
|
||||
Reference in new issue
Block a user