add McMMO hooks

This commit is contained in:
jascotty2 2019-10-09 19:31:33 -05:00
parent 15a191a8b0
commit aeafb31b04
3 changed files with 738 additions and 5 deletions

View File

@ -268,6 +268,12 @@
<version>4.13.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.nossr50</groupId>
<artifactId>mcmmo</artifactId>
<version>2.1.50</version>
<scope>provided</scope>
</dependency>
<!-- End Plugin Hooks -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>

View File

@ -1,17 +1,230 @@
package com.songoda.core.hooks;
import com.songoda.core.hooks.mcmmo.McMMOHandler;
import java.util.Collection;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
public class McMMOHook {
static boolean canHook = false;
static {
try {
// if this class exists, we're good to use WG classes
Class.forName("com.sk89q.worldguard.protection.flags.Flag");
try {
// if this class exists, we're good to use McMMO
Class.forName("com.gmail.nossr50.api.AbilityAPI");
canHook = true;
} catch (ClassNotFoundException ex) {
}
}
public static void addMining(Player player, Collection<Block> blocks) {
if (canHook) {
McMMOHandler.addMining(player, blocks);
}
}
public static void addExcavation(Player player, Collection<Block> blocks) {
if (canHook) {
McMMOHandler.addExcavation(player, blocks);
}
}
public static void addHerbalism(Player player, Collection<Block> blocks) {
if (canHook) {
McMMOHandler.addHerbalism(player, blocks);
}
}
public static void addWoodcutting(Player player, Collection<Block> blocks) {
if (canHook) {
McMMOHandler.addWoodcutting(player, blocks);
}
}
public static int getAcrobaticsSkill(Player player) {
return canHook ? McMMOHandler.getAcrobaticsSkill(player) : -1;
}
public static int getAlchemySkill(Player player) {
return canHook ? McMMOHandler.getAlchemySkill(player) : -1;
}
public static int getArcherySkill(Player player) {
return canHook ? McMMOHandler.getArcherySkill(player) : -1;
}
public static int getAxesSkill(Player player) {
return canHook ? McMMOHandler.getAxesSkill(player) : -1;
}
public static int getExcavationSkill(Player player) {
return canHook ? McMMOHandler.getExcavationSkill(player) : -1;
}
public static int getFishingSkill(Player player) {
return canHook ? McMMOHandler.getFishingSkill(player) : -1;
}
public static int getHerbalismSkill(Player player) {
return canHook ? McMMOHandler.getHerbalismSkill(player) : -1;
}
public static int getMiningSkill(Player player) {
return canHook ? McMMOHandler.getMiningSkill(player) : -1;
}
public static int getRepairSkill(Player player) {
return canHook ? McMMOHandler.getRepairSkill(player) : -1;
}
public static int getSmeltingSkill(Player player) {
return canHook ? McMMOHandler.getSmeltingSkill(player) : -1;
}
public static int getSwordsSkill(Player player) {
return canHook ? McMMOHandler.getSwordsSkill(player) : -1;
}
public static int getTamingSkill(Player player) {
return canHook ? McMMOHandler.getTamingSkill(player) : -1;
}
public static int getUnarmedSkill(Player player) {
return canHook ? McMMOHandler.getUnarmedSkill(player) : -1;
}
public static int getWoodcuttingSkill(Player player) {
return canHook ? McMMOHandler.getWoodcuttingSkill(player) : -1;
}
public static void addAcrobatics(Player player, int xp) {
if (canHook) {
McMMOHandler.addAcrobatics(player, xp);
}
}
public static void addAlchemy(Player player, int xp) {
if (canHook) {
McMMOHandler.addAlchemy(player, xp);
}
}
public static void addArchery(Player player, int xp) {
if (canHook) {
McMMOHandler.addArchery(player, xp);
}
}
public static void addAxes(Player player, int xp) {
if (canHook) {
McMMOHandler.addAxes(player, xp);
}
}
public static void addExcavation(Player player, int xp) {
if (canHook) {
McMMOHandler.addExcavation(player, xp);
}
}
public static void addFishing(Player player, int xp) {
if (canHook) {
McMMOHandler.addFishing(player, xp);
}
}
public static void addHerbalism(Player player, int xp) {
if (canHook) {
McMMOHandler.addHerbalism(player, xp);
}
}
public static void addMining(Player player, int xp) {
if (canHook) {
McMMOHandler.addMining(player, xp);
}
}
public static void addRepair(Player player, int xp) {
if (canHook) {
McMMOHandler.addRepair(player, xp);
}
}
public static void addSmelting(Player player, int xp) {
if (canHook) {
McMMOHandler.addSmelting(player, xp);
}
}
public static void addSwords(Player player, int xp) {
if (canHook) {
McMMOHandler.addSwords(player, xp);
}
}
public static void addTaming(Player player, int xp) {
if (canHook) {
McMMOHandler.addTaming(player, xp);
}
}
public static void addUnarmed(Player player, int xp) {
if (canHook) {
McMMOHandler.addUnarmed(player, xp);
}
}
public static void addWoodcutting(Player player, int xp) {
if (canHook) {
McMMOHandler.addWoodcutting(player, xp);
}
}
public static boolean hasHerbalismDoubleDrops(Player player) {
return canHook ? McMMOHandler.hasHerbalismDoubleDrops(player) : false;
}
public static boolean hasMiningDoubleDrops(Player player) {
return canHook ? McMMOHandler.hasMiningDoubleDrops(player) : false;
}
public static boolean hasWoodcuttingDoubleDrops(Player player) {
return canHook ? McMMOHandler.hasWoodcuttingDoubleDrops(player) : false;
}
public static boolean isUsingBerserk(Player player) {
return canHook ? McMMOHandler.isUsingBerserk(player) : false;
}
public static boolean isUsingGigaDrill(Player player) {
return canHook ? McMMOHandler.isUsingGigaDrill(player) : false;
}
public static boolean isUsingGreenTerra(Player player) {
return canHook ? McMMOHandler.isUsingGreenTerra(player) : false;
}
public static boolean isUsingSerratedStrikes(Player player) {
return canHook ? McMMOHandler.isUsingSerratedStrikes(player) : false;
}
public static boolean isUsingSkullSplitter(Player player) {
return canHook ? McMMOHandler.isUsingSkullSplitter(player) : false;
}
public static boolean isUsingSuperBreaker(Player player) {
return canHook ? McMMOHandler.isUsingSuperBreaker(player) : false;
}
public static boolean isUsingTreeFeller(Player player) {
return canHook ? McMMOHandler.isUsingTreeFeller(player) : false;
}
public static boolean isBleeding(LivingEntity victim) {
return canHook ? McMMOHandler.isBleeding(victim) : false;
}
}

View File

@ -0,0 +1,514 @@
package com.songoda.core.hooks.mcmmo;
import com.gmail.nossr50.api.AbilityAPI;
import com.gmail.nossr50.api.ExperienceAPI;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.experience.XPGainSource;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.random.RandomChanceUtil;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType;
import com.songoda.core.compatibility.ServerVersion;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
public class McMMOHandler {
static boolean mcmmo_v2 = false;
static boolean legacy_v13 = false;
static boolean legacy_v12 = false;
static boolean legacy_v8 = false;
static Class mcmmo_SkillType;
static Method mcmmo_SkillType_valueOf;
static Method mcmmo_SkillType_getDoubleDropsDisabled;
static Object mcmmo_ExperienceConfig_instance;
static Method mcmmo_ExperienceConfig_getXp;
static Method mcmmo_McMMOPlayer_getSkillLevel;
static Class mcmmo_PerksUtils;
static Method mcmmo_PerksUtils_handleLuckyPerks;
static Class mcmmo_SecondaryAbility;
static Method mcmmo_SecondaryAbility_valueOf;
static Method mcmmo_Permissions_secondaryAbilityEnabled;
static Method mcmmo_SkillUtils_activationSuccessful;
static {
try {
Class.forName("com.gmail.nossr50.datatypes.skills.PrimarySkillType");
mcmmo_v2 = true;
} catch (ClassNotFoundException ex) {
try {
mcmmo_SkillType = Class.forName("com.gmail.nossr50.datatypes.skills.SkillType");
mcmmo_SkillType_valueOf = mcmmo_SkillType.getDeclaredMethod("valueOf", String.class);
mcmmo_SkillType_getDoubleDropsDisabled = mcmmo_SkillType.getDeclaredMethod("getDoubleDropsDisabled");
mcmmo_ExperienceConfig_instance = ExperienceConfig.getInstance();
mcmmo_McMMOPlayer_getSkillLevel = com.gmail.nossr50.datatypes.player.McMMOPlayer.class.getDeclaredMethod("getSkillLevel", mcmmo_SkillType);
mcmmo_PerksUtils = Class.forName("com.gmail.nossr50.util.skills.PerksUtils");
mcmmo_PerksUtils_handleLuckyPerks = mcmmo_PerksUtils.getDeclaredMethod("handleLuckyPerks", Player.class, mcmmo_SkillType);
mcmmo_SecondaryAbility = Class.forName("com.gmail.nossr50.datatypes.skills.SecondaryAbility");
mcmmo_SecondaryAbility_valueOf = mcmmo_SecondaryAbility.getDeclaredMethod("valueOf", String.class);
mcmmo_Permissions_secondaryAbilityEnabled = com.gmail.nossr50.util.Permissions.class.getDeclaredMethod("secondaryAbilityEnabled", Player.class, mcmmo_SecondaryAbility);
mcmmo_SkillUtils_activationSuccessful = com.gmail.nossr50.util.skills.SkillUtils.class.getDeclaredMethod("activationSuccessful", mcmmo_SecondaryAbility, Player.class, int.class, int.class);
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.block.data.BlockData.class);
legacy_v13 = true;
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.material.MaterialData.class);
legacy_v12 = true;
} else {
mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.Material.class);
legacy_v8 = true;
}
} catch (Exception ex1) {
Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to register McMMO Legacy Hook", ex1);
}
}
}
public static void addMining(Player player, Collection<Block> blocks) {
if (player == null || blocks == null || blocks.isEmpty()) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
addBlockSkillLegacy(player, blocks, "mining");
return;
}
ArrayList<BlockState> blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new));
ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.MINING);
}
public static void addExcavation(Player player, Collection<Block> blocks) {
if (player == null || blocks == null || blocks.isEmpty()) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
addBlockSkillLegacy(player, blocks, "excavation");
return;
}
ArrayList<BlockState> blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new));
ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.EXCAVATION);
}
public static void addHerbalism(Player player, Collection<Block> blocks) {
if (player == null || blocks == null || blocks.isEmpty()) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
addBlockSkillLegacy(player, blocks, "herbalism");
return;
}
ArrayList<BlockState> blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new));
ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.HERBALISM);
}
public static void addWoodcutting(Player player, Collection<Block> blocks) {
if (player == null || blocks == null || blocks.isEmpty()) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
addBlockSkillLegacy(player, blocks, "woodcutting");
return;
}
ArrayList<BlockState> blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new));
ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.WOODCUTTING);
}
public static int getAcrobaticsSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "acrobatics");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ACROBATICS);
}
public static int getAlchemySkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "alchemy");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ALCHEMY);
}
public static int getArcherySkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "archery");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ARCHERY);
}
public static int getAxesSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "axes");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.AXES);
}
public static int getExcavationSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "excavation");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.EXCAVATION);
}
public static int getFishingSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "fishing");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.FISHING);
}
public static int getHerbalismSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "herbalism");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.HERBALISM);
}
public static int getMiningSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "mining");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.MINING);
}
public static int getRepairSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "repair");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.REPAIR);
}
public static int getSmeltingSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "smelting");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.SMELTING);
}
public static int getSwordsSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "swords");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.SWORDS);
}
public static int getTamingSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "taming");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.TAMING);
}
public static int getUnarmedSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "unarmed");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.UNARMED);
}
public static int getWoodcuttingSkill(Player player) {
if (player == null) {
return -1;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
return getSkillLegacy(player, "woodcutting");
}
return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.WOODCUTTING);
}
public static void addAcrobatics(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "acrobatics", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ACROBATICS, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addAlchemy(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "alchemy", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ALCHEMY, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addArchery(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "archery", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ARCHERY, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addAxes(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "axes", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.AXES, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addExcavation(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "excavation", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.EXCAVATION, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addFishing(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "fishing", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.FISHING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addHerbalism(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "herbalism", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.HERBALISM, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addMining(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "mining", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.MINING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addRepair(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "repair", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.REPAIR, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addSmelting(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "smelting", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.SMELTING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addSwords(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "swords", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.SWORDS, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addTaming(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "taming", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.TAMING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addUnarmed(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "unarmed", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.UNARMED, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static void addWoodcutting(Player player, int xp) {
if (player == null) {
return;
} else if (legacy_v13 || legacy_v12 || legacy_v8) {
ExperienceAPI.addXP(player, "woodcutting", xp);
}
UserManager.getPlayer(player).beginXpGain(PrimarySkillType.WOODCUTTING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM);
}
public static boolean hasHerbalismDoubleDrops(Player player) {
if (legacy_v13 || legacy_v12 || legacy_v8) {
return hasBlockDoubleLegacy(player, "herbalism");
}
if (PrimarySkillType.HERBALISM.getDoubleDropsDisabled()) {
return false;
}
return Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_DOUBLE_DROPS)
&& RankUtils.hasReachedRank(1, player, SubSkillType.HERBALISM_DOUBLE_DROPS)
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_DOUBLE_DROPS, player);
}
public static boolean hasMiningDoubleDrops(Player player) {
if (legacy_v13 || legacy_v12 || legacy_v8) {
return hasBlockDoubleLegacy(player, "mining");
}
if (PrimarySkillType.MINING.getDoubleDropsDisabled()) {
return false;
}
return Permissions.isSubSkillEnabled(player, SubSkillType.MINING_DOUBLE_DROPS)
&& RankUtils.hasReachedRank(1, player, SubSkillType.MINING_DOUBLE_DROPS)
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.MINING_DOUBLE_DROPS, player);
}
public static boolean hasWoodcuttingDoubleDrops(Player player) {
if (legacy_v13 || legacy_v12 || legacy_v8) {
return hasBlockDoubleLegacy(player, "woodcutting");
}
if (PrimarySkillType.WOODCUTTING.getDoubleDropsDisabled()) {
return false;
}
return Permissions.isSubSkillEnabled(player, SubSkillType.WOODCUTTING_HARVEST_LUMBER)
&& RankUtils.hasReachedRank(1, player, SubSkillType.WOODCUTTING_HARVEST_LUMBER)
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.WOODCUTTING_HARVEST_LUMBER, player);
}
public static boolean isUsingBerserk(Player player) {
return AbilityAPI.berserkEnabled(player);
}
public static boolean isUsingGigaDrill(Player player) {
return AbilityAPI.gigaDrillBreakerEnabled(player);
}
public static boolean isUsingGreenTerra(Player player) {
return AbilityAPI.greenTerraEnabled(player);
}
public static boolean isUsingSerratedStrikes(Player player) {
return AbilityAPI.serratedStrikesEnabled(player);
}
public static boolean isUsingSkullSplitter(Player player) {
return AbilityAPI.skullSplitterEnabled(player);
}
public static boolean isUsingSuperBreaker(Player player) {
return AbilityAPI.superBreakerEnabled(player);
}
public static boolean isUsingTreeFeller(Player player) {
return AbilityAPI.treeFellerEnabled(player);
}
public static boolean isBleeding(LivingEntity victim) {
return AbilityAPI.isBleeding(victim);
}
/**
* woodcutting, mining, herbalism
*/
protected static boolean hasBlockDoubleLegacy(Player player, String skill) {
if (player.hasMetadata("mcMMO: Player Data")) {
try {
Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase());
if ((boolean) mcmmo_SkillType_getDoubleDropsDisabled.invoke(skillType)) {
return false;
}
int skillLevel = (int) mcmmo_McMMOPlayer_getSkillLevel.invoke(UserManager.getPlayer(player), skillType);
int activationChance = (int) mcmmo_PerksUtils_handleLuckyPerks.invoke(null, player, skillType);
Object secondaryDouble = mcmmo_SecondaryAbility_valueOf.invoke(null, skill.toUpperCase() + "_DOUBLE_DROPS");
if (!((boolean) mcmmo_Permissions_secondaryAbilityEnabled.invoke(null, player, secondaryDouble))) {
return false;
}
return (boolean) mcmmo_SkillUtils_activationSuccessful.invoke(null, secondaryDouble, player, skillLevel, activationChance);
} catch (Exception ex1) {
Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1);
}
}
return false;
}
protected static void addBlockSkillLegacy(Player player, Collection<Block> blocks, String skill) {
try {
Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase());
int xp = 0;
for (Block block : blocks) {
xp += (int) mcmmo_ExperienceConfig_getXp.invoke(mcmmo_ExperienceConfig_instance, skillType, legacy_getBlock(block));
}
ExperienceAPI.addXP(player, skill, xp);
} catch (Exception ex1) {
Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1);
}
}
protected static Object legacy_getBlock(Block block) {
if (legacy_v13) {
return block.getBlockData();
} else if (legacy_v12) {
return block.getState().getData();
} else {
return block.getType();
}
}
protected static int getSkillLegacy(Player player, String skill) {
if (player.hasMetadata("mcMMO: Player Data")) {
try {
Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase());
return (int) mcmmo_McMMOPlayer_getSkillLevel.invoke(UserManager.getPlayer(player), skillType);
} catch (Exception ex1) {
Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1);
}
}
return 0;
}
}