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


Java InteractBlockEvent.Secondary方法代码示例

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


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

示例1: onOpenInventory

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onOpenInventory(final InteractBlockEvent.Secondary event, @First Player player) {
    Optional<TileEntity> entity = event.getTargetBlock().getLocation().get().getTileEntity();
    if (!entity.isPresent()) {
        return;
    }

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

    if (player.hasPermission("safeguard.mod")) {
        return;
    }

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

示例2: onRightClickBlock

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onRightClickBlock(InteractBlockEvent.Secondary evt, @Root Player player) {
    PlayerRightClicksBlockScriptEvent event = (PlayerRightClicksBlockScriptEvent) clone();
    event.internal = evt;
    event.player = new PlayerTag(player);
    if (evt.getTargetBlock().getLocation().isPresent()) {
        event.location = new LocationTag(evt.getTargetBlock().getLocation().get());
        event.precise_location = new LocationTag(evt.getInteractionPoint().get().add(evt.getTargetBlock().getPosition().toDouble()));
        event.precise_location.getInternal().world = event.location.getInternal().world;
        event.intersection_point = new LocationTag(evt.getInteractionPoint().get());
        event.impact_normal = new LocationTag(evt.getTargetSide().asOffset());
    }
    else {
        BlockRayHit<World> brh = BlockRay.from(player).distanceLimit(Utilities.getHandReach(player)).build().end().get();
        event.location = new LocationTag(brh.getLocation());
        event.precise_location = new LocationTag(brh.getPosition());
        event.precise_location.getInternal().world = event.location.getInternal().world;
        event.intersection_point = new LocationTag(brh.getPosition().sub(brh.getBlockPosition().toDouble()));
        event.impact_normal = new LocationTag(0, 0, 0);
    }
    event.hInternal = evt.getHandType();
    event.hand = new TextTag(Utilities.getIdWithoutDefaultPrefix(evt.getHandType().getId()));
    event.cancelled = evt.isCancelled();
    event.run();
    evt.setCancelled(event.cancelled);
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:27,代码来源:PlayerRightClicksBlockScriptEvent.java

示例3: onUse

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onUse(final InteractBlockEvent.Secondary event, @First Player player) {
    // Ignore clicks in the air
    if (event.getTargetBlock().equals(BlockSnapshot.NONE) || !event.getTargetBlock().getLocation().isPresent()) {
        return;
    }

    try {
        if (!player.hasPermission("keys.mod") && !Keys.getStorageAdapter().allowsAccess(player, event.getTargetBlock().getLocation().get())) {
            player.sendMessage(Format.error("You may not interact with this locked location."));
            event.setCancelled(true);
        }

        listLockOwner(player, event.getTargetBlock().getLocation().get());
    } catch (SQLException e) {
        player.sendMessage(Format.error("Storage error. Details have been logged."));
        e.printStackTrace();
    }
}
 
开发者ID:prism,项目名称:Keys,代码行数:20,代码来源:InteractBlockListener.java

示例4: onInteractBlockSecondaryMain

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) {
    Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
    if(itemStackOptional.isPresent()) {

        BlockState blockState = event.getTargetBlock().getState();
        String blockTypeId = blockState.getType().getId();
        String blockStateId = blockState.getId();

        ItemType itemType = itemStackOptional.get().getType();
        String itemId = itemType.getId();

        PermHandler ph = PermHandler.getInstance();

        if (!ph.checkPerm(player, "protectionperms.item.use." + itemId + ".on." + blockTypeId + ".secondary",
                "protectionperms.item.use." + itemId + ".on." + blockStateId + ".secondary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + blockState.getName() + '!'));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:23,代码来源:SecondaryBlockListener.java

示例5: onInteractBlockSecondary

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onInteractBlockSecondary(InteractBlockEvent.Secondary event, @Root Player player) {

    BlockState blockState = event.getTargetBlock().getState();
    String blockTypeId = blockState.getType().getId();
    String blockStateId = blockState.getId();

    PermHandler ph = PermHandler.getInstance();

    if (!ph.checkPerm(player, "protectionperms.block.interact." + blockTypeId + ".secondary",
            "protectionperms.block.interact." + blockStateId + ".secondary")) {
        event.setCancelled(true);
        player.sendMessage(ChatTypes.ACTION_BAR,
                Text.of(TextColors.RED, "You don't have permission to secondary interact with " + blockState.getName() + '!'));
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:17,代码来源:SecondaryListener.java

示例6: use

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void use(InteractBlockEvent.Secondary event, @Root Player player)
{
    if (!player.hasPermission(Permissions.MOUNT_USE) || player.getVehicle().isPresent())
    {
        return;
    }

    player.getItemInHand()
            .map(ItemStack::getItem)
            .ifPresent(item -> player.get(PlayerMountDataMutable.class)
                    .filter(data -> data.itemType() == item)
                    .flatMap(data -> data.createPlayMount(player))
                    .filter(mount -> mount.mountPlayer(this))
                    .ifPresent(mount -> {
                        activeMounts.add(mount);
                        event.setCancelled(true);
                    })
            );
}
 
开发者ID:dags-,项目名称:Mounts,代码行数:21,代码来源:MountsPlugin.java

示例7: onBlockInteract

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

  Location<World> location = optLocation.get();

  Optional<T> optInst = getApplicable(location);
  if (!optInst.isPresent()) {
    return;
  }

  T inst = optInst.get();
  Vector3i minPoint = inst.getRegion().getMinimumPoint();
  Vector3i clickedPoint = location.getBlockPosition();

  Vector3i offset = clickedPoint.sub(minPoint);

  player.sendMessage(Text.of("Offset: ", offset));
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:23,代码来源:ZoneRelativePositionListener.java

示例8: onPlayerClick

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerClick(InteractBlockEvent.Secondary event, @First Player player) {
    if (state.equals(State.CLICK) && player.getUniqueId().equals(getParent().getUUID())) {
        BlockSnapshot snapshot = event.getTargetBlock();
        // Make sure the block was clicked twice
        if (doubleClickCurrent == null) {
            doubleClickTick = Sponge.getServer().getRunningTimeTicks();
            doubleClickCurrent = snapshot;
        } else {
            if (doubleClickCurrent.equals(snapshot) && Sponge.getServer().getRunningTimeTicks() - doubleClickTick > 5) {
                doubleClickCurrent = null;
                doubleClickTick = 0;
                player.sendMessage(messages.getMessage("creation.breakcurrency"));
                blockState = snapshot.getState();
                state = State.CURRENCY;
            } else {
                doubleClickTick = Sponge.getServer().getRunningTimeTicks();
                doubleClickCurrent = snapshot;
            }
        }
    }
}
 
开发者ID:Flibio,项目名称:JobsLite,代码行数:23,代码来源:BreakTask.java

示例9: onSecondary

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
// TODO @Include(value = {InteractBlockEvent.Secondary.class, InteractEntityEvent.Secondary.class})
public void onSecondary(InteractEvent event, @First Player player)
{
    if (!(event instanceof InteractBlockEvent.Secondary))
    {
        // TODO remove when include works as intended
        return;
    }
    if (player.getItemInHand(HandTypes.MAIN_HAND).map(ItemStack::getType).orElse(null) != COMPASS
            || !player.hasPermission(module.perms().COMPASS_JUMPTO_RIGHT.getId()))
    {
        return;
    }

    Optional<Location<World>> end = LocationUtil.getBlockBehindWall(player, module.getConfig().navigation.thru.maxRange, module.getConfig().navigation.thru.maxWallThickness);
    if (!end.isPresent())
    {
        i18n.send(player, NEGATIVE, "Nothing to pass through!");
        return;
    }

    player.setLocation(end.get().add(0.5, 0, 0.5));
    i18n.send(ChatTypes.ACTION_BAR, player, NEUTRAL, "You passed through a wall");
    event.setCancelled(true);
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:27,代码来源:TeleportListener.java

示例10: onRightClickBlock

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener(order = Order.EARLY)
public void onRightClickBlock(InteractBlockEvent.Secondary event, @First Player player)
{
    if (isPlayerInteract(player))
    {
        return;
    }

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

    LockAction lockAction = lockActions.get(player.getUniqueId());
    if (lockAction != null)
    {
        Lock lock = this.manager.getValidLock(location, player);
        if (lock != null || lockAction instanceof LockAction.LockCreateAction)
        {
            lockAction.apply(lock, location, null);
        }
        // else no lock to modify
        cmdUsed(player);
        event.setCancelled(true);
    }
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:24,代码来源:CommandListener.java

示例11: 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

示例12: onSignClick

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onSignClick(InteractBlockEvent.Secondary event, @Root Player p) {
    if (!event.getTargetBlock().getLocation().isPresent() || !event.getTargetBlock().getLocation().get().getTileEntity().isPresent()) {
        return;
    }
    if (!(event.getTargetBlock().getLocation().get().getTileEntity().get() instanceof Sign)) {
        return;
    }
    Sign sign = (Sign) event.getTargetBlock().getLocation().get().getTileEntity().get();
    for (UCSign usign : UltimateCore.get().getSignService().get().getRegisteredSigns()) {
        if (sign.getSignData().get(0).orElse(Text.of()).toPlain().equalsIgnoreCase("[" + usign.getIdentifier() + "]")) {
            if (!p.hasPermission(usign.getUsePermission().get())) {
                Messages.send(p, "core.nopermissions");
            }
            SignUseEvent cevent = new SignUseEvent(usign, sign.getLocation(), Cause.builder().owner(UltimateCore.getContainer()).notifier(p).build());
            Sponge.getEventManager().post(cevent);
            if (!cevent.isCancelled()) {
                usign.onExecute(p, sign);
            }
        }
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:23,代码来源:SignListener.java

示例13: onInteractSecondary

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onInteractSecondary(InteractBlockEvent.Secondary event, @First Player p) {
    ModuleConfig config = Modules.BLOCKPROTECTION.get().getConfig().get();
    if (!config.get().getNode("protections", "allow-interact-secondary").getBoolean()) return;
    if (!event.getTargetBlock().getLocation().isPresent()) return;

    for (Protection prot : GlobalData.get(BlockprotectionKeys.PROTECTIONS).get()) {
        if (prot.getPlayers().contains(p.getUniqueId())) continue;
        if (!prot.getLocations().contains(event.getTargetBlock().getLocation().get())) continue;

        //Check if it should be cancelled
        if (prot.getLocktype().shouldBeCancelled()) {
            event.setCancelled(true);
            p.sendMessage(prot.getLocktype().getErrorMessage(p, prot));
        }
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:18,代码来源:BlockprotectionListener.java

示例14: onInteractBlockSecondary

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onInteractBlockSecondary(InteractBlockEvent.Secondary event, @Root Player player) {
    Optional<RegionBuffer> regionBufferOptional = regionSelectBuffer.getBuffer(player.getUniqueId());
    if (regionBufferOptional.isPresent()) {
        RegionBuffer regionBuffer = regionBufferOptional.get();
        regionBuffer.addBack(event.getTargetBlock().getPosition());
        player.sendMessage(ChatTypes.CHAT, regionBuffer.getProgressionMessage());
        event.setCancelled(true);
    }
}
 
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:11,代码来源:PlayerShopsRPG.java

示例15: onPlayerInteractBlock

import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerInteractBlock(InteractBlockEvent.Secondary event) {
	Optional<Player> cause = event.getCause().first(Player.class);
	Optional<Location<World>> location = event.getTargetBlock().getLocation();
	if (cause.isPresent() && location.isPresent()) {
		Optional<TileEntity> entity = location.get().getTileEntity();
		if (entity.isPresent() && entity.get() instanceof TileEntityCarrier) {
			if (ChestLinkManager.linkChest(cause.get(), (TileEntityCarrier) entity.get()))
				event.setCancelled(true);
		}
	}
}
 
开发者ID:DosMike,项目名称:VillagerShops,代码行数:13,代码来源:EventListeners.java


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