mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Fixed protection listeners not being registered to Bukkit
Basically removed the "plugin loaded" limitation.
This commit is contained in:
parent
6108277b3c
commit
3e284b90eb
@ -135,6 +135,7 @@ public class BentoBox extends JavaPlugin {
|
||||
islandsManager.save(true);
|
||||
}, getSettings().getDatabaseBackupPeriod() * 20 * 60L, getSettings().getDatabaseBackupPeriod() * 20 * 60L);
|
||||
|
||||
// Make sure all flag listeners are ready.
|
||||
flagsManager.registerListeners();
|
||||
|
||||
// Load metrics
|
||||
|
@ -53,19 +53,20 @@ public class FlagsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any unregistered listeners - called after the plugin is fully loaded
|
||||
* Register any unregistered listeners.
|
||||
* This helps to make sure each flag listener is correctly loaded.
|
||||
*/
|
||||
public void registerListeners() {
|
||||
registeredListeners.entrySet().stream().filter(e -> !e.getValue()).map(Map.Entry::getKey).forEach(this::registerListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to register a listener if the plugin is loaded
|
||||
* Tries to register a listener
|
||||
* @param l - listener
|
||||
*/
|
||||
private void registerListener(Listener l) {
|
||||
registeredListeners.putIfAbsent(l, false);
|
||||
if (BentoBox.getInstance().isLoaded() && !registeredListeners.get(l)) {
|
||||
if (!registeredListeners.get(l)) {
|
||||
Bukkit.getServer().getPluginManager().registerEvents(l, plugin);
|
||||
registeredListeners.put(l, true);
|
||||
}
|
||||
|
@ -104,20 +104,9 @@ public class FlagsManagerTest {
|
||||
.build())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisteroriginalFlagPluginNotLoaded() {
|
||||
when(plugin.isLoaded()).thenReturn(false);
|
||||
FlagsManager fm = new FlagsManager(plugin);
|
||||
// This should pass
|
||||
Flag originalFlag = new FlagBuilder().id("ORIGINAL").icon(Material.EMERALD_BLOCK).listener(new BreakBlocksListener()).build();
|
||||
assertTrue(fm.registerFlag(originalFlag));
|
||||
// Verify no Bukkit listener registered
|
||||
Mockito.verify(server, Mockito.never()).getPluginManager();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRegisteroriginalFlagPluginLoadedOriginalListener() {
|
||||
public void testRegisterOriginalFlagOriginalListener() {
|
||||
when(plugin.isLoaded()).thenReturn(true);
|
||||
FlagsManager fm = new FlagsManager(plugin);
|
||||
// This should pass
|
||||
|
Loading…
Reference in New Issue
Block a user