Java Code Examples for org.bukkit.event.player.PlayerInteractEvent#getPlayer()

The following examples show how to use org.bukkit.event.player.PlayerInteractEvent#getPlayer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 7 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onClickOnObsidian(final PlayerInteractEvent event) {
    if (!plugin.getWorldManager().isSkyWorld(event.getPlayer().getWorld())) {
        return;
    }
    long now = System.currentTimeMillis();
    Player player = event.getPlayer();
    PlayerInventory inventory = player.getInventory();
    Block block = event.getClickedBlock();
    Long lastClick = obsidianClick.get(player.getUniqueId());
    if (lastClick != null && (lastClick + OBSIDIAN_SPAM) >= now) {
        plugin.notifyPlayer(player, tr("\u00a74You can only convert obsidian once every 10 seconds"));
        return;
    }
    if (Settings.extras_obsidianToLava && plugin.playerIsOnIsland(player)
            && plugin.getWorldManager().isSkyWorld(player.getWorld())
            && event.getAction() == Action.RIGHT_CLICK_BLOCK
            && player.getItemInHand() != null
            && player.getItemInHand().getType() == Material.BUCKET
            && block != null
            && block.getType() == Material.OBSIDIAN
            && !testForObsidian(block)) {
        if (inventory.firstEmpty() != -1) {
            obsidianClick.put(player.getUniqueId(), now);
            player.sendMessage(tr("\u00a7eChanging your obsidian back into lava. Be careful!"));
            inventory.removeItem(new ItemStack(Material.BUCKET, 1));
            inventory.addItem(new ItemStack(Material.LAVA_BUCKET, 1));
            player.updateInventory();
            block.setType(Material.AIR);
            event.setCancelled(true); // Don't execute the click anymore (since that would re-place the lava).
        } else {
            player.sendMessage(tr("\u00a7eYour inventory must have another empty space!"));
        }
    }
}
 
Example 2
Source File: Compat18.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onInteractAS(PlayerInteractEvent e) {
    if (e.getClickedBlock() == null) {
        return;
    }

    if (RedProtect.get().bukkitVersion <= 180) {
        return;
    }
    Player p = e.getPlayer();
    Location l = e.getClickedBlock().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    Material m = p.getItemInHand().getType();

    if (RedProtect.get().bukkitVersion >= 190 && e.getItem() != null) {
        m = e.getItem().getType();
    }

    if (m.equals(Material.ARMOR_STAND) || m.equals(Material.END_CRYSTAL)) {
        if (r != null && !r.canBuild(p) && !r.canPlace(m) && !r.canBreak(m)) {
            e.setCancelled(true);
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild");
        }
    }
}
 
Example 3
Source File: PlayerInteract.java    From StaffPlus with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent event)
{
	Player player = event.getPlayer();
	UUID uuid = player.getUniqueId();
	Action action = event.getAction();
	ItemStack item = player.getItemInHand();
	
	if(cpsHandler.isTesting(uuid) && (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK))
	{
		cpsHandler.updateCount(uuid);
		return;
	}
	
	if(!modeCoordinator.isInMode(uuid) || item == null)
	{
		return;
	}
	
	if(handleInteraction(player, item, action))
	{
		event.setCancelled(true);
	}
}
 
Example 4
Source File: SignEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockHit(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    if (e.getPlayer() == null
            || e.getClickedBlock() == null
            || e.getAction() != Action.RIGHT_CLICK_BLOCK
            || e.getPlayer().getGameMode() != GameMode.SURVIVAL
            || !isSign(e.getClickedBlock().getType())
            || !player.hasPermission("usb.island.signs.use")
            || !plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld())) {
        return;
    }

    if (e.getClickedBlock().getState() instanceof Sign) {
        Sign sign = (Sign) e.getClickedBlock().getState();
        String firstLine = FormatUtil.stripFormatting(sign.getLine(0)).trim();
        if (firstLine.startsWith("/")) {
            e.setCancelled(true);
            player.performCommand(firstLine.substring(1));
        }
    }
}
 
Example 5
Source File: LecternInteractListener.java    From ViaBackwards with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onLecternInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (!isOnPipe(player)) return;

    Block block = event.getClickedBlock();
    if (block == null || block.getType() != Material.LECTERN) return;

    Lectern lectern = (Lectern) block.getState();
    ItemStack book = lectern.getInventory().getItem(0);
    if (book == null) return;

    BookMeta meta = (BookMeta) book.getItemMeta();

    // Open a book with the text of the lectern's writable book
    ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta newBookMeta = (BookMeta) newBook.getItemMeta();
    newBookMeta.setPages(meta.getPages());
    newBookMeta.setAuthor("an upsidedown person");
    newBookMeta.setTitle("buk");
    newBook.setItemMeta(newBookMeta);
    player.openBook(newBook);

    event.setCancelled(true);
}
 
