public static LoseZone deserialize(ConfigurationSection section) { int id = section.getInt("id"); Location first = Parser.convertStringtoLocation(section.getString("first")); Location second = Parser.convertStringtoLocation(section.getString("second")); return new LoseZone(first, second, id); }
@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; } } }
/** * Parses data for a kit action * * @param cfg section to parse * @return KitAction */ private KitAction parseAction(ConfigurationSection cfg) { Map<String, Object> vals = cfg.getValues(true); KitAction action; if (vals.containsKey("type")) { String actionType = (String) vals.get("type"); // System.out.println("Type: " + actionType); // Determine what type of action it is if (actionType.equalsIgnoreCase("ITEMS") || actionType.equalsIgnoreCase("ITEM")) { if (vals.containsKey("item")) { action = new ItemsAction(parseItem(cfg.getConfigurationSection("item"))); return action; } return null; } else if (actionType.equalsIgnoreCase("EFFECT") || actionType.equalsIgnoreCase("POTION")) { if (vals.containsKey("effect")) { action = new EffectAction(parsePotion(cfg.getConfigurationSection("effect"))); return action; } return null; } else if (actionType.equalsIgnoreCase("COMMAND") || actionType.equalsIgnoreCase("COMMANDS")) { String cType = cfg.getString("command.type", "console"); String cmd = cfg.getString("command.command", "list"); action = new CommandAction(cType, cmd); return action; } } return null; }
public SQLDatabase( final DatabaseType type, final Class<S> clazz, final SQLColumn[] columns, final String defaultTableName, final ConfigurationSection config) { super(type, clazz, convertColumnNames(columns)); if (config == null) { this.tableName = defaultTableName; this.columns = columns; this.columnNames = defaultColumnNames; this.cached = true; this.doNotUpdate = false; } else { this.tableName = config.getString("tableName", defaultTableName); this.columns = columns; this.columnNames = new String[defaultColumnNames.length]; for (int i = 0; i < defaultColumnNames.length; i++) { columnNames[i] = config.getString("columns." + defaultColumnNames[i], defaultColumnNames[i]); columns[i].setRealName(columnNames[i]); } this.cached = config.getBoolean("cached", true); this.doNotUpdate = config.getBoolean("static", false); } }
private String getJDBCUrl() { return String.format( "jdbc:mysql://%s:%d/%s?user=%s&password=%s", section.getString("host"), section.getInt("port"), section.getString("database"), section.getString("username"), section.getString("password")); }
public static void load(Plugin plugin) { primary = getColor(plugin.getConfig().getString("color.primary")); secondary = getColor(plugin.getConfig().getString("color.secondary")); ConfigurationSection cfg = plugin.getConfig().getConfigurationSection("kick-colors"); regular = getColor(cfg.getString("regular")); banner = getColor(cfg.getString("banner")); reason = getColor(cfg.getString("reason")); time = getColor(cfg.getString("time")); }
@Override public void prepare(CastContext context, ConfigurationSection parameters) { super.prepare(context, parameters); direction = BlockFace.UP; try { direction = BlockFace.valueOf(parameters.getString("direction", "up").toUpperCase()); } catch (Exception ex) { context.getLogger().info("Invalid search direction: " + parameters.getString("direction")); direction = BlockFace.DOWN; } }
@Override protected void loadFromConfig(ConfigurationSection config) { title = config.getString("title", title); if (title != null) title = ChatColor.translateAlternateColorCodes('&', title); subtitle = config.getString("subtitle", subtitle); if (subtitle != null) subtitle = ChatColor.translateAlternateColorCodes('&', subtitle); fadeIn = config.getInt("fade-in", fadeIn); stay = config.getInt("stay", stay); fadeOut = config.getInt("fade-out", fadeOut); broadcast = config.getBoolean("broadcast", broadcast); }
private List<ServerInfo> loadServers() { List<ServerInfo> list = new ArrayList<>(); ConfigurationSection server = config.getConfigurationSection("servers"); for (String servername : server.getKeys(false)) { ConfigurationSection cs = server.getConfigurationSection(servername); String displayname = cs.getString("displayname"); String[] addre = cs.getString("address").split(":"); InetSocketAddress address = new InetSocketAddress(addre[0], Integer.parseInt(addre[1])); ServerInfo si = new ServerInfo(servername, address, displayname); list.add(si); } return list; }
public String parse(String format) { ConfigurationSection node = manager.getPlugin().getGroupNode(group); format = parsePrefix(format, node.getString("prefix")); format = parseGroup(format, node.getString("group")); format = parseSuffix(format, node.getString("suffix")); format = parseHero(format); format = parseWorld(format, manager.getPlugin().getWorldManager().getAlias(world)); format = parseTarget(format); format = parseSelf(format); format = parseAfk(format, node.getString("afk")); format = parseColors(format); return format; }
/** * Loads new test with given name and ConfigurationSection. * * @param plugin instance of BetonTest * @param name name of the test * @param config section containing the test * @throws TestException when configuration is incorrect */ public Test(BetonTest plugin, String name, ConfigurationSection config) throws TestException { this.plugin = plugin; this.name = name; messageStart = config.getString("messages.start"); messageResume = config.getString("messages.resume"); messagePass = config.getString("messages.pass"); messageFail = config.getString("messages.fail"); messagePause = config.getString("messages.pause"); commandWin = config.getString("commands.pass"); commandFail = config.getString("commands.fail"); commandPause = config.getString("commands.pause"); blockedCommands = config.getStringList("blocked_cmds"); teleportBack = config.getBoolean("teleport_back"); maxMistakes = config.getInt("max_mistakes", -1); if (maxMistakes < 0) throw new TestException("max_mistakes must be more than 0"); onMistake = MistakeAction.match(config.getString("on_mistake")); if (onMistake == null) throw new TestException("incorrect on_mistake value"); if (config.getConfigurationSection("categories") == null) throw new TestException("categories not defined"); for (String key : config.getConfigurationSection("categories").getKeys(false)) { try { categories.add( new Category(plugin, this, key, config.getConfigurationSection("categories." + key))); } catch (CategoryException e) { throw new TestException("error in '" + key + "' category: " + e.getMessage()); } } if (categories.isEmpty()) throw new TestException("categories not defined"); for (Category category : categories) { category.shuffle(); } }
public SQLDB(Fe plugin, boolean supportsModification) { super(plugin); this.plugin = plugin; this.supportsModification = supportsModification; ConfigurationSection config = getConfigSection(); accounts = config.getString("accounts"); pname = config.getString("pname"); pbalance = config.getString("pbalance"); }
private static Message getNoCampMessage(ConfigurationSection config) { NoCampMessageDecorator message = new NoCampMessageDecorator( new DefaultMessage(config.getString("Messages.NoCampMessage", NO_CAMP_MESSAGE))); message.setSpawnerCampMessageEnabled(config.getBoolean("Messages.Spawner", false)); return message; }
@Override public boolean onCommand( CommandSender sender, Command command, String alias, LinkedList<String> args) { ConfigurationSection cfg = plugin.getConfig().getConfigurationSection("cook-mappings"); String key = ((Player) sender).getItemInHand().getType().name(); String newMaterialName = cfg.getString(key); if (newMaterialName == null) { ((Player) sender).sendMessage(plugin.getMsg("errors.cant-cook-item")); return true; } Material newMat = null; Short dur = null; if (newMaterialName.contains(":")) { String[] materials = newMaterialName.split(":"); newMat = Material.getMaterial(materials[0]); dur = Short.parseShort(materials[1]); } else { newMat = Material.getMaterial(newMaterialName); } if (newMat == null) { sender.sendMessage(plugin.getMsg("errors.cant-cook-item")); return true; } ((Player) sender).getItemInHand().setType(newMat); if (dur != null) { ((Player) sender).getItemInHand().setDurability(dur); } ((Player) sender).sendMessage(plugin.getMsg("cooked")); return true; }
/** * parse through dat to create a new item with enchantments, quantity, and damage value * * @param cfg to parse through * @return the new ItemStack */ private ItemStack parseItem(ConfigurationSection cfg) { Map<String, Object> vals = cfg.getValues(true); ItemStack newItem; // check material newItem = new ItemStack(Material.getMaterial((cfg.getString("material", "stone")).toUpperCase())); // check damage value newItem.setDurability((short) (cfg.getInt("damage", 0))); // check quantity newItem.setAmount(cfg.getInt("amount", 1)); // enchantment parsing for (String s : cfg.getStringList("enchantments")) { String[] parts = s.split(":"); String enchant = parts[0]; int level = 1; if (parts.length > 1) { level = Integer.parseInt(parts[1]); } newItem.addUnsafeEnchantment(Enchantment.getByName(enchant.toUpperCase()), level); } // System.out.println("Item: "+ newItem.toString()); return newItem; // ItemStack is = new ItemStack(Material.); }
private ChunkGenerator getGenerator(int dimID) { ConfigurationSection section = bukkitConfig.getConfigurationSection("worlds"); ChunkGenerator result = null; if (section != null) { section = section.getConfigurationSection(Integer.toString(dimID)); if (section != null) { String name = section.getString("generator"); if ((name != null) && (!name.equals(""))) { String[] split = name.split(":", 2); String id = (split.length > 1) ? split[1] : null; Plugin plugin = pluginManager.getPlugin(split[0]); if (plugin == null) { getLogger().severe("Could not set generator for default world '" + Integer.toString(dimID) + "': Plugin '" + split[0] + "' does not exist"); } else if (!plugin.isEnabled()) { getLogger().severe("Could not set generator for default world '" + Integer.toString(dimID) + "': Plugin '" + split[0] + "' is not enabled yet (is it load:STARTUP?)"); } else { result = plugin.getDefaultWorldGenerator(Integer.toString(dimID), id); } } } } return result; }
private void initModuleClass(Rilncraft rilncraft, YamlConfiguration definition) { ConfigurationSection module; String className; module = definition.getConfigurationSection("module"); if (module == null) { return; } className = module.getString("main"); try { Class<Module> _tempClass = (Class<Module>) Class.forName(className); Constructor<Module> ctor = _tempClass.getDeclaredConstructor(Rilncraft.class, Configuration.class); Module newInstance = ctor.newInstance(rilncraft, definition); modulesLoaded.add(newInstance); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ex) { Logger.getLogger(ModuleLoader.class.getName()).log(Level.SEVERE, null, ex); } }
public static List<String> getDates(final String name) { BaseSerializer serializer = getSerializer(name); if (serializer == null) return null; PriorityQueue<Long> dates = new PriorityQueue<Long>(Defaults.NUM_INV_SAVES, Collections.reverseOrder()); Set<String> keys = serializer.config.getKeys(false); DateFormat format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); for (String key : keys) { ConfigurationSection cs = serializer.config.getConfigurationSection(key); if (cs == null) continue; String strdate = cs.getString("storedDate"); Date date; try { date = format.parse(strdate); } catch (ParseException e) { e.printStackTrace(); continue; } dates.add(date.getTime()); } List<String> strdates = new ArrayList<String>(); for (Long l : dates) { strdates.add(format.format(l)); } return strdates; }
@Override public SpellResult onCast(ConfigurationSection parameters) { Block target = getTargetBlock(); if (target == null) { return SpellResult.NO_TARGET; } // TODO: Optimize this Set<Material> dropMaterials = controller.getMaterialSet(parameters.getString("drop")); if (!dropMaterials.contains(target.getType())) { return SpellResult.NO_TARGET; } if (!hasBuildPermission(target)) { return SpellResult.INSUFFICIENT_PERMISSION; } int maxRecursion = parameters.getInt("recursion_depth", DEFAULT_MAX_RECURSION); drop(target, dropMaterials, maxRecursion); // Make this undoable.. even though it means you can exploit it for ore with Rewind. Meh! registerForUndo(); return SpellResult.CAST; }
private static Location loadLocation(ConfigurationSection section) { String world = section.getString("world"); double x = section.getDouble("x"); double y = section.getDouble("y"); double z = section.getDouble("z"); return new Location(Bukkit.getWorld(world), x, y, z); }
private static Scoreboard loadScoreboard(ConfigurationSection section, String id) { String interval = section.getString("interval", "30m"); String command = section.getString("command"); Scoreboard.Sender senderType = Scoreboard.Sender.valueOf(section.getString("sender", "console").toUpperCase()); Scoreboard scoreboard = new Scoreboard( id, interval, senderType, command, loadLocation(section.getConfigurationSection("location"))); scoreboard.setFilter(section.getString("filter", null)); scoreboard.setDelay(section.getString("delay", "5s")); return scoreboard; }
@Override protected void loadKeys() { ConfigurationSection groups = config.getConfigurationSection("groups"); for (String keys : groups.getKeys(false)) { ConfigurationSection vars = groups.getConfigurationSection(keys); super.plugin .getChatProfiles() .add( new ChatProfile( vars.getName(), vars.getName(), vars.getString("Prefix"), vars.getString("Suffix"), vars.getString("Muffix"), vars.getString("Format"))); } }
public static Objective deser(ConfigurationSection section) { int amt = 0; String boss = ""; boss = section.getString("boss", ""); if (section.isInt("amount")) amt = section.getInt("amount"); if (amt < 1 || boss.isEmpty()) return null; return new BossObjective(boss, amt); }
private Map<String, SignLayout> loadLayouts() { Map<String, SignLayout> layoutMap = new HashMap<>(); ConfigurationSection layouts = config.getConfigurationSection("layouts"); for (String layout : layouts.getKeys(false)) { ConfigurationSection cs = layouts.getConfigurationSection(layout); String online = cs.getString("online"); String offline = cs.getString("offline"); List<String> lines = cs.getStringList("layout"); boolean teleport = cs.getBoolean("teleport"); String offlineInteger = cs.getString("offline-int"); SignLayout signLayout = new TeleportSignLayout( layout, online, offline, lines.toArray(new String[0]), teleport, offlineInteger); layoutMap.put(layout, signLayout); } return layoutMap; }
/** * 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; } }
public Database(ConfigurationSection config) throws ClassNotFoundException, SQLException { final String hostname = config.getString("hostname", "localhost"); final int port = config.getInt("port", 3306); final String database = config.getString("database", ""); connectionUri = String.format("jdbc:mysql://%s:%d/%s", hostname, port, database); username = config.getString("username", ""); password = config.getString("password", ""); try { Class.forName("com.mysql.jdbc.Driver"); connect(); } catch (SQLException sqlException) { close(); throw sqlException; } }
private ChatColor getPermColor(Player player) { ConfigurationSection colorSection = getConfig().getConfigurationSection("colors"); for (String colorName : colorSection.getKeys(false)) { if (player.hasPermission("coloredplayernames." + colorName)) { return ChatColor.getByChar(colorSection.getString(colorName + ".code")); } } return null; }
private Set<ChatColor> possibleColors() { Set<ChatColor> result = EnumSet.noneOf(ChatColor.class); ConfigurationSection colorSection = getConfig().getConfigurationSection("colors"); for (String colorName : colorSection.getKeys(false)) { ConfigurationSection singleColor = colorSection.getConfigurationSection(colorName); result.add(ChatColor.getByChar(singleColor.getString("code"))); } return result; }
@Override public void prepare(CastContext context, ConfigurationSection parameters) { super.prepare(context, parameters); treeType = null; requireSapling = parameters.getBoolean("require_sapling", false); String typeString = parameters.getString("type", ""); treeType = parseTreeString(typeString, null); }
/** * flicker: true type: BALL trail: red: -1 green: -1 blue: -1 * * @param configurationSection * @return */ public static ConfigFirework load(ConfigurationSection conf) { if (conf == null) return null; return new ConfigFirework( conf.getString("type", "BALL"), conf.getBoolean("flicker", false), conf.getInt("red", -1), conf.getInt("green", -1), conf.getInt("blue", -1)); }