|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jake Potrebic <jake.m.potrebic@gmail.com> |
| 3 | +Date: Sun, 3 Jan 2021 20:03:35 -0800 |
| 4 | +Subject: [PATCH] Add GameEvent tags |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/io/papermc/paper/CraftGameEventTag.java b/src/main/java/io/papermc/paper/CraftGameEventTag.java |
| 8 | +new file mode 100644 |
| 9 | +index 0000000000000000000000000000000000000000..b9614196c360d357ae7e4fcaad5256a12e7cc7cd |
| 10 | +--- /dev/null |
| 11 | ++++ b/src/main/java/io/papermc/paper/CraftGameEventTag.java |
| 12 | +@@ -0,0 +1,31 @@ |
| 13 | ++package io.papermc.paper; |
| 14 | ++ |
| 15 | ++import net.minecraft.core.Registry; |
| 16 | ++import net.minecraft.resources.ResourceLocation; |
| 17 | ++import net.minecraft.tags.TagCollection; |
| 18 | ++import org.bukkit.GameEvent; |
| 19 | ++import org.bukkit.craftbukkit.tag.CraftTag; |
| 20 | ++import org.bukkit.craftbukkit.util.CraftNamespacedKey; |
| 21 | ++import org.jetbrains.annotations.NotNull; |
| 22 | ++ |
| 23 | ++import java.util.Collections; |
| 24 | ++import java.util.Objects; |
| 25 | ++import java.util.Set; |
| 26 | ++import java.util.stream.Collectors; |
| 27 | ++ |
| 28 | ++public class CraftGameEventTag extends CraftTag<net.minecraft.world.level.gameevent.GameEvent, GameEvent> { |
| 29 | ++ |
| 30 | ++ public CraftGameEventTag(TagCollection<net.minecraft.world.level.gameevent.GameEvent> registry, ResourceLocation tag) { |
| 31 | ++ super(registry, tag); |
| 32 | ++ } |
| 33 | ++ |
| 34 | ++ @Override |
| 35 | ++ public boolean isTagged(@NotNull GameEvent item) { |
| 36 | ++ return this.getHandle().contains(Registry.GAME_EVENT.get(CraftNamespacedKey.toMinecraft(item.getKey()))); |
| 37 | ++ } |
| 38 | ++ |
| 39 | ++ @Override |
| 40 | ++ public @NotNull Set<GameEvent> getValues() { |
| 41 | ++ return this.getHandle().getValues().stream().map(ge -> Objects.requireNonNull(GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(Registry.GAME_EVENT.getKey(ge))), ge + " is not a recognized game event")).collect(Collectors.toUnmodifiableSet()); |
| 42 | ++ } |
| 43 | ++} |
| 44 | +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java |
| 45 | +index f0629cac377b29246e990a01d60601270cbd77bd..dbbae437123163c60c3f60a48043967a8adbd124 100644 |
| 46 | +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java |
| 47 | ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java |
| 48 | +@@ -2561,6 +2561,12 @@ public final class CraftServer implements Server { |
| 49 | + Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace must have entity type"); |
| 50 | + |
| 51 | + return (org.bukkit.Tag<T>) new CraftEntityTag(EntityTypeTags.getAllTags(), key); |
| 52 | ++ // Paper start |
| 53 | ++ case org.bukkit.Tag.REGISTRY_GAME_EVENTS: |
| 54 | ++ Preconditions.checkArgument(clazz == org.bukkit.GameEvent.class, "Game Event namespace must have GameEvent type"); |
| 55 | ++ |
| 56 | ++ return (org.bukkit.Tag<T>) new io.papermc.paper.CraftGameEventTag(net.minecraft.tags.GameEventTags.getAllTags(), key); |
| 57 | ++ // Paper end |
| 58 | + default: |
| 59 | + throw new IllegalArgumentException(); |
| 60 | + } |
| 61 | +@@ -2590,6 +2596,13 @@ public final class CraftServer implements Server { |
| 62 | + |
| 63 | + TagCollection<EntityType<?>> entityTags = EntityTypeTags.getAllTags(); |
| 64 | + return entityTags.getAllTags().keySet().stream().map(key -> (org.bukkit.Tag<T>) new CraftEntityTag(entityTags, key)).collect(ImmutableList.toImmutableList()); |
| 65 | ++ // Paper start |
| 66 | ++ case org.bukkit.Tag.REGISTRY_GAME_EVENTS: |
| 67 | ++ Preconditions.checkArgument(clazz == org.bukkit.GameEvent.class); |
| 68 | ++ |
| 69 | ++ TagCollection<net.minecraft.world.level.gameevent.GameEvent> gameEvents = net.minecraft.tags.GameEventTags.getAllTags(); |
| 70 | ++ return gameEvents.getAllTags().keySet().stream().map(key -> (org.bukkit.Tag<T>) new io.papermc.paper.CraftGameEventTag(gameEvents, key)).toList(); |
| 71 | ++ // Paper end |
| 72 | + default: |
| 73 | + throw new IllegalArgumentException(); |
| 74 | + } |
0 commit comments