-
-
Save jwne/46294e528272eaaaca27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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