port 4 patches

This commit is contained in:
kickash32 2020-06-27 14:35:52 -04:00
parent 52f8503639
commit 501c1c7800
4 changed files with 364 additions and 0 deletions

View File

@ -0,0 +1,93 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: kickash32 <kickash32@gmail.com>
Date: Sat, 27 Jun 2020 12:37:58 -0400
Subject: [PATCH] Limit lightning strike effect distance
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 0f4fca90fd6c3788a5762c96c344899cb1665466..4a59d42b778e681e93f1243ecd16c5cf46160b97 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -1,11 +1,5 @@
package com.destroystokyo.paper;
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray.EngineMode;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@@ -13,6 +7,12 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.spigotmc.SpigotWorldConfig;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import static com.destroystokyo.paper.PaperConfig.log;
import static com.destroystokyo.paper.PaperConfig.logError;
@@ -648,4 +648,26 @@ public class PaperWorldConfig {
delayChunkUnloadsBy *= 20;
}
}
+
+ public double sqrMaxThunderDistance;
+ public double sqrMaxLightningImpactSoundDistance;
+ public double maxLightningFlashDistance;
+ private void lightningStrikeDistanceLimit() {
+ sqrMaxThunderDistance = getInt("lightning-strike-distance-limit.sound", -1);
+ if (sqrMaxThunderDistance > 0) {
+ sqrMaxThunderDistance *= sqrMaxThunderDistance;
+ }
+
+ sqrMaxLightningImpactSoundDistance = getInt("lightning-strike-distance-limit.impact-sound", -1);
+ if (sqrMaxLightningImpactSoundDistance < 0) {
+ sqrMaxLightningImpactSoundDistance = 32 * 32; //Vanilla value
+ } else {
+ sqrMaxLightningImpactSoundDistance *= sqrMaxLightningImpactSoundDistance;
+ }
+
+ maxLightningFlashDistance = getInt("lightning-strike-distance-limit.flash", -1);
+ if (maxLightningFlashDistance < 0) {
+ maxLightningFlashDistance = 512; // Vanilla value
+ }
+ }
}
diff --git a/src/main/java/net/minecraft/server/EntityLightning.java b/src/main/java/net/minecraft/server/EntityLightning.java
index 6f979e5f1f1567b140e9689298aff85de34f7413..ebcb9f48f47d1ab1e972bed1bc7cb0ee305a29f2 100644
--- a/src/main/java/net/minecraft/server/EntityLightning.java
+++ b/src/main/java/net/minecraft/server/EntityLightning.java
@@ -56,6 +56,17 @@ public class EntityLightning extends Entity {
double deltaX = this.locX() - player.locX();
double deltaZ = this.locZ() - player.locZ();
double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+ // Paper start - Limit lightning strike effect distance
+ if (distanceSquared <= this.world.paperConfig.sqrMaxLightningImpactSoundDistance) {
+ player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT,
+ SoundCategory.WEATHER, this.locX(), this.locY(), this.locZ(), 2.0f, 0.5F + this.random.nextFloat() * 0.2F));
+ }
+
+ if (world.paperConfig.sqrMaxThunderDistance != -1 && distanceSquared >= world.paperConfig.sqrMaxThunderDistance) {
+ continue;
+ }
+
+ // Paper end
if (distanceSquared > viewDistance * viewDistance) {
double deltaLength = Math.sqrt(distanceSquared);
double relativeX = player.locX() + (deltaX / deltaLength) * viewDistance;
@@ -66,7 +77,7 @@ public class EntityLightning extends Entity {
}
}
// CraftBukkit end
- this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, SoundCategory.WEATHER, 2.0F, 0.5F + this.random.nextFloat() * 0.2F);
+// this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, SoundCategory.WEATHER, 2.0F, 0.5F + this.random.nextFloat() * 0.2F); // Paper
}
--this.lifeTicks;

View File

