Skip to content
This repository has been archived by the owner on Jul 2, 2023. It is now read-only.

Commit

Permalink
fix item/commands not available after setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dementisimus committed Jul 16, 2021
1 parent 1c93632 commit bfb06c0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/java/dev/dementisimus/mrs/MapRatingSystem.java
Expand Up @@ -10,6 +10,7 @@
import dev.dementisimus.mrs.api.MapRating;
import dev.dementisimus.mrs.api.RatingType;
import dev.dementisimus.mrs.commands.COMMAND_maprating;
import dev.dementisimus.mrs.listener.SetupDoneListener;
import dev.dementisimus.mrs.listeners.InventoryClickListener;
import dev.dementisimus.mrs.listeners.PlayerInteractListener;
import dev.dementisimus.mrs.listeners.PlayerLanguageListener;
Expand Down Expand Up @@ -51,23 +52,14 @@ public void onEnable() {
private void init() {
this.bukkitCoreAPI = new BukkitCoreAPI(this);
this.coreAPI = this.bukkitCoreAPI.getCoreAPI();
BukkitHelper.registerEvents(this, new Listener[]{new SetUpStateChangeListener(this), new SetUpStatePrintInstructionsListener(this)});
BukkitHelper.registerEvents(this, new Listener[]{new SetupDoneListener(this), new SetUpStateChangeListener(this), new SetUpStatePrintInstructionsListener(this)});
this.coreAPI.prepareInit(new String[]{DefaultSetUpState.LANGUAGE.name(), AdditionalSetUpState.USE_STANDALONE_VERSION.name(), DefaultSetUpState.STORAGE_TYPE.name(), DefaultSetUpState.MONGODB_CONNECTION_STRING.name(), DefaultSetUpState.MONGODB_DATABASE.name(), DefaultSetUpState.MARIADB_HOST.name(), DefaultSetUpState.MARIADB_PORT.name(), DefaultSetUpState.MARIADB_USER.name(), DefaultSetUpState.MARIADB_PASSWORD.name()}, new ResourceBundle[]{getBundle(this.coreAPI.getBaseName(), ENGLISH), getBundle(this.coreAPI.getBaseName(), GERMAN)}, capi -> capi.enableDatabaseUsage(new String[]{MAPRATINGS.value}, new String[]{RATINGROW.value}));
this.coreAPI.init(initialized -> {
this.createMapRatingAPIObject();
MapRatingInitializationQueue.executeCallbackInQueue(mapRating -> {
if(mapRating != null) {
this.mapRating = mapRating;
this.bukkitCoreAPI.addListenersToRegisterOnSetUpDone(new Listener[]{new InventoryClickListener(this), new PlayerLanguageListener(this), new PlayerInteractListener(this)});
this.bukkitCoreAPI.addCommandToRegisterOnSetUpDone("maprating", new COMMAND_maprating(this));
this.bukkitCoreAPI.addCommandToRegisterOnSetUpDone("mr", new COMMAND_maprating(this));
this.bukkitCoreAPI.registerCommandsAndListeners();
}
});
});
}

private void createMapRatingAPIObject() {
public void createMapRatingAPIObject() {
new Config(this.getCoreAPI().getConfigFile()).read(jsonDocument -> {
if(jsonDocument != null) {
boolean useStandaloneVersion = jsonDocument.getBoolean(AdditionalSetUpState.USE_STANDALONE_VERSION.name());
Expand All @@ -93,6 +85,15 @@ private void createMapRatingAPIObject() {
Bukkit.getPluginManager().disablePlugin(this);
}
}
MapRatingInitializationQueue.executeCallbackInQueue(mapRating -> {
if(mapRating != null) {
this.mapRating = mapRating;
this.bukkitCoreAPI.addListenersToRegisterOnSetUpDone(new Listener[]{new InventoryClickListener(this), new PlayerLanguageListener(this), new PlayerInteractListener(this)});
this.bukkitCoreAPI.addCommandToRegisterOnSetUpDone("maprating", new COMMAND_maprating(this));
this.bukkitCoreAPI.addCommandToRegisterOnSetUpDone("mr", new COMMAND_maprating(this));
this.bukkitCoreAPI.registerCommandsAndListeners();
}
});
}
});
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/dev/dementisimus/mrs/listener/SetupDoneListener.java
@@ -0,0 +1,25 @@
package dev.dementisimus.mrs.listener;

import dev.dementisimus.capi.core.events.bukkit.BukkitSetUpDoneEvent;
import dev.dementisimus.mrs.MapRatingSystem;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* Copyright (c) by dementisimus,
* licensed under Attribution-NonCommercial-NoDerivatives 4.0 International
*
* Class SetupDoneListener @ MapRatingSystem
*
* @author dementisimus
* @since 16.07.2021:21:35
*/
public record SetupDoneListener(MapRatingSystem mapRatingSystem) implements Listener {

@EventHandler
public void on(BukkitSetUpDoneEvent event) {
if(event.isDone()) {
this.mapRatingSystem.createMapRatingAPIObject();
}
}

}

0 comments on commit bfb06c0

Please sign in to comment.