Skip to content

Instantly share code, notes, and snippets.

@SilverCory
Last active January 6, 2016 15:22
Show Gist options
  • Save SilverCory/b94a29b87e5aae39d8c1 to your computer and use it in GitHub Desktop.
Save SilverCory/b94a29b87e5aae39d8c1 to your computer and use it in GitHub Desktop.
package co.ryred.fuckoff;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.locks.ReadWriteLock;
import com.google.common.base.Charsets;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
public class FuckOffPlugin extends Plugin implements Listener {
@Override
public void onEnable() {
getProxy().getPluginManager().registerListener(this, this);
}
@SuppressWarnings({ "unchecked" })
@EventHandler( priority = Byte.MAX_VALUE )
public void onProxyLeave( PlayerDisconnectEvent e ) {
UserConnection uc = ((UserConnection)e.getPlayer());
final String name = uc.getName();
uc.disconnect( "You quit the server." );
getLogger().info("Forcing \"" + name + "\" to fuck off.");
ReadWriteLock connectionLock = null;
try {
Field connectionLockField = BungeeCord.class.getDeclaredField("connectionLock");
connectionLockField.setAccessible(true);
connectionLock = (ReadWriteLock) connectionLockField.get(getProxy());
} catch( Exception ex ) {
ex.printStackTrace();
getLogger().warning("Error on the read write lock.");
}
try {
if(connectionLock != null) connectionLock.writeLock().lock();
Field connectionsField = BungeeCord.class.getDeclaredField("connections");
connectionsField.setAccessible(true);
Map<String, UserConnection> connections = (Map<String, UserConnection>) connectionsField.get(getProxy());
connections.remove( name );
connectionsField.setAccessible(false);
if(connectionLock != null) connectionLock.writeLock().unlock();
} catch ( Exception ex ) {
ex.printStackTrace();
getLogger().warning("Error on name removal.");
}
try {
if(connectionLock != null) connectionLock.writeLock().lock();
Field connectionsField = BungeeCord.class.getDeclaredField("connectionsByOfflineUUID");
connectionsField.setAccessible(true);
Map<UUID, UserConnection> connections = (Map<UUID, UserConnection>) connectionsField.get(getProxy());
connections.remove( UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + name ).getBytes( Charsets.UTF_8 ) ) );
connectionsField.setAccessible(false);
if(connectionLock != null) connectionLock.writeLock().unlock();
} catch ( Exception ex ) {
ex.printStackTrace();
getLogger().warning("Error on UUID removal.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment