Cleaned ElementManager + added more BendingPlayer methods

This commit is contained in:
jayoevans 2019-10-23 09:12:18 +10:00
parent 87b6186bee
commit 64b138a6c1
4 changed files with 174 additions and 77 deletions

View file

@ -40,7 +40,10 @@ import com.projectkorra.projectkorra.waterbending.blood.Bloodbending;
/**
* Class that presents a player and stores all bending information about the
* player.
*
* @deprecated use {@link com.projectkorra.projectkorra.player.BendingPlayer}.
*/
@Deprecated
public class BendingPlayer {
/**

View file

@ -52,6 +52,9 @@ import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
import com.palmergames.bukkit.towny.war.flagwar.TownyWar;
import com.palmergames.bukkit.towny.war.flagwar.TownyWarConfig;
import com.projectkorra.projectkorra.cooldown.CooldownManager;
import com.projectkorra.projectkorra.element.ElementManager;
import com.projectkorra.projectkorra.player.BendingPlayerManager;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
@ -323,7 +326,10 @@ public class GeneralMethods {
* @param uuid The UUID of the player
* @param player The player name
* @throws SQLException
*
* @deprecated use {@link BendingPlayerManager} and {@link ElementManager}.
*/
@Deprecated
public static void createBendingPlayer(final UUID uuid, final String player) {
new BukkitRunnable() {
@ -335,6 +341,7 @@ public class GeneralMethods {
}.runTaskAsynchronously(ProjectKorra.plugin);
}
@Deprecated
private static void createBendingPlayerAsynchronously(final UUID uuid, final String player) {
final ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + uuid.toString() + "'");
try {

View file

@ -2,10 +2,8 @@ package com.projectkorra.projectkorra.element;
import com.google.common.base.Preconditions;
import com.projectkorra.projectkorra.module.DatabaseModule;
import com.projectkorra.projectkorra.module.ModuleManager;
import com.projectkorra.projectkorra.player.BendingPlayer;
import com.projectkorra.projectkorra.player.BendingPlayerLoadedEvent;
import com.projectkorra.projectkorra.player.BendingPlayerManager;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -19,37 +17,26 @@ import java.util.stream.Collectors;
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";
private static final String SAND = "sand";
private static final String FIRE = "fire";
private static final String COMBUSTION = "combustion";
private static final String LIGHTNING = "lightning";
private static final String AIR = "air";
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;
private static final String WATER = "water", EARTH = "earth", FIRE = "fire", AIR = "air", CHI = "chi", AVATAR = "avatar";
private static final String BLOOD = "blood", HEALING = "healing", ICE = "ice", PLANT = "plant";
private static final String LAVA = "lava", METAL = "metal", SAND = "sand";
private static final String COMBUSTION = "combustion", LIGHTNING = "lightning";
private static final String FLIGHT = "flight", SPIRITUAL = "spiritual";
private final Map<Integer, Element> _elements = new HashMap<>();
private final Map<String, Element> _names = new HashMap<>();
private final String _nameRegex = "[a-zA-Z]+";
private Element water, earth, fire, air, chi, avatar;
private SubElement blood, healing, ice, plant;
private SubElement lava, metal, sand;
private SubElement combustion, lightning;
private SubElement flight, spiritual;
private ElementManager()
{
super("Element", new ElementRepository());
_bendingPlayerManager = ModuleManager.getModule(BendingPlayerManager.class);
runAsync(() ->
{
try
@ -57,33 +44,33 @@ public class ElementManager extends DatabaseModule<ElementRepository>
getRepository().createTables();
// Waterbending
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);
water = addElement(WATER, "Water", ChatColor.AQUA);
blood = addSubElement(BLOOD, "Blood", ChatColor.DARK_AQUA, water);
healing = addSubElement(HEALING, "Healing", ChatColor.DARK_AQUA, water);
ice = addSubElement(ICE, "Ice", ChatColor.DARK_AQUA, water);
plant = addSubElement(PLANT, "Plant", ChatColor.DARK_AQUA, water);
// Earthbending
Element earth = addElement(EARTH, "Earth", ChatColor.AQUA);
addSubElement(LAVA, "Lava", ChatColor.DARK_GREEN, earth);
addSubElement(METAL, "Metal", ChatColor.DARK_GREEN, earth);
addSubElement(SAND, "Sand", ChatColor.DARK_GREEN, earth);
earth = addElement(EARTH, "Earth", ChatColor.AQUA);
lava =addSubElement(LAVA, "Lava", ChatColor.DARK_GREEN, earth);
metal = addSubElement(METAL, "Metal", ChatColor.DARK_GREEN, earth);
sand = addSubElement(SAND, "Sand", ChatColor.DARK_GREEN, earth);
// Firebending
Element fire = addElement(FIRE, "Fire", ChatColor.RED);
addSubElement(COMBUSTION, "Combustion", ChatColor.DARK_RED, fire);
addSubElement(LIGHTNING, "Lightning", ChatColor.DARK_RED, fire);
fire = addElement(FIRE, "Fire", ChatColor.RED);
combustion = addSubElement(COMBUSTION, "Combustion", ChatColor.DARK_RED, fire);
lightning = addSubElement(LIGHTNING, "Lightning", ChatColor.DARK_RED, fire);
// Airbending
Element air = addElement(AIR, "Air", ChatColor.GRAY);
addSubElement(FLIGHT, "Flight", ChatColor.DARK_GRAY, air);
addSubElement(SPIRITUAL, "Spiritual", ChatColor.DARK_GRAY, air);
air = addElement(AIR, "Air", ChatColor.GRAY);
flight = addSubElement(FLIGHT, "Flight", ChatColor.DARK_GRAY, air);
spiritual = addSubElement(SPIRITUAL, "Spiritual", ChatColor.DARK_GRAY, air);
// Chiblocking
Element chi = addElement(CHI, "Chi", ChatColor.GOLD);
chi = addElement(CHI, "Chi", ChatColor.GOLD);
// Avatar
Element avatar = addElement(AVATAR, "Avatar", ChatColor.DARK_PURPLE);
avatar = addElement(AVATAR, "Avatar", ChatColor.DARK_PURPLE);
}
catch (SQLException e)
{
@ -127,7 +114,6 @@ public class ElementManager extends DatabaseModule<ElementRepository>
Element element = new Element(elementId, elementName, displayName, color);
_elements.put(elementId, element);
_names.put(elementName, element);
return element;
}
@ -139,7 +125,6 @@ public class ElementManager extends DatabaseModule<ElementRepository>
SubElement element = new SubElement(elementId, elementName, displayName, color, parent);
_elements.put(elementId, element);
_names.put(elementName, element);
return element;
}
@ -161,105 +146,88 @@ public class ElementManager extends DatabaseModule<ElementRepository>
}
}
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);
return water;
}
public SubElement getBlood()
{
return getSubElement(BLOOD);
return blood;
}
public SubElement getHealing()
{
return getSubElement(HEALING);
return healing;
}
public SubElement getIce()
{
return getSubElement(ICE);
return ice;
}
public SubElement getPlant()
{
return getSubElement(PLANT);
return plant;
}
public Element getEarth()
{
return getElement(EARTH);
return earth;
}
public SubElement getLava()
{
return getSubElement(LAVA);
return lava;
}
public SubElement getMetal()
{
return getSubElement(METAL);
return metal;
}
public SubElement getSand()
{
return getSubElement(SAND);
return sand;
}
public Element getFire()
{
return getElement(FIRE);
return fire;
}
public SubElement getCombustion()
{
return getSubElement(COMBUSTION);
return combustion;
}
public SubElement getLightning()
{
return getSubElement(LIGHTNING);
return lightning;
}
public Element getAir()
{
return getElement(AIR);
return air;
}
public SubElement getFlight()
{
return getSubElement(FLIGHT);
return flight;
}
public SubElement getSpiritual()
{
return getSubElement(SPIRITUAL);
return spiritual;
}
public Element getChi()
{
return getElement(CHI);
return chi;
}
public Element getAvatar()
{
return getElement(AVATAR);
return avatar;
}
}

