Skip to content

Instantly share code, notes, and snippets.

@LaxWasHere
Created June 29, 2015 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LaxWasHere/c099dc8785867265d124 to your computer and use it in GitHub Desktop.
Save LaxWasHere/c099dc8785867265d124 to your computer and use it in GitHub Desktop.
package net.awesomepowered.kitpvp.Utilities;
import net.awesomepowered.kitpvp.KitPvP;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
/**
* Created by John on 11/13/2014.
*/
public class AutoRespawn implements Listener {
@EventHandler
public void onDeath(PlayerDeathEvent ev) {
if (!AntiCombat.combatants.contains(ev.getEntity().getName())) {
autoRespawn(ev.getEntity());
}
}
public void autoRespawn(final Player p) {
if (p.isOnline()) {
p.getServer().getScheduler().scheduleSyncDelayedTask(KitPvP.instance, new Runnable() {
@Override
public void run() {
try {
Object nmsPlayer = p.getClass().getMethod("getHandle").invoke(p);
Object packet = Class.forName(nmsPlayer.getClass().getPackage().getName() + ".PacketPlayInClientCommand").newInstance();
Class<?> enumClass = Class.forName(nmsPlayer.getClass().getPackage().getName() + ".EnumClientCommand");
for (Object o : enumClass.getEnumConstants()) {
if (o.toString().equals("PERFORM_RESPAWN")) {
packet = packet.getClass().getConstructor(enumClass).newInstance(o);
break;
}
}
Object con = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
con.getClass().getMethod("a", packet.getClass()).invoke(con, packet);
} catch (Throwable rock) {
rock.printStackTrace();
}
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment