mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Add new child.yml config for picking parents of child skills
This commit is contained in:
parent
3607d0b9a1
commit
5026bdcbd4
@ -40,6 +40,7 @@ Version 1.4.00-dev
|
||||
+ Added config option to make .new config files instead over writing over old ones when updating
|
||||
+ Added "Holy Hound" ability to Taming
|
||||
+ Added "Shroom Thumb" ability to Herbalism
|
||||
+ Added child.yml config file to choose parents for child skills
|
||||
= Fixed Green Thumb on wheat not working properly at rank 4
|
||||
= Fixed Green Thumb and Green Terra consuming twice the amount of seed needed
|
||||
= Fixed Green Terra not also checking Green Thumb permissions
|
||||
|
@ -6,10 +6,12 @@ import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.Database;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.skills.utilities.AbilityType;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.skills.utilities.ToolType;
|
||||
@ -902,13 +904,12 @@ public class PlayerProfile {
|
||||
}
|
||||
|
||||
public int getChildSkillLevel(SkillType skillType) {
|
||||
switch (skillType) {
|
||||
case SMELTING:
|
||||
return ((getSkillLevel(SkillType.MINING) / 4) + (getSkillLevel(SkillType.REPAIR) / 4)); //TODO: Make this cleaner somehow
|
||||
|
||||
default:
|
||||
return 0;
|
||||
Set<SkillType> parents = FamilyTree.getParents(skillType);
|
||||
int sum = 0;
|
||||
for (SkillType parent : parents) {
|
||||
sum += Math.min(getSkillLevel(parent), 1000);
|
||||
}
|
||||
return sum / parents.size();
|
||||
}
|
||||
|
||||
public int getSkillXpLevel(SkillType skillType) {
|
||||
|
@ -44,6 +44,7 @@ import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.party.runnables.PartiesLoader;
|
||||
import com.gmail.nossr50.party.runnables.PartyAutoKick;
|
||||
import com.gmail.nossr50.runnables.SaveTimer;
|
||||
import com.gmail.nossr50.skills.child.ChildConfig;
|
||||
import com.gmail.nossr50.skills.repair.RepairManager;
|
||||
import com.gmail.nossr50.skills.repair.RepairManagerFactory;
|
||||
import com.gmail.nossr50.skills.repair.Repairable;
|
||||
@ -266,8 +267,7 @@ public class mcMMO extends JavaPlugin {
|
||||
TreasuresConfig.getInstance();
|
||||
HiddenConfig.getInstance();
|
||||
AdvancedConfig.getInstance();
|
||||
|
||||
|
||||
new ChildConfig();
|
||||
|
||||
List<Repairable> repairables = new ArrayList<Repairable>();
|
||||
|
||||
|
@ -0,0 +1,60 @@
|
||||
package com.gmail.nossr50.skills.child;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.gmail.nossr50.config.AutoUpdateConfigLoader;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
|
||||
public class ChildConfig extends AutoUpdateConfigLoader {
|
||||
public ChildConfig() {
|
||||
super("child.yml");
|
||||
loadKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
config.setDefaults(YamlConfiguration.loadConfiguration(plugin.getResource("child.yml")));
|
||||
|
||||
for (SkillType skill : SkillType.values()) {
|
||||
if (skill.isChildSkill()) {
|
||||
plugin.debug("Finding parents of " + skill.name());
|
||||
List<String> parentNames = config.getStringList(StringUtils.getCapitalized(skill.name()));
|
||||
EnumSet<SkillType> parentSkills = EnumSet.noneOf(SkillType.class);
|
||||
boolean useDefaults = false; // If we had an error we back out and use defaults
|
||||
for (String name : parentNames) {
|
||||
try {
|
||||
SkillType parentSkill = Enum.valueOf(SkillType.class, name.toUpperCase());
|
||||
FamilyTree.enforceNotChildSkill(parentSkill);
|
||||
parentSkills.add(parentSkill);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
plugin.getLogger().warning(name + " is not a valid skill type, or is a child skill!");
|
||||
useDefaults = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (useDefaults) {
|
||||
parentSkills.clear();
|
||||
for (String name : config.getDefaults().getStringList(StringUtils.getCapitalized(skill.name()))) {
|
||||
/* We do less checks in here because it's from inside our jar.
|
||||
* If they're dedicated enough to have modified it, they can have the errors it may produce.
|
||||
* Alternatively, this can be used to allow child skills to be parent skills, provided there are no circular dependencies this is an advanced sort of configuration.
|
||||
*/
|
||||
parentSkills.add(SkillType.valueOf(name.toUpperCase()));
|
||||
}
|
||||
}
|
||||
|
||||
// Register them
|
||||
for (SkillType parentSkill : parentSkills) {
|
||||
plugin.debug("Registering " + parentSkill.name() + " as parent of " + skill.name());
|
||||
FamilyTree.registerParent(skill, parentSkill);
|
||||
}
|
||||
}
|
||||
}
|
||||
FamilyTree.closeRegistration();
|
||||
}
|
||||
}
|
49
src/main/java/com/gmail/nossr50/skills/child/FamilyTree.java
Normal file
49
src/main/java/com/gmail/nossr50/skills/child/FamilyTree.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.gmail.nossr50.skills.child;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
|
||||
public class FamilyTree {
|
||||
private static HashMap<SkillType, Set<SkillType>> tree = new HashMap<SkillType, Set<SkillType>>();
|
||||
|
||||
public static Set<SkillType> getParents(SkillType childSkill) {
|
||||
enforceChildSkill(childSkill);
|
||||
|
||||
// We do not check if we have the child skill in question, as not having it would mean we did something wrong, and an NPE is desired.
|
||||
return tree.get(childSkill);
|
||||
}
|
||||
|
||||
protected static void registerParent(SkillType childSkill, SkillType parentSkill) {
|
||||
enforceChildSkill(childSkill);
|
||||
enforceNotChildSkill(parentSkill);
|
||||
|
||||
if (!tree.containsKey(childSkill)) {
|
||||
tree.put(childSkill, EnumSet.noneOf(SkillType.class));
|
||||
}
|
||||
|
||||
tree.get(childSkill).add(parentSkill);
|
||||
}
|
||||
|
||||
protected static void closeRegistration() {
|
||||
for (SkillType childSkill : tree.keySet()) {
|
||||
Set<SkillType> immutableSet = Collections.unmodifiableSet(tree.get(childSkill));
|
||||
tree.put(childSkill, immutableSet);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void enforceChildSkill(SkillType skill) {
|
||||
if (!skill.isChildSkill()) {
|
||||
throw new IllegalArgumentException(skill.name() + " is not a child skill!");
|
||||
}
|
||||
}
|
||||
|
||||
protected static void enforceNotChildSkill(SkillType skill) {
|
||||
if (skill.isChildSkill()) {
|
||||
throw new IllegalArgumentException(skill.name() + " is a child skill!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.gmail.nossr50.skills.smelting;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.FurnaceSmeltEvent;
|
||||
@ -7,6 +9,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@ -37,12 +40,11 @@ public class SmeltResourceEventHandler {
|
||||
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (Permissions.skillEnabled(player, SkillType.MINING)) {
|
||||
mcMMOPlayer.beginXpGain(SkillType.MINING, xp / 2);
|
||||
}
|
||||
|
||||
if (Permissions.skillEnabled(player, SkillType.REPAIR)) {
|
||||
mcMMOPlayer.beginXpGain(SkillType.REPAIR, xp / 2);
|
||||
Set<SkillType> parentSkills = FamilyTree.getParents(SkillType.SMELTING);
|
||||
for (SkillType parentSkill : parentSkills) {
|
||||
if (Permissions.skillEnabled(player, parentSkill)) {
|
||||
mcMMOPlayer.beginXpGain(parentSkill, xp / parentSkills.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
11
src/main/resources/child.yml
Normal file
11
src/main/resources/child.yml
Normal file
@ -0,0 +1,11 @@
|
||||
#
|
||||
# mcMMO child skill configuration
|
||||
# You do not need to modify this file except to change parents of child skills
|
||||
#
|
||||
# If you wish a child skill to be the parent of another child skill, you must also make your changes to the child.yml within the jar
|
||||
# WARNING: THIS IS NOT SUPPORTED, IF YOU DO SO YOU ARE RESPONSIBLE FOR THE ISSUES THAT MAY ARISE. That said, watch out for circular dependencies, those are bad.
|
||||
#
|
||||
#####
|
||||
Smelting:
|
||||
- Mining
|
||||
- Repair
|
Loading…
Reference in New Issue
Block a user