Files
src
pom.xml
Code
30 2,505
src/main/java/com/hungergames/HungerGames.java
package com.hungergames;
import com.hungergames.commands.HGCommand;
import com.hungergames.listeners.ChestListener;
import com.hungergames.listeners.CombatListener;
import com.hungergames.listeners.PlayerListener;
import com.hungergames.listeners.ProtectionListener;
import com.hungergames.managers.BorderManager;
import com.hungergames.managers.ChestManager;
import com.hungergames.managers.CombatManager;
import com.hungergames.managers.GameManager;
import com.hungergames.managers.KitManager;
import com.hungergames.managers.ProtectionManager;
import com.hungergames.managers.ScoreboardManager;
import com.hungergames.managers.SpawnManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
@Getter
public class HungerGames extends JavaPlugin {
private GameManager gameManager;
private SpawnManager spawnManager;
private BorderManager borderManager;
private ChestManager chestManager;
private KitManager kitManager;
private CombatManager combatManager;
private ScoreboardManager scoreboardManager;
private ProtectionManager protectionManager;
private File messagesFile;
private FileConfiguration messagesConfig;
private File kitsFile;
private FileConfiguration kitsConfig;
private File scoreboardFile;
private FileConfiguration scoreboardConfig;
@Override
public void onEnable() {
this.saveDefaultConfig();
this.createCustomConfigs();
this.gameManager = new GameManager(this);
this.spawnManager = new SpawnManager(this);
this.borderManager = new BorderManager(this);
this.chestManager = new ChestManager(this);
this.kitManager = new KitManager(this);
this.combatManager = new CombatManager(this);
this.scoreboardManager = new ScoreboardManager(this);
this.protectionManager = new ProtectionManager(this);
this.registerCommands();
this.registerListeners();
this.scoreboardManager.startUpdating();
this.getLogger().info("HungerGames plugin enabled!");
}
@Override
public void onDisable() {
if (this.gameManager.getSession().isGameActive()) {
this.gameManager.forceStop();
}
this.scoreboardManager.stopUpdating();
this.getLogger().info("HungerGames plugin disabled!");
}
private void createCustomConfigs() {
this.messagesFile = new File(this.getDataFolder(), "msgs.yml");
if (!this.messagesFile.exists()) {
this.saveResource("msgs.yml", false);
}
this.messagesConfig = YamlConfiguration.loadConfiguration(this.messagesFile);
this.kitsFile = new File(this.getDataFolder(), "kits.yml");
if (!this.kitsFile.exists()) {
this.saveResource("kits.yml", false);
}
this.kitsConfig = YamlConfiguration.loadConfiguration(this.kitsFile);
this.scoreboardFile = new File(this.getDataFolder(), "scoreboard.yml");
if (!this.scoreboardFile.exists()) {
this.saveResource("scoreboard.yml", false);
}
this.scoreboardConfig = YamlConfiguration.loadConfiguration(this.scoreboardFile);
}
public void reloadConfigs() {
this.reloadConfig();
this.messagesConfig = YamlConfiguration.loadConfiguration(this.messagesFile);
this.kitsConfig = YamlConfiguration.loadConfiguration(this.kitsFile);
this.scoreboardConfig = YamlConfiguration.loadConfiguration(this.scoreboardFile);
this.kitManager.loadKits();
}
private void registerCommands() {
this.getCommand("hg").setExecutor(new HGCommand(this));
}
private void registerListeners() {
Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
Bukkit.getPluginManager().registerEvents(new CombatListener(this), this);
Bukkit.getPluginManager().registerEvents(new ProtectionListener(this), this);
Bukkit.getPluginManager().registerEvents(new ChestListener(this), this);
}
}