mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 11:15:24 +01:00
API: Require getWorldSettings to be a game mode world
This commit is contained in:
parent
cfad9879a5
commit
b5d9d2e52e
@ -1,7 +1,6 @@
|
||||
package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
@ -53,7 +52,7 @@ public class IslandSethomeCommand extends ConfirmableCommand {
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
String number = String.join(" ", args);
|
||||
WorldSettings ws = Objects.requireNonNull(getIWM().getWorldSettings(user.getWorld()));
|
||||
WorldSettings ws = getIWM().getWorldSettings(user.getWorld());
|
||||
// Check if the player is in the Nether
|
||||
if (getIWM().isNether(user.getWorld())) {
|
||||
// Check if he is (not) allowed to set his home here
|
||||
|
@ -175,8 +175,10 @@ public class Flag implements Comparable<Flag> {
|
||||
* If world is not a game world, then the result will always be false!
|
||||
*/
|
||||
public boolean isSetForWorld(World world) {
|
||||
if (!BentoBox.getInstance().getIWM().inWorld(world)) {
|
||||
return false;
|
||||
}
|
||||
WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world);
|
||||
if (ws == null) return false;
|
||||
if (type.equals(Type.WORLD_SETTING) || type.equals(Type.PROTECTION)) {
|
||||
if (!ws.getWorldFlags().containsKey(getID())) {
|
||||
ws.getWorldFlags().put(getID(), setting);
|
||||
@ -234,12 +236,11 @@ public class Flag implements Comparable<Flag> {
|
||||
* @param defaultSetting - true means it is allowed. false means it is not allowed
|
||||
*/
|
||||
public void setDefaultSetting(World world, boolean defaultSetting) {
|
||||
WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world);
|
||||
if (ws == null ) {
|
||||
if (!BentoBox.getInstance().getIWM().inWorld(world)) {
|
||||
BentoBox.getInstance().logError("Attempt to set default world setting for unregistered world. Register flags in onEnable.");
|
||||
return;
|
||||
}
|
||||
ws.getWorldFlags().put(getID(), defaultSetting);
|
||||
BentoBox.getInstance().getIWM().getWorldSettings(world).getWorldFlags().put(getID(), defaultSetting);
|
||||
// Save config file
|
||||
BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class MobSpawnListener extends FlagListener {
|
||||
case RAID:
|
||||
case REINFORCEMENTS:
|
||||
case SILVERFISH_BLOCK:
|
||||
//case SLIME_SPLIT: messes with slimes from spawners, slime must have previously existed to create another
|
||||
//case SLIME_SPLIT: messes with slimes from spawners, slime must have previously existed to create another
|
||||
case TRAP:
|
||||
case VILLAGE_DEFENSE:
|
||||
case VILLAGE_INVASION:
|
||||
|
@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@ -199,11 +200,11 @@ public class IslandWorldManager {
|
||||
* Get the settings for this world or sub-worlds (nether, end)
|
||||
*
|
||||
* @param world world
|
||||
* @return world settings, or null if world is unknown
|
||||
* @return world settings
|
||||
*/
|
||||
@Nullable
|
||||
@NonNull
|
||||
public WorldSettings getWorldSettings(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings() : null;
|
||||
return Objects.requireNonNull(gameModes.get(world), "Attempt to get WorldSettings for non-game world " + world.getName()).getWorldSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -725,7 +726,7 @@ public class IslandWorldManager {
|
||||
public boolean isUseOwnGenerator(@NonNull World world) {
|
||||
return gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isUseOwnGenerator();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check for blocks when searching for a new island. This is a safety net check that does a look
|
||||
* around the new island location (3x3x3 block check). If any non-air or non-water blocks are found
|
||||
|
@ -86,7 +86,7 @@ public class FlagTest {
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
Optional<GameModeAddon> opGma = Optional.of(gma );
|
||||
when(iwm.getAddon(any())).thenReturn(opGma);
|
||||
|
||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||
worldFlags = new HashMap<>();
|
||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||
|
||||
@ -223,7 +223,7 @@ public class FlagTest {
|
||||
*/
|
||||
@Test
|
||||
public void testSetDefaultSettingWorldBooleanNullWorldSettings() {
|
||||
when(iwm.getWorldSettings(any())).thenReturn(null);
|
||||
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
||||
f.setDefaultSetting(world, true);
|
||||
verify(plugin).logError("Attempt to set default world setting for unregistered world. Register flags in onEnable.");
|
||||
}
|
||||
|
@ -104,10 +104,14 @@ public class MobSpawnListenerTest {
|
||||
when(zombie.getLocation()).thenReturn(location);
|
||||
when(slime.getLocation()).thenReturn(location);
|
||||
when(cow.getLocation()).thenReturn(location);
|
||||
when(zombie.getWorld()).thenReturn(world);
|
||||
when(slime.getWorld()).thenReturn(world);
|
||||
when(cow.getWorld()).thenReturn(world);
|
||||
|
||||
// Worlds
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Util class
|
||||
|
@ -211,14 +211,6 @@ public class IslandWorldManagerTest {
|
||||
assertEquals(ws, iwm.getWorldSettings(world));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.IslandWorldManager#getWorldSettings(org.bukkit.World)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetWorldSettingsNull() {
|
||||
assertNull(iwm.getWorldSettings(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.IslandWorldManager#getOverWorld(java.lang.String)}.
|
||||
*/
|
||||
|
@ -191,7 +191,6 @@ public class IslandsManagerTest {
|
||||
|
||||
// Player's manager
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
when(pm.getHomeLocations(any(), any())).thenReturn(Collections.emptyMap());
|
||||
|
||||
// Scheduler
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
|
Loading…
Reference in New Issue
Block a user