From 3046fdc247a249ec6d204d4257044d448be1aab1 Mon Sep 17 00:00:00 2001 From: MATRIX-feather Date: Fri, 3 Nov 2023 14:08:35 +0800 Subject: [PATCH] =?UTF-8?q?misc:=20=E5=85=81=E8=AE=B8=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=B8=B2=E6=9F=93=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/xiamomc/morph/MorphManager.java | 7 +++--- .../subcommands/plugin/OptionSubCommand.java | 2 ++ .../xiamomc/morph/config/ConfigOption.java | 2 ++ .../morph/config/MorphConfigManager.java | 2 +- .../morph/events/CommonEventProcessor.java | 12 +++++---- .../network/server/MorphClientHandler.java | 25 +++++++++++-------- src/main/resources/config.yml | 6 ++++- 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/main/java/xiamomc/morph/MorphManager.java b/src/main/java/xiamomc/morph/MorphManager.java index 84d17138..63e1f0da 100644 --- a/src/main/java/xiamomc/morph/MorphManager.java +++ b/src/main/java/xiamomc/morph/MorphManager.java @@ -117,9 +117,6 @@ private void load() try { - if (1+1==2) - throw new NoClassDefFoundError(); - this.currentBackend = new LibsBackend(); } catch (NoClassDefFoundError e) @@ -141,6 +138,7 @@ private void load() bannedDisguises = config.getBindableList(ConfigOption.BANNED_DISGUISES); config.bind(allowHeadMorph, ConfigOption.ALLOW_HEAD_MORPH); config.bind(allowAcquireMorph, ConfigOption.ALLOW_ACQUIRE_MORPHS); + config.bind(useClientRenderer, ConfigOption.USE_CLIENT_RENDERER); registerProviders(ObjectList.of( new VanillaDisguiseProvider(), @@ -330,6 +328,7 @@ public boolean registerProviders(List providers) private final Bindable allowHeadMorph = new Bindable<>(true); private final Bindable allowAcquireMorph = new Bindable<>(true); + private final Bindable useClientRenderer = new Bindable<>(false); private final Map uuidPlayerTexturesMap = new ConcurrentHashMap<>(); @@ -725,7 +724,7 @@ else if (!provider.isValid(key)) public boolean isUsingClientRenderer() { - return currentBackend == nilBackend; + return currentBackend == nilBackend && useClientRenderer.get(); } //region Command generating diff --git a/src/main/java/xiamomc/morph/commands/subcommands/plugin/OptionSubCommand.java b/src/main/java/xiamomc/morph/commands/subcommands/plugin/OptionSubCommand.java index 29a096d0..7298e390 100644 --- a/src/main/java/xiamomc/morph/commands/subcommands/plugin/OptionSubCommand.java +++ b/src/main/java/xiamomc/morph/commands/subcommands/plugin/OptionSubCommand.java @@ -72,6 +72,8 @@ public OptionSubCommand() subCommands.add(getToggle("allow_acquire_morphs", ConfigOption.ALLOW_ACQUIRE_MORPHS, "allow_acquire_morphs")); subCommands.add(getToggle("allow_flight", ConfigOption.ALLOW_FLIGHT, "allow_flight")); + + subCommands.add(getToggle("client_renderer", ConfigOption.USE_CLIENT_RENDERER, "client_renderer")); } private ISubCommand getGeneric(String name, ConfigOption option, String perm, diff --git a/src/main/java/xiamomc/morph/config/ConfigOption.java b/src/main/java/xiamomc/morph/config/ConfigOption.java index 4a62efb6..2222ae53 100644 --- a/src/main/java/xiamomc/morph/config/ConfigOption.java +++ b/src/main/java/xiamomc/morph/config/ConfigOption.java @@ -39,6 +39,8 @@ public enum ConfigOption LOG_INCOMING_PACKETS(clientNode().append("log_incoming_packets"), false), LOG_OUTGOING_PACKETS(clientNode().append("log_outgoing_packets"), false), + USE_CLIENT_RENDERER(clientNode().append("client_renderer"), true), + MIRROR_CONTROL_DISTANCE(interactionMirrorNode().append("normalDistance"), -1), MIRROR_IGNORE_DISGUISED(interactionMirrorNode().append("ignore_disguised"), true), MIRROR_DESTROY_TIMEOUT(interactionMirrorNode().append("destroy_timeout"), 40), diff --git a/src/main/java/xiamomc/morph/config/MorphConfigManager.java b/src/main/java/xiamomc/morph/config/MorphConfigManager.java index 31c00440..7d0cffec 100644 --- a/src/main/java/xiamomc/morph/config/MorphConfigManager.java +++ b/src/main/java/xiamomc/morph/config/MorphConfigManager.java @@ -129,7 +129,7 @@ public void reload() super.reload(); //更新配置 - int targetVersion = 26; + int targetVersion = 27; var configVersion = getOrDefault(Integer.class, ConfigOption.VERSION); diff --git a/src/main/java/xiamomc/morph/events/CommonEventProcessor.java b/src/main/java/xiamomc/morph/events/CommonEventProcessor.java index 7fea7edd..9e77ac1c 100644 --- a/src/main/java/xiamomc/morph/events/CommonEventProcessor.java +++ b/src/main/java/xiamomc/morph/events/CommonEventProcessor.java @@ -444,14 +444,16 @@ public void onPlayerJoin(PlayerJoinEvent e) networkingHelper.sendCommandToRevealablePlayers(morphs.genPartialMapCommand(state)); - var metaCommand = networkingHelper.prepareMeta(player) - .forDisguiseState(state) - .build(); - networkingHelper.sendCommandToAllPlayers(metaCommand); - if (morphs.isUsingClientRenderer()) + { networkingHelper.sendCommandToAllPlayers(morphs.genClientRenderAddCommand(state)); + var metaCommand = networkingHelper.prepareMeta(player) + .forDisguiseState(state) + .build(); + networkingHelper.sendCommandToAllPlayers(metaCommand); + } + //调用Morph事件 new PlayerJoinedWithDisguiseEvent(player, state).callEvent(); diff --git a/src/main/java/xiamomc/morph/network/server/MorphClientHandler.java b/src/main/java/xiamomc/morph/network/server/MorphClientHandler.java index 34a5e47a..a84a2501 100644 --- a/src/main/java/xiamomc/morph/network/server/MorphClientHandler.java +++ b/src/main/java/xiamomc/morph/network/server/MorphClientHandler.java @@ -127,6 +127,7 @@ private void logPacket(boolean isOutGoingPacket, Player player, String channel, private final CommandRegistries registries = new CommandRegistries(); private final Bindable modifyBoundingBoxes = new Bindable<>(false); + private final Bindable useClientRenderer = new Bindable<>(false); @Initializer private void load(MorphPlugin plugin, MorphConfigManager configManager) @@ -257,6 +258,8 @@ private void load(MorphPlugin plugin, MorphConfigManager configManager) configManager.bind(modifyBoundingBoxes, ConfigOption.MODIFY_BOUNDING_BOX); + configManager.bind(useClientRenderer, ConfigOption.USE_CLIENT_RENDERER); + modifyBoundingBoxes.onValueChanged((o, n) -> { var players = Bukkit.getOnlinePlayers(); @@ -265,6 +268,7 @@ private void load(MorphPlugin plugin, MorphConfigManager configManager) forceTargetVersion.onValueChanged((o, n) -> scheduleReAuthPlayers()); modifyBoundingBoxes.onValueChanged((o, n) -> scheduleReAuthPlayers()); + useClientRenderer.onValueChanged((o, n) -> scheduleReAuthPlayers()); allowClient.onValueChanged((o, n) -> { @@ -623,21 +627,20 @@ public void onInitialCommand(C2SInitialCommand c2SInitialCommand) sendCommand(player, manager.genMapCommand()); if (manager.isUsingClientRenderer()) + { sendCommand(player, manager.genRenderSyncCommand()); - logger.info("READY!"); - var disguises = manager.getDisguiseStates(); - for (DisguiseState bindingState : disguises) - { - logger.info("STATE! " + bindingState); - var bindingPlayer = bindingState.getPlayer(); + var disguises = manager.getDisguiseStates(); + for (DisguiseState bindingState : disguises) + { + var bindingPlayer = bindingState.getPlayer(); - var packet = networkingHelper.prepareMeta(bindingPlayer) - .forDisguiseState(bindingState) - .build(); + var packet = networkingHelper.prepareMeta(bindingPlayer) + .forDisguiseState(bindingState) + .build(); - this.sendCommand(player, packet); - logger.info("SEND! " + packet); + this.sendCommand(player, packet); + } } playerConnectionStates.put(player, InitializeState.DONE); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 84838519..b44ecdf3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -238,5 +238,9 @@ root: # Should we log packets sent to the client? log_outgoing_packets: false + # Make clients render other players' disguises when LibsDisguises is not present? + # Requires the client to implement the v11 protocol + client_renderer: true + # Do not touch unless you know what you're doing! - version: 26 + version: 27