-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathAcidIsland.java
More file actions
219 lines (194 loc) · 7.75 KB
/
AcidIsland.java
File metadata and controls
219 lines (194 loc) · 7.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package world.bentobox.acidisland;
import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.generator.BiomeProvider;
import org.bukkit.generator.ChunkGenerator;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.acidisland.commands.IslandAboutCommand;
import world.bentobox.acidisland.listeners.AcidEffect;
import world.bentobox.acidisland.listeners.LavaCheck;
import world.bentobox.acidisland.listeners.PurifiedWaterListener;
import world.bentobox.acidisland.world.AcidBiomeProvider;
import world.bentobox.acidisland.world.AcidTask;
import world.bentobox.acidisland.world.ChunkGeneratorWorld;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.admin.DefaultAdminCommand;
import world.bentobox.bentobox.api.commands.island.DefaultPlayerCommand;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.lists.Flags;
/**
* Add-on to BentoBox that enables AcidIsland
* @author tastybento
*
*/
public class AcidIsland extends GameModeAddon {
private @Nullable AISettings settings;
private @Nullable AcidTask acidTask;
private @Nullable ChunkGenerator chunkGenerator;
private final Config<AISettings> config = new Config<>(this, AISettings.class);
private BiomeProvider biomeProvider;
private static final String NETHER = "_nether";
private static final String THE_END = "_the_end";
/**
* This addon uses the new chunk generation API for the sea bottom
*/
@Override
public boolean isUsesNewChunkGeneration() {
return true;
}
@Override
public void onLoad() {
// Save the default config from config.yml
saveDefaultConfig();
// Load settings from config.yml. This will check if there are any issues with it too.
loadSettings();
// Make the biome provider
this.biomeProvider = new AcidBiomeProvider(this);
// Chunk generator
chunkGenerator = settings.isUseOwnGenerator() ? null : new ChunkGeneratorWorld(this);
// Register commands
playerCommand = new DefaultPlayerCommand(this)
{
@Override
public void setup()
{
super.setup();
new IslandAboutCommand(this);
}
};
adminCommand = new DefaultAdminCommand(this) {};
}
private boolean loadSettings() {
settings = config.loadConfigObject();
if (settings == null) {
// Woops
this.logError("AcidIsland settings could not load! Addon disabled.");
this.setState(State.DISABLED);
if (acidTask != null) {
acidTask.cancelTasks();
}
return false;
}
return true;
}
@Override
public void onEnable() {
if (settings == null) {
return;
}
// Set default access to boats
Flags.BOAT.setDefaultSetting(islandWorld, true);
if (netherWorld != null) Flags.BOAT.setDefaultSetting(netherWorld, true);
if (endWorld != null) Flags.BOAT.setDefaultSetting(endWorld, true);
// Register listeners
// Acid Effects
registerListener(new AcidEffect(this));
registerListener(new LavaCheck(this));
registerListener(new PurifiedWaterListener(this));
// Burn everything
acidTask = new AcidTask(this);
}
@Override
public void onDisable() {
if (acidTask != null) acidTask.cancelTasks();
}
@NonNull
public AISettings getSettings() {
return Objects.requireNonNull(settings);
}
/* (non-Javadoc)
* @see world.bentobox.bentobox.api.addons.GameModeAddon#createWorlds()
*/
@Override
public void createWorlds() {
String worldName = settings.getWorldName().toLowerCase();
if (Bukkit.getWorld(worldName) == null) {
log("Creating AcidIsland...");
}
// Create the world if it does not exist
chunkGenerator = new ChunkGeneratorWorld(this);
islandWorld = getWorld(worldName, World.Environment.NORMAL, chunkGenerator);
// Make the nether if it does not exist
if (settings.isNetherGenerate()) {
if (Bukkit.getWorld(worldName + NETHER) == null) {
log("Creating AcidIsland's Nether...");
}
netherWorld = settings.isNetherIslands() ? getWorld(worldName, World.Environment.NETHER, chunkGenerator) : getWorld(worldName, World.Environment.NETHER, null);
}
// Make the end if it does not exist
if (settings.isEndGenerate()) {
if (Bukkit.getWorld(worldName + THE_END) == null) {
log("Creating AcidIsland's End World...");
}
endWorld = settings.isEndIslands() ? getWorld(worldName, World.Environment.THE_END, chunkGenerator) : getWorld(worldName, World.Environment.THE_END, null);
}
}
/**
* Gets a world or generates a new world if it does not exist
* @param worldName2 - the overworld name
* @param env - the environment
* @param chunkGenerator2 - the chunk generator. If <tt>null</tt> then the generator will not be specified
* @return world loaded or generated
*/
private World getWorld(String worldName2, Environment env, @Nullable ChunkGenerator chunkGenerator2) {
String name = getWorldName(worldName2, env);
WorldCreator wc = WorldCreator.name(name).environment(env).type(WorldType.NORMAL);
World w = settings.isUseOwnGenerator() ? wc.createWorld() : wc.generator(chunkGenerator2).createWorld();
if (w != null && getSettings() != null) {
configureSpawnRates(w);
}
return w;
}
private String getWorldName(String base, Environment env) {
if (env.equals(World.Environment.NETHER)) return base + NETHER;
if (env.equals(World.Environment.THE_END)) return base + THE_END;
return base;
}
private void configureSpawnRates(World w) {
AISettings s = getSettings();
if (s.getSpawnLimitMonsters() > 0) w.setSpawnLimit(SpawnCategory.MONSTER, s.getSpawnLimitMonsters());
if (s.getSpawnLimitAmbient() > 0) w.setSpawnLimit(SpawnCategory.AMBIENT, s.getSpawnLimitAmbient());
if (s.getSpawnLimitAnimals() > 0) w.setSpawnLimit(SpawnCategory.ANIMAL, s.getSpawnLimitAnimals());
if (s.getSpawnLimitWaterAnimals() > 0) w.setSpawnLimit(SpawnCategory.WATER_ANIMAL, s.getSpawnLimitWaterAnimals());
if (s.getTicksPerAnimalSpawns() > 0) w.setTicksPerSpawns(SpawnCategory.ANIMAL, s.getTicksPerAnimalSpawns());
if (s.getTicksPerMonsterSpawns() > 0) w.setTicksPerSpawns(SpawnCategory.MONSTER, s.getTicksPerMonsterSpawns());
}
@Override
public WorldSettings getWorldSettings() {
return getSettings();
}
@Override
public void onReload() {
if (loadSettings()) {
log("Reloaded AcidIsland settings");
}
}
@Override
public @NonNull ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return chunkGenerator;
}
@Override
public void saveWorldSettings() {
if (settings != null) {
config.saveConfigObject(settings);
}
}
/* (non-Javadoc)
* @see world.bentobox.bentobox.api.addons.Addon#allLoaded()
*/
@Override
public void allLoaded() {
// Save settings. This will occur after all addons have loaded
this.saveWorldSettings();
}
public BiomeProvider getBiomeProvider() {
return this.biomeProvider;
}
}