Skip to content

Commit

Permalink
fix: 玩家伪装下蹲后不会继续站起
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Dec 13, 2023
1 parent 42040e6 commit 0afc5ce
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void write(int index, Object value)
throw new IllegalArgumentException("Incompatable value for index '%s', excepted for '%s', but got '%s'".formatted(index, single.defaultValue().getClass(), value.getClass()));

registry.put(single, value);
dirtySingles.put(single, value);
}

public <X> X get(SingleValue<X> singleValue)
Expand All @@ -116,9 +117,22 @@ public Map<SingleValue<?>, Object> getRegistry()
return new Object2ObjectOpenHashMap<>(registry);
}

private final Map<SingleValue<?>, Object> dirtySingles = new Object2ObjectOpenHashMap<>();

public Map<SingleValue<?>, Object> getDirty()
{
return new Object2ObjectOpenHashMap<>(dirtySingles);
}

//endregion Value Registry

public void doSync()
public void sync()
{
dirtySingles.clear();
doSync();
}

protected void doSync()
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public AllayWatcher(Player bindingPlayer)
}

@Override
public void doSync()
protected void doSync()
{
write(ValueIndex.ALLAY.DANCING, true);
super.doSync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ArmorStandWatcher(Player bindingPlayer)
}

@Override
public void doSync()
protected void doSync()
{
super.doSync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public EntityWatcher(Player bindingPlayer, EntityType entityType)
}

@Override
public void doSync()
protected void doSync()
{
var player = getBindingPlayer();
var nmsPlayer = NmsRecord.ofPlayer(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public LivingEntityWatcher(Player bindingPlayer, EntityType entityType)
}

@Override
public void doSync()
protected void doSync()
{
var player = getBindingPlayer();
var values = ValueIndex.BASE_LIVING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public PlayerWatcher(Player bindingPlayer)
}

@Override
public void doSync()
protected void doSync()
{
this.write(ValueIndex.PLAYER.SKIN, (byte)getBindingPlayer().getClientOption(ClientOption.SKIN_PARTS).getRaw());
this.write(ValueIndex.PLAYER.MAINHAND, (byte)getBindingPlayer().getMainHand().ordinal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataValue;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.bukkit.entity.Player;
import xiamomc.morph.MorphPluginObject;
import xiamomc.morph.backends.server.renderer.network.RegistryParameters;
import xiamomc.morph.backends.server.renderer.network.datawatcher.values.SingleValue;
import xiamomc.morph.backends.server.renderer.network.datawatcher.watchers.SingleWatcher;
import xiamomc.morph.backends.server.renderer.utilties.ProtocolRegistryUtils;

import java.util.List;
import java.util.UUID;
import java.util.Map;

public abstract class ProtocolListener extends MorphPluginObject
{
Expand All @@ -34,11 +35,18 @@ protected PacketContainer getMetaPackets(Player player, SingleWatcher watcher)

List<WrappedDataValue> wrappedDataValues = new ObjectArrayList<>();

watcher.doSync();
watcher.sync();

Map<SingleValue<?>, Object> valuesToSent = new Object2ObjectOpenHashMap<>();
valuesToSent.putAll(watcher.getDirty());
watcher.getRegistry().forEach((single, v) ->
{
if (single.defaultValue().equals(v)) return;
valuesToSent.put(single, v);
});

valuesToSent.forEach((single, v) ->
{
WrappedDataWatcher.Serializer serializer;

try
Expand Down

0 comments on commit 0afc5ce

Please sign in to comment.