Skip to content

Commit f5b9e07

Browse files
Add GameEvent tags (#6439)
1 parent 2a4aef3 commit f5b9e07

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jake Potrebic <jake.m.potrebic@gmail.com>
3+
Date: Sat, 18 Dec 2021 10:34:21 -0800
4+
Subject: [PATCH] Add GameEvent tags
5+
6+
7+
diff --git a/src/main/java/org/bukkit/Tag.java b/src/main/java/org/bukkit/Tag.java
8+
index ddd195a834d1756c903644fc1faffe7ebcb238ed..43ab88bb3721ed499549a9d328be352d6f639871 100644
9+
--- a/src/main/java/org/bukkit/Tag.java
10+
+++ b/src/main/java/org/bukkit/Tag.java
11+
@@ -735,6 +735,18 @@ public interface Tag<T extends Keyed> extends Keyed {
12+
*/
13+
@Deprecated(forRemoval = true)
14+
Tag<EntityType> SKELETONS = ENTITY_TYPES_SKELETONS;
15+
+
16+
+ String REGISTRY_GAME_EVENTS = "game_events";
17+
+
18+
+ /**
19+
+ * Tag for game events that trigger sculk sensors
20+
+ */
21+
+ Tag<GameEvent> GAME_EVENT_VIBRATIONS = Bukkit.getTag(REGISTRY_GAME_EVENTS, NamespacedKey.minecraft("vibrations"), GameEvent.class);
22+
+
23+
+ /**
24+
+ * Tag for game events that are ignored if the entity is sneaking
25+
+ */
26+
+ Tag<GameEvent> GAME_EVENT_IGNORE_VIBRATIONS_SNEAKING = Bukkit.getTag(REGISTRY_GAME_EVENTS, NamespacedKey.minecraft("ignore_vibrations_sneaking"), GameEvent.class);
27+
// Paper end
28+
29+
/**
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)