Added methods to BendingPlayer

This commit is contained in:
jayoevans 2019-10-22 23:10:40 +10:00
parent aee46d53c3
commit 87b6186bee
3 changed files with 272 additions and 19 deletions

View file

@ -8,7 +8,6 @@ import com.projectkorra.projectkorra.player.BendingPlayerLoadedEvent;
import com.projectkorra.projectkorra.player.BendingPlayerManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.sql.SQLException;
@ -175,13 +174,21 @@ public class CooldownManager extends DatabaseModule<CooldownRepository>
return cooldowns != null && cooldowns.containsKey(abilityName);
}
public void removeCooldown(Player player, Cooldown cooldown)
public void removeCooldown(Player player, String abilityName)
{
UUID uuid = player.getUniqueId();
Map<String, Cooldown> cooldowns = _cooldownMap.get(player.getUniqueId());
if (_cooldownMap.containsKey(uuid))
if (cooldowns == null)
{
_cooldownMap.get(uuid).remove(cooldown.AbilityName);
return;
}
Cooldown cooldown = cooldowns.remove(abilityName);
if (cooldown == null)
{
return;
}
if (_cooldownQueue.containsKey(uuid))

View file

@ -22,6 +22,8 @@ public class ElementManager extends DatabaseModule<ElementRepository>
private static final String WATER = "water";
private static final String BLOOD = "blood";
private static final String HEALING = "healing";
private static final String ICE = "ice";
private static final String PLANT = "plant";
private static final String EARTH = "earth";
private static final String LAVA = "lava";
private static final String METAL = "metal";
@ -33,6 +35,7 @@ public class ElementManager extends DatabaseModule<ElementRepository>
private static final String FLIGHT = "flight";
private static final String SPIRITUAL = "spiritual";
private static final String CHI = "chi";
private static final String AVATAR = "avatar";
private final BendingPlayerManager _bendingPlayerManager;
@ -57,6 +60,8 @@ public class ElementManager extends DatabaseModule<ElementRepository>
Element water = addElement(WATER, "Water", ChatColor.AQUA);
addSubElement(BLOOD, "Blood", ChatColor.DARK_AQUA, water);
addSubElement(HEALING, "Healing", ChatColor.DARK_AQUA, water);
addSubElement(ICE, "Ice", ChatColor.DARK_AQUA, water);
addSubElement(PLANT, "Plant", ChatColor.DARK_AQUA, water);
// Earthbending
Element earth = addElement(EARTH, "Earth", ChatColor.AQUA);
@ -76,6 +81,9 @@ public class ElementManager extends DatabaseModule<ElementRepository>
// Chiblocking
Element chi = addElement(CHI, "Chi", ChatColor.GOLD);
// Avatar
Element avatar = addElement(AVATAR, "Avatar", ChatColor.DARK_PURPLE);
}
catch (SQLException e)
{
@ -103,7 +111,7 @@ public class ElementManager extends DatabaseModule<ElementRepository>
.map(_elements::get)
.collect(Collectors.toList());
// bendingPlayer.addElements(elements);
elements.forEach(bendingPlayer::addElement);
}
catch (SQLException e)
{
@ -152,4 +160,106 @@ public class ElementManager extends DatabaseModule<ElementRepository>
return -1;
}
}
private Element getElement(String elementName)
{
return _names.get(elementName);
}
private SubElement getSubElement(String elementName)
{
Element element = getElement(elementName);
if (element instanceof SubElement)
{
return (SubElement) element;
}
return null;
}
public Element getWater()
{
return getElement(WATER);
}
public SubElement getBlood()
{
return getSubElement(BLOOD);
}
public SubElement getHealing()
{
return getSubElement(HEALING);
}
public SubElement getIce()
{
return getSubElement(ICE);
}
public SubElement getPlant()
{
return getSubElement(PLANT);
}
public Element getEarth()
{
return getElement(EARTH);
}
public SubElement getLava()
{
return getSubElement(LAVA);
}
public SubElement getMetal()
{
return getSubElement(METAL);
}
public SubElement getSand()
{
return getSubElement(SAND);
}
public Element getFire()
{
return getElement(FIRE);
}
public SubElement getCombustion()
{
return getSubElement(COMBUSTION);
}
public SubElement getLightning()
{
return getSubElement(LIGHTNING);
}
public Element getAir()
{
return getElement(AIR);
}
public SubElement getFlight()
{
return getSubElement(FLIGHT);
}
public SubElement getSpiritual()
{
return getSubElement(SPIRITUAL);
}
public Element getChi()
{
return getElement(CHI);
}
public Element getAvatar()
{
return getElement(AVATAR);
}
}

