From baf0f254bbf86de5371fdf3a8282f345113d60f3 Mon Sep 17 00:00:00 2001 From: William Burns Date: Wed, 16 Dec 2015 14:41:57 +0000 Subject: [PATCH] Custom data, waiting for JLO --- .../core/account/CoreClientManager.java | 14 ++++- .../core/account/CustomPlayerData.java | 27 +++++++++ .../CustomPlayerDataRepository.java | 57 +++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/account/CustomPlayerData.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/account/repository/CustomPlayerDataRepository.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 26859a6b3..d04045521 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -18,6 +18,7 @@ import mineplex.core.account.command.UpdateRank; import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientWebResponseEvent; import mineplex.core.account.repository.AccountRepository; +import mineplex.core.account.repository.CustomPlayerDataRepository; import mineplex.core.account.repository.token.ClientToken; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; @@ -35,7 +36,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result; -import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -57,6 +57,8 @@ public class CoreClientManager extends MiniPlugin private static AtomicInteger _clientsConnecting = new AtomicInteger(0); private static AtomicInteger _clientsProcessing = new AtomicInteger(0); + + private CustomPlayerDataRepository _customDataRepository; public CoreClientManager(JavaPlugin plugin, String webServer) { @@ -66,6 +68,8 @@ public class CoreClientManager extends MiniPlugin _repository = new AccountRepository(plugin, webServer); _clientList = new NautHashMap(); _duplicateLoginGlitchPreventionList = new HashSet(); + + _customDataRepository = new CustomPlayerDataRepository(plugin); } public AccountRepository getRepository() @@ -580,4 +584,12 @@ public class CoreClientManager extends MiniPlugin PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid); return playerInfo == null ? -1 : playerInfo.getAccountId(); } + + public void addCustomData(Player player, String key, Object data) + { + if (data == null || player == null || key == null) + return; + + _customDataRepository + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CustomPlayerData.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CustomPlayerData.java new file mode 100644 index 000000000..b9fb8c9e3 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CustomPlayerData.java @@ -0,0 +1,27 @@ +package mineplex.core.account; + +/** + * Created by William (WilliamTiger). + * 16/12/15 + */ +public class CustomPlayerData +{ + private int _id; + private String _key; + + public CustomPlayerData(int id, String key) + { + _id = id; + _key = key; + } + + public int getId() + { + return _id; + } + + public String getKey() + { + return _key; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/CustomPlayerDataRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/CustomPlayerDataRepository.java new file mode 100644 index 000000000..69af27ddf --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/CustomPlayerDataRepository.java @@ -0,0 +1,57 @@ +package mineplex.core.account.repository; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.account.CustomPlayerData; +import mineplex.core.database.DBPool; +import mineplex.core.database.RepositoryBase; +import mineplex.core.database.ResultSetCallable; +import mineplex.core.database.column.ColumnVarChar; + +/** + * Created by William (WilliamTiger). + * 16/12/15 + */ +public class CustomPlayerDataRepository extends RepositoryBase +{ + private static final String RETRIEVE_KEYS = "SELECT id, key FROM customDataKeys;"; + private static final String INSERT_KEY = "INSERT INTO customDataKeys (key) VALUES (?);"; + + private ArrayList _playerDataTypes; + + public CustomPlayerDataRepository(JavaPlugin plugin) + { + super(plugin, DBPool.ACCOUNT); + } + + @Override + protected void initialize() + { + _playerDataTypes = new ArrayList<>(); + + executeQuery(RETRIEVE_KEYS, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + _playerDataTypes.add(new CustomPlayerData(resultSet.getInt("id"), resultSet.getString("key"))); + } + } + }); + } + + @Override + protected void update() {} + + public void addKey(String key) + { + //TODO: add the key with auto-increment ID + //executeUpdate(INSERT_KEY, new ColumnVarChar("")) + } +}