2021-06-12 23:31:35 +02:00
|
|
|
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
|
2023-02-13 18:52:27 +01:00
|
|
|
index 95ee8f85dd7e6c32f751f5c754a351cc7bcd6245..ec5fc3293097b364b5f6d8acc756aa8adde15215 100644
|
2021-06-12 23:31:35 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
2022-12-07 19:52:24 +01:00
|
|
|
@@ -212,7 +212,14 @@ public abstract class Projectile extends Entity {
|
2021-06-12 23:31:35 +02:00
|
|
|
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
|
2022-12-07 19:52:24 +01:00
|
|
|
index a6638e626600e4304a973497a39e3fac52203b16..e68b7a1b03783e4f9de24c5ae8773fc359bd2d37 100644
|
2021-06-12 23:31:35 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/item/BlockItem.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/item/BlockItem.java
|
2022-12-07 19:52:24 +01:00
|
|
|
@@ -197,7 +197,8 @@ public class BlockItem extends Item {
|
2021-06-12 23:31:35 +02:00
|
|
|
Player entityhuman = context.getPlayer();
|
2021-11-23 16:04:41 +01:00
|
|
|
CollisionContext voxelshapecollision = entityhuman == null ? CollisionContext.empty() : CollisionContext.of(entityhuman);
|
2021-06-12 23:31:35 +02:00
|
|
|
// 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
|
2023-03-04 20:01:07 +01:00
|
|
|
index bb5d49a1b002fbe9109b2fe6c31c9d4f7c3f9ac8..df273fd4ffbaf8d25286e9ba713999ccab31af90 100644
|
2021-06-12 23:31:35 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
2022-12-07 19:52:24 +01:00
|
|
|
@@ -268,6 +268,45 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
2021-06-12 23:31:35 +02:00
|
|
|
this.tileLimiter = new org.spigotmc.TickLimiter(spigotConfig.tileMaxTickTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ // ret true if no collision
|
2022-12-07 19:52:24 +01:00
|
|
|
+ public final boolean checkEntityCollision(BlockState data, Entity source, net.minecraft.world.phys.shapes.CollisionContext voxelshapedcollision,
|
2021-06-12 23:31:35 +02:00
|
|
|
+ BlockPos position, boolean checkCanSee) {
|
|
|
|
+ // Copied from IWorldReader#a(IBlockData, BlockPosition, VoxelShapeCollision) & EntityAccess#a(Entity, VoxelShape)
|
2022-12-07 19:52:24 +01:00
|
|
|
+ net.minecraft.world.phys.shapes.VoxelShape voxelshape = data.getCollisionShape(this, position, voxelshapedcollision);
|
2021-06-12 23:31:35 +02:00
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
2022-12-07 19:52:24 +01:00
|
|
|
+ if (net.minecraft.world.phys.shapes.Shapes.joinIsNotEmpty(voxelshape, net.minecraft.world.phys.shapes.Shapes.create(entity.getBoundingBox()), net.minecraft.world.phys.shapes.BooleanOp.AND)) {
|
2021-06-12 23:31:35 +02:00
|
|
|
+ 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
|
2022-12-23 06:20:44 +01:00
|
|
|
index fab613b7c4ee48c3f0eac1405bca7bd53da19060..67d820fb9aa00a3275cc3e23461864b496d738aa 100644
|
2021-06-12 23:31:35 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
2022-12-23 06:20:44 +01:00
|
|
|
@@ -1267,6 +1267,14 @@ public class CraftEventFactory {
|
2021-06-12 23:31:35 +02:00
|
|
|
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;
|
|
|
|
}
|