From ba3cdc59cc60455ec327c55cf6221147a3632c65 Mon Sep 17 00:00:00 2001 From: beaness Date: Fri, 24 Jun 2022 19:14:59 +0200 Subject: [PATCH] FlamePaper patches + Upgrade netty --- TacoSpigot-Server/pom.xml | 2 +- .../java/net/minecraft/server/BlockChest.java | 7 +- .../main/java/net/minecraft/server/Chunk.java | 11 + .../minecraft/server/ChunkProviderServer.java | 12 +- .../java/net/minecraft/server/Container.java | 5 + .../java/net/minecraft/server/Entity.java | 6 + .../minecraft/server/IChatBaseComponent.java | 299 +++++++++++++++ .../java/net/minecraft/server/ItemStack.java | 12 + .../minecraft/server/LegacyPingHandler.java | 117 ++++++ .../net/minecraft/server/LoginListener.java | 3 +- .../net/minecraft/server/MinecraftServer.java | 37 +- .../net/minecraft/server/NetworkManager.java | 19 +- .../server/PacketDataSerializer.java | 363 +++++++++++++++++- .../server/PlayerInteractManager.java | 8 + .../minecraft/server/TileEntityBeacon.java | 260 ++++++------- .../minecraft/server/TileEntityHopper.java | 5 +- .../net/minecraft/server/WorldServer.java | 5 +- .../craftbukkit/inventory/CraftMetaBook.java | 5 +- 18 files changed, 978 insertions(+), 198 deletions(-) create mode 100644 TacoSpigot-Server/src/main/java/net/minecraft/server/IChatBaseComponent.java create mode 100644 TacoSpigot-Server/src/main/java/net/minecraft/server/LegacyPingHandler.java diff --git a/TacoSpigot-Server/pom.xml b/TacoSpigot-Server/pom.xml index 3e176f0..9b14d20 100644 --- a/TacoSpigot-Server/pom.xml +++ b/TacoSpigot-Server/pom.xml @@ -38,7 +38,7 @@ io.netty netty-all - 4.0.23.Final + 4.1.78.Final compile diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/BlockChest.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/BlockChest.java index b1bd620..0433fda 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/BlockChest.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/BlockChest.java @@ -48,7 +48,12 @@ public class BlockChest extends BlockContainer { for (EnumDirection enumdirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) { BlockPosition blockposition1 = blockposition.shift(enumdirection); - IBlockData iblockdata1 = world.getType(blockposition1); + // FlamePaper start - Dont load chunks for chests + final IBlockData iblockdata1 = world.isLoaded(blockposition1) ? world.getType(blockposition1) : null; + if (iblockdata1 == null) { + continue; + } + // FlamePaper end if (iblockdata1.getBlock() == this) { this.e(world, blockposition1, iblockdata1); diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java index 01480e5..7d12ba3 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/Chunk.java @@ -1491,4 +1491,15 @@ public class Chunk { private EnumTileEntityState() {} } + + // FlamePaper start - Hopper item lookup optimization + public int getItemCount(BlockPosition blockPosition) { + int k = MathHelper.floor(blockPosition.getY() / 16.0D); + + k = Math.max(0, k); + k = Math.min(this.entitySlices.length - 1, k); + + return itemCounts[k]; + } + // FlamePaper end - Hopper item lookup optimization } diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/ChunkProviderServer.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/ChunkProviderServer.java index 5d99555..f8709ba 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -264,7 +264,7 @@ public class ChunkProviderServer implements IChunkProvider { } public void saveChunkNOP(Chunk chunk) { - if (this.chunkLoader != null) { + if (canSave() && this.chunkLoader != null) { try { this.chunkLoader.b(this.world, chunk); } catch (Exception exception) { @@ -275,7 +275,7 @@ public class ChunkProviderServer implements IChunkProvider { } public void saveChunk(Chunk chunk) { - if (this.chunkLoader != null) { + if (canSave() && this.chunkLoader != null) { try { chunk.setLastSaved(this.world.getTime()); this.chunkLoader.a(this.world, chunk); @@ -410,8 +410,8 @@ public class ChunkProviderServer implements IChunkProvider { } // SportPaper end - public boolean unloadChunks() { - if (!this.world.savingDisabled) { + public boolean unloadChunks(boolean force) { + if (canSave() || force) { // CraftBukkit start Server server = this.world.getServer(); // SportPaper start @@ -434,6 +434,10 @@ public class ChunkProviderServer implements IChunkProvider { return this.chunkProvider.unloadChunks(); } + public boolean unloadChunks() { + return unloadChunks(false); + } + public boolean canSave() { return !this.world.savingDisabled; } diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/Container.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/Container.java index b26ec5c..08090e5 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/Container.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/Container.java @@ -106,6 +106,11 @@ public abstract class Container { } public Slot getSlot(int i) { + final int lastIndex = this.c.size() - 1; + + if (i > lastIndex) { + i = lastIndex; + } return this.c.get(i); } diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/Entity.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/Entity.java index 20fcc03..5a82d03 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/Entity.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/Entity.java @@ -463,6 +463,12 @@ public abstract class Entity implements ICommandListener { public void move(double d0, double d1, double d2) { if (this.loadChunks) loadChunks(); // PaperSpigot - Load chunks + // FlamePaper start - Disable Unloaded Chunk Movement + if (!world.chunkProvider.isChunkLoaded((int) locX >> 4, (int) locZ >> 4)) { + this.a(this.getBoundingBox().c(d0, d1, d2)); + this.recalcPosition(); + } else + // FlamePaper end - Disable Unloaded Chunk Movement if (this.noclip) { this.a(this.getBoundingBox().c(d0, d1, d2)); this.recalcPosition(); diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/IChatBaseComponent.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/IChatBaseComponent.java new file mode 100644 index 0000000..fce8303 --- /dev/null +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/IChatBaseComponent.java @@ -0,0 +1,299 @@ +package net.minecraft.server; + +import java.lang.reflect.Type; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +public interface IChatBaseComponent extends Iterable { + + IChatBaseComponent setChatModifier(ChatModifier chatmodifier); + + ChatModifier getChatModifier(); + + IChatBaseComponent a(String s); + + IChatBaseComponent addSibling(IChatBaseComponent ichatbasecomponent); + + String getText(); + + String c(); + + List a(); + + IChatBaseComponent f(); + + class ChatSerializer implements JsonDeserializer, JsonSerializer { + + private static final int CHATCOMPONENT_LIMIT = 128; + private static final Gson a; + + public ChatSerializer() {} + + public IChatBaseComponent a(int extraCount, String lastElement, JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) throws JsonParseException { + if (jsonelement.isJsonPrimitive()) { + return new ChatComponentText(jsonelement.getAsString()); + } else if (!jsonelement.isJsonObject()) { + if (jsonelement.isJsonArray()) { + JsonArray jsonarray = jsonelement.getAsJsonArray(); + + // FlamePaper start - Limit ChatComponents + if (jsonarray.size() > CHATCOMPONENT_LIMIT) { + throw new JsonParseException("Too many ChatComponent array elements"); + } + // FlamePaper end - Limit Chatcomponents + + IChatBaseComponent ichatbasecomponent = null; + Iterator iterator = jsonarray.iterator(); + + while (iterator.hasNext()) { + JsonElement jsonelement1 = (JsonElement) iterator.next(); + + // FlamePaper start - Limit ChatComponents + if (jsonelement1.isJsonArray()) { + throw new JsonParseException("Stacked ChatComponent array"); + } + // FlamePaper end - Limit Chatcomponents + + IChatBaseComponent ichatbasecomponent1 = this.a(jsonelement1, (Type) jsonelement1.getClass(), jsondeserializationcontext); + + if (ichatbasecomponent == null) { + ichatbasecomponent = ichatbasecomponent1; + } else { + ichatbasecomponent.addSibling(ichatbasecomponent1); + } + } + + return ichatbasecomponent; + } else { + throw new JsonParseException("Don\'t know how to turn " + jsonelement.toString() + " into a Component"); + } + } else { + JsonObject jsonobject = jsonelement.getAsJsonObject(); + Object object; + + if (jsonobject.has("text")) { + object = new ChatComponentText(jsonobject.get("text").getAsString()); + } else if (jsonobject.has("translate")) { + String s = jsonobject.get("translate").getAsString(); + + if (jsonobject.has("with")) { + JsonArray jsonarray1 = jsonobject.getAsJsonArray("with"); + + // FlamePaper start - Limit ChatComponents + if (jsonarray1.size() > CHATCOMPONENT_LIMIT) { + throw new JsonParseException("Too many ChatComponent array elements in with"); + } + // FlamePaper end - Limit Chatcomponents + + // FlamePaper start - Limit ChatComponents + if (lastElement != null && lastElement.equals("with")) { + throw new JsonParseException("Stacked with ChatComponent elements"); + } + // FlamePaper end - Limit Chatcomponents + + Object[] aobject = new Object[jsonarray1.size()]; + + for (int i = 0; i < aobject.length; ++i) { + // FlamePaper start - Limit ChatComponents + if (jsonarray1.get(i).isJsonArray()) { + throw new JsonParseException("Stacked ChatComponent array in with element"); + } + // FlamePaper end - Limit Chatcomponents + + aobject[i] = this.a(extraCount, "with", jsonarray1.get(i), type, jsondeserializationcontext); + if (aobject[i] instanceof ChatComponentText) { + ChatComponentText chatcomponenttext = (ChatComponentText) aobject[i]; + + if (chatcomponenttext.getChatModifier().g() && chatcomponenttext.a().isEmpty()) { + aobject[i] = chatcomponenttext.g(); + } + } + } + + object = new ChatMessage(s, aobject); + } else { + object = new ChatMessage(s, new Object[0]); + } + } else if (jsonobject.has("score")) { + JsonObject jsonobject1 = jsonobject.getAsJsonObject("score"); + + if (!jsonobject1.has("name") || !jsonobject1.has("objective")) { + throw new JsonParseException("A score component needs a least a name and an objective"); + } + + object = new ChatComponentScore(ChatDeserializer.h(jsonobject1, "name"), ChatDeserializer.h(jsonobject1, "objective")); + if (jsonobject1.has("value")) { + ((ChatComponentScore) object).b(ChatDeserializer.h(jsonobject1, "value")); + } + } else { + if (!jsonobject.has("selector")) { + throw new JsonParseException("Don\'t know how to turn " + jsonelement.toString() + " into a Component"); + } + + object = new ChatComponentSelector(ChatDeserializer.h(jsonobject, "selector")); + } + + if (jsonobject.has("extra")) { + JsonArray jsonarray2 = jsonobject.getAsJsonArray("extra"); + + // FlamePaper start - Limit ChatComponents + if (jsonarray2.size() > CHATCOMPONENT_LIMIT) { + throw new JsonParseException("Too many ChatComponent array elements in extra"); + } + // FlamePaper end - Limit Chatcomponents + + // FlamePaper start - Limit ChatComponents + if (extraCount > CHATCOMPONENT_LIMIT) { + throw new JsonParseException("Too many stacked extra ChatComponent elements"); + } + // FlamePaper end - Limit Chatcomponents + + if (jsonarray2.size() <= 0) { + throw new JsonParseException("Unexpected empty array of components"); + } + + for (int j = 0; j < jsonarray2.size(); ++j) { + // FlamePaper start - Limit ChatComponents + if (jsonarray2.get(j).isJsonArray()) { + throw new JsonParseException("Stacked ChatComponent array in extra element"); + } + // FlamePaper end - Limit Chatcomponents + + ((IChatBaseComponent) object).addSibling(this.a(++extraCount, "extra", jsonarray2.get(j), type, jsondeserializationcontext)); + } + } + + ((IChatBaseComponent) object).setChatModifier((ChatModifier) jsondeserializationcontext.deserialize(jsonelement, ChatModifier.class)); + return (IChatBaseComponent) object; + } + } + + public IChatBaseComponent a(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) throws JsonParseException { + return a(0, null, jsonelement, type, jsondeserializationcontext); + } + + private void a(ChatModifier chatmodifier, JsonObject jsonobject, JsonSerializationContext jsonserializationcontext) { + JsonElement jsonelement = jsonserializationcontext.serialize(chatmodifier); + + if (jsonelement.isJsonObject()) { + JsonObject jsonobject1 = (JsonObject) jsonelement; + Iterator iterator = jsonobject1.entrySet().iterator(); + + while (iterator.hasNext()) { + Entry entry = (Entry) iterator.next(); + + jsonobject.add((String) entry.getKey(), (JsonElement) entry.getValue()); + } + } + + } + + public JsonElement a(IChatBaseComponent ichatbasecomponent, Type type, JsonSerializationContext jsonserializationcontext) { + if (ichatbasecomponent instanceof ChatComponentText && ichatbasecomponent.getChatModifier().g() && ichatbasecomponent.a().isEmpty()) { + return new JsonPrimitive(((ChatComponentText) ichatbasecomponent).g()); + } else { + JsonObject jsonobject = new JsonObject(); + + if (!ichatbasecomponent.getChatModifier().g()) { + this.a(ichatbasecomponent.getChatModifier(), jsonobject, jsonserializationcontext); + } + + if (!ichatbasecomponent.a().isEmpty()) { + JsonArray jsonarray = new JsonArray(); + Iterator iterator = ichatbasecomponent.a().iterator(); + + while (iterator.hasNext()) { + IChatBaseComponent ichatbasecomponent1 = (IChatBaseComponent) iterator.next(); + + jsonarray.add(this.a(ichatbasecomponent1, (Type) ichatbasecomponent1.getClass(), jsonserializationcontext)); + } + + jsonobject.add("extra", jsonarray); + } + + if (ichatbasecomponent instanceof ChatComponentText) { + jsonobject.addProperty("text", ((ChatComponentText) ichatbasecomponent).g()); + } else if (ichatbasecomponent instanceof ChatMessage) { + ChatMessage chatmessage = (ChatMessage) ichatbasecomponent; + + jsonobject.addProperty("translate", chatmessage.i()); + if (chatmessage.j() != null && chatmessage.j().length > 0) { + JsonArray jsonarray1 = new JsonArray(); + Object[] aobject = chatmessage.j(); + int i = aobject.length; + + for (int j = 0; j < i; ++j) { + Object object = aobject[j]; + + if (object instanceof IChatBaseComponent) { + jsonarray1.add(this.a((IChatBaseComponent) object, (Type) object.getClass(), jsonserializationcontext)); + } else { + jsonarray1.add(new JsonPrimitive(String.valueOf(object))); + } + } + + jsonobject.add("with", jsonarray1); + } + } else if (ichatbasecomponent instanceof ChatComponentScore) { + ChatComponentScore chatcomponentscore = (ChatComponentScore) ichatbasecomponent; + JsonObject jsonobject1 = new JsonObject(); + + jsonobject1.addProperty("name", chatcomponentscore.g()); + jsonobject1.addProperty("objective", chatcomponentscore.h()); + jsonobject1.addProperty("value", chatcomponentscore.getText()); + jsonobject.add("score", jsonobject1); + } else { + if (!(ichatbasecomponent instanceof ChatComponentSelector)) { + throw new IllegalArgumentException("Don\'t know how to serialize " + ichatbasecomponent + " as a Component"); + } + + ChatComponentSelector chatcomponentselector = (ChatComponentSelector) ichatbasecomponent; + + jsonobject.addProperty("selector", chatcomponentselector.g()); + } + + return jsonobject; + } + } + + public static String a(IChatBaseComponent ichatbasecomponent) { + return IChatBaseComponent.ChatSerializer.a.toJson(ichatbasecomponent); + } + + public static IChatBaseComponent a(String s) { + return (IChatBaseComponent) IChatBaseComponent.ChatSerializer.a.fromJson(s, IChatBaseComponent.class); + } + + @Override + public JsonElement serialize(IChatBaseComponent object, Type type, JsonSerializationContext jsonserializationcontext) { + return this.a((IChatBaseComponent) object, type, jsonserializationcontext); + } + + @Override + public IChatBaseComponent deserialize(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) throws JsonParseException { + return this.a(jsonelement, type, jsondeserializationcontext); + } + + static { + GsonBuilder gsonbuilder = new GsonBuilder(); + + gsonbuilder.registerTypeHierarchyAdapter(IChatBaseComponent.class, new IChatBaseComponent.ChatSerializer()); + gsonbuilder.registerTypeHierarchyAdapter(ChatModifier.class, new ChatModifier.ChatModifierSerializer()); + gsonbuilder.registerTypeAdapterFactory(new ChatTypeAdapterFactory()); + a = gsonbuilder.create(); + } + } +} \ No newline at end of file diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/ItemStack.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/ItemStack.java index a3ff1b5..53fe471 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/ItemStack.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/ItemStack.java @@ -154,6 +154,18 @@ public final class ItemStack { org.bukkit.event.block.BlockPlaceEvent placeEvent = null; List blocks = (List) world.capturedBlockStates.clone(); world.capturedBlockStates.clear(); + + // FlamePaper start - Disable Nether Roof Interaction + if (world.getWorld().getEnvironment() == org.bukkit.World.Environment.NETHER) { + for (BlockState block : blocks) { + if (block.getY() >= 127) { + entityhuman.getBukkitEntity().sendMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&', "&cCan't build on nether roof")); + return false; + } + } + } + // FlamePaper end - Disable Nether Roof Interaction + if (blocks.size() > 1) { placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockMultiPlaceEvent(world, entityhuman, blocks, blockposition.getX(), blockposition.getY(), blockposition.getZ()); } else if (blocks.size() == 1) { diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/LegacyPingHandler.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/LegacyPingHandler.java new file mode 100644 index 0000000..047d1d2 --- /dev/null +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/LegacyPingHandler.java @@ -0,0 +1,117 @@ +package net.minecraft.server; + +import com.google.common.base.Charsets; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import java.net.InetSocketAddress; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class LegacyPingHandler extends ChannelInboundHandlerAdapter { + + private static final Logger a = LogManager.getLogger(); + private ServerConnection b; + + public LegacyPingHandler(ServerConnection serverconnection) { + this.b = serverconnection; + } + + public void channelRead(ChannelHandlerContext channelhandlercontext, Object object) throws Exception { + ByteBuf bytebuf = (ByteBuf) object; + + bytebuf.markReaderIndex(); + boolean flag = true; + + try { + if (bytebuf.readUnsignedByte() == 254) { + InetSocketAddress inetsocketaddress = (InetSocketAddress) channelhandlercontext.channel().remoteAddress(); + MinecraftServer minecraftserver = this.b.d(); + int i = bytebuf.readableBytes(); + String s; + + switch (i) { + case 0: + LegacyPingHandler.a.debug("Ping: (<1.3.x) from {}:{}", inetsocketaddress.getAddress(), inetsocketaddress.getPort()); + s = String.format("%s\u00a7%d\u00a7%d", minecraftserver.getMotd(), minecraftserver.I(), minecraftserver.J()); + this.a(channelhandlercontext, this.a(s)); + break; + + case 1: + if (bytebuf.readUnsignedByte() != 1) { + return; + } + + LegacyPingHandler.a.debug("Ping: (1.4-1.5.x) from {}:{}", inetsocketaddress.getAddress(), inetsocketaddress.getPort()); + s = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", 127, minecraftserver.getVersion(), minecraftserver.getMotd(), minecraftserver.I(), minecraftserver.J()); + this.a(channelhandlercontext, this.a(s)); + break; + + default: + boolean flag1 = bytebuf.readUnsignedByte() == 1; + + flag1 &= bytebuf.readUnsignedByte() == 250; + flag1 &= "MC|PingHost".equals(new String(bytebuf.readBytes(bytebuf.readShort() * 2).array(), Charsets.UTF_16BE)); + int j = bytebuf.readUnsignedShort(); + + flag1 &= bytebuf.readUnsignedByte() >= 73; + flag1 &= 3 + bytebuf.readBytes(bytebuf.readShort() * 2).array().length + 4 == j; + flag1 &= bytebuf.readInt() <= '\uffff'; + flag1 &= bytebuf.readableBytes() == 0; + if (!flag1) { + return; + } + + LegacyPingHandler.a.debug("Ping: (1.6) from {}:{}", inetsocketaddress.getAddress(), inetsocketaddress.getPort()); + String s1 = String.format("\u00a71\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", 127, minecraftserver.getVersion(), minecraftserver.getMotd(), minecraftserver.I(), minecraftserver.J()); + ByteBuf bytebuf1 = this.a(s1); + + try { + this.a(channelhandlercontext, bytebuf1); + } finally { + bytebuf1.release(); + } + } + + bytebuf.release(); + flag = false; + return; + } + } catch (RuntimeException runtimeexception) { + return; + } finally { + if (flag) { + bytebuf.resetReaderIndex(); + channelhandlercontext.channel().pipeline().remove("legacy_query"); + channelhandlercontext.fireChannelRead(object); + } + + } + + } + + private void a(ChannelHandlerContext channelhandlercontext, ByteBuf bytebuf) { + channelhandlercontext.pipeline().firstContext().writeAndFlush(bytebuf).addListener(ChannelFutureListener.CLOSE); + } + + private ByteBuf a(String s) { + ByteBuf bytebuf = Unpooled.buffer(); + + bytebuf.writeByte(255); + char[] achar = s.toCharArray(); + + bytebuf.writeShort(achar.length); + char[] achar1 = achar; + int i = achar.length; + + for (int j = 0; j < i; ++j) { + char c0 = achar1[j]; + + bytebuf.writeChar(c0); + } + + return bytebuf; + } +} \ No newline at end of file diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/LoginListener.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/LoginListener.java index 66f5242..d02d577 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/LoginListener.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/LoginListener.java @@ -166,7 +166,8 @@ public class LoginListener implements PacketLoginInListener, IUpdatePlayerListBo } public String d() { - return this.i != null ? this.i + " (" + this.networkManager.getSocketAddress().toString() + ")" : String.valueOf(this.networkManager.getSocketAddress()); + String socketAddress = networkManager == null ? null : (networkManager.getSocketAddress() == null ? null : networkManager.getSocketAddress().toString()); + return this.i != null ? this.i.toString() + " (" + socketAddress + ")" : socketAddress; } public void a(PacketLoginInStart packetlogininstart) { diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/MinecraftServer.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/MinecraftServer.java index 2309fe3..2bc1b52 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/MinecraftServer.java @@ -514,47 +514,12 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs } protected void k() { - boolean flag = true; - boolean flag1 = true; - boolean flag2 = true; - boolean flag3 = true; - int i = 0; - this.b("menu.generatingTerrain"); - byte b0 = 0; - - // CraftBukkit start - fire WorldLoadEvent and handle whether or not to keep the spawn in memory - for (int m = 0; m < worlds.size(); m++) { - WorldServer worldserver = this.worlds.get(m); - LOGGER.info("Preparing start region for level " + m + " (Seed: " + worldserver.getSeed() + ")"); - - if (!worldserver.getWorld().getKeepSpawnInMemory()) { - continue; - } - - BlockPosition blockposition = worldserver.getSpawn(); - long j = az(); - i = 0; - - for (int k = -192; k <= 192 && this.isRunning(); k += 16) { - for (int l = -192; l <= 192 && this.isRunning(); l += 16) { - long i1 = az(); - - if (i1 - j > 1000L) { - this.a_("Preparing spawn area", i * 100 / 625); - j = i1; - } - - ++i; - worldserver.chunkProviderServer.getChunkAt(blockposition.getX() + k >> 4, blockposition.getZ() + l >> 4); - } - } - } for (WorldServer world : this.worlds) { this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(world.getWorld())); } - // CraftBukkit end + this.s(); } // PaperSpigot End diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/NetworkManager.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/NetworkManager.java index d4ca8f3..e113ef0 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/NetworkManager.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/NetworkManager.java @@ -127,12 +127,14 @@ public class NetworkManager extends SimpleChannelInboundHandler { this.channel = channelhandlercontext.channel(); this.l = this.channel.remoteAddress(); // eSpigot start - this.channel.config().setOption(ChannelOption.SO_KEEPALIVE, true); - this.channel.config().setOption(ChannelOption.TCP_NODELAY, true); - this.channel.config().setOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); - this.channel.config().setOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024); - this.channel.config().setOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024); - this.channel.config().setOption(ChannelOption.IP_TOS, 0x18); + ChannelConfig config = this.channel.config(); + config.setOption(ChannelOption.SO_KEEPALIVE, true); + config.setOption(ChannelOption.TCP_NODELAY, true); + config.setOption(ChannelOption.TCP_FASTOPEN, 1); + config.setOption(ChannelOption.TCP_FASTOPEN_CONNECT, true); + config.setOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); + config.setOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024)); + config.setOption(ChannelOption.IP_TOS, 0x18); // eSpigot end // Spigot Start @@ -478,7 +480,10 @@ public class NetworkManager extends SimpleChannelInboundHandler { } protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet object) throws Exception { // CraftBukkit - fix decompile error - this.a(channelhandlercontext, object); + // FlamePaper - Check if channel is opened before reading packet + if (g()) { + this.a(channelhandlercontext, object); + } } // Spigot Start diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/PacketDataSerializer.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/PacketDataSerializer.java index 1908185..e06e300 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/PacketDataSerializer.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/PacketDataSerializer.java @@ -16,11 +16,14 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.channels.FileChannel; import java.nio.channels.GatheringByteChannel; import java.nio.channels.ScatteringByteChannel; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.UUID; +import io.netty.util.ByteProcessor; import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit // TacoSpigot start import net.techcable.tacospigot.CompatHacks; @@ -185,7 +188,7 @@ public class PacketDataSerializer extends ByteBuf { return null; } else { this.readerIndex(i); - return NBTCompressedStreamTools.a(new ByteBufInputStream(this), new NBTReadLimiter(2097152L)); + return NBTCompressedStreamTools.a(new ByteBufInputStream(this), new NBTReadLimiter(64000L)); // FlamePaper - Reduce NBT read limit } } @@ -239,7 +242,8 @@ public class PacketDataSerializer extends ByteBuf { } else if (j < 0) { throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!"); } else { - String s = new String(this.readBytes(j).array(), Charsets.UTF_8); + String s = toString(readerIndex(), j, StandardCharsets.UTF_8); + readerIndex(readerIndex() + j); if (s.length() > i) { throw new DecoderException("The received string length is longer than maximum allowed (" + j + " > " + i + ")"); @@ -259,8 +263,8 @@ public class PacketDataSerializer extends ByteBuf { throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!"); } else { int len = Math.min(toRead, maxLength); - String s = new String(this.readBytes(len).array(), Charsets.UTF_8); - + String s = toString(readerIndex(), len, StandardCharsets.UTF_8); + readerIndex(readerIndex() + len); int remaining = toRead - len; if (remaining > 0) { this.skipBytes(remaining); @@ -283,462 +287,761 @@ public class PacketDataSerializer extends ByteBuf { } } + @Override public int capacity() { return this.a.capacity(); } + @Override public ByteBuf capacity(int i) { return this.a.capacity(i); } + @Override public int maxCapacity() { return this.a.maxCapacity(); } + @Override public ByteBufAllocator alloc() { return this.a.alloc(); } + @Override public ByteOrder order() { return this.a.order(); } + @Override public ByteBuf order(ByteOrder byteorder) { return this.a.order(byteorder); } + @Override public ByteBuf unwrap() { return this.a.unwrap(); } + @Override public boolean isDirect() { return this.a.isDirect(); } + @Override + public boolean isReadOnly() { + return this.a.isReadOnly(); + } + + @Override + public ByteBuf asReadOnly() { + return this.a.asReadOnly(); + } + + @Override public int readerIndex() { return this.a.readerIndex(); } + @Override public ByteBuf readerIndex(int i) { return this.a.readerIndex(i); } + @Override public int writerIndex() { return this.a.writerIndex(); } + @Override public ByteBuf writerIndex(int i) { return this.a.writerIndex(i); } + @Override public ByteBuf setIndex(int i, int j) { return this.a.setIndex(i, j); } + @Override public int readableBytes() { return this.a.readableBytes(); } + @Override public int writableBytes() { return this.a.writableBytes(); } + @Override public int maxWritableBytes() { return this.a.maxWritableBytes(); } + @Override public boolean isReadable() { return this.a.isReadable(); } + @Override public boolean isReadable(int i) { return this.a.isReadable(i); } + @Override public boolean isWritable() { return this.a.isWritable(); } + @Override public boolean isWritable(int i) { return this.a.isWritable(i); } + @Override public ByteBuf clear() { return this.a.clear(); } + @Override public ByteBuf markReaderIndex() { return this.a.markReaderIndex(); } + @Override public ByteBuf resetReaderIndex() { return this.a.resetReaderIndex(); } + @Override public ByteBuf markWriterIndex() { return this.a.markWriterIndex(); } + @Override public ByteBuf resetWriterIndex() { return this.a.resetWriterIndex(); } + @Override public ByteBuf discardReadBytes() { return this.a.discardReadBytes(); } + @Override public ByteBuf discardSomeReadBytes() { return this.a.discardSomeReadBytes(); } + @Override public ByteBuf ensureWritable(int i) { return this.a.ensureWritable(i); } + @Override public int ensureWritable(int i, boolean flag) { return this.a.ensureWritable(i, flag); } + @Override public boolean getBoolean(int i) { return this.a.getBoolean(i); } + @Override public byte getByte(int i) { return this.a.getByte(i); } + @Override public short getUnsignedByte(int i) { return this.a.getUnsignedByte(i); } + @Override public short getShort(int i) { return this.a.getShort(i); } + @Override + public short getShortLE(int i) { + return this.a.getShortLE(i); + } + + @Override public int getUnsignedShort(int i) { return this.a.getUnsignedShort(i); } + @Override + public int getUnsignedShortLE(int i) { + return this.a.getUnsignedShortLE(i); + } + + @Override public int getMedium(int i) { return this.a.getMedium(i); } + @Override + public int getMediumLE(int i) { + return this.a.getMediumLE(i); + } + + @Override public int getUnsignedMedium(int i) { return this.a.getUnsignedMedium(i); } + @Override + public int getUnsignedMediumLE(int i) { + return this.a.getUnsignedMediumLE(i); + } + + @Override public int getInt(int i) { return this.a.getInt(i); } + @Override + public int getIntLE(int i) { + return this.a.getIntLE(i); + } + + @Override public long getUnsignedInt(int i) { return this.a.getUnsignedInt(i); } + @Override + public long getUnsignedIntLE(int i) { + return this.a.getUnsignedIntLE(i); + } + + @Override + public long getLongLE(int i) { + return this.a.getLongLE(i); + } + + @Override public long getLong(int i) { return this.a.getLong(i); } + @Override public char getChar(int i) { return this.a.getChar(i); } + @Override public float getFloat(int i) { return this.a.getFloat(i); } + @Override public double getDouble(int i) { return this.a.getDouble(i); } + @Override public ByteBuf getBytes(int i, ByteBuf bytebuf) { return this.a.getBytes(i, bytebuf); } + @Override public ByteBuf getBytes(int i, ByteBuf bytebuf, int j) { return this.a.getBytes(i, bytebuf, j); } + @Override public ByteBuf getBytes(int i, ByteBuf bytebuf, int j, int k) { return this.a.getBytes(i, bytebuf, j, k); } + @Override public ByteBuf getBytes(int i, byte[] abyte) { return this.a.getBytes(i, abyte); } + @Override public ByteBuf getBytes(int i, byte[] abyte, int j, int k) { return this.a.getBytes(i, abyte, j, k); } + @Override public ByteBuf getBytes(int i, ByteBuffer bytebuffer) { return this.a.getBytes(i, bytebuffer); } + @Override public ByteBuf getBytes(int i, OutputStream outputstream, int j) throws IOException { return this.a.getBytes(i, outputstream, j); } + @Override public int getBytes(int i, GatheringByteChannel gatheringbytechannel, int j) throws IOException { return this.a.getBytes(i, gatheringbytechannel, j); } + @Override + public int getBytes(int i, FileChannel fileChannel, long l, int i1) throws IOException { + return this.a.getBytes(i, fileChannel, l, i1); + } + + @Override + public CharSequence getCharSequence(int i, int j, Charset charset) { + return this.a.getCharSequence(i, j, charset); + } + + @Override public ByteBuf setBoolean(int i, boolean flag) { return this.a.setBoolean(i, flag); } + @Override public ByteBuf setByte(int i, int j) { return this.a.setByte(i, j); } + @Override public ByteBuf setShort(int i, int j) { return this.a.setShort(i, j); } + @Override + public ByteBuf setShortLE(int i, int j) { + return this.a.setShortLE(i, j); + } + + @Override public ByteBuf setMedium(int i, int j) { return this.a.setMedium(i, j); } + @Override + public ByteBuf setMediumLE(int i, int j) { + return this.a.setMediumLE(i, j); + } + + @Override public ByteBuf setInt(int i, int j) { return this.a.setInt(i, j); } + @Override + public ByteBuf setIntLE(int i, int j) { + return this.a.setIntLE(i, j); + } + + @Override public ByteBuf setLong(int i, long j) { return this.a.setLong(i, j); } + @Override + public ByteBuf setLongLE(int i, long j) { + return this.a.setLongLE(i, j); + } + + @Override public ByteBuf setChar(int i, int j) { return this.a.setChar(i, j); } + @Override public ByteBuf setFloat(int i, float f) { return this.a.setFloat(i, f); } + @Override public ByteBuf setDouble(int i, double d0) { return this.a.setDouble(i, d0); } + @Override public ByteBuf setBytes(int i, ByteBuf bytebuf) { return this.a.setBytes(i, bytebuf); } + @Override public ByteBuf setBytes(int i, ByteBuf bytebuf, int j) { return this.a.setBytes(i, bytebuf, j); } + @Override public ByteBuf setBytes(int i, ByteBuf bytebuf, int j, int k) { return this.a.setBytes(i, bytebuf, j, k); } + @Override public ByteBuf setBytes(int i, byte[] abyte) { return this.a.setBytes(i, abyte); } + @Override public ByteBuf setBytes(int i, byte[] abyte, int j, int k) { return this.a.setBytes(i, abyte, j, k); } + @Override public ByteBuf setBytes(int i, ByteBuffer bytebuffer) { return this.a.setBytes(i, bytebuffer); } + @Override public int setBytes(int i, InputStream inputstream, int j) throws IOException { return this.a.setBytes(i, inputstream, j); } + @Override public int setBytes(int i, ScatteringByteChannel scatteringbytechannel, int j) throws IOException { return this.a.setBytes(i, scatteringbytechannel, j); } + @Override + public int setBytes(int i, FileChannel filechannel, long j, int k) throws IOException { + return this.a.setBytes(i, filechannel, j, k); + } + + @Override public ByteBuf setZero(int i, int j) { return this.a.setZero(i, j); } + @Override + public int setCharSequence(int i, CharSequence charsequence, Charset charset) { + return this.a.setCharSequence(i, charsequence, charset); + } + + @Override public boolean readBoolean() { return this.a.readBoolean(); } + @Override public byte readByte() { return this.a.readByte(); } + @Override public short readUnsignedByte() { return this.a.readUnsignedByte(); } + @Override public short readShort() { return this.a.readShort(); } + @Override + public short readShortLE() { + return this.a.readShortLE(); + } + + @Override public int readUnsignedShort() { return this.a.readUnsignedShort(); } + @Override + public int readUnsignedShortLE() { + return this.a.readUnsignedShortLE(); + } + + @Override public int readMedium() { return this.a.readMedium(); } + @Override + public int readMediumLE() { + return this.a.readMediumLE(); + } + + @Override public int readUnsignedMedium() { return this.a.readUnsignedMedium(); } + @Override + public int readUnsignedMediumLE() { + return this.a.readUnsignedMediumLE(); + } + + @Override public int readInt() { return this.a.readInt(); } + @Override + public int readIntLE() { + return this.a.readIntLE(); + } + + @Override public long readUnsignedInt() { return this.a.readUnsignedInt(); } + @Override + public long readUnsignedIntLE() { + return this.a.readUnsignedIntLE(); + } + + @Override public long readLong() { return this.a.readLong(); } + @Override + public long readLongLE() { + return this.a.readLongLE(); + } + + @Override public char readChar() { return this.a.readChar(); } + @Override public float readFloat() { return this.a.readFloat(); } + @Override public double readDouble() { return this.a.readDouble(); } + @Override public ByteBuf readBytes(int i) { return this.a.readBytes(i); } + @Override public ByteBuf readSlice(int i) { return this.a.readSlice(i); } + @Override + public ByteBuf readRetainedSlice(int i) { + return this.a.readRetainedSlice(i); + } + + @Override public ByteBuf readBytes(ByteBuf bytebuf) { return this.a.readBytes(bytebuf); } + @Override public ByteBuf readBytes(ByteBuf bytebuf, int i) { return this.a.readBytes(bytebuf, i); } + @Override public ByteBuf readBytes(ByteBuf bytebuf, int i, int j) { return this.a.readBytes(bytebuf, i, j); } + @Override public ByteBuf readBytes(byte[] abyte) { return this.a.readBytes(abyte); } + @Override public ByteBuf readBytes(byte[] abyte, int i, int j) { return this.a.readBytes(abyte, i, j); } + @Override public ByteBuf readBytes(ByteBuffer bytebuffer) { return this.a.readBytes(bytebuffer); } + @Override public ByteBuf readBytes(OutputStream outputstream, int i) throws IOException { return this.a.readBytes(outputstream, i); } + @Override public int readBytes(GatheringByteChannel gatheringbytechannel, int i) throws IOException { return this.a.readBytes(gatheringbytechannel, i); } + @Override + public CharSequence readCharSequence(int i, Charset charset) { + return this.a.readCharSequence(i, charset); + } + + @Override + public int readBytes(FileChannel filechannel, long i, int j) throws IOException { + return this.a.readBytes(filechannel, i, j); + } + + @Override public ByteBuf skipBytes(int i) { return this.a.skipBytes(i); } + @Override public ByteBuf writeBoolean(boolean flag) { return this.a.writeBoolean(flag); } + @Override public ByteBuf writeByte(int i) { return this.a.writeByte(i); } + @Override public ByteBuf writeShort(int i) { return this.a.writeShort(i); } + @Override + public ByteBuf writeShortLE(int i) { + return this.a.writeShortLE(i); + } + + @Override public ByteBuf writeMedium(int i) { return this.a.writeMedium(i); } + @Override + public ByteBuf writeMediumLE(int i) { + return this.a.writeMediumLE(i); + } + + @Override public ByteBuf writeInt(int i) { return this.a.writeInt(i); } + @Override + public ByteBuf writeIntLE(int i) { + return this.a.writeIntLE(i); + } + + @Override public ByteBuf writeLong(long i) { return this.a.writeLong(i); } + @Override + public ByteBuf writeLongLE(long i) { + return this.a.writeLongLE(i); + } + + @Override public ByteBuf writeChar(int i) { return this.a.writeChar(i); } + @Override public ByteBuf writeFloat(float f) { return this.a.writeFloat(f); } + @Override public ByteBuf writeDouble(double d0) { return this.a.writeDouble(d0); } + @Override public ByteBuf writeBytes(ByteBuf bytebuf) { return this.a.writeBytes(bytebuf); } + @Override public ByteBuf writeBytes(ByteBuf bytebuf, int i) { return this.a.writeBytes(bytebuf, i); } + @Override public ByteBuf writeBytes(ByteBuf bytebuf, int i, int j) { return this.a.writeBytes(bytebuf, i, j); } + @Override public ByteBuf writeBytes(byte[] abyte) { return this.a.writeBytes(abyte); } + @Override public ByteBuf writeBytes(byte[] abyte, int i, int j) { return this.a.writeBytes(abyte, i, j); } + @Override public ByteBuf writeBytes(ByteBuffer bytebuffer) { return this.a.writeBytes(bytebuffer); } + @Override public int writeBytes(InputStream inputstream, int i) throws IOException { return this.a.writeBytes(inputstream, i); } + @Override public int writeBytes(ScatteringByteChannel scatteringbytechannel, int i) throws IOException { return this.a.writeBytes(scatteringbytechannel, i); } + @Override + public int writeBytes(FileChannel filechannel, long i, int j) throws IOException { + return this.a.writeBytes(filechannel, i, j); + } + + @Override public ByteBuf writeZero(int i) { return this.a.writeZero(i); } + @Override + public int writeCharSequence(CharSequence charsequence, Charset charset) { + return this.a.writeCharSequence(charsequence, charset); + } + + @Override public int indexOf(int i, int j, byte b0) { return this.a.indexOf(i, j, b0); } + @Override public int bytesBefore(byte b0) { return this.a.bytesBefore(b0); } + @Override public int bytesBefore(int i, byte b0) { return this.a.bytesBefore(i, b0); } + @Override public int bytesBefore(int i, int j, byte b0) { return this.a.bytesBefore(i, j, b0); } + @Override + public int forEachByte(int i, int j, ByteProcessor byteprocessor) { + return this.a.forEachByte(i, j, byteprocessor); + } + + @Override + public int forEachByte(ByteProcessor byteprocessor) { + return this.a.forEachByte(byteprocessor); + } + + @Override + public int forEachByteDesc(ByteProcessor byteprocessor) { + return this.a.forEachByteDesc(byteprocessor); + } + + @Override + public int forEachByteDesc(int i, int j, ByteProcessor byteprocessor) { + return this.a.forEachByteDesc(i, j, byteprocessor); + } + public int forEachByte(ByteBufProcessor bytebufprocessor) { return this.a.forEachByte(bytebufprocessor); } @@ -755,110 +1058,162 @@ public class PacketDataSerializer extends ByteBuf { return this.a.forEachByteDesc(i, j, bytebufprocessor); } + @Override public ByteBuf copy() { return this.a.copy(); } + @Override public ByteBuf copy(int i, int j) { return this.a.copy(i, j); } + @Override public ByteBuf slice() { return this.a.slice(); } + @Override + public ByteBuf retainedSlice() { + return this.a.retainedSlice(); + } + + @Override public ByteBuf slice(int i, int j) { return this.a.slice(i, j); } + @Override + public ByteBuf retainedSlice(int i, int i1) { + return this.a.readRetainedSlice(i); + } + + @Override public ByteBuf duplicate() { return this.a.duplicate(); } + @Override + public ByteBuf retainedDuplicate() { + return this.a.retainedDuplicate(); + } + + @Override public int nioBufferCount() { return this.a.nioBufferCount(); } + @Override public ByteBuffer nioBuffer() { return this.a.nioBuffer(); } + @Override public ByteBuffer nioBuffer(int i, int j) { return this.a.nioBuffer(i, j); } + @Override public ByteBuffer internalNioBuffer(int i, int j) { return this.a.internalNioBuffer(i, j); } + @Override public ByteBuffer[] nioBuffers() { return this.a.nioBuffers(); } + @Override public ByteBuffer[] nioBuffers(int i, int j) { return this.a.nioBuffers(i, j); } + @Override public boolean hasArray() { return this.a.hasArray(); } + @Override public byte[] array() { return this.a.array(); } + @Override public int arrayOffset() { return this.a.arrayOffset(); } + @Override public boolean hasMemoryAddress() { return this.a.hasMemoryAddress(); } + @Override public long memoryAddress() { return this.a.memoryAddress(); } + @Override public String toString(Charset charset) { return this.a.toString(charset); } + @Override public String toString(int i, int j, Charset charset) { return this.a.toString(i, j, charset); } + @Override public int hashCode() { return this.a.hashCode(); } + @Override public boolean equals(Object object) { return this.a.equals(object); } + @Override public int compareTo(ByteBuf bytebuf) { return this.a.compareTo(bytebuf); } + @Override public String toString() { return this.a.toString(); } + @Override public ByteBuf retain(int i) { return this.a.retain(i); } + @Override public ByteBuf retain() { return this.a.retain(); } + @Override + public ByteBuf touch() { + return this.a.touch(); + } + + @Override + public ByteBuf touch(Object o) { + return this.a.touch(o); + } + + @Override public int refCnt() { return this.a.refCnt(); } + @Override public boolean release() { return this.a.release(); } + @Override public boolean release(int i) { return this.a.release(i); } diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/PlayerInteractManager.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/PlayerInteractManager.java index 68c93a8..09a1d8f 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/PlayerInteractManager.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/PlayerInteractManager.java @@ -251,6 +251,14 @@ public class PlayerInteractManager { BlockBreakEvent event = null; if (this.player instanceof EntityPlayer) { + // FlamePaper start - Disable Nether Roof Interaction + if (world.getWorld().getEnvironment() == org.bukkit.World.Environment.NETHER && + blockposition.getY() >= 127) { + this.player.getBukkitEntity().sendMessage(org.bukkit.ChatColor.translateAlternateColorCodes('&', "&cCan't build on nether roof")); + this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition)); + return false; + } + // FlamePaper end - Disable Nether Roof Interaction org.bukkit.block.Block block = this.world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); // Sword + Creative mode pre-cancel diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/TileEntityBeacon.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/TileEntityBeacon.java index 5f6a41a..9fc40a3 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/TileEntityBeacon.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/TileEntityBeacon.java @@ -1,39 +1,56 @@ package net.minecraft.server; -import com.google.common.collect.Lists; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; +//import com.google.common.collect.Lists; +//import java.util.Arrays; -// CraftBukkit start import org.bukkit.craftbukkit.entity.CraftHumanEntity; -import org.bukkit.entity.HumanEntity; -// CraftBukkit end - -// PaperSpigot start import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.github.paperspigot.event.block.BeaconEffectEvent; + +import java.util.List; // PaperSpigot end public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlayerListBox, IInventory { - public static final MobEffectList[][] a = new MobEffectList[][] { { MobEffectList.FASTER_MOVEMENT, MobEffectList.FASTER_DIG}, { MobEffectList.RESISTANCE, MobEffectList.JUMP}, { MobEffectList.INCREASE_DAMAGE}, { MobEffectList.REGENERATION}}; - private final List f = Lists.newArrayList(); + public static final MobEffectList[][] a = new MobEffectList[][]{{MobEffectList.FASTER_MOVEMENT, MobEffectList.FASTER_DIG}, {MobEffectList.RESISTANCE, MobEffectList.JUMP}, {MobEffectList.INCREASE_DAMAGE}, {MobEffectList.REGENERATION}}; + // CraftBukkit start - add fields and methods + public List transaction = new java.util.ArrayList(); + // private final List f = Lists.newArrayList(); private boolean i; private int j = -1; private int k; private int l; private ItemStack inventorySlot; private String n; - // CraftBukkit start - add fields and methods - public List transaction = new java.util.ArrayList<>(); private int maxStack = MAX_STACK; + public TileEntityBeacon() { + } + + // NextSpigot - Start + public boolean isEnabled() { + return i; + } + + public void setEnabled(boolean state) { + this.i = state; + } + + public int getLevel() { + return j; + } + + public void setLevel(int newLevel) { + this.j = newLevel; + } + // NextSpigot - end + public ItemStack[] getContents() { - return new ItemStack[] { this.inventorySlot }; + return new ItemStack[]{this.inventorySlot}; } public void onOpen(CraftHumanEntity who) { @@ -47,14 +64,8 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay public List getViewers() { return transaction; } - - public void setMaxStackSize(int size) { - maxStack = size; - } // CraftBukkit end - public TileEntityBeacon() {} - public void c() { if (this.world.getTime() % 80L == 0L) { this.m(); @@ -68,29 +79,28 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay } private void A() { - if (this.i && this.j > 0 && !this.world.isClientSide && this.k > 0) { - double d0 = this.j * 10 + 10; + if (isEnabled() && getLevel() > 0 && !this.world.isClientSide && this.k > 0) { + double radius = getLevel() * 10 + 10; byte b0 = 0; - if (this.j >= 4 && this.k == this.l) { + if (getLevel() >= 4 && this.k == this.l) { b0 = 1; } - int i = this.position.getX(); - int j = this.position.getY(); - int k = this.position.getZ(); - AxisAlignedBB axisalignedbb = (new AxisAlignedBB(i, j, k, i + 1, j + 1, k + 1)).grow(d0, d0, d0).a(0.0D, this.world.getHeight(), 0.0D); - List list = this.world.a(EntityHuman.class, axisalignedbb); - Iterator iterator = list.iterator(); + int posX = this.position.getX(); + int posY = this.position.getY(); + int posZ = this.position.getZ(); + AxisAlignedBB axisalignedbb = new AxisAlignedBB(posX, posY, posZ, posX + 1, posY + 1, posZ + 1) + .grow(radius, radius, radius).a(0.0D, this.world.getHeight(), 0.0D); + + List list = this.world.a(EntityHuman.class, axisalignedbb); - EntityHuman entityhuman; // PaperSpigot start org.bukkit.block.Block block = world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()); PotionEffect primaryEffect = new PotionEffect(PotionEffectType.getById(this.k), 180, b0, true, true); // PaperSpigot end - while (iterator.hasNext()) { - entityhuman = (EntityHuman) iterator.next(); + for (EntityHuman entityhuman : list) { // PaperSpigot start - BeaconEffectEvent BeaconEffectEvent event = new BeaconEffectEvent(block, primaryEffect, (Player) entityhuman.getBukkitEntity(), true); if (CraftEventFactory.callEvent(event).isCancelled()) continue; @@ -100,12 +110,10 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay // PaperSpigot end } - if (this.j >= 4 && this.k != this.l && this.l > 0) { - iterator = list.iterator(); + if (getLevel() >= 4 && this.k != this.l && this.l > 0) { PotionEffect secondaryEffect = new PotionEffect(PotionEffectType.getById(this.l), 180, 0, true, true); // PaperSpigot - while (iterator.hasNext()) { - entityhuman = (EntityHuman) iterator.next(); + for (EntityHuman entityhuman : list) { // PaperSpigot start - BeaconEffectEvent BeaconEffectEvent event = new BeaconEffectEvent(block, secondaryEffect, (Player) entityhuman.getBukkitEntity(), false); if (CraftEventFactory.callEvent(event).isCancelled()) continue; @@ -116,95 +124,63 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay } } } - } private void B() { - int i = this.j; - int j = this.position.getX(); - int k = this.position.getY(); - int l = this.position.getZ(); + int prevLevel = getLevel(); + int posX = this.position.getX(); + int posY = this.position.getY(); + int posZ = this.position.getZ(); + setLevel(0); + setEnabled(true); - this.j = 0; - this.f.clear(); - this.i = true; - TileEntityBeacon.BeaconColorTracker tileentitybeacon_beaconcolortracker = new TileEntityBeacon.BeaconColorTracker(EntitySheep.a(EnumColor.WHITE)); - - this.f.add(tileentitybeacon_beaconcolortracker); - boolean flag = true; - BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); - - int i1; - - for (i1 = k + 1; i1 < 256; ++i1) { - IBlockData iblockdata = this.world.getType(blockposition_mutableblockposition.c(j, i1, l)); - float[] afloat; - - if (iblockdata.getBlock() == Blocks.STAINED_GLASS) { - afloat = EntitySheep.a(iblockdata.get(BlockStainedGlass.COLOR)); - } else { - if (iblockdata.getBlock() != Blocks.STAINED_GLASS_PANE) { - if (iblockdata.getBlock().p() >= 15 && iblockdata.getBlock() != Blocks.BEDROCK) { - this.i = false; - this.f.clear(); - break; - } - - tileentitybeacon_beaconcolortracker.a(); - continue; - } - - afloat = EntitySheep.a(iblockdata.get(BlockStainedGlassPane.COLOR)); + BlockPosition.MutableBlockPosition mutableBlockPosition = new BlockPosition.MutableBlockPosition(); + for (int y = posY + 1; y < 256; ++y) { + Block block = this.world + .getType(mutableBlockPosition.c(posX, y, posZ)) + .getBlock(); + if (block != Blocks.STAINED_GLASS && block != Blocks.STAINED_GLASS_PANE + && block.p() >= 15 && block != Blocks.BEDROCK) { + setEnabled(false); + break; } - - if (!flag) { - afloat = new float[] { (tileentitybeacon_beaconcolortracker.b()[0] + afloat[0]) / 2.0F, (tileentitybeacon_beaconcolortracker.b()[1] + afloat[1]) / 2.0F, (tileentitybeacon_beaconcolortracker.b()[2] + afloat[2]) / 2.0F}; - } - - if (Arrays.equals(afloat, tileentitybeacon_beaconcolortracker.b())) { - tileentitybeacon_beaconcolortracker.a(); - } else { - tileentitybeacon_beaconcolortracker = new TileEntityBeacon.BeaconColorTracker(afloat); - this.f.add(tileentitybeacon_beaconcolortracker); - } - - flag = false; } - if (this.i) { - for (i1 = 1; i1 <= 4; this.j = i1++) { - int j1 = k - i1; + if (isEnabled()) { + for (int layer = 1; layer <= 4; setLevel(layer++)) { + int layerY = posY - layer; - if (j1 < 0) { + if (layerY < 0) { break; } - boolean flag1 = true; - - for (int k1 = j - i1; k1 <= j + i1 && flag1; ++k1) { - for (int l1 = l - i1; l1 <= l + i1; ++l1) { - Block block = this.world.getType(new BlockPosition(k1, j1, l1)).getBlock(); + boolean hasLayer = true; + for (int layerX = posX - layer; layerX <= posX + layer && hasLayer; ++layerX) { + for (int layerZ = posZ - layer; layerZ <= posZ + layer; ++layerZ) { + Block block = this.world.getType(new BlockPosition(layerX, layerY, layerZ)).getBlock(); if (block != Blocks.EMERALD_BLOCK && block != Blocks.GOLD_BLOCK && block != Blocks.DIAMOND_BLOCK && block != Blocks.IRON_BLOCK) { - flag1 = false; + hasLayer = false; break; } } } - if (!flag1) { + if (!hasLayer) { break; } } - if (this.j == 0) { - this.i = false; + if (getLevel() == 0) { + setEnabled(false); } } - if (!this.world.isClientSide && this.j == 4 && i < this.j) { + if (!this.world.isClientSide && getLevel() == 4 && prevLevel < getLevel()) { + AxisAlignedBB bb = new AxisAlignedBB(posX, posY, posZ, posX, posY - 4, posZ) + .grow(10.0D, 5.0D, 10.0D); - for (EntityHuman entityhuman : this.world.a(EntityHuman.class, (new AxisAlignedBB(j, k, l, j, k - 4, l)).grow(10.0D, 5.0D, 10.0D))) { + for (EntityHuman entityhuman : this.world.a(EntityHuman.class, bb)) { entityhuman.b(AchievementList.K); } } @@ -232,14 +208,14 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay super.a(nbttagcompound); this.k = this.h(nbttagcompound.getInt("Primary")); this.l = this.h(nbttagcompound.getInt("Secondary")); - this.j = nbttagcompound.getInt("Levels"); + setLevel(nbttagcompound.getInt("Levels")); } public void b(NBTTagCompound nbttagcompound) { super.b(nbttagcompound); nbttagcompound.setInt("Primary", this.k); nbttagcompound.setInt("Secondary", this.l); - nbttagcompound.setInt("Levels", this.j); + nbttagcompound.setInt("Levels", getLevel()); } public int getSize() { @@ -300,13 +276,19 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay return maxStack; // CraftBukkit } - public boolean a(EntityHuman entityhuman) { - return this.world.getTileEntity(this.position) == this && entityhuman.e((double) this.position.getX() + 0.5D, (double) this.position.getY() + 0.5D, (double) this.position.getZ() + 0.5D) <= 64.0D; + public void setMaxStackSize(int size) { + maxStack = size; } - public void startOpen(EntityHuman entityhuman) {} + public boolean a(EntityHuman entityhuman) { + return this.world.getTileEntity(this.position) != this ? false : entityhuman.e((double) this.position.getX() + 0.5D, (double) this.position.getY() + 0.5D, (double) this.position.getZ() + 0.5D) <= 64.0D; + } - public void closeContainer(EntityHuman entityhuman) {} + public void startOpen(EntityHuman entityhuman) { + } + + public void closeContainer(EntityHuman entityhuman) { + } public boolean b(int i, ItemStack itemstack) { return itemstack.getItem() == Items.EMERALD || itemstack.getItem() == Items.DIAMOND || itemstack.getItem() == Items.GOLD_INGOT || itemstack.getItem() == Items.IRON_INGOT; @@ -322,32 +304,32 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay public int getProperty(int i) { switch (i) { - case 0: - return this.j; + case 0: + return getLevel(); - case 1: - return this.k; + case 1: + return this.k; - case 2: - return this.l; + case 2: + return this.l; - default: - return 0; + default: + return 0; } } public void b(int i, int j) { switch (i) { - case 0: - this.j = j; - break; + case 0: + setLevel(j); + break; - case 1: - this.k = this.h(j); - break; + case 1: + this.k = this.h(j); + break; - case 2: - this.l = this.h(j); + case 2: + this.l = this.h(j); } } @@ -369,22 +351,22 @@ public class TileEntityBeacon extends TileEntityContainer implements IUpdatePlay } } - public static class BeaconColorTracker { - - private final float[] a; - private int b; - - public BeaconColorTracker(float[] afloat) { - this.a = afloat; - this.b = 1; - } - - protected void a() { - ++this.b; - } - - public float[] b() { - return this.a; - } - } +// public static class BeaconColorTracker { +// +// private final float[] a; +// private int b; +// +// public BeaconColorTracker(float[] afloat) { +// this.a = afloat; +// this.b = 1; +// } +// +// protected void a() { +// ++this.b; +// } +// +// public float[] b() { +// return this.a; +// } +// } } diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java index 79e9ac6..a66b5a0 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/TileEntityHopper.java @@ -6,6 +6,7 @@ import java.util.List; // CraftBukkit start import org.bukkit.craftbukkit.entity.CraftHumanEntity; import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent; @@ -604,7 +605,9 @@ public class TileEntityHopper extends TileEntityContainer implements IHopper, IU } } - if (object == null) { + Chunk chunk = world.getChunkAtWorldCoords(blockposition); + + if (object == null && !org.bukkit.craftbukkit.util.CraftMagicNumbers.getMaterial(block).isOccluding() && chunk.getItemCount(blockposition) > 0) { List list = world.a((Entity) null, new AxisAlignedBB(d0 - 0.5D, d1 - 0.5D, d2 - 0.5D, d0 + 0.5D, d1 + 0.5D, d2 + 0.5D), IEntitySelector.c); if (list.size() > 0) { diff --git a/TacoSpigot-Server/src/main/java/net/minecraft/server/WorldServer.java b/TacoSpigot-Server/src/main/java/net/minecraft/server/WorldServer.java index fed25d4..294679c 100644 --- a/TacoSpigot-Server/src/main/java/net/minecraft/server/WorldServer.java +++ b/TacoSpigot-Server/src/main/java/net/minecraft/server/WorldServer.java @@ -233,7 +233,10 @@ public class WorldServer extends World implements IAsyncTaskHandler { // CraftBukkit end timings.doChunkUnload.startTiming(); // Spigot this.methodProfiler.c("chunkSource"); - this.chunkProvider.unloadChunks(); + // Only unload if chunkProvider isn't null + if (this.chunkProvider != null) { + this.chunkProvider.unloadChunks(); + } int j = this.a(1.0F); if (j != this.ab()) { diff --git a/TacoSpigot-Server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/TacoSpigot-Server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java index d458b5d..d48eda6 100644 --- a/TacoSpigot-Server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java +++ b/TacoSpigot-Server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java @@ -34,9 +34,8 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { static final ItemMetaKey RESOLVED = new ItemMetaKey("resolved"); static final ItemMetaKey GENERATION = new ItemMetaKey("generation"); static final int MAX_PAGES = 50; - static final int MAX_PAGE_LENGTH = 256; - static final int MAX_TITLE_LENGTH = 16; - + static final int MAX_PAGE_LENGTH = 340; + static final int MAX_TITLE_LENGTH = 32; protected String title; protected String author;