Skip to content

Commit

Permalink
fix: 玩家切换伪装物品显示时对应的CRMeta指令不会发送
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Oct 31, 2023
1 parent 2fa1449 commit 21f7181
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 36 deletions.
19 changes: 6 additions & 13 deletions src/main/java/xiamomc/morph/MorphManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import xiamomc.morph.messages.vanilla.VanillaMessageStore;
import xiamomc.morph.misc.*;
import xiamomc.morph.misc.permissions.CommonPermissions;
import xiamomc.morph.network.commands.S2C.AbstractS2CCommand;
import xiamomc.morph.network.commands.S2C.clientrender.*;
import xiamomc.morph.network.commands.S2C.map.S2CMapCommand;
import xiamomc.morph.network.commands.S2C.map.S2CMapRemoveCommand;
Expand All @@ -54,7 +53,6 @@
import xiamomc.morph.storage.playerdata.PlayerDataStore;
import xiamomc.morph.storage.playerdata.PlayerMeta;
import xiamomc.morph.utilities.DisguiseUtils;
import xiamomc.morph.utilities.MapMetaUtils;
import xiamomc.morph.utilities.NbtUtils;
import xiamomc.pluginbase.Annotations.Initializer;
import xiamomc.pluginbase.Annotations.Resolved;
Expand Down Expand Up @@ -688,18 +686,13 @@ else if (!provider.isValid(key))
networkingHelper.sendCommandToRevealablePlayers(genPartialMapCommand(outComingState));

//发送元数据
if (isUsingNilServerBackend())
if (isUsingClientRenderer())
{
networkingHelper.sendCommandToAllPlayers(new S2CRenderMapAddCommand(outComingState.getPlayer().getEntityId(), outComingState.getDisguiseIdentifier()));

var meta = new S2CRenderMeta(player.getEntityId());
meta.profileCompound = outComingState.getProfileNbtString();
meta.sNbt = outComingState.getCachedNbtString();
meta.showOverridedEquipment = outComingState.showingDisguisedItems();
meta.overridedEquipment = MapMetaUtils.toPacketEquipment(outComingState.getDisguisedItems());

var packet = new S2CRenderMapMetaCommand(meta);
networkingHelper.sendCommandToAllPlayers(packet);
networkingHelper.prepareMeta(player)
.forDisguiseState(outComingState)
.send();
}

return true;
Expand Down Expand Up @@ -728,7 +721,7 @@ else if (!provider.isValid(key))
}
}

public boolean isUsingNilServerBackend()
public boolean isUsingClientRenderer()
{
return currentBackend == nilBackend;
}
Expand Down Expand Up @@ -949,7 +942,7 @@ public void unMorph(@Nullable CommandSender source, Player player, boolean bypas
// 向管理员发送map移除指令
networkingHelper.sendCommandToRevealablePlayers(new S2CMapRemoveCommand(player.getEntityId()));

if (isUsingNilServerBackend())
if (isUsingClientRenderer())
networkingHelper.sendCommandToAllPlayers(new S2CRenderMapRemoveCommand(player.getEntityId()));
}

Expand Down
7 changes: 1 addition & 6 deletions src/main/java/xiamomc/morph/events/CommonEventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,19 @@
import xiamomc.morph.messages.MorphStrings;
import xiamomc.morph.messages.SkillStrings;
import xiamomc.morph.messages.vanilla.VanillaMessageStore;
import xiamomc.morph.misc.DisguiseState;
import xiamomc.morph.misc.DisguiseTypes;
import xiamomc.morph.misc.NetworkingHelper;
import xiamomc.morph.misc.permissions.CommonPermissions;
import xiamomc.morph.network.commands.S2C.S2CSwapCommand;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMapMetaCommand;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMeta;
import xiamomc.morph.network.commands.S2C.map.S2CMapRemoveCommand;
import xiamomc.morph.network.server.MorphClientHandler;
import xiamomc.morph.network.server.ServerSetEquipCommand;
import xiamomc.morph.skills.MorphSkillHandler;
import xiamomc.morph.utilities.EntityTypeUtils;
import xiamomc.morph.utilities.MapMetaUtils;
import xiamomc.pluginbase.Annotations.Initializer;
import xiamomc.pluginbase.Annotations.Resolved;
import xiamomc.pluginbase.Bindables.Bindable;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -449,7 +444,7 @@ public void onPlayerJoin(PlayerJoinEvent e)

networkingHelper.sendCommandToRevealablePlayers(morphs.genPartialMapCommand(state));

if (morphs.isUsingNilServerBackend())
if (morphs.isUsingClientRenderer())
networkingHelper.sendCommandToAllPlayers(morphs.genClientRenderAddCommand(state));

//调用Morph事件
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/xiamomc/morph/misc/NetworkingHelper.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package xiamomc.morph.misc;

import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.EntityEquipment;
import xiamomc.morph.MorphPluginObject;
import xiamomc.morph.misc.permissions.CommonPermissions;
import xiamomc.morph.network.commands.S2C.AbstractS2CCommand;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMapAddCommand;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMapMetaCommand;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMeta;
import xiamomc.morph.network.commands.S2C.map.S2CPartialMapCommand;
import xiamomc.morph.network.server.MorphClientHandler;
import xiamomc.morph.utilities.MapMetaUtils;
import xiamomc.pluginbase.Annotations.Resolved;

import java.util.HashMap;
Expand Down Expand Up @@ -55,4 +60,71 @@ public void sendCommandToAllPlayers(AbstractS2CCommand<?> cmd)
{
Bukkit.getOnlinePlayers().forEach(p -> clientHandler.sendCommand(p, cmd));
}

public PrepareMeta prepareMeta(int networkId)
{
return new PrepareMeta(networkId, this);
}

public PrepareMeta prepareMeta(Entity entity)
{
return prepareMeta(entity.getEntityId());
}

public static class PrepareMeta
{
public PrepareMeta(int networkId, NetworkingHelper bindingHelper)
{
this.renderMeta = new S2CRenderMeta(networkId);
this.bindingHelper = bindingHelper;
}

private final NetworkingHelper bindingHelper;

private final S2CRenderMeta renderMeta;

public PrepareMeta setSNbt(String snbt)
{
renderMeta.sNbt = snbt;
return this;
}

public PrepareMeta setOverridedEquip(EntityEquipment equipment)
{
renderMeta.overridedEquipment = MapMetaUtils.toPacketEquipment(equipment);
return this;
}

public PrepareMeta setProfileCompound(String compoundString)
{
renderMeta.profileCompound = compoundString;
return this;
}

public PrepareMeta setDisguiseEquipmentShown(boolean newValue)
{
renderMeta.showOverridedEquipment = newValue;
return this;
}

public PrepareMeta forDisguiseState(DisguiseState state)
{
this.setProfileCompound(state.getProfileNbtString())
.setSNbt(state.getCachedNbtString())
.setDisguiseEquipmentShown(state.showingDisguisedItems())
.setOverridedEquip(state.getDisguisedItems());

return this;
}

public S2CRenderMapMetaCommand build()
{
return new S2CRenderMapMetaCommand(renderMeta);
}

public void send()
{
bindingHelper.sendCommandToAllPlayers(build());
}
}
}
18 changes: 8 additions & 10 deletions src/main/java/xiamomc/morph/network/server/MorphClientHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import xiamomc.morph.messages.MessageUtils;
import xiamomc.morph.messages.MorphStrings;
import xiamomc.morph.misc.DisguiseState;
import xiamomc.morph.misc.NetworkingHelper;
import xiamomc.morph.misc.NmsRecord;
import xiamomc.morph.misc.permissions.CommonPermissions;
import xiamomc.morph.network.*;
Expand All @@ -32,13 +33,10 @@
import xiamomc.morph.network.commands.S2C.S2CCurrentCommand;
import xiamomc.morph.network.commands.S2C.S2CReAuthCommand;
import xiamomc.morph.network.commands.S2C.S2CUnAuthCommand;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMapMetaCommand;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMeta;
import xiamomc.morph.network.commands.S2C.query.QueryType;
import xiamomc.morph.network.commands.S2C.query.S2CQueryCommand;
import xiamomc.morph.network.commands.S2C.set.S2CSetModifyBoundingBoxCommand;
import xiamomc.morph.network.commands.S2C.set.S2CSetSelfViewingCommand;
import xiamomc.morph.utilities.MapMetaUtils;
import xiamomc.pluginbase.Annotations.Initializer;
import xiamomc.pluginbase.Annotations.Resolved;
import xiamomc.pluginbase.Bindables.Bindable;
Expand Down Expand Up @@ -624,7 +622,7 @@ public void onInitialCommand(C2SInitialCommand c2SInitialCommand)
if (player.hasPermission(CommonPermissions.DISGUISE_REVEALING))
sendCommand(player, manager.genMapCommand());

