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

76 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;
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;
@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;
}
2023-09-10 21:58:50 +00:00
registerEvents(getServer().getPluginManager());
//add a way to stop and start the fishing event and a way to stop all fishing (so 3 modes normal, active, disabled)
2023-09-24 20:53:30 +00:00
if (new LoadTask(PointsManagement.getInstance(), this, logger).loadOldPointsData())
logger.info("Loaded old points data");
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new SaveTask(PointsManagement.getInstance(), this, logger),
TimeUnit.MINUTES.toSeconds(5) * 20,
TimeUnit.MINUTES.toSeconds(5) * 20);
2023-09-10 21:58:50 +00:00
reloadFishConfigs();
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() {
}
private void registerEvents(@NotNull PluginManager pluginManager) {
pluginManager.registerEvents(new CatchFish(logger, new WaterFishGenerator(Fishes.WATER_FISH.RARITY_FISH_MAP, 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
}
}