Skip to content

Commit

Permalink
misc: 允许关闭客户端渲染器
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Nov 3, 2023
1 parent 8f7217b commit 3046fdc
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 22 deletions.
7 changes: 3 additions & 4 deletions src/main/java/xiamomc/morph/MorphManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ private void load()

try
{
if (1+1==2)
throw new NoClassDefFoundError();

this.currentBackend = new LibsBackend();
}
catch (NoClassDefFoundError e)
Expand All @@ -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(),
Expand Down Expand Up @@ -330,6 +328,7 @@ public boolean registerProviders(List<DisguiseProvider> providers)
private final Bindable<Boolean> allowHeadMorph = new Bindable<>(true);

private final Bindable<Boolean> allowAcquireMorph = new Bindable<>(true);
private final Bindable<Boolean> useClientRenderer = new Bindable<>(false);

private final Map<UUID, PlayerTextures> uuidPlayerTexturesMap = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -725,7 +724,7 @@ else if (!provider.isValid(key))

public boolean isUsingClientRenderer()
{
return currentBackend == nilBackend;
return currentBackend == nilBackend && useClientRenderer.get();
}

//region Command generating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> ISubCommand getGeneric(String name, ConfigOption option, String perm,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xiamomc/morph/config/ConfigOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xiamomc/morph/config/MorphConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void reload()
super.reload();

//更新配置
int targetVersion = 26;
int targetVersion = 27;

var configVersion = getOrDefault(Integer.class, ConfigOption.VERSION);

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/xiamomc/morph/events/CommonEventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
25 changes: 14 additions & 11 deletions src/main/java/xiamomc/morph/network/server/MorphClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private void logPacket(boolean isOutGoingPacket, Player player, String channel,

private final CommandRegistries registries = new CommandRegistries();
private final Bindable<Boolean> modifyBoundingBoxes = new Bindable<>(false);
private final Bindable<Boolean> useClientRenderer = new Bindable<>(false);

@Initializer
private void load(MorphPlugin plugin, MorphConfigManager configManager)
Expand Down Expand Up @@ -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();
Expand All @@ -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) ->
{
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3046fdc

Please sign in to comment.