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


Java Material.DRAGON_EGG属性代码示例

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


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

示例1: onEggPunch

@EventHandler(ignoreCancelled = true)
public void onEggPunch(PlayerInteractEvent evt) {
    Block block = evt.getClickedBlock();
    if ((evt.getAction() != Action.LEFT_CLICK_BLOCK && evt.getAction() != Action.RIGHT_CLICK_BLOCK)
            || block == null || block.getType() != Material.DRAGON_EGG)
        return;

    evt.getPlayer().sendMessage(ChatColor.DARK_PURPLE + "You have picked up the egg.");
    block.setType(Material.AIR);
    Utils.giveItem(evt.getPlayer(), new ItemStack(Material.DRAGON_EGG));
    evt.setCancelled(true);
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:12,代码来源:GeneralMechanics.java

示例2: onItemSpawn

@EventHandler
public void onItemSpawn(ItemSpawnEvent event) {
	Item item = event.getEntity();
	ItemStack stack = item.getItemStack();
	World world = item.getWorld();
	
	if (world.getEnvironment() != Environment.THE_END || stack.getType() != Material.DRAGON_EGG
			|| stack.hasItemMeta()) return;
	
	DragonTemplate dragon = plugin.getDEDManager().getWorldWrapper(world).getActiveBattle();
	DragonLoot loot = dragon.getLoot();
	
	String eggName = loot.getEggName().replace("%dragon%", dragon.getName());
	List<String> eggLore = loot.getEggLore().stream()
			.map(s -> s.replace("%dragon%", dragon.getName()))
			.collect(Collectors.toList());

	ItemMeta eggMeta = stack.getItemMeta();
	
	if (eggName != null && !eggName.isEmpty()) {
		eggMeta.setDisplayName(eggName);
	}
	if (eggLore != null && !eggLore.isEmpty()) {
		eggMeta.setLore(eggLore);
	}
	
	stack.setItemMeta(eggMeta);
}
 
开发者ID:2008Choco,项目名称:DragonEggDrop,代码行数:28,代码来源:LootListeners.java

示例3: onBlockChange

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockChange(BlockFromToEvent event) {
    if (event.getBlock().getType() == Material.DRAGON_EGG) {
        event.setCancelled(true);
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:6,代码来源:WorldListener.java

示例4: spawnLootFor

/**
 * Spawn loot for the specific dragon battle
 * 
 * @param battle the battle to spawn loot for
 * @param dragon the dragon whose egg should be spawned
 */
public void spawnLootFor(DragonBattle battle, EnderDragon dragon) {
	Validate.notNull(battle, "Cannot spawn loot for null dragon battle");
	Validate.notNull(dragon, "Cannot spawn loot for null ender dragon");
	
	Location location = battle.getEndPortalLocation();
	
	boolean spawnEgg = RANDOM.nextDouble() * 100 <= eggSpawnChance;
	boolean spawnChest = RANDOM.nextDouble() * 100 <= chestSpawnChance;
	
	// Spawn a chest
	if (spawnChest) {
		location.getBlock().setType(Material.CHEST);
		Chest chest = (Chest) location.getBlock().getState();
		NMS_ABSTRACT.setChestName(chest, chestName);
		
		Inventory inventory = chest.getInventory();
		inventory.clear();
		
		// Spawn an egg within the chest
		if (spawnEgg) {
			ItemStack eggItem = new ItemStack(Material.DRAGON_EGG);
			ItemMeta eggMeta = eggItem.getItemMeta();
			eggMeta.setDisplayName(eggName.replace("%dragon%", dragon.getName()));
			eggMeta.setLore(eggLore);
			eggItem.setItemMeta(eggMeta);
			
			inventory.setItem(inventory.getSize() / 2, eggItem);
		}
		
		// Generate loot within the chest
		int itemGenCount = Math.max(RANDOM.nextInt(maxLootGen), minLootGen);
		for (int i = 0; i < itemGenCount; i++) {
			if (inventory.firstEmpty() == -1) break;
			
			int slot = RANDOM.nextInt(inventory.getSize());
			
			if (inventory.getItem(slot) != null) {
				i--;
				continue;
			}
			
			inventory.setItem(slot, loot.next());
		}
	}
	
	// Spawn the egg
	else if (spawnEgg) {
		location.getBlock().setType(Material.DRAGON_EGG);
	}
	
	// Execute commands
	List<Player> playersInWorld = dragon.getWorld().getPlayers();
	Player commandTarget = playersInWorld.size() > 0 ? playersInWorld.get(0) : null;
	
	for (String command : commands) {
		if (command.contains("%player%") && commandTarget == null) continue;
		
		String commandToExecute = command.replace("%dragon%", dragon.getCustomName());
		if (commandTarget != null) {
			commandToExecute = commandToExecute.replace("%player%", commandTarget.getName());
		}
		
		Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandToExecute);
	}
}
 
开发者ID:2008Choco,项目名称:DragonEggDrop,代码行数:71,代码来源:DragonLoot.java


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