From 603277d1ce197fd307f1cb4f0c83931f321aa502 Mon Sep 17 00:00:00 2001 From: MATRIX-feather Date: Sat, 16 Dec 2023 16:37:41 +0800 Subject: [PATCH] =?UTF-8?q?rm:=20=E7=A7=BB=E9=99=A4LibsDisguises=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=20rm:=20=E7=A7=BB=E9=99=A4GSit=E9=9B=86=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 12 +- gradle.properties | 3 +- src/main/java/xiamomc/morph/MorphManager.java | 24 +- src/main/java/xiamomc/morph/MorphPlugin.java | 9 - .../morph/backends/libsdisg/LibsBackend.java | 220 -------- .../libsdisg/LibsDisguiseWrapper.java | 511 ------------------ .../morph/events/CommonEventProcessor.java | 15 - .../gsit/GSitCompactProcessor.java | 107 ---- .../morph/providers/ItemDisplayProvider.java | 161 ------ .../providers/LocalDisguiseProvider.java | 132 ----- .../morph/utilities/DisguiseUtils.java | 15 - 11 files changed, 10 insertions(+), 1199 deletions(-) delete mode 100644 src/main/java/xiamomc/morph/backends/libsdisg/LibsBackend.java delete mode 100644 src/main/java/xiamomc/morph/backends/libsdisg/LibsDisguiseWrapper.java delete mode 100644 src/main/java/xiamomc/morph/misc/integrations/gsit/GSitCompactProcessor.java delete mode 100644 src/main/java/xiamomc/morph/providers/ItemDisplayProvider.java delete mode 100644 src/main/java/xiamomc/morph/providers/LocalDisguiseProvider.java diff --git a/build.gradle.kts b/build.gradle.kts index 642d4900..bffed0f3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -36,6 +36,10 @@ repositories { url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/") } + maven { + url = uri("https://repo.dmulloy2.net/repository/public/") + } + maven { url = uri("https://repo.maven.apache.org/maven2/") } @@ -44,11 +48,7 @@ repositories { dependencies { paperweight.paperDevBundle("${project.property("minecraft_version")}") - compileOnly("LibsDisguises:LibsDisguises:${project.property("ld_version")}") - { - exclude("org.spigotmc", "spigot-api") - exclude("org.spigotmc", "spigot") - } + compileOnly("com.comphenix.protocol:ProtocolLib:${project.property("protocollib_version")}") compileOnly(files("libs/CMILib1.4.3.5.jar")) compileOnly(files("libs/Residence5.1.4.0.jar")) @@ -70,7 +70,7 @@ dependencies { exclude("com.google.code.gson", "gson") } - compileOnly("com.github.Gecolay:GSit:${project.property("gsit_version")}") + //compileOnly("com.github.Gecolay:GSit:${project.property("gsit_version")}") compileOnly("me.clip:placeholderapi:${project.property("papi_version")}") } diff --git a/gradle.properties b/gradle.properties index 855d664c..5e3d755d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,8 @@ protocols_local_version=0.13.2 minecraft_version=1.20.4-R0.1-SNAPSHOT # Dependencies -ld_version=10.0.33 +protocollib_version=5.1.0 +#ld_version=10.0.33 pluginbase_version=306d580 gsit_version=1.6.0 papi_version=2.11.5 diff --git a/src/main/java/xiamomc/morph/MorphManager.java b/src/main/java/xiamomc/morph/MorphManager.java index 959ef6f0..a3cb2479 100644 --- a/src/main/java/xiamomc/morph/MorphManager.java +++ b/src/main/java/xiamomc/morph/MorphManager.java @@ -19,7 +19,6 @@ import xiamomc.morph.backends.DisguiseBackend; import xiamomc.morph.backends.DisguiseWrapper; import xiamomc.morph.backends.fallback.NilBackend; -import xiamomc.morph.backends.libsdisg.LibsBackend; import xiamomc.morph.backends.server.ServerBackend; import xiamomc.morph.config.ConfigOption; import xiamomc.morph.config.MorphConfigManager; @@ -120,31 +119,12 @@ private void tryBackends() } catch (NoClassDefFoundError e) { - logger.error("Unable to initialize renderer as our disguise backend, maybe ProtocolLib it's not installed on the server."); - logger.error("Trying LibsBackend..."); - } - catch (Throwable t) - { - logger.error("Unable to initialize renderer as our disguise backend: " + t.getMessage()); - logger.error("Please consider reporting this issue to our GitHub: https://github.com/XiaMoZhiShi/MorphPlugin/issues"); - logger.error("Trying LibsBackend..."); - - t.printStackTrace(); - } - - try - { - this.currentBackend = new LibsBackend(); - return; - } - catch (NoClassDefFoundError e) - { - logger.error("Unable to initialize LibsDisguises as our disguise backend, maybe it's not installed on the server."); + logger.error("Unable to initialize ServerBackend as our disguise backend, maybe ProtocolLib is not installed on the server."); logger.error("Using NilBackend, displaying disguises at the server side will not be supported this run."); } catch (Throwable t) { - logger.error("Unable to initialize LibsDisguises as our disguise backend: " + t.getMessage()); + logger.error("Unable to initialize ServerBackend as our disguise backend: " + t.getMessage()); logger.error("Using NilBackend, displaying disguises at the server side will not be supported this run."); logger.error("Please consider reporting this issue to our GitHub: https://github.com/XiaMoZhiShi/MorphPlugin/issues"); diff --git a/src/main/java/xiamomc/morph/MorphPlugin.java b/src/main/java/xiamomc/morph/MorphPlugin.java index 2678da12..182323b7 100644 --- a/src/main/java/xiamomc/morph/MorphPlugin.java +++ b/src/main/java/xiamomc/morph/MorphPlugin.java @@ -20,7 +20,6 @@ import xiamomc.morph.misc.PlayerOperationSimulator; import xiamomc.morph.misc.integrations.residence.ResidenceEventProcessor; import xiamomc.morph.updates.UpdateHandler; -import xiamomc.morph.misc.integrations.gsit.GSitCompactProcessor; import xiamomc.morph.misc.integrations.placeholderapi.PlaceholderIntegration; import xiamomc.morph.network.server.MorphClientHandler; import xiamomc.morph.skills.MorphSkillHandler; @@ -30,8 +29,6 @@ import xiamomc.pluginbase.Messages.MessageStore; import xiamomc.pluginbase.XiaMoJavaPlugin; -import java.util.Arrays; - public final class MorphPlugin extends XiaMoJavaPlugin { private static MorphPlugin instance; @@ -96,12 +93,6 @@ public void onEnable() var playerTracker = new PlayerTracker(); - softDeps.setHandle("GSit", s -> - { - logger.info("GSit detected, applying integrations..."); - this.registerListener(new GSitCompactProcessor()); - }, true); - softDeps.setHandle("PlaceholderAPI", p -> { logger.info("Registering Placeholders..."); diff --git a/src/main/java/xiamomc/morph/backends/libsdisg/LibsBackend.java b/src/main/java/xiamomc/morph/backends/libsdisg/LibsBackend.java deleted file mode 100644 index 1b759f91..00000000 --- a/src/main/java/xiamomc/morph/backends/libsdisg/LibsBackend.java +++ /dev/null @@ -1,220 +0,0 @@ -package xiamomc.morph.backends.libsdisg; - -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.disguisetypes.*; -import me.libraryaddict.disguise.disguisetypes.watchers.ItemDisplayWatcher; -import me.libraryaddict.disguise.utilities.parser.DisguiseParser; -import org.bukkit.Material; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.ItemDisplay; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.joml.Vector3f; -import xiamomc.morph.backends.DisguiseBackend; -import xiamomc.morph.backends.DisguiseWrapper; - -import java.util.Map; - -public class LibsBackend extends DisguiseBackend -{ - public LibsBackend() throws NoClassDefFoundError - { - } - - - /** - * Gets the identifier of this backend. - * - * @return An identifier of this backend. - */ - @Override - public String getIdentifier() - { - return "ld"; - } - - /** - * 实验中 - */ - @ApiStatus.Experimental - @ApiStatus.Internal - public DisguiseWrapper createItemDisplay(Material defaultMaterial, int scale) - { - Disguise instance = new MiscDisguise(DisguiseType.ITEM_DISPLAY); - - if (defaultMaterial.isAir()) defaultMaterial = Material.STONE; - - var watcher = ((ItemDisplayWatcher) instance.getWatcher()); - var defaultStack = new ItemStack(defaultMaterial); - - watcher.setItemStack(defaultStack); - watcher.setItemDisplayTransform(ItemDisplay.ItemDisplayTransform.NONE); - watcher.setYModifier(scale / 2f); - watcher.setScale(new Vector3f(scale, scale, scale)); - - var wrapper = new LibsDisguiseWrapper(instance, this); - wrapper.preUpdate = (w, player) -> - { - var item = watcher.getItemStack(); - var newStack = player.getEquipment().getItemInMainHand(); - - if (newStack.getType().isAir()) newStack = defaultStack; - - if (!item.isSimilar(newStack)) - watcher.setItemStack(newStack); - - watcher.setPitchLock(-player.getPitch()); - watcher.setYawLock(180 + player.getYaw()); - }; - - return wrapper; - } - - @Override - public DisguiseWrapper createInstance(@NotNull Entity targetEntity) - { - var instance = DisguiseAPI.constructDisguise(targetEntity); - - return new LibsDisguiseWrapper(instance, this); - } - - @Override - public DisguiseWrapper createInstance(EntityType entityType) - { - var instance = new MobDisguise(DisguiseType.getType(entityType)); - - return new LibsDisguiseWrapper(instance, this); - } - - @Override - public DisguiseWrapper createPlayerInstance(String playerName) - { - var instance = new PlayerDisguise(playerName); - - return new LibsDisguiseWrapper(instance, this); - } - - public DisguiseWrapper createInstanceDirect(Disguise disguise) - { - return new LibsDisguiseWrapper(disguise, this); - } - - @Override - public Disguise createRawInstance(Entity entity) - { - return DisguiseAPI.constructDisguise(entity); - } - - @Override - public boolean isDisguised(@Nullable Entity target) - { - return playerLibsDisguiseWrapperMap.containsKey(target); - } - - private final Map playerLibsDisguiseWrapperMap = new Object2ObjectOpenHashMap<>(); - - @Override - public LibsDisguiseWrapper getWrapper(Entity target) - { - if (!(target instanceof Player player)) return null; - - return playerLibsDisguiseWrapperMap.getOrDefault(player, null); - } - - @Override - public boolean disguise(Player player, DisguiseWrapper rawWrapper) - { - if (!(rawWrapper instanceof LibsDisguiseWrapper wrapper)) - return false; - - try - { - playerLibsDisguiseWrapperMap.put(player, wrapper); - DisguiseAPI.disguiseEntity(player, wrapper.getInstance()); - - if (wrapper.getEntityType().equals(EntityType.BAT)) - wrapper.getInstance().getWatcher().setYModifier(-0.8f); - - return true; - } - catch (Throwable t) - { - logger.warn("Unable to disguise player: %s".formatted(t.getMessage())); - t.printStackTrace(); - - return false; - } - } - - @Override - public boolean unDisguise(Player player) - { - var wrapper = playerLibsDisguiseWrapperMap.getOrDefault(player, null); - - if (wrapper != null) - { - playerLibsDisguiseWrapperMap.remove(player); - wrapper.dispose(); - - return wrapper.getInstance().removeDisguise(); - } - - return false; - } - - /** - * Deserialize a wrapper instance from the giving parameter - * - * @param offlineParameter The parameter to deserialize - * @return A wrapper that presents the giving parameter. - * null if invalid or illegal - */ - @Override - public @Nullable LibsDisguiseWrapper fromOfflineSave(String offlineParameter) - { - var strSpilt = offlineParameter.split("\\|", 2); - - if (strSpilt.length < 2) return null; - - if (!strSpilt[0].equals(getIdentifier())) - { - logger.info("Trying to deserialize a empty save: '%s'".formatted(offlineParameter)); - return null; - } - - try - { - var disg = DisguiseParser.parseDisguise(strSpilt[1]); - return new LibsDisguiseWrapper(disg, this); - } - catch (Throwable t) - { - logger.error("Unable to parse from offline string: %s".formatted(t.getMessage())); - t.printStackTrace(); - - return null; - } - } - - /** - * Serialize a wrapper instance to a string that can be saved in the Offline Storage - * - * @param wrapper The target wrapper to save - * @return A serialized string that can be deserialized to a wrapper in the future. - * Null if the giving wrapper is not supported by this backend. - */ - @Override - public @Nullable String toOfflineSave(DisguiseWrapper wrapper) - { - if (!(wrapper instanceof LibsDisguiseWrapper libsDisguiseWrapper)) return null; - - var disguise = libsDisguiseWrapper.getInstance(); - - return DisguiseParser.parseToString(disguise); - } -} diff --git a/src/main/java/xiamomc/morph/backends/libsdisg/LibsDisguiseWrapper.java b/src/main/java/xiamomc/morph/backends/libsdisg/LibsDisguiseWrapper.java deleted file mode 100644 index 4a2956f6..00000000 --- a/src/main/java/xiamomc/morph/backends/libsdisg/LibsDisguiseWrapper.java +++ /dev/null @@ -1,511 +0,0 @@ -package xiamomc.morph.backends.libsdisg; - -import com.comphenix.protocol.wrappers.WrappedGameProfile; -import com.mojang.authlib.GameProfile; -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.disguisetypes.*; -import me.libraryaddict.disguise.disguisetypes.watchers.*; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import me.libraryaddict.disguise.utilities.DisguiseValues; -import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox; -import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; -import net.kyori.adventure.sound.Sound; -import net.kyori.adventure.text.format.NamedTextColor; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; -import net.minecraft.nbt.TagType; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.sounds.SoundSource; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.*; -import org.bukkit.inventory.EntityEquipment; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.util.BoundingBox; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.slf4j.Logger; -import xiamomc.morph.MorphPlugin; -import xiamomc.morph.backends.DisguiseWrapper; -import xiamomc.morph.config.ConfigOption; -import xiamomc.morph.config.MorphConfigManager; -import xiamomc.morph.misc.DisguiseState; -import xiamomc.morph.misc.NmsRecord; -import xiamomc.morph.utilities.*; -import xiamomc.pluginbase.Managers.DependencyManager; -import xiamomc.pluginbase.Utilities.ColorUtils; - -import java.util.Random; -import java.util.function.BiConsumer; - -public class LibsDisguiseWrapper extends DisguiseWrapper -{ - public LibsDisguiseWrapper(@NotNull Disguise instance, LibsBackend backend) - { - super(instance, backend); - - this.watcher = instance.getWatcher(); - var depMgr = DependencyManager.getInstance(MorphPlugin.getMorphNameSpace()); - var config = depMgr.get(MorphConfigManager.class, true); - - if (config == null) return; - } - - private final FlagWatcher watcher; - - @Override - public EntityEquipment getDisplayingEquipments() - { - return watcher.getEquipment(); - } - - @Override - public void setFakeEquipments(@NotNull EntityEquipment newEquipment) - { - watcher.setArmor(newEquipment.getArmorContents()); - watcher.setItemInMainHand(newEquipment.getItemInMainHand()); - watcher.setItemInOffHand(newEquipment.getItemInOffHand()); - - invalidateCompound(); - } - - @Override - public void setDisplayingFakeEquipments(boolean newVal) - { - } - - @Override - public void setServerSelfView(boolean enabled) - { - instance.setSelfDisguiseVisible(enabled); - } - - @Override - public EntityType getEntityType() - { - return instance.getType().getEntityType(); - } - - @Override - public Disguise copyInstance() - { - return instance.clone(); - } - - @Override - public DisguiseWrapper clone() - { - var newWrapper = new LibsDisguiseWrapper(instance.clone(), (LibsBackend) getBackend()); - newWrapper.compoundTag.merge(this.compoundTag); - - return newWrapper; - } - - /** - * 返回此伪装的名称 - * - * @return 伪装名称 - */ - @Override - public String getDisguiseName() - { - return instance instanceof PlayerDisguise playerDisguise ? playerDisguise.getName() : instance.getDisguiseName(); - } - - @Override - public void setDisguiseName(String name) - { - if(instance instanceof PlayerDisguise playerDisguise) - playerDisguise.setName(name); - else - instance.setDisguiseName(name); - - invalidateCompound(); - } - - private boolean isBaby; - - @Override - public boolean isBaby() - { - return isBaby; - } - - @Override - public void setGlowingColor(ChatColor glowingColor) - { - watcher.setGlowColor(glowingColor); - } - - @Override - public void setGlowing(boolean glowing) - { - watcher.setGlowing(glowing); - } - - @Override - public ChatColor getGlowingColor() - { - return watcher.getGlowColor(); - } - - @Override - public void addCustomData(String key, Object data) - { - instance.addCustomData(key, data); - } - - @Override - public Object getCustomData(String key) - { - return instance.getCustomData(key); - } - - @Override - public GameProfile getSkin() - { - if (!(instance instanceof PlayerDisguise playerDisguise)) return null; - - return (GameProfile) playerDisguise.getWatcher().getSkin().getHandle(); - } - - @Override - public void applySkin(GameProfile profile) - { - if (!(instance instanceof PlayerDisguise playerDisguise)) return; - - var wrappedProfile = WrappedGameProfile.fromHandle(profile); - var LDprofile = ReflectionManager.getGameProfileWithThisSkin(wrappedProfile.getUUID(), wrappedProfile.getName(), wrappedProfile); - - //LD不支持直接用profile设置皮肤,只能先存到本地设置完再移除 - DisguiseAPI.addGameProfile(LDprofile.toString(), LDprofile); - playerDisguise.setSkin(LDprofile); - DisguiseUtilities.removeGameProfile(LDprofile.toString()); - - invalidateCompound(); - } - - @SuppressWarnings("PatternValidation") - @Override - public void onPostConstructDisguise(DisguiseState state, @Nullable Entity targetEntity) - { - invalidateCompound(); - - //workaround: 伪装已死亡的LivingEntity - if (watcher instanceof LivingWatcher livingWatcher && livingWatcher.getHealth() <= 0) - livingWatcher.setHealth(1); - - instance.setTallDisguisesVisible(true); - - //禁用actionBar - DisguiseAPI.setActionBarShown(state.getPlayer(), false); - - if (targetEntity != null) - { - switch (targetEntity.getType()) - { - case CAT -> - { - if (instance.getType() == DisguiseType.CAT) - { - var watcher = (CatWatcher) instance.getWatcher(); - var cat = (Cat) targetEntity; - - watcher.setType(cat.getCatType()); - } - } - - case VILLAGER -> - { - if (instance.getType() == DisguiseType.VILLAGER) - { - var watcher = (VillagerWatcher) instance.getWatcher(); - var villager = (Villager) targetEntity; - - watcher.setVillagerData(new VillagerData(villager.getVillagerType(), - villager.getProfession(), villager.getVillagerLevel())); - } - } - } - } - - instance.setKeepDisguiseOnPlayerDeath(true); - } - - private final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard(); - - public BiConsumer preUpdate; - - private final Random random = new Random(); - - private net.minecraft.world.entity.player.Player nmsPlayer; - - @Override - public void update(boolean isClone, DisguiseState state, Player player) - { - var ldInstance = DisguiseAPI.getDisguise(player); - if (this.instance != ldInstance) - { - if (player.isDead()) return; - - throw new RuntimeException("Current disguise instance from LibsDisguises '%s' does not match the one saved in our wrapper '%s'".formatted(ldInstance, this.instance)); - } - - if (nmsPlayer == null) - nmsPlayer = NmsRecord.ofPlayer(player); - - if (preUpdate != null) - preUpdate.accept(watcher, player); - - //对克隆的伪装手动更新一些属性 - if (!isClone) return; - - //workaround: 复制实体伪装时会一并复制隐身标签 - // 会导致复制出来的伪装永久隐身 - if (watcher.isInvisible() != player.isInvisible()) - watcher.setInvisible(player.isInvisible()); - - //workaround: 伪装不会主动检测玩家有没有发光 - if (watcher.isGlowing() != player.isGlowing()) - watcher.setGlowing(player.isGlowing()); - - //设置发光颜色 - if (!state.haveCustomGlowColor()) - { - var team = scoreboard.getPlayerTeam(player); - var playerColor = (team == null || !team.hasColor()) ? NamedTextColor.WHITE : team.color(); - - watcher.setGlowColor(ColorUtils.toChatColor(playerColor)); - } - - //设置滑翔状态 - if (watcher.isFlyingWithElytra() != player.isGliding()) - watcher.setFlyingWithElytra(player.isGliding()); - - //workaround: 复制出来的伪装会忽略玩家Pose - if (state.shouldHandlePose()) - { - var pose = DisguiseUtils.toLibsEntityPose(player.getPose()); - - if (watcher.getEntityPose() != pose) - watcher.setEntityPose(pose); - } - } - - private final CompoundTag compoundTag = new CompoundTag(); - private CompoundTag mixedTag = new CompoundTag(); - private boolean tagValid; - - private void invalidateCompound() - { - this.tagValid = false; - } - - @Override - public void mergeCompound(CompoundTag compoundTag) - { - this.compoundTag.merge(compoundTag); - this.isBaby = NbtUtils.isBabyForType(getEntityType(), compoundTag); - - invalidateCompound(); - - var watcher = instance.getWatcher(); - switch (getEntityType()) - { - case SLIME, MAGMA_CUBE -> - { - var size = compoundTag.getInt("Size"); - ((SlimeWatcher)watcher).setSize(size + 1); - resetDimensions(); - } - } - } - - @Override - public CompoundTag getCompound() - { - if (tagValid) return mixedTag; - - var compoundTag = this.compoundTag.copy(); - - //todo: 将这些东西移动回VanillaDisguiseProvider,找个合适的方法来从外部获取伪装的NBT数据 - var watcher = instance.getWatcher(); - switch (getEntityType()) - { - case SLIME, MAGMA_CUBE -> - { - var size = ((SlimeWatcher) watcher).getSize() - 1; - compoundTag.putInt("Size", size); - } - - case HORSE -> - { - var color = ((HorseWatcher) watcher).getColor().ordinal(); - var style = ((HorseWatcher) watcher).getStyle().ordinal(); - compoundTag.putInt("Variant", color | style << 8); - } - - case PARROT -> - { - var variant = ((ParrotWatcher) watcher).getVariant().ordinal(); - compoundTag.putInt("Variant", variant); - } - - case CAT -> - { - var variant = ((CatWatcher) watcher).getType().getKey().asString(); - compoundTag.putString("variant", variant); - } - - case TROPICAL_FISH -> - { - var variant = ((TropicalFishWatcher) watcher).getVariant(); - - compoundTag.putInt("Variant", variant); - } - - case RABBIT -> - { - var type = ((RabbitWatcher) watcher).getType().getTypeId(); - compoundTag.putInt("RabbitType", type); - } - - case FOX -> - { - var foxType = ((FoxWatcher) watcher).getType().name().toLowerCase(); - compoundTag.putString("Type", foxType); - } - - case FROG -> - { - var variant = ((FrogWatcher) watcher).getVariant().getKey().asString(); - compoundTag.putString("variant", variant); - } - - case GOAT -> - { - var goatWatcher = ((GoatWatcher) watcher); - - var hasLeftHorn = goatWatcher.hasLeftHorn(); - var hasRightHorn = goatWatcher.hasRightHorn(); - var isScreaming = goatWatcher.isScreaming(); - - compoundTag.putBoolean("HasLeftHorn", hasLeftHorn); - compoundTag.putBoolean("HasRightHorn", hasRightHorn); - compoundTag.putBoolean("IsScreamingGoat", isScreaming); - } - - case PANDA -> - { - var pandaWatcher = ((PandaWatcher) watcher); - var mainGene = pandaWatcher.getMainGene(); - var hiddenGene = pandaWatcher.getHiddenGene(); - - compoundTag.putString("MainGene", mainGene.toString().toLowerCase()); - compoundTag.putString("HiddenGene", hiddenGene.toString().toLowerCase()); - } - - case VILLAGER -> - { - if (!compoundTag.contains("VillagerData")) - { - var villagerData = ((VillagerWatcher) watcher).getVillagerData(); - var profession = villagerData.getProfession(); - var type = villagerData.getType(); - var level = villagerData.getLevel(); - - var compound = new CompoundTag(); - compound.putInt("level", level); - compound.putString("profession", profession.getKey().asString()); - compound.putString("type", type.getKey().asString()); - - compoundTag.put("VillagerData", compound); - } - } - } - - this.tagValid = true; - this.mixedTag = compoundTag; - - return compoundTag.copy(); - } - - /** - * Gets network id of this disguise displayed to other players - * - * @return The network id of this disguise - */ - @Override - public int getNetworkEntityId() - { - return nmsPlayer.getId(); - } - - @Nullable - @Override - public R getTag(String path, TagType type) - { - try - { - var obj = (tagValid ? this.mixedTag : getCompound()).get(path); - - if (obj != null && obj.getType() == type) - return (R) obj; - - return null; - } - catch (Throwable t) - { - logger.error("Unable to read NBT '%s' from instance:".formatted(path)); - t.printStackTrace(); - - return null; - } - } - - private static final Logger logger = MorphPlugin.getInstance().getSLF4JLogger(); - - @Override - public void showArms(boolean showarms) - { - if (instance.getWatcher() instanceof ArmorStandWatcher armorStandWatcher) - armorStandWatcher.setShowArms(showarms); - - invalidateCompound(); - } - - @Override - public void setSaddled(boolean saddled) - { - if (instance.getWatcher() instanceof AbstractHorseWatcher horseWatcher) - horseWatcher.setSaddled(saddled); - - invalidateCompound(); - } - - @Override - public boolean isSaddled() - { - if (instance.getWatcher() instanceof AbstractHorseWatcher horseWatcher) - return horseWatcher.isSaddled(); - - invalidateCompound(); - - return false; - } - - @Override - public void setAggressive(boolean aggressive) - { - if (watcher instanceof CreeperWatcher creeperWatcher) - { - creeperWatcher.setIgnited(aggressive); - } - else if (watcher instanceof GhastWatcher ghastWatcher) - { - ghastWatcher.setAggressive(aggressive); - } - - invalidateCompound(); - } -} diff --git a/src/main/java/xiamomc/morph/events/CommonEventProcessor.java b/src/main/java/xiamomc/morph/events/CommonEventProcessor.java index 48b49dfd..89d33297 100644 --- a/src/main/java/xiamomc/morph/events/CommonEventProcessor.java +++ b/src/main/java/xiamomc/morph/events/CommonEventProcessor.java @@ -3,7 +3,6 @@ import com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent; import com.destroystokyo.paper.event.player.PlayerPostRespawnEvent; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import me.libraryaddict.disguise.DisguiseAPI; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; import org.bukkit.Bukkit; @@ -22,7 +21,6 @@ import xiamomc.morph.MorphManager; import xiamomc.morph.MorphPluginObject; import xiamomc.morph.RevealingHandler; -import xiamomc.morph.backends.libsdisg.LibsDisguiseWrapper; import xiamomc.morph.commands.MorphCommandManager; import xiamomc.morph.config.ConfigOption; import xiamomc.morph.config.MorphConfigManager; @@ -294,19 +292,6 @@ public void onPlayerSwapHand(PlayerSwapHandItemsEvent e) if (state != null) { - //workaround: 启用服务端预览的情况下会造成物品栏desync - if (state.getServerSideSelfVisible()) - { - this.addSchedule(() -> - { - if (state.getDisguiseWrapper() instanceof LibsDisguiseWrapper) - { - if (DisguiseAPI.isDisguised(player) && DisguiseAPI.isSelfDisguised(player)) - player.updateInventory(); - } - }, 2); - } - //workaround: 交换副手后伪装有概率在左右手显示同一个物品 if (state.showingDisguisedItems()) { diff --git a/src/main/java/xiamomc/morph/misc/integrations/gsit/GSitCompactProcessor.java b/src/main/java/xiamomc/morph/misc/integrations/gsit/GSitCompactProcessor.java deleted file mode 100644 index dd4a3621..00000000 --- a/src/main/java/xiamomc/morph/misc/integrations/gsit/GSitCompactProcessor.java +++ /dev/null @@ -1,107 +0,0 @@ -package xiamomc.morph.misc.integrations.gsit; - -import dev.geco.gsit.api.event.*; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.utilities.DisguiseUtilities; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerQuitEvent; -import xiamomc.morph.MorphManager; -import xiamomc.morph.MorphPluginObject; -import xiamomc.morph.backends.libsdisg.LibsBackend; -import xiamomc.morph.utilities.EntityTypeUtils; -import xiamomc.pluginbase.Annotations.Resolved; - -import java.util.List; - -public class GSitCompactProcessor extends MorphPluginObject implements Listener -{ - @Resolved - private MorphManager morphs; - - //region GSit <-> LibsDisguises workaround - - @EventHandler - public void onLeave(PlayerQuitEvent e) - { - gSitHandlingPlayers.remove(e.getPlayer()); - } - - @EventHandler - public void onEntityGetUp(EntityGetUpSitEvent e) - { - if (e.getEntity() instanceof Player player) - showDisguiseFor(player); - } - - private final List gSitHandlingPlayers = new ObjectArrayList<>(); - - @EventHandler - public void onEntitySit(EntitySitEvent e) - { - if (e.getEntity() instanceof Player player) - hideDisguiseFor(player); - } - - @EventHandler - public void onEarlyPlayerPlayerSit(PrePlayerPlayerSitEvent e) - { - var state = morphs.getDisguiseStateFor(e.getTarget()); - - if (state != null && !state.getDisguiseWrapper().isPlayerDisguise()) - { - var disguise = state.getDisguiseWrapper(); - - if (EntityTypeUtils.saddleable(disguise.getEntityType())) - { - if (!disguise.isSaddled()) - e.setCancelled(true); - } - else if (!disguise.isPlayerDisguise()) - { - e.setCancelled(true); - } - } - } - - @EventHandler - public void onPlayerPlayerSit(PlayerPlayerSitEvent e) - { - gSitHandlingPlayers.add(e.getPlayer()); - hideDisguiseFor(e.getPlayer()); - } - - @EventHandler - public void onPlayerGetUpPlayerSit(PlayerGetUpPlayerSitEvent e) - { - if (gSitHandlingPlayers.contains(e.getPlayer())) - { - showDisguiseFor(e.getPlayer()); - gSitHandlingPlayers.remove(e.getPlayer()); - } - } - - private void hideDisguiseFor(Player player) - { - if (!(morphs.getCurrentBackend() instanceof LibsBackend)) return; - - if (DisguiseAPI.isDisguised(player)) - DisguiseUtilities.removeSelfDisguise(DisguiseAPI.getDisguise(player)); - } - - private void showDisguiseFor(Player player) - { - if (!(morphs.getCurrentBackend() instanceof LibsBackend)) return; - - if (DisguiseAPI.isDisguised(player)) - this.addSchedule(() -> - { - if (DisguiseAPI.isDisguised(player)) - DisguiseUtilities.setupFakeDisguise(DisguiseAPI.getDisguise(player)); - }); - } - - //endregion GSit <-> LibsDisguises workaround -} \ No newline at end of file diff --git a/src/main/java/xiamomc/morph/providers/ItemDisplayProvider.java b/src/main/java/xiamomc/morph/providers/ItemDisplayProvider.java deleted file mode 100644 index 2d8663e3..00000000 --- a/src/main/java/xiamomc/morph/providers/ItemDisplayProvider.java +++ /dev/null @@ -1,161 +0,0 @@ -package xiamomc.morph.providers; - -import net.kyori.adventure.text.Component; -import org.bukkit.Material; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import xiamomc.morph.backends.DisguiseWrapper; -import xiamomc.morph.backends.libsdisg.LibsBackend; -import xiamomc.morph.misc.DisguiseMeta; -import xiamomc.morph.misc.DisguiseState; -import xiamomc.morph.misc.DisguiseTypes; - -import java.util.List; - -@ApiStatus.Experimental -public class ItemDisplayProvider extends DefaultDisguiseProvider -{ - /** - * 获取此DisguiseProvider的命名空间,此命名空间将被用于判断某个伪装是否属于此Provider - * - * @return 此DisguiseProvider的命名空间 - */ - @Override - public @NotNull String getNameSpace() - { - return DisguiseTypes.ITEM_DISPLAY.getNameSpace(); - } - - /** - * 某个伪装ID是否已知 - * - * @param rawIdentifier 伪装ID - * @return 此ID是否已知 - */ - @Override - public boolean isValid(String rawIdentifier) - { - var idStripped = DisguiseTypes.ITEM_DISPLAY.toStrippedId(rawIdentifier); - return idStripped.startsWith("item@"); - } - - @Nullable - private Material getMaterialFromId(String rawIdentifier) - { - var strippedId = DisguiseTypes.ITEM_DISPLAY.toStrippedId(rawIdentifier); - - return Material.matchMaterial(strippedId); - } - - /** - * Gets all available disguise identifiers for this provider - * - * @return A list containing available disguise identifiers for this provider - */ - @Override - public List getAllAvailableDisguises() - { - return List.of( - "item@1x", - "item@2x", - "item@3x", - "item@4x", - "item@5x", - "item@10x", - "item@20x" - ); - } - - /** - * 为某个玩家创建 {@link DisguiseWrapper} - * - * @param player 目标玩家 - * @param disguiseMeta 伪装ID - * @param targetEntity 玩家的目标实体(如果有), 可用来判断是否要复制伪装 - * @return 操作结果 - */ - @Override - public @NotNull DisguiseResult makeWrapper(Player player, DisguiseMeta disguiseMeta, @Nullable Entity targetEntity) - { - var currentBackend = getBackend(); - - if (!(currentBackend instanceof LibsBackend backend)) - { - logger.error("Item Displays only works with the LibsDisguises backend"); - return DisguiseResult.fail(); - } - - //var material = getMaterialFromId(disguiseMeta.rawIdentifier); - //if (material == null) return DisguiseResult.fail(); - - var idSplit = disguiseMeta.rawIdentifier.split("@"); - int scale = idSplit.length >= 2 ? getScaleFrom(idSplit[1]) : 1; - var wrapper = backend.createItemDisplay(Material.AIR, scale); - - return DisguiseResult.success(wrapper); - } - - private int getScaleFrom(String arg) - { - try - { - return Integer.parseInt(arg.replace("x", "")); - } - catch (Throwable t) - { - logger.warn("Unable to parse scale parameter from input: '%s'".formatted(arg)); - return 1; - } - } - - @Override - public boolean unMorph(Player player, DisguiseState state) - { - return super.unMorph(player, state); - } - - /** - * 我们是否可以通过给定的{@link DisguiseMeta}来从某个实体构建伪装? - * - * @param info {@link DisguiseMeta} - * @param targetEntity 目标实体 - * @param theirState 他们的{@link DisguiseState},为null则代表他们不是玩家或没有通过MorphPlugin伪装 - * @return 是否允许此操作,如果theirState不为null则优先检查theirState是否和传入的info相匹配 - */ - @Override - public boolean canConstruct(DisguiseMeta info, Entity targetEntity, @Nullable DisguiseState theirState) - { - return false; - } - - /** - * 是否可以克隆某个实体现有的伪装? - * - * @param info {@link DisguiseMeta} - * @param targetEntity 目标实体 - * @param theirState 他们的{@link DisguiseState},为null则代表他们不是玩家或没有通过MorphPlugin伪装 - * @param theirDisguise 他们目前应用的伪装 - * @return 是否允许此操作 - */ - @Override - protected boolean canCloneDisguise(DisguiseMeta info, Entity targetEntity, @NotNull DisguiseState theirState, @NotNull DisguiseWrapper theirDisguise) - { - return false; - } - - /** - * 获取某个伪装的显示名称 - * - * @param disguiseIdentifier 伪装ID - * @param locale 显示名称的目标语言 - * @return 显示名称 - */ - @Override - public Component getDisplayName(String disguiseIdentifier, @Nullable String locale) - { - return Component.text(disguiseIdentifier); - } -} diff --git a/src/main/java/xiamomc/morph/providers/LocalDisguiseProvider.java b/src/main/java/xiamomc/morph/providers/LocalDisguiseProvider.java deleted file mode 100644 index 0dee1f79..00000000 --- a/src/main/java/xiamomc/morph/providers/LocalDisguiseProvider.java +++ /dev/null @@ -1,132 +0,0 @@ -package xiamomc.morph.providers; - -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import me.libraryaddict.disguise.DisguiseAPI; -import me.libraryaddict.disguise.DisguiseConfig; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import net.kyori.adventure.text.Component; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import xiamomc.morph.backends.DisguiseWrapper; -import xiamomc.morph.backends.libsdisg.LibsBackend; -import xiamomc.morph.config.ConfigOption; -import xiamomc.morph.config.MorphConfigManager; -import xiamomc.morph.messages.MessageUtils; -import xiamomc.morph.messages.MorphStrings; -import xiamomc.morph.misc.DisguiseMeta; -import xiamomc.morph.misc.DisguiseState; -import xiamomc.morph.misc.DisguiseTypes; -import xiamomc.pluginbase.Annotations.Initializer; -import xiamomc.pluginbase.Bindables.Bindable; - -import java.util.List; - -public class LocalDisguiseProvider extends VanillaDisguiseProvider -{ - private final Bindable allowLD = new Bindable<>(false); - - @Initializer - private void load(MorphConfigManager configManager) - { - configManager.bind(allowLD, ConfigOption.ALLOW_LD_DISGUISES); - } - - @Override - public List getAllAvailableDisguises() - { - var list = new ObjectArrayList(); - - DisguiseConfig.getCustomDisguises().forEach((p, s) -> - { - list.add(DisguiseTypes.LD.toId(p.toReadable())); - }); - - return list; - } - - @Override - public @NotNull String getNameSpace() - { - return DisguiseTypes.LD.getNameSpace(); - } - - @Override - public @NotNull DisguiseResult makeWrapper(Player player, DisguiseMeta disguiseMeta, @Nullable Entity targetEntity) - { - if (!allowLD.get()) - { - player.sendMessage(MessageUtils.prefixes(player, MorphStrings.disguiseBannedOrNotSupportedString())); - return DisguiseResult.fail(); - } - - var id = disguiseMeta.getIdentifier(); - - if (DisguiseTypes.fromId(id) != DisguiseTypes.LD) - return DisguiseResult.fail(); - - Disguise disguise = DisguiseAPI.getCustomDisguise(DisguiseTypes.LD.toStrippedId(id)); - - if (disguise == null) - { - logger.error("未能找到叫" + id + "的伪装"); - player.sendMessage(MessageUtils.prefixes(player, MorphStrings.noSuchLocalDisguiseString().resolve("id", id))); - return DisguiseResult.fail(); - } - - DisguiseAPI.disguiseEntity(player, disguise); - - var ldBackend = new LibsBackend(); - return DisguiseResult.success(ldBackend.createInstanceDirect(disguise)); - } - - @Override - public boolean canConstruct(DisguiseMeta info, Entity targetEntity, @Nullable DisguiseState theirState) - { - return theirState != null && theirState.getDisguiseIdentifier().equals(info.getIdentifier()); - } - - @Override - protected boolean canCloneDisguise(DisguiseMeta info, Entity targetEntity, - @NotNull DisguiseState theirState, @NotNull DisguiseWrapper theirDisguise) - { - if (theirState != null) - return theirState.getDisguiseIdentifier().equals(info.getIdentifier()); - - return false; - } - - @Override - public boolean unMorph(Player player, DisguiseState state) - { - super.unMorph(player, state); - - return false; - } - - @Override - public Component getDisplayName(String disguiseIdentifier, String locale) - { - var ldID = DisguiseTypes.LD.toStrippedId(disguiseIdentifier); - - var disg = DisguiseAPI.getCustomDisguise(ldID); - - if (disg != null) - return Component.text(disg.getType().toReadable().equals(disg.getDisguiseName()) ? ldID : disg.getDisguiseName()); - - return Component.text(ldID); - } - - @Override - public boolean validForClient(DisguiseState state) - { - return false; - } - - @Override - public String getSelfViewIdentifier(DisguiseState state) - { - return ""; - } -} diff --git a/src/main/java/xiamomc/morph/utilities/DisguiseUtils.java b/src/main/java/xiamomc/morph/utilities/DisguiseUtils.java index fd74896f..6a7f329c 100644 --- a/src/main/java/xiamomc/morph/utilities/DisguiseUtils.java +++ b/src/main/java/xiamomc/morph/utilities/DisguiseUtils.java @@ -1,7 +1,6 @@ package xiamomc.morph.utilities; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import me.libraryaddict.disguise.disguisetypes.EntityPose; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.entity.Pose; @@ -23,20 +22,6 @@ public static String asString(DisguiseMeta info) return info.getKey(); } - public static EntityPose toLibsEntityPose(Pose pose) - { - return switch (pose) - { - case SWIMMING -> EntityPose.SWIMMING; - case FALL_FLYING -> EntityPose.FALL_FLYING; - case SNEAKING -> EntityPose.SNEAKING; - case SLEEPING -> EntityPose.SLEEPING; - case SPIN_ATTACK -> EntityPose.SPIN_ATTACK; - case DYING -> EntityPose.DYING; - default -> EntityPose.STANDING; - }; - } - public static boolean validForHeadMorph(Material material) { return material == Material.DRAGON_HEAD