summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/event/entity/CreeperPowerEvent.java
blob: a670696c67a67132242c5be2fdf4987ecb6b0eeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package org.bukkit.event.entity;

import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;

/**
 * Called when a Creeper is struck by lightning.
 *<p />
 * If a Creeper Power event is cancelled, the Creeper will not be powered.
 */
public class CreeperPowerEvent extends EntityEvent implements Cancellable {

    private boolean canceled;
    private PowerCause cause;
    private Entity bolt;

    public CreeperPowerEvent(Entity creeper, Entity bolt, PowerCause cause) {
        super(Type.CREEPER_POWER, creeper);
        this.bolt = bolt;
        this.cause = cause;
    }

    public CreeperPowerEvent(Entity creeper, PowerCause cause) {
        super(Type.CREEPER_POWER, creeper);
        this.cause = cause;
        this.bolt = null;
    }

    public boolean isCancelled() {
        return canceled;
    }

    public void setCancelled(boolean cancel) {
        canceled = cancel;
    }

    /**
     * Gets the lightning bolt which is striking the Creeper.
     *
     * @return The Entity for the lightning bolt which is striking the Creeper
     */
    public Entity getLightning() {
        return bolt;
    }

    /**
     * Gets the cause of the creeper being (un)powered.
     *
     * @return A PowerCause value detailing the cause of change in power.
     */
    public PowerCause getCause() {
        return cause;
    }

    /**
     * An enum to specify the cause of the change in power
     */
    public enum PowerCause {

        /**
         * Power change caused by a lightning bolt
         * Powered state: true
         */
        LIGHTNING,
        /**
         * Power change caused by something else (probably a plugin)
         * Powered state: true
         */
        SET_ON,
        /**
         * Power change caused by something else (probably a plugin)
         * Powered state: false
         */
        SET_OFF
    }
}