use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ManaAbilityManager method startTimer.
private void startTimer() {
new BukkitRunnable() {
@Override
public void run() {
for (UUID id : cooldowns.keySet()) {
Map<MAbility, Integer> abilityCooldowns = cooldowns.get(id);
if (abilityCooldowns != null) {
for (MAbility ab : abilityCooldowns.keySet()) {
int cooldown = abilityCooldowns.get(ab);
if (cooldown >= 2) {
abilityCooldowns.put(ab, cooldown - 2);
} else if (cooldown == 1) {
abilityCooldowns.put(ab, 0);
}
if (cooldown == 2 || cooldown == 1) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(id);
if (playerData != null) {
ManaAbilityRefreshEvent event = new ManaAbilityRefreshEvent(playerData.getPlayer(), ab);
Bukkit.getPluginManager().callEvent(event);
}
}
}
} else {
cooldowns.put(id, new HashMap<>());
}
}
}
}.runTaskTimer(plugin, 0L, 2L);
new BukkitRunnable() {
@Override
public void run() {
for (UUID id : errorTimer.keySet()) {
Map<MAbility, Integer> errorTimers = errorTimer.get(id);
if (errorTimers != null) {
for (MAbility ab : errorTimers.keySet()) {
int timer = errorTimers.get(ab);
if (timer > 0) {
errorTimers.put(ab, timer - 1);
}
}
} else {
errorTimer.put(id, new HashMap<>());
}
}
}
}.runTaskTimer(plugin, 0L, 20L);
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ManaAbilityProvider method hasEnoughMana.
// Returns true if player has enough mana
protected boolean hasEnoughMana(Player player) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return false;
Locale locale = playerData.getLocale();
if (playerData.getMana() >= plugin.getManaAbilityManager().getManaCost(mAbility, playerData)) {
return true;
} else {
plugin.getAbilityManager().sendMessage(player, TextUtil.replace(Lang.getMessage(ManaAbilityMessage.NOT_ENOUGH_MANA, locale), "{mana}", NumberUtil.format0(plugin.getManaAbilityManager().getManaCost(mAbility, playerData)), "{current_mana}", String.valueOf(Math.round(playerData.getMana())), "{max_mana}", String.valueOf(Math.round(playerData.getMaxMana()))));
return false;
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ManaAbilityProvider method activate.
public void activate(Player player) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
int duration = getDuration(playerData);
ManaAbilityActivateEvent event = new ManaAbilityActivateEvent(player, mAbility, duration);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
manager.setActivated(player, mAbility, true);
// Mana ability specific behavior is run
onActivate(player, playerData);
consumeMana(player, playerData);
if (duration != 0) {
// Schedules stop
new BukkitRunnable() {
@Override
public void run() {
stop(player);
manager.setActivated(player, mAbility, false);
manager.setReady(player.getUniqueId(), mAbility, false);
}
}.runTaskLater(plugin, duration);
} else {
stop(player);
manager.setActivated(player, mAbility, false);
manager.setReady(player.getUniqueId(), mAbility, false);
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class ReadiedManaAbility method onReady.
@EventHandler
public void onReady(PlayerInteractEvent event) {
if (!OptionL.isEnabled(skill))
return;
if (!plugin.getAbilityManager().isEnabled(mAbility))
return;
// Check action is valid
boolean valid = false;
for (Action action : actions) {
if (event.getAction() == action) {
valid = true;
break;
}
}
if (!valid)
return;
// Check block exclusions
Block block = event.getClickedBlock();
if (block != null) {
if (isExcludedBlock(block))
return;
}
// Match sure material matches
Player player = event.getPlayer();
if (!isHoldingMaterial(player)) {
return;
}
if (!isAllowReady(player, event)) {
return;
}
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData == null)
return;
Locale locale = playerData.getLocale();
if (playerData.getManaAbilityLevel(mAbility) <= 0) {
return;
}
// Check if already activated
if (manager.isActivated(player.getUniqueId(), mAbility)) {
return;
}
// Checks if already ready
if (manager.isReady(player.getUniqueId(), mAbility)) {
return;
}
if (manager.getPlayerCooldown(player.getUniqueId(), mAbility) == 0) {
// Ready
manager.setReady(player.getUniqueId(), mAbility, true);
plugin.getAbilityManager().sendMessage(player, ChatColor.GRAY + Lang.getMessage(ManaAbilityMessage.valueOf(mAbility.name() + "_RAISE"), locale));
scheduleUnready(player, locale);
} else {
// Cannot ready, send cooldown error
if (manager.getErrorTimer(player.getUniqueId(), mAbility) == 0) {
plugin.getAbilityManager().sendMessage(player, Lang.getMessage(ManaAbilityMessage.NOT_READY, locale).replace("{cooldown}", NumberUtil.format0((double) plugin.getManaAbilityManager().getPlayerCooldown(player.getUniqueId(), mAbility) / 20)));
manager.setErrorTimer(player.getUniqueId(), mAbility, 2);
}
}
}
use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.
the class SkillLeveler method getXp.
public double getXp(Player player, double input, Ability ability) {
PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
if (playerData != null) {
double output = input;
if (ability != null) {
if (plugin.getAbilityManager().isEnabled(ability)) {
double modifier = 1;
modifier += plugin.getAbilityManager().getValue(ability, playerData.getAbilityLevel(ability)) / 100;
output *= modifier;
}
}
return output;
}
return 0.0;
}
Aggregations