View file

@ -1,37 +1,173 @@
package com.projectkorra.projectkorra.player;
import com.projectkorra.projectkorra.ability.Ability;
import com.projectkorra.projectkorra.cooldown.CooldownManager;
import com.projectkorra.projectkorra.element.Element;
import com.projectkorra.projectkorra.element.ElementManager;
import com.projectkorra.projectkorra.module.ModuleManager;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
public class BendingPlayer
{
private final int _playerId;
private final UUID _uuid;
private final String _playerName;
private final long _firstLogin;
private final BendingPlayerManager manager;
private final ElementManager elementManager;
private final CooldownManager cooldownManager;
private final List<Element> _elements;
private final int playerId;
private final UUID uuid;
private final Player player;
private final String playerName;
private final long firstLogin;
private final Set<Element> elements;
public BendingPlayer(int playerId, UUID uuid, String playerName, long firstLogin)
{
_playerId = playerId;
_uuid = uuid;
_playerName = playerName;
_firstLogin = firstLogin;
this.manager = ModuleManager.getModule(BendingPlayerManager.class);
this.elementManager = ModuleManager.getModule(ElementManager.class);
this.cooldownManager = ModuleManager.getModule(CooldownManager.class);
_elements = new ArrayList<>();
this.playerId = playerId;
this.uuid = uuid;
this.player = manager.getPlugin().getServer().getPlayer(uuid);
this.playerName = playerName;
this.firstLogin = firstLogin;
this.elements = new HashSet<>();
}
public void addElement(Element element)
{
this.elements.add(element);
}
public void setElement(Element element)
{
this.elements.clear();
this.elements.add(element);
}
public boolean hasElement(Element element)
{
if (element.equals(elementManager.getAvatar()))
{
return this.player.hasPermission("bending.avatar");
}
return this.elements.contains(element);
}
public boolean canBloodbend()
{
return this.elements.contains(elementManager.getBlood());
}
public boolean canUseHealing()
{
return this.elements.contains(elementManager.getHealing());
}
public boolean canIcebend()
{
return this.elements.contains(elementManager.getIce());
}
public boolean canPlantbend()
{
return this.elements.contains(elementManager.getPlant());
}
public boolean canLavabend()
{
return this.elements.contains(elementManager.getLava());
}
public boolean canMetalbend()
{
return this.elements.contains(elementManager.getMetal());
}
public boolean canSandbend()
{
return this.elements.contains(elementManager.getSand());
}
public boolean canCombustionbend()
{
return this.elements.contains(elementManager.getCombustion());
}
public boolean canUseLightning()
{
return this.elements.contains(elementManager.getLightning());
}
public boolean canUseFlight()
{
return this.elements.contains(elementManager.getFlight());
}
public boolean canUseSpiritual()
{
return this.elements.contains(elementManager.getSpiritual());
}
public void addCooldown(Ability ability)
{
addCooldown(ability, ability.getCooldown());
}
public void addCooldown(Ability ability, long duration)
{
addCooldown(ability.getName(), duration);
}
public void addCooldown(Ability ability, long duration, boolean permanent)
{
addCooldown(ability.getName(), duration, permanent);
}
public void addCooldown(String abilityName, long duration)
{
addCooldown(abilityName, duration, false);
}
public void addCooldown(String abilityName, long duration, boolean permanent)
{
cooldownManager.addCooldown(this.player, abilityName, duration, permanent);
}
public boolean isOnCooldown(Ability ability)
{
return isOnCooldown(ability.getName());
}
public boolean isOnCooldown(String abilityName)
{
return cooldownManager.isOnCooldown(this.player, abilityName);
}
public void removeCooldown(Ability ability)
{
removeCoolldown(ability.getName());
}
public void removeCoolldown(String abilityName)
{
cooldownManager.removeCooldown(this.player, abilityName);
}
public int getId()
{
return _playerId;
return this.playerId;
}
public long getFirstLogin()
{
return _firstLogin;
return this.firstLogin;
}
}