Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-24 15:20:11 +01:00
120 Zeilen
6.9 KiB
Diff
120 Zeilen
6.9 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: Hugo Manrique <hugmanrique@gmail.com>
|
||
|
Date: Mon, 23 Jul 2018 14:22:26 +0200
|
||
|
Subject: [PATCH] Vanished players don't have rights
|
||
|
|
||
|
|
||
|
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
||
|
index c25cb17ef1a7c56e10ce3ccb5665c9dce3e6efa6..30118ff975da9491fa41db2133d217c2a797a8e3 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
||
|
@@ -209,7 +209,14 @@ public abstract class Projectile extends Entity {
|
||
|
if (!entity.isSpectator() && entity.isAlive() && entity.isPickable()) {
|
||
|
Entity entity1 = this.getOwner();
|
||
|
|
||
|
+ // Paper start - Cancel hit for vanished players
|
||
|
+ if (entity1 instanceof net.minecraft.server.level.ServerPlayer && entity instanceof net.minecraft.server.level.ServerPlayer) {
|
||
|
+ org.bukkit.entity.Player collided = (org.bukkit.entity.Player) entity.getBukkitEntity();
|
||
|
+ org.bukkit.entity.Player shooter = (org.bukkit.entity.Player) entity1.getBukkitEntity();
|
||
|
+ if (!shooter.canSee(collided)) return false;
|
||
|
+ }
|
||
|
return entity1 == null || this.leftOwner || !entity1.isPassengerOfSameVehicle(entity);
|
||
|
+ // Paper end
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java
|
||
|
index 86d245c9a817be5fd2be7f331d3a3a5f3169e8c2..44b28773fe8e79931e738d493bd9405e0ee3dca9 100644
|
||
|
--- a/src/main/java/net/minecraft/world/item/BlockItem.java
|
||
|
+++ b/src/main/java/net/minecraft/world/item/BlockItem.java
|
||
|
@@ -191,7 +191,8 @@ public class BlockItem extends Item {
|
||
|
Player entityhuman = context.getPlayer();
|
||
|
CollisionContext voxelshapecollision = entityhuman == null ? CollisionContext.empty() : CollisionContext.of((Entity) entityhuman);
|
||
|
// CraftBukkit start - store default return
|
||
|
- boolean defaultReturn = (!this.mustSurvive() || state.canSurvive(context.getLevel(), context.getClickedPos())) && context.getLevel().isUnobstructed(state, context.getClickedPos(), voxelshapecollision);
|
||
|
+ Level world = context.getLevel(); // Paper
|
||
|
+ boolean defaultReturn = (!this.mustSurvive() || state.canSurvive(context.getLevel(), context.getClickedPos())) && world.checkEntityCollision(state, entityhuman, voxelshapecollision, context.getClickedPos(), true); // Paper
|
||
|
org.bukkit.entity.Player player = (context.getPlayer() instanceof ServerPlayer) ? (org.bukkit.entity.Player) context.getPlayer().getBukkitEntity() : null;
|
||
|
|
||
|
BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(context.getLevel(), context.getClickedPos()), player, CraftBlockData.fromData(state), defaultReturn);
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
||
|
index 2c86a5ae8bbf7d80e7ce8cd08319ed6a17b86dbb..c1cf7f5bff2878281d4a9787ea7160e984268352 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
||
|
@@ -71,6 +71,10 @@ import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
||
|
import net.minecraft.world.level.storage.LevelData;
|
||
|
import net.minecraft.world.level.storage.WritableLevelData;
|
||
|
import net.minecraft.world.phys.AABB;
|
||
|
+import net.minecraft.world.phys.shapes.BooleanOp;
|
||
|
+import net.minecraft.world.phys.shapes.CollisionContext;
|
||
|
+import net.minecraft.world.phys.shapes.Shapes;
|
||
|
+import net.minecraft.world.phys.shapes.VoxelShape;
|
||
|
import net.minecraft.world.scores.Scoreboard;
|
||
|
import org.apache.logging.log4j.LogManager;
|
||
|
import org.apache.logging.log4j.Logger;
|
||
|
@@ -248,6 +252,45 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
||
|
this.tileLimiter = new org.spigotmc.TickLimiter(spigotConfig.tileMaxTickTime);
|
||
|
}
|
||
|
|
||
|
+ // Paper start
|
||
|
+ // ret true if no collision
|
||
|
+ public final boolean checkEntityCollision(BlockState data, Entity source, CollisionContext voxelshapedcollision,
|
||
|
+ BlockPos position, boolean checkCanSee) {
|
||
|
+ // Copied from IWorldReader#a(IBlockData, BlockPosition, VoxelShapeCollision) & EntityAccess#a(Entity, VoxelShape)
|
||
|
+ VoxelShape voxelshape = data.getCollisionShape(this, position, voxelshapedcollision);
|
||
|
+ if (voxelshape.isEmpty()) {
|
||
|
+ return true;
|
||
|
+ }
|
||
|
+
|
||
|
+ voxelshape = voxelshape.move((double) position.getX(), (double) position.getY(), (double) position.getZ());
|
||
|
+ if (voxelshape.isEmpty()) {
|
||
|
+ return true;
|
||
|
+ }
|
||
|
+
|
||
|
+ List<Entity> entities = this.getEntities(null, voxelshape.bounds());
|
||
|
+ for (int i = 0, len = entities.size(); i < len; ++i) {
|
||
|
+ Entity entity = entities.get(i);
|
||
|
+
|
||
|
+ if (checkCanSee && source instanceof net.minecraft.server.level.ServerPlayer && entity instanceof net.minecraft.server.level.ServerPlayer
|
||
|
+ && !((net.minecraft.server.level.ServerPlayer) source).getBukkitEntity().canSee(((net.minecraft.server.level.ServerPlayer) entity).getBukkitEntity())) {
|
||
|
+ continue;
|
||
|
+ }
|
||
|
+
|
||
|
+ // !entity1.dead && entity1.i && (entity == null || !entity1.x(entity));
|
||
|
+ // elide the last check since vanilla calls with entity = null
|
||
|
+ // only we care about the source for the canSee check
|
||
|
+ if (entity.isRemoved() || !entity.blocksBuilding) {
|
||
|
+ continue;
|
||
|
+ }
|
||
|
+
|
||
|
+ if (Shapes.joinIsNotEmpty(voxelshape, Shapes.create(entity.getBoundingBox()), BooleanOp.AND)) {
|
||
|
+ return false;
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
+ return true;
|
||
|
+ }
|
||
|
+ // Paper end
|
||
|
@Override
|
||
|
public boolean isClientSide() {
|
||
|
return this.isClientSide;
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||
|
index 375e9e45331d5be237c67f11af94c6998409418b..966d06e2da7e6f9b4e78ca8ed02f3a6472bc8c05 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||
|
@@ -1190,6 +1190,14 @@ public class CraftEventFactory {
|
||
|
Projectile projectile = (Projectile) entity.getBukkitEntity();
|
||
|
org.bukkit.entity.Entity collided = position.getEntity().getBukkitEntity();
|
||
|
com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = new com.destroystokyo.paper.event.entity.ProjectileCollideEvent(projectile, collided);
|
||
|
+
|
||
|
+ if (projectile.getShooter() instanceof Player && collided instanceof Player) {
|
||
|
+ if (!((Player) projectile.getShooter()).canSee((Player) collided)) {
|
||
|
+ event.setCancelled(true);
|
||
|
+ return event;
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
Bukkit.getPluginManager().callEvent(event);
|
||
|
return event;
|
||
|
}
|