2020-05-06 11:48:49 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2019-05-01 00:51:03 +02:00
From: Hugo Manrique <hugmanrique@gmail.com>
Date: Mon, 23 Jul 2018 14:22:26 +0200
Subject: [PATCH] Vanished players don't have rights
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
2021-03-16 16:50:45 +01:00
index c88eea18e2e219f242c53ffb4e28cfc6d7bf318a..3a46a5001cda7402a97ac8552650cf64e7881fad 100644
2021-03-16 08:19:45 +01:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2021-03-16 14:04:28 +01:00
@@ -184,7 +184,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
2019-05-01 00:51:03 +02:00
private static double e = 1.0D;
private final EntityTypes<?> f;
private int id;
- public boolean i;
+ public boolean i; public final boolean blocksEntitySpawning() { return this.i; } // Paper - OBFHELPER
public final List<Entity> passengers;
protected int j;
2019-12-12 01:03:31 +01:00
@Nullable
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java
2021-03-16 16:50:45 +01:00
index 65cea9282467cb362ac6e9e0bb03c5d36085ee43..65cee640040bdd1229149409ff046b765ee08c34 100644
2021-03-16 08:19:45 +01:00
--- a/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java
2021-03-16 16:50:45 +01:00
@@ -4,6 +4,7 @@ import java.util.Iterator;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.level.WorldServer;
import net.minecraft.util.MathHelper;
import net.minecraft.world.entity.Entity;
@@ -140,8 +141,14 @@ public abstract class IProjectile extends Entity {
2020-06-25 16:09:55 +02:00
protected boolean a(Entity entity) {
if (!entity.isSpectator() && entity.isAlive() && entity.isInteractable()) {
Entity entity1 = this.getShooter();
-
2020-03-18 14:58:50 +01:00
+ // Paper start - Cancel hit for vanished players
2020-06-26 18:20:03 +02:00
+ if (entity1 instanceof EntityPlayer && entity instanceof EntityPlayer) {
2020-06-25 16:09:55 +02:00
+ 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;
2020-03-18 14:58:50 +01:00
+ }
2020-06-25 16:09:55 +02:00
return entity1 == null || this.d || !entity1.isSameVehicle(entity);
2020-03-18 14:58:50 +01:00
+ // Paper end
2020-06-25 16:09:55 +02:00
} else {
return false;
}
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/item/ItemBlock.java b/src/main/java/net/minecraft/world/item/ItemBlock.java
index ec12bea9de910824927ba31628b49f6713f31a29..59d52c252b2e59923b8e513dd4d2e1ec9ce34dc7 100644
--- a/src/main/java/net/minecraft/world/item/ItemBlock.java
+++ b/src/main/java/net/minecraft/world/item/ItemBlock.java
@@ -177,7 +177,8 @@ public class ItemBlock extends Item {
2019-05-01 00:51:03 +02:00
EntityHuman entityhuman = blockactioncontext.getEntity();
VoxelShapeCollision voxelshapecollision = entityhuman == null ? VoxelShapeCollision.a() : VoxelShapeCollision.a((Entity) entityhuman);
// CraftBukkit start - store default return
2020-06-25 16:09:55 +02:00
- boolean defaultReturn = (!this.isCheckCollisions() || iblockdata.canPlace(blockactioncontext.getWorld(), blockactioncontext.getClickPosition())) && blockactioncontext.getWorld().a(iblockdata, blockactioncontext.getClickPosition(), voxelshapecollision);
2019-06-22 20:04:58 +02:00
+ World world = blockactioncontext.getWorld(); // Paper
2020-06-25 16:09:55 +02:00
+ boolean defaultReturn = (!this.isCheckCollisions() || iblockdata.canPlace(blockactioncontext.getWorld(), blockactioncontext.getClickPosition())) && world.checkEntityCollision(iblockdata, entityhuman, voxelshapecollision, blockactioncontext.getClickPosition(), true); // Paper
2019-05-01 00:51:03 +02:00
org.bukkit.entity.Player player = (blockactioncontext.getEntity() instanceof EntityPlayer) ? (org.bukkit.entity.Player) blockactioncontext.getEntity().getBukkitEntity() : null;
BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(blockactioncontext.getWorld(), blockactioncontext.getClickPosition()), player, CraftBlockData.fromData(iblockdata), defaultReturn);
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/level/World.java b/src/main/java/net/minecraft/world/level/World.java
2021-03-16 14:04:28 +01:00
index 8c7263f9dbb00cf6484e7f70b8d97639bab0cefc..07c5cdd00930a55fd412ef95f71f55ee908189a1 100644
2021-03-16 08:19:45 +01:00
--- a/src/main/java/net/minecraft/world/level/World.java
+++ b/src/main/java/net/minecraft/world/level/World.java
2021-03-16 14:04:28 +01:00
@@ -27,6 +27,7 @@ import net.minecraft.network.protocol.Packet;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.level.PlayerChunk;
import net.minecraft.sounds.SoundCategory;
import net.minecraft.sounds.SoundEffect;
@@ -65,6 +66,10 @@ import net.minecraft.world.level.saveddata.maps.WorldMap;
import net.minecraft.world.level.storage.WorldData;
import net.minecraft.world.level.storage.WorldDataMutable;
import net.minecraft.world.phys.AxisAlignedBB;
+import net.minecraft.world.phys.shapes.OperatorBoolean;
+import net.minecraft.world.phys.shapes.VoxelShape;
+import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+import net.minecraft.world.phys.shapes.VoxelShapes;
import net.minecraft.world.scores.Scoreboard;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -232,6 +237,46 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-06-22 20:04:58 +02:00
this.tileLimiter = new org.spigotmc.TickLimiter(spigotConfig.tileMaxTickTime);
}
+ // Paper start
+ // ret true if no collision
+ public final boolean checkEntityCollision(IBlockData data, Entity source, VoxelShapeCollision voxelshapedcollision,
2019-12-12 01:03:31 +01:00
+ BlockPosition position, boolean checkCanSee) {
2019-06-22 20:04:58 +02:00
+ // 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.offset((double) position.getX(), (double) position.getY(), (double) position.getZ());
+ if (voxelshape.isEmpty()) {
+ return true;
+ }
+
+ List<Entity> entities = this.getEntities(null, voxelshape.getBoundingBox());
+ for (int i = 0, len = entities.size(); i < len; ++i) {
+ Entity entity = entities.get(i);
+
+ if (checkCanSee && source instanceof EntityPlayer && entity instanceof EntityPlayer
2019-12-12 01:03:31 +01:00
+ && !((EntityPlayer) source).getBukkitEntity().canSee(((EntityPlayer) entity).getBukkitEntity())) {
2019-06-22 20:04:58 +02:00
+ 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.dead || !entity.blocksEntitySpawning()) {
+ continue;
+ }
+
+ if (VoxelShapes.applyOperation(voxelshape, VoxelShapes.of(entity.getBoundingBox()), OperatorBoolean.AND)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ // Paper end
+
@Override
2020-06-25 16:09:55 +02:00
public boolean s_() {
2019-12-12 01:03:31 +01:00
return this.isClientSide;
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBase.java b/src/main/java/net/minecraft/world/level/block/state/BlockBase.java
2021-04-07 07:17:32 +02:00
index 2902117fd2803741b053a04fda7f4414fb8593cb..10f4015b8c36e4e27cf7d0745ba70b8a9e60aff3 100644
2021-03-16 08:19:45 +01:00
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBase.java
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBase.java
2021-04-07 07:17:32 +02:00
@@ -505,6 +505,7 @@ public abstract class BlockBase {
2021-03-16 08:19:45 +01:00
return this.a != null ? this.a.b : this.b(iblockaccess, blockposition, VoxelShapeCollision.a());
}
+ public final VoxelShape getCollisionShape(IBlockAccess iblockaccess, BlockPosition blockposition, VoxelShapeCollision voxelshapecollision) { return this.b(iblockaccess, blockposition, voxelshapecollision); } // Paper - OBFHELPER
public VoxelShape b(IBlockAccess iblockaccess, BlockPosition blockposition, VoxelShapeCollision voxelshapecollision) {
return this.getBlock().c(this.p(), iblockaccess, blockposition, voxelshapecollision);
}
diff --git a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java b/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
index 1b82349b96b3ec9490d06d1c1d1cbf2b1578d313..887016224c16f8a38c10a98eb0e2ae6cb353a153 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
+++ b/src/main/java/net/minecraft/world/phys/shapes/VoxelShape.java
@@ -54,6 +54,7 @@ public abstract class VoxelShape {
return this.a.a();
}
+ public final VoxelShape offset(double x, double y, double z) { return this.a(x, y, z); } // Paper - OBFHELPER
public VoxelShape a(double d0, double d1, double d2) {
return (VoxelShape) (this.isEmpty() ? VoxelShapes.a() : new VoxelShapeArray(this.a, new DoubleListOffset(this.a(EnumDirection.EnumAxis.X), d0), new DoubleListOffset(this.a(EnumDirection.EnumAxis.Y), d1), new DoubleListOffset(this.a(EnumDirection.EnumAxis.Z), d2)));
}
diff --git a/src/main/java/net/minecraft/world/phys/shapes/VoxelShapes.java b/src/main/java/net/minecraft/world/phys/shapes/VoxelShapes.java
index fdd9e37a8c90fc3311e515355af0a0593efbdacc..cf32a4f63e8e59535c02a3f9c57f98833a2b0e83 100644
--- a/src/main/java/net/minecraft/world/phys/shapes/VoxelShapes.java
+++ b/src/main/java/net/minecraft/world/phys/shapes/VoxelShapes.java
@@ -45,6 +45,7 @@ public final class VoxelShapes {
return a(new AxisAlignedBB(d0, d1, d2, d3, d4, d5));
}
+ public static final VoxelShape of(AxisAlignedBB axisAlignedbb) { return VoxelShapes.a(axisAlignedbb); } // Paper - OBFHELPER
public static VoxelShape a(AxisAlignedBB axisalignedbb) {
int i = a(axisalignedbb.minX, axisalignedbb.maxX);
int j = a(axisalignedbb.minY, axisalignedbb.maxY);
@@ -139,6 +140,7 @@ public final class VoxelShapes {
}
}
+ public static final boolean applyOperation(VoxelShape voxelshape, VoxelShape voxelshape1, OperatorBoolean operatorboolean) { return VoxelShapes.c(voxelshape, voxelshape1, operatorboolean); } // Paper - OBFHELPER
public static boolean c(VoxelShape voxelshape, VoxelShape voxelshape1, OperatorBoolean operatorboolean) {
if (operatorboolean.apply(false, false)) {
throw (IllegalArgumentException) SystemUtils.c((Throwable) (new IllegalArgumentException()));
2019-05-01 00:51:03 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2021-04-07 07:17:32 +02:00
index db8dc8e5dda304a3ccd81dc0c781476d5946a1ba..334ac1cb253cf3d063c7a26db698c596b425b057 100644
2019-05-01 00:51:03 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2021-03-03 23:43:45 +01:00
@@ -1202,6 +1202,14 @@ public class CraftEventFactory {
2019-05-01 00:51:03 +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;
}