本文整理匯總了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);
}
示例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);
}
示例3: onBlockChange
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockChange(BlockFromToEvent event) {
if (event.getBlock().getType() == Material.DRAGON_EGG) {
event.setCancelled(true);
}
}
示例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);
}
}