Files
src
build.gradle
Code
55 5,435
src/main/java/com/arsec4real/cloudpractise/CloudPractise.java
package com.arsec4real.cloudpractise;
import com.arsec4real.cloudpractise.commands.ArenaCommand;
import com.arsec4real.cloudpractise.commands.CloudCommand;
import com.arsec4real.cloudpractise.commands.DuelCommand;
import com.arsec4real.cloudpractise.commands.EventCommand;
import com.arsec4real.cloudpractise.commands.KitCommand;
import com.arsec4real.cloudpractise.commands.LeaderboardCommand;
import com.arsec4real.cloudpractise.commands.PartyCommand;
import com.arsec4real.cloudpractise.commands.QueueCommand;
import com.arsec4real.cloudpractise.commands.SpectateCommand;
import com.arsec4real.cloudpractise.commands.StatsCommand;
import com.arsec4real.cloudpractise.gui.ArenaEditorGUI;
import com.arsec4real.cloudpractise.gui.EventGUI;
import com.arsec4real.cloudpractise.gui.KitEditorGUI;
import com.arsec4real.cloudpractise.gui.KitSelectorGUI;
import com.arsec4real.cloudpractise.gui.LeaderboardGUI;
import com.arsec4real.cloudpractise.gui.PartyGUI;
import com.arsec4real.cloudpractise.gui.QueueSelectorGUI;
import com.arsec4real.cloudpractise.gui.SpectatorGUI;
import com.arsec4real.cloudpractise.gui.StatsGUI;
import com.arsec4real.cloudpractise.listeners.CombatListener;
import com.arsec4real.cloudpractise.listeners.InventoryListener;
import com.arsec4real.cloudpractise.listeners.PlayerListener;
import com.arsec4real.cloudpractise.managers.ArenaManager;
import com.arsec4real.cloudpractise.managers.EventManager;
import com.arsec4real.cloudpractise.managers.KitManager;
import com.arsec4real.cloudpractise.managers.MatchManager;
import com.arsec4real.cloudpractise.managers.PartyManager;
import com.arsec4real.cloudpractise.managers.QueueManager;
import com.arsec4real.cloudpractise.managers.SpectatorManager;
import com.arsec4real.cloudpractise.managers.StatsManager;
import com.arsec4real.cloudpractise.scoreboard.ScoreboardManager;
import com.arsec4real.cloudpractise.utils.ColorUtil;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class CloudPractise extends JavaPlugin {
private static CloudPractise instance;
private ArenaManager arenaManager;
private KitManager kitManager;
private MatchManager matchManager;
private QueueManager queueManager;
private PartyManager partyManager;
private StatsManager statsManager;
private EventManager eventManager;
private SpectatorManager spectatorManager;
private ScoreboardManager scoreboardManager;
private KitSelectorGUI kitSelectorGUI;
private QueueSelectorGUI queueSelectorGUI;
private KitEditorGUI kitEditorGUI;
private SpectatorGUI spectatorGUI;
private StatsGUI statsGUI;
private LeaderboardGUI leaderboardGUI;
private PartyGUI partyGUI;
private EventGUI eventGUI;
private ArenaEditorGUI arenaEditorGUI;
private Location spawn;
@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
getDataFolder().mkdirs();
generateHelpFile();
loadSpawn();
initManagers();
initGUIs();
registerCommands();
registerListeners();
getLogger().info("[CloudPractise] Enabled | Creator: arsec4real");
}
@Override
public void onDisable() {
if (statsManager != null) statsManager.saveAll();
if (kitManager != null) kitManager.saveKits();
if (arenaManager != null) arenaManager.saveArenas();
if (queueManager != null) queueManager.shutdown();
if (scoreboardManager != null) scoreboardManager.shutdown();
instance = null;
getLogger().info("[CloudPractise] Disabled");
}
private void initManagers() {
statsManager = new StatsManager(this);
arenaManager = new ArenaManager(this);
kitManager = new KitManager(this);
spectatorManager = new SpectatorManager(this);
matchManager = new MatchManager(this);
queueManager = new QueueManager(this);
partyManager = new PartyManager(this);
eventManager = new EventManager(this);
scoreboardManager = new ScoreboardManager(this);
}
private void initGUIs() {
kitSelectorGUI = new KitSelectorGUI(this);
queueSelectorGUI = new QueueSelectorGUI(this);
kitEditorGUI = new KitEditorGUI(this);
spectatorGUI = new SpectatorGUI(this);
statsGUI = new StatsGUI(this);
leaderboardGUI = new LeaderboardGUI(this);
partyGUI = new PartyGUI(this);
eventGUI = new EventGUI(this);
arenaEditorGUI = new ArenaEditorGUI(this);
}
private void registerCommands() {
DuelCommand duelCmd = new DuelCommand(this);
getCommand("duel").setExecutor(duelCmd);
getCommand("duel").setTabCompleter(duelCmd);
getCommand("accept").setExecutor(duelCmd);
getCommand("deny").setExecutor(duelCmd);
ArenaCommand arenaCmd = new ArenaCommand(this);
getCommand("arena").setExecutor(arenaCmd);
getCommand("arena").setTabCompleter(arenaCmd);
KitCommand kitCmd = new KitCommand(this);
getCommand("kit").setExecutor(kitCmd);
getCommand("kit").setTabCompleter(kitCmd);
getCommand("editkit").setExecutor(kitCmd);
getCommand("editkit").setTabCompleter(kitCmd);
QueueCommand queueCmd = new QueueCommand(this);
getCommand("queue").setExecutor(queueCmd);
getCommand("queue").setTabCompleter(queueCmd);
getCommand("leave").setExecutor(queueCmd);
PartyCommand partyCmd = new PartyCommand(this);
getCommand("party").setExecutor(partyCmd);
getCommand("party").setTabCompleter(partyCmd);
getCommand("stats").setExecutor(new StatsCommand(this));
getCommand("leaderboard").setExecutor(new LeaderboardCommand(this));
getCommand("event").setExecutor(new EventCommand(this));
getCommand("spectate").setExecutor(new SpectateCommand(this));
CloudCommand cpCmd = new CloudCommand(this);
getCommand("cloudpractise").setExecutor(cpCmd);
getCommand("cloudpractise").setTabCompleter(cpCmd);
getCommand("setspawn").setExecutor(cpCmd);
}
private void registerListeners() {
getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
getServer().getPluginManager().registerEvents(new CombatListener(this), this);
getServer().getPluginManager().registerEvents(new InventoryListener(this), this);
}
private void loadSpawn() {
String world = getConfig().getString("spawn.world", "world");
double x = getConfig().getDouble("spawn.x", 0.0);
double y = getConfig().getDouble("spawn.y", 64.0);
double z = getConfig().getDouble("spawn.z", 0.0);
float yaw = (float) getConfig().getDouble("spawn.yaw", 0.0);
float pitch = (float) getConfig().getDouble("spawn.pitch", 0.0);
org.bukkit.World w = getServer().getWorld(world);
if (w != null) spawn = new Location(w, x, y, z, yaw, pitch);
}
public void setSpawn(Location location) {
this.spawn = location;
getConfig().set("spawn.world", location.getWorld().getName());
getConfig().set("spawn.x", location.getX());
getConfig().set("spawn.y", location.getY());
getConfig().set("spawn.z", location.getZ());
getConfig().set("spawn.yaw", location.getYaw());
getConfig().set("spawn.pitch", location.getPitch());
saveConfig();
}
private void generateHelpFile() {
java.io.File helpFile = new java.io.File(getDataFolder(), "help.txt");
if (helpFile.exists()) return;
try (java.io.PrintWriter writer = new java.io.PrintWriter(new java.io.FileWriter(helpFile))) {
writer.println("========================================");
writer.println(" CloudPractise - Help & Documentation");
writer.println(" Version: " + getDescription().getVersion());
writer.println(" Author: arsec4real");
writer.println("========================================");
writer.println();
writer.println("--- COMMANDS ---");
writer.println();
writer.println("/cloudpractise (alias: /cp)");
writer.println(" /cp help Show help menu");
writer.println(" /cp reload Reload config, kits, arenas, scoreboard");
writer.println(" /cp setspawn Set the server spawn point");
writer.println(" /cp info View plugin stats");
writer.println(" /cp arenas Open arena editor GUI");
writer.println();
writer.println("/duel <player> [kit] Challenge a player to a duel");
writer.println("/accept Accept an incoming duel request");