diff options
author | Ugleh <troti@ymail.com> | 2018-11-02 18:31:00 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-11-02 18:32:19 +1100 |
commit | a8000588cb9368dfedac1536e83ad6d99714f2aa (patch) | |
tree | 1a465f1c090ade41cba4bdd93a7b487124f67645 /src/main | |
parent | aed3aecbafff223bb8c48ace7cb18f8a7dd0b6d5 (diff) | |
download | craftbukkit-a8000588cb9368dfedac1536e83ad6d99714f2aa.tar craftbukkit-a8000588cb9368dfedac1536e83ad6d99714f2aa.tar.gz craftbukkit-a8000588cb9368dfedac1536e83ad6d99714f2aa.tar.lz craftbukkit-a8000588cb9368dfedac1536e83ad6d99714f2aa.tar.xz craftbukkit-a8000588cb9368dfedac1536e83ad6d99714f2aa.zip |
SPIGOT-4395: Additions to PlayerBedEnterEvent.
Contributions by blablubbabc as well - https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/pull-requests/500/overview
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index df8e99f2..328322c1 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -52,6 +52,7 @@ import org.bukkit.entity.ThrownExpBottle; import org.bukkit.entity.ThrownPotion; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; +import org.bukkit.event.Event.Result; import org.bukkit.event.block.*; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.event.entity.*; @@ -63,6 +64,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.PrepareAnvilEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.event.player.*; +import org.bukkit.event.player.PlayerBedEnterEvent.BedEnterResult; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.InventoryView; @@ -100,6 +102,44 @@ public class CraftEventFactory { } /** + * PlayerBedEnterEvent + */ + public static EntityHuman.EnumBedResult callPlayerBedEnterEvent(EntityHuman player, BlockPosition bed, EntityHuman.EnumBedResult nmsBedResult) { + BedEnterResult bedEnterResult; + switch (nmsBedResult) { + case OK: + bedEnterResult = BedEnterResult.OK; + break; + case NOT_POSSIBLE_HERE: + bedEnterResult = BedEnterResult.NOT_POSSIBLE_HERE; + break; + case NOT_POSSIBLE_NOW: + bedEnterResult = BedEnterResult.NOT_POSSIBLE_NOW; + break; + case TOO_FAR_AWAY: + bedEnterResult = BedEnterResult.TOO_FAR_AWAY; + break; + case NOT_SAFE: + bedEnterResult = BedEnterResult.NOT_SAFE; + break; + default: + bedEnterResult = BedEnterResult.OTHER_PROBLEM; + } + + PlayerBedEnterEvent event = new PlayerBedEnterEvent((Player) player.getBukkitEntity(), CraftBlock.at(player.world, bed), bedEnterResult); + Bukkit.getServer().getPluginManager().callEvent(event); + + Result result = event.useBed(); + if (result == Result.ALLOW) { + return EntityHuman.EnumBedResult.OK; + } else if (result == Result.DENY) { + return EntityHuman.EnumBedResult.OTHER_PROBLEM; + } + + return nmsBedResult; + } + + /** * Block place methods */ public static BlockMultiPlaceEvent callBlockMultiPlaceEvent(World world, EntityHuman who, EnumHand hand, List<BlockState> blockStates, int clickedX, int clickedY, int clickedZ) { |