This commit is contained in:
tastybento 2018-08-02 08:11:46 -07:00
parent 2d75a92700
commit 02e528cdc7
3 changed files with 45 additions and 37 deletions

View File

@ -5,6 +5,7 @@ import org.bukkit.World;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import world.bentobox.bentobox.api.commands.MyCommand;
import world.bentobox.bentobox.api.configuration.BSBConfig;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
@ -64,6 +65,7 @@ public class BentoBox extends JavaPlugin {
@Override
public void onEnable(){
// Not loaded
isLoaded = false;
// Store the current millis time so we can tell how many ms it took for BSB to fully load.
@ -72,7 +74,6 @@ public class BentoBox extends JavaPlugin {
// Save the default config from config.yml
saveDefaultConfig();
setInstance(this);
// Load Flags
flagsManager = new FlagsManager(instance);
@ -99,51 +100,56 @@ public class BentoBox extends JavaPlugin {
// Set up command manager
commandsManager = new CommandsManager();
new MyCommand(); // Tab Complete works in-game and in console
getServer().getScheduler().runTask(this, () -> new MyCommand()); // Tab complete does not work in-game, only console
// These items have to be loaded when the server has done 1 tick.
// Note Worlds are not loaded this early, so any Locations or World reference will be null
// at this point. Therefore, the 1 tick scheduler is required.
getServer().getScheduler().runTask(this, () -> {
// Create the world if it does not exist
islandWorldManager = new IslandWorldManager(instance);
// Load schems manager
schemsManager = new SchemsManager(instance);
//getServer().getScheduler().runTask(this, () -> {
// Create the world if it does not exist
islandWorldManager = new IslandWorldManager(instance);
// Load schems manager
schemsManager = new SchemsManager(instance);
// Locales manager must be loaded before addons
localesManager = new LocalesManager(instance);
PlaceholderHandler.register(instance);
// Locales manager must be loaded before addons
localesManager = new LocalesManager(instance);
PlaceholderHandler.register(instance);
// Load addons. Addons may load worlds, so they must go before islands are loaded.
addonsManager = new AddonsManager(instance);
addonsManager.loadAddons();
// Enable addons
addonsManager.enableAddons();
// Load addons. Addons may load worlds, so they must go before islands are loaded.
addonsManager = new AddonsManager(instance);
addonsManager.loadAddons();
// Enable addons
addonsManager.enableAddons();
getServer().getScheduler().runTask(instance, () -> {
// Register Listeners
registerListeners();
getServer().getScheduler().runTask(instance, () -> {
// Register Listeners
registerListeners();
// Load islands from database - need to wait until all the worlds are loaded
islandsManager.load();
// Save islands & players data asynchronously every X minutes
instance.getServer().getScheduler().runTaskTimer(instance, () -> {
playersManager.save(true);
islandsManager.save(true);
}, getSettings().getDatabaseBackupPeriod() * 20 * 60L, getSettings().getDatabaseBackupPeriod() * 20 * 60L);
isLoaded = true;
flagsManager.registerListeners();
instance.log("#############################################");
instance.log(instance.getDescription().getFullName() + " has been fully enabled.");
instance.log("It took: " + (System.currentTimeMillis() - startMillis + "ms"));
instance.log("Thanks for using our plugin !");
instance.log("- Tastybento and Poslovitch, 2017-2018");
instance.log("#############################################");
// Fire plugin ready event
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
// Load islands from database - need to wait until all the worlds are loaded
islandsManager.load();
// Save islands & players data asynchronously every X minutes
instance.getServer().getScheduler().runTaskTimer(instance, () -> {
playersManager.save(true);
islandsManager.save(true);
}, getSettings().getDatabaseBackupPeriod() * 20 * 60L, getSettings().getDatabaseBackupPeriod() * 20 * 60L);
isLoaded = true;
flagsManager.registerListeners();
instance.log("#############################################");
instance.log(instance.getDescription().getFullName() + " has been fully enabled.");
instance.log("It took: " + (System.currentTimeMillis() - startMillis + "ms"));
instance.log("Thanks for using our plugin !");
instance.log("- Tastybento and Poslovitch, 2017-2018");
instance.log("#############################################");
// Fire plugin ready event
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
});
});
// });
}
/**

View File

@ -105,7 +105,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @param aliases - aliases
*/
public CompositeCommand(Addon addon, String label, String... aliases) {
super(label);
super(label, "", "", Arrays.asList(aliases));
this.addon = addon;
this.topLabel = label;
this.plugin = BentoBox.getInstance();
@ -144,7 +144,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @param aliases - aliases for this subcommand
*/
public CompositeCommand(CompositeCommand parent, String label, String... aliases) {
super(label);
super(label, "", "", Arrays.asList(aliases));
this.topLabel = parent.getTopLabel();
this.plugin = BentoBox.getInstance();
this.parent = parent;
@ -478,6 +478,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
@Override
public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) {
Bukkit.getLogger().info("DEBUG tab complete called");
List<String> options = new ArrayList<>();
// Get command object based on args entered so far
CompositeCommand cmd = getCommandFromArgs(args);

View File

@ -16,6 +16,7 @@ public class CommandsManager {
public void registerCommand(CompositeCommand command) {
commands.put(command.getLabel(), command);
// Use reflection to obtain the commandMap method in Bukkit's server. It used to be visible, but isn't anymore.
try{
Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
commandMapField.setAccessible(true);