Example 6
Source File: LauncherGizmo.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    if (!(Gizmos.gizmoMap.get(player) instanceof LauncherGizmo)) return;

    if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) return;
    if (player.getItemInHand().getType() != this.getIcon()) return;

    Firework oldFirework = this.launchedPlayers.get(player);
    if (oldFirework == null || oldFirework.isDead()) {
        Firework firework = this.buildFirework(player.getLocation());
        firework.setPassenger(player);
        this.launchedPlayers.put(player, firework);
    }
}
 
Example 7
Source File: ToolMenuEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockHit(PlayerInteractEvent e) {
    if (e == null || e.getClickedBlock() == null
            || e.getAction() != Action.LEFT_CLICK_BLOCK || e.getPlayer().getGameMode() != GameMode.SURVIVAL) {
        return;
    }
    Player player = e.getPlayer();
    if (!plugin.getWorldManager().isSkyAssociatedWorld(player.getWorld()) || !isTool(e.getItem())) {
        return;
    }

    // We are in a skyworld, a block has been hit, with the tool
    Material block = e.getClickedBlock().getType();
    short data = e.getClickedBlock().getData();
    String itemId = ItemStackUtil.asString(new ItemStack(block, 1, data));
    if (commandMap.containsKey(itemId)) {
        doCmd(e, player, itemId);
    }
    if (!e.isCancelled()) {
        itemId = ItemStackUtil.asString(new ItemStack(block, 1));
        if (commandMap.containsKey(itemId)) {
            doCmd(e, player, itemId);
        }
    }
}
 
Example 8
Source File: ArmorListener.java    From AdditionsAPI with MIT License 6 votes vote down vote up
@EventHandler(priority =  EventPriority.HIGHEST, ignoreCancelled = true)
public void playerInteractEvent(PlayerInteractEvent e){
	if(e.getAction() == Action.PHYSICAL) return;
	if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
		Player player = e.getPlayer();
		ArmorType newArmorType = ArmorType.matchType(e.getItem());
		if(newArmorType != null){
			if(newArmorType.equals(ArmorType.HELMET) && isAirOrNull(e.getPlayer().getInventory().getHelmet()) || newArmorType.equals(ArmorType.CHESTPLATE) && isAirOrNull(e.getPlayer().getInventory().getChestplate()) || newArmorType.equals(ArmorType.LEGGINGS) && isAirOrNull(e.getPlayer().getInventory().getLeggings()) || newArmorType.equals(ArmorType.BOOTS) && isAirOrNull(e.getPlayer().getInventory().getBoots())){
				ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(e.getPlayer(), EquipMethod.HOTBAR, ArmorType.matchType(e.getItem()), null, e.getItem());
				Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent);
				if(armorEquipEvent.isCancelled()){
					e.setCancelled(true);
					player.updateInventory();
				}
			}
		}
	}
}
 
Example 9
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onFireworkLaunch(PlayerInteractEvent event) {
    if (event.getItem() == null || event.getItem().getType() != Material.FIREWORK_ROCKET ||
            (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)) {
        return;
    }
    Player player = event.getPlayer();
    Civilian civilian = CivilianManager.getInstance().getCivilian(player.getUniqueId());
    Town town = TownManager.getInstance().getTownAt(player.getLocation());
    if (town == null) {
        return;
    }
    Government government = GovernmentManager.getInstance().getGovernment(town.getGovernmentType());
    if (government.getGovernmentType() != GovernmentType.IDIOCRACY) {
        return;
    }
    if (!town.getIdiocracyScore().containsKey(civilian.getUuid())) {
        town.getIdiocracyScore().put(civilian.getUuid(), 1);
    } else {
        town.getIdiocracyScore().put(civilian.getUuid(),
                town.getIdiocracyScore().get(civilian.getUuid()) + 1);
    }
    Util.checkNoise(town, event.getPlayer());
    TownManager.getInstance().saveTown(town);
}
 
Example 10
Source File: JumpPads.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (!needsPressurePlate(event.getPlayer())) return;
    Player player = event.getPlayer();
    if (event.getAction() == Action.PHYSICAL && !event.isCancelled() && isEnabledInWorld(player.getWorld())) {
        if (event.getClickedBlock().getType() == getPlateType(player)) {
            boolean apply = true;
            if (isBlockRequired(player)) {
                Location loc = event.getClickedBlock().getLocation().subtract(0, 1, 0);
                apply = loc.getWorld().getBlockAt(loc).getType() == getMaterial(player);
            }
            if (apply) {
                player.setVelocity(calculateVector(player));
                if (getSound(player) != null) {
                    player.playSound(player.getLocation(), getSound(player), 1, 1);
                }
                if (getEffect(player) != null) {
                    particleEffect.display(getEffect(player), player.getLocation(), 1, 1, 1, 1, 40);
                }
                event.setCancelled(true);
            }
        }
    }
}
 
Example 11
Source File: TeamCommand.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH)
public void voteGUIcheck(PlayerInteractEvent event)
{
	if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)
	{
		final Player player = event.getPlayer();
		if(KitUtils.itemHasName(player.getItemInHand(), CustomItem.TEAMMAP.getName()))
		{
			if(menu != null)
				menu.open(player);
			event.setCancelled(true);
		}
	}
}
 
Example 12
Source File: VoteMapManager.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH)
public void voteGUIcheck(PlayerInteractEvent event)
{
	if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)
	{
		final Player player = event.getPlayer();
		if(KitUtils.itemHasName(player.getItemInHand(), CustomItem.VOTEMAP.getName()))
		{
			if(menu != null)
				menu.open(player);
			else player.sendMessage(ChatColor.RED+"There are no maps for voting!");
			event.setCancelled(true);
		}
	}
}
 
Example 13
Source File: GlobalProtectionListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (DPlayerListener.isCitizensNPC(player) || plugin.getPlayerCache().get(player).isInBreakMode()) {
        return;
    }
    Block clickedBlock = event.getClickedBlock();
    if (clickedBlock == null) {
        return;
    }

    if (Category.SIGNS.containsBlock(clickedBlock)) {
        GroupSign groupSign = GroupSign.getByBlock(plugin, clickedBlock);
        if (groupSign != null) {
            groupSign.onPlayerInteract(clickedBlock, player);
            event.setCancelled(true);
        }

        GameSign gameSign = GameSign.getByBlock(plugin, clickedBlock);
        if (gameSign != null) {
            gameSign.onPlayerInteract(clickedBlock, player);
            event.setCancelled(true);
        }

        LeaveSign leaveSign = LeaveSign.getByBlock(plugin, clickedBlock);
        if (leaveSign != null) {
            leaveSign.onPlayerInteract(player);
            event.setCancelled(true);
        }
    }
}
 
Example 14
Source File: SpectatorEvents.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerClickEvent(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    try{
        if(GameManager.getInstance().isSpectator(player) && player.isSneaking() && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR)||
                GameManager.getInstance().isSpectator(player) && player.isSneaking() && (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR)){
            Player[]players = GameManager.getInstance().getGame(GameManager.getInstance().getPlayerSpectateId(player)).getPlayers()[0];
            Game g = GameManager.getInstance().getGame(GameManager.getInstance().getPlayerSpectateId(player));

            int i = g.getNextSpec().get(player);
            if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR)){
                i++;
            }
            else if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR){
                i--;
            }
            if(i>players.length-1){
                i = 0;
            }
            if(i<0){
                i = players.length-1;
            }
            g.getNextSpec().put(player, i);
            Player tpto = players[i];
            Location l = tpto.getLocation();
            l.setYaw(0);
            l.setPitch(0);
            player.teleport(l);
            player.sendMessage(ChatColor.AQUA+"You are now spectating "+tpto.getName());
        }
        else if (GameManager.getInstance().isSpectator(player)) {
            event.setCancelled(true);
        }
    }
    catch(Exception e){e.printStackTrace();}
}
 
