9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-26 18:39:07 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
LoJoSho
3b863e6dde version bump (2.4.7) 2023-06-22 13:38:54 -05:00
LoJoSho
b682dd7c42 feat: optimize new packet pufferfish system 2023-06-22 13:15:44 -05:00
LoJoSho
f34f5f01aa version bump (2.4.7-DEV) 2023-06-22 12:56:04 -05:00
LoJoSho
cb9248db7a feat: Refactored CosmeticUser to accept other entities, not just players 2023-06-22 12:55:56 -05:00
15 changed files with 177 additions and 103 deletions

View File

@@ -8,7 +8,7 @@ plugins {
} }
group = "com.hibiscusmc" group = "com.hibiscusmc"
version = "2.4.6" version = "2.4.7"
allprojects { allprojects {
apply(plugin = "java") apply(plugin = "java")

View File

@@ -52,7 +52,7 @@ public class Wardrobe {
public boolean canEnter(CosmeticUser user) { public boolean canEnter(CosmeticUser user) {
Location wardrobeLocation = location.getNpcLocation(); Location wardrobeLocation = location.getNpcLocation();
Location location = user.getPlayer().getLocation(); Location location = user.getEntity().getLocation();
if (wardrobeLocation == null) return false; if (wardrobeLocation == null) return false;
if (distance == -1) return true; if (distance == -1) return true;
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false; if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;

View File

@@ -8,6 +8,8 @@ import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -26,19 +28,20 @@ public class CosmeticArmorType extends Cosmetic {
@Override @Override
public void update(@NotNull CosmeticUser user) { public void update(@NotNull CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId()); Entity entity = Bukkit.getEntity(user.getUniqueId());
if (player == null) return; if (entity == null) return;
if (user.getUserEmoteManager().isPlayingEmote()) return; // There has to be a better way of doing this... if (user.getUserEmoteManager().isPlayingEmote()) return; // There has to be a better way of doing this...
ItemStack cosmeticItem = user.getUserCosmeticItem(this); ItemStack cosmeticItem = user.getUserCosmeticItem(this);
if (!(entity instanceof HumanEntity humanEntity)) return;
if (equipSlot.equals(EquipmentSlot.OFF_HAND)) { if (equipSlot.equals(EquipmentSlot.OFF_HAND)) {
if (!player.getInventory().getItemInOffHand().getType().isAir()) return; if (!humanEntity.getInventory().getItemInOffHand().getType().isAir()) return;
} }
ItemStack equippedItem = player.getInventory().getItem(equipSlot); ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot);
if (Settings.getShouldAddEnchants(equipSlot)) { if (Settings.getShouldAddEnchants(equipSlot)) {
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments()); cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
} }
NMSHandlers.getHandler().equipmentSlotUpdate(player.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(player.getLocation())); NMSHandlers.getHandler().equipmentSlotUpdate(entity.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(entity.getLocation()));
//PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation())); Old method //PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation())); Old method
} }

View File

@@ -7,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.ConfigurationNode;
@@ -27,10 +28,10 @@ public class CosmeticBackpackType extends Cosmetic {
@Override @Override
public void update(@NotNull CosmeticUser user) { public void update(@NotNull CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId()); Entity entity = Bukkit.getEntity(user.getUniqueId());
if (player == null) return; if (entity == null) return;
Location loc = player.getLocation().clone().add(0, 2, 0); Location loc = entity.getLocation().clone().add(0, 2, 0);
if (user.isInWardrobe() || !user.isBackpackSpawned()) return; if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
if (!user.getUserBackpackManager().IsValidBackpackEntity()) { if (!user.getUserBackpackManager().IsValidBackpackEntity()) {
@@ -46,10 +47,10 @@ public class CosmeticBackpackType extends Cosmetic {
if (user.getUserBackpackManager().getBackpackType().equals(UserBackpackManager.BackpackType.FIRST_PERSON)) { if (user.getUserBackpackManager().getBackpackType().equals(UserBackpackManager.BackpackType.FIRST_PERSON)) {
user.getUserBackpackManager().teleportEffectEntity(loc); user.getUserBackpackManager().teleportEffectEntity(loc);
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc); PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc);
PacketManager.sendRidingPacket(user.getUserBackpackManager().getAreaEffectEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc); PacketManager.sendRidingPacket(user.getUserBackpackManager().getAreaEffectEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
} else { } else {
PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc); PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc);
} }
user.getUserBackpackManager().getArmorStand().setRotation(loc.getYaw(), loc.getPitch()); user.getUserBackpackManager().getArmorStand().setRotation(loc.getYaw(), loc.getPitch());

View File

@@ -7,6 +7,8 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -42,10 +44,10 @@ public class CosmeticBalloonType extends Cosmetic {
@Override @Override
public void update(@NotNull CosmeticUser user) { public void update(@NotNull CosmeticUser user) {
Player player = Bukkit.getPlayer(user.getUniqueId()); Entity entity = Bukkit.getEntity(user.getUniqueId());
UserBalloonManager userBalloonManager = user.getBalloonManager(); UserBalloonManager userBalloonManager = user.getBalloonManager();
if (player == null || userBalloonManager == null) return; if (entity == null || userBalloonManager == null) return;
if (user.isInWardrobe()) return; if (user.isInWardrobe()) return;
if (!userBalloonManager.getModelEntity().isValid()) { if (!userBalloonManager.getModelEntity().isValid()) {
@@ -53,14 +55,13 @@ public class CosmeticBalloonType extends Cosmetic {
return; return;
} }
Location newLocation = player.getLocation(); Location newLocation = entity.getLocation();
Location currentLocation = user.getBalloonManager().getLocation(); Location currentLocation = user.getBalloonManager().getLocation();
newLocation = newLocation.clone().add(Settings.getBalloonOffset()); newLocation = newLocation.clone().add(Settings.getBalloonOffset());
List<Player> viewer = PacketManager.getViewers(player.getLocation()); List<Player> viewer = PacketManager.getViewers(entity.getLocation());
viewer.add(player);
if (player.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) { if (entity.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) {
userBalloonManager.getModelEntity().teleport(newLocation); userBalloonManager.getModelEntity().teleport(newLocation);
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer); PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
return; return;
@@ -71,7 +72,13 @@ public class CosmeticBalloonType extends Cosmetic {
userBalloonManager.setLocation(newLocation); userBalloonManager.setLocation(newLocation);
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer); PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
if (!user.getHidden() && showLead) PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), player.getEntityId(), viewer); PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
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);
}
} }
public String getModelName() { public String getModelName() {

View File

@@ -50,10 +50,13 @@ public abstract class Data {
return data; return data;
} }
@NotNull
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) { public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) {
return deserializeData(user, raw, Settings.getForcePermissionJoin());
}
@NotNull
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw, boolean checkpermissions) {
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>(); Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
boolean checkPermission = Settings.getForcePermissionJoin();
String[] rawData = raw.split(","); String[] rawData = raw.split(",");
for (String a : rawData) { for (String a : rawData) {
@@ -75,8 +78,8 @@ public abstract class Data {
String[] colorSplitData = splitData[1].split("&"); String[] colorSplitData = splitData[1].split("&");
if (Cosmetics.hasCosmetic(colorSplitData[0])) cosmetic = Cosmetics.getCosmetic(colorSplitData[0]); if (Cosmetics.hasCosmetic(colorSplitData[0])) cosmetic = Cosmetics.getCosmetic(colorSplitData[0]);
if (slot == null || cosmetic == null) continue; if (slot == null || cosmetic == null) continue;
if (cosmetic.requiresPermission() && checkPermission) { if (checkpermissions && cosmetic.requiresPermission()) {
if (!user.getPlayer().hasPermission(cosmetic.getPermission())) { if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
continue; continue;
} }
} }
@@ -84,8 +87,8 @@ public abstract class Data {
} else { } else {
if (Cosmetics.hasCosmetic(splitData[1])) cosmetic = Cosmetics.getCosmetic(splitData[1]); if (Cosmetics.hasCosmetic(splitData[1])) cosmetic = Cosmetics.getCosmetic(splitData[1]);
if (slot == null || cosmetic == null) continue; if (slot == null || cosmetic == null) continue;
if (cosmetic.requiresPermission() && checkPermission) { if (checkpermissions && cosmetic.requiresPermission()) {
if (!user.getPlayer().hasPermission(cosmetic.getPermission())) { if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
continue; continue;
} }
} }

View File

@@ -22,11 +22,13 @@ import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*; import org.bukkit.inventory.meta.*;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
@@ -261,7 +263,7 @@ public class CosmeticUser {
} }
} }
itemMeta.getPersistentDataContainer().set(InventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId()); itemMeta.getPersistentDataContainer().set(InventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId());
itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getPlayer().getUniqueId().toString()); itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getEntity().getUniqueId().toString());
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
} }
@@ -360,19 +362,13 @@ public class CosmeticUser {
} }
public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) { public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) {
Player player = Bukkit.getPlayer(getUniqueId());
if (this.userBalloonManager != null) return; if (this.userBalloonManager != null) return;
this.userBalloonManager = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType); this.userBalloonManager = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType);
List<Player> viewer = PlayerUtils.getNearbyPlayers(player);
viewer.add(player);
} }
public void despawnBalloon() { public void despawnBalloon() {
if (this.userBalloonManager == null) return; if (this.userBalloonManager == null) return;
List<Player> sentTo = PlayerUtils.getNearbyPlayers(getPlayer().getLocation()); List<Player> sentTo = PlayerUtils.getNearbyPlayers(getEntity().getLocation());
PacketManager.sendEntityDestroyPacket(userBalloonManager.getPufferfishBalloonId(), sentTo); PacketManager.sendEntityDestroyPacket(userBalloonManager.getPufferfishBalloonId(), sentTo);
@@ -395,13 +391,27 @@ public class CosmeticUser {
} }
public void removeArmor(CosmeticSlot slot) { public void removeArmor(CosmeticSlot slot) {
PacketManager.equipmentSlotUpdate(getPlayer().getEntityId(), this, slot, PlayerUtils.getNearbyPlayers(getPlayer())); PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, PlayerUtils.getNearbyPlayers(getEntity().getLocation()));
} }
/**
* This returns the player associated with the user. Some users may not have a player attached, ie, they are npcs
* wearing cosmetics through an addon. If you need to get locations, use getEntity instead.
* @return Player
*/
@Nullable
public Player getPlayer() { public Player getPlayer() {
return Bukkit.getPlayer(uniqueId); return Bukkit.getPlayer(uniqueId);
} }
/**
* This gets the entity associated with the user.
* @return Entity
*/
public Entity getEntity() {
return Bukkit.getEntity(uniqueId);
}
public Color getCosmeticColor(CosmeticSlot slot) { public Color getCosmeticColor(CosmeticSlot slot) {
return colors.get(slot); return colors.get(slot);
} }

