Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.skidrowapi.myproject;
- import java.lang.String;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.ItemStack;
- import java.util.Objects;
- public class Ender implements Listener {
- @EventHandler
- public void user(PlayerInteractEvent e) {
- if (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
- if (e.getPlayer().getItemInHand().getType() != Material.EYE_OF_ENDER) return;
- Player p = e.getPlayer();
- ItemStack item = e.getPlayer().getItemInHand();
- if (!item.getItemMeta().hasDisplayName()) return;
- if (!item.getItemMeta().hasLore()) return;
- if (!item.getItemMeta().hasDisplayName().quals (ChatColor.GREEN + "Teleporter")) return;
- e.setCancelled(true);
- removeItem(p);
- teleport(p);
- }
- private void removeItem(Player p) {
- ItemStack item = p.getItemInHand();
- item.setAmount(item.getAmount() - 1); //уменьшение предмета на 1 после использования
- p.setItemInHand(item);
- }
- private void teleport(Player p) {
- Location loc = p.getLocation();
- float yaw = loc.getYaw();
- float pitch = loc.getPitch();
- if (pitch < -40 || pitch > 40) {
- vertical(p);
- return;
- }
- }
- private void vertical(Player p) {
- Location loc = p.getLocation();
- float pitch = loc.getPitch();
- if (pitch < -40) {
- loc.setY(loc.getY() + 4);
- if (block(loc)) p.teleport(loc);
- }
- }
- private boolean block (Location loc){
- int x = loc.getBlockX();
- int y = loc.getBlockY();
- int z = loc.getBlockZ();
- if (loc.getWorld().getBlockAt(x, y, z).getType() != Material.AIR) return false;
- if (loc.getWorld().getBlockAt(x, y, z).getType() != Material.AIR) return false;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement