commit a54911ba6cfa1236999318f5827fe0d278f42cbc Author: JH3Y50N Date: Sun Aug 26 07:56:17 2018 -0300 JH_AuthMeBridge 1.0.0 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..43ccfec --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..72d74da --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + JH_AuthMeBridge + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/bin/JH_AuthMeBridge/bungee$1.class b/bin/JH_AuthMeBridge/bungee$1.class new file mode 100644 index 0000000..fbd724c Binary files /dev/null and b/bin/JH_AuthMeBridge/bungee$1.class differ diff --git a/bin/JH_AuthMeBridge/bungee.class b/bin/JH_AuthMeBridge/bungee.class new file mode 100644 index 0000000..9e1c518 Binary files /dev/null and b/bin/JH_AuthMeBridge/bungee.class differ diff --git a/bin/JH_AuthMeBridge/spigot$1.class b/bin/JH_AuthMeBridge/spigot$1.class new file mode 100644 index 0000000..f3b2f94 Binary files /dev/null and b/bin/JH_AuthMeBridge/spigot$1.class differ diff --git a/bin/JH_AuthMeBridge/spigot.class b/bin/JH_AuthMeBridge/spigot.class new file mode 100644 index 0000000..d537a37 Binary files /dev/null and b/bin/JH_AuthMeBridge/spigot.class differ diff --git a/bungee.yml b/bungee.yml new file mode 100644 index 0000000..5d6a192 --- /dev/null +++ b/bungee.yml @@ -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 diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..62d1ea8 --- /dev/null +++ b/config.yml @@ -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" + diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..6f71b2c --- /dev/null +++ b/plugin.yml @@ -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] diff --git a/src/JH_AuthMeBridge/bungee.java b/src/JH_AuthMeBridge/bungee.java new file mode 100644 index 0000000..4f4b269 --- /dev/null +++ b/src/JH_AuthMeBridge/bungee.java @@ -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 lobbyes = new ArrayList<>(); + List logados = new ArrayList<>(); + List 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; + } +} diff --git a/src/JH_AuthMeBridge/spigot.java b/src/JH_AuthMeBridge/spigot.java new file mode 100644 index 0000000..318abe7 --- /dev/null +++ b/src/JH_AuthMeBridge/spigot.java @@ -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(); + } + } +}