Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Can it crash the client?
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Feb 7, 2019
1 parent 5491ad6 commit debe8bc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,60 @@

package com.ishland.bukkit.AsyncKeepAlive.main;

import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.junit.rules.Timeout;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;

/**
* @author ishland
*
*/
public class AsyncKeepAlive extends JavaPlugin implements Listener {
public static Timeout main;
private ProtocolManager protocolManager;

public static Timeout getInstance() {
return main;
}

public Set<UUID> inTimeout = new TreeSet<UUID>();

@Override
public void onEnable() {
protocolManager = ProtocolLibrary.getProtocolManager();
getLogger().info("AsyncKeepAlive by ishland");
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
getLogger().warning("You need ProtocolLib in order to use this plugin");
getServer().getPluginManager().disablePlugin(this);
return;
}
try {

new AsyncPacketThread().start();
protocolManager.addPacketListener(
new PacketAdapter(this, ListenerPriority.HIGHEST, PacketType.Play.Server.KICK_DISCONNECT) {
@Override
public void onPacketSending(PacketEvent e) {
e.setCancelled(true);
if (e.getPacketType() == PacketType.Play.Server.KICK_DISCONNECT) {
if (inTimeout.contains(e.getPlayer().getUniqueId())) {
Bukkit.broadcastMessage("yep");
e.setCancelled(true);
}
}
}
});
} catch (Throwable t) {
t.printStackTrace();
getServer().getPluginManager().disablePlugin(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.junit.rules.Timeout;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
Expand All @@ -20,12 +21,14 @@
*
*/
public class AsyncPacketThread extends Thread {
public static Timeout main;
private ProtocolManager protocolManager;

public AsyncPacketThread() {
setDaemon(true);
}

public void run() {
ProtocolManager protocolManager;
protocolManager = ProtocolLibrary.getProtocolManager();
for (;;) {
try {
Expand Down

0 comments on commit debe8bc

Please sign in to comment.