Java Code Examples for org.bukkit.entity.EntityType#fromName()
The following examples show how to use
org.bukkit.entity.EntityType#fromName() .
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: SpawnEgg1_12.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
/** * Converts from an item stack to a spawn egg 1.9 * * @param item - ItemStack, quantity is disregarded * @return SpawnEgg 1.9 */ public static SpawnEgg1_12 fromItemStack(ItemStack item) { if (item == null) { throw new IllegalArgumentException("item cannot be null"); } if (item.getType() != Material.MONSTER_EGG) { throw new IllegalArgumentException("item is not a monster egg"); } net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item); NBTTagCompound tagCompound = stack.getTag(); if (tagCompound != null) { @SuppressWarnings("deprecation") EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id")); if (type != null) { return new SpawnEgg1_12(type); } else { return null; } } else { return null; } }
Example 2
Source File: SpawnEgg1_11.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
/** * Converts from an item stack to a spawn egg 1.9 * * @param item - ItemStack, quantity is disregarded * @return SpawnEgg 1.9 */ public static SpawnEgg1_11 fromItemStack(ItemStack item) { if (item == null) { throw new IllegalArgumentException("item cannot be null"); } if (item.getType() != Material.MONSTER_EGG) { throw new IllegalArgumentException("item is not a monster egg"); } net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(item); NBTTagCompound tagCompound = stack.getTag(); if (tagCompound != null) { @SuppressWarnings("deprecation") EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id")); if (type != null) { return new SpawnEgg1_11(type); } else { return null; } } else { return null; } }
Example 3
Source File: SpawnEgg1_9.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
/** * Converts from an item stack to a spawn egg 1.9 * * @param item - ItemStack, quantity is disregarded * @return SpawnEgg 1.9 */ public static SpawnEgg1_9 fromItemStack(ItemStack item) { if (item == null) { throw new IllegalArgumentException("item cannot be null"); } if (item.getType() != Material.MONSTER_EGG) { throw new IllegalArgumentException("item is not a monster egg"); } net.minecraft.server.v1_9_R1.ItemStack stack = CraftItemStack.asNMSCopy(item); NBTTagCompound tagCompound = stack.getTag(); if (tagCompound != null) { @SuppressWarnings("deprecation") EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id")); if (type != null) { return new SpawnEgg1_9(type); } else { return null; } } else { return null; } }
Example 4
Source File: ChallengeFactory.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
private static List<EntityMatch> createEntities(List<String> requiredEntities) { List<EntityMatch> entities = new ArrayList<>(); for (String entityString : requiredEntities) { Matcher m = ENTITY_PATTERN.matcher(entityString); if (m.matches()) { String type = m.group("type"); String meta = m.group("meta"); String countStr = m.group("count"); int count = countStr != null ? Integer.parseInt(countStr, 10) : 1; EntityType entityType = EntityType.fromName(type); Map<String, Object> map = meta != null ? MetaUtil.createMap(meta.substring(1)) : new HashMap<String, Object>(); // skip the leading ':' if (entityType != null && map != null) { entities.add(new EntityMatch(entityType, map, count)); } else { throw new IllegalArgumentException("Malformed requiredEntities: " + entityString); } } else { throw new IllegalArgumentException("Malformed requiredEntities: " + entityString); } } return entities; }
Example 5
Source File: SpawnEgg1_9.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
/** * Converts from an item stack to a spawn egg 1.9 * * @param item - ItemStack, quantity is disregarded * @return SpawnEgg 1.9 */ public static SpawnEgg1_9 fromItemStack(ItemStack item) { if (item == null) { throw new IllegalArgumentException("item cannot be null"); } if (item.getType() != Material.MONSTER_EGG) { throw new IllegalArgumentException("item is not a monster egg"); } net.minecraft.server.v1_9_R2.ItemStack stack = CraftItemStack.asNMSCopy(item); NBTTagCompound tagCompound = stack.getTag(); if (tagCompound != null) { @SuppressWarnings("deprecation") EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id")); if (type != null) { return new SpawnEgg1_9(type); } else { return null; } } else { return null; } }
Example 6
Source File: SpawnEgg1_10.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
/** * Converts from an item stack to a spawn egg 1.9 * * @param item - ItemStack, quantity is disregarded * @return SpawnEgg 1.9 */ public static SpawnEgg1_10 fromItemStack(ItemStack item) { if (item == null) { throw new IllegalArgumentException("item cannot be null"); } if (item.getType() != Material.MONSTER_EGG) { throw new IllegalArgumentException("item is not a monster egg"); } net.minecraft.server.v1_10_R1.ItemStack stack = CraftItemStack.asNMSCopy(item); NBTTagCompound tagCompound = stack.getTag(); if (tagCompound != null) { @SuppressWarnings("deprecation") EntityType type = EntityType.fromName(tagCompound.getCompound("EntityTag").getString("id")); if (type != null) { return new SpawnEgg1_10(type); } else { return null; } } else { return null; } }
Example 7
Source File: KillHandler.java From EliteMobs with GNU General Public License v3.0 | 6 votes |
private static void killEntityType(CommandSender commandSender, String[] args) { if (CommandHandler.permCheck(CommandHandler.KILLALL_SPECIFICENTITY, commandSender)) { try { EntityType entityType = EntityType.fromName(args[1].toUpperCase()); int counter = 0; for (World world : EliteMobs.validWorldList) for (LivingEntity livingEntity : world.getLivingEntities()) if (livingEntity.getType().equals(entityType) && (EntityTracker.isEliteMob(livingEntity) || EntityTracker.isSuperMob(livingEntity))) { livingEntity.remove(); counter++; } commandSender.sendMessage("Killed " + counter + " Elite " + args[1] + "."); } catch (Exception e) { commandSender.sendMessage("[EliteMobs] Entity type is not valid!"); } } }
Example 8
Source File: CraftAmbient.java From Thermos with GNU General Public License v3.0 | 5 votes |
public EntityType getType() { // Cauldron start EntityType type = EntityType.fromName(this.entityName); if (type != null) return type; else return EntityType.UNKNOWN; // Cauldron end }
Example 9
Source File: HoverAction.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
public EntityInfo getEntity() { validateAction(type, Type.SHOW_ENTITY); try { NBTCompound compound = MojangsonParser.parse(value); NBTString etype = compound.getTagOfType("type", NBTType.STRING); NBTString euuid = compound.getTagOfType("id", NBTType.STRING); return new EntityInfo( etype != null ? EntityType.fromName(etype.getValue()) : null, euuid != null ? UUID.fromString(euuid.getValue()) : null, NBTString.getValueOrNull(compound.getTagOfType("name", NBTType.STRING)) ); } catch (IOException e) { throw new RuntimeException("Unable to parse value", e); } }
Example 10
Source File: CraftLivingEntity.java From Thermos with GNU General Public License v3.0 | 5 votes |
public EntityType getType() { // Cauldron start EntityType type = EntityType.fromName(this.entityName); if (type != null) return type; else return EntityType.UNKNOWN; // Cauldron end }
Example 11
Source File: CraftCustomEntity.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public EntityType getType() { EntityType type = EntityType.fromName(this.entityName); if (type != null) { return type; } else { return EntityType.UNKNOWN; } }
Example 12
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 13
Source File: Craftbukkit18R1.java From factions-top with MIT License | 5 votes |
@Override public EntityType getSpawnerType(ItemStack item) { CraftItemStack craftStack = CraftItemStack.asCraftCopy(item); NBTTagCompound tag = CraftItemStack.asNMSCopy(craftStack).getTag(); if (tag == null || !tag.hasKey("BlockEntityTag")) { throw new IllegalArgumentException(); } return EntityType.fromName(tag.getCompound("BlockEntityTag").getString("EntityId")); }
Example 14
Source File: CraftMetaSpawnEgg.java From Kettle with GNU General Public License v3.0 | 5 votes |
CraftMetaSpawnEgg(NBTTagCompound tag) { super(tag); if (tag.hasKey(ENTITY_TAG.NBT)) { entityTag = tag.getCompoundTag(ENTITY_TAG.NBT); if (entityTag.hasKey(ENTITY_ID.NBT)) { this.spawnedType = EntityType.fromName(new ResourceLocation(entityTag.getString(ENTITY_ID.NBT)).getResourcePath()); } } }
Example 15
Source File: CraftCreatureSpawner.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public void setCreatureTypeByName(String creatureType) { // Verify input EntityType type = EntityType.fromName(creatureType); if (type == null) { return; } setSpawnedType(type); }
Example 16
Source File: SpawnEggMeta.java From ShopChest with MIT License | 4 votes |
/** * @param plugin An instance of the {@link ShopChest} plugin * @param stack {@link ItemStack} (Spawn Egg) of which the Entity should be gotten * @return The {@link EntityType} the Spawn Egg will spawn or <b>null</b> if <i>nbtEntityID</i> is null */ public static EntityType getEntityTypeFromItemStack(ShopChest plugin, ItemStack stack) { if (Utils.getMajorVersion() == 8) { EntityType type = null; for (EntityType entityType : EntityType.values()) { if (entityType.getTypeId() == stack.getDurability()) { type = entityType; break; } } return type; } String nbtEntityID = getNBTEntityID(plugin, stack); if (nbtEntityID == null) return null; if (Utils.getMajorVersion() >= 11) { if (nbtEntityID.contains(":")) nbtEntityID = nbtEntityID.split(":")[1]; return EntityType.fromName(nbtEntityID); } switch (nbtEntityID) { case "PigZombie": return EntityType.valueOf("PIG_ZOMBIE"); case "CaveSpider": return EntityType.CAVE_SPIDER; case "LavaSlime": return EntityType.MAGMA_CUBE; case "MushroomCow": return EntityType.MUSHROOM_COW; case "EntityHorse": return EntityType.HORSE; case "PolarBear": return EntityType.POLAR_BEAR; case "Ozelot": return EntityType.OCELOT; default: return EntityType.valueOf(nbtEntityID.toUpperCase()); } }
Example 17
Source File: CraftStatistic.java From Thermos with GNU General Public License v3.0 | 4 votes |
public static EntityType getEntityTypeFromStatistic(net.minecraft.stats.StatBase statistic) { String statisticString = statistic.statId; return EntityType.fromName(statisticString.substring(statisticString.lastIndexOf(".") + 1)); }
Example 18
Source File: CraftCustomEntity.java From Thermos with GNU General Public License v3.0 | 4 votes |
public EntityType getType() { EntityType type = EntityType.fromName(this.entityName); if (type != null) return type; else return EntityType.UNKNOWN; }
Example 19
Source File: CraftStatistic.java From Kettle with GNU General Public License v3.0 | 4 votes |
public static EntityType getEntityTypeFromStatistic(StatBase statistic) { String statisticString = statistic.statId; return EntityType.fromName(statisticString.substring(statisticString.lastIndexOf(".") + 1)); }
Example 20
Source File: CraftCreatureSpawner.java From Kettle with GNU General Public License v3.0 | 4 votes |
@Override public EntityType getSpawnedType() { ResourceLocation key = this.getSnapshot().getSpawnerBaseLogic().getEntityId(); return (key == null) ? EntityType.PIG : EntityType.fromName(key.getResourcePath()); }