From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 3 Jan 2021 20:03:35 -0800
Subject: [PATCH] Add GameEvent tags


diff --git a/src/main/java/io/papermc/paper/CraftGameEventTag.java b/src/main/java/io/papermc/paper/CraftGameEventTag.java
new file mode 100644
index 0000000000000000000000000000000000000000..b9614196c360d357ae7e4fcaad5256a12e7cc7cd
--- /dev/null
+++ b/src/main/java/io/papermc/paper/CraftGameEventTag.java
@@ -0,0 +1,31 @@
+package io.papermc.paper;
+
+import net.minecraft.core.Registry;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.tags.TagCollection;
+import org.bukkit.GameEvent;
+import org.bukkit.craftbukkit.tag.CraftTag;
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Collections;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class CraftGameEventTag extends CraftTag<net.minecraft.world.level.gameevent.GameEvent, GameEvent> {
+
+    public CraftGameEventTag(TagCollection<net.minecraft.world.level.gameevent.GameEvent> registry, ResourceLocation tag) {
+        super(registry, tag);
+    }
+
+    @Override
+    public boolean isTagged(@NotNull GameEvent item) {
+        return this.getHandle().contains(Registry.GAME_EVENT.get(CraftNamespacedKey.toMinecraft(item.getKey())));
+    }
+
+    @Override
+    public @NotNull Set<GameEvent> getValues() {
+        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());
+    }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index f0629cac377b29246e990a01d60601270cbd77bd..dbbae437123163c60c3f60a48043967a8adbd124 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2561,6 +2561,12 @@ public final class CraftServer implements Server {
                 Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace must have entity type");
 
                 return (org.bukkit.Tag<T>) new CraftEntityTag(EntityTypeTags.getAllTags(), key);
+            // Paper start
+            case org.bukkit.Tag.REGISTRY_GAME_EVENTS:
+                Preconditions.checkArgument(clazz == org.bukkit.GameEvent.class, "Game Event namespace must have GameEvent type");
+
+                return (org.bukkit.Tag<T>) new io.papermc.paper.CraftGameEventTag(net.minecraft.tags.GameEventTags.getAllTags(), key);
+            // Paper end
             default:
                 throw new IllegalArgumentException();
         }
@@ -2590,6 +2596,13 @@ public final class CraftServer implements Server {
 
                 TagCollection<EntityType<?>> entityTags = EntityTypeTags.getAllTags();
                 return entityTags.getAllTags().keySet().stream().map(key -> (org.bukkit.Tag<T>) new CraftEntityTag(entityTags, key)).collect(ImmutableList.toImmutableList());
+                // Paper start
+            case org.bukkit.Tag.REGISTRY_GAME_EVENTS:
+                Preconditions.checkArgument(clazz == org.bukkit.GameEvent.class);
+
+                TagCollection<net.minecraft.world.level.gameevent.GameEvent> gameEvents = net.minecraft.tags.GameEventTags.getAllTags();
+                return gameEvents.getAllTags().keySet().stream().map(key -> (org.bukkit.Tag<T>) new io.papermc.paper.CraftGameEventTag(gameEvents, key)).toList();
+                // Paper end
             default:
                 throw new IllegalArgumentException();
         }