@ -0,0 +1,79 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: kickash32 <kickash32@gmail.com>
Date: Sat, 27 Jun 2020 13:15:53 -0400
Subject: [PATCH] Add permission for command blocks
diff --git a/src/main/java/net/minecraft/server/BlockCommand.java b/src/main/java/net/minecraft/server/BlockCommand.java
index dd7066d1a72f5c6f54c1f40a7b694deb827410dc..6b353a99c04e0312f520f8559c05ddaf51c26aaf 100644
--- a/src/main/java/net/minecraft/server/BlockCommand.java
+++ b/src/main/java/net/minecraft/server/BlockCommand.java
@@ -105,7 +105,7 @@ public class BlockCommand extends BlockTileEntity {
public EnumInteractionResult interact(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) {
TileEntity tileentity = world.getTileEntity(blockposition);
- if (tileentity instanceof TileEntityCommand && entityhuman.isCreativeAndOp()) {
+ if (tileentity instanceof TileEntityCommand && (entityhuman.isCreativeAndOp() || (entityhuman.isCreative() && entityhuman.getBukkitEntity().hasPermission("minecraft.commandblock")))) { // Paper - command block permission
entityhuman.a((TileEntityCommand) tileentity);
return EnumInteractionResult.a(world.isClientSide);
} else {
diff --git a/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
index 7e13b1cf6d92c3e0f2dab1ba1d42bd4f250e256c..3820acd65f3cd488dba964e6d9c458852570f4a0 100644
--- a/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
+++ b/src/main/java/net/minecraft/server/CommandBlockListenerAbstract.java
@@ -179,7 +179,7 @@ public abstract class CommandBlockListenerAbstract implements ICommandListener {
}
public EnumInteractionResult a(EntityHuman entityhuman) {
- if (!entityhuman.isCreativeAndOp()) {
+ if (!entityhuman.isCreativeAndOp() && !entityhuman.isCreative() && !entityhuman.getBukkitEntity().hasPermission("minecraft.commandblock")) { // Paper - command block permission
return EnumInteractionResult.PASS;
} else {
if (entityhuman.getWorld().isClientSide) {
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index eeb870107031b38e25b5fb85ea731a7db1d6c2d1..103bda41422f0db700b150116c1417736823e763 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -613,7 +613,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
PlayerConnectionUtils.ensureMainThread(packetplayinsetcommandblock, this, this.player.getWorldServer());
if (!this.minecraftServer.getEnableCommandBlock()) {
this.player.sendMessage(new ChatMessage("advMode.notEnabled"), SystemUtils.b);
- } else if (!this.player.isCreativeAndOp()) {
+ } else if (!this.player.isCreativeAndOp() && !this.player.isCreative() && !this.player.getBukkitEntity().hasPermission("minecraft.commandblock")) { // Paper - command block permission
this.player.sendMessage(new ChatMessage("advMode.notAllowed"), SystemUtils.b);
} else {
CommandBlockListenerAbstract commandblocklistenerabstract = null;
@@ -676,7 +676,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
PlayerConnectionUtils.ensureMainThread(packetplayinsetcommandminecart, this, this.player.getWorldServer());
if (!this.minecraftServer.getEnableCommandBlock()) {
this.player.sendMessage(new ChatMessage("advMode.notEnabled"), SystemUtils.b);
- } else if (!this.player.isCreativeAndOp()) {
+ } else if (!this.player.isCreativeAndOp() && !this.player.isCreative() && !this.player.getBukkitEntity().hasPermission("minecraft.commandblock")) { // Paper - command block permission
this.player.sendMessage(new ChatMessage("advMode.notAllowed"), SystemUtils.b);
} else {
CommandBlockListenerAbstract commandblocklistenerabstract = packetplayinsetcommandminecart.a(this.player.world);
diff --git a/src/main/java/net/minecraft/server/PlayerInteractManager.java b/src/main/java/net/minecraft/server/PlayerInteractManager.java
index 734855c1db3215d90b2743988f64af68aacb388e..6d192b27440ddfd34555005dafefbce6bbb67236 100644
--- a/src/main/java/net/minecraft/server/PlayerInteractManager.java
+++ b/src/main/java/net/minecraft/server/PlayerInteractManager.java
@@ -353,7 +353,7 @@ public class PlayerInteractManager {
TileEntity tileentity = this.world.getTileEntity(blockposition);
Block block = iblockdata.getBlock();
- if ((block instanceof BlockCommand || block instanceof BlockStructure || block instanceof BlockJigsaw) && !this.player.isCreativeAndOp()) {
+ if ((block instanceof BlockCommand || block instanceof BlockStructure || block instanceof BlockJigsaw) && !this.player.isCreativeAndOp() && !(block instanceof BlockCommand && (this.player.isCreative() && this.player.getBukkitEntity().hasPermission("minecraft.commandblock")))) { // Paper - command block permission
this.world.notify(blockposition, iblockdata, iblockdata, 3);
return false;
} else if (this.player.a((World) this.world, blockposition, this.gamemode)) {
diff --git a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
index 525ebf961e5da0687183a5e2ead23ed92cbd9d79..a4a809f302c5ff9c76cde5fc0add2ceec1bdf9b5 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/permissions/CraftDefaultPermissions.java
@@ -16,6 +16,7 @@ public final class CraftDefaultPermissions {
DefaultPermissions.registerPermission(ROOT + ".nbt.copy", "Gives the user the ability to copy NBT in creative", org.bukkit.permissions.PermissionDefault.TRUE, parent);
DefaultPermissions.registerPermission(ROOT + ".debugstick", "Gives the user the ability to use the debug stick in creative", org.bukkit.permissions.PermissionDefault.OP, parent);
DefaultPermissions.registerPermission(ROOT + ".debugstick.always", "Gives the user the ability to use the debug stick in all game modes", org.bukkit.permissions.PermissionDefault.FALSE, parent);
+ DefaultPermissions.registerPermission(ROOT + ".commandblock", "Gives the user the ability to use command blocks.", org.bukkit.permissions.PermissionDefault.OP, parent); // Paper
// Spigot end
parent.recalculatePermissibles();
}

View File

@ -0,0 +1,129 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: kickash32 <kickash32@gmail.com>
Date: Sat, 27 Jun 2020 13:32:39 -0400
Subject: [PATCH] Ensure Entity AABB's are never invalid
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index b11383b35662b1e59b89e916e55340cee2726944..2aa40f2a41e21526eb86acd903de024665109ab6 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1,53 +1,54 @@
package net.minecraft.server;
+import co.aikar.timings.MinecraftTimings;
+import co.aikar.timings.Timing;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import it.unimi.dsi.fastutil.objects.Object2DoubleArrayMap;
import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Optional;
-import java.util.Random;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.stream.Stream;
-import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-
-// CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Hanging;
-import org.bukkit.entity.LivingEntity;
-import org.bukkit.entity.Vehicle;
-import co.aikar.timings.MinecraftTimings; // Paper
-import co.aikar.timings.Timing; // Paper
-import org.bukkit.event.entity.EntityCombustByEntityEvent;
-import org.bukkit.event.hanging.HangingBreakByEntityEvent;
-import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
-import org.bukkit.event.vehicle.VehicleEnterEvent;
-import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.entity.Hanging;
+import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Pose;
+import org.bukkit.entity.Vehicle;
import org.bukkit.event.entity.EntityAirChangeEvent;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDropItemEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.EntityPoseChangeEvent;
+import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
+import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
+import org.bukkit.event.vehicle.VehicleEnterEvent;
+import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.plugin.PluginManager;
+
+import javax.annotation.Nullable;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Optional;
+import java.util.Random;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Stream;
+
+// CraftBukkit start
// CraftBukkit end
public abstract class Entity implements INamableTileEntity, ICommandListener, KeyedObject { // Paper
@@ -425,10 +426,12 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
public void setPosition(double d0, double d1, double d2) {
this.setPositionRaw(d0, d1, d2);
- float f = this.size.width / 2.0F;
- float f1 = this.size.height;
+ // Paper start - move into setPositionRaw
+ //float f = this.size.width / 2.0F;
+ //float f1 = this.size.height;
- this.a(new AxisAlignedBB(d0 - (double) f, d1, d2 - (double) f, d0 + (double) f, d1 + (double) f1, d2 + (double) f));
+ //this.a(new AxisAlignedBB(d0 - (double) f, d1, d2 - (double) f, d0 + (double) f, d1 + (double) f1, d2 + (double) f));
+ // Paper end
if (valid) ((WorldServer) world).chunkCheck(this); // CraftBukkit
}
@@ -2901,6 +2904,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
return new AxisAlignedBB(vec3d, vec3d1);
}
+ public final void setBoundingBox(AxisAlignedBB axisalignedbb) { a(axisalignedbb); } // Paper - OBFHELPER
public void a(AxisAlignedBB axisalignedbb) {
// CraftBukkit start - block invalid bounding boxes
double minX = axisalignedbb.minX,
@@ -3339,6 +3343,14 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
public void setPositionRaw(double d0, double d1, double d2) {
+ // Paper start - never allow AABB to become desynced from position
+ // hanging has its own special logic
+ if (!(this instanceof EntityHanging) && (this.loc.x != d0 || this.loc.y != d1 || this.loc.z != d2)) {
+ float f = this.size.width / 2.0F;
+ float f1 = this.size.height;
+ this.setBoundingBox(new AxisAlignedBB(d0 - (double) f, d1, d2 - (double) f, d0 + (double) f, d1 + (double) f1, d2 + (double) f));
+ }
+ // Paper end
if (this.loc.x != d0 || this.loc.y != d1 || this.loc.z != d2) {
this.loc = new Vec3D(d0, d1, d2);
int i = MathHelper.floor(d0);

View File

@ -0,0 +1,63 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: kickash32 <kickash32@gmail.com>
Date: Sat, 27 Jun 2020 14:23:16 -0400
Subject: [PATCH] Optimize WorldBorder collision checks and air
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 2aa40f2a41e21526eb86acd903de024665109ab6..38887c1b7849926fab0a3b2db0e7b81388364172 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -854,7 +854,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
AxisAlignedBB axisalignedbb = this.getBoundingBox();
VoxelShapeCollision voxelshapecollision = VoxelShapeCollision.a(this);
VoxelShape voxelshape = this.world.getWorldBorder().c();
- Stream<VoxelShape> stream = VoxelShapes.c(voxelshape, VoxelShapes.a(axisalignedbb.shrink(1.0E-7D)), OperatorBoolean.AND) ? Stream.empty() : Stream.of(voxelshape);
+ Stream<VoxelShape> stream = !this.world.getWorldBorder().isInBounds(axisalignedbb) ? Stream.empty() : Stream.of(voxelshape); // Paper
Stream<VoxelShape> stream1 = this.world.c(this, axisalignedbb.b(vec3d), (entity) -> {
return true;
});
diff --git a/src/main/java/net/minecraft/server/VoxelShapeSpliterator.java b/src/main/java/net/minecraft/server/VoxelShapeSpliterator.java
index ed0f3ddbcb7d6ce8a59ae3829f4cb11ae75046cb..e841611bb7c36dffec44bb9e74a0a9657a113263 100644
--- a/src/main/java/net/minecraft/server/VoxelShapeSpliterator.java
+++ b/src/main/java/net/minecraft/server/VoxelShapeSpliterator.java
@@ -128,10 +128,10 @@ public class VoxelShapeSpliterator extends AbstractSpliterator<VoxelShape> {
AxisAlignedBB axisalignedbb = this.a.getBoundingBox();
if (!a(worldborder, axisalignedbb)) {
- VoxelShape voxelshape = worldborder.c();
-
- if (!b(voxelshape, axisalignedbb) && a(voxelshape, axisalignedbb)) {
- consumer.accept(voxelshape);
+ // Paper start
+ if (worldborder.isInBounds(axisalignedbb.shrink(1.0E-7D)) && !worldborder.isInBounds(axisalignedbb.grow(1.0E-7D))) {
+ consumer.accept(worldborder.asVoxelShape());
+ // Paper end
return true;
}
}
diff --git a/src/main/java/net/minecraft/server/VoxelShapes.java b/src/main/java/net/minecraft/server/VoxelShapes.java
index aeee4f11828e54ff9e873e452e19299822b1ec86..1fa7061f7adb539b6786fa11a0090f2c188ba9f2 100644
--- a/src/main/java/net/minecraft/server/VoxelShapes.java
+++ b/src/main/java/net/minecraft/server/VoxelShapes.java
@@ -242,7 +242,7 @@ public final class VoxelShapes {
IBlockData iblockdata = iworldreader.getTypeIfLoaded(blockposition_mutableblockposition); // Paper
if (iblockdata == null) return 0.0D; // Paper
- if ((k2 != 1 || iblockdata.d()) && (k2 != 2 || iblockdata.a(Blocks.MOVING_PISTON))) {
+ if (!iblockdata.isAir() && (k2 != 1 || iblockdata.d()) && (k2 != 2 || iblockdata.a(Blocks.MOVING_PISTON))) { // Paper
d0 = iblockdata.b((IBlockAccess) iworldreader, blockposition_mutableblockposition, voxelshapecollision).a(enumdirection_enumaxis2, axisalignedbb.d((double) (-blockposition_mutableblockposition.getX()), (double) (-blockposition_mutableblockposition.getY()), (double) (-blockposition_mutableblockposition.getZ())), d0);
if (Math.abs(d0) < 1.0E-7D) {
return 0.0D;
diff --git a/src/main/java/net/minecraft/server/WorldBorder.java b/src/main/java/net/minecraft/server/WorldBorder.java
index 0ef92a320d132b443e76276b2c34a4626cf187db..b651eb87bb23deeb2a3f4a1c626ddde9b11a7b9e 100644
--- a/src/main/java/net/minecraft/server/WorldBorder.java
+++ b/src/main/java/net/minecraft/server/WorldBorder.java
@@ -42,6 +42,7 @@ public class WorldBorder {
return (double) chunkcoordintpair.f() > this.e() && (double) chunkcoordintpair.d() < this.g() && (double) chunkcoordintpair.g() > this.f() && (double) chunkcoordintpair.e() < this.h();
}
+ public final boolean isInBounds(AxisAlignedBB aabb) { return this.a(aabb); } // Paper - OBFHELPER
public boolean a(AxisAlignedBB axisalignedbb) {
return axisalignedbb.maxX > this.e() && axisalignedbb.minX < this.g() && axisalignedbb.maxZ > this.f() && axisalignedbb.minZ < this.h();
}