Beginning rewrite of Flags and various cleanups

This commit is contained in:
Matt 2016-03-16 10:15:38 -04:00
parent 3fb64d9811
commit 65ddb12701
13 changed files with 135 additions and 111 deletions

View File

@ -163,9 +163,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
}
@Override
public int[] getPluginVersion() {
final String[] split = getDescription().getVersion().split("\\.");
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) };
public String getPluginVersion() {
return getDescription().getVersion();
}
@Override

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

@ -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 {
/**
@ -57,7 +57,7 @@ public interface IPlotMain {
* Get the version of the PlotSquared being used
* @return
*/
int[] getPluginVersion();
String getPluginVersion();
/**
* Get the version of Minecraft that is running

View File

@ -126,7 +126,7 @@ public class PS {
// private:
private File storageFile;
private File FILE = null; // This file
private int[] VERSION = null;
private String VERSION = null;
private String PLATFORM = null;
private String LAST_VERSION;
private Database database;
@ -278,8 +278,8 @@ 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) && !VERSION.equals(LAST_VERSION)) {
log("&aThanks for updating from: " + LAST_VERSION + " to " + VERSION);
}
}
});
@ -383,7 +383,7 @@ public class PS {
* Get the current PlotSquared version
* @return current version in config or null
*/
public int[] getVersion() {
public String getVersion() {
return VERSION;
}
@ -2037,7 +2037,7 @@ public class PS {
*/
public void setupConfig() {
LAST_VERSION = config.getString("version");
config.set("version", StringMan.join(VERSION, "."));
config.set("version", VERSION);
config.set("platform", PLATFORM);
final Map<String, Object> options = new HashMap<>();
@ -2362,7 +2362,7 @@ public class PS {
* Setup the storage file (load + save missing nodes)
*/
private void setupStorage() {
storage.set("version", StringMan.join(VERSION, "."));
storage.set("version", VERSION);
final Map<String, Object> options = new HashMap<>(9);
options.put("mysql.use", false);
options.put("sqlite.use", true);
@ -2414,7 +2414,7 @@ public class PS {
* Setup the style.yml file
*/
private void setupStyle() {
style.set("version", StringMan.join(VERSION, "."));
style.set("version", VERSION);
final Map<String, Object> o = new HashMap<>();
o.put("color.1", "6");
o.put("color.2", "7");

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

@ -2836,11 +2836,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 +2852,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 +2998,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 +3005,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 +3018,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 +3031,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 +3063,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

@ -2308,9 +2308,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)) {

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

@ -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 {
@ -233,8 +234,7 @@ public class ExpireManager {
}
if ((last = opp.getLastPlayed()) != 0) {
dates_cache.put(uuid, last);
}
else {
} else {
return false;
}
}
@ -242,7 +242,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

@ -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;
@ -138,12 +164,11 @@ public class SpongeMain implements IPlotMain {
}
@Override
public int[] getPluginVersion() {
public String 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 };
return version;
}
@Override
@ -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