mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 10:47:33 +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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.1.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<shadedArtifactAttached>false</shadedArtifactAttached>
|
<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.CommonUtil;
|
||||||
import com.github.games647.fastlogin.core.PremiumStatus;
|
import com.github.games647.fastlogin.core.PremiumStatus;
|
||||||
import com.github.games647.fastlogin.core.message.ChannelMessage;
|
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.FastLoginCore;
|
||||||
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
@ -29,6 +30,9 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import org.bukkit.plugin.messaging.PluginMessageRecipient;
|
import org.bukkit.plugin.messaging.PluginMessageRecipient;
|
||||||
import org.slf4j.Logger;
|
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.
|
* 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) {
|
if (bungeeCord) {
|
||||||
setServerStarted();
|
setServerStarted();
|
||||||
|
|
||||||
//check for incoming messages from the bungeecord version of this plugin
|
// check for incoming messages from the bungeecord version of this plugin
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, getName(), new BungeeListener(this));
|
String forceChannel = getName() + ':' + LoginActionMessage.FORCE_CHANNEL;
|
||||||
getServer().getMessenger().registerOutgoingPluginChannel(this, getName());
|
getServer().getMessenger().registerIncomingPluginChannel(this, forceChannel, new BungeeListener(this));
|
||||||
|
|
||||||
|
// outgoing
|
||||||
|
getServer().getMessenger().registerOutgoingPluginChannel(this, getName() + ':' + SUCCESS_CHANNEL);
|
||||||
|
getServer().getMessenger().registerOutgoingPluginChannel(this, getName() + ':' + CHANGE_CHANNEL);
|
||||||
} else {
|
} else {
|
||||||
if (!core.setupDatabase()) {
|
if (!core.setupDatabase()) {
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
@ -167,10 +175,9 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
|
|||||||
public void sendPluginMessage(PluginMessageRecipient player, ChannelMessage message) {
|
public void sendPluginMessage(PluginMessageRecipient player, ChannelMessage message) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||||
dataOutput.writeUTF(message.getChannelName());
|
|
||||||
|
|
||||||
message.writeTo(dataOutput);
|
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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.1.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<shadedArtifactAttached>false</shadedArtifactAttached>
|
<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.ConnectListener;
|
||||||
import com.github.games647.fastlogin.bungee.listener.MessageListener;
|
import com.github.games647.fastlogin.bungee.listener.MessageListener;
|
||||||
import com.github.games647.fastlogin.core.CommonUtil;
|
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.ChannelMessage;
|
||||||
|
import com.github.games647.fastlogin.core.message.SuccessMessage;
|
||||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||||
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
||||||
import com.google.common.collect.MapMaker;
|
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 ConnectListener(this));
|
||||||
getProxy().getPluginManager().registerListener(this, new MessageListener(this));
|
getProxy().getPluginManager().registerListener(this, new MessageListener(this));
|
||||||
|
|
||||||
//this is required to listen to messages from the server
|
//this is required to listen to incoming messages from the server
|
||||||
getProxy().registerChannel(getName());
|
getProxy().registerChannel(getName() + ':' + ChangePremiumMessage.CHANGE_CHANNEL);
|
||||||
|
getProxy().registerChannel(getName() + ':' + SuccessMessage.SUCCESS_CHANNEL);
|
||||||
|
|
||||||
registerHook();
|
registerHook();
|
||||||
}
|
}
|
||||||
@ -82,10 +85,8 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
|
|||||||
public void sendPluginMessage(Server server, ChannelMessage message) {
|
public void sendPluginMessage(Server server, ChannelMessage message) {
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||||
dataOutput.writeUTF(message.getChannelName());
|
|
||||||
|
|
||||||
message.writeTo(dataOutput);
|
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.bungee.task.AsyncToggleMessage;
|
||||||
import com.github.games647.fastlogin.core.StoredProfile;
|
import com.github.games647.fastlogin.core.StoredProfile;
|
||||||
import com.github.games647.fastlogin.core.message.ChangePremiumMessage;
|
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.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
@ -24,14 +25,20 @@ public class MessageListener implements Listener {
|
|||||||
|
|
||||||
private final FastLoginBungee plugin;
|
private final FastLoginBungee plugin;
|
||||||
|
|
||||||
|
private final String successChannel;
|
||||||
|
private final String changeChannel;
|
||||||
|
|
||||||
public MessageListener(FastLoginBungee plugin) {
|
public MessageListener(FastLoginBungee plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
this.successChannel = plugin.getName() + ':' + SuccessMessage.SUCCESS_CHANNEL;
|
||||||
|
this.changeChannel = plugin.getName() + ':' + ChangePremiumMessage.CHANGE_CHANNEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPluginMessage(PluginMessageEvent pluginMessageEvent) {
|
public void onPluginMessage(PluginMessageEvent pluginMessageEvent) {
|
||||||
String channel = pluginMessageEvent.getTag();
|
String channel = pluginMessageEvent.getTag();
|
||||||
if (pluginMessageEvent.isCancelled() || !plugin.getName().equals(channel)) {
|
if (pluginMessageEvent.isCancelled() || !channel.startsWith(plugin.getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,17 +55,16 @@ public class MessageListener implements Listener {
|
|||||||
byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length);
|
byte[] data = Arrays.copyOf(pluginMessageEvent.getData(), pluginMessageEvent.getData().length);
|
||||||
ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
|
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();
|
FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core = plugin.getCore();
|
||||||
|
|
||||||
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
|
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
|
||||||
String subChannel = dataInput.readUTF();
|
if (successChannel.equals(channel)) {
|
||||||
if ("Success".equals(subChannel)) {
|
|
||||||
onSuccessMessage(forPlayer);
|
onSuccessMessage(forPlayer);
|
||||||
} else if ("ChangeStatus".equals(subChannel)) {
|
} else if (changeChannel.equals(channel)) {
|
||||||
ChangePremiumMessage changeMessage = new ChangePremiumMessage();
|
ChangePremiumMessage changeMessage = new ChangePremiumMessage();
|
||||||
changeMessage.readFrom(dataInput);
|
changeMessage.readFrom(dataInput);
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import com.google.common.io.ByteArrayDataOutput;
|
|||||||
|
|
||||||
public class ChangePremiumMessage implements ChannelMessage {
|
public class ChangePremiumMessage implements ChannelMessage {
|
||||||
|
|
||||||
|
public static final String CHANGE_CHANNEL = "ChStatus";
|
||||||
|
|
||||||
private String playerName;
|
private String playerName;
|
||||||
private boolean willEnable;
|
private boolean willEnable;
|
||||||
private boolean isSourceInvoker;
|
private boolean isSourceInvoker;
|
||||||
@ -33,7 +35,7 @@ public class ChangePremiumMessage implements ChannelMessage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getChannelName() {
|
public String getChannelName() {
|
||||||
return "ChangeStatus";
|
return CHANGE_CHANNEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,8 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class LoginActionMessage implements ChannelMessage {
|
public class LoginActionMessage implements ChannelMessage {
|
||||||
|
|
||||||
|
public static final String FORCE_CHANNEL = "ForceAct";
|
||||||
|
|
||||||
private Type type;
|
private Type type;
|
||||||
|
|
||||||
private String playerName;
|
private String playerName;
|
||||||
@ -60,7 +62,7 @@ public class LoginActionMessage implements ChannelMessage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getChannelName() {
|
public String getChannelName() {
|
||||||
return "LoginAction";
|
return FORCE_CHANNEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,9 +5,11 @@ import com.google.common.io.ByteArrayDataOutput;
|
|||||||
|
|
||||||
public class SuccessMessage implements ChannelMessage {
|
public class SuccessMessage implements ChannelMessage {
|
||||||
|
|
||||||
|
public static final String SUCCESS_CHANNEL = "Success";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getChannelName() {
|
public String getChannelName() {
|
||||||
return "Success";
|
return SUCCESS_CHANNEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user