Redis system needs a shit ton of work. Need to design it better.
This commit is contained in:
parent
4ce9c90839
commit
502111ef4e
@ -5,8 +5,7 @@ import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.party.command.PartyCommand;
|
||||
import mineplex.core.party.redis.locate.LocateType;
|
||||
import mineplex.core.party.redis.locate.PartyRedisLocate;
|
||||
import mineplex.core.party.redis.LocateType;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,6 +21,7 @@ public class PartyManager extends MiniPlugin
|
||||
private CoreClientManager _clientManager;
|
||||
private PreferencesManager _preferencesManager;
|
||||
|
||||
|
||||
private String _serverName;
|
||||
|
||||
private Map<UUID, Party> _players = Maps.newHashMap();
|
||||
@ -40,12 +40,8 @@ public class PartyManager extends MiniPlugin
|
||||
|
||||
public void locatePlayer(String player, Callback<String> callback, LocateType reason)
|
||||
{
|
||||
runAsync(() -> {
|
||||
//locate player
|
||||
//Find the player and callback with the results
|
||||
runSync(() -> {
|
||||
callback.run("SomeServer");
|
||||
});
|
||||
runSync(() -> {
|
||||
callback.run("SomeServer");
|
||||
});
|
||||
}
|
||||
|
||||
@ -66,6 +62,5 @@ public class PartyManager extends MiniPlugin
|
||||
|
||||
public void summon(Player player, String target)
|
||||
{
|
||||
new PartyRedisLocate(_serverName, player.getName(), target, LocateType.TRANSFER);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.party.redis.locate;
|
||||
package mineplex.core.party.redis;
|
||||
|
||||
/**
|
||||
* Simplifies the location callback method
|
@ -1,35 +0,0 @@
|
||||
package mineplex.core.party.redis;
|
||||
|
||||
import mineplex.core.party.Party;
|
||||
import mineplex.serverdata.commands.ServerCommand;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Redis party data
|
||||
*/
|
||||
public class PartyData extends ServerCommand
|
||||
{
|
||||
|
||||
private String _owner;
|
||||
private List<String> _members;
|
||||
|
||||
public PartyData(Party party)
|
||||
{
|
||||
_owner = party.getOwner();
|
||||
_members = party.getMembers();
|
||||
}
|
||||
|
||||
public String getOwner()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
public List<String> getMembers()
|
||||
{
|
||||
return _members;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package mineplex.core.party.redis;
|
||||
|
||||
import mineplex.core.party.PartyManager;
|
||||
import mineplex.serverdata.commands.CommandCallback;
|
||||
import mineplex.serverdata.commands.ServerCommand;
|
||||
|
||||
/**
|
||||
* Handler for party redis data
|
||||
*/
|
||||
public class PartyDataHandler implements CommandCallback
|
||||
{
|
||||
|
||||
private final String _currentServer;
|
||||
private final PartyManager _plugin;
|
||||
|
||||
public PartyDataHandler(String thisServer, PartyManager partyManager)
|
||||
{
|
||||
_currentServer = thisServer;
|
||||
_plugin = partyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ServerCommand command)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public String getCurrentServer()
|
||||
{
|
||||
return _currentServer;
|
||||
}
|
||||
|
||||
public PartyManager getPlugin()
|
||||
{
|
||||
return _plugin;
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package mineplex.core.party.redis;
|
||||
|
||||
import mineplex.core.party.PartyManager;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
/**
|
||||
* Redis system for Parties
|
||||
*/
|
||||
public class PartyRedisManager
|
||||
{
|
||||
protected static final String CHANNEL_BASE = "party-pubsub";
|
||||
protected static final String PLAYER_REQUEST_CHANNEL = "mineplex-player-locater";
|
||||
|
||||
private PartyManager _plugin;
|
||||
private JedisPool _writePool;
|
||||
private JedisPool _readPool;
|
||||
private String _channel;
|
||||
private String _serverName;
|
||||
|
||||
public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_serverName = serverName;
|
||||
_readPool = readPool;
|
||||
_writePool = writePool;
|
||||
_channel = CHANNEL_BASE + "-" + serverName;
|
||||
|
||||
plugin.runAsync(() -> {
|
||||
try (Jedis jedis = readPool.getResource())
|
||||
{
|
||||
jedis.subscribe(new PartyRedisListener(), _channel);
|
||||
jedis.subscribe(new PlayerFinderListener(), PLAYER_REQUEST_CHANNEL);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void findPlayer(String player)
|
||||
{
|
||||
_plugin.runAsync(() -> {
|
||||
try (Jedis jedis = _writePool.getResource())
|
||||
{
|
||||
jedis.publish(PLAYER_REQUEST_CHANNEL, player + ":" + _serverName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void publish(String message, String server)
|
||||
{
|
||||
_plugin.runAsync(() -> {
|
||||
try (Jedis jedis = _writePool.getResource())
|
||||
{
|
||||
jedis.publish(CHANNEL_BASE + "-" + server, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package mineplex.core.party.redis.locate;
|
||||
|
||||
import mineplex.serverdata.commands.ServerCommand;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PartyRedisLocate extends ServerCommand
|
||||
{
|
||||
private String _sender;
|
||||
private String _sendingServer;
|
||||
private String _target;
|
||||
private UUID _uuid = UUID.randomUUID();
|
||||
private LocateType _locateType;
|
||||
|
||||
public PartyRedisLocate(String sendingServer, String sender, String target, LocateType locateType)
|
||||
{
|
||||
_sender = sender;
|
||||
_target = target;
|
||||
_sendingServer = sendingServer;
|
||||
_locateType = locateType;
|
||||
}
|
||||
|
||||
public String getSender()
|
||||
{
|
||||
return _sender;
|
||||
}
|
||||
|
||||
public String getServer()
|
||||
{
|
||||
return _sendingServer;
|
||||
}
|
||||
|
||||
public String getTarget()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
public UUID getUUID()
|
||||
{
|
||||
return _uuid;
|
||||
}
|
||||
|
||||
public LocateType getLocateType()
|
||||
{
|
||||
return _locateType;
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package mineplex.core.party.redis.locate;
|
||||
|
||||
import mineplex.serverdata.commands.ServerCommand;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PartyRedisLocateCallback extends ServerCommand
|
||||
{
|
||||
private String _locatedPlayer;
|
||||
private String _server;
|
||||
private String _receivingPlayer;
|
||||
private UUID _uuid;
|
||||
private LocateType _locateType;
|
||||
private String _response;
|
||||
|
||||
public PartyRedisLocateCallback(PartyRedisLocate command, String server, String targetName, LocateType locateType, String response)
|
||||
{
|
||||
_uuid = command.getUUID();
|
||||
_receivingPlayer = command.getSender();
|
||||
_locatedPlayer = targetName;
|
||||
_server = server;
|
||||
_locateType = locateType;
|
||||
_response = response;
|
||||
setTargetServers(command.getServer());
|
||||
}
|
||||
|
||||
public String getLocatedPlayer()
|
||||
{
|
||||
return _locatedPlayer;
|
||||
}
|
||||
|
||||
public String getServer()
|
||||
{
|
||||
return _server;
|
||||
}
|
||||
|
||||
public String getReceivingPlayer()
|
||||
{
|
||||
return _receivingPlayer;
|
||||
}
|
||||
|
||||
public UUID getUUID()
|
||||
{
|
||||
return _uuid;
|
||||
}
|
||||
|
||||
public LocateType getLocateType()
|
||||
{
|
||||
return _locateType;
|
||||
}
|
||||
|
||||
public String getResponse()
|
||||
{
|
||||
return _response;
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
package mineplex.core.party.redis.locate;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.party.PartyManager;
|
||||
import mineplex.serverdata.commands.CommandCallback;
|
||||
import mineplex.serverdata.commands.ServerCommand;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent.Action;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PartyRedisLocateHandler implements CommandCallback
|
||||
{
|
||||
private PartyManager _plugin;
|
||||
private String _serverName;
|
||||
|
||||
public PartyRedisLocateHandler(PartyManager plugin)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_serverName = _plugin.getPlugin().getConfig().getString("serverstatus.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ServerCommand command)
|
||||
{
|
||||
if (command instanceof PartyRedisLocate)
|
||||
{
|
||||
PartyRedisLocate locate = (PartyRedisLocate) command;
|
||||
|
||||
Player target = Bukkit.getPlayerExact(locate.getTarget());
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
handleLocateRequest(locate, target);
|
||||
return;
|
||||
}
|
||||
if (command instanceof PartyRedisLocateCallback)
|
||||
{
|
||||
handleLocatedPlayer((PartyRedisLocateCallback) command);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleLocateRequest(PartyRedisLocate locate, Player player)
|
||||
{
|
||||
LocateType locateType = locate.getLocateType();
|
||||
switch (locateType)
|
||||
{
|
||||
case INVITE_INIT:
|
||||
//A requested invite
|
||||
player.sendMessage(F.main("Party", C.cYellow + locate.getServer() + C.cGray + " has invited you to their party"));
|
||||
sendAcceptOrDeny(player, locate.getSender());
|
||||
break;
|
||||
case INVITE_RESPONSE:
|
||||
break;
|
||||
case KICK:
|
||||
break;
|
||||
case LORE:
|
||||
break;
|
||||
case TRANSFER:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void handleLocatedPlayer(PartyRedisLocateCallback command)
|
||||
{
|
||||
LocateType locateType = command.getLocateType();
|
||||
switch (locateType)
|
||||
{
|
||||
case INVITE_INIT:
|
||||
break;
|
||||
case INVITE_RESPONSE:
|
||||
break;
|
||||
case KICK:
|
||||
break;
|
||||
case LORE:
|
||||
break;
|
||||
case TRANSFER:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendAcceptOrDeny(Player player, String arg)
|
||||
{
|
||||
TextComponent textComponent = new TextComponent(F.main("Party", "Click one: "));
|
||||
|
||||
TextComponent accept = new TextComponent("ACCEPT");
|
||||
accept.setColor(ChatColor.GREEN);
|
||||
accept.setBold(true);
|
||||
accept.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party accept " + arg));
|
||||
accept.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
|
||||
new TextComponent("Click to run /party accept " + arg)
|
||||
}));
|
||||
|
||||
textComponent.addExtra(accept);
|
||||
textComponent.addExtra(" ");
|
||||
|
||||
TextComponent deny = new TextComponent("DENY");
|
||||
deny.setColor(ChatColor.RED);
|
||||
deny.setBold(true);
|
||||
deny.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/party deny " + arg));
|
||||
deny.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent[]{
|
||||
new TextComponent("Click to run /party deny " + arg)
|
||||
}));
|
||||
|
||||
textComponent.addExtra(deny);
|
||||
|
||||
player.spigot().sendMessage(textComponent);
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,7 @@ import mineplex.core.common.util.C;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.party.PartyManager;
|
||||
import mineplex.core.party.redis.locate.LocateType;
|
||||
import mineplex.core.party.redis.LocateType;
|
||||
import mineplex.core.party.ui.Button;
|
||||
import mineplex.core.party.ui.Menu;
|
||||
import org.bukkit.DyeColor;
|
||||
|
Loading…
Reference in New Issue
Block a user