Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ST;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.block.Sign;
- import org.bukkit.entity.Player;
- import org.bukkit.event.Listener;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- public class SignTeleport extends JavaPlugin implements Listener{
- @Override
- public void onEnable(){
- Bukkit.getServer().getPluginManager().registerEvents(this, this);
- }
- @Override
- public void onDisable(){
- }
- @EventHandler
- public void pressOnSign(PlayerInteractEvent e){
- Player p = e.getPlayer();
- Block clickBlock = e.getClickedBlock();
- Sign sign = (Sign)e.getClickedBlock().getState();
- if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
- if(clickBlock.getType() == org.bukkit.Material.WALL_SIGN) {
- if(canMakeTp(sign, p)){
- double foodLevel=p.getFoodLevel();
- int range=Math.abs(Integer.parseInt(sign.getLine(2))-sign.getY()),
- delFoodLevel=((range/13) + 1);
- if(delFoodLevel>foodLevel){
- p.sendMessage("У тебя недостаточно сытости для телепортации");
- }else{
- p.setFoodLevel((int)(foodLevel - delFoodLevel)); //можно заменить снятие голода на что-то другое
- p.teleport(new Location(sign.getWorld(),sign.getX()+0.5,Integer.parseInt(sign.getLine(2)),sign.getZ()+0.5));
- }
- }
- }
- }
- }
- public static Material whichBlockPlacedSign(Sign s){
- Location l=s.getLocation();
- Block b;
- switch(s.getData().getData()){
- case 2:
- l.setZ(l.getZ()+1);
- b = s.getWorld().getBlockAt(l);
- return b.getType();
- case 4:
- l.setX(l.getX()+1);
- b = s.getWorld().getBlockAt(l);
- return b.getType();
- case 3:
- l.setZ(l.getZ()-1);
- b = s.getWorld().getBlockAt(l);
- return b.getType();
- case 5:
- l.setX(l.getX()-1);
- b = s.getWorld().getBlockAt(l);
- return b.getType();
- default: return Material.AIR;
- }
- }
- public boolean canMakeTp(Sign s, Player p){
- Location l=s.getLocation();
- int num;
- // возможно мир называется по другому
- if(!l.getWorld().getName().equals("world")){
- return false;
- }
- if(!s.getLine(1).matches("ALL")&&!s.getLine(1).matches(p.getName()))
- return false;
- try{
- num=Integer.parseInt(s.getLine(2));
- }catch(NumberFormatException e){
- return false;
- }
- if(!whichBlockPlacedSign(s).equals(Material.DIAMOND_BLOCK))
- return false;
- Block b0=otherBlock(l.getBlock(), num-1),
- b1=otherBlock(l.getBlock(), num),
- b2=otherBlock(l.getBlock(), num+1);
- if(num<=255 && num>=5){
- switch(s.getLine(0)){
- case "UP":
- case "DOWN":
- if(!b1.getType().equals(Material.AIR) || b0.getType().equals(Material.AIR) || b0.isLiquid() || !b2.getType().equals(Material.AIR))
- return false;
- break;
- default: return false;
- }
- }
- return true;
- }
- public Block otherBlock(Block b, int y){
- return b.getWorld().getBlockAt(b.getX(),y,b.getZ());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement