diff --git a/eSpigot-Server/src/main/java/com/elevatemc/spigot/config/eSpigotConfig.java b/eSpigot-Server/src/main/java/com/elevatemc/spigot/config/eSpigotConfig.java index ab0f211..199c214 100644 --- a/eSpigot-Server/src/main/java/com/elevatemc/spigot/config/eSpigotConfig.java +++ b/eSpigot-Server/src/main/java/com/elevatemc/spigot/config/eSpigotConfig.java @@ -25,6 +25,13 @@ public class eSpigotConfig return config.getBoolean( path, config.getBoolean( path ) ); } + private static float getFloat(String path, float def) + { + path = "espigot." + path; + config.addDefault( path, def ); + return config.getFloat( path, config.getFloat( path ) ); + } + private static double getDouble(String path, double def) { path = "espigot." + path; @@ -113,6 +120,18 @@ public class eSpigotConfig slowerSaturationLoss = getBoolean( "settings.slower-saturation-loss", true ); } + public static int minBlockTicks; + private static void minBlockTicks() + { + minBlockTicks = getInt( "settings.minimum-blocking-ticks", 40 ); + } + + public static float underMinBlockTicksModifier; + private static void underMinBlockTicksModifier() + { + underMinBlockTicksModifier = (float) getDouble( "settings.under-minimum-blocking-ticks-modifier", 0.20 ); + } + public static boolean fixBouncingArrows; private static void fixBouncingArrows() { diff --git a/eSpigot-Server/src/main/java/com/elevatemc/spigot/util/CachedSizeConcurrentLinkedQueue.java b/eSpigot-Server/src/main/java/com/elevatemc/spigot/util/CachedSizeConcurrentLinkedQueue.java new file mode 100644 index 0000000..8f06d89 --- /dev/null +++ b/eSpigot-Server/src/main/java/com/elevatemc/spigot/util/CachedSizeConcurrentLinkedQueue.java @@ -0,0 +1,31 @@ +package com.elevatemc.spigot.util; + +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.LongAdder; + +public class CachedSizeConcurrentLinkedQueue extends ConcurrentLinkedQueue { + private final LongAdder cachedSize = new LongAdder(); + + @Override + public boolean add(E e) { + boolean result = super.add(e); + if (result) { + cachedSize.increment(); + } + return result; + } + + @Override + public E poll() { + E result = super.poll(); + if (result != null) { + cachedSize.decrement(); + } + return result; + } + + @Override + public int size() { + return cachedSize.intValue(); + } +} \ No newline at end of file diff --git a/eSpigot-Server/src/main/java/net/minecraft/server/Chunk.java b/eSpigot-Server/src/main/java/net/minecraft/server/Chunk.java index fa68764..aa02bfa 100644 --- a/eSpigot-Server/src/main/java/net/minecraft/server/Chunk.java +++ b/eSpigot-Server/src/main/java/net/minecraft/server/Chunk.java @@ -147,6 +147,8 @@ public class Chunk { // CraftBukkit end private final ChunkCoordIntPair chunkCoords; // PandaSpigot + private final BlockPosition blockPos; + private final BlockPosition cachedArea; public Chunk(World world, int i, int j) { this.sections = new ChunkSection[16]; @@ -175,6 +177,8 @@ public class Chunk { this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this); } this.chunkCoords = new ChunkCoordIntPair(this.locX, this.locZ); // PandaSpigot + this.blockPos = new BlockPosition(this.locX << 4, 0, this.locZ << 4); + this.cachedArea = new BlockPosition(this.locX * 16 + 8, 0, this.locZ * 16 + 8); } public org.bukkit.Chunk bukkitChunk; @@ -299,7 +303,7 @@ public class Chunk { private void h(boolean flag) { this.world.methodProfiler.a("recheckGaps"); - if (this.world.areChunksLoaded(new BlockPosition(this.locX * 16 + 8, 0, this.locZ * 16 + 8), 16)) { + if (this.world.areChunksLoaded(this.cachedArea, 16)) { for (int i = 0; i < 16; ++i) { for (int j = 0; j < 16; ++j) { if (this.g[i + j * 16]) { @@ -1375,8 +1379,6 @@ public class Chunk { } public void m() { - BlockPosition blockposition = new BlockPosition(this.locX << 4, 0, this.locZ << 4); - for (int i = 0; i < 8; ++i) { if (this.v >= 4096) { return; @@ -1389,7 +1391,7 @@ public class Chunk { ++this.v; for (int i1 = 0; i1 < 16; ++i1) { - BlockPosition blockposition1 = blockposition.a(k, (j << 4) + i1, l); + BlockPosition blockposition1 = this.blockPos.a(k, (j << 4) + i1, l); boolean flag = i1 == 0 || i1 == 15 || k == 0 || k == 15 || l == 0 || l == 15; if (this.sections[j] == null && flag || this.sections[j] != null && this.sections[j].b(k, i1, l).getMaterial() == Material.AIR) { @@ -1414,10 +1416,9 @@ public class Chunk { public void n() { this.done = true; this.lit = true; - BlockPosition blockposition = new BlockPosition(this.locX << 4, 0, this.locZ << 4); if (!this.world.worldProvider.o()) { - if (this.world.areChunksLoadedBetween(blockposition.a(-1, 0, -1), blockposition.a(16, this.world.F(), 16))) { + if (this.world.areChunksLoadedBetween(this.blockPos.a(-1, 0, -1), this.blockPos.a(16, this.world.F(), 16))) { label42: for (int i = 0; i < 16; ++i) { for (int j = 0; j < 16; ++j) { @@ -1433,7 +1434,7 @@ public class Chunk { for (EnumDirection enumdirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) { int k = enumdirection.c() == EnumDirection.EnumAxisDirection.POSITIVE ? 16 : 1; - this.world.getChunkAtWorldCoords(blockposition.shift(enumdirection, k)).a(enumdirection.opposite()); + this.world.getChunkAtWorldCoords(this.blockPos.shift(enumdirection, k)).a(enumdirection.opposite()); } this.y(); diff --git a/eSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java b/eSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java index ae83ca0..99e5b67 100644 --- a/eSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java +++ b/eSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java @@ -1,5 +1,6 @@ package net.minecraft.server; +import com.elevatemc.spigot.config.eSpigotConfig; import com.elevatemc.spigot.event.PlayerHealthChangeEvent; import com.google.common.base.Charsets; import com.google.common.collect.Lists; @@ -69,6 +70,9 @@ public abstract class EntityHuman extends EntityLiving { private int i; private final boolean bI = false; + // Beanes - blocking ticks + private int blockingTicks = 0; + public EntityHuman(World world, GameProfile gameprofile) { super(world); this.uniqueID = a(gameprofile); @@ -169,12 +173,24 @@ public abstract class EntityHuman extends EntityLiving { return this.bS() && this.g.getItem().e(this.g) == EnumAnimation.BLOCK; } + // Beanes - blocking ticks + public int getBlockingTicks() { + return blockingTicks; + } + public void t_() { this.noclip = this.isSpectator(); if (this.isSpectator()) { this.onGround = false; } + // Beanes - blocking ticks + if (isBlocking()) { + ++blockingTicks; + } else { + blockingTicks = 0; + } + if (this.g != null) { ItemStack itemstack = this.inventory.getItemInHand(); @@ -280,6 +296,7 @@ public abstract class EntityHuman extends EntityLiving { this.setPosition(d4, this.locY, d5); } + // } public int L() { diff --git a/eSpigot-Server/src/main/java/net/minecraft/server/EntityLiving.java b/eSpigot-Server/src/main/java/net/minecraft/server/EntityLiving.java index c012802..302caf6 100644 --- a/eSpigot-Server/src/main/java/net/minecraft/server/EntityLiving.java +++ b/eSpigot-Server/src/main/java/net/minecraft/server/EntityLiving.java @@ -33,6 +33,7 @@ import org.bukkit.event.vehicle.VehicleExitEvent; // PaperSpigot start import org.bukkit.Bukkit; import com.elevatemc.spigot.eSpigot; +import org.github.paperspigot.PaperSpigotWorldConfig; import org.spigotmc.event.entity.EntityDismountEvent; // PaperSpigot end @@ -792,7 +793,7 @@ public abstract class EntityLiving extends Entity { } // Beanes end - if ((float) this.noDamageTicks > (float) this.maxNoDamageTicks / 2.0F || isArrow) { + if ((float) this.noDamageTicks > (float) this.maxNoDamageTicks / 2.0F && !isArrow) { if (f <= this.lastDamage) { this.forceExplosionKnockback = true; // CraftBukkit - SPIGOT-949 - for vanilla consistency, cooldown does not prevent explosion knockback return false; @@ -1121,7 +1122,14 @@ public abstract class EntityLiving extends Entity { Function blocking = f16 -> { if (human) { if (!damagesource.ignoresArmor() && ((EntityHuman) EntityLiving.this).isBlocking() && f16 > 0.0F) { - return -(f16 - ((1.0F + f16) * 0.5F)); + float modifier; + if (((EntityHuman) EntityLiving.this).getBlockingTicks() >= eSpigotConfig.minBlockTicks) { + modifier = PaperSpigotWorldConfig.playerBlockingDamageMultiplier; + } else { + modifier = eSpigotConfig.underMinBlockTicksModifier; + } + + return -(f16 - ((1.0F + f16) * modifier)); } } return -0.0; diff --git a/eSpigot-Server/src/main/java/net/minecraft/server/NetworkManager.java b/eSpigot-Server/src/main/java/net/minecraft/server/NetworkManager.java index a21fede..72d62d0 100644 --- a/eSpigot-Server/src/main/java/net/minecraft/server/NetworkManager.java +++ b/eSpigot-Server/src/main/java/net/minecraft/server/NetworkManager.java @@ -4,6 +4,7 @@ import com.elevatemc.spigot.eSpigot; import com.elevatemc.spigot.exception.CryptException; import com.elevatemc.spigot.exception.ExploitException; import com.elevatemc.spigot.handler.PacketHandler; +import com.elevatemc.spigot.util.CachedSizeConcurrentLinkedQueue; import com.velocitypowered.natives.compression.VelocityCompressor; // Paper import com.velocitypowered.natives.util.Natives; // Paper import com.google.common.collect.Queues; @@ -43,7 +44,7 @@ public class NetworkManager extends SimpleChannelInboundHandler> { public static final AttributeKey c = ATTRIBUTE_PROTOCOL; private final EnumProtocolDirection h; - private final Queue i = Queues.newConcurrentLinkedQueue(); + private final Queue i = new CachedSizeConcurrentLinkedQueue<>(); private final ReentrantReadWriteLock j = new ReentrantReadWriteLock(); public Channel channel; // Spigot Start // PAIL diff --git a/eSpigot-Server/src/main/java/net/minecraft/server/World.java b/eSpigot-Server/src/main/java/net/minecraft/server/World.java index d159309..baf0308 100644 --- a/eSpigot-Server/src/main/java/net/minecraft/server/World.java +++ b/eSpigot-Server/src/main/java/net/minecraft/server/World.java @@ -2338,12 +2338,12 @@ public abstract class World implements IBlockAccess { return null; } else { // CraftBukkit start - if (capturedTileEntities.containsKey(blockposition)) { - return capturedTileEntities.get(blockposition); + TileEntity tileentity = null; + if (!capturedTileEntities.isEmpty() && (tileentity = capturedTileEntities.get(blockposition)) != null) { + return tileentity; } // CraftBukkit end - TileEntity tileentity = null; int i; TileEntity tileentity1;