View File

@@ -15,6 +15,7 @@ import org.bukkit.Color;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -27,13 +28,11 @@ public class UserBalloonManager {
private BalloonType balloonType; private BalloonType balloonType;
private CosmeticBalloonType cosmeticBalloonType; private CosmeticBalloonType cosmeticBalloonType;
private final int balloonID; private UserBalloonPufferfish pufferfish;
private final UUID uniqueID;
private final ArmorStand modelEntity; private final ArmorStand modelEntity;
public UserBalloonManager(@NotNull Location location) { public UserBalloonManager(@NotNull Location location) {
this.uniqueID = UUID.randomUUID(); this.pufferfish = new UserBalloonPufferfish(NMSHandlers.getHandler().getNextEntityId(), UUID.randomUUID());
this.balloonID = NMSHandlers.getHandler().getNextEntityId();
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset())); this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
} }
@@ -136,10 +135,10 @@ public class UserBalloonManager {
public int getPufferfishBalloonId() { public int getPufferfishBalloonId() {
return balloonID; return pufferfish.getId();
} }
public UUID getPufferfishBalloonUniqueId() { public UUID getPufferfishBalloonUniqueId() {
return uniqueID; return pufferfish.getUuid();
} }
public UUID getModelUnqiueId() { public UUID getModelUnqiueId() {
@@ -172,7 +171,13 @@ public class UserBalloonManager {
public void sendLeashPacket(int entityId) { public void sendLeashPacket(int entityId) {
if (cosmeticBalloonType == null) return; if (cosmeticBalloonType == null) return;
if (cosmeticBalloonType.isShowLead()) PacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation()); if (cosmeticBalloonType.isShowLead()) {
PacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation());
}
}
public UserBalloonPufferfish getPufferfish() {
return pufferfish;
} }
public enum BalloonType { public enum BalloonType {

View File

@@ -0,0 +1,58 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class UserBalloonPufferfish {
private int id;
private UUID uuid;
private List<Player> viewers = new ArrayList<>();
private Long lastUpdate;
public UserBalloonPufferfish(int id, UUID uuid) {
this.id = id;
this.uuid = uuid;
this.lastUpdate = System.currentTimeMillis();
}
public int getId() {
return id;
}
public UUID getUuid() {
return uuid;
}
public List<Player> refreshViewers(Location location) {
if (System.currentTimeMillis() - lastUpdate <= 1000) return List.of(); //Prevents mass refreshes
ArrayList<Player> newPlayers = new ArrayList<>();
ArrayList<Player> removePlayers = new ArrayList<>();
List<Player> players = PlayerUtils.getNearbyPlayers(location);
for (Player player : players) {
if (!viewers.contains(player)) {
viewers.add(player);
newPlayers.add(player);
continue;
}
// bad loopdy loops
for (Player viewerPlayer : viewers) {
if (!players.contains(viewerPlayer)) {
removePlayers.add(viewerPlayer);
PacketManager.sendEntityDestroyPacket(id, List.of(viewerPlayer)); // prevents random leashes
}
}
}
viewers.removeAll(removePlayers);
lastUpdate = System.currentTimeMillis();
return newPlayers;
}
}

View File

@@ -97,7 +97,7 @@ public class PacketManager extends BasePacket {
CosmeticSlot cosmeticSlot, CosmeticSlot cosmeticSlot,
List<Player> sendTo List<Player> sendTo
) { ) {
equipmentSlotUpdate(user.getPlayer().getEntityId(), user, cosmeticSlot, sendTo); equipmentSlotUpdate(user.getEntity().getEntityId(), user, cosmeticSlot, sendTo);
} }
public static void equipmentSlotUpdate( public static void equipmentSlotUpdate(

View File

@@ -47,7 +47,7 @@ import java.util.List;
public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public int getNextEntityId() { public int getNextEntityId() {
return Entity.nextEntityId(); return net.minecraft.world.entity.Entity.nextEntityId();
} }
@Override @Override
@@ -85,19 +85,16 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation()); HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
MessagesUtil.sendDebugMessages("spawnBackpack NMS"); MessagesUtil.sendDebugMessages("spawnBackpack NMS");
return invisibleArmorstand.getBukkitLivingEntity(); return invisibleArmorstand.getBukkitLivingEntity();
//PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
} }
@Override @Override
@@ -106,23 +103,21 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
} }
@Override @Override
public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {
Player player = user.getPlayer(); org.bukkit.entity.Entity entity = user.getEntity();
Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset());
UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation());
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); List<Player> sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation());
userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset()));
userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
userBalloonManager1.sendLeashPacket(player.getEntityId()); userBalloonManager1.sendLeashPacket(entity.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }

View File

@@ -47,7 +47,7 @@ import java.util.List;
public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public int getNextEntityId() { public int getNextEntityId() {
return Entity.nextEntityId(); return net.minecraft.world.entity.Entity.nextEntityId();
} }
@Override @Override
@@ -85,19 +85,16 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
HMCArmorStand HMCArmorStand = new HMCArmorStand(user.getPlayer().getLocation()); HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
HMCArmorStand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(HMCArmorStand, CreatureSpawnEvent.SpawnReason.CUSTOM); ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
MessagesUtil.sendDebugMessages("spawnBackpack NMS"); MessagesUtil.sendDebugMessages("spawnBackpack NMS");
return HMCArmorStand.getBukkitLivingEntity(); return invisibleArmorstand.getBukkitLivingEntity();
//PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
} }
@Override @Override
@@ -110,19 +107,19 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {
Player player = user.getPlayer(); org.bukkit.entity.Entity entity = user.getEntity();
Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset());
UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation());
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); List<Player> sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation());
userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset()));
userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
userBalloonManager1.sendLeashPacket(player.getEntityId()); userBalloonManager1.sendLeashPacket(entity.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }

View File

@@ -47,7 +47,7 @@ import java.util.List;
public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public int getNextEntityId() { public int getNextEntityId() {
return Entity.nextEntityId(); return net.minecraft.world.entity.Entity.nextEntityId();
} }
@Override @Override
@@ -85,19 +85,16 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation()); HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
MessagesUtil.sendDebugMessages("spawnBackpack NMS"); MessagesUtil.sendDebugMessages("spawnBackpack NMS");
return invisibleArmorstand.getBukkitLivingEntity(); return invisibleArmorstand.getBukkitLivingEntity();
//PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
} }
@Override @Override
@@ -109,19 +106,19 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {
Player player = user.getPlayer(); org.bukkit.entity.Entity entity = user.getEntity();
Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset());
UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation());
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); List<Player> sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation());
userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset()));
userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
userBalloonManager1.sendLeashPacket(player.getEntityId()); userBalloonManager1.sendLeashPacket(entity.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }

View File

@@ -22,7 +22,6 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerPlayerConnection; import net.minecraft.server.network.ServerPlayerConnection;
import net.minecraft.world.entity.Display; import net.minecraft.world.entity.Display;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.scores.PlayerTeam; import net.minecraft.world.scores.PlayerTeam;
@@ -36,6 +35,7 @@ import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_19_R3.scoreboard.CraftScoreboard; import org.bukkit.craftbukkit.v1_19_R3.scoreboard.CraftScoreboard;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
@@ -48,7 +48,7 @@ import java.util.List;
public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public int getNextEntityId() { public int getNextEntityId() {
return Entity.nextEntityId(); return net.minecraft.world.entity.Entity.nextEntityId();
} }
@Override @Override
@@ -86,18 +86,16 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation()); HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
MessagesUtil.sendDebugMessages("spawnBackpack NMS"); MessagesUtil.sendDebugMessages("spawnBackpack NMS");
return invisibleArmorstand.getBukkitLivingEntity(); return invisibleArmorstand.getBukkitLivingEntity();
//PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
} }
@Override @Override
@@ -115,19 +113,19 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {
Player player = user.getPlayer(); Entity entity = user.getEntity();
Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset());
UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation());
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); List<Player> sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation());
userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset()));
userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
userBalloonManager1.sendLeashPacket(player.getEntityId()); userBalloonManager1.sendLeashPacket(entity.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }

View File

@@ -48,7 +48,7 @@ import java.util.List;
public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public int getNextEntityId() { public int getNextEntityId() {
return Entity.nextEntityId(); return net.minecraft.world.entity.Entity.nextEntityId();
} }
@Override @Override
@@ -86,12 +86,12 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation()); HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
MessagesUtil.sendDebugMessages("spawnBackpack NMS"); MessagesUtil.sendDebugMessages("spawnBackpack NMS");
@@ -115,19 +115,19 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
@Override @Override
public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {
Player player = user.getPlayer(); org.bukkit.entity.Entity entity = user.getEntity();
Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset());
UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation());
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); List<Player> sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation());
userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset()));
userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
userBalloonManager1.sendLeashPacket(player.getEntityId()); userBalloonManager1.sendLeashPacket(entity.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }