diff --git a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index b287db26f..893fdb250 100644 --- a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -56,6 +56,12 @@ public interface IPlotMain { */ int[] getServerVersion(); + /** + * Get the nms package prefix + * @return + */ + String getNMSPackage(); + /** * Get the schematic handler * @return diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 5995d189e..d4be138de 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -75,6 +75,7 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.PlotGamemode; import com.intellectualcrafters.plot.util.PlotWeather; +import com.intellectualcrafters.plot.util.ReflectionUtils; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.StringMan; @@ -129,6 +130,7 @@ public class PS { this.thread = Thread.currentThread(); SetupUtils.generators = new HashMap<>(); IMP = imp_class; + new ReflectionUtils(IMP.getNMSPackage()); URL url; try { url = PS.class.getProtectionDomain().getCodeSource().getLocation(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index bfa2a0009..f3131ef7d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -87,14 +87,14 @@ public class DebugExec extends SubCommand { private ScriptEngine engine; private Bindings scope; - + public void init() { if (engine != null) { return; } - engine = (new ScriptEngineManager()).getEngineByName("nashorn"); + engine = (new ScriptEngineManager(null)).getEngineByName("nashorn"); if (engine == null) { - engine = (new ScriptEngineManager()).getEngineByName("JavaScript"); + engine = (new ScriptEngineManager(null)).getEngineByName("JavaScript"); } ScriptContext context = new SimpleScriptContext(); scope = context.getBindings(ScriptContext.ENGINE_SCOPE); diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index dd4539cfa..d0a3428c3 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -947,7 +947,11 @@ public class SQLManager implements AbstractDB { user = UUID.fromString(o); uuids.put(o, user); } - Timestamp timestamp = r.getTimestamp("timestamp"); + Timestamp timestamp = null; + try { + timestamp = r.getTimestamp("timestamp"); + } + catch (Exception e) {}; long time; if (timestamp == null) { time = plot_id.hashCode(); diff --git a/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java b/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java index 83cebe89a..9016558e7 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ReflectionUtils.java @@ -30,14 +30,18 @@ import java.util.Collections; import java.util.List; import org.bukkit.Bukkit; -import org.bukkit.Server; /** * @author DPOH-VAR * @version 1.0 */ -@SuppressWarnings({ "UnusedDeclaration", "rawtypes" }) public class ReflectionUtils { + + public ReflectionUtils(String version) { + preClassB += "." + version; + preClassM += "." + version; + } + /** * prefix of bukkit classes */ @@ -46,36 +50,6 @@ public class ReflectionUtils { * prefix of minecraft classes */ 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) { 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 * {nm} to net.minecraft diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index ece0c5e6a..b05dd8b94 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -1,6 +1,7 @@ package com.plotsquared.bukkit; import java.io.File; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.UUID; @@ -8,6 +9,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.OfflinePlayer; +import org.bukkit.Server; import org.bukkit.World; import org.bukkit.command.PluginCommand; 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.SchematicHandler; import com.intellectualcrafters.plot.util.SetupUtils; +import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; @@ -106,7 +109,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } } catch (Exception e) { 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; @@ -568,4 +573,29 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } 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"; + } } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 76f1559ea..321b0e2d3 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -2068,7 +2068,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } if (FlagManager.isPlotFlagTrue(plot, FLAG_DISABLE_PHYSICS)) { Block block = event.getBlockPlaced(); - sendBlockChange(block.getLocation(), block.getType(), block.getData()); + if (block.getType().hasGravity()) { + sendBlockChange(block.getLocation(), block.getType(), block.getData()); + } } PlotWorld pw = PS.get().getPlotWorld(loc.getWorld()); if (loc.getY() >= pw.MAX_BUILD_HEIGHT && !Permissions.hasPermission(pp, PERMISSION_ADMIN_BUILD_HEIGHTLIMIT)) { diff --git a/src/main/java/com/plotsquared/bukkit/util/SendChunk.java b/src/main/java/com/plotsquared/bukkit/util/SendChunk.java index 21f925227..97bc28d02 100644 --- a/src/main/java/com/plotsquared/bukkit/util/SendChunk.java +++ b/src/main/java/com/plotsquared/bukkit/util/SendChunk.java @@ -25,22 +25,22 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; public class SendChunk { // Ref Class - private static final RefClass classWorld = getRefClass("{nms}.World"); - private static final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); - private static final RefClass classChunkCoordIntPair = getRefClass("{nms}.ChunkCoordIntPair"); - private static final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); - private static 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 final RefClass classWorld = getRefClass("{nms}.World"); + private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); + private final RefClass classChunkCoordIntPair = getRefClass("{nms}.ChunkCoordIntPair"); + private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk"); + private final RefClass classChunk = getRefClass("{nms}.Chunk"); + 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 - private static RefMethod methodGetHandle; + private RefMethod methodGetHandle; // Ref Field - private static RefField chunkCoordIntPairQueue; - private static RefField players; - private static RefField locX; - private static RefField locZ; - private static RefField world; + private RefField chunkCoordIntPairQueue; + private RefField players; + private RefField locX; + private RefField locZ; + private RefField world; // Ref Constructor - private static RefConstructor ChunkCoordIntPairCon; + private RefConstructor ChunkCoordIntPairCon; /** * Constructor @@ -57,7 +57,7 @@ public class SendChunk { ChunkCoordIntPairCon = classChunkCoordIntPair.getConstructor(int.class, int.class); } - public static void sendChunk(final Collection chunks) { + public void sendChunk(final Collection chunks) { int diffx, diffz; final int view = Bukkit.getServer().getViewDistance() << 4; for (final Chunk chunk : chunks) { @@ -92,7 +92,7 @@ public class SendChunk { } } - public static void sendChunk(final String worldname, final List locs) { + public void sendChunk(final String worldname, final List locs) { final World myworld = Bukkit.getWorld(worldname); final ArrayList chunks = new ArrayList<>(); for (final ChunkLoc loc : locs) { diff --git a/src/main/java/com/plotsquared/bukkit/util/SetBlockFast.java b/src/main/java/com/plotsquared/bukkit/util/SetBlockFast.java index c7b1387a0..72229947d 100644 --- a/src/main/java/com/plotsquared/bukkit/util/SetBlockFast.java +++ b/src/main/java/com/plotsquared/bukkit/util/SetBlockFast.java @@ -39,16 +39,17 @@ import com.intellectualcrafters.plot.util.TaskManager; * @author Empire92 */ public class SetBlockFast extends BukkitSetBlockManager { - private static final RefClass classBlock = getRefClass("{nms}.Block"); - private static final RefClass classChunk = getRefClass("{nms}.Chunk"); - private static final RefClass classWorld = getRefClass("{nms}.World"); - private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); - private static RefMethod methodGetHandle; - private static RefMethod methodGetChunkAt; - private static RefMethod methodA; - private static RefMethod methodGetById; + private final RefClass classBlock = getRefClass("{nms}.Block"); + private final RefClass classChunk = getRefClass("{nms}.Chunk"); + private final RefClass classWorld = getRefClass("{nms}.World"); + private final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); + private RefMethod methodGetHandle; + private RefMethod methodGetChunkAt; + private RefMethod methodA; + private RefMethod methodGetById; + private SendChunk chunksender; - public static HashMap toUpdate = new HashMap<>(); + public HashMap toUpdate = new HashMap<>(); /** * Constructor @@ -69,6 +70,7 @@ public class SetBlockFast extends BukkitSetBlockManager { toUpdate = new HashMap<>(); } }, 20); + this.chunksender = new SendChunk(); } private ChunkLoc lastLoc = null; @@ -127,7 +129,7 @@ public class SetBlockFast extends BukkitSetBlockManager { return; } try { - SendChunk.sendChunk(chunks); + chunksender.sendChunk(chunks); } catch (final Throwable e) { MainUtil.canSendChunk = false; } diff --git a/src/main/java/com/plotsquared/bukkit/util/SetBlockFast_1_8.java b/src/main/java/com/plotsquared/bukkit/util/SetBlockFast_1_8.java index 6306e5f6c..ba2a7ae52 100644 --- a/src/main/java/com/plotsquared/bukkit/util/SetBlockFast_1_8.java +++ b/src/main/java/com/plotsquared/bukkit/util/SetBlockFast_1_8.java @@ -45,17 +45,18 @@ import com.intellectualcrafters.plot.util.TaskManager; * @author Empire92 */ public class SetBlockFast_1_8 extends BukkitSetBlockManager { - private static final RefClass classBlock = getRefClass("{nms}.Block"); - private static final RefClass classBlockPosition = getRefClass("{nms}.BlockPosition"); - private static final RefClass classIBlockData = getRefClass("{nms}.IBlockData"); - private static final RefClass classChunk = getRefClass("{nms}.Chunk"); - private static final RefClass classWorld = getRefClass("{nms}.World"); - private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); - private static RefMethod methodGetHandle; - private static RefMethod methodGetChunkAt; - private static RefMethod methodA; - private static RefMethod methodGetByCombinedId; - private static RefConstructor constructorBlockPosition; + private final RefClass classBlock = getRefClass("{nms}.Block"); + private final RefClass classBlockPosition = getRefClass("{nms}.BlockPosition"); + private final RefClass classIBlockData = getRefClass("{nms}.IBlockData"); + private final RefClass classChunk = getRefClass("{nms}.Chunk"); + private final RefClass classWorld = getRefClass("{nms}.World"); + private final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld"); + private RefMethod methodGetHandle; + private RefMethod methodGetChunkAt; + private RefMethod methodA; + private RefMethod methodGetByCombinedId; + private RefConstructor constructorBlockPosition; + private SendChunk chunksender; public static HashMap toUpdate = new HashMap<>(); @@ -88,6 +89,7 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { update(chunks); } }, 20); + this.chunksender = new SendChunk(); } private ChunkLoc lastLoc = null; @@ -345,7 +347,7 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { return; } try { - SendChunk.sendChunk(chunks); + chunksender.sendChunk(chunks); } catch (final Throwable e) { MainUtil.canSendChunk = false; } diff --git a/src/main/java/com/plotsquared/bukkit/util/SetBlockSlow.java b/src/main/java/com/plotsquared/bukkit/util/SetBlockSlow.java index 2a9f00aff..a66014697 100644 --- a/src/main/java/com/plotsquared/bukkit/util/SetBlockSlow.java +++ b/src/main/java/com/plotsquared/bukkit/util/SetBlockSlow.java @@ -31,18 +31,6 @@ public class SetBlockSlow extends BukkitSetBlockManager { @Override public void update(final Collection chunks) { - if (MainUtil.canSendChunk) { - try { - SendChunk.sendChunk(chunks); - } catch (final Throwable e) { - MainUtil.canSendChunk = false; - } - } - else { - for (Chunk chunk : chunks) { - chunk.unload(); - chunk.load(true); - } - } + // TODO nothing } } diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index b032cc30c..11acee96f 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.slf4j.Logger; import org.spongepowered.api.CatalogType; import org.spongepowered.api.Game; +import org.spongepowered.api.Platform; import org.spongepowered.api.Server; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockType; @@ -637,4 +638,9 @@ public class SpongeMain implements IPlotMain, PluginContainer { } return null; } + + @Override + public String getNMSPackage() { + return "1_8_R3"; + } } \ No newline at end of file diff --git a/src/main/java/com/plotsquared/sponge/generator/WorldModify.java b/src/main/java/com/plotsquared/sponge/generator/WorldModify.java index c5e458a63..dd8b863e1 100644 --- a/src/main/java/com/plotsquared/sponge/generator/WorldModify.java +++ b/src/main/java/com/plotsquared/sponge/generator/WorldModify.java @@ -5,6 +5,7 @@ import org.spongepowered.api.world.WorldCreationSettings; import org.spongepowered.api.world.gen.WorldGenerator; import org.spongepowered.api.world.gen.WorldGeneratorModifier; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.ClusterManager; diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeBlockManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeBlockManager.java index 31489f462..f312ec3e4 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeBlockManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeBlockManager.java @@ -184,7 +184,12 @@ public class SpongeBlockManager extends BlockManager { if (state == null) { 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 diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index 35e56f228..a505a5ec7 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -65,8 +65,14 @@ public class SpongeUtil { } return null; } + + private static World lastWorld; + private static String last; public static World getWorld(String world) { + if (world == last) { + return lastWorld; + } Optional optional = SpongeMain.THIS.getServer().getWorld(world); if (!optional.isPresent()) { return null;