Java Code Examples for org.bukkit.event.block.Action#LEFT_CLICK_AIR

The following examples show how to use org.bukkit.event.block.Action#LEFT_CLICK_AIR . 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: 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 2
Source File: ItemListener.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onLeftClick(PlayerInteractEvent event) {
    if (!(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)) {
        return;
    }
    ItemStack itemStack = ReflectionUtils.invokeMethod(event.getPlayer(), this.getItemInHandMethod);
    if (itemStack != null && itemStack.getType() != Material.AIR) {
        NBTItem nbtItem = new NBTItem(itemStack);
        if (!nbtItem.hasKey("HubBasics")) return;
        event.setCancelled(true);
        CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics"));
        if (item == null) {
            itemStack.setType(Material.AIR); // Destroy old item
            return;
        }
        if (!item.getRunOnLeftClick()) return;
        item.onCommand(event.getPlayer());
    }
}
 
Example 3
Source File: Tutorial.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler
public void onPlayerRightClick(PlayerInteractEvent event) {
    boolean condition = Teams.getTeamByPlayer(event.getPlayer()).isPresent()
            && Teams.getTeamByPlayer(event.getPlayer()).get().isObserver()
            && event.getPlayer().getItemInHand() != null
            && event.getPlayer().getItemInHand().getType().equals(Material.EMERALD);

    if (!this.displayHandlerMap.containsKey(event.getPlayer())) {
        this.displayHandlerMap.put(event.getPlayer(), new DisplayHandler(event.getPlayer(), this));
    }

    if ((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) && condition) {
        this.displayHandlerMap.get(event.getPlayer()).displayNext();
    }
    if ((event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) && condition) {
        this.displayHandlerMap.get(event.getPlayer()).displayPrev();
    }
}
 
Example 4
Source File: CustomItemListener.java    From NBTEditor with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
private void playerInteract(PlayerInteractEvent event) {
	Action action = event.getAction();
	if (action != Action.PHYSICAL) {
		if (action == Action.RIGHT_CLICK_BLOCK && _interationMaterials.contains(event.getClickedBlock().getType())) {
			return;
		}
		CustomItem customItem = CustomItemManager.getCustomItem(event.getItem());
		if (customItem != null) {
			if (verifyCustomItem(customItem, event.getPlayer(), false)) {
				if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
					customItem.onRightClick(event, new PlayerDetails(event));
				} else if (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
					customItem.onLeftClick(event, new PlayerDetails(event));
				}
			} else {
				event.setCancelled(true);
			}
		}
	}
}
 
Example 5
Source File: Spawning.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onEvent(PlayerInteractEvent event) {
  super.onEvent(event);
  event.setCancelled(true);
  if (event.getAction() == Action.LEFT_CLICK_AIR
      || event.getAction() == Action.LEFT_CLICK_BLOCK) {
    requestSpawn();
  }
}
 
Example 6
Source File: ProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private static boolean isValidProjectileAction(Action action, ClickAction clickAction) {
  switch (clickAction) {
    case RIGHT:
      return action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
    case LEFT:
      return action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK;
    case BOTH:
      return action != Action.PHYSICAL;
  }
  return false;
}
 
Example 7
Source File: ProjectilePlayerFacet.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private static boolean isValidProjectileAction(Action action, ClickAction clickAction) {
    switch(clickAction) {
        case RIGHT:
            return action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
        case LEFT:
            return action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK;
        case BOTH:
            return action != Action.PHYSICAL;
    }
    return false;
}
 
Example 8
Source File: CancellableChunkEvents.java    From ClaimChunk with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
    if (e != null
        && e.getClickedBlock() != null
        && e.getAction() != Action.LEFT_CLICK_BLOCK
        && e.getAction() != Action.LEFT_CLICK_AIR
        && e.getAction() != Action.RIGHT_CLICK_AIR) {
        ChunkEventHelper.handleInteractionEvent(e.getPlayer(), e.getClickedBlock().getChunk(), e);
    }
}
 
Example 9
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 10
Source File: MapBuilder.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH)
public void nexusHelperCheck(PlayerInteractEvent event)
{
	if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK
			|| event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
	{
		final Player player = event.getPlayer();
		TeamBlock t = null;
		if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Red.getName()))
			t = TeamBlock.Red;
		else if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Blue.getName()))
			t = TeamBlock.Blue;
		else if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Green.getName()))
			t = TeamBlock.Green;
		else if(KitUtils.itemHasName(player.getItemInHand(), TeamBlock.Yellow.getName()))
			t = TeamBlock.Yellow;
		if(t != null)
		{
			//They made a click with a team block
			event.setCancelled(true);
			List<MetadataValue> vals = player.getMetadata("TeamHandler");
			if(vals != null && vals.size() == 1)
			{
				Object obj = vals.get(0).value();
				if(obj != null && obj instanceof TeamBlockHandler)
				{
					((TeamBlockHandler)obj).onBlockClick(player, t.Team, event.getAction(), event.getClickedBlock(),event.getBlockFace());
				}
			}
		}
	}
}
 
Example 11
Source File: TeamBlock.java    From AnnihilationPro with MIT License 5 votes vote down vote up
public TeamBlock addLine(Action action, ChatColor color1, String message)
{
	String str = "";
	if(action == Action.LEFT_CLICK_BLOCK || action == Action.LEFT_CLICK_AIR)
		str = color1+"Left click to ";
	else if(action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR)
		str = color1+"Right click to ";
	str += message;
	lore.add(str);
	return this;
}
 
Example 12
Source File: MainListener.java    From ArmorStandTools with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    final Player p = event.getPlayer();
    if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) {
        if (plugin.playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) {
            plugin.carryingArmorStand.remove(p.getUniqueId());
            Utils.actionBarMsg(p, Config.asDropped);
            p.setMetadata("lastDrop", new FixedMetadataValue(plugin, System.currentTimeMillis()));
            event.setCancelled(true);
        } else {
            p.sendMessage(ChatColor.RED + Config.wgNoPerm);
        }
        return;
    }
    ArmorStandTool tool = ArmorStandTool.get(event.getItem());
    if(tool == null) return;
    event.setCancelled(true);
    Action action = event.getAction();
    if(action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) {
        Utils.cycleInventory(p);
    } else if((action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) && tool == ArmorStandTool.SUMMON) {
        if (!plugin.playerHasPermission(p, event.getClickedBlock(), tool)) {
            p.sendMessage(ChatColor.RED + Config.generalNoPerm);
            return;
        }
        Location l = Utils.getLocationFacing(p.getLocation());
        plugin.pickUpArmorStand(spawnArmorStand(l), p, true);
        Utils.actionBarMsg(p, Config.carrying);
    }
    new BukkitRunnable() {
        @Override
        public void run() {
            //noinspection deprecation
            p.updateInventory();
        }
    }.runTaskLater(plugin, 1L);
}
 
Example 13
Source File: ItemListener.java    From HubBasics with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onLeftClick(PlayerInteractEvent event) {
    if (!(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)) {
        return;
    }
    ItemStack itemStack;
    if (event.getHand() == EquipmentSlot.HAND) {
        itemStack = event.getPlayer().getInventory().getItemInMainHand();
    } else if (event.getHand() == EquipmentSlot.OFF_HAND) {
        itemStack = event.getPlayer().getInventory().getItemInOffHand();
    } else {
        return;
    }
    if (itemStack.getType() != Material.AIR) {
        NBTItem nbtItem = new NBTItem(itemStack);
        if (!nbtItem.hasKey("HubBasics")) return;
        event.setCancelled(true);
        CustomItem item = HubBasics.getInstance().getItemManager().get(nbtItem.getString("HubBasics"));
        if (item == null) {
            itemStack.setType(Material.AIR); // Destroy old item
            return;
        }
        if (!item.getRunOnLeftClick()) return;
        if (event.getHand() == EquipmentSlot.OFF_HAND) {
            if (item.getRunOnOffhand()) {
                item.onCommand(event.getPlayer());
            }
        } else {
            item.onCommand(event.getPlayer());
        }
    }
}
 
Example 14
Source File: TitleRespawn.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
    UUID id = event.getPlayer().getUniqueId();
    boolean action = event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK;
    if (isDeadUUID(id)) {
        event.setCancelled(true);
        if (action && !hasLeftClicked.contains(id)) hasLeftClicked.add(id);
    }
}
 
Example 15
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
public void onPlayerInteractBlockPrimary(PlayerInteractEvent event, Player player) {
    GDCauseStackManager.getInstance().pushCause(player);
    if (event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.LEFT_CLICK_BLOCK) {
        return;
    }
    if (!GDFlags.INTERACT_BLOCK_PRIMARY || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_BLOCK_PRIMARY.getName(), event.getClickedBlock(), player.getWorld().getUID())) {
        return;
    }

    final Block clickedBlock = event.getClickedBlock();
    final ItemStack itemInHand = event.getItem();
    final Location location = clickedBlock == null ? null : clickedBlock.getLocation();
    final GDPlayerData playerData = this.dataStore.getOrCreateGlobalPlayerData(player.getUniqueId());
    final Object source = itemInHand != null && !event.isBlockInHand() ? itemInHand : player;
    if (playerData.claimMode) {
        return;
    }
    // check give pet
    if (playerData.petRecipientUniqueId != null) {
        playerData.petRecipientUniqueId = null;
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().COMMAND_PET_TRANSFER_CANCEL);
        event.setCancelled(true);
        return;
    }

    if (location == null) {
        return;
    }

    GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.startTiming();
    final GDClaim claim = this.dataStore.getClaimAt(location);
    final GriefDefenderConfig<?> activeConfig = GriefDefenderPlugin.getActiveConfig(location.getWorld().getUID());
    if (activeConfig.getConfig().economy.isSellSignEnabled() ||  activeConfig.getConfig().economy.isRentSignEnabled()) {
        final Sign sign = SignUtil.getSign(location);
        if (sign != null) {
            if (activeConfig.getConfig().economy.isSellSignEnabled() && SignUtil.isSellSign(sign)) {
                if (claim.getEconomyData() != null && claim.getEconomyData().isForSale()) {
                    event.setCancelled(true);
                    EconomyUtil.getInstance().sellCancelConfirmation(event.getPlayer(), claim, sign);
                    GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTiming();
                    return;
                }
            } else if (GriefDefenderPlugin.getGlobalConfig().getConfig().economy.rentSystem  && activeConfig.getConfig().economy.isRentSignEnabled() && SignUtil.isRentSign(claim, sign)) {
                if ((claim.getEconomyData() != null && claim.getEconomyData().isForRent()) || claim.getEconomyData().isRented() ) {
                    event.setCancelled(true);
                    EconomyUtil.getInstance().rentCancelConfirmation(event.getPlayer(), claim, sign);
                    GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTiming();
                    return;
                }
            }
        }
    }

    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_BLOCK_PRIMARY, source, clickedBlock.getState(), player, TrustTypes.BUILDER, true);
    if (result == Tristate.FALSE) {
        if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.BLOCK_BREAK.toString(), clickedBlock.getState(), player.getWorld().getUID())) {
            GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTiming();
            return;
        }
        if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.BLOCK_BREAK, player, clickedBlock.getState(), player, TrustTypes.BUILDER, true) == Tristate.TRUE) {
            GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTiming();
            return;
        }

        // Don't send a deny message if the player is in claim mode or is holding an investigation tool
        if (!playerData.claimMode && (GriefDefenderPlugin.getInstance().investigationTool == null || !NMSUtil.getInstance().hasItemInOneHand(player, GriefDefenderPlugin.getInstance().investigationTool))) {
            this.sendInteractBlockDenyMessage(itemInHand, clickedBlock, claim, player, playerData);
        }
        event.setCancelled(true);
        GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTiming();
        return;
    }
    GDTimings.PLAYER_INTERACT_BLOCK_PRIMARY_EVENT.stopTiming();
}