mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2024-12-23 08:25:07 +00:00
Abstract Management System (#977)
To better store instances of manager classes such as FlightHandler, DBCooldownManager, and more to come in the future, an abstract Manager class implementing Listener has added. This class serves to provide easy accessibility of Manager classes without needing to store individual variables everywhere or restoring to solely static classes. **Usage** To create a Manager class, simply extend `com.projectkorra.projectkorra.Manager`. To register your Manager, simply call `Manager.registerManager(Class<? extends Manager>)`. It is required that your manager has a constructor with no args as this is used to instantiate your class. It is highly recommended to make this constructor private to prevent new unintentional instances being created. To get the Manager throughout your code, simply call `Manager.getManager(Class<? extends Manager>)`. Manager provides two overridable methods, onActivate, and onDeactivate. These methods are called when the Manager is activated and deactivated respectively. A Manager is activated when `Manager.registerManager(Class<? extends Manager>)` is called, and deactivated when ProjectKorra is disabled on reload/restart. As Manager implements Listener, any events related to this manager class should be contained within the class.
This commit is contained in:
parent
4a569ad032
commit
3b074506f7
19 changed files with 193 additions and 55 deletions
|
@ -34,6 +34,7 @@ import com.projectkorra.projectkorra.event.PlayerCooldownChangeEvent;
|
|||
import com.projectkorra.projectkorra.event.PlayerCooldownChangeEvent.Result;
|
||||
import com.projectkorra.projectkorra.storage.DBConnection;
|
||||
import com.projectkorra.projectkorra.util.Cooldown;
|
||||
import com.projectkorra.projectkorra.util.DBCooldownManager;
|
||||
import com.projectkorra.projectkorra.waterbending.blood.Bloodbending;
|
||||
|
||||
/**
|
||||
|
@ -58,6 +59,7 @@ public class BendingPlayer {
|
|||
private final UUID uuid;
|
||||
private final String name;
|
||||
private ChiAbility stance;
|
||||
private final DBCooldownManager cooldownManager;
|
||||
private final ArrayList<Element> elements;
|
||||
private final ArrayList<SubElement> subelements;
|
||||
private HashMap<Integer, String> abilities;
|
||||
|
@ -76,6 +78,7 @@ public class BendingPlayer {
|
|||
public BendingPlayer(final UUID uuid, final String playerName, final ArrayList<Element> elements, final ArrayList<SubElement> subelements, final HashMap<Integer, String> abilities, final boolean permaRemoved) {
|
||||
this.uuid = uuid;
|
||||
this.name = playerName;
|
||||
this.cooldownManager = Manager.getManager(DBCooldownManager.class);
|
||||
this.elements = elements;
|
||||
this.subelements = subelements;
|
||||
this.setAbilities(abilities);
|
||||
|
@ -156,7 +159,7 @@ public class BendingPlayer {
|
|||
while (rs.next()) {
|
||||
final int cooldownId = rs.getInt("cooldown_id");
|
||||
final long value = rs.getLong("value");
|
||||
final String name = ProjectKorra.cooldowns.getCooldownName(cooldownId);
|
||||
final String name = cooldownManager.getCooldownName(cooldownId);
|
||||
cooldowns.put(name, new Cooldown(value, true));
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +174,7 @@ public class BendingPlayer {
|
|||
for (final Entry<String, Cooldown> entry : this.cooldowns.entrySet()) {
|
||||
final String name = entry.getKey();
|
||||
final Cooldown cooldown = entry.getValue();
|
||||
final int cooldownId = ProjectKorra.cooldowns.getCooldownId(name, false);
|
||||
final int cooldownId = cooldownManager.getCooldownId(name, false);
|
||||
try (ResultSet rs = DBConnection.sql.readQuery("SELECT value FROM pk_cooldowns WHERE uuid = '" + this.uuid.toString() + "' AND cooldown_id = " + cooldownId)) {
|
||||
if (rs.next()) {
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_cooldowns SET value = " + cooldown.getCooldown() + " WHERE uuid = '" + this.uuid.toString() + "' AND cooldown_id = " + cooldownId, false);
|
||||
|
|
124
src/com/projectkorra/projectkorra/Manager.java
Normal file
124
src/com/projectkorra/projectkorra/Manager.java
Normal file
|
@ -0,0 +1,124 @@
|
|||
package com.projectkorra.projectkorra;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.projectkorra.projectkorra.util.DBCooldownManager;
|
||||
import com.projectkorra.projectkorra.util.FlightHandler;
|
||||
import com.projectkorra.projectkorra.util.StatisticsManager;
|
||||
|
||||
public abstract class Manager implements Listener {
|
||||
|
||||
/**
|
||||
* {@link Map} containing all {@link Manager} instances by their
|
||||
* {@link Class} as key
|
||||
*/
|
||||
private static final Map<Class<? extends Manager>, Manager> MANAGERS = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Register a new {@link Manager} instance.
|
||||
*
|
||||
* @param managerClass {@link Class} of the {@link Manager} to be registered
|
||||
* @throws NullPointerException if managerClass is null
|
||||
* @throws IllegalArgumentException if managerClass has already been
|
||||
* registered
|
||||
*/
|
||||
public static void registerManager(Class<? extends Manager> managerClass) {
|
||||
Validate.notNull(managerClass, "Manager class cannot be null");
|
||||
Validate.isTrue(!MANAGERS.containsKey(managerClass), "Manager has already been registered");
|
||||
try {
|
||||
Constructor<? extends Manager> constructor = managerClass.getDeclaredConstructor();
|
||||
boolean accessible = constructor.isAccessible();
|
||||
constructor.setAccessible(true);
|
||||
Manager manager = constructor.newInstance();
|
||||
constructor.setAccessible(accessible);
|
||||
manager.activate();
|
||||
MANAGERS.put(managerClass, manager);
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a registered {@link Manager} by its {@link Class}.
|
||||
*
|
||||
* @param managerClass {@link Class} of the registered {@link Manager}
|
||||
* @return instance of the {@link Manager} class
|
||||
* @throws NullPointerException if managerClass is null
|
||||
* @throws IllegalArgumentException if managerClass has not yet been
|
||||
* registered
|
||||
*/
|
||||
public static <T extends Manager> T getManager(Class<T> managerClass) {
|
||||
Validate.notNull(managerClass, "Manager class cannot be null");
|
||||
Validate.isTrue(MANAGERS.containsKey(managerClass), "Manager has not yet been registered");
|
||||
Manager registered = MANAGERS.get(managerClass);
|
||||
return managerClass.cast(registered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this plugin instance
|
||||
*
|
||||
* @return {@link ProjectKorra} plugin instance
|
||||
*/
|
||||
protected ProjectKorra getPlugin() {
|
||||
return JavaPlugin.getPlugin(ProjectKorra.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate this {@link Manager}
|
||||
*/
|
||||
public final void activate() {
|
||||
Bukkit.getPluginManager().registerEvents(this, ProjectKorra.plugin);
|
||||
onActivate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridable method to execute code when this {@link Manager} is activated
|
||||
*/
|
||||
public void onActivate() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate this {@link Manager}
|
||||
*/
|
||||
public final void deactivate() {
|
||||
HandlerList.unregisterAll(this);
|
||||
onDeactivate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridable method to execute code when this {@link Manager} is
|
||||
* deactivated
|
||||
*/
|
||||
public void onDeactivate() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates core {@link Manager} instances
|
||||
*/
|
||||
public static void startup() {
|
||||
registerManager(StatisticsManager.class);
|
||||
registerManager(DBCooldownManager.class);
|
||||
registerManager(FlightHandler.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivates and clears all {@link Manager} instances
|
||||
*/
|
||||
public static void shutdown() {
|
||||
MANAGERS.values().forEach(Manager::deactivate);
|
||||
MANAGERS.clear();
|
||||
}
|
||||
|
||||
}
|
|
@ -160,9 +160,11 @@ import com.projectkorra.projectkorra.object.Preset;
|
|||
import com.projectkorra.projectkorra.util.BlockSource;
|
||||
import com.projectkorra.projectkorra.util.ClickType;
|
||||
import com.projectkorra.projectkorra.util.DamageHandler;
|
||||
import com.projectkorra.projectkorra.util.FlightHandler;
|
||||
import com.projectkorra.projectkorra.util.FlightHandler.Flight;
|
||||
import com.projectkorra.projectkorra.util.MovementHandler;
|
||||
import com.projectkorra.projectkorra.util.PassiveHandler;
|
||||
import com.projectkorra.projectkorra.util.StatisticsManager;
|
||||
import com.projectkorra.projectkorra.util.StatisticsMethods;
|
||||
import com.projectkorra.projectkorra.util.TempArmor;
|
||||
import com.projectkorra.projectkorra.util.TempBlock;
|
||||
|
@ -845,7 +847,7 @@ public class PKListener implements Listener {
|
|||
}
|
||||
|
||||
if (event.getCause() == DamageCause.FALL) {
|
||||
final Flight flight = ProjectKorra.flightHandler.getInstance(player);
|
||||
final Flight flight = Manager.getManager(FlightHandler.class).getInstance(player);
|
||||
if (flight != null) {
|
||||
if (flight.getPlayer() == flight.getSource()) {
|
||||
event.setCancelled(true);
|
||||
|
@ -1116,7 +1118,7 @@ public class PKListener implements Listener {
|
|||
|
||||
GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName());
|
||||
if (ProjectKorra.isStatisticsEnabled()) {
|
||||
ProjectKorra.statistics.load(player.getUniqueId());
|
||||
Manager.getManager(StatisticsManager.class).load(player.getUniqueId());
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, new Runnable() {
|
||||
|
||||
|
@ -1253,7 +1255,7 @@ public class PKListener implements Listener {
|
|||
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
|
||||
|
||||
if (ProjectKorra.isStatisticsEnabled()) {
|
||||
ProjectKorra.statistics.store(player.getUniqueId());
|
||||
Manager.getManager(StatisticsManager.class).store(player.getUniqueId());
|
||||
}
|
||||
if (bPlayer != null) {
|
||||
bPlayer.saveCooldowns();
|
||||
|
|
|
@ -24,8 +24,6 @@ import com.projectkorra.projectkorra.earthbending.util.EarthbendingManager;
|
|||
import com.projectkorra.projectkorra.firebending.util.FirebendingManager;
|
||||
import com.projectkorra.projectkorra.object.Preset;
|
||||
import com.projectkorra.projectkorra.storage.DBConnection;
|
||||
import com.projectkorra.projectkorra.util.DBCooldownManager;
|
||||
import com.projectkorra.projectkorra.util.FlightHandler;
|
||||
import com.projectkorra.projectkorra.util.Metrics;
|
||||
import com.projectkorra.projectkorra.util.RevertChecker;
|
||||
import com.projectkorra.projectkorra.util.StatisticsManager;
|
||||
|
@ -39,9 +37,6 @@ public class ProjectKorra extends JavaPlugin {
|
|||
public static Logger log;
|
||||
public static CollisionManager collisionManager;
|
||||
public static CollisionInitializer collisionInitializer;
|
||||
public static StatisticsManager statistics;
|
||||
public static DBCooldownManager cooldowns;
|
||||
public static FlightHandler flightHandler;
|
||||
public static long time_step = 1;
|
||||
public Updater updater;
|
||||
|
||||
|
@ -70,9 +65,7 @@ public class ProjectKorra extends JavaPlugin {
|
|||
return;
|
||||
}
|
||||
|
||||
statistics = new StatisticsManager();
|
||||
cooldowns = new DBCooldownManager();
|
||||
flightHandler = new FlightHandler();
|
||||
Manager.startup();
|
||||
|
||||
this.getServer().getPluginManager().registerEvents(new PKListener(this), this);
|
||||
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new BendingManager(), 0, 1);
|
||||
|
@ -107,7 +100,7 @@ public class ProjectKorra extends JavaPlugin {
|
|||
|
||||
GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName());
|
||||
GeneralMethods.removeUnusableAbilities(player.getName());
|
||||
statistics.load(player.getUniqueId());
|
||||
Manager.getManager(StatisticsManager.class).load(player.getUniqueId());
|
||||
Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -156,13 +149,14 @@ public class ProjectKorra extends JavaPlugin {
|
|||
GeneralMethods.stopBending();
|
||||
for (final Player player : this.getServer().getOnlinePlayers()) {
|
||||
if (isStatisticsEnabled()) {
|
||||
statistics.save(player.getUniqueId(), false);
|
||||
Manager.getManager(StatisticsManager.class).save(player.getUniqueId(), false);
|
||||
}
|
||||
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
|
||||
if (bPlayer != null) {
|
||||
bPlayer.saveCooldowns();
|
||||
}
|
||||
}
|
||||
Manager.shutdown();
|
||||
if (DBConnection.isOpen()) {
|
||||
DBConnection.sql.close();
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.google.common.reflect.ClassPath.ClassInfo;
|
|||
import com.projectkorra.projectkorra.BendingPlayer;
|
||||
import com.projectkorra.projectkorra.Element;
|
||||
import com.projectkorra.projectkorra.Element.SubElement;
|
||||
import com.projectkorra.projectkorra.Manager;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.ability.util.AbilityLoader;
|
||||
import com.projectkorra.projectkorra.ability.util.AddonAbilityLoader;
|
||||
|
@ -42,6 +43,7 @@ import com.projectkorra.projectkorra.configuration.ConfigManager;
|
|||
import com.projectkorra.projectkorra.event.AbilityEndEvent;
|
||||
import com.projectkorra.projectkorra.event.AbilityProgressEvent;
|
||||
import com.projectkorra.projectkorra.event.AbilityStartEvent;
|
||||
import com.projectkorra.projectkorra.util.FlightHandler;
|
||||
import com.projectkorra.projectkorra.util.TimeUtil;
|
||||
|
||||
import sun.reflect.ReflectionFactory;
|
||||
|
@ -76,6 +78,7 @@ public abstract class CoreAbility implements Ability {
|
|||
|
||||
protected Player player;
|
||||
protected BendingPlayer bPlayer;
|
||||
protected FlightHandler flightHandler;
|
||||
|
||||
private boolean started;
|
||||
private boolean removed;
|
||||
|
@ -115,6 +118,7 @@ public abstract class CoreAbility implements Ability {
|
|||
|
||||
this.player = player;
|
||||
this.bPlayer = BendingPlayer.getBendingPlayer(player);
|
||||
this.flightHandler = Manager.getManager(FlightHandler.class);
|
||||
this.startTime = System.currentTimeMillis();
|
||||
this.started = false;
|
||||
this.id = CoreAbility.idCounter;
|
||||
|
|
|
@ -260,7 +260,7 @@ public class AirBlast extends AirAbility {
|
|||
}
|
||||
|
||||
if (!isUser && entity instanceof Player) {
|
||||
ProjectKorra.flightHandler.createInstance((Player) entity, this.player, 1000L, this.getName());
|
||||
flightHandler.createInstance((Player) entity, this.player, 1000L, this.getName());
|
||||
}
|
||||
if (entity.getFireTicks() > 0) {
|
||||
entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0);
|
||||
|
|
|
@ -11,7 +11,6 @@ import org.bukkit.potion.PotionEffectType;
|
|||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.projectkorra.projectkorra.GeneralMethods;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.ability.AirAbility;
|
||||
import com.projectkorra.projectkorra.ability.ElementalAbility;
|
||||
import com.projectkorra.projectkorra.attribute.Attribute;
|
||||
|
@ -55,7 +54,7 @@ public class AirScooter extends AirAbility {
|
|||
this.random = new Random();
|
||||
this.angles = new ArrayList<>();
|
||||
|
||||
ProjectKorra.flightHandler.createInstance(player, this.getName());
|
||||
flightHandler.createInstance(player, this.getName());
|
||||
player.setAllowFlight(true);
|
||||
player.setFlying(true);
|
||||
|
||||
|
@ -177,7 +176,7 @@ public class AirScooter extends AirAbility {
|
|||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
ProjectKorra.flightHandler.removeInstance(this.player, this.getName());
|
||||
flightHandler.removeInstance(this.player, this.getName());
|
||||
this.bPlayer.addCooldown(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.bukkit.block.BlockFace;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.projectkorra.projectkorra.GeneralMethods;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.ability.AirAbility;
|
||||
import com.projectkorra.projectkorra.ability.util.Collision;
|
||||
import com.projectkorra.projectkorra.attribute.Attribute;
|
||||
|
@ -53,7 +52,7 @@ public class AirSpout extends AirAbility {
|
|||
return;
|
||||
}
|
||||
|
||||
ProjectKorra.flightHandler.createInstance(player, this.getName());
|
||||
flightHandler.createInstance(player, this.getName());
|
||||
|
||||
if (this.bPlayer.isAvatarState()) {
|
||||
this.height = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirSpout.Height");
|
||||
|
@ -163,7 +162,7 @@ public class AirSpout extends AirAbility {
|
|||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
ProjectKorra.flightHandler.removeInstance(this.player, this.getName());
|
||||
flightHandler.removeInstance(this.player, this.getName());
|
||||
}
|
||||
|
||||
private void removeFlight() {
|
||||
|
|
|
@ -272,7 +272,7 @@ public class AirSuction extends AirAbility {
|
|||
new HorizontalVelocityTracker(entity, this.player, 200l, this);
|
||||
entity.setFallDistance(0);
|
||||
if (entity.getEntityId() != this.player.getEntityId() && entity instanceof Player) {
|
||||
ProjectKorra.flightHandler.createInstance((Player) entity, this.player, 5000L, this.getName());
|
||||
flightHandler.createInstance((Player) entity, this.player, 5000L, this.getName());
|
||||
}
|
||||
|
||||
if (entity.getFireTicks() > 0) {
|
||||
|
|
|
@ -220,7 +220,7 @@ public class AirSwipe extends AirAbility {
|
|||
AirSwipe.this.affectedEntities.add(entity);
|
||||
}
|
||||
if (entity instanceof Player) {
|
||||
ProjectKorra.flightHandler.createInstance((Player) entity, AirSwipe.this.player, 1000L, AirSwipe.this.getName());
|
||||
flightHandler.createInstance((Player) entity, AirSwipe.this.player, 1000L, AirSwipe.this.getName());
|
||||
}
|
||||
breakBreathbendingHold(entity);
|
||||
if (AirSwipe.this.elements.containsKey(fDirection)) {
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.projectkorra.projectkorra.GeneralMethods;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.ability.AirAbility;
|
||||
import com.projectkorra.projectkorra.attribute.Attribute;
|
||||
import com.projectkorra.projectkorra.command.Commands;
|
||||
|
@ -68,7 +67,7 @@ public class Tornado extends AirAbility {
|
|||
}
|
||||
}
|
||||
|
||||
ProjectKorra.flightHandler.createInstance(player, this.getName());
|
||||
flightHandler.createInstance(player, this.getName());
|
||||
player.setAllowFlight(true);
|
||||
this.start();
|
||||
}
|
||||
|
@ -95,7 +94,7 @@ public class Tornado extends AirAbility {
|
|||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
ProjectKorra.flightHandler.removeInstance(this.player, this.getName());
|
||||
flightHandler.removeInstance(this.player, this.getName());
|
||||
}
|
||||
|
||||
private void rotateTornado() {
|
||||
|
@ -168,7 +167,7 @@ public class Tornado extends AirAbility {
|
|||
breakBreathbendingHold(entity);
|
||||
|
||||
if (entity instanceof Player) {
|
||||
ProjectKorra.flightHandler.createInstance((Player) entity, 50L, this.getName());
|
||||
flightHandler.createInstance((Player) entity, 50L, this.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ public class AirStream extends AirAbility implements ComboAbility {
|
|||
this.affectedEntities.add(entity);
|
||||
if (entity instanceof Player) {
|
||||
final Player ep = (Player) entity;
|
||||
ProjectKorra.flightHandler.createInstance(ep, this.player, this.getName());
|
||||
flightHandler.createInstance(ep, this.player, this.getName());
|
||||
this.flights.add(ep);
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public class AirStream extends AirAbility implements ComboAbility {
|
|||
task.cancel();
|
||||
}
|
||||
for (final Player flyer : this.flights) {
|
||||
ProjectKorra.flightHandler.removeInstance(flyer, this.getName());
|
||||
flightHandler.removeInstance(flyer, this.getName());
|
||||
}
|
||||
this.flights.clear();
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility {
|
|||
}
|
||||
|
||||
MultiAbilityManager.bindMultiAbility(player, "Flight");
|
||||
ProjectKorra.flightHandler.createInstance(player, ID);
|
||||
flightHandler.createInstance(player, ID);
|
||||
this.hadGlide = player.isGliding();
|
||||
flying.add(player.getUniqueId());
|
||||
this.prevDir = player.getEyeLocation().getDirection().clone();
|
||||
|
@ -311,7 +311,7 @@ public class FlightMultiAbility extends FlightAbility implements MultiAbility {
|
|||
if (this.player.isOnline() && !this.player.isDead()) {
|
||||
this.player.eject();
|
||||
}
|
||||
ProjectKorra.flightHandler.removeInstance(this.player, ID);
|
||||
flightHandler.removeInstance(this.player, ID);
|
||||
this.player.setGliding(this.hadGlide);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import org.bukkit.block.Block;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.ability.FireAbility;
|
||||
import com.projectkorra.projectkorra.airbending.AirSpout;
|
||||
import com.projectkorra.projectkorra.util.ParticleEffect;
|
||||
|
@ -58,7 +57,7 @@ public class FireJet extends FireAbility {
|
|||
block.setType(Material.FIRE);
|
||||
}
|
||||
|
||||
ProjectKorra.flightHandler.createInstance(player, this.getName());
|
||||
flightHandler.createInstance(player, this.getName());
|
||||
player.setAllowFlight(true);
|
||||
this.time = System.currentTimeMillis();
|
||||
|
||||
|
@ -99,7 +98,7 @@ public class FireJet extends FireAbility {
|
|||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
ProjectKorra.flightHandler.removeInstance(this.player, this.getName());
|
||||
flightHandler.removeInstance(this.player, this.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,13 +3,18 @@ package com.projectkorra.projectkorra.util;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.projectkorra.projectkorra.Manager;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.storage.DBConnection;
|
||||
import com.projectkorra.projectkorra.storage.MySQL;
|
||||
|
||||
public class DBCooldownManager {
|
||||
public class DBCooldownManager extends Manager {
|
||||
|
||||
public DBCooldownManager() {
|
||||
private DBCooldownManager() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivate() {
|
||||
this.setupCooldowns();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,10 @@ import java.util.UUID;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.projectkorra.projectkorra.Manager;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
|
||||
public class FlightHandler {
|
||||
public class FlightHandler extends Manager {
|
||||
|
||||
/**
|
||||
* A Map containing all Flight instances.
|
||||
|
@ -29,7 +30,11 @@ public class FlightHandler {
|
|||
}
|
||||
});
|
||||
|
||||
public FlightHandler() {
|
||||
private FlightHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivate() {
|
||||
this.startCleanup();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,13 +11,14 @@ import java.util.UUID;
|
|||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.projectkorra.projectkorra.Manager;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.ability.CoreAbility;
|
||||
import com.projectkorra.projectkorra.storage.DBConnection;
|
||||
import com.projectkorra.projectkorra.storage.MySQL;
|
||||
import com.projectkorra.projectkorra.storage.SQLite;
|
||||
|
||||
public class StatisticsManager implements Runnable {
|
||||
public class StatisticsManager extends Manager implements Runnable {
|
||||
|
||||
/**
|
||||
* HashMap which contains all current statistic values (Map<player,
|
||||
|
@ -44,7 +45,11 @@ public class StatisticsManager implements Runnable {
|
|||
private final Set<UUID> STORAGE = new HashSet<>();
|
||||
private final int INTERVAL = 5;
|
||||
|
||||
public StatisticsManager() {
|
||||
private StatisticsManager() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivate() {
|
||||
if (!ProjectKorra.isStatisticsEnabled()) {
|
||||
ProjectKorra.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(ProjectKorra.plugin, this, 20 * this.INTERVAL, 20 * this.INTERVAL);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.UUID;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.projectkorra.projectkorra.Element;
|
||||
import com.projectkorra.projectkorra.Manager;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.ability.CoreAbility;
|
||||
import com.projectkorra.projectkorra.storage.DBConnection;
|
||||
|
@ -32,7 +33,7 @@ public class StatisticsMethods {
|
|||
return 0;
|
||||
}
|
||||
final int statId = getId(statistic.getStatisticName(ability));
|
||||
return ProjectKorra.statistics.getStatisticCurrent(uuid, statId);
|
||||
return Manager.getManager(StatisticsManager.class).getStatisticCurrent(uuid, statId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +53,7 @@ public class StatisticsMethods {
|
|||
return;
|
||||
}
|
||||
final int statId = getId(statistic.getStatisticName(ability));
|
||||
ProjectKorra.statistics.addStatistic(uuid, statId, statDelta);
|
||||
Manager.getManager(StatisticsManager.class).addStatistic(uuid, statId, statDelta);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +74,7 @@ public class StatisticsMethods {
|
|||
return 0;
|
||||
}
|
||||
long totalValue = 0;
|
||||
for (final int statId : ProjectKorra.statistics.getStatisticsMap(uuid).keySet()) {
|
||||
for (final int statId : Manager.getManager(StatisticsManager.class).getStatisticsMap(uuid).keySet()) {
|
||||
final String abilName = getAbilityName(statId);
|
||||
final CoreAbility ability = CoreAbility.getAbility(abilName);
|
||||
if (ability == null) {
|
||||
|
@ -107,7 +108,7 @@ public class StatisticsMethods {
|
|||
return 0;
|
||||
}
|
||||
long totalValue = 0;
|
||||
for (final int statId : ProjectKorra.statistics.getStatisticsMap(uuid).keySet()) {
|
||||
for (final int statId : Manager.getManager(StatisticsManager.class).getStatisticsMap(uuid).keySet()) {
|
||||
final String abilName = getAbilityName(statId);
|
||||
final CoreAbility ability = CoreAbility.getAbility(abilName);
|
||||
if (ability == null) {
|
||||
|
@ -169,19 +170,19 @@ public class StatisticsMethods {
|
|||
if (!ProjectKorra.isStatisticsEnabled()) {
|
||||
return 0;
|
||||
}
|
||||
if (!ProjectKorra.statistics.getKeysByName().containsKey(statName)) {
|
||||
if (!Manager.getManager(StatisticsManager.class).getKeysByName().containsKey(statName)) {
|
||||
DBConnection.sql.modifyQuery("INSERT INTO pk_statKeys (statName) VALUES ('" + statName + "')", false);
|
||||
try (ResultSet rs = DBConnection.sql.readQuery("SELECT * FROM pk_statKeys WHERE statName = '" + statName + "'")) {
|
||||
if (rs.next()) {
|
||||
ProjectKorra.statistics.getKeysByName().put(rs.getString("statName"), rs.getInt("id"));
|
||||
ProjectKorra.statistics.getKeysById().put(rs.getInt("id"), rs.getString("statName"));
|
||||
Manager.getManager(StatisticsManager.class).getKeysByName().put(rs.getString("statName"), rs.getInt("id"));
|
||||
Manager.getManager(StatisticsManager.class).getKeysById().put(rs.getInt("id"), rs.getString("statName"));
|
||||
}
|
||||
}
|
||||
catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return ProjectKorra.statistics.getKeysByName().containsKey(statName) ? ProjectKorra.statistics.getKeysByName().get(statName) : -1;
|
||||
return Manager.getManager(StatisticsManager.class).getKeysByName().containsKey(statName) ? Manager.getManager(StatisticsManager.class).getKeysByName().get(statName) : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,10 +197,10 @@ public class StatisticsMethods {
|
|||
if (!ProjectKorra.isStatisticsEnabled()) {
|
||||
return "";
|
||||
}
|
||||
if (!ProjectKorra.statistics.getKeysById().containsKey(id)) {
|
||||
if (!Manager.getManager(StatisticsManager.class).getKeysById().containsKey(id)) {
|
||||
return "";
|
||||
}
|
||||
final String statName = ProjectKorra.statistics.getKeysById().get(id);
|
||||
final String statName = Manager.getManager(StatisticsManager.class).getKeysById().get(id);
|
||||
final String[] split = statName.split("_");
|
||||
if (split.length < 2) {
|
||||
return "";
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.projectkorra.projectkorra.GeneralMethods;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.ability.WaterAbility;
|
||||
import com.projectkorra.projectkorra.ability.util.Collision;
|
||||
import com.projectkorra.projectkorra.attribute.Attribute;
|
||||
|
@ -80,7 +79,7 @@ public class WaterSpout extends WaterAbility {
|
|||
if (!this.isWithinMaxSpoutHeight(topBlock.getLocation(), heightRemoveThreshold)) {
|
||||
return;
|
||||
}
|
||||
ProjectKorra.flightHandler.createInstance(player, this.getName());
|
||||
flightHandler.createInstance(player, this.getName());
|
||||
player.setAllowFlight(true);
|
||||
this.spoutableWaterHeight(player.getLocation()); // Sets base.
|
||||
this.start();
|
||||
|
@ -183,7 +182,7 @@ public class WaterSpout extends WaterAbility {
|
|||
AFFECTED_BLOCKS.remove(tb.getBlock());
|
||||
tb.revertBlock();
|
||||
}
|
||||
ProjectKorra.flightHandler.removeInstance(this.player, this.getName());
|
||||
flightHandler.removeInstance(this.player, this.getName());
|
||||
}
|
||||
|
||||
public void revertBaseBlock() {
|
||||
|
|
Loading…
Reference in a new issue