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

The following examples show how to use org.bukkit.event.block.Action#RIGHT_CLICK_BLOCK . 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: 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 2
Source File: PlayerListener.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onDyeing(PlayerInteractEvent e) {
    if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getItem() == null || !Util.isDyes(e.getItem().getType())) {
        return;
    }
    final Block block = e.getClickedBlock();
    if (block == null || !Util.isWallSign(block.getType())) {
        return;
    }
    final Block attachedBlock = Util.getAttached(block);
    if (attachedBlock == null || plugin.getShopManager().getShopIncludeAttached(attachedBlock.getLocation()) == null) {
        return;
    }
    e.setCancelled(true);
    Util.debugLog("Disallow " + e.getPlayer().getName() + " dye the shop sign.");
}
 
Example 3
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 4
Source File: LobbyListener.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = false)
  public void onClick(final PlayerInteractEvent e) {
if (Util.get().isSpawnWorld(e.getPlayer().getWorld())) {
	if (SkyWarsReloaded.getCfg().protectLobby()) {
		e.setCancelled(true);
   		if (e.getPlayer().hasPermission("sw.alterlobby")) {
   			e.setCancelled(false);
   		}
	}
	
	if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
      		if (e.hasItem()) {
                  if (e.getItem().equals(SkyWarsReloaded.getIM().getItem("optionselect"))) {
                  	e.setCancelled(true);
                  	Util.get().playSound(e.getPlayer(), e.getPlayer().getLocation(), SkyWarsReloaded.getCfg().getOpenOptionsMenuSound(), 0.5F, 1);
                  	new OptionsSelectionMenu(e.getPlayer());
                  } else if (e.getItem().equals(SkyWarsReloaded.getIM().getItem("joinselect"))) {
                  	e.setCancelled(true);
                  	Util.get().playSound(e.getPlayer(), e.getPlayer().getLocation(), SkyWarsReloaded.getCfg().getOpenJoinMenuSound(), 1, 1);
                  	e.getPlayer().openInventory(joinMenu);
                  } 
      		}
      	}
}
  }
 
Example 5
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryOpenEvent(InventoryOpenEvent event) {
	if (event.getInventory() instanceof DoubleChestInventory) {
		DoubleChestInventory doubleInv = (DoubleChestInventory)event.getInventory();
					
		Chest leftChest = (Chest)doubleInv.getHolder().getLeftSide();			
		/*Generate a new player 'switch' event for the left and right chests. */
		PlayerInteractEvent interactLeft = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, leftChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactLeft);
		
		if (interactLeft.isCancelled()) {
			event.setCancelled(true);
			return;
		}
		
		Chest rightChest = (Chest)doubleInv.getHolder().getRightSide();
		PlayerInteractEvent interactRight = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, rightChest.getBlock(), null);
		BlockListener.OnPlayerSwitchEvent(interactRight);
		
		if (interactRight.isCancelled()) {
			event.setCancelled(true);
			return;
		}			
	}
}
 
Example 6
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 7
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkUse(final PlayerInteractEvent event) {
    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        MatchPlayer player = this.match.getParticipant(event.getPlayer());
        if(player == null) return;

        Block block = event.getClickedBlock();
        if(block == null) return;

        this.handleUse(event, block.getState(), player);
    }
}
 
Example 8
Source File: BrewingTaskType.java    From Quests with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (event.getClickedBlock().getType() == Material.BREWING_STAND) {
            brewingStands.put(event.getClickedBlock().getLocation(), event.getPlayer().getUniqueId());
        }
    }
}
 
Example 9
Source File: ItemUseListener.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onRightClick(PlayerInteractEvent e) throws Exception {
	if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
		ItemUseEvent event = new ItemUseEvent(e, e.getAction() == Action.RIGHT_CLICK_BLOCK ? e.getClickedBlock(): null);
		Bukkit.getPluginManager().callEvent(event);
		if (!e.isCancelled()) e.setCancelled(event.isCancelled());
	}
}
 
