2019-01-28 07:27:44 +01:00
|
|
|
package world.bentobox.caveblock;
|
|
|
|
|
|
|
|
|
2019-04-24 16:39:10 +02:00
|
|
|
import org.bukkit.Material;
|
2019-01-28 07:27:44 +01:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.WorldCreator;
|
|
|
|
import org.bukkit.WorldType;
|
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
|
|
|
import org.eclipse.jdt.annotation.NonNull;
|
|
|
|
|
|
|
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
2020-05-01 22:29:02 +02:00
|
|
|
import world.bentobox.bentobox.api.commands.admin.DefaultAdminCommand;
|
|
|
|
import world.bentobox.bentobox.api.commands.island.DefaultPlayerCommand;
|
2019-01-28 07:27:44 +01:00
|
|
|
import world.bentobox.bentobox.api.configuration.Config;
|
|
|
|
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
2019-04-24 16:39:10 +02:00
|
|
|
import world.bentobox.bentobox.api.flags.Flag;
|
2020-05-01 22:29:02 +02:00
|
|
|
import world.bentobox.caveblock.commands.IslandAboutCommand;
|
2019-01-28 07:27:44 +01:00
|
|
|
import world.bentobox.caveblock.generators.ChunkGeneratorWorld;
|
2019-02-03 01:45:35 +01:00
|
|
|
import world.bentobox.caveblock.listeners.CustomHeightLimitations;
|
2019-01-28 07:27:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
public class CaveBlock extends GameModeAddon
|
|
|
|
{
|
2019-08-30 22:08:44 +02:00
|
|
|
|
2019-02-01 21:29:28 +01:00
|
|
|
/**
|
|
|
|
* Executes code when loading the addon. This is called before {@link #onEnable()}. This should preferably
|
2021-12-21 18:00:28 +01:00
|
|
|
* be used to set up configuration and worlds.
|
2019-02-01 21:29:28 +01:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onLoad()
|
|
|
|
{
|
|
|
|
super.onLoad();
|
|
|
|
|
|
|
|
this.saveDefaultConfig();
|
|
|
|
this.loadSettings();
|
2019-05-05 09:41:57 +02:00
|
|
|
|
2021-12-21 07:14:33 +01:00
|
|
|
this.chunkGenerator = new ChunkGeneratorWorld(this);
|
2019-05-05 09:41:57 +02:00
|
|
|
|
2020-05-01 22:29:02 +02:00
|
|
|
// Player Command
|
|
|
|
this.playerCommand = new DefaultPlayerCommand(this)
|
2020-09-28 03:12:22 +02:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void setup()
|
2020-05-01 22:29:02 +02:00
|
|
|
{
|
2020-09-28 03:12:22 +02:00
|
|
|
super.setup();
|
|
|
|
new IslandAboutCommand(this);
|
|
|
|
}
|
|
|
|
};
|
2020-05-01 22:29:02 +02:00
|
|
|
|
|
|
|
// Admin command.
|
|
|
|
this.adminCommand = new DefaultAdminCommand(this) {};
|
2019-02-01 21:29:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes code when enabling the addon. This is called after {@link #onLoad()}.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2019-04-24 16:39:10 +02:00
|
|
|
|
|
|
|
// Register flags
|
|
|
|
CaveBlock.SKY_WALKER_FLAG.addGameModeAddon(this);
|
|
|
|
this.getPlugin().getFlagsManager().registerFlag(CaveBlock.SKY_WALKER_FLAG);
|
|
|
|
|
|
|
|
// Register listener
|
|
|
|
this.registerListener(new CustomHeightLimitations(this));
|
2019-02-01 21:29:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes code when reloading the addon.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onReload()
|
|
|
|
{
|
|
|
|
super.onReload();
|
|
|
|
this.loadSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes code when disabling the addon.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onDisable()
|
|
|
|
{
|
2019-03-23 23:58:37 +01:00
|
|
|
// Do nothing
|
2019-02-01 21:29:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method loads CaveBlock settings
|
|
|
|
*/
|
|
|
|
private void loadSettings()
|
|
|
|
{
|
2019-08-30 22:08:44 +02:00
|
|
|
this.settings = settingsConfig.loadConfigObject();
|
2019-02-01 21:29:28 +01:00
|
|
|
|
|
|
|
if (this.settings == null)
|
|
|
|
{
|
|
|
|
// Disable
|
|
|
|
this.logError("CaveBlock settings could not load! Addon disabled.");
|
|
|
|
this.setState(State.DISABLED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-14 06:04:55 +02:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see world.bentobox.bentobox.api.addons.Addon#allLoaded()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void allLoaded() {
|
|
|
|
// Reload settings and save them. This will occur after all addons have loaded
|
|
|
|
this.loadSettings();
|
|
|
|
this.saveWorldSettings();
|
|
|
|
}
|
|
|
|
|
2019-02-01 21:29:28 +01:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: World generators
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the worlds for this GameMode in this method. BentoBox will call it after onLoad() and before
|
2021-12-21 18:00:28 +01:00
|
|
|
* onEnable(). {@code islandWorld} must be created and assigned, {@code netherWorld} and {@code
|
|
|
|
* endWorld} are optional and may be null.
|
2019-02-01 21:29:28 +01:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void createWorlds()
|
|
|
|
{
|
2019-05-19 23:15:26 +02:00
|
|
|
String worldName = this.settings.getWorldName().toLowerCase();
|
2019-02-01 21:29:28 +01:00
|
|
|
|
|
|
|
if (this.getServer().getWorld(worldName) == null)
|
|
|
|
{
|
|
|
|
this.getLogger().info("Creating CaveBlock world ...");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the world if it does not exist
|
|
|
|
this.islandWorld = WorldCreator.name(worldName).
|
|
|
|
environment(World.Environment.NORMAL).
|
|
|
|
generator(this.chunkGenerator).
|
|
|
|
createWorld();
|
2020-09-28 03:12:22 +02:00
|
|
|
// Set spawn rates
|
|
|
|
setSpawnRates(islandWorld);
|
2019-02-01 21:29:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Make the nether if it does not exist
|
|
|
|
if (this.settings.isNetherGenerate())
|
|
|
|
{
|
|
|
|
if (this.getServer().getWorld(worldName + NETHER) == null)
|
|
|
|
{
|
|
|
|
this.log("Creating CaveBlock's Nether...");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.settings.isNetherIslands())
|
|
|
|
{
|
|
|
|
this.netherWorld = WorldCreator.name(worldName + NETHER).
|
|
|
|
type(WorldType.NORMAL).
|
|
|
|
environment(World.Environment.NETHER).
|
|
|
|
createWorld();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.netherWorld = WorldCreator.name(worldName + NETHER).
|
|
|
|
type(WorldType.FLAT).
|
|
|
|
generator(this.chunkGenerator).
|
|
|
|
environment(World.Environment.NETHER).
|
|
|
|
createWorld();
|
|
|
|
}
|
2020-09-28 03:12:22 +02:00
|
|
|
setSpawnRates(netherWorld);
|
2019-02-01 21:29:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make the end if it does not exist
|
|
|
|
if (this.settings.isEndGenerate())
|
|
|
|
{
|
|
|
|
if (this.getServer().getWorld(worldName + THE_END) == null)
|
|
|
|
{
|
|
|
|
this.log("Creating CaveBlock's End World...");
|
|
|
|
}
|
|
|
|
if (!this.settings.isEndIslands())
|
|
|
|
{
|
|
|
|
this.endWorld = WorldCreator.name(worldName + THE_END).
|
|
|
|
type(WorldType.NORMAL).
|
|
|
|
environment(World.Environment.THE_END).
|
|
|
|
createWorld();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.endWorld = WorldCreator.name(worldName + THE_END).
|
|
|
|
type(WorldType.FLAT).
|
|
|
|
generator(this.chunkGenerator).
|
|
|
|
environment(World.Environment.THE_END).
|
|
|
|
createWorld();
|
|
|
|
}
|
2020-09-28 03:12:22 +02:00
|
|
|
setSpawnRates(endWorld);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setSpawnRates(World w) {
|
|
|
|
if (w != null) {
|
2020-11-27 16:55:25 +01:00
|
|
|
if (getSettings().getSpawnLimitMonsters() > 0) {
|
|
|
|
w.setMonsterSpawnLimit(getSettings().getSpawnLimitMonsters());
|
|
|
|
}
|
|
|
|
if (getSettings().getSpawnLimitAmbient() > 0) {
|
|
|
|
w.setAmbientSpawnLimit(getSettings().getSpawnLimitAmbient());
|
|
|
|
}
|
|
|
|
if (getSettings().getSpawnLimitAnimals() > 0) {
|
|
|
|
w.setAnimalSpawnLimit(getSettings().getSpawnLimitAnimals());
|
|
|
|
}
|
|
|
|
if (getSettings().getSpawnLimitWaterAnimals() > 0) {
|
|
|
|
w.setWaterAnimalSpawnLimit(getSettings().getSpawnLimitWaterAnimals());
|
|
|
|
}
|
|
|
|
if (getSettings().getTicksPerAnimalSpawns() > 0) {
|
|
|
|
w.setTicksPerAnimalSpawns(getSettings().getTicksPerAnimalSpawns());
|
|
|
|
}
|
|
|
|
if (getSettings().getTicksPerMonsterSpawns() > 0) {
|
|
|
|
w.setTicksPerMonsterSpawns(getSettings().getTicksPerMonsterSpawns());
|
|
|
|
}
|
2019-02-01 21:29:28 +01:00
|
|
|
}
|
2020-09-28 03:12:22 +02:00
|
|
|
|
2019-02-01 21:29:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines the world generator for this game mode
|
|
|
|
*
|
|
|
|
* @param worldName - name of world that this applies to
|
|
|
|
* @param id - id if any
|
|
|
|
* @return Chunk generator
|
|
|
|
* @since 1.2.0
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public @NonNull ChunkGenerator getDefaultWorldGenerator(String worldName, String id)
|
|
|
|
{
|
|
|
|
return this.chunkGenerator;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Getters
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return WorldSettings for this GameMode
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public WorldSettings getWorldSettings()
|
|
|
|
{
|
|
|
|
return this.settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Settings for this GameMode
|
|
|
|
*/
|
|
|
|
public Settings getSettings()
|
|
|
|
{
|
|
|
|
return this.settings;
|
|
|
|
}
|
|
|
|
|
2019-04-24 16:39:10 +02:00
|
|
|
|
2019-03-23 23:58:37 +01:00
|
|
|
@Override
|
2019-04-24 16:39:10 +02:00
|
|
|
public void saveWorldSettings()
|
|
|
|
{
|
|
|
|
if (this.settings != null)
|
|
|
|
{
|
2019-08-30 22:08:44 +02:00
|
|
|
settingsConfig.saveConfigObject(this.settings);
|
2019-03-23 23:58:37 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-01 21:29:28 +01:00
|
|
|
|
2019-04-24 16:39:10 +02:00
|
|
|
|
2019-02-01 21:29:28 +01:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Variables
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
2019-08-30 22:08:44 +02:00
|
|
|
/**
|
|
|
|
* Config object
|
|
|
|
*/
|
|
|
|
private final Config<Settings> settingsConfig = new Config<>(this, Settings.class);
|
2019-02-01 21:29:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This stores CaveBlock addon settings.
|
|
|
|
*/
|
|
|
|
private Settings settings;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This stores CaveBlock addon WorldGenerator.
|
|
|
|
*/
|
|
|
|
private ChunkGeneratorWorld chunkGenerator;
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Section: Constants
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2019-04-24 16:39:10 +02:00
|
|
|
/**
|
|
|
|
* This flag allows enables and disables to walk on top of the world without a
|
|
|
|
* permission. When enabled, players will be able to reach other player islands through
|
|
|
|
* top of the world.
|
|
|
|
*/
|
|
|
|
public final static Flag SKY_WALKER_FLAG =
|
2019-05-05 09:41:57 +02:00
|
|
|
new Flag.Builder("SKY_WALKER_FLAG", Material.FEATHER).
|
2019-04-24 16:39:10 +02:00
|
|
|
type(Flag.Type.WORLD_SETTING).
|
|
|
|
defaultSetting(false).
|
|
|
|
build();
|
|
|
|
|
2019-02-01 21:29:28 +01:00
|
|
|
/**
|
|
|
|
* String for nether world.
|
|
|
|
*/
|
|
|
|
private static final String NETHER = "_nether";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* String for the end world.
|
|
|
|
*/
|
|
|
|
private static final String THE_END = "_the_end";
|
2019-01-28 07:27:44 +01:00
|
|
|
}
|