mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-08-05 12:03:17 +00:00
Fix ComboManager Lag Issue
This commit is contained in:
parent
eeae6d217b
commit
8e8e4a2555
1 changed files with 26 additions and 24 deletions
|
@ -20,7 +20,7 @@ import java.util.HashSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class ComboManager {
|
public class ComboManager {
|
||||||
private static final long CLEANUP_DELAY = 10000;
|
private static final long CLEANUP_DELAY = 20 * 60 * 60;
|
||||||
public static ConcurrentHashMap<String, ArrayList<AbilityInformation>> recentlyUsedAbilities = new ConcurrentHashMap<String, ArrayList<AbilityInformation>>();
|
public static ConcurrentHashMap<String, ArrayList<AbilityInformation>> recentlyUsedAbilities = new ConcurrentHashMap<String, ArrayList<AbilityInformation>>();
|
||||||
public static HashSet<ComboAbility> comboAbilityList = new HashSet<ComboAbility>();
|
public static HashSet<ComboAbility> comboAbilityList = new HashSet<ComboAbility>();
|
||||||
public static HashMap<String, String> authors = new HashMap<String, String>();
|
public static HashMap<String, String> authors = new HashMap<String, String>();
|
||||||
|
@ -216,11 +216,14 @@ public class ComboManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a Player's {@link ComboManager#recentlyUsedAbilities recentlyUsedAbilities}
|
* Checks if a Player's {@link ComboManager#recentlyUsedAbilities
|
||||||
* contains a valid set of moves to perform any combos. If it does, it
|
* recentlyUsedAbilities} contains a valid set of moves to perform any
|
||||||
* returns the valid combo.
|
* combos. If it does, it returns the valid combo.
|
||||||
* @param player The player for whom to check if a valid combo has been performed
|
*
|
||||||
* @return The ComboAbility of the combo that has been performed, or null if no valid combo was found
|
* @param player The player for whom to check if a valid combo has been
|
||||||
|
* performed
|
||||||
|
* @return The ComboAbility of the combo that has been performed, or null if
|
||||||
|
* no valid combo was found
|
||||||
*/
|
*/
|
||||||
public static ComboAbility checkForValidCombo(Player player) {
|
public static ComboAbility checkForValidCombo(Player player) {
|
||||||
ArrayList<AbilityInformation> playerCombo = getRecentlyUsedAbilities(player, 8);
|
ArrayList<AbilityInformation> playerCombo = getRecentlyUsedAbilities(player, 8);
|
||||||
|
@ -249,25 +252,18 @@ public class ComboManager {
|
||||||
while (keys.hasMoreElements()) {
|
while (keys.hasMoreElements()) {
|
||||||
String name = keys.nextElement();
|
String name = keys.nextElement();
|
||||||
ArrayList<AbilityInformation> usedAbilities = recentlyUsedAbilities.get(name);
|
ArrayList<AbilityInformation> usedAbilities = recentlyUsedAbilities.get(name);
|
||||||
ArrayList<AbilityInformation> stillValidAbilities = new ArrayList<AbilityInformation>();
|
usedAbilities.clear();
|
||||||
recentlyUsedAbilities.remove(name);
|
|
||||||
|
|
||||||
for (AbilityInformation info : usedAbilities) {
|
|
||||||
if (System.currentTimeMillis() - info.getTime() <= CLEANUP_DELAY) {
|
|
||||||
stillValidAbilities.add(info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stillValidAbilities.size() > 0)
|
|
||||||
recentlyUsedAbilities.put(name, stillValidAbilities);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the player's most recently used abilities, up to a maximum of 10.
|
* Gets the player's most recently used abilities, up to a maximum of 10.
|
||||||
|
*
|
||||||
* @param player The player to get recent abilities for
|
* @param player The player to get recent abilities for
|
||||||
* @param amount The amount of recent abilities to get, starting from most recent and getting older
|
* @param amount The amount of recent abilities to get, starting from most
|
||||||
* @return An ArrayList<{@link AbilityInformation}> of the player's recently used abilities
|
* recent and getting older
|
||||||
|
* @return An ArrayList<{@link AbilityInformation}> of the player's recently
|
||||||
|
* used abilities
|
||||||
*/
|
*/
|
||||||
public static ArrayList<AbilityInformation> getRecentlyUsedAbilities(Player player, int amount) {
|
public static ArrayList<AbilityInformation> getRecentlyUsedAbilities(Player player, int amount) {
|
||||||
String name = player.getName();
|
String name = player.getName();
|
||||||
|
@ -286,13 +282,14 @@ public class ComboManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all of the combos for a given element.
|
* Gets all of the combos for a given element.
|
||||||
|
*
|
||||||
* @param element The element to get combos for
|
* @param element The element to get combos for
|
||||||
* @return An ArrayList of the combos for that element
|
* @return An ArrayList of the combos for that element
|
||||||
*/
|
*/
|
||||||
public static ArrayList<String> getCombosForElement(Element element) {
|
public static ArrayList<String> getCombosForElement(Element element) {
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
for (ComboAbility comboab : comboAbilityList) {
|
for (ComboAbility comboab : comboAbilityList) {
|
||||||
if(GeneralMethods.getAbilityElement(comboab.getAbilities().get(0).getAbilityName())==element)
|
if (GeneralMethods.getAbilityElement(comboab.getAbilities().get(0).getAbilityName()) == element)
|
||||||
list.add(comboab.getName());
|
list.add(comboab.getName());
|
||||||
}
|
}
|
||||||
Collections.sort(list);
|
Collections.sort(list);
|
||||||
|
@ -304,11 +301,12 @@ public class ComboManager {
|
||||||
public void run() {
|
public void run() {
|
||||||
cleanupOldCombos();
|
cleanupOldCombos();
|
||||||
}
|
}
|
||||||
}.runTaskTimer(ProjectKorra.plugin, 0, CLEANUP_DELAY / 1000 * 20);
|
}.runTaskTimer(ProjectKorra.plugin, 0, CLEANUP_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains information on an ability used in a combo.
|
* Contains information on an ability used in a combo.
|
||||||
|
*
|
||||||
* @author kingbirdy
|
* @author kingbirdy
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -328,7 +326,9 @@ public class ComboManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares if two {@link AbilityInformation}'s are equal without respect to {@link AbilityInformation#time time}.
|
* Compares if two {@link AbilityInformation}'s are equal without
|
||||||
|
* respect to {@link AbilityInformation#time time}.
|
||||||
|
*
|
||||||
* @param info The AbilityInformation to compare against
|
* @param info The AbilityInformation to compare against
|
||||||
* @return True if they are equal without respect to time
|
* @return True if they are equal without respect to time
|
||||||
*/
|
*/
|
||||||
|
@ -338,6 +338,7 @@ public class ComboManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of the ability.
|
* Gets the name of the ability.
|
||||||
|
*
|
||||||
* @return The name of the ability.
|
* @return The name of the ability.
|
||||||
*/
|
*/
|
||||||
public String getAbilityName() {
|
public String getAbilityName() {
|
||||||
|
@ -346,6 +347,7 @@ public class ComboManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link ClickType} of the {@link AbilityInformation}.
|
* Gets the {@link ClickType} of the {@link AbilityInformation}.
|
||||||
|
*
|
||||||
* @return The ClickType
|
* @return The ClickType
|
||||||
*/
|
*/
|
||||||
public ClickType getClickType() {
|
public ClickType getClickType() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue