mirror of
https://github.com/GeyserExtensionists/GeyserUtils.git
synced 2025-12-19 14:59:18 +00:00
I did a whole lot, essentially added a whole property system. (sorry for not commiting, i forgot)
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.packet;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class EntityPropertyPacket<T> extends CustomPayloadPacket {
|
||||||
|
private int entityId;
|
||||||
|
|
||||||
|
private String identifier;
|
||||||
|
private T value;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package me.zimzaza4.geyserutils.common.packet;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class EntityPropertyRegisterPacket extends CustomPayloadPacket {
|
||||||
|
private int entityId;
|
||||||
|
|
||||||
|
private String identifier;
|
||||||
|
private Class<?> type;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -45,6 +45,7 @@ import org.geysermc.geyser.api.skin.Skin;
|
|||||||
import org.geysermc.geyser.api.skin.SkinData;
|
import org.geysermc.geyser.api.skin.SkinData;
|
||||||
import org.geysermc.geyser.api.skin.SkinGeometry;
|
import org.geysermc.geyser.api.skin.SkinGeometry;
|
||||||
import org.geysermc.geyser.entity.EntityDefinition;
|
import org.geysermc.geyser.entity.EntityDefinition;
|
||||||
|
import org.geysermc.geyser.entity.properties.GeyserEntityProperties;
|
||||||
import org.geysermc.geyser.entity.type.Entity;
|
import org.geysermc.geyser.entity.type.Entity;
|
||||||
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
||||||
import org.geysermc.geyser.inventory.GeyserItemStack;
|
import org.geysermc.geyser.inventory.GeyserItemStack;
|
||||||
@@ -94,13 +95,19 @@ public class GeyserUtils implements Extension {
|
|||||||
public static ItemParticlesMappings particlesMappings = new ItemParticlesMappings();
|
public static ItemParticlesMappings particlesMappings = new ItemParticlesMappings();
|
||||||
static Cape EMPTY_CAPE = new Cape("", "no-cape", ByteArrays.EMPTY_ARRAY, true);
|
static Cape EMPTY_CAPE = new Cape("", "no-cape", ByteArrays.EMPTY_ARRAY, true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
|
public static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
|
||||||
|
|
||||||
|
private static final Map<String, List<Map.Entry<String, Class<?>>>> properties = new HashMap<>();
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static GeyserUtils instance;
|
||||||
|
|
||||||
|
public GeyserUtils() {
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEnable(GeyserPostInitializeEvent event) {
|
public void onEnable(GeyserPostInitializeEvent event) {
|
||||||
|
|
||||||
Registries.BEDROCK_PACKET_TRANSLATORS.register(NpcRequestPacket.class, new NPCFormResponseTranslator());
|
Registries.BEDROCK_PACKET_TRANSLATORS.register(NpcRequestPacket.class, new NPCFormResponseTranslator());
|
||||||
loadSkins();
|
loadSkins();
|
||||||
ReflectionUtils.init();
|
ReflectionUtils.init();
|
||||||
@@ -115,6 +122,60 @@ public class GeyserUtils implements Extension {
|
|||||||
particlesMappings.read(dataFolder().resolve("item_particles_mappings.json"));
|
particlesMappings.read(dataFolder().resolve("item_particles_mappings.json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the static here is crazy ;(
|
||||||
|
private static GeyserEntityProperties getProperties(String id) {
|
||||||
|
if (!properties.containsKey(id)) return null;
|
||||||
|
|
||||||
|
GeyserEntityProperties.Builder builder = new GeyserEntityProperties.Builder();
|
||||||
|
List<Map.Entry<String, Class<?>>> pairs = properties.get(id);
|
||||||
|
pairs.forEach(p -> {
|
||||||
|
// only bool, float and int support for now
|
||||||
|
if (p.getValue() == Boolean.class) builder.addBoolean(p.getKey());
|
||||||
|
else if (p.getValue() == Float.class) builder.addBoolean(p.getKey());
|
||||||
|
else if (p.getValue() == Integer.class) builder.addBoolean(p.getKey());
|
||||||
|
else instance.logger().info("Found unknown property: " + p.getKey());
|
||||||
|
});
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsProperty(String entityId, String identifier) {
|
||||||
|
if (!properties.containsKey(entityId)) return false;
|
||||||
|
|
||||||
|
return properties.get(entityId).stream().anyMatch(p -> p.getKey().equalsIgnoreCase(identifier));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addProperty(String entityId, String identifier, Class<?> type) {
|
||||||
|
if (containsProperty(entityId, identifier)) return;
|
||||||
|
|
||||||
|
List<Map.Entry<String, Class<?>>> pairs = properties.getOrDefault(entityId, new ArrayList<>());
|
||||||
|
pairs.add(new AbstractMap.SimpleEntry<>(identifier, type));
|
||||||
|
|
||||||
|
if (properties.containsKey(entityId)) properties.replace(entityId, pairs);
|
||||||
|
else properties.put(entityId, pairs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerProperties(String entityId) {
|
||||||
|
GeyserEntityProperties entityProperties = getProperties(entityId);
|
||||||
|
if (entityProperties == null) return;
|
||||||
|
|
||||||
|
properties.values().stream()
|
||||||
|
.flatMap(List::stream)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.forEach(id -> {
|
||||||
|
Registries.BEDROCK_ENTITY_PROPERTIES.get().removeIf(i -> i.containsKey(id));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Registries.BEDROCK_ENTITY_PROPERTIES.get().add(entityProperties.toNbtMap(entityId));
|
||||||
|
|
||||||
|
EntityDefinition old = LOADED_ENTITY_DEFINITIONS.get(entityId);
|
||||||
|
LOADED_ENTITY_DEFINITIONS.replace(entityId, new EntityDefinition(old.factory(), old.entityType(), old.identifier(),
|
||||||
|
old.width(), old.height(), old.offset(), entityProperties, old.translators()));
|
||||||
|
|
||||||
|
instance.logger().info("Defined property: " + entityId + " in registry.");
|
||||||
|
}
|
||||||
|
|
||||||
public static void addCustomEntity(String id) {
|
public static void addCustomEntity(String id) {
|
||||||
/*
|
/*
|
||||||
LOADED_ENTITY_DEFINITIONS.put(id,
|
LOADED_ENTITY_DEFINITIONS.put(id,
|
||||||
@@ -140,7 +201,9 @@ public class GeyserUtils implements Extension {
|
|||||||
Registries.BEDROCK_ENTITY_IDENTIFIERS.set(NbtMap.builder()
|
Registries.BEDROCK_ENTITY_IDENTIFIERS.set(NbtMap.builder()
|
||||||
.putList("idlist", NbtType.COMPOUND, idList).build()
|
.putList("idlist", NbtType.COMPOUND, idList).build()
|
||||||
);
|
);
|
||||||
EntityDefinition<Entity> def = EntityDefinition.builder(null).height(0.1f).width(0.1f).identifier(id).build();
|
|
||||||
|
EntityDefinition<Entity> def = EntityDefinition.builder(null)
|
||||||
|
.height(0.1f).width(0.1f).identifier(id).registeredProperties(getProperties(id)).build();
|
||||||
|
|
||||||
LOADED_ENTITY_DEFINITIONS.put(id, def);
|
LOADED_ENTITY_DEFINITIONS.put(id, def);
|
||||||
}
|
}
|
||||||
@@ -356,6 +419,45 @@ public class GeyserUtils implements Extension {
|
|||||||
if (customEntityDataPacket.getScale() != null) entity.getDirtyMetadata().put(EntityDataTypes.SCALE, customEntityDataPacket.getScale());
|
if (customEntityDataPacket.getScale() != null) entity.getDirtyMetadata().put(EntityDataTypes.SCALE, customEntityDataPacket.getScale());
|
||||||
entity.updateBedrockMetadata();
|
entity.updateBedrockMetadata();
|
||||||
}
|
}
|
||||||
|
} else if (customPacket instanceof EntityPropertyPacket entityPropertyPacket) {
|
||||||
|
Entity entity = (session.getEntityCache().getEntityByJavaId(entityPropertyPacket.getEntityId()));
|
||||||
|
if (entity != null) {
|
||||||
|
if (entityPropertyPacket.getIdentifier() == null
|
||||||
|
|| entityPropertyPacket.getValue() == null) return;
|
||||||
|
|
||||||
|
String def = CUSTOM_ENTITIES.get(session).getIfPresent(entity.getEntityId());
|
||||||
|
if (def == null) return;
|
||||||
|
|
||||||
|
if (!containsProperty(def, entityPropertyPacket.getIdentifier())) {
|
||||||
|
addProperty(def, entityPropertyPacket.getIdentifier(), entityPropertyPacket.getValue().getClass());
|
||||||
|
|
||||||
|
registerProperties(def);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.getPropertyManager() == null) return;
|
||||||
|
entity.getPropertyManager().add(entityPropertyPacket.getIdentifier(),
|
||||||
|
(Boolean) entityPropertyPacket.getValue());
|
||||||
|
|
||||||
|
entity.updateBedrockEntityProperties();
|
||||||
|
}
|
||||||
|
} else if (customPacket instanceof EntityPropertyRegisterPacket entityPropertyRegisterPacket) {
|
||||||
|
if (entityPropertyRegisterPacket.getIdentifier() == null
|
||||||
|
|| entityPropertyRegisterPacket.getType() == null) return;
|
||||||
|
|
||||||
|
Entity entity = (session.getEntityCache().getEntityByJavaId(entityPropertyRegisterPacket.getEntityId()));
|
||||||
|
if (entity != null) {
|
||||||
|
String def = CUSTOM_ENTITIES.get(session).getIfPresent(entity.getEntityId());
|
||||||
|
if (def == null) return;
|
||||||
|
|
||||||
|
if (!containsProperty(def, entityPropertyRegisterPacket.getIdentifier())) {
|
||||||
|
addProperty(def, entityPropertyRegisterPacket.getIdentifier(), entityPropertyRegisterPacket.getType());
|
||||||
|
|
||||||
|
registerProperties(def);
|
||||||
|
logger().info("Defined property: " + entityPropertyRegisterPacket.getIdentifier() + " in registry.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} else if (customPacket instanceof CustomEntityPacket customEntityPacket) {
|
} else if (customPacket instanceof CustomEntityPacket customEntityPacket) {
|
||||||
if (!LOADED_ENTITY_DEFINITIONS.containsKey(customEntityPacket.getIdentifier())) {
|
if (!LOADED_ENTITY_DEFINITIONS.containsKey(customEntityPacket.getIdentifier())) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package me.zimzaza4.geyserutils.geyser.replace;
|
package me.zimzaza4.geyserutils.geyser.replace;
|
||||||
|
|
||||||
|
import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.FallingBlockData;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.FallingBlockData;
|
||||||
@@ -44,6 +45,8 @@ import org.geysermc.geyser.text.GeyserLocale;
|
|||||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||||
import org.geysermc.geyser.translator.protocol.Translator;
|
import org.geysermc.geyser.translator.protocol.Translator;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import static me.zimzaza4.geyserutils.geyser.GeyserUtils.CUSTOM_ENTITIES;
|
import static me.zimzaza4.geyserutils.geyser.GeyserUtils.CUSTOM_ENTITIES;
|
||||||
import static me.zimzaza4.geyserutils.geyser.GeyserUtils.LOADED_ENTITY_DEFINITIONS;
|
import static me.zimzaza4.geyserutils.geyser.GeyserUtils.LOADED_ENTITY_DEFINITIONS;
|
||||||
|
|
||||||
@@ -127,8 +130,15 @@ public class JavaAddEntityTranslatorReplace extends PacketTranslator<Clientbound
|
|||||||
|
|
||||||
String def = CUSTOM_ENTITIES.get(session).getIfPresent(entity.getEntityId());
|
String def = CUSTOM_ENTITIES.get(session).getIfPresent(entity.getEntityId());
|
||||||
if (def != null) {
|
if (def != null) {
|
||||||
// System.out.println("CUSTOM ENTITY :" + event.entityId() + " | " + def);
|
System.out.println("CUSTOM ENTITY :" + entity.getEntityId() + " | " + def);
|
||||||
entity.setDefinition(LOADED_ENTITY_DEFINITIONS.getOrDefault(def, entity.getDefinition()));
|
|
||||||
|
EntityDefinition newDef = LOADED_ENTITY_DEFINITIONS.getOrDefault(def, entity.getDefinition());
|
||||||
|
System.out.println("CUSTOM DEF : " + newDef);
|
||||||
|
entity.setDefinition(newDef);
|
||||||
|
|
||||||
|
// reinstantiate the entity object to create the propertymanager.
|
||||||
|
entity = new Entity(entity.getSession(), entity.getEntityId(), entity.getGeyserId(), entity.getUuid(),
|
||||||
|
entity.getDefinition(), entity.getPosition(), entity.getMotion(), yaw, pitch, headYaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
session.getEntityCache().spawnEntity(entity);
|
session.getEntityCache().spawnEntity(entity);
|
||||||
|
|||||||
@@ -31,11 +31,7 @@ public class ReflectionUtils {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static void init() {
|
public static void init() {
|
||||||
PlatformType type = GeyserImpl.getInstance().platformType();
|
PlatformType type = GeyserImpl.getInstance().platformType();
|
||||||
if (type == PlatformType.STANDALONE) {
|
prefix = type == PlatformType.STANDALONE || type == PlatformType.VELOCITY ? "" : "org.geysermc.geyser.platform." + type.platformName().toLowerCase() + ".shaded.";
|
||||||
prefix = "";
|
|
||||||
} else {
|
|
||||||
prefix = "org.geysermc.geyser.platform." + type.platformName().toLowerCase() + ".shaded.";
|
|
||||||
}
|
|
||||||
CLIENTBOUND_PAYLOAD_PACKET_CLASS = ClientboundCustomPayloadPacket.class;
|
CLIENTBOUND_PAYLOAD_PACKET_CLASS = ClientboundCustomPayloadPacket.class;
|
||||||
SERVERBOUND_PAYLOAD_PACKET_CLASS = ServerboundCustomPayloadPacket.class;
|
SERVERBOUND_PAYLOAD_PACKET_CLASS = ServerboundCustomPayloadPacket.class;
|
||||||
KEY_CLASS = Class.forName(prefix + "net.kyori.adventure.key.Key");
|
KEY_CLASS = Class.forName(prefix + "net.kyori.adventure.key.Key");
|
||||||
|
|||||||
@@ -61,6 +61,10 @@
|
|||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>opencollab-snapshot</id>
|
||||||
|
<url>https://repo.opencollab.dev/main/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import me.zimzaza4.geyserutils.common.packet.*;
|
|||||||
import me.zimzaza4.geyserutils.common.particle.CustomParticle;
|
import me.zimzaza4.geyserutils.common.particle.CustomParticle;
|
||||||
import me.zimzaza4.geyserutils.common.util.Pos;
|
import me.zimzaza4.geyserutils.common.util.Pos;
|
||||||
import me.zimzaza4.geyserutils.spigot.GeyserUtils;
|
import me.zimzaza4.geyserutils.spigot.GeyserUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -88,4 +89,38 @@ public class PlayerUtils {
|
|||||||
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// (yes I'm aware it's "horrible" code, I'm just matching the energy of this plugin), also this aint player packets at all lmao
|
||||||
|
|
||||||
|
public static void registerProperty(Player player, Entity entity, String identifier, Class<?> type) {
|
||||||
|
EntityPropertyRegisterPacket packet = new EntityPropertyRegisterPacket();
|
||||||
|
packet.setEntityId(entity.getEntityId());
|
||||||
|
packet.setIdentifier(identifier);
|
||||||
|
packet.setType(type);
|
||||||
|
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendBoolProperty(Player player, Entity entity, String identifier, Boolean value) {
|
||||||
|
EntityPropertyPacket<Boolean> packet = new EntityPropertyPacket<>();
|
||||||
|
packet.setEntityId(entity.getEntityId());
|
||||||
|
packet.setIdentifier(identifier);
|
||||||
|
packet.setValue(value);
|
||||||
|
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendFloatProperty(Player player, Entity entity, String identifier, Float value) {
|
||||||
|
EntityPropertyPacket<Float> packet = new EntityPropertyPacket<>();
|
||||||
|
packet.setEntityId(entity.getEntityId());
|
||||||
|
packet.setIdentifier(identifier);
|
||||||
|
packet.setValue(value);
|
||||||
|
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendIntProperty(Player player, Entity entity, String identifier, Integer value) {
|
||||||
|
EntityPropertyPacket<Integer> packet = new EntityPropertyPacket<>();
|
||||||
|
packet.setEntityId(entity.getEntityId());
|
||||||
|
packet.setIdentifier(identifier);
|
||||||
|
packet.setValue(value);
|
||||||
|
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user