Dieser Commit ist enthalten in:
Ursprung
833e6f5818
Commit
ad9b2465ee
@ -40,6 +40,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
|
||||||
public class REntityServer implements Listener {
|
public class REntityServer implements Listener {
|
||||||
@ -48,15 +49,16 @@ public class REntityServer implements Listener {
|
|||||||
private static final HashSet<Player> emptyPlayers = new HashSet<>(0);
|
private static final HashSet<Player> emptyPlayers = new HashSet<>(0);
|
||||||
|
|
||||||
private static final Class<?> useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity");
|
private static final Class<?> useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity");
|
||||||
private static final Class<?> useEntityEnumAction = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity$EnumEntityUseAction");
|
|
||||||
private static final Reflection.FieldAccessor<Integer> useEntityTarget = Reflection.getField(useEntity, int.class, 0);
|
private static final Reflection.FieldAccessor<Integer> useEntityTarget = Reflection.getField(useEntity, int.class, 0);
|
||||||
private static final Reflection.FieldAccessor<Object> useEntityAction = (Reflection.FieldAccessor<Object>) Reflection.getField(useEntity, useEntityEnumAction, 0);
|
private static final Class<?> useEntityEnumAction = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity$EnumEntityUseAction");
|
||||||
private static final Reflection.MethodInvoker useEntityGetAction;
|
private static final Reflection.FieldAccessor<?> useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0);
|
||||||
|
private static final Function<Object, Integer> getEntityAction;
|
||||||
static {
|
static {
|
||||||
if (useEntityEnumAction.isEnum()) {
|
if(Core.getVersion() > 15) {
|
||||||
useEntityGetAction = null;
|
Reflection.MethodInvoker useEntityGetAction = Reflection.getMethod(useEntity, "a");
|
||||||
|
getEntityAction = value -> ((Enum<?>) useEntityGetAction.invoke(value)).ordinal();
|
||||||
} else {
|
} else {
|
||||||
useEntityGetAction = Reflection.getMethod(useEntity, "a");
|
getEntityAction = value -> ((Enum<?>) value).ordinal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,24 +70,13 @@ public class REntityServer implements Listener {
|
|||||||
|
|
||||||
private EntityActionListener callback = null;
|
private EntityActionListener callback = null;
|
||||||
|
|
||||||
private BiFunction<Player, Object, Object> filter = (player, packet) -> {
|
private final BiFunction<Player, Object, Object> filter = (player, packet) -> {
|
||||||
if (callback == null) return packet;
|
REntity entity = entityMap.get(useEntityTarget.get(packet));
|
||||||
int target = useEntityTarget.get(packet);
|
if (entity == null)
|
||||||
REntity entity = entityMap.get(target);
|
return packet;
|
||||||
if (entity == null) return packet;
|
|
||||||
|
|
||||||
Object entityAction = useEntityAction.get(packet);
|
EntityAction action = getEntityAction.apply(useEntityAction.get(packet)) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT;
|
||||||
int entityActionOrdinal;
|
Bukkit.getScheduler().runTask(Core.getInstance(), () -> callback.onAction(player, entity, action));
|
||||||
if (useEntityEnumAction.isEnum()) {
|
|
||||||
entityActionOrdinal = ((Enum<?>) entityAction).ordinal();
|
|
||||||
} else {
|
|
||||||
entityActionOrdinal = ((Enum<?>) useEntityGetAction.invoke(entityAction)).ordinal();
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityAction action = entityActionOrdinal == 1 ? EntityAction.ATTACK : EntityAction.INTERACT;
|
|
||||||
Bukkit.getScheduler().runTask(Core.getInstance(), () -> {
|
|
||||||
callback.onAction(player, entity, action);
|
|
||||||
});
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren