Merge the Bukkit and BungeeCord version together to a universal plugin

This commit is contained in:
games647 committed 2015-11-14 20:03:24 +01:00
1 parent c3f8e59a9a
commit f8c10d6890
30 files changed
+377 -354

No files matched your search

@@ -1,4 +1,4 @@
package com.github.games647.fastloginbungee;
package com.github.games647.fastlogin.bungee;
import com.google.common.collect.Sets;
@@ -10,7 +10,7 @@ import net.md_5.bungee.api.plugin.Plugin;
* BungeeCord version of FastLogin. This plugin keeps track
* on online mode connections.
*/
public class FastLogin extends Plugin {
public class FastLoginBungee extends Plugin {
private final Set<String> enabledPremium = Sets.newConcurrentHashSet();
@@ -19,8 +19,8 @@ public class FastLogin extends Plugin {
//events
getProxy().getPluginManager().registerListener(this, new PlayerConnectionListener(this));
//commands
getProxy().getPluginManager().registerCommand(this, new PremiumCommand(this));
//this is required to listen to messages from the server
getProxy().registerChannel(getDescription().getName());
}
/**
@@ -1,5 +1,6 @@
package com.github.games647.fastloginbungee;
package com.github.games647.fastlogin.bungee;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
@@ -21,9 +22,9 @@ import net.md_5.bungee.event.EventHandler;
*/
public class PlayerConnectionListener implements Listener {
private final FastLogin plugin;
private final FastLoginBungee plugin;
public PlayerConnectionListener(FastLogin plugin) {
public PlayerConnectionListener(FastLoginBungee plugin) {
this.plugin = plugin;
}
@@ -50,16 +51,16 @@ public class PlayerConnectionListener implements Listener {
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
//subchannel name
dataOutput.writeUTF("Checked");
dataOutput.writeUTF("CHECKED");
//Data is sent through a random player. We have to tell the Bukkit version of this plugin the target
dataOutput.writeUTF(player.getName());
//proxy identifier to check if it's a acceptable proxy
UUID proxyId = UUID.fromString(plugin.getProxy().getConfig().getUuid());
dataOutput.writeLong(proxyId.getMostSignificantBits());
dataOutput.writeLong(proxyId.getLeastSignificantBits());
//Data is sent through a random player. We have to tell the Bukkit version of this plugin the target
dataOutput.writeUTF(player.getName());
server.sendData(plugin.getDescription().getName(), dataOutput.toByteArray());
}
}
@@ -74,5 +75,16 @@ public class PlayerConnectionListener implements Listener {
//the client shouldn't be able to read the messages in order to know something about server internal states
//moreover the client shouldn't be able fake a running premium check by sending the result message
pluginMessageEvent.setCancelled(true);
//check if the message is sent from the server
if (Server.class.isAssignableFrom(pluginMessageEvent.getSender().getClass())) {
byte[] data = pluginMessageEvent.getData();
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
String subchannel = dataInput.readUTF();
if ("ACTIVE".equals(subchannel)) {
ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver();
plugin.getEnabledPremium().add(forPlayer.getName());
}
}
}
}
@@ -1,38 +0,0 @@
package com.github.games647.fastloginbungee;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
/**
* Let players activate the fastlogin method on a BungeeCord instance.
*/
public class PremiumCommand extends Command {
private final FastLogin plugin;
public PremiumCommand(FastLogin plugin) {
super(plugin.getDescription().getName()
, plugin.getDescription().getName() + ".command." + "premium"
, "prem" , "premium", "loginfast");
this.plugin = plugin;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (!(sender instanceof ProxiedPlayer)) {
sender.sendMessage(new ComponentBuilder("Only player can invoke this command")
.color(ChatColor.DARK_RED)
.create());
return;
}
plugin.getEnabledPremium().add(sender.getName());
sender.sendMessage(new ComponentBuilder("Added to the list of premium players")
.color(ChatColor.DARK_GREEN)
.create());
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
# project informations for BungeeCord
# This file will be prioritised over plugin.yml which can be also used for Bungee
# This make it easy to combine BungeeCord and Bukkit support in one plugin
name: ${project.name}
# ${...} will be automatically replaced by Maven
name: ${project.parent.name}
# ${-} will be automatically replaced by Maven
main: ${project.groupId}.${project.artifactId}.${project.name}
version: ${project.version}