diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java index 549ca01b8..f972da43a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java @@ -1,11 +1,10 @@ package mineplex.core.communities; -import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Statement; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import org.bukkit.entity.Player; @@ -17,45 +16,54 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.serverdata.database.DBPool; +import mineplex.core.communities.storage.CommunityRepository; public class CommunityManager extends MiniDbClientPlugin { - private final Map _loadedCommunities = new HashMap<>(); + private final CommunityRepository _repo; + private final Map _loadedCommunities; public CommunityManager(JavaPlugin plugin, CoreClientManager clientManager) { super("Communities", plugin, clientManager); + + _repo = new CommunityRepository(plugin); + _loadedCommunities = new HashMap<>(); + _repo.loadCommunities(_loadedCommunities); } - public void getCommunity(int id, Callback callback) + public Community getLoadedCommunity(String name) + { + for (Entry entry : _loadedCommunities.entrySet()) + { + if (entry.getValue().getName().equalsIgnoreCase(name)) + { + return entry.getValue(); + } + } + + return null; + } + + public void handleCommunitySettingUpdate(Integer id, CommunitySetting setting, String newValue) + { + + } + + public void loadCommunity(Integer id, Callback callback) { runAsync(() -> { - try (Connection connection = DBPool.getAccount().getConnection(); Statement statement = connection.createStatement()) + Community c = _repo.getCommunityById(id); + _loadedCommunities.remove(id); + _loadedCommunities.put(id, c); + if (callback != null) { - - } - catch (SQLException e) - { - runSync(() -> - { - callback.run(null); - }); + runSync(() -> callback.run(c)); } }); } - public void getCommunity(String name) - { - - } - - public void reloadCommunity(Integer id) - { - - } - public void handleCommunityChat(Integer communityId, String senderName, String message) { Community community = _loadedCommunities.get(communityId); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunitySetting.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunitySetting.java new file mode 100644 index 000000000..1f33c7df3 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunitySetting.java @@ -0,0 +1,21 @@ +package mineplex.core.communities; + +import mineplex.core.common.Pair; +import mineplex.core.common.util.Callback; + +public enum CommunitySetting +{ + ; + + private Callback> _parser; + + private CommunitySetting(Callback> parseValue) + { + + } + + public void parseValueInto(String value, Community community) + { + _parser.run(Pair.create(value, community)); + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdate.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdate.java deleted file mode 100644 index 325598d67..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdate.java +++ /dev/null @@ -1,18 +0,0 @@ -package mineplex.core.communities.redis; - -import mineplex.serverdata.commands.ServerCommand; - -public class CommunityUpdate extends ServerCommand -{ - private Integer _communityId; - - public CommunityUpdate(Integer communityId) - { - _communityId = communityId; - } - - public Integer getCommunityId() - { - return _communityId; - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdateHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdateHandler.java deleted file mode 100644 index 2b43b0b29..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdateHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -package mineplex.core.communities.redis; - -import mineplex.core.communities.CommunityManager; -import mineplex.serverdata.commands.CommandCallback; -import mineplex.serverdata.commands.ServerCommand; - -public class CommunityUpdateHandler implements CommandCallback -{ - private CommunityManager _manager; - - public CommunityUpdateHandler(CommunityManager manager) - { - _manager = manager; - } - - @Override - public void run(ServerCommand command) - { - if (command instanceof CommunityUpdate) - { - CommunityUpdate update = ((CommunityUpdate) command); - _manager.reloadCommunity(update.getCommunityId()); - } - } -} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdateSetting.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdateSetting.java new file mode 100644 index 000000000..48b5e2673 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdateSetting.java @@ -0,0 +1,32 @@ +package mineplex.core.communities.redis; + +import mineplex.serverdata.commands.ServerCommand; + +public class CommunityUpdateSetting extends ServerCommand +{ + private Integer _communityId; + private String _setting; + private String _newValue; + + public CommunityUpdateSetting(Integer communityId, String setting, String newValue) + { + _communityId = communityId; + _setting = setting; + _newValue = newValue; + } + + public Integer getCommunityId() + { + return _communityId; + } + + public String getSetting() + { + return _setting; + } + + public String getNewValue() + { + return _newValue; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdateSettingHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdateSettingHandler.java new file mode 100644 index 000000000..e7769eaf2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/redis/CommunityUpdateSettingHandler.java @@ -0,0 +1,29 @@ +package mineplex.core.communities.redis; + +import mineplex.core.communities.CommunityManager; +import mineplex.core.communities.CommunitySetting; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +public class CommunityUpdateSettingHandler implements CommandCallback +{ + private CommunityManager _manager; + + public CommunityUpdateSettingHandler(CommunityManager manager) + { + _manager = manager; + } + + @Override + public void run(ServerCommand command) + { + if (command instanceof CommunityUpdateSetting) + { + CommunityUpdateSetting update = ((CommunityUpdateSetting) command); + Integer id = update.getCommunityId(); + CommunitySetting setting = CommunitySetting.valueOf(update.getSetting()); + String newValue = update.getNewValue(); + _manager.reloadCommunity(update.getCommunityId()); + } + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java index 0e830a58b..a007a9a2b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java @@ -12,6 +12,7 @@ import mineplex.serverdata.database.column.ColumnVarChar; public class CommunityRepository extends MinecraftRepository { + private static final String GET_ALL_COMMUNITIES = ""; private static final String GET_COMMUNITY_BY_ID = ""; private static final String GET_COMMUNITY_BY_NAME = ""; @@ -52,7 +53,13 @@ public class CommunityRepository extends MinecraftRepository public void loadCommunities(final Map communityMap) { - + executeQuery(GET_ALL_COMMUNITIES, resultSet -> + { + while (resultSet.next()) + { + + } + }); } protected void initialize() {}