mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Remove Static Abuse - Database Tasks
This commit is contained in:
parent
4da455b9d2
commit
982e67af70
@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.listeners.InteractionManager;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.random.RandomChanceSkill;
|
||||
import com.gmail.nossr50.util.random.RandomChanceUtil;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -4,7 +4,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.archery.Archery;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.axes.Axes;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -9,7 +9,6 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.fishing.Fishing;
|
||||
import com.gmail.nossr50.skills.fishing.FishingManager;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.random.RandomChanceUtil;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -4,7 +4,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Material;
|
||||
|
@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -6,7 +6,6 @@ import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.listeners.InteractionManager;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -6,7 +6,6 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.repair.RepairManager;
|
||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Material;
|
||||
|
@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.salvage.Salvage;
|
||||
import com.gmail.nossr50.skills.salvage.SalvageManager;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -7,7 +7,6 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.random.RandomChanceUtil;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillActivationType;
|
||||
|
@ -4,7 +4,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -4,7 +4,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -5,7 +5,6 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.taming.Taming;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -4,7 +4,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -4,7 +4,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -8,6 +8,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface DatabaseManager {
|
||||
/**
|
||||
@ -29,6 +30,19 @@ public interface DatabaseManager {
|
||||
*/
|
||||
public boolean removeUser(String playerName, UUID uuid);
|
||||
|
||||
/**
|
||||
* Prints progress on long database operations
|
||||
* @param convertedUsers amount of users converted so far
|
||||
* @param startMillis the start time stamp in millis
|
||||
* @param logger logger
|
||||
*/
|
||||
//TODO: Hacky fix, cleanup later
|
||||
default void printProgress(int convertedUsers, long startMillis, Logger logger) {
|
||||
if ((convertedUsers % getDatabaseProgressPrintInterval()) == 0) {
|
||||
logger.info(String.format("Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / (double) ((System.currentTimeMillis() - startMillis) / 1000)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any cache used for faster lookups
|
||||
* Currently only used for SQL
|
||||
@ -125,6 +139,12 @@ public interface DatabaseManager {
|
||||
|
||||
boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
|
||||
|
||||
/**
|
||||
* Gets the interval in which any task that does an operation over the whole database should print progress updates to console
|
||||
* @return the interval in which progress should be reported for database wide operations
|
||||
*/
|
||||
int getDatabaseProgressPrintInterval();
|
||||
|
||||
/**
|
||||
* Retrieve the type of database in use. Custom databases should return CUSTOM.
|
||||
*
|
||||
|
@ -85,6 +85,11 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDatabaseProgressPrintInterval() {
|
||||
return progressInterval;
|
||||
}
|
||||
|
||||
public void purgePowerlessUsers() {
|
||||
int purgedUsers = 0;
|
||||
|
||||
|
@ -23,7 +23,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
private final String COM_MYSQL_JDBC_DRIVER = "com.mysql.jdbc.Driver";
|
||||
private final String ALL_QUERY_VERSION = "total";
|
||||
private final Map<UUID, Integer> cachedUserIDs = new HashMap<>();
|
||||
private String tablePrefix = pluginRef.getMySQLConfigSettings().getConfigSectionDatabase().getTablePrefix();
|
||||
private String tablePrefix;
|
||||
private DataSource miscPool;
|
||||
private DataSource loadPool;
|
||||
private DataSource savePool;
|
||||
@ -37,6 +37,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
|
||||
protected SQLDatabaseManager(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
|
||||
tablePrefix = pluginRef.getMySQLConfigSettings().getConfigSectionDatabase().getTablePrefix();
|
||||
purgeTime = 2630000000L * pluginRef.getDatabaseCleaningSettings().getOldUserCutoffMonths();
|
||||
progressInterval = 200;
|
||||
|
||||
@ -113,6 +115,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
return poolProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDatabaseProgressPrintInterval() {
|
||||
return progressInterval;
|
||||
}
|
||||
|
||||
public void purgePowerlessUsers() {
|
||||
massUpdateLock.lock();
|
||||
pluginRef.getLogger().info("Purging powerless users...");
|
||||
|
@ -11,7 +11,6 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.party.ShareHandler;
|
||||
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
|
||||
import com.gmail.nossr50.skills.fishing.FishingManager;
|
||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||
|
@ -1,18 +1,21 @@
|
||||
package com.gmail.nossr50.runnables.database;
|
||||
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class DatabaseConversionTask extends BukkitRunnable {
|
||||
private final mcMMO pluginRef;
|
||||
private final DatabaseManager sourceDatabase;
|
||||
private final CommandSender sender;
|
||||
private final String message;
|
||||
|
||||
public DatabaseConversionTask(DatabaseManager sourceDatabase, CommandSender sender, String oldType, String newType) {
|
||||
public DatabaseConversionTask(mcMMO pluginRef, DatabaseManager sourceDatabase, CommandSender sender, String oldType, String newType) {
|
||||
this.pluginRef = pluginRef;
|
||||
this.sourceDatabase = sourceDatabase;
|
||||
this.sender = sender;
|
||||
message = pluginRef.getLocaleManager().getString("Commands.mcconvert.Database.Finish", oldType, newType);
|
||||
this.message = pluginRef.getLocaleManager().getString("Commands.mcconvert.Database.Finish", oldType, newType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,19 +1,28 @@
|
||||
package com.gmail.nossr50.runnables.database;
|
||||
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
//TODO: PUUUUUUUUUUURGE
|
||||
/**
|
||||
* This whole design of this thing is Jank
|
||||
* The name is Jank
|
||||
* Everything about this is Jank
|
||||
*
|
||||
* Fix this at some point in the future
|
||||
*/
|
||||
public class FormulaConversionTask extends BukkitRunnable {
|
||||
private CommandSender sender;
|
||||
private FormulaType previousFormula;
|
||||
private mcMMO pluginRef;
|
||||
|
||||
public FormulaConversionTask(CommandSender sender, FormulaType previousFormula) {
|
||||
public FormulaConversionTask(mcMMO pluginRef, CommandSender sender, FormulaType previousFormula) {
|
||||
this.pluginRef = pluginRef;
|
||||
this.sender = sender;
|
||||
this.previousFormula = previousFormula;
|
||||
}
|
||||
@ -43,7 +52,7 @@ public class FormulaConversionTask extends BukkitRunnable {
|
||||
editValues(profile);
|
||||
}
|
||||
convertedUsers++;
|
||||
Misc.printProgress(convertedUsers, DatabaseManager.progressInterval, startMillis);
|
||||
pluginRef.getDatabaseManager().printProgress(convertedUsers, startMillis, pluginRef.getLogger());
|
||||
}
|
||||
|
||||
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.mcconvert.Experience.Finish", pluginRef.getConfigManager().getConfigLeveling().getConfigExperienceFormula().toString()));
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.gmail.nossr50.runnables.database;
|
||||
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.uuid.UUIDFetcher;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -13,19 +11,19 @@ import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class UUIDUpdateAsyncTask extends BukkitRunnable {
|
||||
private mcMMO plugin;
|
||||
private static final int MAX_LOOKUP = 100;
|
||||
private static final int RATE_LIMIT = 300;
|
||||
private static final long LIMIT_PERIOD = 6000;
|
||||
private static final int BATCH_SIZE = MAX_LOOKUP * 3;
|
||||
private mcMMO pluginRef;
|
||||
private final int MAX_LOOKUP = 100;
|
||||
private final int RATE_LIMIT = 300;
|
||||
private final long LIMIT_PERIOD = 6000;
|
||||
private final int BATCH_SIZE = MAX_LOOKUP * 3;
|
||||
|
||||
private List<String> userNames;
|
||||
private int size;
|
||||
private int checkedUsers;
|
||||
private long startMillis;
|
||||
|
||||
public UUIDUpdateAsyncTask(mcMMO plugin, List<String> userNames) {
|
||||
this.plugin = plugin;
|
||||
public UUIDUpdateAsyncTask(mcMMO pluginRef, List<String> userNames) {
|
||||
this.pluginRef = pluginRef;
|
||||
this.userNames = userNames;
|
||||
|
||||
this.checkedUsers = 0;
|
||||
@ -36,7 +34,7 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable {
|
||||
public void run() {
|
||||
size = userNames.size();
|
||||
|
||||
plugin.getLogger().info("Starting to check and update UUIDs, total amount of users: " + size);
|
||||
pluginRef.getLogger().info("Starting to check and update UUIDs, total amount of users: " + size);
|
||||
|
||||
List<String> userNamesSection;
|
||||
Map<String, UUID> fetchedUUIDs = new HashMap<String, UUID>();
|
||||
@ -77,7 +75,7 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUIDs!", e);
|
||||
pluginRef.getLogger().log(Level.SEVERE, "Unable to fetch UUIDs!", e);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -85,7 +83,8 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable {
|
||||
userNamesSection.clear();
|
||||
size = userNames.size();
|
||||
|
||||
Misc.printProgress(checkedUsers, DatabaseManager.progressInterval, startMillis);
|
||||
pluginRef.getDatabaseManager().printProgress(checkedUsers, startMillis, pluginRef.getLogger());
|
||||
|
||||
if (fetchedUUIDs.size() >= BATCH_SIZE) {
|
||||
pluginRef.getDatabaseManager().saveUserUUIDs(fetchedUUIDs);
|
||||
fetchedUUIDs = new HashMap<String, UUID>();
|
||||
@ -94,7 +93,7 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable {
|
||||
|
||||
if (fetchedUUIDs.size() == 0 || pluginRef.getDatabaseManager().saveUserUUIDs(fetchedUUIDs)) {
|
||||
//mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS);
|
||||
plugin.getLogger().info("UUID upgrade completed!");
|
||||
pluginRef.getLogger().info("UUID upgrade completed!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,18 @@
|
||||
package com.gmail.nossr50.runnables.database;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class UserPurgeTask extends BukkitRunnable {
|
||||
private ReentrantLock lock = new ReentrantLock();
|
||||
private final mcMMO pluginRef;
|
||||
private ReentrantLock lock;
|
||||
|
||||
public UserPurgeTask(mcMMO pluginRef) {
|
||||
this.pluginRef = pluginRef;
|
||||
lock = new ReentrantLock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -180,12 +180,6 @@ public final class Misc {
|
||||
}
|
||||
}
|
||||
|
||||
public static void printProgress(int convertedUsers, int progressInterval, long startMillis) {
|
||||
if ((convertedUsers % progressInterval) == 0) {
|
||||
pluginRef.getLogger().info(String.format("Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / (double) ((System.currentTimeMillis() - startMillis) / TIME_CONVERSION_FACTOR)));
|
||||
}
|
||||
}
|
||||
|
||||
public static String getModName(String materialName) {
|
||||
for (String mod : modNames) {
|
||||
if (materialName.contains(mod)) {
|
||||
|
@ -9,7 +9,6 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerNotificationEvent;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.TextComponentFactory;
|
||||
import com.gmail.nossr50.util.sounds.SoundManager;
|
||||
import com.gmail.nossr50.util.sounds.SoundType;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
|
Loading…
Reference in New Issue
Block a user