use of org.bukkit.configuration.ConfigurationSection in project Jobs by GamingMesh.
the class JobConfig method loadJobSettings.
/**
* Method to load the jobs configuration
*
* loads from Jobs/jobConfig.yml
*/
private void loadJobSettings() {
File f = new File(plugin.getDataFolder(), "jobConfig.yml");
ArrayList<Job> jobs = new ArrayList<Job>();
Jobs.setJobs(jobs);
Jobs.setNoneJob(null);
if (!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
Jobs.getPluginLogger().severe("Unable to create jobConfig.yml! No jobs were loaded!");
return;
}
}
YamlConfiguration conf = new YamlConfiguration();
conf.options().pathSeparator('/');
try {
conf.load(f);
} catch (Exception e) {
Bukkit.getServer().getLogger().severe("==================== Jobs ====================");
Bukkit.getServer().getLogger().severe("Unable to load jobConfig.yml!");
Bukkit.getServer().getLogger().severe("Check your config for formatting issues!");
Bukkit.getServer().getLogger().severe("No jobs were loaded!");
Bukkit.getServer().getLogger().severe("Error: " + e.getMessage());
Bukkit.getServer().getLogger().severe("==============================================");
return;
}
conf.options().header(new StringBuilder().append("Jobs configuration.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Stores information about each job.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("For example configurations, visit http://dev.bukkit.org/server-mods/jobs/.").append(System.getProperty("line.separator")).toString());
ConfigurationSection jobsSection = conf.getConfigurationSection("Jobs");
if (jobsSection == null) {
jobsSection = conf.createSection("Jobs");
}
for (String jobKey : jobsSection.getKeys(false)) {
ConfigurationSection jobSection = jobsSection.getConfigurationSection(jobKey);
String jobName = jobSection.getString("fullname");
if (jobName == null) {
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid fullname property. Skipping job!");
continue;
}
int maxLevel = jobSection.getInt("max-level", 0);
if (maxLevel < 0)
maxLevel = 0;
Integer maxSlots = jobSection.getInt("slots", 0);
if (maxSlots.intValue() <= 0) {
maxSlots = null;
}
String jobShortName = jobSection.getString("shortname");
if (jobShortName == null) {
Jobs.getPluginLogger().warning("Job " + jobKey + " is missing the shortname property. Skipping job!");
continue;
}
String description = jobSection.getString("description", "");
ChatColor color = ChatColor.WHITE;
if (jobSection.contains("ChatColour")) {
color = ChatColor.matchColor(jobSection.getString("ChatColour", ""));
if (color == null) {
color = ChatColor.WHITE;
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid ChatColour property. Defaulting to WHITE!");
}
}
DisplayMethod displayMethod = DisplayMethod.matchMethod(jobSection.getString("chat-display", ""));
if (displayMethod == null) {
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid chat-display property. Defaulting to None!");
displayMethod = DisplayMethod.NONE;
}
Parser maxExpEquation;
String maxExpEquationInput = jobSection.getString("leveling-progression-equation");
try {
maxExpEquation = new Parser(maxExpEquationInput);
// test equation
maxExpEquation.setVariable("numjobs", 1);
maxExpEquation.setVariable("joblevel", 1);
maxExpEquation.getValue();
} catch (Exception e) {
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid leveling-progression-equation property. Skipping job!");
continue;
}
Parser incomeEquation;
String incomeEquationInput = jobSection.getString("income-progression-equation");
try {
incomeEquation = new Parser(incomeEquationInput);
// test equation
incomeEquation.setVariable("numjobs", 1);
incomeEquation.setVariable("joblevel", 1);
incomeEquation.setVariable("baseincome", 1);
incomeEquation.getValue();
} catch (Exception e) {
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid income-progression-equation property. Skipping job!");
continue;
}
Parser expEquation;
String expEquationInput = jobSection.getString("experience-progression-equation");
try {
expEquation = new Parser(expEquationInput);
// test equation
expEquation.setVariable("numjobs", 1);
expEquation.setVariable("joblevel", 1);
expEquation.setVariable("baseexperience", 1);
expEquation.getValue();
} catch (Exception e) {
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid experience-progression-equation property. Skipping job!");
continue;
}
// Permissions
ArrayList<JobPermission> jobPermissions = new ArrayList<JobPermission>();
ConfigurationSection permissionsSection = jobSection.getConfigurationSection("permissions");
if (permissionsSection != null) {
for (String permissionKey : permissionsSection.getKeys(false)) {
ConfigurationSection permissionSection = permissionsSection.getConfigurationSection(permissionKey);
String node = permissionKey.toLowerCase();
if (permissionSection == null) {
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid permission key" + permissionKey + "!");
continue;
}
boolean value = permissionSection.getBoolean("value", true);
int levelRequirement = permissionSection.getInt("level", 0);
jobPermissions.add(new JobPermission(node, value, levelRequirement));
}
}
Job job = new Job(jobName, jobShortName, description, color, maxExpEquation, displayMethod, maxLevel, maxSlots, jobPermissions);
for (ActionType actionType : ActionType.values()) {
ConfigurationSection typeSection = jobSection.getConfigurationSection(actionType.getName());
ArrayList<JobInfo> jobInfo = new ArrayList<JobInfo>();
if (typeSection != null) {
for (String key : typeSection.getKeys(false)) {
ConfigurationSection section = typeSection.getConfigurationSection(key);
String myKey = key.toUpperCase();
String type = null;
String subType = "";
if (myKey.contains("-")) {
// uses subType
subType = ":" + myKey.split("-")[1];
myKey = myKey.split("-")[0];
}
Material material = Material.matchMaterial(myKey);
if (material == null) {
// try integer method
Integer matId = null;
try {
matId = Integer.decode(myKey);
} catch (NumberFormatException e) {
}
if (matId != null) {
material = Material.getMaterial(matId);
if (material != null) {
Jobs.getPluginLogger().warning("Job " + jobKey + " " + actionType.getName() + " is using a block by number ID: " + key + "!");
Jobs.getPluginLogger().warning("Please switch to using the Material name instead: " + material.toString() + "!");
Jobs.getPluginLogger().warning("Blocks by number IDs may break in a future release!");
}
}
}
if (material != null) {
// Break and Place actions MUST be blocks
if (actionType == ActionType.BREAK || actionType == ActionType.PLACE) {
if (!material.isBlock()) {
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid " + actionType.getName() + " type property: " + key + "! Material must be a block!");
continue;
}
}
/*
* Historically, GLOWING_REDSTONE_ORE would ONLY work as REDSTONE_ORE, and putting
* GLOWING_REDSTONE_ORE in the configuration would not work. Unfortunately, this is
* completely backwards and wrong.
*
* To maintain backwards compatibility, all instances of REDSTONE_ORE should normalize
* to GLOWING_REDSTONE_ORE, and warn the user to change their configuration. In the
* future this hack may be removed and anybody using REDSTONE_ORE will have their
* configurations broken.
*/
if (material == Material.REDSTONE_ORE) {
Jobs.getPluginLogger().warning("Job " + jobKey + " is using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE.");
Jobs.getPluginLogger().warning("Automatically changing block to GLOWING_REDSTONE_ORE. Please update your configuration.");
Jobs.getPluginLogger().warning("In vanilla minecraft, REDSTONE_ORE changes to GLOWING_REDSTONE_ORE when interacted with.");
Jobs.getPluginLogger().warning("In the future, Jobs using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE may fail to work correctly.");
material = Material.GLOWING_REDSTONE_ORE;
}
// END HACK
type = material.toString();
} else if (actionType == ActionType.KILL) {
// check entities
EntityType entity = EntityType.fromName(key);
if (entity == null) {
try {
entity = EntityType.valueOf(key.toUpperCase());
} catch (IllegalArgumentException e) {
}
}
if (entity != null && entity.isAlive())
type = entity.toString();
}
if (type == null) {
Jobs.getPluginLogger().warning("Job " + jobKey + " has an invalid " + actionType.getName() + " type property: " + key + "!");
continue;
}
double income = section.getDouble("income", 0.0);
double experience = section.getDouble("experience", 0.0);
jobInfo.add(new JobInfo(type + subType, income, incomeEquation, experience, expEquation));
}
}
job.setJobInfo(actionType, jobInfo);
}
if (jobKey.equalsIgnoreCase("none")) {
Jobs.setNoneJob(job);
} else {
jobs.add(job);
}
}
try {
conf.save(f);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bukkit.configuration.ConfigurationSection in project Jobs by GamingMesh.
the class JobsConfiguration method loadTitleSettings.
/**
* Method to load the title configuration
*
* loads from Jobs/titleConfig.yml
*/
private synchronized void loadTitleSettings() {
this.titles.clear();
File f = new File(plugin.getDataFolder(), "titleConfig.yml");
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
StringBuilder header = new StringBuilder().append("Title configuration").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Stores the titles people gain at certain levels.").append(System.getProperty("line.separator")).append("Each title requres to have a name, short name (used when the player has more than").append(System.getProperty("line.separator")).append("1 job) the colour of the title and the level requrirement to attain the title.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("It is recommended but not required to have a title at level 0.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Titles are completely optional.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Titles:").append(System.getProperty("line.separator")).append(" Apprentice:").append(System.getProperty("line.separator")).append(" Name: Apprentice").append(System.getProperty("line.separator")).append(" ShortName: A").append(System.getProperty("line.separator")).append(" ChatColour: WHITE").append(System.getProperty("line.separator")).append(" levelReq: 0").append(System.getProperty("line.separator")).append(" Novice:").append(System.getProperty("line.separator")).append(" Name: Novice").append(System.getProperty("line.separator")).append(" ShortName: N").append(System.getProperty("line.separator")).append(" ChatColour: GRAY").append(System.getProperty("line.separator")).append(" levelReq: 30").append(System.getProperty("line.separator")).append(" Journeyman:").append(System.getProperty("line.separator")).append(" Name: Journeyman").append(System.getProperty("line.separator")).append(" ShortName: J").append(System.getProperty("line.separator")).append(" ChatColour: GOLD").append(System.getProperty("line.separator")).append(" levelReq: 60").append(System.getProperty("line.separator")).append(" Master:").append(System.getProperty("line.separator")).append(" Name: Master").append(System.getProperty("line.separator")).append(" ShortName: M").append(System.getProperty("line.separator")).append(" ChatColour: BLACK").append(System.getProperty("line.separator")).append(" levelReq: 90").append(System.getProperty("line.separator")).append(System.getProperty("line.separator"));
conf.options().header(header.toString());
conf.options().copyDefaults(true);
conf.options().indent(2);
ConfigurationSection titleSection = conf.getConfigurationSection("Titles");
if (titleSection == null) {
titleSection = conf.createSection("Titles");
}
for (String titleKey : titleSection.getKeys(false)) {
String titleName = conf.getString("Titles." + titleKey + ".Name");
String titleShortName = conf.getString("Titles." + titleKey + ".ShortName");
ChatColor titleColor = ChatColor.matchColor(conf.getString("Titles." + titleKey + ".ChatColour", ""));
int levelReq = conf.getInt("Titles." + titleKey + ".levelReq", -1);
if (titleName == null) {
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid Name property. Skipping!");
continue;
}
if (titleShortName == null) {
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid ShortName property. Skipping!");
continue;
}
if (titleColor == null) {
Jobs.getPluginLogger().severe("Title " + titleKey + "has an invalid ChatColour property. Skipping!");
continue;
}
if (levelReq <= -1) {
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid levelReq property. Skipping!");
continue;
}
this.titles.add(new Title(titleName, titleShortName, titleColor, levelReq));
}
try {
conf.save(f);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bukkit.configuration.ConfigurationSection in project Jobs by GamingMesh.
the class JobsConfiguration method loadRestrictedAreaSettings.
/**
* Method to load the restricted areas configuration
*
* loads from Jobs/restrictedAreas.yml
*/
private synchronized void loadRestrictedAreaSettings() {
this.restrictedAreas.clear();
File f = new File(plugin.getDataFolder(), "restrictedAreas.yml");
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
conf.options().indent(2);
conf.options().copyDefaults(true);
StringBuilder header = new StringBuilder();
header.append("Restricted area configuration").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Configures restricted areas where you cannot get experience or money").append(System.getProperty("line.separator")).append("when performing a job.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("The multiplier changes the experience/money gains in an area.").append(System.getProperty("line.separator")).append("A multiplier of 0.0 means no money or xp, while 0.5 means you will get half the normal money/exp").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("restrictedareas:").append(System.getProperty("line.separator")).append(" area1:").append(System.getProperty("line.separator")).append(" world: 'world'").append(System.getProperty("line.separator")).append(" multiplier: 0.0").append(System.getProperty("line.separator")).append(" point1:").append(System.getProperty("line.separator")).append(" x: 125").append(System.getProperty("line.separator")).append(" y: 0").append(System.getProperty("line.separator")).append(" z: 125").append(System.getProperty("line.separator")).append(" point2:").append(System.getProperty("line.separator")).append(" x: 150").append(System.getProperty("line.separator")).append(" y: 100").append(System.getProperty("line.separator")).append(" z: 150").append(System.getProperty("line.separator")).append(" area2:").append(System.getProperty("line.separator")).append(" world: 'world_nether'").append(System.getProperty("line.separator")).append(" multiplier: 0.0").append(System.getProperty("line.separator")).append(" point1:").append(System.getProperty("line.separator")).append(" x: -100").append(System.getProperty("line.separator")).append(" y: 0").append(System.getProperty("line.separator")).append(" z: -100").append(System.getProperty("line.separator")).append(" point2:").append(System.getProperty("line.separator")).append(" x: -150").append(System.getProperty("line.separator")).append(" y: 100").append(System.getProperty("line.separator")).append(" z: -150");
conf.options().header(header.toString());
ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas");
if (areaSection != null) {
for (String areaKey : areaSection.getKeys(false)) {
String worldName = conf.getString("restrictedareas." + areaKey + ".world");
double multiplier = conf.getDouble("restrictedareas." + areaKey + ".multiplier", 0.0);
World world = Bukkit.getServer().getWorld(worldName);
if (world == null)
continue;
Location point1 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point1.x", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point1.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point1.z", 0.0));
Location point2 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point2.x", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.z", 0.0));
this.restrictedAreas.add(new RestrictedArea(point1, point2, multiplier));
}
}
try {
conf.save(f);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.bukkit.configuration.ConfigurationSection in project Denizen-For-Bukkit by DenizenScript.
the class NotableManager method _recallNotables.
/**
* Called on '/denizen reload notables'.
*/
private static void _recallNotables() {
notableObjects.clear();
typeTracker.clear();
reverseObjects.clear();
// Find each type of notable
for (String key : DenizenAPI.getCurrentInstance().notableManager().getNotables().getKeys(false)) {
Class<? extends dObject> clazz = reverse_objects.get(key);
ConfigurationSection section = DenizenAPI.getCurrentInstance().notableManager().getNotables().getConfigurationSection(key);
if (section == null) {
continue;
}
for (String notable : section.getKeys(false)) {
Notable obj = (Notable) ObjectFetcher.getObjectFrom(clazz, section.getString(notable));
if (obj != null) {
obj.makeUnique(notable.replace("DOT", "."));
} else {
dB.echoError("Notable '" + notable.replace("DOT", ".") + "' failed to load!");
}
}
}
}
use of org.bukkit.configuration.ConfigurationSection in project Denizen-For-Bukkit by DenizenScript.
the class DenizenMapManager method reloadMaps.
public static void reloadMaps() {
Map<Short, List<MapRenderer>> oldMapRenderers = new HashMap<Short, List<MapRenderer>>();
for (Map.Entry<Short, DenizenMapRenderer> entry : mapRenderers.entrySet()) {
DenizenMapRenderer renderer = entry.getValue();
oldMapRenderers.put(entry.getKey(), renderer.getOldRenderers());
renderer.deactivate();
}
mapRenderers.clear();
downloadedByUrl.clear();
mapsConfig = YamlConfiguration.loadConfiguration(mapsFile);
ConfigurationSection mapsSection = mapsConfig.getConfigurationSection("MAPS");
if (mapsSection == null) {
return;
}
for (String key : mapsSection.getKeys(false)) {
short mapId = Short.valueOf(key);
MapView mapView = Bukkit.getServer().getMap(mapId);
if (mapView == null) {
dB.echoError("Map #" + key + " does not exist. Has it been removed? Deleting from maps.yml...");
mapsSection.set(key, null);
continue;
}
ConfigurationSection objectsData = mapsSection.getConfigurationSection(key + ".objects");
List<MapRenderer> oldRenderers;
if (oldMapRenderers.containsKey(mapId)) {
oldRenderers = oldMapRenderers.get(mapId);
} else {
oldRenderers = mapView.getRenderers();
for (MapRenderer oldRenderer : oldRenderers) {
mapView.removeRenderer(oldRenderer);
}
}
DenizenMapRenderer renderer = new DenizenMapRenderer(oldRenderers, mapsSection.getBoolean(key + ".auto update", false));
List<String> objects = new ArrayList<String>(objectsData.getKeys(false));
Collections.sort(objects, new NaturalOrderComparator());
for (String objectKey : objects) {
String type = objectsData.getString(objectKey + ".type").toUpperCase();
String xTag = objectsData.getString(objectKey + ".x");
String yTag = objectsData.getString(objectKey + ".y");
String visibilityTag = objectsData.getString(objectKey + ".visibility");
boolean debug = objectsData.getBoolean(objectKey + ".debug");
MapObject object = null;
if (type.equals("CURSOR")) {
object = new MapCursor(xTag, yTag, visibilityTag, debug, objectsData.getString(objectKey + ".direction"), objectsData.getString(objectKey + ".cursor"));
} else if (type.equals("IMAGE")) {
String file = objectsData.getString(objectKey + ".image");
int width = objectsData.getInt(objectKey + ".width", 0);
int height = objectsData.getInt(objectKey + ".height", 0);
if (CoreUtilities.toLowerCase(file).endsWith(".gif")) {
object = new MapAnimatedImage(xTag, yTag, visibilityTag, debug, file, width, height);
} else {
object = new MapImage(xTag, yTag, visibilityTag, debug, file, width, height);
}
} else if (type.equals("TEXT")) {
object = new MapText(xTag, yTag, visibilityTag, debug, objectsData.getString(objectKey + ".text"));
}
if (object != null) {
renderer.addObject(object);
}
}
mapView.addRenderer(renderer);
mapRenderers.put(mapId, renderer);
}
for (Map.Entry<Short, List<MapRenderer>> entry : oldMapRenderers.entrySet()) {
short id = entry.getKey();
if (!mapRenderers.containsKey(id)) {
MapView mapView = Bukkit.getServer().getMap(id);
if (mapView != null) {
for (MapRenderer renderer : entry.getValue()) {
mapView.addRenderer(renderer);
}
}
// If it's null, the server no longer has the map - don't do anything about it
}
}
ConfigurationSection downloadedImages = mapsConfig.getConfigurationSection("DOWNLOADED");
if (downloadedImages == null) {
return;
}
for (String image : downloadedImages.getKeys(false)) {
downloadedByUrl.put(CoreUtilities.toLowerCase(downloadedImages.getString(image)), image.replace("DOT", "."));
}
}
Aggregations