Use Plugin:Subchannel for channel messages

This is required to follow 1.13 spec.
(Related #216, #215)
This commit is contained in:
games647
2018-07-23 14:11:40 +02:00
parent c172b1ec84
commit 6604cca8bd
8 changed files with 42 additions and 22 deletions

View File

@ -20,7 +20,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>false</shadedArtifactAttached>

View File

@ -11,6 +11,7 @@ import com.github.games647.fastlogin.bukkit.task.DelayedAuthHook;
import com.github.games647.fastlogin.core.CommonUtil;
import com.github.games647.fastlogin.core.PremiumStatus;
import com.github.games647.fastlogin.core.message.ChannelMessage;
import com.github.games647.fastlogin.core.message.LoginActionMessage;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
import com.google.common.io.ByteArrayDataOutput;
@ -29,6 +30,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageRecipient;
import org.slf4j.Logger;
import static com.github.games647.fastlogin.core.message.ChangePremiumMessage.CHANGE_CHANNEL;
import static com.github.games647.fastlogin.core.message.SuccessMessage.SUCCESS_CHANNEL;
/**
* This plugin checks if a player has a paid account and if so tries to skip offline mode authentication.
*/
@ -66,9 +70,13 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
if (bungeeCord) {
setServerStarted();
//check for incoming messages from the bungeecord version of this plugin
getServer().getMessenger().registerIncomingPluginChannel(this, getName(), new BungeeListener(this));
getServer().getMessenger().registerOutgoingPluginChannel(this, getName());
// check for incoming messages from the bungeecord version of this plugin
String forceChannel = getName() + ':' + LoginActionMessage.FORCE_CHANNEL;
getServer().getMessenger().registerIncomingPluginChannel(this, forceChannel, new BungeeListener(this));
// outgoing
getServer().getMessenger().registerOutgoingPluginChannel(this, getName() + ':' + SUCCESS_CHANNEL);
getServer().getMessenger().registerOutgoingPluginChannel(this, getName() + ':' + CHANGE_CHANNEL);
} else {
if (!core.setupDatabase()) {
setEnabled(false);
@ -167,10 +175,9 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
public void sendPluginMessage(PluginMessageRecipient player, ChannelMessage message) {
if (player != null) {
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
dataOutput.writeUTF(message.getChannelName());
message.writeTo(dataOutput);
player.sendPluginMessage(this, this.getName(), dataOutput.toByteArray());
String channel = this.getName() + ':' + message.getChannelName();
player.sendPluginMessage(this, channel, dataOutput.toByteArray());
}
}

View File

@ -21,7 +21,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>false</shadedArtifactAttached>

View File

@ -4,7 +4,9 @@ import com.github.games647.fastlogin.bungee.hook.BungeeAuthHook;
import com.github.games647.fastlogin.bungee.listener.ConnectListener;
import com.github.games647.fastlogin.bungee.listener.MessageListener;
import com.github.games647.fastlogin.core.CommonUtil;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.ChannelMessage;
import com.github.games647.fastlogin.core.message.SuccessMessage;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
import com.google.common.collect.MapMaker;
@ -50,8 +52,9 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
getProxy().getPluginManager().registerListener(this, new ConnectListener(this));
getProxy().getPluginManager().registerListener(this, new MessageListener(this));
//this is required to listen to messages from the server
getProxy().registerChannel(getName());
//this is required to listen to incoming messages from the server
getProxy().registerChannel(getName() + ':' + ChangePremiumMessage.CHANGE_CHANNEL);
getProxy().registerChannel(getName() + ':' + SuccessMessage.SUCCESS_CHANNEL);
registerHook();
}
@ -82,10 +85,8 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
public void sendPluginMessage(Server server, ChannelMessage message) {
if (server != null) {
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
dataOutput.writeUTF(message.getChannelName());
message.writeTo(dataOutput);
server.sendData(core.getPlugin().getName(), dataOutput.toByteArray());
server.sendData(core.getPlugin().getName() + ':' + message.getChannelName(), dataOutput.toByteArray());
}
}

View File

@ -5,6 +5,7 @@ import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.bungee.task.AsyncToggleMessage;
import com.github.games647.fastlogin.core.StoredProfile;
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
import com.github.games647.fastlogin.core.message.SuccessMessage;
import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
@ -24,14 +25,20 @@ public class MessageListener implements Listener {
private final FastLoginBungee plugin;
private final String successChannel;
private final String changeChannel;
public MessageListener(FastLoginBungee plugin) {
this.plugin = plugin;
this.successChannel = plugin.getName() + ':' + SuccessMessage.SUCCESS_CHANNEL;
this.changeChannel = plugin.getName() + ':' + ChangePremiumMessage.CHANGE_CHANNEL;
}
@EventHandler
public void onPluginMessage(PluginMessageEvent pluginMessageEvent) {
String channel = pluginMessageEvent.getTag();
if (pluginMessageEvent.isCancelled() || !plugin.getName().equals(channel)) {
if (pluginMessageEvent.isCancelled() || !channel.startsWith(plugin.getName())) {
return;
}
@ -48,17 +55,16 @@ public class MessageListener implements Listener {
byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length);
ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> readMessage(forPlayer, data));
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> readMessage(forPlayer, channel, data));
}
private void readMessage(ProxiedPlayer forPlayer, byte[] data) {
private void readMessage(ProxiedPlayer forPlayer, String channel, byte[] data) {
FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core = plugin.getCore();
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
String subChannel = dataInput.readUTF();
if ("Success".equals(subChannel)) {
if (successChannel.equals(channel)) {
onSuccessMessage(forPlayer);
} else if ("ChangeStatus".equals(subChannel)) {
} else if (changeChannel.equals(channel)) {
ChangePremiumMessage changeMessage = new ChangePremiumMessage();
changeMessage.readFrom(dataInput);

View File

@ -5,6 +5,8 @@ import com.google.common.io.ByteArrayDataOutput;
public class ChangePremiumMessage implements ChannelMessage {
public static final String CHANGE_CHANNEL = "ChStatus";
private String playerName;
private boolean willEnable;
private boolean isSourceInvoker;
@ -33,7 +35,7 @@ public class ChangePremiumMessage implements ChannelMessage {
@Override
public String getChannelName() {
return "ChangeStatus";
return CHANGE_CHANNEL;
}
@Override

View File

@ -7,6 +7,8 @@ import java.util.UUID;
public class LoginActionMessage implements ChannelMessage {
public static final String FORCE_CHANNEL = "ForceAct";
private Type type;
private String playerName;
@ -60,7 +62,7 @@ public class LoginActionMessage implements ChannelMessage {
@Override
public String getChannelName() {
return "LoginAction";
return FORCE_CHANNEL;
}
@Override

View File

@ -5,9 +5,11 @@ import com.google.common.io.ByteArrayDataOutput;
public class SuccessMessage implements ChannelMessage {
public static final String SUCCESS_CHANNEL = "Success";
@Override
public String getChannelName() {
return "Success";
return SUCCESS_CHANNEL;
}
@Override