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


Java InteractBlockEvent类代码示例

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


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

示例1: onBlockPrimaryInteract

import org.spongepowered.api.event.block.InteractBlockEvent; //导入依赖的package包/类
@Listener
public void onBlockPrimaryInteract(InteractBlockEvent.Primary.MainHand e, @First Player p) {
	if (!plugin.getInspectManager().isInspector(p))
		return;
	
	e.setCancelled(true);
	BlockSnapshot block = e.getTargetBlock();
	if (block == null || !block.getLocation().isPresent())
		return;
	
	Location<World> loc = block.getLocation().get();
	
	p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
	Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
		plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition()); });
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:17,代码来源:PlayerInspectListener.java

示例2: onBlockSecondaryInteract

import org.spongepowered.api.event.block.InteractBlockEvent; //导入依赖的package包/类
@Listener
public void onBlockSecondaryInteract(InteractBlockEvent.Secondary.MainHand e, @First Player p) {		
	if (!plugin.getInspectManager().isInspector(p))
		return;
	
	//TODO: Figure out why shearing sheep causes weird shit to happen
	
	e.setCancelled(true);
	BlockSnapshot block = e.getTargetBlock();
	if (block == null || !block.getLocation().isPresent())
		return;
	
	Location<World> loc = block.getLocation().get();
	
	p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
	if (loc.getTileEntity().isPresent() && loc.getTileEntity().get() instanceof TileEntityCarrier) {
		Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
			plugin.getInspectManager().inspectContainer(p, block.getWorldUniqueId(), loc.getBlockPosition()); });
	} else {
		Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
			plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition().add(e.getTargetSide().asBlockOffset())); });
	}
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:24,代码来源:PlayerInspectListener.java

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

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

示例5: onPlayerRightClick

import org.spongepowered.api.event.block.InteractBlockEvent; //导入依赖的package包/类
@Listener(order=Order.AFTER_PRE, beforeModifications = true)
public void onPlayerRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player)
{
	Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
	if (!optLoc.isPresent())
		return;

	Optional<List<Shop>> shops = ShopsData.getShops(optLoc.get());
	if (shops.isPresent()) {
		shops.get().forEach((shop) -> {
			if (shop.getLocation().equals(optLoc.get())) {
				shop.trigger(player);
				Sponge.getScheduler().createTaskBuilder().delayTicks(4).execute(
						task -> {
							shop.update();
							task.cancel();
						}).submit(CarrotShop.getInstance());
			}
		});
	}
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:22,代码来源:PlayerClickListener.java

示例6: onPlayerLeftClickProtect

import org.spongepowered.api.event.block.InteractBlockEvent; //导入依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerLeftClickProtect(InteractBlockEvent.Primary.MainHand event, @First Player player)
{
	if (!player.gameMode().get().equals(GameModes.CREATIVE))
		return;

	Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
	if (!optLoc.isPresent())
		return;

	Optional<List<Shop>> shop = ShopsData.getShops(optLoc.get());
	if (shop.isPresent()) {
		Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);

		if (!optItem.isPresent() || (!optItem.get().getItem().equals(ItemTypes.BEDROCK) && !optItem.get().getItem().equals(ItemTypes.REDSTONE) && !optItem.get().getItem().equals(ItemTypes.STICK))) {
			event.setCancelled(true);
		}
	}
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:20,代码来源:PlayerClickListener.java

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

示例8: onInteract

import org.spongepowered.api.event.block.InteractBlockEvent; //导入依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onInteract(InteractBlockEvent event, @First Player player)
{
	if (!ConfigHandler.getNode("worlds").getNode(player.getWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	if (player.hasPermission("nations.admin.bypass.perm.interact"))
	{
		return;
	}
	Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);
	if (optItem.isPresent() && (ConfigHandler.isWhitelisted("use", optItem.get().getItem().getId()) || optItem.get().getItem().equals(ItemTypes.GOLDEN_AXE) && ConfigHandler.getNode("others", "enableGoldenAxe").getBoolean(true)))
		return;
	event.getTargetBlock().getLocation().ifPresent(loc -> {
		if (!DataHandler.getPerm("interact", player.getUniqueId(), loc))
		{
			event.setCancelled(true);
			if (loc.getBlockType() != BlockTypes.STANDING_SIGN && loc.getBlockType() != BlockTypes.WALL_SIGN)
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_INTERACT));
		}
	});
}
 
开发者ID:Arckenver,项目名称:Nations,代码行数:24,代码来源:InteractPermListener.java

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

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

示例11: onPunchBlock

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

    Optional<InteractionHandler> optional = Keys.getInteractionHandler(player);
    if (!optional.isPresent()) {
        return;
    }

    optional.get().handle(player, event.getTargetBlock().getLocation().get());

    Keys.removeInteractionHandler(player);
}
 
开发者ID:prism,项目名称:Keys,代码行数:17,代码来源:InteractBlockListener.java

示例12: onInteractBlock

import org.spongepowered.api.event.block.InteractBlockEvent; //导入依赖的package包/类
@Listener(order=Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onInteractBlock(InteractBlockEvent.Primary event) {
	Optional<Player> optPlayer = event.getCause().get(NamedCause.SOURCE, Player.class);
	if (!optPlayer.isPresent()) return;
	
	Player player = optPlayer.get();
	if (!this.players.contains(player.getUniqueId())) return;
	
	event.setCancelled(true);
	
	player.sendMessage(Text.of(TextColors.GRAY, TextStyles.BOLD, "============================================"));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Type: ", TextColors.BLUE, TextStyles.RESET, event.getTargetBlock().getState().getId()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Owner: ", TextColors.BLUE, TextStyles.RESET, event.getTargetBlock().getCreator()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Notifier: ", TextColors.BLUE, TextStyles.RESET, event.getTargetBlock().getNotifier()));
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:17,代码来源:EAInfo.java

示例13: onInteractBlockPrimaryMain

import org.spongepowered.api.event.block.InteractBlockEvent; //导入依赖的package包/类
@Listener
public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary 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 + ".primary",
                "protectionperms.item.use." + itemId + ".on." + blockStateId + ".primary")) {
            event.setCancelled(true);
            player.sendMessage(ChatTypes.ACTION_BAR,
                    Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + blockState.getName() + '!'));
        }
    }
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:23,代码来源:PrimaryBlockListener.java

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

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


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