Wire up Party Config pt 2

This commit is contained in:
nossr50 2019-03-16 23:52:50 -07:00
parent 70b3ca3094
commit 82dec38e5c
16 changed files with 106 additions and 50 deletions

View File

@ -50,6 +50,7 @@ Version 2.2.0
Party's "Old_Party_Member_Cutoff" renamed -> "Offline-Day-Limit"
Added toggle to limit max party size, previously this was done by setting party maximum size above -1
Leveling your Party-Level now requires being near another party member by default
Leveling your Party now is no longer tied to player xp formula variables and instead uses its own parameters
Party members are now informed about your skill ups by default
Notification config options will now be found in "chat_and_hud_notifications.conf"

View File

@ -8,6 +8,7 @@ import com.gmail.nossr50.datatypes.party.PartyFeature;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
@ -119,7 +120,7 @@ public abstract class ChatCommand implements TabExecutor {
return;
}
if (chatMode == ChatMode.PARTY && (mcMMOPlayer.getParty().getLevel() < MainConfig.getInstance().getPartyFeatureUnlockLevel(PartyFeature.CHAT))) {
if (chatMode == ChatMode.PARTY && (mcMMOPlayer.getParty().getLevel() < PartyManager.getPartyFeatureUnlockLevel(PartyFeature.CHAT))) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.1"));
return;
}

View File

