Skip to content

Commit

Permalink
Fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
cavallium committed Jul 13, 2021
1 parent 3c51259 commit 0e08326
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.warp</groupId>
<artifactId>CoordinatesObfuscator</artifactId>
<version>1.4.1</version>
<version>1.4.2</version>
<name>CoordinatesObfuscator</name>
<build>
<resources>
Expand Down Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.7.0-SNAPSHOT</version>
<version>4.7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void onDisable() {
}


@SuppressWarnings("CommentedOutCode")
@Override
public void onEnable() {
this.logger = getLogger();
Expand Down Expand Up @@ -97,22 +98,35 @@ public void onEnable() {
packets.add(PacketType.Play.Server.WINDOW_DATA);
packets.add(PacketType.Play.Server.SET_SLOT);

packets.add(Server.TILE_ENTITY_DATA);

//todo: these packets shouldn't have position. Check if some of them must be translated
// packets.add(Server.ENTITY_DESTROY);
// packets.add(Server.ENTITY_EQUIPMENT);
// packets.add(Server.ENTITY_LOOK);
// packets.add(Server.ENTITY_EFFECT);
// packets.add(Server.ENTITY_HEAD_ROTATION);
// packets.add(Server.ENTITY_SOUND);
// packets.add(Server.ENTITY_STATUS);
// packets.add(Server.ENTITY_VELOCITY);
// packets.add(Server.REL_ENTITY_MOVE);
// packets.add(Server.REL_ENTITY_MOVE_LOOK);
// packets.add(Server.ATTACH_ENTITY);

paramsServer.types(packets);

pm.addPacketListener(new PacketAdapter(paramsServer) {
@SuppressWarnings("DuplicateBranchesInSwitch")
@Override
public void onPacketSending(final PacketEvent event) {

PacketContainer packet;

packet = event.getPacket().shallowClone();
switch (packet.getType().name()) {
case "TILE_ENTITY_DATA":
cloneTileEntityData(packet);
break;
case "MAP_CHUNK":
cloneMapChunkEntitiesData(packet);
break;
switch (event.getPacket().getType().name()) {
case "LIGHT_UPDATE" -> packet = event.getPacket().shallowClone();
case "TILE_ENTITY_DATA" -> packet = cloneTileEntityData(event.getPacket());
case "MAP_CHUNK" -> packet = cloneMapChunkEntitiesData(event.getPacket());
default -> packet = event.getPacket().shallowClone();
}

Player player = event.getPlayer();
Expand Down Expand Up @@ -187,7 +201,8 @@ public void onPlayerJoin(final PlayerJoinEvent event) {
}


private PacketContainer cloneTileEntityData(final PacketContainer packet) {
private PacketContainer cloneTileEntityData(PacketContainer packet) {
packet = packet.shallowClone();
int i = 0;
for (final NbtBase<?> obj : packet.getNbtModifier().getValues()) {
packet.getNbtModifier().write(i, obj.deepClone());
Expand All @@ -198,6 +213,7 @@ private PacketContainer cloneTileEntityData(final PacketContainer packet) {
}

private PacketContainer cloneMapChunkEntitiesData(PacketContainer packet) {
packet = packet.shallowClone();
int i = 0;
for (final List<NbtBase<?>> obj : packet.getListNbtModifier().getValues()) {
ArrayList<NbtBase<?>> newList = new ArrayList<NbtBase<?>>(obj.size());
Expand Down

0 comments on commit 0e08326

Please sign in to comment.