2018-10-19 03:24:09 +00:00
From 9d3389fb2535b20a63c20203e34b59b5a83817e9 Mon Sep 17 00:00:00 2001
2016-03-29 01:01:42 +00:00
From: Aikar <aikar@aikar.co>
Date: Mon, 28 Mar 2016 20:55:47 -0400
Subject: [PATCH] MC Utils
2018-10-19 03:24:09 +00:00
diff --git a/src/main/java/net/minecraft/server/AttributeInstance.java b/src/main/java/net/minecraft/server/AttributeInstance.java
index 1c1a6a37a..0929e0189 100644
--- a/src/main/java/net/minecraft/server/AttributeInstance.java
+++ b/src/main/java/net/minecraft/server/AttributeInstance.java
@@ -20,8 +20,10 @@ public interface AttributeInstance {
@Nullable
AttributeModifier a(UUID var1);
+ default void addModifier(AttributeModifier modifier) { b(modifier); } // Paper - OBFHELPER
void b(AttributeModifier var1);
+ default void removeModifier(AttributeModifier modifier) { c(modifier); } // Paper - OBFHELPER
void c(AttributeModifier var1);
void b(UUID var1);
2018-07-17 15:14:23 +00:00
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
2018-10-19 03:24:09 +00:00
index 6ffc53514..5c5f19b4b 100644
2018-07-17 15:14:23 +00:00
--- a/src/main/java/net/minecraft/server/BlockPosition.java
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
2018-08-31 22:56:57 +00:00
@@ -9,7 +9,7 @@ import org.apache.logging.log4j.Logger;
2018-07-17 15:14:23 +00:00
@Immutable
public class BlockPosition extends BaseBlockPosition {
- private static final Logger b = LogManager.getLogger();
2018-08-26 18:11:49 +00:00
+ //private static final Logger b = LogManager.getLogger(); // Paper - variable name conflict, logger isn't used
2018-07-17 15:14:23 +00:00
public static final BlockPosition ZERO = new BlockPosition(0, 0, 0);
private static final int c = 1 + MathHelper.e(MathHelper.c(30000000));
2018-08-31 22:56:57 +00:00
private static final int d = c;
@@ -44,6 +44,7 @@ public class BlockPosition extends BaseBlockPosition {
return d0 == 0.0D && d1 == 0.0D && d2 == 0.0D ? this : new BlockPosition((double)this.getX() + d0, (double)this.getY() + d1, (double)this.getZ() + d2);
2018-07-18 23:31:45 +00:00
}
+ public BlockPosition add(int i, int j, int k) {return a(i, j, k);} // Paper - OBFHELPER
2018-08-31 22:56:57 +00:00
public BlockPosition a(int ix, int jx, int kx) {
return ix == 0 && jx == 0 && kx == 0 ? this : new BlockPosition(this.getX() + ix, this.getY() + jx, this.getZ() + kx);
2018-07-18 23:31:45 +00:00
}
2018-10-05 03:18:46 +00:00
@@ -186,6 +187,7 @@ public class BlockPosition extends BaseBlockPosition {
};
}
+ public BlockPosition asImmutable() { return h(); } // Paper - OBFHELPER
public BlockPosition h() {
return this;
}
@@ -282,6 +284,7 @@ public class BlockPosition extends BaseBlockPosition {
2018-07-19 04:42:43 +00:00
return this.d;
}
+ public BlockPosition.MutableBlockPosition setValues(int i, int j, int k) { return c(i, j, k);} // Paper - OBFHELPER
public BlockPosition.MutableBlockPosition c(int i, int j, int k) {
this.b = i;
this.c = j;
2018-10-05 03:18:46 +00:00
@@ -289,6 +292,7 @@ public class BlockPosition extends BaseBlockPosition {
2018-07-19 04:42:43 +00:00
return this;
}
+ public BlockPosition.MutableBlockPosition setValues(double d0, double d1, double d2) { return c(d0, d1, d2);} // Paper - OBFHELPER
public BlockPosition.MutableBlockPosition c(double d0, double d1, double d2) {
return this.c(MathHelper.floor(d0), MathHelper.floor(d1), MathHelper.floor(d2));
}
2016-06-18 06:03:40 +00:00
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
2018-10-19 03:24:09 +00:00
index bc5e4a654..d3eac35e4 100644
2016-06-18 06:03:40 +00:00
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
2018-07-15 01:53:17 +00:00
@@ -28,7 +28,7 @@ import com.google.common.collect.Lists; // CraftBukkit
public class Chunk implements IChunkAccess {
2017-10-05 13:38:21 +00:00
2018-08-26 18:11:49 +00:00
private static final Logger d = LogManager.getLogger();
2017-10-05 13:38:21 +00:00
- public static final ChunkSection a = null;
+ public static final ChunkSection a = null; public static final ChunkSection EMPTY_CHUNK_SECTION = Chunk.a; // Paper - OBFHELPER
private final ChunkSection[] sections;
2018-08-26 18:11:49 +00:00
private final BiomeBase[] f;
private final boolean[] g;
2018-08-27 15:07:22 +00:00
@@ -699,6 +699,7 @@ public class Chunk implements IChunkAccess {
2018-07-15 01:53:17 +00:00
return this.a(blockposition, Chunk.EnumTileEntityState.CHECK);
2016-06-18 06:03:40 +00:00
}
+ @Nullable public final TileEntity getTileEntityImmediately(BlockPosition pos) { return this.a(pos, EnumTileEntityState.IMMEDIATE); } // Paper - OBFHELPER
@Nullable
public TileEntity a(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) {
// CraftBukkit start
2017-11-11 23:47:30 +00:00
diff --git a/src/main/java/net/minecraft/server/ChunkCoordIntPair.java b/src/main/java/net/minecraft/server/ChunkCoordIntPair.java
2018-10-19 03:24:09 +00:00
index 744762b8b..d9608121b 100644
2017-11-11 23:47:30 +00:00
--- a/src/main/java/net/minecraft/server/ChunkCoordIntPair.java
+++ b/src/main/java/net/minecraft/server/ChunkCoordIntPair.java
2018-08-31 22:56:57 +00:00
@@ -23,6 +23,8 @@ public class ChunkCoordIntPair {
2018-07-15 01:53:17 +00:00
return a(this.x, this.z);
2017-11-11 23:47:30 +00:00
}
+ public static long asLong(final BlockPosition pos) { return a(pos.getX() >> 4, pos.getZ() >> 4); } // Paper - OBFHELPER
+ public static long asLong(int x, int z) { return a(x, z); } // Paper - OBFHELPER
public static long a(int i, int j) {
2018-08-31 22:56:57 +00:00
return (long)i & 4294967295L | ((long)j & 4294967295L) << 32;
2017-11-11 23:47:30 +00:00
}
2018-08-26 02:37:58 +00:00
diff --git a/src/main/java/net/minecraft/server/ChunkTaskScheduler.java b/src/main/java/net/minecraft/server/ChunkTaskScheduler.java
2018-10-19 03:24:09 +00:00
index 3b6b3b9a9..22af9c188 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/ChunkTaskScheduler.java
+++ b/src/main/java/net/minecraft/server/ChunkTaskScheduler.java
2018-08-26 18:11:49 +00:00
@@ -16,7 +16,7 @@ import org.apache.logging.log4j.Logger;
2018-08-26 02:37:58 +00:00
public class ChunkTaskScheduler extends Scheduler<ChunkCoordIntPair, ChunkStatus, ProtoChunk> {
private static final Logger b = LogManager.getLogger();
- private final World c;
+ private final World c; private final World getWorld() { return this.c; } // Paper - OBFHELPER
private final ChunkGenerator<?> d;
private final IChunkLoader e;
private final IAsyncTaskHandler f;
diff --git a/src/main/java/net/minecraft/server/DataBits.java b/src/main/java/net/minecraft/server/DataBits.java
2018-10-19 03:24:09 +00:00
index 95ca5f6d8..0dc948a37 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/DataBits.java
+++ b/src/main/java/net/minecraft/server/DataBits.java
2018-08-31 22:56:57 +00:00
@@ -54,6 +54,7 @@ public class DataBits {
2018-08-26 02:37:58 +00:00
}
}
+ public long[] getDataBits() { return this.a(); } // Paper - OBFHELPER
public long[] a() {
return this.a;
}
diff --git a/src/main/java/net/minecraft/server/DataPalette.java b/src/main/java/net/minecraft/server/DataPalette.java
2018-10-19 03:24:09 +00:00
index 7f905b1e0..fa5b9262b 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/DataPalette.java
+++ b/src/main/java/net/minecraft/server/DataPalette.java
2018-08-31 22:56:57 +00:00
@@ -3,10 +3,11 @@ package net.minecraft.server;
import javax.annotation.Nullable;
2018-08-26 02:37:58 +00:00
public interface DataPalette<T> {
2018-09-01 04:30:04 +00:00
+ default int getOrCreateIdFor(T object) { return this.a(object); } // Paper - OBFHELPER
2018-08-31 22:56:57 +00:00
int a(T var1);
2018-08-26 02:37:58 +00:00
2018-08-31 22:56:57 +00:00
- @Nullable
- T a(int var1);
2018-08-26 02:37:58 +00:00
+ @Nullable default T getObject(int dataBits) { return this.a(dataBits); } // Paper - OBFHELPER
2018-08-31 22:56:57 +00:00
+ @Nullable T a(int var1);
void b(PacketDataSerializer var1);
2018-08-26 02:37:58 +00:00
diff --git a/src/main/java/net/minecraft/server/DataPaletteBlock.java b/src/main/java/net/minecraft/server/DataPaletteBlock.java
2018-10-19 03:24:09 +00:00
index 304e47bf2..6e7454b13 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/DataPaletteBlock.java
+++ b/src/main/java/net/minecraft/server/DataPaletteBlock.java
2018-08-31 22:56:57 +00:00
@@ -7,7 +7,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
2018-08-26 02:37:58 +00:00
public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
- private final DataPalette<T> b;
2018-08-31 22:56:57 +00:00
+ private final DataPalette<T> b;private final DataPalette<T> getDataPaletteGlobal() { return this.b; } // Paper - OBFHELPER
private final DataPaletteExpandable<T> c = (var0, var1) -> {
2018-08-26 02:37:58 +00:00
return 0;
};
2018-08-31 22:56:57 +00:00
@@ -15,9 +15,9 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
2018-08-26 02:37:58 +00:00
private final Function<NBTTagCompound, T> e;
private final Function<T, NBTTagCompound> f;
private final T g;
- protected DataBits a;
- private DataPalette<T> h;
- private int i;
+ protected DataBits a; protected DataBits getDataBits() { return this.a; } // Paper - OBFHELPER
+ private DataPalette<T> h; private DataPalette<T> getDataPalette() { return this.h; } // Paper - OBFHELPER
+ private int i; private int getBitsPerObject() { return this.i; } // Paper - OBFHELPER
private final ReentrantLock j = new ReentrantLock();
private void b() {
2018-08-31 22:56:57 +00:00
@@ -51,6 +51,7 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
return jx << 8 | k << 4 | ix;
2018-08-26 02:37:58 +00:00
}
+ private void initialize(int bitsPerObject) { this.b(bitsPerObject); } // Paper - OBFHELPER
2018-08-31 22:56:57 +00:00
private void b(int ix) {
if (ix != this.i) {
this.i = ix;
@@ -107,6 +108,7 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
return (T)(object == null ? this.g : object);
2018-08-26 02:37:58 +00:00
}
+ public void writeDataPaletteBlock(PacketDataSerializer packetDataSerializer) { this.b(packetDataSerializer); } // Paper - OBFHELPER
public void b(PacketDataSerializer packetdataserializer) {
this.b();
packetdataserializer.writeByte(this.i);
2018-08-04 21:03:53 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityCreature.java b/src/main/java/net/minecraft/server/EntityCreature.java
2018-10-19 03:24:09 +00:00
index 2c6fbd1d6..a5c147b98 100644
2018-08-04 21:03:53 +00:00
--- a/src/main/java/net/minecraft/server/EntityCreature.java
+++ b/src/main/java/net/minecraft/server/EntityCreature.java
@@ -6,6 +6,7 @@ import org.bukkit.event.entity.EntityUnleashEvent;
public abstract class EntityCreature extends EntityInsentient {
2018-08-31 22:56:57 +00:00
+ public org.bukkit.craftbukkit.entity.CraftCreature getBukkitCreature() { return (org.bukkit.craftbukkit.entity.CraftCreature) super.getBukkitEntity(); } // Paper
2018-08-04 21:03:53 +00:00
private BlockPosition a;
private float b;
2018-08-31 22:56:57 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
2018-10-19 03:24:09 +00:00
index ebb177927..60b1dcd8e 100644
2018-08-31 22:56:57 +00:00
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
@@ -124,6 +124,7 @@ public abstract class EntityInsentient extends EntityLiving {
return this.goalTarget;
}
+ public org.bukkit.craftbukkit.entity.CraftMob getBukkitMob() { return (org.bukkit.craftbukkit.entity.CraftMob) super.getBukkitEntity(); } // Paper
public void setGoalTarget(@Nullable EntityLiving entityliving) {
// CraftBukkit start - fire event
setGoalTarget(entityliving, EntityTargetEvent.TargetReason.UNKNOWN, true);
2018-08-04 21:03:53 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
2018-10-19 03:24:09 +00:00
index 1aefd3763..76cc9085b 100644
2018-08-04 21:03:53 +00:00
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -122,6 +122,7 @@ public abstract class EntityLiving extends Entity {
public org.bukkit.craftbukkit.attribute.CraftAttributeMap craftAttributes;
public boolean collides = true;
public boolean canPickUpLoot;
2018-08-31 22:56:57 +00:00
+ public org.bukkit.craftbukkit.entity.CraftLivingEntity getBukkitLivingEntity() { return (org.bukkit.craftbukkit.entity.CraftLivingEntity) super.getBukkitEntity(); } // Paper
2018-08-04 21:03:53 +00:00
@Override
public float getBukkitYaw() {
diff --git a/src/main/java/net/minecraft/server/EntityMonster.java b/src/main/java/net/minecraft/server/EntityMonster.java
2018-10-19 03:24:09 +00:00
index c0f48bbc2..a0e3b72c1 100644
2018-08-04 21:03:53 +00:00
--- a/src/main/java/net/minecraft/server/EntityMonster.java
+++ b/src/main/java/net/minecraft/server/EntityMonster.java
2018-10-19 03:24:09 +00:00
@@ -1,11 +1,14 @@
2018-08-31 22:56:57 +00:00
package net.minecraft.server;
2018-08-04 21:03:53 +00:00
public abstract class EntityMonster extends EntityCreature implements IMonster {
2018-08-31 22:56:57 +00:00
+
+ public org.bukkit.craftbukkit.entity.CraftMonster getBukkitMonster() { return (org.bukkit.craftbukkit.entity.CraftMonster) super.getBukkitEntity(); } // Paper
2018-08-04 21:03:53 +00:00
protected EntityMonster(EntityTypes<?> entitytypes, World world) {
super(entitytypes, world);
this.b_ = 5;
2018-10-19 03:24:09 +00:00
}
+ public SoundCategory getSoundCategory() { return bV(); } // Paper - OBFHELPER
public SoundCategory bV() {
return SoundCategory.HOSTILE;
}
2018-01-14 22:02:38 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
2018-10-19 03:24:09 +00:00
index 17bfa356f..5c1ab6a0b 100644
2018-01-14 22:02:38 +00:00
--- a/src/main/java/net/minecraft/server/EntityTypes.java
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
2018-07-15 01:53:17 +00:00
@@ -3,6 +3,7 @@ package net.minecraft.server;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.types.Type;
2018-01-14 22:15:27 +00:00
2018-07-15 01:53:17 +00:00
+import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
2018-08-26 18:11:49 +00:00
@@ -123,9 +124,20 @@ public class EntityTypes<T extends Entity> {
2018-07-15 01:53:17 +00:00
public static <T extends Entity> EntityTypes<T> a(String s, EntityTypes.a<T> entitytypes_a) {
EntityTypes entitytypes = entitytypes_a.a(s);
2018-01-14 22:15:27 +00:00
2018-07-15 01:53:17 +00:00
+ // Paper start
2018-07-19 04:42:43 +00:00
+ if (clsToKeyMap == null ) clsToKeyMap = new java.util.HashMap<>();
+ if (clsToTypeMap == null ) clsToTypeMap = new java.util.HashMap<>();
+
2018-07-15 01:53:17 +00:00
+ MinecraftKey key = new MinecraftKey(s);
+ Class<? extends T> entityClass = entitytypes_a.getEntityClass();
2018-08-26 18:11:49 +00:00
IRegistry.ENTITY_TYPE.a(new MinecraftKey(s), entitytypes); // CraftBukkit - decompile error
2018-07-15 01:53:17 +00:00
+ clsToKeyMap.put(entityClass, key);
+ clsToTypeMap.put(entityClass, org.bukkit.entity.EntityType.fromName(s));
return entitytypes;
}
2018-07-19 04:42:43 +00:00
+ public static Map<Class<? extends Entity>, MinecraftKey> clsToKeyMap;
+ public static Map<Class<? extends Entity>, org.bukkit.entity.EntityType> clsToTypeMap;
2018-01-14 22:02:38 +00:00
+ // Paper end
2018-07-15 01:53:17 +00:00
@Nullable
public static MinecraftKey getName(EntityTypes<?> entitytypes) {
2018-08-26 18:11:49 +00:00
@@ -287,7 +299,7 @@ public class EntityTypes<T extends Entity> {
2018-07-15 01:53:17 +00:00
public static class a<T extends Entity> {
2018-01-14 22:02:38 +00:00
2018-07-15 01:53:17 +00:00
- private final Class<? extends T> a;
+ private final Class<? extends T> a; public Class<? extends T> getEntityClass() { return a; } // Paper - OBFHELPER
private final Function<? super World, ? extends T> b;
private boolean c = true;
private boolean d = true;
2018-08-26 18:11:49 +00:00
@@ -338,7 +350,7 @@ public class EntityTypes<T extends Entity> {
// Paper start
public static Set<MinecraftKey> getEntityNameList() {
- return REGISTRY.keySet();
+ return IRegistry.ENTITY_TYPE.keySet();
}
// Paper end
}
2018-06-29 04:55:29 +00:00
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
2018-10-19 03:24:09 +00:00
index c54275bc2..318c4204d 100644
2018-06-29 04:55:29 +00:00
--- a/src/main/java/net/minecraft/server/ItemStack.java
+++ b/src/main/java/net/minecraft/server/ItemStack.java
2018-07-26 15:20:37 +00:00
@@ -26,6 +26,7 @@ import org.bukkit.TreeType;
2018-06-29 04:55:29 +00:00
import org.bukkit.block.BlockState;
2018-07-26 15:20:37 +00:00
import org.bukkit.craftbukkit.block.CraftBlock;
2018-06-29 04:55:29 +00:00
import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.entity.Player;
2018-07-26 15:20:37 +00:00
import org.bukkit.event.block.BlockFertilizeEvent;
2018-08-03 05:04:28 +00:00
@@ -561,6 +562,17 @@ public final class ItemStack {
2018-07-15 01:53:17 +00:00
return this.tag != null ? this.tag.getList("Enchantments", 10) : new NBTTagList();
2018-06-29 04:55:29 +00:00
}
+ // Paper start - (this is just a good no conflict location)
+ public org.bukkit.inventory.ItemStack asBukkitMirror() {
+ return CraftItemStack.asCraftMirror(this);
+ }
+ public org.bukkit.inventory.ItemStack asBukkitCopy() {
+ return CraftItemStack.asCraftMirror(this.cloneItemStack());
+ }
+ public static ItemStack fromBukkitCopy(org.bukkit.inventory.ItemStack itemstack) {
+ return CraftItemStack.asNMSCopy(itemstack);
+ }
+ // Paper end
public void setTag(@Nullable NBTTagCompound nbttagcompound) {
this.tag = nbttagcompound;
}
2016-03-29 01:01:42 +00:00
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
new file mode 100644
2018-10-19 03:24:09 +00:00
index 000000000..c97e116aa
2016-03-29 01:01:42 +00:00
--- /dev/null
+++ b/src/main/java/net/minecraft/server/MCUtil.java
2018-10-05 03:18:46 +00:00
@@ -0,0 +1,316 @@
2016-03-29 01:01:42 +00:00
+package net.minecraft.server;
+
2018-09-03 23:59:54 +00:00
+import com.destroystokyo.paper.block.TargetBlockInfo;
2016-05-17 00:50:09 +00:00
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
2016-03-29 01:01:42 +00:00
+import org.bukkit.Location;
2018-09-03 23:59:54 +00:00
+import org.bukkit.block.BlockFace;
+import org.bukkit.craftbukkit.CraftWorld;
2016-05-28 02:28:23 +00:00
+import org.bukkit.craftbukkit.util.Waitable;
+import org.spigotmc.AsyncCatcher;
2016-03-29 01:01:42 +00:00
+
2018-09-03 23:59:54 +00:00
+import javax.annotation.Nonnull;
2016-05-13 05:34:37 +00:00
+import javax.annotation.Nullable;
2018-07-22 04:45:49 +00:00
+import java.util.Queue;
+import java.util.concurrent.CompletableFuture;
2016-05-28 02:28:23 +00:00
+import java.util.concurrent.ExecutionException;
2016-05-17 00:50:09 +00:00
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
2018-07-22 04:45:49 +00:00
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
2016-05-28 02:28:23 +00:00
+import java.util.function.Supplier;
2016-03-29 01:01:42 +00:00
+
2016-05-14 02:27:20 +00:00
+public final class MCUtil {
2016-05-23 02:14:17 +00:00
+ private static final Executor asyncExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("Paper Async Task Handler Thread - %1$d").build());
2016-03-29 01:01:42 +00:00
+
+ private MCUtil() {}
+
+
2018-07-22 04:45:49 +00:00
+ public static boolean isMainThread() {
+ return MinecraftServer.getServer().isMainThread();
+ }
+
2018-07-22 23:39:56 +00:00
+ private static class DelayedRunnable implements Runnable {
+
+ private final int ticks;
+ private final Runnable run;
+
+ private DelayedRunnable(int ticks, Runnable run) {
+ this.ticks = ticks;
+ this.run = run;
+ }
+
+ @Override
+ public void run() {
+ if (ticks <= 0) {
+ run.run();
+ } else {
+ scheduleTask(ticks-1, run);
+ }
+ }
+ }
+
+ public static void scheduleTask(int ticks, Runnable runnable) {
+ // We use post to main instead of process queue as we don't want to process these mid tick if
+ // Someone uses processQueueWhileWaiting
+ MinecraftServer.getServer().postToMainThread(new DelayedRunnable(ticks, runnable));
+ }
+
2018-07-22 04:45:49 +00:00
+ public static void processQueue() {
+ Runnable runnable;
+ Queue<Runnable> processQueue = getProcessQueue();
+ while ((runnable = processQueue.poll()) != null) {
+ try {
+ runnable.run();
+ } catch (Exception e) {
+ MinecraftServer.LOGGER.error("Error executing task", e);
+ }
+ }
+ }
+ public static <T> T processQueueWhileWaiting(CompletableFuture <T> future) {
+ try {
+ if (isMainThread()) {
+ while (!future.isDone()) {
+ try {
+ return future.get(1, TimeUnit.MILLISECONDS);
+ } catch (TimeoutException ignored) {
+ processQueue();
+ }
+ }
+ }
+ return future.get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static void ensureMain(Runnable run) {
+ ensureMain(null, run);
+ }
+ /**
+ * Ensures the target code is running on the main thread
+ * @param reason
+ * @param run
+ * @return
+ */
+ public static void ensureMain(String reason, Runnable run) {
+ if (AsyncCatcher.enabled && Thread.currentThread() != MinecraftServer.getServer().primaryThread) {
+ if (reason != null) {
+ new IllegalStateException("Asynchronous " + reason + "!").printStackTrace();
+ }
+ getProcessQueue().add(run);
+ return;
+ }
+ run.run();
+ }
+
+ private static Queue<Runnable> getProcessQueue() {
+ return MinecraftServer.getServer().processQueue;
+ }
+
+ public static <T> T ensureMain(Supplier<T> run) {
+ return ensureMain(null, run);
+ }
2016-03-29 01:01:42 +00:00
+ /**
2016-05-28 02:28:23 +00:00
+ * Ensures the target code is running on the main thread
+ * @param reason
+ * @param run
+ * @param <T>
+ * @return
+ */
+ public static <T> T ensureMain(String reason, Supplier<T> run) {
+ if (AsyncCatcher.enabled && Thread.currentThread() != MinecraftServer.getServer().primaryThread) {
2018-07-22 04:45:49 +00:00
+ if (reason != null) {
+ new IllegalStateException("Asynchronous " + reason + "! Blocking thread until it returns ").printStackTrace();
+ }
2016-05-28 02:28:23 +00:00
+ Waitable<T> wait = new Waitable<T>() {
+ @Override
+ protected T evaluate() {
+ return run.get();
+ }
+ };
2018-07-22 04:45:49 +00:00
+ getProcessQueue().add(wait);
2016-05-28 02:28:23 +00:00
+ try {
+ return wait.get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+ return run.get();
+ }
+
+ /**
2016-03-29 01:01:42 +00:00
+ * Calculates distance between 2 entities
+ * @param e1
+ * @param e2
+ * @return
+ */
+ public static double distance(Entity e1, Entity e2) {
+ return Math.sqrt(distanceSq(e1, e2));
+ }
+
+
+ /**
+ * Calculates distance between 2 block positions
+ * @param e1
+ * @param e2
+ * @return
+ */
+ public static double distance(BlockPosition e1, BlockPosition e2) {
+ return Math.sqrt(distanceSq(e1, e2));
+ }
+
+ /**
+ * Gets the distance between 2 positions
+ * @param x1
+ * @param y1
+ * @param z1
+ * @param x2
+ * @param y2
+ * @param z2
+ * @return
+ */
+ public static double distance(double x1, double y1, double z1, double x2, double y2, double z2) {
+ return Math.sqrt(distanceSq(x1, y1, z1, x2, y2, z2));
+ }
+
+ /**
+ * Get's the distance squared between 2 entities
+ * @param e1
+ * @param e2
+ * @return
+ */
+ public static double distanceSq(Entity e1, Entity e2) {
+ return distanceSq(e1.locX,e1.locY,e1.locZ, e2.locX,e2.locY,e2.locZ);
+ }
+
+ /**
+ * Gets the distance sqaured between 2 block positions
+ * @param pos1
+ * @param pos2
+ * @return
+ */
+ public static double distanceSq(BlockPosition pos1, BlockPosition pos2) {
+ return distanceSq(pos1.getX(), pos1.getY(), pos1.getZ(), pos2.getX(), pos2.getY(), pos2.getZ());
+ }
+
+ /**
+ * Gets the distance squared between 2 positions
+ * @param x1
+ * @param y1
+ * @param z1
+ * @param x2
+ * @param y2
+ * @param z2
+ * @return
+ */
+ public static double distanceSq(double x1, double y1, double z1, double x2, double y2, double z2) {
+ return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2);
+ }
+
+ /**
+ * Converts a NMS World/BlockPosition to Bukkit Location
+ * @param world
2018-01-14 22:02:38 +00:00
+ * @param x
+ * @param y
+ * @param z
+ * @return
+ */
+ public static Location toLocation(World world, double x, double y, double z) {
+ return new Location(world.getWorld(), x, y, z);
+ }
+
+ /**
+ * Converts a NMS World/BlockPosition to Bukkit Location
+ * @param world
2016-03-29 01:01:42 +00:00
+ * @param pos
+ * @return
+ */
+ public static Location toLocation(World world, BlockPosition pos) {
+ return new Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ());
+ }
+
+ /**
+ * Converts an NMS entity's current location to a Bukkit Location
+ * @param entity
+ * @return
+ */
+ public static Location toLocation(Entity entity) {
+ return new Location(entity.getWorld().getWorld(), entity.locX, entity.locY, entity.locZ);
+ }
2016-03-31 23:29:06 +00:00
+
2018-08-26 18:11:49 +00:00
+ public static org.bukkit.block.Block toBukkitBlock(World world, BlockPosition pos) {
+ return world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
+ }
+
2016-04-16 01:31:12 +00:00
+ public static BlockPosition toBlockPosition(Location loc) {
+ return new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
+ }
+
2016-03-31 23:29:06 +00:00
+ public static boolean isEdgeOfChunk(BlockPosition pos) {
2016-04-01 01:43:37 +00:00
+ final int modX = pos.getX() & 15;
+ final int modZ = pos.getZ() & 15;
+ return (modX == 0 || modX == 15 || modZ == 0 || modZ == 15);
2016-03-31 23:29:06 +00:00
+ }
2016-05-13 05:34:37 +00:00
+
+ /**
2016-05-17 00:50:09 +00:00
+ * Posts a task to be executed asynchronously
+ * @param run
+ */
+ public static void scheduleAsyncTask(Runnable run) {
+ asyncExecutor.execute(run);
+ }
2016-06-18 06:03:40 +00:00
+
+ @Nullable
+ public static TileEntityHopper getHopper(World world, BlockPosition pos) {
+ Chunk chunk = world.getChunkIfLoaded(pos.getX() >> 4, pos.getZ() >> 4);
2018-09-03 23:59:54 +00:00
+ if (chunk != null && chunk.getBlockData(pos.getX(), pos.getY(), pos.getZ()).getBlock() == Blocks.HOPPER) {
2016-06-18 06:03:40 +00:00
+ TileEntity tileEntity = chunk.getTileEntityImmediately(pos);
+ if (tileEntity instanceof TileEntityHopper) {
+ return (TileEntityHopper) tileEntity;
+ }
+ }
+ return null;
+ }
2018-09-03 23:59:54 +00:00
+
+ @Nonnull
+ public static World getNMSWorld(@Nonnull org.bukkit.World world) {
+ return ((CraftWorld) world).getHandle();
+ }
+
+ public static World getNMSWorld(@Nonnull org.bukkit.entity.Entity entity) {
+ return getNMSWorld(entity.getWorld());
+ }
+
+ public static FluidCollisionOption getNMSFluidCollisionOption(TargetBlockInfo.FluidMode fluidMode) {
+ if (fluidMode == TargetBlockInfo.FluidMode.NEVER) {
+ return FluidCollisionOption.NEVER;
+ }
+ if (fluidMode == TargetBlockInfo.FluidMode.SOURCE_ONLY) {
+ return FluidCollisionOption.SOURCE_ONLY;
+ }
+ if (fluidMode == TargetBlockInfo.FluidMode.ALWAYS) {
+ return FluidCollisionOption.ALWAYS;
+ }
+ return null;
+ }
+
+ public static BlockFace toBukkitBlockFace(EnumDirection enumDirection) {
+ switch (enumDirection) {
+ case DOWN:
+ return BlockFace.DOWN;
+ case UP:
+ return BlockFace.UP;
+ case NORTH:
+ return BlockFace.NORTH;
+ case SOUTH:
+ return BlockFace.SOUTH;
+ case WEST:
+ return BlockFace.WEST;
+ case EAST:
+ return BlockFace.EAST;
+ default:
+ return null;
+ }
+ }
2016-03-29 01:01:42 +00:00
+}
2016-05-02 03:54:08 +00:00
diff --git a/src/main/java/net/minecraft/server/NBTTagCompound.java b/src/main/java/net/minecraft/server/NBTTagCompound.java
2018-10-19 03:24:09 +00:00
index 41cd3ceab..2a66a3026 100644
2016-05-02 03:54:08 +00:00
--- a/src/main/java/net/minecraft/server/NBTTagCompound.java
+++ b/src/main/java/net/minecraft/server/NBTTagCompound.java
2018-08-31 22:56:57 +00:00
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.Logger;
public class NBTTagCompound implements NBTBase {
2018-07-15 01:53:17 +00:00
private static final Logger f = LogManager.getLogger();
private static final Pattern g = Pattern.compile("[A-Za-z0-9._+-]+");
2016-06-09 03:57:14 +00:00
- private final Map<String, NBTBase> map = Maps.newHashMap();
+ public final Map<String, NBTBase> map = Maps.newHashMap(); // Paper
2016-05-02 03:54:08 +00:00
2018-08-31 22:56:57 +00:00
public NBTTagCompound() {
}
@@ -89,11 +89,13 @@ public class NBTTagCompound implements NBTBase {
2016-05-02 03:54:08 +00:00
this.map.put(s, new NBTTagLong(i));
}
2016-07-27 22:46:02 +00:00
+ public void setUUID(String prefix, UUID uuid) { a(prefix, uuid); } // Paper - OBFHELPER
2016-05-02 03:54:08 +00:00
public void a(String s, UUID uuid) {
this.setLong(s + "Most", uuid.getMostSignificantBits());
this.setLong(s + "Least", uuid.getLeastSignificantBits());
}
2016-07-27 22:46:02 +00:00
+ public UUID getUUID(String prefix) { return a(prefix); } // Paper - OBFHELPER
2016-05-12 02:07:46 +00:00
@Nullable
2016-05-02 03:54:08 +00:00
public UUID a(String s) {
return new UUID(this.getLong(s + "Most"), this.getLong(s + "Least"));
2018-08-31 22:56:57 +00:00
@@ -322,7 +324,7 @@ public class NBTTagCompound implements NBTBase {
public String toString() {
StringBuilder stringbuilder = new StringBuilder("{");
- Object object = this.map.keySet();
+ Collection<String> object = this.map.keySet(); // Paper - decompile fix
if (f.isDebugEnabled()) {
ArrayList arraylist = Lists.newArrayList(this.map.keySet());
Collections.sort(arraylist);
@@ -476,7 +478,7 @@ public class NBTTagCompound implements NBTBase {
2018-07-15 01:53:17 +00:00
}
2018-08-31 22:56:57 +00:00
// $FF: synthetic method
2018-07-15 01:53:17 +00:00
- public NBTBase clone() {
2018-08-31 22:56:57 +00:00
+ public NBTBase clone_bad() { // Paper - decompile fix
return this.clone();
}
2018-07-15 01:53:17 +00:00
}
2018-08-26 02:37:58 +00:00
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
2018-10-19 03:24:09 +00:00
index 0afaea810..26da89724 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/NetworkManager.java
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
@@ -44,7 +44,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
return new DefaultEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Client IO #%d").setDaemon(true).build());
});
private final EnumProtocolDirection h;
- private final Queue<NetworkManager.QueuedPacket> i = Queues.newConcurrentLinkedQueue();
+ private final Queue<NetworkManager.QueuedPacket> i = Queues.newConcurrentLinkedQueue(); private final Queue<NetworkManager.QueuedPacket> getPacketQueue() { return this.i; } // Paper - OBFHELPER
private final ReentrantReadWriteLock j = new ReentrantReadWriteLock();
public Channel channel;
// Spigot Start // PAIL
@@ -168,6 +168,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
}
+ private void dispatchPacket(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericFutureListener) { this.b(packet, genericFutureListener); } // Paper - OBFHELPER
private void b(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
EnumProtocol enumprotocol = EnumProtocol.a(packet);
EnumProtocol enumprotocol1 = (EnumProtocol) this.channel.attr(NetworkManager.c).get();
@@ -208,6 +209,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
}
+ private void sendPacketQueue() { this.o(); } // Paper - OBFHELPER
private void o() {
if (this.channel != null && this.channel.isOpen()) {
this.j.readLock().lock();
@@ -338,9 +340,9 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
static class QueuedPacket {
- private final Packet<?> a;
+ private final Packet<?> a; private final Packet<?> getPacket() { return this.a; } // Paper - OBFHELPER
@Nullable
- private final GenericFutureListener<? extends Future<? super Void>> b;
+ private final GenericFutureListener<? extends Future<? super Void>> b; private final GenericFutureListener<? extends Future<? super Void>> getGenericFutureListener() { return this.b; } // Paper - OBFHELPER
public QueuedPacket(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
this.a = packet;
diff --git a/src/main/java/net/minecraft/server/PacketDataSerializer.java b/src/main/java/net/minecraft/server/PacketDataSerializer.java
2018-10-19 03:24:09 +00:00
index d04afceb7..a63a5811d 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/PacketDataSerializer.java
+++ b/src/main/java/net/minecraft/server/PacketDataSerializer.java
@@ -33,6 +33,7 @@ public class PacketDataSerializer extends ByteBuf {
this.a = bytebuf;
}
+ public static int countBytes(int i) { return PacketDataSerializer.a(i); } // Paper - OBFHELPER
public static int a(int i) {
for (int j = 1; j < 5; ++j) {
if ((i & -1 << j * 7) == 0) {
2018-10-03 02:53:27 +00:00
diff --git a/src/main/java/net/minecraft/server/PacketEncoder.java b/src/main/java/net/minecraft/server/PacketEncoder.java
2018-10-19 03:24:09 +00:00
index 8e312c761..c20911c96 100644
2018-10-03 02:53:27 +00:00
--- a/src/main/java/net/minecraft/server/PacketEncoder.java
+++ b/src/main/java/net/minecraft/server/PacketEncoder.java
@@ -38,6 +38,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
packet.b(packetdataserializer);
} catch (Throwable throwable) {
a.error(throwable);
+ throwable.printStackTrace(); // Paper - WHAT WAS IT? WHO DID THIS TO YOU? WHAT DID YOU SEE?
if (packet.a()) {
throw new SkipEncodeException(throwable);
} else {
2018-08-26 02:37:58 +00:00
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
2018-10-19 03:24:09 +00:00
index 12d6c99cf..af382815f 100644
2018-08-26 02:37:58 +00:00
--- a/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMapChunk.java
2018-08-31 22:56:57 +00:00
@@ -11,7 +11,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
2018-08-26 02:37:58 +00:00
private int a;
private int b;
private int c;
- private byte[] d;
+ private byte[] d; private byte[] getData() { return this.d; } // Paper - OBFHELPER
private List<NBTTagCompound> e;
private boolean f;
2018-08-31 22:56:57 +00:00
@@ -85,6 +85,7 @@ public class PacketPlayOutMapChunk implements Packet<PacketListenerPlayOut> {
2018-08-26 02:37:58 +00:00
return bytebuf;
}
+ public int writeChunk(PacketDataSerializer packetDataSerializer, Chunk chunk, boolean writeSkyLightArray, int chunkSectionSelector) { return this.a(packetDataSerializer, chunk, writeSkyLightArray, chunkSectionSelector); } // Paper - OBFHELPER
public int a(PacketDataSerializer packetdataserializer, Chunk chunk, boolean flag, int i) {
int j = 0;
ChunkSection[] achunksection = chunk.getSections();
2017-10-15 13:00:42 +00:00
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
2018-10-19 03:24:09 +00:00
index d455eadfc..8db0b6a6d 100644
2017-10-15 13:00:42 +00:00
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
2018-08-26 18:11:49 +00:00
@@ -68,9 +68,9 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
2017-10-15 13:00:42 +00:00
private final MinecraftServer minecraftServer;
public EntityPlayer player;
private int e;
- private long f;
- private boolean g;
- private long h;
+ private long f; private void setLastPing(long lastPing) { this.f = lastPing;}; private long getLastPing() { return this.f;}; // Paper - OBFHELPER
+ private boolean g; private void setPendingPing(boolean isPending) { this.g = isPending;}; private boolean isPendingPing() { return this.g;}; // Paper - OBFHELPER
+ private long h; private void setKeepAliveID(long keepAliveID) { this.h = keepAliveID;}; private long getKeepAliveID() {return this.h; }; // Paper - OBFHELPER
// CraftBukkit start - multithreaded fields
private volatile int chatThrottle;
private static final AtomicIntegerFieldUpdater chatSpamField = AtomicIntegerFieldUpdater.newUpdater(PlayerConnection.class, "chatThrottle");
2018-10-19 03:24:09 +00:00
diff --git a/src/main/java/net/minecraft/server/PotionUtil.java b/src/main/java/net/minecraft/server/PotionUtil.java
index 8fce3b022..58ac6eafc 100644
--- a/src/main/java/net/minecraft/server/PotionUtil.java
+++ b/src/main/java/net/minecraft/server/PotionUtil.java
@@ -103,6 +103,7 @@ public class PotionUtil {
return nbttagcompound == null ? Potions.EMPTY : PotionRegistry.a(nbttagcompound.getString("Potion"));
}
+ public static ItemStack addPotionToItemStack(ItemStack itemstack, PotionRegistry potionregistry) { return a(itemstack, potionregistry); } // Paper - OBFHELPER
public static ItemStack a(ItemStack itemstack, PotionRegistry potionregistry) {
MinecraftKey minecraftkey = IRegistry.POTION.getKey(potionregistry);
if (potionregistry == Potions.EMPTY) {
2018-07-19 04:42:43 +00:00
diff --git a/src/main/java/net/minecraft/server/RegistryBlockID.java b/src/main/java/net/minecraft/server/RegistryBlockID.java
2018-10-19 03:24:09 +00:00
index a21006290..6c6f006f3 100644
2018-07-19 04:42:43 +00:00
--- a/src/main/java/net/minecraft/server/RegistryBlockID.java
+++ b/src/main/java/net/minecraft/server/RegistryBlockID.java
2018-08-31 22:56:57 +00:00
@@ -54,6 +54,7 @@ public class RegistryBlockID<T> implements Registry<T> {
2018-08-26 02:37:58 +00:00
return Iterators.filter(this.c.iterator(), Predicates.notNull());
}
+ public int size() { return this.a(); } // Paper - OBFHELPER
public int a() {
return this.b.size();
}
2018-10-04 05:45:11 +00:00
diff --git a/src/main/java/net/minecraft/server/SystemUtils.java b/src/main/java/net/minecraft/server/SystemUtils.java
2018-10-19 03:24:09 +00:00
index 1f1cb6a1b..ced573d7f 100644
2018-10-04 05:45:11 +00:00
--- a/src/main/java/net/minecraft/server/SystemUtils.java
+++ b/src/main/java/net/minecraft/server/SystemUtils.java
@@ -34,8 +34,8 @@ public class SystemUtils {
return Collectors.toMap(Entry::getKey, Entry::getValue);
}
- public static <T extends Comparable<T>> String a(IBlockState<T> iblockstate, Object object) {
- return iblockstate.a((Comparable)object);
+ public static <T extends Comparable<T>> String a(IBlockState<T> iblockstate, T object) { // Paper - decompile fix
+ return iblockstate.a(object); // Paper - decompile fix
}
public static String a(String s, @Nullable MinecraftKey minecraftkey) {
@@ -43,11 +43,11 @@ public class SystemUtils {
}
public static long b() {
- return c() / 1000000L;
+ return System.nanoTime() / 1000000L; // Paper
}
public static long c() {
- return a.getAsLong();
+ return System.nanoTime(); // Paper
}
public static long d() {
@@ -109,7 +109,7 @@ public class SystemUtils {
futuretask.run();
return (V)futuretask.get();
} catch (ExecutionException executionexception) {
- logger.fatal("Error executing task", executionexception);
+ logger.fatal("Error executing task", executionexception.getCause() != null ? executionexception.getCause() : executionexception); // Paper
} catch (InterruptedException interruptedexception) {
logger.fatal("Error executing task", interruptedexception);
}
@@ -169,7 +169,7 @@ public class SystemUtils {
}
public static <K> Strategy<K> g() {
- return SystemUtils.IdentityHashingStrategy.INSTANCE;
+ return (Strategy<K>) IdentityHashingStrategy.INSTANCE; // Paper - decompile fix
}
static enum IdentityHashingStrategy implements Strategy<Object> {
2016-03-29 01:01:42 +00:00
--
2018-10-19 03:24:09 +00:00
2.19.1
2016-03-29 01:01:42 +00:00