|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: SageSphinx63920 <sage@sagesphinx63920.dev> |
| 3 | +Date: Mon, 26 Dec 2022 23:40:13 +0100 |
| 4 | +Subject: [PATCH] Add PreExplodeEvents |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java b/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java |
| 8 | +new file mode 100644 |
| 9 | +index 0000000000000000000000000000000000000000..b7db0db7f3afbccdb07390d1bcada109e9e6b30b |
| 10 | +--- /dev/null |
| 11 | ++++ b/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java |
| 12 | +@@ -0,0 +1,52 @@ |
| 13 | ++package org.purpurmc.purpur.event; |
| 14 | ++ |
| 15 | ++import org.bukkit.block.Block; |
| 16 | ++import org.bukkit.event.Cancellable; |
| 17 | ++import org.bukkit.event.HandlerList; |
| 18 | ++import org.bukkit.event.block.BlockExplodeEvent; |
| 19 | ++import org.jetbrains.annotations.NotNull; |
| 20 | ++import java.util.Collections; |
| 21 | ++ |
| 22 | ++/** |
| 23 | ++ * Called before a block's explosion is processed |
| 24 | ++ */ |
| 25 | ++public class PreBlockExplodeEvent extends BlockExplodeEvent implements Cancellable { |
| 26 | ++ private static final HandlerList handlers = new HandlerList(); |
| 27 | ++ private boolean cancelled; |
| 28 | ++ private final float yield; |
| 29 | ++ |
| 30 | ++ public PreBlockExplodeEvent(@NotNull final Block what, final float yield) { |
| 31 | ++ super(what, Collections.emptyList(), yield); |
| 32 | ++ this.yield = yield; |
| 33 | ++ this.cancelled = false; |
| 34 | ++ } |
| 35 | ++ |
| 36 | ++ /** |
| 37 | ++ * Returns the percentage of blocks to drop from this explosion |
| 38 | ++ * |
| 39 | ++ * @return The yield. |
| 40 | ++ */ |
| 41 | ++ public float getYield() { |
| 42 | ++ return yield; |
| 43 | ++ } |
| 44 | ++ |
| 45 | ++ @Override |
| 46 | ++ public boolean isCancelled() { |
| 47 | ++ return this.cancelled; |
| 48 | ++ } |
| 49 | ++ |
| 50 | ++ @Override |
| 51 | ++ public void setCancelled(boolean cancel) { |
| 52 | ++ this.cancelled = cancel; |
| 53 | ++ } |
| 54 | ++ |
| 55 | ++ @Override |
| 56 | ++ public @NotNull HandlerList getHandlers() { |
| 57 | ++ return handlers; |
| 58 | ++ } |
| 59 | ++ |
| 60 | ++ @NotNull |
| 61 | ++ public static HandlerList getHandlerList() { |
| 62 | ++ return handlers; |
| 63 | ++ } |
| 64 | ++} |
| 65 | +diff --git a/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java b/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java |
| 66 | +new file mode 100644 |
| 67 | +index 0000000000000000000000000000000000000000..2d4f68228861492baaea0bcc604dfef623b337ba |
| 68 | +--- /dev/null |
| 69 | ++++ b/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java |
| 70 | +@@ -0,0 +1,64 @@ |
| 71 | ++package org.purpurmc.purpur.event.entity; |
| 72 | ++ |
| 73 | ++import org.bukkit.Location; |
| 74 | ++import org.bukkit.event.Cancellable; |
| 75 | ++import org.bukkit.event.HandlerList; |
| 76 | ++import org.bukkit.event.entity.EntityExplodeEvent; |
| 77 | ++import org.jetbrains.annotations.NotNull; |
| 78 | ++import java.util.Collections; |
| 79 | ++ |
| 80 | ++/** |
| 81 | ++ * Called before an entity's explosion is processed |
| 82 | ++ */ |
| 83 | ++public class PreEntityExplodeEvent extends EntityExplodeEvent implements Cancellable { |
| 84 | ++ private static final HandlerList handlers = new HandlerList(); |
| 85 | ++ private boolean cancelled; |
| 86 | ++ private final float yield; |
| 87 | ++ private final Location location; |
| 88 | ++ |
| 89 | ++ public PreEntityExplodeEvent(@NotNull org.bukkit.entity.Entity what, @NotNull final Location location, final float yield) { |
| 90 | ++ super(what, location, Collections.emptyList(), yield); |
| 91 | ++ this.cancelled = false; |
| 92 | ++ this.yield = yield; |
| 93 | ++ this.location = location; |
| 94 | ++ } |
| 95 | ++ |
| 96 | ++ /** |
| 97 | ++ * Returns the percentage of blocks to drop from this explosion |
| 98 | ++ * |
| 99 | ++ * @return The yield. |
| 100 | ++ */ |
| 101 | ++ public float getYield() { |
| 102 | ++ return yield; |
| 103 | ++ } |
| 104 | ++ |
| 105 | ++ /** |
| 106 | ++ * Returns the location where the explosion happened. |
| 107 | ++ * |
| 108 | ++ * @return The location of the explosion |
| 109 | ++ */ |
| 110 | ++ @NotNull |
| 111 | ++ public Location getLocation() { |
| 112 | ++ return location; |
| 113 | ++ } |
| 114 | ++ |
| 115 | ++ @Override |
| 116 | ++ public boolean isCancelled() { |
| 117 | ++ return this.cancelled; |
| 118 | ++ } |
| 119 | ++ |
| 120 | ++ @Override |
| 121 | ++ public void setCancelled(boolean cancel) { |
| 122 | ++ this.cancelled = cancel; |
| 123 | ++ } |
| 124 | ++ |
| 125 | ++ @Override |
| 126 | ++ public @NotNull HandlerList getHandlers() { |
| 127 | ++ return handlers; |
| 128 | ++ } |
| 129 | ++ |
| 130 | ++ @NotNull |
| 131 | ++ public static HandlerList getHandlerList() { |
| 132 | ++ return handlers; |
| 133 | ++ } |
| 134 | ++} |
0 commit comments