Merge pull request #185 from DevotedMC/master

Fix for fake ores. Refactoring.
master
Daniel Boston 2018-09-09 06:39:08 -04:00 committed by GitHub
commit d4ef3d6304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 88 additions and 671 deletions

View File

@ -1,14 +0,0 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.nms;
import java.util.HashSet;
import org.bukkit.entity.Player;
public interface IChunkManager {
boolean resendChunk(int chunkX, int chunkZ, HashSet<Player> affectedPlayers);
}

View File

@ -16,8 +16,6 @@ public interface INBT {
void setLong(String tag, long value);
void setBoolean(String tag, boolean value);
void setByteArray(String tag, byte[] value);
void setIntArray(String tag, int[] value);
@ -26,8 +24,6 @@ public interface INBT {
long getLong(String tag);
boolean getBoolean(String tag);
byte[] getByteArray(String tag);
int[] getIntArray(String tag);

View File

@ -18,8 +18,6 @@ public interface INmsManager {
IChunkCache createChunkCache();
IChunkManager getChunkManager(World world);
void updateBlockTileEntity(BlockCoord blockCoord, Player player);
void notifyBlockChange(World world, IBlockInfo blockInfo);
@ -31,6 +29,8 @@ public interface INmsManager {
BlockState getBlockState(World world, int x, int y, int z);
int getBlockId(World world, int x, int y, int z);
int loadChunkAndGetBlockId(World world, int x, int y, int z);
String getTextFromChatComponent(String json);
}

View File

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

View File

@ -33,7 +33,6 @@ import com.lishid.orebfuscator.config.OrebfuscatorConfig;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import com.lishid.orebfuscator.hook.ProtocolLibHook;
import com.lishid.orebfuscator.listeners.OrebfuscatorBlockListener;
import com.lishid.orebfuscator.listeners.OrebfuscatorChunkListener;
import com.lishid.orebfuscator.listeners.OrebfuscatorEntityListener;
import com.lishid.orebfuscator.listeners.OrebfuscatorPlayerListener;
import com.lishid.orebfuscator.nms.INmsManager;
@ -83,8 +82,7 @@ public class Orebfuscator extends JavaPlugin {
pm.registerEvents(new OrebfuscatorPlayerListener(), this);
pm.registerEvents(new OrebfuscatorEntityListener(), this);
pm.registerEvents(new OrebfuscatorBlockListener(), this);
pm.registerEvents(new OrebfuscatorChunkListener(), this);
(new ProtocolLibHook()).register(this);
// Run CacheCleaner

View File

@ -44,8 +44,6 @@ public class OrebfuscatorConfig {
private static final int antiHitHackDecrementFactor = 1000;
private static final int antiHitHackMaxViolation = 15;
private static final int proximityHiderRate = 500;
private static final int chunkReloaderRate = 500;
private static final boolean useChunkReloader = false;
private static final long cacheCleanRate = 60 * 60 * 20;//once per hour
public boolean isUseCache() {
@ -254,14 +252,6 @@ public class OrebfuscatorConfig {
return proximityHiderRate;
}
public int getChunkReloaderRate() {
return chunkReloaderRate;
}
public boolean isUseChunkReloader() {
return useChunkReloader;
}
public long getCacheCleanRate() {
return cacheCleanRate;
}

View File

@ -1,33 +0,0 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.listeners;
import org.bukkit.Chunk;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import com.lishid.orebfuscator.obfuscation.ChunkReloader;
public class OrebfuscatorChunkListener implements Listener {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkLoad(ChunkLoadEvent event) {
Chunk chunk = event.getChunk();
ChunkReloader.addLoadedChunk(event.getWorld(), chunk.getX(), chunk.getZ());
//Orebfuscator.log("Chunk x = " + chunk.getX() + ", z = " + chunk.getZ() + " is loaded");/*debug*/
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) {
Chunk chunk = event.getChunk();
ChunkReloader.addUnloadedChunk(event.getWorld(), chunk.getX(), chunk.getZ());
//Orebfuscator.log("Chunk x = " + chunk.getX() + ", z = " + chunk.getZ() + " is unloaded");/*debug*/
}
}

View File

@ -376,10 +376,10 @@ public class Calculations {
int id;
if (blockData < 0) {
id = Orebfuscator.nms.getBlockId(world, x, y, z);
id = Orebfuscator.nms.loadChunkAndGetBlockId(world, x, y, z);
if (id < 0) {
id = 1;
id = 1;// Stone
chunkData.useCache = false;
}
} else {

View File

@ -1,242 +0,0 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.obfuscation;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.cache.ObfuscatedCachedChunk;
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
import com.lishid.orebfuscator.config.ProximityHiderConfig;
import com.lishid.orebfuscator.nms.IChunkManager;
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();
private long lastExecute = System.currentTimeMillis();
private AtomicBoolean kill = new AtomicBoolean(false);
public static void Load() {
if (thread == null || thread.isInterrupted() || !thread.isAlive()) {
thread = new ChunkReloader();
thread.setName("Orebfuscator ChunkReloader Thread");
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
}
public static void terminate() {
if (thread != null) {
thread.kill.set(true);
}
}
public void run() {
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>();
while (!this.isInterrupted() && !kill.get()) {
try {
// Wait until necessary
long timeWait = lastExecute + Orebfuscator.config.getChunkReloaderRate() - System.currentTimeMillis();
lastExecute = System.currentTimeMillis();
if (timeWait > 0) {
Thread.sleep(timeWait);
}
if (!Orebfuscator.config.isUseChunkReloader()) {
return;
}
synchronized (loadedChunks) {
localWorldsToCheck.addAll(loadedChunks.keySet());
}
for(World world : localWorldsToCheck) {
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()) {
localUnloadedChunks.addAll(unloadedChunksForWorld);
unloadedChunksForWorld.clear();
}
}
for(ChunkCoord unloadedChunk : localUnloadedChunks) {
localChunksForReloadForWorld.remove(unloadedChunk);
}
localUnloadedChunks.clear();
synchronized (loadedChunks) {
HashSet<ChunkCoord> loadedChunksForWorld = loadedChunks.get(world);
if(loadedChunksForWorld != null && !loadedChunksForWorld.isEmpty()) {
localLoadedChunks.addAll(loadedChunksForWorld);
loadedChunksForWorld.clear();
}
}
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);
localChunksForReloadForWorld.add(chunk1);
localChunksForReloadForWorld.add(chunk2);
localChunksForReloadForWorld.add(chunk3);
localChunksForReloadForWorld.add(chunk4);
}
localLoadedChunks.clear();
if(!localChunksForReloadForWorld.isEmpty()) {
scheduleReloadChunks(world, localChunksForReloadForWorld);
localChunksForReloadForWorld.clear();
}
}
localWorldsToCheck.clear();
} catch (Exception e) {
Orebfuscator.log(e);
}
}
}
private static void scheduleReloadChunks(final World world, HashSet<ChunkCoord> chunksForReloadForWorld) {
File cacheFolder = new File(ObfuscatedDataCache.getCacheFolder(), world.getName());
final IChunkManager chunkManager = Orebfuscator.nms.getChunkManager(world);
for(final ChunkCoord chunk : chunksForReloadForWorld) {
if(Orebfuscator.config.isUseCache()) {
ObfuscatedCachedChunk cache = new ObfuscatedCachedChunk(cacheFolder, chunk.x, chunk.z);
if(cache.getHash() != 0) continue;
}
//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>();
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("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) {
ProximityHiderConfig proximityHider = Orebfuscator.configManager.getWorld(world).getProximityHiderConfig();
if(proximityHider.isEnabled()) {
ProximityHider.addPlayersToReload(affectedPlayers);
}
}
}
private static void restart() {
synchronized (thread) {
if (thread.isInterrupted() || !thread.isAlive()) {
ChunkReloader.Load();
}
}
}
public static void addLoadedChunk(World world, int chunkX, int chunkZ) {
if (!Orebfuscator.config.isEnabled() // Plugin enabled
|| !Orebfuscator.config.isUseChunkReloader()
|| !Orebfuscator.configManager.getWorld(world).isEnabled() // World not enabled
)
{
return;
}
restart();
synchronized (loadedChunks) {
HashSet<ChunkCoord> chunks = loadedChunks.get(world);
if(chunks == null) {
loadedChunks.put(world, chunks = new HashSet<ChunkCoord>());
}
chunks.add(new ChunkCoord(chunkX, chunkZ));
}
}
public static void addUnloadedChunk(World world, int chunkX, int chunkZ) {
if (!Orebfuscator.config.isEnabled() // Plugin enabled
|| !Orebfuscator.config.isUseChunkReloader()
|| !Orebfuscator.configManager.getWorld(world).isEnabled() // World not enabled
)
{
return;
}
restart();
synchronized (unloadedChunks) {
HashSet<ChunkCoord> chunks = unloadedChunks.get(world);
if(chunks == null) {
unloadedChunks.put(world, chunks = new HashSet<ChunkCoord>());
}
chunks.add(new ChunkCoord(chunkX, chunkZ));
}
}
}

View File

@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.bukkit.Location;
@ -35,13 +34,13 @@ import com.lishid.orebfuscator.types.BlockCoord;
import com.lishid.orebfuscator.types.BlockState;
public class ProximityHider extends Thread implements Runnable {
private static final Map<Player, ProximityHiderPlayer> proximityHiderTracker = new WeakHashMap<Player, ProximityHiderPlayer>();
private static final Map<Player, ProximityHiderPlayer> proximityHiderTracker = new HashMap<Player, ProximityHiderPlayer>();
private static final Map<Player, Location> playersToCheck = new HashMap<Player, Location>();
private static final HashSet<Player> playersToReload = new HashSet<Player>();
private static ProximityHider thread = new ProximityHider();
private Map<Player, ProximityHiderPlayer> proximityHiderTrackerLocal = new WeakHashMap<Player, ProximityHiderPlayer>();
private Map<Player, ProximityHiderPlayer> proximityHiderTrackerLocal = new HashMap<Player, ProximityHiderPlayer>();
private long lastExecute = System.currentTimeMillis();
private AtomicBoolean kill = new AtomicBoolean(false);
private static boolean running = false;
@ -327,6 +326,14 @@ public class ProximityHider extends Thread implements Runnable {
synchronized (proximityHiderTracker) {
proximityHiderTracker.remove(player);
}
synchronized (playersToCheck) {
playersToCheck.remove(player);
}
synchronized (playersToReload) {
playersToReload.remove(player);
}
}
public static void clearBlocksForOldWorld(Player player) {

View File

@ -2,6 +2,7 @@ name: ${project.name}
main: com.lishid.orebfuscator.Orebfuscator
version: ${project.version}
author: lishid
authors: [Aleksey-Terzi, ProgrammerDan]
softdepend: [ProtocolLib]
load: startup
description: 'The most powerful and efficient Anti Xray plugin compatible with any CraftBukkit fork!'

View File

@ -1,43 +0,0 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.nms.v1_10_R1;
import java.util.HashSet;
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.PacketPlayOutMapChunk;
import net.minecraft.server.v1_10_R1.PacketPlayOutUnloadChunk;
import net.minecraft.server.v1_10_R1.PlayerChunk;
import net.minecraft.server.v1_10_R1.PlayerChunkMap;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IChunkManager;
public class ChunkManager implements IChunkManager {
private PlayerChunkMap chunkMap;
public ChunkManager(PlayerChunkMap chunkMap) {
this.chunkMap = chunkMap;
}
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);
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return false;
for(EntityPlayer player : playerChunk.c) {
player.playerConnection.sendPacket(new PacketPlayOutUnloadChunk(chunkX, chunkZ));
player.playerConnection.sendPacket(new PacketPlayOutMapChunk(playerChunk.chunk, 0xffff));
affectedPlayers.add(player.getBukkitEntity());
}
return true;
}
}

View File

@ -31,10 +31,6 @@ public class NBT implements INBT {
nbt.setLong(tag, value);
}
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@ -51,10 +47,6 @@ public class NBT implements INBT {
return nbt.getLong(tag);
}
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}

View File

@ -13,7 +13,6 @@ import net.minecraft.server.v1_10_R1.ChunkProviderServer;
import net.minecraft.server.v1_10_R1.IBlockData;
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
import net.minecraft.server.v1_10_R1.Packet;
import net.minecraft.server.v1_10_R1.PlayerChunkMap;
import net.minecraft.server.v1_10_R1.TileEntity;
import net.minecraft.server.v1_10_R1.WorldServer;
@ -25,7 +24,6 @@ import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IBlockInfo;
import com.lishid.orebfuscator.nms.IChunkCache;
import com.lishid.orebfuscator.nms.IChunkManager;
import com.lishid.orebfuscator.nms.INBT;
import com.lishid.orebfuscator.nms.INmsManager;
import com.lishid.orebfuscator.types.BlockCoord;
@ -47,14 +45,6 @@ public class NmsManager implements INmsManager {
return new ChunkCache(this.maxLoadedCacheFiles);
}
@Override
public IChunkManager getChunkManager(World world) {
WorldServer worldServer = ((CraftWorld)world).getHandle();
PlayerChunkMap chunkMap = worldServer.getPlayerChunkMap();
return new ChunkManager(chunkMap);
}
@Override
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
CraftWorld world = (CraftWorld)player.getWorld();
@ -87,7 +77,7 @@ public class NmsManager implements INmsManager {
@Override
public IBlockInfo getBlockInfo(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null
? new BlockInfo(x, y, z, blockData)
@ -96,7 +86,7 @@ public class NmsManager implements INmsManager {
@Override
public BlockState getBlockState(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
if(blockData == null) return null;
@ -111,10 +101,16 @@ public class NmsManager implements INmsManager {
@Override
public int getBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
@Override
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z, true);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
@Override
public String getTextFromChatComponent(String json) {
@ -122,17 +118,17 @@ public class NmsManager implements INmsManager {
return CraftChatMessage.fromComponent(component);
}
private static IBlockData getBlockData(World world, int x, int y, int z) {
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
int chunkX = x >> 4;
int chunkZ = z >> 4;
WorldServer worldServer = ((CraftWorld)world).getHandle();
ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer();
if(!chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
if(!loadChunk && !chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
Chunk chunk = chunkProviderServer.getOrLoadChunkAt(chunkX, chunkZ);
return chunk.getBlockData(new BlockPosition(x, y, z));
return chunk != null ? chunk.getBlockData(new BlockPosition(x, y, z)) : null;
}
}

View File

@ -1,43 +0,0 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.nms.v1_11_R1;
import java.util.HashSet;
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.PacketPlayOutMapChunk;
import net.minecraft.server.v1_11_R1.PacketPlayOutUnloadChunk;
import net.minecraft.server.v1_11_R1.PlayerChunk;
import net.minecraft.server.v1_11_R1.PlayerChunkMap;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IChunkManager;
public class ChunkManager implements IChunkManager {
private PlayerChunkMap chunkMap;
public ChunkManager(PlayerChunkMap chunkMap) {
this.chunkMap = chunkMap;
}
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);
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return false;
for(EntityPlayer player : playerChunk.c) {
player.playerConnection.sendPacket(new PacketPlayOutUnloadChunk(chunkX, chunkZ));
player.playerConnection.sendPacket(new PacketPlayOutMapChunk(playerChunk.chunk, 0xffff));
affectedPlayers.add(player.getBukkitEntity());
}
return true;
}
}

View File

@ -31,10 +31,6 @@ public class NBT implements INBT {
nbt.setLong(tag, value);
}
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@ -51,10 +47,6 @@ public class NBT implements INBT {
return nbt.getLong(tag);
}
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}

View File

@ -13,7 +13,6 @@ import net.minecraft.server.v1_11_R1.ChunkProviderServer;
import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
import net.minecraft.server.v1_11_R1.Packet;
import net.minecraft.server.v1_11_R1.PlayerChunkMap;
import net.minecraft.server.v1_11_R1.TileEntity;
import net.minecraft.server.v1_11_R1.WorldServer;
@ -25,7 +24,6 @@ import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IBlockInfo;
import com.lishid.orebfuscator.nms.IChunkCache;
import com.lishid.orebfuscator.nms.IChunkManager;
import com.lishid.orebfuscator.nms.INBT;
import com.lishid.orebfuscator.nms.INmsManager;
import com.lishid.orebfuscator.types.BlockCoord;
@ -47,14 +45,6 @@ public class NmsManager implements INmsManager {
return new ChunkCache(this.maxLoadedCacheFiles);
}
@Override
public IChunkManager getChunkManager(World world) {
WorldServer worldServer = ((CraftWorld)world).getHandle();
PlayerChunkMap chunkMap = worldServer.getPlayerChunkMap();
return new ChunkManager(chunkMap);
}
@Override
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
CraftWorld world = (CraftWorld)player.getWorld();
@ -87,7 +77,7 @@ public class NmsManager implements INmsManager {
@Override
public IBlockInfo getBlockInfo(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null
? new BlockInfo(x, y, z, blockData)
@ -96,7 +86,7 @@ public class NmsManager implements INmsManager {
@Override
public BlockState getBlockState(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
if(blockData == null) return null;
@ -111,28 +101,34 @@ public class NmsManager implements INmsManager {
@Override
public int getBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
@Override
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z, true);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
@Override
public String getTextFromChatComponent(String json) {
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
return CraftChatMessage.fromComponent(component);
}
private static IBlockData getBlockData(World world, int x, int y, int z) {
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
int chunkX = x >> 4;
int chunkZ = z >> 4;
WorldServer worldServer = ((CraftWorld)world).getHandle();
ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer();
if(!chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
if(!loadChunk && !chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
Chunk chunk = chunkProviderServer.getOrLoadChunkAt(chunkX, chunkZ);
return chunk.getBlockData(new BlockPosition(x, y, z));
return chunk != null ? chunk.getBlockData(new BlockPosition(x, y, z)) : null;
}
}

View File

@ -1,43 +0,0 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.nms.v1_12_R1;
import java.util.HashSet;
import net.minecraft.server.v1_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk;
import net.minecraft.server.v1_12_R1.PacketPlayOutUnloadChunk;
import net.minecraft.server.v1_12_R1.PlayerChunk;
import net.minecraft.server.v1_12_R1.PlayerChunkMap;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IChunkManager;
public class ChunkManager implements IChunkManager {
private PlayerChunkMap chunkMap;
public ChunkManager(PlayerChunkMap chunkMap) {
this.chunkMap = chunkMap;
}
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);
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return false;
for(EntityPlayer player : playerChunk.c) {
player.playerConnection.sendPacket(new PacketPlayOutUnloadChunk(chunkX, chunkZ));
player.playerConnection.sendPacket(new PacketPlayOutMapChunk(playerChunk.chunk, 0xffff));
affectedPlayers.add(player.getBukkitEntity());
}
return true;
}
}

View File

@ -31,10 +31,6 @@ public class NBT implements INBT {
nbt.setLong(tag, value);
}
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@ -51,10 +47,6 @@ public class NBT implements INBT {
return nbt.getLong(tag);
}
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}

View File

@ -13,7 +13,6 @@ import net.minecraft.server.v1_12_R1.ChunkProviderServer;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
import net.minecraft.server.v1_12_R1.Packet;
import net.minecraft.server.v1_12_R1.PlayerChunkMap;
import net.minecraft.server.v1_12_R1.TileEntity;
import net.minecraft.server.v1_12_R1.WorldServer;
@ -25,7 +24,6 @@ import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IBlockInfo;
import com.lishid.orebfuscator.nms.IChunkCache;
import com.lishid.orebfuscator.nms.IChunkManager;
import com.lishid.orebfuscator.nms.INBT;
import com.lishid.orebfuscator.nms.INmsManager;
import com.lishid.orebfuscator.types.BlockCoord;
@ -47,14 +45,6 @@ public class NmsManager implements INmsManager {
return new ChunkCache(this.maxLoadedCacheFiles);
}
@Override
public IChunkManager getChunkManager(World world) {
WorldServer worldServer = ((CraftWorld)world).getHandle();
PlayerChunkMap chunkMap = worldServer.getPlayerChunkMap();
return new ChunkManager(chunkMap);
}
@Override
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
CraftWorld world = (CraftWorld)player.getWorld();
@ -87,7 +77,7 @@ public class NmsManager implements INmsManager {
@Override
public IBlockInfo getBlockInfo(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null
? new BlockInfo(x, y, z, blockData)
@ -96,7 +86,7 @@ public class NmsManager implements INmsManager {
@Override
public BlockState getBlockState(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
if(blockData == null) return null;
@ -111,8 +101,13 @@ public class NmsManager implements INmsManager {
@Override
public int getBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
@Override
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z, true);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
@ -122,17 +117,17 @@ public class NmsManager implements INmsManager {
return CraftChatMessage.fromComponent(component);
}
private static IBlockData getBlockData(World world, int x, int y, int z) {
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
int chunkX = x >> 4;
int chunkZ = z >> 4;
WorldServer worldServer = ((CraftWorld)world).getHandle();
ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer();
if(!chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
if(!loadChunk && !chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
Chunk chunk = chunkProviderServer.getOrLoadChunkAt(chunkX, chunkZ);
return chunk.getBlockData(new BlockPosition(x, y, z));
return chunk != null ? chunk.getBlockData(new BlockPosition(x, y, z)) : null;
}
}

View File

@ -1,53 +0,0 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.nms.v1_9_R1;
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.EntityPlayer;
import net.minecraft.server.v1_9_R1.PlayerChunk;
import net.minecraft.server.v1_9_R1.PlayerChunkMap;
import net.minecraft.server.v1_9_R1.WorldServer;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IChunkManager;
public class ChunkManager implements IChunkManager {
private PlayerChunkMap chunkMap;
public ChunkManager(PlayerChunkMap chunkMap) {
this.chunkMap = chunkMap;
}
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);
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return false;
WorldServer world = this.chunkMap.getWorld();
int px = chunkX << 4;
int pz = chunkZ << 4;
int height = world.getHeight() / 16;
for (int idx = 0; idx < 64; idx++) {
world.notify(new BlockPosition(px + idx / height, idx % height * 16, pz), Blocks.AIR.getBlockData(), Blocks.STONE.getBlockData(), 3);
}
world.notify(new BlockPosition(px + 15, height * 16 - 1, pz + 15), Blocks.AIR.getBlockData(), Blocks.STONE.getBlockData(), 3);
for(EntityPlayer player : playerChunk.c) {
affectedPlayers.add(player.getBukkitEntity());
}
return true;
}
}

View File

@ -31,10 +31,6 @@ public class NBT implements INBT {
nbt.setLong(tag, value);
}
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@ -51,10 +47,6 @@ public class NBT implements INBT {
return nbt.getLong(tag);
}
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}

View File

@ -13,7 +13,6 @@ import net.minecraft.server.v1_9_R1.ChunkProviderServer;
import net.minecraft.server.v1_9_R1.IBlockData;
import net.minecraft.server.v1_9_R1.IChatBaseComponent;
import net.minecraft.server.v1_9_R1.Packet;
import net.minecraft.server.v1_9_R1.PlayerChunkMap;
import net.minecraft.server.v1_9_R1.TileEntity;
import net.minecraft.server.v1_9_R1.WorldServer;
@ -25,7 +24,6 @@ import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IBlockInfo;
import com.lishid.orebfuscator.nms.IChunkCache;
import com.lishid.orebfuscator.nms.IChunkManager;
import com.lishid.orebfuscator.nms.INBT;
import com.lishid.orebfuscator.nms.INmsManager;
import com.lishid.orebfuscator.types.BlockCoord;
@ -46,13 +44,6 @@ public class NmsManager implements INmsManager {
return new ChunkCache(this.maxLoadedCacheFiles);
}
public IChunkManager getChunkManager(World world) {
WorldServer worldServer = ((CraftWorld)world).getHandle();
PlayerChunkMap chunkMap = worldServer.getPlayerChunkMap();
return new ChunkManager(chunkMap);
}
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
CraftWorld world = (CraftWorld)player.getWorld();
TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.z);
@ -81,7 +72,7 @@ public class NmsManager implements INmsManager {
}
public IBlockInfo getBlockInfo(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null
? new BlockInfo(x, y, z, blockData)
@ -89,7 +80,7 @@ public class NmsManager implements INmsManager {
}
public BlockState getBlockState(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
if(blockData == null) return null;
@ -103,27 +94,32 @@ public class NmsManager implements INmsManager {
}
public int getBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z, true);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
public String getTextFromChatComponent(String json) {
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
return CraftChatMessage.fromComponent(component);
}
private static IBlockData getBlockData(World world, int x, int y, int z) {
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
int chunkX = x >> 4;
int chunkZ = z >> 4;
WorldServer worldServer = ((CraftWorld)world).getHandle();
ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer();
if(!chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) return null;
if(!loadChunk && !chunkProviderServer.isChunkLoaded(chunkX, chunkZ)) return null;
Chunk chunk = chunkProviderServer.getOrLoadChunkAt(chunkX, chunkZ);
return chunk.getBlockData(new BlockPosition(x, y, z));
return chunk != null ? chunk.getBlockData(new BlockPosition(x, y, z)) : null;
}
}

View File

@ -1,43 +0,0 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.nms.v1_9_R2;
import java.util.HashSet;
import net.minecraft.server.v1_9_R2.EntityPlayer;
import net.minecraft.server.v1_9_R2.PacketPlayOutMapChunk;
import net.minecraft.server.v1_9_R2.PacketPlayOutUnloadChunk;
import net.minecraft.server.v1_9_R2.PlayerChunk;
import net.minecraft.server.v1_9_R2.PlayerChunkMap;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IChunkManager;
public class ChunkManager implements IChunkManager {
private PlayerChunkMap chunkMap;
public ChunkManager(PlayerChunkMap chunkMap) {
this.chunkMap = chunkMap;
}
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);
if(playerChunk == null || playerChunk.chunk == null || !playerChunk.chunk.isReady()) return false;
for(EntityPlayer player : playerChunk.c) {
player.playerConnection.sendPacket(new PacketPlayOutUnloadChunk(chunkX, chunkZ));
player.playerConnection.sendPacket(new PacketPlayOutMapChunk(playerChunk.chunk, 0xffff));
affectedPlayers.add(player.getBukkitEntity());
}
return true;
}
}

View File

@ -31,10 +31,6 @@ public class NBT implements INBT {
nbt.setLong(tag, value);
}
public void setBoolean(String tag, boolean value) {
nbt.setBoolean(tag, value);
}
public void setByteArray(String tag, byte[] value) {
nbt.setByteArray(tag, value);
}
@ -51,10 +47,6 @@ public class NBT implements INBT {
return nbt.getLong(tag);
}
public boolean getBoolean(String tag) {
return nbt.getBoolean(tag);
}
public byte[] getByteArray(String tag) {
return nbt.getByteArray(tag);
}

View File

@ -13,7 +13,6 @@ import net.minecraft.server.v1_9_R2.ChunkProviderServer;
import net.minecraft.server.v1_9_R2.IBlockData;
import net.minecraft.server.v1_9_R2.IChatBaseComponent;
import net.minecraft.server.v1_9_R2.Packet;
import net.minecraft.server.v1_9_R2.PlayerChunkMap;
import net.minecraft.server.v1_9_R2.TileEntity;
import net.minecraft.server.v1_9_R2.WorldServer;
@ -25,7 +24,6 @@ import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IBlockInfo;
import com.lishid.orebfuscator.nms.IChunkCache;
import com.lishid.orebfuscator.nms.IChunkManager;
import com.lishid.orebfuscator.nms.INBT;
import com.lishid.orebfuscator.nms.INmsManager;
import com.lishid.orebfuscator.types.BlockCoord;
@ -45,14 +43,7 @@ public class NmsManager implements INmsManager {
public IChunkCache createChunkCache() {
return new ChunkCache(this.maxLoadedCacheFiles);
}
public IChunkManager getChunkManager(World world) {
WorldServer worldServer = ((CraftWorld)world).getHandle();
PlayerChunkMap chunkMap = worldServer.getPlayerChunkMap();
return new ChunkManager(chunkMap);
}
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
CraftWorld world = (CraftWorld)player.getWorld();
TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.z);
@ -81,7 +72,7 @@ public class NmsManager implements INmsManager {
}
public IBlockInfo getBlockInfo(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null
? new BlockInfo(x, y, z, blockData)
@ -89,7 +80,7 @@ public class NmsManager implements INmsManager {
}
public BlockState getBlockState(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
if(blockData == null) return null;
@ -103,27 +94,32 @@ public class NmsManager implements INmsManager {
}
public int getBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
IBlockData blockData = getBlockData(world, x, y, z, false);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z, true);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
public String getTextFromChatComponent(String json) {
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
return CraftChatMessage.fromComponent(component);
}
private static IBlockData getBlockData(World world, int x, int y, int z) {
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
int chunkX = x >> 4;
int chunkZ = z >> 4;
WorldServer worldServer = ((CraftWorld)world).getHandle();
ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer();
if(!chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
if(!loadChunk && !chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
Chunk chunk = chunkProviderServer.getOrLoadChunkAt(chunkX, chunkZ);
return chunk.getBlockData(new BlockPosition(x, y, z));
return chunk != null ? chunk.getBlockData(new BlockPosition(x, y, z)) : null;
}
}