mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
Cleanup
This commit is contained in:
1 parent
575c00242c
commit
9c80c5d0a2
4 files changed
+81
-38
No files matched your search
@@ -97,7 +97,7 @@ public class Main extends JavaPlugin {
|
||||
new RaidCommands(this);
|
||||
getCommand("war").setTabCompleter(new WarTabCompletion());
|
||||
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 CommandsListener(), (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 {
|
||||
|
||||
//Ticks between activity, this is lower than siege because more activity is occuring in a raid
|
||||
private static final int incremental = 40;
|
||||
private War war;
|
||||
private final String name;
|
||||
@@ -88,7 +89,14 @@ public class Raid {
|
||||
public ArrayList<String> defenderPlayers;
|
||||
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,
|
||||
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) {
|
||||
this(war, raidedTown, gatherTown, side1AreRaiders, raidTicks);
|
||||
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,
|
||||
final boolean side1AreRaiders) {
|
||||
this.bukkitId = new int[1];
|
||||
@@ -125,6 +150,9 @@ public class Raid {
|
||||
this.lootedChunks = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run when raid starts
|
||||
*/
|
||||
public void start() {
|
||||
|
||||
//start
|
||||
@@ -459,7 +487,9 @@ public class Raid {
|
||||
}, 0L, incremental);
|
||||
}
|
||||
|
||||
// End of raid
|
||||
/**
|
||||
* End of raid
|
||||
*/
|
||||
public void stop() {
|
||||
this.phase = RaidPhase.END;
|
||||
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 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) {
|
||||
|
||||
@@ -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) {
|
||||
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) {
|
||||
|
||||
@@ -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) {
|
||||
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) {
|
||||
//TODO finalize payout
|
||||
|
||||
@@ -724,6 +759,10 @@ public class Raid {
|
||||
stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Defenders win, payout, and finalize raid
|
||||
* @param raidScore
|
||||
*/
|
||||
public void defendersWin(int raidScore) {
|
||||
//TODO finalize payout
|
||||
/*
|
||||
@@ -768,12 +807,20 @@ public class Raid {
|
||||
stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Positively impact the raid score
|
||||
* @param points
|
||||
*/
|
||||
public void addPointsToRaidScore(final int points) {
|
||||
this.raidScore += points;
|
||||
//cap
|
||||
if (raidScore > 1000) this.raidScore = 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Negatively impact the raid score
|
||||
* @param points
|
||||
*/
|
||||
public void subtractPointsFromRaidScore(final int points) {
|
||||
this.raidScore -= points;
|
||||
//cap
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package me.ShermansWorld.AlathraWar.data;
|
||||
|
||||
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;
|
||||
@@ -36,12 +35,13 @@ public class RaidData {
|
||||
|
||||
/**
|
||||
* Gets a raid with a specific name
|
||||
*
|
||||
* @param name - Name to check
|
||||
* @return Raid or Null
|
||||
*/
|
||||
public static Raid getRaidOrNull(String name) {
|
||||
for (Raid raid : raids) {
|
||||
if(raid.getName().equals(name)) return raid;
|
||||
if (raid.getName().equals(name)) return raid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -69,13 +69,14 @@ public class RaidData {
|
||||
|
||||
/**
|
||||
* Creates a raid object from a provided HashMap
|
||||
*
|
||||
* @param fileData
|
||||
* @return Raid object
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Raid fromMap(War war, HashMap<String, Object> fileData) {
|
||||
|
||||
if (fileData.get("raidedTown") == null || fileData.get("gatherTown") == null || fileData.get("side1AreRaiders") == null) {
|
||||
if (fileData.get("raidedTown") == null || fileData.get("gatherTown") == null || fileData.get("side1AreRaiders") == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ public class RaidData {
|
||||
Raid raid = new Raid(war, raidedTown, gatherTown, attackBoolean);
|
||||
|
||||
//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
|
||||
raid.setRaidPhase(RaidPhase.getByName((String) fileData.get("raidPhase")));
|
||||
raid.setRaidTicks((Integer) fileData.get("raidTicks"));
|
||||
@@ -116,9 +117,9 @@ public class RaidData {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Saves the war into files.
|
||||
*
|
||||
* @param raid - War to be saved.
|
||||
*/
|
||||
public static void saveRaid(Raid raid) {
|
||||
@@ -141,6 +142,7 @@ public class RaidData {
|
||||
|
||||
/**
|
||||
* Turns a raid into a map
|
||||
*
|
||||
* @param raid - Raid
|
||||
* @return Map
|
||||
*/
|
||||
@@ -180,6 +182,7 @@ public class RaidData {
|
||||
|
||||
/**
|
||||
* Creates a map of raid maps
|
||||
*
|
||||
* @param war - War to map
|
||||
* @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
|
||||
* @Isaac this is for getting when the last raid was on a town
|
||||
*/
|
||||
public static long whenTownLastRaided(Town town) {
|
||||
if(town.hasMeta("lastRaided")) {
|
||||
if (town.hasMeta("lastRaided")) {
|
||||
CustomDataField field = town.getMetadata("lastRaided");
|
||||
if(field != null) {
|
||||
if (field != null) {
|
||||
if (field instanceof IntegerDataField) {
|
||||
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
|
||||
* (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) {
|
||||
long townTime = whenTownLastRaided(town);
|
||||
|
||||
//24 hours town cooldown
|
||||
if((System.currentTimeMillis() / 1000) - townTime <= 86400) {
|
||||
if ((System.currentTimeMillis() / 1000) - townTime <= 86400) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
//6 hour raid cooldown for war
|
||||
if((System.currentTimeMillis() / 1000) - war.getLastRaidTime() <= 21600) {
|
||||
if ((System.currentTimeMillis() / 1000) - war.getLastRaidTime() <= 21600) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,31 +4,24 @@ import me.ShermansWorld.AlathraWar.Helper;
|
||||
import me.ShermansWorld.AlathraWar.Raid;
|
||||
import me.ShermansWorld.AlathraWar.Siege;
|
||||
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.WarData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class CommandsListener implements Listener {
|
||||
|
||||
public class CommandsListener implements Listener
|
||||
{
|
||||
|
||||
final static String[] prefixes = new String[] {
|
||||
"", "towny", "essentials", "wild", "minecraft"
|
||||
final static String[] prefixes = new String[]{
|
||||
"", "towny", "essentials", "wild", "minecraft"
|
||||
};
|
||||
final static String[] blacklistedLong = new String[] {
|
||||
final static String[] blacklistedLong = new String[]{
|
||||
"n spawn", "nat spawn", "nation spawn",
|
||||
"t spawn", "town spawn"
|
||||
};
|
||||
final static String[] blacklistedShort = new String[] {
|
||||
final static String[] blacklistedShort = new String[]{
|
||||
"home", "homes", "warp", "warps",
|
||||
"wild", "rtp", "spawn", "wilderness", "wildtp",
|
||||
"tpa", "tpahere", "tpaccept", "tpacancel",
|
||||
@@ -38,7 +31,6 @@ public class CommandsListener implements Listener
|
||||
};
|
||||
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
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
|
||||
*/
|
||||
for(War war : WarData.getWars()) {
|
||||
for(Raid raid : war.getRaids()) {
|
||||
for (War war : WarData.getWars()) {
|
||||
for (Raid raid : war.getRaids()) {
|
||||
//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) {
|
||||
//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("towny:n spawn") || parse.equals("towny:nat spawn") || parse.equals("towny:nation 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;
|
||||
}
|
||||
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
|
||||
@@ -107,7 +102,7 @@ public class CommandsListener implements Listener
|
||||
/*
|
||||
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
|
||||
if (siege.getSiegeTicks() > 0) {
|
||||
//only do for active raiders and any defenders
|
||||
|
||||
Reference in new issue
Block a user