Example 10
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 11
Source File: MapRatingsMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onOpenButtonClick(PlayerInteractEvent event) {
    if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;

    MatchPlayer player = this.getMatch().getPlayer(event.getPlayer());
    if(player == null) return;

    ItemStack stack = event.getPlayer().getItemInHand();
    if(stack == null) return;
    if(stack.getType() != Material.HOPPER) return;

    String name = stack.getItemMeta().getDisplayName();
    if(name == null || !name.startsWith(BUTTON_PREFIX)) return;
    this.showDialog(player);
}
 
Example 12
Source File: DebugFishListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onDebug(PlayerInteractEvent e) {
    if (e.getAction() == Action.PHYSICAL || e.getHand() != EquipmentSlot.HAND) {
        return;
    }

    Player p = e.getPlayer();

    if (p.isOp() && SlimefunUtils.isItemSimilar(e.getItem(), SlimefunItems.DEBUG_FISH, true)) {
        e.setCancelled(true);

        if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
            if (p.isSneaking()) {
                if (BlockStorage.hasBlockInfo(e.getClickedBlock())) {
                    BlockStorage.clearBlockInfo(e.getClickedBlock());
                }
            }
            else {
                e.setCancelled(false);
            }
        }
        else if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (p.isSneaking()) {
                Block b = e.getClickedBlock().getRelative(e.getBlockFace());
                b.setType(Material.PLAYER_HEAD);
                SkullBlock.setFromHash(b, HeadTexture.MISSING_TEXTURE.getTexture());
            }
            else if (BlockStorage.hasBlockInfo(e.getClickedBlock())) {
                sendInfo(p, e.getClickedBlock());
            }
        }
    }
}
 
Example 13
Source File: DSignListener.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (DPlayerListener.isCitizensNPC(player)) {
        return;
    }
    Block clickedBlock = event.getClickedBlock();
    if (clickedBlock == null) {
        return;
    }
    GamePlayer dPlayer = api.getPlayerCache().getGamePlayer(player);
    if (dPlayer == null) {
        return;
    }

    DGameWorld gameWorld = (DGameWorld) dPlayer.getGameWorld();
    if (gameWorld == null) {
        return;
    }

    InteractTrigger trigger = InteractTrigger.getByBlock(clickedBlock, gameWorld);
    if (trigger != null) {
        if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            trigger.onTrigger(player);
        }
    }
}
 
Example 14
Source File: TutorialListener.java    From ServerTutorial with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    String name = player.getName();
    if (event.getAction() != Action.PHYSICAL) {
        if (TutorialManager.getManager().isInTutorial(name) && TutorialManager.getManager().getCurrentTutorial
                (name).getViewType() != ViewType.TIME) {
            if (TutorialManager.getManager().getCurrentTutorial(name).getTotalViews() == TutorialManager
                    .getManager().getCurrentView(name)) {
                plugin.getEndTutorial().endTutorial(player);
            } else {
                plugin.incrementCurrentView(name);
                TutorialUtils.getTutorialUtils().messageUtils(player);
                Caching.getCaching().setTeleport(player, true);
                player.teleport(TutorialManager.getManager().getTutorialView(name).getLocation());
            }
        }
    }
    if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) &&
            !TutorialManager.getManager().isInTutorial(name)) {
        Block block = event.getClickedBlock();
        if (block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN) {
            Sign sign = (Sign) block.getState();
            String match = ChatColor.stripColor(TutorialUtils.color(TutorialManager.getManager().getConfigs()
                    .signSetting()));
            if (sign.getLine(0).equalsIgnoreCase(match) && sign.getLine(1) != null) {
                plugin.startTutorial(sign.getLine(1), player);
            }
        }
    }
}
 
Example 15
Source File: SignListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (event.getClickedBlock().getState() instanceof Sign) {
            if (manager.isSignRegistered(event.getClickedBlock().getLocation())) {
                SignBlock sign = manager.getSign(event.getClickedBlock().getLocation());
                owner.onClick(event.getPlayer(), sign);
            }
        }
    }
}
 
