bentobox/src/main/java/world/bentobox/bentobox/api/configuration/WorldSettings.java

656 lines
19 KiB
Java
Raw Normal View History

package world.bentobox.bentobox.api.configuration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.entity.EntityType;
import org.eclipse.jdt.annotation.NonNull;
2 0 0 multi island (#2185) * Multi world WIP - stashing * Initial work on supporting multiple islands per player The default allowed number is 5 for now, but will be set to 1 by default. Lots more work to do on this! * More work on multi island. Fixed tests so clean compile. * Remove unused imports * Updated island go and homes command to multi island Updated tests. * Do not reload addons anymore. * Add island name when entering or leaving own island * Remove unused import * Adds island names to /island go command. * Enables more homes to be set if player has more than one island * Switch to using a set for islands and explicit primary boolean in Island * WIP * Fix bugs with the go command. * Be able to delete multiple islands, e.g. when joining a team This is not fully tested. * Do not remove all islands when a player does reset. Players can reset just the island they are on. * More fixes for go command * Fix tests * Fix @NonNull annotation * Fix home syntax listing reference for IslandDeleteHome * Fixed deletehome for multiple islands. * Fix /island command teleport to current island default home. * Remove deprecated code. * Fix tag for concurrent island setting in config.yml * Improve error when trying to make additional islands over limit * Update config.yml * Correctly assign invites for islands. * Switch to canExecute API in prep for multi-island handling * Prevent players from obtaining more concurrent islands by owner transfer * Handle leaving and disbanding of teams * Fix tests * Fix minor bugs or code smells. * Restore the quarantine code from deprecation. This code can stay. It checks if islands can load, and if not puts them in a trash. It does no harm. * Remove unneeded eq()'s * Fix tests
2023-09-17 00:55:52 +02:00
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.lists.Flags;
/**
2019-01-02 13:45:21 +01:00
* Contains world-specific settings that must be provided by the {@link world.bentobox.bentobox.api.addons.GameModeAddon} in order to register its Worlds.
* <br/>
* Depending on your implementation, you may need to add setters.
* @author tastybento
*/
Database transition (#662) - JSON is now the default database type - JSON database files are now pretty-printed - It is now possible to migrate from a database type to another through the use of a command and specific transition database types - It is recommended to move from YAML to JSON. = Commits breakdown = * Proposal to make JSON the default database and retire YAML. * Make JSON file format easier to read. * Fix tests. * Adds a hybrid Yaml2Json database type. This database always tries to use JSON if it is available. If a YAML file is found, it will be loaded and replaced with a JSON file. * Move to generic database transition code * Better comments * Adds transitional database options so admins can choose. Adds Yaml2MySQL option and changes config.yml to add instructions. * Enables full database migration between databases. Adds /bbox migrate command. Adds a number of transition databases. DB starts transition when the server boots up and will migrate organically. The admin can force an immediate update using the bbox migrate command. This operation requires an API breaking change: Addons that use the Config API must now implement ConfigObject in their config class instead of DataObject. This is to differentiate YAML config classes from YAML database classes. If a class is already implements WorldSettings (GameModeAddons), then no change is required because WorldSettings implements ConfigObject now. If an old addon is used that does not implement ConfigObject, BentoBox will not load. * Added null check to YAML deletion * Removed the 2YAML transition dbs because YAML is deprecated. YAML does not support some data structures so conversion could corrupt data. * Fixed some javadoc and added missing DatabaseType#JSON2MARIADB * Renamed package database/transitiondb to database/transition
2019-05-08 21:15:22 +02:00
public interface WorldSettings extends ConfigObject {
/**
* Get the default game mode for this game world, e.g. SURVIVAL
* @return game mode
*/
GameMode getDefaultGameMode();
/**
* @return default rank settings for new islands
2023-01-01 18:25:09 +01:00
* @deprecated Map of Flag, Integer does not allow to load other plugin/addon flags.
* It cannot be replaced with Map of String, Integer due to compatibility issues.
* @see WorldSettings#getDefaultIslandFlagNames()
2023-01-01 18:25:09 +01:00
* @since 1.21.0
*/
@Deprecated(since="1.21.0", forRemoval=true)
Map<Flag, Integer> getDefaultIslandFlags();
/**
* Return map of flags ID's linked to default rank for new island.
* This is necessary so users could specify any flag names in settings file from other plugins and addons.
* Otherwise, Flag reader would mark flag as invalid and remove it.
* Default implementation is compatibility layer so GameModes that are not upgraded still works.
* @since 1.21
* @return default rank settings for new islands.
*/
default Map<String, Integer> getDefaultIslandFlagNames()
{
Map<String, Integer> flags = new HashMap<>();
this.getDefaultIslandFlags().forEach((key, value) -> flags.put(key.getID(), value));
return flags;
}
/**
* @return default settings for new
2023-01-01 18:25:09 +01:00
* @deprecated Map of Flag, Integer does not allow to load other plugin/addon flags.
* It cannot be replaced with Map of String, Integer due to compatibility issues.
* @see WorldSettings#getDefaultIslandSettingNames()
2023-01-01 18:25:09 +01:00
* @since 1.21.0
*/
@Deprecated(since="1.21.0", forRemoval=true)
Map<Flag, Integer> getDefaultIslandSettings();
/**
* Return map of flags ID's linked to default settings for new island.
* This is necessary so users could specify any flag names in settings file from other plugins and addons.
* Otherwise, Flag reader would mark flag as invalid and remove it.
* Default implementation is compatibility layer so GameModes that are not upgraded still works.
2023-01-01 18:25:09 +01:00
* @since 1.21.0
* @return default settings for new islands.
*/
default Map<String, Integer> getDefaultIslandSettingNames()
{
Map<String, Integer> flags = new HashMap<>();
this.getDefaultIslandSettings().forEach((key, value) -> flags.put(key.getID(), value));
return flags;
}
/**
* Get the world difficulty
* @return difficulty
*/
Difficulty getDifficulty();
/**
* Set the world difficulty
2018-08-05 06:50:10 +02:00
* @param difficulty - difficulty
*/
void setDifficulty(Difficulty difficulty);
/**
* @return the friendly name of the world. Used in player commands
*/
String getFriendlyName();
/**
* @return the islandDistance
*/
2018-06-01 03:52:05 +02:00
int getIslandDistance();
/**
* @return the islandHeight
*/
2018-06-01 03:52:05 +02:00
int getIslandHeight();
/**
* @return the islandProtectionRange
*/
2018-06-01 03:52:05 +02:00
int getIslandProtectionRange();
/**
* @return the islandStartX
*/
2018-06-01 03:52:05 +02:00
int getIslandStartX();
/**
* @return the islandStartZ
*/
2018-06-01 03:52:05 +02:00
int getIslandStartZ();
/**
* @return the islandXOffset
*/
2018-06-01 03:52:05 +02:00
int getIslandXOffset();
/**
* @return the islandZOffset
*/
2018-06-01 03:52:05 +02:00
int getIslandZOffset();
/**
* @return Invincible Visitor setting list
*/
List<String> getIvSettings();
/**
* @return the max homes
*/
int getMaxHomes();
/**
* 0 or -1 is unlimited. It will block island creation if the island count for the world is higher than this.
* @return the maxIslands
*/
int getMaxIslands();
/**
* @return the max team size for this world
*/
int getMaxTeamSize();
/**
* @return the max coop size for this world
* @since 1.13.0
*/
default int getMaxCoopSize() {
return 4;
}
/**
* @return the max trust size for this world
* @since 1.13.0
*/
default int getMaxTrustSize() {
return 4;
}
/**
* @return the netherSpawnRadius
*/
int getNetherSpawnRadius();
/**
* @return the permission prefix
*/
String getPermissionPrefix();
/**
* Get the set of entity types that should not be removed in this world when a player teleports to their island
* @return set of entity types
*/
Set<EntityType> getRemoveMobsWhitelist();
/**
* @return the seaHeight
*/
int getSeaHeight();
/**
* @return hidden flag list
*/
List<String> getHiddenFlags();
/**
* @return the visitorBannedCommands
*/
List<String> getVisitorBannedCommands();
/**
* Optional list of commands that are banned when falling. Not applicable to all game modes so defaults to empty.
* @return the fallingBannedCommands
* @since 1.8.0
*/
default List<String> getFallingBannedCommands() {
return Collections.emptyList();
}
/**
* Get world flags
* @return Map of world flags
*/
Map<String, Boolean> getWorldFlags();
/**
* @return the worldName
*/
String getWorldName();
/**
* @return the dragonSpawn
*/
boolean isDragonSpawn();
/**
* @return the endGenerate
*/
boolean isEndGenerate();
/**
* @return the endIslands
*/
boolean isEndIslands();
/**
* @return the netherGenerate
*/
boolean isNetherGenerate();
/**
* @return the netherIslands
*/
boolean isNetherIslands();
/**
* @return the onJoinResetEnderChest
*/
boolean isOnJoinResetEnderChest();
/**
* @return the onJoinResetInventory
*/
boolean isOnJoinResetInventory();
/**
* @return the onJoinResetMoney
*/
boolean isOnJoinResetMoney();
/**
* Whether the player's health should be reset upon him joining an island or creating it.
* @return the onJoinResetHealth
* @since 1.8.0
*/
boolean isOnJoinResetHealth();
/**
* Whether the player's hunger should be reset upon him joining an island or creating it.
* @return the onJoinResetHunger
* @since 1.8.0
*/
boolean isOnJoinResetHunger();
/**
* Whether the player's XP should be reset upon him joining an island or creating it.
* @return the onJoinResetXP
* @since 1.8.0
*/
boolean isOnJoinResetXP();
/**
* Returns a list of commands that should be executed when the player joins an island or creates one.<br/>
* These commands are executed by the console, unless otherwise stated using the {@code [SUDO]} prefix, in which case they are executed by the player.<br/>
* <br/>
* Available placeholders for the commands are the following:
* <ul>
* <li>{@code [player]}: name of the player</li>
* <li>{@code [owner]}: name of the owner of the island. When joining a team, this will be the team leader's name. When
* creating an island, it is the name of the player</li>
* </ul>
* <br/>
* Here are some examples of valid commands to execute:
* <ul>
* <li>{@code "[SUDO] bbox version"}</li>
* <li>{@code "bsbadmin deaths set [player] 0"}</li>
* </ul>
* @return a list of commands.
* @since 1.8.0
* @see #getOnLeaveCommands()
*/
@NonNull
List<String> getOnJoinCommands();
/**
* @return the onLeaveResetEnderChest
*/
boolean isOnLeaveResetEnderChest();
/**
* @return the onLeaveResetInventory
*/
boolean isOnLeaveResetInventory();
/**
* @return the onLeaveResetMoney
*/
boolean isOnLeaveResetMoney();
/**
* Whether the player's health should be reset upon him leaving his island or resetting it.
* @return the onLeaveResetHealth
* @since 1.8.0
*/
boolean isOnLeaveResetHealth();
/**
* Whether the player's hunger should be reset upon him leaving his island or resetting it.
* @return the onLeaveResetHunger
* @since 1.8.0
*/
boolean isOnLeaveResetHunger();
/**
* Whether the player's XP should be reset upon him leaving his island or resetting it.
* @return the onLeaveResetXP
* @since 1.8.0
*/
boolean isOnLeaveResetXP();
/**
* Returns a list of commands that should be executed when the player leaves an island, resets his island or gets kicked from it.<br/>
* These commands are executed by the console, unless otherwise stated using the {@code [SUDO]} prefix, in which case they are executed by the player.<br/>
* <br/>
* Available placeholders for the commands are the following:
* <ul>
* <li>{@code [player]}: name of the player</li>
* <li>{@code [owner]}: name of the owner of the island. When joining a team, this will be the team leader's name. When
* creating an island, it is the name of the player</li>
* </ul>
* <br/>
* Here are some examples of valid commands to execute:
* <ul>
* <li>{@code "[SUDO] bbox version"}</li>
* <li>{@code "bsbadmin deaths set [player] 0"}</li>
* </ul>
* <br/>
* Note that player-executed commands might not work, as these commands can be run with said player being offline.
* @return a list of commands.
* @since 1.8.0
* @see #getOnJoinCommands()
*/
@NonNull
List<String> getOnLeaveCommands();
/**
* Returns a list of commands that should be executed when the player respawns after death if {@link Flags#ISLAND_RESPAWN} is true.<br/>
* These commands are executed by the console, unless otherwise stated using the {@code [SUDO]} prefix, in which case they are executed by the player.<br/>
* <br/>
* Available placeholders for the commands are the following:
* <ul>
* <li>{@code [player]}: name of the player</li>
* <li>{@code [owner]}: name of the owner of the island. When joining a team, this will be the team leader's name. When
* creating an island, it is the name of the player</li>
* </ul>
* <br/>
* Here are some examples of valid commands to execute:
* <ul>
* <li>{@code "[SUDO] bbox version"}</li>
* <li>{@code "bsbadmin deaths set [player] 0"}</li>
* </ul>
* <br/>
* Note that player-executed commands might not work, as these commands can be run with said player being offline.
* @return a list of commands.
* @since 1.14.0
* @see #getOnJoinCommands()
*/
@NonNull
default List<String> getOnRespawnCommands() {
return Collections.emptyList();
}
/**
* @return true if the default world generator should not operate in this world
*/
boolean isUseOwnGenerator();
/**
* @return true if water is not safe in this world, e.g, should not be a home location
*/
boolean isWaterUnsafe();
/**
* @return list of entity types that should not exit the island limits
*/
List<String> getGeoLimitSettings();
2018-07-25 16:04:40 +02:00
/**
* Get list of entities that should not spawn in this game mode
* @return list of entities that should NOT spawn
* @since 1.12.0
*/
default List<String> getMobLimitSettings() {
return new ArrayList<>();
}
2018-07-25 16:04:40 +02:00
/**
* @return reset limit for world
*/
int getResetLimit();
/**
* Get the island reset time stamp. Any player who last logged in before this time will have resets zeroed
*/
long getResetEpoch();
/**
* Set the island reset time stamp. Any player who last logged in before this time will have resets zeroed
*/
void setResetEpoch(long timestamp);
2018-07-29 22:21:46 +02:00
/**
* @return true if the death count should be reset when joining a team in this world
*/
boolean isTeamJoinDeathReset();
/**
* @return max number of deaths for this world
*/
int getDeathsMax();
2018-12-28 02:25:14 +01:00
/**
* @return whether deaths should be counted.
*/
boolean isDeathsCounted();
/**
* @return true if deaths in the world are reset when the player has a new island
* @since 1.6.0
*/
boolean isDeathsResetOnNewIsland();
/**
* @return whether a player can set their home in the Nether or not.
*/
boolean isAllowSetHomeInNether();
/**
* @return whether a player can set their home in the End or not.
*/
boolean isAllowSetHomeInTheEnd();
/**
* @return whether a confirmation is required when a player tries to set their home in the Nether.
*/
boolean isRequireConfirmationToSetHomeInNether();
/**
* @return whether a confirmation is required when a player tries to set their home in the End.
*/
boolean isRequireConfirmationToSetHomeInTheEnd();
/**
* Gets ban limit for this world.
* Once exceeded, island members won't be able to ban any more players from their island.
* Set it to -1 for unlimited.
* <br/>
* Permission to increase the limit: {@code (permissionprefix).ban.maxlimit.(value)}
* @return the ban limit for this world.
*/
int getBanLimit();
/**
* @return whether leavers should lose a reset or not
* @since 1.5.0
*/
boolean isLeaversLoseReset();
/**
* @return whether players keep their inventory when they are kicked
* @since 1.5.0
*/
boolean isKickedKeepInventory();
/* Create island on first login */
/**
*
2019-12-01 18:03:22 +01:00
* @return true if island should be created on first login
* @since 1.9.0
*/
boolean isCreateIslandOnFirstLoginEnabled();
/**
*
2019-12-01 18:03:22 +01:00
* @return the island creation delay after login
* @since 1.9.0
*/
int getCreateIslandOnFirstLoginDelay();
/**
*
2019-12-01 18:03:22 +01:00
* @return if island creation should abort on logout
* @since 1.9.0
*/
boolean isCreateIslandOnFirstLoginAbortOnLogout();
/**
* Check if nether or end islands should be pasted on teleporting
* @return true if missing nether or end islands should be pasted
* @since 1.10.0
*/
default boolean isPasteMissingIslands() {
// Note that glitches can enable bedrock to be removed in ways that will not generate events.
return true;
}
/**
* Toggles whether the player should be teleported on his island after it got created.
* <br/>
* If set to {@code true}, the player will be teleported right away.
* <br/>
* If set to {@code false}, the player will remain where he is and a message will be sent inviting him to teleport to his island.
* <br/><br/>
* This does not apply to any other occurrences such as island reset, or island join.
* <br/><br/>
* Default value: {@code true} (to retain backward compatibility).
* @return {@code true} if the player should be teleported to his island, {@code false} otherwise.
* @since 1.10.0
*/
default boolean isTeleportPlayerToIslandUponIslandCreation() {
return true;
}
/**
* Returns all aliases for main admin command.
* It is assumed that all aliases are split with whitespace between them.
* String cannot be empty.
2023-08-01 18:43:47 +02:00
* The first command listed is the "label" in the API, and after that are the aliases
* Default value: {@code getFriendlyName() + "admin"} (to retain backward compatibility).
* @return String value
* @since 1.13.0
*/
default String getAdminCommandAliases()
{
return this.getFriendlyName().toLowerCase(Locale.ENGLISH) + "admin";
}
/**
* Returns all aliases for main player command.
* It is assumed that all aliases are split with whitespace between them.
* String cannot be empty.
2023-08-01 18:43:47 +02:00
* The first command listed is the "label" in the API, and after that are the aliases
* Default value: {@code getFriendlyName()} (to retain backward compatibility).
* @return String value
* @since 1.13.0
*/
default String getPlayerCommandAliases()
{
return this.getFriendlyName().toLowerCase(Locale.ENGLISH);
}
/**
* Returns sub-command for users when they execute main user command and they have an
* island.
* If defined sub-command does not exist in accessible user command list, then it will
* still call "go" sub-command.
* Default value: {@code "go"} (to retain backward compatibility)
* @return name of default sub-command for main command if user does have an island.
* @since 1.13.0
*/
default String getDefaultPlayerAction()
{
return "go";
}
/**
* Returns default sub-command for users when they execute main user command and they
* do not have an island.
* If defined sub-command does not exist in accessible user command list, then it will
* still call "create" sub-command.
* Default value: {@code "create"} (to retain backward compatibility)
* @return name of default sub-command for main command if user does not have an island.
* @since 1.13.0
*/
default String getDefaultNewPlayerAction()
{
return "create";
}
/**
* Make a nether portal when teleporting to the nether through an overworld portal
* @return true if a portal should be made
* @since 1.16.0
*/
default boolean isMakeNetherPortals() {
return false;
}
/**
* Make an end portal when teleporting to the end through an end portal
* @return true if a portal should be made
* @since 1.16.0
*/
default boolean isMakeEndPortals() {
return false;
}
2023-01-01 18:25:09 +01:00
/**
* 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
* then the island is marked as being used. It is mainly for migration handling from worlds that
* do not register island properly. It is incompatible with CaveBlock or other gamemodes that will
* have blocks there.
* @return true if a check for blocks should happen
* @since 1.16.0
*/
default boolean isCheckForBlocks() {
return true;
}
2 0 0 multi island (#2185) * Multi world WIP - stashing * Initial work on supporting multiple islands per player The default allowed number is 5 for now, but will be set to 1 by default. Lots more work to do on this! * More work on multi island. Fixed tests so clean compile. * Remove unused imports * Updated island go and homes command to multi island Updated tests. * Do not reload addons anymore. * Add island name when entering or leaving own island * Remove unused import * Adds island names to /island go command. * Enables more homes to be set if player has more than one island * Switch to using a set for islands and explicit primary boolean in Island * WIP * Fix bugs with the go command. * Be able to delete multiple islands, e.g. when joining a team This is not fully tested. * Do not remove all islands when a player does reset. Players can reset just the island they are on. * More fixes for go command * Fix tests * Fix @NonNull annotation * Fix home syntax listing reference for IslandDeleteHome * Fixed deletehome for multiple islands. * Fix /island command teleport to current island default home. * Remove deprecated code. * Fix tag for concurrent island setting in config.yml * Improve error when trying to make additional islands over limit * Update config.yml * Correctly assign invites for islands. * Switch to canExecute API in prep for multi-island handling * Prevent players from obtaining more concurrent islands by owner transfer * Handle leaving and disbanding of teams * Fix tests * Fix minor bugs or code smells. * Restore the quarantine code from deprecation. This code can stay. It checks if islands can load, and if not puts them in a trash. It does no harm. * Remove unneeded eq()'s * Fix tests
2023-09-17 00:55:52 +02:00
/**
* Get the number of concurrent islands a player can have in the world
* @return 1 by default
* @since 2.0.0
*/
default int getConcurrentIslands() {
return BentoBox.getInstance().getSettings().getIslandNumber();
}
/**
* Remove islands when players join a team and not allow players to have other islands if they are in a team.
* @return true or false
*/
2024-03-30 04:26:07 +01:00
default boolean isDisallowTeamMemberIslands() {
return true;
}
}