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
+99
View File
@@ -0,0 +1,99 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.games647</groupId>
<!--This have to be in lowercase because it's used by plugin.yml-->
<artifactId>fastloginbungee</artifactId>
<packaging>jar</packaging>
<name>FastLogin</name>
<version>0.1</version>
<inceptionYear>2015</inceptionYear>
<url>https://github.com/games647/FastLogin</url>
<description>
Automatically logins premium (paid accounts) player on a offline mode server
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--Possibility to deploy directly to the plugins folder-->
<outputDir>${basedir}/target</outputDir>
</properties>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/games647/FastLogin/issues</url>
</issueManagement>
<scm>
<url>https://github.com/games647/FastLogin</url>
<connection>scm:git:git://github.com/games647/FastLogin.git</connection>
<developerConnection>scm:git:ssh://git@github.com:games647/FastLogin.git</developerConnection>
</scm>
<build>
<defaultGoal>install</defaultGoal>
<!--Just use the project name to replace an old version of the plugin if the user does only copy-paste-->
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<!--false means actual true http://jira.codehaus.org/browse/MCOMPILER-209-->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>${outputDir}</outputDirectory>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<!--Replace variables-->
<filtering>true</filtering>
</resource>
<!--Add the license to jar in order to see it in the final jar-->
<resource>
<directory>${basedir}</directory>
<includes>
<include>LICENSE</include>
</includes>
</resource>
</resources>
</build>
<repositories>
<!-- BungeeCord -->
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.8-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -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}