mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
Use Plugin:Subchannel for channel messages
This is required to follow 1.13 spec. (Related #216, #215)
This commit is contained in:
@ -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>
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user