* Fixed NPE on events, auto-disable Spigot built-in Orebfuscator.

master
lishid 2015-01-08 12:01:13 -05:00
parent 0d7fe40a23
commit 2b150cc616
6 changed files with 38 additions and 21 deletions

View File

@ -22,10 +22,12 @@ import com.lishid.orebfuscator.hithack.BlockHitManager;
import com.lishid.orebfuscator.hook.ChunkProcessingThread;
import com.lishid.orebfuscator.hook.OrebfuscatorPlayerHook;
import com.lishid.orebfuscator.hook.ProtocolLibHook;
import com.lishid.orebfuscator.internal.MinecraftInternals;
import com.lishid.orebfuscator.listeners.OrebfuscatorBlockListener;
import com.lishid.orebfuscator.listeners.OrebfuscatorEntityListener;
import com.lishid.orebfuscator.listeners.OrebfuscatorPlayerListener;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginManager;
@ -76,12 +78,15 @@ public class Orebfuscator extends JavaPlugin {
}, 0, 60 * 1000);// Warn every minute
}
// TODO: Disable spigot's built-in orebfuscator since it has limited functionality
// Disable spigot's built-in orebfuscator since it has limited functionality
try {
Class.forName("org.spigotmc.SpigotConfig");
useSpigot = true;
Class.forName("org.spigotmc.AntiXray");
Orebfuscator.log("Spigot found! Automatically disabling built-in AntiXray.");
for (World world : getServer().getWorlds()) {
MinecraftInternals.tryDisableSpigotAntiXray(world);
}
} catch (Exception e) {
// If error occurred, then ignore.
// Spigot not found
}
}

View File

@ -17,7 +17,7 @@
package com.lishid.orebfuscator;
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
import com.lishid.orebfuscator.internal.BlockAccess;
import com.lishid.orebfuscator.internal.MinecraftInternals;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Block;
@ -96,15 +96,10 @@ public class OrebfuscatorConfig {
return CacheFolder;
}
public static BlockAccess blockAccess;
private static boolean[] TransparentBlocks = new boolean[256];
private static boolean TransparentCached = false;
public static boolean isBlockTransparent(int id) {
if (blockAccess == null) {
blockAccess = new BlockAccess();
}
if (!TransparentCached) {
// Generate TransparentBlocks by reading them from Minecraft
generateTransparentBlocks();
@ -122,7 +117,7 @@ public class OrebfuscatorConfig {
private static void generateTransparentBlocks() {
for (int i = 0; i < TransparentBlocks.length; i++) {
TransparentBlocks[i] = blockAccess.isBlockTransparent(i);
TransparentBlocks[i] = MinecraftInternals.isBlockTransparent(i);
if (i == org.bukkit.Material.TNT.getId()) {
TransparentBlocks[i] = false;
}

View File

@ -16,19 +16,21 @@
package com.lishid.orebfuscator.internal;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.utils.ReflectionHelper;
import net.minecraft.server.v1_8_R1.*;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_8_R1.*;
import org.bukkit.craftbukkit.v1_8_R1.entity.*;
import org.bukkit.craftbukkit.v1_8_R1.*;
public class BlockAccess {
public boolean isBlockTransparent(int id) {
public class MinecraftInternals {
public static boolean isBlockTransparent(int id) {
return !Block.getById(id).s();
}
public void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
public static void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
CraftWorld world = (CraftWorld) block.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
@ -44,4 +46,14 @@ public class BlockAccess {
public static void notifyBlockChange(org.bukkit.World world, int x, int y, int z) {
((CraftWorld) world).getHandle().notify(new BlockPosition(x, y, z));
}
public static void tryDisableSpigotAntiXray(org.bukkit.World world) {
try {
World mcworld = ((CraftWorld) world).getHandle();
Object spigotWorldConfig = ReflectionHelper.getPrivateField(mcworld, "spigotConfig");
ReflectionHelper.setPrivateField(spigotWorldConfig, "antiXray", false);
} catch (Exception e) {
Orebfuscator.log(e);
}
}
}

View File

@ -17,7 +17,7 @@
package com.lishid.orebfuscator.obfuscation;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.BlockAccess;
import com.lishid.orebfuscator.internal.MinecraftInternals;
import org.bukkit.World;
import org.bukkit.block.Block;
@ -40,6 +40,10 @@ public class BlockUpdate {
}
public static void Update(List<Block> blocks) {
if (blocks.isEmpty()) {
return;
}
Set<Block> updateBlocks = new HashSet<Block>();
for (Block block : blocks) {
if (needsUpdate(block)) {
@ -54,7 +58,7 @@ public class BlockUpdate {
private static void sendUpdates(World world, Set<Block> blocks) {
for (Block block : blocks) {
BlockAccess.notifyBlockChange(world, block.getX(), block.getY(), block.getZ());
MinecraftInternals.notifyBlockChange(world, block.getX(), block.getY(), block.getZ());
}
}

View File

@ -18,6 +18,7 @@ package com.lishid.orebfuscator.obfuscation;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.internal.MinecraftInternals;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -147,7 +148,7 @@ public class ProximityHider extends Thread implements Runnable {
Orebfuscator.instance.runTask(new Runnable() {
@Override
public void run() {
OrebfuscatorConfig.blockAccess.updateBlockTileEntity(block, player);
MinecraftInternals.updateBlockTileEntity(block, player);
}
});
}

View File

@ -1,6 +1,6 @@
name: Orebfuscator3
main: com.lishid.orebfuscator.Orebfuscator
version: 3.0.3
version: 3.0.4
author: lishid
softdepend: [ProtocolLib]
load: startup