-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
192 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ava/xiamomc/morph/backends/server/renderer/network/listeners/EquipmentPacketListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package xiamomc.morph.backends.server.renderer.network.listeners; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.events.ListeningWhitelist; | ||
import com.comphenix.protocol.events.PacketEvent; | ||
import com.comphenix.protocol.injector.GamePhase; | ||
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; | ||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; | ||
import org.bukkit.entity.Player; | ||
import xiamomc.morph.MorphPlugin; | ||
import xiamomc.morph.backends.server.renderer.network.PacketFactory; | ||
import xiamomc.morph.backends.server.renderer.network.registries.EntryIndex; | ||
import xiamomc.morph.backends.server.renderer.network.registries.RenderRegistry; | ||
import xiamomc.morph.utilities.NmsUtils; | ||
import xiamomc.pluginbase.Annotations.Resolved; | ||
|
||
public class EquipmentPacketListener extends ProtocolListener | ||
{ | ||
@Resolved(shouldSolveImmediately = true) | ||
private RenderRegistry registry; | ||
|
||
@Override | ||
public void onPacketSending(PacketEvent event) | ||
{ | ||
if (event.getPacketType() != PacketType.Play.Server.ENTITY_EQUIPMENT) | ||
return; | ||
|
||
var packet = event.getPacket(); | ||
|
||
//不要处理来自我们自己的包 | ||
if (packet.getMeta(PacketFactory.MORPH_PACKET_METAKEY).isPresent()) | ||
return; | ||
|
||
onEquipmentPacket((ClientboundSetEquipmentPacket) event.getPacket().getHandle(), event); | ||
} | ||
|
||
private void onEquipmentPacket(ClientboundSetEquipmentPacket packet, PacketEvent event) | ||
{ | ||
if (event.getPacket().getMeta(PacketFactory.MORPH_PACKET_METAKEY).isPresent()) | ||
return; | ||
|
||
//获取此包的来源实体 | ||
var sourceNmsEntity = NmsUtils.getNmsLevel(event.getPlayer().getWorld()).getEntity(packet.getEntity()); | ||
if (!(sourceNmsEntity.getBukkitEntity() instanceof Player sourcePlayer)) return; | ||
|
||
var watcher = registry.getWatcher(sourcePlayer.getUniqueId()); | ||
|
||
if (watcher == null) | ||
return; | ||
|
||
if (!watcher.getOrDefault(EntryIndex.DISPLAY_FAKE_EQUIPMENT, false)) | ||
return; | ||
|
||
event.setPacket(getFactory().getEquipmentPacket(sourcePlayer, watcher)); | ||
} | ||
|
||
@Override | ||
public void onPacketReceiving(PacketEvent event) | ||
{ | ||
} | ||
|
||
@Override | ||
public ListeningWhitelist getSendingWhitelist() | ||
{ | ||
return ListeningWhitelist | ||
.newBuilder() | ||
.types(PacketType.Play.Server.ENTITY_EQUIPMENT) | ||
.gamePhase(GamePhase.PLAYING) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public ListeningWhitelist getReceivingWhitelist() | ||
{ | ||
return ListeningWhitelist.EMPTY_WHITELIST; | ||
} | ||
|
||
@Override | ||
public org.bukkit.plugin.Plugin getPlugin() | ||
{ | ||
return MorphPlugin.getInstance(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.