diff options
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) { |