Example 15
Source File: BlockListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onClick(PlayerInteractEvent event) {
	Player player = event.getPlayer();

	ItemStack norm = null;
	if (event.getHand() == EquipmentSlot.HAND) {
		norm = player.getInventory().getItemInMainHand();
	} else if (event.getHand() == EquipmentSlot.OFF_HAND) {
		norm = player.getInventory().getItemInOffHand();
	}

	if (norm == null) return;

	if (event.getAction() == Action.RIGHT_CLICK_AIR) {
		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
		}
	} else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
		Block block = event.getClickedBlock();

		if (block == null) {
			return;
		}
		if (!player.isSneaking()) {
			Material type = block.getType();

			if (type == Material.ANVIL || type == Material.CRAFTING_TABLE
					|| type == Material.CHEST || type == Material.ENDER_CHEST
					|| type == Material.DROPPER || type == Material.HOPPER
					|| type == Material.DISPENSER || type == Material.TRAPPED_CHEST
					|| type == Material.FURNACE || type == Material.ENCHANTING_TABLE) {

				return;
			}
		}

		if (modManager.isModifierItem(norm)) {
			event.setCancelled(true);
			return;
		}

		if (block.getType() == Material.getMaterial(MineTinker.getPlugin().getConfig().getString("BlockToEnchantModifiers", Material.BOOKSHELF.name()))) {
			ItemStack item = player.getInventory().getItemInMainHand();

			for (Modifier m : modManager.getAllMods()) {
				if (m.getModItem().getType().equals(item.getType())) {
					if (!m.isEnchantable()) continue;
					m.enchantItem(player);
					event.setCancelled(true);
					break;
				}
			}
		}
	}
}
 
Example 16
Source File: PlayerInteract.java    From ZombieEscape with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    /* Check if a sign was interacted with */
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (event.getClickedBlock().getState() instanceof Sign) {
            Sign sign = (Sign) event.getClickedBlock().getState();

            GameArena gameArena = plugin.getGameArena();
            for (Door door : gameArena.getDoors()) {
                if (door.matches(sign)) {
                    if (door.isNukeroom()) {
                        if (gameArena.getGameState() != GameState.NUKEROOM) {
                            door.activate(player, sign, plugin);
                            gameArena.setGameState(GameState.NUKEROOM);
                            Messages.NUKEROOM_ACTIVATED.broadcast(player.getName());

                            NukeRoomTask nukeRoomTask = new NukeRoomTask(gameArena, gameArena.getNukeRoom(), plugin);
                            nukeRoomTask.runTaskTimer(plugin, 0, 20);
                            gameArena.setNukeRoomTask(nukeRoomTask);
                        }
                    } else {
                        door.activate(player, sign, plugin);
                    }
                    break;
                }
            }
        }
    }

    /* Check for kit/selector interaction */
    ItemStack item = event.getItem();

    if (item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
        String stackName = ChatColor.stripColor(item.getItemMeta().getDisplayName());

        switch (stackName) {
            case "Vote":
                plugin.getMenuManager().getMenu("vote").show(player);
                break;
            case "Human Kits":
                plugin.getMenuManager().getMenu("hkits").show(player);
                break;
            case "Zombie Kits":
                plugin.getMenuManager().getMenu("zkits").show(player);
                break;
            default:
                /* We know iteration is O(N), however the N in this case is very small */
                for (KitType kitType : KitType.values()) {
                    if (kitType.getName().equals(stackName)) {
                        /* Activates the kit callback */
                        kitType.getKitAction().interact(event, event.getPlayer(), item);
                        break;
                    }
                }
        }
    }
}
 
Example 17
Source File: EasyHarvestListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onHarvestTry(PlayerInteractEvent event) {
	if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
		return;
	}

	Player player = event.getPlayer();

	if (Lists.WORLDS_EASYHARVEST.contains(player.getWorld().getName())) {
		return;
	}

	if (!(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE
			|| player.getGameMode() == GameMode.CREATIVE)) {
		return;
	}

	ItemStack tool = player.getInventory().getItemInMainHand();

	if (!ToolType.HOE.contains(tool.getType())) {
		return;
	}

	if (!modManager.isToolViable(tool)) {
		return;
	}

	if (event.getClickedBlock() == null) {
		return;
	}

	if (event.getItem() == null) {
		return;
	}

	Block block = event.getClickedBlock();

	if (!(block.getBlockData() instanceof Ageable)) {
		return;
	}

	//triggers a pseudoevent to find out if the Player can build
	BlockPlaceEvent placeEvent = new BlockPlaceEvent(block, block.getState(), block, event.getItem(), player,
			true, EquipmentSlot.HAND);
	Bukkit.getPluginManager().callEvent(placeEvent);

	//check the pseudoevent
	if (!placeEvent.canBuild() || placeEvent.isCancelled()) {
		return;
	}

	harvestCrops(player, tool, block);
}
 
Example 18
Source File: LWCBlockInteractEvent.java    From Modern-LWC with MIT License 4 votes vote down vote up
public LWCBlockInteractEvent(PlayerInteractEvent event, Block block, Set<String> actions) {
    super(ModuleLoader.Event.INTERACT_BLOCK, event.getPlayer());

    this.block = block;
    this.actions = actions;
}
 