Example 16
Source File: ItemListener.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
   public void onCauldronClick(PlayerInteractEvent evt) {
       if (evt.getAction() == Action.RIGHT_CLICK_BLOCK) {
           if (evt.getBlockFace() == BlockFace.UP && evt.getClickedBlock().getType() == Material.CAULDRON && evt.getItem() != null && evt.getItem().getType() == Carbon.injector().bannerItemMat) {
           	evt.setCancelled(true);
           	ItemStack originalBanner = evt.getItem();
           	//create new banner with latest pattern removed
               net.minecraft.server.v1_7_R4.ItemStack nmsNewBanner = CraftItemStack.asNMSCopy(originalBanner);
               NBTTagCompound tag = nmsNewBanner.getTag();
               byte waterLevel = evt.getClickedBlock().getData();
               if (waterLevel > 0 && tag != null && tag.hasKey("BlockEntityTag") && tag.getCompound("BlockEntityTag").hasKey("Patterns")) {
                NBTTagCompound compound = tag.getCompound("BlockEntityTag");
                NBTTagList list = compound.getList("Patterns", 10);
                NBTTagList newList = new NBTTagList();
                for (int n = 0; n < list.size() - 1; n++) {
                    newList.add(list.get(n));
                }
                if (newList.size() > 0) {
                	compound.set("Patterns", newList);
                } else {
                	compound.remove("Patterns");
                }
                ItemStack newBannerItem = CraftItemStack.asCraftMirror(nmsNewBanner);
                newBannerItem.setAmount(1);
                //update cauldron
                evt.getClickedBlock().setData(--waterLevel);
                //update used itemstack
                if (originalBanner.getAmount() > 1) {
                	evt.getItem().setAmount(originalBanner.getAmount() - 1);
                } else {
                	evt.getItem().setAmount(0);
                	evt.getPlayer().setItemInHand(null);
                }
                //add new banner
                evt.getPlayer().getInventory().addItem(newBannerItem);
                evt.getPlayer().updateInventory();
               }
           }
       }
   }
 
Example 17
Source File: PlayerInteract.java    From StaffPlus with GNU General Public License v3.0 4 votes vote down vote up
private boolean handleInteraction(Player player, ItemStack item, Action action)
{
	boolean isHandled = true;
	
	if(action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK)
	{
		return isHandled = false;
	}
	
	switch(gadgetHandler.getGadgetType(item, versionProtocol.getNbtString(item)))
	{
		case COMPASS:
			gadgetHandler.onCompass(player);
			break;
		case RANDOM_TELEPORT:
			gadgetHandler.onRandomTeleport(player, 1);
			break;
		case VANISH:
			gadgetHandler.onVanish(player, true);
			break;
		case GUI_HUB:
			gadgetHandler.onGuiHub(player);
			break;
		case COUNTER:
			gadgetHandler.onCounter(player);
			break;
		case FREEZE:
			gadgetHandler.onFreeze(player, JavaUtils.getTargetPlayer(player));
			break;
		case CPS:
			gadgetHandler.onCps(player, JavaUtils.getTargetPlayer(player));
			break;
		case EXAMINE:
			gadgetHandler.onExamine(player, JavaUtils.getTargetPlayer(player));
			break;
		case FOLLOW:
			gadgetHandler.onFollow(player, JavaUtils.getTargetPlayer(player));
			break;
		case CUSTOM:
			ModuleConfiguration moduleConfiguration = gadgetHandler.getModule(item);
			
			if(moduleConfiguration != null)
			{
				gadgetHandler.onCustom(player, JavaUtils.getTargetPlayer(player), moduleConfiguration);
			}else isHandled = false;
			
			break;
	}
	
	return isHandled;
}
 