if (manager.isUsingNilServerBackend())
if (manager.isUsingClientRenderer())
sendCommand(player, manager.genRenderSyncCommand());

logger.info("READY!");
Expand All @@ -634,13 +632,10 @@ public void onInitialCommand(C2SInitialCommand c2SInitialCommand)
logger.info("STATE! " + bindingState);
var bindingPlayer = bindingState.getPlayer();

var meta = new S2CRenderMeta(bindingPlayer.getEntityId());
meta.profileCompound = bindingState.getProfileNbtString();
meta.sNbt = bindingState.getCachedNbtString();
meta.showOverridedEquipment = bindingState.showingDisguisedItems();
meta.overridedEquipment = MapMetaUtils.toPacketEquipment(bindingState.getDisguisedItems());
var packet = networkingHelper.prepareMeta(bindingPlayer)
.forDisguiseState(bindingState)
.build();

var packet = new S2CRenderMapMetaCommand(meta);
this.sendCommand(player, packet);
logger.info("SEND! " + packet);
}
Expand Down Expand Up @@ -747,6 +742,9 @@ public void onUnmorphCommand(C2SUnmorphCommand c2SUnmorphCommand)
@Resolved
private IManageRequests requestManager;

@Resolved
private NetworkingHelper networkingHelper;

@Override
public void onRequestCommand(C2SRequestCommand c2SRequestCommand)
{
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/xiamomc/morph/skills/impl/InventoryMorphSkill.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import xiamomc.morph.messages.SkillStrings;
import xiamomc.morph.misc.DisguiseState;
import xiamomc.morph.misc.NetworkingHelper;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMapMetaCommand;
import xiamomc.morph.network.commands.S2C.clientrender.S2CRenderMeta;
import xiamomc.morph.network.commands.S2C.set.S2CSetDisplayingFakeEquipCommand;
import xiamomc.morph.network.server.MorphClientHandler;
import xiamomc.morph.skills.MorphSkill;
Expand Down Expand Up @@ -39,6 +37,14 @@ public int executeSkill(Player player, DisguiseState state, SkillAbilityConfigur
? SkillStrings.displayingDisguiseInventoryString()
: SkillStrings.displayingPlayerInventoryString()));

//发送元数据
if (manager.isUsingClientRenderer())
{
networkingHelper.prepareMeta(state.getPlayer())
.setDisguiseEquipmentShown(defaultShown)
.send();
}

return configuration.getCooldown();
}

Expand All @@ -51,12 +57,11 @@ public void onInitialEquip(DisguiseState state)
clientHandler.sendCommand(state.getPlayer(), new S2CSetDisplayingFakeEquipCommand(state.showingDisguisedItems()));

//发送元数据
if (manager.isUsingNilServerBackend())
if (manager.isUsingClientRenderer())
{
var meta = new S2CRenderMeta(state.getPlayer().getEntityId());
meta.showOverridedEquipment = state.showingDisguisedItems();
var packet = new S2CRenderMapMetaCommand(meta);
networkingHelper.sendCommandToAllPlayers(packet);
networkingHelper.prepareMeta(state.getPlayer())
.setDisguiseEquipmentShown(state.showingDisguisedItems())
.send();
}

super.onInitialEquip(state);
Expand Down

0 comments on commit 21f7181

Please sign in to comment.