Fixes #868
Fixes #778
Fixes attributes passing wrong key to persistent meta
Fixes blob compatibility with JDBC driver for persistent meta
Fix stackoverflow from countEntities under certain circumstances
Minor cleanup
This commit is contained in:
Jesse Boyd 2016-02-26 01:17:07 +11:00
parent efae2c2e63
commit 7659884e73
8 changed files with 78 additions and 177 deletions

View File

@ -1,16 +1,5 @@
package com.plotsquared.bukkit.object; package com.plotsquared.bukkit.object;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.WeatherType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
@ -19,6 +8,16 @@ import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.WeatherType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import java.util.UUID;
public class BukkitPlayer extends PlotPlayer { public class BukkitPlayer extends PlotPlayer {
@ -133,24 +132,6 @@ public class BukkitPlayer extends PlotPlayer {
return BukkitUtil.getLocationFull(player); return BukkitUtil.getLocationFull(player);
} }
@Override
public void setAttribute(String key) {
setPersistentMeta("attrib_" + key, new byte[]{(byte) 1});
}
@Override
public boolean getAttribute(String key) {
if (!hasPersistentMeta(key)) {
return false;
}
return getPersistentMeta("attrib_" + key)[0] == 1;
}
@Override
public void removeAttribute(String key) {
removePersistentMeta("attrib_" + key);
}
@Override @Override
public void loadData() { public void loadData() {
if (!player.isOnline()) { if (!player.isOnline()) {

View File

@ -1075,9 +1075,11 @@ public class BukkitChunkManager extends ChunkManager {
final Set<Chunk> chunks = new HashSet<>(); final Set<Chunk> chunks = new HashSet<>();
for (int X = bx; X <= tx; X++) { for (int X = bx; X <= tx; X++) {
for (int Z = bz; Z <= tz; Z++) { for (int Z = bz; Z <= tz; Z++) {
if (world.isChunkLoaded(X, Z)) {
chunks.add(world.getChunkAt(X, Z)); chunks.add(world.getChunkAt(X, Z));
} }
} }
}
boolean doWhole = false; boolean doWhole = false;
List<Entity> entities = null; List<Entity> entities = null;

View File

@ -129,8 +129,10 @@ public class SendChunk {
final World myworld = Bukkit.getWorld(worldname); final World myworld = Bukkit.getWorld(worldname);
final ArrayList<Chunk> chunks = new ArrayList<>(); final ArrayList<Chunk> chunks = new ArrayList<>();
for (final ChunkLoc loc : locs) { for (final ChunkLoc loc : locs) {
if (myworld.isChunkLoaded(loc.x, loc.z)) {
chunks.add(myworld.getChunkAt(loc.x, loc.z)); chunks.add(myworld.getChunkAt(loc.x, loc.z));
} }
}
sendChunk(chunks); sendChunk(chunks);
} }
} }

View File

@ -1,38 +1,5 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import com.intellectualcrafters.configuration.ConfigurationSection; import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.MemorySection; import com.intellectualcrafters.configuration.MemorySection;
import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.configuration.file.YamlConfiguration;
@ -41,11 +8,7 @@ import com.intellectualcrafters.plot.commands.WE_Anywhere;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Configuration;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.*;
import com.intellectualcrafters.plot.database.Database;
import com.intellectualcrafters.plot.database.MySQL;
import com.intellectualcrafters.plot.database.SQLManager;
import com.intellectualcrafters.plot.database.SQLite;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue; import com.intellectualcrafters.plot.flag.FlagValue;
@ -53,41 +16,26 @@ import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridPlotWorld; import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotFilter;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.CommentManager;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.ReflectionUtils;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetQueue;
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.WorldUtil;
import com.intellectualcrafters.plot.util.area.QuadMap; import com.intellectualcrafters.plot.util.area.QuadMap;
import com.plotsquared.listener.WESubscriber; import com.plotsquared.listener.WESubscriber;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/** /**
* An implementation of the core, * An implementation of the core,
* with a static getter for easy access * with a static getter for easy access
@ -1874,7 +1822,14 @@ public class PS {
TASK = null; TASK = null;
database = null; database = null;
// Validate that all data in the db is correct // Validate that all data in the db is correct
DBFunc.validatePlots(getPlots()); final HashSet<Plot> plots = new HashSet<>();
foreachPlotRaw(new RunnableVal<Plot>() {
@Override
public void run(Plot value) {
plots.add(value);
}
});
DBFunc.validatePlots(plots);
// Close the connection // Close the connection
DBFunc.close(); DBFunc.close();

View File

@ -113,7 +113,7 @@ public class Purge extends SubCommand {
} }
} }
} }
final HashSet<Integer> toDelete = new HashSet<>(); final HashSet<Plot> toDelete = new HashSet<>();
for (Plot plot : PS.get().getBasePlots()) { for (Plot plot : PS.get().getBasePlots()) {
if (world != null && !plot.getArea().worldname.equalsIgnoreCase(world)) { if (world != null && !plot.getArea().worldname.equalsIgnoreCase(world)) {
continue; continue;
@ -134,10 +134,7 @@ public class Purge extends SubCommand {
continue; continue;
} }
for (Plot current : plot.getConnectedPlots()) { for (Plot current : plot.getConnectedPlots()) {
final int DBid = DBFunc.getId(current); toDelete.add(current);
if (DBid != Integer.MAX_VALUE) {
toDelete.add(DBid);
}
} }
} }
if (PS.get().plots_tmp != null) { if (PS.get().plots_tmp != null) {
@ -160,10 +157,7 @@ public class Purge extends SubCommand {
if (unknown && UUIDHandler.getName(plot.owner) != null) { if (unknown && UUIDHandler.getName(plot.owner) != null) {
continue; continue;
} }
final int DBid = DBFunc.getId(plot); toDelete.add(plot);
if (DBid != Integer.MAX_VALUE) {
toDelete.add(DBid);
}
} }
} }
} }
@ -175,8 +169,16 @@ public class Purge extends SubCommand {
CmdConfirm.addPending(plr, cmd, new Runnable() { CmdConfirm.addPending(plr, cmd, new Runnable() {
@Override @Override
public void run() { public void run() {
DBFunc.purgeIds(toDelete); HashSet<Integer> ids = new HashSet<Integer>();
C.PURGE_SUCCESS.send(plr, toDelete.size() + ""); for (Plot plot : toDelete) {
if (plot.temp != Integer.MAX_VALUE) {
ids.add(plot.temp);
PlotArea area = plot.getArea();
plot.getArea().removePlot(plot.getId());
}
}
DBFunc.purgeIds(ids);
C.PURGE_SUCCESS.send(plr, ids.size() + "/" + (toDelete.size()));
} }
}); });
return true; return true;

View File

@ -25,38 +25,15 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import java.sql.Blob; import java.sql.*;
import java.sql.Connection; import java.util.*;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -2423,16 +2400,14 @@ public class SQLManager implements AbstractDB {
addPlayerTask(uuid, new UniqueStatement("addPersistentMeta") { addPlayerTask(uuid, new UniqueStatement("addPersistentMeta") {
@Override @Override
public void set(final PreparedStatement stmt) throws SQLException { public void set(final PreparedStatement stmt) throws SQLException {
Blob blob = connection.createBlob();
blob.setBytes(1, meta);
if (replace) { if (replace) {
stmt.setBlob(1, blob); stmt.setBytes(1, meta);
stmt.setString(2, uuid.toString()); stmt.setString(2, uuid.toString());
stmt.setString(3, key); stmt.setString(3, key);
} else { } else {
stmt.setString(1, uuid.toString()); stmt.setString(1, uuid.toString());
stmt.setString(2, key); stmt.setString(2, key);
stmt.setBlob(3, blob); stmt.setBytes(3, meta);
} }
} }
@ -2487,8 +2462,7 @@ public class SQLManager implements AbstractDB {
while (resultSet.next()) { while (resultSet.next()) {
String key = resultSet.getString("key"); String key = resultSet.getString("key");
Blob rawValue = resultSet.getBlob("value"); byte[] bytes = resultSet.getBytes("value");
byte[] bytes = rawValue.getBytes(1, (int) rawValue.length());
metaMap.put(key, bytes); metaMap.put(key, bytes);
} }
@ -3019,9 +2993,12 @@ public class SQLManager implements AbstractDB {
} }
for (final Entry<String, HashMap<PlotId, Plot>> entry : database.entrySet()) { for (final Entry<String, HashMap<PlotId, Plot>> entry : database.entrySet()) {
String worldname = entry.getKey();
final HashMap<PlotId, Plot> map = entry.getValue(); final HashMap<PlotId, Plot> map = entry.getValue();
if (!map.isEmpty()) { if (!map.isEmpty()) {
for (final Entry<PlotId, Plot> entry2 : map.entrySet()) { for (final Entry<PlotId, Plot> entry2 : map.entrySet()) {
Plot plot = entry2.getValue();
System.out.println("Plot: " + plot + " | " + worldname);
PS.debug("$1Plot was deleted: " + entry2.getValue() + "// TODO implement this when sure safe"); PS.debug("$1Plot was deleted: " + entry2.getValue() + "// TODO implement this when sure safe");
} }
} }

View File

@ -304,19 +304,29 @@ public abstract class PlotPlayer implements CommandCaller {
* - For session only data use meta * - For session only data use meta
* @param key * @param key
*/ */
public abstract void setAttribute(final String key); public void setAttribute(final String key) {
setPersistentMeta("attrib_" + key, new byte[]{(byte) 1});
}
/** /**
* The attribute will be either true or false * The attribute will be either true or false
* @param key * @param key
*/ */
public abstract boolean getAttribute(final String key); public boolean getAttribute(final String key) {
if (!hasPersistentMeta("attrib_" + key)) {
return false;
}
return getPersistentMeta("attrib_" + key)[0] == 1;
}
/** /**
* Remove an attribute from a player * Remove an attribute from a player
* @param key * @param key
*/ */
public abstract void removeAttribute(final String key); public void removeAttribute(final String key) {
removePersistentMeta("attrib_" + key);
}
/** /**
* Set the player's local weather * Set the player's local weather

View File

@ -5,7 +5,6 @@ import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.PlotGamemode; import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
@ -147,33 +146,6 @@ public class SpongePlayer extends PlotPlayer {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET"); throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
} }
@Override
public void setAttribute(String key) {
key = "plotsquared_user_attributes." + key;
if ((EconHandler.manager == null) || player.hasPermission("plotsquared_user_attributes.*")) {
setMeta(key, true);
return;
}
EconHandler.manager.setPermission(getName(), key, true);
}
@Override
public boolean getAttribute(String key) {
key = "plotsquared_user_attributes." + key;
if ((EconHandler.manager == null) || player.hasPermission("plotsquared_user_attributes.*")) {
final Object v = getMeta(key);
return v == null ? false : (Boolean) v;
}
return player.hasPermission(key);
}
@Override
public void removeAttribute(String key) {
key = "plotsquared_user_attributes." + key;
EconHandler.manager.setPermission(getName(), key, false);
deleteMeta(key);
}
@Override @Override
public void setWeather(final PlotWeather weather) { public void setWeather(final PlotWeather weather) {
// TODO Auto-generated method stub // TODO Auto-generated method stub