Added some JSON, much more to come.

This commit is contained in:
nossr50
2019-01-02 08:06:18 -08:00
parent 336e41b40c
commit ebec5d6f70
31 changed files with 473 additions and 278 deletions

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.util;
import java.text.DecimalFormat;
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
@ -36,6 +37,8 @@ public final class Motd {
public static void displayVersion(Player player, String version) {
if (Permissions.showversion(player)) {
player.sendMessage(LocaleLoader.getString("MOTD.Version", version));
//TODO: Remove this at release
player.sendMessage(ChatColor.YELLOW + "You're playing an "+ ChatColor.RED +"UNSTABLE" +ChatColor.YELLOW+" version of mcMMO! 2.1.0 is making many changes and if you are playing dev-snapshot you know the risks!");
}
}

View File

@ -0,0 +1,84 @@
package com.gmail.nossr50.util;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.SubSkill;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.RankUtils;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
import java.util.HashMap;
public class SkillTextComponentFactory {
public static HashMap<SubSkill, TextComponent> subSkillTextComponents;
public static HashMap<SubSkill, BaseComponent[]> subSkillHoverComponents;
public static TextComponent getSubSkillTextComponent(Player player, SubSkill subSkill, int localeKeyName, int localeKeyDescription)
{
boolean playerHasUnlocked = false;
//Init our maps
if (subSkillTextComponents == null)
{
subSkillTextComponents = new HashMap<>();
subSkillHoverComponents = new HashMap<>();
}
int curRank = RankUtils.getRank(player, subSkill);
if(curRank > 0)
playerHasUnlocked = true;
//The skill milestone holds relevant information about the ranks of a skill
PlayerProfile playerProfile = UserManager.getPlayer(player).getProfile();
//Get skill name & description from our locale file
String skillName = LocaleLoader.getString(subSkill.getLocalKeyRoot()+localeKeyName);
String skillDescription = LocaleLoader.getString(subSkill.getLocalKeyRoot()+localeKeyDescription);
if(subSkillTextComponents.get(subSkill) == null)
{
//Setup Text Component
TextComponent textComponent = new TextComponent(skillName);
textComponent.setColor(ChatColor.DARK_AQUA);
//Hover Event
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getBaseComponent(player, subSkill, skillName, skillDescription, curRank, playerHasUnlocked)));
//Insertion
textComponent.setInsertion(skillName);
subSkillTextComponents.put(subSkill, textComponent);
return subSkillTextComponents.get(subSkill);
} else {
return subSkillTextComponents.get(subSkill);
}
}
private static BaseComponent[] getBaseComponent(Player player, SubSkill subSkill, String skillName, String skillDescription, int curRank, boolean playerHasUnlocked)
{
if(subSkillHoverComponents.get(subSkill) != null)
{
return subSkillHoverComponents.get(subSkill);
}
BaseComponent[] newComponents;
//TODO: Clean this up
if(subSkill.getNumRanks() == 0)
newComponents = new ComponentBuilder(skillName).bold(true).color(ChatColor.GOLD).append("\n\nDescription").bold(true).color(ChatColor.GREEN).append("\n"+skillDescription).bold(false).color(ChatColor.WHITE).create();
else if(playerHasUnlocked)
newComponents = new ComponentBuilder(skillName).bold(true).color(ChatColor.GOLD).append("\nRank "+curRank).bold(false).color(ChatColor.GREEN).append(" of ").color(ChatColor.WHITE).append(String.valueOf(subSkill.getNumRanks())).color(ChatColor.GOLD).append("\n\nDescription").bold(true).color(ChatColor.GREEN).append("\n"+skillDescription).bold(false).color(ChatColor.WHITE).create();
else
newComponents = new ComponentBuilder(skillName).bold(true).color(ChatColor.RED).append("\n-=LOCKED=-").color(ChatColor.GRAY).append("\n\nUnlock Requirements").color(ChatColor.YELLOW).append("\nLevel "+ AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkill, 1)+" "+subSkill.getParentNiceNameLocale()).bold(false).create();
subSkillHoverComponents.put(subSkill, newComponents);
return subSkillHoverComponents.get(subSkill);
}
}

View File

