本文整理匯總了Java中org.bukkit.block.CreatureSpawner類的典型用法代碼示例。如果您正苦於以下問題:Java CreatureSpawner類的具體用法?Java CreatureSpawner怎麽用?Java CreatureSpawner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CreatureSpawner類屬於org.bukkit.block包,在下文中一共展示了CreatureSpawner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: placeBlock
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@Override
public boolean placeBlock(ArmorStand e, Player p) {
getTexture().placeBlock(e.getLocation().add(0, -0.40, -0.375));
//p.sendMessage(e.getLocation().getBlock().getLocation().toString());
if (getMaterial().equals(Material.MOB_SPAWNER)) {
CreatureSpawner cs = (CreatureSpawner) e.getLocation().getBlock().getState();
cs.setSpawnedType(EntityType.DROPPED_ITEM);
cs.update();
}
setLe(e);
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SuperiorCraft.plugin, new Runnable() {
public void run() {
e.getLocation().getBlock().setType(Material.STONE_SLAB2);
e.getLocation().getBlock().setData((byte) 2);
e.getLocation().getBlock().getWorld().dropItemNaturally(e.getLocation(), new ItemStack(e.getLocation().add(0, -1, 0).getBlock().getType()));
e.getLocation().add(0, -1, 0).getBlock().setType(Material.GLOWSTONE);
}
}, (1 * 20));
return true;
}
示例2: autoClean
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
private void autoClean(Chunk chunk) {
if (chunk == null) {
return;
}
for (BlockState tiles : chunk.getTileEntities()) {
if (tiles instanceof CreatureSpawner) {
CreatureSpawner spawner = (CreatureSpawner) tiles;
// 非法類型檢測
if (cm.illegalSpawnerType.contains(spawner.getCreatureTypeName().toLowerCase())) {
switch (cm.illegalTypeSpawnerCleanMode) {
case 0:
spawner.getBlock().setType(Material.AIR);
break;
case 1:
spawner.setCreatureType(RND_ENTITYTYPE[(int) (Math.random() * RND_ENTITYTYPE.length)]);
break;
default:
break;
}
}
}
}
}
示例3: onBlockPlace
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlockPlaced();
ItemStack stack = event.getItemInHand();
Player player = event.getPlayer();
if (block.getState() instanceof CreatureSpawner && stack.hasItemMeta()) {
ItemMeta meta = stack.getItemMeta();
if (meta.hasLore() && meta.hasDisplayName()) {
CreatureSpawner spawner = (CreatureSpawner) block.getState();
List<String> lore = meta.getLore();
if (!lore.isEmpty()) {
String spawnerName = ChatColor.stripColor(lore.get(0).toUpperCase());
Optional<EntityType> entityTypeOptional = GuavaCompat.getIfPresent(EntityType.class, spawnerName);
if (entityTypeOptional.isPresent()) {
spawner.setSpawnedType(entityTypeOptional.get());
spawner.update(true, true);
player.sendMessage(ChatColor.AQUA + "Placed a " + ChatColor.BLUE + spawnerName + ChatColor.AQUA + " spawner.");
}
}
}
}
}
示例4: 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;
}
示例5: updateWorth
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateWorth(SpawnerMultiplierChangeEvent event) {
// Do nothing if this area should not be calculated.
Block block = event.getBlock();
String factionId = plugin.getFactionsHook().getFactionAt(block);
if (plugin.getSettings().getIgnoredFactionIds().contains(factionId)) {
return;
}
// Get the worth type and price of this event.
int difference = event.getNewMultiplier() - event.getOldMultiplier();
WorthType worthType = WorthType.SPAWNER;
Map<Material, Integer> materials = new HashMap<>();
Map<EntityType, Integer> spawners = new HashMap<>();
EntityType spawnType = ((CreatureSpawner) block.getState()).getSpawnedType();
double price = difference * plugin.getSettings().getSpawnerPrice(spawnType);
spawners.put(spawnType, difference);
RecalculateReason reason = difference > 0 ? RecalculateReason.PLACE : RecalculateReason.BREAK;
// Add block price to the count.
plugin.getWorthManager().add(block.getChunk(), reason, worthType, price, materials, spawners);
}
示例6: change
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode){
if (spawner != null) {
Number delay = (Number)delta[0];
Number delayNow = ((CreatureSpawner)spawner.getSingle(e).getState()).getDelay();
CreatureSpawner spawn = ((CreatureSpawner)spawner.getSingle(e).getState());
if (mode == ChangeMode.SET) {
spawn.setDelay(delay.intValue());
} else if (mode == ChangeMode.ADD) {
spawn.setDelay(delayNow.intValue() + delay.intValue());
} else if (mode == ChangeMode.REMOVE) {
spawn.setDelay(delayNow.intValue() - delay.intValue());
}
spawn.update();
}
}
示例7: placeWoolSpawner
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
private void placeWoolSpawner(Location loc, String colorName) {
Wool wool = new Wool(DyeColor.valueOf(colorName));
final Block block = loc.getBlock();
block.setType(Material.MOB_SPAWNER);
final BlockState genericBlockState = block.getState();
final CreatureSpawner cs = (CreatureSpawner) block.getState();
final ItemStack stack = wool.toItemStack(1);
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
cs.setSpawnedType(block.getWorld().dropItem(block.getLocation(), stack).getType());
genericBlockState.update();
}
});
}
示例8: placeBlock
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@Override
public boolean placeBlock(ArmorStand e, Player p) {
getTexture().placeBlock(e.getLocation().add(0, 0.125, -0.375));
e.getLocation().getBlock().setType(getMaterial());
if (getMaterial().equals(Material.MOB_SPAWNER)) {
CreatureSpawner cs = (CreatureSpawner) e.getLocation().getBlock().getState();
cs.setSpawnedType(EntityType.DROPPED_ITEM);
cs.update();
}
setLe(e);
return true;
}
示例9: onBlockBreak
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
if (player.getWorld().getEnvironment() == World.Environment.NETHER && event.getBlock().getState() instanceof CreatureSpawner
&& !player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You may not break spawners in the nether.");
}
}
示例10: onBlockPlace
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
if (player.getWorld().getEnvironment() == World.Environment.NETHER && event.getBlock().getState() instanceof CreatureSpawner
&& !player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You may not place spawners in the nether.");
}
}
示例11: getStackSize
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@Override
public int getStackSize(CreatureSpawner spawner) {
if (api == null) {
return 1;
}
return api.getSpawnerMultiplier(spawner.getLocation());
}
示例12: updateWorth
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void updateWorth(SpawnerChangeEvent event) {
CreatureSpawner spawner = (CreatureSpawner) event.getSpawner().getState();
int oldMultiplier = event.getOldMulti();
int newMultiplier = event.getCurrentMulti();
SpawnerMultiplierChangeEvent event1 = new SpawnerMultiplierChangeEvent(spawner, oldMultiplier, newMultiplier);
if (plugin.getServer().isPrimaryThread()) {
plugin.getServer().getPluginManager().callEvent(event1);
return;
}
plugin.getServer().getScheduler().runTask(plugin, () ->
plugin.getServer().getPluginManager().callEvent(event1));
}
示例13: execute
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@Override
protected void execute(Event e) {
if (spawner != null) {
int delay = ((CreatureSpawner)spawner.getSingle(e)).getDelay();
CreatureSpawner state = (CreatureSpawner)spawner.getSingle(e).getState();
state.setDelay(0);
state.update();
state.setDelay(delay);
state.update();
}
}
示例14: get
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
@Nullable
protected String[] get(Event e) {
if (spawner != null) {
return new String[]{((CreatureSpawner)spawner.getSingle(e).getState()).getCreatureTypeName()};
}
return null;
}
示例15: change
import org.bukkit.block.CreatureSpawner; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public void change(Event e, Object[] delta, Changer.ChangeMode mode){
if (spawner != null) {
CreatureSpawner spawn = ((CreatureSpawner)spawner.getSingle(e).getState());
if (mode == ChangeMode.SET) {
spawn.setCreatureTypeByName((String)delta[0]);
}
spawn.update();
}
}