13
0

Add some Sneaking Methods

Dieser Commit ist enthalten in:
Chaoscaot 2021-04-11 18:23:57 +02:00
Ursprung ca8801563d
Commit 17c0995f24

Datei anzeigen

@ -19,13 +19,21 @@
package de.steamwar.spectatesystem.elements;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.mojang.authlib.GameProfile;
import de.steamwar.spectatesystem.SpectateSystem;
import net.minecraft.server.v1_15_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_15_R1.metadata.EntityMetadataStore;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@ -48,6 +56,7 @@ public abstract class REntity {
for(Player player : Bukkit.getOnlinePlayers()){
sendToPlayer(player);
}
sneak(false);
}
public static void playerJoins(Player player){
@ -103,17 +112,33 @@ public abstract class REntity {
}
}
public void sneak(boolean sneaking) {
entity.setSneaking(sneaking);
private static Method setPoseMethod = null;
/*DataWatcher dataWatcher = new DataWatcher(entity);
System.out.println("Let " + entity.getName() + " sneak " + sneaking);
dataWatcher.register(new DataWatcherObject<>(0, DataWatcherRegistry.a), sneaking ? (byte)0x02 : (byte)0x40);
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false);
public void sneak(boolean sneaking) {
try {
if(setPoseMethod == null) {
setPoseMethod = Entity.class.getDeclaredMethod("setPose", EntityPose.class);
setPoseMethod.setAccessible(true);
}
setPoseMethod.invoke(entity, sneaking?EntityPose.CROUCHING:EntityPose.STANDING);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
/*System.out.println("Let " + entity.getName() + " sneak " + sneaking+ " | " + entity.getClass());
DataWatcher dataWatcher = entity.getDataWatcher();
dataWatcher.set(new DataWatcherObject<>(6, DataWatcherRegistry.s), sneaking?EntityPose.CROUCHING:EntityPose.STANDING);
//dataWatcher.set(new DataWatcherObject<>(0, DataWatcherRegistry.a), Byte.valueOf((byte) (sneaking?2:0)));*/
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), false);
for(Player player : Bukkit.getOnlinePlayers()){
((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
}*/
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
public void animation(byte animation) {