Merge master into endgame branch to prepare merge for beta 2.2.000 update

This commit is contained in:
nossr50
2022-12-04 15:58:23 -08:00
283 changed files with 24630 additions and 17228 deletions

View File

@@ -2,7 +2,7 @@ package com.gmail.nossr50.api;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.util.MetadataConstants;
import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@@ -83,6 +83,12 @@ public final class AbilityAPI {
}
public static boolean isBleeding(LivingEntity entity) {
return BleedTimerTask.isBleeding(entity);
if(entity.isValid()) {
if(entity.hasMetadata(MetadataConstants.METADATA_KEY_RUPTURE)) {
return true;
}
}
return false;
}
}

View File

@@ -2,6 +2,8 @@ package com.gmail.nossr50.api;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.mcMMO;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@@ -9,20 +11,38 @@ public class DatabaseAPI {
/**
* Checks if a player exists in the mcMMO Database
* @param uuid player UUID
* @param offlinePlayer target player
* @return true if the player exists in the DB, false if they do not
*/
public boolean doesPlayerExistInDB(String uuid) {
return doesPlayerExistInDB(UUID.fromString(uuid));
public boolean doesPlayerExistInDB(@NotNull OfflinePlayer offlinePlayer) {
PlayerProfile playerProfile = mcMMO.getDatabaseManager().loadPlayerProfile(offlinePlayer);
return playerProfile.isLoaded();
}
/**
* Checks if a player exists in the mcMMO Database
* @param uuid player UUID
* @param uuid target player
* @return true if the player exists in the DB, false if they do not
*/
public boolean doesPlayerExistInDB(UUID uuid) {
PlayerProfile playerProfile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
public boolean doesPlayerExistInDB(@NotNull UUID uuid) {
PlayerProfile playerProfile = null;
try {
playerProfile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
} catch (Exception e) {
return false;
}
return playerProfile.isLoaded();
}
/**
* Checks if a player exists in the mcMMO Database
* @param playerName target player
* @return true if the player exists in the DB, false if they do not
*/
public boolean doesPlayerExistInDB(@NotNull String playerName) {
PlayerProfile playerProfile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName);
return playerProfile.isLoaded();
}

View File

@@ -1,7 +1,6 @@
package com.gmail.nossr50.api;
import com.gmail.nossr50.api.exceptions.*;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
@@ -13,9 +12,12 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.child.FamilyTree;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillTools;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Set;
@@ -33,8 +35,8 @@ public final class ExperienceAPI {
* @param skillType A string that may or may not be a skill
* @return true if this is a valid mcMMO skill
*/
public static boolean isValidSkillType(String skillType) {
return PrimarySkillType.getSkill(skillType) != null;
public static boolean isValidSkillType(@NotNull String skillType) {
return mcMMO.p.getSkillTools().matchSkill(skillType) != null;
}
/**
@@ -77,9 +79,9 @@ public final class ExperienceAPI {
* @return true if this is a valid, non-child mcMMO skill
*/
public static boolean isNonChildSkill(String skillType) {
PrimarySkillType skill = PrimarySkillType.getSkill(skillType);
PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
return skill != null && !skill.isChildSkill();
return skill != null && !SkillTools.isChildSkill(skill);
}
@Deprecated
@@ -293,11 +295,12 @@ public final class ExperienceAPI {
PrimarySkillType skill = getSkillType(skillType);
if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).beginUnsharedXpGain(skill,
(int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
return;
}
getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).applyXpGain(skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
}
/**
@@ -316,7 +319,7 @@ public final class ExperienceAPI {
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
PrimarySkillType skill = getSkillType(skillType);
addOfflineXP(playerName, skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
addOfflineXP(playerName, skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
}
/**
@@ -429,6 +432,23 @@ public final class ExperienceAPI {
return getOfflineProfile(uuid).getSkillXpLevel(getNonChildSkillType(skillType));
}
/**
* Get the amount of XP an offline player has in a specific skill.
* </br>
* This function is designed for API usage.
*
* @param offlinePlayer The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getOfflineXP(@NotNull OfflinePlayer offlinePlayer, @NotNull String skillType) throws InvalidPlayerException {
return getOfflineProfile(offlinePlayer).getSkillXpLevel(getNonChildSkillType(skillType));
}
/**
* Get the raw amount of XP a player has in a specific skill.
* </br>
@@ -480,6 +500,30 @@ public final class ExperienceAPI {
return getOfflineProfile(uuid).getSkillXpLevelRaw(getNonChildSkillType(skillType));
}
/**
* Get the raw amount of XP an offline player has in a specific skill.
* </br>
* This function is designed for API usage.
*
* @param offlinePlayer The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static float getOfflineXPRaw(@NotNull OfflinePlayer offlinePlayer, @NotNull String skillType) throws InvalidPlayerException, UnsupportedOperationException, InvalidSkillException {
return getOfflineProfile(offlinePlayer).getSkillXpLevelRaw(getNonChildSkillType(skillType));
}
public static float getOfflineXPRaw(@NotNull OfflinePlayer offlinePlayer, @NotNull PrimarySkillType skillType) throws InvalidPlayerException, UnsupportedOperationException {
if(SkillTools.isChildSkill(skillType))
throw new UnsupportedOperationException();
return getOfflineProfile(offlinePlayer).getSkillXpLevelRaw(skillType);
}
/**
* Get the total amount of XP needed to reach the next level.
* </br>
@@ -527,10 +571,27 @@ public final class ExperienceAPI {
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getOfflineXPToNextLevel(UUID uuid, String skillType) {
public static int getOfflineXPToNextLevel(@NotNull UUID uuid, @NotNull String skillType) {
return getOfflineProfile(uuid).getXpToLevel(getNonChildSkillType(skillType));
}
/**
* Get the total amount of XP an offline player needs to reach the next level.
* </br>
* This function is designed for API usage.
*
* @param offlinePlayer The player to get XP for
* @param skillType The skill to get XP for
* @return the total amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getOfflineXPToNextLevel(@NotNull OfflinePlayer offlinePlayer, @NotNull String skillType) throws UnsupportedOperationException, InvalidSkillException, InvalidPlayerException {
return getOfflineProfile(offlinePlayer).getXpToLevel(getNonChildSkillType(skillType));
}
/**
* Get the amount of XP remaining until the next level.
* </br>
@@ -592,6 +653,26 @@ public final class ExperienceAPI {
return profile.getXpToLevel(skill) - profile.getSkillXpLevelRaw(skill);
}
/**
* Get the amount of XP an offline player has left before leveling up.
* </br>
* This function is designed for API usage.
*
* @param offlinePlayer The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static float getOfflineXPRemaining(OfflinePlayer offlinePlayer, String skillType) throws InvalidSkillException, InvalidPlayerException, UnsupportedOperationException {
PrimarySkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = getOfflineProfile(offlinePlayer);
return profile.getXpToLevel(skill) - profile.getSkillXpLevelRaw(skill);
}
/**
* Add levels to a skill.
* </br>
@@ -624,7 +705,7 @@ public final class ExperienceAPI {
PlayerProfile profile = getOfflineProfile(playerName);
PrimarySkillType skill = getSkillType(skillType);
if (skill.isChildSkill()) {
if (SkillTools.isChildSkill(skill)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
for (PrimarySkillType parentSkill : parentSkills) {
@@ -655,7 +736,7 @@ public final class ExperienceAPI {
PlayerProfile profile = getOfflineProfile(uuid);
PrimarySkillType skill = getSkillType(skillType);
if (skill.isChildSkill()) {
if (SkillTools.isChildSkill(skill)) {
Set<PrimarySkillType> parentSkills = FamilyTree.getParents(skill);
for (PrimarySkillType parentSkill : parentSkills) {
@@ -714,7 +795,6 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static int getLevelOffline(String playerName, String skillType) {
return getOfflineProfile(playerName).getSkillLevel(getSkillType(skillType));
}
@@ -762,7 +842,7 @@ public final class ExperienceAPI {
int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(playerName);
for (PrimarySkillType type : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType type : SkillTools.NON_CHILD_SKILLS) {
powerLevel += profile.getSkillLevel(type);
}
@@ -783,7 +863,7 @@ public final class ExperienceAPI {
int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(uuid);
for (PrimarySkillType type : PrimarySkillType.NON_CHILD_SKILLS) {
for (PrimarySkillType type : SkillTools.NON_CHILD_SKILLS) {
powerLevel += profile.getSkillLevel(type);
}
@@ -801,7 +881,7 @@ public final class ExperienceAPI {
* @throws InvalidSkillException if the given skill is not valid
*/
public static int getLevelCap(String skillType) {
return Config.getInstance().getLevelCap(getSkillType(skillType));
return mcMMO.p.getSkillTools().getLevelCap(getSkillType(skillType));
}
/**
@@ -812,7 +892,7 @@ public final class ExperienceAPI {
* @return the overall power level cap
*/
public static int getPowerLevelCap() {
return Config.getInstance().getPowerLevelCap();
return mcMMO.p.getGeneralConfig().getPowerLevelCap();
}
/**
@@ -1126,25 +1206,22 @@ public final class ExperienceAPI {
}
}
// Utility methods follow.
private static void addOfflineXP(UUID playerUniqueId, PrimarySkillType skill, int XP) {
private static void addOfflineXP(@NotNull UUID playerUniqueId, @NotNull PrimarySkillType skill, int XP) {
PlayerProfile profile = getOfflineProfile(playerUniqueId);
profile.addXp(skill, XP);
profile.save(true);
}
@Deprecated
private static void addOfflineXP(String playerName, PrimarySkillType skill, int XP) {
private static void addOfflineXP(@NotNull String playerName, @NotNull PrimarySkillType skill, int XP) {
PlayerProfile profile = getOfflineProfile(playerName);
profile.addXp(skill, XP);
profile.scheduleAsyncSave();
}
private static PlayerProfile getOfflineProfile(UUID uuid) {
private static @NotNull PlayerProfile getOfflineProfile(@NotNull UUID uuid) throws InvalidPlayerException {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
if (!profile.isLoaded()) {
@@ -1154,10 +1231,18 @@ public final class ExperienceAPI {
return profile;
}
@Deprecated
private static PlayerProfile getOfflineProfile(String playerName) {
UUID uuid = mcMMO.p.getServer().getOfflinePlayer(playerName).getUniqueId();
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
private static @NotNull PlayerProfile getOfflineProfile(@NotNull OfflinePlayer offlinePlayer) throws InvalidPlayerException {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(offlinePlayer);
if (!profile.isLoaded()) {
throw new InvalidPlayerException();
}
return profile;
}
private static @NotNull PlayerProfile getOfflineProfile(@NotNull String playerName) throws InvalidPlayerException {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName);
if (!profile.isLoaded()) {
throw new InvalidPlayerException();
@@ -1167,7 +1252,7 @@ public final class ExperienceAPI {
}
private static PrimarySkillType getSkillType(String skillType) throws InvalidSkillException {
PrimarySkillType skill = PrimarySkillType.getSkill(skillType);
PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
if (skill == null) {
throw new InvalidSkillException();
@@ -1179,7 +1264,7 @@ public final class ExperienceAPI {
private static PrimarySkillType getNonChildSkillType(String skillType) throws InvalidSkillException, UnsupportedOperationException {
PrimarySkillType skill = getSkillType(skillType);
if (skill.isChildSkill()) {
if (SkillTools.isChildSkill(skill)) {
throw new UnsupportedOperationException("Child skills do not have XP");
}

View File

@@ -1,6 +1,5 @@
package com.gmail.nossr50.api;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.party.PartyLeader;
@@ -108,7 +107,7 @@ public final class PartyAPI {
*/
public static int getMaxPartySize()
{
return Config.getInstance().getPartyMaxSize();
return mcMMO.p.getGeneralConfig().getPartyMaxSize();
}
/**

View File

@@ -1,6 +1,8 @@
package com.gmail.nossr50.api;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.skills.SkillTools;
import java.util.ArrayList;
import java.util.Arrays;
@@ -30,7 +32,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getNonChildSkills() {
return getListFromEnum(PrimarySkillType.NON_CHILD_SKILLS);
return getListFromEnum(SkillTools.NON_CHILD_SKILLS);
}
/**
@@ -42,7 +44,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getChildSkills() {
return getListFromEnum(PrimarySkillType.CHILD_SKILLS);
return getListFromEnum(mcMMO.p.getSkillTools().CHILD_SKILLS);
}
/**
@@ -54,7 +56,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getCombatSkills() {
return getListFromEnum(PrimarySkillType.COMBAT_SKILLS);
return getListFromEnum(mcMMO.p.getSkillTools().COMBAT_SKILLS);
}
/**
@@ -66,7 +68,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getGatheringSkills() {
return getListFromEnum(PrimarySkillType.GATHERING_SKILLS);
return getListFromEnum(mcMMO.p.getSkillTools().GATHERING_SKILLS);
}
/**
@@ -78,7 +80,7 @@ public final class SkillAPI {
* @return a list of strings with valid skill names
*/
public static List<String> getMiscSkills() {
return getListFromEnum(PrimarySkillType.MISC_SKILLS);
return getListFromEnum(mcMMO.p.getSkillTools().MISC_SKILLS);
}
private static List<String> getListFromEnum(List<PrimarySkillType> skillsTypes) {

View File

@@ -7,6 +7,6 @@ public class McMMOPlayerNotFoundException extends RuntimeException {
private static final long serialVersionUID = 761917904993202836L;
public McMMOPlayerNotFoundException(@NotNull Player player) {
super("McMMOPlayer object was not found for [NOTE: This can mean the profile is not loaded yet!] : " + player.getName() + " " + player.getUniqueId());
super("McMMOPlayer object was not found for [NOTE: This can mean the profile is not loaded yet! : " + player.getName() + " " + player.getUniqueId());
}
}