summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorUgleh <troti@ymail.com>2018-11-02 18:31:15 +1100
committermd_5 <git@md-5.net>2018-11-02 18:31:57 +1100
commit9be7f0ea9669fe6ec5bde2ab754d8bf32185c125 (patch)
treecb213f01073cad1bc6dadc634c6c058e167a40fd /src/main
parent01e534c6d0d8802a7c9f6fc2ee26a09ed5fa9d5d (diff)
downloadbukkit-9be7f0ea9669fe6ec5bde2ab754d8bf32185c125.tar
bukkit-9be7f0ea9669fe6ec5bde2ab754d8bf32185c125.tar.gz
bukkit-9be7f0ea9669fe6ec5bde2ab754d8bf32185c125.tar.lz
bukkit-9be7f0ea9669fe6ec5bde2ab754d8bf32185c125.tar.xz
bukkit-9be7f0ea9669fe6ec5bde2ab754d8bf32185c125.zip
SPIGOT-4395: Additions to PlayerBedEnterEvent.
Contributions by blablubbabc as well - https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/pull-requests/383/overview
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/bukkit/event/player/PlayerBedEnterEvent.java118
1 files changed, 114 insertions, 4 deletions
diff --git a/src/main/java/org/bukkit/event/player/PlayerBedEnterEvent.java b/src/main/java/org/bukkit/event/player/PlayerBedEnterEvent.java
index 09f1a669..d938883a 100644
--- a/src/main/java/org/bukkit/event/player/PlayerBedEnterEvent.java
+++ b/src/main/java/org/bukkit/event/player/PlayerBedEnterEvent.java
@@ -9,21 +9,131 @@ import org.bukkit.event.HandlerList;
* This event is fired when the player is almost about to enter the bed.
*/
public class PlayerBedEnterEvent extends PlayerEvent implements Cancellable {
+
+ /**
+ * Represents the default possible outcomes of this event.
+ * @deprecated draft API
+ */
+ @Deprecated
+ public enum BedEnterResult {
+ /**
+ * The player will enter the bed.
+ */
+ OK,
+ /**
+ * The world doesn't allow sleeping (ex. Nether or The End). Entering
+ * the bed is prevented and the bed explodes.
+ */
+ NOT_POSSIBLE_HERE,
+ /**
+ * Entering the bed is prevented due to it not being night nor
+ * thundering currently.
+ * <p>
+ * If the event is forcefully allowed during daytime, the player will
+ * enter the bed (and set its bed location), but might get immediately
+ * thrown out again.
+ */
+ NOT_POSSIBLE_NOW,
+ /**
+ * Entering the bed is prevented due to the player being too far away.
+ */
+ TOO_FAR_AWAY,
+ /**
+ * Entering the bed is prevented due to there being monsters nearby.
+ */
+ NOT_SAFE,
+ /**
+ * Entering the bed is prevented due to there being some other problem.
+ */
+ OTHER_PROBLEM;
+ }
+
private static final HandlerList handlers = new HandlerList();
- private boolean cancel = false;
private final Block bed;
+ private final BedEnterResult bedEnterResult;
+ private Result useBed = Result.DEFAULT;
- public PlayerBedEnterEvent(final Player who, final Block bed) {
+ public PlayerBedEnterEvent(Player who, Block bed, BedEnterResult bedEnterResult) {
super(who);
this.bed = bed;
+ this.bedEnterResult = bedEnterResult;
+ }
+
+ @Deprecated
+ public PlayerBedEnterEvent(Player who, Block bed) {
+ this(who, bed, BedEnterResult.OK);
+ }
+
+ /**
+ * This describes the default outcome of this event.
+ *
+ * @return the bed enter result representing the default outcome of this event
+ */
+ public BedEnterResult getBedEnterResult() {
+ return bedEnterResult;
+ }
+
+ /**
+ * This controls the action to take with the bed that was clicked on.
+ * <p>
+ * In case of {@link Result#DEFAULT}, the default outcome is described by
+ * {@link #getBedEnterResult()}.
+ *
+ * @return the action to take with the interacted bed
+ * @see #setUseBed(Result)
+ */
+ public Result useBed() {
+ return useBed;
+ }
+
+ /**
+ * Sets the action to take with the interacted bed.
+ * <p>
+ * {@link Result#ALLOW} will result in the player sleeping, regardless of
+ * the default outcome described by {@link #getBedEnterResult()}.
+ * <br>
+ * {@link Result#DENY} will prevent the player from sleeping. This has the
+ * same effect as canceling the event via {@link #setCancelled(boolean)}.
+ * <br>
+ * {@link Result#DEFAULT} will result in the outcome described by
+ * {@link #getBedEnterResult()}.
+ *
+ * @param useBed the action to take with the interacted bed
+ * @see #useBed()
+ */
+ public void setUseBed(Result useBed) {
+ this.useBed = useBed;
}
+ /**
+ * Gets the cancellation state of this event. Set to true if you want to
+ * prevent the player from sleeping.
+ * <p>
+ * Canceling the event has the same effect as setting {@link #useBed()} to
+ * {@link Result#DENY}.
+ * <p>
+ * For backwards compatibility reasons this also returns true if
+ * {@link #useBed()} is {@link Result#DEFAULT} and the
+ * {@link #getBedEnterResult() default action} is to prevent bed entering.
+ *
+ * @return boolean cancellation state
+ */
+ @Override
public boolean isCancelled() {
- return cancel;
+ return (useBed == Result.DENY || useBed == Result.DEFAULT && bedEnterResult != BedEnterResult.OK);
}
+ /**
+ * Sets the cancellation state of this event. A canceled event will not be
+ * executed in the server, but will still pass to other plugins.
+ * <p>
+ * Canceling this event will prevent use of the bed.
+ *
+ * @param cancel true if you wish to cancel this event
+ */
+ @Override
public void setCancelled(boolean cancel) {
- this.cancel = cancel;
+ setUseBed(cancel ? Result.DENY : useBed() == Result.DENY ? Result.DEFAULT : useBed());
}
/**