From f1d5af45a7394a0d5c878d7c29e4ce3b88f7b3ac Mon Sep 17 00:00:00 2001 From: zimzaza4 <3625282098@qq.com> Date: Tue, 16 Jul 2024 22:31:20 +0800 Subject: [PATCH] split --- .../geyserutils/spigot/api/EntityUtils.java | 120 ++++++++++++++++++ .../geyserutils/spigot/api/PlayerUtils.java | 82 ++---------- 2 files changed, 132 insertions(+), 70 deletions(-) create mode 100644 spigot/src/main/java/me/zimzaza4/geyserutils/spigot/api/EntityUtils.java diff --git a/spigot/src/main/java/me/zimzaza4/geyserutils/spigot/api/EntityUtils.java b/spigot/src/main/java/me/zimzaza4/geyserutils/spigot/api/EntityUtils.java new file mode 100644 index 0000000..3e1db35 --- /dev/null +++ b/spigot/src/main/java/me/zimzaza4/geyserutils/spigot/api/EntityUtils.java @@ -0,0 +1,120 @@ +package me.zimzaza4.geyserutils.spigot.api; + +import me.zimzaza4.geyserutils.common.channel.GeyserUtilsChannels; +import me.zimzaza4.geyserutils.common.packet.*; +import me.zimzaza4.geyserutils.spigot.GeyserUtils; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.awt.*; +import java.util.Map; + +public class EntityUtils { + + public static void sendCustomHitBox(Player player, int id, float height, float width) { + CustomEntityDataPacket packet = new CustomEntityDataPacket(); + packet.setEntityId(id); + packet.setWidth(width); + packet.setHeight(height); + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + + } + + public static void sendCustomScale(Player player, int id, float scale) { + CustomEntityDataPacket packet = new CustomEntityDataPacket(); + packet.setEntityId(id); + packet.setScale(scale); + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + + } + + public static void sendCustomColor(Player player, int id, Color color) { + CustomEntityDataPacket packet = new CustomEntityDataPacket(); + packet.setEntityId(id); + packet.setColor(color.getRGB()); + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + + } + + public static void setCustomEntity(Player player, int entityId, String def) { + CustomEntityPacket packet = new CustomEntityPacket(entityId, def); + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + + } + + // (yes I'm aware it's "horrible" code), also this aint player packets at all lmao + // right, so this part needs to be refactored xD + // the plugin didn't have this much functionality in its earliest days (it even just have camera shakes), + // so I didn't think too much about it + + public static void registerProperty(Player player, int id, String identifier, Class type) { + EntityPropertyRegisterPacket packet = new EntityPropertyRegisterPacket(); + packet.setEntityId(id); + packet.setIdentifier(identifier); + packet.setType(type); + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + } + + public static void sendBoolProperty(Player player, int id, String identifier, Boolean value) { + EntityPropertyPacket packet = new EntityPropertyPacket<>(); + packet.setEntityId(id); + packet.setIdentifier(identifier); + packet.setValue(value); + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + } + + public static void sendBoolProperties(Player player, int id, Map bundle) { + BundlePacket packet = new BundlePacket(); + bundle.forEach((identifier, value) -> { + EntityPropertyPacket propertyPacket = new EntityPropertyPacket<>(); + propertyPacket.setEntityId(id); + propertyPacket.setIdentifier(identifier); + propertyPacket.setValue(value); + packet.addPacket(propertyPacket); + }); + + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + } + + public static void sendFloatProperty(Player player, int id, String identifier, Float value) { + EntityPropertyPacket packet = new EntityPropertyPacket<>(); + packet.setEntityId(id); + packet.setIdentifier(identifier); + packet.setValue(value); + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + } + + public static void sendFloatProperties(Player player, int id, Map bundle) { + BundlePacket packet = new BundlePacket(); + bundle.forEach((identifier, value) -> { + EntityPropertyPacket propertyPacket = new EntityPropertyPacket<>(); + propertyPacket.setEntityId(id); + propertyPacket.setIdentifier(identifier); + propertyPacket.setValue(value); + packet.addPacket(propertyPacket); + }); + + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + } + + public static void sendIntProperty(Player player, int id, String identifier, Integer value) { + EntityPropertyPacket packet = new EntityPropertyPacket<>(); + packet.setEntityId(id); + packet.setIdentifier(identifier); + packet.setValue(value); + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + } + + public static void sendIntProperties(Player player, int id, Map bundle) { + BundlePacket packet = new BundlePacket(); + bundle.forEach((identifier, value) -> { + EntityPropertyPacket propertyPacket = new EntityPropertyPacket<>(); + propertyPacket.setEntityId(id); + propertyPacket.setIdentifier(identifier); + propertyPacket.setValue(value); + packet.addPacket(propertyPacket); + }); + + player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + } +} diff --git a/spigot/src/main/java/me/zimzaza4/geyserutils/spigot/api/PlayerUtils.java b/spigot/src/main/java/me/zimzaza4/geyserutils/spigot/api/PlayerUtils.java index af86b1b..cf5e229 100644 --- a/spigot/src/main/java/me/zimzaza4/geyserutils/spigot/api/PlayerUtils.java +++ b/spigot/src/main/java/me/zimzaza4/geyserutils/spigot/api/PlayerUtils.java @@ -64,34 +64,19 @@ public class PlayerUtils { } public static void sendCustomHitBox(Player player, Entity entity, float height, float width) { - CustomEntityDataPacket packet = new CustomEntityDataPacket(); - packet.setEntityId(entity.getEntityId()); - packet.setWidth(width); - packet.setHeight(height); - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); - + EntityUtils.sendCustomHitBox(player, entity.getEntityId(), height, width); } public static void sendCustomScale(Player player, Entity entity, float scale) { - CustomEntityDataPacket packet = new CustomEntityDataPacket(); - packet.setEntityId(entity.getEntityId()); - packet.setScale(scale); - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); - + EntityUtils.sendCustomScale(player, entity.getEntityId(), scale); } public static void sendCustomColor(Player player, Entity entity, Color color) { - CustomEntityDataPacket packet = new CustomEntityDataPacket(); - packet.setEntityId(entity.getEntityId()); - packet.setColor(color.getRGB()); - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); - + EntityUtils.sendCustomColor(player, entity.getEntityId(), color); } - public static void setCustomEntity(Player player, int entityId, String def) { - CustomEntityPacket packet = new CustomEntityPacket(entityId, def); - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); - + public static void setCustomEntity(Player player, Entity entity, String def) { + EntityUtils.setCustomEntity(player, entity.getEntityId(), def); } // (yes I'm aware it's "horrible" code), also this aint player packets at all lmao @@ -100,73 +85,30 @@ public class PlayerUtils { // so I didn't think too much about it 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)); + EntityUtils.registerProperty(player, entity.getEntityId(), identifier, type); } public static void sendBoolProperty(Player player, Entity entity, String identifier, Boolean value) { - EntityPropertyPacket packet = new EntityPropertyPacket<>(); - packet.setEntityId(entity.getEntityId()); - packet.setIdentifier(identifier); - packet.setValue(value); - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + EntityUtils.sendBoolProperty(player, entity.getEntityId(), identifier, value); } public static void sendBoolProperties(Player player, Entity entity, Map bundle) { - BundlePacket packet = new BundlePacket(); - bundle.forEach((identifier, value) -> { - EntityPropertyPacket propertyPacket = new EntityPropertyPacket<>(); - propertyPacket.setEntityId(entity.getEntityId()); - propertyPacket.setIdentifier(identifier); - propertyPacket.setValue(value); - packet.addPacket(propertyPacket); - }); - - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + EntityUtils.sendBoolProperties(player, entity.getEntityId(), bundle); } public static void sendFloatProperty(Player player, Entity entity, String identifier, Float value) { - EntityPropertyPacket packet = new EntityPropertyPacket<>(); - packet.setEntityId(entity.getEntityId()); - packet.setIdentifier(identifier); - packet.setValue(value); - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + EntityUtils.sendFloatProperty(player, entity.getEntityId(), identifier, value); } public static void sendFloatProperties(Player player, Entity entity, Map bundle) { - BundlePacket packet = new BundlePacket(); - bundle.forEach((identifier, value) -> { - EntityPropertyPacket propertyPacket = new EntityPropertyPacket<>(); - propertyPacket.setEntityId(entity.getEntityId()); - propertyPacket.setIdentifier(identifier); - propertyPacket.setValue(value); - packet.addPacket(propertyPacket); - }); - - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + EntityUtils.sendFloatProperties(player, entity.getEntityId(), bundle); } public static void sendIntProperty(Player player, Entity entity, String identifier, Integer value) { - EntityPropertyPacket packet = new EntityPropertyPacket<>(); - packet.setEntityId(entity.getEntityId()); - packet.setIdentifier(identifier); - packet.setValue(value); - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + EntityUtils.sendIntProperty(player, entity.getEntityId(), identifier, value); } public static void sendIntProperties(Player player, Entity entity, Map bundle) { - BundlePacket packet = new BundlePacket(); - bundle.forEach((identifier, value) -> { - EntityPropertyPacket propertyPacket = new EntityPropertyPacket<>(); - propertyPacket.setEntityId(entity.getEntityId()); - propertyPacket.setIdentifier(identifier); - propertyPacket.setValue(value); - packet.addPacket(propertyPacket); - }); - - player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet)); + EntityUtils.sendIntProperties(player, entity.getEntityId(), bundle); } }