当前位置: 首页>>代码示例>>Java>>正文


Java InteractBlockEvent.setCancelled方法代码示例

本文整理汇总了Java中org.spongepowered.api.event.block.InteractBlockEvent.setCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java InteractBlockEvent.setCancelled方法的具体用法?Java InteractBlockEvent.setCancelled怎么用?Java InteractBlockEvent.setCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.event.block.InteractBlockEvent的用法示例。


在下文中一共展示了InteractBlockEvent.setCancelled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onEitherClick

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onEitherClick(final InteractBlockEvent event, @First Player player) {
    if (player.hasPermission("safeguard.mod")) {
        return;
    }

    // Ignore clicks in the air
    if (event.getTargetBlock().equals(BlockSnapshot.NONE) || !event.getTargetBlock().getLocation().isPresent()) {
        return;
    }

    if (!event.getTargetBlock().getState().getType().equals(BlockTypes.DRAGON_EGG)) {
        return;
    }

    if (!SafeGuard.getZoneManager().allows(player, changeFlag, event.getTargetBlock().getLocation().get())) {
        player.sendMessage(Format.error("Sorry, this zone doesn't allow you to do that."));
        event.setCancelled(true);
    }
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:21,代码来源:InteractBlockListener.java

示例2: onInteractBlock

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onInteractBlock(InteractBlockEvent event) {
    java.util.Optional<Player> player = event.getCause().first(Player.class);
    if (!player.isPresent()) {
        return;
    }

    // check if the damager is a challenger
    Optional<Challenger> challenger = Main.getMinigame().getChallenger(player.get().getUniqueId());
    if (challenger.isPresent()) { // damager is a challenger
        // check if the round hasn't started yet
        if (!challenger.get().getRound().getLifecycleStage().getId().equals(Main.PLAYING_STAGE_ID)) {
            event.setCancelled(true); // can't break blocks in advance
        }
        // check if they're holding a shovel
        if (!player.get().getItemInHand(HandTypes.MAIN_HAND).isPresent()
                || !Main.SHOVELS.contains(player.get().getItemInHand(HandTypes.MAIN_HAND).get().getItem())) {
            event.setCancelled(true); // can't break blocks without a shovel
        }
    }
}
 
开发者ID:caseif,项目名称:InfernoSpleef,代码行数:22,代码来源:BlockListener.java

示例3: onInteract

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
/** protect playershop crates */
	
	@Listener
	public void onInteract(InteractBlockEvent event) {
		Optional<Player> source = event.getCause().first(Player.class);
		if (!source.isPresent()) return;
		if (!event.getTargetBlock().getLocation().isPresent()) return;
		Extent tex = event.getTargetBlock().getLocation().get().getExtent();
		Vector3i tv3 = event.getTargetBlock().getPosition(); 
		for (NPCguard g : VillagerShops.npcs)
			if (g.playershopcontainer != null && 
					g.playershopcontainer.getExtent().equals(tex) &&
					g.playershopcontainer.getBlockPosition().equals(tv3)) {
//				VillagerShops.l("Is Stock Container");
				if (	( g.playershopholder!=null && !g.playershopholder.equals(source.get().getUniqueId()) ) &&
						( !source.get().hasPermission("vshop.edit.admin")) ) {
//					VillagerShops.l("But not yours!");
					event.setCancelled(true);
					return;
				}
			}
	}
 
开发者ID:DosMike,项目名称:VillagerShops,代码行数:23,代码来源:EventListeners.java

示例4: onRemove

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onRemove(InteractBlockEvent event, @First Player player)
{
    if (!(event instanceof InteractBlockEvent.Primary.MainHand) && !(event instanceof InteractBlockEvent.Secondary.MainHand))
    {
        return;
    }
    if (!this.removeRequests.contains(player.getUniqueId()))
    {
        return;
    }
    if (event instanceof InteractBlockEvent.Secondary)
    {
        event.setCancelled(true);
        if (this.rbm.detachRepairBlock(event.getTargetBlock().getLocation().get()))
        {
            i18n.send(player, POSITIVE, "Repair block successfully removed!");
        }
        else
        {
            i18n.send(player, NEGATIVE, "This block is not a repair block!");
        }
        this.removeRequests.remove(player.getUniqueId());
    }
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:26,代码来源:ItemRepairCommands.java

示例5: onPlayerInteractEntity

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerInteractEntity(InteractBlockEvent event, @First Player player) {
	if (event.isCancelled()) {
		return;
	}
	event.setCancelled(this.jailInteract(player));
}
 
开发者ID:EverCraft,项目名称:EverSanctions,代码行数:8,代码来源:ESListener.java

示例6: onBlockInteract

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockInteract(InteractBlockEvent event, @First Player player) {
    HandType hand = Utils.getEventHand(event);
    BlockSnapshot blockSnapshot = event.getTargetBlock();
    if (blockSnapshot == BlockSnapshot.NONE) {
        return;
    }
    CustomWorld world = WorldManager.toCustomWorld(player.getWorld());
    Vector3i pos = blockSnapshot.getPosition();
    BlockNature block = world.getBlock(pos);
    if (block == null) {
        return;
    }
    Direction side = event.getTargetSide();
    Vector3d point = event.getInteractionPoint().orElse(null);
    boolean allowInteract = !event.isCancelled();
    if (event instanceof InteractBlockEvent.Primary) {
        allowInteract = block.onBlockHit(world, pos, player, hand, side, point);
    } else if (event instanceof InteractBlockEvent.Secondary) {
        if (player.getItemInHand(hand).isPresent() && player.get(Keys.IS_SNEAKING).get()) {
            // Pass on the item click without telling the block
            allowInteract = true;
        } else {
            allowInteract = block.onBlockActivated(world, pos, player, hand, side, point);
        }
    }
    event.setCancelled(!allowInteract);

}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:30,代码来源:CustomBlockEventListeners.java

示例7: onInteractBlock

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
	BlockSnapshot b = event.getTargetBlock();
    Location<World> l = null;
    
    RedProtect.get().logger.debug("player","RPBlockListener - Is InteractBlockEvent event");
    
    if (!b.getState().getType().equals(BlockTypes.AIR)){
    	l = b.getLocation().get();
    	RedProtect.get().logger.debug("player","RPBlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName());
    } else {
    	l = p.getLocation();
    }
    
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r != null){
    	ItemType itemInHand = ItemTypes.NONE;                
        if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
        	itemInHand = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
        } else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()){
        	itemInHand = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
        }
        if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)){
			RPLang.sendMessage(p, "blocklistener.region.cantbuild");
            event.setCancelled(true); 
		}
    }        
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:29,代码来源:RPBlockListener.java

