Ranks config idea

This commit is contained in:
t00thpick1 2013-10-04 17:52:47 -04:00
parent b8e937a234
commit 63ae7e97e1
7 changed files with 291 additions and 0 deletions

View File

@ -0,0 +1,45 @@
package com.gmail.nossr50.config.tiers;
import org.bukkit.configuration.ConfigurationSection;
public class BlastMiningRank extends Rank {
private double blastDamageDecrease;
private double oreBonus;
private double debrisReduction;
private int dropMultiplier;
private double blastRadiusModifier;
public BlastMiningRank(int level, double blastDamageDecrease, double oreBonus, double debrisReduction, int dropMultiplier, double blastRadiusModifier) {
super(level);
this.blastDamageDecrease = blastDamageDecrease;
this.oreBonus = oreBonus;
this.debrisReduction = debrisReduction;
this.dropMultiplier = dropMultiplier;
this.blastRadiusModifier = blastRadiusModifier;
}
public BlastMiningRank(ConfigurationSection section) {
this(section.getInt("Level"), section.getDouble("BlastDamageDecrease"), section.getDouble("OreBonus"), section.getDouble("DebrisReduction"), section.getInt("DropMultiplier"), section.getDouble("BlastRadiusModifier"));
}
public double getBlastDamageDecrease() {
return blastDamageDecrease;
}
public double getOreBonus() {
return oreBonus;
}
public double getDebrisReduction() {
return debrisReduction;
}
public int getDropMultiplier() {
return dropMultiplier;
}
public double getBlastRadiusModifier() {
return blastRadiusModifier;
}
}

View File

@ -0,0 +1,27 @@
package com.gmail.nossr50.config.tiers;
import org.bukkit.configuration.ConfigurationSection;
public class FishingRank extends Rank {
private double shakeChance;
private int xpBoost;
private FishingRank(int level, double shakeChance, int xpBoost) {
super(level);
this.shakeChance = shakeChance;
this.xpBoost = xpBoost;
}
public FishingRank(ConfigurationSection section) {
this(section.getInt("Level"), section.getDouble("ShakeChance"), section.getInt("VanillaXPBoost"));
}
public double getShakeChance() {
return shakeChance;
}
public int getXpBoost() {
return xpBoost;
}
}

View File

@ -0,0 +1,13 @@
package com.gmail.nossr50.config.tiers;
public abstract class Rank {
private int level;
public Rank(int level) {
this.level = level;
}
public int getLevel() {
return level;
}
}

View File

@ -0,0 +1,117 @@
package com.gmail.nossr50.config.tiers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
import com.gmail.nossr50.config.ConfigLoader;
public class RankLoader extends ConfigLoader {
private List<FishingRank> fishingRanks;
private List<SmeltingRank> smeltingRanks;
private List<BlastMiningRank> blastMiningRanks;
private List<RepairRank> repairRanks;
private static RankLoader instance;
private RankLoader() {
super("ranks.yml");
fishingRanks = new ArrayList<FishingRank>();
smeltingRanks = new ArrayList<SmeltingRank>();
blastMiningRanks = new ArrayList<BlastMiningRank>();
repairRanks = new ArrayList<RepairRank>();
loadKeys();
}
public static RankLoader getInstance() {
if (instance == null) {
instance = new RankLoader();
}
return instance;
}
@Override
protected void loadKeys() {
ConfigurationSection section = config.getConfigurationSection("Ranks.Fishing");
RankComparator rankComparator = new RankComparator();
for (String rank : section.getKeys(false)) {
fishingRanks.add(new FishingRank(section.getConfigurationSection(rank)));
}
Collections.sort(fishingRanks, rankComparator);
section = config.getConfigurationSection("Ranks.BlastMining");
for (String rank : section.getKeys(false)) {
blastMiningRanks.add(new BlastMiningRank(section.getConfigurationSection(rank)));
}
Collections.sort(blastMiningRanks, rankComparator);
section = config.getConfigurationSection("Ranks.Repair");
for (String rank : section.getKeys(false)) {
repairRanks.add(new RepairRank(section.getConfigurationSection(rank)));
}
Collections.sort(repairRanks, rankComparator);
section = config.getConfigurationSection("Ranks.Smelting");
for (String rank : section.getKeys(false)) {
smeltingRanks.add(new SmeltingRank(section.getConfigurationSection(rank)));
}
Collections.sort(smeltingRanks, rankComparator);
}
public FishingRank getFishingRank(int level) {
Iterator<FishingRank> it = fishingRanks.iterator();
while (it.hasNext()) {
FishingRank rank = it.next();
if (rank.getLevel() > level) {
return rank;
}
}
return null;
}
public RepairRank getRepairRank(int level) {
Iterator<RepairRank> it = repairRanks.iterator();
while (it.hasNext()) {
RepairRank rank = it.next();
if (rank.getLevel() > level) {
return rank;
}
}
return null;
}
public SmeltingRank getSmeltingRank(int level) {
Iterator<SmeltingRank> it = smeltingRanks.iterator();
while (it.hasNext()) {
SmeltingRank rank = it.next();
if (rank.getLevel() > level) {
return rank;
}
}
return null;
}
public BlastMiningRank getBlastMiningRank(int level) {
Iterator<BlastMiningRank> it = blastMiningRanks.iterator();
while (it.hasNext()) {
BlastMiningRank rank = it.next();
if (rank.getLevel() > level) {
return rank;
}
}
return null;
}
private class RankComparator implements Comparator<Rank> {
@Override
public int compare(Rank o1, Rank o2) {
return Integer.valueOf(o1.getLevel()).compareTo(Integer.valueOf(o2.getLevel()));
}
}
}

View File

@ -0,0 +1,27 @@
package com.gmail.nossr50.config.tiers;
import org.bukkit.configuration.ConfigurationSection;
public class RepairRank extends Rank {
private double downgradeChance;
private double keepEnchantsChance;
public RepairRank(int level, double downgradeChance, double keepEnchantsChance) {
super(level);
this.downgradeChance = downgradeChance;
this.keepEnchantsChance = keepEnchantsChance;
}
public RepairRank(ConfigurationSection section) {
this(section.getInt("Level"), section.getDouble("DowngradeChance"), section.getDouble("KeepEnchantsChance"));
}
public double getDowngradeChance() {
return downgradeChance;
}
public double getKeepEnchantsChance() {
return keepEnchantsChance;
}
}

View File

@ -0,0 +1,21 @@
package com.gmail.nossr50.config.tiers;
import org.bukkit.configuration.ConfigurationSection;
public class SmeltingRank extends Rank {
private int xpMultiplier;
public SmeltingRank(int level, int xpMultiplier) {
super(level);
this.xpMultiplier = xpMultiplier;
}
public SmeltingRank(ConfigurationSection section) {
this(section.getInt("Level"), section.getInt("VanillaXPMultiplier"));
}
public int getXpMultiplier() {
return xpMultiplier;
}
}

View File

@ -0,0 +1,41 @@
Ranks:
Fishing:
Rank1:
Level: 0
ShakeChance: 1.0
VanillaXPBoost: 1
ect:
Level: 1
ShakeChance: 1.0
VanillaXPBoost: 1
Smelting:
Rank1:
Level: 0
VanillaXPBoost: 1
ect:
Level: 1
VanillaXPBoost: 1
BlastMining:
Rank1:
Level: 0
BlastDamageDecrease: 1.0
OreBonus: 1.0
DebrisReduction: 1.0
DropMultiplier: 1
BlastRadiusModifier: 1
ect:
Level: 1
BlastDamageDecrease: 1.0
OreBonus: 1.0
DebrisReduction: 1.0
DropMultiplier: 1
BlastRadiusModifier: 1
Repair:
Rank1:
Level: 0
DowngradeChance: 1.0
KeepEnchantsChance: 1.0
ect:
Level: 1
DowngradeChance: 1.0
KeepEnchantsChance: 1.0