diff --git a/Plugins/.idea/dataSources.xml b/Plugins/.idea/dataSources.xml index 16b134887..bcd6c7f0b 100644 --- a/Plugins/.idea/dataSources.xml +++ b/Plugins/.idea/dataSources.xml @@ -1,11 +1,11 @@ - + mysql true com.mysql.jdbc.Driver - jdbc:mysql://db.mineplex.com:3306 + jdbc:mysql://db.mineplex.com:3306/Account diff --git a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java index 92d7e4afb..e5723e652 100644 --- a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java @@ -47,8 +47,9 @@ public class ClanRepository extends RepositoryBase private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverId = ?;"; private static String RETRIEVE_CLAN_MEMBERS = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE lower(c.name) = ?;"; private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT c.name, cOther.name, ca.trusted FROM clanAlliances AS ca INNER JOIN clans AS c ON c.id = ca.clanId INNER JOIN clans as cOther ON cOther.id = ca.otherClanId WHERE c.serverId = ?;"; - private static String RETRIEVE_CLAN_ENEMY_INFO = "SELECT c.name, cOther.name, clanScore, otherClanScore, clanKills, otherClanKills, timeFormed FROM clanEnemies AS ce INNER JOIN clans AS c ON c.id = ce.clanId INNER JOIN clans as cOther ON cOther.id = ce.otherClanId WHERE c.serverId = ?;"; - +// private static String RETRIEVE_CLAN_ENEMY_INFO = "SELECT c.name, cOther.name, clanScore, otherClanScore, clanKills, otherClanKills, timeFormed FROM clanEnemies AS ce INNER JOIN clans AS c ON c.id = ce.clanId INNER JOIN clans as cOther ON cOther.id = ce.otherClanId WHERE c.serverId = ?;"; + private static String RETRIEVE_CLAN_WAR_INFO = "SELECT c.name, cOther.name, cw.score, cw.created, cw.ended, cw.lastUpdated FROM clanWar AS cw INNER JOIN clans AS c on c.id = cw.initiatorId INNER JOIN clans as cOther ON cOther.id = cw.clanId WHERE c.serverId = ? AND completed = FALSE"; + private static String DELETE_CLAN_MEMBER = "DELETE aC FROM accountClan AS aC INNER JOIN accounts ON accounts.id = aC.accountId WHERE aC.clanId = ? AND accounts.name = ?;"; private static String DELETE_CLAN_MEMBERS = "DELETE FROM accountClan WHERE clanId = ?;"; private static String DELETE_CLAN_TERRITORY = "DELETE FROM clanTerritory WHERE clanId = ? AND chunk = ?;"; @@ -56,20 +57,21 @@ public class ClanRepository extends RepositoryBase private static String DELETE_CLAN_TERRITORIES = "DELETE FROM clanTerritory WHERE clanId = ?;"; // private static String DELETE_CLAN_ALLIANCE = "DELETE FROM clanAlliances WHERE clanId = ? AND otherClanId = ?;"; private static String DELETE_CLAN_ALLIANCES = "DELETE FROM clanAlliances WHERE clanId = ? OR otherClanId = ?;"; - private static String DELETE_CLAN_ENEMIES = "DELETE FROM clanEnemies WHERE clanId = ? OR otherClanId = ?;"; +// private static String DELETE_CLAN_ENEMIES = "DELETE FROM clanEnemies WHERE clanId = ? OR otherClanId = ?;"; private static String DELETE_CLAN = "DELETE FROM clans WHERE id = ?;"; + private static String DELETE_ALL_WAR = "DELETE FROM clanWar WHERE initiatorId = ? OR clanId = ?"; private static String ADD_CLAN = "INSERT INTO clans (serverId, name, description, home, admin, dateCreated, energy, lastOnline) VALUES (?, ?, ?, ?, ?, now(), ?, now());"; private static String ADD_CLAN_MEMBER = "INSERT INTO accountClan (accountId, clanId, clanRole) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.name = ?;"; private static String ADD_CLAN_ALLIANCE = "INSERT INTO clanAlliances (clanId, otherClanId, trusted) VALUES (?, ?, ?);"; - private static String ADD_CLAN_ENEMY = "INSERT INTO clanEnemies (clanId, otherClanId, initiator, timeFormed) VALUES (?, ?, 1, now());"; + private static String ADD_CLAN_WAR = "INSERT INTO clanWar (initiatorId, clanId, score) VALUES (?, ?, ?)"; private static String ADD_CLAN_TERRITORY = "INSERT INTO clanTerritory (clanId, chunk, safe) VALUES (?, ?, ?);"; private static String UPDATE_CLAN = "UPDATE clans SET name = ?, description = ?, home = ?, admin = ?, energy = ?, kills = ?, murder = ?, deaths = ?, warWins = ?, warLosses = ?, lastOnline = ? WHERE id = ?;"; private static String UPDATE_CLAN_MEMBER = "UPDATE accountClan AS AC INNER JOIN accounts ON accounts.id = AC.accountId SET AC.clanRole = ? WHERE AC.clanId = ? AND accounts.name = ?;"; private static String UPDATE_CLAN_ALLIANCE = "UPDATE clanAlliances SET trusted = ? WHERE clanId = ? AND otherClanId = ?;"; - private static String UPDATE_CLAN_ENEMY = "UPDATE clanEnemies SET clanScore = ?, otherClanScore = ?, clanKills = ?, otherClanKills = ? WHERE clanId = ? AND otherClanId = ?;"; private static String UPDATE_CLAN_TERRITORY = "UPDATE clanTerritory SET safe = ? WHERE chunk = ?;"; // + private static String UPDATE_CLAN_WAR = "UPDATE clanWar SET score = ?, completed = ?, ended = ?, lastUpdated = NOW() WHERE initiatorId = ? AND clanId = ?"; private static String UPDATE_CLAN_SERVER_ID = "UPDATE clans SET serverId = ?, home = '', generator = '' WHERE id = ?;"; private static String UPDATE_CLAN_GENERATOR = "UPDATE clans SET generator = ?, generatorStock = ? WHERE id = ?;"; @@ -161,7 +163,7 @@ public class ClanRepository extends RepositoryBase ColumnInt serverIdCol = new ColumnInt("serverId", serverId); executeUpdate(DELETE_CLAN_ALLIANCES, clanIdCol, clanIdCol); - executeUpdate(DELETE_CLAN_ENEMIES, clanIdCol, clanIdCol); + deleteAllWar(clanId); executeUpdate(DELETE_CLAN_TERRITORIES, clanIdCol); executeUpdate(UPDATE_CLAN_SERVER_ID, serverIdCol, clanIdCol); } @@ -356,44 +358,6 @@ public class ClanRepository extends RepositoryBase }, new ColumnInt("serverId", _serverId)); System.out.println("3"); - - executeQuery(RETRIEVE_CLAN_ENEMY_INFO, new ResultSetCallable() - { - @Override - public void processResultSet(ResultSet resultSet) throws SQLException - { - while (resultSet.next()) - { - ClanEnemyToken clanToken = new ClanEnemyToken(); - ClanEnemyToken otherClanToken = new ClanEnemyToken(); - - //c.name, cOther.name, clanScore, otherClanScore, clanKills, otherClanKills - String clanName = resultSet.getString(1); - String otherClanName = resultSet.getString(2); - int clanScore = resultSet.getInt(3); - int otherClanScore = resultSet.getInt(4); - int clanKills = resultSet.getInt(5); - int otherClanKills = resultSet.getInt(6); - Timestamp timeFormed = resultSet.getTimestamp(7); - - clanToken.EnemyName = otherClanName; - clanToken.Score = clanScore; - clanToken.Kills = clanKills; - clanToken.Initiator = true; - clanToken.TimeFormed = timeFormed; - - otherClanToken.EnemyName = clanName; - otherClanToken.Score = otherClanScore; - otherClanToken.Kills = otherClanKills; - otherClanToken.Initiator = false; - otherClanToken.TimeFormed = timeFormed; - - clans.get(clanName).EnemyToken = clanToken; - clans.get(otherClanName).EnemyToken = otherClanToken; - } - } - - }, new ColumnInt("serverId", _serverId)); System.out.println("Finished loading clans from database..."); return clans.values(); @@ -521,11 +485,27 @@ public class ClanRepository extends RepositoryBase return affectedRows == size; } - public void addEnemy(int clanId, int otherClanId) + public void addWar(int initiatorId, int clanId, int score) { - executeUpdate(ADD_CLAN_ENEMY, new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId)); + executeUpdate(ADD_CLAN_WAR, new ColumnInt("initiatorId", initiatorId), new ColumnInt("clanId", clanId), new ColumnInt("score", score)); } + public void updateWar(int initiatorId, int clanId, int score, boolean completed, Timestamp ended) + { + executeUpdate(UPDATE_CLAN_WAR, new ColumnInt("score", score), new ColumnBoolean("completed", completed), new ColumnTimestamp("ended", ended), + new ColumnInt("initiatorId", initiatorId), new ColumnInt("clanId", clanId)); + } + + public void deleteAllWar(int clanId) + { + executeUpdate(DELETE_ALL_WAR, new ColumnInt("initiatorId", clanId), new ColumnInt("clanId", clanId)); + } + +// public void addEnemy(int clanId, int otherClanId) +// { +// executeUpdate(ADD_CLAN_ENEMY, new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId)); +// } + public void removeTerritoryClaim(int clanId, String chunk) { executeUpdate(DELETE_CLAN_TERRITORY, new ColumnInt("clanId", clanId), new ColumnVarChar("chunk", 100, chunk)); @@ -543,12 +523,12 @@ public class ClanRepository extends RepositoryBase new ColumnInt("warWins", warWins), new ColumnInt("warLosses", warLosses), new ColumnTimestamp("lastOnline", lastOnline), new ColumnInt("clanId", clanId)); } - public void updateEnemy(int clanId, int otherClanId, int clanScore, int otherClanScore, int clanKills, int otherClanKills) - { - executeUpdate(UPDATE_CLAN_ENEMY, new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId), - new ColumnInt("clanScore", clanScore), new ColumnInt("otherClanScore", otherClanScore), new ColumnInt("clanKills", clanKills), - new ColumnInt("otherClanKills", otherClanKills), new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId)); - } +// public void updateEnemy(int clanId, int otherClanId, int clanScore, int otherClanScore, int clanKills, int otherClanKills) +// { +// executeUpdate(UPDATE_CLAN_ENEMY, new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId), +// new ColumnInt("clanScore", clanScore), new ColumnInt("otherClanScore", otherClanScore), new ColumnInt("clanKills", clanKills), +// new ColumnInt("otherClanKills", otherClanKills), new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId)); +// } public boolean updateClanGenerator(int clanId, String generator, int generatorStock) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java index 63ab09785..1d8ff946e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java @@ -2,6 +2,7 @@ package mineplex.game.clans.clans; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -17,11 +18,11 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilWorld; import mineplex.game.clans.clans.ClansUtility.ClanRelation; +import mineplex.game.clans.clans.war.ClanWar; import mineplex.game.clans.core.repository.tokens.ClanAllianceToken; import mineplex.game.clans.core.repository.tokens.ClanEnemyToken; import mineplex.game.clans.core.repository.tokens.ClanMemberToken; @@ -58,6 +59,13 @@ public class ClanInfo private HashSet _claimSet = new HashSet(); private EnemyData _enemyData; + /** + * When a war is formed, a clan can either be the initiator, or be initiated on. We seperate these + * two categories into separate maps, as they are treated slightly different. + */ + private HashMap _initiatedWars = new HashMap(); + private HashMap _initiatedOnWars = new HashMap(); + // Temporary private NautHashMap _inviteeMap = new NautHashMap(); private NautHashMap _inviterMap = new NautHashMap(); @@ -308,7 +316,7 @@ public class ClanInfo EnemyData otherEnemyData = Clans.getClanUtility().getClanByClanName(enemyName).getEnemyData(); stringList.add(F.value("Enemy", _enemyData.getEnemyName())); stringList.add(F.value("Formed", _enemyData.getRelativeTimeFormed())); - stringList.add(F.value("War Score", _enemyData.getScore() + " : " + otherEnemyData.getScore())); + stringList.add(F.value("ClanWar Score", _enemyData.getScore() + " : " + otherEnemyData.getScore())); } return stringList; @@ -552,6 +560,47 @@ public class ClanInfo { return hasEnemy() && clanName != null && clanName.equals(_enemyData.getEnemyName()); } + + public ClanWar getInitiatedWar(ClanInfo againstClan) + { + return getInitiatedWar(againstClan.getName()); + } + + public ClanWar getInitiatedOnWar(ClanInfo againstClan) + { + return getInitiatedOnWar(againstClan.getName()); + } + + public ClanWar getWar(ClanInfo againstClan) + { + return getWar(againstClan.getName()); + } + + public ClanWar getInitiatedWar(String againstClan) + { + return _initiatedWars.get(againstClan); + } + + public ClanWar getInitiatedOnWar(String againstClan) + { + return _initiatedOnWars.get(againstClan); + } + + public ClanWar getWar(String againstClan) + { + ClanWar initiated = getInitiatedWar(againstClan); + return initiated == null ? getInitiatedOnWar(againstClan) : initiated; + } + + public boolean isAtWar(ClanInfo clanInfo) + { + return isAtWar(clanInfo.getName()); + } + + public boolean isAtWar(String clanName) + { + return _initiatedWars.containsKey(clanName) || _initiatedOnWars.containsKey(clanName); + } public void adjustEnergy(int energy) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java index 45f9190a3..903d4e441 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDataAccessLayer.java @@ -327,6 +327,7 @@ public class ClansDataAccessLayer _manager.log("Added Ally for [" + cB.getName() + "] and [" + cA.getName() + "] by [" + player + "]."); } + /* public void enemy(final ClanInfo clan, final ClanInfo otherClan, String player) { runAsync(new Runnable() @@ -360,6 +361,7 @@ public class ClansDataAccessLayer _manager.log("Added Enemy for [" + clan.getName() + "] and [" + otherClan.getName() + "] by [" + player + "]."); } + */ public boolean trust(final ClanInfo ownerClan, final ClanInfo otherClan, String player) { @@ -610,6 +612,7 @@ public class ClansDataAccessLayer }); } + /* public void updateEnemy(ClanInfo clan, ClanInfo otherClan) { assert clan.getEnemyData() != null && otherClan.getEnemyData() != null; @@ -624,6 +627,7 @@ public class ClansDataAccessLayer //Log _manager.log("Updated Enemy Data for [" + clan.getName() + ", " + otherClan.getName() + "]"); } + */ public void updateGenerator(final ClanInfo clanInfo, final Callback callback) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java index 972b22961..9847b2827 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java @@ -39,14 +39,8 @@ import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansUtility.ClanRelation; -import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; -import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.damage.CustomDamageEvent; public class ClansGame extends MiniPlugin @@ -60,18 +54,6 @@ public class ClansGame extends MiniPlugin Clans = clans; } - @EventHandler - public void deductEnergy(UpdateEvent event) - { - if (event.getType() != UpdateType.SEC) - return; - - for (ClanInfo clan : Clans.getClanMap().values()) - { - - } - } - @EventHandler(ignoreCancelled = true) public void openClanShop(PlayerInteractEvent event) { @@ -194,7 +176,7 @@ public class ClansGame extends MiniPlugin else mimic = ""; } - + //Borderlands if (Clans.getClanUtility().isBorderlands(event.getBlock().getLocation()) && event.getPlayer().getGameMode() != GameMode.CREATIVE) { @@ -249,6 +231,12 @@ public class ClansGame extends MiniPlugin return; } + if (Clans.getWarManager().allowFromInvade(event.getBlock().getLocation(), event.getPlayer())) + { + // Allow because of invasion + return; + } + //Disallow event.setCancelled(true); @@ -302,6 +290,12 @@ public class ClansGame extends MiniPlugin //Block Interaction Location loc = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation(); if (UtilBlock.usable(event.getClickedBlock())) loc = event.getClickedBlock().getLocation(); + + if (Clans.getWarManager().allowFromInvade(loc, event.getPlayer())) + { + // Allow because of invasion + return; + } //Borderlands if ( player.getGameMode() != GameMode.CREATIVE && @@ -547,6 +541,12 @@ public class ClansGame extends MiniPlugin ClanInfo clan = Clans.getClanUtility().getOwner(event.getEntity().getLocation()); if (clan == null) return; + if (Clans.getWarManager().isBeingInvaded(clan)) + { + // Allow because of invasion + return; + } + if (!clan.isOnline()) event.setCancelled(true); else diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index df289de04..c8b64cba3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -6,8 +6,6 @@ import java.util.TimeZone; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_7_R4.util.CraftMagicNumbers; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -16,6 +14,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemBreakEvent; @@ -39,14 +38,12 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilWorld; import mineplex.core.creature.Creature; import mineplex.core.creature.event.CreatureSpawnCustomEvent; import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; import mineplex.core.energy.Energy; import mineplex.core.explosion.Explosion; -import mineplex.core.gui.SimpleGuiItem; import mineplex.core.movement.Movement; import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; @@ -61,7 +58,8 @@ import mineplex.game.clans.clans.commands.ClansCommand; import mineplex.game.clans.clans.commands.ClansLoginManager; import mineplex.game.clans.clans.commands.MapCommand; import mineplex.game.clans.clans.commands.RegionsCommand; -import mineplex.game.clans.clans.commands.ServerTimeCommand; +import mineplex.game.clans.clans.data.PlayerClan; +import mineplex.game.clans.clans.event.ClansPlayerDeathEvent; import mineplex.game.clans.clans.loot.LootManager; import mineplex.game.clans.clans.map.ItemMapManager; import mineplex.game.clans.clans.murder.MurderManager; @@ -101,11 +99,7 @@ import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.damage.DamageManager; import mineplex.minecraft.game.core.fire.Fire; import mineplex.minecraft.game.core.mechanics.Weapon; -import mineplex.serverdata.Region; import mineplex.serverdata.commands.ServerCommandManager; -import mineplex.serverdata.redis.RedisDataRepository; -import mineplex.serverdata.servers.ConnectionData; -import mineplex.serverdata.servers.ServerManager; public class ClansManager extends MiniClientPlugin implements IRelation { @@ -259,7 +253,6 @@ public class ClansManager extends MiniClientPlugin implements IRelat addCommand(new RegionsCommand(this)); addCommand(new ClansChatCommand(this)); addCommand(new ClansAllyChatCommand(this)); - addCommand(new ServerTimeCommand(this)); addCommand(new ClanManagementCommand(this)); addCommand(new MapCommand(this)); } @@ -778,6 +771,27 @@ public class ClansManager extends MiniClientPlugin implements IRelat Bukkit.broadcastMessage("name: " + item.getName() + " max dur: " + item.getMaxDurability()); } + @EventHandler(priority = EventPriority.HIGH) + public void handleClansDeath(PlayerDeathEvent event) + { + PlayerClan playerClan; + PlayerClan killerClan = null; + + Player player = event.getEntity(); + ClanInfo pClan = _clanMemberMap.get(player.getName()); + playerClan = new PlayerClan(player, pClan); + + if (player.getKiller() != null) + { + Player killer = player.getKiller(); + ClanInfo kClan = _clanMemberMap.get(killer.getName()); + killerClan = new PlayerClan(killer, kClan); + } + + ClansPlayerDeathEvent clansPlayerDeathEvent = new ClansPlayerDeathEvent(event, playerClan, killerClan); + Bukkit.getServer().getPluginManager().callEvent(clansPlayerDeathEvent); + } + @EventHandler(priority = EventPriority.HIGHEST) public void onJoin(PlayerLoginEvent event) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index 77abf86cf..95b1480ce 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -104,8 +104,10 @@ public class ClansCommand extends CommandBase else if (args[0].equalsIgnoreCase("sethome")) homeSet(caller); + /* else if (args[0].equalsIgnoreCase("enemy") || args[0].equals("e")) enemy(caller, args); + */ else if (args[0].equalsIgnoreCase("territory") || args[0].equalsIgnoreCase("t")) infoTerritory(caller, args); @@ -119,6 +121,7 @@ public class ClansCommand extends CommandBase infoClan(caller, args[0]); } + /* public void enemy(Player caller, String[] args) { if (args.length == 2) @@ -143,11 +146,14 @@ public class ClansCommand extends CommandBase infoEnemy(caller); } } + */ + /* private void attemptEnemy(Player caller, ClanInfo initiatorClan, ClanInfo otherClan) { Plugin.getWarManager().attemptEnemy(caller, initiatorClan, otherClan); } + */ private void infoEnemy(Player caller) { @@ -211,7 +217,7 @@ public class ClansCommand extends CommandBase UtilPlayer.message(caller, F.help("/c invite ", "Invite Player to Clan", Rank.ADMIN)); UtilPlayer.message(caller, F.help("/c kick ", "Kick Player from Clan", Rank.ADMIN)); UtilPlayer.message(caller, F.help("/c neutral ", "Request Neutrality with Clan", Rank.ADMIN)); - UtilPlayer.message(caller, F.help("/c enemy ", "Declare War with Clan", Rank.ADMIN)); + UtilPlayer.message(caller, F.help("/c enemy ", "Declare ClanWar with Clan", Rank.ADMIN)); UtilPlayer.message(caller, F.help("/c ally ", "Send Alliance to Clan", Rank.ADMIN)); UtilPlayer.message(caller, F.help("/c trust ", "Give Trust to Clan", Rank.ADMIN)); UtilPlayer.message(caller, F.help("/c claim", "Claim Territory", Rank.ADMIN)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ServerTimeCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ServerTimeCommand.java deleted file mode 100644 index 8f862c736..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ServerTimeCommand.java +++ /dev/null @@ -1,22 +0,0 @@ -package mineplex.game.clans.clans.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.Rank; -import mineplex.core.common.util.UtilPlayer; -import mineplex.game.clans.clans.ClansManager; - -public class ServerTimeCommand extends CommandBase -{ - public ServerTimeCommand(ClansManager plugin) - { - super(plugin, Rank.ALL, "servertime", "t"); - } - - @Override - public void Execute(Player caller, String[] args) - { - UtilPlayer.message(caller, Plugin.getWarManager().mServerTime()); - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/data/PlayerClan.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/data/PlayerClan.java new file mode 100644 index 000000000..f1e204206 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/data/PlayerClan.java @@ -0,0 +1,27 @@ +package mineplex.game.clans.clans.data; + +import org.bukkit.entity.Player; + +import mineplex.game.clans.clans.ClanInfo; + +public class PlayerClan +{ + private Player _player; + private ClanInfo _clan; + + public PlayerClan(Player player, ClanInfo clan) + { + _player = player; + _clan = clan; + } + + public Player getPlayer() + { + return _player; + } + + public ClanInfo getClan() + { + return _clan; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansPlayerDeathEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansPlayerDeathEvent.java new file mode 100644 index 000000000..a59064aca --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansPlayerDeathEvent.java @@ -0,0 +1,51 @@ +package mineplex.game.clans.clans.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.PlayerDeathEvent; + +import mineplex.game.clans.clans.data.PlayerClan; + +public class ClansPlayerDeathEvent extends Event +{ + private PlayerDeathEvent _event; + private PlayerClan _player; + private PlayerClan _killer; + + public ClansPlayerDeathEvent(PlayerDeathEvent event, PlayerClan player, PlayerClan killer) + { + _event = event; + _player = player; + _killer = killer; + } + + public PlayerDeathEvent getEvent() + { + return _event; + } + + public PlayerClan getPlayer() + { + return _player; + } + + public PlayerClan getKiller() + { + return _killer; + } + + public void setPlayer(PlayerClan player) + { + _player = player; + } + + public void setKiller(PlayerClan killer) + { + _killer = killer; + } + + // Bukkit event stuff + private static final HandlerList handlers = new HandlerList(); + public static HandlerList getHandlerList() { return handlers; } + public HandlerList getHandlers() { return handlers; } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansScoreboardManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansScoreboardManager.java index c6b9e4305..8e85faabc 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansScoreboardManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansScoreboardManager.java @@ -4,7 +4,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.MiniPlugin; import mineplex.core.TablistFix; import mineplex.core.account.CoreClientManager; import mineplex.core.donation.DonationManager; @@ -17,7 +16,6 @@ import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.scoreboard.elements.ScoreboardElementClan; import mineplex.game.clans.clans.scoreboard.elements.ScoreboardElementPlayer; -import mineplex.game.clans.clans.scoreboard.elements.ScoreboardElementWar; import mineplex.game.clans.clans.war.WarManager; import mineplex.game.clans.clans.worldevent.WorldEventManager; @@ -46,9 +44,6 @@ public class ClansScoreboardManager extends ScoreboardManager data.writeEmpty(); data.writeElement(new ScoreboardElementClan(_clansManager)); - data.writeEmpty(); - data.writeElement(new ScoreboardElementWar(_clansManager, _warManager)); - data.writeEmpty(); data.writeElement(new ScoreboardElementPlayer(_clansManager)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementWar.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementWar.java deleted file mode 100644 index 3306a1e98..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementWar.java +++ /dev/null @@ -1,82 +0,0 @@ -package mineplex.game.clans.clans.scoreboard.elements; - -import java.util.ArrayList; -import java.util.Date; - -import org.bukkit.entity.Player; - -import mineplex.core.common.util.C; -import mineplex.core.common.util.UtilTime; -import mineplex.core.scoreboard.ScoreboardManager; -import mineplex.core.scoreboard.elements.ScoreboardElement; -import mineplex.game.clans.clans.ClanInfo; -import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.EnemyData; -import mineplex.game.clans.clans.war.WarManager; -import mineplex.game.clans.clans.war.WarState; - -public class ScoreboardElementWar implements ScoreboardElement -{ - private ClansManager _clansManager; - private WarManager _warManager; - - public ScoreboardElementWar(ClansManager clansManager, WarManager warManager) - { - _clansManager = clansManager; - _warManager = warManager; - } - - - @Override - public ArrayList getLines(ScoreboardManager manager, Player player) - { - ArrayList output = new ArrayList(); - - ClanInfo clanInfo = _clansManager.getClan(player); - EnemyData enemyData = clanInfo == null ? null : clanInfo.getEnemyData(); - - if (_warManager.getWarState() == WarState.WAR) - { - if (clanInfo != null && enemyData != null) - { - ClanInfo enemy = _clansManager.getClan(enemyData.getEnemyName()); - output.add(C.cGreen + "Enemy: " + C.cWhite + enemyData.getEnemyName()); - output.add(C.cGreen + "Score: " + C.cWhite + enemyData.getScore() + " to " + enemy.getEnemyData().getScore()); - } - else - { - output.add(C.cGreen + "War in Progress"); - } - - Date invade = _warManager.getNextInvadeTime(); - String invadeString = UtilTime.convertString(invade.getTime() - System.currentTimeMillis(), 1, UtilTime.TimeUnit.FIT); - output.add(C.cGreen + "Raid: " + C.cWhite + invadeString); - - } - else if (_warManager.getWarState() == WarState.FORM_ENEMIES) - { - output.add(C.cGreen + "War: " + C.cWhite + "Form Enemies"); - - Date start = _warManager.getNextWarStart(); - String startString = UtilTime.convertString(start.getTime() - System.currentTimeMillis(), 1, UtilTime.TimeUnit.FIT); - output.add(C.cGreen + "War Start: " + C.cWhite + startString); - } - else if (_warManager.getWarState() == WarState.INVADE) - { - output.add(C.cGreen + "War: " + C.cWhite + "Raid in Progress"); - - if (clanInfo != null && enemyData != null) - { - ClanInfo enemy = _clansManager.getClan(enemyData.getEnemyName()); - output.add(C.cGreen + "Enemy: " + C.cWhite + enemyData.getEnemyName()); - output.add(C.cGreen + "Score: " + C.cWhite + enemyData.getScore() + " to " + enemy.getEnemyData().getScore()); - } - - Date end = _warManager.getNextEnemyTime(); - String startString = UtilTime.convertString(end.getTime() - System.currentTimeMillis(), 1, UtilTime.TimeUnit.FIT); - output.add(C.cGreen + "Finish: " + C.cWhite + startString); - } - - return output; - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/ClanWar.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/ClanWar.java new file mode 100644 index 000000000..e3c3eb906 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/ClanWar.java @@ -0,0 +1,110 @@ +package mineplex.game.clans.clans.war; + +import java.sql.Timestamp; + +import mineplex.game.clans.clans.ClanInfo; + +public class ClanWar +{ + private ClanInfo _clanA; + private ClanInfo _clanB; + private int _score; + private boolean _completed; + private Timestamp _created; + private Timestamp _ended; + private Timestamp _lastUpdated; + + public ClanWar(ClanInfo clanA, ClanInfo clanB, int score, boolean completed, Timestamp created, Timestamp ended, Timestamp lastUpdated) + { + _clanA = clanA; + _clanB = clanB; + _score = score; + _completed = completed; + _created = created; + _ended = ended; + _lastUpdated = lastUpdated; + } + + /** + * Get the clan that was the initiator for this war + */ + public ClanInfo getClanA() + { + return _clanA; + } + + /** + * Get the clan that was initiated on for this war + */ + public ClanInfo getClanB() + { + return _clanB; + } + + /** + * Get the score of the war. Score is represented as an int value with the initiator clan's score. The score + * works as a tug of war, score starts at 20 and either the initiator will get to 40 or 0 to trigger the end of war + */ + public int getScore() + { + return _score; + } + + /** + * Is the war finished (has a clan won already) + */ + public boolean isCompleted() + { + return _completed; + } + + public void setCompleted(boolean completed) + { + _completed = completed; + } + + public void setEnded(Timestamp ended) + { + _ended = ended; + } + + /** + * Timestamp the war was initiated at + */ + public Timestamp getCreated() + { + return _created; + } + + /** + * Timestamp that the war ended. Could be null if the war is still in progress (isCompleted() false) + */ + public Timestamp getEnded() + { + return _ended; + } + + /** + * Timestamp that the war was last updated at. Currently not used, could be used to prune old wars + * @return + */ + public Timestamp getLastUpdated() + { + return _lastUpdated; + } + + /** + * Utility method, adds a point for clanInfo + */ + public void increaseScoreFor(ClanInfo clanInfo) + { + if (_clanA.equals(clanInfo)) + { + _score++; + } + else if (_clanB.equals(clanInfo)) + { + _score--; + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarInvasion.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarInvasion.java new file mode 100644 index 000000000..fa5c91f99 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarInvasion.java @@ -0,0 +1,60 @@ +package mineplex.game.clans.clans.war; + +import mineplex.game.clans.clans.ClanInfo; + +public class WarInvasion +{ + private static final long INVADE_LENGTH = 60000L * 30; // 30 Minutes + + private ClanInfo _invadedClan; + private ClanInfo _invaderClan; + private long _startTime; + private long _endTime; + + public WarInvasion(ClanWar clanWar) + { + if (clanWar.getScore() > WarManager.WAR_START_SCORE) + { + // Initiator Won + _invaderClan = clanWar.getClanA(); + _invadedClan = clanWar.getClanB(); + } + else + { + // Initiated On Won + _invaderClan = clanWar.getClanB(); + _invadedClan = clanWar.getClanA(); + } + + _startTime = System.currentTimeMillis(); + _endTime = _startTime + INVADE_LENGTH; + } + + public WarInvasion(ClanInfo invadedClan, ClanInfo invaderClan) + { + _invadedClan = invadedClan; + _invaderClan = invaderClan; + _startTime = System.currentTimeMillis(); + _endTime = _startTime + INVADE_LENGTH; + } + + public ClanInfo getInvadedClan() + { + return _invadedClan; + } + + public ClanInfo getInvaderClan() + { + return _invaderClan; + } + + public long getStartTime() + { + return _startTime; + } + + public long getEndTime() + { + return _endTime; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java index df6c0d402..1fd532d91 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java @@ -1,338 +1,175 @@ package mineplex.game.clans.clans.war; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; +import java.sql.Timestamp; +import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedList; +import java.util.List; +import java.util.Map; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.EnemyData; +import mineplex.game.clans.clans.event.ClansPlayerDeathEvent; +import mineplex.game.clans.clans.war.event.WarEndEvent; +import mineplex.game.clans.clans.war.event.WarInvasionEndEvent; +import mineplex.game.clans.clans.war.event.WarInvasionStartEvent; public class WarManager extends MiniPlugin { - private static final int INVADE_ENEMY_DATE = Calendar.SATURDAY; - private static final int CREATE_ENEMY_DATE = Calendar.SUNDAY; + public static final int WAR_START_SCORE = 20; private final ClansManager _clansManager; - private WarState _warState; + /** + * Map of the active war invasions. This is indexed by the clan that is being invaded on + * We will need to access this when blocks are broken in the invaded on clan's land! + */ + private HashMap> _activeInvasions; public WarManager(JavaPlugin plugin, ClansManager clansManager) { - super("War Manager", plugin); + super("ClanWar Manager", plugin); _clansManager = clansManager; - _warState = calculateWarState(); + _activeInvasions = new HashMap>(); } - @EventHandler - public void update(UpdateEvent event) + public ClansManager getClansManager() { - if (event.getType() != UpdateType.SLOWEST) - return; - - WarState currentState = calculateWarState(); - - if (currentState != _warState) - { - WarStateChangeEvent warEvent = new WarStateChangeEvent(_warState, currentState); - UtilServer.getServer().getPluginManager().callEvent(warEvent); - _warState = currentState; - } + return _clansManager; } - private WarState calculateWarState() + public List getWarInvasions(ClanInfo invadedOn) { - // Get a calendar snapshot of the current time using server timezone - Calendar calendar = getCurrentDate(); - - WarState warState = WarState.WAR; - - if (isEnemyTime(calendar)) - warState = WarState.FORM_ENEMIES; - else if (isInvadeTime(calendar)) - warState = WarState.INVADE; - - return warState; - } - - private Calendar getCurrentDate() - { - Calendar date = Calendar.getInstance(_clansManager.getServerTimeZone()); - return date; + return _activeInvasions.get(invadedOn.getName()); } - public void attemptEnemy(Player player, ClanInfo initiatingClan, ClanInfo otherClan) + private void addInvasion(WarInvasion invasion) { - attemptEnemy(player, initiatingClan, otherClan, true); - } - - public void attemptEnemy(Player player, ClanInfo initiatingClan, ClanInfo otherClan, boolean notify) - { - String notifyMessage = null; - - if (_warState != WarState.FORM_ENEMIES) + ClanInfo invaded = invasion.getInvadedClan(); + if (_activeInvasions.containsKey(invaded)) { - notifyMessage = "Enemies cannot be formed at this time. Please see mineplex.com/clans for info"; - } - else if (initiatingClan.getEnemyData() != null) - { - notifyMessage = "Your clan already has an enemy."; - } - else if (otherClan.getEnemyData() != null) - { - notifyMessage = "The clan " + F.elem(otherClan.getName()) + " already has an enemy."; - } - else if (initiatingClan.getSize() > (otherClan.getSize() * 2)) // Initiators have more than double the members of other clan - { - notifyMessage = "The clan " + F.elem(otherClan.getName()) + " has less than half your members!"; + _activeInvasions.get(invaded.getName()).add(invasion); } else { - _clansManager.getClanDataAccess().enemy(initiatingClan, otherClan, player.getName()); - _clansManager.messageClan(initiatingClan, F.main("Clans", "Your clan is now enemies with " + F.elem(otherClan.getName()))); - _clansManager.messageClan(otherClan, F.main("Clans", "Your clan is now enemies with " + F.elem(initiatingClan.getName()))); - } - - if (notify && notifyMessage != null) - { - UtilPlayer.message(player, F.main("Clans", notifyMessage)); + LinkedList invasions = new LinkedList(); + invasions.add(invasion); + _activeInvasions.put(invaded.getName(), invasions); } } - @EventHandler - public void handleDeath(PlayerDeathEvent event) + private void checkWarComplete(ClanWar clanWar) { - Player player = event.getEntity(); - Player killer = player.getKiller(); - if (killer == null) return; // Wasn't killed by player + boolean completed = false; + if (clanWar.getScore() >= WAR_START_SCORE * 2) + { + // Initiator Won + completed = true; + } + else if (clanWar.getScore() <= 0) + { + // Initiated On Won + completed = true; + } + + if (completed) + { + clanWar.setCompleted(true); + clanWar.setEnded(new Timestamp(System.currentTimeMillis())); + + WarInvasion invasion = new WarInvasion(clanWar); + addInvasion(invasion); + + WarEndEvent warEndEvent = new WarEndEvent(clanWar); + WarInvasionStartEvent invasionStartEvent = new WarInvasionStartEvent(invasion); + Bukkit.getServer().getPluginManager().callEvent(warEndEvent); + Bukkit.getServer().getPluginManager().callEvent(invasionStartEvent); + } + } + + public boolean isBeingInvaded(ClanInfo clanInfo) + { + List invasions = _activeInvasions.get(clanInfo.getName()); + return invasions != null && !invasions.isEmpty(); + } + + public boolean allowFromInvade(Location location, Player player) + { + ClanInfo clanInfo = _clansManager.getClanUtility().getOwner(location); ClanInfo playerClan = _clansManager.getClan(player); - ClanInfo killerClan = _clansManager.getClan(killer); - - if (playerClan != null && killerClan != null) + if (clanInfo != null) { - if (playerClan.getEnemyData() != null && playerClan.getEnemyData().getEnemyName().equalsIgnoreCase(killerClan.getName())) + List invasions = _activeInvasions.get(clanInfo.getName()); + if (invasions != null) { - // Only adjust score if we are in WAR or FORM ENEMIES state. Once invasion begins score should never change - // Adjust kill stats no matter what war state we are in (so we track kills during invasion) - - if (_warState == WarState.WAR || _warState == WarState.FORM_ENEMIES) + for (WarInvasion invasion : invasions) { - playerClan.getEnemyData().addScore(-1); - killerClan.getEnemyData().addScore(1); + if (invasion.getInvaderClan().equals(playerClan)) + return true; } - - killerClan.getEnemyData().addKill(); } } - } - - - /** - * Check if a specific Calendar is currently in enemy time - * If this returns true, isInvadeTime should always return false for the same Calendar - * - * @param c {@link java.util.Calendar} instance that should be checked - */ - private boolean isEnemyTime(Calendar c) - { - int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); - - if (dayOfWeek == CREATE_ENEMY_DATE) - { - return true; - } - return false; } - /** - * Check if a specific Calendar is currently in invade time - * If this returns true, isEnemyTime should always return false for the same Calendar - * - * @param c {@link java.util.Calendar} instance that should be checked - */ - private boolean isInvadeTime(Calendar c) - { - int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); - - if (dayOfWeek == INVADE_ENEMY_DATE) - { - return true; - } - return false; - } - - /** - * Get the starting time of when enemies can be formed next - * @return The enemy start time in the form of {@link java.util.Date} - */ - public Date getNextEnemyTime() - { - Calendar c = getCurrentDate(); - int currDayOfWeek = c.get(Calendar.DAY_OF_WEEK); - - c.set(Calendar.DAY_OF_WEEK, CREATE_ENEMY_DATE); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - - if (currDayOfWeek >= CREATE_ENEMY_DATE) - c.add(Calendar.DATE, 7); - - return c.getTime(); - } - - /** - * Get the starting time of the next enemy invasion - * @return The invasion start time in the form of {@link java.util.Date} - */ - public Date getNextInvadeTime() - { - Calendar c = getCurrentDate(); - int currDayOfWeek = c.get(Calendar.DAY_OF_WEEK); - - c.set(Calendar.DAY_OF_WEEK, INVADE_ENEMY_DATE); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - - if (currDayOfWeek >= INVADE_ENEMY_DATE) - c.add(Calendar.DATE, 7); - - return c.getTime(); - } - - public Date getNextWarStart() - { - Calendar c = getCurrentDate(); - int currDayOfWeek = c.get(Calendar.DAY_OF_WEEK); - - c.set(Calendar.DAY_OF_WEEK, INVADE_ENEMY_DATE); - c.set(Calendar.HOUR_OF_DAY, 0); - c.set(Calendar.MINUTE, 0); - c.set(Calendar.SECOND, 0); - - if (currDayOfWeek >= INVADE_ENEMY_DATE) - c.add(Calendar.DATE, 7); - - c.add(Calendar.DATE, 1); - - return c.getTime(); - } - - /** - * Get the current War State of the server - * War state determines what events are going on - * with respect to the current war. - */ - public WarState getWarState() - { - return _warState; - } - @EventHandler - public void stateChange(WarStateChangeEvent event) + public void handleDeath(ClansPlayerDeathEvent event) { - WarState state = event.getNewState(); - Bukkit.broadcastMessage(F.main("Clans", "War state changed: " + F.elem(state.getDescription()))); - } - - @EventHandler - private void updateClanWins(WarStateChangeEvent event) - { - for (ClanInfo clan : _clansManager.getClanMap().values()) + if (event.getPlayer() != null && event.getPlayer().getClan() != null) { - WarOutcome outcome = getWarOutcome(clan); - - switch (outcome) + if (event.getKiller() != null && event.getKiller().getClan() != null) { - case WIN: - clan.addWarWins(1); - break; - case LOSE: - clan.addWarLosses(1); - default: + ClanInfo clan = event.getPlayer().getClan(); + ClanInfo killerClan = event.getKiller().getClan(); + + ClanWar war = clan.getWar(killerClan); + if (war != null && !war.isCompleted()) + { + war.increaseScoreFor(killerClan); + checkWarComplete(war); + } } } } - public WarOutcome getWarOutcome(ClanInfo clanInfo) + @EventHandler + public void clearInvasions(UpdateEvent event) { - WarOutcome outcome = WarOutcome.NOT_IN_WAR; + if (event.getType() != UpdateType.SEC) + return; - EnemyData enemyData = clanInfo.getEnemyData(); + long currentTime = System.currentTimeMillis(); - if (enemyData != null) + Iterator>> iterator = _activeInvasions.entrySet().iterator(); + while (iterator.hasNext()) { - ClanInfo enemyClan = _clansManager.getClan(enemyData.getEnemyName()); - if (enemyClan != null) + List invasions = iterator.next().getValue(); + Iterator invasionIterator = invasions.iterator(); + while (invasionIterator.hasNext()) { - if (enemyData.getScore() > enemyClan.getEnemyData().getScore()) + WarInvasion invasion = invasionIterator.next(); + if (invasion.getEndTime() > currentTime) { - outcome = WarOutcome.WIN; - } - else if (enemyData.getScore() < enemyClan.getEnemyData().getScore()) - { - outcome = WarOutcome.LOSE; - } - else - { - outcome = WarOutcome.TIE; + WarInvasionEndEvent endEvent = new WarInvasionEndEvent(invasion); + Bukkit.getServer().getPluginManager().callEvent(endEvent); + + invasionIterator.remove(); } } + + if (invasions.isEmpty()) + iterator.remove(); } - - return outcome; - } - - /** - * Send the current server time information to the player - */ - public LinkedList mServerTime() - { - LinkedList messageList = new LinkedList(); - - messageList.add(F.main("Clans", "Server Time")); - Date currDate = new Date(); - SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy"); - dateFormat.setTimeZone(_clansManager.getServerTimeZone()); - - messageList.add(F.value("Server Time", dateFormat.format(currDate))); - - messageList.add(F.value("Status", _warState.getDescription())); - - if (_warState != WarState.INVADE) - { - long next = getNextInvadeTime().getTime(); - long currTime = System.currentTimeMillis(); - - messageList.add(F.value("Invasion", UtilTime.convertString(next - currTime, 1, UtilTime.TimeUnit.FIT))); - } - - if (_warState != WarState.FORM_ENEMIES) - { - long next = getNextEnemyTime().getTime(); - long currTime = System.currentTimeMillis(); - - messageList.add(F.value("Enemy Reset", UtilTime.convertString(next - currTime, 1, UtilTime.TimeUnit.FIT))); - } - - return messageList; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarOutcome.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarOutcome.java deleted file mode 100644 index 2a0252ecb..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarOutcome.java +++ /dev/null @@ -1,21 +0,0 @@ -package mineplex.game.clans.clans.war; - -public enum WarOutcome -{ - WIN("Win"), - LOSE("Lose"), - TIE("Tie"), - NOT_IN_WAR("Not in War"); - - private String _friendlyName; - - WarOutcome(String friendlyName) - { - _friendlyName = friendlyName; - } - - public String getFriendlyName() - { - return _friendlyName; - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarState.java deleted file mode 100644 index e8bac93ea..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarState.java +++ /dev/null @@ -1,20 +0,0 @@ -package mineplex.game.clans.clans.war; - -public enum WarState -{ - FORM_ENEMIES("Enemies can now be formed"), - WAR("War is in progress"), - INVADE("Winning teams can invade enemies"); - - private String _description; - - WarState(String description) - { - _description = description; - } - - public String getDescription() - { - return _description; - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarStateChangeEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarStateChangeEvent.java deleted file mode 100644 index b525f63c5..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarStateChangeEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -package mineplex.game.clans.clans.war; - -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class WarStateChangeEvent extends Event -{ - private static final HandlerList handlers = new HandlerList(); - - private WarState _oldState; - private WarState _newState; - - public WarStateChangeEvent(WarState oldState, WarState newState) - { - _oldState = oldState; - _newState = newState; - } - - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } - - public WarState getOldState() - { - return _oldState; - } - - public WarState getNewState() - { - return _newState; - } - -} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarEndEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarEndEvent.java new file mode 100644 index 000000000..62fd6e095 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarEndEvent.java @@ -0,0 +1,26 @@ +package mineplex.game.clans.clans.war.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.game.clans.clans.war.ClanWar; + +public class WarEndEvent extends Event +{ + private ClanWar _war; + + public WarEndEvent(ClanWar war) + { + _war = war; + } + + public ClanWar getWar() + { + return _war; + } + + // Bukkit event stuff + private static final HandlerList handlers = new HandlerList(); + public static HandlerList getHandlerList() { return handlers; } + public HandlerList getHandlers() { return handlers; } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarInvasionEndEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarInvasionEndEvent.java new file mode 100644 index 000000000..048ed8dd1 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarInvasionEndEvent.java @@ -0,0 +1,29 @@ +package mineplex.game.clans.clans.war.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.game.clans.clans.war.WarInvasion; + +/** + * Called when a war invasion is ended + */ +public class WarInvasionEndEvent extends Event +{ + private WarInvasion _warInvasion; + + public WarInvasionEndEvent(WarInvasion warInvasion) + { + _warInvasion = warInvasion; + } + + public WarInvasion getWarInvasion() + { + return _warInvasion; + } + + // Bukkit event stuff + private static final HandlerList handlers = new HandlerList(); + public static HandlerList getHandlerList() { return handlers; } + public HandlerList getHandlers() { return handlers; } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarInvasionStartEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarInvasionStartEvent.java new file mode 100644 index 000000000..9f3d10f0b --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarInvasionStartEvent.java @@ -0,0 +1,29 @@ +package mineplex.game.clans.clans.war.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.game.clans.clans.war.WarInvasion; + +/** + * Called when a war invasion is started + */ +public class WarInvasionStartEvent extends Event +{ + private WarInvasion _warInvasion; + + public WarInvasionStartEvent(WarInvasion warInvasion) + { + _warInvasion = warInvasion; + } + + public WarInvasion getWarInvasion() + { + return _warInvasion; + } + + // Bukkit event stuff + private static final HandlerList handlers = new HandlerList(); + public static HandlerList getHandlerList() { return handlers; } + public HandlerList getHandlers() { return handlers; } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarStartEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarStartEvent.java new file mode 100644 index 000000000..0ba55d1bc --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/event/WarStartEvent.java @@ -0,0 +1,26 @@ +package mineplex.game.clans.clans.war.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.game.clans.clans.war.ClanWar; + +public class WarStartEvent extends Event +{ + private ClanWar _war; + + public WarStartEvent(ClanWar war) + { + _war = war; + } + + public ClanWar getWar() + { + return _war; + } + + // Bukkit event stuff + private static final HandlerList handlers = new HandlerList(); + public static HandlerList getHandlerList() { return handlers; } + public HandlerList getHandlers() { return handlers; } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index 764887b57..9efff5514 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -498,7 +498,7 @@ public class Gameplay extends MiniPlugin } @EventHandler - public void onBlockPlace(BlockBreakEvent event) + public void onBlockBreak(BlockBreakEvent event) { Location location = event.getBlock().getLocation(); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java index fbd5bf0e6..8208dcba5 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -431,7 +431,7 @@ public class ServerNpcPage extends ShopPageInventory