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.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; 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.BSBConfig;
import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent; import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
@ -64,6 +65,7 @@ public class BentoBox extends JavaPlugin {
@Override @Override
public void onEnable(){ public void onEnable(){
// Not loaded // Not loaded
isLoaded = false; isLoaded = false;
// Store the current millis time so we can tell how many ms it took for BSB to fully load. // 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 // Save the default config from config.yml
saveDefaultConfig(); saveDefaultConfig();
setInstance(this); setInstance(this);
// Load Flags // Load Flags
flagsManager = new FlagsManager(instance); flagsManager = new FlagsManager(instance);
@ -99,51 +100,56 @@ public class BentoBox extends JavaPlugin {
// Set up command manager // Set up command manager
commandsManager = new CommandsManager(); 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. // 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 // 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. // at this point. Therefore, the 1 tick scheduler is required.
getServer().getScheduler().runTask(this, () -> { //getServer().getScheduler().runTask(this, () -> {
// Create the world if it does not exist // Create the world if it does not exist
islandWorldManager = new IslandWorldManager(instance); islandWorldManager = new IslandWorldManager(instance);
// Load schems manager // Load schems manager
schemsManager = new SchemsManager(instance); schemsManager = new SchemsManager(instance);
// Locales manager must be loaded before addons // Locales manager must be loaded before addons
localesManager = new LocalesManager(instance); localesManager = new LocalesManager(instance);
PlaceholderHandler.register(instance); PlaceholderHandler.register(instance);
// Load addons. Addons may load worlds, so they must go before islands are loaded. // Load addons. Addons may load worlds, so they must go before islands are loaded.
addonsManager = new AddonsManager(instance); addonsManager = new AddonsManager(instance);
addonsManager.loadAddons(); addonsManager.loadAddons();
// Enable addons // Enable addons
addonsManager.enableAddons(); addonsManager.enableAddons();
getServer().getScheduler().runTask(instance, () -> { getServer().getScheduler().runTask(instance, () -> {
// Register Listeners // Register Listeners
registerListeners(); 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 * @param aliases - aliases
*/ */
public CompositeCommand(Addon addon, String label, String... aliases) { public CompositeCommand(Addon addon, String label, String... aliases) {
super(label); super(label, "", "", Arrays.asList(aliases));
this.addon = addon; this.addon = addon;
this.topLabel = label; this.topLabel = label;
this.plugin = BentoBox.getInstance(); this.plugin = BentoBox.getInstance();
@ -144,7 +144,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* @param aliases - aliases for this subcommand * @param aliases - aliases for this subcommand
*/ */
public CompositeCommand(CompositeCommand parent, String label, String... aliases) { public CompositeCommand(CompositeCommand parent, String label, String... aliases) {
super(label); super(label, "", "", Arrays.asList(aliases));
this.topLabel = parent.getTopLabel(); this.topLabel = parent.getTopLabel();
this.plugin = BentoBox.getInstance(); this.plugin = BentoBox.getInstance();
this.parent = parent; this.parent = parent;
@ -478,6 +478,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
@Override @Override
public List<String> tabComplete(final CommandSender sender, final String alias, final String[] args) { 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<>(); List<String> options = new ArrayList<>();
// Get command object based on args entered so far // Get command object based on args entered so far
CompositeCommand cmd = getCommandFromArgs(args); CompositeCommand cmd = getCommandFromArgs(args);

View File

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