Skip to content

Commit

Permalink
Prevent interactions with vanished players
Browse files Browse the repository at this point in the history
resolves #50
  • Loading branch information
DrexHD committed Sep 18, 2024
1 parent 23f03de commit dc93f24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Containers remaining open by vanished players in certain conditions
- Pressure plates remaining pressed by vanished players in certain conditions
- Vanished players blocking merchant (villager / wandering trader) trading
- Players can attack vanished players

## [1.5.6] - 2024-06-20
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -39,6 +41,21 @@ public void vanish_hideLeaveMessage(PlayerList playerList, Component component,
}
}

@WrapOperation(
method = "handleInteract",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/protocol/game/ServerboundInteractPacket;getTarget(Lnet/minecraft/server/level/ServerLevel;)Lnet/minecraft/world/entity/Entity;"
)
)
public Entity vanish_preventInteraction(ServerboundInteractPacket instance, ServerLevel serverLevel, Operation<Entity> original) {
Entity entity = original.call(instance, serverLevel);
if (entity instanceof ServerPlayer actor && !VanishAPI.canSeePlayer(actor, this.player)) {
return null;
}
return entity;
}

@Inject(
method = "handlePlayerAction",
at = @At(
Expand Down

0 comments on commit dc93f24

Please sign in to comment.