diff --git a/Plugins/BuildFiles/common.xml b/Plugins/BuildFiles/common.xml index 4c3d6b432..103162fb8 100644 --- a/Plugins/BuildFiles/common.xml +++ b/Plugins/BuildFiles/common.xml @@ -146,6 +146,9 @@ + + + diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index b8ccbce3b..a2a6c4fd1 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -516,6 +516,14 @@ public class UtilPlayer if (log) System.out.println("Kicked Client [" + player.getName() + "] for [" + module + " - " + message + "]"); } + + public static void kick(Collection players, String module, String message, boolean log) + { + for (Player player : players) + { + kick(player, module, message, log); + } + } public static HashMap getInRadius(Location loc, double dR) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/DisplayButton.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/DisplayButton.java similarity index 80% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/DisplayButton.java rename to Plugins/Mineplex.Core/src/mineplex/core/shop/item/DisplayButton.java index f2e04bb5e..9697e4934 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/DisplayButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/DisplayButton.java @@ -1,11 +1,10 @@ -package mineplex.game.clans.shop.bank; +package mineplex.core.shop.item; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import mineplex.core.shop.item.IButton; -import mineplex.game.clans.economy.GoldManager; public class DisplayButton implements IButton { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java index bb41d48a5..4b01a608a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java @@ -229,7 +229,7 @@ public abstract class ShopPageBase + + + + + + + + + + + diff --git a/Plugins/Mineplex.Game.Clans.Core/.project b/Plugins/Mineplex.Game.Clans.Core/.project new file mode 100644 index 000000000..fb0cce853 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans.Core/.project @@ -0,0 +1,17 @@ + + + Mineplex.Game.Clans.Core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/ClanServerChangeCommand.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/ClanServerChangeCommand.java new file mode 100644 index 000000000..6a4422bd5 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/ClanServerChangeCommand.java @@ -0,0 +1,29 @@ +package mineplex.game.clans.core; + +import mineplex.game.clans.core.repository.tokens.SimpleClanToken; +import mineplex.serverdata.commands.ServerCommand; + + +public class ClanServerChangeCommand extends ServerCommand +{ + private String _clanName; + public String getClanName() { return _clanName; } + + public ClanServerChangeCommand(String serverName, String clanName) + { + super(serverName); + + _clanName = clanName; + } + + public ClanServerChangeCommand(SimpleClanToken clan) + { + this(clan.getHomeServer(), clan.getClanName()); + } + + @Override + public void run() + { + // Utilitizes a callback functionality to seperate dependencies + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java similarity index 79% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java rename to Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java index 566e32b52..307efe8fe 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.repository; +package mineplex.game.clans.core.repository; import java.sql.Connection; import java.sql.PreparedStatement; @@ -9,9 +9,7 @@ import java.sql.Timestamp; import java.util.Collection; import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; - +import mineplex.core.common.util.Callback; import mineplex.core.common.util.NautHashMap; import mineplex.core.database.DBPool; import mineplex.core.database.RepositoryBase; @@ -22,12 +20,15 @@ import mineplex.core.database.column.ColumnInt; import mineplex.core.database.column.ColumnTimestamp; import mineplex.core.database.column.ColumnVarChar; import mineplex.database.tables.records.ClansRecord; -import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken; -import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken; -import mineplex.game.clans.clans.repository.tokens.ClanMemberToken; -import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken; -import mineplex.game.clans.clans.repository.tokens.ClanToken; +import mineplex.game.clans.core.repository.tokens.ClanAllianceToken; +import mineplex.game.clans.core.repository.tokens.ClanEnemyToken; +import mineplex.game.clans.core.repository.tokens.ClanMemberToken; +import mineplex.game.clans.core.repository.tokens.ClanTerritoryToken; +import mineplex.game.clans.core.repository.tokens.ClanToken; +import mineplex.game.clans.core.repository.tokens.SimpleClanToken; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; import org.jooq.DSLContext; import static mineplex.database.Tables.*; @@ -40,7 +41,9 @@ public class ClanRepository extends RepositoryBase private static String CREATE_CLAN_TERRITORY_TABLE = "CREATE TABLE IF NOT EXISTS clanTerritory (id INT NOT NULL AUTO_INCREMENT, clanId INT, serverId INT NOT NULL, chunk VARCHAR(100), safe BIT(1), PRIMARY KEY (id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId, serverId));"; private static String CREATE_CLAN_ALLIANCE_TABLE = "CREATE TABLE IF NOT EXISTS clanAlliances (id INT NOT NULL AUTO_INCREMENT, clanId INT, otherClanId INT, trusted BIT(1), PRIMARY KEY (id), FOREIGN KEY (otherClanId) REFERENCES clans(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));"; - private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.dateCreated, c.lastOnline, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverId = ?;"; + private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.dateCreated, c.lastOnline, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverId = ? OR c.admin = 1;"; + private static String RETRIEVE_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.dateCreated, c.lastOnline FROM clans AS c WHERE lower(c.name) = ?;"; + private static String RETRIEVE_PLAYER_CLAN_INFO = "SELECT clans.name, accountClan.clanRole, clanServer.serverName, clans.id FROM accountClan INNER JOIN clans ON clans.id = accountClan.clanId INNER JOIN clanServer ON clans.serverId = clanServer.id WHERE accountClan.accountId = ?;"; 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_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 = ?;"; @@ -52,7 +55,7 @@ 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_ENEMY = "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 ADD_CLAN = "INSERT INTO clans (serverId, name, description, home, admin, dateCreated, energy, lastOnline) VALUES (?, ?, ?, ?, ?, now(), ?, now());"; @@ -66,7 +69,8 @@ public class ClanRepository extends RepositoryBase 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 serverId = ? AND chunk = ?;"; - + private static String UPDATE_CLAN_SERVER_ID = "UPDATE clans SET serverId = ?, home = '' WHERE id = ?;"; + private static String GET_CLAN_SERVER = "SELECT id FROM clanServer WHERE clanServer.serverName = ?"; private static String ADD_CLAN_SERVER = "INSERT INTO clanServer (serverName) VALUES (?);"; @@ -78,7 +82,7 @@ public class ClanRepository extends RepositoryBase super(plugin, DBPool.ACCOUNT); _serverName = serverName; - _serverId = -1; + _serverId = -1; loadServerId(); } @@ -123,7 +127,106 @@ public class ClanRepository extends RepositoryBase executeUpdate(CREATE_CLAN_TERRITORY_TABLE); executeUpdate(CREATE_CLAN_ALLIANCE_TABLE); } + + /** + * Updates a clan's home server while removing all + * alliances, enemies, teritory claims and homes set on + * originating server. + * @param clanId - the id of the clan to move + * @param serverId - the id of the destination server being moved to + */ + public void moveClanServer(int clanId, String serverName, Callback callback) + { + executeQuery(GET_CLAN_SERVER, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + boolean success = resultSet.next(); + + if (success) + { + int serverId = resultSet.getInt(1); + ColumnInt clanIdCol = new ColumnInt("clanId", clanId); + ColumnInt serverIdCol = new ColumnInt("serverId", serverId); + + executeUpdate(DELETE_CLAN_ALLIANCES, clanIdCol, clanIdCol); + executeUpdate(DELETE_CLAN_ENEMIES, clanIdCol, clanIdCol); + executeUpdate(DELETE_CLAN_TERRITORIES, clanIdCol); + executeUpdate(UPDATE_CLAN_SERVER_ID, serverIdCol, clanIdCol); + } + + callback.run(success); + } + }, new ColumnVarChar("serverName", 100, serverName)); + + } + + public void retrieveClan(String clanName, final Callback callback) + { + executeQuery(RETRIEVE_CLAN_INFO, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + if (resultSet.next()) + { + ClanToken token = new ClanToken(); + token.Id = resultSet.getInt(1); + token.Name = resultSet.getString(2); + token.Description = resultSet.getString(3); + token.Home = resultSet.getString(4); + token.Admin = resultSet.getBoolean(5); + token.Energy = resultSet.getInt(6); + token.Kills = resultSet.getInt(7); + token.Murder = resultSet.getInt(8); + token.Deaths = resultSet.getInt(9); + token.WarWins = resultSet.getInt(10); + token.WarLosses = resultSet.getInt(11); + token.DateCreated = resultSet.getTimestamp(12); + token.LastOnline = resultSet.getTimestamp(13); + + callback.run(token); + } + } + }, new ColumnVarChar("name", 100, clanName.toLowerCase())); + } + + public void clanExists(String clanName, final Callback callback) + { + executeQuery(RETRIEVE_CLAN_INFO, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + boolean clanExists = resultSet.next(); + callback.run(clanExists); + } + }, new ColumnVarChar("name", 100, clanName.toLowerCase())); + } + public void retrievePlayersClan(int accountId, final Callback callback) + { + executeQuery(RETRIEVE_PLAYER_CLAN_INFO, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + SimpleClanToken clanToken = null; + if (resultSet.next()) + { + String clanName = resultSet.getString(1); + String clanRole = resultSet.getString(2); + String homeServer = resultSet.getString(3); + int clanId = resultSet.getInt(4); + clanToken = new SimpleClanToken(clanName, clanRole, homeServer, clanId); + } + + callback.run(clanToken); + } + }, new ColumnInt("accountId", accountId)); + } + public Collection retrieveClans() { System.out.println("Beginning to load clans from database..."); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanTerritory.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanTerritory.java similarity index 72% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanTerritory.java rename to Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanTerritory.java index c13d2a36c..1ee9303a1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanTerritory.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanTerritory.java @@ -1,6 +1,6 @@ -package mineplex.game.clans.clans.repository; +package mineplex.game.clans.core.repository; -import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken; +import mineplex.game.clans.core.repository.tokens.ClanTerritoryToken; public class ClanTerritory { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanAllianceToken.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanAllianceToken.java similarity index 61% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanAllianceToken.java rename to Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanAllianceToken.java index fe4520969..c749feec1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanAllianceToken.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanAllianceToken.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.repository.tokens; +package mineplex.game.clans.core.repository.tokens; public class ClanAllianceToken { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanEnemyToken.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanEnemyToken.java similarity index 77% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanEnemyToken.java rename to Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanEnemyToken.java index 3aa201763..8fb9e1ed1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanEnemyToken.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanEnemyToken.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.repository.tokens; +package mineplex.game.clans.core.repository.tokens; import java.sql.Timestamp; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanMemberToken.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanMemberToken.java similarity index 70% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanMemberToken.java rename to Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanMemberToken.java index 4af96feb0..9fab8c68a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanMemberToken.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanMemberToken.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.repository.tokens; +package mineplex.game.clans.core.repository.tokens; import java.util.UUID; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanTerritoryToken.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanTerritoryToken.java similarity index 74% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanTerritoryToken.java rename to Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanTerritoryToken.java index 5b7ca2108..d7c6cbfde 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanTerritoryToken.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanTerritoryToken.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.repository.tokens; +package mineplex.game.clans.core.repository.tokens; public class ClanTerritoryToken { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanToken.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanToken.java similarity index 92% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanToken.java rename to Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanToken.java index d739ceb69..a9812c731 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/tokens/ClanToken.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/ClanToken.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.repository.tokens; +package mineplex.game.clans.core.repository.tokens; import java.sql.Timestamp; import java.util.ArrayList; diff --git a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java new file mode 100644 index 000000000..70757bd98 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java @@ -0,0 +1,25 @@ +package mineplex.game.clans.core.repository.tokens; + +public class SimpleClanToken +{ + + private String _clanName; + public String getClanName() { return _clanName; } + + private String _clanRole; + public String getClanRole() { return _clanRole; } + + private String _homeServer; + public String getHomeServer() { return _homeServer; } + + private int _clanId; + public int getClanId() { return _clanId; } + + public SimpleClanToken(String clanName, String clanRole, String homeServer, int clanId) + { + _clanName = clanName; + _clanRole = clanRole; + _homeServer = homeServer; + _clanId = clanId; + } +} diff --git a/Plugins/Mineplex.Game.Clans/.classpath b/Plugins/Mineplex.Game.Clans/.classpath index 33cd9fb00..4a7e01944 100644 --- a/Plugins/Mineplex.Game.Clans/.classpath +++ b/Plugins/Mineplex.Game.Clans/.classpath @@ -11,5 +11,6 @@ + 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 9e721cdf8..8c84da5f7 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 @@ -21,11 +21,11 @@ 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.repository.tokens.ClanAllianceToken; -import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken; -import mineplex.game.clans.clans.repository.tokens.ClanMemberToken; -import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken; -import mineplex.game.clans.clans.repository.tokens.ClanToken; +import mineplex.game.clans.core.repository.tokens.ClanAllianceToken; +import mineplex.game.clans.core.repository.tokens.ClanEnemyToken; +import mineplex.game.clans.core.repository.tokens.ClanMemberToken; +import mineplex.game.clans.core.repository.tokens.ClanTerritoryToken; +import mineplex.game.clans.core.repository.tokens.ClanToken; public class ClanInfo { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansAdmin.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansAdmin.java index 67273393c..9b4e17bdc 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansAdmin.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansAdmin.java @@ -9,7 +9,7 @@ import mineplex.core.common.util.UtilInput; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilWorld; -import mineplex.game.clans.clans.repository.ClanTerritory; +import mineplex.game.clans.core.repository.ClanTerritory; import org.bukkit.Bukkit; import org.bukkit.entity.Player; 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 36a5ce169..2759a6490 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 @@ -10,14 +10,15 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import com.sun.org.apache.xpath.internal.operations.Bool; + import mineplex.core.common.util.Callback; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilWorld; -import mineplex.game.clans.clans.repository.ClanRepository; -import mineplex.game.clans.clans.repository.ClanTerritory; -import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken; -import mineplex.game.clans.clans.repository.tokens.ClanToken; import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager; +import mineplex.game.clans.core.repository.ClanRepository; +import mineplex.game.clans.core.repository.ClanTerritory; +import mineplex.game.clans.core.repository.tokens.ClanEnemyToken; +import mineplex.game.clans.core.repository.tokens.ClanToken; public class ClansDataAccessLayer { @@ -43,35 +44,42 @@ public class ClansDataAccessLayer if (out) { - //Territory Unclaim - for (String cur : clan.getClaimSet()) - _manager.getClaimMap().remove(cur); - - _manager.getClanMap().remove(clan.getName()); - - for (String cur : clan.getMembers().keySet()) - { - _manager.getClanMemberMap().remove(cur); - } - - //Clean from Others - for (ClanInfo cur : _manager.getClanMap().values()) - { - cur.getAllyMap().remove(clan.getName()); - cur.getRequestMap().remove(clan.getName()); - } - - //Scoreboard - _scoreboard.refresh(clan); - - //Log - _manager.log("Deleted [" + clan.getName() + "]."); + deleteLocally(clan); } if (callback != null) callback.run(out); } }); } + + public void deleteLocally(ClanInfo clan) + { + //Territory Unclaim + for (String cur : clan.getClaimSet()) + { + _manager.getClaimMap().remove(cur); + } + + _manager.getClanMap().remove(clan.getName()); + + for (String cur : clan.getMembers().keySet()) + { + _manager.getClanMemberMap().remove(cur); + } + + //Clean from Others + for (ClanInfo cur : _manager.getClanMap().values()) + { + cur.getAllyMap().remove(clan.getName()); + cur.getRequestMap().remove(clan.getName()); + } + + //Scoreboard + _scoreboard.refresh(clan); + + //Log + _manager.log("Deleted [" + clan.getName() + "]."); + } public void createAndJoin(final Player player, final String name, final Callback callback) { @@ -621,6 +629,16 @@ public class ClansDataAccessLayer _manager.log("Safe Zone at [" + claim.Chunk + "] set to [" + claim.Safe + "] by [" + player + "]."); } + public void retrieveClan(String clanName, Callback callback) + { + _repository.retrieveClan(clanName, callback); + } + + public void clanExists(String clanName, Callback callback) + { + _repository.clanExists(clanName, callback); + } + public ClanRepository getRepository() { return _repository; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java index 438bcf71e..647167773 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java @@ -13,7 +13,7 @@ import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansUtility.ClanRelation; -import mineplex.game.clans.clans.repository.ClanTerritory; +import mineplex.game.clans.core.repository.ClanTerritory; import org.bukkit.Chunk; import org.bukkit.Material; 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 4f4d8038a..5e9d45737 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 @@ -26,7 +26,6 @@ import org.bukkit.plugin.java.JavaPlugin; import net.minecraft.server.v1_7_R4.EnumToolMaterial; import net.minecraft.server.v1_7_R4.Item; import net.minecraft.server.v1_7_R4.ItemSword; - import mineplex.core.MiniClientPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; @@ -62,15 +61,17 @@ import mineplex.game.clans.clans.commands.ServerTimeCommand; import mineplex.game.clans.clans.loot.LootManager; import mineplex.game.clans.clans.map.ItemMapManager; import mineplex.game.clans.clans.murder.MurderManager; +import mineplex.game.clans.clans.redis.ClanServerChangeHandler; import mineplex.game.clans.clans.regions.ClansRegions; -import mineplex.game.clans.clans.repository.ClanTerritory; -import mineplex.game.clans.clans.repository.tokens.ClanMemberToken; -import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken; -import mineplex.game.clans.clans.repository.tokens.ClanToken; import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager; import mineplex.game.clans.clans.war.WarManager; import mineplex.game.clans.economy.GoldManager; import mineplex.game.clans.clans.worldevent.WorldEventManager; +import mineplex.game.clans.core.ClanServerChangeCommand; +import mineplex.game.clans.core.repository.ClanTerritory; +import mineplex.game.clans.core.repository.tokens.ClanMemberToken; +import mineplex.game.clans.core.repository.tokens.ClanTerritoryToken; +import mineplex.game.clans.core.repository.tokens.ClanToken; import mineplex.game.clans.fields.Field; import mineplex.game.clans.gameplay.Gameplay; import mineplex.game.clans.gameplay.safelog.LoggingManager; @@ -92,12 +93,21 @@ 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.data.DataRepository; +import mineplex.serverdata.data.PlayerServerInfo; +import mineplex.serverdata.redis.RedisDataRepository; +import mineplex.serverdata.servers.ConnectionData; +import mineplex.serverdata.servers.ServerManager; public class ClansManager extends MiniClientPlugin implements IRelation { public static final int CLAIMABLE_RADIUS = 800; public static final int WORLD_RADIUS = 1200; private static final TimeZone TIME_ZONE = TimeZone.getDefault(); + private static ClansManager _instance; + public static ClansManager getInstance() { return _instance; } private String _serverName; @@ -115,6 +125,7 @@ public class ClansManager extends MiniClientPlugin implements IRelat private Teleport _teleport; private ConditionManager _condition; private ClassCombatShop _classShop; + private DataRepository _playerRepository; // private ClassManager _classManager; public ClassManager getClassManager() { return _classManager; } @@ -150,6 +161,7 @@ public class ClansManager extends MiniClientPlugin implements IRelat { super("Clans Manager", plugin); + _instance = this; _serverName = serverName; _clientManager = clientManager; _combatManager = new CombatManager(plugin); @@ -209,6 +221,9 @@ public class ClansManager extends MiniClientPlugin implements IRelat skillManager.removeSkill("Shield Smash"); _classManager = new ClassManager(plugin, _clientManager, donationManager, skillManager, itemFactory, webServerAddress); + // Register redis based server commands + ServerCommandManager.getInstance().registerCommandType(ClanServerChangeCommand.class, new ClanServerChangeHandler()); + StatsManager statsManager = new StatsManager(plugin, _clientManager); AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, donationManager); ClassShopManager shopManager = new ClassShopManager(plugin, _classManager, skillManager, itemFactory, achievementManager, _clientManager); @@ -228,6 +243,8 @@ public class ClansManager extends MiniClientPlugin implements IRelat _claimMap.put(territoryToken.Chunk, new ClanTerritory(territoryToken)); } + _playerRepository = new RedisDataRepository(Region.ALL, PlayerServerInfo.class, "ClansServerCache"); + //RedisDataRepository(ConnectionData writeConn, ConnectionData readConn, Region region, Class elementType, String elementLabel) // Initialize default region factions and territory (spawn/fields/borderlands) _clanRegions = new ClansRegions(plugin, this); _clanRegions.initializeRegions(); @@ -751,7 +768,7 @@ public class ClansManager extends MiniClientPlugin implements IRelat e.printStackTrace(); } catch (IllegalAccessException e) - { + { e.printStackTrace(); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java index be9746c2b..e5a879e1e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java @@ -17,7 +17,7 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; -import mineplex.game.clans.clans.repository.ClanTerritory; +import mineplex.game.clans.core.repository.ClanTerritory; public class ClansUtility { 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 93c7d9324..6dd3aa8ec 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 @@ -24,6 +24,7 @@ import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansUtility.ClanRelation; import mineplex.game.clans.clans.ClientClan; +import mineplex.game.clans.core.repository.tokens.ClanToken; public class ClansCommand extends CommandBase { @@ -69,7 +70,7 @@ public class ClansCommand extends CommandBase else if (args[0].equalsIgnoreCase("demote") || args[0].equalsIgnoreCase("-")) demote(caller, args); - + else if (args[0].equalsIgnoreCase("join") || args[0].equalsIgnoreCase("j")) join(caller, args); @@ -285,35 +286,39 @@ public class ClansCommand extends CommandBase { UtilPlayer.message(caller, F.main("Clans", "Clan name cannot be a Clan command.")); return; - } + } } - for (String cur : Plugin.getClanMap().keySet()) - { - if (cur.equalsIgnoreCase(args[1])) - { - UtilPlayer.message(caller, F.main("Clans", "Clan name is already in use by another Clan.")); - return; - } - } - - Plugin.getClanDataAccess().createAndJoin(caller, args[1], new Callback() - { - @Override - public void run(ClanInfo data) - { - if (data != null) + Plugin.getClanDataAccess().clanExists(args[1], new Callback() { - //Inform - UtilServer.broadcast(F.main("Clans", F.name(caller.getName()) + " formed " + F.elem("Clan " + args[1]) + ".")); - } - else - { - // Hopefully shouldn't happen! - UtilPlayer.message(caller, F.main("Clans", "There was an error creating the clan. Please try again")); - } - } - }); + @Override + public void run(Boolean clanExists) + { + if (clanExists) + { + UtilPlayer.message(caller, F.main("Clans", "Clan name is already in use by another Clan.")); + } + else + { + Plugin.getClanDataAccess().createAndJoin(caller, args[1], new Callback() + { + @Override + public void run(ClanInfo data) + { + if (data != null) + { + //Inform + UtilServer.broadcast(F.main("Clans", F.name(caller.getName()) + " formed " + F.elem("Clan " + args[1]) + ".")); + } + else + { + // Hopefully shouldn't happen! + UtilPlayer.message(caller, F.main("Clans", "There was an error creating the clan. Please try again")); + } + } + }); + } + }}); } public void delete(final Player caller, String[] args) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/murder/MurderManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/murder/MurderManager.java index 985095a88..64637f164 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/murder/MurderManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/murder/MurderManager.java @@ -21,7 +21,7 @@ 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.repository.ClanTerritory; +import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.minecraft.game.core.combat.CombatComponent; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/redis/ClanServerChangeHandler.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/redis/ClanServerChangeHandler.java new file mode 100644 index 000000000..6e794960c --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/redis/ClanServerChangeHandler.java @@ -0,0 +1,29 @@ +package mineplex.game.clans.clans.redis; + +import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.core.ClanServerChangeCommand; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +public class ClanServerChangeHandler implements CommandCallback +{ + + public void run(ServerCommand command) + { + if (command instanceof ClanServerChangeCommand) + { + ClanServerChangeCommand serverCommand = (ClanServerChangeCommand) command; + String clanName = serverCommand.getClanName(); + ClanInfo clanInfo = ClansManager.getInstance().getClan(clanName); + + if (clanInfo != null) + { + // Kick all online players from clan and delete clan info locally + UtilPlayer.kick(clanInfo.getOnlinePlayers(), "Clans", "Your clan leader has moved your clan to another server!", true); + ClansManager.getInstance().getClanDataAccess().deleteLocally(clanInfo); + } + } + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java index 33a30c870..011d3b91d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java @@ -8,7 +8,7 @@ import mineplex.core.scoreboard.ScoreboardManager; import mineplex.core.scoreboard.elements.ScoreboardElement; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansUtility; -import mineplex.game.clans.clans.repository.ClanTerritory; +import mineplex.game.clans.core.repository.ClanTerritory; import org.bukkit.entity.Player; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java index 5f45ffe02..0e7929e36 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java @@ -192,7 +192,7 @@ public class GoldManager extends MiniPlugin { deductGems(player, gemAmount); addGold(player, goldCount); - notify(player, String.format("You have transferred %d gems into %d gold coins!", gemCount, goldCount)); + notify(player, String.format("You have transferred %d gems into %d gold coins!", gemAmount, goldCount)); _transferTracker.insertTransfer(player); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java index b93f992fa..92fa19555 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java @@ -51,7 +51,7 @@ public abstract class ClansShopPage> extends Sh public void addShopItem(int slot, Material material, int buyPrice, int sellPrice, byte data) { - addShopItem(slot, material, buyPrice, sellPrice, Clans.prettifyName(material)); + addShopItem(slot, material, buyPrice, sellPrice, data, Clans.prettifyName(material), 1); } public void addShopItem(int slot, Material material, int buyPrice, int sellPrice, String displayName) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/BankPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/BankPage.java index a97b503de..ad48389a7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/BankPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/BankPage.java @@ -10,6 +10,7 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.donation.DonationManager; import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.shop.item.DisplayButton; import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.page.ShopPageBase; import mineplex.game.clans.clans.ClanInfo; diff --git a/Plugins/Mineplex.Hub/.classpath b/Plugins/Mineplex.Hub/.classpath index 866da57e1..baebf1394 100644 --- a/Plugins/Mineplex.Hub/.classpath +++ b/Plugins/Mineplex.Hub/.classpath @@ -12,5 +12,6 @@ + diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index 9cfa24d21..7da629370 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -62,6 +62,7 @@ import mineplex.hub.server.ui.LobbyShop; import mineplex.hub.server.ui.QuickShop; import mineplex.hub.server.ui.ServerCountSorter; import mineplex.hub.server.ui.ServerNpcShop; +import mineplex.hub.server.ui.clans.ClansServerShop; import mineplex.serverdata.Region; import mineplex.serverdata.data.MinecraftServer; import mineplex.serverdata.data.ServerGroup; @@ -124,6 +125,9 @@ public class ServerManager extends MiniPlugin _quickShop = new QuickShop(this, clientManager, donationManager, "Quick Menu"); _lobbyShop = new LobbyShop(this, clientManager, donationManager, "Lobby Menu"); //_domShop = new new QueueShop(_queueManager, clientManager, donationManager, "Dominate"); + + // TODO: Find more appropriate place to initialize Clans server shop? + new ClansServerShop(this, _clientManager, _donationManager); } @EventHandler(priority = EventPriority.LOW) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/LobbyMenu.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/LobbyMenu.java index f084c2ded..2e743365c 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/LobbyMenu.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/LobbyMenu.java @@ -77,7 +77,7 @@ public class LobbyMenu extends ShopPageBase implements lore.add(ChatColor.RESET + C.Line + "Click to join!"); if (status != Material.EMERALD_BLOCK) - addButton(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Integer.parseInt(serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1)), false), new JoinServerButton(this, serverInfo)); + addButton(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Integer.parseInt(serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1)), false), new JoinServerButton(this, getPlugin(), serverInfo, getPlayer())); else addItem(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Integer.parseInt(serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1)), false)); } 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 64993b32e..6f383a8b9 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -26,7 +26,7 @@ import mineplex.hub.server.ServerManager; import mineplex.hub.server.ServerSorter; import mineplex.hub.server.ui.button.JoinServerButton; -public class ServerNpcPage extends ShopPageBase implements IServerPage +public class ServerNpcPage extends ShopPageBase { // Shop Item Messages private static final String MESSAGE_BETA_GET_ULTRA = ChatColor.RESET + C.Line + "Get Ultra to join Tournament servers!"; @@ -238,7 +238,7 @@ public class ServerNpcPage extends ShopPageBase im if (serverInfo.HostedByStaff && staffSlot < 9) { - addButton(staffSlot, getPrivateItem(serverInfo), new JoinServerButton(this, serverInfo)); + addButton(staffSlot, getPrivateItem(serverInfo), new JoinServerButton(this, getPlugin(), serverInfo, getPlayer())); staffSlot++; } else @@ -246,7 +246,7 @@ public class ServerNpcPage extends ShopPageBase im if (slot >= 54) continue; - addButton(slot, getPrivateItem(serverInfo), new JoinServerButton(this, serverInfo)); + addButton(slot, getPrivateItem(serverInfo), new JoinServerButton(this, getPlugin(), serverInfo, getPlayer())); slot++; } } @@ -276,7 +276,7 @@ public class ServerNpcPage extends ShopPageBase im setItem(slot, shopItem); else { - addButton(slot, shopItem, new JoinServerButton(this, serverInfo)); + addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer())); } if (full) @@ -378,7 +378,7 @@ public class ServerNpcPage extends ShopPageBase im { ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded); - addButton(slot, shopItem, new JoinServerButton(this, serverInfo)); + addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer())); slot++; } @@ -409,17 +409,4 @@ public class ServerNpcPage extends ShopPageBase im buildPage(); } - public void SelectServer(Player player, ServerInfo serverInfo) - { - System.out.println("Selecting server :" + serverInfo.Name); - int slots = getPlugin().getRequiredSlots(player, serverInfo.ServerType); - - if (serverInfo.getAvailableSlots() < slots && !(getDonationManager().Get(getPlayer().getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || getClient().GetRank().Has(Rank.ULTRA))) - { - playDenySound(player); - return; - } - - getPlugin().selectServer(player, serverInfo); - } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/JoinServerButton.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/JoinServerButton.java index d0a57ec41..872b0f430 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/JoinServerButton.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/JoinServerButton.java @@ -3,24 +3,54 @@ package mineplex.hub.server.ui.button; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; +import mineplex.core.common.Rank; import mineplex.core.shop.item.IButton; +import mineplex.core.shop.page.ShopPageBase; import mineplex.hub.server.ServerInfo; +import mineplex.hub.server.ServerManager; import mineplex.hub.server.ui.IServerPage; public class JoinServerButton implements IButton { - private IServerPage _page; + private ShopPageBase _page; + private ServerManager _serverManager; private ServerInfo _serverInfo; + private Player _player; - public JoinServerButton(IServerPage page, ServerInfo serverInfo) + public JoinServerButton(ShopPageBase page, ServerManager serverManager, ServerInfo serverInfo, Player player) { _page = page; + _serverManager = serverManager; _serverInfo = serverInfo; + _player = player; } @Override public void onClick(Player player, ClickType clickType) { - _page.SelectServer(player, _serverInfo); + selectServer(player, _serverInfo); + } + + public void selectServer(Player player, ServerInfo serverInfo) + { + if (serverInfo != null) + { + System.out.println("Selecting server :" + serverInfo.Name); + int slots = _serverManager.getRequiredSlots(player, serverInfo.ServerType); + + if (serverInfo.getAvailableSlots() < slots && !(_page.getDonationManager().Get(_player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || _page.getClient().GetRank().Has(Rank.ULTRA))) + { + _page.playDenySound(player); + + } + else + { + _serverManager.selectServer(player, serverInfo); + } + } + else + { + _page.playDenySound(player); + } } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerButton.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerButton.java new file mode 100644 index 000000000..743090912 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerButton.java @@ -0,0 +1,48 @@ +package mineplex.hub.server.ui.clans; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import mineplex.core.common.util.Callback; +import mineplex.core.shop.item.IButton; +import mineplex.game.clans.core.ClanServerChangeCommand; +import mineplex.game.clans.core.repository.ClanRepository; +import mineplex.game.clans.core.repository.tokens.SimpleClanToken; + +public class ClanMoveServerButton implements IButton +{ + + private ClanRepository _repository; + private SimpleClanToken _clan; + private String _serverName; + + public ClanMoveServerButton(ClanRepository repository, SimpleClanToken clan, String serverName) + { + _repository = repository; + _clan = clan; + _serverName = serverName; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + _repository.moveClanServer(_clan.getClanId(), _serverName, new Callback() + { + @Override + public void run(Boolean success) + { + if (success) + { + ClanServerChangeCommand changeCommand = new ClanServerChangeCommand(_clan); + changeCommand.publish(); + System.out.println("Successfully finished moving clan to new home server!"); + } + else + { + System.out.println("ERROR: Unable to successfully move clan to new home server!"); + } + } + }); + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerPage.java new file mode 100644 index 000000000..c74be3a16 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerPage.java @@ -0,0 +1,68 @@ +package mineplex.hub.server.ui.clans; + +import java.util.Collection; +import java.util.List; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.item.DisplayButton; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.core.repository.ClanRepository; +import mineplex.game.clans.core.repository.tokens.SimpleClanToken; +import mineplex.hub.server.ServerInfo; +import mineplex.hub.server.ServerManager; + +import org.bukkit.Material; +import org.bukkit.entity.Player; + +public class ClanMoveServerPage extends ShopPageBase +{ + + //private DataRepository _repository; // Stores the name of the last Clans server a player was on + private ClanRepository _repository; + private SimpleClanToken _clan; + private int _accountId; + + public ClanMoveServerPage(ServerManager plugin, ClanMoveServerShop shop, CoreClientManager clientManager, + DonationManager donationManager, Player player, ClanRepository repository, SimpleClanToken clan) + { + super(plugin, shop, clientManager, donationManager, "Clans Server Change", player, 27); + + _repository = repository; + _clan = clan; + _accountId = clientManager.getAccountId(player); + + buildPage(); + } + + @Override + protected void buildPage() + { + Collection servers = getPlugin().getServerList("Clans"); + + int currentSlot = 9; + for (ServerInfo server : servers) + { + if (!server.Name.equalsIgnoreCase(_clan.getHomeServer())) + { + buildServerButton(currentSlot, server); + currentSlot++; + } + } + // TODO: Build a button for each available clans server to move clan to + // clicking the button should move the clan to the new server + } + + private void buildServerButton(int slot, ServerInfo server) + { + ClanMoveServerButton button = new ClanMoveServerButton(_repository, _clan, server.Name); + String title = C.Bold + C.cGold + "Move Clan To Server!"; + String desc1 = C.cGold + "Server: " + C.cAqua + server.Name; + String desc2 = C.cGold + "Players: " + C.cAqua + server.CurrentPlayers + "/" + server.MaxPlayers; + ShopItem shopItem = new ShopItem(Material.DIAMOND_BLOCK, title, new String[] {" ", desc1, desc2, " "}, 0, true, true); + addButton(slot, shopItem, button); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java new file mode 100644 index 000000000..6336115e2 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java @@ -0,0 +1,62 @@ +package mineplex.hub.server.ui.clans; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.donation.DonationManager; +import mineplex.core.party.Party; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.core.repository.ClanRepository; +import mineplex.game.clans.core.repository.tokens.SimpleClanToken; +import mineplex.hub.server.ServerManager; + +public class ClanMoveServerShop extends ShopBase +{ + + private ClanRepository _repository; + private SimpleClanToken _clan; + + public ClanMoveServerShop(ServerManager plugin, CoreClientManager clientManager, DonationManager donationManager, + SimpleClanToken clan) + { + super(plugin, clientManager, donationManager, "Move Clans Server"); + + _repository = new ClanRepository(plugin.getPlugin(), plugin.getStatusManager().getCurrentServerName()); + _clan = clan; + } + + @Override + protected ShopPageBase> buildPagesFor(Player player) + { + return new ClanMoveServerPage(getPlugin(), this, getClientManager(), getDonationManager(), player, _repository, _clan); + } + + @Override + protected boolean canOpenShop(Player player) + { + Party party = getPlugin().getPartyManager().GetParty(player); + + if (party != null) + { + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + player.sendMessage(F.main("Party", "You cannot join Clans while in a party.")); + return false; + } + + return true; + } + + protected void openShopForPlayer(Player player) + { + getPlugin().getHubManager().GetVisibility().addHiddenPlayer(player); + } + + protected void closeShopForPlayer(Player player) + { + getPlugin().getHubManager().GetVisibility().removeHiddenPlayer(player); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java new file mode 100644 index 000000000..d5c16fdfd --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java @@ -0,0 +1,147 @@ +package mineplex.hub.server.ui.clans; + +import java.util.Collection; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.item.DisplayButton; +import mineplex.core.shop.item.IButton; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.core.repository.ClanRepository; +import mineplex.game.clans.core.repository.tokens.SimpleClanToken; +import mineplex.hub.server.ServerInfo; +import mineplex.hub.server.ServerManager; +import mineplex.hub.server.ui.button.JoinServerButton; +import mineplex.serverdata.data.DataRepository; + +public class ClansServerPage extends ShopPageBase +{ + + //private DataRepository _repository; // Stores the name of the last Clans server a player was on + private ClanRepository _repository; + private int _accountId; + + public ClansServerPage(ServerManager plugin, ClansServerShop shop, CoreClientManager clientManager, + DonationManager donationManager, Player player, ClanRepository repository) + { + super(plugin, shop, clientManager, donationManager, "Clans", player, 27); + + _repository = repository; + _accountId = clientManager.getAccountId(player); + + buildPage(); + } + + @Override + protected void buildPage() + { + _repository.retrievePlayersClan(_accountId, new Callback() + { + @Override + public void run(SimpleClanToken data) + { + if (data != null) + { + System.out.println("Found clan: " + data.getClanName() + " - " + data.getHomeServer()); + buildClanPage(data); + } + else + { + System.out.println("NO CLAN FOUND!"); + buildNoClanPage(); + } + } + }); + } + + private void buildClanPage(SimpleClanToken clan) + { + buildJoinHomeServer(clan); + + if (isLeader(clan)) + { + buildMoveClan(clan); + } + } + + private void buildNoClanPage() + { + Collection servers = getPlugin().getServerList("Clans"); + + int currentSlot = 9; + for (ServerInfo server : servers) + { + buildJoinServer(currentSlot, server); + currentSlot++; + } + } + + private boolean isLeader(SimpleClanToken clan) + { + return clan.getClanRole().equalsIgnoreCase("Leader"); + } + + private void buildJoinHomeServer(SimpleClanToken clan) + { + ServerInfo serverInfo = getServerInfo(clan.getHomeServer()); + boolean serverOnline = (serverInfo != null); + String serverStatus = serverOnline ? C.cGreen + "Online" : C.cRed + "Offline"; + + String title = C.cRed + C.Bold + "Join Home Server!"; + String description = C.cGold + "Join your home server, " + C.cAqua + clan.getHomeServer() + C.cGold + "!"; + String serverDesc = C.cGold + "Server Status: " + serverStatus + C.cGold + "!"; + ShopItem shopItem = new ShopItem(Material.GOLD_BLOCK, title, new String[] {" ", description, serverDesc, " "}, 0, true, true); + addButton(4, shopItem, new JoinServerButton(this, getPlugin(), getServerInfo(clan.getHomeServer()), getPlayer())); + } + + private void buildJoinServer(int slot, ServerInfo server) + { + String title = C.cRed + C.Bold + "Join Clans Server!"; + String desc1 = C.cGold + "Name: " + C.cAqua + server.Name; + String desc2 = C.cGold + "Players: " + C.cAqua + server.CurrentPlayers + "/" + server.MaxPlayers; + + ShopItem shopItem = new ShopItem(Material.GOLD_BLOCK, title, new String[] {" ", desc1, desc2, " "}, 0, true, true); + addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), server, getPlayer())); + } + + private void buildMoveClan(final SimpleClanToken clan) + { + // Build button for moving clan to another server + String title = C.cRed + C.Bold + "Change Clan's Home Server!"; + String description = C.cGold + "Move your clan to another server!"; + String desc2 = C.Bold + C.cRed + "Warning: " + ChatColor.RESET + C.cGold + "Changing your clan's"; + String desc3 = C.cGold + "home server will permanently unclaim"; + String desc4 = C.cGold + "your land and prevent you from"; + String desc5 = C.cGold + "joining the original server."; + ShopItem shopItem = new ShopItem(Material.BOOK_AND_QUILL, title, new String[] {" ", description, desc2, desc3, desc4, desc5, " "}, 0, true, true); + + IButton button = new IButton() + { + @Override + public void onClick(Player player, ClickType clickType) + { + ClanMoveServerShop shop = new ClanMoveServerShop(getPlugin(), getClientManager(), getDonationManager(), clan); + + if (!shop.attemptShopOpen(player)) + { + playDenySound(player); + } + } + }; + + addButton(13, shopItem, button); + } + + private ServerInfo getServerInfo(String serverName) + { + return getPlugin().getServerInfo(serverName); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java new file mode 100644 index 000000000..3cca1edda --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java @@ -0,0 +1,59 @@ +package mineplex.hub.server.ui.clans; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.donation.DonationManager; +import mineplex.core.party.Party; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.core.repository.ClanRepository; +import mineplex.game.clans.core.repository.tokens.SimpleClanToken; +import mineplex.hub.server.ServerManager; + +public class ClansServerShop extends ShopBase +{ + + private ClanRepository _repository; + + public ClansServerShop(ServerManager plugin, CoreClientManager clientManager, DonationManager donationManager) + { + super(plugin, clientManager, donationManager, "Clans"); + + _repository = new ClanRepository(plugin.getPlugin(), plugin.getStatusManager().getCurrentServerName()); + } + + @Override + protected ShopPageBase> buildPagesFor(Player player) + { + return new ClansServerPage(getPlugin(), this, getClientManager(), getDonationManager(), player, _repository); + } + + @Override + protected boolean canOpenShop(Player player) + { + Party party = getPlugin().getPartyManager().GetParty(player); + + if (party != null) + { + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f); + player.sendMessage(F.main("Party", "You cannot join Clans while in a party.")); + return false; + } + + return true; + } + + protected void openShopForPlayer(Player player) + { + getPlugin().getHubManager().GetVisibility().addHiddenPlayer(player); + } + + protected void closeShopForPlayer(Player player) + { + getPlugin().getHubManager().GetVisibility().removeHiddenPlayer(player); + } +} diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/commands/ServerCommandManager.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/commands/ServerCommandManager.java index 31341ae10..5cc588d2b 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/commands/ServerCommandManager.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/commands/ServerCommandManager.java @@ -157,6 +157,11 @@ public class ServerCommandManager System.out.println("Registered : " + commandName); } + public void registerCommandType(Class commandType, CommandCallback callback) + { + registerCommandType(commandType.getSimpleName(), commandType, callback); + } + public void registerCommandType(String commandName, Class commandType) { registerCommandType(commandName, commandType, null); diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerServerInfo.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerServerInfo.java new file mode 100644 index 000000000..f4a0be4f4 --- /dev/null +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/PlayerServerInfo.java @@ -0,0 +1,25 @@ +package mineplex.serverdata.data; + +public class PlayerServerInfo implements Data +{ + + private String _playerName; + public String getPlayerName() { return _playerName; } + + private String _lastServer; + public String getLastServer() { return _lastServer; } + public void setLastServer(String lastServer) { _lastServer = lastServer; } + + public PlayerServerInfo(String playerName, String lastServer) + { + _playerName = playerName; + _lastServer = lastServer; + } + + @Override + public String getDataId() + { + return _playerName; + } + +}