This commit is contained in:
Aubri Seebauer committed 2023-04-10 20:26:18 -04:00
1 parent 575c00242c
commit 9c80c5d0a2
4 files changed
+79 -36

No files matched your search

@@ -97,7 +97,7 @@ public class Main extends JavaPlugin {
new RaidCommands(this); new RaidCommands(this);
getCommand("war").setTabCompleter(new WarTabCompletion()); getCommand("war").setTabCompleter(new WarTabCompletion());
getCommand("siege").setTabCompleter(new SiegeTabCompletion()); getCommand("siege").setTabCompleter(new SiegeTabCompletion());
//getCommand("raid").setTabCompleter(new RaidTabCompletion()); getCommand("raid").setTabCompleter(new RaidTabCompletion());
getServer().getPluginManager().registerEvents((Listener) new KillsListener(), (Plugin) this); getServer().getPluginManager().registerEvents((Listener) new KillsListener(), (Plugin) this);
getServer().getPluginManager().registerEvents((Listener) new CommandsListener(), (Plugin) this); getServer().getPluginManager().registerEvents((Listener) new CommandsListener(), (Plugin) this);
getServer().getPluginManager().registerEvents((Listener) new JoinListener(), (Plugin) this); getServer().getPluginManager().registerEvents((Listener) new JoinListener(), (Plugin) this);
@@ -66,6 +66,7 @@ v/ Raiders on death are teleported to their town spawn.
*/ */
public class Raid { public class Raid {
//Ticks between activity, this is lower than siege because more activity is occuring in a raid
private static final int incremental = 40; private static final int incremental = 40;
private War war; private War war;
private final String name; private final String name;
@@ -88,7 +89,14 @@ public class Raid {
public ArrayList<String> defenderPlayers; public ArrayList<String> defenderPlayers;
public Map<WorldCoord, LootBlock> lootedChunks; public Map<WorldCoord, LootBlock> lootedChunks;
// Constructs raid for staging phase /** Constructs raid for staging phase
*
* @param war
* @param raidedTown
* @param gatherTown
* @param side1AreRaiders
* @param raidTicks
*/
public Raid(final War war, final Town raidedTown, final Town gatherTown, public Raid(final War war, final Town raidedTown, final Town gatherTown,
final boolean side1AreRaiders, final int raidTicks) { final boolean side1AreRaiders, final int raidTicks) {
@@ -105,6 +113,16 @@ public class Raid {
} }
/**
* IDK why this constructor exists but it does
* @param war
* @param raidedTown
* @param gatherTown
* @param side1AreRaiders
* @param raidTicks
* @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) { public Raid(final War war, final Town raidedTown, final Town gatherTown, final boolean side1AreRaiders, final int raidTicks, ArrayList<String> activeRaiders, RaidPhase phase) {
this(war, raidedTown, gatherTown, side1AreRaiders, raidTicks); this(war, raidedTown, gatherTown, side1AreRaiders, raidTicks);
this.activeRaiders = activeRaiders; this.activeRaiders = activeRaiders;
@@ -112,6 +130,13 @@ public class Raid {
} }
/**
* Initial Constructor
* @param war
* @param raidedTown
* @param gatherTown
* @param side1AreRaiders
*/
public Raid(final War war, final Town raidedTown, final Town gatherTown, public Raid(final War war, final Town raidedTown, final Town gatherTown,
final boolean side1AreRaiders) { final boolean side1AreRaiders) {
this.bukkitId = new int[1]; this.bukkitId = new int[1];
@@ -125,6 +150,9 @@ public class Raid {
this.lootedChunks = new HashMap<>(); this.lootedChunks = new HashMap<>();
} }
/**
* Run when raid starts
*/
public void start() { public void start() {
//start //start
@@ -459,7 +487,9 @@ public class Raid {
}, 0L, incremental); }, 0L, incremental);
} }
// End of raid /**
* End of raid
*/
public void stop() { public void stop() {
this.phase = RaidPhase.END; this.phase = RaidPhase.END;
Bukkit.getScheduler().cancelTask(this.bukkitId[0]); Bukkit.getScheduler().cancelTask(this.bukkitId[0]);
@@ -468,7 +498,7 @@ public class Raid {
/** /**
* do loot logic for a chunk, synchronized in case multiple players are looting at once and something breaks * Do loot logic for a chunk, synchronized in case multiple players are looting at once and something breaks
* *
* @param p * @param p
* @param wc * @param wc
@@ -546,7 +576,7 @@ public class Raid {
} }
/** /**
* Need to add call to KillsListener (defined seperate from Siege) * Raider killed in combat
*/ */
public void raiderKilledInCombat(PlayerDeathEvent event) { public void raiderKilledInCombat(PlayerDeathEvent event) {
@@ -578,7 +608,7 @@ public class Raid {
} }
/** /**
* Need to add call to KillsListener (defined seperate from Siege) * Defender killed in combat
*/ */
public void defenderKilledInCombat(PlayerDeathEvent event) { public void defenderKilledInCombat(PlayerDeathEvent event) {
this.addPointsToRaidScore(20); this.addPointsToRaidScore(20);
@@ -604,7 +634,7 @@ public class Raid {
} }
/** /**
* Need to add call to KillsListener (defined seperate from Siege) * Raider killed outside of combat
*/ */
public void raiderKilledOutofCombat(PlayerDeathEvent event) { public void raiderKilledOutofCombat(PlayerDeathEvent event) {
@@ -635,7 +665,7 @@ public class Raid {
} }
/** /**
* Need to add call to KillsListener (defined seperate from Siege) * Defender killed out of combat
*/ */
public void defenderKilledOutofCombat(PlayerDeathEvent event) { public void defenderKilledOutofCombat(PlayerDeathEvent event) {
for (final String playerName : this.getActiveRaiders()) { for (final String playerName : this.getActiveRaiders()) {
@@ -659,6 +689,11 @@ public class Raid {
} }
} }
/**
* Raiders win, give payout and finalize raid
* @param owner
* @param raidScore
*/
public void raidersWin(final Player owner, int raidScore) { public void raidersWin(final Player owner, int raidScore) {
//TODO finalize payout //TODO finalize payout
@@ -724,6 +759,10 @@ public class Raid {
stop(); stop();
} }
/**
* Defenders win, payout, and finalize raid
* @param raidScore
*/
public void defendersWin(int raidScore) { public void defendersWin(int raidScore) {
//TODO finalize payout //TODO finalize payout
/* /*
@@ -768,12 +807,20 @@ public class Raid {
stop(); stop();
} }
/**
* Positively impact the raid score
* @param points
*/
public void addPointsToRaidScore(final int points) { public void addPointsToRaidScore(final int points) {
this.raidScore += points; this.raidScore += points;
//cap //cap
if (raidScore > 1000) this.raidScore = 1000; if (raidScore > 1000) this.raidScore = 1000;
} }
/**
* Negatively impact the raid score
* @param points
*/
public void subtractPointsFromRaidScore(final int points) { public void subtractPointsFromRaidScore(final int points) {
this.raidScore -= points; this.raidScore -= points;
//cap //cap
@@ -1,7 +1,6 @@
package me.ShermansWorld.AlathraWar.data; package me.ShermansWorld.AlathraWar.data;
import com.palmergames.bukkit.towny.TownyAPI; 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.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.CustomDataField;
@@ -36,12 +35,13 @@ public class RaidData {
/** /**
* Gets a raid with a specific name * Gets a raid with a specific name
*
* @param name - Name to check * @param name - Name to check
* @return Raid or Null * @return Raid or Null
*/ */
public static Raid getRaidOrNull(String name) { public static Raid getRaidOrNull(String name) {
for (Raid raid : raids) { for (Raid raid : raids) {
if(raid.getName().equals(name)) return raid; if (raid.getName().equals(name)) return raid;
} }
return null; return null;
} }
@@ -69,6 +69,7 @@ public class RaidData {
/** /**
* Creates a raid object from a provided HashMap * Creates a raid object from a provided HashMap
*
* @param fileData * @param fileData
* @return Raid object * @return Raid object
*/ */
@@ -86,7 +87,7 @@ public class RaidData {
Raid raid = new Raid(war, raidedTown, gatherTown, attackBoolean); Raid raid = new Raid(war, raidedTown, gatherTown, attackBoolean);
//Extra properties, if any are missing the raid doesnt exist yet //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) { if (fileData.get("raidTicks") != null && fileData.get("raidPhase") != null && fileData.get("activeRaiders") != null && fileData.get("lootedChunks") != null) {
//active properties //active properties
raid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase"))); raid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase")));
raid.setRaidTicks((Integer) fileData.get("raidTicks")); raid.setRaidTicks((Integer) fileData.get("raidTicks"));
@@ -116,9 +117,9 @@ public class RaidData {
} }
/** /**
* Saves the war into files. * Saves the war into files.
*
* @param raid - War to be saved. * @param raid - War to be saved.
*/ */
public static void saveRaid(Raid raid) { public static void saveRaid(Raid raid) {
@@ -141,6 +142,7 @@ public class RaidData {
/** /**
* Turns a raid into a map * Turns a raid into a map
*
* @param raid - Raid * @param raid - Raid
* @return Map * @return Map
*/ */
@@ -180,6 +182,7 @@ public class RaidData {
/** /**
* Creates a map of raid maps * Creates a map of raid maps
*
* @param war - War to map * @param war - War to map
* @return Map of Maps * @return Map of Maps
*/ */
@@ -192,14 +195,13 @@ public class RaidData {
} }
/** /**
* @Isaac this is for getting when the last raid was on a town
*
* @return * @return
* @Isaac this is for getting when the last raid was on a town
*/ */
public static long whenTownLastRaided(Town town) { public static long whenTownLastRaided(Town town) {
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 IntegerDataField) {
return ((IntegerDataField) field).getValue(); return ((IntegerDataField) field).getValue();
} }
@@ -212,21 +214,20 @@ public class RaidData {
} }
/** /**
* @return
* @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 war 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) { public static int isValidRaid(War war, Town town) {
long townTime = whenTownLastRaided(town); long townTime = whenTownLastRaided(town);
//24 hours town cooldown //24 hours town cooldown
if((System.currentTimeMillis() / 1000) - townTime <= 86400) { if ((System.currentTimeMillis() / 1000) - townTime <= 86400) {
return -1; return -1;
} }
//6 hour raid cooldown for war //6 hour raid cooldown for war
if((System.currentTimeMillis() / 1000) - war.getLastRaidTime() <= 21600) { if ((System.currentTimeMillis() / 1000) - war.getLastRaidTime() <= 21600) {
return 0; return 0;
} }
@@ -4,31 +4,24 @@ import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Raid; import me.ShermansWorld.AlathraWar.Raid;
import me.ShermansWorld.AlathraWar.Siege; import me.ShermansWorld.AlathraWar.Siege;
import me.ShermansWorld.AlathraWar.War; import me.ShermansWorld.AlathraWar.War;
import me.ShermansWorld.AlathraWar.commands.RaidCommands;
import me.ShermansWorld.AlathraWar.commands.SiegeCommands;
import me.ShermansWorld.AlathraWar.data.RaidPhase; import me.ShermansWorld.AlathraWar.data.RaidPhase;
import me.ShermansWorld.AlathraWar.data.WarData; import me.ShermansWorld.AlathraWar.data.WarData;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.ArrayList; public class CommandsListener implements Listener {
import java.util.List;
public class CommandsListener implements Listener final static String[] prefixes = new String[]{
{
final static String[] prefixes = new String[] {
"", "towny", "essentials", "wild", "minecraft" "", "towny", "essentials", "wild", "minecraft"
}; };
final static String[] blacklistedLong = new String[] { final static String[] blacklistedLong = new String[]{
"n spawn", "nat spawn", "nation spawn", "n spawn", "nat spawn", "nation spawn",
"t spawn", "town spawn" "t spawn", "town spawn"
}; };
final static String[] blacklistedShort = new String[] { final static String[] blacklistedShort = new String[]{
"home", "homes", "warp", "warps", "home", "homes", "warp", "warps",
"wild", "rtp", "spawn", "wilderness", "wildtp", "wild", "rtp", "spawn", "wilderness", "wildtp",
"tpa", "tpahere", "tpaccept", "tpacancel", "tpa", "tpahere", "tpaccept", "tpacancel",
@@ -38,7 +31,6 @@ public class CommandsListener implements Listener
}; };
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onCommandSend(final PlayerCommandPreprocessEvent event) { public void onCommandSend(final PlayerCommandPreprocessEvent event) {
@@ -54,8 +46,8 @@ public class CommandsListener implements Listener
allow n spawn and t spawn for defenders trapped in spawn allow n spawn and t spawn for defenders trapped in spawn
*/ */
for(War war : WarData.getWars()) { for (War war : WarData.getWars()) {
for(Raid raid : war.getRaids()) { for (Raid raid : war.getRaids()) {
//Only do this during regular phases, start and end ignored in case something breaks //Only do this during regular phases, start and end ignored in case something breaks
if (raid.getPhase() == RaidPhase.COMBAT || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.GATHER) { if (raid.getPhase() == RaidPhase.COMBAT || raid.getPhase() == RaidPhase.TRAVEL || raid.getPhase() == RaidPhase.GATHER) {
//only do for active raiders and any defenders //only do for active raiders and any defenders
@@ -74,9 +66,12 @@ public class CommandsListener implements Listener
|| parse.equals("t spawn") || parse.equals("town spawn") || parse.equals("t spawn") || parse.equals("town spawn")
|| parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn") || parse.equals("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation spawn")
|| parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) { || parse.equals("towny:t spawn") || parse.equals("towny:town spawn")) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and allowed to teleport to your town or nation!"); p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and are allowed to teleport to your town or nation.");
return; return;
} }
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You are stuck in spawn and are allowed to teleport to your town or nation.");
event.setCancelled(true);
return;
} }
//else //else
@@ -107,7 +102,7 @@ public class CommandsListener implements Listener
/* /*
Prevent players from teleporting during a siege Prevent players from teleporting during a siege
*/ */
for(Siege siege : war.getSieges()) { for (Siege siege : war.getSieges()) {
//Only do this during regular phases, start and end ignored in case something breaks //Only do this during regular phases, start and end ignored in case something breaks
if (siege.getSiegeTicks() > 0) { if (siege.getSiegeTicks() > 0) {
//only do for active raiders and any defenders //only do for active raiders and any defenders