@ -29,7 +29,7 @@ public class PartyChatCommand extends ChatCommand {
return;
}
if (party.getLevel() < MainConfig.getInstance().getPartyFeatureUnlockLevel(PartyFeature.CHAT)) {
if (party.getLevel() < PartyManager.getPartyFeatureUnlockLevel(PartyFeature.CHAT)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.1"));
return;
}

View File

@ -79,7 +79,7 @@ public class PartyInfoCommand implements CommandExecutor {
}
private boolean isUnlockedFeature(Party party, PartyFeature partyFeature) {
return party.getLevel() >= MainConfig.getInstance().getPartyFeatureUnlockLevel(partyFeature);
return party.getLevel() >= PartyManager.getPartyFeatureUnlockLevel(partyFeature);
}
private void displayShareModeInfo(Player player, Party party) {

View File

@ -19,7 +19,7 @@ public class PartyItemShareCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Party party = UserManager.getPlayer((Player) sender).getParty();
if (party.getLevel() < MainConfig.getInstance().getPartyFeatureUnlockLevel(PartyFeature.ITEM_SHARE)) {
if (party.getLevel() < PartyManager.getPartyFeatureUnlockLevel(PartyFeature.ITEM_SHARE)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.4"));
return true;
}

View File

@ -18,7 +18,7 @@ public class PartyXpShareCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Party party = UserManager.getPlayer((Player) sender).getParty();
if (party.getLevel() < MainConfig.getInstance().getPartyFeatureUnlockLevel(PartyFeature.XP_SHARE)) {
if (party.getLevel() < PartyManager.getPartyFeatureUnlockLevel(PartyFeature.XP_SHARE)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.5"));
return true;
}

View File

@ -44,7 +44,7 @@ public class PartyAllianceCommand implements TabExecutor {
switch (args.length) {
case 1:
if (playerParty.getLevel() < MainConfig.getInstance().getPartyFeatureUnlockLevel(PartyFeature.ALLIANCE)) {
if (playerParty.getLevel() < PartyManager.getPartyFeatureUnlockLevel(PartyFeature.ALLIANCE)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.3"));
return true;
}
@ -62,7 +62,7 @@ public class PartyAllianceCommand implements TabExecutor {
case 2:
case 3:
if (playerParty.getLevel() < MainConfig.getInstance().getPartyFeatureUnlockLevel(PartyFeature.ALLIANCE)) {
if (playerParty.getLevel() < PartyManager.getPartyFeatureUnlockLevel(PartyFeature.ALLIANCE)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.3"));
return true;
}

View File

@ -68,7 +68,7 @@ public class PtpCommand implements TabExecutor {
Party party = mcMMOPlayer.getParty();
if (party.getLevel() < MainConfig.getInstance().getPartyFeatureUnlockLevel(PartyFeature.TELEPORT)) {
if (party.getLevel() < PartyManager.getPartyFeatureUnlockLevel(PartyFeature.TELEPORT)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.2"));
return true;
}

View File

@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.party.PartyFeature;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.StringUtils;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import org.bukkit.Material;
@ -329,7 +330,7 @@ public class MainConfig extends ConfigValidated {
}
/* PARTY SETTINGS */
if (getAutoPartyKickInterval() < -1) {
/*if (getAutoPartyKickInterval() < -1) {
reason.add(PARTY + "." + AUTO_KICK_INTERVAL + " should be at least -1!");
}
@ -351,17 +352,17 @@ public class MainConfig extends ConfigValidated {
if (getPartyShareRange() <= 0) {
reason.add(PARTY + "." + SHARING + "." + RANGE + " should be greater than 0!");
}
}*/
if (getPartyXpCurveMultiplier() < 1) {
/*if (getPartyXpCurveMultiplier() < 1) {
reason.add(PARTY + "." + LEVELING + "." + XP_CURVE_MODIFIER + " should be at least 1!");
}
for (PartyFeature partyFeature : PartyFeature.values()) {
if (getPartyFeatureUnlockLevel(partyFeature) < 0) {
if (PartyManager. < 0) {
reason.add(PARTY + "." + LEVELING + "." + StringUtils.getPrettyPartyFeatureString(partyFeature).replace(" ", "") + "_UnlockLevel should be at least 0!");
}
}
}*/
/* Inspect command distance */
if (getInspectDistance() <= 0) {
@ -697,23 +698,6 @@ public class MainConfig extends ConfigValidated {
/* PARTY SETTINGS */
//TODO: Move this to Experience Config
public int getPartyXpCurveMultiplier() {
return getIntValue(PARTY, LEVELING, XP_CURVE_MODIFIER);
}
public boolean getPartyXpNearMembersNeeded() {
return getBooleanValue(PARTY, LEVELING, NEAR_MEMBERS_NEEDED);
}
public boolean getPartyInformAllMembers() {
return getBooleanValue(PARTY, LEVELING, INFORM_ALL_PARTY_MEMBERS_ON_LEVEL_UP);
}
public int getPartyFeatureUnlockLevel(PartyFeature partyFeature) {
return getIntValue(PARTY, LEVELING, StringUtils.getPrettyPartyFeatureString(partyFeature).replace(" ", "") + UNLOCK_LEVEL);
}
/* Party Teleport Settings */
public int getPTPCommandCooldown() {
return getIntValue(COMMANDS, PTP, COOLDOWN);

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.config.hocon.party;
import com.gmail.nossr50.datatypes.party.PartyFeature;
import com.google.common.collect.Maps;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ -21,8 +22,25 @@ public class ConfigSectionPartyLevel {
PARTY_FEATURE_MAP_DEFAULT.put(PartyFeature.CHAT, 1);
}
@Setting(value = "Party-XP-Rate-Multiplier")
private int partyXpCurveMultiplier = 3;
/*
int base = ExperienceConfig.getInstance().getBase(FormulaType.EXPONENTIAL);
double multiplier = ExperienceConfig.getInstance().getMultiplier(FormulaType.EXPONENTIAL);
double exponent = ExperienceConfig.getInstance().getExponent(FormulaType.EXPONENTIAL);
if (!experienceNeededExponential.containsKey(level)) {
experience = (int) Math.floor((multiplier * Math.pow(level, exponent) + base));
experience *= mcMMO.getConfigManager().getConfigParty().getPartyXP().getPartyLevel().getPartyXpCurveMultiplier();
experienceNeededExponential.put(level, experience);
}
*/
@Setting(value = "Party-XP-Formula-Multiplier",
comment = "The Party XP Formula is borrowed from the Player XP formula to help determine the amount of XP needed to level the party." +
"\nThe Party XP Formula used to be based on your settings for player XP formula but I have separated it from those settings." +
"\nThe Party XP Curve Multiplier takes the final result of calculating one level of XP and multiplies it by this value to get the amount of XP needed to level the party." +
"\nParty Leveling used to have a level cap, I have removed this level cap as part of a feature request. It seems fun to level up parties indefinitely." +
"\nParty Leveling is now using exponential level scaling by default.")
private int partyXpCurveMultiplier = 10;
@Setting(value = "Party-Leveling-Requires-Nearby-Party-Members")
private boolean partyLevelingNeedsNearbyMembers = true;
@ -33,10 +51,6 @@ public class ConfigSectionPartyLevel {
@Setting(value = "Party-Feature-Unlock-Level-Requirements")
private Map<PartyFeature, Integer> partyFeatureUnlockMap = PARTY_FEATURE_MAP_DEFAULT;
public static HashMap<PartyFeature, Integer> getPartyFeatureMapDefault() {
return PARTY_FEATURE_MAP_DEFAULT;
}
public int getPartyXpCurveMultiplier() {
return partyXpCurveMultiplier;
}
@ -49,7 +63,7 @@ public class ConfigSectionPartyLevel {
return informPartyMembersOnLevelup;
}
public Map<PartyFeature, Integer> getPartyFeatureUnlockMap() {
return partyFeatureUnlockMap;
public HashMap<PartyFeature, Integer> getPartyFeatureUnlockMap() {
return Maps.newHashMap(partyFeatureUnlockMap);
}
}

View File

@ -192,7 +192,7 @@ public class Party {
public int getXpToLevel() {
FormulaType formulaType = ExperienceConfig.getInstance().getFormulaType();
return (mcMMO.getFormulaManager().getCachedXpToLevel(level, formulaType)) * (getOnlineMembers().size() + MainConfig.getInstance().getPartyXpCurveMultiplier());
return mcMMO.getFormulaManager().getPartyCachedXpToLevel(level);
}
public String getXpToLevelPercentage() {
@ -231,7 +231,7 @@ public class Party {
return;
}
if (!MainConfig.getInstance().getPartyInformAllMembers()) {
if (!mcMMO.getConfigManager().getConfigParty().getPartyXP().getPartyLevel().isInformPartyMembersOnLevelup()) {
Player leader = mcMMO.p.getServer().getPlayer(this.leader.getUniqueId());
if (leader != null) {

View File

@ -19,7 +19,7 @@ public enum PartyFeature {
}
public String getFeatureLockedLocaleString() {
return LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Party.Feature.Locked." + StringUtils.getPrettyPartyFeatureString(this).replace(" ", ""), MainConfig.getInstance().getPartyFeatureUnlockLevel(this)));
return LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Party.Feature.Locked." + StringUtils.getPrettyPartyFeatureString(this).replace(" ", ""), PartyManager.getPartyFeatureUnlockLevel(this)));
}
public boolean hasPermission(Player player) {

View File

@ -500,7 +500,7 @@ public class McMMOPlayer {
return;
}
if (!MainConfig.getInstance().getPartyXpNearMembersNeeded() || !PartyManager.getNearMembers(this).isEmpty()) {
if (!mcMMO.getConfigManager().getConfigParty().getPartyXP().getPartyLevel().isPartyLevelingNeedsNearbyMembers() || !PartyManager.getNearMembers(this).isEmpty()) {
party.applyXpGain(modifyXpGain(skill, xp));
}
}

View File

@ -7,10 +7,13 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.config.hocon.database.ConfigSectionCleaning;
import com.gmail.nossr50.config.hocon.database.ConfigSectionMySQL;
import com.gmail.nossr50.config.hocon.party.ConfigSectionPartyExperienceSharing;
import com.gmail.nossr50.config.hocon.party.ConfigSectionPartyLevel;
import com.gmail.nossr50.config.hocon.party.ConfigSectionPartyLimit;
import com.gmail.nossr50.config.hocon.playerleveling.ConfigLeveling;
import com.gmail.nossr50.config.hocon.scoreboard.ConfigScoreboard;
import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.database.DatabaseManagerFactory;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.subskills.acrobatics.Roll;
import com.gmail.nossr50.listeners.*;
@ -137,6 +140,7 @@ public class mcMMO extends JavaPlugin {
registerCustomRecipes();
PartyManager.loadParties();
PartyManager.reloadPartyFeatureHashMap();
formulaManager = new FormulaManager();
holidayManager = new HolidayManager();
@ -336,6 +340,15 @@ public class mcMMO extends JavaPlugin {
return configManager.getConfigParty().getPartyXP().getPartyExperienceSharing();
}
/**
* Returns settings for Party Leveling from the users config
* @return settings for the Party Leveling from the users config
*/
public static ConfigSectionPartyLevel getPartyLevelSettings()
{
return configManager.getConfigParty().getPartyXP().getPartyLevel();
}
/**
* Returns settings for Scoreboards from the users config
* @return settings for Scoreboards from the users config

View File

@ -3,10 +3,7 @@ package com.gmail.nossr50.party;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.datatypes.chat.ChatMode;
import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.party.ItemShareType;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.party.PartyLeader;
import com.gmail.nossr50.datatypes.party.ShareMode;
import com.gmail.nossr50.datatypes.party.*;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyAllianceChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
@ -24,19 +21,35 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.*;
import java.util.Map.Entry;
import java.util.UUID;
public final class PartyManager {
private static String partiesFilePath = mcMMO.getFlatFileDirectory() + "parties.yml";
private static List<Party> parties = new ArrayList<Party>();
private static File partyFile = new File(partiesFilePath);
private static HashMap<PartyFeature, Integer> partyFeatureUnlockMap;
private PartyManager() {}
/**
* Sets the unlock feature map for parties to the currently loaded hash map representation from the User's Config File
*/
public static void reloadPartyFeatureHashMap()
{
partyFeatureUnlockMap = mcMMO.getPartyLevelSettings().getPartyFeatureUnlockMap();
}
/**
* Grab the appropriate unlock level for a party feature
* @param partyFeature target party feature
* @return the unlock level for the feature
*/
public static int getPartyFeatureUnlockLevel(PartyFeature partyFeature)
{
return partyFeatureUnlockMap.get(partyFeature);
}
/**
* Check if a party with a given name already exists.
*

View File

@ -156,6 +156,36 @@ public class FormulaManager {
}
}
/**
* Get the cached amount of experience needed to reach the next party level,
* if cache doesn't contain the given value it is calculated and added
* to the cached data.
*
* Parties use the exponential leveling formula
*
* @param level level to check
* @return amount of experience needed to reach next level
*/
public int getPartyCachedXpToLevel(int level) {
int experience;
/**
* Retro mode XP requirements are the default requirements
* Standard mode XP requirements are multiplied by a factor of 10
*/
int base = ExperienceConfig.getInstance().getBase(FormulaType.EXPONENTIAL);
double multiplier = ExperienceConfig.getInstance().getMultiplier(FormulaType.EXPONENTIAL);
double exponent = ExperienceConfig.getInstance().getExponent(FormulaType.EXPONENTIAL);
if (!experienceNeededExponential.containsKey(level)) {
experience = (int) Math.floor((multiplier * Math.pow(level, exponent) + base));
experience *= mcMMO.getConfigManager().getConfigParty().getPartyXP().getPartyLevel().getPartyXpCurveMultiplier();
experienceNeededExponential.put(level, experience);
}
return experienceNeededExponential.get(level);
}
/**
* Load formula file.
*/