正如标题所说,我需要一种方法(无论是否复杂)来创建一个将请求包发送到服务器的getData()方法>收到我已经有系统设置的消息,但我有一个问题,我只能在PluginMessageReceiveEvent
得到结果这里有我的代码和解释:
public String requestData(String path) {
SocketUtils.sendData("REQUEST|" + p.getPlayer().getUniqueId() + "|" + path, "playerconfig", "BUNGEE");
return /*Need to get data from the plugin message to here*/;
}
@EventHandler
public void onPluginMessageReceive(PluginMessageReceiveEvent e) {
if (e.getChannel().equalsIgnoreCase("playerconfig")) {
String[] args = e.getMessage().split("\\|");
String uuid = args[0];
String path = args[1];//Maybe a HashMap<Path, Data> but that would make the requestData() result return null because you don't get the data instantly.
String data = args[2].replace("_", " ");
if (uuid.equals(p.getPlayer().getUniqueId() + "")) {
return data; //I need to get this result on request data method.
}
}
}
答案 0 :(得分:1)
一个简单的解决方案是wait
锁定requestData
,并在onPluginMessageReceive
中通知锁定。像这样:
synchronized(this) {
wait();
}
在你的接收方法中:
synchronized(this) {
notifyAll();
}
使数据成为该类的成员字段。
注意异常处理和语法错误。