mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-27 19:09:19 +00:00
1.18.2 support, balloon bug fix
This commit is contained in:
@@ -46,7 +46,7 @@ public class HMCCosmeticsAPI {
|
||||
return false;
|
||||
}
|
||||
|
||||
userManager.setItem(userOptional.get(), cosmeticItem.getArmorItem());
|
||||
userManager.setItem(userOptional.get(), cosmeticItem.getArmorItem(), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,12 @@ public class CosmeticChangeEvent extends CosmeticItemEvent {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public CosmeticChangeEvent(final boolean isAsync, final CosmeticItem cosmeticItem, final CosmeticItem removed, final BaseUser<?> user) {
|
||||
super(isAsync, cosmeticItem);
|
||||
this.removed = removed;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public BaseUser<?> getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@ public abstract class CosmeticItemEvent extends Event implements Cancellable {
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public CosmeticItemEvent(final boolean isAsync, final CosmeticItem cosmeticItem) {
|
||||
super(isAsync);
|
||||
this.cosmeticItem = cosmeticItem;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
this.setDyeColor(dyeColor, armorItem, player);
|
||||
|
||||
this.userManager.setItem(user, armorItem);
|
||||
this.userManager.setItem(user, armorItem, true);
|
||||
|
||||
this.messageHandler.sendMessage(
|
||||
player,
|
||||
@@ -186,7 +186,7 @@ public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
final Message setMessage = Messages.getSetMessage(armorItem.getType());
|
||||
final Message setOtherMessage = Messages.getSetOtherMessage(armorItem.getType());
|
||||
this.userManager.setItem(user, armorItem);
|
||||
this.userManager.setItem(user, armorItem, true);
|
||||
this.messageHandler.sendMessage(
|
||||
player,
|
||||
setMessage
|
||||
@@ -219,7 +219,7 @@ public class CosmeticsCommand extends CommandBase {
|
||||
final ArmorItem.Type type = ArmorItem.Type.valueOf(typeString.toUpperCase());
|
||||
|
||||
final Message setOtherMessage = Messages.getSetOtherMessage(type);
|
||||
this.userManager.removeItem(user, type);
|
||||
this.userManager.removeItem(user, type, true);
|
||||
this.messageHandler.sendMessage(
|
||||
sender,
|
||||
setOtherMessage,
|
||||
@@ -286,14 +286,11 @@ public class CosmeticsCommand extends CommandBase {
|
||||
wardrobe.setCurrentLocation(null);
|
||||
}
|
||||
|
||||
wardrobe.setActive(true);
|
||||
settings.playOpenSound(player);
|
||||
|
||||
final Player finalPlayer = player;
|
||||
new TaskChain(this.plugin).
|
||||
chain(() -> {
|
||||
wardrobe.spawnFakePlayer(finalPlayer);
|
||||
}, true).
|
||||
chain(() -> wardrobe.spawnFakePlayer(finalPlayer), true).
|
||||
chain(() -> {
|
||||
// this.cosmeticsMenu.openDefault(finalPlayer);
|
||||
this.messageHandler.sendMessage(
|
||||
|
||||
@@ -102,7 +102,9 @@ public class ActionSerializer implements TypeSerializer<List<CosmeticGuiAction>>
|
||||
final String openMenu = openMenuNode.getString();
|
||||
|
||||
final List<ArmorItem.Type> removeCosmeticTypes = this.loadRemoveTypes(removeItemsNode);
|
||||
final int totalRemoveCosmetics = removeCosmeticTypes.size();
|
||||
final List<String> setCosmetics = this.loadSetCosmetics(setCosmeticsNode);
|
||||
final int totalSetCosmetics = setCosmetics.size();
|
||||
|
||||
final ClickType click = Utils.stringToEnum(clickType, ClickType.class, ClickType.UNKNOWN);
|
||||
final Map<Integer, GuiItem> setItems = this.loadSetItems(setItemsNode);
|
||||
@@ -127,13 +129,19 @@ public class ActionSerializer implements TypeSerializer<List<CosmeticGuiAction>>
|
||||
if (optionalUser.isEmpty()) return;
|
||||
final User user = optionalUser.get();
|
||||
final CosmeticManager cosmeticManager = plugin.getCosmeticManager();
|
||||
int index = 0;
|
||||
for (final String id : setCosmetics) {
|
||||
index++;
|
||||
final boolean sendPacket = index == totalSetCosmetics ;
|
||||
final ArmorItem armorItem = cosmeticManager.getArmorItem(id);
|
||||
if (armorItem == null) continue;
|
||||
userManager.setItem(user, armorItem);
|
||||
userManager.setItem(user, armorItem, sendPacket);
|
||||
}
|
||||
index = 0;
|
||||
for (final ArmorItem.Type type : removeCosmeticTypes) {
|
||||
userManager.removeItem(user, type);
|
||||
index++;
|
||||
final boolean sendPacket = index == totalSetCosmetics ;
|
||||
userManager.removeItem(user, type, sendPacket);
|
||||
}
|
||||
final CosmeticGui gui = user.getOpenGui();
|
||||
if (gui != null) {
|
||||
|
||||
@@ -12,8 +12,6 @@ import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@@ -100,7 +98,8 @@ public class CosmeticGui {
|
||||
setUser,
|
||||
armorItem,
|
||||
Messages.getRemovedMessage(type),
|
||||
Messages.getSetMessage(type)
|
||||
Messages.getSetMessage(type),
|
||||
true
|
||||
);
|
||||
|
||||
if (!setTo.isEmpty()) {
|
||||
|
||||
@@ -133,11 +133,13 @@ public class DyeSelectorGui extends CosmeticGui {
|
||||
armorItem.setDye(colorItem.getColor().asRGB());
|
||||
|
||||
if (user.isWardrobeActive()) {
|
||||
this.plugin.getUserManager().setItem(user.getWardrobe(), armorItem);
|
||||
this.plugin.getUserManager().setItem(user.getWardrobe(), armorItem, true);
|
||||
} else {
|
||||
this.plugin.getUserManager().setItem(user, armorItem);
|
||||
this.plugin.getUserManager().setItem(user, armorItem, true);
|
||||
}
|
||||
if (colorItem.getAction() != null) {
|
||||
colorItem.getAction().execute(event);
|
||||
}
|
||||
colorItem.getAction().execute(event);
|
||||
this.updateSelected(user, player);
|
||||
});
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class MEGEntity implements BaseEntity<MEGEntity> {
|
||||
this.uuid = uuid;
|
||||
this.entityId = entityId;
|
||||
this.entityType = entityType;
|
||||
this.alive = true;
|
||||
this.alive = false;
|
||||
}
|
||||
|
||||
public void update(final BalloonEntity entity) {
|
||||
|
||||
@@ -3,13 +3,14 @@ package io.github.fisher2911.hmccosmetics.listener;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class RespawnListener implements Listener {
|
||||
|
||||
private final HMCCosmetics plugin;
|
||||
@@ -28,7 +29,6 @@ public class RespawnListener implements Listener {
|
||||
optionalUser.ifPresent(user -> {
|
||||
user.despawnAttached();
|
||||
this.userManager.updateCosmetics(user);
|
||||
this.userManager.setItem(user, user.getPlayerArmor().getHat());
|
||||
});
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
||||
import com.github.retrooper.packetevents.protocol.player.Equipment;
|
||||
import com.github.retrooper.packetevents.protocol.player.EquipmentSlot;
|
||||
import com.github.retrooper.packetevents.protocol.player.GameMode;
|
||||
import com.github.retrooper.packetevents.protocol.player.TextureProperty;
|
||||
import com.github.retrooper.packetevents.protocol.player.UserProfile;
|
||||
import com.github.retrooper.packetevents.util.Vector3d;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerAttachEntity;
|
||||
@@ -212,9 +214,6 @@ public class PacketManager {
|
||||
final int entityId,
|
||||
final Player... sendTo
|
||||
) {
|
||||
for (final Equipment equipment : equipmentList) {
|
||||
final ItemStack itemStack = SpigotDataHelper.toBukkitItemStack(equipment.getItem());
|
||||
}
|
||||
for (final Player p : sendTo) {
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacketSilentlyAsync(p, new WrapperPlayServerEntityEquipment(
|
||||
entityId,
|
||||
@@ -369,30 +368,33 @@ public class PacketManager {
|
||||
}
|
||||
|
||||
public static void sendFakePlayerInfoPacket(
|
||||
final Player player,
|
||||
final Player skinnedPlayer,
|
||||
final UUID uuid,
|
||||
final Collection<? extends Player> sendTo
|
||||
) {
|
||||
sendFakePlayerInfoPacket(player, uuid, sendTo.toArray(new Player[0]));
|
||||
sendFakePlayerInfoPacket(skinnedPlayer, uuid, sendTo.toArray(new Player[0]));
|
||||
}
|
||||
|
||||
public static void sendFakePlayerInfoPacket(
|
||||
final Player player,
|
||||
final Player skinnedPlayer,
|
||||
final UUID uuid,
|
||||
final Player... sendTo
|
||||
) {
|
||||
final List<TextureProperty> textures = PacketEvents.getAPI().getPlayerManager().getUser(skinnedPlayer).getProfile().getTextureProperties();
|
||||
final WrapperPlayServerPlayerInfo.PlayerData data = new WrapperPlayServerPlayerInfo.PlayerData(
|
||||
Component.text(""),
|
||||
new UserProfile(
|
||||
uuid,
|
||||
"",
|
||||
textures
|
||||
),
|
||||
GameMode.CREATIVE,
|
||||
0
|
||||
);
|
||||
for (final Player p : sendTo) {
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacketSilentlyAsync(p, new WrapperPlayServerPlayerInfo(
|
||||
WrapperPlayServerPlayerInfo.Action.ADD_PLAYER,
|
||||
new WrapperPlayServerPlayerInfo.PlayerData(
|
||||
Component.empty(),
|
||||
new UserProfile(
|
||||
uuid,
|
||||
player.getDisplayName()
|
||||
),
|
||||
com.github.retrooper.packetevents.protocol.player.GameMode.SURVIVAL,
|
||||
0
|
||||
)
|
||||
data
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -413,7 +415,7 @@ public class PacketManager {
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacketSilentlyAsync(p, new WrapperPlayServerEntityMetadata(
|
||||
playerId,
|
||||
List.of(
|
||||
new EntityData(17, EntityDataTypes.BYTE, mask),
|
||||
new EntityData(17, EntityDataTypes.BYTE, mask),
|
||||
new EntityData(15, EntityDataTypes.BYTE, (byte) 0x10)
|
||||
)
|
||||
));
|
||||
|
||||
@@ -18,16 +18,6 @@ public class TaskManager {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
// this.timer = Bukkit.getScheduler().runTaskTimerAsynchronously(
|
||||
// this.plugin,
|
||||
// () -> tasks.removeIf(task -> {
|
||||
// task.run();
|
||||
// Bukkit.broadcastMessage("Task Size: " + this.tasks.size());
|
||||
// return task.isComplete();
|
||||
// }),
|
||||
// 1,
|
||||
// 1
|
||||
// );
|
||||
this.timer = Bukkit.getScheduler().runTaskTimerAsynchronously(
|
||||
this.plugin,
|
||||
() -> {
|
||||
|
||||
@@ -34,6 +34,8 @@ public abstract class BaseUser<T> {
|
||||
protected final EntityIds entityIds;
|
||||
protected final BalloonEntity balloon;
|
||||
protected final PlayerArmor playerArmor;
|
||||
// for setting multiple items
|
||||
protected boolean armorUpdated;
|
||||
|
||||
protected ArmorItem lastSetItem = ArmorItem.empty(ArmorItem.Type.HAT);
|
||||
|
||||
@@ -103,8 +105,8 @@ public abstract class BaseUser<T> {
|
||||
public void despawnBalloon() {
|
||||
final HookManager hookManager = HookManager.getInstance();
|
||||
if (!hookManager.isEnabled(ModelEngineHook.class)) return;
|
||||
this.balloon.remove();
|
||||
PacketManager.sendEntityDestroyPacket(this.getBalloonId(), Bukkit.getOnlinePlayers());
|
||||
this.balloon.remove();
|
||||
this.viewingBalloon.clear();
|
||||
this.balloon.setAlive(false);
|
||||
}
|
||||
@@ -128,6 +130,10 @@ public abstract class BaseUser<T> {
|
||||
final String id = balloonItem.getModelId();
|
||||
final HookManager hookManager = HookManager.getInstance();
|
||||
if (id.isBlank() || !hookManager.isEnabled(ModelEngineHook.class)) return;
|
||||
if (this.balloon.isAlive()) {
|
||||
this.updateBalloon(other, actual, settings);
|
||||
return;
|
||||
}
|
||||
this.balloon.setAlive(true);
|
||||
if (!this.viewingBalloon.contains(other.getUniqueId())) {
|
||||
this.viewingBalloon.add(other.getUniqueId());
|
||||
@@ -135,18 +141,25 @@ public abstract class BaseUser<T> {
|
||||
this.balloon.spawnModel(id);
|
||||
this.balloon.addPlayerToModel(other, id);
|
||||
}
|
||||
this.updateBalloon(other, location, settings);
|
||||
final int balloonId = this.getBalloonId();
|
||||
PacketManager.sendEntitySpawnPacket(actual, balloonId, EntityTypes.PUFFERFISH, other);
|
||||
PacketManager.sendInvisibilityPacket(balloonId, other);
|
||||
PacketManager.sendLeashPacket(balloonId, this.getEntityId(), other);
|
||||
this.updateBalloon(other, location, settings);
|
||||
}
|
||||
|
||||
protected void updateBalloon(final Player other, final Location location, final CosmeticSettings settings) {
|
||||
final HookManager hookManager = HookManager.getInstance();
|
||||
if (!hookManager.isEnabled(ModelEngineHook.class)) return;
|
||||
final BalloonItem balloonItem = (BalloonItem) this.playerArmor.getItem(ArmorItem.Type.BALLOON);
|
||||
if (balloonItem.isEmpty()) return;
|
||||
if (!this.viewingBalloon.contains(other.getUniqueId())) {
|
||||
this.spawnBalloon(other, location, settings);
|
||||
if (!this.balloon.isAlive()) {
|
||||
this.spawnBalloon(other, location, settings);
|
||||
return;
|
||||
}
|
||||
this.viewingBalloon.add(other.getUniqueId());
|
||||
this.balloon.addPlayerToModel(other, balloonItem.getModelId());
|
||||
return;
|
||||
}
|
||||
final Location actual = location.clone().add(settings.getBalloonOffset());
|
||||
@@ -162,8 +175,8 @@ public abstract class BaseUser<T> {
|
||||
}
|
||||
|
||||
private void spawnArmorStand(final Player other, final Location location) {
|
||||
// todo
|
||||
PacketManager.sendEntitySpawnPacket(location, this.getArmorStandId(), EntityTypes.ARMOR_STAND, other);
|
||||
PacketManager.sendArmorStandMetaContainer(this.getArmorStandId(), other);
|
||||
}
|
||||
|
||||
public void updateOutsideCosmetics(final Settings settings) {
|
||||
@@ -174,6 +187,36 @@ public abstract class BaseUser<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBackpack(final Player other, final Settings settings) {
|
||||
final Location location = this.getLocation();
|
||||
if (location == null) return;
|
||||
final List<com.github.retrooper.packetevents.protocol.player.Equipment> equipment = new ArrayList<>();
|
||||
final boolean hidden = !this.shouldShow(other);
|
||||
final int lookDownPitch = settings.getCosmeticSettings().getLookDownPitch();
|
||||
final boolean isLookingDown =
|
||||
this.id.equals(other.getUniqueId()) && lookDownPitch
|
||||
!= -1 &&
|
||||
this.isFacingDown(location, lookDownPitch);
|
||||
if (hidden || isLookingDown) {
|
||||
equipment.add(new com.github.retrooper.packetevents.protocol.player.Equipment(
|
||||
EquipmentSlot.HELMET,
|
||||
new com.github.retrooper.packetevents.protocol.item.ItemStack.Builder().
|
||||
type(ItemTypes.AIR).
|
||||
build()
|
||||
));
|
||||
} else {
|
||||
final com.github.retrooper.packetevents.protocol.item.ItemStack itemStack =
|
||||
SpigotDataHelper.fromBukkitItemStack(this.playerArmor.getBackpack().getItemStack(ArmorItem.Status.APPLIED));
|
||||
equipment.add(new com.github.retrooper.packetevents.protocol.player.Equipment(
|
||||
EquipmentSlot.HELMET,
|
||||
itemStack
|
||||
));
|
||||
}
|
||||
|
||||
final int armorStandId = this.getArmorStandId();
|
||||
PacketManager.sendEquipmentPacket(equipment, armorStandId, other);
|
||||
}
|
||||
|
||||
public void updateOutsideCosmetics(final Player other, final Location location, final Settings settings) {
|
||||
final boolean inViewDistance = settings.getCosmeticSettings().isInViewDistance(location, other.getLocation());
|
||||
final boolean shouldShow = shouldShow(other);
|
||||
@@ -228,11 +271,9 @@ public abstract class BaseUser<T> {
|
||||
}
|
||||
|
||||
final int armorStandId = this.getArmorStandId();
|
||||
PacketManager.sendEquipmentPacket(equipment, armorStandId, other);
|
||||
PacketManager.sendRotationPacket(armorStandId, location, false, other);
|
||||
PacketManager.sendLookPacket(armorStandId, location, other);
|
||||
PacketManager.sendRidingPacket(this.getEntityId(), armorStandId, other);
|
||||
PacketManager.sendArmorStandMetaContainer(armorStandId, other);
|
||||
|
||||
if (hidden) return;
|
||||
this.updateBalloon(other, location, settings.getCosmeticSettings());
|
||||
@@ -271,4 +312,11 @@ public abstract class BaseUser<T> {
|
||||
|
||||
public abstract boolean isWardrobeActive();
|
||||
|
||||
public boolean isArmorUpdated() {
|
||||
return armorUpdated;
|
||||
}
|
||||
|
||||
public void setArmorUpdated(boolean armorUpdated) {
|
||||
this.armorUpdated = armorUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,44 +118,9 @@ public class UserManager {
|
||||
user,
|
||||
this.getItemList(user, user.getEquipment(), Collections.emptySet())
|
||||
);
|
||||
// for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
// this.updateCosmetics(user, player);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
// public void updateCosmetics(final BaseUser<?> user, final Player other) {
|
||||
// final Equipment equipment = user.getEquipment();
|
||||
// for (final ArmorItem.Type type : ArmorItem.Type.values()) {
|
||||
// if (type.getSlot() == null) continue;
|
||||
// this.sendUpdatePacket(
|
||||
// user,
|
||||
// other,
|
||||
// equipment,
|
||||
// type
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// private void sendUpdatePacket(
|
||||
// final BaseUser<?> user,
|
||||
// final Player other,
|
||||
// final Equipment equipment,
|
||||
// final ArmorItem.Type type) {
|
||||
// final PlayerArmor playerArmor = user.getPlayerArmor();
|
||||
// final EquipmentSlot slot = type.getSlot();
|
||||
// final ItemStack itemStack = this.getCosmeticItem(playerArmor.getItem(type), equipment.getItem(type.getSlot()), ArmorItem.Status.APPLIED, slot);
|
||||
// if (itemStack != null && itemStack.equals(equipment.getItem(slot))) return;
|
||||
// final List<com.github.retrooper.packetevents.protocol.player.Equipment> itemList = new ArrayList<>();
|
||||
// itemList.add(new com.github.retrooper.packetevents.protocol.player.Equipment(
|
||||
// PacketManager.fromBukkitSlot(slot), SpigotDataHelper.fromBukkitItemStack(itemStack)
|
||||
// ));
|
||||
// PacketManager.sendEquipmentPacket(
|
||||
// itemList,
|
||||
// user.getEntityId(),
|
||||
// other
|
||||
// );
|
||||
// }
|
||||
|
||||
public ItemStack getCosmeticItem(
|
||||
final ArmorItem armorItem,
|
||||
final ItemStack wearing,
|
||||
@@ -205,35 +170,40 @@ public class UserManager {
|
||||
ArmorItem.Status.APPLIED,
|
||||
slot
|
||||
);
|
||||
if (itemStack.getType() != Material.AIR) items.add(PacketManager.getEquipment(itemStack, slot));
|
||||
items.add(PacketManager.getEquipment(itemStack, slot));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItem(final BaseUser<?> user, final ArmorItem armorItem) {
|
||||
public void setItem(final BaseUser<?> user, final ArmorItem armorItem, final boolean sendPacket) {
|
||||
ArmorItem previous = user.getPlayerArmor().getItem(armorItem.getType());
|
||||
|
||||
final CosmeticChangeEvent event =
|
||||
new CosmeticChangeEvent(new CosmeticItem(armorItem.copy()), new CosmeticItem(previous.copy()), user);
|
||||
new CosmeticChangeEvent(
|
||||
!Bukkit.isPrimaryThread(),
|
||||
new CosmeticItem(armorItem.copy()),
|
||||
new CosmeticItem(previous.copy()),
|
||||
user
|
||||
);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
final ArmorItem.Type type = armorItem.getType();
|
||||
if (type == ArmorItem.Type.BALLOON) user.despawnBalloon();
|
||||
user.setItem(event.getCosmeticItem().getArmorItem());
|
||||
if (!sendPacket) {
|
||||
user.setArmorUpdated(false);
|
||||
return;
|
||||
}
|
||||
user.setArmorUpdated(true);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
switch (type) {
|
||||
case HAT, OFF_HAND, CHEST_PLATE, PANTS, BOOTS -> this.updateCosmetics(user);
|
||||
case BACKPACK -> {
|
||||
user.despawnAttached();
|
||||
if (user instanceof Wardrobe) user.updateOutsideCosmetics(settings);
|
||||
}
|
||||
}
|
||||
this.updateCosmetics(user);
|
||||
if (user instanceof Wardrobe) user.updateOutsideCosmetics(settings);
|
||||
});
|
||||
}
|
||||
|
||||
public void removeItem(final User user, final ArmorItem.Type type) {
|
||||
this.setItem(user, ArmorItem.empty(type));
|
||||
public void removeItem(final User user, final ArmorItem.Type type, final boolean sendPacket) {
|
||||
this.setItem(user, ArmorItem.empty(type), sendPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,7 +217,8 @@ public class UserManager {
|
||||
final User user,
|
||||
final ArmorItem armorItem,
|
||||
final Message removeMessage,
|
||||
final Message setMessage) {
|
||||
final Message setMessage,
|
||||
final boolean sendPacket) {
|
||||
final Player player = user.getPlayer();
|
||||
|
||||
final ArmorItem.Type type = armorItem.getType();
|
||||
@@ -261,7 +232,7 @@ public class UserManager {
|
||||
final ArmorItem check = user.getPlayerArmor().getItem(type);
|
||||
|
||||
if (armorItem.getId().equals(check.getId())) {
|
||||
this.setItem(user, ArmorItem.empty(type));
|
||||
this.setItem(user, ArmorItem.empty(type), sendPacket);
|
||||
|
||||
messageHandler.sendMessage(
|
||||
player,
|
||||
@@ -271,7 +242,7 @@ public class UserManager {
|
||||
return empty;
|
||||
}
|
||||
|
||||
this.setItem(user, armorItem);
|
||||
this.setItem(user, armorItem, sendPacket);
|
||||
messageHandler.sendMessage(
|
||||
player,
|
||||
setMessage
|
||||
@@ -324,6 +295,7 @@ public class UserManager {
|
||||
if (other == null) continue;
|
||||
if (!user.shouldShow(other)) continue;
|
||||
if (!this.settings.getCosmeticSettings().isInViewDistance(location, other.getLocation())) continue;
|
||||
user.updateBackpack(other, this.settings);
|
||||
PacketManager.sendEquipmentPacket(
|
||||
items,
|
||||
entityId,
|
||||
|
||||
@@ -56,29 +56,6 @@ public class Wardrobe extends User {
|
||||
this.hidePlayer();
|
||||
}
|
||||
).execute();
|
||||
// for if we ever switch to packets
|
||||
// final Location viewerLocation = settings.getViewerLocation();
|
||||
// final UUID viewerUUID = UUID.randomUUID();
|
||||
// new TaskChain(this.plugin).chain(() -> {
|
||||
// viewer.setGameMode(GameMode.SPECTATOR);
|
||||
// }).chain(
|
||||
// () -> {
|
||||
// PacketManager.sendPacket(
|
||||
// viewer,
|
||||
// PacketManager.getEntitySpawnPacket(
|
||||
// viewerLocation,
|
||||
// this.viewerId,
|
||||
// EntityType.ZOMBIE,
|
||||
// viewerUUID
|
||||
// ),
|
||||
// PacketManager.getLookPacket(this.viewerId, viewerLocation),
|
||||
// PacketManager.getRotationPacket(this.viewerId, viewerLocation),
|
||||
// PacketManager.getSpectatePacket(this.viewerId)
|
||||
// );
|
||||
// },
|
||||
// true
|
||||
// ).execute();
|
||||
|
||||
|
||||
} else if (this.currentLocation == null) {
|
||||
this.currentLocation = viewer.getLocation().clone();
|
||||
@@ -88,24 +65,39 @@ public class Wardrobe extends User {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.setActive(true);
|
||||
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(
|
||||
this.plugin,
|
||||
() -> {
|
||||
final int entityId = this.getEntityId();
|
||||
PacketManager.sendFakePlayerSpawnPacket(this.currentLocation, this.getId(), entityId, viewer);
|
||||
PacketManager.sendFakePlayerInfoPacket(viewer, this.getId(), viewer);
|
||||
this.updateOutsideCosmetics(viewer, this.currentLocation, plugin.getSettings());
|
||||
PacketManager.sendFakePlayerSpawnPacket(this.currentLocation, this.getId(), entityId, viewer);
|
||||
// this.updateOutsideCosmetics(viewer, this.currentLocation, plugin.getSettings());
|
||||
PacketManager.sendLookPacket(entityId, this.currentLocation, viewer);
|
||||
PacketManager.sendRotationPacket(entityId, this.currentLocation, true, viewer);
|
||||
PacketManager.sendPlayerOverlayPacket(entityId, viewer);
|
||||
final UserManager userManager = this.plugin.getUserManager();
|
||||
userManager.get(viewer.getUniqueId()).
|
||||
ifPresent(user -> {
|
||||
int index = 0;
|
||||
final Collection<ArmorItem> armorItems = user.getPlayerArmor().getArmorItems();
|
||||
for (final ArmorItem armorItem : armorItems) {
|
||||
index++;
|
||||
final boolean sendPacket = armorItems.size() == index;
|
||||
userManager.setItem(
|
||||
this,
|
||||
armorItem,
|
||||
sendPacket
|
||||
);
|
||||
}
|
||||
});
|
||||
// PacketManager.sendEntitySpawnPacket(this.currentLocation, this.getEntityId(), EntityTypes.ZOMBIE, viewer);
|
||||
this.spawned = true;
|
||||
this.startSpinTask(viewer);
|
||||
},
|
||||
settings.getSpawnDelay()
|
||||
);
|
||||
|
||||
this.spawned = true;
|
||||
this.startSpinTask(viewer);
|
||||
}
|
||||
|
||||
public void despawnFakePlayer(final Player viewer, final UserManager userManager) {
|
||||
@@ -114,13 +106,13 @@ public class Wardrobe extends User {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(
|
||||
this.plugin,
|
||||
() -> {
|
||||
this.spawned = false;
|
||||
final int entityId = this.getEntityId();
|
||||
PacketManager.sendEntityDestroyPacket(entityId, viewer);
|
||||
PacketManager.sendRemovePlayerPacket(viewer, this.id, viewer);
|
||||
this.despawnAttached();
|
||||
this.despawnBalloon();
|
||||
PacketManager.sendEntityDestroyPacket(entityId, viewer);
|
||||
PacketManager.sendRemovePlayerPacket(viewer, this.id, viewer);
|
||||
this.showPlayer(this.plugin.getUserManager());
|
||||
this.spawned = false;
|
||||
this.cameraLocked = false;
|
||||
this.currentLocation = null;
|
||||
final Collection<ArmorItem> armorItems = new ArrayList<>(this.getPlayerArmor().getArmorItems());
|
||||
@@ -129,9 +121,12 @@ public class Wardrobe extends User {
|
||||
optionalUser.ifPresent(user -> Bukkit.getScheduler().runTask(
|
||||
plugin,
|
||||
() -> {
|
||||
int index = 0;
|
||||
for (final ArmorItem armorItem : armorItems) {
|
||||
index++;
|
||||
final boolean sendPacket = armorItems.size() == index;
|
||||
if (!user.hasPermissionToUse(armorItem)) continue;
|
||||
userManager.setItem(user, armorItem);
|
||||
userManager.setItem(user, armorItem, sendPacket);
|
||||
}
|
||||
}
|
||||
));
|
||||
@@ -243,8 +238,8 @@ public class Wardrobe extends User {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(
|
||||
this.plugin,
|
||||
() -> {
|
||||
optional.ifPresent(user -> userManager.updateCosmetics(user, player));
|
||||
optionalUser.ifPresent(userManager::updateCosmetics);
|
||||
// optional.ifPresent(user -> userManager.updateCosmetics(user, player));
|
||||
// optionalUser.ifPresent(userManager::updateCosmetics);
|
||||
},
|
||||
1
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user