Commits
coll1234567 authored and md_5 committed 653d7edb32b
1 + | package org.bukkit.event.block; |
2 + | |
3 + | import org.bukkit.block.Block; |
4 + | import org.bukkit.entity.Entity; |
5 + | import org.bukkit.event.Cancellable; |
6 + | import org.bukkit.event.HandlerList; |
7 + | import org.jetbrains.annotations.NotNull; |
8 + | import org.jetbrains.annotations.Nullable; |
9 + | |
10 + | /** |
11 + | * Called when a block of TNT in the world become primed. |
12 + | * <p> |
13 + | * If a TNT Prime event is cancelled, the block of TNT will not become primed. |
14 + | */ |
15 + | public class TNTPrimeEvent extends BlockEvent implements Cancellable { |
16 + | |
17 + | private static final HandlerList handlers = new HandlerList(); |
18 + | private boolean cancelled; |
19 + | private final PrimeCause igniteCause; |
20 + | private final Entity primingEntity; |
21 + | private final Block primingBlock; |
22 + | |
23 + | public TNTPrimeEvent( final Block block, final PrimeCause igniteCause, final Entity primingEntity, final Block primingBlock) { |
24 + | super(block); |
25 + | this.igniteCause = igniteCause; |
26 + | this.primingEntity = primingEntity; |
27 + | this.primingBlock = primingBlock; |
28 + | } |
29 + | |
30 + | |
31 + | public boolean isCancelled() { |
32 + | return cancelled; |
33 + | } |
34 + | |
35 + | |
36 + | public void setCancelled(boolean cancel) { |
37 + | this.cancelled = cancel; |
38 + | } |
39 + | |
40 + | /** |
41 + | * Get the cause of the TNT becoming primed. |
42 + | * |
43 + | * @return the cause |
44 + | */ |
45 + | |
46 + | public PrimeCause getCause() { |
47 + | return igniteCause; |
48 + | } |
49 + | |
50 + | /** |
51 + | * Get the entity that caused the TNT to be primed. |
52 + | * |
53 + | * @return the entity that caused the TNT to be primed, or null if it was |
54 + | * not caused by an entity. |
55 + | */ |
56 + | |
57 + | public Entity getPrimingEntity() { |
58 + | return primingEntity; |
59 + | } |
60 + | |
61 + | /** |
62 + | * Get the block that caused the TNT to be primed. |
63 + | * |
64 + | * @return the block that caused the TNT to be primed, or null if it was not |
65 + | * caused by a block. |
66 + | */ |
67 + | |
68 + | public Block getPrimingBlock() { |
69 + | return primingBlock; |
70 + | } |
71 + | |
72 + | |
73 + | |
74 + | public HandlerList getHandlers() { |
75 + | return handlers; |
76 + | } |
77 + | |
78 + | |
79 + | public static HandlerList getHandlerList() { |
80 + | return handlers; |
81 + | } |
82 + | |
83 + | /** |
84 + | * An enum to represent the cause of a TNT block becoming primed. |
85 + | */ |
86 + | public enum PrimeCause { |
87 + | |
88 + | /** |
89 + | * When TNT is primed by fire spreading. |
90 + | */ |
91 + | FIRE, |
92 + | /** |
93 + | * When TNT is primed by a redstone signal. |
94 + | */ |
95 + | REDSTONE, |
96 + | /** |
97 + | * When TNT is primed by a player interacting with it directly. |
98 + | */ |
99 + | PLAYER, |
100 + | /** |
101 + | * When TNT is primed by a nearby explosion. |
102 + | */ |
103 + | EXPLOSION, |
104 + | /** |
105 + | * When TNT is primed after getting hit with a burning projectile. |
106 + | */ |
107 + | PROJECTILE, |
108 + | /** |
109 + | * When TNT with the unstable block state set to true is broken. |
110 + | * <p> |
111 + | * Note: Canceling a prime event with this cause will stop the primed |
112 + | * TNT from spawning but will not stop the block from being broken. |
113 + | */ |
114 + | BLOCK_BREAK, |
115 + | /** |
116 + | * When TNT is primed by a dispenser holding flint and steel. |
117 + | * <p> |
118 + | * Note: This event is not called for a dispenser dispensing TNT |
119 + | * directly. |
120 + | */ |
121 + | DISPENSER; |
122 + | } |
123 + | } |