JH_AuthMeBridge 1.0.0

This commit is contained in:
JH3Y50N 2018-08-26 07:56:17 -03:00
commit a54911ba6c
12 changed files with 314 additions and 0 deletions

9
.classpath Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="C:/Users/jheys/Downloads/AuthMe.jar"/>
<classpathentry kind="lib" path="C:/Users/jheys/Documents/bungeecord/bungeecord.jar"/>
<classpathentry kind="lib" path="C:/Users/jheys/Documents/MC - Plugins/PaperSpigot-1.8.8.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>JH_AuthMeBridge</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

6
bungee.yml Normal file
View File

@ -0,0 +1,6 @@
name: JH_AuthMeBridge
main: JH_AuthMeBridge.bungee
version: 1.0
website: www.jhdev.xyz
author: Jheyson
description: Um plugin para ligaro AuthMe com seu bungeecord

18
config.yml Normal file
View File

@ -0,0 +1,18 @@
# Login and Registration Servers, players can enter these servers without being logged in
Lobbyes:
- Lobby
# commands that can be used without being logged in
CommandsAllowed:
- "/login"
- "/register"
# Attempting to execute commands without being logged in
NeedLoginToEnter: "&cYou must be logged in to this"
# Need to be logged in to connect to other servers? recommend true
NeedLoginServerChange: true
# Trying to change server "NPC, Command, and others" without being logged in
KickMessageNeedLogged: "&cYou must be logged in to enter this server"

7
plugin.yml Normal file
View File

@ -0,0 +1,7 @@
name: JH_AuthMeBridge
main: JH_AuthMeBridge.spigot
version: 1.0
website: www.jhdev.xyz
author: Jheyson
description: Um plugin para ligaro AuthMe com seu bungeecord
depend: [AuthMe]

View File

@ -0,0 +1,181 @@
package JH_AuthMeBridge;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.ServerSwitchEvent;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.YamlConfiguration;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
public class bungee extends Plugin implements Listener {
@Override
public void onEnable() {
getProxy().getPluginManager().registerListener(this, this);
try {
loadConfig();
} catch (IOException e) {
e.printStackTrace();
}
getProxy().getPluginManager().registerCommand(this, new Command("jh_authmebridge") {
@Override
public void execute(CommandSender sender, String[] args) {
if(!sender.hasPermission("jh_authmebridge.reload")){
sender.sendMessage(new TextComponent("§cYou do not have permission to run this command!"));
return;
}
try {
loadConfig();
sender.sendMessage(new TextComponent("§aSuccessfully reloaded configuration"));
} catch (IOException e) {
sender.sendMessage(new TextComponent("§aError loading configuration errors were shown in console"));
e.printStackTrace();
}
}
});
System.out.println("[JH_AuthMeBridge] It started successfully.");
}
Configuration config;
private void loadConfig() throws IOException{
if(!getDataFolder().exists()){
getDataFolder().mkdir();
}
File file = new File(getDataFolder(), "config.yml");
if(!file.exists()){
file.createNewFile();
try (InputStream in = getResourceAsStream("config.yml");
OutputStream out = new FileOutputStream(file)) {
ByteStreams.copy(in, out);
}
}
config = YamlConfiguration.getProvider(YamlConfiguration.class).load(file);
comandos.clear();
lobbyes.clear();
for(String s : getConfig().getStringList("CommandsAllowed")){
comandos.add(s.toLowerCase());
}
for(String s : getConfig().getStringList("Lobbyes")){
lobbyes.add(s.toLowerCase());
}
}
private Configuration getConfig()
{
return config;
}
public void saveConfig(String config){
File file = new File(getDataFolder(), "config.yml");
try {
YamlConfiguration.getProvider(YamlConfiguration.class).save(getConfig(), file);
} catch (IOException e) {
e.printStackTrace();
}
}
List<String> lobbyes = new ArrayList<>();
List<String> logados = new ArrayList<>();
List<String> comandos = new ArrayList<>();
@EventHandler
public void onPluginMessage(PluginMessageEvent e){
if (e.getTag().equalsIgnoreCase("BungeeCord")) {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
try {
String channel = in.readUTF();
if(channel.equals("JH_AuthMeBridge")){
String input = in.readUTF();
if(isLogged(input))return;
logados.add(input);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
@EventHandler
public void onPlayerLeave(PlayerDisconnectEvent event) {
if(logados.contains(event.getPlayer().getName())){
logados.remove(event.getPlayer().getName());
}
}
@EventHandler(priority=EventPriority.LOWEST)
public void onChat(ChatEvent event) {
if (event.isCancelled())return;
if (!(event.getSender() instanceof ProxiedPlayer))return;
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
if(isLogged(player))return;
if(event.isCommand()) {
String command = event.getMessage().split(" ")[0].toLowerCase();
if(comandos.contains(command)){
return;
}
}
if(!isLogged(player)){
event.setCancelled(true);
TextComponent message = new TextComponent(ChatColor.translateAlternateColorCodes('&', getConfig().getString("NeedLoginToEnter")));
player.sendMessage(message);
}
}
@EventHandler
public void onServerSwitch(ServerSwitchEvent event) {
if(isLogged(event.getPlayer())){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(stream);
try {
out.writeUTF("JH_AuthMeBridge");
out.writeUTF(event.getPlayer().getName());
} catch (IOException e) {
e.printStackTrace();
}
event.getPlayer().getServer().sendData("BungeeCord", stream.toByteArray());
return;
}
String server = event.getPlayer().getServer().getInfo().getName();
if(!lobbyes.contains(server.toLowerCase())) {
TextComponent kickReason = new TextComponent(ChatColor.translateAlternateColorCodes('&', getConfig().getString("KickMessageNeedLogged")));
kickReason.setColor(ChatColor.RED);
event.getPlayer().disconnect(kickReason);
}
}
public Boolean isLogged(ProxiedPlayer player){
if(logados.contains(player.getName())){
return true;
}
return false;
}
public Boolean isLogged(String player){
if(logados.contains(player)){
return true;
}
return false;
}
}

View File

@ -0,0 +1,65 @@
package JH_AuthMeBridge;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.bukkit.scheduler.BukkitRunnable;
import fr.xephi.authme.events.LoginEvent;
public class spigot extends JavaPlugin implements Listener, PluginMessageListener {
@Override
public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this);
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
}
@EventHandler
public void onLogin(LoginEvent event){
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try {
out.writeUTF("JH_AuthMeBridge");
out.writeUTF(event.getPlayer().getName());
} catch (IOException e) {
e.printStackTrace();
}
Bukkit.getServer().sendPluginMessage(this, "BungeeCord", b.toByteArray());
}
@Override
public void onPluginMessageReceived(String channel, Player p, byte[] message) {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
try {
String subchannel = in.readUTF();
if(subchannel.equals("JH_AuthMeBridge")){
String input = in.readUTF();
Player player = Bukkit.getPlayer(input);
if(player != null && player.isOnline()){
new BukkitRunnable()
{
public void run()
{
// For older versions of Authme
// fr.xephi.authme.api.API.forceLogin(player);
fr.xephi.authme.api.v3.AuthMeApi.getInstance().forceLogin(player);
}
}.runTaskLater(this, 20L);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}