Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. package ru.skidrowapi.myproject;
  2.  
  3. import java.lang.String;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.block.Action;
  11. import org.bukkit.event.player.PlayerInteractEvent;
  12. import org.bukkit.inventory.ItemStack;
  13.  
  14. import java.util.Objects;
  15.  
  16. public class Ender implements Listener {
  17.  
  18. @EventHandler
  19. public void user(PlayerInteractEvent e) {
  20.  
  21. if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
  22. if (e.getPlayer().getItemInHand().getType() != Material.EYE_OF_ENDER) return;
  23. Player p = e.getPlayer();
  24. ItemStack item = e.getPlayer().getItemInHand();
  25. if (!item.getItemMeta().hasDisplayName()) return;
  26. if (!item.getItemMeta().hasLore()) return;
  27. if (!item.getItemMeta().hasDisplayName().quals (ChatColor.GREEN + "Teleporter")) return;
  28.  
  29.  
  30. e.setCancelled(true);
  31. removeItem(p);
  32. teleport(p);
  33. }
  34.  
  35. private void removeItem(Player p) {
  36. ItemStack item = p.getItemInHand();
  37. item.setAmount(item.getAmount() - 1); //уменьшение предмета на 1 после использования
  38. p.setItemInHand(item);
  39. }
  40.  
  41. private void teleport(Player p) {
  42. Location loc = p.getLocation();
  43. float yaw = loc.getYaw();
  44. float pitch = loc.getPitch();
  45. if (pitch < -40 || pitch > 40) {
  46. vertical(p);
  47. return;
  48. }
  49. }
  50.  
  51.  
  52. private void vertical(Player p) {
  53. Location loc = p.getLocation();
  54. float pitch = loc.getPitch();
  55. if (pitch < -40) {
  56. loc.setY(loc.getY() + 4);
  57. if (block(loc)) p.teleport(loc);
  58. }
  59. }
  60.  
  61. private boolean block (Location loc){
  62. int x = loc.getBlockX();
  63. int y = loc.getBlockY();
  64. int z = loc.getBlockZ();
  65. if (loc.getWorld().getBlockAt(x, y, z).getType() != Material.AIR) return false;
  66. if (loc.getWorld().getBlockAt(x, y, z).getType() != Material.AIR) return false;
  67. return true;
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement