Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
3b9db2b194
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: bb4e97c6 Add support for Java 23 bc6874dd Bump asm to 9.7.1 50e8a00b PR-1064: Add specific getTopInventory methods for InventoryView derivatives 758b0a0f SPIGOT-7911: Fix Location#isWorldLoaded() for re-loaded worlds 133a64a7 Improve Registry#getOrThrow messages be0f5957 PR-1058: Add tests for Minecraft registry <-> Bukkit fields d1b31df2 PR-1062: Clarify BeaconView documentation 3fab4384 PR-1060: Cache Material to BlockType and ItemType conversion 967a7301 SPIGOT-7906: Increase YAML nesting limit to 100 6ecf033d SPIGOT-7899: Smithing recipes don't require inputs CraftBukkit Changes: 0a7bd6c81 PR-1493: Improve reroute performance and add some tests 54941524c Add support for Java 23 f4d957fff SPIGOT-7915: Fix World#getKeepSpawnInMemory() using Spawn Radius rather than Spawn Chunk Radius ded183674 Fix HIDE_ENCHANTS flag in items without enchantments 308785a0a Bump asm to 9.7.1 and re-add ClassReader to ClassWriter 72ce823cd PR-1487: Add specific getTopInventory methods for InventoryView derivatives 11a5e840c SPIGOT-7907, PR-1484: Improve merchant recipe item matching behavior to more closely align with older versions 45b66f7e4 SPIGOT-7909: Always set HIDE_ENCHANTS flag to item if flag is set 963459791 Increase outdated build delay fc5b2d75f SPIGOT-7910: Fix launching breeze wind charge from API and improve dispenser launch API c7d6428f2 SPIGOT-7856, PR-1483: End platform not dropping items after replacing blocks 2a5572b52 SPIGOT-7780, PR-1482: Cannot edit chunks during unload event 527041ab5 SPIGOT-7902, PR-1477: Fix CraftMetaPotion#hasCustomEffects() does not check if customEffects (List) is empty 5529a1769 Implement base methods for tags 30fbdbaaf Improve Registry#getOrThrow messages 6b71a7322 PR-1475: Add tests for Minecraft registry <-> Bukkit fields 5f24c255c SPIGOT-7908: Mark junit-platform-suite-engine as test scope e4c92ef65 PR-1473: Change tests to use suites, to run tests in different environments and feature flags d25e1e722 PR-1481: Fix BeaconView#set[X]Effect(null) d69a05362 PR-1480: Fix PerMaterialTest#isEdible test running for legacy materials bb3284a89 PR-1479: Use custom #isBlock method in legacy init instead of the one in Material, since it relies on legacy being init 98c57cbbe SPIGOT-7904: Fix NPE for PlayerItemBreakEvent f35bae9ec Fix missing hasJukeboxPlayable 8a6f8b6d8 SPIGOT-7881: CTRL+Pick Block saves position data into item 7913b3be7 SPIGOT-7899: Smithing recipes don't require inputs
210 Zeilen
7.9 KiB
Diff
210 Zeilen
7.9 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
|
|
|
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
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..8bd8263b51fb2bb364353565b1ba26b3b0d1d55e
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/datapack/PaperDatapack.java
|
|
@@ -0,0 +1,103 @@
|
|
+package io.papermc.paper.datapack;
|
|
+
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
+import io.papermc.paper.event.server.ServerResourcesReloadedEvent;
|
|
+import io.papermc.paper.world.flag.PaperFeatureFlagProviderImpl;
|
|
+import java.util.ArrayList;
|
|
+import java.util.List;
|
|
+import java.util.Map;
|
|
+import java.util.Set;
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.server.packs.repository.Pack;
|
|
+import net.minecraft.server.packs.repository.PackSource;
|
|
+import org.bukkit.FeatureFlag;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+import org.checkerframework.checker.nullness.qual.Nullable;
|
|
+import org.checkerframework.framework.qual.DefaultQualifier;
|
|
+
|
|
+@DefaultQualifier(NonNull.class)
|
|
+public class PaperDatapack implements Datapack {
|
|
+
|
|
+ private static final Map<PackSource, DatapackSource> PACK_SOURCES = new ConcurrentHashMap<>();
|
|
+ static {
|
|
+ PACK_SOURCES.put(PackSource.DEFAULT, DatapackSource.DEFAULT);
|
|
+ PACK_SOURCES.put(PackSource.BUILT_IN, DatapackSource.BUILT_IN);
|
|
+ PACK_SOURCES.put(PackSource.FEATURE, DatapackSource.FEATURE);
|
|
+ PACK_SOURCES.put(PackSource.WORLD, DatapackSource.WORLD);
|
|
+ PACK_SOURCES.put(PackSource.SERVER, DatapackSource.SERVER);
|
|
+ }
|
|
+
|
|
+ private final Pack pack;
|
|
+ private final boolean enabled;
|
|
+
|
|
+ PaperDatapack(final Pack pack, final boolean enabled) {
|
|
+ this.pack = pack;
|
|
+ this.enabled = enabled;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getName() {
|
|
+ return this.pack.getId();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Component getTitle() {
|
|
+ return PaperAdventure.asAdventure(this.pack.getTitle());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Component getDescription() {
|
|
+ return PaperAdventure.asAdventure(this.pack.getDescription());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isRequired() {
|
|
+ return this.pack.isRequired();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Compatibility getCompatibility() {
|
|
+ return Datapack.Compatibility.valueOf(this.pack.getCompatibility().name());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Set<FeatureFlag> getRequiredFeatures() {
|
|
+ return PaperFeatureFlagProviderImpl.fromNms(this.pack.getRequestedFeatures());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isEnabled() {
|
|
+ return this.enabled;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setEnabled(final boolean enabled) {
|
|
+ final MinecraftServer server = MinecraftServer.getServer();
|
|
+ final List<Pack> enabledPacks = new ArrayList<>(server.getPackRepository().getSelectedPacks());
|
|
+ final @Nullable Pack packToChange = server.getPackRepository().getPack(this.getName());
|
|
+ if (packToChange == null) {
|
|
+ throw new IllegalStateException("Cannot toggle state of pack that doesn't exist: " + this.getName());
|
|
+ }
|
|
+ if (enabled == enabledPacks.contains(packToChange)) {
|
|
+ return;
|
|
+ }
|
|
+ if (enabled) {
|
|
+ packToChange.getDefaultPosition().insert(enabledPacks, packToChange, Pack::selectionConfig, false); // modeled off the default /datapack enable logic
|
|
+ } else {
|
|
+ enabledPacks.remove(packToChange);
|
|
+ }
|
|
+ server.reloadResources(enabledPacks.stream().map(Pack::getId).toList(), ServerResourcesReloadedEvent.Cause.PLUGIN);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public DatapackSource getSource() {
|
|
+ return PACK_SOURCES.computeIfAbsent(this.pack.location().source(), source -> new DatapackSourceImpl(source.toString()));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Component computeDisplayName() {
|
|
+ return PaperAdventure.asAdventure(this.pack.getChatLink(this.enabled));
|
|
+ }
|
|
+}
|
|
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..caa41c525d2b36b5a9f9942380f06c97d5781a93
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/datapack/PaperDatapackManager.java
|
|
@@ -0,0 +1,55 @@
|
|
+package io.papermc.paper.datapack;
|
|
+
|
|
+import com.google.common.collect.Collections2;
|
|
+import java.util.Collection;
|
|
+import java.util.Collections;
|
|
+import java.util.function.Predicate;
|
|
+import net.minecraft.server.packs.repository.Pack;
|
|
+import net.minecraft.server.packs.repository.PackRepository;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+import org.checkerframework.checker.nullness.qual.Nullable;
|
|
+import org.checkerframework.framework.qual.DefaultQualifier;
|
|
+
|
|
+@DefaultQualifier(NonNull.class)
|
|
+public class PaperDatapackManager implements DatapackManager {
|
|
+
|
|
+ private final PackRepository repository;
|
|
+
|
|
+ public PaperDatapackManager(final PackRepository repository) {
|
|
+ this.repository = repository;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void refreshPacks() {
|
|
+ this.repository.reload();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @Nullable Datapack getPack(final @NonNull String name) {
|
|
+ final @Nullable Pack pack = this.repository.getPack(name);
|
|
+ if (pack == null) {
|
|
+ return null;
|
|
+ }
|
|
+ return new PaperDatapack(pack, this.repository.getSelectedPacks().contains(pack));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Collection<Datapack> getPacks() {
|
|
+ final Collection<Pack> enabledPacks = this.repository.getSelectedPacks();
|
|
+ return this.transformPacks(this.repository.getAvailablePacks(), enabledPacks::contains);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Collection<Datapack> getEnabledPacks() {
|
|
+ return this.transformPacks(this.repository.getSelectedPacks(), pack -> true);
|
|
+ }
|
|
+
|
|
+ private Collection<Datapack> transformPacks(final Collection<Pack> packs, final Predicate<Pack> enabled) {
|
|
+ return Collections.unmodifiableCollection(
|
|
+ Collections2.transform(
|
|
+ packs,
|
|
+ pack -> new PaperDatapack(pack, enabled.test(pack))
|
|
+ )
|
|
+ );
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index a9c6f53c7e828a4b7d0cefbaa98e50ff1db9354a..a142c62a51ddf59e968c3ddb401dc137c4c07ef6 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -305,6 +305,7 @@ public final class CraftServer implements Server {
|
|
private final List<CraftPlayer> playerView;
|
|
public int reloadCount;
|
|
public Set<String> activeCompatibilities = Collections.emptySet();
|
|
+ private final io.papermc.paper.datapack.PaperDatapackManager datapackManager; // Paper
|
|
public static Exception excessiveVelEx; // Paper - Velocity warnings
|
|
|
|
static {
|
|
@@ -390,6 +391,7 @@ public final class CraftServer implements Server {
|
|
if (this.configuration.getBoolean("settings.use-map-color-cache")) {
|
|
MapPalette.setMapColorCache(new CraftMapColorCache(this.logger));
|
|
}
|
|
+ datapackManager = new io.papermc.paper.datapack.PaperDatapackManager(console.getPackRepository()); // Paper
|
|
}
|
|
|
|
public boolean getCommandBlockOverride(String command) {
|
|
@@ -3008,5 +3010,11 @@ public final class CraftServer implements Server {
|
|
public com.destroystokyo.paper.entity.ai.MobGoals getMobGoals() {
|
|
return mobGoals;
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public io.papermc.paper.datapack.PaperDatapackManager getDatapackManager() {
|
|
+ return datapackManager;
|
|
+ }
|
|
+
|
|
// Paper end
|
|
}
|