Provided better documentation around when flags should be declared.

Protects against null worlds.

Related to https://github.com/BentoBoxWorld/AcidIsland/issues/53
This commit is contained in:
tastybento 2019-07-18 18:45:59 -07:00
parent 6bbe9a3f2a
commit 38248bad29
2 changed files with 8 additions and 2 deletions

View File

@ -39,7 +39,8 @@ public abstract class GameModeAddon extends Addon {
/**
* Make the worlds for this GameMode in this method. BentoBox will call it
* after onLoad() and before onEnable().
* after onLoad() and before onEnable(). Do not register flags in this method.
* They ,ust be registered afterwards in onEnable()
* {@link #islandWorld} must be created and assigned,
* {@link #netherWorld} and {@link #endWorld} are optional and may be null.
*/

View File

@ -155,11 +155,16 @@ public class Flag implements Comparable<Flag> {
}
/**
* Set the status of this flag for locations outside of island spaces for a specific world
* Set the status of this flag for locations outside of island spaces for a specific world.
* World must exist and be registered before this method can be called.
* @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 ) {
BentoBox.getInstance().logError("Attempt to set default world setting for unregistered world. Register flags in onEnable.");
return;
}
ws.getWorldFlags().put(getID(), defaultSetting);
// Save config file
BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings);