本文整理汇总了Java中org.bukkit.material.SpawnEgg类的典型用法代码示例。如果您正苦于以下问题:Java SpawnEgg类的具体用法?Java SpawnEgg怎么用?Java SpawnEgg使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SpawnEgg类属于org.bukkit.material包,在下文中一共展示了SpawnEgg类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSpawnEggEvent
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
@EventHandler
public void onSpawnEggEvent(PlayerInteractEvent event) {
Player player = event != null ? event.getPlayer() : null;
if (player == null || event.isCancelled() || !plugin.isSkyWorld(player.getWorld())) {
return; // Bail out, we don't care
}
if (hasPermission(player, "usb.mod.bypassprotection") || player.isOp()) {
return;
}
ItemStack item = event.getItem();
if (RIGHT_CLICKS.contains(event.getAction()) && item != null && item.getType() == Material.MONSTER_EGG && item.getData() instanceof SpawnEgg) {
if (!plugin.playerIsOnIsland(player)) {
event.setCancelled(true);
plugin.notifyPlayer(player, tr("\u00a7eYou can only use spawn-eggs on your own island."));
return;
}
SpawnEgg spawnEgg = (SpawnEgg) item.getData();
checkLimits(event, spawnEgg.getSpawnedType(), player.getLocation());
if (event.isCancelled()) {
plugin.notifyPlayer(player, tr("\u00a7cYou have reached your spawn-limit for your island."));
event.setUseItemInHand(Event.Result.DENY);
event.setUseInteractedBlock(Event.Result.DENY);
}
}
}
示例2: onPlayerInteract
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
if ((player.hasPermission("tse.use")) && ((event.getAction().equals(Action.RIGHT_CLICK_AIR)) || (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)))) {
if (event.getItem() == null)
return;
ItemStack item = event.getItem();
if ((!(item.getData() instanceof SpawnEgg)) || (item == null))
return;
SpawnEgg segg = (SpawnEgg) item.getData();
Egg egg = (Egg) event.getPlayer().launchProjectile(Egg.class);
this.eggs.put(egg, segg.getSpawnedType());
if (item.getAmount() > 1)
item.setAmount(item.getAmount() - 1);
else {
player.getInventory().remove(item);
}
event.setCancelled(true);
}
}
示例3: createSpawnEggData
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
default SpawnEggItemData createSpawnEggData(EntityType entityType, ItemMeta meta) {
if (Versioning.NMS_VERSION.getMajorVersion() >= 9) throw new UnsupportedOperationException("Can't use bukkit API on versions newer than 1.9");
Preconditions.checkNotNull(meta, "Null meta");
Preconditions.checkNotNull(entityType, "Null entity type");
return new SpawnEggItemData(new SpawnEgg(entityType).getData(), meta) {
@Override
@SuppressWarnings("depreciation") // Bukkit is okay on versions less than 1.9, and we've already checked above
public EntityType getSpawnedType() {
return ((SpawnEgg) getMaterialData()).getSpawnedType();
}
};
}
示例4: getSpawnEgg
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
public ItemStack getSpawnEgg(EntityType entityType, Integer amount) {
ItemStack egg = new ItemStack(Material.MONSTER_EGG, amount);
if (entityType != null) {
SpawnEgg spawnEgg = new SpawnEgg(entityType);
egg.setData(spawnEgg);
}
return egg;
}
示例5: getEntityType
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
/**
* Get the type of entity being spawned.
*/
public EntityType getEntityType() {
ItemMeta meta = _spawnEgg.getItemMeta();
if (meta instanceof SpawnEgg) {
return ((SpawnEgg) meta).getSpawnedType();
}
return EntityType.UNKNOWN;
}
示例6: onPlayerInteract
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
ItemStack itemStack = event.getItem();
if (itemStack != null && itemStack.getData() instanceof SpawnEgg) {
SpawnEgg data = (SpawnEgg) event.getItem().getData();
EntityType type = data.getSpawnedType();
MobPermission permission = plugin.getMobPermission(type);
if (permission == MobPermission.DISABLED) {
event.getPlayer().sendMessage(
plugin.getDescription().getName() + " prevented " + EntityHelper.getEntityName(type) + " to be spawned.");
event.setCancelled(true);
}
}
}
示例7: setChest_Concurrent
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
public BlockMeta setChest_Concurrent(int x,int y,int z)
{
ArrayList<Map<String,Object>> Inventory = new ArrayList<Map<String,Object>>();
Random random = new Random();
int maxsize = 27;
for(int i = 0; i < maxsize;i++)
{
Inventory.add(i,null);
}
for(int j = 0; j < try_count_takaramono; j++) {
for (int i = 0; i < gen_count_takaramono; i++) {
int invnumber = random.nextInt(maxsize);
ItemStack item;
if(Inventory.get(i) != null)
{
item = ItemStack.deserialize(Inventory.get(i));
}
else
{
item = null;
}
Material m;
if (item == null) {
if (random.nextFloat() < chance_takaramono_rare)
{
m = BonusItems_rare.get(random.nextInt(BonusItems_rare.size()));
}
else
{
m = BonusItems.get(random.nextInt(BonusItems.size()));
}
if(m.toString().matches("(SWORD|CHESTPLATE|HELMET|BOOTS|LEGGINGS|PICKAXE|BOW|BOOK)"))
{
item = new ItemStack(m);
for (int k = 0; k < random.nextInt(4); k++) {
try {
item.addEnchantment(Enchantments.get(random.nextInt(Enchantments.size())), random.nextInt(5));
} catch (IllegalArgumentException e)
{
}
}
}
else if(m == Material.MONSTER_EGG)
{
item = new SpawnEgg(Monsters.get(random.nextInt(Monsters.size()))).toItemStack();
}
else
{
item = new ItemStack(m);
}
int amount = 1 + random.nextInt(3);
if(amount > item.getMaxStackSize())
{
amount = 1;
}
item.setAmount(amount);
}
Inventory.add(invnumber,item.serialize());
}
}
return new BlockMeta(Material.CHEST,x,y,z,Inventory);
}
示例8: setChest_Concurrent
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
public BlockMeta setChest_Concurrent(int x,int y,int z)
{
ArrayList<Map<String,Object>> Inventory = new ArrayList<Map<String,Object>>();
Random random = new Random();
int maxsize = 27;
for(int i = 0; i < maxsize;i++)
{
Inventory.add(i,null);
}
for(int j = 0; j < try_count_takaramono; j++) {
for (int i = 0; i < gen_count_takaramono; i++) {
int invnumber = random.nextInt(maxsize);
ItemStack item;
if(Inventory.get(i) != null)
{
item = ItemStack.deserialize(Inventory.get(i));
}
else
{
item = null;
}
Material m;
if (item == null) {
if (random.nextFloat() < chance_takaramono_rare)
{
m = BonusItems_rare.get(random.nextInt(BonusItems_rare.size()));
}
else
{
m = BonusItems.get(random.nextInt(BonusItems.size()));
}
if(m.toString().matches("(SWORD|CHESTPLATE|HELMET|BOOTS|LEGGINGS|PICKAXE|BOW|BOOK)"))
{
item = new ItemStack(m);
for (int k = 0; k < random.nextInt(4); k++) {
try {
item.addEnchantment(Enchantments.get(random.nextInt(Enchantments.size())), random.nextInt(5));
} catch (IllegalArgumentException e)
{
}
}
}
else if(m == Material.MONSTER_EGG)
{
item = new SpawnEgg(Monsters.get(random.nextInt(Monsters.size()))).toItemStack();
}
else if(m == Material.SAND || m == Material.COBBLESTONE)
{
item = new ItemStack(m,64);
Inventory.add(invnumber,item.serialize());
continue;
}
else
{
item = new ItemStack(m);
}
int amount = 1 + random.nextInt(3);
if(amount > item.getMaxStackSize())
{
amount = 1;
}
item.setAmount(amount);
}
Inventory.add(invnumber,item.serialize());
}
}
return new BlockMeta(Material.CHEST,x,y,z,Inventory);
}
示例9: createSpawnEggData
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
@Override
public SpawnEggItemData createSpawnEggData(EntityType entityType, ItemMeta meta) {
checkNotNull(entityType, "Null entity type");
checkNotNull(meta, "Null item meta");
return new NMSSpawnEggItemData(new SpawnEgg(entityType).getData(), meta, entityType); // Pretend we use metadata to make the code happy
}
示例10: getEntityTypeFromItemStack
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
public EntityType getEntityTypeFromItemStack(ItemStack itemStack) {
SpawnEgg spawnEgg = (SpawnEgg) itemStack.getData();
return spawnEgg.getSpawnedType();
}
示例11: getSpawnEgg
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
@Override
public ItemStack getSpawnEgg(EntityType type, int amount) {
SpawnEgg egg = new SpawnEgg(type);
return egg.toItemStack(amount);
}
示例12: SpawnEgg
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
public SpawnEgg() {
}
示例13: clone
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
public SpawnEgg clone() {
return null;
}
示例14: getMaterialData
import org.bukkit.material.SpawnEgg; //导入依赖的package包/类
public static MaterialData getMaterialData(String identifier) {
final String[] split = identifier.replaceAll("\\s+", "_").split("\\W");
// TODO: Add additional material/name database like essentials/worldedit have
Material material = matchMaterial(split[0]);
if (material == null) {
// try worldedit
material = getWEMaterial(split[0]);
if (material == null) return null;
}
if (split.length == 1) {
return new MaterialData(material);
}
try {
final byte rawData = Byte.parseByte(split[1]);
return new MaterialData(material, rawData);
} catch (NumberFormatException e) {
// ignore
}
switch (material) {
case LEAVES:
return getMaterialData(material, Leaves::new, TreeSpecies.class, split[1]);
case COAL:
return getMaterialData(material, Coal::new, CoalType.class, split[1]);
case LONG_GRASS:
return getMaterialData(material, LongGrass::new, GrassSpecies.class, split[1]);
case SANDSTONE:
return getMaterialData(material, Sandstone::new, SandstoneType.class, split[1]);
case MONSTER_EGG:
return getMaterialData(material, SpawnEgg::new, EntityType.class, split[1]);
case LOG:
return getMaterialData(material, Tree::new, TreeSpecies.class, split[1]);
case WOOD_STEP:
return getMaterialData(material, WoodenStep::new, TreeSpecies.class, split[1]);
case WOOL:
return getMaterialData(material, Wool::new, DyeColor.class, split[1]);
// TODO: Add Dye here when Spigot finally accepts my PR to match other MaterialData types
default:
// Couldn't find additional data for this material
return new MaterialData(material);
}
}