Java Code Examples for org.bukkit.event.block.Action#LEFT_CLICK_BLOCK
The following examples show how to use
org.bukkit.event.block.Action#LEFT_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: CustomItemListener.java From NBTEditor with GNU General Public License v3.0 | 6 votes |
@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 2
Source File: ToolMenuEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@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 3
Source File: Tutorial.java From CardinalPGM with MIT License | 6 votes |
@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: ItemListener.java From HubBasics with GNU Lesser General Public License v3.0 | 6 votes |
@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 5
Source File: Spawning.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@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: DebugFishListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@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 7
Source File: TitleRespawn.java From CardinalPGM with MIT License | 5 votes |
@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 8
Source File: DSignListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@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 9
Source File: TeamBlock.java From AnnihilationPro with MIT License | 5 votes |
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 10
Source File: MapBuilder.java From AnnihilationPro with MIT License | 5 votes |
@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: SignClickEvent.java From Survival-Games with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void clickHandler(PlayerInteractEvent e){ if(!(e.getAction()==Action.RIGHT_CLICK_BLOCK || e.getAction()==Action.LEFT_CLICK_BLOCK)) return; Block clickedBlock = e.getClickedBlock(); if(!(clickedBlock.getState() instanceof Sign)) return; Sign thisSign = (Sign) clickedBlock.getState(); //System.out.println("Clicked sign"); String[] lines = thisSign.getLines(); if(lines.length<3) return; if(lines[0].equalsIgnoreCase("[SurvivalGames]")) { e.setCancelled(true); try{ if(lines[2].equalsIgnoreCase("Auto Assign")){ if(SettingsManager.getInstance().getConfig().getInt("randomjoin-mode", 1) == 0) { GameManager.getInstance().addPlayerRandomly(e.getPlayer()); }else { GameManager.getInstance().autoAddPlayer(e.getPlayer()); } } else{ String game = lines[2].replace("Arena ", ""); int gameno = Integer.parseInt(game); GameManager.getInstance().addPlayer(e.getPlayer(), gameno); } }catch(Exception ek){} } }
Example 12
Source File: CancellableChunkEvents.java From ClaimChunk with MIT License | 5 votes |
@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 13
Source File: ProjectilePlayerFacet.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
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 14
Source File: ProjectileMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
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 15
Source File: QuadCrate.java From Crazy-Crates with MIT License | 4 votes |
@EventHandler public void onChestClick(PlayerInteractEvent e) { Player player = e.getPlayer(); if (QuadCrateSession.inSession(player)) { QuadCrateSession session = QuadCrateSession.getSession(player); if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) { Block block = e.getClickedBlock(); if (session.getChestLocations().contains(block.getLocation())) { e.setCancelled(true); if (!session.hasChestBeenOpened(block.getLocation())) { nms.openChest(block, true); Crate crate = session.getCrate(); Prize prize = crate.pickPrize(player, block.getLocation().add(.5, 1.3, .5)); cc.givePrize(player, prize); ItemBuilder itemBuilder = ItemBuilder.convertItemStack(prize.getDisplayItem()); itemBuilder.addLore(new Random().nextInt(Integer.MAX_VALUE) + "");//Makes sure items don't merge ItemStack item = itemBuilder.build(); NBTItem nbtItem = new NBTItem(item); nbtItem.setBoolean("crazycrates-item", true); item = nbtItem.getItem(); Item reward = player.getWorld().dropItem(block.getLocation().add(.5, 1, .5), item); reward.setMetadata("betterdrops_ignore", new FixedMetadataValue(cc.getPlugin(), true)); reward.setVelocity(new Vector(0, .2, 0)); reward.setCustomName(prize.getDisplayItem().getItemMeta().getDisplayName()); reward.setCustomNameVisible(true); reward.setPickupDelay(Integer.MAX_VALUE); session.getDisplayedRewards().add(reward); session.setChestOpened(block.getLocation(), true); if (session.allChestsOpened()) {//All 4 crates have been opened new BukkitRunnable() { @Override public void run() { session.endCrate(); player.playSound(player.getLocation(), cc.getSound("BLOCK_STONE_STEP", "STEP_STONE"), 1, 1); } }.runTaskLater(cc.getPlugin(), 60); } } } } } }
Example 16
Source File: InteractListener.java From SaneEconomy with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent evt) { if (!evt.getPlayer().hasPermission("saneeconomy.signshop.use")) { return; } if (evt.getHand() != EquipmentSlot.HAND) { return; } if ((evt.getPlayer().getInventory().getItemInMainHand() != null) && (evt.getPlayer().getInventory().getItemInMainHand().getType() == Material.DIAMOND_AXE)) { return; } if ((evt.getAction() != Action.RIGHT_CLICK_BLOCK) && (evt.getAction() != Action.LEFT_CLICK_BLOCK)) { return; } Optional<SignShop> shopOptional = this.plugin.getSignShopManager().getSignShop(evt.getClickedBlock().getLocation()); if (!shopOptional.isPresent()) { return; } SignShop shop = shopOptional.get(); // Buy if (evt.getAction() == Action.RIGHT_CLICK_BLOCK) { evt.setCancelled(true); if (!shop.canBuy()) { this.plugin.getMessenger().sendMessage(evt.getPlayer(), "This shop does not permit buying."); return; } this.doBuy(shop, evt.getPlayer()); } // Sell if (evt.getAction() == Action.LEFT_CLICK_BLOCK) { evt.setCancelled(true); if (!shop.canSell()) { this.plugin.getMessenger().sendMessage(evt.getPlayer(), "This shop does not permit selling."); return; } this.doSell(shop, evt.getPlayer()); } }
Example 17
Source File: Game.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") public void onPlayerInteract(PlayerInteractEvent event, SpleefPlayer player) { Block block = event.getClickedBlock(); Action action = event.getAction(); PlayerInteractGameEvent spleefEvent = new PlayerInteractGameEvent(this, player, block, action); eventBus.callEvent(spleefEvent); if (spleefEvent.isCancelled()) { event.setCancelled(true); return; } if (gameState != GameState.INGAME) { return; } boolean isInstantBreak = getPropertyValue(GameProperty.INSTANT_BREAK); boolean playBreakEffect = getPropertyValue(GameProperty.PLAY_BLOCK_BREAK); if (action == Action.LEFT_CLICK_BLOCK && isInstantBreak) { boolean breakBlock = false; for (Floor floor : floors.values()) { if (floor.contains(block)) { breakBlock = true; break; } } if (breakBlock) { PlayerBlockBreakEvent breakEvent = new PlayerBlockBreakEvent(this, player, block); eventBus.callEvent(breakEvent); if (breakEvent.isCancelled()) { return; } Material blockMaterial = block.getType(); block.setType(Material.AIR); if (playBreakEffect) { block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, blockMaterial.getId()); } addBlockBroken(player, block); } } }
Example 18
Source File: ActionObjective.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void onInteract(PlayerInteractEvent event) { // Only fire the event for the main hand to avoid that the event is triggered two times. if (event.getHand() == EquipmentSlot.OFF_HAND && event.getHand() != null) { return; // off hand packet, ignore. } String playerID = PlayerConverter.getID(event.getPlayer()); if (!containsPlayer(playerID)) { return; } if (selector == null) { switch (action) { case RIGHT: if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && checkConditions(playerID)) { if (cancel) event.setCancelled(true); completeObjective(playerID); } break; case LEFT: if ((event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK)) && checkConditions(playerID)) { if (cancel) event.setCancelled(true); completeObjective(playerID); } break; case ANY: default: if ((event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && checkConditions(playerID)) { if (cancel) event.setCancelled(true); completeObjective(playerID); } break; } } else { Action actionEnum; switch (action) { case RIGHT: actionEnum = Action.RIGHT_CLICK_BLOCK; break; case LEFT: actionEnum = Action.LEFT_CLICK_BLOCK; break; case ANY: default: actionEnum = null; break; } try { if (((actionEnum == null && (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_BLOCK))) || event.getAction().equals(actionEnum)) && (event.getClickedBlock() != null && (((selector.match(Material.FIRE) || selector.match(Material.LAVA) || selector.match(Material.WATER)) && selector.match(event.getClickedBlock().getRelative(event.getBlockFace()))) || selector.match(event.getClickedBlock())))) { if (loc != null) { Location location = loc.getLocation(playerID); double r = range.getDouble(playerID); if (!event.getClickedBlock().getWorld().equals(location.getWorld()) || event.getClickedBlock().getLocation().distance(location) > r) { return; } } if (checkConditions(playerID)) { if (cancel) { event.setCancelled(true); } completeObjective(playerID); } } } catch (QuestRuntimeException e) { LogUtils.getLogger().log(Level.WARNING, "Error while handling '" + instruction.getID() + "' objective: " + e.getMessage()); LogUtils.logThrowable(e); } } }
Example 19
Source File: SignExtension.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Block clickedBlock = event.getClickedBlock(); if (clickedBlock == null) { return; } if (clickedBlock.getType() != Material.SIGN_POST && clickedBlock.getType() != Material.WALL_SIGN) { return; } Location loc = clickedBlock.getLocation(); if (!loc.equals(location)) { return; } SpleefPlayer player = getHeavySpleef().getSpleefPlayer(event.getPlayer()); Action action = event.getAction(); if (action == Action.LEFT_CLICK_BLOCK && player.getBukkitPlayer().getGameMode() == GameMode.CREATIVE) { return; } String[] permissions = getPermission(); boolean hasPermission = false; for (String perm : permissions) { if (!player.hasPermission(perm)) { continue; } hasPermission = true; } if (!hasPermission) { player.sendMessage(i18n.getString(Messages.Command.NO_PERMISSION)); return; } event.setCancelled(true); onSignClick(player); }
Example 20
Source File: SignsFeature.java From AreaShop with GNU General Public License v3.0 | 4 votes |
@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); }