mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 02:55:47 +01:00
a207d14a0e
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
175 lines
7.1 KiB
Diff
175 lines
7.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Connor Linfoot <connorlinfoot@me.com>
|
|
Date: Sun, 16 May 2021 15:07:34 +0100
|
|
Subject: [PATCH] Add basic Datapack API
|
|
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/datapack/PaperDatapack.java b/src/main/java/io/papermc/paper/datapack/PaperDatapack.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..66debefcd474e4dcc2a8889a82af6c1809c93f46
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/datapack/PaperDatapack.java
|
|
@@ -0,0 +1,51 @@
|
|
+package io.papermc.paper.datapack;
|
|
+
|
|
+import Compatibility;
|
|
+import io.papermc.paper.event.server.ServerResourcesReloadedEvent;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.server.packs.repository.Pack;
|
|
+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(Pack 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<String> enabledKeys = server.getPackRepository().getEnabledPacks().stream().map(Pack::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/datapack/PaperDatapackManager.java b/src/main/java/io/papermc/paper/datapack/PaperDatapackManager.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..ec221183bef1065bda0a37e1025958df0d1f6318
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/datapack/PaperDatapackManager.java
|
|
@@ -0,0 +1,25 @@
|
|
+package io.papermc.paper.datapack;
|
|
+
|
|
+import java.util.Collection;
|
|
+import java.util.stream.Collectors;
|
|
+import net.minecraft.server.packs.repository.Pack;
|
|
+import net.minecraft.server.packs.repository.PackRepository;
|
|
+
|
|
+public class PaperDatapackManager implements DatapackManager {
|
|
+ private final PackRepository repository;
|
|
+
|
|
+ public PaperDatapackManager(PackRepository repository) {
|
|
+ this.repository = repository;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Collection<Datapack> getPacks() {
|
|
+ Collection<Pack> enabledPacks = repository.getEnabledPacks();
|
|
+ return repository.getPacks().stream().map(loader -> new PaperDatapack(loader, enabledPacks.contains(loader))).collect(Collectors.toList());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Collection<Datapack> 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/Pack.java b/src/main/java/net/minecraft/server/packs/repository/Pack.java
|
|
index df5d258b80e37077fa236e4190ad934853c88619..4120326e0d047347e5d7ab9521babe7bb6b6a7db 100644
|
|
--- a/src/main/java/net/minecraft/server/packs/repository/Pack.java
|
|
+++ b/src/main/java/net/minecraft/server/packs/repository/Pack.java
|
|
@@ -101,6 +101,7 @@ public class Pack implements AutoCloseable {
|
|
});
|
|
}
|
|
|
|
+ public final PackCompatibility getVersion() { return this.getCompatibility(); } // Paper - OBFHELPER
|
|
public PackCompatibility getCompatibility() {
|
|
return this.compatibility;
|
|
}
|
|
@@ -109,6 +110,7 @@ public class Pack implements AutoCloseable {
|
|
return (PackResources) this.supplier.get();
|
|
}
|
|
|
|
+ public final String getName() { return this.getId(); } // Paper - OBFHELPER
|
|
public String getId() {
|
|
return this.id;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/packs/repository/PackRepository.java b/src/main/java/net/minecraft/server/packs/repository/PackRepository.java
|
|
index bce2fd67048bd1fd53865eef81bac262dbda2865..8d0ef3bdf9fa283f54628800768717181df28aa5 100644
|
|
--- a/src/main/java/net/minecraft/server/packs/repository/PackRepository.java
|
|
+++ b/src/main/java/net/minecraft/server/packs/repository/PackRepository.java
|
|
@@ -88,6 +88,7 @@ public class PackRepository implements AutoCloseable {
|
|
return this.available.keySet();
|
|
}
|
|
|
|
+ public final Collection<Pack> getPacks() { return this.getAvailablePacks(); } // Paper - OBFHELPER
|
|
public Collection<Pack> getAvailablePacks() {
|
|
return this.available.values();
|
|
}
|
|
@@ -96,6 +97,7 @@ public class PackRepository implements AutoCloseable {
|
|
return (Collection) this.selected.stream().map(Pack::getId).collect(ImmutableSet.toImmutableSet());
|
|
}
|
|
|
|
+ public final Collection<Pack> getEnabledPacks() { return this.getSelectedPacks(); } // Paper - OBFHELPER
|
|
public Collection<Pack> getSelectedPacks() {
|
|
return this.selected;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index 6905256147d9bd79e5f52bf86bdb21c89b8411a7..63639923f7875d76f569b8c6e958782c6462d906 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -18,6 +18,7 @@ import com.mojang.serialization.Lifecycle;
|
|
import io.netty.buffer.ByteBuf;
|
|
import io.netty.buffer.ByteBufOutputStream;
|
|
import io.netty.buffer.Unpooled;
|
|
+import io.papermc.paper.datapack.PaperDatapackManager; // Paper
|
|
import io.papermc.paper.util.TraceUtil;
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
|
|
import java.awt.image.BufferedImage;
|
|
@@ -264,6 +265,7 @@ public final class CraftServer implements Server {
|
|
public boolean ignoreVanillaPermissions = false;
|
|
private final List<CraftPlayer> playerView;
|
|
public int reloadCount;
|
|
+ private final PaperDatapackManager datapackManager; // Paper
|
|
public static Exception excessiveVelEx; // Paper - Velocity warnings
|
|
|
|
static {
|
|
@@ -346,6 +348,7 @@ public final class CraftServer implements Server {
|
|
TicketType.PLUGIN.timeout = 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.getPackRepository()); // Paper
|
|
}
|
|
|
|
public boolean getCommandBlockOverride(String command) {
|
|
@@ -2496,5 +2499,11 @@ public final class CraftServer implements Server {
|
|
public com.destroystokyo.paper.entity.ai.MobGoals getMobGoals() {
|
|
return mobGoals;
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public PaperDatapackManager getDatapackManager() {
|
|
+ return datapackManager;
|
|
+ }
|
|
+
|
|
// Paper end
|
|
}
|