diff --git a/Spigot-API-Patches/Add-basic-Datapack-API.patch b/Spigot-API-Patches/Add-basic-Datapack-API.patch new file mode 100644 index 0000000000..6a09e3b070 --- /dev/null +++ b/Spigot-API-Patches/Add-basic-Datapack-API.patch @@ -0,0 +1,106 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Connor Linfoot +Date: Sun, 16 May 2021 15:07:34 +0100 +Subject: [PATCH] Add basic Datapack API + + +diff --git a/src/main/java/io/papermc/paper/resource/Datapack.java b/src/main/java/io/papermc/paper/resource/Datapack.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/resource/Datapack.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.resource; ++ ++import org.checkerframework.checker.nullness.qual.NonNull; ++ ++public interface Datapack { ++ ++ /** ++ * @return the name of the pack ++ */ ++ @NonNull ++ String getName(); ++ ++ /** ++ * @return the compatibility of the pack ++ */ ++ @NonNull ++ Compatibility getCompatibility(); ++ ++ /** ++ * @return whether or not the pack is currently enabled ++ */ ++ boolean isEnabled(); ++ ++ void setEnabled(boolean enabled); ++ ++ enum Compatibility { ++ TOO_OLD, ++ TOO_NEW, ++ COMPATIBLE, ++ } ++ ++} +diff --git a/src/main/java/io/papermc/paper/resource/DatapackManager.java b/src/main/java/io/papermc/paper/resource/DatapackManager.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/resource/DatapackManager.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.resource; ++ ++import org.checkerframework.checker.nullness.qual.NonNull; ++ ++import java.util.Collection; ++ ++public interface DatapackManager { ++ ++ /** ++ * @return all the packs known to the server ++ */ ++ @NonNull ++ Collection getPacks(); ++ ++ /** ++ * @return all the packs which are currently enabled ++ */ ++ @NonNull ++ Collection getEnabledPacks(); ++ ++} +diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/Bukkit.java ++++ b/src/main/java/org/bukkit/Bukkit.java +@@ -0,0 +0,0 @@ public final class Bukkit { + public static com.destroystokyo.paper.entity.ai.MobGoals getMobGoals() { + return server.getMobGoals(); + } ++ ++ /** ++ * @return the resource pack manager ++ */ ++ @NotNull ++ public static io.papermc.paper.resource.DatapackManager getDatapackManager() { ++ return server.getDatapackManager(); ++ } + // Paper end + + @NotNull +diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/Server.java ++++ b/src/main/java/org/bukkit/Server.java +@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi + */ + @NotNull + com.destroystokyo.paper.entity.ai.MobGoals getMobGoals(); ++ ++ /** ++ * @return the resource pack manager ++ */ ++ @NotNull ++ io.papermc.paper.resource.DatapackManager getDatapackManager(); + // Paper end + } diff --git a/Spigot-Server-Patches/Add-basic-Datapack-API.patch b/Spigot-Server-Patches/Add-basic-Datapack-API.patch new file mode 100644 index 0000000000..3b4abd811e --- /dev/null +++ b/Spigot-Server-Patches/Add-basic-Datapack-API.patch @@ -0,0 +1,175 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Connor Linfoot +Date: Sun, 16 May 2021 15:07:34 +0100 +Subject: [PATCH] Add basic Datapack API + + +diff --git a/src/main/java/io/papermc/paper/resource/PaperDatapack.java b/src/main/java/io/papermc/paper/resource/PaperDatapack.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/resource/PaperDatapack.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.resource; ++ ++import io.papermc.paper.event.server.ServerResourcesReloadedEvent; ++import net.minecraft.server.MinecraftServer; ++import net.minecraft.server.packs.repository.ResourcePackLoader; ++ ++import java.util.List; ++import java.util.stream.Collectors; ++ ++public class PaperDatapack implements Datapack { ++ private final String name; ++ private final Compatibility compatibility; ++ private final boolean enabled; ++ ++ PaperDatapack(ResourcePackLoader loader, boolean enabled) { ++ this.name = loader.getName(); ++ this.compatibility = Compatibility.valueOf(loader.getVersion().name()); ++ this.enabled = enabled; ++ } ++ ++ @Override ++ public String getName() { ++ return name; ++ } ++ ++ @Override ++ public Compatibility getCompatibility() { ++ return compatibility; ++ } ++ ++ @Override ++ public boolean isEnabled() { ++ return enabled; ++ } ++ ++ @Override ++ public void setEnabled(boolean enabled) { ++ if (enabled == this.enabled) { ++ return; ++ } ++ ++ MinecraftServer server = MinecraftServer.getServer(); ++ List enabledKeys = server.getResourcePackRepository().getEnabledPacks().stream().map(ResourcePackLoader::getName).collect(Collectors.toList()); ++ if (enabled) { ++ enabledKeys.add(this.name); ++ } else { ++ enabledKeys.remove(this.name); ++ } ++ server.reloadServerResources(enabledKeys, ServerResourcesReloadedEvent.Cause.PLUGIN); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/resource/PaperDatapackManager.java b/src/main/java/io/papermc/paper/resource/PaperDatapackManager.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/resource/PaperDatapackManager.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.resource; ++ ++import net.minecraft.server.packs.repository.ResourcePackLoader; ++import net.minecraft.server.packs.repository.ResourcePackRepository; ++ ++import java.util.Collection; ++import java.util.stream.Collectors; ++ ++public class PaperDatapackManager implements DatapackManager { ++ private final ResourcePackRepository repository; ++ ++ public PaperDatapackManager(ResourcePackRepository repository) { ++ this.repository = repository; ++ } ++ ++ @Override ++ public Collection getPacks() { ++ Collection enabledPacks = repository.getEnabledPacks(); ++ return repository.getPacks().stream().map(loader -> new PaperDatapack(loader, enabledPacks.contains(loader))).collect(Collectors.toList()); ++ } ++ ++ @Override ++ public Collection getEnabledPacks() { ++ return repository.getEnabledPacks().stream().map(loader -> new PaperDatapack(loader, true)).collect(Collectors.toList()); ++ } ++} +diff --git a/src/main/java/net/minecraft/server/packs/repository/ResourcePackLoader.java b/src/main/java/net/minecraft/server/packs/repository/ResourcePackLoader.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/packs/repository/ResourcePackLoader.java ++++ b/src/main/java/net/minecraft/server/packs/repository/ResourcePackLoader.java +@@ -0,0 +0,0 @@ public class ResourcePackLoader implements AutoCloseable { + }); + } + ++ public final EnumResourcePackVersion getVersion() { return this.c(); } // Paper - OBFHELPER + public EnumResourcePackVersion c() { + return this.g; + } +@@ -0,0 +0,0 @@ public class ResourcePackLoader implements AutoCloseable { + return (IResourcePack) this.d.get(); + } + ++ public final String getName() { return this.e(); } // Paper - OBFHELPER + public String e() { + return this.c; + } +diff --git a/src/main/java/net/minecraft/server/packs/repository/ResourcePackRepository.java b/src/main/java/net/minecraft/server/packs/repository/ResourcePackRepository.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/packs/repository/ResourcePackRepository.java ++++ b/src/main/java/net/minecraft/server/packs/repository/ResourcePackRepository.java +@@ -0,0 +0,0 @@ public class ResourcePackRepository implements AutoCloseable { + return this.b.keySet(); + } + ++ public final Collection getPacks() { return this.c(); } // Paper - OBFHELPER + public Collection c() { + return this.b.values(); + } +@@ -0,0 +0,0 @@ public class ResourcePackRepository implements AutoCloseable { + return (Collection) this.c.stream().map(ResourcePackLoader::e).collect(ImmutableSet.toImmutableSet()); + } + ++ public final Collection getEnabledPacks() { return this.e(); } // Paper - OBFHELPER + public Collection e() { + return this.c; + } +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -0,0 +0,0 @@ import com.mojang.serialization.Lifecycle; + import io.netty.buffer.ByteBuf; + import io.netty.buffer.ByteBufOutputStream; + import io.netty.buffer.Unpooled; ++import io.papermc.paper.resource.PaperDatapackManager; // Paper + import io.papermc.paper.util.TraceUtil; + import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; + import java.awt.image.BufferedImage; +@@ -0,0 +0,0 @@ public final class CraftServer implements Server { + public boolean ignoreVanillaPermissions = false; + private final List playerView; + public int reloadCount; ++ private final PaperDatapackManager datapackManager; // Paper + public static Exception excessiveVelEx; // Paper - Velocity warnings + + static { +@@ -0,0 +0,0 @@ public final class CraftServer implements Server { + TicketType.PLUGIN.loadPeriod = Math.min(20, configuration.getInt("chunk-gc.period-in-ticks")); // Paper - cap plugin loads to 1 second + minimumAPI = configuration.getString("settings.minimum-api"); + loadIcon(); ++ datapackManager = new PaperDatapackManager(console.getResourcePackRepository()); // Paper + } + + public boolean getCommandBlockOverride(String command) { +@@ -0,0 +0,0 @@ public final class CraftServer implements Server { + public com.destroystokyo.paper.entity.ai.MobGoals getMobGoals() { + return mobGoals; + } ++ ++ @Override ++ public PaperDatapackManager getDatapackManager() { ++ return datapackManager; ++ } ++ + // Paper end + }