Some fixes

This commit is contained in:
boy0001 2015-08-04 04:20:04 +10:00
parent 0a0c72bc7d
commit 76ca8a7376
15 changed files with 117 additions and 96 deletions

View File

@ -56,6 +56,12 @@ public interface IPlotMain {
*/ */
int[] getServerVersion(); int[] getServerVersion();
/**
* Get the nms package prefix
* @return
*/
String getNMSPackage();
/** /**
* Get the schematic handler * Get the schematic handler
* @return * @return

View File

@ -75,6 +75,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.PlotGamemode; import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.ReflectionUtils;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
@ -129,6 +130,7 @@ public class PS {
this.thread = Thread.currentThread(); this.thread = Thread.currentThread();
SetupUtils.generators = new HashMap<>(); SetupUtils.generators = new HashMap<>();
IMP = imp_class; IMP = imp_class;
new ReflectionUtils(IMP.getNMSPackage());
URL url; URL url;
try { try {
url = PS.class.getProtectionDomain().getCodeSource().getLocation(); url = PS.class.getProtectionDomain().getCodeSource().getLocation();

View File

@ -92,9 +92,9 @@ public class DebugExec extends SubCommand {
if (engine != null) { if (engine != null) {
return; return;
} }
engine = (new ScriptEngineManager()).getEngineByName("nashorn"); engine = (new ScriptEngineManager(null)).getEngineByName("nashorn");
if (engine == null) { if (engine == null) {
engine = (new ScriptEngineManager()).getEngineByName("JavaScript"); engine = (new ScriptEngineManager(null)).getEngineByName("JavaScript");
} }
ScriptContext context = new SimpleScriptContext(); ScriptContext context = new SimpleScriptContext();
scope = context.getBindings(ScriptContext.ENGINE_SCOPE); scope = context.getBindings(ScriptContext.ENGINE_SCOPE);

View File

@ -947,7 +947,11 @@ public class SQLManager implements AbstractDB {
user = UUID.fromString(o); user = UUID.fromString(o);
uuids.put(o, user); uuids.put(o, user);
} }
Timestamp timestamp = r.getTimestamp("timestamp"); Timestamp timestamp = null;
try {
timestamp = r.getTimestamp("timestamp");
}
catch (Exception e) {};
long time; long time;
if (timestamp == null) { if (timestamp == null) {
time = plot_id.hashCode(); time = plot_id.hashCode();

View File

@ -30,14 +30,18 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Server;
/** /**
* @author DPOH-VAR * @author DPOH-VAR
* @version 1.0 * @version 1.0
*/ */
@SuppressWarnings({ "UnusedDeclaration", "rawtypes" })
public class ReflectionUtils { public class ReflectionUtils {
public ReflectionUtils(String version) {
preClassB += "." + version;
preClassM += "." + version;
}
/** /**
* prefix of bukkit classes * prefix of bukkit classes
*/ */
@ -46,36 +50,6 @@ public class ReflectionUtils {
* prefix of minecraft classes * prefix of minecraft classes
*/ */
private static String preClassM = "net.minecraft.server"; private static String preClassM = "net.minecraft.server";
/**
* boolean value, TRUE if server uses forge or MCPC+
*/
private static boolean forge = false;
/** check server version and class names */
static {
if (Bukkit.getServer() != null) {
if (Bukkit.getVersion().contains("MCPC") || Bukkit.getVersion().contains("Forge")) {
forge = true;
}
final Server server = Bukkit.getServer();
final Class<?> bukkitServerClass = server.getClass();
String[] pas = bukkitServerClass.getName().split("\\.");
if (pas.length == 5) {
final String verB = pas[3];
preClassB += "." + verB;
}
try {
final Method getHandle = bukkitServerClass.getDeclaredMethod("getHandle");
final Object handle = getHandle.invoke(server);
final Class handleServerClass = handle.getClass();
pas = handleServerClass.getName().split("\\.");
if (pas.length == 5) {
final String verM = pas[3];
preClassM += "." + verM;
}
} catch (final Exception ignored) {
}
}
}
public static Class<?> getNmsClass(final String name) { public static Class<?> getNmsClass(final String name) {
final String className = "net.minecraft.server." + getVersion() + "." + name; final String className = "net.minecraft.server." + getVersion() + "." + name;
@ -211,13 +185,6 @@ public class ReflectionUtils {
} }
} }
/**
* @return true if server has forge classes
*/
public static boolean isForge() {
return forge;
}
/** /**
* Get class for name. Replace {nms} to net.minecraft.server.V*. Replace {cb} to org.bukkit.craftbukkit.V*. Replace * Get class for name. Replace {nms} to net.minecraft.server.V*. Replace {cb} to org.bukkit.craftbukkit.V*. Replace
* {nm} to net.minecraft * {nm} to net.minecraft

View File

@ -1,6 +1,7 @@
package com.plotsquared.bukkit; package com.plotsquared.bukkit;
import java.io.File; import java.io.File;
import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
@ -8,6 +9,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -40,6 +42,7 @@ import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
@ -106,7 +109,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; PS.debug(StringMan.getString(Bukkit.getBukkitVersion()));
PS.debug(StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\.")));
return new int[] { Integer.MAX_VALUE, 0, 0 };
} }
} }
return version; return version;
@ -568,4 +573,29 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
} }
return null; return null;
} }
@Override
public String getNMSPackage() {
final Server server = Bukkit.getServer();
final Class<?> bukkitServerClass = server.getClass();
String[] pas = bukkitServerClass.getName().split("\\.");
if (pas.length == 5) {
final String verB = pas[3];
return verB;
}
try {
final Method getHandle = bukkitServerClass.getDeclaredMethod("getHandle");
final Object handle = getHandle.invoke(server);
final Class handleServerClass = handle.getClass();
pas = handleServerClass.getName().split("\\.");
if (pas.length == 5) {
final String verM = pas[3];
return verM;
}
} catch (Exception e) {
e.printStackTrace();
}
PS.debug("Unknown NMS package: " + StringMan.getString(pas));
return "1_8_R3";
}
} }

View File

@ -2068,8 +2068,10 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
} }
if (FlagManager.isPlotFlagTrue(plot, FLAG_DISABLE_PHYSICS)) { if (FlagManager.isPlotFlagTrue(plot, FLAG_DISABLE_PHYSICS)) {
Block block = event.getBlockPlaced(); Block block = event.getBlockPlaced();
if (block.getType().hasGravity()) {
sendBlockChange(block.getLocation(), block.getType(), block.getData()); sendBlockChange(block.getLocation(), block.getType(), block.getData());
} }
}
PlotWorld pw = PS.get().getPlotWorld(loc.getWorld()); PlotWorld pw = PS.get().getPlotWorld(loc.getWorld());
if (loc.getY() >= pw.MAX_BUILD_HEIGHT && !Permissions.hasPermission(pp, PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) { if (loc.getY() >= pw.MAX_BUILD_HEIGHT && !Permissions.hasPermission(pp, PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) {
event.setCancelled(true); event.setCancelled(true);

View File

@ -25,22 +25,22 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
public class SendChunk { public class SendChunk {
// Ref Class // Ref Class
private static final RefClass classWorld = getRefClass("{nms}.World"); private final RefClass classWorld = getRefClass("{nms}.World");
private static final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
private static final RefClass classChunkCoordIntPair = getRefClass("{nms}.ChunkCoordIntPair"); private final RefClass classChunkCoordIntPair = getRefClass("{nms}.ChunkCoordIntPair");
private static final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
private static final RefClass classChunk = getRefClass("{nms}.Chunk"); private final RefClass classChunk = getRefClass("{nms}.Chunk");
private static boolean v1_7_10 = PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 7, 10) && !PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 8, 0); private boolean v1_7_10 = PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 7, 10) && !PS.get().checkVersion(PS.get().IMP.getServerVersion(), 1, 8, 0);
// Ref Method // Ref Method
private static RefMethod methodGetHandle; private RefMethod methodGetHandle;
// Ref Field // Ref Field
private static RefField chunkCoordIntPairQueue; private RefField chunkCoordIntPairQueue;
private static RefField players; private RefField players;
private static RefField locX; private RefField locX;
private static RefField locZ; private RefField locZ;
private static RefField world; private RefField world;
// Ref Constructor // Ref Constructor
private static RefConstructor ChunkCoordIntPairCon; private RefConstructor ChunkCoordIntPairCon;
/** /**
* Constructor * Constructor
@ -57,7 +57,7 @@ public class SendChunk {
ChunkCoordIntPairCon = classChunkCoordIntPair.getConstructor(int.class, int.class); ChunkCoordIntPairCon = classChunkCoordIntPair.getConstructor(int.class, int.class);
} }
public static void sendChunk(final Collection<Chunk> chunks) { public void sendChunk(final Collection<Chunk> chunks) {
int diffx, diffz; int diffx, diffz;
final int view = Bukkit.getServer().getViewDistance() << 4; final int view = Bukkit.getServer().getViewDistance() << 4;
for (final Chunk chunk : chunks) { for (final Chunk chunk : chunks) {
@ -92,7 +92,7 @@ public class SendChunk {
} }
} }
public static void sendChunk(final String worldname, final List<ChunkLoc> locs) { public void sendChunk(final String worldname, final List<ChunkLoc> locs) {
final World myworld = Bukkit.getWorld(worldname); final World myworld = Bukkit.getWorld(worldname);
final ArrayList<Chunk> chunks = new ArrayList<>(); final ArrayList<Chunk> chunks = new ArrayList<>();
for (final ChunkLoc loc : locs) { for (final ChunkLoc loc : locs) {

View File

@ -39,16 +39,17 @@ import com.intellectualcrafters.plot.util.TaskManager;
* @author Empire92 * @author Empire92
*/ */
public class SetBlockFast extends BukkitSetBlockManager { public class SetBlockFast extends BukkitSetBlockManager {
private static final RefClass classBlock = getRefClass("{nms}.Block"); private final RefClass classBlock = getRefClass("{nms}.Block");
private static final RefClass classChunk = getRefClass("{nms}.Chunk"); private final RefClass classChunk = getRefClass("{nms}.Chunk");
private static final RefClass classWorld = getRefClass("{nms}.World"); private final RefClass classWorld = getRefClass("{nms}.World");
private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); private final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
private static RefMethod methodGetHandle; private RefMethod methodGetHandle;
private static RefMethod methodGetChunkAt; private RefMethod methodGetChunkAt;
private static RefMethod methodA; private RefMethod methodA;
private static RefMethod methodGetById; private RefMethod methodGetById;
private SendChunk chunksender;
public static HashMap<ChunkLoc, Chunk> toUpdate = new HashMap<>(); public HashMap<ChunkLoc, Chunk> toUpdate = new HashMap<>();
/** /**
* Constructor * Constructor
@ -69,6 +70,7 @@ public class SetBlockFast extends BukkitSetBlockManager {
toUpdate = new HashMap<>(); toUpdate = new HashMap<>();
} }
}, 20); }, 20);
this.chunksender = new SendChunk();
} }
private ChunkLoc lastLoc = null; private ChunkLoc lastLoc = null;
@ -127,7 +129,7 @@ public class SetBlockFast extends BukkitSetBlockManager {
return; return;
} }
try { try {
SendChunk.sendChunk(chunks); chunksender.sendChunk(chunks);
} catch (final Throwable e) { } catch (final Throwable e) {
MainUtil.canSendChunk = false; MainUtil.canSendChunk = false;
} }

View File

@ -45,17 +45,18 @@ import com.intellectualcrafters.plot.util.TaskManager;
* @author Empire92 * @author Empire92
*/ */
public class SetBlockFast_1_8 extends BukkitSetBlockManager { public class SetBlockFast_1_8 extends BukkitSetBlockManager {
private static final RefClass classBlock = getRefClass("{nms}.Block"); private final RefClass classBlock = getRefClass("{nms}.Block");
private static final RefClass classBlockPosition = getRefClass("{nms}.BlockPosition"); private final RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
private static final RefClass classIBlockData = getRefClass("{nms}.IBlockData"); private final RefClass classIBlockData = getRefClass("{nms}.IBlockData");
private static final RefClass classChunk = getRefClass("{nms}.Chunk"); private final RefClass classChunk = getRefClass("{nms}.Chunk");
private static final RefClass classWorld = getRefClass("{nms}.World"); private final RefClass classWorld = getRefClass("{nms}.World");
private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); private final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
private static RefMethod methodGetHandle; private RefMethod methodGetHandle;
private static RefMethod methodGetChunkAt; private RefMethod methodGetChunkAt;
private static RefMethod methodA; private RefMethod methodA;
private static RefMethod methodGetByCombinedId; private RefMethod methodGetByCombinedId;
private static RefConstructor constructorBlockPosition; private RefConstructor constructorBlockPosition;
private SendChunk chunksender;
public static HashMap<ChunkLoc, Chunk> toUpdate = new HashMap<>(); public static HashMap<ChunkLoc, Chunk> toUpdate = new HashMap<>();
@ -88,6 +89,7 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager {
update(chunks); update(chunks);
} }
}, 20); }, 20);
this.chunksender = new SendChunk();
} }
private ChunkLoc lastLoc = null; private ChunkLoc lastLoc = null;
@ -345,7 +347,7 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager {
return; return;
} }
try { try {
SendChunk.sendChunk(chunks); chunksender.sendChunk(chunks);
} catch (final Throwable e) { } catch (final Throwable e) {
MainUtil.canSendChunk = false; MainUtil.canSendChunk = false;
} }

View File

@ -31,18 +31,6 @@ public class SetBlockSlow extends BukkitSetBlockManager {
@Override @Override
public void update(final Collection<Chunk> chunks) { public void update(final Collection<Chunk> chunks) {
if (MainUtil.canSendChunk) { // TODO nothing
try {
SendChunk.sendChunk(chunks);
} catch (final Throwable e) {
MainUtil.canSendChunk = false;
}
}
else {
for (Chunk chunk : chunks) {
chunk.unload();
chunk.load(true);
}
}
} }
} }

View File

@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.spongepowered.api.CatalogType; import org.spongepowered.api.CatalogType;
import org.spongepowered.api.Game; import org.spongepowered.api.Game;
import org.spongepowered.api.Platform;
import org.spongepowered.api.Server; import org.spongepowered.api.Server;
import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockType; import org.spongepowered.api.block.BlockType;
@ -637,4 +638,9 @@ public class SpongeMain implements IPlotMain, PluginContainer {
} }
return null; return null;
} }
@Override
public String getNMSPackage() {
return "1_8_R3";
}
} }

View File

@ -5,6 +5,7 @@ import org.spongepowered.api.world.WorldCreationSettings;
import org.spongepowered.api.world.gen.WorldGenerator; import org.spongepowered.api.world.gen.WorldGenerator;
import org.spongepowered.api.world.gen.WorldGeneratorModifier; import org.spongepowered.api.world.gen.WorldGeneratorModifier;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ClusterManager;

View File

@ -184,7 +184,12 @@ public class SpongeBlockManager extends BlockManager {
if (state == null) { if (state == null) {
return; return;
} }
SpongeUtil.getWorld(worldname).setBlock(x, y, z, state); World world = SpongeUtil.getWorld(worldname);
BlockState block = world.getBlock(x, y, z);
if (block != state) {
world.setBlock(x, y, z, state);
}
} }
@Override @Override

View File

@ -66,7 +66,13 @@ public class SpongeUtil {
return null; return null;
} }
private static World lastWorld;
private static String last;
public static World getWorld(String world) { public static World getWorld(String world) {
if (world == last) {
return lastWorld;
}
Optional<World> optional = SpongeMain.THIS.getServer().getWorld(world); Optional<World> optional = SpongeMain.THIS.getServer().getWorld(world);
if (!optional.isPresent()) { if (!optional.isPresent()) {
return null; return null;