From d937034264b32b735bcc588587ccfd11a31c3314 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <nassim@njahnke.dev>
Date: Sat, 12 Jun 2021 12:26:21 +0200
Subject: [PATCH] More work

---
 ...upstream-javadoc-warnings-and-errors.patch |  0
 .../Item-canEntityPickup.patch                |  0
 ...PlayerPickupItemEvent-setFlyAtPlayer.patch |  6 +-
 .../Item-canEntityPickup.patch                |  6 +-
 ...PlayerPickupItemEvent-setFlyAtPlayer.patch |  8 +-
 ...oleAppender-for-console-improvements.patch | 92 +++++++------------
 ...urable-option-to-disable-creeper-lin.patch |  2 +-
 7 files changed, 46 insertions(+), 68 deletions(-)
 rename patches/{api-unmapped => api}/Fix-upstream-javadoc-warnings-and-errors.patch (100%)
 rename patches/{api-unmapped => api}/Item-canEntityPickup.patch (100%)
 rename patches/{api-unmapped => api}/PlayerPickupItemEvent-setFlyAtPlayer.patch (99%)
 rename patches/{server-remapped => server}/Item-canEntityPickup.patch (91%)
 rename patches/{server-remapped => server}/PlayerPickupItemEvent-setFlyAtPlayer.patch (88%)
 rename patches/{server-remapped => server}/Use-TerminalConsoleAppender-for-console-improvements.patch (90%)
 rename patches/{server-remapped => server}/provide-a-configurable-option-to-disable-creeper-lin.patch (96%)

diff --git a/patches/api-unmapped/Fix-upstream-javadoc-warnings-and-errors.patch b/patches/api/Fix-upstream-javadoc-warnings-and-errors.patch
similarity index 100%
rename from patches/api-unmapped/Fix-upstream-javadoc-warnings-and-errors.patch
rename to patches/api/Fix-upstream-javadoc-warnings-and-errors.patch
diff --git a/patches/api-unmapped/Item-canEntityPickup.patch b/patches/api/Item-canEntityPickup.patch
similarity index 100%
rename from patches/api-unmapped/Item-canEntityPickup.patch
rename to patches/api/Item-canEntityPickup.patch
diff --git a/patches/api-unmapped/PlayerPickupItemEvent-setFlyAtPlayer.patch b/patches/api/PlayerPickupItemEvent-setFlyAtPlayer.patch
similarity index 99%
rename from patches/api-unmapped/PlayerPickupItemEvent-setFlyAtPlayer.patch
rename to patches/api/PlayerPickupItemEvent-setFlyAtPlayer.patch
index 71a965b6fc..62d8f08dc2 100644
--- a/patches/api-unmapped/PlayerPickupItemEvent-setFlyAtPlayer.patch
+++ b/patches/api/PlayerPickupItemEvent-setFlyAtPlayer.patch
@@ -15,11 +15,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    private boolean flyAtPlayer = true; // Paper
      private boolean cancel = false;
      private final int remaining;
- 
+
 @@ -0,0 +0,0 @@ public class PlayerPickupItemEvent extends PlayerEvent implements Cancellable {
          return remaining;
      }
