/** * Check to see if an ability can be activated. * * @param skill The skill the ability is based on */ public void checkAbilityActivation(SkillType skill) { ToolType tool = skill.getTool(); AbilityType ability = skill.getAbility(); setToolPreparationMode(tool, false); if (getAbilityMode(ability)) { return; } int timeRemaining = calculateTimeRemaining(ability); if (timeRemaining > 0) { /* * Axes and Woodcutting are odd because they share the same tool. * We show them the too tired message when they take action. */ if (skill == SkillType.WOODCUTTING || skill == SkillType.AXES) { player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining)); } return; } if (EventUtils.callPlayerAbilityActivateEvent(player, skill).isCancelled()) { return; } int ticks = PerksUtils.handleActivationPerks( player, 2 + (getSkillLevel(skill) / AdvancedConfig.getInstance().getAbilityLength()), ability.getMaxLength()); // Notify people that ability has been activated ParticleEffectUtils.playAbilityEnabledEffect(player); if (useChatNotifications()) { player.sendMessage(ability.getAbilityOn()); } SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player)); // Enable the ability profile.setAbilityDATS( ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR)); setAbilityMode(ability, true); if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) { SkillUtils.handleAbilitySpeedIncrease(player); } new AbilityDisableTask(this, ability) .runTaskLater(mcMMO.p, ticks * Misc.TICK_CONVERSION_FACTOR); }
public void processAbilityActivation(SkillType skill) { if (Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && !player.isSneaking()) { return; } ItemStack inHand = player.getItemInHand(); if (mcMMO.getModManager().isCustomTool(inHand) && !mcMMO.getModManager().getTool(inHand).isAbilityEnabled()) { return; } if (!getAbilityUse()) { return; } for (AbilityType abilityType : AbilityType.values()) { if (getAbilityMode(abilityType)) { return; } } AbilityType ability = skill.getAbility(); ToolType tool = skill.getTool(); /* * Woodcutting & Axes need to be treated differently. * Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action */ if (ability.getPermissions(player) && tool.inHand(inHand) && !getToolPreparationMode(tool)) { if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) { int timeRemaining = calculateTimeRemaining(ability); if (!getAbilityMode(ability) && timeRemaining > 0) { player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining)); return; } } if (Config.getInstance().getAbilityMessagesEnabled()) { player.sendMessage(tool.getRaiseTool()); } setToolPreparationMode(tool, true); new ToolLowerTask(this, tool) .runTaskLaterAsynchronously(mcMMO.p, 4 * Misc.TICK_CONVERSION_FACTOR); } }
/** * Calculate the time remaining until the ability's cooldown expires. * * @param ability AbilityType whose cooldown to check * @return the number of seconds remaining before the cooldown expires */ public int calculateTimeRemaining(AbilityType ability) { long deactivatedTimestamp = profile.getAbilityDATS(ability) * Misc.TIME_CONVERSION_FACTOR; return (int) (((deactivatedTimestamp + (PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR); }
public McMMOPlayer(Player player, PlayerProfile profile) { String playerName = player.getName(); UUID uuid = player.getUniqueId(); this.player = player; playerMetadata = new FixedMetadataValue(mcMMO.p, playerName); this.profile = profile; if (profile.getUniqueId() == null) { profile.setUniqueId(uuid); } /* * I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually), * but I actually have no idea about the performance impact, if there is any. * If in the future someone wants to remove this, don't forget to also remove what is in the SkillType enum. - bm01 */ try { for (SkillType skillType : SkillType.values()) { skillManagers.put( skillType, skillType.getManagerClass().getConstructor(McMMOPlayer.class).newInstance(this)); } } catch (Exception e) { e.printStackTrace(); mcMMO.p.getPluginLoader().disablePlugin(mcMMO.p); } for (AbilityType abilityType : AbilityType.values()) { abilityMode.put(abilityType, false); abilityInformed.put(abilityType, true); // This is intended } for (ToolType toolType : ToolType.values()) { toolMode.put(toolType, false); } }
public int getMaxLength(AbilityType ability) { return config.getInt("Abilities.Max_Seconds." + ability.toString()); }
public int getCooldown(AbilityType ability) { return config.getInt("Abilities.Cooldowns." + ability.toString()); }
/** Reset the mode of all abilities. */ public void resetAbilityMode() { for (AbilityType ability : AbilityType.values()) { // Correctly disable and handle any special deactivate code new AbilityDisableTask(this, ability).run(); } }