mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-30 11:05:28 +02:00
Static Abuse Removal - BlockUtils -> BlockTools
This commit is contained in:
@@ -3,8 +3,7 @@ package com.gmail.nossr50.util;
|
||||
import com.gmail.nossr50.core.MetadataConstants;
|
||||
import com.gmail.nossr50.datatypes.meta.BonusDropMeta;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
import com.gmail.nossr50.skills.salvage.Salvage;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.random.RandomChanceSkill;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -15,9 +14,12 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public final class BlockUtils {
|
||||
public final class BlockTools {
|
||||
|
||||
private BlockUtils() {
|
||||
private final mcMMO pluginRef;
|
||||
|
||||
public BlockTools(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,7 +28,7 @@ public final class BlockUtils {
|
||||
* @param blockState target blockstate
|
||||
* @param triple marks the block to give triple drops
|
||||
*/
|
||||
public static void markDropsAsBonus(BlockState blockState, boolean triple) {
|
||||
public void markDropsAsBonus(BlockState blockState, boolean triple) {
|
||||
if (triple)
|
||||
blockState.setMetadata(MetadataConstants.BONUS_DROPS_METAKEY, new BonusDropMeta(2, pluginRef));
|
||||
else
|
||||
@@ -39,7 +41,7 @@ public final class BlockUtils {
|
||||
* @param blockState target blockstate
|
||||
* @param amount amount of extra items to drop
|
||||
*/
|
||||
public static void markDropsAsBonus(BlockState blockState, int amount) {
|
||||
public void markDropsAsBonus(BlockState blockState, int amount) {
|
||||
blockState.setMetadata(MetadataConstants.BONUS_DROPS_METAKEY, new BonusDropMeta(amount, pluginRef));
|
||||
}
|
||||
|
||||
@@ -49,9 +51,9 @@ public final class BlockUtils {
|
||||
* @param blockState the blockstate
|
||||
* @return true if the player succeeded in the check
|
||||
*/
|
||||
public static boolean checkDoubleDrops(Player player, BlockState blockState, SubSkillType subSkillType) {
|
||||
public boolean checkDoubleDrops(Player player, BlockState blockState, SubSkillType subSkillType) {
|
||||
if (pluginRef.getDynamicSettingsManager().isBonusDropsEnabled(blockState.getType()) && Permissions.isSubSkillEnabled(player, subSkillType)) {
|
||||
return pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(new RandomChanceSkill(player, subSkillType, true));
|
||||
return pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(new RandomChanceSkill(pluginRef, player, subSkillType, true));
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -63,7 +65,7 @@ public final class BlockUtils {
|
||||
* @param block The {@link Block} of the block to check
|
||||
* @return true if the block awards XP, false otherwise
|
||||
*/
|
||||
public static boolean shouldBeWatched(Block block) {
|
||||
public boolean shouldBeWatched(Block block) {
|
||||
return affectedByGigaDrillBreaker(block.getType()) || affectedByGreenTerra(block.getType()) || affectedBySuperBreaker(block.getType()) || isLog(block.getType());
|
||||
}
|
||||
|
||||
@@ -73,7 +75,7 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block awards XP, false otherwise
|
||||
*/
|
||||
public static boolean shouldBeWatched(BlockState blockState) {
|
||||
public boolean shouldBeWatched(BlockState blockState) {
|
||||
return affectedByGigaDrillBreaker(blockState) || affectedByGreenTerra(blockState) || affectedBySuperBreaker(blockState) || isLog(blockState);
|
||||
}
|
||||
|
||||
@@ -83,7 +85,7 @@ public final class BlockUtils {
|
||||
* @param material The {@link Material} of the block to check
|
||||
* @return true if the block awards XP, false otherwise
|
||||
*/
|
||||
public static boolean shouldBeWatched(Material material) {
|
||||
public boolean shouldBeWatched(Material material) {
|
||||
return affectedByGigaDrillBreaker(material) || affectedByGreenTerra(material) || affectedBySuperBreaker(material) || isLog(material);
|
||||
}
|
||||
|
||||
@@ -94,7 +96,7 @@ public final class BlockUtils {
|
||||
* @return true if the block should allow ability activation, false
|
||||
* otherwise
|
||||
*/
|
||||
public static boolean canActivateAbilities(BlockState blockState) {
|
||||
public boolean canActivateAbilities(BlockState blockState) {
|
||||
return !pluginRef.getMaterialMapStore().isAbilityActivationBlackListed(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -106,7 +108,7 @@ public final class BlockUtils {
|
||||
* @return true if the block should allow ability activation, false
|
||||
* otherwise
|
||||
*/
|
||||
public static boolean canActivateTools(BlockState blockState) {
|
||||
public boolean canActivateTools(BlockState blockState) {
|
||||
return !pluginRef.getMaterialMapStore().isToolActivationBlackListed(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -116,7 +118,7 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block is an ore, false otherwise
|
||||
*/
|
||||
public static boolean isOre(BlockState blockState) {
|
||||
public boolean isOre(BlockState blockState) {
|
||||
return MaterialUtils.isOre(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -126,7 +128,7 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block can be made mossy, false otherwise
|
||||
*/
|
||||
public static boolean canMakeMossy(BlockState blockState) {
|
||||
public boolean canMakeMossy(BlockState blockState) {
|
||||
return pluginRef.getMaterialMapStore().isMossyWhiteListed(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -136,7 +138,7 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block should affected by Green Terra, false otherwise
|
||||
*/
|
||||
public static boolean affectedByGreenTerra(BlockState blockState) {
|
||||
public boolean affectedByGreenTerra(BlockState blockState) {
|
||||
return pluginRef.getDynamicSettingsManager().getExperienceManager().hasHerbalismXp(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -146,7 +148,7 @@ public final class BlockUtils {
|
||||
* @param material The {@link Material} of the block to check
|
||||
* @return true if the block should affected by Green Terra, false otherwise
|
||||
*/
|
||||
public static boolean affectedByGreenTerra(Material material) {
|
||||
public boolean affectedByGreenTerra(Material material) {
|
||||
return pluginRef.getDynamicSettingsManager().getExperienceManager().hasHerbalismXp(material);
|
||||
}
|
||||
|
||||
@@ -157,7 +159,7 @@ public final class BlockUtils {
|
||||
* @return true if the block should affected by Super Breaker, false
|
||||
* otherwise
|
||||
*/
|
||||
public static Boolean affectedBySuperBreaker(BlockState blockState) {
|
||||
public Boolean affectedBySuperBreaker(BlockState blockState) {
|
||||
if (pluginRef.getDynamicSettingsManager().getExperienceManager().hasMiningXp(blockState.getType()))
|
||||
return true;
|
||||
|
||||
@@ -171,7 +173,7 @@ public final class BlockUtils {
|
||||
* @return true if the block should affected by Super Breaker, false
|
||||
* otherwise
|
||||
*/
|
||||
public static Boolean affectedBySuperBreaker(Material material) {
|
||||
public Boolean affectedBySuperBreaker(Material material) {
|
||||
if (pluginRef.getDynamicSettingsManager().getExperienceManager().hasMiningXp(material))
|
||||
return true;
|
||||
|
||||
@@ -184,7 +186,7 @@ public final class BlockUtils {
|
||||
* @param material target blocks material
|
||||
* @return
|
||||
*/
|
||||
public static boolean isMineable(Material material) {
|
||||
public boolean isMineable(Material material) {
|
||||
switch (material) {
|
||||
case COAL_ORE:
|
||||
case DIAMOND_ORE:
|
||||
@@ -211,7 +213,7 @@ public final class BlockUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMineable(BlockState blockState) {
|
||||
public boolean isMineable(BlockState blockState) {
|
||||
return isMineable(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -222,7 +224,7 @@ public final class BlockUtils {
|
||||
* @return true if the block should affected by Giga Drill Breaker, false
|
||||
* otherwise
|
||||
*/
|
||||
public static boolean affectedByGigaDrillBreaker(Material material) {
|
||||
public boolean affectedByGigaDrillBreaker(Material material) {
|
||||
if (pluginRef.getDynamicSettingsManager().getExperienceManager().hasExcavationXp(material))
|
||||
return true;
|
||||
|
||||
@@ -236,7 +238,7 @@ public final class BlockUtils {
|
||||
* @return true if the block should affected by Giga Drill Breaker, false
|
||||
* otherwise
|
||||
*/
|
||||
public static boolean affectedByGigaDrillBreaker(BlockState blockState) {
|
||||
public boolean affectedByGigaDrillBreaker(BlockState blockState) {
|
||||
if (pluginRef.getDynamicSettingsManager().getExperienceManager().hasExcavationXp(blockState.getType()))
|
||||
return true;
|
||||
|
||||
@@ -250,7 +252,7 @@ public final class BlockUtils {
|
||||
* @return true if a shovel is typically used for digging this block
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isDiggable(BlockState blockState) {
|
||||
public boolean isDiggable(BlockState blockState) {
|
||||
return isDiggable(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -260,7 +262,7 @@ public final class BlockUtils {
|
||||
* @param material target blocks material
|
||||
* @return true if a shovel is typically used for digging this block
|
||||
*/
|
||||
public static boolean isDiggable(Material material) {
|
||||
public boolean isDiggable(Material material) {
|
||||
switch (material) {
|
||||
case CLAY:
|
||||
case FARMLAND:
|
||||
@@ -288,7 +290,7 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block is a log, false otherwise
|
||||
*/
|
||||
public static boolean isLog(BlockState blockState) {
|
||||
public boolean isLog(BlockState blockState) {
|
||||
if (pluginRef.getDynamicSettingsManager().getExperienceManager().hasWoodcuttingXp(blockState.getType()))
|
||||
return true;
|
||||
|
||||
@@ -302,7 +304,7 @@ public final class BlockUtils {
|
||||
* @param material The {@link Material} of the block to check
|
||||
* @return true if the block is a log, false otherwise
|
||||
*/
|
||||
public static boolean isLog(Material material) {
|
||||
public boolean isLog(Material material) {
|
||||
if (pluginRef.getDynamicSettingsManager().getExperienceManager().hasWoodcuttingXp(material))
|
||||
return true;
|
||||
|
||||
@@ -316,7 +318,7 @@ public final class BlockUtils {
|
||||
* @param material target material
|
||||
* @return true if the block is gathered via axe
|
||||
*/
|
||||
public static boolean isLoggingRelated(Material material) {
|
||||
public boolean isLoggingRelated(Material material) {
|
||||
switch (material) {
|
||||
case ACACIA_LOG:
|
||||
case BIRCH_LOG:
|
||||
@@ -354,7 +356,7 @@ public final class BlockUtils {
|
||||
* @param blockState target blockstate
|
||||
* @return true if the block is gathered via axe
|
||||
*/
|
||||
public static boolean isLoggingRelated(BlockState blockState) {
|
||||
public boolean isLoggingRelated(BlockState blockState) {
|
||||
return isLoggingRelated(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -364,7 +366,7 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block is a leaf, false otherwise
|
||||
*/
|
||||
public static boolean isLeaves(BlockState blockState) {
|
||||
public boolean isLeaves(BlockState blockState) {
|
||||
return pluginRef.getMaterialMapStore().isLeavesWhiteListed(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -374,7 +376,7 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block should affected by Flux Mining, false otherwise
|
||||
*/
|
||||
public static boolean affectedByFluxMining(BlockState blockState) {
|
||||
public boolean affectedByFluxMining(BlockState blockState) {
|
||||
switch (blockState.getType()) {
|
||||
case IRON_ORE:
|
||||
case GOLD_ORE:
|
||||
@@ -393,7 +395,7 @@ public final class BlockUtils {
|
||||
* @return true if the block can be activate Herbalism abilities, false
|
||||
* otherwise
|
||||
*/
|
||||
public static boolean canActivateHerbalism(BlockState blockState) {
|
||||
public boolean canActivateHerbalism(BlockState blockState) {
|
||||
return pluginRef.getMaterialMapStore().isHerbalismAbilityWhiteListed(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -404,7 +406,7 @@ public final class BlockUtils {
|
||||
* @return true if the block should affected by Block Cracker, false
|
||||
* otherwise
|
||||
*/
|
||||
public static boolean affectedByBlockCracker(BlockState blockState) {
|
||||
public boolean affectedByBlockCracker(BlockState blockState) {
|
||||
return pluginRef.getMaterialMapStore().isBlockCrackerWhiteListed(blockState.getType());
|
||||
}
|
||||
|
||||
@@ -414,23 +416,23 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block can be made into Mycelium, false otherwise
|
||||
*/
|
||||
public static boolean canMakeShroomy(BlockState blockState) {
|
||||
public boolean canMakeShroomy(BlockState blockState) {
|
||||
return pluginRef.getMaterialMapStore().isShroomyWhiteListed(blockState.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given block is an mcMMO anvil
|
||||
*
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block is an mcMMO anvil, false otherwise
|
||||
*/
|
||||
public static boolean isMcMMOAnvil(BlockState blockState) {
|
||||
Material type = blockState.getType();
|
||||
// /**
|
||||
// * Determine if a given block is an mcMMO anvil
|
||||
// *
|
||||
// * @param blockState The {@link BlockState} of the block to check
|
||||
// * @return true if the block is an mcMMO anvil, false otherwise
|
||||
// */
|
||||
// public boolean isMcMMOAnvil(BlockState blockState) {
|
||||
// Material type = blockState.getType();
|
||||
//
|
||||
// return type == Repair.getInstance().getAnvilMaterial() || type == Salvage.anvilMaterial;
|
||||
// }
|
||||
|
||||
return type == Repair.getInstance().getAnvilMaterial() || type == Salvage.anvilMaterial;
|
||||
}
|
||||
|
||||
public static boolean isPistonPiece(BlockState blockState) {
|
||||
public boolean isPistonPiece(BlockState blockState) {
|
||||
Material type = blockState.getType();
|
||||
|
||||
return type == Material.MOVING_PISTON || type == Material.AIR;
|
||||
@@ -441,7 +443,7 @@ public final class BlockUtils {
|
||||
*
|
||||
* @return HashSet with the IDs of every transparent block
|
||||
*/
|
||||
public static HashSet<Material> getTransparentBlocks() {
|
||||
public HashSet<Material> getTransparentBlocks() {
|
||||
HashSet<Material> transparentBlocks = new HashSet<>();
|
||||
|
||||
for (Material material : Material.values()) {
|
||||
@@ -453,7 +455,7 @@ public final class BlockUtils {
|
||||
return transparentBlocks;
|
||||
}
|
||||
|
||||
public static boolean isFullyGrown(BlockState blockState) {
|
||||
public boolean isFullyGrown(BlockState blockState) {
|
||||
BlockData data = blockState.getBlockData();
|
||||
if (data.getMaterial() == Material.CACTUS || data.getMaterial() == Material.SUGAR_CANE)
|
||||
return true;
|
@@ -411,8 +411,8 @@ public class EventManager {
|
||||
return !isCancelled;
|
||||
}
|
||||
|
||||
public void callAbilityDeactivateEvent(Player player, SuperAbilityType ability) {
|
||||
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, PrimarySkillType.getPrimarySkillBySuperAbility(ability));
|
||||
public void callAbilityDeactivateEvent(Player player, SuperAbilityType superAbilityType) {
|
||||
McMMOPlayerAbilityDeactivateEvent event = new McMMOPlayerAbilityDeactivateEvent(player, pluginRef.getSkillTools().getPrimarySkillBySuperAbility(superAbilityType));
|
||||
pluginRef.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.listeners.InteractionManager;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.*;
|
||||
@@ -273,7 +272,7 @@ public class TextComponentFactory {
|
||||
//Get skill name
|
||||
String skillName = subSkillType.getLocaleName();
|
||||
|
||||
boolean skillUnlocked = RankUtils.hasUnlockedSubskill(player, subSkillType);
|
||||
boolean skillUnlocked = pluginRef.getRankTools().hasUnlockedSubskill(player, subSkillType);
|
||||
|
||||
TextComponent textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked);
|
||||
|
||||
@@ -297,7 +296,7 @@ public class TextComponentFactory {
|
||||
//Setup Text Component
|
||||
SubSkillType subSkillType = abstractSubSkill.getSubSkillType();
|
||||
|
||||
boolean skillUnlocked = RankUtils.hasUnlockedSubskill(player, subSkillType);
|
||||
boolean skillUnlocked = pluginRef.getRankTools().hasUnlockedSubskill(player, subSkillType);
|
||||
|
||||
TextComponent textComponent = initNewSkillTextComponent(player, skillName, subSkillType, skillUnlocked);
|
||||
|
||||
@@ -313,7 +312,7 @@ public class TextComponentFactory {
|
||||
private TextComponent initNewSkillTextComponent(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) {
|
||||
TextComponent textComponent;
|
||||
if (skillUnlocked) {
|
||||
if (RankUtils.getHighestRank(subSkillType) == RankUtils.getRank(player, subSkillType) && subSkillType.getNumRanks() > 1)
|
||||
if (pluginRef.getRankTools().getHighestRank(subSkillType) == pluginRef.getRankTools().getRank(player, subSkillType) && subSkillType.getNumRanks() > 1)
|
||||
textComponent = new TextComponent(pluginRef.getLocaleManager().getString("JSON.Hover.MaxRankSkillName", skillName));
|
||||
else
|
||||
textComponent = new TextComponent(pluginRef.getLocaleManager().getString("JSON.Hover.SkillName", skillName));
|
||||
@@ -322,7 +321,7 @@ public class TextComponentFactory {
|
||||
|
||||
} else {
|
||||
textComponent = new TextComponent(pluginRef.getLocaleManager().getString("JSON.Hover.Mystery",
|
||||
String.valueOf(RankUtils.getUnlockLevel(subSkillType))));
|
||||
String.valueOf(pluginRef.getRankTools().getUnlockLevel(subSkillType))));
|
||||
|
||||
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mmoinfo ???"));
|
||||
}
|
||||
@@ -364,23 +363,23 @@ public class TextComponentFactory {
|
||||
SubSkillType subSkillType = abstractSubSkill.getSubSkillType();
|
||||
|
||||
//SubSkillType Name
|
||||
ComponentBuilder componentBuilder = setupSkillComponentNameStyle(player, skillName, subSkillType, RankUtils.hasUnlockedSubskill(player, abstractSubSkill));
|
||||
ComponentBuilder componentBuilder = setupSkillComponentNameStyle(player, skillName, subSkillType, pluginRef.getRankTools().hasUnlockedSubskill(player, abstractSubSkill));
|
||||
|
||||
if (!RankUtils.hasUnlockedSubskill(player, abstractSubSkill)) {
|
||||
if (!pluginRef.getRankTools().hasUnlockedSubskill(player, abstractSubSkill)) {
|
||||
//Skill is not unlocked yet
|
||||
addLocked(abstractSubSkill, ccLocked, ccLevelRequirement, ccLevelRequired, componentBuilder);
|
||||
} else {
|
||||
addSubSkillTypeToHoverEventJSON(abstractSubSkill, componentBuilder);
|
||||
|
||||
//RANK
|
||||
int curRank = RankUtils.getRank(player, abstractSubSkill);
|
||||
int curRank = pluginRef.getRankTools().getRank(player, abstractSubSkill);
|
||||
int nextRank = 0;
|
||||
|
||||
if (curRank < abstractSubSkill.getNumRanks() && abstractSubSkill.getNumRanks() > 0) {
|
||||
nextRank = RankUtils.getRankUnlockLevel(abstractSubSkill, curRank + 1);
|
||||
nextRank = pluginRef.getRankTools().getRankUnlockLevel(abstractSubSkill, curRank + 1);
|
||||
}
|
||||
|
||||
addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, abstractSubSkill.getNumRanks(), RankUtils.getRank(player, abstractSubSkill), nextRank);
|
||||
addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, abstractSubSkill.getNumRanks(), pluginRef.getRankTools().getRank(player, abstractSubSkill), nextRank);
|
||||
|
||||
componentBuilder.append(pluginRef.getLocaleManager().getString("JSON.DescriptionHeader"));
|
||||
componentBuilder.append("\n").append(abstractSubSkill.getDescription()).append("\n");
|
||||
@@ -399,13 +398,13 @@ public class TextComponentFactory {
|
||||
private ComponentBuilder setupSkillComponentNameStyle(Player player, String skillName, SubSkillType subSkillType, boolean skillUnlocked) {
|
||||
ComponentBuilder componentBuilder;
|
||||
if (skillUnlocked) {
|
||||
if (RankUtils.getHighestRank(subSkillType) == RankUtils.getRank(player, subSkillType) && subSkillType.getNumRanks() > 1)
|
||||
if (pluginRef.getRankTools().getHighestRank(subSkillType) == pluginRef.getRankTools().getRank(player, subSkillType) && subSkillType.getNumRanks() > 1)
|
||||
componentBuilder = getNewComponentBuilder(pluginRef.getLocaleManager().getString("JSON.Hover.MaxRankSkillName", skillName));
|
||||
else
|
||||
componentBuilder = getNewComponentBuilder(pluginRef.getLocaleManager().getString("JSON.Hover.SkillName", skillName));
|
||||
} else
|
||||
componentBuilder = getNewComponentBuilder(pluginRef.getLocaleManager().getString("JSON.Hover.Mystery",
|
||||
String.valueOf(RankUtils.getUnlockLevel(subSkillType))));
|
||||
String.valueOf(pluginRef.getRankTools().getUnlockLevel(subSkillType))));
|
||||
return componentBuilder;
|
||||
}
|
||||
|
||||
@@ -433,13 +432,13 @@ public class TextComponentFactory {
|
||||
|
||||
private void addLocked(SubSkillType subSkillType, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) {
|
||||
addLocked(ccLocked, ccLevelRequirement, componentBuilder);
|
||||
componentBuilder.append(String.valueOf(RankUtils.getSubSkillUnlockLevel(subSkillType, 1))).color(ccLevelRequired);
|
||||
componentBuilder.append(String.valueOf(pluginRef.getRankTools().getSubSkillUnlockLevel(subSkillType, 1))).color(ccLevelRequired);
|
||||
//componentBuilder.append("\n");
|
||||
}
|
||||
|
||||
private void addLocked(AbstractSubSkill abstractSubSkill, ChatColor ccLocked, ChatColor ccLevelRequirement, ChatColor ccLevelRequired, ComponentBuilder componentBuilder) {
|
||||
addLocked(ccLocked, ccLevelRequirement, componentBuilder);
|
||||
componentBuilder.append(String.valueOf(RankUtils.getSubSkillUnlockLevel(abstractSubSkill, 1))).color(ccLevelRequired);
|
||||
componentBuilder.append(String.valueOf(pluginRef.getRankTools().getSubSkillUnlockLevel(abstractSubSkill, 1))).color(ccLevelRequired);
|
||||
//componentBuilder.append("\n");m
|
||||
}
|
||||
|
||||
@@ -468,9 +467,9 @@ public class TextComponentFactory {
|
||||
ChatColor ccLevelRequired = ChatColor.RED;
|
||||
|
||||
//SubSkillType Name
|
||||
ComponentBuilder componentBuilder = setupSkillComponentNameStyle(player, skillName, subSkillType, RankUtils.hasUnlockedSubskill(player, subSkillType));
|
||||
ComponentBuilder componentBuilder = setupSkillComponentNameStyle(player, skillName, subSkillType, pluginRef.getRankTools().hasUnlockedSubskill(player, subSkillType));
|
||||
|
||||
if (!RankUtils.hasUnlockedSubskill(player, subSkillType)) {
|
||||
if (!pluginRef.getRankTools().hasUnlockedSubskill(player, subSkillType)) {
|
||||
//Skill is not unlocked yet
|
||||
addLocked(subSkillType, ccLocked, ccLevelRequirement, ccLevelRequired, componentBuilder);
|
||||
} else {
|
||||
@@ -478,14 +477,14 @@ public class TextComponentFactory {
|
||||
|
||||
//RANK
|
||||
if (subSkillType.getNumRanks() > 0) {
|
||||
int curRank = RankUtils.getRank(player, subSkillType);
|
||||
int curRank = pluginRef.getRankTools().getRank(player, subSkillType);
|
||||
int nextRank = 0;
|
||||
|
||||
if (curRank < subSkillType.getNumRanks() && subSkillType.getNumRanks() > 0) {
|
||||
nextRank = RankUtils.getRankUnlockLevel(subSkillType, curRank + 1);
|
||||
nextRank = pluginRef.getRankTools().getRankUnlockLevel(subSkillType, curRank + 1);
|
||||
}
|
||||
|
||||
addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, subSkillType.getNumRanks(), RankUtils.getRank(player, subSkillType), nextRank);
|
||||
addRanked(ccRank, ccCurRank, ccPossessive, ccNumRanks, componentBuilder, subSkillType.getNumRanks(), pluginRef.getRankTools().getRank(player, subSkillType), nextRank);
|
||||
|
||||
}
|
||||
|
||||
@@ -536,7 +535,7 @@ public class TextComponentFactory {
|
||||
|
||||
public TextComponent getSubSkillUnlockedNotificationComponents(Player player, SubSkillType subSkillType) {
|
||||
TextComponent unlockMessage = new TextComponent("");
|
||||
unlockMessage.setText(pluginRef.getLocaleManager().getString("JSON.SkillUnlockMessage", subSkillType.getLocaleName(), RankUtils.getRank(player, subSkillType)));
|
||||
unlockMessage.setText(pluginRef.getLocaleManager().getString("JSON.SkillUnlockMessage", subSkillType.getLocaleName(), pluginRef.getRankTools().getRank(player, subSkillType)));
|
||||
unlockMessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, getSubSkillHoverComponent(player, subSkillType)));
|
||||
unlockMessage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + subSkillType.getParentSkill().toString().toLowerCase()));
|
||||
return unlockMessage;
|
||||
|
@@ -376,7 +376,7 @@ public final class CombatTools {
|
||||
}
|
||||
|
||||
public int getLimitBreakDamage(Player player, SubSkillType subSkillType) {
|
||||
return RankUtils.getRank(player, subSkillType);
|
||||
return pluginRef.getRankTools().getRank(player, subSkillType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,7 +386,7 @@ public final class CombatTools {
|
||||
* @return true if the player has access to the limit break
|
||||
*/
|
||||
public boolean canUseLimitBreak(Player player, SubSkillType subSkillType) {
|
||||
return RankUtils.hasUnlockedSubskill(player, subSkillType)
|
||||
return pluginRef.getRankTools().hasUnlockedSubskill(player, subSkillType)
|
||||
&& Permissions.isSubSkillEnabled(player, subSkillType);
|
||||
}
|
||||
|
||||
|
@@ -8,28 +8,34 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.listeners.InteractionManager;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.runnables.skills.SkillUnlockNotificationTask;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RankUtils {
|
||||
private static HashMap<String, HashMap<Integer, Integer>> subSkillRanks;
|
||||
private static int count = 0;
|
||||
public class RankTools {
|
||||
|
||||
private final mcMMO pluginRef;
|
||||
|
||||
public RankTools(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
}
|
||||
|
||||
private HashMap<String, HashMap<Integer, Integer>> subSkillRanks;
|
||||
private int count = 0;
|
||||
|
||||
/**
|
||||
* @param plugin plugin instance ref
|
||||
* @param mcMMOPlayer target player
|
||||
* @param primarySkillType target primary skill
|
||||
* @param newLevel the new level of this skill
|
||||
*/
|
||||
public static void executeSkillUnlockNotifications(Plugin plugin, McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, int newLevel) {
|
||||
for (SubSkillType subSkillType : primarySkillType.getSkillAbilities()) {
|
||||
public void executeSkillUnlockNotifications(McMMOPlayer mcMMOPlayer, PrimarySkillType primarySkillType, int newLevel) {
|
||||
for (SubSkillType subSkillType : pluginRef.getSkillTools().getSkillAbilities(primarySkillType)) {
|
||||
int playerRankInSkill = getRank(mcMMOPlayer.getPlayer(), subSkillType);
|
||||
|
||||
HashMap<Integer, Integer> innerMap = subSkillRanks.get(subSkillType.toString());
|
||||
@@ -44,21 +50,21 @@ public class RankUtils {
|
||||
|
||||
//The players level is the exact level requirement for this skill
|
||||
if (newLevel == innerMap.get(playerRankInSkill)) {
|
||||
SkillUnlockNotificationTask skillUnlockNotificationTask = new SkillUnlockNotificationTask(mcMMOPlayer, subSkillType);
|
||||
SkillUnlockNotificationTask skillUnlockNotificationTask = new SkillUnlockNotificationTask(pluginRef, mcMMOPlayer, subSkillType);
|
||||
|
||||
skillUnlockNotificationTask.runTaskLater(plugin, (count * 100));
|
||||
skillUnlockNotificationTask.runTaskLater(pluginRef, (count * 100));
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetUnlockDelayTimer() {
|
||||
public void resetUnlockDelayTimer() {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
/* NEW SYSTEM */
|
||||
private static void addRanks(AbstractSubSkill abstractSubSkill) {
|
||||
private void addRanks(AbstractSubSkill abstractSubSkill) {
|
||||
//Fill out the rank array
|
||||
for (int i = 0; i < abstractSubSkill.getNumRanks(); i++) {
|
||||
//This adds the highest ranks first
|
||||
@@ -69,7 +75,7 @@ public class RankUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addRanks(SubSkillType subSkillType) {
|
||||
private void addRanks(SubSkillType subSkillType) {
|
||||
//Fill out the rank array
|
||||
for (int i = 0; i < subSkillType.getNumRanks(); i++) {
|
||||
//This adds the highest ranks first
|
||||
@@ -83,7 +89,7 @@ public class RankUtils {
|
||||
/**
|
||||
* Populates the ranks for every skill we know about
|
||||
*/
|
||||
public static void populateRanks() {
|
||||
public void populateRanks() {
|
||||
for (SubSkillType subSkillType : SubSkillType.values()) {
|
||||
addRanks(subSkillType);
|
||||
}
|
||||
@@ -100,7 +106,7 @@ public class RankUtils {
|
||||
* @param subSkillType the target subskill
|
||||
* @return true if the player has at least one rank in the skill
|
||||
*/
|
||||
public static boolean hasUnlockedSubskill(Player player, SubSkillType subSkillType) {
|
||||
public boolean hasUnlockedSubskill(Player player, SubSkillType subSkillType) {
|
||||
int curRank = getRank(player, subSkillType);
|
||||
|
||||
//-1 means the skill has no unlockable levels and is therefor unlocked
|
||||
@@ -114,7 +120,7 @@ public class RankUtils {
|
||||
* @param abstractSubSkill the target subskill
|
||||
* @return true if the player has at least one rank in the skill
|
||||
*/
|
||||
public static boolean hasUnlockedSubskill(Player player, AbstractSubSkill abstractSubSkill) {
|
||||
public boolean hasUnlockedSubskill(Player player, AbstractSubSkill abstractSubSkill) {
|
||||
int curRank = getRank(player, abstractSubSkill);
|
||||
|
||||
//-1 means the skill has no unlockable levels and is therefor unlocked
|
||||
@@ -129,7 +135,7 @@ public class RankUtils {
|
||||
* @param subSkillType the target subskill
|
||||
* @return true if the player is at least that rank in this subskill
|
||||
*/
|
||||
public static boolean hasReachedRank(int rank, Player player, SubSkillType subSkillType) {
|
||||
public boolean hasReachedRank(int rank, Player player, SubSkillType subSkillType) {
|
||||
return getRank(player, subSkillType) >= rank;
|
||||
}
|
||||
|
||||
@@ -141,7 +147,7 @@ public class RankUtils {
|
||||
* @param abstractSubSkill the target subskill
|
||||
* @return true if the player is at least that rank in this subskill
|
||||
*/
|
||||
public static boolean hasReachedRank(int rank, Player player, AbstractSubSkill abstractSubSkill) {
|
||||
public boolean hasReachedRank(int rank, Player player, AbstractSubSkill abstractSubSkill) {
|
||||
return getRank(player, abstractSubSkill) >= rank;
|
||||
}
|
||||
|
||||
@@ -152,7 +158,7 @@ public class RankUtils {
|
||||
* @param subSkillType Target subskill
|
||||
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
|
||||
*/
|
||||
public static int getRank(Player player, SubSkillType subSkillType) {
|
||||
public int getRank(Player player, SubSkillType subSkillType) {
|
||||
String skillName = subSkillType.toString();
|
||||
int numRanks = subSkillType.getNumRanks();
|
||||
|
||||
@@ -172,7 +178,7 @@ public class RankUtils {
|
||||
return 0;
|
||||
|
||||
//Skill level of parent skill
|
||||
int currentSkillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(subSkillType.getParentSkill());
|
||||
int currentSkillLevel = pluginRef.getUserManager().getPlayer(player).getSkillLevel(subSkillType.getParentSkill(pluginRef));
|
||||
|
||||
for (int i = 0; i < numRanks; i++) {
|
||||
//Compare against the highest to lowest rank in that order
|
||||
@@ -198,7 +204,7 @@ public class RankUtils {
|
||||
* @param abstractSubSkill Target subskill
|
||||
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
|
||||
*/
|
||||
public static int getRank(Player player, AbstractSubSkill abstractSubSkill) {
|
||||
public int getRank(Player player, AbstractSubSkill abstractSubSkill) {
|
||||
String skillName = abstractSubSkill.getConfigKeyName();
|
||||
int numRanks = abstractSubSkill.getNumRanks();
|
||||
|
||||
@@ -243,7 +249,7 @@ public class RankUtils {
|
||||
* @param abstractSubSkill The subskill to add ranks for
|
||||
* @param rank The rank to add
|
||||
*/
|
||||
private static void addRank(AbstractSubSkill abstractSubSkill, int rank) {
|
||||
private void addRank(AbstractSubSkill abstractSubSkill, int rank) {
|
||||
initMaps(abstractSubSkill.getConfigKeyName());
|
||||
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(abstractSubSkill.getConfigKeyName());
|
||||
@@ -252,7 +258,7 @@ public class RankUtils {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static void addRank(SubSkillType subSkillType, int rank) {
|
||||
private void addRank(SubSkillType subSkillType, int rank) {
|
||||
initMaps(subSkillType.toString());
|
||||
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkillType.toString());
|
||||
@@ -260,14 +266,14 @@ public class RankUtils {
|
||||
rankMap.put(rank, getRankUnlockLevel(subSkillType, rank));
|
||||
}
|
||||
|
||||
private static void initMaps(String s) {
|
||||
private void initMaps(String s) {
|
||||
if (subSkillRanks == null)
|
||||
subSkillRanks = new HashMap<>();
|
||||
|
||||
subSkillRanks.computeIfAbsent(s, k -> new HashMap<>());
|
||||
}
|
||||
|
||||
/* public static int getSubSkillUnlockRequirement(SubSkillType subSkillType)
|
||||
/* public int getSubSkillUnlockRequirement(SubSkillType subSkillType)
|
||||
{
|
||||
String skillName = subSkillType.toString();
|
||||
int numRanks = subSkillType.getNumRanks();
|
||||
@@ -292,11 +298,11 @@ public class RankUtils {
|
||||
* @return The level at which this rank unlocks
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getRankUnlockLevel(SubSkillType subSkillType, int rank) {
|
||||
public int getRankUnlockLevel(SubSkillType subSkillType, int rank) {
|
||||
return getSubSkillUnlockLevel(subSkillType, rank);
|
||||
}
|
||||
|
||||
public static int getRankUnlockLevel(AbstractSubSkill abstractSubSkill, int rank) {
|
||||
public int getRankUnlockLevel(AbstractSubSkill abstractSubSkill, int rank) {
|
||||
return getSubSkillUnlockLevel(abstractSubSkill, rank);
|
||||
}
|
||||
|
||||
@@ -306,7 +312,7 @@ public class RankUtils {
|
||||
* @param subSkillType target subskill
|
||||
* @return The unlock requirements for rank 1 in this skill
|
||||
*/
|
||||
public static int getUnlockLevel(SubSkillType subSkillType) {
|
||||
public int getUnlockLevel(SubSkillType subSkillType) {
|
||||
return getSubSkillUnlockLevel(subSkillType, 1);
|
||||
}
|
||||
|
||||
@@ -316,7 +322,7 @@ public class RankUtils {
|
||||
* @param abstractSubSkill target subskill
|
||||
* @return The unlock requirements for rank 1 in this skill
|
||||
*/
|
||||
public static int getUnlockLevel(AbstractSubSkill abstractSubSkill) {
|
||||
public int getUnlockLevel(AbstractSubSkill abstractSubSkill) {
|
||||
return getSubSkillUnlockLevel(abstractSubSkill, 1);
|
||||
}
|
||||
|
||||
@@ -326,11 +332,11 @@ public class RankUtils {
|
||||
* @param subSkillType target subskill
|
||||
* @return the last rank of a subskill
|
||||
*/
|
||||
public static int getHighestRank(SubSkillType subSkillType) {
|
||||
public int getHighestRank(SubSkillType subSkillType) {
|
||||
return subSkillType.getNumRanks();
|
||||
}
|
||||
|
||||
public static String getHighestRankStr(SubSkillType subSkillType) {
|
||||
public String getHighestRankStr(SubSkillType subSkillType) {
|
||||
return String.valueOf(subSkillType.getNumRanks());
|
||||
}
|
||||
|
||||
@@ -340,11 +346,11 @@ public class RankUtils {
|
||||
* @param abstractSubSkill target subskill
|
||||
* @return the last rank of a subskill
|
||||
*/
|
||||
public static int getHighestRank(AbstractSubSkill abstractSubSkill) {
|
||||
public int getHighestRank(AbstractSubSkill abstractSubSkill) {
|
||||
return abstractSubSkill.getNumRanks();
|
||||
}
|
||||
|
||||
public static int getSuperAbilityUnlockRequirement(SuperAbilityType superAbilityType) {
|
||||
public int getSuperAbilityUnlockRequirement(SuperAbilityType superAbilityType) {
|
||||
return getRankUnlockLevel(superAbilityType.getSubSkillTypeDefinition(), 1);
|
||||
}
|
||||
|
||||
@@ -355,7 +361,7 @@ public class RankUtils {
|
||||
* @param rank the rank we are checking
|
||||
* @return the level requirement for a subskill at this particular rank
|
||||
*/
|
||||
public static int getSubSkillUnlockLevel(SubSkillType subSkillType, int rank) {
|
||||
public int getSubSkillUnlockLevel(SubSkillType subSkillType, int rank) {
|
||||
return findRankByRootAddress(rank, subSkillType);
|
||||
}
|
||||
|
||||
@@ -366,7 +372,7 @@ public class RankUtils {
|
||||
* @param rank the rank we are checking
|
||||
* @return the level requirement for a subskill at this particular rank
|
||||
*/
|
||||
public static int getSubSkillUnlockLevel(AbstractSubSkill abstractSubSkill, int rank) {
|
||||
public int getSubSkillUnlockLevel(AbstractSubSkill abstractSubSkill, int rank) {
|
||||
return findRankByRootAddress(rank, abstractSubSkill.getSubSkillType());
|
||||
}
|
||||
|
||||
@@ -377,13 +383,13 @@ public class RankUtils {
|
||||
* @param rank the rank we are checking
|
||||
* @return the level requirement for a subskill at this particular rank
|
||||
*/
|
||||
private static int findRankByRootAddress(int rank, SubSkillType subSkillType) {
|
||||
private int findRankByRootAddress(int rank, SubSkillType subSkillType) {
|
||||
|
||||
CommentedConfigurationNode rankConfigRoot = pluginRef.getConfigManager().getConfigRanksRootNode();
|
||||
|
||||
try {
|
||||
SkillRankProperty skillRankProperty
|
||||
= (SkillRankProperty) rankConfigRoot.getNode(subSkillType.getParentSkill().getCapitalizedPrimarySkillName())
|
||||
= (SkillRankProperty) rankConfigRoot.getNode(pluginRef.getSkillTools().getCapitalizedPrimarySkillName(subSkillType.getParentSkill(pluginRef)))
|
||||
.getNode(subSkillType.getHoconFriendlyConfigName())
|
||||
.getValue(TypeToken.of(SkillRankProperty.class));
|
||||
|
||||
@@ -397,10 +403,10 @@ public class RankUtils {
|
||||
}
|
||||
|
||||
//Default to the max level for the skill if any errors were encountered incorrect
|
||||
return pluginRef.getConfigManager().getConfigLeveling().getSkillLevelCap(subSkillType.getParentSkill());
|
||||
return pluginRef.getConfigManager().getConfigLeveling().getSkillLevelCap(subSkillType.getParentSkill(pluginRef));
|
||||
}
|
||||
|
||||
public static boolean isPlayerMaxRankInSubSkill(Player player, SubSkillType subSkillType) {
|
||||
public boolean isPlayerMaxRankInSubSkill(Player player, SubSkillType subSkillType) {
|
||||
int playerRank = getRank(player, subSkillType);
|
||||
int highestRank = getHighestRank(subSkillType);
|
||||
|
@@ -276,7 +276,7 @@ public class SkillTools {
|
||||
}
|
||||
|
||||
public int handleFoodSkills(Player player, int eventFoodLevel, SubSkillType subSkillType) {
|
||||
int curRank = RankUtils.getRank(player, subSkillType);
|
||||
int curRank = pluginRef.getRankTools().getRank(player, subSkillType);
|
||||
|
||||
int currentFoodLevel = player.getFoodLevel();
|
||||
int foodChange = eventFoodLevel - currentFoodLevel;
|
||||
@@ -643,7 +643,7 @@ public class SkillTools {
|
||||
}
|
||||
|
||||
public boolean isSuperAbilityUnlocked(PrimarySkillType primarySkillType, Player player) {
|
||||
return RankUtils.getRank(player, getSuperAbility(primarySkillType).getSubSkillTypeDefinition()) >= 1;
|
||||
return pluginRef.getRankTools().getRank(player, getSuperAbility(primarySkillType).getSubSkillTypeDefinition()) >= 1;
|
||||
}
|
||||
|
||||
public boolean getPVPEnabled(PrimarySkillType primarySkillType) {
|
||||
|
Reference in New Issue
Block a user