Merge remote-tracking branch 'IntellectualSites/master' into testing

This commit is contained in:
zomb 2016-03-18 23:28:49 -10:00
commit f16affabcc
40 changed files with 875 additions and 676 deletions

View File

@ -78,7 +78,6 @@ 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;
@ -91,8 +90,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@ -655,25 +652,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override
public String getNMSPackage() {
final Server server = Bukkit.getServer();
final Class<?> bukkitServerClass = server.getClass();
String[] pas = bukkitServerClass.getName().split("\\.");
if (pas.length == 5) {
return pas[3];
}
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) {
return pas[3];
}
} catch (IllegalAccessException | InvocationTargetException | SecurityException | NoSuchMethodException | IllegalArgumentException e) {
e.printStackTrace();
}
PS.debug("Unknown NMS package: " + StringMan.getString(pas));
return "1_8_R3";
String name = Bukkit.getServer().getClass().getPackage().getName();
return name.substring(name.lastIndexOf('.') + 1);
}
@Override

View File

@ -1,6 +1,6 @@
package com.plotsquared.bukkit.chat;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PS;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@ -29,7 +29,6 @@ public final class Reflection {
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
*/
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>();
private static String _versionString;
private Reflection() {
@ -41,16 +40,7 @@ public final class Reflection {
* @return The version string of the OBC and NMS packages, <em>including the trailing dot</em>.
*/
public synchronized static String getVersion() {
if (_versionString == null) {
if (Bukkit.getServer() == null) {
// The server hasn't started, static initializer call?
return null;
}
final String name = Bukkit.getServer().getClass().getPackage().getName();
_versionString = name.substring(name.lastIndexOf('.') + 1) + ".";
}
return _versionString;
return PS.get().IMP.getNMSPackage();
}
/**
@ -64,7 +54,7 @@ public final class Reflection {
return _loadedNMSClasses.get(className);
}
final String fullName = "net.minecraft.server." + getVersion() + className;
final String fullName = "net.minecraft.server." + getVersion() + "." + className;
Class<?> clazz;
try {
clazz = Class.forName(fullName);
@ -90,7 +80,7 @@ public final class Reflection {
return _loadedOBCClasses.get(className);
}
final String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
final String fullName = "org.bukkit.craftbukkit." + getVersion() + "." + className;
Class<?> clazz;
try {
clazz = Class.forName(fullName);
@ -162,13 +152,7 @@ public final class Reflection {
field.setAccessible(true);
loaded.put(name, field);
return field;
} catch (NoSuchFieldException e) {
// Error loading
e.printStackTrace();
// Cache field as not existing
loaded.put(name, null);
return null;
} catch (SecurityException e) {
} catch (NoSuchFieldException | SecurityException e) {
// Error loading
e.printStackTrace();
// Cache field as not existing

View File

@ -32,10 +32,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
@Override
public Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder) {
this.plugin = plugin.toLowerCase();
prefix = plotConfig.getString("mySQLprefix");
if (prefix == null) {
prefix = plugin.toLowerCase();
}
prefix = plotConfig.getString("mySQLprefix", plugin.toLowerCase());
try {
if (plotConfig.getBoolean("usemySQL")) {
final String user = plotConfig.getString("mySQLuname");

View File

@ -234,6 +234,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
// Set the result data
result.cd = createChunkData(world);
result.grid = grid;
result.result = null;
result.result_data = null;
// Catch any exceptions (as exceptions usually thrown
try {
// Fill the result data if necessary
@ -259,9 +261,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
// Set random seed
this.random.state = (cx << 16) | (cz & 0xFFFF);
// Process the chunk
result.modified = false;
ChunkManager.preProcessChunk(result);
if (result.modified) {
if (ChunkManager.preProcessChunk(result)) {
return;
}
PlotArea area = PS.get().getPlotArea(world.getName(), null);
@ -279,6 +279,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
result.result = new short[16][];
result.result_data = new byte[16][];
result.grid = grid;
result.cd = null;
// Catch any exceptions (as exceptions usually thrown
try {
// Fill the result data

View File

@ -1196,6 +1196,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return;
}
break;
case BUILD_IRONGOLEM:
case BUILD_WITHER:
case BUILD_SNOWMAN:
case CUSTOM:
if (!area.SPAWN_CUSTOM && entity.getType().getTypeId() != 30) {
event.setCancelled(true);
@ -1505,7 +1508,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return;
}
} else if (fireball.getShooter() instanceof BlockProjectileSource) {
final Block shooter = (Block) ((BlockProjectileSource) fireball.getShooter()).getBlock();
final Block shooter = ((BlockProjectileSource) fireball.getShooter()).getBlock();
if (BukkitUtil.getLocation(shooter.getLocation()).getPlot() == null) {
e.setCancelled(true);
return;

View File

@ -534,7 +534,7 @@ public class BukkitChunkManager extends ChunkManager {
}
}
}
final PlotLoc loc = new PlotLoc(x, z);
final PlotLoc loc = new PlotLoc(x + offset_x, z + offset_z);
allblocks.put(loc, ids);
}
@ -633,133 +633,48 @@ public class BukkitChunkManager extends ChunkManager {
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
final int relX = newPos.getX() - pos1.getX();
final int relZ = newPos.getZ() - pos1.getZ();
final int relCX = relX >> 4;
final int relCZ = relZ >> 4;
final Location pos4 = new Location(newPos.getWorld(), newPos.getX() + relX, 256, newPos.getZ() + relZ);
final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
final World newWorld = Bukkit.getWorld(newPos.getWorld());
final String newWorldname = newWorld.getName();
final List<ChunkLoc> chunks = new ArrayList<>();
initMaps();
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
@Override
public void run(int[] value) {
initMaps();
final int bx = value[2];
final int bz = value[3];
final int tx = value[4];
final int tz = value[5];
// Load chunks
final ChunkLoc loc1 = new ChunkLoc(value[0], value[1]);
final ChunkLoc loc2 = new ChunkLoc(loc1.x + relCX, loc1.z + relCZ);
final Chunk c1 = oldWorld.getChunkAt(loc1.x, loc1.z);
final Chunk c2 = newWorld.getChunkAt(loc2.x, loc2.z);
c1.load(true);
c2.load(true);
chunks.add(loc2);
// entities
saveEntitiesIn(c1, region);
// copy chunk
setChunkInPlotArea(null, new RunnableVal<PlotChunk<?>>() {
@Override
public void run(PlotChunk<?> value) {
final ChunkLoc loc = new ChunkLoc(value[0], value[1]);
final int cxx = loc.x << 4;
final int czz = loc.z << 4;
final Chunk chunk = oldWorld.getChunkAt(loc.x, loc.z);
saveEntitiesIn(chunk, region);
for (int x = bx & 15; x <= (tx & 15); x++) {
for (int z = bz & 15; z <= (tz & 15); z++) {
for (int y = 1; y < 256; y++) {
Block block = c1.getBlock(x, y, z);
Material id = block.getType();
switch (id) {
case AIR:
case GRASS:
case COBBLESTONE:
case GRAVEL:
case GOLD_ORE:
case IRON_ORE:
case GLASS:
case LAPIS_ORE:
case LAPIS_BLOCK:
case WEB:
case DEAD_BUSH:
case YELLOW_FLOWER:
case BROWN_MUSHROOM:
case RED_MUSHROOM:
case GOLD_BLOCK:
case IRON_BLOCK:
case BRICK:
case TNT:
case BOOKSHELF:
case MOSSY_COBBLESTONE:
case OBSIDIAN:
case FIRE:
case REDSTONE_WIRE:
case DIAMOND_ORE:
case DIAMOND_BLOCK:
case WORKBENCH:
case SOIL:
case BEDROCK:
case WATER:
case STATIONARY_WATER:
case LAVA:
case STATIONARY_LAVA:
case REDSTONE_ORE:
case GLOWING_REDSTONE_ORE:
case SNOW:
case ICE:
case SNOW_BLOCK:
case CACTUS:
case CLAY:
case SUGAR_CANE_BLOCK:
case FENCE:
case NETHERRACK:
case SOUL_SAND:
case IRON_FENCE:
case THIN_GLASS:
case MELON_BLOCK:
case MYCEL:
case NETHER_BRICK:
case NETHER_FENCE:
case ENDER_STONE:
case DRAGON_EGG:
case EMERALD_ORE:
case EMERALD_BLOCK:
case SLIME_BLOCK:
case BARRIER:
case SEA_LANTERN:
case HAY_BLOCK:
case HARD_CLAY:
case COAL_BLOCK:
case PACKED_ICE:
case DOUBLE_STONE_SLAB2:
case STONE_SLAB2:
case SPRUCE_FENCE:
case BIRCH_FENCE:
case JUNGLE_FENCE:
case DARK_OAK_FENCE:
case ACACIA_FENCE:
value.setBlock(x, y, z, id.getId(), (byte) 0);
break;
default:
value.setBlock(x, y, z, id.getId(), block.getData());
break;
saveBlocks(oldWorld, 256, cxx + x, czz + z, relX, relZ, true);
}
}
}
}
}
}, newWorldname, loc2);
// restore chunk
restoreBlocks(newWorld, relX, relZ);
restoreEntities(newWorld, relX, relZ);
}
}, new Runnable() {
@Override
public void run() {
SetQueue.IMP.queue.sendChunk(newWorldname, chunks);
for (Entry<PlotLoc, PlotBlock[]> entry : allblocks.entrySet()) {
PlotLoc loc = entry.getKey();
PlotBlock[] blocks = entry.getValue();
for (int y = 0; y < blocks.length; y++) {
PlotBlock block = blocks[y];
if (block != null) {
SetQueue.IMP.setBlock(newWorldname, loc.x, y, loc.z, block);
}
}
}
while (SetQueue.IMP.forceChunkSet());
restoreBlocks(newWorld, 0, 0);
restoreEntities(newWorld, relX, relZ);
TaskManager.runTask(whenDone);
}
}, 5);

View File

@ -162,6 +162,22 @@ public class BukkitUtil extends WorldUtil {
return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), temp.getPitch());
}
@Override
public void setSpawn(Location loc) {
World world = getWorld(loc.getWorld());
if (world != null) {
world.setSpawnLocation(loc.getX(), loc.getY(), loc.getZ());
}
}
@Override
public void saveWorld(String worldname) {
World world = getWorld(worldname);
if (world != null) {
world.save();
}
}
@Override
public int getHighestBlock(final String world, final int x, final int z) {
return getWorld(world).getHighestBlockAt(x, z).getY();

View File

@ -2,31 +2,40 @@ package com.plotsquared.bukkit.util.block;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor;
import com.intellectualcrafters.plot.util.SetQueue;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.SendChunk;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.Map.Entry;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
public class FastQueue_1_9 extends SlowQueue {
final Object air;
private final SendChunk chunksender;
private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
private final RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
@ -41,25 +50,24 @@ public class FastQueue_1_9 extends SlowQueue {
private final RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
private final RefClass classBlock = getRefClass("{nms}.Block");
private final RefClass classIBlockData = getRefClass("{nms}.IBlockData");
private HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
private RefMethod methodGetHandleChunk;
private RefConstructor MapChunk;
private RefMethod methodInitLighting;
private RefConstructor classBlockPositionConstructor;
private RefConstructor classChunkSectionConstructor;
private RefMethod methodW;
private RefMethod methodAreNeighborsLoaded;
private RefField fieldSections;
private RefField fieldWorld;
private RefMethod methodGetBlocks;
private RefMethod methodGetType;
private RefMethod methodSetType;
private RefMethod methodGetCombinedId;
private RefMethod methodGetByCombinedId;
final Object air;
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
private final RefMethod methodGetHandleChunk;
private final RefConstructor MapChunk;
private final RefMethod methodInitLighting;
private final RefConstructor classBlockPositionConstructor;
private final RefConstructor classChunkSectionConstructor;
private final RefMethod methodW;
private final RefMethod methodAreNeighborsLoaded;
private final RefField fieldSections;
private final RefField fieldWorld;
private final RefMethod methodGetBlocks;
private final RefMethod methodGetType;
private final RefMethod methodSetType;
private final RefMethod methodGetCombinedId;
private final RefMethod methodGetByCombinedId;
public FastQueue_1_9() throws NoSuchMethodException, RuntimeException {
public FastQueue_1_9() throws RuntimeException {
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
methodInitLighting = classChunk.getMethod("initLighting");
MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
@ -106,7 +114,7 @@ public class FastQueue_1_9 extends SlowQueue {
if (!MainUtil.canSendChunk) {
for (final Chunk chunk : chunks) {
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
chunk.unload(true, false);
chunk.unload(true, true);
chunk.load();
}
return;
@ -143,16 +151,15 @@ public class FastQueue_1_9 extends SlowQueue {
final Field sf = clazz.getDeclaredField("sections");
sf.setAccessible(true);
final Field tf = clazz.getDeclaredField("tileEntities");
final Field ef = clazz.getDeclaredField("entitySlices");
final Field entitySlices = clazz.getDeclaredField("entitySlices");
final Object[] sections = (Object[]) sf.get(c);
final HashMap<?, ?> tiles = (HashMap<?, ?>) tf.get(c);
final List<?>[] entities = (List<?>[]) ef.get(c);
final Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
Method xm = null;
Method ym = null;
Method zm = null;
// Trim tiles
final Set<Entry<?, ?>> entryset = (Set<Entry<?, ?>>) (Set<?>) tiles.entrySet();
final Iterator<Entry<?, ?>> iter = entryset.iterator();
@ -228,7 +235,7 @@ public class FastQueue_1_9 extends SlowQueue {
int x = MainUtil.x_loc[j][k];
int y = MainUtil.y_loc[j][k];
int z = MainUtil.z_loc[j][k];
int id = (int) n;
int id = n;
Object iblock = methodGetByCombinedId.call((int) n);
setType.call(x, y & 15, z, iblock);
continue;
@ -292,7 +299,7 @@ public class FastQueue_1_9 extends SlowQueue {
if (!chunk.isLoaded()) {
chunk.load(false);
} else {
chunk.unload(true, false);
chunk.unload(true, true);
chunk.load(false);
}

View File

@ -17,7 +17,6 @@ public class GenChunk extends PlotChunk<Chunk> {
public short[][] result;
public byte[][] result_data;
public ChunkData cd;
public boolean modified = false;
public BiomeGrid grid;
public GenChunk(Chunk chunk, ChunkWrapper wrap) {
@ -42,7 +41,6 @@ public class GenChunk extends PlotChunk<Chunk> {
@Override
public void setBiome(int x, int z, int biome) {
modified = true;
grid.setBiome(x, z, biomes[biome]);
}
@ -55,14 +53,12 @@ public class GenChunk extends PlotChunk<Chunk> {
@Override
public void setBlock(int x, int y, int z, int id, byte data) {
if (result == null) {
modified = true;
cd.setBlock(x, y, z, id, data);
return;
}
int i = MainUtil.CACHE_I[y][x][z];
short[] v = result[i];
if (v == null) {
modified = true;
result[i] = v = new short[4096];
}
int j = MainUtil.CACHE_J[y][x][z];

View File

@ -1,8 +1,5 @@
package com.intellectualcrafters.plot;
import java.io.File;
import java.util.List;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
@ -20,6 +17,9 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
import com.intellectualcrafters.plot.util.WorldUtil;
import java.io.File;
import java.util.List;
public interface IPlotMain {
/**

View File

@ -127,8 +127,8 @@ public class PS {
private File storageFile;
private File FILE = null; // This file
private int[] VERSION = null;
private int[] LAST_VERSION;
private String PLATFORM = null;
private String LAST_VERSION;
private Database database;
private Thread thread;
@ -278,8 +278,11 @@ public class PS {
final URL url = Updater.getUpdate();
if (url != null) {
update = url;
} else if ((LAST_VERSION != null) && !StringMan.join(VERSION, ".").equals(LAST_VERSION)) {
log("&aThanks for updating from: " + LAST_VERSION + " to " + StringMan.join(VERSION, "."));
} else if (LAST_VERSION == null) {
log("&aThanks for installing PlotSquared!");
} else if (!PS.get().checkVersion(LAST_VERSION, VERSION)) {
log("&aThanks for updating from " + StringMan.join(LAST_VERSION, ".") + " to " + StringMan.join(VERSION, ".") + "!");
DBFunc.dbManager.updateTables(LAST_VERSION);
}
}
});
@ -366,16 +369,22 @@ public class PS {
return this.thread == thread;
}
public boolean checkVersion(final int[] version, final int major, final int minor, final int minor2) {
return (version[0] > major) || ((version[0] == major) && (version[1] > minor)) || ((version[0] == major) && (version[1] == minor) && (
version[2] >= minor2));
/**
* Check if `version` is >= `version2`
* @param version
* @param version2
* @return true if `version` is >= `version2`
*/
public boolean checkVersion(final int[] version, int... version2) {
return (version[0] > version2[0]) || ((version[0] == version2[0]) && (version[1] > version2[1])) || ((version[0] == version2[0]) && (version[1] == version2[1]) && (
version[2] >= version2[2]));
}
/**
* Get the last PlotSquared version
* @return last version in config or null
*/
public String getLastVersion() {
public int[] getLastVersion() {
return LAST_VERSION;
}
@ -914,6 +923,55 @@ public class PS {
return result;
}
@Deprecated
public ArrayList<Plot> sortPlotsByTimestamp(final Collection<Plot> plots) {
List<Plot> unknown = new ArrayList<>();
int hardmax = 256000;
int max = 0;
int overflowSize = 0;
for (final Plot plot : plots) {
final int hash = MathMan.getPositiveId(plot.hashCode());
if (hash > max) {
if (hash >= hardmax) {
overflowSize++;
} else {
max = hash;
}
}
}
hardmax = Math.min(hardmax, max);
final Plot[] cache = new Plot[hardmax + 1];
final List<Plot> overflow = new ArrayList<>(overflowSize);
final ArrayList<Plot> extra = new ArrayList<>();
for (final Plot plot : plots) {
final int hash = MathMan.getPositiveId(plot.hashCode());
if (hash < hardmax) {
if (hash >= 0) {
cache[hash] = plot;
} else {
extra.add(plot);
}
} else if ((Math.abs(plot.getId().x) > 15446) || (Math.abs(plot.getId().y) > 15446)) {
extra.add(plot);
} else {
overflow.add(plot);
}
}
final Plot[] overflowArray = overflow.toArray(new Plot[overflow.size()]);
sortPlotsByHash(overflowArray);
final ArrayList<Plot> result = new ArrayList<>(cache.length + overflowArray.length);
for (final Plot plot : cache) {
if (plot != null) {
result.add(plot);
}
}
Collections.addAll(result, overflowArray);
for (final Plot plot : extra) {
result.add(plot);
}
return result;
}
/**
* Sort plots by creation timestamp
* @param input
@ -921,167 +979,20 @@ public class PS {
* @return
*/
@Deprecated
public ArrayList<Plot> sortPlotsByTimestamp(final Collection<Plot> input) {
public List<Plot> sortPlotsByModified(final Collection<Plot> input) {
List<Plot> list;
if (input instanceof ArrayList<?>) {
if (input instanceof List) {
list = (List<Plot>) input;
} else {
list = new ArrayList<>(input);
}
long min = Integer.MAX_VALUE;
long max = 0;
final int size = list.size();
final int limit = Math.min(1048576, size * 2);
for (final Plot plot : list) {
final long time = plot.getTimestamp();
if (time < min) {
min = time;
}
if (time > max) {
max = time;
}
}
final long range = max - min;
try {
final ArrayList<Plot> overflow = new ArrayList<>();
Plot[] plots;
if ((range > limit) && (size > 1024)) {
plots = new Plot[limit];
final int factor = (int) ((range / limit));
for (Plot plot : list) {
int index = (int) (plot.getTimestamp() - min) / factor;
if (index < 0) {
index = 0;
}
if (index >= plots.length) {
overflow.add(plot);
continue;
}
Plot current = plots[index];
while (true) {
if (current == null) {
plots[index] = plot;
break;
}
if (current.getTimestamp() > plot.getTimestamp()) {
plots[index] = plot;
plot = current;
}
index++;
if (index >= plots.length) {
overflow.add(plot);
break;
}
current = plots[index];
}
}
} else if ((range < size) || (size < 1024)) {
final ArrayList<Plot> result = new ArrayList<>(list);
Collections.sort(result, new Comparator<Plot>() {
Collections.sort(list, new Comparator<Plot>() {
@Override
public int compare(final Plot a, final Plot b) {
if (a.getTimestamp() > b.getTimestamp()) {
return -1;
} else if (b.getTimestamp() > a.getTimestamp()) {
return 1;
}
return 0;
public int compare(Plot a, Plot b) {
return (int) Math.signum(ExpireManager.IMP.getTimestamp(a.owner) - ExpireManager.IMP.getTimestamp(b.owner));
}
});
return result;
} else if (min != 0) {
plots = new Plot[(int) range];
for (Plot plot : list) {
int index = (int) (plot.getTimestamp() - min);
if (index >= plots.length) {
overflow.add(plot);
continue;
}
Plot current = plots[index];
while (true) {
if (current == null) {
plots[index] = plot;
break;
}
if (current.getTimestamp() > plot.getTimestamp()) {
plots[index] = plot;
plot = current;
}
index++;
if (index >= plots.length) {
overflow.add(plot);
break;
}
current = plots[index];
}
}
} else {
plots = new Plot[(int) range];
for (Plot plot : list) {
int index = (int) (plot.getTimestamp());
if (index >= plots.length) {
overflow.add(plot);
continue;
}
Plot current = plots[index];
// Move everything along until a free spot is found
while (true) {
if (current == null) {
plots[index] = plot;
break;
}
if (current.getTimestamp() > plot.getTimestamp()) {
plots[index] = plot;
plot = current;
}
index++;
if (index >= plots.length) {
overflow.add(plot);
break;
}
current = plots[index];
}
}
}
final ArrayList<Plot> result = new ArrayList<>(size);
if (!overflow.isEmpty()) {
Collections.sort(overflow, new Comparator<Plot>() {
@Override
public int compare(final Plot a, final Plot b) {
if (a.getTimestamp() > b.getTimestamp()) {
return -1;
} else if (b.getTimestamp() > a.getTimestamp()) {
return 1;
}
return 0;
}
});
for (final Plot plot : overflow) {
result.add(plot);
}
}
for (int i = plots.length - 1; i >= 0; i--) {
if (plots[i] != null) {
result.add(plots[i]);
}
}
return result;
} catch (final Exception e) {
e.printStackTrace();
final ArrayList<Plot> result = new ArrayList<>(list);
Collections.sort(result, new Comparator<Plot>() {
@Override
public int compare(final Plot a, final Plot b) {
if (a.getTimestamp() > b.getTimestamp()) {
return -1;
} else if (b.getTimestamp() > a.getTimestamp()) {
return 1;
}
return 0;
}
});
return result;
}
return list;
}
/**
@ -1170,6 +1081,8 @@ public class PS {
case DISTANCE_FROM_ORIGIN:
toReturn.addAll(sortPlotsByHash(map.get(area)));
break;
case LAST_MODIFIED:
toReturn.addAll(sortPlotsByModified(map.get(area)));
default:
break;
}
@ -2039,7 +1952,12 @@ public class PS {
* Setup the default configuration (settings.yml)
*/
public void setupConfig() {
LAST_VERSION = config.getString("version");
String lastVersionString = config.getString("version");
if (lastVersionString != null) {
String[] split = lastVersionString.split("\\.");
LAST_VERSION = new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) };
}
config.set("version", StringMan.join(VERSION, "."));
config.set("platform", PLATFORM);
@ -2548,6 +2466,6 @@ public class PS {
}
public enum SortType {
CREATION_DATE, CREATION_DATE_TIMESTAMP, DISTANCE_FROM_ORIGIN
CREATION_DATE, CREATION_DATE_TIMESTAMP, LAST_MODIFIED, DISTANCE_FROM_ORIGIN
}
}

View File

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot;
import com.intellectualcrafters.json.JSONArray;
import com.intellectualcrafters.json.JSONObject;
import com.intellectualcrafters.plot.util.StringMan;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -51,13 +52,15 @@ public class Updater {
String name = asset.getString("name");
if (downloadURL.equals(name)) {
try {
String version = release.getString("name");
String[] split = release.getString("name").split("\\.");
int[] version = new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
URL url = new URL(asset.getString("browser_download_url"));
if (!PS.get().canUpdate(PS.get().config.getString("version"), version)) {
// If current version >= update
if (PS.get().checkVersion(PS.get().getVersion(), version)) {
PS.debug("&7PlotSquared is already up to date!");
return null;
}
log("&6PlotSquared " + version + " is available:");
log("&6PlotSquared " + StringMan.join(split, ".") + " is available:");
log("&8 - &3Use: &7/plot update");
log("&8 - &3Or: &7" + downloadURL);
return url;

View File

@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
@ -40,8 +39,7 @@ public class Continue extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = loc.getPlotAbs();
final Plot plot = plr.getCurrentPlot();
if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -53,7 +51,8 @@ public class Continue extends SubCommand {
MainUtil.sendMessage(plr, C.DONE_NOT_DONE);
return false;
}
if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr.getPlotCount())) {
int size = plot.getConnectedPlots().size();
if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() < plr.getPlotCount() + size)) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue");
return false;
}

View File

@ -8,15 +8,16 @@ import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BO3Handler;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.general.commands.CommandDeclaration;
import java.net.URL;
@CommandDeclaration(command = "download", aliases = { "dl" }, category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, description = "Download your plot", permission = "plots.download")
@CommandDeclaration(usage = "/plot download [schematic|bo3|world]", command = "download", aliases = { "dl" }, category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, description = "Download your plot", permission = "plots.download")
public class Download extends SubCommand {
@Override
@ -41,26 +42,63 @@ public class Download extends SubCommand {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
if (args.length == 0 || (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "sch", "schem", "schematic"))) {
plot.addRunning();
MainUtil.sendMessage(plr, C.GENERATING_LINK);
SchematicHandler.manager.getCompoundTag(plot, new RunnableVal<CompoundTag>() {
@Override
public void run(final CompoundTag value) {
TaskManager.runTaskAsync(new Runnable() {
plot.removeRunning();
SchematicHandler.manager.upload(value, null, null, new RunnableVal<URL>() {
@Override
public void run() {
final URL url = SchematicHandler.manager.upload(value, null, null);
public void run(URL url) {
if (url == null) {
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
plot.removeRunning();
return;
}
MainUtil.sendMessage(plr, url.toString());
}
});
}
});
} else if (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "bo3", "bo2", "b03", "b02")) {
if (!Permissions.hasPermission(plr, "plots.download.bo3")) {
C.NO_PERMISSION.send(plr, "plots.download.bo3");
}
plot.addRunning();
BO3Handler.upload(plot, null, null, new RunnableVal<URL>() {
@Override
public void run(URL url) {
plot.removeRunning();
if (url == null) {
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
return;
}
MainUtil.sendMessage(plr, url.toString());
}
});
} else if (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "mcr", "world", "mca")) {
if (!Permissions.hasPermission(plr, "plots.download.world")) {
C.NO_PERMISSION.send(plr, "plots.download.world");
}
MainUtil.sendMessage(plr, "&cNote: The `.mca` files are 512x512");
plot.addRunning();
WorldUtil.IMP.upload(plot, null, null, new RunnableVal<URL>() {
@Override
public void run(URL url) {
plot.removeRunning();
if (url == null) {
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
return;
}
MainUtil.sendMessage(plr, url.toString());
}
});
}
});
else {
C.COMMAND_SYNTAX.send(plr, getUsage());
return false;
}
MainUtil.sendMessage(plr, C.GENERATING_LINK);
return true;
}
}

View File

@ -374,14 +374,14 @@ public class MainCommand extends CommandManager<PlotPlayer> {
// ex. /p h:2 SomeUsername
// > /p h SomeUsername 2
String[] temp = label.split(":");
if (temp.length == 2) {
label = temp[0];
String[] tempArgs = new String[args.length + 1];
System.arraycopy(args, 0, tempArgs, 0, args.length);
tempArgs[tempArgs.length - 1] = temp[1];
args = tempArgs;
}
}
cmd = getInstance().commands.get(label.toLowerCase());
} else {
cmd = null;

View File

@ -64,11 +64,12 @@ public class Save extends SubCommand {
final String world = plot.getArea().toString().replaceAll(";", "-").replaceAll("[^A-Za-z0-9]", "");
final String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name;
final UUID uuid = plr.getUUID();
final URL url = SchematicHandler.manager.upload(value, uuid, file);
SchematicHandler.manager.upload(value, uuid, file, new RunnableVal<URL>() {
@Override
public void run(URL url) {
plot.removeRunning();
if (url == null) {
MainUtil.sendMessage(plr, C.SAVE_FAILED);
plot.removeRunning();
return;
}
MainUtil.sendMessage(plr, C.SAVE_SUCCESS);
@ -76,7 +77,8 @@ public class Save extends SubCommand {
if (schematics != null) {
schematics.add(file);
}
plot.removeRunning();
}
});
}
});
}

View File

@ -30,8 +30,12 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@CommandDeclaration(
command = "visit",
@ -82,8 +86,6 @@ public class Visit extends SubCommand {
}
if (user != null) {
unsorted = PS.get().getBasePlots(user);
} else if (PS.get().getPlotAreaByString(args[0]) != null) {
unsorted = PS.get().getPlotAreaByString(args[0]).getPlots();
} else {
final Plot plot = MainUtil.getPlotFromString(player, args[0], true);
if (plot != null) {

View File

@ -23,18 +23,18 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "plugin", permission = "plots.use", description = "Show plugin information", aliases = { "version" }, category = CommandCategory.INFO)
@CommandDeclaration(command = "plugin", permission = "plots.use", description = "Show plugin information", aliases = "version",
category = CommandCategory.INFO)
public class plugin extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
MainUtil.sendMessage(plr, String.format("$2>> $1&lPlotSquared $2($1Version$2: $1%s$2)", StringMan.join(PS.get().IMP.getPluginVersion(), ".")));
MainUtil.sendMessage(plr, String.format("$2>> $1&lPlotSquared $2($1Version$2: $1%s$2)", PS.get().IMP.getPluginVersion()));
MainUtil.sendMessage(plr, "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92");
MainUtil.sendMessage(plr, "$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki");
MainUtil.sendMessage(plr, "$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? StringMan.join(PS.get().IMP.getPluginVersion(), ".") : PS.get().update));
MainUtil.sendMessage(plr, "$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? PS.get().IMP.getPluginVersion() : PS.get().update));
return true;
}
}

View File

@ -353,4 +353,6 @@ public interface AbstractDB {
void close();
void replaceWorld(String oldWorld, String newWorld, PlotId min, PlotId max);
void updateTables(int[] oldVersion);
}

View File

@ -173,7 +173,6 @@ public class SQLManager implements AbstractDB {
CREATE_TIERS = "INSERT INTO `" + prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values ";
CREATE_PLOT = "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) VALUES(?, ?, ?, ?, ?)";
CREATE_CLUSTER = "INSERT INTO `" + prefix + "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
updateTables();
createTables();
}
@ -1100,8 +1099,7 @@ public class SQLManager implements AbstractDB {
+ " `flags` VARCHAR(512) DEFAULT NULL,"
+ " `merged` INT(11) DEFAULT NULL,"
+ " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT',"
+ " PRIMARY KEY (`plot_plot_id`),"
+ " UNIQUE KEY `unique_alias` (`alias`)"
+ " PRIMARY KEY (`plot_plot_id`)"
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8");
stmt.addBatch("CREATE TABLE IF NOT EXISTS `"
+ prefix
@ -1469,11 +1467,14 @@ public class SQLManager implements AbstractDB {
return Integer.MAX_VALUE;
}
public void updateTables() {
if (PS.get().getVersion().equals(PS.get().getLastVersion()) || (PS.get().getLastVersion() == null)) {
return;
}
public void updateTables(int[] oldVersion) {
try {
if (MYSQL && !PS.get().checkVersion(oldVersion, 3, 3, 2)) {
try (Statement stmt = connection.createStatement()) {
stmt.executeUpdate("ALTER TABLE `" + prefix + "plots` DROP INDEX `unique_alias`");
}
catch (SQLException ignore) {}
}
final DatabaseMetaData data = connection.getMetaData();
ResultSet rs = data.getColumns(null, null, prefix + "plot_comments", "plot_plot_id");
if (rs.next()) {
@ -1559,17 +1560,17 @@ public class SQLManager implements AbstractDB {
@Override
public String getCreateMySQL(int size) {
return getCreateMySQL(1, "DELETE FROM `" + table + "` WHERE `" + prefix + column + "` IN ", size);
return getCreateMySQL(1, "DELETE FROM `" + table + "` WHERE `" + column + "` IN ", size);
}
@Override
public String getCreateSQLite(int size) {
return getCreateMySQL(1, "DELETE FROM `" + table + "` WHERE `" + prefix + column + "` IN ", size);
return getCreateMySQL(1, "DELETE FROM `" + table + "` WHERE `" + column + "` IN ", size);
}
@Override
public String getCreateSQL() {
return "DELETE FROM `" + table + "` WHERE `" + prefix + column + "` = ?";
return "DELETE FROM `" + table + "` WHERE `" + column + "` = ?";
}
@Override
@ -1662,7 +1663,7 @@ public class SQLManager implements AbstractDB {
if (Settings.AUTO_PURGE) {
toDelete.add(id);
} else {
PS.debug("&cPLOT " + id + " in `plot` is a duplicate. Delete this plot or set `auto-purge: true` in the settings.yml.");
PS.debug("&cPLOT " + id + " in `" + prefix + "plot` is a duplicate. Delete this plot or set `auto-purge: true` in the settings.yml.");
}
continue;
}
@ -1673,7 +1674,7 @@ public class SQLManager implements AbstractDB {
}
plots.put(id, p);
}
deleteRows(toDelete, "plot", "id");
deleteRows(toDelete, prefix + "plot", "id");
}
if (Settings.CACHE_RATINGS) {
try (ResultSet r = stmt.executeQuery("SELECT `plot_plot_id`, `player`, `rating` FROM `" + prefix + "plot_rating`")) {
@ -1695,7 +1696,7 @@ public class SQLManager implements AbstractDB {
PS.debug("&cENTRY " + id + " in `plot_rating` does not exist. Create this plot or set `auto-purge: true` in the settings.yml.");
}
}
deleteRows(toDelete, "plot_rating", "plot_plot_id");
deleteRows(toDelete, prefix + "plot_rating", "plot_plot_id");
}
}
@ -1721,7 +1722,7 @@ public class SQLManager implements AbstractDB {
PS.debug("&cENTRY " + id + " in `plot_helpers` does not exist. Create this plot or set `auto-purge: true` in the settings.yml.");
}
}
deleteRows(toDelete, "plot_helpers", "plot_plot_id");
deleteRows(toDelete, prefix + "plot_helpers", "plot_plot_id");
}
/*
@ -1746,7 +1747,7 @@ public class SQLManager implements AbstractDB {
PS.debug("&cENTRY " + id + " in `plot_trusted` does not exist. Create this plot or set `auto-purge: true` in the settings.yml.");
}
}
deleteRows(toDelete, "plot_trusted", "plot_plot_id");
deleteRows(toDelete, prefix + "plot_trusted", "plot_plot_id");
}
/*
@ -1771,7 +1772,7 @@ public class SQLManager implements AbstractDB {
PS.debug("&cENTRY " + id + " in `plot_denied` does not exist. Create this plot or set `auto-purge: true` in the settings.yml.");
}
}
deleteRows(toDelete, "plot_denied", "plot_plot_id");
deleteRows(toDelete, prefix + "plot_denied", "plot_plot_id");
}
try (ResultSet r = stmt.executeQuery("SELECT * FROM `" + prefix + "plot_settings`")) {
@ -1850,7 +1851,7 @@ public class SQLManager implements AbstractDB {
}
}
stmt.close();
deleteRows(toDelete, "plot_settings", "plot_plot_id");
deleteRows(toDelete, prefix + "plot_settings", "plot_plot_id");
}
if (!plots.entrySet().isEmpty()) {
createEmptySettings(new ArrayList<>(plots.keySet()), null);
@ -2836,11 +2837,11 @@ public class SQLManager implements AbstractDB {
@Override
public boolean deleteTables() {
try {
try (Statement stmt = connection.createStatement();
PreparedStatement statement = connection.prepareStatement("DROP TABLE `" + prefix + "plot`")) {
close();
CLOSED = false;
SQLManager.this.connection = database.forceConnection();
final Statement stmt = connection.createStatement();
stmt.addBatch("DROP TABLE `" + prefix + "cluster_invited`");
stmt.addBatch("DROP TABLE `" + prefix + "cluster_helpers`");
stmt.addBatch("DROP TABLE `" + prefix + "cluster`");
@ -2852,9 +2853,6 @@ public class SQLManager implements AbstractDB {
stmt.addBatch("DROP TABLE `" + prefix + "plot_denied`");
stmt.executeBatch();
stmt.clearBatch();
stmt.close();
final PreparedStatement statement = connection.prepareStatement("DROP TABLE `" + prefix + "plot`");
statement.executeUpdate();
statement.close();
} catch (ClassNotFoundException | SQLException e) {
@ -3001,7 +2999,6 @@ public class SQLManager implements AbstractDB {
stmt.setString(1, newWorld);
stmt.setString(2, oldWorld);
stmt.executeUpdate();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
@ -3009,14 +3006,12 @@ public class SQLManager implements AbstractDB {
stmt.setString(1, newWorld);
stmt.setString(2, oldWorld);
stmt.executeUpdate();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
} else {
try (PreparedStatement stmt = connection.prepareStatement("UPDATE `"
+ prefix
+ "plot` SET `world` = ? WHERE `world` = ? AND `plot_id_x` BETWEEN ? AND ? AND `plot_id_z` BETWEEN ? AND ?")) {
+ prefix + "plot` SET `world` = ? WHERE `world` = ? AND `plot_id_x` BETWEEN ? AND ? AND `plot_id_z` BETWEEN ? AND ?")) {
stmt.setString(1, newWorld);
stmt.setString(2, oldWorld);
stmt.setInt(3, min.x);
@ -3024,7 +3019,6 @@ public class SQLManager implements AbstractDB {
stmt.setInt(5, min.y);
stmt.setInt(6, max.y);
stmt.executeUpdate();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
@ -3038,7 +3032,6 @@ public class SQLManager implements AbstractDB {
stmt.setInt(5, min.x);
stmt.setInt(6, min.y);
stmt.executeUpdate();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
@ -3071,7 +3064,6 @@ public class SQLManager implements AbstractDB {
stmt.executeUpdate(
"UPDATE `" + prefix + "plot_trusted` SET `user_uuid` = '" + now.toString() + "' WHERE `user_uuid` = '" + old.toString()
+ "'");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}

View File

@ -97,9 +97,6 @@ public class AbstractFlag {
@Override
public boolean equals(final Object other) {
if (other == null) {
return false;
}
if (other == this) {
return true;
}

View File

@ -0,0 +1,8 @@
package com.intellectualcrafters.plot.flag;
public class BooleanFlag extends Flag<Boolean> {
public BooleanFlag(String name) {
super(name);
}
}

View File

@ -25,9 +25,10 @@ import com.intellectualcrafters.plot.util.StringMan;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Flag implements Cloneable {
public class Flag<T> implements Cloneable {
private AbstractFlag key;
private Object value;
private String name;
/**
* Flag object used to store basic information for a Plot. Flags are a key/value pair. For a flag to be usable by a
@ -60,6 +61,10 @@ public class Flag implements Cloneable {
this.value = value;
}
public Flag(String name) {
this.name = name;
}
/**
* Get the AbstractFlag used in creating the flag
*
@ -145,4 +150,8 @@ public class Flag implements Cloneable {
}
return this;
}
public String getName() {
return name;
}
}

View File

@ -1,12 +1,19 @@
package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.util.MainUtil;
import java.io.File;
public class BO3 {
private final ChunkLoc chunk;
private final String world;
private final StringBuilder blocks;
private final StringBuilder children;
private final String name;
public BO3(final String name, final ChunkLoc loc) {
public BO3(final String name, final String world, final ChunkLoc loc) {
this.world = world;
this.name = name;
chunk = loc;
blocks = new StringBuilder();
@ -22,6 +29,10 @@ public class BO3 {
return chunk;
}
public String getWorld() {
return world;
}
public String getName() {
return name;
}
@ -42,4 +53,12 @@ public class BO3 {
public String getChildren() {
return children.toString();
}
public File getFile() {
return MainUtil.getFile(PS.get().IMP.getDirectory(), Settings.BO3_SAVE_PATH + File.separator + getWorld() + File.separator + getFilename());
}
public String getFilename() {
return name + (((chunk.x == 0) && (chunk.z == 0)) ? "" : ("_" + chunk.x + "_" + chunk.z)) + ".bo3";
}
}

View File

@ -36,7 +36,7 @@ public class BlockLoc {
return true;
}
if (obj == null) {
return false;
return x == 0 && y == 0 && z == 0;
}
if (getClass() != obj.getClass()) {
return false;
@ -47,7 +47,11 @@ public class BlockLoc {
@Override
public String toString() {
if (x == 0 && y == 0 && z == 0) {
return "";
}
return x + "," + y + "," + z + "," + yaw + "," + pitch;
}
public static BlockLoc fromString(final String string) {

View File

@ -564,7 +564,9 @@ public class Plot {
* @return true if merged in that direction
*/
public boolean getMerged(final int direction) {
if (isMerged()) {
if (settings == null) {
return false;
}
switch (direction) {
case 0:
case 1:
@ -596,9 +598,6 @@ public class Plot {
}
return false;
} else {
return false;
}
}
/**
@ -1129,13 +1128,13 @@ public class Plot {
* @param loc
*/
public void setHome(final BlockLoc loc) {
final BlockLoc pos = this.getSettings().getPosition();
if (pos.equals(new BlockLoc(0, 0, 0)) && loc == null || pos.equals(loc)) {
final Plot plot = this.getBasePlot(false);
final BlockLoc pos = plot.getSettings().getPosition();
if (new BlockLoc(0, 0, 0).equals(loc)) {
return;
}
final Plot plot = this.getBasePlot(false);
plot.getSettings().setPosition(loc);
DBFunc.setPosition(plot, this.getSettings().getPosition().toString());
DBFunc.setPosition(plot, plot.getSettings().getPosition().toString());
}
/**
@ -1761,25 +1760,38 @@ public class Plot {
}
/**
* Upload the plot as a schematic to the configured web interface
* Upload the plot as a schematic to the configured web interface<br>
* @param whenDone value will be null if uploading fails
*/
public void upload(final RunnableVal<URL> whenDone) {
SchematicHandler.manager.getCompoundTag(this, new RunnableVal<CompoundTag>() {
@Override
public void run(final CompoundTag value) {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
final URL url = SchematicHandler.manager.upload(value, null, null);
if (whenDone != null) {
whenDone.value = url;
}
TaskManager.runTask(whenDone);
SchematicHandler.manager.upload(value, null, null, whenDone);
}
});
}
});
/**
* Upload this plot as a world file<br>
* - The mca files are each 512x512, so depending on the plot size it may also download adjacent plots<br>
* - Works best when (plot width + road width) % 512 == 0<br>
* @see com.intellectualcrafters.plot.util.WorldUtil
* @param whenDone
*/
public void uploadWorld(RunnableVal<URL> whenDone) {
WorldUtil.IMP.upload(this, null, null, whenDone);
}
/**
* Upload this plot as a BO3<br>
* - May not work on non default generator<br>
* - BO3 includes flags/ignores plot main/floor block<br>
* @see com.intellectualcrafters.plot.util.BO3Handler
* @param whenDone
*/
public void uploadBO3(RunnableVal<URL> whenDone) {
BO3Handler.upload(this, null, null, whenDone);
}
@Override
@ -2308,9 +2320,6 @@ public class Plot {
connected_cache.add(current);
queuecache.remove(current);
merged = current.getMerged();
for (int i = 0; i < 5; i++) {
}
if (merged[0]) {
tmp = current.area.getPlotAbs(current.id.getRelative(0));
if ((tmp != null) && !queuecache.contains(tmp) && !connected_cache.contains(tmp)) {
@ -2780,7 +2789,7 @@ public class Plot {
// copy data
for (final Plot plot : plots) {
final Plot other = plot.getRelative(offset.x, offset.y);
other.create(other.owner, false);
other.create(plot.owner, false);
if (!plot.getFlags().isEmpty()) {
other.getSettings().flags = plot.getFlags();
DBFunc.setFlags(other, plot.getFlags().values());
@ -2790,19 +2799,19 @@ public class Plot {
}
if ((plot.members != null) && !plot.members.isEmpty()) {
other.members = plot.members;
for (final UUID member : other.members) {
for (final UUID member : plot.members) {
DBFunc.setMember(other, member);
}
}
if ((plot.trusted != null) && !plot.trusted.isEmpty()) {
other.trusted = plot.trusted;
for (final UUID trusted : other.trusted) {
for (final UUID trusted : plot.trusted) {
DBFunc.setTrusted(other, trusted);
}
}
if ((plot.denied != null) && !plot.denied.isEmpty()) {
other.denied = plot.denied;
for (final UUID denied : other.denied) {
for (final UUID denied : plot.denied) {
DBFunc.setDenied(other, denied);
}
}

View File

@ -21,10 +21,11 @@
package com.intellectualcrafters.plot.object;
/**
*/
public class PlotBlock {
public static PlotBlock EVERYTHING = new PlotBlock((short) 0, (byte) 0);
public final static PlotBlock EVERYTHING = new PlotBlock((short) 0, (byte) 0);
public final short id;
public final byte data;

View File

@ -18,6 +18,11 @@ public class PlotLoc {
return result;
}
@Override
public String toString() {
return x + "," + z;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {

View File

@ -12,8 +12,13 @@ import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
@ -22,11 +27,14 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class BO3Handler {
/**
* @see #saveBO3(PlotPlayer, Plot)
* @see #saveBO3(PlotPlayer, Plot, RunnableVal)
* @param plot
* @return if successfully exported
*/
@ -34,6 +42,15 @@ public class BO3Handler {
return saveBO3(null, plot);
}
public static boolean saveBO3(final PlotPlayer player, final Plot plot) {
return saveBO3(player, plot, new RunnableVal<BO3>() {
@Override
public void run(BO3 bo3) {
save(plot, bo3);
}
});
}
public static boolean contains(final PlotBlock[] blocks, final PlotBlock block) {
for (final PlotBlock item : blocks) {
if (item.equals(block)) {
@ -50,7 +67,10 @@ public class BO3Handler {
* @param plot
* @return
*/
public static boolean saveBO3(final PlotPlayer plr, final Plot plot) {
public static boolean saveBO3(final PlotPlayer plr, final Plot plot, RunnableVal<BO3> saveTask) {
if (saveTask == null) {
throw new IllegalArgumentException("Save task cannot be null!");
}
final PlotArea plotworld = plot.getArea();
if (!(plotworld instanceof ClassicPlotWorld) || (plotworld.TYPE != 0)) {
MainUtil.sendMessage(plr, "BO3 exporting only supports type 0 classic generation.");
@ -83,8 +103,8 @@ public class BO3Handler {
boolean content = false;
for (RegionWrapper region : regions) {
Location pos1 = new Location(plot.getArea().worldname, region.minX, region.minY, region.minZ);
Location pos2 = new Location(plot.getArea().worldname, region.maxX, region.maxY, region.maxZ);
Location pos1 = new Location(plotworld.worldname, region.minX, region.minY, region.minZ);
Location pos2 = new Location(plotworld.worldname, region.maxX, region.maxY, region.maxZ);
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
final int X = ((x + 7) - cx) >> 4;
final int xx = (x - cx) % 16;
@ -97,7 +117,7 @@ public class BO3Handler {
final PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, y, z));
if (!contains(cpw.MAIN_BLOCK, block)) {
if (bo3 == null) {
bo3 = new BO3(alias, loc);
bo3 = new BO3(alias, plotworld.worldname, loc);
map.put(loc, bo3);
content = true;
}
@ -107,7 +127,7 @@ public class BO3Handler {
final PlotBlock floor = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, height, z));
if (!contains(cpw.TOP_BLOCK, floor)) {
if (bo3 == null) {
bo3 = new BO3(alias, loc);
bo3 = new BO3(alias, plotworld.worldname, loc);
map.put(loc, bo3);
content = true;
}
@ -117,7 +137,7 @@ public class BO3Handler {
final PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, y, z));
if (block.id != 0) {
if (bo3 == null) {
bo3 = new BO3(alias, loc);
bo3 = new BO3(alias, plotworld.worldname, loc);
map.put(loc, bo3);
content = true;
}
@ -164,14 +184,78 @@ public class BO3Handler {
}
for (final Entry<ChunkLoc, BO3> entry : map.entrySet()) {
save(plot, entry.getValue());
saveTask.run(entry.getValue());
}
MainUtil.sendMessage(plr, "BO3 exporting was successful!");
return true;
}
public static void upload(final Plot plot, final UUID uuid, final String file, final RunnableVal<URL> whenDone) {
if (plot == null) {
throw new IllegalArgumentException("Arguments may not be null!");
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (final ZipOutputStream zos = new ZipOutputStream(baos)) {
saveBO3(null, plot, new RunnableVal<BO3>() {
@Override
public void run(BO3 bo3) {
try {
final ZipEntry ze = new ZipEntry(bo3.getFilename());
zos.putNextEntry(ze);
write(zos, plot, bo3);
zos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
catch (IOException e) {
e.printStackTrace();
whenDone.run();
return;
}
MainUtil.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
@Override
public void run(OutputStream output) {
try {
output.write(baos.toByteArray());
baos.flush();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}, whenDone);
}
public static void write(OutputStream stream, final Plot plot, BO3 bo3) throws IOException {
File base = getBaseFile(bo3.getWorld());
final List<String> lines = Files.readAllLines(base.toPath(), StandardCharsets.UTF_8);
for (int i = 0; i < lines.size(); i++) {
final String line = lines.get(i).trim();
final String result = StringMan.replaceAll(line, "%owner%", MainUtil.getName(plot.owner), "%alias%", plot.toString(), "%blocks%", bo3.getBlocks(), "%branches%", bo3.getChildren(),
"%flags%", StringMan.join(FlagManager.getPlotFlags(plot).values(), ","));
if (!StringMan.isEqual(result, line)) {
lines.set(i, result);
}
}
stream.write(StringMan.join(lines, System.getProperty("line.separator")).getBytes());
}
public static boolean save(final Plot plot, final BO3 bo3) {
try {
File bo3File = bo3.getFile();
bo3File.createNewFile();
try (FileOutputStream fos = new FileOutputStream(bo3File)) {
write(fos, plot, bo3);
}
} catch (final Exception e) {
e.printStackTrace();
return false;
}
final File base = getBaseFile(plot.getArea().worldname);
try {
final List<String> lines = Files.readAllLines(base.toPath(), StandardCharsets.UTF_8);

View File

@ -49,18 +49,22 @@ public abstract class ChunkManager {
}
}
public static void preProcessChunk(PlotChunk<?> chunk) {
public static boolean preProcessChunk(PlotChunk<?> chunk) {
if (CURRENT_FORCE_CHUNK != null) {
CURRENT_FORCE_CHUNK.run(chunk);
CURRENT_FORCE_CHUNK = null;
return true;
}
return false;
}
public static void postProcessChunk(PlotChunk<?> chunk) {
public static boolean postProcessChunk(PlotChunk<?> chunk) {
if (CURRENT_ADD_CHUNK != null) {
CURRENT_ADD_CHUNK.run(chunk);
CURRENT_ADD_CHUNK = null;
return true;
}
return false;
}
public static void largeRegionTask(final String world, final RegionWrapper region, final RunnableVal<ChunkLoc> task, final Runnable whenDone) {

View File

@ -21,6 +21,7 @@ import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
public class ExpireManager {
@ -45,6 +46,11 @@ public class ExpireManager {
}
}
public long getTimestamp(UUID uuid) {
Long value = dates_cache.get(uuid);
return value == null ? 0 : value;
}
public void confirmExpiry(final PlotPlayer pp) {
if (Settings.AUTO_CLEAR_CONFIRMATION && plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) {
final int num = plotsToDelete.size();
@ -233,8 +239,7 @@ public class ExpireManager {
}
if ((last = opp.getLastPlayed()) != 0) {
dates_cache.put(uuid, last);
}
else {
} else {
return false;
}
}
@ -242,7 +247,7 @@ public class ExpireManager {
return false;
}
final long compared = System.currentTimeMillis() - last;
if (compared >= (86400000l * Settings.AUTO_CLEAR_DAYS)) {
if (compared >= (TimeUnit.DAYS.toMillis(Settings.AUTO_CLEAR_DAYS))) {
return true;
}
}

View File

@ -26,12 +26,35 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import java.io.File;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.regex.Matcher;
/**
@ -106,6 +129,86 @@ public class MainUtil {
}
}
public static void upload(UUID uuid, String file, String extension, final RunnableVal<OutputStream> writeTask, final RunnableVal<URL> whenDone) {
if (writeTask == null) {
PS.debug("&cWrite task cannot be null");
TaskManager.runTask(whenDone);
return;
}
final String filename;
final String website;
if (uuid == null) {
uuid = UUID.randomUUID();
website = Settings.WEB_URL + "upload.php?" + uuid;
filename = "plot." + extension;
} else {
website = Settings.WEB_URL + "save.php?" + uuid;
filename = file + "." + extension;
}
final URL url;
try {
url = new URL(Settings.WEB_URL + "?key=" + uuid + "&ip=" + Settings.WEB_IP + "&type=" + extension);
} catch (MalformedURLException e) {
e.printStackTrace();
whenDone.run();
return;
}
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
try {
final String boundary = Long.toHexString(System.currentTimeMillis());
final URLConnection con = new URL(website).openConnection();
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
try (OutputStream output = con.getOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) {
final String CRLF = "\r\n";
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
writer.append("Content-Type: text/plain; charset=" + StandardCharsets.UTF_8.displayName()).append(CRLF);
final String param = "value";
writer.append(CRLF).append(param).append(CRLF).flush();
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"schematicFile\"; filename=\"" + filename + "\"").append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(filename)).append(CRLF);
writer.append("Content-Transfer-Encoding: binary").append(CRLF);
writer.append(CRLF).flush();
writeTask.value = output;
writeTask.run();
output.flush();
writer.append(CRLF).flush();
writer.append("--" + boundary + "--").append(CRLF).flush();
}
// try (Reader response = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)) {
// final char[] buffer = new char[256];
// final StringBuilder result = new StringBuilder();
// while (true) {
// final int r = response.read(buffer);
// if (r < 0) {
// break;
// }
// result.append(buffer, 0, r);
// }
// if (!result.toString().startsWith("Success")) {
// PS.debug(result);
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
final int responseCode = ((HttpURLConnection) con).getResponseCode();
if (responseCode == 200) {
whenDone.value = url;
}
TaskManager.runTask(whenDone);
} catch (Exception e) {
e.printStackTrace();
TaskManager.runTask(whenDone);
}
}
});
}
/**
* Resets the biome if it was modified
* @param area

View File

@ -24,7 +24,6 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@ -34,14 +33,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@ -566,72 +561,26 @@ public abstract class SchematicHandler {
return null;
}
public URL upload(final CompoundTag tag, UUID uuid, String file) {
public void upload(final CompoundTag tag, UUID uuid, String file, RunnableVal<URL> whenDone) {
if (tag == null) {
PS.debug("&cCannot save empty tag");
return null;
TaskManager.runTask(whenDone);
return;
}
MainUtil.upload(uuid, file, "schematic", new RunnableVal<OutputStream>() {
@Override
public void run(OutputStream output) {
try {
String website;
if (uuid == null) {
uuid = UUID.randomUUID();
website = Settings.WEB_URL + "upload.php?" + uuid;
file = "plot";
} else {
website = Settings.WEB_URL + "save.php?" + uuid;
}
final String boundary = Long.toHexString(System.currentTimeMillis());
final URLConnection con = new URL(website).openConnection();
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
try (OutputStream output = con.getOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8), true)) {
final String CRLF = "\r\n";
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"param\"").append(CRLF);
writer.append("Content-Type: text/plain; charset=" + StandardCharsets.UTF_8.displayName()).append(CRLF);
final String param = "value";
writer.append(CRLF).append(param).append(CRLF).flush();
writer.append("--" + boundary).append(CRLF);
writer.append("Content-Disposition: form-data; name=\"schematicFile\"; filename=\"" + file + ".schematic" + "\"").append(CRLF);
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(file + ".schematic")).append(CRLF);
writer.append("Content-Transfer-Encoding: binary").append(CRLF);
writer.append(CRLF).flush();
final GZIPOutputStream gzip = new GZIPOutputStream(output);
final NBTOutputStream nos = new NBTOutputStream(gzip);
GZIPOutputStream gzip = new GZIPOutputStream(output, true);
NBTOutputStream nos = new NBTOutputStream(gzip);
nos.writeTag(tag);
gzip.finish();
nos.flush();
output.flush();
writer.append(CRLF).flush();
writer.append("--" + boundary + "--").append(CRLF).flush();
nos.close();
}
// try (Reader response = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)) {
// final char[] buffer = new char[256];
// final StringBuilder result = new StringBuilder();
// while (true) {
// final int r = response.read(buffer);
// if (r < 0) {
// break;
// }
// result.append(buffer, 0, r);
// }
// if (!result.toString().equals("The file plot.schematic has been uploaded.")) {
// PS.debug(result);
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
final int responseCode = ((HttpURLConnection) con).getResponseCode();
if (responseCode != 200) {
return null;
}
return new URL(Settings.WEB_URL + "?key=" + uuid + "&ip=" + Settings.WEB_IP);
gzip.flush();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}, whenDone);
}
/**

View File

@ -1,9 +1,20 @@
package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public abstract class WorldUtil {
public static WorldUtil IMP;
@ -20,6 +31,10 @@ public abstract class WorldUtil {
public abstract Location getSpawn(String world);
public abstract void setSpawn(Location loc);
public abstract void saveWorld(String world);
public abstract String getClosestMatchingName(PlotBlock plotBlock);
public abstract boolean isBlockSolid(PlotBlock block);
@ -37,4 +52,78 @@ public abstract class WorldUtil {
public abstract void setSign(String world, int x, int y, int z, String[] lines);
public abstract void setBiomes(String world, RegionWrapper region, String biome);
public void upload(final Plot plot, final UUID uuid, final String file, final RunnableVal<URL> whenDone) {
if (plot == null) {
throw new IllegalArgumentException("Plot may not be null!");
}
final Location home = plot.getHome();
MainUtil.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
@Override
public void run(OutputStream output) {
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
final byte[] buffer = new byte[1024];
final File dat = getDat(plot.getArea().worldname);
Location spawn = getSpawn(plot.getArea().worldname);
setSpawn(home);
if (dat != null) {
final ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName());
zos.putNextEntry(ze);
final FileInputStream in = new FileInputStream(dat);
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
}
setSpawn(spawn);
for (Plot current : plot.getConnectedPlots()) {
final Location bot = current.getBottomAbs();
final Location top = current.getTopAbs();
final int brx = bot.getX() >> 9;
final int brz = bot.getZ() >> 9;
final int trx = top.getX() >> 9;
final int trz = top.getZ() >> 9;
for (int x = brx; x <= trx; x++) {
for (int z = brz; z <= trz; z++) {
final File file = getMcr(plot.getArea().worldname, x, z);
if (file != null) {
//final String name = "r." + (x - cx) + "." + (z - cz) + ".mca";
String name = file.getName();
final ZipEntry ze = new ZipEntry("world" + File.separator + "region" + File.separator + name);
zos.putNextEntry(ze);
final FileInputStream in = new FileInputStream(file);
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
in.close();
}
}
}
}
zos.closeEntry();
zos.flush();
zos.finish();
} catch (IOException e) {
e.printStackTrace();
}
}
}, whenDone);
}
public File getDat(final String world) {
final File file = new File(PS.get().IMP.getWorldContainer() + File.separator + world + File.separator + "level.dat");
if (file.exists()) {
return file;
}
return null;
}
public File getMcr(final String world, final int x, final int z) {
final File file = new File(PS.get().IMP.getWorldContainer(), world + File.separator + "region" + File.separator + "r." + x + "." + z + ".mca");
if (file.exists()) {
return file;
}
return null;
}
}

View File

@ -3,6 +3,7 @@ package com.plotsquared.listener;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.MainUtil;
@ -14,13 +15,15 @@ import com.sk89q.worldedit.command.tool.Tool;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.*;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.ChangeSetExtent;
import com.sk89q.worldedit.extent.MaskingExtent;
import com.sk89q.worldedit.extent.reorder.MultiStageReorder;
import com.sk89q.worldedit.extent.world.FastModeExtent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.World;
import java.lang.reflect.Field;
import java.util.HashSet;
@ -39,10 +42,21 @@ public class WESubscriber {
if (actor != null && actor.isPlayer()) {
final String name = actor.getName();
final PlotPlayer pp = PlotPlayer.wrap(name);
if (pp != null && pp.getAttribute("worldedit")) {
final HashSet<RegionWrapper> mask;
if (pp == null) {
Player player = (Player) actor;
Location loc = player.getLocation();
com.intellectualcrafters.plot.object.Location pLoc = new com.intellectualcrafters.plot.object.Location(player.getWorld().getName(), loc.getBlockX(), loc.getBlockX(), loc.getBlockZ());
Plot plot = pLoc.getPlot();
if (plot == null) {
event.setExtent(new com.sk89q.worldedit.extent.NullExtent());
return;
}
final HashSet<RegionWrapper> mask = WEManager.getMask(pp);
mask = plot.getRegions();
} else if (pp.getAttribute("worldedit")) {
return;
} else {
mask = WEManager.getMask(pp);
if (mask.isEmpty()) {
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
@ -52,6 +66,7 @@ public class WESubscriber {
}
return;
}
}
if (Settings.CHUNK_PROCESSOR) {
if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
try {

View File

@ -13,14 +13,40 @@ import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlotQueue;
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;
import com.intellectualcrafters.plot.util.WorldUtil;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
import com.plotsquared.sponge.generator.SpongePlotGenerator;
import com.plotsquared.sponge.listener.ChunkProcessor;
import com.plotsquared.sponge.listener.MainListener;
import com.plotsquared.sponge.listener.WorldEvents;
import com.plotsquared.sponge.util.*;
import com.plotsquared.sponge.util.KillRoadMobs;
import com.plotsquared.sponge.util.SpongeChatManager;
import com.plotsquared.sponge.util.SpongeChunkManager;
import com.plotsquared.sponge.util.SpongeCommand;
import com.plotsquared.sponge.util.SpongeEconHandler;
import com.plotsquared.sponge.util.SpongeEventUtil;
import com.plotsquared.sponge.util.SpongeHybridUtils;
import com.plotsquared.sponge.util.SpongeInventoryUtil;
import com.plotsquared.sponge.util.SpongeMetrics;
import com.plotsquared.sponge.util.SpongeSchematicHandler;
import com.plotsquared.sponge.util.SpongeSetupUtils;
import com.plotsquared.sponge.util.SpongeTaskManager;
import com.plotsquared.sponge.util.SpongeTitleManager;
import com.plotsquared.sponge.util.SpongeUtil;
import com.plotsquared.sponge.util.block.FastQueue;
import com.plotsquared.sponge.util.block.SlowQueue;
import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper;
@ -141,7 +167,6 @@ public class SpongeMain implements IPlotMain {
public int[] getPluginVersion() {
PluginContainer plugin = game.getPluginManager().fromInstance(this).get();
String version = plugin.getVersion().get();
log("Checking plugin version: PlotSquared: ");
final String[] split = version.split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
}
@ -203,7 +228,7 @@ public class SpongeMain implements IPlotMain {
@Override
public void registerCommands() {
getGame().getCommandManager().register(THIS, new SpongeCommand(), new String[] { "plots", "p", "plot", "ps", "plotsquared", "p2", "2" });
getGame().getCommandManager().register(THIS, new SpongeCommand(), "plots", "p", "plot", "ps", "plotsquared", "p2", "2");
}
@Override

View File

@ -19,6 +19,7 @@ import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer;
import net.minecraft.block.Block;
import net.minecraft.world.biome.BiomeGenBase;
import org.apache.commons.lang3.NotImplementedException;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockType;
@ -356,6 +357,19 @@ public class SpongeUtil extends WorldUtil {
return result;
}
@Override
public void setSpawn(Location loc) {
World world = getWorld(loc.getWorld());
if (world != null) {
world.getProperties().setSpawnPosition(new Vector3i(loc.getX(), loc.getY(), loc.getZ()));
}
}
@Override
public void saveWorld(String worldname) {
throw new NotImplementedException("TODO WIP"); // TODO FIXME
}
@Override
public String[] getSign(final Location loc) {
final World world = SpongeUtil.getWorld(loc.getWorld());

View File

@ -1,12 +1,11 @@
package com.plotsquared.sponge.util.block;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.extent.MutableBiomeArea;
import org.spongepowered.api.world.extent.MutableBlockVolume;
import com.intellectualcrafters.plot.util.PlotChunk;
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
import com.plotsquared.sponge.util.SpongeUtil;
import org.spongepowered.api.world.Chunk;
import org.spongepowered.api.world.extent.MutableBiomeArea;
import org.spongepowered.api.world.extent.MutableBlockVolume;
public class GenChunk extends PlotChunk<Chunk> {
@ -42,6 +41,11 @@ public class GenChunk extends PlotChunk<Chunk> {
terain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
}
@Override
public void setChunkWrapper(ChunkWrapper loc) {
super.setChunkWrapper(loc);
}
@Override
public PlotChunk clone() {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");

View File

@ -77,7 +77,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.9-SNAPSHOT</version>
<version>1.9-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>