diff --git a/server/src/main/java/server/command/CommandEnvironment.java b/server/src/main/java/server/command/CommandEnvironment.java index 4a67f7ba..cb2b63b2 100644 --- a/server/src/main/java/server/command/CommandEnvironment.java +++ b/server/src/main/java/server/command/CommandEnvironment.java @@ -277,5 +277,7 @@ public class CommandEnvironment { this.registerExecutable(new CommandShowwarp()); this.registerExecutable(new CommandTphere()); this.registerExecutable(new CommandEffect()); + this.registerExecutable(new CommandExterminatus()); + this.registerExecutable(new CommandReset()); } } diff --git a/server/src/main/java/server/command/commands/CommandExterminatus.java b/server/src/main/java/server/command/commands/CommandExterminatus.java new file mode 100644 index 00000000..91025584 --- /dev/null +++ b/server/src/main/java/server/command/commands/CommandExterminatus.java @@ -0,0 +1,27 @@ +package server.command.commands; + +import common.color.TextColor; +import common.dimension.Space; +import server.command.Command; +import server.command.CommandEnvironment; +import server.command.Executor; +import server.command.RunException; +import server.world.WorldServer; + +public class CommandExterminatus extends Command { + public CommandExterminatus() { + super("exterminatus"); + + this.addWorld("dim", true); + } + + public void exec(CommandEnvironment env, Executor exec, WorldServer world) { + if(world.dimension == Space.INSTANCE) + throw new RunException("Der Weltraum kann nicht zerstört werden (lol?)"); + else if(world.isExterminated()) + throw new RunException("Dimension %s ist bereits zerstört", world.dimension.getFormattedName(false)); + exec.log(TextColor.YELLOW + "Dimension %s wird zerstört ...", world.dimension.getFormattedName(false)); + world.exterminate(); + exec.log(TextColor.CRIMSON + "Die Welt %s wurde vernichtet >:)-", world.dimension.getFormattedName(false)); + } +} diff --git a/server/src/main/java/server/command/commands/CommandReset.java b/server/src/main/java/server/command/commands/CommandReset.java new file mode 100644 index 00000000..c4552542 --- /dev/null +++ b/server/src/main/java/server/command/commands/CommandReset.java @@ -0,0 +1,20 @@ +package server.command.commands; + +import server.command.Command; +import server.command.CommandEnvironment; +import server.command.Executor; +import server.world.WorldServer; + +public class CommandReset extends Command { + public CommandReset() { + super("reset"); + + this.addWorld("dim", true); + } + + public void exec(CommandEnvironment env, Executor exec, WorldServer world) { + exec.log("Dimension %s wird zurückgesetzt ...", world.dimension.getFormattedName(false)); + world.reset(); + exec.log("Dimension %s zurückgesetzt", world.dimension.getFormattedName(false)); + } +} diff --git a/server/src/main/java/server/world/WorldServer.java b/server/src/main/java/server/world/WorldServer.java index f0acf312..b3bfd64f 100755 --- a/server/src/main/java/server/world/WorldServer.java +++ b/server/src/main/java/server/world/WorldServer.java @@ -353,90 +353,7 @@ public final class WorldServer extends AWorldServer { if(this.exterminated) this.weather = Weather.CLEAR; this.grng = new Random(this.seed); -// GeneratorSettings settings = !debug && !this.exterminated ? dim.getSettings() : null; - if(this.exterminated) { - this.setExterminatedGen(); - } -// else if(settings != null) { -//// settings = settings == null ? new GeneratorSettings() : settings; -// this.liquid = settings.useLavaSeas ? Blocks.lava.getDefaultState() : Blocks.water.getDefaultState(); -// this.biomeGen = new BiomeGenNew(this.seed, settings); -// switch(settings.genMode) { -// case 0: -// this.generator = new GeneratorFlat(settings); -// break; -// case 1: -// default: -// this.generator = new GeneratorNew(this.grng, settings); -// break; -// case 2: -// this.generator = new GeneratorSimple(this.seed, this.grng, settings); -// break; -// } -// switch(settings.replMode) { -// case 0: -// this.replacer = null; -// break; -// case 1: -// default: -// this.replacer = new ReplacerBiome(this.grng); -// break; -// case 2: -// this.replacer = new ReplacerAltBiome(this.grng, settings); -// break; -// } -// this.populator = settings.populate == 0 ? null : -// (settings.populate == 2 ? new PopulatorSimple(this.grng, settings) : new PopulatorNew(this.grng, settings)); -// this.caveGen = settings.useCaves ? -// (new MapGenCaves(settings.caveFill == 1 ? Blocks.lava.getDefaultState() : -// (settings.caveFill == 2 ? Blocks.water.getDefaultState() : Blocks.air.getDefaultState()), Blocks.stone, -// Blocks.dirt, Blocks.grass, Blocks.gravel)) : null; -// this.bigCaveGen = null; -// this.ravineGen = settings.useRavines ? -// (new MapGenRavine(settings.ravineFill == 1 ? Blocks.flowing_lava.getDefaultState() : (settings.ravineFill == 2 -// ? Blocks.flowing_water.getDefaultState() : Blocks.air.getDefaultState()), Blocks.stone, Blocks.dirt, Blocks.grass)) : null; -// this.base = settings.useBedrock ? Blocks.bedrock.getDefaultState() : null; -// this.ceil = null; -// this.mobs = settings.mobs; -// this.snow = settings.snow; -// this.strongholdGen = settings.useStrongholds ? new MapGenStronghold() : null; -// this.villageGen = settings.useVillages ? new MapGenVillage() : null; -// this.mineshaftGen = settings.useMineShafts ? new MapGenMineshaft() : null; -// this.scatteredGen = settings.useScattered ? new MapGenScatteredFeature() : null; -// this.bridgeGen = null; -// this.seaLevel = settings.genMode == 0 ? this.generator.getMaximumHeight() : settings.seaLevel; -// this.ores = new FeatureOres[settings.oreList.size()]; -// for(int z = 0; z < settings.oreList.size(); z++) { -// this.ores[z] = settings.oreList.get(z).createGenerator(); -// } -//// PlanetTerra.setOres(settings.oreList); -// } - else { - this.liquid = this.dimension.getLiquid(); - this.biomeGen = this.createBiomeGenerator(this.grng); - this.generator = this.createChunkGenerator(this.grng); - this.replacer = this.createBlockReplacer(this.grng); - this.populate = this.dimension.hasPopulator(); - this.caveGen = this.createCaveGenerator(); - this.bigCaveGen = this.createBigCaveGenerator(); - this.ravineGen = this.createRavineGenerator(); - this.base = this.dimension.getFiller().getBlock() != Blocks.air && this.dimension.getGeneratorType() != GeneratorType.FLAT; - this.ceil = this.dimension.hasWorldCeiling(); - this.mobs = this.dimension.hasMobs(); - this.snow = this.dimension.hasSnow(); - this.strongholdGen = this.dimension.hasStrongholds() ? new MapGenStronghold() : null; - this.villageGen = this.dimension.hasVillages() ? new MapGenVillage() : null; - this.mineshaftGen = this.dimension.hasMineshafts() ? new MapGenMineshaft() : null; - this.scatteredGen = this.dimension.hasScattered() ? new MapGenScatteredFeature() : null; - this.bridgeGen = this.dimension.hasFortresses() ? new MapGenBridge() : null; - this.seaLevel = this.dimension.getSeaLevel(); - this.ores = this.createOres(); - this.lakes = this.createLakes(); - this.liquids = this.createLiquids(); - this.dungeons = this.createDungeonGenerator(); - } - this.height = this.generator.getMaximumHeight(); -// this.teleporter = new Teleporter(this); + this.initGenerator(this.exterminated); this.calculateInitialSkylight(); this.calculateInitialWeather(); this.updatePhysics(); @@ -457,18 +374,6 @@ public final class WorldServer extends AWorldServer { } this.loadersModified = false; } - if(this.villageGen != null) { - tag = null; - try { - File dat = new File(this.chunkDir, "villages.cdt"); - if(dat.exists() && dat.isFile()) - tag = TagObject.readGZip(dat); - } - catch(Exception e) { - Log.IO.error(e, "Konnte Dorfliste nicht laden"); - } - this.villageStorage = new VillageCollection(tag); - } } public Server getServer() { @@ -1620,9 +1525,23 @@ public final class WorldServer extends AWorldServer { public boolean exterminate() { if(this.exterminated) return false; - this.setWeather(Weather.CLEAR); + this.resetData(true); + this.reloadChunks(); + for(EntityNPC player : this.players) { + player.attackEntityFrom(DamageSource.causeExterminatusDamage(null), 5000); + Packet packet = new SPacketEffect(1025, new BlockPos(player.posX, (double)this.getSeaLevel() + 4.0, player.posZ), 0); + player.connection.sendPacket(packet); + } + return true; + } + + public void reset() { + this.resetData(false); + } + + private void resetData(boolean exterminated) { + this.setWeather(exterminated ? Weather.CLEAR : this.dimension.getWeather()); this.resetWeather(); -// this.updateWeather(); if(!this.loaderList.isEmpty()) this.loadersModified = true; for(BlockPos pos : this.loaderList) { @@ -1637,11 +1556,15 @@ public final class WorldServer extends AWorldServer { Region.finishWrite(); deleteFiles(this.chunkDir.listFiles(new FileFilter() { public boolean accept(File file) { - return file.isDirectory(); + return file.isDirectory() || !file.getName().equals("data.cdt"); } })); - this.exterminated = true; -// this.dataModified = true; + this.exterminated = exterminated; + this.initGenerator(exterminated); + this.reloadChunks(); + } + + private void reloadChunks() { for(Long v : this.dropped) { ChunkServer chunk = this.chunks.getValueByKey(v.longValue()); if(chunk != null) { @@ -1653,7 +1576,6 @@ public final class WorldServer extends AWorldServer { this.dropped.clear(); List loaded = Lists.newArrayList(this.loaded); this.loaded.clear(); - this.setExterminatedGen(); for(ChunkServer chunk : loaded) { long pos = LongHashMap.packInt(chunk.xPos, chunk.zPos); chunk.onChunkUnload(); @@ -1662,10 +1584,11 @@ public final class WorldServer extends AWorldServer { this.chunks.add(pos, chunk); this.loaded.add(chunk); chunk.onChunkLoad(); - chunk.checkLight(); - chunk.setModified(true); +// chunk.checkLight(); +// chunk.setModified(true); } for(ChunkServer chunk : this.loaded) { + this.popChunk(chunk.xPos, chunk.zPos); chunk.update(false); } this.entities.removeAll(this.unloaded); @@ -1685,39 +1608,48 @@ public final class WorldServer extends AWorldServer { for(int z = 0; z < this.instList.size(); ++z) { this.instList.get(z).resend(); } - for(EntityNPC player : this.players) { - player.attackEntityFrom(DamageSource.causeExterminatusDamage(null), 5000); - Packet packet = new SPacketEffect(1025, new BlockPos(player.posX, (double)this.getSeaLevel() + 4.0, player.posZ), 0); - player.connection.sendPacket(packet); - } - return true; } - private void setExterminatedGen() { - this.mobs = false; - this.snow = false; - this.caveGen = null; - this.bigCaveGen = null; - this.ravineGen = null; - this.strongholdGen = null; - this.villageGen = null; - this.villageStorage = null; - this.mineshaftGen = null; - this.scatteredGen = null; - this.bridgeGen = null; - this.generator = new GeneratorDestroyed(this.dimension.getSeaLevel()); - this.biomeGen = new BiomeGenSingle(Biome.EXTERMINATED); - this.replacer = null; - this.populate = false; - this.liquid = Blocks.air.getState(); - this.base = false; - this.ceil = false; - this.height = this.generator.getMaximumHeight(); + private void initGenerator(boolean exterminated) { + this.grng.setSeed(this.seed); + this.liquid = exterminated ? Blocks.air.getState() : this.dimension.getLiquid(); + this.biomeGen = exterminated ? new BiomeGenSingle(Biome.EXTERMINATED) : this.createBiomeGenerator(this.grng); + this.generator = exterminated ? new GeneratorDestroyed(this.dimension.getSeaLevel()) : this.createChunkGenerator(this.grng); + this.replacer = exterminated ? null : this.createBlockReplacer(this.grng); + this.populate = !exterminated && this.dimension.hasPopulator(); + this.caveGen = exterminated ? null : this.createCaveGenerator(); + this.bigCaveGen = exterminated ? null : this.createBigCaveGenerator(); + this.ravineGen = exterminated ? null : this.createRavineGenerator(); + this.base = !exterminated && this.dimension.getFiller().getBlock() != Blocks.air && this.dimension.getGeneratorType() != GeneratorType.FLAT; + this.ceil = !exterminated && this.dimension.hasWorldCeiling(); + this.mobs = !exterminated && this.dimension.hasMobs(); + this.snow = !exterminated && this.dimension.hasSnow(); + this.strongholdGen = !exterminated && this.dimension.hasStrongholds() ? new MapGenStronghold() : null; + this.villageGen = !exterminated && this.dimension.hasVillages() ? new MapGenVillage() : null; + this.mineshaftGen = !exterminated && this.dimension.hasMineshafts() ? new MapGenMineshaft() : null; + this.scatteredGen = !exterminated && this.dimension.hasScattered() ? new MapGenScatteredFeature() : null; + this.bridgeGen = !exterminated && this.dimension.hasFortresses() ? new MapGenBridge() : null; this.seaLevel = this.dimension.getSeaLevel(); - this.ores = null; - this.lakes = null; - this.liquids = null; - this.dungeons = null; + this.ores = exterminated ? null : this.createOres(); + this.lakes = exterminated ? null : this.createLakes(); + this.liquids = exterminated ? null : this.createLiquids(); + this.dungeons = exterminated ? null : this.createDungeonGenerator(); + this.height = this.generator.getMaximumHeight(); + if(this.villageGen != null) { + TagObject tag = null; + try { + File dat = new File(this.chunkDir, "villages.cdt"); + if(dat.exists() && dat.isFile()) + tag = TagObject.readGZip(dat); + } + catch(Exception e) { + Log.IO.error(e, "Konnte Dorfliste nicht laden"); + } + this.villageStorage = new VillageCollection(tag); + } + else { + this.villageStorage = null; + } } public static String getLoadedInfo(Server server) {