More backend for handling community settings

This commit is contained in:
AlexTheCoder 2016-11-13 00:27:06 -05:00 committed by cnr
parent 5143a7cd61
commit 0007ffc91e
7 changed files with 122 additions and 68 deletions

View File

@ -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<CommunityMemberData>
{
private final Map<Integer, Community> _loadedCommunities = new HashMap<>();
private final CommunityRepository _repo;
private final Map<Integer, Community> _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<Community> callback)
public Community getLoadedCommunity(String name)
{
for (Entry<Integer, Community> 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<Community> 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);

View File

@ -0,0 +1,21 @@
package mineplex.core.communities;
import mineplex.core.common.Pair;
import mineplex.core.common.util.Callback;
public enum CommunitySetting
{
;
private Callback<Pair<String, Community>> _parser;
private CommunitySetting(Callback<Pair<String, Community>> parseValue)
{
}
public void parseValueInto(String value, Community community)
{
_parser.run(Pair.create(value, community));
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}
}

View File

@ -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<Integer, Community> communityMap)
{
executeQuery(GET_ALL_COMMUNITIES, resultSet ->
{
while (resultSet.next())
{
}
});
}
protected void initialize() {}