示例8: onBlockInteract

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockInteract(InteractBlockEvent event, @First(typeFilter = Player.class) Player player) {
	if (event.getTargetBlock().getState().getType() == BlockTypes.BREWING_STAND) {
		IActiveCharacter character = characterService.getCharacter(player);
		if (!character.hasEffect(AlchemyEffect.name)) {
			event.setCancelled(true);
		}
	}
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:10,代码来源:SkillListener.java

示例9: onInteract

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onInteract(InteractBlockEvent event, @First Player player) {
  Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
  if (!optLoc.isPresent()) {
    return;
  }

  if (check(player, optLoc.get())) {
    event.setCancelled(true);
    if (event.getCause().root().equals(player)) {
      player.sendMessage(Text.of(TextColors.RED, "You can't interact with blocks here!"));
      player.sendMessage(Text.of(TextColors.RED, "[Debug] ", optLoc.get(), " [Cause ", event.getCause(), "]"));
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:16,代码来源:RegionServiceImpl.java

示例10: onClick

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onClick(InteractBlockEvent event, @First Player player)
{
    if (event instanceof InteractBlockEvent.Primary.MainHand || event instanceof InteractBlockEvent.Secondary.MainHand)
    {
        Optional<ItemStack> itemInHand = player.getItemInHand(HandTypes.MAIN_HAND);
        if (itemInHand.isPresent() && itemInHand.get().get(LookupData.class).isPresent())
        {
            if (!player.hasPermission(toolPerm.getId()) || event.getTargetBlock() == BlockSnapshot.NONE)
            {
                return;
            }
            Location<World> loc;
            if (event instanceof InteractBlockEvent.Primary)
            {
                loc = event.getTargetBlock().getLocation().get();
            }
            else
            {
                loc = event.getTargetBlock().getLocation().get().getRelative(event.getTargetSide());
            }

            qm.queryAndShow(new Lookup(itemInHand.get().get(LookupData.class).get()).with(loc), player);
            event.setCancelled(true);
        }
    }
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:28,代码来源:ToolListener.java

示例11: onAdd

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onAdd(InteractBlockEvent event, @First Player player)
{
    if (!(event instanceof InteractBlockEvent.Primary.MainHand) && !(event instanceof InteractBlockEvent.Secondary.MainHand))
    {
        return;
    }
    if (!this.addRequests.contains(player.getUniqueId()) || !event.getTargetBlock().getLocation().isPresent())
    {
        return;
    }
    if (event instanceof InteractBlockEvent.Primary)
    {
        this.addRequests.remove(player.getUniqueId());
        return;
    }
    event.setCancelled(true);
    Location<World> block = event.getTargetBlock().getLocation().get();
    if (rbm.isRepairBlock(block))
    {
        i18n.send(player, NEGATIVE, "This block is already a repair block!");
    }
    this.addRequests.remove(player.getUniqueId());
    if (rbm.attachRepairBlock(block))
    {
        i18n.send(player, POSITIVE, "Repair block successfully added!");
        return;
    }
    i18n.send(player, NEGATIVE, "This block can't be used as a repair block!");
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:31,代码来源:ItemRepairCommands.java

示例12: onPlayerClick

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
@Include({InteractBlockEvent.Primary.class, InteractBlockEvent.Secondary.class})
public void onPlayerClick(final InteractBlockEvent event, @Root Player player) {
    if (!event.getTargetBlock().getLocation().isPresent()) {
        return;
    }
    final Location<World> location = event.getTargetBlock().getLocation().get();
    //Special code to handle shift secondary clicking (placing a block)
    if (event instanceof InteractBlockEvent.Secondary && player.get(Keys.IS_SNEAKING).orElse(false)) {
        if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent() && player.getItemInHand(HandTypes.MAIN_HAND).get().getItem().getBlock().isPresent()) {
            if (location.getBlockRelative(event.getTargetSide()).getBlockType() == BlockTypes.AIR) {
                //If they're sneaking and have an item(block) in their hand, and are clicking to replace air... let the block place handle it
                return;
            }
        }
    }

    //Ignore air and invalid locations, and non-lockable blocks
    if (event.getTargetBlock().equals(BlockSnapshot.NONE) || !Latch.getLockManager().isLockableBlock(event.getTargetBlock().getState().getType())) {
        return;
    }

    //If they have an interaction, handle the interaction
    if (Latch.getLockManager().hasInteractionData(player.getUniqueId())) {
        final LockInteraction lockInteraction = Latch.getLockManager().getInteractionData(player.getUniqueId());

        lockInteraction.handleInteraction(player, location, event.getTargetBlock());

        event.setCancelled(true);

        if (!lockInteraction.shouldPersist()) {
            Latch.getLockManager().removeInteractionData(player.getUniqueId());
        }
    } else {
        //Otherwise we only care if it's a lock
        if (Latch.getLockManager().isLockableBlock(event.getTargetBlock().getState().getType())) {
            Latch.getLockManager().getLock(location).ifPresent(lock -> {
                if (lock.getLockType() != LockType.DONATION && !lock.canAccess(player.getUniqueId())) {
                    player.sendMessage(Text.of(TextColors.RED, "You cannot access this lock."));
                    event.setCancelled(true);
                } else {
                    final BlockType blockType = event.getTargetBlock().getState().getType();
                    // Work around code for donation furnaces allowing infinite experience
                    if ((blockType.equals(BlockTypes.FURNACE) || blockType.equals(BlockTypes.LIT_FURNACE))
                        && lock.getLockType() == LockType.DONATION && !lock.canAccess(player.getUniqueId())) {
                        this.stopThem.add(player.getUniqueId());
                    }
                    lock.updateLastAccessed();
                }
            });
        }
    }
}
 
开发者ID:ichorpowered,项目名称:latch,代码行数:54,代码来源:InteractBlockListener.java

示例13: onPlayerInteractBlock

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerInteractBlock(InteractBlockEvent event, @Root Player player)
{
	if (EssentialCmds.frozenPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot interact while frozen."));
		event.setCancelled(true);
		return;
	}

	if (EssentialCmds.jailedPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot interact while jailed."));
		event.setCancelled(true);
		return;
	}

	Optional<Location<World>> optLocation = event.getTargetBlock().getLocation();

	if (optLocation.isPresent() && optLocation.get().getTileEntity().isPresent())
	{
		Location<World> location = optLocation.get();
		TileEntity clickedEntity = location.getTileEntity().get();

		if (event.getTargetBlock().getState().getType().equals(BlockTypes.STANDING_SIGN) || event.getTargetBlock().getState().getType().equals(BlockTypes.WALL_SIGN))
		{
			Optional<SignData> signData = clickedEntity.getOrCreate(SignData.class);

			if (signData.isPresent())
			{
				SignData data = signData.get();
				CommandManager cmdService = Sponge.getGame().getCommandManager();
				String line0 = data.getValue(Keys.SIGN_LINES).get().get(0).toPlain();
				String line1 = data.getValue(Keys.SIGN_LINES).get().get(1).toPlain();
				String command = "warp " + line1;

				if (line0.equals("[Warp]"))
				{
					if (player.hasPermission("essentialcmds.warps.use.sign"))
					{
						cmdService.process(player, command);
					}
					else
					{
						player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to use Warp Signs!"));
					}
				}
			}
		}
	}
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:52,代码来源:PlayerInteractListener.java

示例14: onInteract

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
/**
 * Listens for interactions by Players with active inspection wands.
 *
 * This listener is required and does not track any events.
 *
 * @param event InteractEvent
 */
@Listener
public void onInteract(final InteractBlockEvent event, @First Player player) {
    // Wand support
    if (Prism.getActiveWands().contains(player.getUniqueId())) {
        QuerySession session = new QuerySession(player);
        session.addFlag(Flag.EXTENDED);
        session.addFlag(Flag.NO_GROUP);

        Query query = session.newQuery();

        if (event.getTargetBlock().equals(BlockSnapshot.NONE)) {
            return;
        }

        // Location of block
        Location<World> location = event.getTargetBlock().getLocation().get();

        // Secondary click gets location relative to side clicked
        if (event instanceof Secondary) {
            location = location.getRelative(event.getTargetSide());
        }

        query.addCondition(ConditionGroup.from(location));

        player.sendMessage(Format.heading(String.format("Querying x:%d y:%d z:%d:",
                location.getBlockX(),
                location.getBlockY(),
                location.getBlockZ())));

        // Pass off to an async lookup helper
        try {
            AsyncUtil.lookup(session);
        } catch (Exception e) {
            player.sendMessage(Format.error(e.getMessage()));
            e.printStackTrace();
        }

        event.setCancelled(true);
    }
}
 
开发者ID:prism,项目名称:Prism,代码行数:48,代码来源:RequiredInteractListener.java

示例15: onInteract

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onInteract(InteractBlockEvent event) {
    Player player = SpongeUtil.getCause(event.getCause(), Player.class);
    if (player == null) {
        event.setCancelled(true);
        return;
    }
    BlockSnapshot block = event.getTargetBlock();
    if (block == null) {
        return;
    }
    Optional<org.spongepowered.api.world.Location<World>> bloc = block.getLocation();
    if (!bloc.isPresent()) {
        return;
    }
    Location loc = SpongeUtil.getLocation(player.getWorld().getName(), bloc.get());
    PlotArea area = loc.getPlotArea();
    if (area == null) {
        return;
    }
    Plot plot = area.getPlot(loc);
    PlotPlayer pp = SpongeUtil.getPlayer(player);
    if (plot == null) {
        if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD, true)) {
            event.setCancelled(true);
            return;
        }
        return;
    }
    if (!plot.hasOwner()) {
        if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED)) {
            return;
        }
        MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_UNOWNED);
        event.setCancelled(true);
        return;
    }
    if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
        return;
    } else {
        com.google.common.base.Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
        org.spongepowered.api.world.Location l = SpongeUtil.getLocation(loc);
        if (flag.isPresent() && flag.get().contains(SpongeUtil.getPlotBlock(l.getBlock()))) {
            return;
        }
        MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
        event.setCancelled(true);
        return;
    }
}
 
开发者ID:IntellectualSites,项目名称:PlotSquared,代码行数:51,代码来源:MainListener.java


注:本文中的org.spongepowered.api.event.block.InteractBlockEvent.setCancelled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。