Files
src
pom.xml
Code
20 3,538
src/main/java/dev/spark/swiftquests/SwiftQuests.java
package dev.spark.swiftquests;
import java.util.Locale;
import java.util.logging.Level;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import dev.spark.swiftquests.command.AdminCommand;
import dev.spark.swiftquests.command.PointsCommand;
import dev.spark.swiftquests.command.QuestsCommand;
import dev.spark.swiftquests.config.ConfigManager;
import dev.spark.swiftquests.config.Messages;
import dev.spark.swiftquests.config.Settings;
import dev.spark.swiftquests.data.DataManager;
import dev.spark.swiftquests.data.Storage;
import dev.spark.swiftquests.gui.MenuManager;
import dev.spark.swiftquests.hook.PointsExpansion;
import dev.spark.swiftquests.hook.QuestsExpansion;
import dev.spark.swiftquests.listener.BlockTracker;
import dev.spark.swiftquests.listener.PaperQuestListener;
import dev.spark.swiftquests.listener.QuestListener;
import dev.spark.swiftquests.platform.Sched;
import dev.spark.swiftquests.points.PointsManager;
import dev.spark.swiftquests.quest.QuestManager;
import dev.spark.swiftquests.quest.QuestTrigger;
import dev.spark.swiftquests.shop.ShopManager;
import dev.spark.swiftquests.util.PapiBridge;
import dev.spark.swiftquests.util.Text;
public class SwiftQuests extends JavaPlugin {
private static SwiftQuests instance;
private ConfigManager configs;
private Settings settings;
private Messages messages;
private Storage storage;
private DataManager data;
private PointsManager points;
private QuestManager quests;
private ShopManager shop;
private MenuManager menus;
private BlockTracker blockTracker;
private QuestListener questListener;
private Sched.Task playtimeTask;
private PointsExpansion pointsExpansion;
private QuestsExpansion questsExpansion;
private boolean paperTradeEvent;
private volatile boolean ready;
public static SwiftQuests instance() {
return instance;
}
public void onEnable() {
instance = this;
long start = System.currentTimeMillis();
Sched.init(this);
this.configs = new ConfigManager(this);
this.configs.loadAll();
this.settings = new Settings(this);
this.settings.load();
this.messages = new Messages(this);
this.messages.load();
this.storage = new Storage(this);
if (!this.storage.awaitConnect()) {
this.getLogger().severe("SwiftQuests could not open its database and will not enable.");
this.getServer().getPluginManager().disablePlugin(this);
} else {
this.data = new DataManager(this, this.storage);
this.points = new PointsManager(this);
this.points.reload();
this.blockTracker = new BlockTracker(this);
this.blockTracker.reload();
this.quests = new QuestManager(this);
this.quests.loadDefinitions();
this.shop = new ShopManager(this);
this.shop.load();
this.menus = new MenuManager(this);
this.menus.load();
this.quests.loadBoard();
this.quests.startTasks();
this.menus.startTask();
this.startPlaytimeTask();
this.questListener = new QuestListener(this, this.blockTracker);
this.getServer().getPluginManager().registerEvents(this.questListener, this);
this.getServer().getPluginManager().registerEvents(this.menus, this);
this.registerPaperListener();
this.register("quests", new QuestsCommand(this, false));
this.register("questshop", new QuestsCommand(this, true));
this.register("swiftquestpoints", new PointsCommand(this));
this.register("swiftquestsadmin", new AdminCommand(this));
this.registerExpansions();
for (Player player : this.getServer().getOnlinePlayers()) {
this.data.load(player.getUniqueId(), player.getName());
}
this.ready = true;
this.getLogger().info("SwiftQuests v" + this.version() + " enabled on " + Sched.platformName() + " in " + (System.currentTimeMillis() - start) + "ms.");
}
}
public void onDisable() {
this.ready = false;
if (this.menus != null) {
this.menus.stopTask();
this.menus.closeAll();
}
if (this.playtimeTask != null) {
this.playtimeTask.cancel();
}
if (this.quests != null) {
this.quests.stopTasks();
this.quests.saveBoard();
this.quests.saveProgress();
}
if (this.data != null) {
this.data.flush();
}
if (this.pointsExpansion != null) {
this.safeUnregister(this.pointsExpansion);
}
if (this.questsExpansion != null) {
this.safeUnregister(this.questsExpansion);
}
if (this.storage != null) {
this.storage.shutdown();
}
this.getLogger().info("SwiftQuests disabled.");
}
private void safeUnregister(Object expansion) {
try {
((PlaceholderExpansion)expansion).unregister();
} catch (Throwable var3) {
}
}
public boolean isReady() {
return this.ready;
}
public String version() {
return this.getDescription().getVersion();
}
private void register(String name, Object executor) {
PluginCommand command = this.getCommand(name);
if (command == null) {
this.getLogger().warning("Command '" + name + "' is missing from plugin.yml.");
} else {
command.setExecutor((CommandExecutor)executor);
if (executor instanceof TabCompleter completer) {
command.setTabCompleter(completer);
}
}
}
private void registerPaperListener() {
try {
Class.forName("io.papermc.paper.event.player.PlayerTradeEvent");
this.paperTradeEvent = true;
} catch (Throwable var3) {
this.paperTradeEvent = false;
}
if (!this.paperTradeEvent) {
this.getLogger().info("Paper trade events unavailable - using the vanilla merchant fallback.");
} else {
try {
this.getServer().getPluginManager().registerEvents(new PaperQuestListener(this), this);
} catch (Throwable var2) {
this.paperTradeEvent = false;
this.getLogger().log(Level.WARNING, "Could not register the Paper listener - falling back to the vanilla merchant handler.", var2);
}
}
}
public boolean hasPaperTradeEvent() {
return this.paperTradeEvent;
}
private void registerExpansions() {
PapiBridge.reset();
if (!PapiBridge.isPresent()) {
this.getLogger().info("PlaceholderAPI not found - placeholders are disabled.");
} else {
try {
this.pointsExpansion = new PointsExpansion(this);