Skip to content

Commit 0e5c41c

Browse files
committed
Update BukkitWorldHolder.java
1 parent c781c7a commit 0e5c41c

File tree

1 file changed

+67
-28
lines changed
  • multiworld-api/multiworld-api-bukkit/src/main/java/com/dev7ex/multiworld/api/bukkit/world

1 file changed

+67
-28
lines changed

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

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import org.bukkit.Difficulty;
1414
import org.bukkit.GameMode;
1515
import org.bukkit.World;
16+
import org.bukkit.conversations.Conversation;
17+
import org.bukkit.entity.Animals;
18+
import org.bukkit.entity.Entity;
19+
import org.bukkit.entity.Monster;
1620
import org.jetbrains.annotations.NotNull;
1721

1822
import java.util.ArrayList;
@@ -34,23 +38,30 @@ public class BukkitWorldHolder implements WorldHolder {
3438
private String name;
3539
private String creatorName;
3640
private long creationTimeStamp;
37-
private WorldType type;
38-
private GameMode gameMode;
41+
private boolean autoLoadEnabled;
42+
private boolean autoUnloadEnabled;
3943
private Difficulty difficulty;
40-
private boolean pvpEnabled;
41-
private boolean loaded;
42-
private boolean spawnAnimals;
43-
private boolean spawnMonsters;
44-
private boolean spawnEntities;
4544
private boolean endPortalAccessible;
46-
private boolean netherPortalAccessible;
45+
private World.Environment environment;
46+
private GameMode gameMode;
47+
private String generator;
48+
private boolean hungerEnabled;
49+
private boolean keepSpawnInMemory;
4750
private String endWorldName;
4851
private String netherWorldName;
4952
private String normalWorldName;
53+
private boolean netherPortalAccessible;
54+
private boolean pvpEnabled;
55+
private boolean receiveAchievements;
56+
private boolean redstoneEnabled;
57+
private boolean spawnAnimals;
58+
private boolean spawnMonsters;
59+
private boolean spawnEntities;
60+
private WorldType type;
61+
private boolean weatherEnabled;
5062
private List<String> whitelist = new ArrayList<>();
5163
private boolean whitelistEnabled;
52-
private boolean autoLoadEnabled = false;
53-
private boolean receiveAchievements;
64+
private boolean loaded;
5465

5566
/**
5667
* Gets the Bukkit world associated with this world holder.
@@ -75,12 +86,12 @@ public WorldLocation getSpawnLocation() {
7586
@Override
7687
public void updateFlag(@NotNull final WorldFlag flag, @NotNull final String value) {
7788
switch (flag) {
78-
case PVP_ENABLED:
79-
this.pvpEnabled = Boolean.parseBoolean(value);
89+
case AUTO_LOAD_ENABLED:
90+
this.autoLoadEnabled = Boolean.parseBoolean(value);
8091
break;
8192

82-
case GAME_MODE:
83-
this.gameMode = GameMode.valueOf(value);
93+
case AUTO_UNLOAD_ENABLED:
94+
this.autoUnloadEnabled = Boolean.parseBoolean(value);
8495
break;
8596

8697
case DIFFICULTY:
@@ -90,38 +101,66 @@ public void updateFlag(@NotNull final WorldFlag flag, @NotNull final String valu
90101
}
91102
break;
92103

104+
case END_PORTAL_ACCESSIBLE:
105+
this.endPortalAccessible = Boolean.parseBoolean(value);
106+
break;
107+
108+
case GAME_MODE:
109+
this.gameMode = GameMode.valueOf(value);
110+
Bukkit.getOnlinePlayers().forEach(player -> player.setGameMode(this.gameMode));
111+
break;
112+
113+
case HUNGER_ENABLED:
114+
this.hungerEnabled = Boolean.parseBoolean(value);
115+
if (!this.hungerEnabled) {
116+
Bukkit.getOnlinePlayers().forEach(player -> {
117+
player.setSaturation(20.00F);
118+
});
119+
}
120+
121+
case KEEP_SPAWN_IN_MEMORY:
122+
this.keepSpawnInMemory = Boolean.parseBoolean(value);
123+
this.getWorld().setKeepSpawnInMemory(this.keepSpawnInMemory);
124+
break;
125+
126+
case NETHER_PORTAL_ACCESSIBLE:
127+
this.netherPortalAccessible = Boolean.parseBoolean(value);
128+
break;
129+
130+
case PVP_ENABLED:
131+
this.pvpEnabled = Boolean.parseBoolean(value);
132+
break;
133+
134+
case RECEIVE_ACHIEVEMENTS:
135+
this.receiveAchievements = Boolean.parseBoolean(value);
136+
break;
137+
138+
case REDSTONE_ENABLED:
139+
this.redstoneEnabled = Boolean.parseBoolean(value);
140+
break;
141+
93142
case SPAWN_ANIMALS:
94143
this.spawnAnimals = Boolean.parseBoolean(value);
95144
if (this.loaded) {
96145
this.getWorld().setSpawnFlags(this.spawnMonsters, this.spawnAnimals);
146+
this.getWorld().getEntities().stream().filter(entity -> entity instanceof Animals).forEach(Entity::remove);
97147
}
98148
break;
99149

100150
case SPAWN_MONSTERS:
101151
this.spawnMonsters = Boolean.parseBoolean(value);
102152
if (this.loaded) {
103153
this.getWorld().setSpawnFlags(this.spawnMonsters, this.spawnAnimals);
154+
this.getWorld().getEntities().stream().filter(entity -> entity instanceof Monster).forEach(Entity::remove);
104155
}
105156
break;
106157

107158
case SPAWN_ENTITIES:
108159
this.spawnEntities = Boolean.parseBoolean(value);
109160
break;
110161

111-
case END_PORTAL_ACCESSIBLE:
112-
this.endPortalAccessible = Boolean.parseBoolean(value);
113-
break;
114-
115-
case NETHER_PORTAL_ACCESSIBLE:
116-
this.netherPortalAccessible = Boolean.parseBoolean(value);
117-
break;
118-
119-
case RECEIVE_ACHIEVEMENTS:
120-
this.receiveAchievements = Boolean.parseBoolean(value);
121-
break;
122-
123-
case WORLD_TYPE:
124-
this.type = WorldType.valueOf(value);
162+
case WEATHER_ENABLED:
163+
this.weatherEnabled = Boolean.parseBoolean(value);
125164
break;
126165
}
127166
}

0 commit comments

Comments
 (0)