2014-11-08 20:27:09 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
|
|
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
|
|
|
// /
|
|
|
|
// This program is free software; you can redistribute it and/or modify /
|
|
|
|
// it under the terms of the GNU General Public License as published by /
|
|
|
|
// the Free Software Foundation; either version 3 of the License, or /
|
|
|
|
// (at your option) any later version. /
|
|
|
|
// /
|
|
|
|
// This program is distributed in the hope that it will be useful, /
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
|
|
|
// GNU General Public License for more details. /
|
|
|
|
// /
|
|
|
|
// You should have received a copy of the GNU General Public License /
|
|
|
|
// along with this program; if not, write to the Free Software Foundation, /
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
|
|
|
// /
|
|
|
|
// You can contact us via: support@intellectualsites.com /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
package com.intellectualcrafters.plot.util;
|
2014-10-02 14:54:49 +02:00
|
|
|
|
2015-01-13 17:38:15 +01:00
|
|
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
2014-11-08 20:27:09 +01:00
|
|
|
|
2015-02-15 08:40:55 +01:00
|
|
|
import java.util.List;
|
2014-12-18 03:15:11 +01:00
|
|
|
|
2015-01-13 17:38:15 +01:00
|
|
|
import org.bukkit.Chunk;
|
2015-02-11 16:37:52 +01:00
|
|
|
import org.bukkit.World;
|
2015-01-13 17:38:15 +01:00
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
|
|
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-09-25 08:39:13 +02:00
|
|
|
/**
|
2014-12-18 03:15:11 +01:00
|
|
|
* SetBlockFast class<br> Used to do fast world editing
|
2014-11-20 00:00:38 +01:00
|
|
|
*
|
|
|
|
* @author Empire92
|
2014-09-25 08:39:13 +02:00
|
|
|
*/
|
2015-02-19 04:24:05 +01:00
|
|
|
public class SetBlockFast extends SetBlockManager {
|
2015-02-19 04:38:49 +01:00
|
|
|
|
2014-09-24 14:21:43 +02:00
|
|
|
|
2014-12-18 03:15:11 +01:00
|
|
|
private static final RefClass classBlock = getRefClass("{nms}.Block");
|
|
|
|
private static final RefClass classChunk = getRefClass("{nms}.Chunk");
|
|
|
|
private static final RefClass classWorld = getRefClass("{nms}.World");
|
2014-11-05 04:42:08 +01:00
|
|
|
private static final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
|
|
|
|
2014-12-18 03:15:11 +01:00
|
|
|
private static RefMethod methodGetHandle;
|
|
|
|
private static RefMethod methodGetChunkAt;
|
|
|
|
private static RefMethod methodA;
|
|
|
|
private static RefMethod methodGetById;
|
2014-11-05 04:42:08 +01:00
|
|
|
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @throws NoSuchMethodException
|
|
|
|
*/
|
2014-11-05 04:42:08 +01:00
|
|
|
public SetBlockFast() throws NoSuchMethodException {
|
|
|
|
methodGetHandle = classCraftWorld.getMethod("getHandle");
|
|
|
|
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
|
|
|
|
methodA = classChunk.getMethod("a", int.class, int.class, int.class, classBlock, int.class);
|
|
|
|
methodGetById = classBlock.getMethod("getById", int.class);
|
|
|
|
}
|
|
|
|
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* Set the block at the location
|
2014-12-16 06:03:20 +01:00
|
|
|
*
|
2014-12-18 03:15:11 +01:00
|
|
|
* @param world World in which the block should be set
|
|
|
|
* @param x X Coordinate
|
|
|
|
* @param y Y Coordinate
|
|
|
|
* @param z Z Coordinate
|
|
|
|
* @param blockId Block ID
|
|
|
|
* @param data Block Data Value
|
|
|
|
*
|
2014-11-20 00:00:38 +01:00
|
|
|
* @return true
|
|
|
|
*/
|
2015-02-11 16:37:52 +01:00
|
|
|
@Override
|
2015-02-19 04:24:05 +01:00
|
|
|
public void set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data) {
|
2014-11-05 04:42:08 +01:00
|
|
|
final Object w = methodGetHandle.of(world).call();
|
|
|
|
final Object chunk = methodGetChunkAt.of(w).call(x >> 4, z >> 4);
|
|
|
|
final Object block = methodGetById.of(null).call(blockId);
|
|
|
|
methodA.of(chunk).call(x & 0x0f, y, z & 0x0f, block, data);
|
|
|
|
}
|
|
|
|
|
2014-11-20 00:00:38 +01:00
|
|
|
/**
|
|
|
|
* Update chunks
|
2014-12-16 06:03:20 +01:00
|
|
|
*
|
2014-12-18 03:15:11 +01:00
|
|
|
* @param player Player whose chunks we're updating
|
2014-11-20 00:00:38 +01:00
|
|
|
*/
|
2015-02-11 16:37:52 +01:00
|
|
|
@Override
|
2015-02-15 08:40:55 +01:00
|
|
|
public void update(List<Chunk> chunks) {
|
2015-02-11 16:37:52 +01:00
|
|
|
if (chunks.size() == 0) {
|
2015-01-08 09:50:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-11-21 04:11:41 +01:00
|
|
|
if (!PlotHelper.canSendChunk) {
|
2015-02-11 16:37:52 +01:00
|
|
|
World world = chunks.get(0).getWorld();
|
|
|
|
for (Chunk chunk : chunks) {
|
|
|
|
world.refreshChunk(chunk.getX(), chunk.getZ());
|
2014-11-21 04:11:41 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
SendChunk.sendChunk(chunks);
|
2014-12-18 03:15:11 +01:00
|
|
|
} catch (final Throwable e) {
|
2014-11-21 04:11:41 +01:00
|
|
|
PlotHelper.canSendChunk = false;
|
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|