Skip to content

Commit

Permalink
Small stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceX100 committed Nov 26, 2023
1 parent 8e54f19 commit 40b83ba
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

import java.io.File;
import java.nio.file.Path;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public final class HMCCosmeticsPlugin extends JavaPlugin {

Expand All @@ -52,6 +54,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
private static final int pluginId = 13873;
private static boolean onLatestVersion = true;
private static String latestVersion = "";
public static ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();

@Override
public void onEnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
Expand All @@ -15,6 +16,11 @@
import org.jetbrains.annotations.NotNull;
import org.spongepowered.configurate.ConfigurationNode;

import java.util.List;
import java.util.concurrent.Executors;

import static com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin.EXECUTOR;

public class CosmeticArmorType extends Cosmetic {

private final EquipmentSlot equipSlot;
Expand All @@ -40,7 +46,9 @@ public void update(@NotNull CosmeticUser user) {
if (!Settings.isCosmeticForceOffhandCosmeticShow()
&& equipSlot.equals(EquipmentSlot.OFF_HAND)
&& ((entity instanceof Player) && !user.getPlayer().getInventory().getItemInOffHand().getType().isAir())) return;
NMSHandlers.getHandler().equipmentSlotUpdate(entity.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(entity.getLocation()));

final List<Player> viewers = PacketManager.getViewers(entity.getLocation());
EXECUTOR.execute(() -> NMSHandlers.getHandler().equipmentSlotUpdate(entity.getEntityId(), equipSlot, cosmeticItem, viewers));
}

public EquipmentSlot getEquipSlot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.UUID;
import java.util.logging.Level;

import static com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin.EXECUTOR;

public class CosmeticBackpackType extends Cosmetic {

@Getter
Expand All @@ -47,42 +49,44 @@ public void update(@NotNull CosmeticUser user) {
if (entity == null) return;

Location loc = entity.getLocation().clone().add(0, 2, 0);

if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
// This needs to be moved to purely packet based, there are far to many plugin doing dumb stuff that prevents spawning armorstands ignoring our spawn reason.
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);

user.getUserBackpackManager().getEntityManager().teleport(loc);
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());

PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
PacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, 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 (Settings.isBackpackForceRidingEnabled()) PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
else PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);

if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
List<Player> owner = List.of(user.getPlayer());

ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId();
for (int i = 0; i < particleCloud.size(); i++) {
if (i == 0) {
PacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
} else {
PacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
final Location playerLoc = user.getEntity().getLocation();
EXECUTOR.execute(() -> {
user.getUserBackpackManager().getEntityManager().teleport(loc);
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());

PacketManager.sendEntitySpawnPacket(playerLoc, user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
PacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, 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 (Settings.isBackpackForceRidingEnabled()) PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
else PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);

if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
List<Player> owner = List.of(user.getPlayer());

ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId();
for (int i = 0; i < particleCloud.size(); i++) {
if (i == 0) {
PacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
} else {
PacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
}
}
PacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
if (!user.getHidden()) {
//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);
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
}
MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
}
PacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
if (!user.getHidden()) {
//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);
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
}
MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
}

user.getUserBackpackManager().showBackpack();
user.getUserBackpackManager().showBackpack();
});
}

public boolean isFirstPersonCompadible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public void start() {
MessagesUtil.sendMessage(player, "opened-wardrobe");

Runnable run = () -> {

player.teleport(viewingLocation);

// Armorstand
PacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendArmorstandMetadata(ARMORSTAND_ID, viewer);
Expand Down

0 comments on commit 40b83ba

Please sign in to comment.