9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-30 04:19:28 +00:00

feat: me4 balloons working?

This commit is contained in:
LoJoSho
2023-10-11 21:46:17 -05:00
parent b08b4019a9
commit 734c04c1f4
5 changed files with 48 additions and 27 deletions

View File

@@ -91,8 +91,7 @@ public class CosmeticBalloonType extends Cosmetic {
if (!user.getHidden() && showLead) {
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
if (sendTo.isEmpty()) return;
PacketManager.sendEntitySpawnPacket(newLocation, userBalloonManager.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager.getPufferfishBalloonUniqueId(), sendTo);
PacketManager.sendInvisibilityPacket(userBalloonManager.getPufferfishBalloonId(), sendTo);
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
}
}

View File

@@ -349,11 +349,14 @@ public class PlayerGameListener implements Listener {
public void onPlayerCosmeticEquip(PlayerCosmeticPostEquipEvent event) {
CosmeticUser user = event.getUser();
if (user.isInWardrobe() && event.getCosmetic().getSlot().equals(CosmeticSlot.BALLOON)) {
Location NPCLocation = user.getWardrobeManager().getNpcLocation();
CosmeticBalloonType cosmetic = (CosmeticBalloonType) event.getCosmetic();
Location npclocation = user.getWardrobeManager().getNpcLocation().clone().add(cosmetic.getBalloonOffset());
// We know that no other entity besides a regular player will be in the wardrobe
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), NPCLocation.add(cosmetic.getBalloonOffset()), false, List.of(user.getPlayer()));
user.getBalloonManager().getModelEntity().teleport(NPCLocation.add(cosmetic.getBalloonOffset()));
List<Player> viewer = List.of(user.getPlayer());
user.getBalloonManager().getPufferfish().spawnPufferfish(npclocation.clone().add(cosmetic.getBalloonOffset()), viewer);
PacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), user.getWardrobeManager().getNPC_ID(), viewer);
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npclocation, false, viewer);
user.getBalloonManager().getModelEntity().teleport(npclocation);
}
}

View File

@@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.ticxo.modelengine.api.ModelEngineAPI;
@@ -24,18 +25,23 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
public class UserBalloonManager {
private CosmeticUser user;
@Getter
private BalloonType balloonType;
private CosmeticBalloonType cosmeticBalloonType;
@Getter
private UserBalloonPufferfish pufferfish;
private final ArmorStand modelEntity;
public UserBalloonManager(CosmeticUser user, @NotNull Location location) {
this.user = user;
this.pufferfish = new UserBalloonPufferfish(user.getUniqueId(), NMSHandlers.getHandler().getNextEntityId(), UUID.randomUUID());
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
}
@@ -65,6 +71,7 @@ public class UserBalloonManager {
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id));
model.setCanHurt(false);
modeledEntity.addModel(model, false);
if (color != null) {
modeledEntity.getModels().forEach((d, singleModel) -> {
if (cosmeticBalloonType.isDyablePart(d)) {
@@ -73,6 +80,10 @@ public class UserBalloonManager {
}
});
}
BukkitEntityData data = (BukkitEntityData) modeledEntity.getBase().getData();
data.setBlockedCullIgnoreRadius((double) Settings.getViewDistance());
data.getTracked().setPlayerPredicate(this::playerCheck);
return;
}
if (balloonType == BalloonType.ITEM) {
@@ -88,10 +99,6 @@ public class UserBalloonManager {
return;
}
//for (String model : entity.getModels().keySet()) {
// entity.removeModel(model);
//}
entity.destroy();
MessagesUtil.sendDebugMessages("Balloon Model Engine Removal");
}
@@ -113,13 +120,7 @@ public class UserBalloonManager {
MessagesUtil.sendDebugMessages("model is null");
return;
}
BukkitEntityData data = (BukkitEntityData) model.getBase().getData();
data.getTracked().setPlayerPredicate(player -> {
if (player == user.getPlayer()) {
return true;
}
else return false;
});
MessagesUtil.sendDebugMessages("Show to player");
return;
}
@@ -131,14 +132,6 @@ public class UserBalloonManager {
if (balloonType == BalloonType.MODELENGINE) {
final ModeledEntity model = ModelEngineAPI.getModeledEntity(modelEntity);
if (model == null) return;
BukkitEntityData data = (BukkitEntityData) model.getBase().getData();
//data.getTracked().removeForcedPairing(viewer);
data.getTracked().setPlayerPredicate(player -> {
if (player.getUniqueId() == viewer.getUniqueId()) {
return true;
}
else return false;
});
MessagesUtil.sendDebugMessages("Hidden from player");
return;
@@ -190,7 +183,6 @@ public class UserBalloonManager {
}
public void sendLeashPacket(int entityId) {
if (cosmeticBalloonType == null) return;
if (cosmeticBalloonType.isShowLead()) {
PacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation());
}
@@ -201,4 +193,21 @@ public class UserBalloonManager {
ITEM,
NONE
}
private boolean playerCheck(final Player player) {
MessagesUtil.sendDebugMessages("playerCheck");
CosmeticUser viewer = CosmeticUsers.getUser(player.getUniqueId());
if (user.getPlayer() == player) {
return true;
} else {
if (user.isInWardrobe()) return false;
MessagesUtil.sendDebugMessages("playerCheck - Not Same Player");
if (viewer != null && viewer.isInWardrobe()) {
MessagesUtil.sendDebugMessages("playerCheck - Viewer in Wardrobe");
return false;
}
}
return (!user.getHidden());
}
}

View File

@@ -1,10 +1,12 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.comphenix.protocol.PacketType;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@@ -35,6 +37,11 @@ public class UserBalloonPufferfish extends UserEntity {
getViewers().clear();
}
public void spawnPufferfish(Location location, List<Player> sendTo) {
PacketManager.sendEntitySpawnPacket(location, pufferFishEntityId, EntityType.PUFFERFISH, uuid, sendTo);
PacketManager.sendInvisibilityPacket(pufferFishEntityId, sendTo);
}
@Override
public List<Player> refreshViewers(Location location) {
if (System.currentTimeMillis() - getViewerLastUpdate() <= 1000) return List.of(); //Prevents mass refreshes

View File

@@ -145,6 +145,7 @@ public class UserWardrobeManager {
Location balloonLocation = npcLocation.clone().add(cosmetic.getBalloonOffset());
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), balloonLocation , false, viewer);
user.getBalloonManager().getModelEntity().teleport(balloonLocation);
user.getBalloonManager().setLocation(balloonLocation);
}
if (WardrobeSettings.isEnabledBossbar()) {
@@ -234,7 +235,7 @@ public class UserWardrobeManager {
}
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
user.respawnBalloon();
//user.respawnBalloon();
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
}
@@ -300,7 +301,9 @@ public class UserWardrobeManager {
//PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npcLocation.add(Settings.getBalloonOffset()), false, viewer);
//user.getBalloonManager().getModelEntity().teleport(npcLocation.add(Settings.getBalloonOffset()));
user.getBalloonManager().sendRemoveLeashPacket(outsideViewers);
PacketManager.sendEntityDestroyPacket(user.getBalloonManager().getModelId(), outsideViewers);
if (user.getBalloonManager().getBalloonType() != UserBalloonManager.BalloonType.MODELENGINE) {
PacketManager.sendEntityDestroyPacket(user.getBalloonManager().getModelId(), outsideViewers);
}
user.getBalloonManager().sendLeashPacket(NPC_ID);
}