so://phie

poppy

A feature-rich Minecraft plugin which enhances gaming experience
git clone git://soophie.de/poppy

blob: 185c351df688aed24e40cd5cf55bf5f9422312fb (2494 bytes)[doc][blame][raw]

1package de.typable.minecrafthub.event;

2

3import org.bukkit.Location;

4import org.bukkit.Material;

5import org.bukkit.block.Block;

6import org.bukkit.block.data.type.Stairs;

7import org.bukkit.entity.AbstractArrow.PickupStatus;

8import org.bukkit.entity.Arrow;

9import org.bukkit.entity.Entity;

10import org.bukkit.entity.Player;

11import org.bukkit.event.EventHandler;

12import org.bukkit.event.Listener;

13import org.bukkit.event.block.Action;

14import org.bukkit.event.player.PlayerInteractEvent;

15import org.bukkit.util.Vector;

16import org.spigotmc.event.entity.EntityDismountEvent;

17

18

19public class ChairListener implements Listener

20{

21 private static final Material[] CHAIR_TYPE = new Material[] {

22 Material.OAK_STAIRS,

23 Material.SPRUCE_STAIRS,

24 Material.BIRCH_STAIRS,

25 Material.JUNGLE_STAIRS,

26 Material.ACACIA_STAIRS,

27 Material.DARK_OAK_STAIRS,

28 Material.ACACIA_STAIRS,

29 Material.CRIMSON_STAIRS,

30 Material.WARPED_STAIRS

31 };

32

33 @SuppressWarnings("deprecation")

34 @EventHandler

35 public void onPlayerInteract(PlayerInteractEvent event)

36 {

37 if(event.getAction() == Action.RIGHT_CLICK_BLOCK)

38 {

39 if(event.getClickedBlock() != null)

40 {

41 Block block = event.getClickedBlock();

42

43 if(isChair(block.getType()))

44 {

45 Block upperBlock = block.getWorld().getBlockAt(block.getLocation().add(0, 1, 0));

46

47 if(upperBlock != null && upperBlock.getType() == Material.AIR)

48 {

49 Stairs stairs = (Stairs) block.getState().getBlockData();

50

51 if(isCompatible(stairs))

52 {

53 Location location = block.getLocation().add(0.5, 0, 0.5);

54 Arrow arrow = (Arrow) block.getWorld().spawnArrow(location, new Vector(), 0F, 0F);

55 arrow.setGravity(false);

56 arrow.setInvulnerable(true);

57 arrow.setPickupStatus(PickupStatus.DISALLOWED);

58 arrow.setPassenger((Entity) event.getPlayer());

59 }

60 }

61 }

62 }

63 }

64 }

65

66 @EventHandler

67 public void onEntityDismount(EntityDismountEvent event)

68 {

69 if(event.getEntity() instanceof Player)

70 {

71 Entity entity = event.getDismounted();

72

73 if(entity != null && entity instanceof Arrow)

74 {

75 entity.remove();

76 }

77 }

78 }

79

80 private boolean isChair(Material material)

81 {

82 for(Material chair : CHAIR_TYPE)

83 {

84 if(material == chair)

85 {

86 return true;

87 }

88 }

89

90 return false;

91 }

92

93 private boolean isCompatible(Stairs stairs)

94 {

95 if(stairs.isWaterlogged())

96 {

97 return false;

98 }

99

100 if(stairs.getShape() != Stairs.Shape.STRAIGHT)

101 {

102 return false;

103 }

104

105 return true;

106 }

107}