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


Java Material.LEVER属性代码示例

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


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

示例1: onLeverOrButton

@EventHandler
public void onLeverOrButton(PlayerInteractEvent event) {
	Block clickedBlock = event.getClickedBlock();
	Player player = event.getPlayer();

	if (clickedBlock == null)
		return;

	String chunk = clickedBlock.getLocation().getChunk().getX() + ";"
			+ clickedBlock.getLocation().getChunk().getZ();
	if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
		return;
	if (!powerable.containsKey(clickedBlock.getWorld().getName()))
		return;
	if (powerable.get(clickedBlock.getWorld().getName()).getList(chunk).contains(clickedBlock.getLocation()))
		return;

	// We cancel; send smoke particles for button, and we just turn off the
	// lever (if it was, for some reason, on).
	if (clickedBlock.getType() == Material.STONE_BUTTON || clickedBlock.getType() == Material.WOOD_BUTTON) {

		clickedBlock.getWorld().spawnParticle(Particle.SMOKE_NORMAL, clickedBlock.getLocation().add(0.5, 1, 0.5), 7,
				0, 0.2, 0, 0.03);
		player.sendMessage(MortuusTerraCore.NOTI_PREFIX + ChatColor.RED + " There is no generator in range!");

	} else if (clickedBlock.getType() == Material.LEVER) {
		BlockState state = clickedBlock.getState();
		Lever lever = (Lever) state.getData();

		lever.setPowered(false);
		state.setData(lever);
		state.update();
		clickedBlock.getWorld().spawnParticle(Particle.SMOKE_NORMAL, clickedBlock.getLocation().add(0.5, 1, 0.5), 7,
				0, 0.2, 0, 0.03);
		player.sendMessage(MortuusTerraCore.NOTI_PREFIX + ChatColor.RED + " There is no generator in range!");
	}

}
 
开发者ID:kadeska,项目名称:MT_Core,代码行数:38,代码来源:GeneratorListener.java

示例2: onPlayerLeaverInteract

@EventHandler
public void onPlayerLeaverInteract(PlayerInteractEvent e) {
	Player p = e.getPlayer();
	Block clicked = e.getClickedBlock();

	if (clicked == null)
		return;

	Block underneath = clicked.getRelative(BlockFace.DOWN);
	Location underneathLoc = underneath.getLocation();

	if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getHand() == EquipmentSlot.OFF_HAND)
		return;

	if (clicked.getType() != Material.LEVER || underneath == null)
		return;

	String chunk = clicked.getLocation().getChunk().getX() + ";" + clicked.getLocation().getChunk().getZ();

	if (underneath.getType() == Material.SPONGE && !underneath.isBlockPowered()) {
		if (!main.getGeckManager().isGeckBuildCorrect(underneath)) {
			p.sendMessage(ChatColor.RED + "You must build the GECK correctly!");

			// Check if the geck is inside the powerables list
		} else if (main.getGenListener().getPowerable().get(clicked.getWorld().getName()).getList(chunk)
				.contains(underneathLoc)) {
			main.getGeckObjectManager().addGeckLocation(underneathLoc);
			main.getGeckObjectManager().getGeckObject(underneathLoc).setCorrect(true);
			main.getGeckObjectManager().getGeckObject(underneathLoc).setPowered(true);
			p.sendMessage(ChatColor.GREEN + "GECK Enabled!");
			return;
		}

	} else if (main.getGeckObjectManager().getGeckObject(underneathLoc) != null && underneath.isBlockPowered()) {
		main.getGeckObjectManager().getGeckObject(underneathLoc).setPowered(false);
		main.getGeckObjectManager().removeGeckLocation(underneathLoc);
		p.sendMessage(ChatColor.RED + "GECK Disabled!");
	}
}
 
开发者ID:kadeska,项目名称:MT_Core,代码行数:39,代码来源:GeckPowerListener.java

示例3: onBreakBlock

@EventHandler
public void onBreakBlock(BlockBreakEvent event) {
	Player player = event.getPlayer();
	Block broken = event.getBlock();
	Location geckLocation = broken.getRelative(0, -1, 0).getLocation();

	if (broken.getType() == Material.LEVER) {
		if (main.getGeckObjectManager().getGeckObject(geckLocation) != null) {
			main.getGeckObjectManager().removeGeckLocation(geckLocation);
			player.sendMessage(ChatColor.RED + "GECK disabled.");
		}

	} else if (broken.getType() == Material.SPONGE
			&& main.getGeckObjectManager().getGeckObject(broken.getLocation()) != null) {
		main.getGeckObjectManager().removeGeckLocation(broken.getLocation());
		player.sendMessage(ChatColor.RED + "GECK disabled.");

	} else if (broken.getType() == Material.PISTON_BASE) {
		List<BlockFace> sides = Arrays.asList(BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH);
		sides.forEach(side -> {
			Location bloc = broken.getRelative(side).getLocation();

			if (main.getGeckObjectManager().getGeckObject(bloc) != null) {
				main.getGeckObjectManager().removeGeckLocation(bloc);
				player.sendMessage(ChatColor.RED + "GECK disabled.");
			}
		});
	}
}
 
开发者ID:kadeska,项目名称:MT_Core,代码行数:29,代码来源:GeckPowerListener.java


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