Created
June 29, 2015 03:08
-
-
Save LaxWasHere/c099dc8785867265d124 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 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