mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-28 12:56:05 +01:00
Redstone, chunk sending, reload fix, chunk unloader,
- Added redstone disabler when no players are in the plot - Fixed chunk sending leaving ghost blocks - Fixed reloading not populating new values - Added chunk unloader to chunk processor (decreases memory usage)
This commit is contained in:
parent
ae7eed8a5b
commit
b063494955
2
pom.xml
2
pom.xml
@ -8,7 +8,7 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
<artifactId>PlotSquared</artifactId>
|
<artifactId>PlotSquared</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>3.1.3</version>
|
||||||
<name>PlotSquared</name>
|
<name>PlotSquared</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<build>
|
<build>
|
||||||
|
@ -1743,6 +1743,7 @@ public class PS {
|
|||||||
|
|
||||||
// Protection
|
// Protection
|
||||||
options.put("protection.redstone.disable-offline", Settings.REDSTONE_DISABLER);
|
options.put("protection.redstone.disable-offline", Settings.REDSTONE_DISABLER);
|
||||||
|
options.put("protection.redstone.disable-unoccupied", Settings.REDSTONE_DISABLER_UNOCCUPIED);
|
||||||
options.put("protection.tnt-listener.enabled", Settings.TNT_LISTENER);
|
options.put("protection.tnt-listener.enabled", Settings.TNT_LISTENER);
|
||||||
options.put("protection.piston.falling-blocks", Settings.PISTON_FALLING_BLOCK_CHECK);
|
options.put("protection.piston.falling-blocks", Settings.PISTON_FALLING_BLOCK_CHECK);
|
||||||
|
|
||||||
@ -1837,6 +1838,7 @@ public class PS {
|
|||||||
|
|
||||||
// Chunk processor
|
// Chunk processor
|
||||||
options.put("chunk-processor.enabled", Settings.CHUNK_PROCESSOR);
|
options.put("chunk-processor.enabled", Settings.CHUNK_PROCESSOR);
|
||||||
|
options.put("chunk-processor.random-chunk-unloads", Settings.CHUNK_PROCESSOR_RANDOM_CHUNK_UNLOADS);
|
||||||
options.put("chunk-processor.max-blockstates", Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES);
|
options.put("chunk-processor.max-blockstates", Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES);
|
||||||
options.put("chunk-processor.max-entities", Settings.CHUNK_PROCESSOR_MAX_ENTITIES);
|
options.put("chunk-processor.max-entities", Settings.CHUNK_PROCESSOR_MAX_ENTITIES);
|
||||||
options.put("chunk-processor.disable-physics", Settings.CHUNK_PROCESSOR_DISABLE_PHYSICS);
|
options.put("chunk-processor.disable-physics", Settings.CHUNK_PROCESSOR_DISABLE_PHYSICS);
|
||||||
@ -1869,6 +1871,8 @@ public class PS {
|
|||||||
|
|
||||||
// Protection
|
// Protection
|
||||||
Settings.REDSTONE_DISABLER = config.getBoolean("protection.redstone.disable-offline");
|
Settings.REDSTONE_DISABLER = config.getBoolean("protection.redstone.disable-offline");
|
||||||
|
Settings.REDSTONE_DISABLER_UNOCCUPIED = config.getBoolean("protection.redstone.disable-unoccupied");
|
||||||
|
|
||||||
Settings.TNT_LISTENER = config.getBoolean("protection.tnt-listener.enabled");
|
Settings.TNT_LISTENER = config.getBoolean("protection.tnt-listener.enabled");
|
||||||
Settings.PISTON_FALLING_BLOCK_CHECK = config.getBoolean("protection.piston.falling-blocks");
|
Settings.PISTON_FALLING_BLOCK_CHECK = config.getBoolean("protection.piston.falling-blocks");
|
||||||
|
|
||||||
@ -1948,6 +1952,7 @@ public class PS {
|
|||||||
|
|
||||||
// Chunk processor
|
// Chunk processor
|
||||||
Settings.CHUNK_PROCESSOR = config.getBoolean("chunk-processor.enabled");
|
Settings.CHUNK_PROCESSOR = config.getBoolean("chunk-processor.enabled");
|
||||||
|
Settings.CHUNK_PROCESSOR_RANDOM_CHUNK_UNLOADS = config.getInt("chunk-processor.random-chunk-unloads");
|
||||||
Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES = config.getInt("chunk-processor.max-blockstates");
|
Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES = config.getInt("chunk-processor.max-blockstates");
|
||||||
Settings.CHUNK_PROCESSOR_MAX_ENTITIES = config.getInt("chunk-processor.max-entities");
|
Settings.CHUNK_PROCESSOR_MAX_ENTITIES = config.getInt("chunk-processor.max-entities");
|
||||||
Settings.CHUNK_PROCESSOR_DISABLE_PHYSICS = config.getBoolean("chunk-processor.disable-physics");
|
Settings.CHUNK_PROCESSOR_DISABLE_PHYSICS = config.getBoolean("chunk-processor.disable-physics");
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
@ -46,10 +47,13 @@ public class Reload extends SubCommand {
|
|||||||
C.load(PS.get().translationFile);
|
C.load(PS.get().translationFile);
|
||||||
for (final String pw : PS.get().getPlotWorlds()) {
|
for (final String pw : PS.get().getPlotWorlds()) {
|
||||||
final PlotWorld plotworld = PS.get().getPlotWorld(pw);
|
final PlotWorld plotworld = PS.get().getPlotWorld(pw);
|
||||||
plotworld.loadDefaultConfiguration(PS.get().config.getConfigurationSection("worlds." + pw));
|
ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + pw);
|
||||||
|
plotworld.saveConfiguration(section);
|
||||||
|
plotworld.loadDefaultConfiguration(section);
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
|
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
MainUtil.sendMessage(plr, C.RELOAD_FAILED);
|
MainUtil.sendMessage(plr, C.RELOAD_FAILED);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -69,6 +69,7 @@ public class Settings {
|
|||||||
*/
|
*/
|
||||||
public static boolean CHUNK_PROCESSOR = false;
|
public static boolean CHUNK_PROCESSOR = false;
|
||||||
public static int CHUNK_PROCESSOR_MAX_BLOCKSTATES = 4096;
|
public static int CHUNK_PROCESSOR_MAX_BLOCKSTATES = 4096;
|
||||||
|
public static int CHUNK_PROCESSOR_RANDOM_CHUNK_UNLOADS = 1;
|
||||||
public static int CHUNK_PROCESSOR_MAX_ENTITIES = 512;
|
public static int CHUNK_PROCESSOR_MAX_ENTITIES = 512;
|
||||||
public static boolean CHUNK_PROCESSOR_DISABLE_PHYSICS = false;
|
public static boolean CHUNK_PROCESSOR_DISABLE_PHYSICS = false;
|
||||||
/**
|
/**
|
||||||
@ -79,6 +80,7 @@ public class Settings {
|
|||||||
* Redstone disabler
|
* Redstone disabler
|
||||||
*/
|
*/
|
||||||
public static boolean REDSTONE_DISABLER = false;
|
public static boolean REDSTONE_DISABLER = false;
|
||||||
|
public static boolean REDSTONE_DISABLER_UNOCCUPIED = false;
|
||||||
/**
|
/**
|
||||||
* Check for falling blocks when pistons extend?
|
* Check for falling blocks when pistons extend?
|
||||||
*/
|
*/
|
||||||
|
@ -3,6 +3,7 @@ package com.plotsquared.bukkit.listeners;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
@ -19,6 +20,8 @@ import org.bukkit.event.world.ChunkUnloadEvent;
|
|||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
|
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||||
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
|
||||||
public class ChunkListener implements Listener {
|
public class ChunkListener implements Listener {
|
||||||
@ -27,6 +30,27 @@ public class ChunkListener implements Listener {
|
|||||||
private long last = 0;
|
private long last = 0;
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
|
public ChunkListener() {
|
||||||
|
final PseudoRandom r = new PseudoRandom();
|
||||||
|
r.state = System.currentTimeMillis();
|
||||||
|
if (Settings.CHUNK_PROCESSOR_RANDOM_CHUNK_UNLOADS > 0) {
|
||||||
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
if (!PS.get().isPlotWorld(world.getName())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Chunk[] chunks = world.getLoadedChunks();
|
||||||
|
for (int i = 0; i < Math.min(chunks.length, Settings.CHUNK_PROCESSOR_RANDOM_CHUNK_UNLOADS); i++) {
|
||||||
|
chunks[r.random(chunks.length)].unload(true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||||
if (processChunk(event.getChunk(), true)) {
|
if (processChunk(event.getChunk(), true)) {
|
||||||
|
@ -64,6 +64,7 @@ import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
|||||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||||
@ -83,6 +84,7 @@ import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
|||||||
import org.bukkit.event.world.ChunkLoadEvent;
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.event.world.StructureGrowEvent;
|
import org.bukkit.event.world.StructureGrowEvent;
|
||||||
import org.bukkit.help.HelpTopic;
|
import org.bukkit.help.HelpTopic;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.projectiles.BlockProjectileSource;
|
import org.bukkit.projectiles.BlockProjectileSource;
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
@ -156,11 +158,61 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
|
|||||||
}, 3);
|
}, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryPickup(InventoryPickupItemEvent event) {
|
||||||
|
Inventory inv = event.getInventory();
|
||||||
|
System.out.print(inv.getTitle() + " | " + inv.getHolder() + " | " + inv + " | " + inv.getType());
|
||||||
|
Location loc = BukkitUtil.getLocation(event.getItem().getLocation());
|
||||||
|
if (!PS.get().isPlotWorld(loc.getWorld())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plot plot = MainUtil.getPlot(loc);
|
||||||
|
if (plot == null || !plot.hasOwner()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Flag redstone = FlagManager.getPlotFlag(plot, "redstone");
|
||||||
|
if (redstone != null) {
|
||||||
|
if ((Boolean) redstone.getValue()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Settings.REDSTONE_DISABLER) {
|
||||||
|
if (UUIDHandler.getPlayer(plot.owner) == null) {
|
||||||
|
boolean disable = true;
|
||||||
|
for (UUID trusted : plot.getTrusted()) {
|
||||||
|
if (UUIDHandler.getPlayer(trusted) != null) {
|
||||||
|
disable = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (disable) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Settings.REDSTONE_DISABLER_UNOCCUPIED) {
|
||||||
|
for (PlotPlayer pp : UUIDHandler.getPlayers().values()) {
|
||||||
|
if (plot.equals(pp.getCurrentPlot())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onRedstoneEvent(BlockRedstoneEvent event) {
|
public void onRedstoneEvent(BlockRedstoneEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
switch (block.getType()) {
|
switch (block.getType()) {
|
||||||
case REDSTONE_LAMP_OFF:
|
case REDSTONE_LAMP_OFF:
|
||||||
|
case REDSTONE_WIRE:
|
||||||
case REDSTONE_LAMP_ON:
|
case REDSTONE_LAMP_ON:
|
||||||
case PISTON_BASE:
|
case PISTON_BASE:
|
||||||
case PISTON_STICKY_BASE:
|
case PISTON_STICKY_BASE:
|
||||||
@ -198,10 +250,16 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Flag redstone = FlagManager.getPlotFlag(plot, "redstone");
|
Flag redstone = FlagManager.getPlotFlag(plot, "redstone");
|
||||||
if (Settings.REDSTONE_DISABLER) {
|
if (redstone != null) {
|
||||||
if (redstone != null && (Boolean) redstone.getValue()) {
|
if ((Boolean) redstone.getValue()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
event.setNewCurrent(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Settings.REDSTONE_DISABLER) {
|
||||||
if (UUIDHandler.getPlayer(plot.owner) == null) {
|
if (UUIDHandler.getPlayer(plot.owner) == null) {
|
||||||
boolean disable = true;
|
boolean disable = true;
|
||||||
for (UUID trusted : plot.getTrusted()) {
|
for (UUID trusted : plot.getTrusted()) {
|
||||||
@ -216,10 +274,15 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (redstone == null || (Boolean) redstone.getValue()) {
|
if (Settings.REDSTONE_DISABLER_UNOCCUPIED) {
|
||||||
|
for (PlotPlayer pp : UUIDHandler.getPlayers().values()) {
|
||||||
|
if (plot.equals(pp.getCurrentPlot())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
event.setNewCurrent(0);
|
event.setNewCurrent(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,19 +4,28 @@ import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
||||||
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
|
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS)
|
* An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS)
|
||||||
@ -25,23 +34,17 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
|||||||
*/
|
*/
|
||||||
public class SendChunk {
|
public class SendChunk {
|
||||||
|
|
||||||
// Ref Class
|
// // Ref Class
|
||||||
private final RefClass classWorld = getRefClass("{nms}.World");
|
|
||||||
private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
||||||
private final RefClass classChunkCoordIntPair = getRefClass("{nms}.ChunkCoordIntPair");
|
private final RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||||
|
private final RefClass classConnection = getRefClass("{nms}.EntityPlayer.playerConnection");
|
||||||
private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||||
private final RefClass classChunk = getRefClass("{nms}.Chunk");
|
private final RefClass classCraftPlayer = getRefClass("{cb}.CraftPlayer");
|
||||||
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);
|
private RefMethod methodGetHandleChunk;
|
||||||
// Ref Method
|
private RefMethod methodGetHandlePlayer;
|
||||||
private RefMethod methodGetHandle;
|
private RefConstructor MapChunk;
|
||||||
// Ref Field
|
private RefField connection;
|
||||||
private RefField chunkCoordIntPairQueue;
|
private RefMethod send;
|
||||||
private RefField players;
|
|
||||||
private RefField locX;
|
|
||||||
private RefField locZ;
|
|
||||||
private RefField world;
|
|
||||||
// Ref Constructor
|
|
||||||
private RefConstructor ChunkCoordIntPairCon;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -49,45 +52,71 @@ public class SendChunk {
|
|||||||
* @throws NoSuchMethodException
|
* @throws NoSuchMethodException
|
||||||
*/
|
*/
|
||||||
public SendChunk() throws NoSuchMethodException {
|
public SendChunk() throws NoSuchMethodException {
|
||||||
methodGetHandle = classCraftChunk.getMethod("getHandle");
|
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
chunkCoordIntPairQueue = classEntityPlayer.getField("chunkCoordIntPairQueue");
|
methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
|
||||||
players = classWorld.getField("players");
|
MapChunk = classMapChunk.getConstructor(Chunk.class, boolean.class, int.class);
|
||||||
locX = classEntityPlayer.getField("locX");
|
connection = classCraftPlayer.getField("playerConnection");
|
||||||
locZ = classEntityPlayer.getField("locZ");
|
send = classConnection.getMethod("sendPacket", classMapChunk.getRealClass());
|
||||||
world = classChunk.getField("world");
|
|
||||||
ChunkCoordIntPairCon = classChunkCoordIntPair.getConstructor(int.class, int.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendChunk(final Collection<Chunk> chunks) {
|
public void sendChunk(final Collection<Chunk> input) {
|
||||||
int diffx, diffz;
|
HashSet<Chunk> chunks = new HashSet<Chunk>(input);
|
||||||
final int view = Bukkit.getServer().getViewDistance() << 4;
|
HashMap<String, ArrayList<Chunk>> map = new HashMap<>();
|
||||||
for (final Chunk chunk : chunks) {
|
int view = Bukkit.getServer().getViewDistance();
|
||||||
if (!chunk.isLoaded()) {
|
for (Chunk chunk : chunks) {
|
||||||
continue;
|
String world = chunk.getWorld().getName();
|
||||||
|
ArrayList<Chunk> list = map.get(world);
|
||||||
|
if (list == null) {
|
||||||
|
list = new ArrayList<>();
|
||||||
|
map.put(world, list);
|
||||||
}
|
}
|
||||||
boolean unload = true;
|
list.add(chunk);
|
||||||
final Object c = methodGetHandle.of(chunk).call();
|
}
|
||||||
final Object w = world.of(c).get();
|
for (PlotPlayer pp : UUIDHandler.getPlayers().values() ) {
|
||||||
final Object p = players.of(w).get();
|
Plot plot = pp.getCurrentPlot();
|
||||||
for (final Object ep : (List<Object>) p) {
|
Location loc = null;
|
||||||
final int x = ((Double) locX.of(ep).get()).intValue();
|
String world;
|
||||||
final int z = ((Double) locZ.of(ep).get()).intValue();
|
if (plot != null) {
|
||||||
diffx = Math.abs(x - (chunk.getX() << 4));
|
world = plot.world;
|
||||||
diffz = Math.abs(z - (chunk.getZ() << 4));
|
|
||||||
if ((diffx <= view) && (diffz <= view)) {
|
|
||||||
unload = false;
|
|
||||||
if (v1_7_10) {
|
|
||||||
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
|
||||||
chunk.load(true);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ());
|
loc = pp.getLocation();
|
||||||
final Object pq = chunkCoordIntPairQueue.of(ep).get();
|
world = loc.getWorld();
|
||||||
((List) pq).add(pair);
|
}
|
||||||
|
ArrayList<Chunk> list = map.get(world);
|
||||||
|
if (list == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (loc == null) {
|
||||||
|
loc = pp.getLocation();
|
||||||
|
}
|
||||||
|
int cx = loc.getX() >> 4;
|
||||||
|
int cz = loc.getZ() >> 4;
|
||||||
|
Player player = ((BukkitPlayer) pp).player;
|
||||||
|
Object entity = methodGetHandlePlayer.of(player).call();
|
||||||
|
|
||||||
|
for (Chunk chunk : list) {
|
||||||
|
int dx = Math.abs(cx - chunk.getX());
|
||||||
|
int dz = Math.abs(cz - chunk.getZ());
|
||||||
|
if (dx > view || dz > view) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
chunks.remove(chunk);
|
||||||
|
|
||||||
|
Object packet = MapChunk.create(chunk, true, 0);
|
||||||
|
Object con = connection.of(entity).get();
|
||||||
|
send.of(con).call(packet);
|
||||||
|
packet = MapChunk.create(chunk, true, 65565);
|
||||||
|
send.of(con).call(packet);
|
||||||
|
// Object packet = MapChunk.create(chunk, true, 0);
|
||||||
|
//
|
||||||
|
// PacketPlayOutMapChunk packet = new PacketPlayOutMapChunk(chunk, true, 0);
|
||||||
|
// entity.playerConnection.sendPacket(packet);
|
||||||
|
// packet = new PacketPlayOutMapChunk(chunk, true, 65565);
|
||||||
|
// entity.playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
for (final Chunk chunk : chunks) {
|
||||||
if (unload) {
|
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -103,8 +132,54 @@ public class SendChunk {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
//
|
||||||
}
|
//
|
||||||
|
// int diffx, diffz;
|
||||||
|
// << 4;
|
||||||
|
// for (final Chunk chunk : chunks) {
|
||||||
|
// if (!chunk.isLoaded()) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// boolean unload = true;
|
||||||
|
// final Object c = methodGetHandle.of(chunk).call();
|
||||||
|
// final Object w = world.of(c).get();
|
||||||
|
// final Object p = players.of(w).get();
|
||||||
|
// for (final Object ep : (List<Object>) p) {
|
||||||
|
// final int x = ((Double) locX.of(ep).get()).intValue();
|
||||||
|
// final int z = ((Double) locZ.of(ep).get()).intValue();
|
||||||
|
// diffx = Math.abs(x - (chunk.getX() << 4));
|
||||||
|
// diffz = Math.abs(z - (chunk.getZ() << 4));
|
||||||
|
// if ((diffx <= view) && (diffz <= view)) {
|
||||||
|
// unload = false;
|
||||||
|
// if (v1_7_10) {
|
||||||
|
// chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||||
|
// chunk.load(true);
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ());
|
||||||
|
// final Object pq = chunkCoordIntPairQueue.of(ep).get();
|
||||||
|
// ((List) pq).add(pair);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (unload) {
|
||||||
|
// TaskManager.runTask(new Runnable() {
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
// try {
|
||||||
|
// chunk.unload(true, true);
|
||||||
|
// }
|
||||||
|
// catch (Exception e) {
|
||||||
|
// String worldname = chunk.getWorld().getName();
|
||||||
|
// PS.debug("$4Could not save chunk: " + worldname + ";" + chunk.getX() + ";" + chunk.getZ());
|
||||||
|
// PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
||||||
|
// PS.debug("$3 - $4" + worldname + "/level.dat or " + worldname + "level_old.dat may be corrupt (try repairing or removing these)");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendChunk(final String worldname, final List<ChunkLoc> locs) {
|
public void sendChunk(final String worldname, final List<ChunkLoc> locs) {
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user