mirror of
https://github.com/xSquishyLiam/mc-GeyserModelEngine-plugin.git
synced 2025-12-19 14:59:19 +00:00
Packet-based entity
This commit is contained in:
@@ -16,7 +16,6 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import re.imc.geysermodelengine.listener.AddEntityPacketListener;
|
||||
import re.imc.geysermodelengine.listener.ModelListener;
|
||||
import re.imc.geysermodelengine.listener.MountPacketListener;
|
||||
import re.imc.geysermodelengine.model.ModelEntity;
|
||||
@@ -35,7 +34,7 @@ public final class GeyserModelEngine extends JavaPlugin {
|
||||
private static boolean alwaysSendSkin;
|
||||
|
||||
@Getter
|
||||
private int skinSendDelay;
|
||||
private int sendDelay;
|
||||
|
||||
@Getter
|
||||
private int viewDistance;
|
||||
@@ -72,8 +71,8 @@ public final class GeyserModelEngine extends JavaPlugin {
|
||||
// Plugin startup logic
|
||||
saveDefaultConfig();
|
||||
// alwaysSendSkin = getConfig().getBoolean("always-send-skin");
|
||||
skinSendDelay = getConfig().getInt("skin-send-delay", 0);
|
||||
viewDistance = getConfig().getInt("skin-view-distance", 60);
|
||||
sendDelay = getConfig().getInt("data-send-delay", 0);
|
||||
viewDistance = getConfig().getInt("entity-view-distance", 60);
|
||||
debug = getConfig().getBoolean("debug", false);
|
||||
modelEntityType = EntityType.valueOf(getConfig().getString("model-entity-type", "BAT"));
|
||||
joinSendDelay = getConfig().getInt("join-send-delay", 20);
|
||||
@@ -82,7 +81,7 @@ public final class GeyserModelEngine extends JavaPlugin {
|
||||
.expireAfterWrite(joinSendDelay * 50L, TimeUnit.MILLISECONDS).build();
|
||||
}
|
||||
instance = this;
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new AddEntityPacketListener());
|
||||
// ProtocolLibrary.getProtocolManager().addPacketListener(new AddEntityPacketListener());
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new MountPacketListener());
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new ModelListener(), this);
|
||||
|
||||
@@ -4,26 +4,16 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.*;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import com.ticxo.modelengine.api.entity.BukkitEntity;
|
||||
import com.ticxo.modelengine.api.entity.Hitbox;
|
||||
import com.ticxo.modelengine.api.interaction.DynamicHitbox;
|
||||
import com.ticxo.modelengine.api.interaction.InteractionTracker;
|
||||
import com.ticxo.modelengine.api.model.bone.type.SubHitbox;
|
||||
import com.ticxo.modelengine.api.nms.entity.HitboxEntity;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import re.imc.geysermodelengine.GeyserModelEngine;
|
||||
import re.imc.geysermodelengine.model.EntityTask;
|
||||
import re.imc.geysermodelengine.model.ModelEntity;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Deprecated
|
||||
public class AddEntityPacketListener extends PacketAdapter {
|
||||
public AddEntityPacketListener() {
|
||||
super(GeyserModelEngine.getInstance(), ListenerPriority.HIGHEST, Set.of(PacketType.Play.Server.SPAWN_ENTITY), ListenerOptions.SYNC);
|
||||
@@ -62,10 +52,10 @@ public class AddEntityPacketListener extends PacketAdapter {
|
||||
}
|
||||
if (task == null || firstJoined) {
|
||||
Bukkit.getScheduler().runTaskLater(GeyserModelEngine.getInstance(), () -> {
|
||||
model.getTask().sendEntityData(event.getPlayer(), GeyserModelEngine.getInstance().getSkinSendDelay());
|
||||
model.getTask().sendEntityData(event.getPlayer(), GeyserModelEngine.getInstance().getSendDelay());
|
||||
}, delay);
|
||||
} else {
|
||||
task.sendEntityData(event.getPlayer(), GeyserModelEngine.getInstance().getSkinSendDelay());
|
||||
task.sendEntityData(event.getPlayer(), GeyserModelEngine.getInstance().getSendDelay());
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
@@ -97,21 +97,6 @@ public class ModelListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onModelHurt(EntityDamageEvent event) {
|
||||
ModelEntity model = ModelEntity.MODEL_ENTITIES.get(event.getEntity().getEntityId());
|
||||
if (model != null) {
|
||||
if (!event.getEntity().hasMetadata("show_damage")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
event.getEntity().removeMetadata("show_damage", GeyserModelEngine.getInstance());
|
||||
|
||||
if (!model.getEntity().isDead()) {
|
||||
event.setDamage(0);
|
||||
model.getEntity().setHealth(model.getEntity().getMaxHealth());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@@ -142,8 +127,7 @@ public class ModelListener implements Listener {
|
||||
if (model != null) {
|
||||
for (Map.Entry<ActiveModel, ModelEntity> entry : model.entrySet()) {
|
||||
if (!entry.getValue().getEntity().isDead()) {
|
||||
entry.getValue().getEntity().setMetadata("show_damage", new FixedMetadataValue(GeyserModelEngine.getInstance(), true));
|
||||
entry.getValue().getEntity().damage(0);
|
||||
entry.getValue().getEntity().sendHurtPacket(entry.getValue().getViewers());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,20 +148,6 @@ public class ModelListener implements Listener {
|
||||
|
||||
*/
|
||||
|
||||
@EventHandler
|
||||
public void onModelHit(ProjectileHitEvent event) {
|
||||
if (event.getHitEntity() == null) {
|
||||
return;
|
||||
}
|
||||
ModelEntity model = ModelEntity.MODEL_ENTITIES.get(event.getHitEntity().getEntityId());
|
||||
if (model != null) {
|
||||
|
||||
event.setCancelled(true);
|
||||
model.getEntity().setHealth(model.getEntity().getMaxHealth());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onAnimationEnd(AnimationEndEvent event) {
|
||||
|
||||
@@ -41,15 +41,12 @@ public class MountPacketListener extends PacketAdapter {
|
||||
if (event.getPlayer().getInventory().getHeldItemSlot() == 0) {
|
||||
event.getPacket().getBooleans().writeSafely(0, true);
|
||||
event.getPlayer().getInventory().setHeldItemSlot(3);
|
||||
event.getPlayer().sendActionBar("jump");
|
||||
}
|
||||
if (pitch > 89 || event.getPlayer().getInventory().getHeldItemSlot() == 1) {
|
||||
event.getPacket().getBooleans().writeSafely(1, true);
|
||||
event.getPlayer().sendActionBar("shift");
|
||||
}
|
||||
if (event.getPlayer().getInventory().getHeldItemSlot() == 8) {
|
||||
event.getPacket().getBooleans().writeSafely(0, true);
|
||||
event.getPlayer().sendActionBar("hold jump");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
package re.imc.geysermodelengine.model;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.ticxo.modelengine.api.animation.BlueprintAnimation;
|
||||
import com.ticxo.modelengine.api.entity.BaseEntity;
|
||||
import com.ticxo.modelengine.api.entity.BukkitEntity;
|
||||
import com.ticxo.modelengine.api.generator.blueprint.BlueprintBone;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
import com.ticxo.modelengine.api.model.bone.BoneBehaviorTypes;
|
||||
import com.ticxo.modelengine.api.model.bone.ModelBone;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.zimzaza4.geyserutils.common.animation.Animation;
|
||||
import me.zimzaza4.geyserutils.spigot.GeyserUtils;
|
||||
import me.zimzaza4.geyserutils.spigot.api.PlayerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.Vector3f;
|
||||
import re.imc.geysermodelengine.GeyserModelEngine;
|
||||
import re.imc.geysermodelengine.listener.ModelListener;
|
||||
import re.imc.geysermodelengine.packet.entity.PacketEntity;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
@@ -64,35 +57,13 @@ public class EntityTask {
|
||||
public EntityTask(ModelEntity model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public void runSync() {
|
||||
|
||||
syncTick ++;
|
||||
if (syncTick > 400) {
|
||||
syncTick = 0;
|
||||
}
|
||||
|
||||
if (syncTick % 5 == 0) {
|
||||
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (!FloodgateApi.getInstance().isFloodgatePlayer(onlinePlayer.getUniqueId())) {
|
||||
onlinePlayer.hideEntity(GeyserModelEngine.getInstance(), model.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!removed && model.getEntity().isDead() && model.getModeledEntity().getBase().isAlive() && !model.getActiveModel().isRemoved()) {
|
||||
// model.spawnEntity();
|
||||
}
|
||||
|
||||
model.getEntity().setVisualFire(false);
|
||||
model.teleportToModel();
|
||||
}
|
||||
public void runAsync() {
|
||||
Entity entity = model.getEntity();
|
||||
PacketEntity entity = model.getEntity();
|
||||
if (entity.isDead()) {
|
||||
return;
|
||||
}
|
||||
|
||||
model.teleportToModel();
|
||||
Set<Player> viewers = model.getViewers();
|
||||
ActiveModel activeModel = model.getActiveModel();
|
||||
ModeledEntity modeledEntity = model.getModeledEntity();
|
||||
@@ -147,6 +118,7 @@ public class EntityTask {
|
||||
if (canSee(onlinePlayer, model.getEntity())) {
|
||||
|
||||
if (!viewers.contains(onlinePlayer)) {
|
||||
sendSpawnPacket(onlinePlayer);
|
||||
viewers.add(onlinePlayer);
|
||||
/*
|
||||
if (GeyserModelEngine.getInstance().getSkinSendDelay() > 0) {
|
||||
@@ -162,6 +134,8 @@ public class EntityTask {
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
|
||||
entity.sendEntityDestroyPacket(Collections.singletonList(onlinePlayer));
|
||||
viewers.remove(onlinePlayer);
|
||||
}
|
||||
}
|
||||
@@ -221,10 +195,27 @@ public class EntityTask {
|
||||
sendColor(player.get(), true);
|
||||
}
|
||||
|
||||
private void sendSpawnPacket(Player onlinePlayer) {
|
||||
EntityTask task = model.getTask();
|
||||
int delay = 1;
|
||||
boolean firstJoined = GeyserModelEngine.getInstance().getJoinedPlayer().getIfPresent(onlinePlayer) != null;
|
||||
if (firstJoined) {
|
||||
delay = GeyserModelEngine.getInstance().getJoinSendDelay();
|
||||
}
|
||||
if (task == null || firstJoined) {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> {
|
||||
model.getTask().sendEntityData(onlinePlayer, GeyserModelEngine.getInstance().getSendDelay());
|
||||
}, delay);
|
||||
} else {
|
||||
task.sendEntityData(onlinePlayer, GeyserModelEngine.getInstance().getSendDelay());
|
||||
}
|
||||
}
|
||||
|
||||
public void sendEntityData(Player player, int delay) {
|
||||
// System.out.println("TYPE: " + "modelengine:" + model.getActiveModel().getBlueprint().getName().toLowerCase());
|
||||
PlayerUtils.setCustomEntity(player, model.getEntity().getEntityId(), "modelengine:" + model.getActiveModel().getBlueprint().getName().toLowerCase());
|
||||
|
||||
model.getEntity().sendSpawnPacket(Collections.singletonList(player));
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> {
|
||||
// PlayerUtils.sendCustomSkin(player, model.getEntity(), model.getActiveModel().getBlueprint().getName());
|
||||
if (looping) {
|
||||
@@ -442,7 +433,7 @@ public class EntityTask {
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
syncTask.cancel();
|
||||
// syncTask.cancel();
|
||||
asyncTask.cancel();
|
||||
}
|
||||
|
||||
@@ -458,13 +449,6 @@ public class EntityTask {
|
||||
|
||||
lastAnimation = id;
|
||||
sendHitBoxToAll();
|
||||
syncTask = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runSync();
|
||||
}
|
||||
};
|
||||
syncTask.runTaskTimer(instance, i, 0);
|
||||
|
||||
asyncTask = new BukkitRunnable() {
|
||||
@Override
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
package re.imc.geysermodelengine.model;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import com.ticxo.modelengine.api.entity.BukkitEntity;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
import lombok.Getter;
|
||||
import me.zimzaza4.geyserutils.spigot.api.PlayerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
import re.imc.geysermodelengine.GeyserModelEngine;
|
||||
import re.imc.geysermodelengine.packet.entity.PacketEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -28,8 +23,7 @@ public class ModelEntity {
|
||||
|
||||
public static Map<Integer, ModelEntity> MODEL_ENTITIES = new ConcurrentHashMap<>();
|
||||
|
||||
private LivingEntity entity;
|
||||
private BukkitEntity controllerEntity;
|
||||
private PacketEntity entity;
|
||||
|
||||
private final Set<Player> viewers = Sets.newConcurrentHashSet();
|
||||
|
||||
@@ -48,24 +42,7 @@ public class ModelEntity {
|
||||
|
||||
public void teleportToModel() {
|
||||
Location location = modeledEntity.getBase().getLocation();
|
||||
/*
|
||||
location.setPitch(modeledEntity.getXHeadRot());
|
||||
location.setYaw(modeledEntity.getYHeadRot());
|
||||
for (Player viewer : viewers) {
|
||||
viewer.sendActionBar("X:" + modeledEntity.getXHeadRot() + ", Y:" + modeledEntity.getYHeadRot());
|
||||
}
|
||||
|
||||
*/
|
||||
Vector vector = modeledEntity.getBase().getMoveController().getVelocity();
|
||||
ModelEngineAPI.getEntityHandler().setPosition(entity, location.getX(), location.getY(), location.getZ());
|
||||
// ModelEngineAPI.getEntityHandler().movePassenger(entity, location.getX(), location.getY(), location.getZ());
|
||||
controllerEntity.getMoveController().setVelocity(vector.getX(), vector.getY(), vector.getZ());
|
||||
if (modeledEntity.getBase() instanceof BukkitEntity bukkitEntity && bukkitEntity.getOriginal() instanceof LivingEntity livingEntity) {
|
||||
controllerEntity.getLookController().setHeadYaw(livingEntity.getEyeLocation().getYaw());
|
||||
controllerEntity.getLookController().setPitch(livingEntity.getEyeLocation().getPitch());
|
||||
controllerEntity.getLookController().setBodyYaw(livingEntity.getBodyYaw());
|
||||
}
|
||||
|
||||
entity.teleport(location);
|
||||
}
|
||||
public static ModelEntity create(ModeledEntity entity, ActiveModel model) {
|
||||
ModelEntity modelEntity = new ModelEntity(entity, model);
|
||||
@@ -81,14 +58,8 @@ public class ModelEntity {
|
||||
return modelEntity;
|
||||
}
|
||||
|
||||
public LivingEntity spawnEntity() {
|
||||
ModelEntity model = this;
|
||||
// int lastEntityId = ReflectionManager.getNewEntityId();
|
||||
// System.out.println("RID:" + entityId);
|
||||
GeyserModelEngine.getInstance().setSpawningModelEntity(true);
|
||||
GeyserModelEngine.getInstance().setCurrentModel(model);
|
||||
entity = (LivingEntity) modeledEntity.getBase().getLocation().getWorld().spawnEntity(modeledEntity.getBase().getLocation(), GeyserModelEngine.getInstance().getModelEntityType());
|
||||
controllerEntity = new BukkitEntity(entity);
|
||||
public PacketEntity spawnEntity() {
|
||||
entity = new PacketEntity(GeyserModelEngine.getInstance().getModelEntityType(), viewers, modeledEntity.getBase().getLocation());
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package re.imc.geysermodelengine.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class EntityDestroyPacket implements WrapperPacket {
|
||||
|
||||
private final int id;
|
||||
|
||||
public EntityDestroyPacket(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketContainer encode() {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
packet.getIntLists().write(0, Collections.singletonList(this.id));
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package re.imc.geysermodelengine.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
public class EntityHurtAnimationPacket implements WrapperPacket {
|
||||
|
||||
private final int id;
|
||||
|
||||
public EntityHurtAnimationPacket(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketContainer encode() {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.HURT_ANIMATION);
|
||||
packet.getIntegers().write(0, id);
|
||||
packet.getFloat().write(0, 1f);
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package re.imc.geysermodelengine.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class EntitySpawnPacket implements WrapperPacket {
|
||||
|
||||
private final int id;
|
||||
private final UUID uuid;
|
||||
private final EntityType type;
|
||||
private final Location location;
|
||||
public EntitySpawnPacket(int entityID, UUID uuid, EntityType type, Location location) {
|
||||
this.id = entityID;
|
||||
this.uuid = uuid;
|
||||
this.type = type;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketContainer encode() {
|
||||
PacketContainer packet = ProtocolLibrary.getProtocolManager()
|
||||
.createPacket(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
packet.getIntegers()
|
||||
.write(0, this.id);
|
||||
packet.getUUIDs()
|
||||
.write(0, this.uuid);
|
||||
packet.getDoubles()
|
||||
.write(0, this.location.getX())
|
||||
.write(1, this.location.getY())
|
||||
.write(2, this.location.getZ());
|
||||
packet.getBytes()
|
||||
.write(0, (byte) (this.location.getYaw() * 256.0F / 360.0F))
|
||||
.write(1, (byte) (this.location.getPitch() * 256.0F / 360.0F));
|
||||
packet.getEntityTypeModifier()
|
||||
.writeSafely(0, type);
|
||||
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package re.imc.geysermodelengine.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class EntityTeleportPacket implements WrapperPacket {
|
||||
|
||||
private final int id;
|
||||
private final Location loc;
|
||||
|
||||
public EntityTeleportPacket(int entityID, Location location) {
|
||||
this.id = entityID;
|
||||
this.loc = location;
|
||||
}
|
||||
@Override
|
||||
public PacketContainer encode() {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
packet.getIntegers().write(0, this.id);
|
||||
packet.getDoubles().write(0, loc.getX());
|
||||
packet.getDoubles().write(1, loc.getY());
|
||||
packet.getDoubles().write(2, loc.getZ());
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package re.imc.geysermodelengine.packet;
|
||||
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
public interface WrapperPacket {
|
||||
|
||||
default WrapperPacket decode() { return null; };
|
||||
default PacketContainer encode() { return null; };
|
||||
}
|
||||
@@ -0,0 +1,804 @@
|
||||
package re.imc.geysermodelengine.packet.entity;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import io.papermc.paper.entity.TeleportFlag;
|
||||
import io.papermc.paper.threadedregions.scheduler.EntityScheduler;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.PistonMoveReaction;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import re.imc.geysermodelengine.packet.EntityDestroyPacket;
|
||||
import re.imc.geysermodelengine.packet.EntityHurtAnimationPacket;
|
||||
import re.imc.geysermodelengine.packet.EntitySpawnPacket;
|
||||
import re.imc.geysermodelengine.packet.EntityTeleportPacket;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class PacketEntity implements Entity {
|
||||
public PacketEntity(EntityType type, Set<Player> viewers, Location location) {
|
||||
this.id = ThreadLocalRandom.current().nextInt(20000, 100000000);
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.type = type;
|
||||
this.viewers = viewers;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
private int id;
|
||||
private UUID uuid;
|
||||
private EntityType type;
|
||||
private Set<Player> viewers;
|
||||
private Location location;
|
||||
private boolean removed = false;
|
||||
@Override
|
||||
public @NotNull Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(@NotNull Location location) {
|
||||
this.location = location;
|
||||
sendLocationPacket(viewers);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
removed = true;
|
||||
sendEntityDestroyPacket(viewers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDead() {
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return !removed;
|
||||
}
|
||||
|
||||
public void sendSpawnPacket(Collection<Player> players) {
|
||||
EntitySpawnPacket packet = new EntitySpawnPacket(id, uuid, type, location);
|
||||
players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet.encode()));
|
||||
}
|
||||
public void sendLocationPacket(Collection<Player> players) {
|
||||
EntityTeleportPacket packet = new EntityTeleportPacket(id, location);
|
||||
players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet.encode()));
|
||||
|
||||
}
|
||||
|
||||
public void sendHurtPacket(Collection<Player> players) {
|
||||
EntityHurtAnimationPacket packet = new EntityHurtAnimationPacket(id);
|
||||
players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet.encode()));
|
||||
|
||||
}
|
||||
|
||||
public void sendEntityDestroyPacket(Collection<Player> players) {
|
||||
EntityDestroyPacket packet = new EntityDestroyPacket(id);
|
||||
players.forEach(player -> ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet.encode()));
|
||||
|
||||
}
|
||||
|
||||
// ----------------
|
||||
|
||||
@Override
|
||||
public @Nullable Location getLocation(@Nullable Location location) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVelocity(@NotNull Vector vector) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Vector getVelocity() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BoundingBox getBoundingBox() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnGround() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInWater() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull World getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(float v, float v1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(@NotNull Location location, PlayerTeleportEvent.@NotNull TeleportCause teleportCause, @NotNull TeleportFlag @NotNull ... teleportFlags) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean teleport(@NotNull Location location, PlayerTeleportEvent.@NotNull TeleportCause teleportCause) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(@NotNull Entity entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean teleport(@NotNull Entity entity, PlayerTeleportEvent.@NotNull TeleportCause teleportCause) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Boolean> teleportAsync(@NotNull Location location, PlayerTeleportEvent.@NotNull TeleportCause teleportCause, @NotNull TeleportFlag @NotNull ... teleportFlags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<Entity> getNearbyEntities(double v, double v1, double v2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntityId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFireTicks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxFireTicks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFireTicks(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisualFire(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisualFire() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFreezeTicks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxFreezeTicks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFreezeTicks(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFrozen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInvisible(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNoPhysics(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNoPhysics() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFreezeTickingLocked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockFreezeTicks(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NotNull String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NotNull String... strings) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@Nullable UUID uuid, @NotNull String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@Nullable UUID uuid, @NotNull String... strings) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Server getServer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPersistent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPersistent(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Entity getPassenger() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setPassenger(@NotNull Entity entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<Entity> getPassengers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addPassenger(@NotNull Entity entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removePassenger(@NotNull Entity entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eject() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFallDistance() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFallDistance(float v) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastDamageCause(@Nullable EntityDamageEvent entityDamageEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable EntityDamageEvent getLastDamageCause() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull UUID getUniqueId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTicksLived() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTicksLived(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playEffect(@NotNull EntityEffect entityEffect) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EntityType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Sound getSwimSound() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Sound getSwimSplashSound() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Sound getSwimHighSpeedSplashSound() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInsideVehicle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean leaveVehicle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Entity getVehicle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomNameVisible(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomNameVisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisibleByDefault(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisibleByDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<Player> getTrackedBy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGlowing(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGlowing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInvulnerable(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvulnerable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSilent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSilent(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGravity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGravity(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPortalCooldown() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPortalCooldown(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<String> getScoreboardTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addScoreboardTag(@NotNull String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeScoreboardTag(@NotNull String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PistonMoveReaction getPistonMoveReaction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockFace getFacing() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Pose getPose() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSneaking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSneaking(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPose(@NotNull Pose pose, boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFixedPose() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SpawnCategory getSpawnCategory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInWorld() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable EntitySnapshot createSnapshot() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Entity copy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Entity copy(@NotNull Location location) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Spigot spigot() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component name() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component teamDisplayName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getOrigin() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fromMobSpawner() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreatureSpawnEvent.@NotNull SpawnReason getEntitySpawnReason() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderWater() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInRain() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInBubbleColumn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInWaterOrRain() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInWaterOrBubbleColumn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInWaterOrRainOrBubbleColumn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInLava() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTicking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<Player> getTrackedPlayers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnAt(@NotNull Location location, CreatureSpawnEvent.@NotNull SpawnReason spawnReason) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInPowderedSnow() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getZ() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPitch() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYaw() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean collidesAt(@NotNull Location location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wouldCollideUsing(@NotNull BoundingBox boundingBox) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EntityScheduler getScheduler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getScoreboardEntryName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component customName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(@Nullable Component component) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getCustomName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(@Nullable String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMetadata(@NotNull String s, @NotNull MetadataValue metadataValue) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<MetadataValue> getMetadata(@NotNull String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMetadata(@NotNull String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMetadata(@NotNull String s, @NotNull Plugin plugin) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NotNull String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(@NotNull Permission permission) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NotNull Permission permission) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String s, boolean b) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PermissionAttachment addAttachment(@NotNull Plugin plugin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String s, boolean b, int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable PermissionAttachment addAttachment(@NotNull Plugin plugin, int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(@NotNull PermissionAttachment permissionAttachment) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PersistentDataContainer getPersistentDataContainer() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
skin-send-delay: 0
|
||||
skin-view-distance: 50
|
||||
data-send-delay: 0
|
||||
entity-view-distance: 50
|
||||
join-send-delay: 20
|
||||
model-entity-type: BAT # must be a living entity
|
||||
debug: false
|
||||
Reference in New Issue
Block a user