Added BungeeCord support

This commit is contained in:
games647
2015-11-13 22:46:38 +01:00
parent 834818bb7a
commit c3f8e59a9a
16 changed files with 527 additions and 78 deletions
@@ -0,0 +1,34 @@
package com.github.games647.fastloginbungee;
import com.google.common.collect.Sets;
import java.util.Set;
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 {
private final Set<String> enabledPremium = Sets.newConcurrentHashSet();
@Override
public void onEnable() {
//events
getProxy().getPluginManager().registerListener(this, new PlayerConnectionListener(this));
//commands
getProxy().getPluginManager().registerCommand(this, new PremiumCommand(this));
}
/**
* A set of players who want to use fastlogin
*
* @return all player which want to be in onlinemode
*/
public Set<String> getEnabledPremium() {
return enabledPremium;
}
}
@@ -0,0 +1,78 @@
package com.github.games647.fastloginbungee;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import java.util.UUID;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.PreLoginEvent;
import net.md_5.bungee.api.event.ServerConnectedEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
/**
* Enables online mode logins for specified users and sends
* plugin message to the Bukkit version of this plugin in
* order to clear that the connection is online mode.
*/
public class PlayerConnectionListener implements Listener {
private final FastLogin plugin;
public PlayerConnectionListener(FastLogin plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPreLogin(PreLoginEvent preLoginEvent) {
if (preLoginEvent.isCancelled()) {
return;
}
PendingConnection connection = preLoginEvent.getConnection();
String username = connection.getName();
//just enable it for activated users
if (plugin.getEnabledPremium().contains(username)) {
connection.setOnlineMode(true);
}
}
@EventHandler
public void onServerConnected(ServerConnectedEvent serverConnectedEvent) {
ProxiedPlayer player = serverConnectedEvent.getPlayer();
//send message even when the online mode is activated by default
if (player.getPendingConnection().isOnlineMode()) {
Server server = serverConnectedEvent.getServer();
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
//subchannel name
dataOutput.writeUTF("Checked");
//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());
}
}
@EventHandler
public void onPluginMessage(PluginMessageEvent pluginMessageEvent) {
String channel = pluginMessageEvent.getTag();
if (pluginMessageEvent.isCancelled() || !plugin.getDescription().getName().equals(channel)) {
return;
}
//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);
}
}
@@ -0,0 +1,38 @@
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());
}
}
+12
View File
@@ -0,0 +1,12 @@
# 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
main: ${project.groupId}.${project.artifactId}.${project.name}
version: ${project.version}
author: games647, http://github.com/games647/FastLogin/graphs/contributors
description: |
${project.description}