13
0

Adding crazy world reset

Dieser Commit ist enthalten in:
Lixfel 2020-10-16 11:34:16 +02:00
Ursprung aef57c490e
Commit 8956c5523e
2 geänderte Dateien mit 41 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -37,7 +37,7 @@ public class BlockTextCreator {
private static BlockArrayClipboard[] createText(String text){ private static BlockArrayClipboard[] createText(String text){
List<BlockArrayClipboard> result = new ArrayList<>(); List<BlockArrayClipboard> result = new ArrayList<>();
for(char c : text.toCharArray()){ for(char c : text.toUpperCase().toCharArray()){
try { try {
result.add((BlockArrayClipboard) new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(SpectateSystem.get().getDataFolder(), "text/" + c + ".schem"))))).read()); result.add((BlockArrayClipboard) new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(SpectateSystem.get().getDataFolder(), "text/" + c + ".schem"))))).read());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -96,7 +96,7 @@ public class BlockTextCreator {
Paster.replaceTeamColor( Paster.replaceTeamColor(
WorldEdit.getInstance().getEditSessionFactory().getEditSession(WORLD, -1), WorldEdit.getInstance().getEditSessionFactory().getEditSession(WORLD, -1),
c, c,
x, y, z, length, 6, 0); x - length / 2, y, z, length, 6, 0);
} }
private static void pasteForTeam(int teamId, int x, int z, boolean rotate, String color){ private static void pasteForTeam(int teamId, int x, int z, boolean rotate, String color){

Datei anzeigen

@ -19,10 +19,20 @@
package de.steamwar.spectatesystem.util; package de.steamwar.spectatesystem.util;
import de.steamwar.spectatesystem.Config;
import de.steamwar.spectatesystem.SpectateSystem; import de.steamwar.spectatesystem.SpectateSystem;
import de.steamwar.spectatesystem.elements.REntity; import de.steamwar.spectatesystem.elements.REntity;
import net.minecraft.server.v1_15_R1.Block;
import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.WorldServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import java.util.Objects;
public class WorldLoader { public class WorldLoader {
private WorldLoader(){} private WorldLoader(){}
@ -32,17 +42,35 @@ public class WorldLoader {
public static void reloadWorld(){ public static void reloadWorld(){
Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> {
REntity.removeAll(); REntity.removeAll();
/*
Chunk[] chunks = world.getLoadedChunks(); WorldServer cworld = ((CraftWorld)world).getHandle();
PlayerChunkMap playerChunkMap = ((CraftWorld)world).getHandle().getChunkProvider().playerChunkMap; WorldServer backup = ((CraftWorld) Objects.requireNonNull(new WorldCreator(world.getName() + "-backup").createWorld())).getHandle();
for(long l : playerChunkMap.updatingChunks.keySet())
playerChunkMap.unloadQueue.add(l); for(int cX = Config.ArenaMinX / 16; cX <= Config.ArenaMaxX / 16; cX++){
System.out.println(world.getLoadedChunks().length); for(int cZ = Config.ArenaMinZ / 16; cZ <= Config.ArenaMaxZ / 16; cZ++){
for(Chunk chunk: chunks){ long start = System.currentTimeMillis();
//world.getChunkAt(chunk.getX(), chunk.getZ()); int changedBlocks = 0;
for(Player player : Bukkit.getOnlinePlayers()) net.minecraft.server.v1_15_R1.Chunk cchunk = ((CraftChunk) world.getChunkAt(cX, cZ)).getHandle();
((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)chunk).getHandle(), 65535)); for(int y = 255; y >= 0; y--){ // y top down to reduce lightning calculations
}*/ for(int x = cX * 16; x < (cX + 1) * 16; x++){
for(int z = cZ; z < (cZ + 1) * 16; z++){
BlockPosition blockPos = new BlockPosition(x, y, z);
IBlockData backupBlock = backup.getType(blockPos);
if(Block.REGISTRY_ID.getId(backupBlock) == Block.REGISTRY_ID.getId(cchunk.getType(blockPos)))
continue;
changedBlocks++;
cchunk.removeTileEntity(blockPos);
cworld.setTypeAndData(blockPos, backupBlock, 1042);
cworld.getChunkProvider().flagDirty(blockPos);
}
}
}
System.out.println("Resetted " + changedBlocks + " in " + (System.currentTimeMillis() - start) + "ms");
}
}
Bukkit.unloadWorld(world.getName() + "-backup", false);
}); });
} }
} }