mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-23 00:49:33 +00:00
1.5.19-PRE1
This commit is contained in:
@@ -42,11 +42,18 @@ public final class CustomCrops extends JavaPlugin {
|
||||
|
||||
public static JavaPlugin instance;
|
||||
public static BukkitAudiences adventure;
|
||||
|
||||
private CropTimer cropTimer;
|
||||
private CropManager cropManager;
|
||||
private SprinklerManager sprinklerManager;
|
||||
private SeasonManager seasonManager;
|
||||
private PotManager potManager;
|
||||
private Placeholders placeholders;
|
||||
|
||||
public CropManager getCropManager() { return this.cropManager; }
|
||||
public SprinklerManager getSprinklerManager() { return sprinklerManager; }
|
||||
public SeasonManager getSeasonManager() { return seasonManager; }
|
||||
public PotManager getPotManager() { return potManager; }
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -56,40 +63,83 @@ public final class CustomCrops extends JavaPlugin {
|
||||
|
||||
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#FFEBCD>Running on " + Bukkit.getVersion());
|
||||
|
||||
//加载配置文件
|
||||
ConfigReader.ReloadConfig();
|
||||
|
||||
//PAPI
|
||||
if(Bukkit.getPluginManager().getPlugin("PlaceHolderAPI") != null){
|
||||
new Placeholders().register();
|
||||
placeholders = new Placeholders();
|
||||
placeholders.register();
|
||||
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>PlaceHolderAPI <color:#FFEBCD>Hooked!");
|
||||
}
|
||||
|
||||
//指令注册
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setExecutor(new Executor(this));
|
||||
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setTabCompleter(new Completer());
|
||||
|
||||
//注册事件
|
||||
Bukkit.getPluginManager().registerEvents(new ItemSpawn(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new RightClick(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new BreakBlock(), this);
|
||||
Bukkit.getPluginManager().registerEvents(new InteractEntity(this), this);
|
||||
|
||||
//开始计时器
|
||||
this.cropTimer = new CropTimer(this);
|
||||
|
||||
//载入数据
|
||||
if (ConfigReader.Season.enable){
|
||||
this.seasonManager = new SeasonManager(this);
|
||||
this.seasonManager = new SeasonManager();
|
||||
this.seasonManager.loadData();
|
||||
}
|
||||
this.cropManager = new CropManager(this);
|
||||
this.cropManager = new CropManager();
|
||||
this.cropManager.loadData();
|
||||
this.sprinklerManager = new SprinklerManager(this);
|
||||
this.sprinklerManager = new SprinklerManager();
|
||||
this.sprinklerManager.loadData();
|
||||
this.potManager = new PotManager(this);
|
||||
this.potManager = new PotManager();
|
||||
this.potManager.loadData();
|
||||
this.cropTimer = new CropTimer(this);
|
||||
|
||||
checkIAConfig();
|
||||
|
||||
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>Plugin Enabled!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
HoloUtil.cache.keySet().forEach(location -> HoloUtil.cache.get(location).remove());
|
||||
|
||||
if (this.cropManager != null){
|
||||
this.cropManager.cleanData();
|
||||
this.cropManager.saveData();
|
||||
this.cropManager = null;
|
||||
}
|
||||
if (this.potManager != null){
|
||||
this.potManager.saveData();
|
||||
this.potManager = null;
|
||||
}
|
||||
if (this.sprinklerManager != null){
|
||||
this.sprinklerManager.cleanData();
|
||||
this.sprinklerManager.saveData();
|
||||
this.sprinklerManager = null;
|
||||
}
|
||||
if (ConfigReader.Season.enable && !ConfigReader.Season.seasonChange && this.seasonManager != null){
|
||||
this.seasonManager.saveData();
|
||||
this.seasonManager = null;
|
||||
}
|
||||
if (this.placeholders != null){
|
||||
placeholders.unregister();
|
||||
placeholders = null;
|
||||
}
|
||||
|
||||
getLogger().info("Backing Up...");
|
||||
BackUp.backUpData();
|
||||
getLogger().info("Done.");
|
||||
|
||||
if (cropTimer != null) {
|
||||
this.cropTimer.stopTimer(cropTimer.getTaskID());
|
||||
}
|
||||
if (adventure != null) {
|
||||
adventure.close();
|
||||
}
|
||||
if (instance != null) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIAConfig(){
|
||||
FileConfiguration fileConfiguration = Bukkit.getPluginManager().getPlugin("ItemsAdder").getConfig();
|
||||
if (fileConfiguration.getBoolean("blocks.disable-REAL_WIRE")){
|
||||
fileConfiguration.set("blocks.disable-REAL_WIRE", false);
|
||||
@@ -100,46 +150,6 @@ public final class CustomCrops extends JavaPlugin {
|
||||
}
|
||||
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><red>Detected that you might have not set \"disable-REAL_WIRE\" false in ItemsAdder's config!");
|
||||
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><red>You need a restart to apply that config :)");
|
||||
}else {
|
||||
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>Plugin Enabled!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
//保存数据
|
||||
this.cropManager.cleanData();
|
||||
this.cropManager.saveData();
|
||||
this.sprinklerManager.cleanData();
|
||||
this.sprinklerManager.saveData();
|
||||
this.potManager.saveData();
|
||||
if (ConfigReader.Season.enable && !ConfigReader.Season.seasonChange){
|
||||
this.seasonManager.saveData();
|
||||
}
|
||||
|
||||
//备份数据
|
||||
getLogger().info("Back Up...");
|
||||
BackUp.backUpData();
|
||||
getLogger().info("Done.");
|
||||
|
||||
//清除悬浮展示实体
|
||||
HoloUtil.cache.keySet().forEach(location -> {
|
||||
HoloUtil.cache.get(location).remove();
|
||||
});
|
||||
|
||||
//关闭计时器
|
||||
if (cropTimer != null) {
|
||||
this.cropTimer.stopTimer(cropTimer.getTaskID());
|
||||
}
|
||||
|
||||
if (adventure != null) {
|
||||
adventure.close();
|
||||
}
|
||||
}
|
||||
|
||||
public CropManager getCropManager() { return this.cropManager; }
|
||||
public SprinklerManager getSprinklerManager() { return sprinklerManager; }
|
||||
public SeasonManager getSeasonManager() { return seasonManager; }
|
||||
public PotManager getPotManager() { return potManager; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user