2020-01-14 22:43:50 +01:00
From 1b08c2466b0ea7593464c5d507c01381b8654d1f 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
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
2020-01-14 22:43:50 +01:00
index 189542b91..c2ca16968 100644
2019-05-01 00:51:03 +02:00
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
2019-12-12 01:03:31 +01:00
@@ -98,7 +98,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
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
2019-06-22 20:04:58 +02:00
diff --git a/src/main/java/net/minecraft/server/IBlockData.java b/src/main/java/net/minecraft/server/IBlockData.java
2019-12-19 20:17:36 +01:00
index 3a1ad2346..9ab57be85 100644
2019-06-22 20:04:58 +02:00
--- a/src/main/java/net/minecraft/server/IBlockData.java
+++ b/src/main/java/net/minecraft/server/IBlockData.java
2019-06-25 03:47:58 +02:00
@@ -146,6 +146,7 @@ public class IBlockData extends BlockDataAbstract<Block, IBlockData> implements
return this.c != null ? this.c.g : this.b(iblockaccess, blockposition, VoxelShapeCollision.a());
2019-05-01 00:51:03 +02:00
}
2019-06-22 20:04:58 +02:00
+ 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().b(this, iblockaccess, blockposition, voxelshapecollision);
2019-05-01 00:51:03 +02:00
}
diff --git a/src/main/java/net/minecraft/server/ItemBlock.java b/src/main/java/net/minecraft/server/ItemBlock.java
2019-12-19 20:17:36 +01:00
index ab875a736..aed353365 100644
2019-05-01 00:51:03 +02:00
--- a/src/main/java/net/minecraft/server/ItemBlock.java
+++ b/src/main/java/net/minecraft/server/ItemBlock.java
2019-07-11 18:59:21 +02:00
@@ -136,7 +136,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
2019-12-12 01:03:31 +01:00
- boolean defaultReturn = (!this.T_() || 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
2019-12-12 01:03:31 +01:00
+ boolean defaultReturn = (!this.T_() || 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);
2019-06-22 20:04:58 +02:00
diff --git a/src/main/java/net/minecraft/server/VoxelShape.java b/src/main/java/net/minecraft/server/VoxelShape.java
2019-12-19 20:17:36 +01:00
index 0f64a3c05..0f95bcbcc 100644
2019-06-22 20:04:58 +02:00
--- a/src/main/java/net/minecraft/server/VoxelShape.java
+++ b/src/main/java/net/minecraft/server/VoxelShape.java
@@ -46,6 +46,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/server/VoxelShapes.java b/src/main/java/net/minecraft/server/VoxelShapes.java
2019-12-19 20:17:36 +01:00
index 143be566c..08c83c62d 100644
2019-06-22 20:04:58 +02:00
--- a/src/main/java/net/minecraft/server/VoxelShapes.java
+++ b/src/main/java/net/minecraft/server/VoxelShapes.java
@@ -33,6 +33,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);
@@ -127,6 +128,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)) {
2019-12-12 01:03:31 +01:00
throw (IllegalArgumentException) SystemUtils.c(new IllegalArgumentException());
2019-06-22 20:04:58 +02:00
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2020-01-14 22:43:50 +01:00
index 6742c991f..b6d904007 100644
2019-06-22 20:04:58 +02:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2019-12-12 01:03:31 +01:00
@@ -164,6 +164,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
2019-12-12 01:03:31 +01:00
public boolean p_() {
return this.isClientSide;
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
2020-01-14 22:43:50 +01:00
index f931fa48b..317a5bf4e 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
2020-01-14 22:43:50 +01:00
@@ -1171,6 +1171,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;
}
--
2019-12-16 03:58:10 +01:00
2.24.1
2019-05-01 00:51:03 +02:00