本文整理匯總了Java中org.bukkit.block.CreatureSpawner.setSpawnedType方法的典型用法代碼示例。如果您正苦於以下問題:Java CreatureSpawner.setSpawnedType方法的具體用法?Java CreatureSpawner.setSpawnedType怎麽用?Java CreatureSpawner.setSpawnedType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.block.CreatureSpawner
的用法示例。
在下文中一共展示了CreatureSpawner.setSpawnedType方法的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: 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.");
}
}
}
}
}
示例3: 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;
}
示例4: setSpawner
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
private void setSpawner(Block b, Random random) {
CreatureSpawner spawner = (CreatureSpawner) b.getState();
TreeMap<Integer,EntityType> spawns = WorldStyles.get(b.getWorld().getEnvironment()).getSpawns();
int randKey = random.nextInt(spawns.lastKey());
//Bukkit.getLogger().info("DEBUG: spawner rand key = " + randKey + " out of " + spawns.lastKey());
EntityType type = spawns.ceilingEntry(randKey).getValue();
//Bukkit.getLogger().info("DEBUG: spawner type = " + type);
spawner.setDelay(120);
spawner.setSpawnedType(type);
spawner.update(true);
}
示例5: onSpawnerBlockPlace
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
/**
* Sets spawners to their type
* @param e
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSpawnerBlockPlace(final BlockPlaceEvent e) {
if (DEBUG)
plugin.getLogger().info("DEBUG: block place");
if (inWorld(e.getPlayer()) && Util.playerIsHolding(e.getPlayer(), Material.MOB_SPAWNER)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: in world");
// Get item in hand
for (ItemStack item : Util.getPlayerInHandItems(e.getPlayer())) {
if (item.getType().equals(Material.MOB_SPAWNER) && item.hasItemMeta() && item.getItemMeta().hasLore()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: spawner in hand with lore");
List<String> lore = item.getItemMeta().getLore();
if (!lore.isEmpty()) {
if (DEBUG)
plugin.getLogger().info("DEBUG: lore is not empty");
for (EntityType type : EntityType.values()) {
if (lore.get(0).equals(Util.prettifyText(type.name()))) {
// Found the spawner type
if (DEBUG)
plugin.getLogger().info("DEBUG: found type");
e.getBlock().setType(Material.MOB_SPAWNER);
CreatureSpawner cs = (CreatureSpawner)e.getBlock().getState();
cs.setSpawnedType(type);
}
}
// Spawner type not found - do anything : it may be another plugin's spawner
}
}
}
}
}
示例6: commandUse
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
public boolean commandUse(CommandSender sender, String[] args) {
Variables var = Necessities.getVar();
if (sender instanceof Player) {
Player p = (Player) sender;
User u = Necessities.getUM().getUser(p.getUniqueId());
Location l = u.getLookingAt();
if (l == null) {
p.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "Block out of range.");
return true;
}
if (l.getBlock().getState() instanceof CreatureSpawner) {
CreatureSpawner spawner = (CreatureSpawner) l.getBlock().getState();
if (args.length == 0) {
p.sendMessage(var.getMessages() + "Spawner type is " + spawner.getSpawnedType().toString().replaceAll("_", " ").toLowerCase() + '.');
return true;
}
EntityType spawnerType = getType(args[0]);
if (spawnerType == null) {
p.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "Invalid mob type.");
p.sendMessage(var.getMessages() + "Valid mob types: " + ChatColor.WHITE + validTypes());
return true;
}
spawner.setSpawnedType(spawnerType);
spawner.update();
p.sendMessage(var.getMessages() + "Spawner type set to " + var.getObj() + spawner.getSpawnedType().toString().replaceAll("_", " ").toLowerCase() + var.getMessages() + '.');
return true;
}
sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "That block is not a spawner.");
return true;
} else
sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You cannot change the type of spawner because you cannot look at the spawner.");
return true;
}
示例7: onCommand
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender.hasPermission("wayward.essentials.command.spawner")) {
if (args.length >= 1) {
if (sender instanceof Player) {
Player player = (Player) sender;
Block block = getTargetBlock(player);
if (block.getType() == Material.MOB_SPAWNER) {
CreatureSpawner spawner = (CreatureSpawner) block.getState();
try {
EntityType entityType = EntityType.valueOf(args[0].toUpperCase());
spawner.setSpawnedType(entityType);
sender.sendMessage(plugin.getPrefix() + ChatColor.GREEN + "Spawner type set.");
} catch (IllegalArgumentException exception) {
sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "That entity does not exist.");
}
} else {
sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "That's not a mob spawner.");
}
} else {
sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "You must be a player to use this command.");
}
} else {
sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "You must specify the mob type.");
}
} else {
sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "You do not have permission.");
}
return true;
}
示例8: handlePlayer
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
@Override
public boolean handlePlayer(TregminePlayer player, String[] args)
{
if (!player.getRank().canSetSpawners()) {
return true;
}
if (args.length != 1) {
player.sendMessage(RED + "Type /spawner <mobname> whilst pointing "
+ "at a spawner");
return false;
}
Block target = player.getDelegate().getTargetBlock((Set<Material>) null, 15);
if (!target.getType().equals(Material.MOB_SPAWNER)) {
player.sendMessage(RED + "Please point at a spawner.");
return false;
}
CreatureSpawner spawner = (CreatureSpawner) target.getState();
try {
spawner.setSpawnedType(EntityType.valueOf(args[0].toUpperCase()));
} catch (Exception error) {
player.sendMessage(RED
+ "An error occured. Did you specify a valid "
+ "mob type?");
}
return true;
}
示例9: onBlockPlace
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent e) {
Block block = e.getBlockPlaced();
ItemStack spawner = e.getItemInHand();
if (spawner.getType().equals(Material.MOB_SPAWNER) && !e.isCancelled()) {
if (spawner.getItemMeta().hasLore()) {
if (spawner.getItemMeta().getLore().toString().contains("Spawner")) {
CreatureSpawner placedSpawner = (CreatureSpawner) block.getState();
if (spawner.getItemMeta().getLore().toString().contains("Pig")) {
placedSpawner.setSpawnedType(EntityType.PIG);
} else if (spawner.getItemMeta().getLore().toString().contains("Skeleton")) {
placedSpawner.setSpawnedType(EntityType.SKELETON);
} else if (spawner.getItemMeta().getLore().toString().contains("Spider")) {
placedSpawner.setSpawnedType(EntityType.SPIDER);
} else if (spawner.getItemMeta().getLore().toString().contains("Zombie")) {
placedSpawner.setSpawnedType(EntityType.ZOMBIE);
} else if (spawner.getItemMeta().getLore().toString().contains("Cave Spider")) {
placedSpawner.setSpawnedType(EntityType.CAVE_SPIDER);
} else if (spawner.getItemMeta().getLore().toString().contains("Blaze")) {
placedSpawner.setSpawnedType(EntityType.BLAZE);
} else if (spawner.getItemMeta().getLore().toString().contains("SilverFish")) {
placedSpawner.setSpawnedType(EntityType.SILVERFISH);
}
placedSpawner.update();
}
}
}
}
示例10: paste
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
/**
* Paste this block at blockLoc
* @param nms
* @param blockLoc
*/
//@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) {
// Only paste air if it is below the sea level and in the overworld
Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock();
block.setBiome(biome);
block.getChunk().load();
nms.setBlockSuperFast(block, typeId, data, usePhysics);
if (signText != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
// Sign
Sign sign = (Sign) block.getState();
int index = 0;
for (String line : signText) {
sign.setLine(index++, line);
}
sign.update();
} else if (banner != null) {
banner.set(block);
} else if (spawnerBlockType != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
CreatureSpawner cs = (CreatureSpawner)block.getState();
cs.setSpawnedType(spawnerBlockType);
} else if (!chestContents.isEmpty()) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
// Check if this is a double chest
Chest chestBlock = (Chest) block.getState();
InventoryHolder iH = chestBlock.getInventory().getHolder();
if (iH instanceof DoubleChest) {
//Bukkit.getLogger().info("DEBUG: double chest");
DoubleChest doubleChest = (DoubleChest) iH;
for (ItemStack chestItem: chestContents.values()) {
doubleChest.getInventory().addItem(chestItem);
}
} else {
// Single chest
for (Entry<Byte, ItemStack> en : chestContents.entrySet()) {
chestBlock.getInventory().setItem(en.getKey(), en.getValue());
}
}
}
}
示例11: setSpawner
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
public void setSpawner(Block block, EntityType ent) {
BlockState blockState = block.getState();
CreatureSpawner spawner = ((CreatureSpawner) blockState);
spawner.setSpawnedType(ent);
blockState.update();
}
示例12: pasteNether
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
public static void pasteNether(File f, final Location loc, boolean log) {
try {
long start = System.currentTimeMillis();
if (log)
Bukkit.getLogger().info("Pasting " + f.getAbsolutePath() + "...");
if (!f.exists()) {
Bukkit.getLogger().info("Schematic doesn't exist, skipping.");
return;
}
NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(new FileInputStream(f)));
CompoundTag nbt = (CompoundTag) nbtStream.readNamedTag().getTag();
if (nbt == null)
return;
short width = nbt.getShort("Width");
short height = nbt.getShort("Height");
short length = nbt.getShort("Length");
loadChunks(loc.getWorld(), loc.getBlockX(), loc.getBlockZ(), width, length);
final byte[] blocks = nbt.getByteArray("Blocks");
final byte[] data = nbt.getByteArray("Data");
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
final int index = y * width * length + z * width + x;
final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
final int b = blocks[index] & 0xFF;
final Block block = l.getBlock();
final Material m = Material.getMaterial(b);
block.setType(m, false);
if (m == Material.MOB_SPAWNER) {
CreatureSpawner spawner = (CreatureSpawner) block.getState();
spawner.setSpawnedType(EntityType.BLAZE);
spawner.setDelay(1);
spawner.update();
} else {
block.setData(data[index]);
}
}
}
}
if (log)
Bukkit.getLogger().info("Pasted successfully in " + (System.currentTimeMillis() - start) + " milliseconds.");
} catch (Exception e) {
e.printStackTrace();
}
}
示例13: paste
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
/**
* Paste this block at blockLoc
* @param nms
* @param blockLoc
*/
//@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) {
// Only paste air if it is below the sea level and in the overworld
Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock();
block.setBiome(biome);
nms.setBlockSuperFast(block, typeId, data, usePhysics);
if (signText != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
// Sign
Sign sign = (Sign) block.getState();
int index = 0;
for (String line : signText) {
sign.setLine(index++, line);
}
sign.update(true, false);
} else if (banner != null) {
banner.set(block);
} else if (skull != null){
skull.set(block);
} else if (pot != null){
pot.set(nms, block);
} else if (spawnerBlockType != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
CreatureSpawner cs = (CreatureSpawner)block.getState();
cs.setSpawnedType(spawnerBlockType);
//Bukkit.getLogger().info("DEBUG: setting spawner");
cs.update(true, false);
} else if (!chestContents.isEmpty()) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
//Bukkit.getLogger().info("DEBUG: inventory holder "+ block.getType());
// Check if this is a double chest
InventoryHolder chestBlock = (InventoryHolder) block.getState();
//InventoryHolder iH = chestBlock.getInventory().getHolder();
if (chestBlock instanceof DoubleChest) {
//Bukkit.getLogger().info("DEBUG: double chest");
DoubleChest doubleChest = (DoubleChest) chestBlock;
for (ItemStack chestItem: chestContents.values()) {
doubleChest.getInventory().addItem(chestItem);
}
} else {
// Single chest
for (Entry<Byte, ItemStack> en : chestContents.entrySet()) {
//Bukkit.getLogger().info("DEBUG: " + en.getKey() + "," + en.getValue());
chestBlock.getInventory().setItem(en.getKey(), en.getValue());
}
}
}
}
示例14: execute
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public boolean execute(CommandSender sender, Command cmd, String[] args) {
if(cmd.getName().equalsIgnoreCase("spawner")) {
if(sender instanceof Player) {
if(sender.hasPermission(PermissionKey.CMD_SPAWNER.getPermission())) {
EntityType[] entity = EntityType.values();
if(args.length == 0) {
StringBuilder build = new StringBuilder();
for(int i = 0; i < entity.length; i++) {
if(entity[i].isAlive()) {
if(entity[i] == EntityType.WITHER) {
} else if(entity[i] == EntityType.PLAYER) {
} else {
build.append(entity[i].name() + ", ").toString();
}
}
}
sender.sendMessage(ChatColor.GOLD + ".oO___[Spawnmob]___Oo.");
sender.sendMessage(ChatColor.GRAY + build.toString().toLowerCase());
} else if(args.length == 1) {
Player p = (Player) sender;
if(args[0].equalsIgnoreCase("give")) {
sendMessage("added spawner in your inventory");
p.getInventory().addItem(new ItemStack(Material.MOB_SPAWNER));
} else {
try {
EntityType type = EntityType.valueOf(args[0].toUpperCase());
if(type.isAlive()) {
if(type == EntityType.PLAYER) {
sendMessage("player entities cannot used through Bukkit");
} else {
Block block = p.getTargetBlock((HashSet<Byte>)null, 50);
if(block.getType() == Material.MOB_SPAWNER) {
CreatureSpawner spawner = (CreatureSpawner) block.getState();
String old = spawner.getSpawnedType().name();
sendMessage("successfully changed spawner from " + old.toLowerCase() + " to " + type.name().toLowerCase());
spawner.setSpawnedType(type);
}
}
} else {
sendMessage("this is not a peacefull mob or a hostile mob");
}
} catch(IllegalArgumentException e) {
sendMessage("this mob does not exist!");
}
}
}
} else {
getWarning(WarningType.NO_PERMISSION);
}
} else {
getWarning(WarningType.PLAYER_ONLY);
}
}
return false;
}
示例15: execute
import org.bukkit.block.CreatureSpawner; //導入方法依賴的package包/類
public static boolean execute(CommandSender sender, Command cmd, String[] args) {
if(cmd.getName().equalsIgnoreCase("spawner")) {
if(sender instanceof Player) {
if(sender.hasPermission("xEssentials.command.spawner")) {
EntityType[] entity = EntityType.values();
if(args.length == 0) {
StringBuilder build = new StringBuilder();
for(int i = 0; i < entity.length; i++) {
if(entity[i].isAlive()) {
if(entity[i] == EntityType.WITHER) {
} else if(entity[i] == EntityType.PLAYER) {
} else {
build.append(entity[i].name() + ", ").toString();
}
}
}
sender.sendMessage(ChatColor.GOLD + ".oO___[Spawnmob]___Oo.");
sender.sendMessage(ChatColor.GRAY + build.toString().toLowerCase());
} else if(args.length == 1) {
Player p = (Player) sender;
if(args[0].equalsIgnoreCase("give")) {
sender.sendMessage(ChatColor.GREEN + "added spawner in your inventory");
p.getInventory().addItem(new ItemStack(Material.MOB_SPAWNER));
} else {
try {
EntityType type = EntityType.valueOf(args[0].toUpperCase());
if(type.isAlive()) {
if(type == EntityType.WITHER) {
sender.sendMessage(ChatColor.RED + "you are not allowed to make wither spawners");
} else if(type == EntityType.PLAYER) {
sender.sendMessage(ChatColor.RED + "player entities cannot used through Bukkit");
} else {
@SuppressWarnings("deprecation")
Block block = p.getTargetBlock(null, 50);
if(block.getType() == Material.MOB_SPAWNER) {
CreatureSpawner spawner = (CreatureSpawner) block.getState();
String old = spawner.getSpawnedType().name();
sender.sendMessage(ChatColor.GREEN + "successfully changed spawner from " + old.toLowerCase() + " to " + type.name().toLowerCase());
spawner.setSpawnedType(type);
}
}
} else {
sender.sendMessage(ChatColor.RED + "this is not a peacefull mob or a hostile mob");
}
} catch(IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + "this mob does not exist!");
}
}
}
} else {
playerPermission.getPermissionError(sender, cmd, args);
}
} else {
consolePermission.getConsoleMessage(sender);
}
}
return false;
}