mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
Merge pull request #172 from yusshu/remapped
Micro-optimization on methods that are called a lot of times
This commit is contained in:
@@ -3,6 +3,8 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
|||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||||
|
import com.hibiscusmc.hmccosmetics.user.manager.UserEntity;
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -39,10 +41,11 @@ public class CosmeticBackpackType extends Cosmetic {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull CosmeticUser user) {
|
public void update(@NotNull CosmeticUser user) {
|
||||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
Entity entity = user.getEntity();
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
|
|
||||||
Location loc = entity.getLocation().clone().add(0, 2, 0);
|
Location entityLocation = entity.getLocation();
|
||||||
|
Location loc = entityLocation.clone().add(0, 2, 0);
|
||||||
|
|
||||||
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
|
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
|
||||||
if (user.isHidden()) {
|
if (user.isHidden()) {
|
||||||
@@ -50,22 +53,27 @@ public class CosmeticBackpackType extends Cosmetic {
|
|||||||
user.despawnBackpack();
|
user.despawnBackpack();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
|
|
||||||
|
|
||||||
user.getUserBackpackManager().getEntityManager().teleport(loc);
|
UserBackpackManager backpackManager = user.getUserBackpackManager();
|
||||||
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
UserEntity entityManager = backpackManager.getEntityManager();
|
||||||
|
int firstArmorStandId = backpackManager.getFirstArmorStandId();
|
||||||
|
|
||||||
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
|
List<Player> outsideViewers = entityManager.refreshViewers(loc);
|
||||||
HMCCPacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
|
||||||
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
|
entityManager.teleport(loc);
|
||||||
|
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||||
|
|
||||||
|
HMCCPacketManager.sendEntitySpawnPacket(entityLocation, firstArmorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
|
||||||
|
HMCCPacketManager.sendArmorstandMetadata(firstArmorStandId, outsideViewers);
|
||||||
|
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
|
||||||
// If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players
|
// If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players
|
||||||
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
|
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, entityManager.getViewers());
|
||||||
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, outsideViewers);
|
||||||
|
|
||||||
if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
|
if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
|
||||||
List<Player> owner = List.of(user.getPlayer());
|
List<Player> owner = List.of(user.getPlayer());
|
||||||
|
|
||||||
ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId();
|
ArrayList<Integer> particleCloud = backpackManager.getAreaEffectEntityId();
|
||||||
for (int i = 0; i < particleCloud.size(); i++) {
|
for (int i = 0; i < particleCloud.size(); i++) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
|
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
|
||||||
@@ -73,16 +81,16 @@ public class CosmeticBackpackType extends Cosmetic {
|
|||||||
HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
|
HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
|
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), firstArmorStandId, owner);
|
||||||
if (!user.isHidden()) {
|
if (!user.isHidden()) {
|
||||||
//if (loc.getPitch() < -70) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, new ItemStack(Material.AIR), owner);
|
//if (loc.getPitch() < -70) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, new ItemStack(Material.AIR), owner);
|
||||||
//else NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
|
//else NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
|
||||||
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
|
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
|
||||||
}
|
}
|
||||||
//MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
|
//MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getUserBackpackManager().showBackpack();
|
backpackManager.showBackpack();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFirstPersonCompadible() {
|
public boolean isFirstPersonCompadible() {
|
||||||
|
|||||||
@@ -79,8 +79,8 @@ public class CosmeticBalloonType extends Cosmetic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector velocity = newLocation.toVector().subtract(currentLocation.toVector());
|
Vector velocity = newLocation.toVector().subtract(currentLocation.toVector());
|
||||||
userBalloonManager.setVelocity(velocity.multiply(1.1));
|
|
||||||
userBalloonManager.setLocation(newLocation);
|
userBalloonManager.setLocation(newLocation);
|
||||||
|
userBalloonManager.setVelocity(velocity.multiply(1.1));
|
||||||
|
|
||||||
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||||
HMCCPacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
|
HMCCPacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
|
||||||
|
|||||||
@@ -700,7 +700,6 @@ public class PlayerGameListener implements Listener {
|
|||||||
for (final EquipmentSlot slot : EquipmentSlot.values()) {
|
for (final EquipmentSlot slot : EquipmentSlot.values()) {
|
||||||
final Set<Material> armorItems = ARMOR_ITEMS.get(slot);
|
final Set<Material> armorItems = ARMOR_ITEMS.get(slot);
|
||||||
if (armorItems == null) continue;
|
if (armorItems == null) continue;
|
||||||
if (material == null) continue;
|
|
||||||
if (armorItems.contains(material)) return slot;
|
if (armorItems.contains(material)) return slot;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ public class CosmeticUser implements CosmeticHolder {
|
|||||||
|
|
||||||
this.updateCosmetic();
|
this.updateCosmetic();
|
||||||
|
|
||||||
if(isHidden() && !getUserEmoteManager().isPlayingEmote() && !getCosmetics().isEmpty()) {
|
if(isHidden() && !getUserEmoteManager().isPlayingEmote() && !playerCosmetics.isEmpty()) {
|
||||||
MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
|
MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,11 +301,10 @@ public class CosmeticUser implements CosmeticHolder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateCosmetic(@NotNull CosmeticSlot slot) {
|
public void updateCosmetic(@NotNull CosmeticSlot slot) {
|
||||||
if (getCosmetic(slot) == null) {
|
Cosmetic cosmetic = playerCosmetics.get(slot);
|
||||||
return;
|
if (cosmetic != null) {
|
||||||
|
cosmetic.update(this);
|
||||||
}
|
}
|
||||||
getCosmetic(slot).update(this);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCosmetic(Cosmetic cosmetic) {
|
public void updateCosmetic(Cosmetic cosmetic) {
|
||||||
@@ -316,7 +315,7 @@ public class CosmeticUser implements CosmeticHolder {
|
|||||||
MessagesUtil.sendDebugMessages("updateCosmetic (All) - start");
|
MessagesUtil.sendDebugMessages("updateCosmetic (All) - start");
|
||||||
HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
|
HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
|
||||||
|
|
||||||
for (Cosmetic cosmetic : getCosmetics()) {
|
for (Cosmetic cosmetic : playerCosmetics.values()) {
|
||||||
if (cosmetic instanceof CosmeticArmorType armorType) {
|
if (cosmetic instanceof CosmeticArmorType armorType) {
|
||||||
if (getUserEmoteManager().isPlayingEmote() || isInWardrobe()) return;
|
if (getUserEmoteManager().isPlayingEmote() || isInWardrobe()) return;
|
||||||
if (!(getEntity() instanceof HumanEntity humanEntity)) return;
|
if (!(getEntity() instanceof HumanEntity humanEntity)) return;
|
||||||
@@ -328,7 +327,7 @@ public class CosmeticUser implements CosmeticHolder {
|
|||||||
|
|
||||||
items.put(HMCCInventoryUtils.getEquipmentSlot(armorType.getSlot()), armorType.getItem(this));
|
items.put(HMCCInventoryUtils.getEquipmentSlot(armorType.getSlot()), armorType.getItem(this));
|
||||||
} else {
|
} else {
|
||||||
updateCosmetic(cosmetic.getSlot());
|
cosmetic.update(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (items.isEmpty() || getEntity() == null) return;
|
if (items.isEmpty() || getEntity() == null) return;
|
||||||
@@ -633,7 +632,7 @@ public class CosmeticUser implements CosmeticHolder {
|
|||||||
public List<CosmeticSlot> getDyeableSlots() {
|
public List<CosmeticSlot> getDyeableSlots() {
|
||||||
ArrayList<CosmeticSlot> dyableSlots = new ArrayList<>();
|
ArrayList<CosmeticSlot> dyableSlots = new ArrayList<>();
|
||||||
|
|
||||||
for (Cosmetic cosmetic : getCosmetics()) {
|
for (Cosmetic cosmetic : playerCosmetics.values()) {
|
||||||
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
|
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class UserBackpackManager {
|
|||||||
@Getter
|
@Getter
|
||||||
private boolean backpackHidden;
|
private boolean backpackHidden;
|
||||||
@Getter
|
@Getter
|
||||||
private int invisibleArmorStand;
|
private final int invisibleArmorStand;
|
||||||
private ArrayList<Integer> particleCloud = new ArrayList<>();
|
private ArrayList<Integer> particleCloud = new ArrayList<>();
|
||||||
@Getter
|
@Getter
|
||||||
private final CosmeticUser user;
|
private final CosmeticUser user;
|
||||||
|
|||||||
@@ -180,6 +180,10 @@ public class UserBalloonManager {
|
|||||||
this.getModelEntity().teleport(location);
|
this.getModelEntity().teleport(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector getVelocity() {
|
||||||
|
return getModelEntity().getVelocity();
|
||||||
|
}
|
||||||
|
|
||||||
public void setVelocity(Vector vector) {
|
public void setVelocity(Vector vector) {
|
||||||
this.getModelEntity().setVelocity(vector);
|
this.getModelEntity().setVelocity(vector);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -389,13 +389,7 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<Player> getViewers(@NotNull Location location) {
|
public static List<Player> getViewers(@NotNull Location location) {
|
||||||
ArrayList<Player> viewers = new ArrayList<>();
|
return PacketManager.getViewers(location, Settings.getViewDistance());
|
||||||
if (Settings.getViewDistance() <= 0) {
|
|
||||||
viewers.addAll(location.getWorld().getPlayers());
|
|
||||||
} else {
|
|
||||||
viewers.addAll(PacketManager.getViewers(location, Settings.getViewDistance()));
|
|
||||||
}
|
|
||||||
return viewers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendPacket(Player player, PacketContainer packet) {
|
public static void sendPacket(Player player, PacketContainer packet) {
|
||||||
|
|||||||
Reference in New Issue
Block a user