- 
+
 +    // Paper Start
 +    /**
 +     * Set if the item will fly at the player
@@ -50,5 +50,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          this.cancel = cancel;
 +        this.flyAtPlayer = !cancel; // Paper
      }
- 
+
      @NotNull
diff --git a/patches/server-remapped/Item-canEntityPickup.patch b/patches/server/Item-canEntityPickup.patch
similarity index 91%
rename from patches/server-remapped/Item-canEntityPickup.patch
rename to patches/server/Item-canEntityPickup.patch
index 4d167395ae..ae2954513a 100644
--- a/patches/server-remapped/Item-canEntityPickup.patch
+++ b/patches/server/Item-canEntityPickup.patch
@@ -11,7 +11,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public abstract class Mob extends LivingEntity {
                  ItemEntity entityitem = (ItemEntity) iterator.next();
  
-                 if (!entityitem.removed && !entityitem.getItem().isEmpty() && !entityitem.hasPickUpDelay() && this.wantsToPickUp(entityitem.getItem())) {
+                 if (!entityitem.isRemoved() && !entityitem.getItem().isEmpty() && !entityitem.hasPickUpDelay() && this.wantsToPickUp(entityitem.getItem())) {
 +                    // Paper Start
 +                    if (!entityitem.canMobPickup) {
 +                        continue;
@@ -41,10 +41,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      }
  
 +    // Paper Start
++    @Override
 +    public boolean canMobPickup() {
 +        return item.canMobPickup;
 +    }
 +
++    @Override
 +    public void setCanMobPickup(boolean canMobPickup) {
 +        item.canMobPickup = canMobPickup;
 +    }
@@ -52,4 +54,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +
      @Override
      public void setOwner(UUID uuid) {
-         item.setOwner(uuid);
+         this.item.setOwner(uuid);
diff --git a/patches/server-remapped/PlayerPickupItemEvent-setFlyAtPlayer.patch b/patches/server/PlayerPickupItemEvent-setFlyAtPlayer.patch
similarity index 88%
rename from patches/server-remapped/PlayerPickupItemEvent-setFlyAtPlayer.patch
rename to patches/server/PlayerPickupItemEvent-setFlyAtPlayer.patch
index 2d681e9d96..1d0d50f679 100644
--- a/patches/server-remapped/PlayerPickupItemEvent-setFlyAtPlayer.patch
+++ b/patches/server/PlayerPickupItemEvent-setFlyAtPlayer.patch
@@ -10,7 +10,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
 @@ -0,0 +0,0 @@ public class ItemEntity extends Entity {
              // CraftBukkit start - fire PlayerPickupItemEvent
-             int canHold = player.inventory.canHold(itemstack);
+             int canHold = player.getInventory().canHold(itemstack);
              int remaining = i - canHold;
 +            boolean flyAtPlayer = false; // Paper
  
@@ -18,7 +18,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
                  itemstack.setCount(canHold);
 @@ -0,0 +0,0 @@ public class ItemEntity extends Entity {
                  PlayerPickupItemEvent playerEvent = new PlayerPickupItemEvent((org.bukkit.entity.Player) player.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining);
-                 playerEvent.setCancelled(!player.canPickUpLoot);
+                 playerEvent.setCancelled(!playerEvent.getPlayer().getCanPickupItems());
                  this.level.getCraftServer().getPluginManager().callEvent(playerEvent);
 +                flyAtPlayer = playerEvent.getFlyAtPlayer(); // Paper
                  if (playerEvent.isCancelled()) {
@@ -34,7 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public class ItemEntity extends Entity {
              // CraftBukkit end
  
-             if (this.pickupDelay == 0 && (this.owner == null || this.owner.equals(player.getUUID())) && player.inventory.add(itemstack)) {
+             if (this.pickupDelay == 0 && (this.owner == null || this.owner.equals(player.getUUID())) && player.getInventory().add(itemstack)) {
 -                player.take(this, i);
 +                // Paper Start
 +                if (flyAtPlayer) {
@@ -42,5 +42,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                }
 +                // Paper End
                  if (itemstack.isEmpty()) {
-                     this.remove();
+                     this.discard();
                      itemstack.setCount(i);
diff --git a/patches/server-remapped/Use-TerminalConsoleAppender-for-console-improvements.patch b/patches/server/Use-TerminalConsoleAppender-for-console-improvements.patch
similarity index 90%
rename from patches/server-remapped/Use-TerminalConsoleAppender-for-console-improvements.patch
rename to patches/server/Use-TerminalConsoleAppender-for-console-improvements.patch
index a11fc149bc..d60f00fc45 100644
--- a/patches/server-remapped/Use-TerminalConsoleAppender-for-console-improvements.patch
+++ b/patches/server/Use-TerminalConsoleAppender-for-console-improvements.patch
@@ -18,60 +18,29 @@ Other changes:
   - Server starts 1-2 seconds faster thanks to optimizations in Log4j
     configuration
 
-diff --git a/pom.xml b/pom.xml
+diff --git a/build.gradle.kts b/build.gradle.kts
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/pom.xml
-+++ b/pom.xml
-@@ -0,0 +0,0 @@
-             <scope>compile</scope>
-         </dependency>
-         <dependency>
--            <groupId>jline</groupId>
--            <artifactId>jline</artifactId>
--            <version>2.12.1</version>
--            <scope>compile</scope>
-+            <groupId>net.minecrell</groupId>
-+            <artifactId>terminalconsoleappender</artifactId>
-+            <version>1.2.0</version>
-+        </dependency>
-+        <dependency>
-+            <groupId>org.jline</groupId>
-+            <artifactId>jline-terminal-jansi</artifactId>
-+            <version>3.12.1</version>
-+            <scope>runtime</scope>
-+        </dependency>
-+        <!--
+--- a/build.gradle.kts
++++ b/build.gradle.kts
+@@ -0,0 +0,0 @@ repositories {
+ 
+ dependencies {
+     implementation(project(":Paper-API"))
+-    implementation("jline:jline:2.12.1")
++    // Paper start
++    implementation("org.jline:jline-terminal-jansi:3.12.1")
++    implementation("net.minecrell:terminalconsoleappender:1.2.0")
++    /*
 +          Required to add the missing Log4j2Plugins.dat file from log4j-core
 +          which has been removed by Mojang. Without it, log4j has to classload
 +          all its classes to check if they are plugins.
 +          Scanning takes about 1-2 seconds so adding this speeds up the server start.
-+        -->
-+        <dependency>
-+            <groupId>org.apache.logging.log4j</groupId>
-+            <artifactId>log4j-core</artifactId>
-+            <scope>runtime</scope>
-         </dependency>
-         <dependency>
-             <groupId>org.apache.logging.log4j</groupId>
-@@ -0,0 +0,0 @@
-                                 <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
-                                     <resource>META-INF/services/java.sql.Driver</resource>
-                                 </transformer>
-+                                <transformer implementation="com.github.edwgiz.maven_shade_plugin.log4j2_cache_transformer.PluginsCacheFileTransformer" />
-                             </transformers>
-                         </configuration>
-                     </execution>
-                 </executions>
-+                <dependencies>
-+                    <dependency>
-+                        <groupId>com.github.edwgiz</groupId>
-+                        <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
-+                        <version>2.13.1</version>
-+                    </dependency>
-+                </dependencies>
-             </plugin>
-             <plugin>
-                 <groupId>org.apache.maven.plugins</groupId>
++     */
++    runtimeOnly("org.apache.logging.log4j:log4j-core:2.14.1")
++    // Paper end
+     implementation("org.apache.logging.log4j:log4j-iostreams:2.14.1") // Paper
+     implementation("org.apache.logging.log4j:log4j-api:2.14.1") // Paper
+     implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.14.1") // Paper
 diff --git a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
 new file mode 100644
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
@@ -152,8 +121,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  import io.netty.buffer.Unpooled;
 +import io.papermc.paper.adventure.PaperAdventure; // Paper
  import it.unimi.dsi.fastutil.longs.LongIterator;
