mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-01-06 19:18:07 +01:00
Split load and unload code into their own functions
to prepare for reload support
This commit is contained in:
parent
167a204c2a
commit
392a2a7c74
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 GeorgH93
|
* Copyright (C) 2016, 2017 GeorgH93
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -94,6 +94,35 @@ public void onEnable()
|
|||||||
instance = this;
|
instance = this;
|
||||||
config = new Config(this);
|
config = new Config(this);
|
||||||
lang = new Language(this);
|
lang = new Language(this);
|
||||||
|
|
||||||
|
load();
|
||||||
|
|
||||||
|
if(config.getAutoUpdate()) // Lets check for updates
|
||||||
|
{
|
||||||
|
getLogger().info("Checking for updates ...");
|
||||||
|
Updater updater = new Updater(this, this.getFile(), true, 83445); // Create a new updater with dev.bukkit.org as update provider
|
||||||
|
updater.update(); // Starts the update
|
||||||
|
}
|
||||||
|
StringUtils.getPluginEnabledMessage(getDescription().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
Updater updater = null;
|
||||||
|
if(config.getAutoUpdate()) // Lets check for updates
|
||||||
|
{
|
||||||
|
getLogger().info("Checking for updates ...");
|
||||||
|
updater = new Updater(this, this.getFile(), true, 83445); // Create a new updater with dev.bukkit.org as update provider
|
||||||
|
updater.update(); // Starts the update, if there is a new update available it will download while we close the rest
|
||||||
|
}
|
||||||
|
unload();
|
||||||
|
if(updater != null) updater.waitForAsyncOperation(); // The update can download while we kill the listeners and close the DB connections
|
||||||
|
StringUtils.getPluginDisabledMessage(getDescription().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
lang.load(config.getLanguage(), config.getLanguageUpdateMode());
|
lang.load(config.getLanguage(), config.getLanguageUpdateMode());
|
||||||
database = Database.getDatabase(this);
|
database = Database.getDatabase(this);
|
||||||
maxSize = config.getBackpackMaxSize();
|
maxSize = config.getBackpackMaxSize();
|
||||||
@ -115,31 +144,20 @@ public void onEnable()
|
|||||||
{
|
{
|
||||||
(new ItemsCollector(this)).runTaskTimer(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval());
|
(new ItemsCollector(this)).runTaskTimer(this, config.getFullInvCheckInterval(), config.getFullInvCheckInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config.getAutoUpdate()) // Lets check for updates
|
|
||||||
{
|
|
||||||
getLogger().info("Checking for updates ...");
|
|
||||||
Updater updater = new Updater(this, this.getFile(), true, 83445); // Create a new updater with dev.bukkit.org as update provider
|
|
||||||
updater.update(); // Starts the update
|
|
||||||
}
|
|
||||||
StringUtils.getPluginEnabledMessage(getDescription().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void unload()
|
||||||
public void onDisable()
|
|
||||||
{
|
{
|
||||||
Updater updater = null;
|
|
||||||
if(config.getAutoUpdate()) // Lets check for updates
|
|
||||||
{
|
|
||||||
getLogger().info("Checking for updates ...");
|
|
||||||
updater = new Updater(this, this.getFile(), true, 83445); // Create a new updater with dev.bukkit.org as update provider
|
|
||||||
updater.update(); // Starts the update, if there is a new update available it will download while we close the rest
|
|
||||||
}
|
|
||||||
getServer().getScheduler().cancelTasks(this); // Stop the listener, we don't need them any longer
|
getServer().getScheduler().cancelTasks(this); // Stop the listener, we don't need them any longer
|
||||||
database.close(); // Close the DB connection, we won't need them any longer
|
database.close(); // Close the DB connection, we won't need them any longer
|
||||||
instance = null;
|
instance = null;
|
||||||
if(updater != null) updater.waitForAsyncOperation(); // The update can download while we kill the listeners and close the DB connections
|
}
|
||||||
StringUtils.getPluginDisabledMessage(getDescription().getName());
|
|
||||||
|
public void reload()
|
||||||
|
{
|
||||||
|
unload();
|
||||||
|
config.reload();
|
||||||
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warnOnVersionIncompatibility(String version)
|
public void warnOnVersionIncompatibility(String version)
|
||||||
|
Loading…
Reference in New Issue
Block a user