Post login Kick FIX

This commit is contained in:
JH3Y50N 2018-10-07 18:54:14 -03:00
parent a54911ba6c
commit 6beb53c2ec
3 changed files with 52 additions and 36 deletions

View File

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

View File

@ -10,6 +10,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
@ -98,18 +99,18 @@ public class bungee extends Plugin implements Listener {
} }
} }
List<String> lobbyes = new ArrayList<>(); List<String> lobbyes = new ArrayList<>();
List<String> logados = new ArrayList<>(); HashMap<String, Boolean> logados = new HashMap<String, Boolean>();
List<String> comandos = new ArrayList<>(); List<String> comandos = new ArrayList<>();
@EventHandler @EventHandler
public void onPluginMessage(PluginMessageEvent e){ public void onPluginMessage(PluginMessageEvent e){
if (e.getTag().equalsIgnoreCase("BungeeCord")) { if (e.getTag().equalsIgnoreCase("BungeeCord")) {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
try { try {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
String channel = in.readUTF(); String channel = in.readUTF();
if(channel.equals("JH_AuthMeBridge")){ if(channel.equals("JH_AuthMeBridge")){
String input = in.readUTF(); String input = in.readUTF();
if(isLogged(input))return; if(isLogged(input))return;
logados.add(input); logados.put(input, true);
} }
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
@ -119,18 +120,18 @@ public class bungee extends Plugin implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerLeave(PlayerDisconnectEvent event) { public void onPlayerLeave(PlayerDisconnectEvent event) {
if(logados.contains(event.getPlayer().getName())){ if(isLogged(event.getPlayer())){
logados.remove(event.getPlayer().getName()); logados.remove(event.getPlayer().getName());
} }
} }
@EventHandler(priority=EventPriority.LOWEST) @EventHandler(priority=EventPriority.LOWEST)
public void onChat(ChatEvent event) { public void onChat(ChatEvent event){
if (event.isCancelled())return; if (event.isCancelled())return;
if (!(event.getSender() instanceof ProxiedPlayer))return; if (!(event.getSender() instanceof ProxiedPlayer))return;
ProxiedPlayer player = (ProxiedPlayer) event.getSender(); ProxiedPlayer player = (ProxiedPlayer)event.getSender();
if(isLogged(player))return; if(isLogged(player))return;
if(event.isCommand()) { if(event.isCommand()){
String command = event.getMessage().split(" ")[0].toLowerCase(); String command = event.getMessage().split(" ")[0].toLowerCase();
if(comandos.contains(command)){ if(comandos.contains(command)){
return; return;
@ -145,20 +146,19 @@ public class bungee extends Plugin implements Listener {
@EventHandler @EventHandler
public void onServerSwitch(ServerSwitchEvent event) { public void onServerSwitch(ServerSwitchEvent event) {
if(isLogged(event.getPlayer())){ if(isLogged(event.getPlayer())){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(stream);
try { try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(stream);
out.writeUTF("JH_AuthMeBridge"); out.writeUTF("JH_AuthMeBridge");
out.writeUTF(event.getPlayer().getName()); out.writeUTF(event.getPlayer().getName());
event.getPlayer().getServer().sendData("BungeeCord", stream.toByteArray());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
event.getPlayer().getServer().sendData("BungeeCord", stream.toByteArray());
return; return;
} }
String server = event.getPlayer().getServer().getInfo().getName(); if(!lobbyes.contains(event.getPlayer().getServer().getInfo().getName().toLowerCase())) {
if(!lobbyes.contains(server.toLowerCase())) {
TextComponent kickReason = new TextComponent(ChatColor.translateAlternateColorCodes('&', getConfig().getString("KickMessageNeedLogged"))); TextComponent kickReason = new TextComponent(ChatColor.translateAlternateColorCodes('&', getConfig().getString("KickMessageNeedLogged")));
kickReason.setColor(ChatColor.RED); kickReason.setColor(ChatColor.RED);
event.getPlayer().disconnect(kickReason); event.getPlayer().disconnect(kickReason);
@ -166,16 +166,10 @@ public class bungee extends Plugin implements Listener {
} }
public Boolean isLogged(ProxiedPlayer player){ public Boolean isLogged(ProxiedPlayer player){
if(logados.contains(player.getName())){ return logados.containsKey(player.getName());
return true;
}
return false;
} }
public Boolean isLogged(String player){ public Boolean isLogged(String player){
if(logados.contains(player)){ return logados.containsKey(player);
return true;
}
return false;
} }
} }

View File

@ -5,11 +5,14 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener; import org.bukkit.plugin.messaging.PluginMessageListener;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -21,32 +24,40 @@ public class spigot extends JavaPlugin implements Listener, PluginMessageListene
@Override @Override
public void onEnable() { public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this); Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
} }
@EventHandler @EventHandler
public void onLogin(LoginEvent event){ public void onLogin(LoginEvent event){
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try { try {
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
out.writeUTF("JH_AuthMeBridge"); out.writeUTF("JH_AuthMeBridge");
out.writeUTF(event.getPlayer().getName()); out.writeUTF(event.getPlayer().getName());
Bukkit.getServer().sendPluginMessage(this, "BungeeCord", b.toByteArray());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
Bukkit.getServer().sendPluginMessage(this, "BungeeCord", b.toByteArray());
} }
@EventHandler
public void onQuit(PlayerQuitEvent event){
if(isLogged(event.getPlayer())){
logados.remove(event.getPlayer().getName());
}
}
@Override @Override
public void onPluginMessageReceived(String channel, Player p, byte[] message) { public void onPluginMessageReceived(String channel, Player p, byte[] message) {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
try { try {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
String subchannel = in.readUTF(); String subchannel = in.readUTF();
if(subchannel.equals("JH_AuthMeBridge")){ if(subchannel.equals("JH_AuthMeBridge")){
String input = in.readUTF(); String input = in.readUTF();
if(isLogged(input))return;
Player player = Bukkit.getPlayer(input); Player player = Bukkit.getPlayer(input);
if(player != null && player.isOnline()){ if(player != null && player.isOnline()){
new BukkitRunnable() new BukkitRunnable()
{ {
public void run() public void run()
@ -54,6 +65,7 @@ public class spigot extends JavaPlugin implements Listener, PluginMessageListene
// For older versions of Authme // For older versions of Authme
// fr.xephi.authme.api.API.forceLogin(player); // fr.xephi.authme.api.API.forceLogin(player);
fr.xephi.authme.api.v3.AuthMeApi.getInstance().forceLogin(player); fr.xephi.authme.api.v3.AuthMeApi.getInstance().forceLogin(player);
logados.add(player.getName());
} }
}.runTaskLater(this, 20L); }.runTaskLater(this, 20L);
} }
@ -62,4 +74,14 @@ public class spigot extends JavaPlugin implements Listener, PluginMessageListene
e.printStackTrace(); e.printStackTrace();
} }
} }
List<String> logados = new ArrayList<>();
public Boolean isLogged(Player player){
return logados.contains(player.getName());
}
public Boolean isLogged(String player){
return logados.contains(player);
}
} }