mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-02 20:45:28 +02:00
Unlimited custom xp perks Part 1
This commit is contained in:
@@ -307,10 +307,14 @@ public final class ConfigManager {
|
||||
customSerializers = TypeSerializers.getDefaultSerializers().newChild();
|
||||
|
||||
mcMMO.p.getLogger().info("Registering custom type serializers for Configurate...");
|
||||
customSerializers.registerType(new TypeToken<PrimarySkillType>() {}, new CustomEnumValueSerializer());
|
||||
customSerializers.registerType(new TypeToken<Material>() {}, new CustomEnumValueSerializer());
|
||||
customSerializers.registerType(new TypeToken<PartyFeature>() {}, new CustomEnumValueSerializer());
|
||||
customSerializers.registerType(new TypeToken<FormulaType>() {}, new CustomEnumValueSerializer());
|
||||
customSerializers.registerType(new TypeToken<PrimarySkillType>() {
|
||||
}, new CustomEnumValueSerializer());
|
||||
customSerializers.registerType(new TypeToken<Material>() {
|
||||
}, new CustomEnumValueSerializer());
|
||||
customSerializers.registerType(new TypeToken<PartyFeature>() {
|
||||
}, new CustomEnumValueSerializer());
|
||||
customSerializers.registerType(new TypeToken<FormulaType>() {
|
||||
}, new CustomEnumValueSerializer());
|
||||
customSerializers.registerType(TypeToken.of(Repairable.class), new RepairableSerializer());
|
||||
customSerializers.registerType(TypeToken.of(Salvageable.class), new SalvageableSerializer());
|
||||
customSerializers.registerType(TypeToken.of(MinecraftMaterialWrapper.class), new MinecraftMaterialWrapperSerializer());
|
||||
|
@@ -0,0 +1,62 @@
|
||||
package com.gmail.nossr50.config.hocon;
|
||||
|
||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||
import com.gmail.nossr50.datatypes.experience.CustomXPPerk;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.google.common.reflect.TypeResolver;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class CustomXPPerkSerializer implements TypeSerializer<CustomXPPerk> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CustomXPPerk deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
String perkName = value.getNode("name").getValue(TypeToken.of(String.class));
|
||||
CustomXPPerk customXPPerk = new CustomXPPerk(perkName);
|
||||
|
||||
//See if any children nodes match skills by name
|
||||
for(ConfigurationNode configurationNode : value.getChildrenList())
|
||||
{
|
||||
try {
|
||||
PrimarySkillType primarySkillType = matchIgnoreCase(configurationNode.getValue(TypeToken.of(String.class)));
|
||||
float boostValue = configurationNode.getNode("XP-Multiplier").getValue(TypeToken.of(Float.class));
|
||||
customXPPerk.setCustomXPValue(primarySkillType, boostValue);
|
||||
} catch (InvalidSkillException e) {
|
||||
mcMMO.p.getLogger().info("Custom XP perk has a skill defined that was not found, did you misspell it?");
|
||||
e.printStackTrace();
|
||||
} catch (ObjectMappingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return customXPPerk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NonNull TypeToken<?> type, @Nullable CustomXPPerk obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
|
||||
|
||||
}
|
||||
|
||||
private PrimarySkillType matchIgnoreCase(String string) throws InvalidSkillException
|
||||
{
|
||||
for(PrimarySkillType primarySkillType : PrimarySkillType.values())
|
||||
{
|
||||
if(string.equalsIgnoreCase(primarySkillType.toString()))
|
||||
return primarySkillType;
|
||||
}
|
||||
|
||||
throw new InvalidSkillException();
|
||||
}
|
||||
|
||||
/*
|
||||
CustomXPPerk customXPPerk = new CustomXPPerk("examplecustomxpperk");
|
||||
customXPPerk.setCustomXPValue(PrimarySkillType.MINING, 13.37f);
|
||||
customXPPerk.setCustomXPValue(PrimarySkillType.WOODCUTTING, 4.0f);
|
||||
*/
|
||||
}
|
@@ -1,9 +1,11 @@
|
||||
package com.gmail.nossr50.config.hocon.experience;
|
||||
|
||||
import com.gmail.nossr50.datatypes.experience.CustomXPPerk;
|
||||
import ninja.leaping.configurate.objectmapping.Setting;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
@ConfigSerializable
|
||||
public class ConfigExperience {
|
||||
@@ -21,10 +23,21 @@ public class ConfigExperience {
|
||||
@Setting(value = "Skill-XP-Settings", comment = "XP values and multipliers for each skill")
|
||||
private ConfigExperienceSkills configExperienceSkills = new ConfigExperienceSkills();
|
||||
|
||||
@Setting(value = "Skill-XP-Perks", comment = "Define a set of custom XP boosts given to players with matching permission nodes.")
|
||||
private ConfigExperienceCustomBoosts configExperienceCustomBoosts = new ConfigExperienceCustomBoosts();
|
||||
|
||||
/*
|
||||
* BOILER PLATE GETTERS
|
||||
*/
|
||||
|
||||
public HashSet<CustomXPPerk> getCustomXPBoosts() {
|
||||
return configExperienceCustomBoosts.getCustomXPBoosts();
|
||||
}
|
||||
|
||||
public ConfigExperienceCustomBoosts getConfigExperienceCustomBoosts() {
|
||||
return configExperienceCustomBoosts;
|
||||
}
|
||||
|
||||
public ConfigExperienceSkillMultiplier getConfigExperienceSkillMultiplier() {
|
||||
return configExperienceSkillMultiplier;
|
||||
}
|
||||
|
@@ -0,0 +1,31 @@
|
||||
package com.gmail.nossr50.config.hocon.experience;
|
||||
|
||||
import com.gmail.nossr50.datatypes.experience.CustomXPPerk;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import ninja.leaping.configurate.objectmapping.Setting;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
@ConfigSerializable
|
||||
public class ConfigExperienceCustomBoosts {
|
||||
|
||||
private static final HashSet<CustomXPPerk> CUSTOM_BOOST_SET_DEFAULT;
|
||||
|
||||
static {
|
||||
CUSTOM_BOOST_SET_DEFAULT = new HashSet<>();
|
||||
CustomXPPerk customXPPerk = new CustomXPPerk("examplecustomxpperk");
|
||||
customXPPerk.setCustomXPValue(PrimarySkillType.MINING, 13.37f);
|
||||
customXPPerk.setCustomXPValue(PrimarySkillType.WOODCUTTING, 4.0f);
|
||||
CUSTOM_BOOST_SET_DEFAULT.add(customXPPerk);
|
||||
}
|
||||
|
||||
@Setting(value = "Custom-Global-XP-Permissions", comment = "You can give custom global xp perks to players by adding 'mcmmo.customperks.xp.<PERK NAME HERE>' to your players" +
|
||||
"\nEnter the name of a permission node and the value of the XP boost that permission node should have." +
|
||||
"\nPlayers do not benefit from custom xp perks without being assigned positive permission nodes for said xp perks")
|
||||
private HashSet<CustomXPPerk> customXPBoosts = CUSTOM_BOOST_SET_DEFAULT;
|
||||
|
||||
public HashSet<CustomXPPerk> getCustomXPBoosts() {
|
||||
return customXPBoosts;
|
||||
}
|
||||
}
|
@@ -13,12 +13,11 @@ public class ConfigExperienceSkillMultiplier {
|
||||
|
||||
static {
|
||||
SKILL_GLOBAL_MULT_DEFAULT = new HashMap<>();
|
||||
for(PrimarySkillType primarySkillType : PrimarySkillType.values())
|
||||
{
|
||||
if(primarySkillType.isChildSkill())
|
||||
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (primarySkillType.isChildSkill())
|
||||
continue;
|
||||
|
||||
SKILL_GLOBAL_MULT_DEFAULT.put(primarySkillType,1.0D);
|
||||
SKILL_GLOBAL_MULT_DEFAULT.put(primarySkillType, 1.0D);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -15,9 +15,8 @@ public class ConfigExperienceFormula {
|
||||
|
||||
static {
|
||||
SKILL_FORMULA_MODIFIER_DEFAULT = new HashMap<>();
|
||||
for(PrimarySkillType primarySkillType : PrimarySkillType.values())
|
||||
{
|
||||
if(primarySkillType.isChildSkill())
|
||||
for (PrimarySkillType primarySkillType : PrimarySkillType.values()) {
|
||||
if (primarySkillType.isChildSkill())
|
||||
continue;
|
||||
|
||||
SKILL_FORMULA_MODIFIER_DEFAULT.put(primarySkillType, 1.0D);
|
||||
|
@@ -10,13 +10,13 @@ public class ConfigLevelEarlyGameBoost {
|
||||
public static final double BOOST_MULTIPLIER_DEFAULT = 0.05D;
|
||||
|
||||
@Setting(value = "Enabled", comment = "If set to true, the early game XP boost will be applied." +
|
||||
"\nDefault value: "+EARLY_GAME_BOOST_DEFAULT)
|
||||
"\nDefault value: " + EARLY_GAME_BOOST_DEFAULT)
|
||||
private boolean enableEarlyGameBoost = EARLY_GAME_BOOST_DEFAULT;
|
||||
|
||||
@Setting(value = "Max-Level-Percentage", comment = "This value is multiplied by a skills level cap to see determine when to stop giving a boost." +
|
||||
"\nLevels in mcMMO are not capped by default, so if the skill has no set level cap it will instead use the value 100 or 1000 (if in RetroMode)" +
|
||||
"\nWith default settings, this will result in the first 5 levels (or 50 in Retro) being boosted" +
|
||||
"\nDefault value: "+BOOST_MULTIPLIER_DEFAULT)
|
||||
"\nDefault value: " + BOOST_MULTIPLIER_DEFAULT)
|
||||
private double earlyGameBoostMultiplier = BOOST_MULTIPLIER_DEFAULT;
|
||||
|
||||
public double getEarlyGameBoostMultiplier() {
|
||||
|
Reference in New Issue
Block a user