@ -0,0 +1,100 @@
package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.skills.SubSkill;
import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.entity.Player;
import java.util.HashMap;
public class RankUtils {
public static HashMap<SubSkill, HashMap<Integer, Integer>> subSkillRanks;
/**
* Adds ranks to subSkillRanks for target SubSkill
* @param subSkill Target SubSkill
*/
private static void addRanks(SubSkill subSkill) {
int numRanks = subSkill.getNumRanks();
//Fill out the rank array
for(int i = 0; i < numRanks; i++)
{
//This adds the highest ranks first
addRank(subSkill, numRanks-i);
}
}
/**
* Gets the current rank of the subskill for the player
* @param player The player in question
* @param subSkill Target subskill
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
*/
public static int getRank(Player player, SubSkill subSkill)
{
if(subSkillRanks == null)
subSkillRanks = new HashMap<>();
if(subSkill.getNumRanks() == 0)
return -1; //-1 Means the skill doesn't have ranks
if(subSkillRanks.get(subSkill) == null && subSkill.getNumRanks() > 0)
addRanks(subSkill);
//Get our rank map
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkill);
//Skill level of parent skill
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(subSkill.getParentSkill());
for(int i = 0; i < subSkill.getNumRanks(); i++)
{
//Compare against the highest to lowest rank in that order
int rank = subSkill.getNumRanks()-i;
//System.out.println("Checking rank "+rank+" of "+subSkill.getNumRanks());
int unlockLevel = getUnlockLevel(subSkill, rank);
//System.out.println("Rank "+rank+" -- Unlock level: "+unlockLevel);
//System.out.println("Rank" +rank+" -- Player Skill Level: "+currentSkillLevel);
//If we check all ranks and still cannot unlock the skill, we return rank 0
if(rank == 0)
return 0;
//True if our skill level can unlock the current rank
if(currentSkillLevel >= unlockLevel)
return rank;
}
return 0; //We should never reach this
}
/**
* Adds ranks to our map
* @param subSkill The subskill to add ranks for
* @param rank The rank to add
*/
private static void addRank(SubSkill subSkill, int rank)
{
if(subSkillRanks == null)
subSkillRanks = new HashMap<>();
if(subSkillRanks.get(subSkill) == null)
subSkillRanks.put(subSkill, new HashMap<>());
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkill);
rankMap.put(rank, getUnlockLevel(subSkill, rank));
}
/**
* Gets the unlock level for a specific rank in a subskill
* @param subSkill The target subskill
* @param rank The target rank
* @return The level at which this rank unlocks
*/
private static int getUnlockLevel(SubSkill subSkill, int rank)
{
return AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkill, rank);
}
}

View File

@ -1,55 +0,0 @@
package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.datatypes.skills.SkillMilestone;
import com.gmail.nossr50.datatypes.skills.SubSkill;
import java.util.HashMap;
/**
* This Factory class builds SkillMilestone chains as needed
* SkillMilestones are stored in a hash map
*/
public class SkillMilestoneFactory {
private static HashMap<SubSkill, SkillMilestone> skillMilestoneMap;
/**
* Gets a the SkillMilestone chain for this subskill
* Builds that chain if it doesn't exist before returning the parent node
* @param subSkill The SubSkill to get the SkillMilestone chain for
* @return The parent node of the SkillMilestone chain for the target subskill
*/
public static SkillMilestone getSkillMilestone(SubSkill subSkill)
{
//Init the map
if(skillMilestoneMap == null)
skillMilestoneMap = new HashMap<>();
if(skillMilestoneMap.get(subSkill) == null)
return buildSkillMilestone(subSkill);
else
return skillMilestoneMap.get(subSkill);
}
/**
* Constructs a SkillMilestone chain for a given subskill
* @param subSkill The subskill to build the SkillMilestone chain for
* @return The base node of the SkillMilestone chain
*/
private static SkillMilestone buildSkillMilestone(SubSkill subSkill)
{
//Init our parent node
SkillMilestone newSkillMilestone = new SkillMilestone(subSkill, AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkill, 1));
//There's probably a better way to do this
for(int x = 0; x < subSkill.getNumRanks()-1; x++)
{
newSkillMilestone.addChildMilestone();
}
//DEBUG
System.out.println("Milestone constructed for "+subSkill);
return skillMilestoneMap.put(subSkill, newSkillMilestone);
}
}

View File

@ -1,33 +0,0 @@
package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.datatypes.skills.SubSkill;
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
import java.util.HashMap;
/**
* This class will handle the following things
* 1) Informing the player of important milestones in a skill (Every 5 levels)
* 2) Getting lists of milestones (skill unlocks) a player has
* 3) Propagating events for milestones (API)
*
* By setting up a skill milestone system it will make managing the audio/visual feedback for progression a lot easier
*
*/
//TODO: Inform players of milestones
//TODO: Helper methods for getting milestones
//TODO: Propagate events when milestones are achieved
//TODO: Update existing parts of the codebase to use this where appropriate
public class SkillMilestoneManager {
public static final HashMap<PrimarySkill, SubSkill> subskillMilestones;
static {
//Init our maps
subskillMilestones = new HashMap<>();
for(PrimarySkill primarySkill : PrimarySkill.values())
{
//TODO: Setup these values
}
}
}