mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
major optimizations to getting xp values for specific blocks
This commit is contained in:
parent
03c9dfda02
commit
ce18f3df97
@ -1,4 +1,5 @@
|
|||||||
Version 2.2.024
|
Version 2.2.024
|
||||||
|
Significant optimizations to the way mcMMO handles grabbing XP values for blocks
|
||||||
|
|
||||||
Version 2.2.023
|
Version 2.2.023
|
||||||
Compatibility with Minecraft 1.21.3
|
Compatibility with Minecraft 1.21.3
|
||||||
|
@ -1154,15 +1154,19 @@ public final class ExperienceAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given if it matches the given skillType
|
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given
|
||||||
|
* if it matches the given skillType
|
||||||
* @param blockStates the blocks to reward XP for
|
* @param blockStates the blocks to reward XP for
|
||||||
* @param mcMMOPlayer the target player
|
* @param mcMMOPlayer the target player
|
||||||
* @param skillType target primary skill
|
* @param skillType target primary skill
|
||||||
*/
|
*/
|
||||||
public static void addXpFromBlocksBySkill(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType) {
|
public static void addXpFromBlocksBySkill(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer,
|
||||||
|
PrimarySkillType skillType) {
|
||||||
for(BlockState bs : blockStates) {
|
for(BlockState bs : blockStates) {
|
||||||
if (ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0) {
|
if (ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0) {
|
||||||
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
|
mcMMOPlayer.applyXpGain(skillType,
|
||||||
|
ExperienceConfig.getInstance().getXp(skillType, bs.getType()),
|
||||||
|
XPGainReason.PVE, XPGainSource.SELF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1175,7 +1179,8 @@ public final class ExperienceAPI {
|
|||||||
public static void addXpFromBlock(BlockState blockState, McMMOPlayer mcMMOPlayer) {
|
public static void addXpFromBlock(BlockState blockState, McMMOPlayer mcMMOPlayer) {
|
||||||
for(PrimarySkillType skillType : PrimarySkillType.values()) {
|
for(PrimarySkillType skillType : PrimarySkillType.values()) {
|
||||||
if (ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0) {
|
if (ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0) {
|
||||||
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
|
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(
|
||||||
|
skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1188,7 +1193,8 @@ public final class ExperienceAPI {
|
|||||||
*/
|
*/
|
||||||
public static void addXpFromBlockBySkill(BlockState blockState, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType) {
|
public static void addXpFromBlockBySkill(BlockState blockState, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType) {
|
||||||
if (ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0) {
|
if (ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0) {
|
||||||
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
|
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()),
|
||||||
|
XPGainReason.PVE, XPGainSource.SELF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import com.gmail.nossr50.util.Misc;
|
|||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.text.StringUtils;
|
import com.gmail.nossr50.util.text.StringUtils;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.chat.SignedMessage;
|
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -6,7 +6,6 @@ import com.gmail.nossr50.util.skills.CombatUtils;
|
|||||||
import com.gmail.nossr50.util.skills.RankUtils;
|
import com.gmail.nossr50.util.skills.RankUtils;
|
||||||
import com.gmail.nossr50.util.text.TextComponentFactory;
|
import com.gmail.nossr50.util.text.TextComponentFactory;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -10,7 +10,6 @@ import com.gmail.nossr50.util.skills.RankUtils;
|
|||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||||
import com.gmail.nossr50.util.text.TextComponentFactory;
|
import com.gmail.nossr50.util.text.TextComponentFactory;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -5,7 +5,6 @@ import com.gmail.nossr50.util.skills.CombatUtils;
|
|||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||||
import com.gmail.nossr50.util.text.TextComponentFactory;
|
import com.gmail.nossr50.util.text.TextComponentFactory;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -711,7 +711,7 @@ public class GeneralConfig extends BukkitConfig {
|
|||||||
if (material.toString().equalsIgnoreCase("LILY_PAD"))
|
if (material.toString().equalsIgnoreCase("LILY_PAD"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return config.getBoolean("Bonus_Drops." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getPrettyItemString(material).replace(" ", "_"));
|
return config.getBoolean("Bonus_Drops." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getFormattedMaterialString(material).replace(" ", "_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getDoubleDropsDisabled(PrimarySkillType skill) {
|
public boolean getDoubleDropsDisabled(PrimarySkillType skill) {
|
||||||
@ -890,8 +890,9 @@ public class GeneralConfig extends BukkitConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Woodcutting */
|
/* Woodcutting */
|
||||||
public boolean getWoodcuttingDoubleDropsEnabled(BlockData material) {
|
public boolean getWoodcuttingDoubleDropsEnabled(BlockData blockData) {
|
||||||
return config.getBoolean("Bonus_Drops.Woodcutting." + StringUtils.getFriendlyConfigBlockDataString(material));
|
return config.getBoolean("Bonus_Drops.Woodcutting."
|
||||||
|
+ StringUtils.getFormattedMaterialString(blockData.getMaterial()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getTreeFellerSoundsEnabled() {
|
public boolean getTreeFellerSoundsEnabled() {
|
||||||
|
@ -15,10 +15,15 @@ import org.bukkit.boss.BarStyle;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.gmail.nossr50.util.skills.SkillTools.isChildSkill;
|
||||||
|
|
||||||
public class ExperienceConfig extends BukkitConfig {
|
public class ExperienceConfig extends BukkitConfig {
|
||||||
private static ExperienceConfig instance;
|
private static ExperienceConfig instance;
|
||||||
|
final private Map<PrimarySkillType, Map<Material, Integer>> blockExperienceMap = new HashMap<>();
|
||||||
|
|
||||||
private ExperienceConfig() {
|
private ExperienceConfig() {
|
||||||
super("experience.yml");
|
super("experience.yml");
|
||||||
@ -30,6 +35,23 @@ public class ExperienceConfig extends BukkitConfig {
|
|||||||
instance = new ExperienceConfig();
|
instance = new ExperienceConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (PrimarySkillType skill : PrimarySkillType.values()) {
|
||||||
|
// Skip child skills
|
||||||
|
if (isChildSkill(skill)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Map<Material, Integer> experienceMap = new HashMap<>();
|
||||||
|
for (Material material : Material.values()) {
|
||||||
|
int xp = instance.getConfigXp(skill, material);
|
||||||
|
|
||||||
|
if (xp > 0) {
|
||||||
|
experienceMap.put(material, xp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
instance.blockExperienceMap.put(skill, experienceMap);
|
||||||
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,15 +343,22 @@ public class ExperienceConfig extends BukkitConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Materials */
|
/* Materials */
|
||||||
|
private int getConfigXp(PrimarySkillType skill, Material material) {
|
||||||
|
// prevents exploit
|
||||||
|
if (material == Material.LILY_PAD)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
final String baseString = "Experience_Values." + StringUtils.getCapitalized(skill.toString()) + ".";
|
||||||
|
final String configPath = baseString + StringUtils.getFormattedMaterialString(material);
|
||||||
|
return config.getInt(configPath, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public int getXp(PrimarySkillType skill, Material material) {
|
public int getXp(PrimarySkillType skill, Material material) {
|
||||||
return getXpHelper(skill, StringUtils.getExplicitConfigMaterialString(material),
|
return blockExperienceMap.get(skill).getOrDefault(material, 0);
|
||||||
StringUtils.getFriendlyConfigMaterialString(material),
|
|
||||||
StringUtils.getWildcardConfigMaterialString(material));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getXp(PrimarySkillType skill, BlockState blockState) {
|
public int getXp(PrimarySkillType skill, BlockState blockState) {
|
||||||
Material material = blockState.getType();
|
return getXp(skill, blockState.getType());
|
||||||
return getXp(skill, material);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getXp(PrimarySkillType skill, Block block) {
|
public int getXp(PrimarySkillType skill, Block block) {
|
||||||
@ -338,57 +367,17 @@ public class ExperienceConfig extends BukkitConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getXp(PrimarySkillType skill, BlockData data) {
|
public int getXp(PrimarySkillType skill, BlockData data) {
|
||||||
return getXpHelper(skill, StringUtils.getExplicitConfigBlockDataString(data),
|
return getXp(skill, data.getMaterial());
|
||||||
StringUtils.getFriendlyConfigBlockDataString(data),
|
|
||||||
StringUtils.getWildcardConfigBlockDataString(data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getXpHelper(PrimarySkillType skill, String explicitString, String friendlyString, String wildcardString) {
|
|
||||||
if (explicitString.equalsIgnoreCase("LILY_PAD")) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
String baseString = "Experience_Values." + StringUtils.getCapitalized(skill.toString()) + ".";
|
|
||||||
String[] configStrings = {explicitString, friendlyString, wildcardString};
|
|
||||||
|
|
||||||
for (String configString : configStrings) {
|
|
||||||
String fullPath = baseString + configString;
|
|
||||||
if (config.contains(fullPath)) {
|
|
||||||
return config.getInt(fullPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean doesBlockGiveSkillXP(PrimarySkillType skill, Material material) {
|
public boolean doesBlockGiveSkillXP(PrimarySkillType skill, Material material) {
|
||||||
return doesBlockGiveSkillXPHelper(skill, StringUtils.getExplicitConfigMaterialString(material),
|
return getXp(skill, material) > 0;
|
||||||
StringUtils.getFriendlyConfigMaterialString(material),
|
|
||||||
StringUtils.getWildcardConfigMaterialString(material));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doesBlockGiveSkillXP(PrimarySkillType skill, BlockData data) {
|
public boolean doesBlockGiveSkillXP(PrimarySkillType skill, BlockData data) {
|
||||||
return doesBlockGiveSkillXPHelper(skill, StringUtils.getExplicitConfigBlockDataString(data),
|
return getXp(skill, data) > 0;
|
||||||
StringUtils.getFriendlyConfigBlockDataString(data),
|
|
||||||
StringUtils.getWildcardConfigBlockDataString(data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doesBlockGiveSkillXPHelper(PrimarySkillType skill, String explicitString, String friendlyString, String wildcardString) {
|
|
||||||
String baseString = "Experience_Values." + StringUtils.getCapitalized(skill.toString()) + ".";
|
|
||||||
String[] configStrings = {explicitString, friendlyString, wildcardString};
|
|
||||||
|
|
||||||
for (String configString : configStrings) {
|
|
||||||
String fullPath = baseString + configString;
|
|
||||||
if (config.contains(fullPath)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Experience Bar Stuff
|
* Experience Bar Stuff
|
||||||
*/
|
*/
|
||||||
|
@ -23,7 +23,7 @@ public class ItemWeightConfig extends BukkitConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getItemWeight(Material material) {
|
public int getItemWeight(Material material) {
|
||||||
return config.getInt("Item_Weights." + StringUtils.getPrettyItemString(material).replace(" ", "_"), config.getInt("Item_Weights.Default"));
|
return config.getInt("Item_Weights." + StringUtils.getFormattedMaterialString(material).replace(" ", "_"), config.getInt("Item_Weights.Default"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<Material> getMiscItems() {
|
public HashSet<Material> getMiscItems() {
|
||||||
|
@ -21,7 +21,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static com.gmail.nossr50.util.ItemUtils.setItemName;
|
import static com.gmail.nossr50.util.ItemUtils.setItemName;
|
||||||
import static com.gmail.nossr50.util.PotionUtil.*;
|
import static com.gmail.nossr50.util.PotionUtil.*;
|
||||||
|
@ -9,7 +9,6 @@ import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
|
|||||||
import com.gmail.nossr50.skills.salvage.salvageables.SalvageableFactory;
|
import com.gmail.nossr50.skills.salvage.salvageables.SalvageableFactory;
|
||||||
import com.gmail.nossr50.util.ItemUtils;
|
import com.gmail.nossr50.util.ItemUtils;
|
||||||
import com.gmail.nossr50.util.LogUtils;
|
import com.gmail.nossr50.util.LogUtils;
|
||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
@ -239,29 +239,29 @@ public class TreasureConfig extends BukkitConfig {
|
|||||||
|
|
||||||
for (String dropper : dropList) {
|
for (String dropper : dropList) {
|
||||||
if (dropper.equals("Bushes")) {
|
if (dropper.equals("Bushes")) {
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.FERN), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.FERN), hylianTreasure);
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(BlockUtils.getShortGrass()), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(BlockUtils.getShortGrass()), hylianTreasure);
|
||||||
for (Material species : Tag.SAPLINGS.getValues())
|
for (Material species : Tag.SAPLINGS.getValues())
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(species), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(species), hylianTreasure);
|
||||||
|
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.DEAD_BUSH), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.DEAD_BUSH), hylianTreasure);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (dropper.equals("Flowers")) {
|
if (dropper.equals("Flowers")) {
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.POPPY), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.POPPY), hylianTreasure);
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.DANDELION), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.DANDELION), hylianTreasure);
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.BLUE_ORCHID), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.BLUE_ORCHID), hylianTreasure);
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.ALLIUM), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.ALLIUM), hylianTreasure);
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.AZURE_BLUET), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.AZURE_BLUET), hylianTreasure);
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.ORANGE_TULIP), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.ORANGE_TULIP), hylianTreasure);
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.PINK_TULIP), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.PINK_TULIP), hylianTreasure);
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.RED_TULIP), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.RED_TULIP), hylianTreasure);
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(Material.WHITE_TULIP), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(Material.WHITE_TULIP), hylianTreasure);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (dropper.equals("Pots")) {
|
if (dropper.equals("Pots")) {
|
||||||
for (Material species : Tag.FLOWER_POTS.getValues())
|
for (Material species : Tag.FLOWER_POTS.getValues())
|
||||||
AddHylianTreasure(StringUtils.getFriendlyConfigMaterialString(species), hylianTreasure);
|
AddHylianTreasure(StringUtils.getFormattedMaterialString(species), hylianTreasure);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
AddHylianTreasure(dropper, hylianTreasure);
|
AddHylianTreasure(dropper, hylianTreasure);
|
||||||
|
@ -2,7 +2,6 @@ package com.gmail.nossr50.datatypes.player;
|
|||||||
|
|
||||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||||
import com.gmail.nossr50.chat.author.PlayerAuthor;
|
import com.gmail.nossr50.chat.author.PlayerAuthor;
|
||||||
import com.gmail.nossr50.config.AdvancedConfig;
|
|
||||||
import com.gmail.nossr50.config.ChatConfig;
|
import com.gmail.nossr50.config.ChatConfig;
|
||||||
import com.gmail.nossr50.config.WorldBlacklist;
|
import com.gmail.nossr50.config.WorldBlacklist;
|
||||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||||
|
@ -167,7 +167,7 @@ public enum SuperAbilityType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return StringUtils.getPrettyAbilityString(this);
|
return StringUtils.getPrettySuperAbilityString(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocalizedName() {
|
public String getLocalizedName() {
|
||||||
|
@ -27,7 +27,6 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
@ -45,8 +44,6 @@ import org.bukkit.potion.PotionEffect;
|
|||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.gmail.nossr50.util.AttributeMapper.MAPPED_MAX_HEALTH;
|
import static com.gmail.nossr50.util.AttributeMapper.MAPPED_MAX_HEALTH;
|
||||||
|
@ -34,7 +34,7 @@ public class AlchemyManager extends SkillManager {
|
|||||||
StringBuilder list = new StringBuilder();
|
StringBuilder list = new StringBuilder();
|
||||||
|
|
||||||
for (ItemStack ingredient : getIngredients()) {
|
for (ItemStack ingredient : getIngredients()) {
|
||||||
String string = StringUtils.getPrettyItemString(ingredient.getType());
|
String string = StringUtils.getFormattedMaterialString(ingredient.getType());
|
||||||
|
|
||||||
list.append(", ").append(string);
|
list.append(", ").append(string);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import com.gmail.nossr50.util.random.ProbabilityUtil;
|
|||||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
||||||
import com.gmail.nossr50.util.skills.RankUtils;
|
import com.gmail.nossr50.util.skills.RankUtils;
|
||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
|
@ -19,7 +19,7 @@ public class Excavation {
|
|||||||
* @return the list of treasures that could be found
|
* @return the list of treasures that could be found
|
||||||
*/
|
*/
|
||||||
protected static List<ExcavationTreasure> getTreasures(BlockState blockState) {
|
protected static List<ExcavationTreasure> getTreasures(BlockState blockState) {
|
||||||
String friendly = StringUtils.getFriendlyConfigBlockDataString(blockState.getBlockData());
|
String friendly = StringUtils.getFormattedMaterialString(blockState.getBlockData().getMaterial());
|
||||||
if (TreasureConfig.getInstance().excavationMap.containsKey(friendly))
|
if (TreasureConfig.getInstance().excavationMap.containsKey(friendly))
|
||||||
return TreasureConfig.getInstance().excavationMap.get(friendly);
|
return TreasureConfig.getInstance().excavationMap.get(friendly);
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
@ -113,7 +113,8 @@ public class HerbalismManager extends SkillManager {
|
|||||||
mmoPlayer.getPlayer().sendMessage("Bush Reward Multiplier: " + rewardByAge);
|
mmoPlayer.getPlayer().sendMessage("Bush Reward Multiplier: " + rewardByAge);
|
||||||
}
|
}
|
||||||
|
|
||||||
int xpReward = ExperienceConfig.getInstance().getXp(PrimarySkillType.HERBALISM, blockState) * rewardByAge;
|
int xpReward = ExperienceConfig.getInstance().getXp(PrimarySkillType.HERBALISM, blockState.getType())
|
||||||
|
* rewardByAge;
|
||||||
|
|
||||||
if (mmoPlayer.isDebugMode()) {
|
if (mmoPlayer.isDebugMode()) {
|
||||||
mmoPlayer.getPlayer().sendMessage("Bush XP: " + xpReward);
|
mmoPlayer.getPlayer().sendMessage("Bush XP: " + xpReward);
|
||||||
@ -713,12 +714,11 @@ public class HerbalismManager extends SkillManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String friendly = StringUtils.getFriendlyConfigBlockDataString(blockState.getBlockData());
|
final String friendly = StringUtils.getFormattedMaterialString(blockState.getBlockData().getMaterial());
|
||||||
if (!TreasureConfig.getInstance().hylianMap.containsKey(friendly))
|
if (!TreasureConfig.getInstance().hylianMap.containsKey(friendly))
|
||||||
return false;
|
return false;
|
||||||
List<HylianTreasure> treasures = TreasureConfig.getInstance().hylianMap.get(friendly);
|
List<HylianTreasure> treasures = TreasureConfig.getInstance().hylianMap.get(friendly);
|
||||||
|
|
||||||
|
|
||||||
if (treasures.isEmpty()) {
|
if (treasures.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -750,12 +750,12 @@ public class HerbalismManager extends SkillManager {
|
|||||||
PlayerInventory playerInventory = getPlayer().getInventory();
|
PlayerInventory playerInventory = getPlayer().getInventory();
|
||||||
|
|
||||||
if (!playerInventory.contains(Material.BROWN_MUSHROOM, 1)) {
|
if (!playerInventory.contains(Material.BROWN_MUSHROOM, 1)) {
|
||||||
NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.REQUIREMENTS_NOT_MET, "Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM));
|
NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.REQUIREMENTS_NOT_MET, "Skills.NeedMore", StringUtils.getFormattedMaterialString(Material.BROWN_MUSHROOM));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!playerInventory.contains(Material.RED_MUSHROOM, 1)) {
|
if (!playerInventory.contains(Material.RED_MUSHROOM, 1)) {
|
||||||
NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.REQUIREMENTS_NOT_MET, "Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM));
|
NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.REQUIREMENTS_NOT_MET, "Skills.NeedMore", StringUtils.getFormattedMaterialString(Material.RED_MUSHROOM));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class RepairManager extends SkillManager {
|
|||||||
|
|
||||||
// Level check
|
// Level check
|
||||||
if (skillLevel < minimumRepairableLevel) {
|
if (skillLevel < minimumRepairableLevel) {
|
||||||
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Repair.Skills.Adept", String.valueOf(minimumRepairableLevel), StringUtils.getPrettyItemString(item.getType()));
|
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Repair.Skills.Adept", String.valueOf(minimumRepairableLevel), StringUtils.getFormattedMaterialString(item.getType()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ public class RepairManager extends SkillManager {
|
|||||||
|
|
||||||
// Check if they have the proper material to repair with
|
// Check if they have the proper material to repair with
|
||||||
if (!inventory.contains(repairMaterial)) {
|
if (!inventory.contains(repairMaterial)) {
|
||||||
String prettyName = repairable.getRepairMaterialPrettyName() == null ? StringUtils.getPrettyItemString(repairMaterial) : repairable.getRepairMaterialPrettyName();
|
String prettyName = repairable.getRepairMaterialPrettyName() == null ? StringUtils.getFormattedMaterialString(repairMaterial) : repairable.getRepairMaterialPrettyName();
|
||||||
|
|
||||||
String materialsNeeded = "";
|
String materialsNeeded = "";
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ public class RepairManager extends SkillManager {
|
|||||||
|
|
||||||
// Fail out with "you need material" if we don't find a suitable alternative.
|
// Fail out with "you need material" if we don't find a suitable alternative.
|
||||||
if (possibleMaterial.isEmpty()) {
|
if (possibleMaterial.isEmpty()) {
|
||||||
String prettyName = repairable.getRepairMaterialPrettyName() == null ? StringUtils.getPrettyItemString(repairMaterial) : repairable.getRepairMaterialPrettyName();
|
String prettyName = repairable.getRepairMaterialPrettyName() == null ? StringUtils.getFormattedMaterialString(repairMaterial) : repairable.getRepairMaterialPrettyName();
|
||||||
|
|
||||||
String materialsNeeded = "";
|
String materialsNeeded = "";
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class SalvageManager extends SkillManager {
|
|||||||
if (getSkillLevel() < minimumSalvageableLevel) {
|
if (getSkillLevel() < minimumSalvageableLevel) {
|
||||||
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET,
|
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET,
|
||||||
"Salvage.Skills.Adept.Level",
|
"Salvage.Skills.Adept.Level",
|
||||||
String.valueOf(minimumSalvageableLevel), StringUtils.getPrettyItemString(item.getType()));
|
String.valueOf(minimumSalvageableLevel), StringUtils.getFormattedMaterialString(item.getType()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,11 +143,11 @@ public class SalvageManager extends SkillManager {
|
|||||||
|
|
||||||
// We only send a confirmation message after processing the event (fixes #4694)
|
// We only send a confirmation message after processing the event (fixes #4694)
|
||||||
if (lotteryResults == potentialSalvageYield && potentialSalvageYield != 1 && RankUtils.isPlayerMaxRankInSubSkill(player, SubSkillType.SALVAGE_ARCANE_SALVAGE)) {
|
if (lotteryResults == potentialSalvageYield && potentialSalvageYield != 1 && RankUtils.isPlayerMaxRankInSubSkill(player, SubSkillType.SALVAGE_ARCANE_SALVAGE)) {
|
||||||
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Perfect", String.valueOf(lotteryResults), StringUtils.getPrettyItemString(item.getType()));
|
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Perfect", String.valueOf(lotteryResults), StringUtils.getFormattedMaterialString(item.getType()));
|
||||||
} else if (salvageable.getMaximumQuantity() == 1 || getSalvageLimit() >= salvageable.getMaximumQuantity()) {
|
} else if (salvageable.getMaximumQuantity() == 1 || getSalvageLimit() >= salvageable.getMaximumQuantity()) {
|
||||||
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Normal", String.valueOf(lotteryResults), StringUtils.getPrettyItemString(item.getType()));
|
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Normal", String.valueOf(lotteryResults), StringUtils.getFormattedMaterialString(item.getType()));
|
||||||
} else {
|
} else {
|
||||||
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Untrained", String.valueOf(lotteryResults), StringUtils.getPrettyItemString(item.getType()));
|
NotificationManager.sendPlayerInformationChatOnly(player, "Salvage.Skills.Lottery.Untrained", String.valueOf(lotteryResults), StringUtils.getFormattedMaterialString(item.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
||||||
|
@ -23,7 +23,6 @@ import com.gmail.nossr50.util.sounds.SoundType;
|
|||||||
import com.gmail.nossr50.util.text.StringUtils;
|
import com.gmail.nossr50.util.text.StringUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -371,7 +370,7 @@ public class TamingManager extends SkillManager {
|
|||||||
} else {
|
} else {
|
||||||
//Player did not have enough of the item in their main hand
|
//Player did not have enough of the item in their main hand
|
||||||
int difference = tamingSummon.getItemAmountRequired() - itemInMainHand.getAmount();
|
int difference = tamingSummon.getItemAmountRequired() - itemInMainHand.getAmount();
|
||||||
NotificationManager.sendPlayerInformationChatOnly(player, "Taming.Summon.COTW.NeedMoreItems", String.valueOf(difference), StringUtils.getPrettyItemString(itemInMainHand.getType()));
|
NotificationManager.sendPlayerInformationChatOnly(player, "Taming.Summon.COTW.NeedMoreItems", String.valueOf(difference), StringUtils.getFormattedMaterialString(itemInMainHand.getType()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.gmail.nossr50.util;
|
package com.gmail.nossr50.util;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import org.bukkit.Registry;
|
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
@ -21,10 +21,8 @@ import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
|||||||
import com.gmail.nossr50.util.*;
|
import com.gmail.nossr50.util.*;
|
||||||
import com.gmail.nossr50.util.player.NotificationManager;
|
import com.gmail.nossr50.util.player.NotificationManager;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
@ -387,26 +387,6 @@ public class SkillTools {
|
|||||||
return pluginRef.getGeneralConfig().getMaxLength(superAbilityType);
|
return pluginRef.getGeneralConfig().getMaxLength(superAbilityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSuperAbilityOnLocaleKey(SuperAbilityType superAbilityType) {
|
|
||||||
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + ".On";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSuperAbilityOffLocaleKey(SuperAbilityType superAbilityType) {
|
|
||||||
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + ".Off";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSuperAbilityOtherPlayerActivationLocaleKey(SuperAbilityType superAbilityType) {
|
|
||||||
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + ".Other.On";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSuperAbilityOtherPlayerDeactivationLocaleKey(SuperAbilityType superAbilityType) {
|
|
||||||
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + "Other.Off";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSuperAbilityRefreshedLocaleKey(SuperAbilityType superAbilityType) {
|
|
||||||
return "SuperAbility." + StringUtils.getPrettyCamelCaseName(superAbilityType) + ".Refresh";
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLevelCap(@NotNull PrimarySkillType primarySkillType) {
|
public int getLevelCap(@NotNull PrimarySkillType primarySkillType) {
|
||||||
return mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType);
|
return mcMMO.p.getGeneralConfig().getLevelCap(primarySkillType);
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class SoundManager {
|
public class SoundManager {
|
||||||
public static Sound CRIPPLE_SOUND;
|
private static Sound CRIPPLE_SOUND;
|
||||||
static {
|
|
||||||
try {
|
|
||||||
CRIPPLE_SOUND = Sound.valueOf("ITEM_MACE_SMASH_GROUND");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
CRIPPLE_SOUND = Sound.BLOCK_ANVIL_PLACE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a sound to the player
|
* Sends a sound to the player
|
||||||
@ -107,10 +100,24 @@ public class SoundManager {
|
|||||||
case DEFLECT_ARROWS, BLEED -> Sound.ENTITY_ENDER_EYE_DEATH;
|
case DEFLECT_ARROWS, BLEED -> Sound.ENTITY_ENDER_EYE_DEATH;
|
||||||
case GLASS -> Sound.BLOCK_GLASS_BREAK;
|
case GLASS -> Sound.BLOCK_GLASS_BREAK;
|
||||||
case ITEM_CONSUMED -> Sound.ITEM_BOTTLE_EMPTY;
|
case ITEM_CONSUMED -> Sound.ITEM_BOTTLE_EMPTY;
|
||||||
case CRIPPLE -> CRIPPLE_SOUND;
|
case CRIPPLE -> getCrippleSound();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Sound getCrippleSound() {
|
||||||
|
if (CRIPPLE_SOUND != null) {
|
||||||
|
return CRIPPLE_SOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
CRIPPLE_SOUND = Sound.valueOf("ITEM_MACE_SMASH_GROUND");
|
||||||
|
return CRIPPLE_SOUND;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
CRIPPLE_SOUND = Sound.BLOCK_ANVIL_PLACE;
|
||||||
|
return CRIPPLE_SOUND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static float getFizzPitch() {
|
public static float getFizzPitch() {
|
||||||
return 2.6F + (Misc.getRandom().nextFloat() - Misc.getRandom().nextFloat()) * 0.8F;
|
return 2.6F + (Misc.getRandom().nextFloat() - Misc.getRandom().nextFloat()) * 0.8F;
|
||||||
}
|
}
|
||||||
|
@ -3,192 +3,217 @@ package com.gmail.nossr50.util.text;
|
|||||||
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
||||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.Ageable;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for String operations, including formatting and caching deterministic results to improve performance.
|
||||||
|
*/
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
|
|
||||||
protected static DecimalFormat percent = new DecimalFormat("##0.00%");
|
protected static final DecimalFormat percent = new DecimalFormat("##0.00%");
|
||||||
protected static DecimalFormat shortDecimal = new DecimalFormat("##0.0");
|
protected static final DecimalFormat shortDecimal = new DecimalFormat("##0.0");
|
||||||
|
|
||||||
|
// Using concurrent hash maps to avoid concurrency issues (Folia)
|
||||||
|
private static final Map<EntityType, String> formattedEntityStrings = new HashMap<>();
|
||||||
|
private static final Map<SuperAbilityType, String> formattedSuperAbilityStrings = new HashMap<>();
|
||||||
|
private static final Map<Material, String> formattedMaterialStrings = new HashMap<>();
|
||||||
|
private static final Map<PartyFeature, String> prettyPartyFeatureStringCache = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a capitalized version of the target string.
|
* Gets a capitalized version of the target string.
|
||||||
|
* Results are cached to improve performance.
|
||||||
*
|
*
|
||||||
* @param target
|
* @param target String to capitalize
|
||||||
* String to capitalize
|
|
||||||
* @return the capitalized string
|
* @return the capitalized string
|
||||||
*/
|
*/
|
||||||
public static String getCapitalized(String target) {
|
public static String getCapitalized(String target) {
|
||||||
return target.substring(0, 1).toUpperCase() + target.substring(1).toLowerCase(Locale.ENGLISH);
|
if (target == null || target.isEmpty()) {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
return target.substring(0, 1).toUpperCase(Locale.ENGLISH) + target.substring(1).toLowerCase(Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts ticks to seconds, formatted to one decimal place.
|
||||||
|
*
|
||||||
|
* @param ticks Number of ticks
|
||||||
|
* @return String representation of seconds
|
||||||
|
*/
|
||||||
public static String ticksToSeconds(double ticks) {
|
public static String ticksToSeconds(double ticks) {
|
||||||
return shortDecimal.format(ticks / 20);
|
return shortDecimal.format(ticks / 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertToCamelCaseString(String baseString, String splitBy) {
|
/**
|
||||||
String[] substrings = baseString.split(splitBy);
|
* Gets a pretty string representation of a SuperAbilityType.
|
||||||
String prettyString = "";
|
* Results are cached to improve performance.
|
||||||
int size = 1;
|
*
|
||||||
|
* @param superAbilityType SuperAbilityType to convert
|
||||||
for (String string : substrings) {
|
* @return Pretty string representation of the SuperAbilityType
|
||||||
prettyString = prettyString.concat(getCapitalized(string));
|
*/
|
||||||
|
public static String getPrettySuperAbilityString(SuperAbilityType superAbilityType) {
|
||||||
if (size < substrings.length) {
|
requireNonNull(superAbilityType, "superAbilityType cannot be null");
|
||||||
prettyString = prettyString.concat("");
|
return formattedSuperAbilityStrings.computeIfAbsent(superAbilityType, StringUtils::createPrettyString);
|
||||||
}
|
|
||||||
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return prettyString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPrettyCamelCaseName(Object o) {
|
|
||||||
return StringUtils.convertToCamelCaseString(o.toString(), "_");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPrettySuperAbilityName(SuperAbilityType superAbilityType) {
|
|
||||||
return StringUtils.getPrettySuperAbilityString(superAbilityType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPrettySuperAbilityString(SuperAbilityType ability) {
|
|
||||||
return createPrettyString(ability.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a string from an array skipping the first n elements
|
* Creates a string from an array skipping the first n elements.
|
||||||
* @param args the array to iterate over when forming the string
|
*
|
||||||
* @param index the amount of elements to skip over
|
* @param args The array to iterate over when forming the string
|
||||||
* @return the "trimmed" string
|
* @param index The number of elements to skip over
|
||||||
|
* @return The "trimmed" string
|
||||||
*/
|
*/
|
||||||
public static String buildStringAfterNthElement(@NotNull String @NotNull []args, int index) {
|
public static String buildStringAfterNthElement(@NotNull String @NotNull [] args, int index) {
|
||||||
StringBuilder trimMessage = new StringBuilder();
|
StringBuilder trimMessage = new StringBuilder();
|
||||||
|
|
||||||
for (int i = index; i < args.length; i++) {
|
for (int i = index; i < args.length; i++) {
|
||||||
if (i + 1 >= args.length)
|
if (i > index) {
|
||||||
trimMessage.append(args[i]);
|
trimMessage.append(' ');
|
||||||
else
|
}
|
||||||
trimMessage.append(args[i]).append(" ");
|
trimMessage.append(args[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return trimMessage.toString();
|
return trimMessage.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPrettyItemString(Material material) {
|
/**
|
||||||
return createPrettyString(material.toString());
|
* Gets a pretty string representation of a Material.
|
||||||
}
|
* Results are cached to improve performance.
|
||||||
|
*
|
||||||
public static String getPrettyEntityTypeString(EntityType entity) {
|
* @param material Material to convert
|
||||||
return createPrettyString(entity.toString());
|
* @return Pretty string representation of the Material
|
||||||
}
|
*/
|
||||||
|
public static String getFormattedMaterialString(Material material) {
|
||||||
public static String getPrettyAbilityString(SuperAbilityType ability) {
|
return formattedMaterialStrings.computeIfAbsent(material, StringUtils::createPrettyString);
|
||||||
return createPrettyString(ability.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getWildcardConfigBlockDataString(BlockData data) {
|
|
||||||
return getWildcardConfigMaterialString(data.getMaterial());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getWildcardConfigMaterialString(Material data) {
|
|
||||||
return StringUtils.getPrettyItemString(data).replace(" ", "_") + "|*";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getFriendlyConfigBlockDataString(BlockData data) {
|
|
||||||
switch(data.getMaterial()){
|
|
||||||
case CHORUS_FLOWER:
|
|
||||||
case COCOA:
|
|
||||||
case WHEAT:
|
|
||||||
case BEETROOTS:
|
|
||||||
case CARROTS:
|
|
||||||
case POTATOES:
|
|
||||||
case NETHER_WART: {
|
|
||||||
if (data instanceof Ageable ageData) {
|
|
||||||
if (ageData.getAge() == ageData.getMaximumAge()) {
|
|
||||||
return getPrettyItemString(data.getMaterial()).replace(" ", "_") + "_Ripe";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getPrettyItemString(data.getMaterial()).replace(" ", "_") + "_Ungrown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getPrettyItemString(data.getMaterial()).replace(" ", "_");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getFriendlyConfigMaterialString(Material data) {
|
|
||||||
return getPrettyItemString(data).replace(" ", "_");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getExplicitConfigBlockDataString(BlockData data) {
|
|
||||||
return getExplicitConfigMaterialString(data.getMaterial());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getExplicitConfigMaterialString(Material data) {
|
|
||||||
return StringUtils.getPrettyItemString(data).replace(" ", "_");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPrettyPartyFeatureString(PartyFeature partyFeature) {
|
|
||||||
return createPrettyString(partyFeature.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String createPrettyString(String baseString) {
|
|
||||||
String[] substrings = baseString.split("_");
|
|
||||||
String prettyString = "";
|
|
||||||
int size = 1;
|
|
||||||
|
|
||||||
for (String string : substrings) {
|
|
||||||
prettyString = prettyString.concat(getCapitalized(string));
|
|
||||||
|
|
||||||
if (size < substrings.length) {
|
|
||||||
prettyString = prettyString.concat(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return prettyString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a string represents an Integer
|
* Gets a pretty string representation of an EntityType.
|
||||||
|
* Results are cached to improve performance.
|
||||||
*
|
*
|
||||||
* @param string
|
* @param entityType EntityType to convert
|
||||||
* String to check
|
* @return Pretty string representation of the EntityType
|
||||||
|
*/
|
||||||
|
public static String getPrettyEntityTypeString(EntityType entityType) {
|
||||||
|
return formattedEntityStrings.computeIfAbsent(entityType, StringUtils::createPrettyString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a wildcard configuration string for BlockData.
|
||||||
|
* Results are cached to improve performance.
|
||||||
|
*
|
||||||
|
* @param blockData BlockData to convert
|
||||||
|
* @return Wildcard configuration string
|
||||||
|
*/
|
||||||
|
public static String getWildcardConfigBlockDataString(BlockData blockData) {
|
||||||
|
return getFormattedMaterialString(blockData.getMaterial());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an explicit configuration string for BlockData.
|
||||||
|
* Results are cached to improve performance.
|
||||||
|
*
|
||||||
|
* @param data BlockData to convert
|
||||||
|
* @return Explicit configuration string
|
||||||
|
*/
|
||||||
|
public static String getExplicitConfigBlockDataString(BlockData data) {
|
||||||
|
return getFormattedMaterialString(data.getMaterial());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a pretty string representation of a PartyFeature.
|
||||||
|
* Results are cached to improve performance.
|
||||||
|
*
|
||||||
|
* @param partyFeature PartyFeature to convert
|
||||||
|
* @return Pretty string representation
|
||||||
|
*/
|
||||||
|
public static String getPrettyPartyFeatureString(PartyFeature partyFeature) {
|
||||||
|
return prettyPartyFeatureStringCache.computeIfAbsent(partyFeature, StringUtils::createPrettyString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a pretty string from a base string by splitting underscores and capitalizing words.
|
||||||
|
*
|
||||||
|
* @param baseString String to convert
|
||||||
|
* @return Pretty string
|
||||||
|
*/
|
||||||
|
private static String createPrettyString(String baseString) {
|
||||||
|
return PRETTY_STRING_FUNC.apply(baseString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to create a pretty string from a base string.
|
||||||
|
*/
|
||||||
|
private static final Function<String, String> PRETTY_STRING_FUNC = baseString -> {
|
||||||
|
if (baseString.contains("_") && !baseString.contains(" ")) {
|
||||||
|
return prettify(baseString.split("_"));
|
||||||
|
} else {
|
||||||
|
if(baseString.contains(" ")) {
|
||||||
|
return prettify(baseString.split(" "));
|
||||||
|
} else{
|
||||||
|
return getCapitalized(baseString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static @NotNull String prettify(String[] substrings) {
|
||||||
|
final StringBuilder prettyString = new StringBuilder();
|
||||||
|
|
||||||
|
for (int i = 0; i < substrings.length; i++) {
|
||||||
|
prettyString.append(getCapitalized(substrings[i]));
|
||||||
|
if (i < substrings.length - 1) {
|
||||||
|
prettyString.append(' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return prettyString.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a pretty string from an object.
|
||||||
|
* @param object Object to convert
|
||||||
|
* @return Pretty string representation of the object
|
||||||
|
*/
|
||||||
|
private static String createPrettyString(Object object) {
|
||||||
|
return createPrettyString(object.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a string represents an Integer.
|
||||||
|
*
|
||||||
|
* @param string String to check
|
||||||
* @return true if the string is an Integer, false otherwise
|
* @return true if the string is an Integer, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isInt(String string) {
|
public static boolean isInt(String string) {
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(string);
|
Integer.parseInt(string);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException nFE) {
|
} catch (NumberFormatException ignored) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a string represents a Double
|
* Determine if a string represents a Double.
|
||||||
*
|
*
|
||||||
* @param string
|
* @param string String to check
|
||||||
* String to check
|
|
||||||
* @return true if the string is a Double, false otherwise
|
* @return true if the string is a Double, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isDouble(String string) {
|
public static boolean isDouble(String string) {
|
||||||
try {
|
try {
|
||||||
Double.parseDouble(string);
|
Double.parseDouble(string);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException nFE) {
|
} catch (NumberFormatException ignored) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertKeyToName(@NotNull String key) {
|
|
||||||
// used when no display name is given for a potion
|
|
||||||
final String noUnderscores = key.replace("_", " ").toLowerCase(Locale.ENGLISH);
|
|
||||||
return org.codehaus.plexus.util.StringUtils.capitalise(noUnderscores);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import com.gmail.nossr50.util.skills.RankUtils;
|
|||||||
import com.gmail.nossr50.util.skills.SkillTools;
|
import com.gmail.nossr50.util.skills.SkillTools;
|
||||||
import com.gmail.nossr50.util.sounds.SoundManager;
|
import com.gmail.nossr50.util.sounds.SoundManager;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
Loading…
Reference in New Issue
Block a user