mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-28 17:38:01 +01:00
Some fixes
This commit is contained in:
parent
0a0c72bc7d
commit
76ca8a7376
@ -56,6 +56,12 @@ public interface IPlotMain {
|
||||
*/
|
||||
int[] getServerVersion();
|
||||
|
||||
/**
|
||||
* Get the nms package prefix
|
||||
* @return
|
||||
*/
|
||||
String getNMSPackage();
|
||||
|
||||
/**
|
||||
* Get the schematic handler
|
||||
* @return
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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<Chunk> chunks) {
|
||||
public void sendChunk(final Collection<Chunk> 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<ChunkLoc> locs) {
|
||||
public void sendChunk(final String worldname, final List<ChunkLoc> locs) {
|
||||
final World myworld = Bukkit.getWorld(worldname);
|
||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
for (final ChunkLoc loc : locs) {
|
||||
|
@ -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<ChunkLoc, Chunk> toUpdate = new HashMap<>();
|
||||
public HashMap<ChunkLoc, Chunk> 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;
|
||||
}
|
||||
|
@ -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<ChunkLoc, Chunk> 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;
|
||||
}
|
||||
|
@ -31,18 +31,6 @@ public class SetBlockSlow extends BukkitSetBlockManager {
|
||||
|
||||
@Override
|
||||
public void update(final Collection<Chunk> 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
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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<World> optional = SpongeMain.THIS.getServer().getWorld(world);
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user