View file

@ -1,6 +1,9 @@
package com.projectkorra.projectkorra.player;
import com.projectkorra.projectkorra.ability.Ability;
import com.projectkorra.projectkorra.ability.ChiAbility;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.ability.util.PassiveManager;
import com.projectkorra.projectkorra.cooldown.CooldownManager;
import com.projectkorra.projectkorra.element.Element;
import com.projectkorra.projectkorra.element.ElementManager;
@ -24,6 +27,16 @@ public class BendingPlayer
private final long firstLogin;
private final Set<Element> elements;
private final Set<Element> toggledElements;
private final String[] abilities;
private ChiAbility stance;
private boolean permanentlyRemoved;
private boolean toggled;
private boolean tremorSense;
private boolean illumination;
private boolean chiBlocked;
private long slowTime;
public BendingPlayer(int playerId, UUID uuid, String playerName, long firstLogin)
{
@ -38,6 +51,8 @@ public class BendingPlayer
this.firstLogin = firstLogin;
this.elements = new HashSet<>();
this.toggledElements = new HashSet<>();
this.abilities = new String[9];
}
public void addElement(Element element)
@ -116,6 +131,34 @@ public class BendingPlayer
return this.elements.contains(elementManager.getSpiritual());
}
public boolean isElementToggled(Element element)
{
return this.toggledElements.contains(element);
}
public void toggleElement(Element element)
{
if (this.toggledElements.contains(element))
{
this.toggledElements.remove(element);
}
else
{
this.toggledElements.add(element);
}
}
public CoreAbility getBoundAbility()
{
return CoreAbility.getAbility(getBoundAbilityName());
}
public String getBoundAbilityName()
{
int slot = this.player.getInventory().getHeldItemSlot();
return this.abilities[slot];
}
public void addCooldown(Ability ability)
{
addCooldown(ability, ability.getCooldown());
@ -161,6 +204,82 @@ public class BendingPlayer
cooldownManager.removeCooldown(this.player, abilityName);
}
public ChiAbility getStance()
{
return this.stance;
}
public void setStance(ChiAbility stance)
{
this.stance = stance;
}
public boolean isPermanentlyRemoved()
{
return this.permanentlyRemoved;
}
public void setPermanentlyRemoved(boolean permanentlyRemoved)
{
this.permanentlyRemoved = permanentlyRemoved;
}
public boolean isToggled()
{
return this.toggled;
}
public void toggleBending()
{
this.toggled = !this.toggled;
PassiveManager.registerPassives(this.player); // TODO redo this passive system
}
public boolean isTremorSensing()
{
return this.tremorSense;
}
public void toggleTremorSense()
{
this.tremorSense = !this.tremorSense;
}
public boolean isIlluminating()
{
return this.illumination;
}
public void toggleIllumination()
{
this.illumination = !this.illumination;
}
public boolean isChiBlocked()
{
return this.chiBlocked;
}
public void blockChi()
{
this.chiBlocked = true;
}
public void unblockChi()
{
this.chiBlocked = false;
}
public boolean canBeSlowed()
{
return System.currentTimeMillis() > this.slowTime;
}
public void slow(long cooldown)
{
this.slowTime = System.currentTimeMillis() + cooldown;
}
public int getId()
{
return this.playerId;