Java Code Examples for org.bukkit.entity.EntityType#valueOf()
The following examples show how to use
org.bukkit.entity.EntityType#valueOf() .
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: GameCreator.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
private String changeStoreEntityType(Location loc, String type) { type = type.toUpperCase(); String location = loc.getBlockX() + ";" + loc.getBlockY() + ";" + loc.getBlockZ(); if (villagerstores.containsKey(location)) { EntityType t = null; try { t = EntityType.valueOf(type); if (!t.isAlive()) { t = null; } } catch (Exception e) { } if (t == null) { return i18n("admin_command_wrong_living_entity_type"); } villagerstores.get(location).setEntityType(t); return i18n("admin_command_store_living_entity_type_set").replace("%type%", t.toString()); } return i18n("admin_command_store_not_exists"); }
Example 2
Source File: GameCreator.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
private String changeStoreEntityType(Location loc, String type) { type = type.toUpperCase(); String location = loc.getBlockX() + ";" + loc.getBlockY() + ";" + loc.getBlockZ(); if (villagerstores.containsKey(location)) { EntityType t = null; try { t = EntityType.valueOf(type); if (!t.isAlive()) { t = null; } } catch (Exception e) { } if (t == null) { return i18n("admin_command_wrong_living_entity_type"); } villagerstores.get(location).setEntityType(t); return i18n("admin_command_store_living_entity_type_set").replace("%type%", t.toString()); } return i18n("admin_command_store_not_exists"); }
Example 3
Source File: ClearEvent.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
public ClearEvent(Instruction instruction) throws InstructionParseException { super(instruction, true); staticness = true; persistent = true; String[] entities = instruction.getArray(); types = new EntityType[entities.length]; for (int i = 0; i < types.length; i++) { try { types[i] = EntityType.valueOf(entities[i].toUpperCase()); } catch (IllegalArgumentException e) { throw new InstructionParseException("Entity type '" + entities[i] + "' does not exist", e); } } loc = instruction.getLocation(); range = instruction.getVarNum(); name = instruction.getOptional("name"); kill = instruction.hasArgument("kill"); marked = instruction.getOptional("marked"); if (marked != null) { marked = Utils.addPackage(instruction.getPackage(), marked); } }
Example 4
Source File: NMS_1_9_R1.java From MineableSpawners with MIT License | 6 votes |
@Override public EntityType getType(ItemStack itemStack) { net.minecraft.server.v1_9_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound nmsItemCompound = (nmsItem.hasTag()) ? nmsItem.getTag() : new NBTTagCompound(); if (nmsItemCompound == null) { return null; } String mob = nmsItemCompound.getString("ms_mob"); EntityType entity = null; try { entity = EntityType.valueOf(mob); } catch (Exception ignore) {} return entity; }
Example 5
Source File: NMS_1_9_R2.java From MineableSpawners with MIT License | 6 votes |
@Override public EntityType getType(ItemStack itemStack) { net.minecraft.server.v1_9_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound nmsItemCompound = (nmsItem.hasTag()) ? nmsItem.getTag() : new NBTTagCompound(); if (nmsItemCompound == null) { return null; } String mob = nmsItemCompound.getString("ms_mob"); EntityType entity = null; try { entity = EntityType.valueOf(mob); } catch (Exception ignore) {} return entity; }
Example 6
Source File: NMS_1_13_R1.java From MineableSpawners with MIT License | 6 votes |
@Override public EntityType getType(ItemStack itemStack) { net.minecraft.server.v1_13_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound nmsItemCompound = (nmsItem.hasTag()) ? nmsItem.getTag() : new NBTTagCompound(); if (nmsItemCompound == null) { return null; } String mob = nmsItemCompound.getString("ms_mob"); EntityType entity = null; try { entity = EntityType.valueOf(mob); } catch (Exception ignore) {} return entity; }
Example 7
Source File: NMS_1_11_R1.java From MineableSpawners with MIT License | 6 votes |
@Override public EntityType getType(ItemStack itemStack) { net.minecraft.server.v1_11_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack); NBTTagCompound nmsItemCompound = (nmsItem.hasTag()) ? nmsItem.getTag() : new NBTTagCompound(); if (nmsItemCompound == null) { return null; } String mob = nmsItemCompound.getString("ms_mob"); EntityType entity = null; try { entity = EntityType.valueOf(mob); } catch (Exception ignore) {} return entity; }
Example 8
Source File: WrappedEntityType.java From EchoPet with GNU General Public License v3.0 | 5 votes |
public EntityType get() { try { return EntityType.valueOf(this.entityTypeName); } catch (Exception exception) { return null; } }
Example 9
Source File: IslandBlock.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * Sets the spawner type if this block is a spawner * @param tileData */ public void setSpawnerType(Map<String, Tag> tileData) { //Bukkit.getLogger().info("DEBUG: " + tileData.toString()); String creatureType = ""; if (tileData.containsKey("EntityId")) { creatureType = ((StringTag) tileData.get("EntityId")).getValue().toUpperCase(); } else if (tileData.containsKey("SpawnData")) { // 1.9 format Map<String,Tag> spawnData = ((CompoundTag) tileData.get("SpawnData")).getValue(); //Bukkit.getLogger().info("DEBUG: " + spawnData.toString()); if (spawnData.containsKey("id")) { creatureType = ((StringTag) spawnData.get("id")).getValue().toUpperCase(); } } //Bukkit.getLogger().info("DEBUG: creature type = " + creatureType); // The mob type might be prefixed with "Minecraft:" if (creatureType.startsWith("MINECRAFT:")) { creatureType = creatureType.substring(10); } if (WEtoME.containsKey(creatureType)) { spawnerBlockType = WEtoME.get(creatureType); } else { try { spawnerBlockType = EntityType.valueOf(creatureType); } catch (Exception e) { Bukkit.getLogger().warning("Spawner setting of " + creatureType + " is unknown for this server. Skipping."); } } //Bukkit.getLogger().info("DEBUG: spawnerblock type = " + spawnerBlockType); }
Example 10
Source File: WrappedEntityType.java From SonarPet with GNU General Public License v3.0 | 5 votes |
public EntityType get() { try { return EntityType.valueOf(this.entityTypeName); } catch (Exception exception) { return null; } }
Example 11
Source File: SpawnEffect.java From Civs with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onUpkeep(RegionUpkeepEvent event) { Location location = event.getRegion().getLocation(); if (!event.getRegion().getEffects().containsKey(KEY) || !Util.isLocationWithinSightOfPlayer(location)) { return; } EntityType entityType; try { entityType = EntityType.valueOf(event.getRegion().getEffects().get(KEY)); } catch (Exception ex) { Civs.logger.severe("Wrong entity type " + event.getRegion().getEffects().get(KEY) + " for " + event.getRegion().getType()); return; } RegionType regionType = (RegionType) ItemManager.getInstance().getItemType(event.getRegion().getType()); // int entityCount = 0; //TODO fix this so that it detects the correct type of entity int radius = Math.max(regionType.getEffectRadius(), regionType.getBuildRadius()); // for (Entity e : location.getWorld().getNearbyEntities(location, // radius, radius, radius)) { // if (entityType.getEntityClass().isAssignableFrom(e.getClass())) { // entityCount++; // if (entityCount > 5) { // return; // } // } // } if (location.getWorld().getNearbyEntities(location, radius, radius, radius).size() > 5) { return; } Location spawnLocation = new Location(location.getWorld(), location.getX(), location.getY() + 1, location.getZ()); location.getWorld().spawnEntity(spawnLocation, entityType); }
Example 12
Source File: RepairedSpawner.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
/** * This method tries to obtain an {@link EntityType} from a given {@link ItemStack}. * The provided {@link ItemStack} must be a {@link RepairedSpawner} item. * * @param item * The {@link ItemStack} to extract the {@link EntityType} from * * @return An {@link Optional} describing the result */ public Optional<EntityType> getEntityType(ItemStack item) { for (String line : item.getItemMeta().getLore()) { if (ChatColor.stripColor(line).startsWith("Type: ") && !line.contains("<Type>")) { EntityType type = EntityType.valueOf(ChatColor.stripColor(line).replace("Type: ", "").replace(' ', '_').toUpperCase(Locale.ROOT)); return Optional.of(type); } } return Optional.empty(); }
Example 13
Source File: VehicleObjective.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
public VehicleObjective(Instruction instruction) throws InstructionParseException { super(instruction); template = ObjectiveData.class; String name = instruction.next(); if (name.equalsIgnoreCase("any")) { any = true; } else try { vehicle = EntityType.valueOf(name.toUpperCase()); } catch (IllegalArgumentException e) { throw new InstructionParseException("Entity type " + name + " does not exist.", e); } }
Example 14
Source File: SpawnMobs.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void process() { class SyncTask implements Runnable { @Override public void run() { /* Spawn in mobs */ EntityType type = EntityType.valueOf(getString("what")); /* Get amount. */ int amount = Integer.valueOf(getString("amount")); /* Pick a random town chunk and spawn mobs there. */ Random rand = new Random(); int index = rand.nextInt(getParentTown().getTownChunks().size()); TownChunk tc = (TownChunk)getParentTown().getTownChunks().toArray()[index]; World world = Bukkit.getServer().getWorld(tc.getChunkCoord().getWorldname()); for (int i = 0; i < amount; i++) { int x = rand.nextInt(16); int z = rand.nextInt(16); x += (tc.getChunkCoord().getX() * 16); z += (tc.getChunkCoord().getZ() * 16); int y = world.getHighestBlockAt(x, z).getY(); Location loc = new Location(world, x, y, z); Bukkit.getServer().getWorld(tc.getChunkCoord().getWorldname()).spawnEntity(loc, type); } sendMessage(amount+" "+type.toString()+" have spawned in the vincitiy of "+ (tc.getChunkCoord().getX()*16)+",64,"+(tc.getChunkCoord().getZ()*16)); } } TaskMaster.syncTask(new SyncTask()); }
Example 15
Source File: RecipeType.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private static void registerMobDrop(ItemStack[] recipe, ItemStack output) { String mob = ChatColor.stripColor(recipe[4].getItemMeta().getDisplayName()).toUpperCase(Locale.ROOT).replace(' ', '_'); EntityType entity = EntityType.valueOf(mob); Set<ItemStack> dropping = SlimefunPlugin.getRegistry().getMobDrops().getOrDefault(entity, new HashSet<>()); dropping.add(output); SlimefunPlugin.getRegistry().getMobDrops().put(entity, dropping); }
Example 16
Source File: MobFilterParser.java From CardinalPGM with MIT License | 4 votes |
public MobFilterParser(final Element element) { super(element); this.mobType = EntityType.valueOf(element.getText().toUpperCase().replace(" ", "_")); }
Example 17
Source File: SentinelVersionCompat.java From Sentinel with MIT License | 4 votes |
static EntityType[] v1_8_monsters() { return new EntityType[]{EntityType.GUARDIAN, EntityType.CREEPER, EntityType.SKELETON, EntityType.ZOMBIE, EntityType.MAGMA_CUBE, EntityType.valueOf("PIG_ZOMBIE"), EntityType.SILVERFISH, EntityType.BAT, EntityType.BLAZE, EntityType.GHAST, EntityType.GIANT, EntityType.SLIME, EntityType.SPIDER, EntityType.CAVE_SPIDER, EntityType.ENDERMAN, EntityType.ENDERMITE, EntityType.WITHER, EntityType.ENDER_DRAGON, EntityType.WITCH}; }
Example 18
Source File: API.java From MineableSpawners with MIT License | 4 votes |
public ItemStack getSpawnerFromEntityName(String entityName) { EntityType entityType = EntityType.valueOf(entityName.toUpperCase().replace(" ","_")); return getSpawnerFromEntityType(entityType); }
Example 19
Source File: SetSubCommand.java From MineableSpawners with MIT License | 4 votes |
public void execute(MineableSpawners plugin, CommandSender sender, String type) { if (!(sender instanceof Player)) { System.out.println("[MineableSpawners] Only players can run this command!"); return; } Player player = (Player) sender; if (plugin.getConfigurationHandler().getList("set", "blacklisted-worlds").contains(player.getWorld().getName())) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "blacklisted")); return; } EntityType entityType; try { entityType = EntityType.valueOf(type.toUpperCase()); } catch (IllegalArgumentException e) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "invalid-type")); return; } if (plugin.getConfigurationHandler().getBoolean("set", "require-individual-permission")) { if (!player.hasPermission("mineablespawners.set." + type.toLowerCase())) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "no-individual-permission")); return; } } Block target = player.getTargetBlock(invisibleBlocks, 5); if (target.getState().getBlock().getType() != XMaterial.SPAWNER.parseMaterial()) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "not-looking-at")); return; } CreatureSpawner spawner = (CreatureSpawner) target.getState(); String from = Chat.uppercaseStartingLetters(spawner.getSpawnedType().name()); String to = Chat.uppercaseStartingLetters(type); if (from.equals(to)) { player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "already-type")); return; } spawner.setSpawnedType(entityType); spawner.update(); player.sendMessage(plugin.getConfigurationHandler().getMessage("set", "success").replace("%from%", from).replace("%to%", to)); }
Example 20
Source File: LimitsV2.java From Modern-LWC with MIT License | 4 votes |
/** * Find limits that are attached to the player via permissions (e.g * lwc.protect.*.10 = 10 of any protection) * * @param player * @return */ private List<Limit> findLimitsViaPermissions(Player player) { List<Limit> limits = new LinkedList<>(); for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) { String permission = pai.getPermission(); boolean value = pai.getValue(); if (!value || !permission.startsWith("lwc.protect.")) { continue; } String[] split = permission.substring("lwc.protect.".length()).split("."); if (split.length != 2) { continue; } String matchName = split[0]; String strCount = split[1]; int count; try { count = Integer.parseInt(strCount); } catch (NumberFormatException e) { continue; } if (matchName.equals("*")) { limits.add(new DefaultLimit(count)); } else if (matchName.equals("sign")) { limits.add(new SignLimit(count)); } else if (!matchName.equals("*") && !matchName.equals("sign")) { Material material = materialCache.get(matchName); if (material == null) { continue; } limits.add(new BlockLimit(material, count)); } else if (EntityType.valueOf(matchName.toUpperCase()) != null) { limits.add(new EntityLimit(EntityType.valueOf(matchName.toUpperCase()), count)); } } return limits; }