Optimizations and a purge fix

This commit is contained in:
MattBDev
2016-04-02 01:30:26 -04:00
parent 8243e0118a
commit 4ebd778c62
33 changed files with 765 additions and 835 deletions

View File

@ -15,7 +15,7 @@ import java.util.HashMap;
abstract class APlotMeConnector {
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder);
public abstract Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder);
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException;

View File

@ -30,16 +30,15 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
private String prefix;
@Override
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
this.plugin = plugin.toLowerCase();
this.prefix = plotConfig.getString("mySQLprefix", plugin.toLowerCase());
public Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder) {
this.plugin = this.plugin.toLowerCase();
this.prefix = plotConfig.getString("mySQLprefix", this.plugin.toLowerCase());
try {
if (plotConfig.getBoolean("usemySQL")) {
String user = plotConfig.getString("mySQLuname");
String password = plotConfig.getString("mySQLpass");
String con = plotConfig.getString("mySQLconn");
return DriverManager.getConnection(con, user, password);
// return new MySQL(plotsquared, hostname, port, database, username, password)
} else {
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
}
@ -110,17 +109,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
owner = DBFunc.everyone;
} else {
if (checkUUID || checkUUID2) {
try {
byte[] bytes = resultSet.getBytes(column);
if (bytes != null) {
ByteBuffer bb = ByteBuffer.wrap(bytes);
long high = bb.getLong();
long low = bb.getLong();
owner = new UUID(high, low);
UUIDHandler.add(new StringWrapper(name), owner);
}
} catch (SQLException e) {
e.printStackTrace();
byte[] bytes = resultSet.getBytes(column);
if (bytes != null) {
ByteBuffer bb = ByteBuffer.wrap(bytes);
long high = bb.getLong();
long low = bb.getLong();
owner = new UUID(high, low);
UUIDHandler.add(new StringWrapper(name), owner);
}
}
if (name.isEmpty()) {
@ -173,17 +168,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
if ("*".equals(name)) {
denied = DBFunc.everyone;
} else if (DBFunc.hasColumn(resultSet, "playerid")) {
try {
byte[] bytes = resultSet.getBytes("playerid");
if (bytes != null) {
ByteBuffer bb = ByteBuffer.wrap(bytes);
long mostSigBits = bb.getLong();
long leastSigBits = bb.getLong();
denied = new UUID(mostSigBits, leastSigBits);
UUIDHandler.add(new StringWrapper(name), denied);
}
} catch (SQLException e) {
e.printStackTrace();
byte[] bytes = resultSet.getBytes("playerid");
if (bytes != null) {
ByteBuffer bb = ByteBuffer.wrap(bytes);
long mostSigBits = bb.getLong();
long leastSigBits = bb.getLong();
denied = new UUID(mostSigBits, leastSigBits);
UUIDHandler.add(new StringWrapper(name), denied);
}
}
if (denied == null) {
@ -212,17 +203,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
if ("*".equals(name)) {
helper = DBFunc.everyone;
} else if (DBFunc.hasColumn(resultSet, "playerid")) {
try {
byte[] bytes = resultSet.getBytes("playerid");
if (bytes != null) {
ByteBuffer bb = ByteBuffer.wrap(bytes);
long mostSigBits = bb.getLong();
long leastSigBits = bb.getLong();
helper = new UUID(mostSigBits, leastSigBits);
UUIDHandler.add(new StringWrapper(name), helper);
}
} catch (SQLException e) {
e.printStackTrace();
byte[] bytes = resultSet.getBytes("playerid");
if (bytes != null) {
ByteBuffer bb = ByteBuffer.wrap(bytes);
long mostSigBits = bb.getLong();
long leastSigBits = bb.getLong();
helper = new UUID(mostSigBits, leastSigBits);
UUIDHandler.add(new StringWrapper(name), helper);
}
}
if (helper == null) {

View File

@ -63,10 +63,10 @@ public class LikePlotMeConverter {
return plotConfig.getConfigurationSection("worlds").getKeys(false);
}
public void mergeWorldYml(String plugin, FileConfiguration plotConfig) {
public void mergeWorldYml(FileConfiguration plotConfig) {
try {
File genConfig =
new File("plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
new File("plugins" + File.separator + "PlotMe" + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
if (genConfig.exists()) {
YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
for (String key : yml.getKeys(true)) {
@ -83,7 +83,7 @@ public class LikePlotMeConverter {
}
}
public void updateWorldYml(String plugin, String location) {
public void updateWorldYml(String location) {
try {
Path path = Paths.get(location);
File file = new File(location);
@ -92,7 +92,7 @@ public class LikePlotMeConverter {
}
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
content = content.replaceAll(plugin, "PlotSquared");
content = content.replaceAll("PlotMe", "PlotSquared");
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
} catch (IOException ignored) {
//ignored
@ -117,7 +117,7 @@ public class LikePlotMeConverter {
PS.debug("&3Using connector: " + connector.getClass().getCanonicalName());
Connection connection = connector.getPlotMeConnection("PlotMe", plotConfig, dataFolder);
Connection connection = connector.getPlotMeConnection(plotConfig, dataFolder);
if (!connector.isValidConnection(connection)) {
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
@ -126,7 +126,7 @@ public class LikePlotMeConverter {
sendMessage("PlotMe conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
mergeWorldYml("PlotMe", plotConfig);
mergeWorldYml(plotConfig);
sendMessage("Connecting to PlotMe DB");
@ -140,8 +140,8 @@ public class LikePlotMeConverter {
if (Settings.CONVERT_PLOTME) {
sendMessage("Updating bukkit.yml");
updateWorldYml("PlotMe", "bukkit.yml");
updateWorldYml("PlotMe", "plugins/Multiverse-Core/worlds.yml");
updateWorldYml("bukkit.yml");
updateWorldYml("plugins/Multiverse-Core/worlds.yml");
for (String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
sendMessage("Copying config for: " + world);
try {

View File

@ -26,8 +26,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
private String plugin;
@Override
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
this.plugin = plugin.toLowerCase();
public Connection getPlotMeConnection(FileConfiguration plotConfig, String dataFolder) {
this.plugin = this.plugin.toLowerCase();
try {
if (plotConfig.getBoolean("usemySQL")) {
String user = plotConfig.getString("mySQLuname");
@ -109,14 +109,10 @@ public class PlotMeConnector_017 extends APlotMeConnector {
owner = DBFunc.everyone;
} else {
if (checkUUID) {
try {
byte[] bytes = resultSet.getBytes("ownerid");
if (bytes != null) {
owner = UUID.nameUUIDFromBytes(bytes);
UUIDHandler.add(new StringWrapper(name), owner);
}
} catch (Exception e) {
e.printStackTrace();
byte[] bytes = resultSet.getBytes("ownerid");
if (bytes != null) {
owner = UUID.nameUUIDFromBytes(bytes);
UUIDHandler.add(new StringWrapper(name), owner);
}
}
if (owner == null) {

View File

@ -34,14 +34,14 @@ import org.bukkit.util.Vector;
public class EntityWrapper {
public final EntityType type;
public final float yaw;
public final float pitch;
public final short depth;
private final int hash;
public EntityType type;
public float yaw;
public float pitch;
public double x;
public double y;
public double z;
public short depth;
public EntityBaseStats base = null;
// Extended
public ItemStack stack;

View File

@ -8,11 +8,6 @@ import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.object.schematic.ItemType;
import com.intellectualcrafters.plot.util.MathMan;
import com.plotsquared.bukkit.util.BukkitUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
@ -21,6 +16,12 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class StateWrapper {
public BlockState state = null;
@ -38,8 +39,8 @@ public class StateWrapper {
if (this.tag == null) {
return false;
}
switch (tag.getString("id").toLowerCase()) {
case "chest": {
switch (this.tag.getString("id").toLowerCase()) {
case "chest":
List<Tag> itemsTag = this.tag.getListTag("Items").getValue();
int length = itemsTag.size();
short[] ids = new short[length];
@ -75,9 +76,7 @@ public class StateWrapper {
}
state.update(true);
return true;
} else {
}
}
}
return false;
}

View File

@ -43,9 +43,8 @@ public class DefaultTitleManager {
* Create a new 1.8 title.
*
* @param title Title
* @throws ClassNotFoundException
*/
public DefaultTitleManager(String title) throws ClassNotFoundException {
public DefaultTitleManager(String title) {
this.title = title;
loadClasses();
}
@ -55,9 +54,8 @@ public class DefaultTitleManager {
*
* @param title Title text
* @param subtitle Subtitle text
* @throws ClassNotFoundException
*/
public DefaultTitleManager(String title, String subtitle) throws ClassNotFoundException {
public DefaultTitleManager(String title, String subtitle) {
this.title = title;
this.subtitle = subtitle;
loadClasses();
@ -67,9 +65,8 @@ public class DefaultTitleManager {
* Copy 1.8 title.
*
* @param title Title
* @throws ClassNotFoundException
*/
public DefaultTitleManager(DefaultTitleManager title) throws ClassNotFoundException {
public DefaultTitleManager(DefaultTitleManager title) {
// Copy title
this.title = title.title;
this.subtitle = title.subtitle;
@ -90,10 +87,8 @@ public class DefaultTitleManager {
* @param fadeInTime Fade in time
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
* @throws ClassNotFoundException
*/
public DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime)
throws ClassNotFoundException {
public DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
this.title = title;
this.subtitle = subtitle;
this.fadeInTime = fadeInTime;

View File

@ -42,11 +42,9 @@ public class DefaultTitleManager_183 {
/**
* Create a new 1.8 title
*
* @param title
* Title
* @throws ClassNotFoundException
* @param title Title
*/
public DefaultTitleManager_183(String title) throws ClassNotFoundException {
public DefaultTitleManager_183(String title) {
this.title = title;
loadClasses();
}
@ -56,9 +54,8 @@ public class DefaultTitleManager_183 {
*
* @param title Title text
* @param subtitle Subtitle text
* @throws ClassNotFoundException
*/
public DefaultTitleManager_183(String title, String subtitle) throws ClassNotFoundException {
public DefaultTitleManager_183(String title, String subtitle) {
this.title = title;
this.subtitle = subtitle;
loadClasses();
@ -68,9 +65,8 @@ public class DefaultTitleManager_183 {
* Copy 1.8 title.
*
* @param title Title
* @throws ClassNotFoundException
*/
public DefaultTitleManager_183(DefaultTitleManager_183 title) throws ClassNotFoundException {
public DefaultTitleManager_183(DefaultTitleManager_183 title) {
// Copy title
this.title = title.title;
this.subtitle = title.subtitle;
@ -91,9 +87,8 @@ public class DefaultTitleManager_183 {
* @param fadeInTime Fade in time
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
* @throws ClassNotFoundException
*/
public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) throws ClassNotFoundException {
public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
this.title = title;
this.subtitle = subtitle;
this.fadeInTime = fadeInTime;

View File

@ -42,9 +42,8 @@ public class HackTitleManager {
* Create a new 1.8 title.
*
* @param title Title
* @throws ClassNotFoundException NMS Error.
*/
public HackTitleManager(String title) throws ClassNotFoundException {
public HackTitleManager(String title) {
this.title = title;
loadClasses();
}
@ -54,9 +53,8 @@ public class HackTitleManager {
*
* @param title Title text
* @param subtitle Subtitle text
* @throws ClassNotFoundException NMS Error
*/
public HackTitleManager(String title, String subtitle) throws ClassNotFoundException {
public HackTitleManager(String title, String subtitle) {
this.title = title;
this.subtitle = subtitle;
loadClasses();
@ -66,9 +64,8 @@ public class HackTitleManager {
* Copy 1.8 title.
*
* @param title Title
* @throws ClassNotFoundException NMS Error
*/
public HackTitleManager(HackTitleManager title) throws ClassNotFoundException {
public HackTitleManager(HackTitleManager title) {
// Copy title
this.title = title.title;
this.subtitle = title.subtitle;
@ -89,9 +86,8 @@ public class HackTitleManager {
* @param fadeInTime Fade in time
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
* @throws ClassNotFoundException NMS error
*/
public HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) throws ClassNotFoundException {
public HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
this.title = title;
this.subtitle = subtitle;
this.fadeInTime = fadeInTime;

View File

@ -53,6 +53,6 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
for (Object o : objects) {
result.add(o.toString());
}
return result.size() == 0 ? null : result;
return result.isEmpty() ? null : result;
}
}

View File

@ -50,6 +50,7 @@ public class SendChunk {
RefClass classChunk = getRefClass("{nms}.Chunk");
this.methodInitLighting = classChunk.getMethod("initLighting");
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
//TODO in 1.7.10 this is PacketPlayOutMapChunk(Chunk chunk, boolean flag, int i, int version)
this.mapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
this.connection = classEntityPlayer.getField("playerConnection");