Files
src
build.gradle
settings.gradle
Code
19 1,153
src/main/java/com/drfrozenxd/frozenlives/FrozenLives.java
package com.drfrozenxd.frozenlives;
import com.drfrozenxd.frozenlives.antifarm.KillCooldownManager;
import com.drfrozenxd.frozenlives.commands.LivesCommand;
import com.drfrozenxd.frozenlives.data.PlayerDataManager;
import com.drfrozenxd.frozenlives.gui.LivesShopGUI;
import com.drfrozenxd.frozenlives.listeners.*;
import com.drfrozenxd.frozenlives.placeholders.FrozenLivesPlaceholder;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public final class FrozenLives extends JavaPlugin {
private static FrozenLives instance;
private Economy economy;
private PlayerDataManager playerDataManager;
private KillCooldownManager killCooldownManager;
private LivesShopGUI livesShopGUI;
@Override
public void onEnable() {
instance = this;
// Load configs
saveDefaultConfig();
saveResource("lives-shop.yml", false);
// Vault check
if (!setupEconomy()) {
getLogger().severe("Vault not found! Disabling FrozenLives.");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
// Player data manager
playerDataManager = new PlayerDataManager(this);
// Anti-farm cooldown
long cooldownSeconds = getConfig()
.getLong("anti-farm.kill-cooldown-seconds", 120);
killCooldownManager = new KillCooldownManager(cooldownSeconds);
// Lives shop GUI
livesShopGUI = new LivesShopGUI(this);
// Register listeners
Bukkit.getPluginManager().registerEvents(
new PlayerConnectionListener(playerDataManager),
this
);
Bukkit.getPluginManager().registerEvents(
new PlayerDeathListener(this, playerDataManager, killCooldownManager),
this
);
Bukkit.getPluginManager().registerEvents(
new PlayerQuitListener(this),
this
);
Bukkit.getPluginManager().registerEvents(
new PlayerLoginListener(this),
this
);
Bukkit.getPluginManager().registerEvents(
livesShopGUI,
this
);
// Register commands
getCommand("lives").setExecutor(new LivesCommand(this));
// PlaceholderAPI hook
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new FrozenLivesPlaceholder(this).register();
getLogger().info("PlaceholderAPI support enabled.");
}
getLogger().info("FrozenLives enabled successfully.");
}
@Override
public void onDisable() {
if (playerDataManager != null) {
playerDataManager.saveAll();
}
getLogger().info("FrozenLives disabled.");
}
// =======================
// Getters
// =======================
public static FrozenLives getInstance() {
return instance;
}
public Economy getEconomy() {
return economy;
}
public PlayerDataManager getPlayerDataManager() {
return playerDataManager;
}
public KillCooldownManager getKillCooldownManager() {
return killCooldownManager;
}
public LivesShopGUI getLivesShopGUI() {
return livesShopGUI;
}
// =======================
// Vault setup
// =======================
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) return false;
RegisteredServiceProvider<Economy> provider =
getServer().getServicesManager().getRegistration(Economy.class);
if (provider == null) return false;
economy = provider.getProvider();
return economy != null;
}
}