-
-
Notifications
You must be signed in to change notification settings - Fork 211
/
MixinWorldInfo.java
836 lines (725 loc) · 29 KB
/
MixinWorldInfo.java
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.mixin.core.world.storage;
import static com.google.common.base.Preconditions.checkNotNull;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.scoreboard.ServerScoreboard;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.GameRules;
import net.minecraft.world.GameType;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.WorldType;
import net.minecraft.world.storage.WorldInfo;
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.DataQuery;
import org.spongepowered.api.data.DataView;
import org.spongepowered.api.data.MemoryDataContainer;
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
import org.spongepowered.api.util.annotation.NonnullByDefault;
import org.spongepowered.api.world.DimensionType;
import org.spongepowered.api.world.DimensionTypes;
import org.spongepowered.api.world.GeneratorType;
import org.spongepowered.api.world.PortalAgentType;
import org.spongepowered.api.world.PortalAgentTypes;
import org.spongepowered.api.world.SerializationBehavior;
import org.spongepowered.api.world.SerializationBehaviors;
import org.spongepowered.api.world.WorldArchetype;
import org.spongepowered.api.world.difficulty.Difficulty;
import org.spongepowered.api.world.gen.WorldGeneratorModifier;
import org.spongepowered.api.world.storage.WorldProperties;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.SpongeImpl;
import org.spongepowered.common.config.SpongeConfig;
import org.spongepowered.common.config.type.DimensionConfig;
import org.spongepowered.common.config.type.WorldConfig;
import org.spongepowered.common.data.persistence.NbtTranslator;
import org.spongepowered.common.data.util.DataQueries;
import org.spongepowered.common.data.util.DataUtil;
import org.spongepowered.common.data.util.NbtDataUtil;
import org.spongepowered.common.event.SpongeCommonEventFactory;
import org.spongepowered.common.interfaces.world.IMixinDimensionType;
import org.spongepowered.common.interfaces.world.IMixinWorldInfo;
import org.spongepowered.common.interfaces.world.IMixinWorldSettings;
import org.spongepowered.common.registry.type.entity.GameModeRegistryModule;
import org.spongepowered.common.registry.type.world.DimensionTypeRegistryModule;
import org.spongepowered.common.registry.type.world.PortalAgentRegistryModule;
import org.spongepowered.common.registry.type.world.WorldGeneratorModifierRegistryModule;
import org.spongepowered.common.util.FunctionalUtil;
import org.spongepowered.common.util.SpongeHooks;
import org.spongepowered.common.util.persistence.JsonTranslator;
import org.spongepowered.common.world.WorldManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
@NonnullByDefault
@Mixin(WorldInfo.class)
@Implements(@Interface(iface = WorldProperties.class, prefix = "worldproperties$"))
public abstract class MixinWorldInfo implements WorldProperties, IMixinWorldInfo {
@Shadow private long randomSeed;
@Shadow private WorldType terrainType;
@Shadow private String generatorOptions;
@Shadow private int spawnX;
@Shadow private int spawnY;
@Shadow private int spawnZ;
@Shadow private long totalTime;
@Shadow private long worldTime;
@Shadow private long lastTimePlayed;
@Shadow private long sizeOnDisk;
@Shadow private NBTTagCompound playerTag;
@Shadow private String levelName;
@Shadow private int saveVersion;
@Shadow private int cleanWeatherTime;
@Shadow private boolean raining;
@Shadow private int rainTime;
@Shadow private boolean thundering;
@Shadow private int thunderTime;
@Shadow private GameType theGameType;
@Shadow private boolean mapFeaturesEnabled;
@Shadow private boolean hardcore;
@Shadow private boolean allowCommands;
@Shadow private boolean initialized;
@Shadow private EnumDifficulty difficulty;
@Shadow private boolean difficultyLocked;
@Shadow private double borderCenterX;
@Shadow private double borderCenterZ;
@Shadow private double borderSize;
@Shadow private long borderSizeLerpTime;
@Shadow private double borderSizeLerpTarget;
@Shadow private double borderSafeZone;
@Shadow private double borderDamagePerBlock;
@Shadow private int borderWarningDistance;
@Shadow private int borderWarningTime;
@Shadow private GameRules theGameRules;
// TODO 1.9 Clone is an AWFUL NAME for this, its really fillCompound which takes a playerNbtCompound to use or if null, uses the player one
// TODO 1.9 already in this info. It then populates a returned compound with the worldInfo's properties.
@Shadow public abstract NBTTagCompound cloneNBTCompound(NBTTagCompound nbt);
private UUID uuid;
private Integer dimensionId;
private DimensionType dimensionType = DimensionTypes.OVERWORLD;
private SerializationBehavior serializationBehavior = SerializationBehaviors.AUTOMATIC;
private boolean isMod, generateBonusChest, isValid = true;
private NBTTagCompound spongeRootLevelNbt = new NBTTagCompound(), spongeNbt = new NBTTagCompound();
private NBTTagList playerUniqueIdNbt = new NBTTagList();
private BiMap<Integer, UUID> playerUniqueIdMap = HashBiMap.create();
private List<UUID> pendingUniqueIds = new ArrayList<>();
private int trackedUniqueIdCount = 0;
private SpongeConfig<WorldConfig> worldConfig;
@SuppressWarnings("unused")
private ServerScoreboard scoreboard;
private PortalAgentType portalAgentType;
// protected WorldInfo()
@Inject(method = "<init>", at = @At("RETURN") )
public void onConstruction(CallbackInfo ci) {
this.spongeNbt.setTag(NbtDataUtil.SPONGE_PLAYER_UUID_TABLE, this.playerUniqueIdNbt);
this.spongeRootLevelNbt.setTag(NbtDataUtil.SPONGE_DATA, this.spongeNbt);
}
// public WorldInfo(NBTTagCompound nbt)
@Inject(method = "<init>*", at = @At("RETURN") )
public void onConstruction(NBTTagCompound nbt, CallbackInfo ci) {
if (!SpongeCommonEventFactory.convertingMapFormat) {
onConstruction(ci);
}
}
// public WorldInfo(WorldSettings settings, String name)
@Inject(method = "<init>*", at = @At("RETURN"))
public void onConstruction(WorldSettings settings, String name, CallbackInfo ci) {
if (name.equals("MpServer") || name.equals("sponge$dummy_world")) {
this.isValid = false;
return;
}
onConstruction(ci);
final WorldArchetype archetype = (WorldArchetype) (Object) settings;
setDimensionType(archetype.getDimensionType());
boolean configNewlyCreated = createWorldConfig();
setEnabled(archetype.isEnabled());
setLoadOnStartup(archetype.loadOnStartup());
setKeepSpawnLoaded(archetype.doesKeepSpawnLoaded());
setGenerateSpawnOnLoad(archetype.doesGenerateSpawnOnLoad());
setDifficulty(archetype.getDifficulty());
setGeneratorModifiers(archetype.getGeneratorModifiers());
setDoesGenerateBonusChest(archetype.doesGenerateBonusChest());
setSerializationBehavior(archetype.getSerializationBehavior());
// Mark configs enabled if coming from WorldCreationSettings builder and config didn't previously exist.
if (configNewlyCreated && ((IMixinWorldSettings) (Object) settings).isFromBuilder()) {
this.worldConfig.getConfig().setConfigEnabled(true);
}
this.worldConfig.save();
}
// public WorldInfo(WorldInfo worldInformation)
@Inject(method = "<init>*", at = @At("RETURN") )
public void onConstruction(WorldInfo worldInformation, CallbackInfo ci) {
// TODO Since we're making a WorldInfo from a WorldInfo, perhaps we should clone the Sponge data here? Currently this is done in WorldManager.
onConstruction(ci);
// TODO Zidane needs to fix this
MixinWorldInfo info = (MixinWorldInfo) (Object) worldInformation;
this.portalAgentType = info.portalAgentType;
this.dimensionType = info.dimensionType;
}
@Inject(method = "updateTagCompound", at = @At("HEAD"))
private void ensureLevelNameMatchesDirectory(NBTTagCompound compound, NBTTagCompound player, CallbackInfo ci) {
if (this.dimensionId == null) {
return;
}
final String name = WorldManager.getWorldFolderByDimensionId(this.dimensionId).orElse(this.levelName);
if (!this.levelName.equalsIgnoreCase(name)) {
this.levelName = name;
}
}
@Override
public boolean createWorldConfig() {
if (this.worldConfig != null) {
return false;
}
this.worldConfig =
new SpongeConfig<>(SpongeConfig.Type.WORLD, ((IMixinDimensionType) this.dimensionType).getConfigPath()
.resolve(this.levelName)
.resolve("world.conf"),
SpongeImpl.ECOSYSTEM_ID);
return true;
}
@Override
public boolean isValid() {
return this.isValid;
}
@Override
public Vector3i getSpawnPosition() {
return new Vector3i(this.spawnX, this.spawnY, this.spawnZ);
}
@Override
public void setSpawnPosition(Vector3i position) {
checkNotNull(position);
this.spawnX = position.getX();
this.spawnY = position.getY();
this.spawnZ = position.getZ();
}
@Override
public GeneratorType getGeneratorType() {
return (GeneratorType) this.terrainType;
}
@Override
public void setGeneratorType(GeneratorType type) {
this.terrainType = (WorldType) type;
}
@Intrinsic
public long worldproperties$getSeed() {
return this.randomSeed;
}
@Override
public void setSeed(long seed) {
this.randomSeed = seed;
}
@Override
public long getTotalTime() {
return this.totalTime;
}
@Intrinsic
public long worldproperties$getWorldTime() {
return this.worldTime;
}
@Override
public void setWorldTime(long time) {
this.worldTime = time;
}
@Override
public DimensionType getDimensionType() {
return this.dimensionType;
}
@Override
public void setDimensionType(DimensionType type) {
this.dimensionType = type;
}
@Override
public PortalAgentType getPortalAgentType() {
if (this.portalAgentType == null) {
this.portalAgentType = PortalAgentTypes.DEFAULT;
}
return this.portalAgentType;
}
@Override
public void setPortalAgentType(PortalAgentType type) {
this.portalAgentType = type;
}
@Intrinsic
public String worldproperties$getWorldName() {
return this.levelName;
}
@Intrinsic
public boolean worldproperties$isRaining() {
return this.raining;
}
@Override
public void setRaining(boolean state) {
this.raining = state;
}
@Intrinsic
public int worldproperties$getRainTime() {
return this.rainTime;
}
@Intrinsic
public void worldproperties$setRainTime(int time) {
this.rainTime = time;
}
@Intrinsic
public boolean worldproperties$isThundering() {
return this.thundering;
}
@Intrinsic
public void worldproperties$setThundering(boolean state) {
this.thundering = state;
}
@Override
public int getThunderTime() {
return this.thunderTime;
}
@Override
public void setThunderTime(int time) {
this.thunderTime = time;
}
@Override
public GameMode getGameMode() {
return (GameMode) (Object) this.theGameType;
}
@Override
public void setGameMode(GameMode gamemode) {
this.theGameType = GameModeRegistryModule.toGameType(gamemode);
}
@Override
public boolean usesMapFeatures() {
return this.mapFeaturesEnabled;
}
@Override
public void setMapFeaturesEnabled(boolean state) {
this.mapFeaturesEnabled = state;
}
@Override
public boolean isHardcore() {
return this.hardcore;
}
@Override
public void setHardcore(boolean state) {
this.hardcore = state;
}
@Override
public boolean areCommandsAllowed() {
return this.allowCommands;
}
@Override
public void setCommandsAllowed(boolean state) {
this.allowCommands = state;
}
@Override
public boolean isInitialized() {
return this.initialized;
}
@Override
public Difficulty getDifficulty() {
return (Difficulty) (Object) this.difficulty;
}
@Override
public void setDifficulty(Difficulty difficulty) {
this.difficulty = (EnumDifficulty) (Object) difficulty;
}
@Override
public boolean doesGenerateBonusChest() {
return this.generateBonusChest;
}
public void setDoesGenerateBonusChest(boolean state) {
this.generateBonusChest = state;
}
@Override
public Vector3d getWorldBorderCenter() {
return new Vector3d(this.borderCenterX, 0, this.borderCenterZ);
}
@Override
public void setWorldBorderCenter(double x, double z) {
this.borderCenterX = x;
this.borderCenterZ = z;
}
@Override
public double getWorldBorderDiameter() {
return this.borderSize;
}
@Override
public void setWorldBorderDiameter(double diameter) {
this.borderSize = diameter;
}
@Override
public double getWorldBorderTargetDiameter() {
return this.borderSizeLerpTarget;
}
@Override
public void setWorldBorderTargetDiameter(double diameter) {
this.borderSizeLerpTarget = diameter;
}
@Override
public double getWorldBorderDamageThreshold() {
return this.borderSafeZone;
}
@Override
public void setWorldBorderDamageThreshold(double distance) {
this.borderSafeZone = distance;
}
@Override
public double getWorldBorderDamageAmount() {
return this.borderDamagePerBlock;
}
@Override
public void setWorldBorderDamageAmount(double damage) {
this.borderDamagePerBlock = damage;
}
@Override
public int getWorldBorderWarningTime() {
return this.borderWarningTime;
}
@Override
public void setWorldBorderWarningTime(int time) {
this.borderWarningTime = time;
}
@Override
public int getWorldBorderWarningDistance() {
return this.borderWarningDistance;
}
@Override
public void setWorldBorderWarningDistance(int distance) {
this.borderWarningDistance = distance;
}
@Override
public long getWorldBorderTimeRemaining() {
return this.borderSizeLerpTime;
}
@Override
public void setWorldBorderTimeRemaining(long time) {
this.borderSizeLerpTime = time;
}
@Override
public Optional<String> getGameRule(String gameRule) {
if (this.theGameRules.hasRule(gameRule)) {
return Optional.of(this.theGameRules.getString(gameRule));
}
return Optional.empty();
}
@Override
public Map<String, String> getGameRules() {
ImmutableMap.Builder<String, String> ruleMap = ImmutableMap.builder();
for (String rule : this.theGameRules.getRules()) {
ruleMap.put(rule, this.theGameRules.getString(rule));
}
return ruleMap.build();
}
@Override
public void setGameRule(String gameRule, String value) {
this.theGameRules.setOrCreateGameRule(gameRule, value);
}
@Override
public void setDimensionId(int id) {
this.dimensionId = id;
}
@Override
public Integer getDimensionId() {
return this.dimensionId;
}
@Override
public UUID getUniqueId() {
return this.uuid;
}
@Override
public int getContentVersion() {
return 0;
}
@Override
public DataContainer toContainer() {
return NbtTranslator.getInstance().translateFrom(cloneNBTCompound(null));
}
@Override
public boolean isEnabled() {
if (!this.worldConfig.getConfig().isConfigEnabled()) {
return SpongeHooks.getActiveConfig(((IMixinDimensionType) this.dimensionType).getConfigPath(), this.getWorldName()).getConfig().getWorld().isWorldEnabled();
}
return this.worldConfig.getConfig().getWorld().isWorldEnabled();
}
@Override
public void setEnabled(boolean enabled) {
this.worldConfig.getConfig().getWorld().setWorldEnabled(enabled);
}
@Override
public boolean loadOnStartup() {
Boolean loadOnStartup = null;
if (!this.worldConfig.getConfig().isConfigEnabled()) {
DimensionConfig dimConfig = ((IMixinDimensionType) this.dimensionType).getDimensionConfig().getConfig();
if (dimConfig.isConfigEnabled()) {
loadOnStartup = dimConfig.getWorld().loadOnStartup();
} else {
loadOnStartup = this.worldConfig.getConfig().getWorld().loadOnStartup();
}
} else {
loadOnStartup = this.worldConfig.getConfig().getWorld().loadOnStartup();
}
if (loadOnStartup == null) {
if (this.dimensionId != null) {
return ((IMixinDimensionType) this.dimensionType).shouldGenerateSpawnOnLoad();
}
return false;
}
return loadOnStartup;
}
@Override
public void setLoadOnStartup(boolean state) {
this.worldConfig.getConfig().getWorld().setLoadOnStartup(state);
}
@Override
public boolean doesKeepSpawnLoaded() {
Boolean keepSpawnLoaded = null;
if (!this.worldConfig.getConfig().isConfigEnabled()) {
DimensionConfig dimConfig = ((IMixinDimensionType) this.dimensionType).getDimensionConfig().getConfig();
if (dimConfig.isConfigEnabled()) {
keepSpawnLoaded = dimConfig.getWorld().getKeepSpawnLoaded();
} else {
keepSpawnLoaded = this.worldConfig.getConfig().getWorld().getKeepSpawnLoaded();
}
} else {
keepSpawnLoaded = this.worldConfig.getConfig().getWorld().getKeepSpawnLoaded();
}
if (keepSpawnLoaded == null) {
return ((IMixinDimensionType) this.dimensionType).shouldGenerateSpawnOnLoad();
}
return keepSpawnLoaded;
}
@Override
public void setKeepSpawnLoaded(boolean loaded) {
this.worldConfig.getConfig().getWorld().setKeepSpawnLoaded(loaded);
}
@Override
public boolean doesGenerateSpawnOnLoad() {
Boolean shouldGenerateSpawn = null;
if (!this.worldConfig.getConfig().isConfigEnabled()) {
DimensionConfig dimConfig = ((IMixinDimensionType) this.dimensionType).getDimensionConfig().getConfig();
if (dimConfig.isConfigEnabled()) {
shouldGenerateSpawn = dimConfig.getWorld().getGenerateSpawnOnLoad();
} else {
shouldGenerateSpawn = this.worldConfig.getConfig().getWorld().getGenerateSpawnOnLoad();
}
} else {
shouldGenerateSpawn = this.worldConfig.getConfig().getWorld().getGenerateSpawnOnLoad();
}
if (shouldGenerateSpawn == null) {
return ((IMixinDimensionType) this.dimensionType).shouldGenerateSpawnOnLoad();
}
return shouldGenerateSpawn;
}
@Override
public void setGenerateSpawnOnLoad(boolean state) {
this.worldConfig.getConfig().getWorld().setGenerateSpawnOnLoad(state);
}
@Override
public boolean isPVPEnabled() {
return !this.worldConfig.getConfig().isConfigEnabled() || this.worldConfig.getConfig().getWorld().getPVPEnabled();
}
@Override
public void setPVPEnabled(boolean enabled) {
this.worldConfig.getConfig().getWorld().setPVPEnabled(enabled);
}
@Override
public void setUniqueId(UUID uniqueId) {
this.uuid = uniqueId;
}
@Override
public void setIsMod(boolean flag) {
this.isMod = flag;
}
@Override
public void setScoreboard(ServerScoreboard scoreboard) {
this.scoreboard = scoreboard;
}
@Override
public boolean getIsMod() {
return this.isMod;
}
@Override
public SpongeConfig<WorldConfig> getWorldConfig() {
return this.worldConfig;
}
@Override
public Collection<WorldGeneratorModifier> getGeneratorModifiers() {
return WorldGeneratorModifierRegistryModule.getInstance().toModifiers(this.worldConfig.getConfig().getWorldGenModifiers());
}
@Override
public void setGeneratorModifiers(Collection<WorldGeneratorModifier> modifiers) {
checkNotNull(modifiers, "modifiers");
this.worldConfig.getConfig().getWorldGenModifiers().clear();
this.worldConfig.getConfig().getWorldGenModifiers().addAll(WorldGeneratorModifierRegistryModule.getInstance().toIds(modifiers));
}
@Override
public DataContainer getGeneratorSettings() {
// Minecraft uses a String, we want to return a fancy DataContainer
// Parse the world generator settings as JSON
try {
return JsonTranslator.translateFrom(new JsonParser().parse(this.generatorOptions).getAsJsonObject());
} catch (JsonParseException | IllegalStateException ignored) {
}
return new MemoryDataContainer().set(DataQueries.WORLD_CUSTOM_SETTINGS, this.generatorOptions);
}
@Override
public SerializationBehavior getSerializationBehavior() {
return this.serializationBehavior;
}
@Override
public void setSerializationBehavior(SerializationBehavior behavior) {
this.serializationBehavior = behavior;
}
@Override
public Optional<DataView> getPropertySection(DataQuery path) {
if (this.spongeRootLevelNbt.hasKey(path.toString())) {
return Optional
.<DataView>of(NbtTranslator.getInstance().translateFrom(this.spongeRootLevelNbt.getCompoundTag(path.toString())));
} else {
return Optional.empty();
}
}
@Override
public void setPropertySection(DataQuery path, DataView data) {
NBTTagCompound nbt = NbtTranslator.getInstance().translateData(data);
this.spongeRootLevelNbt.setTag(path.toString(), nbt);
}
@Override
public int getIndexForUniqueId(UUID uuid) {
if (this.playerUniqueIdMap.inverse().get(uuid) == null) {
this.playerUniqueIdMap.put(this.trackedUniqueIdCount, uuid);
this.pendingUniqueIds.add(uuid);
return this.trackedUniqueIdCount++;
} else {
return this.playerUniqueIdMap.inverse().get(uuid);
}
}
@Override
public Optional<UUID> getUniqueIdForIndex(int index) {
return Optional.ofNullable(this.playerUniqueIdMap.get(index));
}
@Override
public NBTTagCompound getSpongeRootLevelNbt() {
writeSpongeNbt();
return this.spongeRootLevelNbt;
}
@Override
public NBTTagCompound getSpongeNbt() {
writeSpongeNbt();
return this.spongeNbt;
}
@Override
public void setSpongeRootLevelNBT(NBTTagCompound nbt) {
this.spongeRootLevelNbt = nbt;
if (nbt.hasKey(NbtDataUtil.SPONGE_DATA)) {
this.spongeNbt = nbt.getCompoundTag(NbtDataUtil.SPONGE_DATA);
}
}
@Override
public void readSpongeNbt(NBTTagCompound nbt) {
final UUID nbtUniqueId = nbt.getUniqueId(NbtDataUtil.UUID);
if (nbtUniqueId.equals(UUID.fromString("00000000-0000-0000-0000-000000000000"))) {
return;
}
this.uuid = nbtUniqueId;
this.dimensionId = nbt.getInteger(NbtDataUtil.DIMENSION_ID);
final String dimensionTypeId = nbt.getString(NbtDataUtil.DIMENSION_TYPE);
this.dimensionType = DimensionTypeRegistryModule.getInstance().getById(dimensionTypeId)
.orElseThrow(FunctionalUtil.invalidArgument("Could not find a DimensionType by id: " + dimensionTypeId));
this.isMod = nbt.getBoolean(NbtDataUtil.IS_MOD);
this.generateBonusChest = nbt.getBoolean(NbtDataUtil.GENERATE_BONUS_CHEST);
this.portalAgentType = PortalAgentRegistryModule.getInstance().validatePortalAgent(nbt.getString(NbtDataUtil.PORTAL_AGENT_TYPE), this.levelName);
this.trackedUniqueIdCount = 0;
if (nbt.hasKey(NbtDataUtil.WORLD_SERIALIZATION_BEHAVIOR)) {
short saveBehavior = nbt.getShort(NbtDataUtil.WORLD_SERIALIZATION_BEHAVIOR);
if (saveBehavior == 1) {
this.serializationBehavior = SerializationBehaviors.AUTOMATIC;
} else if (saveBehavior == 0) {
this.serializationBehavior = SerializationBehaviors.MANUAL;
} else {
this.serializationBehavior = SerializationBehaviors.NONE;
}
}
if (nbt.hasKey(NbtDataUtil.SPONGE_PLAYER_UUID_TABLE, NbtDataUtil.TAG_LIST)) {
final NBTTagList playerIdList = nbt.getTagList(NbtDataUtil.SPONGE_PLAYER_UUID_TABLE, NbtDataUtil.TAG_COMPOUND);
for (int i = 0; i < playerIdList.tagCount(); i++) {
final NBTTagCompound playerId = playerIdList.getCompoundTagAt(i);
final UUID playerUuid = playerId.getUniqueId(NbtDataUtil.UUID);
this.playerUniqueIdMap.put(this.trackedUniqueIdCount++, playerUuid);
}
}
}
private void writeSpongeNbt() {
// Never save Sponge data if we have no UUID
if (this.uuid != null) {
this.spongeNbt.setInteger(NbtDataUtil.DATA_VERSION, DataUtil.DATA_VERSION);
this.spongeNbt.setUniqueId(NbtDataUtil.UUID, this.uuid);
this.spongeNbt.setInteger(NbtDataUtil.DIMENSION_ID, this.dimensionId);
this.spongeNbt.setString(NbtDataUtil.DIMENSION_TYPE, this.dimensionType.getId());
this.spongeNbt.setBoolean(NbtDataUtil.IS_MOD, this.isMod);
this.spongeNbt.setBoolean(NbtDataUtil.GENERATE_BONUS_CHEST, this.generateBonusChest);
if (this.portalAgentType == null) {
this.portalAgentType = PortalAgentTypes.DEFAULT;
}
this.spongeNbt.setString(NbtDataUtil.PORTAL_AGENT_TYPE, this.portalAgentType.getPortalAgentClass().getName());
short saveBehavior = 1;
if (this.serializationBehavior == SerializationBehaviors.NONE) {
saveBehavior = -1;
} else if (serializationBehavior == SerializationBehaviors.MANUAL) {
saveBehavior = 0;
}
this.spongeNbt.setShort(NbtDataUtil.WORLD_SERIALIZATION_BEHAVIOR, saveBehavior);
final Iterator<UUID> iterator = this.pendingUniqueIds.iterator();
final NBTTagList playerIdList = this.spongeNbt.getTagList(NbtDataUtil.SPONGE_PLAYER_UUID_TABLE, NbtDataUtil.TAG_COMPOUND);
while (iterator.hasNext()) {
final NBTTagCompound compound = new NBTTagCompound();
compound.setUniqueId(NbtDataUtil.UUID, iterator.next());
playerIdList.appendTag(compound);
iterator.remove();
}
}
}
@Override
public DataContainer getAdditionalProperties() {
NBTTagCompound additionalProperties = this.spongeRootLevelNbt.copy();
additionalProperties.removeTag(SpongeImpl.ECOSYSTEM_NAME);
return NbtTranslator.getInstance().translateFrom(additionalProperties);
}
}