Merge pull request #119 from DevotedMC/master

Bringing main repository up to date in preparation for a release.
master
Daniel Boston 2016-08-05 02:51:35 -04:00 committed by GitHub
commit e3b9e36d6d
6 changed files with 82 additions and 96 deletions

View File

@ -10,6 +10,5 @@ import java.util.HashSet;
import org.bukkit.entity.Player;
public interface IChunkManager {
boolean canResendChunk(int chunkX, int chunkZ);
void resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers);
boolean resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers);
}

View File

@ -4,7 +4,7 @@
<groupId>com.lishid</groupId>
<artifactId>orebfuscator</artifactId>
<version>4.1.2-SNAPSHOT</version>
<version>4.1.4-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Orebfuscator4</name>

View File

@ -24,6 +24,7 @@ import com.lishid.orebfuscator.types.ChunkCoord;
public class ChunkReloader extends Thread implements Runnable {
private static final Map<World, HashSet<ChunkCoord>> loadedChunks = new WeakHashMap<World, HashSet<ChunkCoord>>();
private static final Map<World, HashSet<ChunkCoord>> unloadedChunks = new WeakHashMap<World, HashSet<ChunkCoord>>();
private static final Map<World, HashSet<ChunkCoord>> chunksForReload = new WeakHashMap<World, HashSet<ChunkCoord>>();
private static ChunkReloader thread = new ChunkReloader();
@ -46,11 +47,10 @@ public class ChunkReloader extends Thread implements Runnable {
}
public void run() {
HashSet<ChunkCoord> loadedChunksForProcess = new HashSet<ChunkCoord>();
HashSet<ChunkCoord> unloadedChunksForProcess = new HashSet<ChunkCoord>();
Map<World, HashSet<ChunkCoord>> chunksForReload = new WeakHashMap<World, HashSet<ChunkCoord>>();
HashSet<ChunkCoord> localLoadedChunks = new HashSet<ChunkCoord>();
HashSet<ChunkCoord> localUnloadedChunks = new HashSet<ChunkCoord>();
Map<World, HashSet<ChunkCoord>> localChunksForReload = new WeakHashMap<World, HashSet<ChunkCoord>>();
ArrayList<World> localWorldsToCheck = new ArrayList<World>();
ArrayList<ChunkCoord> reloadedChunks = new ArrayList<ChunkCoord>();
while (!this.isInterrupted() && !kill.get()) {
try {
@ -66,54 +66,62 @@ public class ChunkReloader extends Thread implements Runnable {
}
for(World world : localWorldsToCheck) {
HashSet<ChunkCoord> chunksForReloadForWorld = chunksForReload.get(world);
if(chunksForReloadForWorld == null) {
chunksForReload.put(world, chunksForReloadForWorld = new HashSet<ChunkCoord>());
HashSet<ChunkCoord> localChunksForReloadForWorld = localChunksForReload.get(world);
if(localChunksForReloadForWorld == null) {
localChunksForReload.put(world, localChunksForReloadForWorld = new HashSet<ChunkCoord>());
}
synchronized (chunksForReload) {
HashSet<ChunkCoord> chunksForReloadForWorld = chunksForReload.get(world);
if(chunksForReloadForWorld != null && !chunksForReloadForWorld.isEmpty()) {
localChunksForReloadForWorld.addAll(chunksForReloadForWorld);
chunksForReloadForWorld.clear();
}
}
synchronized (unloadedChunks) {
HashSet<ChunkCoord> unloadedChunksForWorld = unloadedChunks.get(world);
if(unloadedChunksForWorld != null && !unloadedChunksForWorld.isEmpty()) {
unloadedChunksForProcess.addAll(unloadedChunksForWorld);
localUnloadedChunks.addAll(unloadedChunksForWorld);
unloadedChunksForWorld.clear();
}
}
for(ChunkCoord unloadedChunk : unloadedChunksForProcess) {
chunksForReloadForWorld.remove(unloadedChunk);
for(ChunkCoord unloadedChunk : localUnloadedChunks) {
localChunksForReloadForWorld.remove(unloadedChunk);
}
unloadedChunksForProcess.clear();
localUnloadedChunks.clear();
synchronized (loadedChunks) {
HashSet<ChunkCoord> loadedChunksForWorld = loadedChunks.get(world);
if(loadedChunksForWorld != null && !loadedChunksForWorld.isEmpty()) {
loadedChunksForProcess.addAll(loadedChunksForWorld);
localLoadedChunks.addAll(loadedChunksForWorld);
loadedChunksForWorld.clear();
}
}
for(ChunkCoord loadedChunk : loadedChunksForProcess) {
for(ChunkCoord loadedChunk : localLoadedChunks) {
ChunkCoord chunk1 = new ChunkCoord(loadedChunk.x - 1, loadedChunk.z);
ChunkCoord chunk2 = new ChunkCoord(loadedChunk.x + 1, loadedChunk.z);
ChunkCoord chunk3 = new ChunkCoord(loadedChunk.x, loadedChunk.z - 1);
ChunkCoord chunk4 = new ChunkCoord(loadedChunk.x, loadedChunk.z + 1);
chunksForReloadForWorld.add(chunk1);
chunksForReloadForWorld.add(chunk2);
chunksForReloadForWorld.add(chunk3);
chunksForReloadForWorld.add(chunk4);
localChunksForReloadForWorld.add(chunk1);
localChunksForReloadForWorld.add(chunk2);
localChunksForReloadForWorld.add(chunk3);
localChunksForReloadForWorld.add(chunk4);
}
loadedChunksForProcess.clear();
localLoadedChunks.clear();
if(!chunksForReloadForWorld.isEmpty()) {
reloadChunks(world, chunksForReloadForWorld, reloadedChunks);
chunksForReloadForWorld.removeAll(reloadedChunks);
reloadedChunks.clear();
if(!localChunksForReloadForWorld.isEmpty()) {
scheduleReloadChunks(world, localChunksForReloadForWorld);
localChunksForReloadForWorld.clear();
}
}
@ -124,45 +132,51 @@ public class ChunkReloader extends Thread implements Runnable {
}
}
private static void reloadChunks(
World world,
HashSet<ChunkCoord> chunksForReloadForWorld,
ArrayList<ChunkCoord> reloadedChunks
)
{
private static void scheduleReloadChunks(final World world, HashSet<ChunkCoord> chunksForReloadForWorld) {
File cacheFolder = new File(OrebfuscatorConfig.getCacheFolder(), world.getName());
final IChunkManager chunkManager = Orebfuscator.nms.getChunkManager(world);
final ArrayList<ChunkCoord> scheduledChunksForReload = new ArrayList<ChunkCoord>();
final IChunkManager chunkManager = Orebfuscator.nms.getChunkManager(world);
for(ChunkCoord chunk : chunksForReloadForWorld) {
if(!chunkManager.canResendChunk(chunk.x, chunk.z)) continue;
reloadedChunks.add(chunk);
for(final ChunkCoord chunk : chunksForReloadForWorld) {
if(OrebfuscatorConfig.UseCache) {
ObfuscatedCachedChunk cache = new ObfuscatedCachedChunk(cacheFolder, chunk.x, chunk.z);
if(cache.getHash() != 0) continue;
}
scheduledChunksForReload.add(chunk);
//Orebfuscator.log("Add chunk x = " + chunk.x + ", z = " + chunk.z + " to schedule for reload for players");/*debug*/
Orebfuscator.instance.runTask(new Runnable() {
public void run() {
runReloadChunk(world, chunkManager, chunk);
}
});
}
}
private static void runReloadChunk(World world, IChunkManager chunkManager, ChunkCoord chunk) {
//Reload chunk for players
HashSet<Player> affectedPlayers = new HashSet<Player>();
Orebfuscator.instance.runTask(new Runnable() {
public void run() {
//Reload chunk for players
HashSet<Player> affectedPlayers = new HashSet<Player>();
for(ChunkCoord chunk : scheduledChunksForReload) {
chunkManager.resendChunk(chunk.x, chunk.z, affectedPlayers);
if(!world.isChunkLoaded(chunk.x, chunk.z)) return;
if(!chunkManager.resendChunk(chunk.x, chunk.z, affectedPlayers)) {
synchronized (chunksForReload) {
HashSet<ChunkCoord> chunksForReloadForWorld = chunksForReload.get(world);
if(chunksForReloadForWorld == null) {
chunksForReload.put(world, chunksForReloadForWorld = new HashSet<ChunkCoord>());
}
chunksForReloadForWorld.add(chunk);
}
//Orebfuscator.log("Force chunk x = " + chunk.x + ", z = " + chunk.z + " to reload for players");/*debug*/
}
ProximityHider.addPlayersToReload(affectedPlayers);
}
});
//Orebfuscator.log("Is not possible to reload chunk x = " + chunk.x + ", z = " + chunk.z + ", add for later reload");/*debug*/
} else {
//Orebfuscator.log("Force chunk x = " + chunk.x + ", z = " + chunk.z + " to reload for players");/*debug*/
}
if(affectedPlayers.size() > 0) {
ProximityHider.addPlayersToReload(affectedPlayers);
}
}
private static void restart() {

View File

@ -7,7 +7,6 @@ package com.lishid.orebfuscator.nms.v1_10_R1;
import java.util.HashSet;
import net.minecraft.server.v1_10_R1.ChunkProviderServer;
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.PacketPlayOutMapChunk;
import net.minecraft.server.v1_10_R1.PacketPlayOutUnloadChunk;
@ -20,27 +19,17 @@ import com.lishid.orebfuscator.nms.IChunkManager;
public class ChunkManager implements IChunkManager {
private PlayerChunkMap chunkMap;
private ChunkProviderServer chunkProvider;
public ChunkManager(PlayerChunkMap chunkMap) {
this.chunkMap = chunkMap;
this.chunkProvider = this.chunkMap.getWorld().getChunkProviderServer();
}
public boolean canResendChunk(int chunkX, int chunkZ) {
if(!this.chunkProvider.isLoaded(chunkX, chunkZ) || !this.chunkMap.isChunkInUse(chunkX, chunkZ)) return false;
public boolean resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers) {
if(!this.chunkMap.isChunkInUse(chunkX, chunkZ)) return true;
PlayerChunk playerChunk = this.chunkMap.getChunk(chunkX, chunkZ);
return playerChunk != null && playerChunk.chunk != null && playerChunk.chunk.isReady();
}
public void resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers) {
if(!this.chunkMap.isChunkInUse(chunkX, chunkZ)) return;
PlayerChunk playerChunk = this.chunkMap.getChunk(chunkX, chunkZ);
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return;
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return false;
for(EntityPlayer player : playerChunk.c) {
player.playerConnection.sendPacket(new PacketPlayOutUnloadChunk(chunkX, chunkZ));
@ -48,5 +37,7 @@ public class ChunkManager implements IChunkManager {
affectedPlayers.add(player.getBukkitEntity());
}
return true;
}
}

View File

@ -9,7 +9,6 @@ import java.util.HashSet;
import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.Blocks;
import net.minecraft.server.v1_9_R1.ChunkProviderServer;
import net.minecraft.server.v1_9_R1.EntityPlayer;
import net.minecraft.server.v1_9_R1.PlayerChunk;
import net.minecraft.server.v1_9_R1.PlayerChunkMap;
@ -21,27 +20,17 @@ import com.lishid.orebfuscator.nms.IChunkManager;
public class ChunkManager implements IChunkManager {
private PlayerChunkMap chunkMap;
private ChunkProviderServer chunkProvider;
public ChunkManager(PlayerChunkMap chunkMap) {
this.chunkMap = chunkMap;
this.chunkProvider = this.chunkMap.getWorld().getChunkProviderServer();
}
public boolean canResendChunk(int chunkX, int chunkZ) {
if(!this.chunkProvider.isChunkLoaded(chunkX, chunkZ) || !this.chunkMap.isChunkInUse(chunkX, chunkZ)) return false;
public boolean resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers) {
if(!this.chunkMap.isChunkInUse(chunkX, chunkZ)) return true;
PlayerChunk playerChunk = this.chunkMap.b(chunkX, chunkZ);
return playerChunk != null && playerChunk.chunk != null && playerChunk.chunk.isReady();
}
public void resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers) {
if(!this.chunkMap.isChunkInUse(chunkX, chunkZ)) return;
PlayerChunk playerChunk = this.chunkMap.b(chunkX, chunkZ);
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return;
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return false;
WorldServer world = this.chunkMap.getWorld();
@ -58,5 +47,7 @@ public class ChunkManager implements IChunkManager {
for(EntityPlayer player : playerChunk.c) {
affectedPlayers.add(player.getBukkitEntity());
}
return true;
}
}

View File

@ -7,7 +7,6 @@ package com.lishid.orebfuscator.nms.v1_9_R2;
import java.util.HashSet;
import net.minecraft.server.v1_9_R2.ChunkProviderServer;
import net.minecraft.server.v1_9_R2.EntityPlayer;
import net.minecraft.server.v1_9_R2.PacketPlayOutMapChunk;
import net.minecraft.server.v1_9_R2.PacketPlayOutUnloadChunk;
@ -20,27 +19,17 @@ import com.lishid.orebfuscator.nms.IChunkManager;
public class ChunkManager implements IChunkManager {
private PlayerChunkMap chunkMap;
private ChunkProviderServer chunkProvider;
public ChunkManager(PlayerChunkMap chunkMap) {
this.chunkMap = chunkMap;
this.chunkProvider = this.chunkMap.getWorld().getChunkProviderServer();
}
public boolean canResendChunk(int chunkX, int chunkZ) {
if(!this.chunkProvider.isLoaded(chunkX, chunkZ) || !this.chunkMap.isChunkInUse(chunkX, chunkZ)) return false;
public boolean resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers) {
if(!this.chunkMap.isChunkInUse(chunkX, chunkZ)) return true;
PlayerChunk playerChunk = this.chunkMap.getChunk(chunkX, chunkZ);
return playerChunk != null && playerChunk.chunk != null && playerChunk.chunk.isReady();
}
public void resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers) {
if(!this.chunkMap.isChunkInUse(chunkX, chunkZ)) return;
PlayerChunk playerChunk = this.chunkMap.getChunk(chunkX, chunkZ);
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return;
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return false;
for(EntityPlayer player : playerChunk.c) {
player.playerConnection.sendPacket(new PacketPlayOutUnloadChunk(chunkX, chunkZ));
@ -48,5 +37,7 @@ public class ChunkManager implements IChunkManager {
affectedPlayers.add(player.getBukkitEntity());
}
return true;
}
}