+ import java.awt.GraphicsEnvironment;
  import java.awt.image.BufferedImage;
- import java.io.BufferedWriter;
 @@ -0,0 +0,0 @@ import org.apache.logging.log4j.Logger;
  import com.mojang.serialization.DynamicOps;
  import com.mojang.serialization.Lifecycle;
@@ -183,7 +152,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              System.setProperty("jline.terminal", "jline.UnsupportedTerminal");
              Main.useJline = false;
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
-                 LOGGER.warn((String) null, ex);
+                 MinecraftServer.LOGGER.warn((String) null, ex);
              }
          }
 +        */
@@ -195,7 +164,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
                  org.spigotmc.WatchdogThread.doStop(); // Spigot
                  // CraftBukkit start - Restore terminal to original settings
                  try {
--                    reader.getTerminal().restore();
+-                    this.reader.getTerminal().restore();
 +                    net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Use TerminalConsoleAppender
                  } catch (Exception ignored) {
                  }
@@ -203,7 +172,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
  
      @Override
-     public void sendMessage(Component message, UUID senderUuid) {
+     public void sendMessage(Component message, UUID sender) {
 -        MinecraftServer.LOGGER.info(message.getString());
 +        MinecraftServer.LOGGER.info(PaperAdventure.LEGACY_SECTION_UXRC.serialize(PaperAdventure.asAdventure(message))); // Paper - Log message with colors
      }
@@ -295,7 +264,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  import net.minecraft.server.bossevents.CustomBossEvent;
  import net.minecraft.server.commands.ReloadCommand;
 @@ -0,0 +0,0 @@ public final class CraftServer implements Server {
-         return logger;
+         return this.logger;
      }
  
 +    // Paper start - JLine update
@@ -343,12 +312,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                // Paper end
  
                  if (options.has("noconsole")) {
-                     useConsole = false;
+                     Main.useConsole = false;
 +                    useJline = false; // Paper
 +                    System.setProperty(TerminalConsoleAppender.JLINE_OVERRIDE_PROPERTY, "false"); // Paper
                  }
  
-                 if (false && Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {
+                 if (Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {
 @@ -0,0 +0,0 @@ public class Main {
                      System.out.println("Unable to read system info");
                  }
@@ -427,7 +396,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          Waitable<List<String>> waitable = new Waitable<List<String>>() {
              @Override
              protected List<String> evaluate() {
-@@ -0,0 +0,0 @@ public class ConsoleCommandCompleter implements Completer {
+-                List<String> offers = ConsoleCommandCompleter.this.server.getCommandMap().tabComplete(ConsoleCommandCompleter.this.server.getConsoleSender(), buffer);
++                List<String> offers = server.getCommandMap().tabComplete(server.getConsoleSender(), buffer); // Paper - fix remap
+ 
+-                TabCompleteEvent tabEvent = new TabCompleteEvent(ConsoleCommandCompleter.this.server.getConsoleSender(), buffer, (offers == null) ? Collections.EMPTY_LIST : offers);
+-                ConsoleCommandCompleter.this.server.getPluginManager().callEvent(tabEvent);
++                TabCompleteEvent tabEvent = new TabCompleteEvent(server.getConsoleSender(), buffer, (offers == null) ? Collections.EMPTY_LIST : offers); // Paper - fix remap
++                server.getPluginManager().callEvent(tabEvent); // Paper - fix remap
+ 
                  return tabEvent.isCancelled() ? Collections.EMPTY_LIST : tabEvent.getCompletions();
              }
          };
@@ -475,7 +451,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
 +++ b/src/main/java/org/bukkit/craftbukkit/util/ServerShutdownThread.java
 @@ -0,0 +0,0 @@ public class ServerShutdownThread extends Thread {
-             server.close();
+             this.server.close();
          } finally {
              try {
 -                server.reader.getTerminal().restore();
diff --git a/patches/server-remapped/provide-a-configurable-option-to-disable-creeper-lin.patch b/patches/server/provide-a-configurable-option-to-disable-creeper-lin.patch
similarity index 96%
rename from patches/server-remapped/provide-a-configurable-option-to-disable-creeper-lin.patch
rename to patches/server/provide-a-configurable-option-to-disable-creeper-lin.patch
index 07088cf9d9..9b22046211 100644
--- a/patches/server-remapped/provide-a-configurable-option-to-disable-creeper-lin.patch
+++ b/patches/server/provide-a-configurable-option-to-disable-creeper-lin.patch
@@ -24,7 +24,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/monster/Creeper.java b/src
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/monster/Creeper.java
 +++ b/src/main/java/net/minecraft/world/entity/monster/Creeper.java
-@@ -0,0 +0,0 @@ public class Creeper extends Monster {
+@@ -0,0 +0,0 @@ public class Creeper extends Monster implements PowerableMob {
      private void spawnLingeringCloud() {
          Collection<MobEffectInstance> collection = this.getActiveEffects();