Example 18
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteractBlockSecondary(PlayerInteractEvent event) {
    final Block clickedBlock = event.getClickedBlock();
    if (clickedBlock == null) {
        return;
    }

    final String id = GDPermissionManager.getInstance().getPermissionIdentifier(clickedBlock);
    final GDBlockType gdBlock = BlockTypeRegistryModule.getInstance().getById(id).orElse(null);
    if (gdBlock == null || (!gdBlock.isInteractable() && event.getAction() != Action.PHYSICAL)) {
        return;
    }
    if (NMSUtil.getInstance().isBlockStairs(clickedBlock) && event.getAction() != Action.PHYSICAL) {
        return;
    }

    final Player player = event.getPlayer();
    GDCauseStackManager.getInstance().pushCause(player);
    final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) {
        onPlayerInteractBlockPrimary(event, player);
        return;
    }

    final Location location = clickedBlock.getLocation();
    GDClaim claim = this.dataStore.getClaimAt(location);
    final Sign sign = SignUtil.getSign(location);
    // check sign
    if (SignUtil.isSellSign(sign)) {
        EconomyUtil.getInstance().buyClaimConsumerConfirmation(player, claim, sign);
        return;
    }
    if (SignUtil.isRentSign(claim, sign)) {
        EconomyUtil.getInstance().rentClaimConsumerConfirmation(player, claim, sign);
        return;
    }

    final BlockState state = clickedBlock.getState();
    final ItemStack itemInHand = event.getItem();
    final boolean hasInventory = NMSUtil.getInstance().isTileInventory(location) || clickedBlock.getType() == Material.ENDER_CHEST;
    if (hasInventory) {
        onInventoryOpen(event, state.getLocation(), state, player);
        return;
    }

    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_BLOCK_SECONDARY.getName(), event.getClickedBlock(), player.getWorld().getUID())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.startTiming();
    final Object source = player;

    final TrustType trustType = NMSUtil.getInstance().isTileInventory(location) || clickedBlock.getType() == Material.ENDER_CHEST ? TrustTypes.CONTAINER : TrustTypes.ACCESSOR;
    if (GDFlags.INTERACT_BLOCK_SECONDARY && playerData != null) {
        Flag flag = Flags.INTERACT_BLOCK_SECONDARY;
        if (event.getAction() == Action.PHYSICAL) {
            flag = Flags.COLLIDE_BLOCK;
        }
        Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, flag, source, clickedBlock, player, trustType, true);
        if (result == Tristate.FALSE) {
            // if player is holding an item, check if it can be placed
            if (GDFlags.BLOCK_PLACE && itemInHand != null && itemInHand.getType().isBlock()) {
                if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.BLOCK_PLACE.getName(), itemInHand, player.getWorld().getUID())) {
                    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
                    return;
                }
                if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.BLOCK_PLACE, source, itemInHand, player, TrustTypes.BUILDER, true) == Tristate.TRUE) {
                    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
                    return;
                }
            }
            // Don't send a deny message if the player is in claim mode or is holding an investigation tool
            if (lastInteractItemCancelled != true) {
                if (!playerData.claimMode && (GriefDefenderPlugin.getInstance().investigationTool == null || !NMSUtil.getInstance().hasItemInOneHand(player, GriefDefenderPlugin.getInstance().investigationTool))) {
                    if (event.getAction() == Action.PHYSICAL) {
                        if (player.getWorld().getTime() % 100 == 0L) {
                            this.sendInteractBlockDenyMessage(itemInHand, clickedBlock, claim, player, playerData);
                        }
                    } else {
                        if (gdBlock != null && gdBlock.isInteractable()) {
                            this.sendInteractBlockDenyMessage(itemInHand, clickedBlock, claim, player, playerData);
                        }
                    }
                }
            }

            event.setUseInteractedBlock(Result.DENY);
            GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
            return;
        }
    }

    GDTimings.PLAYER_INTERACT_BLOCK_SECONDARY_EVENT.stopTiming();
}
 
