fishing_event/src/main/java/com/alttd/fishingevent/FishingEvent.java

79 lines
2.8 KiB
Java
Raw Normal View History

2023-09-10 21:58:50 +00:00
package com.alttd.fishingevent;
import com.alttd.fishingevent.commands.FishCommand;
import com.alttd.fishingevent.config.Config;
import com.alttd.fishingevent.config.Fishes;
import com.alttd.fishingevent.config.Messages;
2023-09-22 00:21:53 +00:00
import com.alttd.fishingevent.config.NPCLocationConfig;
2023-09-10 21:58:50 +00:00
import com.alttd.fishingevent.fish_generator.WaterFishGenerator;
2023-09-22 00:37:05 +00:00
import com.alttd.fishingevent.gui.GUIListener;
2023-09-10 21:58:50 +00:00
import com.alttd.fishingevent.listeners.CatchFish;
2023-09-21 23:33:21 +00:00
import com.alttd.fishingevent.npc.NPCManager;
import com.alttd.fishingevent.objects.RarityManager;
2023-09-24 20:53:30 +00:00
import com.alttd.fishingevent.points.LoadTask;
2023-09-10 21:58:50 +00:00
import com.alttd.fishingevent.points.PointsManagement;
2023-09-24 20:53:30 +00:00
import com.alttd.fishingevent.points.SaveTask;
2023-09-10 21:58:50 +00:00
import com.alttd.fishingevent.util.Logger;
2023-09-22 00:21:53 +00:00
import dev.sergiferry.playernpc.api.NPCLib;
import org.bukkit.Bukkit;
2023-09-10 21:58:50 +00:00
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
2023-09-24 20:53:30 +00:00
import java.util.concurrent.TimeUnit;
2023-09-10 21:58:50 +00:00
public final class FishingEvent extends JavaPlugin {
private Logger logger;
2023-09-24 22:00:32 +00:00
private SaveTask saveTask;
2023-09-10 21:58:50 +00:00
@Override
public void onEnable() {
this.logger = new Logger(getLogger());
2023-09-22 00:21:53 +00:00
if (!loadNPCLib()) {
logger.severe("NPC Lib failed to load, shutting down plugin...");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
reloadFishConfigs();
2023-09-10 21:58:50 +00:00
registerEvents(getServer().getPluginManager());
2023-09-24 20:53:30 +00:00
if (new LoadTask(PointsManagement.getInstance(), this, logger).loadOldPointsData())
logger.info("Loaded old points data");
2023-09-24 22:00:32 +00:00
saveTask = new SaveTask(PointsManagement.getInstance(), this, logger);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, saveTask,
2023-09-24 20:53:30 +00:00
TimeUnit.MINUTES.toSeconds(5) * 20,
TimeUnit.MINUTES.toSeconds(5) * 20);
2023-09-10 21:58:50 +00:00
registerCommands();
2023-09-21 23:33:21 +00:00
NPCManager.spawnNPCs(this, logger);
2023-09-10 21:58:50 +00:00
}
2023-09-22 00:21:53 +00:00
private boolean loadNPCLib() {
NPCLib instance = NPCLib.getInstance();
if (instance == null)
return false;
NPCLib.PluginManager pluginManager = instance.registerPlugin(this);
return pluginManager != null;
}
2023-09-10 21:58:50 +00:00
@Override
public void onDisable() {
2023-09-24 22:00:32 +00:00
saveTask.run();
2023-09-10 21:58:50 +00:00
}
private void registerEvents(@NotNull PluginManager pluginManager) {
pluginManager.registerEvents(new CatchFish(logger, new WaterFishGenerator(Fishes.FISH.RARITY_WATER_FISH_MAP, new RarityManager(Config.RARITY.RARITY_SET), logger), PointsManagement.getInstance()), this);
2023-09-22 00:37:05 +00:00
pluginManager.registerEvents(new GUIListener(), this);
2023-09-10 21:58:50 +00:00
}
private void registerCommands() {
new FishCommand(this, logger);
}
public void reloadFishConfigs() {
Config.reload(this, logger);
Fishes.reload(this, logger);
Messages.reload(this, logger);
2023-09-22 00:22:00 +00:00
NPCLocationConfig.reload(this, logger);
2023-09-10 21:58:50 +00:00
}
}