9
0
mirror of https://github.com/GeyserExtensionists/GeyserUtils.git synced 2025-12-19 15:09:24 +00:00
This commit is contained in:
zimzaza4
2024-07-16 22:31:20 +08:00
parent 91a3f04bd8
commit f1d5af45a7
2 changed files with 132 additions and 70 deletions

View File

@@ -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<Boolean> 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<String, Boolean> bundle) {
BundlePacket packet = new BundlePacket();
bundle.forEach((identifier, value) -> {
EntityPropertyPacket<Boolean> 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<Float> 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<String, Float> bundle) {
BundlePacket packet = new BundlePacket();
bundle.forEach((identifier, value) -> {
EntityPropertyPacket<Float> 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<Integer> 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<String, Integer> bundle) {
BundlePacket packet = new BundlePacket();
bundle.forEach((identifier, value) -> {
EntityPropertyPacket<Integer> 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));
}
}

View File

@@ -64,34 +64,19 @@ public class PlayerUtils {
} }
public static void sendCustomHitBox(Player player, Entity entity, float height, float width) { public static void sendCustomHitBox(Player player, Entity entity, float height, float width) {
CustomEntityDataPacket packet = new CustomEntityDataPacket(); EntityUtils.sendCustomHitBox(player, entity.getEntityId(), height, width);
packet.setEntityId(entity.getEntityId());
packet.setWidth(width);
packet.setHeight(height);
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
} }
public static void sendCustomScale(Player player, Entity entity, float scale) { public static void sendCustomScale(Player player, Entity entity, float scale) {
CustomEntityDataPacket packet = new CustomEntityDataPacket(); EntityUtils.sendCustomScale(player, entity.getEntityId(), scale);
packet.setEntityId(entity.getEntityId());
packet.setScale(scale);
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
} }
public static void sendCustomColor(Player player, Entity entity, Color color) { public static void sendCustomColor(Player player, Entity entity, Color color) {
CustomEntityDataPacket packet = new CustomEntityDataPacket(); EntityUtils.sendCustomColor(player, entity.getEntityId(), color);
packet.setEntityId(entity.getEntityId());
packet.setColor(color.getRGB());
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
} }
public static void setCustomEntity(Player player, int entityId, String def) { public static void setCustomEntity(Player player, Entity entity, String def) {
CustomEntityPacket packet = new CustomEntityPacket(entityId, def); EntityUtils.setCustomEntity(player, entity.getEntityId(), 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 // (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 // so I didn't think too much about it
public static void registerProperty(Player player, Entity entity, String identifier, Class<?> type) { public static void registerProperty(Player player, Entity entity, String identifier, Class<?> type) {
EntityPropertyRegisterPacket packet = new EntityPropertyRegisterPacket(); EntityUtils.registerProperty(player, entity.getEntityId(), identifier, type);
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) { public static void sendBoolProperty(Player player, Entity entity, String identifier, Boolean value) {
EntityPropertyPacket<Boolean> packet = new EntityPropertyPacket<>(); EntityUtils.sendBoolProperty(player, entity.getEntityId(), identifier, value);
packet.setEntityId(entity.getEntityId());
packet.setIdentifier(identifier);
packet.setValue(value);
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
} }
public static void sendBoolProperties(Player player, Entity entity, Map<String, Boolean> bundle) { public static void sendBoolProperties(Player player, Entity entity, Map<String, Boolean> bundle) {
BundlePacket packet = new BundlePacket(); EntityUtils.sendBoolProperties(player, entity.getEntityId(), bundle);
bundle.forEach((identifier, value) -> {
EntityPropertyPacket<Boolean> 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));
} }
public static void sendFloatProperty(Player player, Entity entity, String identifier, Float value) { public static void sendFloatProperty(Player player, Entity entity, String identifier, Float value) {
EntityPropertyPacket<Float> packet = new EntityPropertyPacket<>(); EntityUtils.sendFloatProperty(player, entity.getEntityId(), identifier, value);
packet.setEntityId(entity.getEntityId());
packet.setIdentifier(identifier);
packet.setValue(value);
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
} }
public static void sendFloatProperties(Player player, Entity entity, Map<String, Float> bundle) { public static void sendFloatProperties(Player player, Entity entity, Map<String, Float> bundle) {
BundlePacket packet = new BundlePacket(); EntityUtils.sendFloatProperties(player, entity.getEntityId(), bundle);
bundle.forEach((identifier, value) -> {
EntityPropertyPacket<Float> 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));
} }
public static void sendIntProperty(Player player, Entity entity, String identifier, Integer value) { public static void sendIntProperty(Player player, Entity entity, String identifier, Integer value) {
EntityPropertyPacket<Integer> packet = new EntityPropertyPacket<>(); EntityUtils.sendIntProperty(player, entity.getEntityId(), identifier, value);
packet.setEntityId(entity.getEntityId());
packet.setIdentifier(identifier);
packet.setValue(value);
player.sendPluginMessage(GeyserUtils.getInstance(), GeyserUtilsChannels.MAIN, GeyserUtils.getPacketManager().encodePacket(packet));
} }
public static void sendIntProperties(Player player, Entity entity, Map<String, Integer> bundle) { public static void sendIntProperties(Player player, Entity entity, Map<String, Integer> bundle) {
BundlePacket packet = new BundlePacket(); EntityUtils.sendIntProperties(player, entity.getEntityId(), bundle);
bundle.forEach((identifier, value) -> {
EntityPropertyPacket<Integer> 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));
} }
} }