@Override public void prepare(CastContext context, ConfigurationSection parameters) { track = parameters.getBoolean("track", true); loot = parameters.getBoolean("loot", false); force = parameters.getBoolean("force", false); setTarget = parameters.getBoolean("set_target", false); speed = parameters.getDouble("speed", 0); direction = ConfigurationUtils.getVector(parameters, "direction"); dyOffset = parameters.getDouble("dy_offset", 0); if (parameters.contains("type")) { String mobType = parameters.getString("type"); entityData = context.getController().getMob(mobType); if (entityData == null) { entityData = new com.elmakers.mine.bukkit.entity.EntityData(context.getController(), parameters); } } if (parameters.contains("reason")) { String reasonText = parameters.getString("reason").toUpperCase(); try { spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText); } catch (Exception ex) { spawnReason = CreatureSpawnEvent.SpawnReason.EGG; } } }
@Override public void prepare(CastContext context, ConfigurationSection parameters) { super.prepare(context, parameters); targetEntityLocation = parameters.getBoolean("target_entity"); targetSelf = parameters.getBoolean("target_caster"); sourceAtTarget = parameters.getBoolean("source_at_target"); targetOffset = ConfigurationUtils.getVector(parameters, "target_offset"); sourceOffset = ConfigurationUtils.getVector(parameters, "source_offset"); randomTargetOffset = ConfigurationUtils.getVector(parameters, "random_target_offset"); randomSourceOffset = ConfigurationUtils.getVector(parameters, "random_source_offset"); sourceDirection = ConfigurationUtils.getVector(parameters, "source_direction"); targetDirection = ConfigurationUtils.getVector(parameters, "target_direction"); sourceDirectionOffset = ConfigurationUtils.getVector(parameters, "source_direction_offset"); targetDirectionOffset = ConfigurationUtils.getVector(parameters, "source_direction_offset"); persistTarget = parameters.getBoolean("persist_target", false); attachBlock = parameters.getBoolean("target_attachment", false); if (parameters.contains("target_direction_speed")) { targetDirectionSpeed = parameters.getDouble("target_direction_speed"); } else { targetDirectionSpeed = null; } if (parameters.contains("source_direction_speed")) { sourceDirectionSpeed = parameters.getDouble("source_direction_speed"); } else { sourceDirectionSpeed = null; } }
public static ItemStack loadItemStack(final ConfigurationSection config) { final ItemStack item = new MaterialData(config.getInt("id"), (byte) config.getInt("data")) .toItemStack(config.getInt("amount", 1)); if (config.contains("durability")) item.setDurability((short) config.getInt("durability")); if (config.contains("enchantments")) item.addEnchantments(loadEnchantments(config.getConfigurationSection("enchantments"))); return item; }
/** * Parse a ConfigurationSection representing a AlchemyPotion. Returns null if input cannot be * parsed. * * @param potion_section ConfigurationSection to be parsed. * @return Parsed AlchemyPotion. */ private AlchemyPotion loadPotion(ConfigurationSection potion_section) { try { short dataValue = Short.parseShort(potion_section.getName()); String name = potion_section.getString("Name"); if (name != null) { name = ChatColor.translateAlternateColorCodes('&', name); } List<String> lore = new ArrayList<String>(); if (potion_section.contains("Lore")) { for (String line : potion_section.getStringList("Lore")) { lore.add(ChatColor.translateAlternateColorCodes('&', line)); } } List<PotionEffect> effects = new ArrayList<PotionEffect>(); if (potion_section.contains("Effects")) { for (String effect : potion_section.getStringList("Effects")) { String[] parts = effect.split(" "); PotionEffectType type = parts.length > 0 ? PotionEffectType.getByName(parts[0]) : null; int amplifier = parts.length > 1 ? Integer.parseInt(parts[1]) : 0; int duration = parts.length > 2 ? Integer.parseInt(parts[2]) : 0; if (type != null) { effects.add(new PotionEffect(type, duration, amplifier)); } else { mcMMO .p .getLogger() .warning("Failed to parse effect for potion " + name + ": " + effect); } } } Map<ItemStack, Short> children = new HashMap<ItemStack, Short>(); if (potion_section.contains("Children")) { for (String child : potion_section.getConfigurationSection("Children").getKeys(false)) { ItemStack ingredient = loadIngredient(child); if (ingredient != null) { children.put( ingredient, Short.parseShort( potion_section.getConfigurationSection("Children").getString(child))); } else { mcMMO.p.getLogger().warning("Failed to parse child for potion " + name + ": " + child); } } } return new AlchemyPotion(dataValue, name, lore, effects, children); } catch (Exception e) { mcMMO.p.getLogger().warning("Failed to load Alchemy potion: " + potion_section.getName()); return null; } }
private static ArenaClass parseArenaClass(ConfigurationSection cs) { List<ItemStack> items = null; List<PotionEffect> effects = null; if (cs.contains("items")) { items = BAConfigSerializer.getItemList(cs, "items"); } if (cs.contains("enchants")) { effects = BAConfigSerializer.getEffectList(cs, "enchants"); } String prettyName = cs.getString("displayName", null); return new ArenaClass(cs.getName(), prettyName, items, effects); }
@Override public void initialize(Spell spell, ConfigurationSection parameters) { super.initialize(spell, parameters); if (parameters.contains("biomes")) { ConfigurationSection biomeConfig = ConfigurationUtils.getConfigurationSection(parameters, "biomes"); biomeMap = new HashMap<>(); Collection<String> biomeKeys = biomeConfig.getKeys(false); for (String biomeKey : biomeKeys) { try { Biome biome = Biome.valueOf(biomeKey.toUpperCase()); List<String> treeTypes = ConfigurationUtils.getStringList(biomeConfig, biomeKey); for (String typeKey : treeTypes) { try { TreeType treeType = TreeType.valueOf(typeKey.toUpperCase()); List<TreeType> biomeTypes = biomeMap.get(biome); if (biomeTypes == null) { biomeTypes = new ArrayList<>(); biomeMap.put(biome, biomeTypes); } biomeTypes.add(treeType); } catch (Exception treeEx) { Bukkit.getLogger().warning("Invalid tree type: " + typeKey); } } } catch (Exception biomeEx) { Bukkit.getLogger().warning("Invalid biome: " + biomeKey); } } } }
private boolean importIsland(uSkyBlock plugin, File file) { log.info("Importing " + file); FileConfiguration config = new YamlConfiguration(); readConfig(config, file); if (config.contains("party.leader") && !config.contains("party.leader.name")) { String leaderName = config.getString("party.leader"); ConfigurationSection leaderSection = config.createSection("party.leader"); leaderSection.set("name", leaderName); leaderSection.set("uuid", UUIDUtil.asString(getUUID(leaderName))); } ConfigurationSection members = config.getConfigurationSection("party.members"); if (members != null) { for (String member : members.getKeys(false)) { ConfigurationSection section = members.getConfigurationSection(member); if (!section.contains("name")) { members.set(member, null); String uuid = UUIDUtil.asString(getUUID(member)); members.createSection(uuid, section.getValues(true)); members.set(uuid + ".name", member); } else { log.info("Skipping " + member + ", already has a name"); } } } try { config.save(file); return true; } catch (IOException e) { log.log(Level.SEVERE, "Failed to import " + file, e); return false; } }
public void save(MagickElement element, ConfigurationSection spellSection) throws Exception { for (Entry<String, SpellEntry> spellRegistry : spellRegistries.entrySet()) { String spellKey = spellRegistry.getKey(); SpellEntry spellEntry = spellRegistry.getValue(); if (!spellSection.contains(spellKey)) spellSection.createSection(spellKey); ConfigurationSection spell = spellSection.getConfigurationSection(spellKey); spellEntry.save(element, spell); } }
protected String getOnStartKey(ConfigurationSection section) throws InvalidConfigurationException { if (!section.contains("on start")) return null; if (!section.isString("on start")) throw new InvalidConfigurationException( "Expected a String at `on start` but found something else instead"); return section.getString("on start"); }
public void loadFrom(ConfigurationSection warConfigSection) { for (WarConfig config : WarConfig.values()) { if (warConfigSection.contains(config.toString())) { if (config.getConfigType().equals(Integer.class)) { this.put(config, warConfigSection.getInt(config.toString())); } else if (config.getConfigType().equals(Boolean.class)) { this.put(config, warConfigSection.getBoolean(config.toString())); } } } }
@Override public void prepare(CastContext context, ConfigurationSection parameters) { super.prepare(context, parameters); double damage = parameters.getDouble("damage", 1); entityDamage = parameters.getDouble("entity_damage", damage); playerDamage = parameters.getDouble("player_damage", damage); elementalDamage = parameters.getDouble("elemental_damage", damage); if (parameters.contains("percentage")) { percentage = parameters.getDouble("percentage"); } else { percentage = null; } magicDamage = parameters.getBoolean("magic_damage", true); magicEntityDamage = parameters.getBoolean("magic_entity_damage", true); if (parameters.contains("knockback_resistance")) { knockbackResistance = parameters.getDouble("knockback_resistance"); } else { knockbackResistance = null; } }
@Override public void setValues(ConfigurationSection sect) { if (sect == null || sect.getValues(false).size() == 0) { ConfigurationSection parent_sect = mod.getConfig().getValues(); if (parent_sect.contains("armore") && parent_sect.isConfigurationSection("armor")) { sect = parent_sect.createSection( this.getName(), parent_sect.getConfigurationSection("armor").getValues(true)); } } super.setValues(sect); }
@Override public void initialize(Spell spell, ConfigurationSection parameters) { super.initialize(spell, parameters); if (parameters.contains("entity_types")) { RandomUtils.populateStringProbabilityMap( entityTypeProbability, ConfigurationUtils.getConfigurationSection(parameters, "entity_types"), 0, 0, 0); } else { entityTypeProbability.add(new WeightedPair<String>(100.0f, "pig")); } }
public static void save(ConfigurationSection section, ConfigurationSection oldData) { p.createWorldSections(section); // loc is saved as a String in world sections with format x/y/z/pitch/yaw if (!wakeups.isEmpty()) { Iterator<Wakeup> iter = wakeups.iterator(); for (int id = 0; iter.hasNext(); id++) { Wakeup wakeup = iter.next(); if (!wakeup.active) { continue; } String worldName = wakeup.loc.getWorld().getName(); String prefix; if (worldName.startsWith("DXL_")) { prefix = p.getDxlName(worldName) + "." + id; } else { prefix = wakeup.loc.getWorld().getUID().toString() + "." + id; } section.set( prefix, wakeup.loc.getX() + "/" + wakeup.loc.getY() + "/" + wakeup.loc.getZ() + "/" + wakeup.loc.getPitch() + "/" + wakeup.loc.getYaw()); } } // copy Wakeups that are not loaded if (oldData != null) { for (String uuid : oldData.getKeys(false)) { if (!section.contains(uuid)) { section.set(uuid, oldData.get(uuid)); } } } }
@Override protected void load(ConfigurationSection config) { super.load(config); costs = new HashMap<ItemStack, Cost>(); ConfigurationSection costsSection = config.getConfigurationSection("costs"); if (costsSection != null) { for (String key : costsSection.getKeys(false)) { ConfigurationSection itemSection = costsSection.getConfigurationSection(key); ItemStack item = itemSection.getItemStack("item"); if (itemSection.contains("attributes")) { String attr = itemSection.getString("attributes"); if (attr != null && !attr.isEmpty()) { item = NMSManager.getProvider().loadItemAttributesFromString(item, attr); } } Cost cost = new Cost(); cost.amount = itemSection.getInt("amount"); cost.item1 = itemSection.getItemStack("item1"); cost.item2 = itemSection.getItemStack("item2"); costs.put(item, cost); } } }
@Override public void prepare(CastContext context, ConfigurationSection parameters) { super.prepare(context, parameters); doVelocity = parameters.getBoolean("apply_velocity", true); doTeleport = parameters.getBoolean("teleport", true); noTarget = parameters.getBoolean("no_target", true); orient = parameters.getBoolean("orient", true); velocityOffset = ConfigurationUtils.getVector(parameters, "velocity_offset"); locationOffset = ConfigurationUtils.getVector(parameters, "location_offset"); try { String entityTypeName = parameters.getString("type", ""); if (!entityTypeName.isEmpty()) { entityType = EntityType.valueOf(entityTypeName.toUpperCase()); } } catch (Exception ex) { entityType = null; } if (parameters.contains("spawn_reason")) { String reasonText = parameters.getString("spawn_reason").toUpperCase(); try { spawnReason = CreatureSpawnEvent.SpawnReason.valueOf(reasonText); } catch (Exception ex) { context.getMage().sendMessage("Unknown spawn reason: " + reasonText); } } customName = parameters.getString("name"); isBaby = parameters.getBoolean("baby", false); variantName = parameters.getString("variant"); if (variantName != null && variantName.isEmpty()) { variantName = null; } }
/** * Require the presence of the given field in the given configuration. * * @param node The node to check * @param field The field to check for * @throws SMSException if the field is not present in the configuration */ public static void mustHaveField(ConfigurationSection node, String field) throws SMSException { SMSValidate.isTrue( node.contains(field), "Field '" + field + "' missing - corrupted save file?"); }
public static void load(LogBlock logblock) throws DataFormatException, IOException { final ConfigurationSection config = logblock.getConfig(); final Map<String, Object> def = new HashMap<String, Object>(); def.put("version", logblock.getDescription().getVersion()); final List<String> worldNames = new ArrayList<String>(); for (final World world : getWorlds()) worldNames.add(world.getName()); if (worldNames.isEmpty()) { worldNames.add("world"); worldNames.add("world_nether"); worldNames.add("world_the_end"); } def.put("loggedWorlds", worldNames); def.put("mysql.host", "localhost"); def.put("mysql.port", 3306); def.put("mysql.database", "minecraft"); def.put("mysql.user", "username"); def.put("mysql.password", "pass"); def.put("consumer.delayBetweenRuns", 2); def.put("consumer.forceToProcessAtLeast", 200); def.put("consumer.timePerRun", 1000); def.put("consumer.fireCustomEvents", false); def.put("consumer.useBukkitScheduler", true); def.put("consumer.queueWarningSize", 1000); def.put("clearlog.dumpDeletedLog", false); def.put("clearlog.enableAutoClearLog", false); def.put( "clearlog.auto", Arrays.asList( "world \"world\" before 365 days all", "world \"world\" player lavaflow waterflow leavesdecay before 7 days all", "world world_nether before 365 days all", "world world_nether player lavaflow before 7 days all")); def.put("clearlog.autoClearLogDelay", "6h"); def.put("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false); def.put("logging.logKillsLevel", "PLAYERS"); def.put("logging.logPlayerInfo", false); def.put("logging.hiddenPlayers", new ArrayList<String>()); def.put("logging.hiddenBlocks", Arrays.asList(0)); def.put("logging.ignoredChat", Arrays.asList("/register", "/login")); def.put("rollback.dontRollback", Arrays.asList(10, 11, 46, 51)); def.put("rollback.replaceAnyway", Arrays.asList(8, 9, 10, 11, 51)); def.put("rollback.maxTime", "2 days"); def.put("rollback.maxArea", 50); def.put("lookup.defaultDist", 20); def.put("lookup.defaultTime", "30 minutes"); def.put("lookup.linesPerPage", 15); def.put("lookup.linesLimit", 1500); try { formatter = new SimpleDateFormat(config.getString("lookup.dateFormat", "MM-dd HH:mm:ss")); } catch (IllegalArgumentException e) { throw new DataFormatException( "Invalid specification for date format, please see http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html : " + e.getMessage()); } def.put("lookup.dateFormat", "MM-dd HH:mm:ss"); def.put("questioner.askRollbacks", true); def.put("questioner.askRedos", true); def.put("questioner.askClearLogs", true); def.put("questioner.askClearLogAfterRollback", true); def.put("questioner.askRollbackAfterBan", false); def.put("questioner.banPermission", "mcbans.ban.local"); def.put("tools.tool.aliases", Arrays.asList("t")); def.put("tools.tool.leftClickBehavior", "NONE"); def.put("tools.tool.rightClickBehavior", "TOOL"); def.put("tools.tool.defaultEnabled", true); def.put("tools.tool.item", 270); def.put("tools.tool.canDrop", true); def.put("tools.tool.params", "area 0 all sum none limit 15 desc silent"); def.put("tools.tool.mode", "LOOKUP"); def.put("tools.tool.permissionDefault", "OP"); def.put("tools.toolblock.aliases", Arrays.asList("tb")); def.put("tools.toolblock.leftClickBehavior", "TOOL"); def.put("tools.toolblock.rightClickBehavior", "BLOCK"); def.put("tools.toolblock.defaultEnabled", true); def.put("tools.toolblock.item", 7); def.put("tools.toolblock.canDrop", false); def.put("tools.toolblock.params", "area 0 all sum none limit 15 desc silent"); def.put("tools.toolblock.mode", "LOOKUP"); def.put("tools.toolblock.permissionDefault", "OP"); def.put("safety.id.check", true); for (final Entry<String, Object> e : def.entrySet()) if (!config.contains(e.getKey())) config.set(e.getKey(), e.getValue()); logblock.saveConfig(); url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database"); user = getStringIncludingInts(config, "mysql.user"); password = getStringIncludingInts(config, "mysql.password"); delayBetweenRuns = config.getInt("consumer.delayBetweenRuns", 2); forceToProcessAtLeast = config.getInt("consumer.forceToProcessAtLeast", 0); timePerRun = config.getInt("consumer.timePerRun", 1000); fireCustomEvents = config.getBoolean("consumer.fireCustomEvents", false); useBukkitScheduler = config.getBoolean("consumer.useBukkitScheduler", true); queueWarningSize = config.getInt("consumer.queueWarningSize", 1000); enableAutoClearLog = config.getBoolean("clearlog.enableAutoClearLog"); autoClearLog = config.getStringList("clearlog.auto"); dumpDeletedLog = config.getBoolean("clearlog.dumpDeletedLog", false); autoClearLogDelay = parseTimeSpec(config.getString("clearlog.autoClearLogDelay").split(" ")); logCreeperExplosionsAsPlayerWhoTriggeredThese = config.getBoolean("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false); logPlayerInfo = config.getBoolean("logging.logPlayerInfo", true); try { logKillsLevel = LogKillsLevel.valueOf(config.getString("logging.logKillsLevel").toUpperCase()); } catch (final IllegalArgumentException ex) { throw new DataFormatException( "lookup.toolblockID doesn't appear to be a valid log level. Allowed are 'PLAYERS', 'MONSTERS' and 'ANIMALS'"); } hiddenPlayers = new HashSet<String>(); for (final String playerName : config.getStringList("logging.hiddenPlayers")) hiddenPlayers.add(playerName.toLowerCase().trim()); hiddenBlocks = new HashSet<Integer>(); for (final Object blocktype : config.getList("logging.hiddenBlocks")) { final Material mat = Material.matchMaterial(String.valueOf(blocktype)); if (mat != null) hiddenBlocks.add(mat.getId()); else throw new DataFormatException("Not a valid material: '" + blocktype + "'"); } ignoredChat = new HashSet<String>(); for (String chatCommand : config.getStringList("logging.ignoredChat")) { ignoredChat.add(chatCommand); } dontRollback = new HashSet<Integer>(config.getIntegerList("rollback.dontRollback")); replaceAnyway = new HashSet<Integer>(config.getIntegerList("rollback.replaceAnyway")); rollbackMaxTime = parseTimeSpec(config.getString("rollback.maxTime").split(" ")); rollbackMaxArea = config.getInt("rollback.maxArea", 50); defaultDist = config.getInt("lookup.defaultDist", 20); defaultTime = parseTimeSpec(config.getString("lookup.defaultTime").split(" ")); linesPerPage = config.getInt("lookup.linesPerPage", 15); linesLimit = config.getInt("lookup.linesLimit", 1500); askRollbacks = config.getBoolean("questioner.askRollbacks", true); askRedos = config.getBoolean("questioner.askRedos", true); askClearLogs = config.getBoolean("questioner.askClearLogs", true); askClearLogAfterRollback = config.getBoolean("questioner.askClearLogAfterRollback", true); askRollbackAfterBan = config.getBoolean("questioner.askRollbackAfterBan", false); safetyIdCheck = config.getBoolean("safety.id.check", true); banPermission = config.getString("questioner.banPermission"); final List<Tool> tools = new ArrayList<Tool>(); final ConfigurationSection toolsSec = config.getConfigurationSection("tools"); for (final String toolName : toolsSec.getKeys(false)) try { final ConfigurationSection tSec = toolsSec.getConfigurationSection(toolName); final List<String> aliases = tSec.getStringList("aliases"); final ToolBehavior leftClickBehavior = ToolBehavior.valueOf(tSec.getString("leftClickBehavior").toUpperCase()); final ToolBehavior rightClickBehavior = ToolBehavior.valueOf(tSec.getString("rightClickBehavior").toUpperCase()); final boolean defaultEnabled = tSec.getBoolean("defaultEnabled", false); final int item = tSec.getInt("item", 0); final boolean canDrop = tSec.getBoolean("canDrop", false); final QueryParams params = new QueryParams(logblock); params.prepareToolQuery = true; params.parseArgs(getConsoleSender(), Arrays.asList(tSec.getString("params").split(" "))); final ToolMode mode = ToolMode.valueOf(tSec.getString("mode").toUpperCase()); final PermissionDefault pdef = PermissionDefault.valueOf(tSec.getString("permissionDefault").toUpperCase()); tools.add( new Tool( toolName, aliases, leftClickBehavior, rightClickBehavior, defaultEnabled, item, canDrop, params, mode, pdef)); } catch (final Exception ex) { getLogger().log(Level.WARNING, "Error at parsing tool '" + toolName + "': ", ex); } toolsByName = new HashMap<String, Tool>(); toolsByType = new HashMap<Integer, Tool>(); for (final Tool tool : tools) { toolsByType.put(tool.item, tool); toolsByName.put(tool.name.toLowerCase(), tool); for (final String alias : tool.aliases) toolsByName.put(alias, tool); } final List<String> loggedWorlds = config.getStringList("loggedWorlds"); worldConfigs = new HashMap<String, WorldConfig>(); if (loggedWorlds.isEmpty()) throw new DataFormatException("No worlds configured"); for (final String world : loggedWorlds) worldConfigs.put( world, new WorldConfig(new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml"))); superWorldConfig = new LoggingEnabledMapping(); for (final WorldConfig wcfg : worldConfigs.values()) for (final Logging l : Logging.values()) if (wcfg.isLogging(l)) superWorldConfig.setLogging(l, true); }