mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
Remove redundant SmartCache and refactor related classes
The SmartCache class has been removed, and logic within it has been moved to relevant classes to reduce redundancy. This involved utilizing the PlayerManager for player data, instead of invalidating a separate cache in the now-removed SmartCache. Other classes that interacted with SmartCache, such as API, listeners and PreventStabby, have been updated to use the newly refactored system.
This commit is contained in:
@@ -5,65 +5,31 @@ import me.youhavetrouble.preventstabby.config.ConfigCache;
|
||||
import me.youhavetrouble.preventstabby.hooks.PlaceholderApiHook;
|
||||
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
|
||||
import me.youhavetrouble.preventstabby.players.PlayerManager;
|
||||
import me.youhavetrouble.preventstabby.players.SmartCache;
|
||||
import me.youhavetrouble.preventstabby.util.*;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.reflections.Reflections;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Set;
|
||||
|
||||
public final class PreventStabby extends JavaPlugin {
|
||||
|
||||
@Getter private static PreventStabby plugin;
|
||||
private static PreventStabby plugin;
|
||||
private ConfigCache configCache;
|
||||
private PlayerManager playerManager;
|
||||
|
||||
private DamageUtil damageUtil;
|
||||
private DamageCheck damageCheck;
|
||||
private DatabaseSQLite sqLite;
|
||||
private SmartCache smartCache;
|
||||
private static boolean worldGuardHook;
|
||||
|
||||
private static BukkitAudiences adventure;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
Util.initData();
|
||||
reloadPluginConfig();
|
||||
File dbFile = new File("plugins/PreventStabby");
|
||||
sqLite = new DatabaseSQLite("jdbc:sqlite:plugins/PreventStabby/database.db", dbFile, getLogger());
|
||||
sqLite.createDatabaseFile();
|
||||
if (!sqLite.testConnection()) {
|
||||
getLogger().severe("Error with accessing database. Check if server has write rights.");
|
||||
getLogger().severe("Plugin will now disable.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
adventure = BukkitAudiences.create(this);
|
||||
playerManager = new PlayerManager();
|
||||
damageUtil = new DamageUtil(this);
|
||||
smartCache = new SmartCache();
|
||||
smartCache.runSmartCache();
|
||||
playerManager = new PlayerManager(this);
|
||||
damageCheck = new DamageCheck(this);
|
||||
|
||||
// Register listeners TODO
|
||||
|
||||
// Register listeners
|
||||
Reflections reflections = new Reflections((Object[]) new String[]{"me.youhavetrouble.preventstabby"});
|
||||
Set<Class<?>> listenerClasses = reflections.getTypesAnnotatedWith(PreventStabbyListener.class);
|
||||
listenerClasses.forEach((listener)-> {
|
||||
try {
|
||||
getServer().getPluginManager().registerEvents((org.bukkit.event.Listener) listener.getConstructor().newInstance(), this);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
getLogger().severe("Error with registering listeners.");
|
||||
getLogger().severe("Plugin will now disable.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
});
|
||||
|
||||
// Register command
|
||||
PluginCommand pvpCommand = getCommand("pvp");
|
||||
@@ -100,7 +66,7 @@ public final class PreventStabby extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void reloadPluginConfig() {
|
||||
configCache = new ConfigCache();
|
||||
configCache = new ConfigCache(this);
|
||||
}
|
||||
|
||||
public void reloadPluginConfig(CommandSender commandSender) {
|
||||
@@ -118,17 +84,14 @@ public final class PreventStabby extends JavaPlugin {
|
||||
return playerManager;
|
||||
}
|
||||
|
||||
public DamageUtil getDamageUtil() {
|
||||
return damageUtil;
|
||||
public DamageCheck getDamageUtil() {
|
||||
return damageCheck;
|
||||
}
|
||||
|
||||
public DatabaseSQLite getSqLite() {return sqLite;}
|
||||
|
||||
public SmartCache getSmartCache() {
|
||||
return smartCache;
|
||||
public static PreventStabby getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static BukkitAudiences getAudiences() {
|
||||
return adventure;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user