org.bukkit.event.block.Action#LEFT_CLICK_BLOCK源码实例Demo

下面列出了org.bukkit.event.block.Action#LEFT_CLICK_BLOCK 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: CardinalPGM   文件: Tutorial.java
@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();
    }
}
 
源代码2 项目: HubBasics   文件: ItemListener.java
@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());
    }
}
 
源代码3 项目: uSkyBlock   文件: ToolMenuEvents.java
@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);
        }
    }
}
 
源代码4 项目: NBTEditor   文件: CustomItemListener.java
@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);
			}
		}
	}
}
 
源代码5 项目: PGM   文件: Spawning.java
@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();
  }
}
 
源代码6 项目: PGM   文件: ProjectileMatchModule.java
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;
}
 
源代码7 项目: ProjectAres   文件: ProjectilePlayerFacet.java
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;
}
 
源代码8 项目: ClaimChunk   文件: CancellableChunkEvents.java
@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);
    }
}
 
源代码9 项目: Survival-Games   文件: SignClickEvent.java
@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){}
    }

}
 
源代码10 项目: AnnihilationPro   文件: MapBuilder.java
@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());
				}
			}
		}
	}
}
 
源代码11 项目: AnnihilationPro   文件: TeamBlock.java
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;
}
 
源代码12 项目: DungeonsXL   文件: DSignListener.java
@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);
        }
    }
}
 
源代码13 项目: CardinalPGM   文件: TitleRespawn.java
@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);
    }
}
 
源代码14 项目: Slimefun4   文件: DebugFishListener.java
@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());
            }
        }
    }
}
 
源代码15 项目: HeavySpleef   文件: SignExtension.java
@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);
}
 
源代码16 项目: Crazy-Crates   文件: QuadCrate.java
@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);
                    }
                }
            }
        }
    }
}
 
源代码17 项目: SaneEconomy   文件: InteractListener.java
@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());
    }
}
 
源代码18 项目: HeavySpleef   文件: Game.java
@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);
		}
	}
}
 
源代码19 项目: BetonQuest   文件: ActionObjective.java
@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);
        }
    }
}
 
源代码20 项目: AreaShop   文件: SignsFeature.java
@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);
}