diff --git a/src/main/java/com/gmail/nossr50/commands/CommandManager.java b/src/main/java/com/gmail/nossr50/commands/CommandManager.java index b1bb5abf4..0fe58d12f 100644 --- a/src/main/java/com/gmail/nossr50/commands/CommandManager.java +++ b/src/main/java/com/gmail/nossr50/commands/CommandManager.java @@ -7,7 +7,6 @@ import com.gmail.nossr50.commands.chat.AdminChatCommand; import com.gmail.nossr50.commands.chat.PartyChatCommand; import com.gmail.nossr50.commands.skills.PowerLevelCommand; import com.gmail.nossr50.config.ChatConfig; -import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.chat.ChatChannel; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; @@ -48,7 +47,7 @@ public class CommandManager { } private void registerSkillCommands() { - if(Config.getInstance().isMasterySystemEnabled()) { + if(mcMMO.p.getGeneralConfig().isMasterySystemEnabled()) { bukkitCommandManager.registerCommand(new PowerLevelCommand(pluginRef)); } } diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java deleted file mode 100644 index 9e43be65c..000000000 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ /dev/null @@ -1,605 +0,0 @@ -package com.gmail.nossr50.config; - -import com.gmail.nossr50.database.SQLDatabaseManager.PoolIdentifier; -import com.gmail.nossr50.datatypes.MobHealthbarType; -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.util.text.StringUtils; -import org.bukkit.Material; -import org.bukkit.block.data.BlockData; -import org.bukkit.configuration.ConfigurationSection; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Set; - -public class Config extends AutoUpdateConfigLoader { - private static Config instance; - - private Config() { - super("config.yml"); - validate(); - } - - public static Config getInstance() { - if (instance == null) { - instance = new Config(); - } - - return instance; - } - - @Override - protected void loadKeys() { - - } - - @Override - protected boolean validateKeys() { - // Validate all the settings! - List reason = new ArrayList<>(); - - /* General Settings */ - if (getSaveInterval() <= 0) { - reason.add("General.Save_Interval should be greater than 0!"); - } - - /* MySQL Settings */ - for (PoolIdentifier identifier : PoolIdentifier.values()) { - if (getMySQLMaxConnections(identifier) <= 0) { - reason.add("MySQL.Database.MaxConnections." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 0!"); - } - if (getMySQLMaxPoolSize(identifier) <= 0) { - reason.add("MySQL.Database.MaxPoolSize." + StringUtils.getCapitalized(identifier.toString()) + " should be greater than 0!"); - } - } - - /* Mob Healthbar */ - if (getMobHealthbarTime() == 0) { - reason.add("Mob_Healthbar.Display_Time cannot be 0! Set to -1 to disable or set a valid value."); - } - - /* Scoreboards */ - /*if (getRankScoreboardTime() != -1 && getRankScoreboardTime() <= 0) { - reason.add("Scoreboard.Types.Rank.Display_Time should be greater than 0, or -1!"); - } - - if (getStatsScoreboardTime() != -1 && getStatsScoreboardTime() <= 0) { - reason.add("Scoreboard.Types.Stats.Display_Time should be greater than 0, or -1!"); - } - - if (getTopScoreboardTime() != -1 && getTopScoreboardTime() <= 0) { - reason.add("Scoreboard.Types.Top.Display_Time should be greater than 0, or -1!"); - } - - if (getInspectScoreboardTime() != -1 && getInspectScoreboardTime() <= 0) { - reason.add("Scoreboard.Types.Inspect.Display_Time should be greater than 0, or -1!"); - } - - if (getSkillScoreboardTime() != -1 && getSkillScoreboardTime() <= 0) { - reason.add("Scoreboard.Types.Skill.Display_Time should be greater than 0, or -1!"); - } - - if (getSkillLevelUpTime() != -1 && getSkillScoreboardTime() <= 0) { - reason.add("Scoreboard.Types.Skill.Display_Time should be greater than 0, or -1!"); - } - - if (!(getRankUseChat() || getRankUseBoard())) { - reason.add("Either Board or Print in Scoreboard.Types.Rank must be true!"); - } - - if (!(getTopUseChat() || getTopUseBoard())) { - reason.add("Either Board or Print in Scoreboard.Types.Top must be true!"); - } - - if (!(getStatsUseChat() || getStatsUseBoard())) { - reason.add("Either Board or Print in Scoreboard.Types.Stats must be true!"); - } - - if (!(getInspectUseChat() || getInspectUseBoard())) { - reason.add("Either Board or Print in Scoreboard.Types.Inspect must be true!"); - }*/ - - /* Database Purging */ - if (getPurgeInterval() < -1) { - reason.add("Database_Purging.Purge_Interval should be greater than, or equal to -1!"); - } - - if (getOldUsersCutoff() != -1 && getOldUsersCutoff() <= 0) { - reason.add("Database_Purging.Old_User_Cutoff should be greater than 0 or -1!"); - } - - /* Hardcore Mode */ - if (getHardcoreDeathStatPenaltyPercentage() < 0.01 || getHardcoreDeathStatPenaltyPercentage() > 100) { - reason.add("Hardcore.Death_Stat_Loss.Penalty_Percentage only accepts values from 0.01 to 100!"); - } - - if (getHardcoreVampirismStatLeechPercentage() < 0.01 || getHardcoreVampirismStatLeechPercentage() > 100) { - reason.add("Hardcore.Vampirism.Leech_Percentage only accepts values from 0.01 to 100!"); - } - - /* Items */ - if (getChimaeraUseCost() < 1 || getChimaeraUseCost() > 64) { - reason.add("Items.Chimaera_Wing.Use_Cost only accepts values from 1 to 64!"); - } - - if (getChimaeraRecipeCost() < 1 || getChimaeraRecipeCost() > 9) { - reason.add("Items.Chimaera_Wing.Recipe_Cost only accepts values from 1 to 9!"); - } - - if (getChimaeraItem() == null) { - reason.add("Items.Chimaera_Wing.Item_Name is invalid!"); - } - - /* Particles */ - if (getLevelUpEffectsTier() < 1) { - reason.add("Particles.LevelUp_Tier should be at least 1!"); - } - - /* PARTY SETTINGS */ - if (getAutoPartyKickInterval() < -1) { - reason.add("Party.AutoKick_Interval should be at least -1!"); - } - - if (getAutoPartyKickTime() < 0) { - reason.add("Party.Old_Party_Member_Cutoff should be at least 0!"); - } - - if (getPartyShareBonusBase() <= 0) { - reason.add("Party.Sharing.ExpShare_bonus_base should be greater than 0!"); - } - - if (getPartyShareBonusIncrease() < 0) { - reason.add("Party.Sharing.ExpShare_bonus_increase should be at least 0!"); - } - - if (getPartyShareBonusCap() <= 0) { - reason.add("Party.Sharing.ExpShare_bonus_cap should be greater than 0!"); - } - - if (getPartyShareRange() <= 0) { - reason.add("Party.Sharing.Range should be greater than 0!"); - } - - if (getPartyXpCurveMultiplier() < 1) { - reason.add("Party.Leveling.Xp_Curve_Modifier should be at least 1!"); - } - - for (PartyFeature partyFeature : PartyFeature.values()) { - if (getPartyFeatureUnlockLevel(partyFeature) < 0) { - reason.add("Party.Leveling." + StringUtils.getPrettyPartyFeatureString(partyFeature).replace(" ", "") + "_UnlockLevel should be at least 0!"); - } - } - - /* Inspect command distance */ - if (getInspectDistance() <= 0) { - reason.add("Commands.inspect.Max_Distance should be greater than 0!"); - } - - if (getTreeFellerThreshold() <= 0) { - reason.add("Abilities.Limits.Tree_Feller_Threshold should be greater than 0!"); - } - - if (getFishingLureModifier() < 0) { - reason.add("Abilities.Fishing.Lure_Modifier should be at least 0!"); - } - - if (getRepairAnvilMaterial() == null) { - reason.add("Skills.Repair.Anvil_Type is invalid!!"); - } - - if (getSalvageAnvilMaterial() == null) { - reason.add("Skills.Repair.Salvage_Anvil_Type is invalid!"); - } - - if (getRepairAnvilMaterial() == getSalvageAnvilMaterial()) { - reason.add("Cannot use the same item for Repair and Salvage anvils!"); - } - -// if (getTamingCOTWMaterial(EntityType.WOLF) == null) { -// reason.add("Skills.Taming.Call_Of_The_Wild.Wolf.Item_Material is invalid!!"); -// } -// -// if (getTamingCOTWMaterial(EntityType.OCELOT) == null) { -// reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot.Item_Material is invalid!!"); -// } -// -// if (getTamingCOTWMaterial(EntityType.HORSE) == null) { -// reason.add("Skills.Taming.Call_Of_The_Wild.Horse.Item_Material is invalid!!"); -// } -// -// if (getTamingCOTWCost(EntityType.WOLF) <= 0) { -// reason.add("Skills.Taming.Call_Of_The_Wild.Wolf.Item_Amount should be greater than 0!"); -// } -// -// if (getTamingCOTWCost(EntityType.OCELOT) <= 0) { -// reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot.Item_Amount should be greater than 0!"); -// } -// -// if (getTamingCOTWCost(EntityType.HORSE) <= 0) { -// reason.add("Skills.Taming.Call_Of_The_Wild.Horse.Item_Amount should be greater than 0!"); -// } -// -// if (getTamingCOTWAmount(EntityType.WOLF) <= 0) { -// reason.add("Skills.Taming.Call_Of_The_Wild.Wolf.Summon_Amount should be greater than 0!"); -// } -// -// if (getTamingCOTWAmount(EntityType.OCELOT) <= 0) { -// reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot.Summon_Amount should be greater than 0!"); -// } -// -// if (getTamingCOTWAmount(EntityType.HORSE) <= 0) { -// reason.add("Skills.Taming.Call_Of_The_Wild.Horse.Summon_Amount should be greater than 0!"); -// } - - return noErrorsInConfig(reason); - } - - /* - * GENERAL SETTINGS - */ - - public boolean isAprilFoolsAllowed() { return config.getBoolean("General.AprilFoolsEvent", true); } - - /* General Settings */ - public boolean getIsMetricsEnabled() { return config.getBoolean("Metrics.bstats", true); } - - //Retro mode will default the value to true if the config file doesn't contain the entry (server is from a previous mcMMO install) - public boolean getIsRetroMode() { return config.getBoolean("General.RetroMode.Enabled", true); } - - public String getLocale() { return config.getString("General.Locale", "en_us"); } - public boolean getMOTDEnabled() { return config.getBoolean("General.MOTD_Enabled", true); } - public boolean getShowProfileLoadedMessage() { return config.getBoolean("General.Show_Profile_Loaded", true); } - public boolean getDonateMessageEnabled() { return config.getBoolean("Commands.mcmmo.Donate_Message", true); } - public int getSaveInterval() { return config.getInt("General.Save_Interval", 10); } - public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); } - public boolean getUpdateCheckEnabled() { return config.getBoolean("General.Update_Check", true); } - public boolean getPreferBeta() { return config.getBoolean("General.Prefer_Beta", false); } - public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); } - - - public boolean getMatchOfflinePlayers() { return config.getBoolean("Commands.Generic.Match_OfflinePlayers", false); } - public long getDatabasePlayerCooldown() { return config.getLong("Commands.Database.Player_Cooldown", 1750); } - - public boolean getLevelUpSoundsEnabled() { return config.getBoolean("General.LevelUp_Sounds", true); } - public boolean getRefreshChunksEnabled() { return config.getBoolean("General.Refresh_Chunks", false); } - - public boolean getMobHealthbarEnabled() { return config.getBoolean("Mob_Healthbar.Enabled", true); } - - /* Mob Healthbar */ - public MobHealthbarType getMobHealthbarDefault() { - try { - return MobHealthbarType.valueOf(config.getString("Mob_Healthbar.Display_Type", "HEARTS").toUpperCase(Locale.ENGLISH).trim()); - } - catch (IllegalArgumentException ex) { - return MobHealthbarType.HEARTS; - } - } - - public int getMobHealthbarTime() { return config.getInt("Mob_Healthbar.Display_Time", 3); } - - /* Scoreboards */ - public boolean getScoreboardsEnabled() { return config.getBoolean("Scoreboard.UseScoreboards", true); } - public boolean getPowerLevelTagsEnabled() { return config.getBoolean("Scoreboard.Power_Level_Tags", false); } - public boolean getAllowKeepBoard() { return config.getBoolean("Scoreboard.Allow_Keep", true); } - public int getTipsAmount() { return config.getInt("Scoreboard.Tips_Amount", 5); } - public boolean getShowStatsAfterLogin() { return config.getBoolean("Scoreboard.Show_Stats_After_Login", false); } - public boolean getScoreboardRainbows() { return config.getBoolean("Scoreboard.Rainbows", false); } - public boolean getShowAbilityNames() { return config.getBoolean("Scoreboard.Ability_Names", true); } - - public boolean getRankUseChat() { return config.getBoolean("Scoreboard.Types.Rank.Print", false); } - public boolean getRankUseBoard() { return config.getBoolean("Scoreboard.Types.Rank.Board", true); } - public int getRankScoreboardTime() { return config.getInt("Scoreboard.Types.Rank.Display_Time", 10); } - - public boolean getTopUseChat() { return config.getBoolean("Scoreboard.Types.Top.Print", true); } - public boolean getTopUseBoard() { return config.getBoolean("Scoreboard.Types.Top.Board", true); } - public int getTopScoreboardTime() { return config.getInt("Scoreboard.Types.Top.Display_Time", 15); } - - public boolean getStatsUseChat() { return config.getBoolean("Scoreboard.Types.Stats.Print", true); } - public boolean getStatsUseBoard() { return config.getBoolean("Scoreboard.Types.Stats.Board", true); } - public int getStatsScoreboardTime() { return config.getInt("Scoreboard.Types.Stats.Display_Time", 10); } - - public boolean getInspectUseChat() { return config.getBoolean("Scoreboard.Types.Inspect.Print", true); } - public boolean getInspectUseBoard() { return config.getBoolean("Scoreboard.Types.Inspect.Board", true); } - public int getInspectScoreboardTime() { return config.getInt("Scoreboard.Types.Inspect.Display_Time", 25); } - - public boolean getCooldownUseChat() { return config.getBoolean("Scoreboard.Types.Cooldown.Print", false); } - public boolean getCooldownUseBoard() { return config.getBoolean("Scoreboard.Types.Cooldown.Board", true); } - public int getCooldownScoreboardTime() { return config.getInt("Scoreboard.Types.Cooldown.Display_Time", 41); } - - public boolean getSkillUseBoard() { return config.getBoolean("Scoreboard.Types.Skill.Board", true); } - public int getSkillScoreboardTime() { return config.getInt("Scoreboard.Types.Skill.Display_Time", 30); } - public boolean getSkillLevelUpBoard() { return config.getBoolean("Scoreboard.Types.Skill.LevelUp_Board", true); } - public int getSkillLevelUpTime() { return config.getInt("Scoreboard.Types.Skill.LevelUp_Time", 5); } - - /* Database Purging */ - public int getPurgeInterval() { return config.getInt("Database_Purging.Purge_Interval", -1); } - public int getOldUsersCutoff() { return config.getInt("Database_Purging.Old_User_Cutoff", 6); } - - /* Backups */ - public boolean getBackupsEnabled() { return config.getBoolean("Backups.Enabled", true); } - public boolean getKeepLast24Hours() { return config.getBoolean("Backups.Keep.Last_24_Hours", true); } - public boolean getKeepDailyLastWeek() { return config.getBoolean("Backups.Keep.Daily_Last_Week", true); } - public boolean getKeepWeeklyPastMonth() { return config.getBoolean("Backups.Keep.Weekly_Past_Months", true); } - - /* mySQL */ - public boolean getUseMySQL() { return config.getBoolean("MySQL.Enabled", false); } - public String getMySQLTablePrefix() { return config.getString("MySQL.Database.TablePrefix", "mcmmo_"); } - public String getMySQLDatabaseName() { return getStringIncludingInts("MySQL.Database.Name"); } - public String getMySQLUserName() { return getStringIncludingInts("MySQL.Database.User_Name"); } - public int getMySQLServerPort() { return config.getInt("MySQL.Server.Port", 3306); } - public String getMySQLServerName() { return config.getString("MySQL.Server.Address", "localhost"); } - public String getMySQLUserPassword() { return getStringIncludingInts("MySQL.Database.User_Password"); } - public int getMySQLMaxConnections(PoolIdentifier identifier) { return config.getInt("MySQL.Database.MaxConnections." + StringUtils.getCapitalized(identifier.toString()), 30); } - public int getMySQLMaxPoolSize(PoolIdentifier identifier) { return config.getInt("MySQL.Database.MaxPoolSize." + StringUtils.getCapitalized(identifier.toString()), 10); } - public boolean getMySQLSSL() { return config.getBoolean("MySQL.Server.SSL", true); } - public boolean getMySQLDebug() { return config.getBoolean("MySQL.Debug", false); } - - private String getStringIncludingInts(String key) { - String str = config.getString(key); - - if (str == null) { - str = String.valueOf(config.getInt(key)); - } - - if (str.equals("0")) { - str = "No value set for '" + key + "'"; - } - return str; - } - - /* Hardcore Mode */ - public boolean getHardcoreStatLossEnabled(PrimarySkillType primarySkillType) { return config.getBoolean("Hardcore.Death_Stat_Loss.Enabled." + StringUtils.getCapitalized(primarySkillType.toString()), false); } - public void setHardcoreStatLossEnabled(PrimarySkillType primarySkillType, boolean enabled) { config.set("Hardcore.Death_Stat_Loss.Enabled." + StringUtils.getCapitalized(primarySkillType.toString()), enabled); } - - public double getHardcoreDeathStatPenaltyPercentage() { return config.getDouble("Hardcore.Death_Stat_Loss.Penalty_Percentage", 75.0D); } - public void setHardcoreDeathStatPenaltyPercentage(double value) { config.set("Hardcore.Death_Stat_Loss.Penalty_Percentage", value); } - - public int getHardcoreDeathStatPenaltyLevelThreshold() { return config.getInt("Hardcore.Death_Stat_Loss.Level_Threshold", 0); } - - public boolean getHardcoreVampirismEnabled(PrimarySkillType primarySkillType) { return config.getBoolean("Hardcore.Vampirism.Enabled." + StringUtils.getCapitalized(primarySkillType.toString()), false); } - public void setHardcoreVampirismEnabled(PrimarySkillType primarySkillType, boolean enabled) { config.set("Hardcore.Vampirism.Enabled." + StringUtils.getCapitalized(primarySkillType.toString()), enabled); } - - public double getHardcoreVampirismStatLeechPercentage() { return config.getDouble("Hardcore.Vampirism.Leech_Percentage", 5.0D); } - public void setHardcoreVampirismStatLeechPercentage(double value) { config.set("Hardcore.Vampirism.Leech_Percentage", value); } - - public int getHardcoreVampirismLevelThreshold() { return config.getInt("Hardcore.Vampirism.Level_Threshold", 0); } - - /* SMP Mods */ - public boolean getToolModsEnabled() { return config.getBoolean("Mods.Tool_Mods_Enabled", false); } - public boolean getArmorModsEnabled() { return config.getBoolean("Mods.Armor_Mods_Enabled", false); } - public boolean getBlockModsEnabled() { return config.getBoolean("Mods.Block_Mods_Enabled", false); } - public boolean getEntityModsEnabled() { return config.getBoolean("Mods.Entity_Mods_Enabled", false); } - - /* Items */ - public int getChimaeraUseCost() { return config.getInt("Items.Chimaera_Wing.Use_Cost", 1); } - public int getChimaeraRecipeCost() { return config.getInt("Items.Chimaera_Wing.Recipe_Cost", 5); } - public Material getChimaeraItem() { return Material.matchMaterial(config.getString("Items.Chimaera_Wing.Item_Name", "Feather")); } - public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); } - public boolean getChimaeraPreventUseUnderground() { return config.getBoolean("Items.Chimaera_Wing.Prevent_Use_Underground", true); } - public boolean getChimaeraUseBedSpawn() { return config.getBoolean("Items.Chimaera_Wing.Use_Bed_Spawn", true); } - public int getChimaeraCooldown() { return config.getInt("Items.Chimaera_Wing.Cooldown", 240); } - public int getChimaeraWarmup() { return config.getInt("Items.Chimaera_Wing.Warmup", 5); } - public int getChimaeraRecentlyHurtCooldown() { return config.getInt("Items.Chimaera_Wing.RecentlyHurt_Cooldown", 60); } - public boolean getChimaeraSoundEnabled() { return config.getBoolean("Items.Chimaera_Wing.Sound_Enabled", true); } - - public boolean getFluxPickaxeSoundEnabled() { return config.getBoolean("Items.Flux_Pickaxe.Sound_Enabled", true); } - - /* Particles */ - public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); } - public boolean getAbilityDeactivationEffectEnabled() { return config.getBoolean("Particles.Ability_Deactivation", true); } - public boolean getBleedEffectEnabled() { return config.getBoolean("Particles.Bleed", true); } - public boolean getDodgeEffectEnabled() { return config.getBoolean("Particles.Dodge", true); } - public boolean getFluxEffectEnabled() { return config.getBoolean("Particles.Flux", true); } - public boolean getGreaterImpactEffectEnabled() { return config.getBoolean("Particles.Greater_Impact", true); } - public boolean getCallOfTheWildEffectEnabled() { return config.getBoolean("Particles.Call_of_the_Wild", true); } - public boolean getLevelUpEffectsEnabled() { return config.getBoolean("Particles.LevelUp_Enabled", true); } - public int getLevelUpEffectsTier() { return config.getInt("Particles.LevelUp_Tier", 100); } -// public boolean getLargeFireworks() { return config.getBoolean("Particles.LargeFireworks", true); } - - /* PARTY SETTINGS */ - public boolean getPartyFriendlyFire() { return config.getBoolean("Party.FriendlyFire", false);} - public int getPartyMaxSize() {return config.getInt("Party.MaxSize", -1); } - public int getAutoPartyKickInterval() { return config.getInt("Party.AutoKick_Interval", 12); } - public int getAutoPartyKickTime() { return config.getInt("Party.Old_Party_Member_Cutoff", 7); } - - public double getPartyShareBonusBase() { return config.getDouble("Party.Sharing.ExpShare_bonus_base", 1.1D); } - public double getPartyShareBonusIncrease() { return config.getDouble("Party.Sharing.ExpShare_bonus_increase", 0.05D); } - public double getPartyShareBonusCap() { return config.getDouble("Party.Sharing.ExpShare_bonus_cap", 1.5D); } - public double getPartyShareRange() { return config.getDouble("Party.Sharing.Range", 75.0D); } - - public int getPartyLevelCap() { - int cap = config.getInt("Party.Leveling.Level_Cap", 10); - return (cap <= 0) ? Integer.MAX_VALUE : cap; - } - - public int getPartyXpCurveMultiplier() { return config.getInt("Party.Leveling.Xp_Curve_Modifier", 3); } - public boolean getPartyXpNearMembersNeeded() { return config.getBoolean("Party.Leveling.Near_Members_Needed", false); } - public boolean getPartyInformAllMembers() { return config.getBoolean("Party.Leveling.Inform_All_Party_Members_On_LevelUp", false); } - - public int getPartyFeatureUnlockLevel(PartyFeature partyFeature) { return config.getInt("Party.Leveling." + StringUtils.getPrettyPartyFeatureString(partyFeature).replace(" ", "") + "_UnlockLevel", 0); } - - /* Party Teleport Settings */ - public int getPTPCommandCooldown() { return config.getInt("Commands.ptp.Cooldown", 120); } - public int getPTPCommandWarmup() { return config.getInt("Commands.ptp.Warmup", 5); } - public int getPTPCommandRecentlyHurtCooldown() { return config.getInt("Commands.ptp.RecentlyHurt_Cooldown", 60); } - public int getPTPCommandTimeout() { return config.getInt("Commands.ptp.Request_Timeout", 300); } - public boolean getPTPCommandConfirmRequired() { return config.getBoolean("Commands.ptp.Accept_Required", true); } - public boolean getPTPCommandWorldPermissions() { return config.getBoolean("Commands.ptp.World_Based_Permissions", false); } - - /* Inspect command distance */ - public double getInspectDistance() { return config.getDouble("Commands.inspect.Max_Distance", 30.0D); } - - /* - * ABILITY SETTINGS - */ - - /* General Settings */ - public boolean getUrlLinksEnabled() { return config.getBoolean("Commands.Skills.URL_Links"); } - public boolean getAbilityMessagesEnabled() { return config.getBoolean("Abilities.Messages", true); } - public boolean getAbilitiesEnabled() { return config.getBoolean("Abilities.Enabled", true); } - public boolean getAbilitiesOnlyActivateWhenSneaking() { return config.getBoolean("Abilities.Activation.Only_Activate_When_Sneaking", false); } - public boolean getAbilitiesGateEnabled() { return config.getBoolean("Abilities.Activation.Level_Gate_Abilities"); } - - public int getCooldown(SuperAbilityType ability) { return config.getInt("Abilities.Cooldowns." + ability.toString()); } - public int getMaxLength(SuperAbilityType ability) { return config.getInt("Abilities.Max_Seconds." + ability.toString()); } - - /* Durability Settings */ - public int getAbilityToolDamage() { return config.getInt("Abilities.Tools.Durability_Loss", 1); } - - /* Thresholds */ - public int getTreeFellerThreshold() { return config.getInt("Abilities.Limits.Tree_Feller_Threshold", 1000); } - - /* - * SKILL SETTINGS - */ - public boolean getDoubleDropsEnabled(PrimarySkillType skill, Material material) { - //TODO: Temporary measure to fix an exploit caused by a yet to be fixed Spigot bug (as of 7/3/2020) - if(material.toString().equalsIgnoreCase("LILY_PAD")) - return false; - - return config.getBoolean("Bonus_Drops." + StringUtils.getCapitalized(skill.toString()) + "." + StringUtils.getPrettyItemString(material).replace(" ", "_")); - } - - public boolean getDoubleDropsDisabled(PrimarySkillType skill) { - String skillName = StringUtils.getCapitalized(skill.toString()); - ConfigurationSection section = config.getConfigurationSection("Bonus_Drops." + skillName); - if (section == null) - return false; - Set keys = section.getKeys(false); - boolean disabled = true; - - for (String key : keys) { - if (config.getBoolean("Bonus_Drops." + skillName + "." + key)) { - disabled = false; - break; - } - } - - return disabled; - } - - /* Axes */ - public int getAxesGate() { return config.getInt("Skills.Axes.Ability_Activation_Level_Gate", 10); } - - /* Acrobatics */ - public boolean getDodgeLightningDisabled() { return config.getBoolean("Skills.Acrobatics.Prevent_Dodge_Lightning", false); } - public int getXPAfterTeleportCooldown() { return config.getInt("Skills.Acrobatics.XP_After_Teleport_Cooldown", 5); } - - /* Alchemy */ - public boolean getEnabledForHoppers() { return config.getBoolean("Skills.Alchemy.Enabled_for_Hoppers", true); } - public boolean getPreventHopperTransferIngredients() { return config.getBoolean("Skills.Alchemy.Prevent_Hopper_Transfer_Ingredients", false); } - public boolean getPreventHopperTransferBottles() { return config.getBoolean("Skills.Alchemy.Prevent_Hopper_Transfer_Bottles", false); } - - /* Fishing */ - public boolean getFishingDropsEnabled() { return config.getBoolean("Skills.Fishing.Drops_Enabled", true); } - public boolean getFishingOverrideTreasures() { return config.getBoolean("Skills.Fishing.Override_Vanilla_Treasures", true); } - public boolean getFishingExtraFish() { return config.getBoolean("Skills.Fishing.Extra_Fish", true); } - public double getFishingLureModifier() { return config.getDouble("Skills.Fishing.Lure_Modifier", 4.0D); } - - /* Mining */ - public Material getDetonatorItem() { return Material.matchMaterial(config.getString("Skills.Mining.Detonator_Name", "FLINT_AND_STEEL")); } - - /* Excavation */ - public int getExcavationGate() { return config.getInt("Skills.Excavation.Ability_Activation_Level_Gate", 10); } - - /* Repair */ - public boolean getRepairAnvilMessagesEnabled() { return config.getBoolean("Skills.Repair.Anvil_Messages", true); } - public boolean getRepairAnvilPlaceSoundsEnabled() { return config.getBoolean("Skills.Repair.Anvil_Placed_Sounds", true); } - public boolean getRepairAnvilUseSoundsEnabled() { return config.getBoolean("Skills.Repair.Anvil_Use_Sounds", true); } - public @Nullable Material getRepairAnvilMaterial() { return Material.matchMaterial(config.getString("Skills.Repair.Anvil_Material", "IRON_BLOCK")); } - public boolean getRepairConfirmRequired() { return config.getBoolean("Skills.Repair.Confirm_Required", true); } - public boolean getAllowVanillaInventoryRepair() { return config.getBoolean("Skills.Repair.Allow_Vanilla_Anvil_Repair", false); } - public boolean getAllowVanillaAnvilRepair() { return config.getBoolean("Skills.Repair.Allow_Vanilla_Inventory_Repair", false); } - public boolean getAllowVanillaGrindstoneRepair() { return config.getBoolean("Skills.Repair.Allow_Vanilla_Grindstone_Repair", false); } - - /* Salvage */ - public boolean getSalvageAnvilMessagesEnabled() { return config.getBoolean("Skills.Salvage.Anvil_Messages", true); } - public boolean getSalvageAnvilPlaceSoundsEnabled() { return config.getBoolean("Skills.Salvage.Anvil_Placed_Sounds", true); } - public boolean getSalvageAnvilUseSoundsEnabled() { return config.getBoolean("Skills.Salvage.Anvil_Use_Sounds", true); } - public @Nullable Material getSalvageAnvilMaterial() { return Material.matchMaterial(config.getString("Skills.Salvage.Anvil_Material", "GOLD_BLOCK")); } - public boolean getSalvageConfirmRequired() { return config.getBoolean("Skills.Salvage.Confirm_Required", true); } - - /* Unarmed */ - public boolean getUnarmedBlockCrackerSmoothbrickToCracked() { return config.getBoolean("Skills.Unarmed.Block_Cracker.SmoothBrick_To_CrackedBrick", true); } - public boolean getUnarmedItemPickupDisabled() { return config.getBoolean("Skills.Unarmed.Item_Pickup_Disabled_Full_Inventory", true); } - public boolean getUnarmedItemsAsUnarmed() { return config.getBoolean("Skills.Unarmed.Items_As_Unarmed", false); } - public int getUnarmedGate() { return config.getInt("Skills.Unarmed.Ability_Activation_Level_Gate", 10); } - - /* Swords */ - public int getSwordsGate() { return config.getInt("Skills.Swords.Ability_Activation_Level_Gate", 10); } - - /* Taming */ -// public Material getTamingCOTWMaterial(EntityType type) { return Material.matchMaterial(config.getString("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Item_Material")); } -// public int getTamingCOTWCost(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Item_Amount"); } -// public int getTamingCOTWAmount(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type) + ".Summon_Amount"); } -// public int getTamingCOTWLength(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type)+ ".Summon_Length"); } -// public int getTamingCOTWMaxAmount(EntityType type) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + StringUtils.getPrettyEntityTypeString(type)+ ".Summon_Max_Amount"); } - - public Material getTamingCOTWMaterial(String cotwEntity) { return Material.matchMaterial(config.getString("Skills.Taming.Call_Of_The_Wild." + cotwEntity + ".Item_Material")); } - public int getTamingCOTWCost(String cotwEntity) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + cotwEntity + ".Item_Amount"); } - public int getTamingCOTWAmount(String cotwEntity) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + cotwEntity + ".Summon_Amount"); } - public int getTamingCOTWLength(String cotwEntity) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + cotwEntity+ ".Summon_Length"); } - public int getTamingCOTWMaxAmount(String cotwEntity) { return config.getInt("Skills.Taming.Call_Of_The_Wild." + cotwEntity+ ".Per_Player_Limit", 1); } - - /* Woodcutting */ - public boolean getWoodcuttingDoubleDropsEnabled(BlockData material) { return config.getBoolean("Bonus_Drops.Woodcutting." + StringUtils.getFriendlyConfigBlockDataString(material)); } - public boolean getTreeFellerSoundsEnabled() { return config.getBoolean("Skills.Woodcutting.Tree_Feller_Sounds", true); } - public int getWoodcuttingGate() { return config.getInt("Skills.Woodcutting.Ability_Activation_Level_Gate", 10); } - - /* AFK Leveling */ - public boolean getHerbalismPreventAFK() { return config.getBoolean("Skills.Herbalism.Prevent_AFK_Leveling", true); } - - /* Level Caps */ - public int getPowerLevelCap() { - int cap = config.getInt("General.Power_Level_Cap", 0); - return (cap <= 0) ? Integer.MAX_VALUE : cap; - } - - public int getLevelCap(PrimarySkillType skill) { - int cap = config.getInt("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Level_Cap"); - return (cap <= 0) ? Integer.MAX_VALUE : cap; - } - - - /*public int isSuperAbilityUnlocked(PrimarySkillType skill) { - return config.getInt("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Ability_Activation_Level_Gate"); - }*/ - - public boolean getTruncateSkills() { return config.getBoolean("General.TruncateSkills", false); } - - /* PVP & PVE Settings */ - public boolean getPVPEnabled(PrimarySkillType skill) { return config.getBoolean("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Enabled_For_PVP", true); } - public boolean getPVEEnabled(PrimarySkillType skill) { return config.getBoolean("Skills." + StringUtils.getCapitalized(skill.toString()) + ".Enabled_For_PVE", true); } - - //public float getMasterVolume() { return (float) config.getDouble("Sounds.MasterVolume", 1.0); } - - public boolean broadcastEventMessages() { return config.getBoolean("General.EventBroadcasts", true);} - public boolean playerJoinEventInfo() { return config.getBoolean("General.EventInfoOnPlayerJoin", true);} - public boolean adminNotifications() { return config.getBoolean("General.AdminNotifications", true);} - - public boolean shouldLevelUpBroadcasts() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Enabled", true); } - public boolean shouldLevelUpBroadcastToConsole() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Broadcast_Targets.Send_To_Console", true); } - public boolean isLevelUpBroadcastsPartyMembersOnly() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Broadcast_Targets.Only_Party_Members", false); } - public boolean isLevelUpBroadcastsSameWorldOnly() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Broadcast_Targets.Only_Same_World", false); } - public boolean shouldLevelUpBroadcastsRestrictDistance() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Broadcast_Targets.Distance_Restrictions.Restrict_Distance", false); } - public int getLevelUpBroadcastRadius() { return config.getInt("General.Level_Up_Chat_Broadcasts.Broadcast_Targets.Distance_Restrictions.Restricted_Radius", 100); } - public int getLevelUpBroadcastInterval() { return config.getInt("General.Level_Up_Chat_Broadcasts.Milestone_Interval", 100); } - - public boolean shouldPowerLevelUpBroadcasts() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Broadcast_Powerlevels.Enabled", true); } - public boolean shouldPowerLevelUpBroadcastToConsole() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Broadcast_Powerlevels.Broadcast_Targets.Send_To_Console", true); } - public boolean isPowerLevelUpBroadcastsPartyMembersOnly() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Broadcast_Powerlevels.Broadcast_Targets.Only_Party_Members", false); } - public boolean isPowerLevelUpBroadcastsSameWorldOnly() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Broadcast_Powerlevels.Broadcast_Targets.Only_Same_World", false); } - public boolean shouldPowerLevelUpBroadcastsRestrictDistance() { return config.getBoolean("General.Level_Up_Chat_Broadcasts.Broadcast_Powerlevels.Broadcast_Targets.Distance_Restrictions.Restrict_Distance", false); } - public int getPowerLevelUpBroadcastRadius() { return config.getInt("General.Level_Up_Chat_Broadcasts.Broadcast_Powerlevels.Broadcast_Targets.Distance_Restrictions.Restricted_Radius", 100); } - public int getPowerLevelUpBroadcastInterval() { return config.getInt("General.Level_Up_Chat_Broadcasts.Broadcast_Powerlevels.Milestone_Interval", 100); } - - public boolean isMasterySystemEnabled() { return config.getBoolean( "General.PowerLevel.Skill_Mastery.Enabled"); } - public boolean isGreenThumbReplantableCrop(@NotNull Material material) { - return config.getBoolean("Green_Thumb_Replanting_Crops." + StringUtils.getCapitalized(material.toString()), true); - } -} diff --git a/src/main/java/com/gmail/nossr50/config/GeneralConfig.java b/src/main/java/com/gmail/nossr50/config/GeneralConfig.java index fb86a42f4..f0ae3cd1c 100644 --- a/src/main/java/com/gmail/nossr50/config/GeneralConfig.java +++ b/src/main/java/com/gmail/nossr50/config/GeneralConfig.java @@ -1005,4 +1005,6 @@ public class GeneralConfig extends BukkitConfig { public boolean isGreenThumbReplantableCrop(@NotNull Material material) { return config.getBoolean("Green_Thumb_Replanting_Crops." + StringUtils.getCapitalized(material.toString()), true); } + + public boolean isMasterySystemEnabled() { return config.getBoolean( "General.PowerLevel.Skill_Mastery.Enabled"); } } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java index bc6ca7988..15ea49679 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java @@ -111,7 +111,7 @@ public class Roll extends AcrobaticsSubSkill { */ @Override public boolean hasPermission(Player player) { - return Permissions.isSubSkillEnabled(player, this); + return Permissions.isSubSkillEnabled(player, getSubSkillType()); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java index 3643d9ce3..fe0ae14ce 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java @@ -1,7 +1,6 @@ package com.gmail.nossr50.skills.woodcutting; import com.gmail.nossr50.api.ItemSpawnReason; -import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.interactions.NotificationType; @@ -88,7 +87,7 @@ public class WoodcuttingManager extends SkillManager { */ public void processBonusDropCheck(@NotNull BlockState blockState) { //TODO: Why isn't this using the item drop event? Potentially because of Tree Feller? This should be adjusted either way. - if(Config.getInstance().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, blockState.getType())) { + if(mcMMO.p.getGeneralConfig().getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, blockState.getType())) { //Mastery enabled for player if(Permissions.canUseSubSkill(getPlayer(), SubSkillType.WOODCUTTING_CLEAN_CUTS)) { if(checkCleanCutsActivation(blockState.getType())) { @@ -406,6 +405,10 @@ public class WoodcuttingManager extends SkillManager { * @param blockState Block being broken */ protected void spawnHarvestLumberBonusDrops(@NotNull BlockState blockState) { - Misc.spawnItemsFromCollection(getPlayer(), Misc.getBlockCenter(blockState), blockState.getBlock().getDrops(getPlayer().getInventory().getItemInMainHand()), ItemSpawnReason.BONUS_DROPS); + Misc.spawnItemsFromCollection( + getPlayer(), + Misc.getBlockCenter(blockState), + blockState.getBlock().getDrops(getPlayer().getInventory().getItemInMainHand()), + ItemSpawnReason.BONUS_DROPS); } } diff --git a/src/main/java/com/gmail/nossr50/util/Permissions.java b/src/main/java/com/gmail/nossr50/util/Permissions.java index d7fdb9085..93c27fea3 100644 --- a/src/main/java/com/gmail/nossr50/util/Permissions.java +++ b/src/main/java/com/gmail/nossr50/util/Permissions.java @@ -170,7 +170,6 @@ public final class Permissions { public static boolean skillEnabled(Permissible permissible, PrimarySkillType skill) {return permissible.hasPermission("mcmmo.skills." + skill.toString().toLowerCase(Locale.ENGLISH)); } public static boolean vanillaXpBoost(Permissible permissible, PrimarySkillType skill) { return permissible.hasPermission("mcmmo.ability." + skill.toString().toLowerCase(Locale.ENGLISH) + ".vanillaxpboost"); } public static boolean isSubSkillEnabled(Permissible permissible, SubSkillType subSkillType) { return permissible.hasPermission(subSkillType.getPermissionNodeAddress()); } - public static boolean isSubSkillEnabled(Permissible permissible, AbstractSubSkill abstractSubSkill) { return permissible.hasPermission(abstractSubSkill.getPermissionNode()); } /* ACROBATICS */ public static boolean dodge(Permissible permissible) { return permissible.hasPermission("mcmmo.ability.acrobatics.dodge"); } diff --git a/src/main/java/com/gmail/nossr50/util/random/Probability.java b/src/main/java/com/gmail/nossr50/util/random/Probability.java index b792ad64a..a4d8c848c 100644 --- a/src/main/java/com/gmail/nossr50/util/random/Probability.java +++ b/src/main/java/com/gmail/nossr50/util/random/Probability.java @@ -29,7 +29,7 @@ public interface Probability { * @return true for succeeding, false for failing */ static private boolean isSuccessfulRoll(double probabilityValue) { - return probabilityValue >= ThreadLocalRandom.current().nextDouble(100D); + return (probabilityValue * 100) >= ThreadLocalRandom.current().nextDouble(100D); } /** diff --git a/src/main/java/com/gmail/nossr50/util/random/ProbabilityUtil.java b/src/main/java/com/gmail/nossr50/util/random/ProbabilityUtil.java index 55d6950b6..ba3ce84e1 100644 --- a/src/main/java/com/gmail/nossr50/util/random/ProbabilityUtil.java +++ b/src/main/java/com/gmail/nossr50/util/random/ProbabilityUtil.java @@ -84,10 +84,11 @@ public class ProbabilityUtil { if (player != null) { McMMOPlayer mmoPlayer = UserManager.getPlayer(player); - if(mmoPlayer != null) + if(mmoPlayer != null) { xPos = mmoPlayer.getSkillLevel(subSkillType.getParentSkill()); - else + } else { xPos = 0; + } } else { xPos = 0; } diff --git a/src/main/java/com/gmail/nossr50/util/text/TextComponentFactory.java b/src/main/java/com/gmail/nossr50/util/text/TextComponentFactory.java index 5506b6685..708fab805 100644 --- a/src/main/java/com/gmail/nossr50/util/text/TextComponentFactory.java +++ b/src/main/java/com/gmail/nossr50/util/text/TextComponentFactory.java @@ -88,7 +88,7 @@ public class TextComponentFactory { TextComponent emptySpace = Component.space(); - mcMMO.getAudiences().player(player).sendMessage(Identity.nil(),TextComponent.ofChildren( + mcMMO.getAudiences().player(player).sendMessage(Identity.nil(),Component.textOfChildren( prefix, getWebLinkTextComponent(McMMOWebLinks.WEBSITE), emptySpace, @@ -138,40 +138,38 @@ public class TextComponentFactory { { TextComponent.Builder webTextComponent; - switch(webLinks) - { - case WEBSITE: + switch (webLinks) { + case WEBSITE -> { webTextComponent = Component.text().content(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); TextUtils.addChildWebComponent(webTextComponent, "Web"); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlWebsite)); - break; - case SPIGOT: + } + case SPIGOT -> { webTextComponent = Component.text().content(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); TextUtils.addChildWebComponent(webTextComponent, "Spigot"); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlSpigot)); - break; - case DISCORD: + } + case DISCORD -> { webTextComponent = Component.text().content(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); TextUtils.addChildWebComponent(webTextComponent, "Discord"); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlDiscord)); - break; - case PATREON: + } + case PATREON -> { webTextComponent = Component.text().content(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); TextUtils.addChildWebComponent(webTextComponent, "Patreon"); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlPatreon)); - break; - case WIKI: + } + case WIKI -> { webTextComponent = Component.text().content(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); TextUtils.addChildWebComponent(webTextComponent, "Wiki"); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlWiki)); - break; - case HELP_TRANSLATE: + } + case HELP_TRANSLATE -> { webTextComponent = Component.text().content(LocaleLoader.getString("JSON.Hover.AtSymbolURL")); TextUtils.addChildWebComponent(webTextComponent, "Lang"); webTextComponent.clickEvent(getUrlClickEvent(McMMOUrl.urlTranslate)); - break; - default: - webTextComponent = Component.text().content("NOT DEFINED"); + } + default -> webTextComponent = Component.text().content("NOT DEFINED"); } TextUtils.addNewHoverComponentToTextComponent(webTextComponent, getUrlHoverEvent(webLinks)); @@ -184,46 +182,46 @@ public class TextComponentFactory { { TextComponent.Builder componentBuilder = Component.text().content(webLinks.getNiceTitle()); - switch(webLinks) - { - case WEBSITE: + switch (webLinks) { + case WEBSITE -> { addUrlHeaderHover(webLinks, componentBuilder); componentBuilder.append(Component.newline()).append(Component.newline()); componentBuilder.append(Component.text(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); componentBuilder.append(Component.text("\nDev Blogs, and information related to mcMMO can be found here", NamedTextColor.GRAY)); - break; - case SPIGOT: + } + case SPIGOT -> { addUrlHeaderHover(webLinks, componentBuilder); componentBuilder.append(Component.newline()).append(Component.newline()); componentBuilder.append(Component.text(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); componentBuilder.append(Component.text("\nI post regularly in the discussion thread here!", NamedTextColor.GRAY)); - break; - case PATREON: + } + case PATREON -> { addUrlHeaderHover(webLinks, componentBuilder); componentBuilder.append(Component.newline()).append(Component.newline()); componentBuilder.append(Component.text(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); componentBuilder.append(Component.newline()); componentBuilder.append(Component.text("Show support by buying me a coffee :)", NamedTextColor.GRAY)); - break; - case WIKI: + } + case WIKI -> { addUrlHeaderHover(webLinks, componentBuilder); componentBuilder.append(Component.newline()).append(Component.newline()); componentBuilder.append(Component.text(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); componentBuilder.append(Component.newline()); componentBuilder.append(Component.text("I'm looking for more wiki staff, contact me on our discord!", NamedTextColor.DARK_GRAY)); - break; - case DISCORD: + } + case DISCORD -> { addUrlHeaderHover(webLinks, componentBuilder); componentBuilder.append(Component.newline()).append(Component.newline()); componentBuilder.append(Component.text(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); - break; - case HELP_TRANSLATE: + } + case HELP_TRANSLATE -> { addUrlHeaderHover(webLinks, componentBuilder); componentBuilder.append(Component.newline()).append(Component.newline()); componentBuilder.append(Component.text(webLinks.getLocaleDescription(), NamedTextColor.GREEN)); componentBuilder.append(Component.newline()); componentBuilder.append(Component.text("You can use this website to help translate mcMMO into your language!" + - "\nIf you want to know more contact me in discord.", NamedTextColor.DARK_GRAY)); + "\nIf you want to know more contact me in discord.", NamedTextColor.DARK_GRAY)); + } } return componentBuilder.build(); @@ -510,7 +508,7 @@ public class TextComponentFactory { { if(abstractSubSkill.getPrimarySkill() == parentSkill) { - if(Permissions.isSubSkillEnabled(player, abstractSubSkill)) + if(Permissions.isSubSkillEnabled(player, abstractSubSkill.getSubSkillType())) textComponents.add(TextComponentFactory.getSubSkillTextComponent(player, abstractSubSkill)); } } diff --git a/src/test/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManagerTest.java b/src/test/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManagerTest.java new file mode 100644 index 000000000..abeadaa21 --- /dev/null +++ b/src/test/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManagerTest.java @@ -0,0 +1,218 @@ +package com.gmail.nossr50.skills.woodcutting; + +import com.gmail.nossr50.config.AdvancedConfig; +import com.gmail.nossr50.config.ChatConfig; +import com.gmail.nossr50.config.GeneralConfig; +import com.gmail.nossr50.config.RankConfig; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.datatypes.player.PlayerProfile; +import com.gmail.nossr50.datatypes.skills.PrimarySkillType; +import com.gmail.nossr50.datatypes.skills.SubSkillType; +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.EventUtils; +import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.TransientEntityTracker; +import com.gmail.nossr50.util.player.UserManager; +import com.gmail.nossr50.util.skills.RankUtils; +import com.gmail.nossr50.util.skills.SkillTools; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.plugin.PluginManager; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.bukkit.entity.Player; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + +import java.util.UUID; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; + +class WoodcuttingManagerTest { + private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(WoodcuttingManagerTest.class.getName()); + private MockedStatic mockedMcMMO; + private MockedStatic mockedChatConfig; + private MockedStatic mockedPermissions; + private MockedStatic mockedRankUtils; + private MockedStatic mockedUserManager; + private MockedStatic mockedMisc; + private MockedStatic mockedSkillTools; + private MockedStatic mockedEventUtils; + private TransientEntityTracker transientEntityTracker; + private AdvancedConfig advancedConfig; + private GeneralConfig generalConfig; + private RankConfig rankConfig; + private SkillTools skillTools; + private Server server; + private PluginManager pluginManager; + private World world; + + private WoodcuttingManager woodcuttingManager; + + /* Mocks */ + Player player; + + UUID playerUUID = UUID.randomUUID(); + ItemStack itemInMainHand; + + PlayerInventory playerInventory; + PlayerProfile playerProfile; + McMMOPlayer mmoPlayer; + String playerName = "testPlayer"; + + @BeforeEach + void setUp() { + mockedMcMMO = Mockito.mockStatic(mcMMO.class); + mcMMO.p = Mockito.mock(mcMMO.class); + Mockito.when(mcMMO.p.getLogger()).thenReturn(logger); + + // chat config + mockedChatConfig = Mockito.mockStatic(ChatConfig.class); + Mockito.when(ChatConfig.getInstance()).thenReturn(Mockito.mock(ChatConfig.class)); + + // general config + generalConfig = Mockito.mock(GeneralConfig.class); + Mockito.when(generalConfig.getTreeFellerThreshold()).thenReturn(100); + Mockito.when(generalConfig.getDoubleDropsEnabled(PrimarySkillType.WOODCUTTING, Material.OAK_LOG)).thenReturn(true); + Mockito.when(generalConfig.getLocale()).thenReturn("en_US"); + Mockito.when(mcMMO.p.getGeneralConfig()).thenReturn(generalConfig); + + // rank config + rankConfig = Mockito.mock(RankConfig.class); + Mockito.when(rankConfig.getSubSkillUnlockLevel(SubSkillType.WOODCUTTING_HARVEST_LUMBER, 1)).thenReturn(1); + + // wire advanced config + this.advancedConfig = Mockito.mock(AdvancedConfig.class); + Mockito.when(advancedConfig.getMaximumProbability(SubSkillType.WOODCUTTING_HARVEST_LUMBER)).thenReturn(100D); + Mockito.when(advancedConfig.getMaximumProbability(SubSkillType.WOODCUTTING_CLEAN_CUTS)).thenReturn(10D); + Mockito.when(advancedConfig.getMaxBonusLevel(SubSkillType.WOODCUTTING_HARVEST_LUMBER)).thenReturn(1000); + Mockito.when(advancedConfig.getMaxBonusLevel(SubSkillType.WOODCUTTING_CLEAN_CUTS)).thenReturn(10000); + Mockito.when(mcMMO.p.getAdvancedConfig()).thenReturn(advancedConfig); + + // wire skill tools + this.skillTools = new SkillTools(mcMMO.p); + Mockito.when(mcMMO.p.getSkillTools()).thenReturn(skillTools); + + this.transientEntityTracker = new TransientEntityTracker(); + Mockito.when(mcMMO.getTransientEntityTracker()).thenReturn(transientEntityTracker); + + mockedPermissions = Mockito.mockStatic(Permissions.class); + Mockito.when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(true); + Mockito.when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(true); + Mockito.when(Permissions.isSubSkillEnabled(any(Player.class), any(SubSkillType.class))).thenReturn(true); + Mockito.when(Permissions.canUseSubSkill(any(Player.class), any(SubSkillType.class))).thenReturn(true); + Mockito.when(Permissions.lucky(player, PrimarySkillType.WOODCUTTING)).thenReturn(false); // player is not lucky + + mockedRankUtils = Mockito.mockStatic(RankUtils.class); + Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.WOODCUTTING_HARVEST_LUMBER, 1)).thenReturn(1); // needed? + Mockito.when(RankUtils.getRankUnlockLevel(SubSkillType.WOODCUTTING_CLEAN_CUTS, 1)).thenReturn(1000); // needed? + Mockito.when(RankUtils.hasReachedRank(eq(1), any(Player.class), eq(SubSkillType.WOODCUTTING_HARVEST_LUMBER))).thenReturn(true); + Mockito.when(RankUtils.hasReachedRank(eq(1), any(Player.class), eq(SubSkillType.WOODCUTTING_CLEAN_CUTS))).thenReturn(true); + + // wire server + this.server = Mockito.mock(Server.class); + Mockito.when(mcMMO.p.getServer()).thenReturn(server); + + // wire plugin manager + this.pluginManager = Mockito.mock(PluginManager.class); + Mockito.when(server.getPluginManager()).thenReturn(pluginManager); + + // wire world + this.world = Mockito.mock(World.class); + + // wire Misc + this.mockedMisc = Mockito.mockStatic(Misc.class); + Mockito.when(Misc.getBlockCenter(any())).thenReturn(new Location(world, 0, 0, 0)); + + // setup player and player related mocks after everything else + this.player = Mockito.mock(Player.class); + Mockito.when(player.getUniqueId()).thenReturn(playerUUID); + + // wire inventory + this.playerInventory = Mockito.mock(PlayerInventory.class); + this.itemInMainHand = new ItemStack(Material.DIAMOND_AXE); + Mockito.when(player.getInventory()).thenReturn(playerInventory); + Mockito.when(playerInventory.getItemInMainHand()).thenReturn(itemInMainHand); + + // PlayerProfile and McMMOPlayer are partially mocked + playerProfile = new PlayerProfile("testPlayer", player.getUniqueId(), 0); + mmoPlayer = Mockito.spy(new McMMOPlayer(player, playerProfile)); + + // wire user manager + this.mockedUserManager = Mockito.mockStatic(UserManager.class); + Mockito.when(UserManager.getPlayer(player)).thenReturn(mmoPlayer); + + // Set up spy for WoodcuttingManager + woodcuttingManager = Mockito.spy(new WoodcuttingManager(mmoPlayer)); + } + + @AfterEach + void tearDown() { + // Clean up resources here if needed. + if (mockedMcMMO != null) { + mockedMcMMO.close(); + } + if (mockedChatConfig != null) { + mockedChatConfig.close(); + } + if (mockedPermissions != null) { + mockedPermissions.close(); + } + if (mockedRankUtils != null) { + mockedRankUtils.close(); + } + if (mockedUserManager != null) { + mockedUserManager.close(); + } + if (mockedMisc != null) { + mockedMisc.close(); + } + if (mockedEventUtils != null) { + mockedEventUtils.close(); + } + } + + @Test + void harvestLumberShouldDoubleDrop() { + mmoPlayer.modifySkill(PrimarySkillType.WOODCUTTING, 1000); + + BlockState blockState = Mockito.mock(BlockState.class); + Block block = Mockito.mock(Block.class); + // wire block + Mockito.when(blockState.getBlock()).thenReturn(block); + + Mockito.when(blockState.getBlock().getDrops(any())).thenReturn(null); + Mockito.when(blockState.getType()).thenReturn(Material.OAK_LOG); + woodcuttingManager.processBonusDropCheck(blockState); + + // verify bonus drops were spawned + Mockito.verify(woodcuttingManager, Mockito.times(1)).spawnHarvestLumberBonusDrops(blockState); + } + + + @Test + void harvestLumberShouldNotDoubleDrop() { + mmoPlayer.modifySkill(PrimarySkillType.WOODCUTTING, 0); + + BlockState blockState = Mockito.mock(BlockState.class); + Block block = Mockito.mock(Block.class); + // wire block + Mockito.when(blockState.getBlock()).thenReturn(block); + + Mockito.when(blockState.getBlock().getDrops(any())).thenReturn(null); + Mockito.when(blockState.getType()).thenReturn(Material.OAK_LOG); + woodcuttingManager.processBonusDropCheck(blockState); + + // verify bonus drops were not spawned + Mockito.verify(woodcuttingManager, Mockito.times(0)).spawnHarvestLumberBonusDrops(blockState); + } +}