Change/Expand redis interaction and community storage, implement chat formatting

This commit is contained in:
AlexTheCoder 2016-11-12 18:58:51 -05:00 committed by cnr
parent ac224e3f68
commit 5143a7cd61
7 changed files with 79 additions and 8 deletions

View File

@ -1,5 +1,7 @@
package mineplex.core.communities;
import org.bukkit.ChatColor;
public class Community
{
public Community()
@ -16,4 +18,9 @@ public class Community
{
return "";
}
public ChatColor[] getChatFormatting()
{
return new ChatColor[] {ChatColor.BLUE, ChatColor.RED, ChatColor.GREEN};
}
}

View File

@ -4,6 +4,8 @@ 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.UUID;
import org.bukkit.entity.Player;
@ -11,6 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
@ -18,6 +21,8 @@ import mineplex.serverdata.database.DBPool;
public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
{
private final Map<Integer, Community> _loadedCommunities = new HashMap<>();
public CommunityManager(JavaPlugin plugin, CoreClientManager clientManager)
{
super("Communities", plugin, clientManager);
@ -46,14 +51,23 @@ public class CommunityManager extends MiniDbClientPlugin<CommunityMemberData>
}
public void handleCommunityChat(Integer communityId, String senderDisplay, String message)
public void reloadCommunity(Integer id)
{
}
public void handleCommunityChat(Integer communityId, String senderName, String message)
{
Community community = _loadedCommunities.get(communityId);
if (community == null)
{
return;
}
for (Player player : UtilServer.getPlayers())
{
if (Get(player).isMemberOf(community))
{
UtilPlayer.message(player, "");
UtilPlayer.message(player, community.getChatFormatting()[0] + C.Bold + community.getName() + " " + community.getChatFormatting()[1] + C.Bold + senderName + " " + community.getChatFormatting()[2] + message);
}
}
}

View File

@ -4,20 +4,20 @@ import mineplex.serverdata.commands.ServerCommand;
public class CommunityChat extends ServerCommand
{
private String _senderDisplay;
private String _senderName;
private Integer _communityId;
private String _message;
public CommunityChat(String senderDisplay, Integer communityId, String message)
public CommunityChat(String senderName, Integer communityId, String message)
{
_senderDisplay = senderDisplay;
_senderName = senderName;
_communityId = communityId;
_message = message;
}
public String getSenderDisplay()
public String getSenderName()
{
return _senderDisplay;
return _senderName;
}
public Integer getCommunityId()

View File

@ -19,7 +19,7 @@ public class CommunityChatHandler implements CommandCallback
if (command instanceof CommunityChat)
{
CommunityChat chat = ((CommunityChat) command);
_manager.handleCommunityChat(chat.getCommunityId(), chat.getSenderDisplay(), chat.getMessage());
_manager.handleCommunityChat(chat.getCommunityId(), chat.getSenderName(), chat.getMessage());
}
}
}

View File

@ -0,0 +1,18 @@
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

@ -0,0 +1,25 @@
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

@ -1,5 +1,7 @@
package mineplex.core.communities.storage;
import java.util.Map;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.communities.Community;
@ -47,6 +49,11 @@ public class CommunityRepository extends MinecraftRepository
return community;
}
public void loadCommunities(final Map<Integer, Community> communityMap)
{
}
protected void initialize() {}
protected void update() {}