Example 19
Source File: SitListener.java    From NyaaUtils with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onClickBlock(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && !event.hasItem()) {
        Block block = event.getClickedBlock();
        BlockFace face = event.getBlockFace();
        if (face == BlockFace.DOWN || block.isLiquid() || !plugin.cfg.sit_blocks.contains(block.getType())) {
            return;
        }
        Block relative = block.getRelative(0, 1, 0);
        Player player = event.getPlayer();
        if (messageCooldown.getIfPresent(player.getUniqueId()) != null) {
            return;
        }
        messageCooldown.put(player.getUniqueId(), true);
        if (!player.hasPermission("nu.sit") || !enabledPlayers.contains(player.getUniqueId()) || player.isInsideVehicle() || !player.getPassengers().isEmpty() || player.getGameMode() == GameMode.SPECTATOR || !player.isOnGround()) {
            return;
        }
        if (relative.isLiquid() || !(relative.isEmpty() || relative.isPassable())) {
            player.sendMessage(I18n.format("user.sit.invalid_location"));
            return;
        }
        Vector vector = block.getBoundingBox().getCenter().clone();
        Location loc = vector.setY(block.getBoundingBox().getMaxY()).toLocation(player.getWorld()).clone();
        for (SitLocation sl : plugin.cfg.sit_locations.values()) {
            if (sl.blocks != null && sl.x != null && sl.y != null && sl.z != null && sl.blocks.contains(block.getType().name())) {
                loc.add(sl.x, sl.y, sl.z);
            }
        }
        if (block.getBlockData() instanceof Directional) {
            face = ((Directional) block.getBlockData()).getFacing();
            if (face == BlockFace.EAST) {
                loc.setYaw(90);
            } else if (face == BlockFace.WEST) {
                loc.setYaw(-90);
            } else if (face == BlockFace.NORTH) {
                loc.setYaw(0);
            } else if (face == BlockFace.SOUTH) {
                loc.setYaw(-180);
            }
        } else {
            if (face == BlockFace.WEST) {
                loc.setYaw(90);
            } else if (face == BlockFace.EAST) {
                loc.setYaw(-90);
            } else if (face == BlockFace.SOUTH) {
                loc.setYaw(0);
            } else if (face == BlockFace.NORTH) {
                loc.setYaw(-180);
            } else {
                loc.setYaw(player.getEyeLocation().getYaw());
            }
        }
        for (Entity e : loc.getWorld().getNearbyEntities(loc, 0.5, 0.7, 0.5)) {
            if (e instanceof LivingEntity) {
                if (e.hasMetadata(metadata_key) || (e instanceof Player && e.isInsideVehicle() && e.getVehicle().hasMetadata(metadata_key))) {
                    player.sendMessage(I18n.format("user.sit.invalid_location"));
                    return;
                }
            }
        }
        Location safeLoc = player.getLocation().clone();
        ArmorStand armorStand = loc.getWorld().spawn(loc, ArmorStand.class, (e) -> {
            e.setVisible(false);
            e.setPersistent(false);
            e.setCanPickupItems(false);
            e.setBasePlate(false);
            e.setArms(false);
            e.setMarker(true);
            e.setInvulnerable(true);
            e.setGravity(false);
        });
        if (armorStand != null) {
            armorStand.setMetadata(metadata_key, new FixedMetadataValue(plugin, true));
            if (armorStand.addPassenger(player)) {
                safeLocations.put(player.getUniqueId(), safeLoc);
            } else {
                armorStand.remove();
            }
        }
    }
}
 
Example 20
Source File: TriggerListener.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) {
        return;
    }
    Player player = event.getPlayer();
    if (DPlayerListener.isCitizensNPC(player)) {
        return;
    }
    DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(player.getWorld());
    if (gameWorld == null) {
        return;
    }

    ItemStack item = event.getItem();
    if (item == null) {
        return;
    }
    String name = null;
    if (item.hasItemMeta()) {
        if (item.getItemMeta().hasDisplayName()) {
            name = item.getItemMeta().getDisplayName();

        } else if (VanillaItem.WRITTEN_BOOK.is(item) || VanillaItem.WRITABLE_BOOK.is(item)) {
            if (item.getItemMeta() instanceof BookMeta) {
                BookMeta meta = (BookMeta) item.getItemMeta();
                if (meta.hasTitle()) {
                    name = meta.getTitle();
                }
            }
        }
    }
    if (name == null) {
        name = plugin.getCaliburn().getExItem(item).getName();
    }

    UseItemTrigger trigger = UseItemTrigger.getByName(name, gameWorld);
    if (trigger != null) {
        trigger.onTrigger(player);
    }
}