Example 19
Source File: ObserverModule.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onInteraction(PlayerInteractEvent event) {
    if (testObserver(event.getPlayer())) {
        event.setCancelled(true);
        if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (event.getPlayer().getInventory().getItemInMainHand() != null && event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.WRITTEN_BOOK))){
            event.setUseInteractedBlock(Event.Result.DENY);
            event.setUseItemInHand(Event.Result.ALLOW);
        }
        if (event.getClickedBlock() != null && !event.getPlayer().isSneaking() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (event.getClickedBlock().getType().equals(Material.CHEST) || event.getClickedBlock().getType().equals(Material.TRAPPED_CHEST)) {
                Inventory chest = Bukkit.createInventory(null, ((Chest) event.getClickedBlock().getState()).getInventory().getSize());
                for (int i = 0; i < ((Chest) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    chest.setItem(i, ((Chest) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(chest);
            }
            if (event.getClickedBlock().getType().equals(Material.FURNACE) || event.getClickedBlock().getType().equals(Material.BURNING_FURNACE)) {
                Inventory furnace = Bukkit.createInventory(null, InventoryType.FURNACE);
                for (int i = 0; i < ((Furnace) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    furnace.setItem(i, ((Furnace) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(furnace);
            }
            if (event.getClickedBlock().getType().equals(Material.DISPENSER)) {
                Inventory dispenser = Bukkit.createInventory(null, InventoryType.DISPENSER);
                for (int i = 0; i < ((Dispenser) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    dispenser.setItem(i, ((Dispenser) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(dispenser);
            }
            if (event.getClickedBlock().getType().equals(Material.DROPPER)) {
                Inventory dropper = Bukkit.createInventory(null, InventoryType.DROPPER);
                for (int i = 0; i < ((Dropper) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    dropper.setItem(i, ((Dropper) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(dropper);
            }
            if (event.getClickedBlock().getType().equals(Material.HOPPER)) {
                Inventory hopper = Bukkit.createInventory(null, InventoryType.HOPPER);
                for (int i = 0; i < ((Hopper) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    hopper.setItem(i, ((Hopper) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(hopper);
            }
            if (event.getClickedBlock().getType().equals(Material.BREWING_STAND)) {
                Inventory brewingStand = Bukkit.createInventory(null, InventoryType.BREWING);
                for (int i = 0; i < ((BrewingStand) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    brewingStand.setItem(i, ((BrewingStand) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(brewingStand);
            }
            if (event.getClickedBlock().getType().equals(Material.BEACON)) {
                Inventory beacon = Bukkit.createInventory(null, InventoryType.BEACON);
                for (int i = 0; i < ((Beacon) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    beacon.setItem(i, ((Beacon) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(beacon);
            }
        }
    }
}
 
Example 20
Source File: SignsFeature.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSignClick(PlayerInteractEvent event) {
	Block block = event.getClickedBlock();
	if (block == null) {
		return;
	}

	// Only listen to left and right clicks on blocks
	if (!(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK)) {
		return;
	}

	// Only care about clicking blocks
	if(!Materials.isSign(block.getType())) {
		return;
	}

	// Check if this sign belongs to a region
	RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
	if(regionSign == null) {
		return;
	}

	// Ignore players that are in sign link mode (which will handle the event itself)
	Player player = event.getPlayer();
	if(plugin.getSignlinkerManager().isInSignLinkMode(player)) {
		return;
	}

	// Get the clicktype
	GeneralRegion.ClickType clickType = null;
	if(player.isSneaking() && event.getAction() == Action.LEFT_CLICK_BLOCK) {
		clickType = GeneralRegion.ClickType.SHIFTLEFTCLICK;
	} else if(!player.isSneaking() && event.getAction() == Action.LEFT_CLICK_BLOCK) {
		clickType = GeneralRegion.ClickType.LEFTCLICK;
	} else if(player.isSneaking() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
		clickType = GeneralRegion.ClickType.SHIFTRIGHTCLICK;
	} else if(!player.isSneaking() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
		clickType = GeneralRegion.ClickType.RIGHTCLICK;
	}

	boolean ran = regionSign.runSignCommands(player, clickType);

	// Only cancel event if at least one command has been executed
	event.setCancelled(ran);
}