org.bukkit.material.SpawnEgg Java Examples
The following examples show how to use
org.bukkit.material.SpawnEgg.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpawnEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onSpawnEggEvent(PlayerInteractEvent event) { Player player = event != null ? event.getPlayer() : null; if (player == null || event.isCancelled() || !plugin.getWorldManager().isSkyWorld(player.getWorld())) { return; // Bail out, we don't care } if (player.hasPermission("usb.mod.bypassprotection") || player.isOp()) { return; } ItemStack item = event.getItem(); if (RIGHT_CLICKS.contains(event.getAction()) && item != null && isSpawnEgg(item)) { 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); } } }
Example #2
Source File: INMS.java From SonarPet with GNU General Public License v3.0 | 5 votes |
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(); } }; }
Example #3
Source File: SpawnEggNBT.java From CratesPlus with GNU General Public License v3.0 | 5 votes |
public static SpawnEggNBT fromItemStack(ItemStack itemStack) { if (itemStack == null || itemStack.getType() != LegacyMaterial.MONSTER_EGG.getMaterial()) return null; try { Class craftItemStack = ReflectionUtil.getCBClass("inventory.CraftItemStack"); Method asNMSCopyMethod = craftItemStack.getDeclaredMethod("asNMSCopy", ItemStack.class); Object nmsItemStack = asNMSCopyMethod.invoke(null, itemStack); Class nmsItemStackClass = ReflectionUtil.getNMSClass("ItemStack"); Object nbtTagCompound = nmsItemStackClass.getDeclaredMethod("getTag").invoke(nmsItemStack); Class nbtTagCompoundClass = ReflectionUtil.getNMSClass("NBTTagCompound"); if (nbtTagCompound != null) { Method getCompoundMethod = nbtTagCompoundClass.getDeclaredMethod("getCompound", String.class); Object entityTagCompount = getCompoundMethod.invoke(nbtTagCompound, "EntityTag"); Method getStringMethod = nbtTagCompoundClass.getDeclaredMethod("getString", String.class); String type = (String) getStringMethod.invoke(entityTagCompount, "id"); type = type.replaceFirst("minecraft:", ""); switch (type) { case "CAVESPIDER": type = "CAVE_SPIDER"; break; } EntityType entityType = EntityType.fromName(type); if (entityType == null || !entityType.isAlive()) return null; return new SpawnEggNBT(entityType); } else if (itemStack.getData() instanceof SpawnEgg) { return new SpawnEggNBT(((SpawnEgg) itemStack.getData()).getSpawnedType()); } } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } return null; }
Example #4
Source File: NMSImpl.java From SonarPet with GNU General Public License v3.0 | 4 votes |
@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 }
Example #5
Source File: NMSImpl.java From SonarPet with GNU General Public License v3.0 | 4 votes |
@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 }
Example #6
Source File: NMSImpl.java From SonarPet with GNU General Public License v3.0 | 4 votes |
@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 }
Example #7
Source File: NMSImpl.java From SonarPet with GNU General Public License v3.0 | 4 votes |
@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 }
Example #8
Source File: TNTSheep.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") public void run(Location startLocation) { ItemStack usedStack = null; if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) { usedStack = player.getInventory().getItemInHand(); if (((SpawnEgg) usedStack.getData()).getSpawnedType() != EntityType.SHEEP) { return; } usedStack.setAmount(usedStack.getAmount() - 1); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), usedStack); } else { if (player.getInventory().getItemInOffHand().getType() == this.getItemMaterial()) { usedStack = player.getInventory().getItemInOffHand(); usedStack.setAmount(usedStack.getAmount() - 1); player.getInventory().setItemInOffHand(usedStack); } else if (player.getInventory().getItemInMainHand().getType() == this.getItemMaterial()) { usedStack = player.getInventory().getItemInMainHand(); usedStack.setAmount(usedStack.getAmount() - 1); player.getInventory().setItemInMainHand(usedStack); } } player.updateInventory(); final Team playerTeam = this.game.getPlayerTeam(this.player); Player targetPlayer = this.findTargetPlayer(this.player); if (targetPlayer == null) { this.player.sendMessage(ChatWriter .pluginMessage( ChatColor.RED + BedwarsRel ._l(this.player, "ingame.specials.tntsheep.no-target-found"))); return; } BedwarsUseTNTSheepEvent event = new BedwarsUseTNTSheepEvent(this.game, this.player, targetPlayer, startLocation); BedwarsRel.getInstance().getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return; } final Player target = event.getTargetPlayer(); final Location start = event.getStartLocation(); // as task new BukkitRunnable() { @Override public void run() { final TNTSheep that = TNTSheep.this; try { // register entity Class<?> tntRegisterClass = BedwarsRel.getInstance() .getVersionRelatedClass("TNTSheepRegister"); ITNTSheepRegister register = (ITNTSheepRegister) tntRegisterClass.newInstance(); TNTSheep.this.sheep = register.spawnCreature(that, start, TNTSheep.this.player, target, playerTeam.getColor().getDyeColor()); new BukkitRunnable() { @Override public void run() { that.getGame().getRegion() .removeRemovingEntity(that.getSheep().getTNT().getVehicle()); that.getGame().getRegion().removeRemovingEntity(that.getSheep().getTNT()); } }.runTaskLater(BedwarsRel.getInstance(), (long) (( BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.fuse-time", 8.0) * 20) - 5)); new BukkitRunnable() { @Override public void run() { that.getSheep().getTNT().remove(); that.getSheep().remove(); that.getGame().removeSpecialItem(that); } }.runTaskLater(BedwarsRel.getInstance(), (long) (( BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.fuse-time", 8.0) * 20) + 13)); TNTSheep.this.game.addSpecialItem(that); } catch (Exception ex) { BedwarsRel.getInstance().getBugsnag().notify(ex); ex.printStackTrace(); } } }.runTask(BedwarsRel.getInstance()); }
Example #9
Source File: NMSImpl.java From SonarPet with GNU General Public License v3.0 | 4 votes |
@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 }
Example #10
Source File: Version_Util.java From CratesPlus with GNU General Public License v3.0 | 4 votes |
public EntityType getEntityTypeFromItemStack(ItemStack itemStack) { SpawnEgg spawnEgg = (SpawnEgg) itemStack.getData(); return spawnEgg.getSpawnedType(); }
Example #11
Source File: INMS.java From SonarPet with GNU General Public License v3.0 | 4 votes |
default SpawnEggItemData createSpawnEggData(byte rawData, ItemMeta meta) { EntityType entityType = new SpawnEgg(rawData).getSpawnedType(); if (entityType == null) entityType = SpawnEggItemData.DEFAULT_TYPE; return createSpawnEggData(entityType, meta); // Convert raw data to entity type }
Example #12
Source File: NMSHandler.java From askyblock with GNU General Public License v2.0 | 4 votes |
@Override public ItemStack getSpawnEgg(EntityType type, int amount) { SpawnEgg egg = new SpawnEgg(type); return egg.toItemStack(amount); }
Example #13
Source File: NMSHandler.java From askyblock with GNU General Public License v2.0 | 4 votes |
@Override public ItemStack getSpawnEgg(EntityType type, int amount) { SpawnEgg egg = new SpawnEgg(type); return egg.toItemStack(amount); }
Example #14
Source File: NMSHandler.java From askyblock with GNU General Public License v2.0 | 4 votes |
@Override public ItemStack getSpawnEgg(EntityType type, int amount) { SpawnEgg egg = new SpawnEgg(type); return egg.toItemStack(amount); }
Example #15
Source File: NMSHandler.java From askyblock with GNU General Public License v2.0 | 4 votes |
@Override public ItemStack getSpawnEgg(EntityType type, int amount) { SpawnEgg egg = new SpawnEgg(type); return egg.toItemStack(amount); }
Example #16
Source File: NMSHandler.java From askyblock with GNU General Public License v2.0 | 4 votes |
@Override public ItemStack getSpawnEgg(EntityType type, int amount) { SpawnEgg egg = new SpawnEgg(type); return egg.toItemStack(amount); }
Example #17
Source File: NMSHandler.java From askyblock with GNU General Public License v2.0 | 4 votes |
@Override public ItemStack getSpawnEgg(EntityType type, int amount) { SpawnEgg egg = new SpawnEgg(type); return egg.toItemStack(amount); }