diff --git a/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java b/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java index 943f06f0..ff969105 100644 --- a/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java +++ b/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java @@ -1,14 +1,10 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types; -import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; -import com.hibiscusmc.hmccosmetics.entities.MEGEntity; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; -import com.ticxo.modelengine.api.ModelEngineAPI; -import com.ticxo.modelengine.api.generator.model.ModelBlueprint; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -39,8 +35,8 @@ public class CosmeticBalloonType extends Cosmetic { user.getBalloonEntity().setVelocity(actual.clone().subtract(previous.clone()).toVector()); user.getBalloonEntity().updateModel(); - PacketManager.sendTeleportPacket(user.getBalloonEntity().getBalloonID(), actual, false, PlayerUtils.getNearbyPlayers(player)); - PacketManager.sendLeashPacket(user.getBalloonEntity().getBalloonID(), player.getEntityId(), PlayerUtils.getNearbyPlayers(player)); + PacketManager.sendTeleportPacket(user.getBalloonEntity().getPufferfishBalloonId(), actual, false, PlayerUtils.getNearbyPlayers(player)); + PacketManager.sendLeashPacket(user.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), PlayerUtils.getNearbyPlayers(player)); } public String getModelName() { diff --git a/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java b/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java index 0542d500..78ba1c4c 100644 --- a/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java +++ b/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java @@ -4,6 +4,7 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.ticxo.modelengine.api.ModelEngineAPI; import com.ticxo.modelengine.api.model.ActiveModel; import com.ticxo.modelengine.api.model.ModeledEntity; +import net.minecraft.world.entity.Entity; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -17,13 +18,15 @@ public class BalloonEntity { private final UUID uniqueID; private final MEGEntity megEntity; - public BalloonEntity(int balloonID, Location location) { + public BalloonEntity(Location location) { this.uniqueID = UUID.randomUUID(); - this.balloonID = balloonID; - this.megEntity = new MEGEntity(UUID.randomUUID(), balloonID, new Vector(0, 0, 0), location, false); + this.balloonID = Entity.nextEntityId(); + this.megEntity = new MEGEntity(UUID.randomUUID(), Entity.nextEntityId(), new Vector(0, 0, 0), location, false); } public void updateModel() { + this.megEntity.update(); + /* final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(megEntity.getUniqueId()); if (model == null) return; @@ -32,6 +35,7 @@ public class BalloonEntity { //HMCCosmeticsPlugin.getInstance().getLogger().info("Updated Model"); e.update(this); } + */ } public void spawnModel(final String id) { @@ -69,6 +73,15 @@ public class BalloonEntity { model.showToPlayer(player); } + public void addPlayerToModel(final Player player) { + final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(megEntity.getUniqueId()); + if (model == null) { + return; + } + //if (megEntity.getRangeManager().getPlayerInRange().contains(player)) return; + model.showToPlayer(player); + } + public void removePlayerFromModel(final Player player) { final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(megEntity.getUniqueId()); @@ -78,17 +91,21 @@ public class BalloonEntity { } - public int getBalloonID() { + public int getPufferfishBalloonId() { return balloonID; } - public UUID getBalloonUUID() { + public UUID getPufferfishBalloonUniqueId() { return uniqueID; } - public UUID getUniqueID() { + public UUID getModelUnqiueId() { return megEntity.getUniqueId(); } + public int getModelId() { + return megEntity.getEntityId(); + } + public Location getLocation() { return this.megEntity.getLocation(); } diff --git a/src/main/java/com/hibiscusmc/hmccosmetics/entities/MEGEntity.java b/src/main/java/com/hibiscusmc/hmccosmetics/entities/MEGEntity.java index 72bcfcb0..8efc56d7 100644 --- a/src/main/java/com/hibiscusmc/hmccosmetics/entities/MEGEntity.java +++ b/src/main/java/com/hibiscusmc/hmccosmetics/entities/MEGEntity.java @@ -57,10 +57,10 @@ public class MEGEntity implements BaseEntity { this.alive = false; } - public void update(BalloonEntity entity) { - this.velocity = entity.getLocation().toVector(); - this.location = entity.getLocation(); - this.alive = entity.isAlive(); + public void update() { + for (Player player : rangeManager.getPlayerInRange()) { + rangeManager.updatePlayer(player); + } } public void setVelocity(final Vector velocity) { diff --git a/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java b/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java index e6489091..4ccc84a7 100644 --- a/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -9,13 +9,8 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; import com.hibiscusmc.hmccosmetics.entities.InvisibleArmorstand; -import com.hibiscusmc.hmccosmetics.entities.MEGEntity; import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; -import com.ticxo.modelengine.api.ModelEngineAPI; -import com.ticxo.modelengine.api.model.ActiveModel; -import com.ticxo.modelengine.api.model.ModeledEntity; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -24,7 +19,6 @@ import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.util.Vector; import java.util.Collection; import java.util.HashMap; @@ -173,15 +167,15 @@ public class CosmeticUser { Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); if (this.balloonEntity != null) return; - BalloonEntity balloonEntity1 = new BalloonEntity(Entity.nextEntityId(), player.getLocation()); + BalloonEntity balloonEntity1 = new BalloonEntity(player.getLocation()); balloonEntity1.spawnModel(cosmeticBalloonType.getModelName()); balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName()); balloonEntity1.updateModel(); - PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getBalloonID(), EntityType.PUFFERFISH, balloonEntity1.getBalloonUUID(), sentTo); - PacketManager.sendInvisibilityPacket(balloonEntity1.getBalloonID(), sentTo); - PacketManager.sendLeashPacket(balloonEntity1.getBalloonID(), player.getEntityId(), sentTo); + PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo); + PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo); + PacketManager.sendLeashPacket(balloonEntity1.getPufferfishBalloonId(), player.getEntityId(), sentTo); this.balloonEntity = balloonEntity1; }