A feature-rich Minecraft plugin which enhances gaming experience
git clone git://soophie.de/poppy
blob: 3b8fa9923caca6c4fecda195d94bd607a27f4ed5 (2535 bytes)[doc][blame][raw]
1
package de.typable.minecrafthub.event;3
import org.bukkit.Location;4
import org.bukkit.Material;5
import org.bukkit.block.Block;6
import org.bukkit.block.data.type.Stairs;7
import org.bukkit.entity.AbstractArrow.PickupStatus;8
import org.bukkit.entity.Arrow;9
import org.bukkit.entity.Entity;10
import org.bukkit.entity.Player;11
import org.bukkit.event.EventHandler;12
import org.bukkit.event.Listener;13
import org.bukkit.event.block.Action;14
import org.bukkit.event.player.PlayerInteractEvent;15
import org.bukkit.util.Vector;16
import org.spigotmc.event.entity.EntityDismountEvent;19
public class ChairListener implements Listener20
{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_STAIRS31
};33
@SuppressWarnings("deprecation")34
@EventHandler35
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();43
if(isChair(block.getType()))44
{45
Block upperBlock = block.getWorld().getBlockAt(block.getLocation().add(0, 1, 0));47
if(upperBlock != null && upperBlock.getType() == Material.AIR)48
{49
Stairs stairs = (Stairs) block.getState().getBlockData();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());60
event.setCancelled(true);61
}62
}63
}64
}65
}66
}68
@EventHandler69
public void onEntityDismount(EntityDismountEvent event)70
{71
if(event.getEntity() instanceof Player)72
{73
Entity entity = event.getDismounted();75
if(entity != null && entity instanceof Arrow)76
{77
entity.remove();78
}79
}80
}82
private boolean isChair(Material material)83
{84
for(Material chair : CHAIR_TYPE)85
{86
if(material == chair)87
{88
return true;89
}90
}92
return false;93
}95
private boolean isCompatible(Stairs stairs)96
{97
if(stairs.isWaterlogged())98
{99
return false;100
}102
if(stairs.getShape() != Stairs.Shape.STRAIGHT)103
{104
return false;105
}107
return true;108
}109
}