9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2026-01-04 15:41:45 +00:00

Fixed ModelEngine bug again

This commit is contained in:
Fisher2911
2022-03-12 13:16:09 -05:00
parent a06a5004e1
commit 13212fe26e
5 changed files with 101 additions and 102 deletions

View File

@@ -123,7 +123,7 @@ public class CitizensHook implements Hook, Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onNpcLoad(final PlayerCreateNPCEvent event) {
this.loadNpc(event.getNPC());
this.loadNpc(event.getNPC());
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@@ -133,12 +133,13 @@ public class CitizensHook implements Hook, Listener {
private void loadNpc(final NPC npc) {
if (Bukkit.getPlayer(npc.getUniqueId()) != null) return;
if (npc.getEntity() == null) return;
final Entity entity = npc.getEntity();
if (entity == null) return;
Bukkit.getScheduler().runTaskLater(this.plugin,
() -> Threads.getInstance().execute(() -> this.database.loadNPCUser(
npc.getId(),
npc.getEntity(),
entity,
user -> Bukkit.getScheduler().runTask(
this.plugin,
() -> {

View File

@@ -1,14 +1,5 @@
package io.github.fisher2911.hmccosmetics.hook;
import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import io.github.fisher2911.hmccosmetics.hook.entity.BalloonEntity;
import io.github.fisher2911.hmccosmetics.hook.entity.MEGEntity;
import org.bukkit.entity.Player;
import java.util.UUID;
public class ModelEngineHook implements Hook {
public ModelEngineHook() {
@@ -16,58 +7,6 @@ public class ModelEngineHook implements Hook {
private static final String ID = "model-engine";
public void updateModel(final BalloonEntity entity) {
final ModeledEntity model = ModelEngineAPI.getModeledEntity(entity.getUuid());
if (model == null) return;
if (model.getEntity() instanceof final MEGEntity e) e.update(entity);
}
public void spawnModel(final String id, final BalloonEntity entity) {
this.spawnModel(id, new MEGEntity(entity));
}
public void spawnModel(final String id, final MEGEntity entity) {
if (ModelEngineAPI.getModeledEntity(entity.getUuid()) != null) return;
final ActiveModel model = ModelEngineAPI.createActiveModel(id);
ModeledEntity modeledEntity = ModelEngineAPI.api.getModelManager().createModeledEntity(entity);
modeledEntity.addActiveModel(model);
}
public void addPlayerToModel(final Player player, final String id, final BalloonEntity entity) {
final ModeledEntity model = ModelEngineAPI.getModeledEntity(entity.getUuid());
if (model == null) {
this.spawnModel(id, entity);
return;
}
if (model.getPlayerInRange().contains(player)) return;
model.addPlayerAsync(player);
}
public void removePlayerFromModel(final Player player, final UUID uuid) {
final ModeledEntity model = ModelEngineAPI.getModeledEntity(uuid);
if (model == null) return;
model.removePlayerAsync(player);
}
public void remove(final UUID uuid) {
final ModeledEntity entity = ModelEngineAPI.getModeledEntity(uuid);
if (entity == null) return;
for (final Player player : entity.getPlayerInRange()) {
entity.removePlayerAsync(player);
}
entity.getEntity().remove();
ModelEngineAPI.api.getModelManager().removeModeledEntity(uuid);
}
@Override
public String getId() {
return ID;

View File

@@ -1,72 +1,124 @@
package io.github.fisher2911.hmccosmetics.hook.entity;
import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.UUID;
public class BalloonEntity {
private final UUID uuid;
private final int entityId;
private EntityType entityType;
private Vector velocity;
private Location location;
private boolean alive;
private final MEGEntity megEntity;
// private final UUID uuid;
// private final int entityId;
// private EntityType entityType;
// private Vector velocity;
// private Location location;
// private boolean alive;
public BalloonEntity(final UUID uuid, final int entityId, final EntityType entityType, final Vector velocity, final Location location, final boolean alive) {
this.uuid = uuid;
this.entityId = entityId;
this.entityType = entityType;
this.velocity = velocity;
this.location = location;
this.alive = alive;
this.megEntity = new MEGEntity(uuid, entityId, entityType, velocity, location, alive);
// this.uuid = uuid;
// this.entityId = entityId;
// this.entityType = entityType;
// this.velocity = velocity;
// this.location = location;
// this.alive = alive;
// this.megEntity = new MEGEntity(this);
}
public BalloonEntity(final UUID uuid, final int entityId, final EntityType entityType) {
this.uuid = uuid;
this.entityId = entityId;
this.entityType = entityType;
// this.uuid = uuid;
// this.entityId = entityId;
// this.entityType = entityType;
this.megEntity = new MEGEntity(uuid, entityId, entityType);
}
public UUID getUuid() {
return uuid;
return this.megEntity.getUuid();
}
public int getEntityId() {
return entityId;
return this.megEntity.getEntityId();
}
public EntityType getType() {
return entityType;
}
public void setEntityType(final EntityType entityType) {
this.entityType = entityType;
return this.megEntity.getType();
}
public Vector getVelocity() {
return velocity;
return this.megEntity.getVelocity();
}
public void setVelocity(final Vector velocity) {
this.velocity = velocity;
this.megEntity.setVelocity(velocity);
}
public Location getLocation() {
return location;
return this.megEntity.getLocation();
}
public void setLocation(final Location location) {
this.location = location;
this.megEntity.setLocation(location);
}
public boolean isAlive() {
return alive;
return this.megEntity.isAlive();
}
public void setAlive(final boolean alive) {
this.alive = alive;
this.megEntity.setAlive(alive);
}
public void updateModel() {
final ModeledEntity model = ModelEngineAPI.getModeledEntity(this.getUuid());
if (model == null) return;
if (model.getEntity() instanceof final MEGEntity e) e.update(this);
}
public void spawnModel(final String id) {
if (ModelEngineAPI.getModeledEntity(this.getUuid()) != null) return;
final ActiveModel model = ModelEngineAPI.createActiveModel(id);
ModeledEntity modeledEntity = ModelEngineAPI.api.getModelManager().createModeledEntity(this.megEntity);
modeledEntity.addActiveModel(model);
}
public void addPlayerToModel(final Player player, final String id) {
final ModeledEntity model = ModelEngineAPI.getModeledEntity(this.getUuid());
if (model == null) {
this.spawnModel(id);
return;
}
if (model.getPlayerInRange().contains(player)) return;
model.addPlayerAsync(player);
}
public void removePlayerFromModel(final Player player) {
final ModeledEntity model = ModelEngineAPI.getModeledEntity(this.getUuid());
if (model == null) return;
model.removePlayerAsync(player);
}
public void remove() {
final ModeledEntity entity = ModelEngineAPI.getModeledEntity(this.getUuid());
if (entity == null) return;
for (final Player player : entity.getPlayerInRange()) {
entity.removePlayerAsync(player);
}
entity.getEntity().remove();
ModelEngineAPI.api.getModelManager().removeModeledEntity(this.getUuid());
}
}

View File

@@ -22,6 +22,7 @@ public class MEGEntity implements BaseEntity<MEGEntity> {
private final UUID uuid;
private final int entityId;
private final EntityType entityType;
private Vector velocity = new Vector(0, 0, 0);
private Location location;
private boolean alive;
@@ -29,22 +30,25 @@ public class MEGEntity implements BaseEntity<MEGEntity> {
public MEGEntity(final BalloonEntity entity) {
this.uuid = entity.getUuid();
this.entityId = entity.getEntityId();
this.entityType = entity.getType();
this.velocity = entity.getVelocity();
this.location = entity.getLocation();
this.alive = entity.isAlive();
}
protected MEGEntity(final UUID uuid, final int entityId, final Vector velocity, final Location location, final boolean alive) {
protected MEGEntity(final UUID uuid, final int entityId, final EntityType entityType, final Vector velocity, final Location location, final boolean alive) {
this.uuid = uuid;
this.entityId = entityId;
this.entityType = entityType;
this.velocity = velocity;
this.location = location;
this.alive = alive;
}
protected MEGEntity(final UUID uuid, final int entityId) {
protected MEGEntity(final UUID uuid, final int entityId, final EntityType entityType) {
this.uuid = uuid;
this.entityId = entityId;
this.entityType = entityType;
this.alive = true;
}

View File

@@ -3,7 +3,6 @@ package io.github.fisher2911.hmccosmetics.user;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.Pair;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.config.CosmeticSettings;
import io.github.fisher2911.hmccosmetics.config.Settings;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
@@ -46,7 +45,11 @@ public abstract class BaseUser<T> {
this.id = id;
this.entityIds = entityIds;
this.playerArmor = playerArmor;
this.balloon = new BalloonEntity(UUID.randomUUID(), -1, EntityType.PUFFERFISH);
if (!HookManager.getInstance().isEnabled(ModelEngineHook.class)) {
this.balloon = null;
} else {
this.balloon = new BalloonEntity(UUID.randomUUID(), -1, EntityType.PUFFERFISH);
}
}
@Nullable
@@ -97,7 +100,7 @@ public abstract class BaseUser<T> {
public void despawnBalloon() {
final HookManager hookManager = HookManager.getInstance();
if (!hookManager.isEnabled(ModelEngineHook.class)) return;
hookManager.getModelEngineHook().remove(this.balloon.getUuid());
this.balloon.remove();
PacketManager.sendPacketToOnline(PacketManager.getEntityDestroyPacket(this.getBalloonId()));
this.viewingBalloon.clear();
this.balloon.setAlive(false);
@@ -106,7 +109,7 @@ public abstract class BaseUser<T> {
protected void despawnBalloon(final Player other) {
final HookManager hookManager = HookManager.getInstance();
if (!hookManager.isEnabled(ModelEngineHook.class)) return;
hookManager.getModelEngineHook().removePlayerFromModel(other, this.balloon.getUuid());
this.balloon.removePlayerFromModel(other);
PacketManager.sendPacket(other, PacketManager.getEntityDestroyPacket(this.getBalloonId()));
this.viewingBalloon.remove(other.getUniqueId());
if (this.viewingBalloon.isEmpty()) {
@@ -127,9 +130,8 @@ public abstract class BaseUser<T> {
if (!this.viewingBalloon.contains(other.getUniqueId())) {
this.viewingBalloon.add(other.getUniqueId());
this.balloon.setLocation(actual);
final ModelEngineHook hook = hookManager.getModelEngineHook();
hook.spawnModel(id, this.balloon);
hook.addPlayerToModel(other, id, this.balloon);
this.balloon.spawnModel(id);
this.balloon.addPlayerToModel(other, id);
}
this.updateBalloon(other, location, settings);
PacketManager.sendPacket(
@@ -158,7 +160,8 @@ public abstract class BaseUser<T> {
final Location previous = this.balloon.getLocation();
this.balloon.setLocation(actual);
this.balloon.setVelocity(actual.clone().subtract(previous.clone()).toVector());
hookManager.getModelEngineHook().updateModel(this.balloon);
// hookManager.getModelEngineHook().updateModel(this.balloon);
this.balloon.updateModel();
PacketManager.sendPacket(
other,
PacketManager.getTeleportPacket(this.getBalloonId(), actual),