Skip to content

Commit 71eb940

Browse files
committed
Function added to completely deactivate the spawning of entites (Issue #28)
1 parent 6a7bba2 commit 71eb940

File tree

10 files changed

+60
-7
lines changed

10 files changed

+60
-7
lines changed

multiworld-api/multiworld-api-bukkit/src/main/java/com/dev7ex/multiworld/api/bukkit/MultiWorldBukkitApiConfiguration.java

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public enum Entry {
5050
SETTINGS_DEFAULTS_PVP_ENABLED("settings.defaults.pvp-enabled", true, false),
5151
SETTINGS_DEFAULTS_SPAWN_ANIMALS("settings.defaults.spawn-animals", true, false),
5252
SETTINGS_DEFAULTS_SPAWN_MONSTERS("settings.defaults.spawn-monsters", true, false),
53+
SETTINGS_DEFAULTS_SPAWN_ENTITIES("settings.defaults.spawn-entities", true, false),
5354
SETTINGS_DEFAULTS_END_PORTAL_ACCESSIBLE("settings.defaults.end-portal-accessible", true, false),
5455
SETTINGS_DEFAULTS_NETHER_PORTAL_ACCESSIBLE("settings.defaults.nether-portal-accessible", true, false),
5556
SETTINGS_DEFAULTS_WHITELIST_ENABLED("settings.defaults.whitelist-enabled", false, false),

multiworld-api/multiworld-api-bukkit/src/main/java/com/dev7ex/multiworld/api/bukkit/world/BukkitWorldHolder.java

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class BukkitWorldHolder implements WorldHolder {
3535
private boolean loaded;
3636
private boolean spawnAnimals;
3737
private boolean spawnMonsters;
38+
private boolean spawnEntities;
3839
private boolean endPortalAccessible;
3940
private boolean netherPortalAccessible;
4041
private List<String> whitelist = new ArrayList<>();
@@ -77,6 +78,10 @@ public void updateFlag(@NotNull final WorldFlag flag, @NotNull final String valu
7778
}
7879
break;
7980

81+
case SPAWN_ENTITIES:
82+
this.spawnEntities = Boolean.parseBoolean(value);
83+
break;
84+
8085
case END_PORTAL_ACCESSIBLE:
8186
this.endPortalAccessible = Boolean.parseBoolean(value);
8287
break;

multiworld-api/multiworld-api-core/src/main/java/com/dev7ex/multiworld/api/world/WorldDefaultProperty.java

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public enum WorldDefaultProperty {
2020
PVP_ENABLED("pvp-enabled", "settings.defaults.pvp-enabled"),
2121
SPAWN_ANIMALS("spawn-animals", "settings.defaults.spawn-animals"),
2222
SPAWN_MONSTERS("spawn-monsters", "settings.defaults.spawn-monsters"),
23+
SPAWN_ENTITIES("spawn-entities", "settings.defaults.spawn-entities"),
2324
END_PORTAL_ACCESSIBLE("end-portal-accessible", "settings.defaults.end-portal-accessible"),
2425
NETHER_PORTAL_ACCESSIBLE("nether-portal-accessible", "settings.defaults.nether-portal-accessible"),
2526
WORLD("world", "settings.defaults.world"),

multiworld-api/multiworld-api-core/src/main/java/com/dev7ex/multiworld/api/world/WorldFlag.java

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public enum WorldFlag {
2020
GAME_MODE("game-mode", List.of("ADVENTURE", "CREATIVE", "SURVIVAL", "SPECTATOR")),
2121
SPAWN_MONSTERS("spawn-monsters", List.of("false", "true")),
2222
SPAWN_ANIMALS("spawn-animals", List.of("false", "true")),
23+
SPAWN_ENTITIES("spawn-entities", List.of("false", "true")),
2324
END_PORTAL_ACCESSIBLE("end-portal-accessible", List.of("false", "true")),
2425
NETHER_PORTAL_ACCESSIBLE("nether-portal-accessible", List.of("false", "true")),
2526
PVP_ENABLED("pvp-enabled", List.of("false", "true")),

multiworld-api/multiworld-api-core/src/main/java/com/dev7ex/multiworld/api/world/WorldHolder.java

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public interface WorldHolder {
3333

3434
boolean isSpawnMonsters();
3535

36+
boolean isSpawnEntities();
37+
3638
boolean isEndPortalAccessible();
3739

3840
void setEndPortalAccessible(final boolean accessible);

multiworld-api/multiworld-api-core/src/main/java/com/dev7ex/multiworld/api/world/WorldProperty.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@Getter(AccessLevel.PUBLIC)
1515
public enum WorldProperty {
1616

17-
LOAD_AUTO("load-auto", false),
17+
LOAD_AUTO("load-auto", true),
1818
CREATOR_NAME("creator-name", true),
1919
CREATION_TIMESTAMP("creation-timestamp", true),
2020
TYPE("type", true),
@@ -23,6 +23,7 @@ public enum WorldProperty {
2323
PVP_ENABLED("pvp-enabled", true),
2424
SPAWN_ANIMALS("spawn-animals", true),
2525
SPAWN_MONSTERS("spawn-monsters", true),
26+
SPAWN_ENTITIES("spawn-entities", true),
2627
END_PORTAL_ACCESSIBLE("end-portal-accessible", true),
2728
NETHER_PORTAL_ACCESSIBLE("nether-portal-accessible", true),
2829
WHITELIST("whitelist", true),

multiworld-bukkit/src/main/java/com/dev7ex/multiworld/MultiWorldPlugin.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
import com.dev7ex.multiworld.api.bukkit.expansion.MultiWorldExpansion;
1010
import com.dev7ex.multiworld.api.bukkit.world.location.BukkitWorldLocation;
1111
import com.dev7ex.multiworld.command.WorldCommand;
12-
import com.dev7ex.multiworld.listener.PlayerConnectionListener;
13-
import com.dev7ex.multiworld.listener.PlayerDamagePlayerListener;
14-
import com.dev7ex.multiworld.listener.PlayerEnterPortalListener;
15-
import com.dev7ex.multiworld.listener.UserTeleportWorldListener;
12+
import com.dev7ex.multiworld.listener.*;
1613
import com.dev7ex.multiworld.user.UserService;
1714
import com.dev7ex.multiworld.util.UpdateChecker;
1815
import com.dev7ex.multiworld.world.DefaultWorldConfiguration;
@@ -91,6 +88,7 @@ public void registerListeners() {
9188
super.registerListener(new PlayerConnectionListener(this));
9289
super.registerListener(new PlayerEnterPortalListener(this));
9390
super.registerListener(new PlayerDamagePlayerListener(this));
91+
super.registerListener(new EntitySpawnListener(this));
9492

9593
super.registerListener(new UserTeleportWorldListener(this));
9694
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.dev7ex.multiworld.listener;
2+
3+
import com.dev7ex.multiworld.api.bukkit.MultiWorldBukkitApi;
4+
import com.dev7ex.multiworld.api.bukkit.event.MultiWorldListener;
5+
import com.dev7ex.multiworld.api.bukkit.world.BukkitWorldHolder;
6+
import org.bukkit.event.EventHandler;
7+
import org.bukkit.event.EventPriority;
8+
import org.bukkit.event.entity.EntitySpawnEvent;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
/**
12+
* @author Dev7ex
13+
* @since 06.03.2024
14+
*/
15+
public class EntitySpawnListener extends MultiWorldListener {
16+
17+
public EntitySpawnListener(@NotNull final MultiWorldBukkitApi multiWorldApi) {
18+
super(multiWorldApi);
19+
}
20+
21+
@EventHandler(priority = EventPriority.NORMAL)
22+
public void handleEntitySpawn(final EntitySpawnEvent event) {
23+
if (event.getLocation().getWorld() == null) {
24+
return;
25+
}
26+
final String worldName = event.getLocation().getWorld().getName();
27+
28+
if (super.getWorldProvider().getWorldHolder(worldName).isEmpty()) {
29+
return;
30+
}
31+
final BukkitWorldHolder worldHolder = super.getWorldProvider().getWorldHolder(worldName).get();
32+
33+
event.setCancelled(!worldHolder.isSpawnEntities());
34+
}
35+
36+
}

multiworld-bukkit/src/main/java/com/dev7ex/multiworld/world/DefaultWorldConfiguration.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void add(@NotNull final BukkitWorldHolder worldHolder) {
4444
super.getFileConfiguration().set(worldHolder.getName() + "." + WorldProperty.PVP_ENABLED.getStoragePath(), worldHolder.isPvpEnabled());
4545
super.getFileConfiguration().set(worldHolder.getName() + "." + WorldProperty.SPAWN_ANIMALS.getStoragePath(), worldHolder.isSpawnAnimals());
4646
super.getFileConfiguration().set(worldHolder.getName() + "." + WorldProperty.SPAWN_MONSTERS.getStoragePath(), worldHolder.isSpawnMonsters());
47+
super.getFileConfiguration().set(worldHolder.getName() + "." + WorldProperty.SPAWN_ENTITIES.getStoragePath(), worldHolder.isSpawnEntities());
4748
super.getFileConfiguration().set(worldHolder.getName() + "." + WorldProperty.END_PORTAL_ACCESSIBLE.getStoragePath(), worldHolder.isEndPortalAccessible());
4849
super.getFileConfiguration().set(worldHolder.getName() + "." + WorldProperty.NETHER_PORTAL_ACCESSIBLE.getStoragePath(), worldHolder.isNetherPortalAccessible());
4950
super.getFileConfiguration().set(worldHolder.getName() + "." + WorldProperty.WHITELIST.getStoragePath(), Collections.emptyList());
@@ -118,6 +119,11 @@ public void addMissingProperty(@NotNull final BukkitWorldHolder worldHolder, @No
118119
MultiWorldPlugin.getInstance().getLogger().info("Adding Missing Property [" + property.name() + "] to " + worldHolder.getName());
119120
break;
120121

122+
case SPAWN_ENTITIES:
123+
this.write(worldHolder, property, this.defaultProperties.getBoolean(WorldDefaultProperty.SPAWN_ENTITIES));
124+
MultiWorldPlugin.getInstance().getLogger().info("Adding Missing Property [" + property.name() + "] to " + worldHolder.getName());
125+
break;
126+
121127
case END_PORTAL_ACCESSIBLE:
122128
this.write(worldHolder, property, this.defaultProperties.getBoolean(WorldDefaultProperty.END_PORTAL_ACCESSIBLE));
123129
MultiWorldPlugin.getInstance().getLogger().info("Adding Missing Property [" + property.name() + "] to " + worldHolder.getName());
@@ -177,8 +183,8 @@ public void write(@NotNull final BukkitWorldHolder worldHolder, @NotNull final P
177183
super.getFileConfiguration().set(worldHolder.getName() + "." + property.getStoragePath(), worldData.getLong(property));
178184
break;
179185

180-
case PVP_ENABLED: case SPAWN_ANIMALS: case SPAWN_MONSTERS: case WHITELIST_ENABLED: case END_PORTAL_ACCESSIBLE: case NETHER_PORTAL_ACCESSIBLE:
181-
case LOAD_AUTO:
186+
case PVP_ENABLED: case SPAWN_ANIMALS: case SPAWN_MONSTERS: case SPAWN_ENTITIES:
187+
case WHITELIST_ENABLED: case END_PORTAL_ACCESSIBLE: case NETHER_PORTAL_ACCESSIBLE: case LOAD_AUTO:
182188
super.getFileConfiguration().set(worldHolder.getName() + "." + property.getStoragePath(), worldData.getBoolean(property));
183189
break;
184190

@@ -218,6 +224,7 @@ public BukkitWorldHolder getWorldHolder(@NotNull final String name) {
218224
.setPvpEnabled(super.getFileConfiguration().getBoolean(name + "." + WorldProperty.PVP_ENABLED.getStoragePath()))
219225
.setSpawnAnimals(super.getFileConfiguration().getBoolean(name + "." + WorldProperty.SPAWN_ANIMALS.getStoragePath()))
220226
.setSpawnMonsters(super.getFileConfiguration().getBoolean(name + "." + WorldProperty.SPAWN_MONSTERS.getStoragePath()))
227+
.setSpawnEntities(super.getFileConfiguration().getBoolean(name + "." + WorldProperty.SPAWN_ENTITIES.getStoragePath()))
221228
.setEndPortalAccessible(super.getFileConfiguration().getBoolean(name + "." + WorldProperty.END_PORTAL_ACCESSIBLE.getStoragePath(), true))
222229
.setNetherPortalAccessible(super.getFileConfiguration().getBoolean(name + "." + WorldProperty.NETHER_PORTAL_ACCESSIBLE.getStoragePath(), true))
223230
.setWhitelist(super.getFileConfiguration().getStringList(name + "." + WorldProperty.WHITELIST.getStoragePath()))

multiworld-bukkit/src/main/resources/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ settings:
3232
pvp-enabled: true
3333
spawn-animals: true
3434
spawn-monsters: true
35+
spawn-entities: true
3536
end-portal-accessible: true
3637
nether-portal-accessible: true
3738
whitelist-enabled: false

0 commit comments

Comments
 (0)