From b3c84b4e7deca504907a4f0f5fd7b136f0bcdf63 Mon Sep 17 00:00:00 2001 From: Jake Potrebic <jake.m.potrebic@gmail.com> Date: Sat, 21 Aug 2021 07:26:42 -0700 Subject: [PATCH] Add API to send game events (#6444) --- patches/api/More-World-API.patch | 9 +++++++++ patches/server/More-World-API.patch | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/patches/api/More-World-API.patch b/patches/api/More-World-API.patch index e2cc9b5e87..65b4856be4 100644 --- a/patches/api/More-World-API.patch +++ b/patches/api/More-World-API.patch @@ -109,6 +109,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + */ + @NotNull + Collection<Material> getInfiniburn(); ++ ++ /** ++ * Posts a specified game event at a location ++ * ++ * @param sourceEntity optional source entity ++ * @param gameEvent the game event to post ++ * @param position the position in the world where to post the event to listeners ++ */ ++ void sendGameEvent(@Nullable Entity sourceEntity, @NotNull GameEvent gameEvent, @NotNull Vector position); + // Paper end + // Spigot start diff --git a/patches/server/More-World-API.patch b/patches/server/More-World-API.patch index 850153777a..d55b35955d 100644 --- a/patches/server/More-World-API.patch +++ b/patches/server/More-World-API.patch @@ -64,8 +64,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public Collection<org.bukkit.Material> getInfiniburn() { + return com.google.common.collect.Sets.newHashSet(com.google.common.collect.Iterators.transform(getHandle().dimensionType().infiniburn().getValues().iterator(), CraftMagicNumbers::getMaterial)); + } ++ ++ @Override ++ public void sendGameEvent(Entity sourceEntity, org.bukkit.GameEvent gameEvent, Vector position) { ++ getHandle().gameEvent(sourceEntity != null ? ((CraftEntity) sourceEntity).getHandle(): null, net.minecraft.core.Registry.GAME_EVENT.get(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(gameEvent.getKey())), org.bukkit.craftbukkit.util.CraftVector.toBlockPos(position)); ++ } + // Paper end + @Override public Raid locateNearestRaid(Location location, int radius) { Validate.notNull(location, "Location cannot be null"); +diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftVector.java b/src/main/java/org/bukkit/craftbukkit/util/CraftVector.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/CraftVector.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/CraftVector.java +@@ -0,0 +0,0 @@ public final class CraftVector { + public static net.minecraft.world.phys.Vec3 toNMS(org.bukkit.util.Vector bukkit) { + return new net.minecraft.world.phys.Vec3(bukkit.getX(), bukkit.getY(), bukkit.getZ()); + } ++ // Paper start ++ public static org.bukkit.util.Vector toBukkit(net.minecraft.core.BlockPos blockPosition) { ++ return new org.bukkit.util.Vector(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ()); ++ } ++ ++ public static net.minecraft.core.BlockPos toBlockPos(org.bukkit.util.Vector bukkit) { ++ return new net.minecraft.core.BlockPos(bukkit.getX(), bukkit.getY(), bukkit.getZ()); ++ } ++ // Paper end + }