Merge pull request #2153 from BentoBoxWorld/delete_manager_refactor

Put island deletion under one class manager
This commit is contained in:
tastybento 2023-07-01 13:18:28 -07:00 committed by GitHub
commit 6d3349a0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 21 deletions

View File

@ -39,7 +39,6 @@ import world.bentobox.bentobox.managers.BlueprintsManager;
import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.FlagsManager;
import world.bentobox.bentobox.managers.HooksManager;
import world.bentobox.bentobox.managers.IslandChunkDeletionManager;
import world.bentobox.bentobox.managers.IslandDeletionManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
@ -74,7 +73,6 @@ public class BentoBox extends JavaPlugin implements Listener {
private HooksManager hooksManager;
private PlaceholdersManager placeholdersManager;
private IslandDeletionManager islandDeletionManager;
private IslandChunkDeletionManager islandChunkDeletionManager;
private WebManager webManager;
// Settings
@ -306,7 +304,6 @@ public class BentoBox extends JavaPlugin implements Listener {
// MV unregister
manager.registerEvents(this, this);
// Island Delete Manager
islandChunkDeletionManager = new IslandChunkDeletionManager(this);
islandDeletionManager = new IslandDeletionManager(this);
manager.registerEvents(islandDeletionManager, this);
}
@ -545,13 +542,6 @@ public class BentoBox extends JavaPlugin implements Listener {
return islandDeletionManager;
}
/**
* @return the islandChunkDeletionManager
*/
public IslandChunkDeletionManager getIslandChunkDeletionManager() {
return islandChunkDeletionManager;
}
/**
* @return an optional of the Bstats instance
* @since 1.1

View File

@ -31,11 +31,13 @@ public class IslandDeletionManager implements Listener {
*/
private final Database<IslandDeletion> handler;
private final Set<Location> inDeletion;
private final IslandChunkDeletionManager islandChunkDeletionManager;
public IslandDeletionManager(BentoBox plugin) {
this.plugin = plugin;
handler = new Database<>(plugin, IslandDeletion.class);
inDeletion = new HashSet<>();
islandChunkDeletionManager = new IslandChunkDeletionManager(plugin);
}
/**
@ -56,7 +58,7 @@ public class IslandDeletionManager implements Listener {
} else {
plugin.log("Resuming deletion of island at " + di.getLocation().getWorld().getName() + " " + Util.xyz(di.getLocation().toVector()));
inDeletion.add(di.getLocation());
plugin.getIslandChunkDeletionManager().add(di);
this.islandChunkDeletionManager.add(di);
}
});
}
@ -86,4 +88,12 @@ public class IslandDeletionManager implements Listener {
public boolean inDeletion(Location location) {
return inDeletion.contains(location);
}
/**
* @return the islandChunkDeletionManager
*/
public IslandChunkDeletionManager getIslandChunkDeletionManager() {
return islandChunkDeletionManager;
}
}

View File

@ -343,7 +343,7 @@ public class IslandsManager {
// Remove players from island
removePlayersFromIsland(island);
// Remove blocks from world
plugin.getIslandChunkDeletionManager().add(new IslandDeletion(island));
plugin.getIslandDeletionManager().getIslandChunkDeletionManager().add(new IslandDeletion(island));
}
}

View File

@ -67,9 +67,6 @@ public class IslandDeletionManagerTest {
private BukkitScheduler scheduler;
@Mock
private IslandWorldManager iwm;
@Mock
private IslandChunkDeletionManager chunkDeletionManager;
/**
*/
@ -102,8 +99,6 @@ public class IslandDeletionManagerTest {
// IWM
when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getIslandDistance(any())).thenReturn(64);
// Chunk deletion manager
when(plugin.getIslandChunkDeletionManager()).thenReturn(chunkDeletionManager);
// Island Deletion Manager
idm = new IslandDeletionManager(plugin);

View File

@ -109,6 +109,8 @@ public class IslandsManagerTest extends AbstractCommonSetup {
@Mock
private IslandWorldManager iwm;
@Mock
private IslandDeletionManager deletionManager;
@Mock
private IslandChunkDeletionManager chunkDeletionManager;
@Mock
private IslandCache islandCache;
@ -161,9 +163,6 @@ public class IslandsManagerTest extends AbstractCommonSetup {
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm);
// Chunk deletion manager
when(plugin.getIslandChunkDeletionManager()).thenReturn(chunkDeletionManager);
// Settings
Settings s = mock(Settings.class);
when(plugin.getSettings()).thenReturn(s);
@ -311,7 +310,9 @@ public class IslandsManagerTest extends AbstractCommonSetup {
.getNearbyEntities(any(Location.class), Mockito.anyDouble(), Mockito.anyDouble(), Mockito.anyDouble()))
.thenReturn(collection);
// Deletion Manager
when(deletionManager.getIslandChunkDeletionManager()).thenReturn(chunkDeletionManager);
when(plugin.getIslandDeletionManager()).thenReturn(deletionManager);
// database must be mocked here
db = mock(Database.class);