本文整理匯總了Java中org.bukkit.block.CreatureSpawner.getSpawnedType方法的典型用法代碼示例。如果您正苦於以下問題:Java CreatureSpawner.getSpawnedType方法的具體用法?Java CreatureSpawner.getSpawnedType怎麽用?Java CreatureSpawner.getSpawnedType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.block.CreatureSpawner
的用法示例。
在下文中一共展示了CreatureSpawner.getSpawnedType方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSpawnerWorth
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
/**
* Calculates the spawner worth of a chunk.
*
* @param chunk the chunk.
* @param spawners the spawner totals to add to.
* @return the chunk worth in spawners.
*/
private double getSpawnerWorth(Chunk chunk, Map<EntityType, Integer> spawners) {
int count;
double worth = 0;
for (BlockState blockState : chunk.getTileEntities()) {
if (!(blockState instanceof CreatureSpawner)) {
continue;
}
CreatureSpawner spawner = (CreatureSpawner) blockState;
EntityType spawnType = spawner.getSpawnedType();
int stackSize = plugin.getSpawnerStackerHook().getStackSize(spawner);
double blockPrice = plugin.getSettings().getSpawnerPrice(spawnType) * stackSize;
worth += blockPrice;
if (blockPrice != 0) {
count = spawners.getOrDefault(spawnType, 0);
spawners.put(spawnType, count + stackSize);
}
}
return worth;
}
示例2: onBlockBreak
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
if(controller.isStarting())
e.setCancelled(true);
else if(controller.isPlaying()
&& e.getBlock().getType() == Material.MOB_SPAWNER) {
CreatureSpawner spawner = (CreatureSpawner) e.getBlock().getState();
if(spawner.getSpawnedType() == EntityType.BLAZE)
e.setCancelled(true);
}
}
示例3: getSpawnerType
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
@Override
public EntityType getSpawnerType(ItemStack item) {
BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
return bs.getSpawnedType();
}
示例4: updateWorth
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
private void updateWorth(Block block, RecalculateReason reason, boolean negate) {
// Do nothing if this area should not be calculated.
String factionId = plugin.getFactionsHook().getFactionAt(block);
if (plugin.getSettings().getIgnoredFactionIds().contains(factionId)) {
return;
}
// Get the worth type and price of this event.
int multiplier = negate ? -1 : 1;
double price = multiplier * plugin.getSettings().getBlockPrice(block.getType());
WorthType worthType = WorthType.BLOCK;
Map<Material, Integer> materials = new HashMap<>();
Map<EntityType, Integer> spawners = new HashMap<>();
plugin.getWorthManager().add(block.getChunk(), reason, worthType, price,
ImmutableMap.of(block.getType(), multiplier), spawners);
switch (block.getType()) {
case MOB_SPAWNER:
worthType = WorthType.SPAWNER;
CreatureSpawner spawner = (CreatureSpawner) block.getState();
EntityType spawnedType = spawner.getSpawnedType();
multiplier *= plugin.getSpawnerStackerHook().getStackSize(spawner);
price = multiplier * plugin.getSettings().getSpawnerPrice(spawnedType);
spawners.put(spawnedType, multiplier);
break;
case CHEST:
case TRAPPED_CHEST:
if (plugin.getSettings().isDisableChestEvents()) {
return;
}
worthType = WorthType.CHEST;
Chest chest = (Chest) block.getState();
ChestWorth chestWorth = negate ? getWorthNegative(chest.getBlockInventory()) : getWorth(chest.getBlockInventory());
price = chestWorth.getTotalWorth();
materials.putAll(chestWorth.getMaterials());
spawners.putAll(chestWorth.getSpawners());
break;
default:
return;
}
// Add block price to the count.
plugin.getWorthManager().add(block.getChunk(), reason, worthType, price, materials, spawners);
}
示例5: onMineStuff
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR)
public void onMineStuff(BlockBreakEvent e) {
if (!(e.isCancelled()) && e.getPlayer().hasPermission("minegusta.donator")) {
Material block = e.getBlock().getType();
if (block.equals(Material.MOB_SPAWNER)) {
if (e.getPlayer().getItemInHand().containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) {
e.getPlayer().sendMessage(ChatColor.DARK_RED + "You cannot mine spawners with the fortune enchantment.");
e.setCancelled(true);
} else {
CreatureSpawner spawner = (CreatureSpawner) e.getBlock().getState();
String mobType = "Pig";
EntityType entity = spawner.getSpawnedType();
switch (entity) {
case PIG:
mobType = ChatColor.LIGHT_PURPLE + "Pig";
break;
case SKELETON:
mobType = ChatColor.WHITE + "Skeleton";
break;
case SPIDER:
mobType = ChatColor.BLACK + "Spider";
break;
case ZOMBIE:
mobType = ChatColor.DARK_GREEN + "Zombie";
break;
case CAVE_SPIDER:
mobType = ChatColor.DARK_PURPLE + "Cave Spider";
break;
case BLAZE:
mobType = ChatColor.GOLD + "Blaze";
break;
case SILVERFISH:
mobType = ChatColor.GRAY + "SilverFish";
break;
default:
mobType = ChatColor.LIGHT_PURPLE + "Pig";
break;
}
ItemStack mobSpawner = new ItemStack(Material.MOB_SPAWNER, 1);
ArrayList<String> spawnerType = Lists.newArrayList();
spawnerType.add(mobType + " Spawner");
ItemMeta meta = mobSpawner.getItemMeta();
meta.setLore(spawnerType);
mobSpawner.setItemMeta(meta);
e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), mobSpawner);
e.setExpToDrop(0);
}
}
}
}
示例6: Spawner
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
public Spawner(Block block, BlockFace face) {
super(false);
CreatureSpawner originalSpawner = (CreatureSpawner) block.getState();
EntityType originalEntityType = originalSpawner.getSpawnedType();
int originalEntityDelay = originalSpawner.getDelay();
Location blockLocation = block.getLocation();
int blockX = blockLocation.getBlockX();
int blockY = blockLocation.getBlockY();
int blockZ = blockLocation.getBlockZ();
Block newSpawn = block.getWorld().getBlockAt(blockLocation);
switch (face) {
case NORTH:
newSpawn = block.getWorld().getBlockAt(blockX, blockY, blockZ + 1);
break;
case EAST:
newSpawn = block.getWorld().getBlockAt(blockX - 1, blockY, blockZ);
break;
case SOUTH:
newSpawn = block.getWorld().getBlockAt(blockX, blockY, blockZ - 1);
break;
case WEST:
newSpawn = block.getWorld().getBlockAt(blockX + 1, blockY, blockZ);
break;
case UP:
newSpawn = block.getWorld().getBlockAt(blockX, blockY - 1, blockZ);
break;
case DOWN:
newSpawn = block.getWorld().getBlockAt(blockX, blockY + 1, blockZ);
break;
}
if (newSpawn.getType().equals(Material.AIR)) {
block.setType(Material.AIR);
newSpawn.setType(Material.MOB_SPAWNER);
BlockState blockState = newSpawn.getState();
((CreatureSpawner) blockState).setSpawnedType(originalEntityType);
((CreatureSpawner) blockState).setDelay(originalEntityDelay);
blockState.update(true);
}
}