plot settings

This commit is contained in:
boy0001 2015-01-12 03:25:33 +11:00
parent 040045eed5
commit d4393caaf4
6 changed files with 155 additions and 178 deletions

View File

@ -209,10 +209,6 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
*/ */
private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots; private static LinkedHashMap<String, HashMap<PlotId, Plot>> plots;
/**
* If plotme converter is enabled
*/
private static boolean CONVERT_PLOTME = enablePlotMe();
/** /**
* Return an instance of MySQL * Return an instance of MySQL
*/ */
@ -899,7 +895,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
public static void worldLoad(WorldLoadEvent event) { public static void worldLoad(WorldLoadEvent event) {
if (!UUIDHandler.CACHED) { if (!UUIDHandler.CACHED) {
UUIDHandler.cacheAll(); UUIDHandler.cacheAll();
if (CONVERT_PLOTME) { if (Settings.CONVERT_PLOTME && Bukkit.getPluginManager().getPlugin("PlotMe") != null) {
try { try {
new PlotMeConverter(PlotMain.getMain()).runAsync(); new PlotMeConverter(PlotMain.getMain()).runAsync();
} catch (final Exception e) { } catch (final Exception e) {
@ -1323,49 +1319,11 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
Logger.add(LogLevel.GENERAL, "Logger enabled"); Logger.add(LogLevel.GENERAL, "Logger enabled");
} }
public static boolean enablePlotMe() {
if (!Settings.CONVERT_PLOTME) {
return false;
}
File file = new File(new File("").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe-Core.jar");
if (file.exists()) {
sendConsoleSenderMessage("&b==== Copying 'PlotMe-Core.jar' to 'PlotMe_JAR_relocated' for conversion purposes ===");
sendConsoleSenderMessage("&c - If you do not wish to convert, please stop the server now and set 'plotme-convert.enabled' to false");
sendConsoleSenderMessage("&3 - Please ignore the below stacktrace...");
try {
File to = new File(new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe_JAR_relocated" + File.separator + "PlotMe-Core.jar");
File parent = to.getParentFile();
if(!parent.exists()){
parent.mkdirs();
}
to.createNewFile();
Files.copy(file, to);
file.delete();
} catch (IOException e) {
e.printStackTrace();
}
try {
Thread.sleep(5000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
return true;
}
file = new File(new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe.jar");
if (file.exists()) {
return true;
}
return false;
}
/** /**
* On Load. * On Load.
*/ */
@Override @Override
final public void onEnable() { final public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("PlotMe") != null) {
CONVERT_PLOTME = true;
}
PlotMain.main = this; PlotMain.main = this;
// Setup the logger mechanics // Setup the logger mechanics
setupLogger(); setupLogger();

View File

@ -30,7 +30,7 @@ import org.bukkit.entity.Player;
public class WE_Anywhere extends SubCommand { public class WE_Anywhere extends SubCommand {
public WE_Anywhere() { public WE_Anywhere() {
super("weanywhere", "plots.worldedit.bypass", "Force bypass of WorldEdit", "weanywhere", "wea", CommandCategory.DEBUG, true); super("weanywhere", "plots.admin", "Force bypass of WorldEdit", "weanywhere", "wea", CommandCategory.DEBUG, true);
} }
@Override @Override
@ -39,9 +39,15 @@ public class WE_Anywhere extends SubCommand {
PlayerFunctions.sendMessage(plr, "&cWorldEdit is not enabled on this server"); PlayerFunctions.sendMessage(plr, "&cWorldEdit is not enabled on this server");
return false; return false;
} }
if (PWE.hasMask(plr)) {
PWE.removeMask(plr); PWE.removeMask(plr);
PlayerFunctions.sendMessage(plr, "&6Removed your WorldEdit mask"); PlayerFunctions.sendMessage(plr, "&6Cleared your WorldEdit mask");
}
else {
PWE.setMask(plr, plr.getLocation());
PlayerFunctions.sendMessage(plr, "&6Updated your WorldEdit mask");
}
return true; return true;
} }
} }

View File

@ -21,26 +21,29 @@
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import com.intellectualcrafters.plot.PlotMain; import java.io.File;
import com.intellectualcrafters.plot.generator.HybridGen; import java.io.IOException;
import com.intellectualcrafters.plot.object.Plot; import java.sql.Connection;
import com.intellectualcrafters.plot.object.PlotId; import java.sql.DriverManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import java.sql.ResultSet;
import com.sk89q.worldedit.util.YAMLConfiguration; import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import java.io.File; import com.intellectualcrafters.plot.PlotMain;
import java.io.IOException; import com.intellectualcrafters.plot.generator.HybridGen;
import java.sql.Connection; import com.intellectualcrafters.plot.object.Plot;
import java.sql.ResultSet; import com.intellectualcrafters.plot.object.PlotId;
import java.sql.Statement; import com.intellectualcrafters.plot.util.UUIDHandler;
import java.util.*;
/** /**
* Created 2014-08-17 for PlotSquared * Created 2014-08-17 for PlotSquared
@ -54,6 +57,7 @@ public class PlotMeConverter {
* PlotMain Object * PlotMain Object
*/ */
private final PlotMain plugin; private final PlotMain plugin;
/** /**
* Constructor * Constructor
* *
@ -69,48 +73,43 @@ public class PlotMeConverter {
public void runAsync() throws Exception { public void runAsync() throws Exception {
// We have to make it wait a couple of seconds // We have to make it wait a couple of seconds
Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable() { Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
sendMessage("Conversion has started"); sendMessage("Conversion has started");
sendMessage("Connecting to PlotMe DB"); sendMessage("Connecting to PlotMe DB");
final ArrayList<Plot> createdPlots = new ArrayList<>(); final ArrayList<Plot> createdPlots = new ArrayList<>();
String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator; final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
File plotMeFile = new File(dataFolder + "config.yml"); final File plotMeFile = new File(dataFolder + "config.yml");
final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile); final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile);
int count = 0; int count = 0;
Connection connection; Connection connection;
if (plotConfig.getBoolean("usemySQL")) { if (plotConfig.getBoolean("usemySQL")) {
String user = plotConfig.getString("mySQLuname"); final String user = plotConfig.getString("mySQLuname");
String password = plotConfig.getString("mySQLpass"); final String password = plotConfig.getString("mySQLpass");
String con = plotConfig.getString("mySQLconn").replaceAll("jdbc:mysql://", ""); final String con = plotConfig.getString("mySQLconn");
String host = con.split(":")[0]; connection = DriverManager.getConnection(con, user, password);
String port = con.split(":")[1].split("/")[0]; } else {
String database = con.split(":")[1].split("/")[1];
MySQL mySQL = new MySQL(PlotMain.getMain(), host, port, database, user, password);
connection = mySQL.openConnection();
}
else {
connection = new SQLite(PlotMain.getMain(), dataFolder + File.separator + "plots.db").openConnection(); connection = new SQLite(PlotMain.getMain(), dataFolder + File.separator + "plots.db").openConnection();
} }
sendMessage("Collecting plot data"); sendMessage("Collecting plot data");
ResultSet r; ResultSet r;
Statement stmt; Statement stmt;
HashMap<String, Integer> plotSize = new HashMap<>(); final HashMap<String, Integer> plotSize = new HashMap<>();
HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>(); final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
Set<String> worlds = plotConfig.getConfigurationSection("worlds").getKeys(false); final Set<String> worlds = plotConfig.getConfigurationSection("worlds").getKeys(false);
stmt = connection.createStatement(); stmt = connection.createStatement();
r = stmt.executeQuery("SELECT * FROM `plotmePlots`"); r = stmt.executeQuery("SELECT * FROM `plotmePlots`");
while (r.next()) { while (r.next()) {
count++; count++;
PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
String name = r.getString("owner"); final String name = r.getString("owner");
String world = r.getString("world"); final String world = r.getString("world");
if (!plotSize.containsKey(world)) { if (!plotSize.containsKey(world)) {
int size = r.getInt("topZ") - r.getInt("bottomZ"); final int size = r.getInt("topZ") - r.getInt("bottomZ");
plotSize.put(world, size); plotSize.put(world, size);
plots.put(world, new HashMap<PlotId, Plot>()); plots.put(world, new HashMap<PlotId, Plot>());
} }
@ -119,27 +118,25 @@ public class PlotMeConverter {
if (owner == null) { if (owner == null) {
if (name.equals("*")) { if (name.equals("*")) {
owner = DBFunc.everyone; owner = DBFunc.everyone;
} } else {
else {
sendMessage("&cCould not identify owner for plot: " + id); sendMessage("&cCould not identify owner for plot: " + id);
continue; continue;
} }
} }
Plot plot = new Plot(id, owner, new ArrayList<UUID>() , new ArrayList<UUID>(), world); final Plot plot = new Plot(id, owner, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
plots.get(world).put(id, plot); plots.get(world).put(id, plot);
} }
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`"); r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
while (r.next()) { while (r.next()) {
PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
String name = r.getString("player"); final String name = r.getString("player");
String world = r.getString("world"); final String world = r.getString("world");
UUID helper = UUIDHandler.getUUID(name); UUID helper = UUIDHandler.getUUID(name);
if (helper == null) { if (helper == null) {
if (name.equals("*")) { if (name.equals("*")) {
helper = DBFunc.everyone; helper = DBFunc.everyone;
} } else {
else {
sendMessage("&6Could not identify helper for plot: " + id); sendMessage("&6Could not identify helper for plot: " + id);
continue; continue;
} }
@ -151,15 +148,14 @@ public class PlotMeConverter {
r = stmt.executeQuery("SELECT * FROM `plotmeDenied`"); r = stmt.executeQuery("SELECT * FROM `plotmeDenied`");
while (r.next()) { while (r.next()) {
PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ")); final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
String name = r.getString("player"); final String name = r.getString("player");
String world = r.getString("world"); final String world = r.getString("world");
UUID denied = UUIDHandler.getUUID(name); UUID denied = UUIDHandler.getUUID(name);
if (denied == null) { if (denied == null) {
if (name.equals("*")) { if (name.equals("*")) {
denied = DBFunc.everyone; denied = DBFunc.everyone;
} } else {
else {
sendMessage("&6Could not identify denied for plot: " + id); sendMessage("&6Could not identify denied for plot: " + id);
continue; continue;
} }
@ -171,7 +167,7 @@ public class PlotMeConverter {
sendMessage("Collected " + count + " plots from PlotMe"); sendMessage("Collected " + count + " plots from PlotMe");
for (String world : plots.keySet()) { for (final String world : plots.keySet()) {
sendMessage("Copying config for: " + world); sendMessage("Copying config for: " + world);
try { try {
final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); // final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
@ -199,11 +195,11 @@ public class PlotMeConverter {
} }
} }
File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml"); final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
if (PLOTME_DG_FILE.exists()) { if (PLOTME_DG_FILE.exists()) {
YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE); final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
try { try {
for (String world : plots.keySet()) { for (final String world : plots.keySet()) {
final Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + world + ".PathWidth"); // final Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + world + ".PathWidth"); //
PlotMain.config.set("worlds." + world + ".road.width", pathwidth); PlotMain.config.set("worlds." + world + ".road.width", pathwidth);
@ -225,18 +221,16 @@ public class PlotMeConverter {
final Integer height = PLOTME_DG_YML.getInt("worlds." + world + ".RoadHeight"); // final Integer height = PLOTME_DG_YML.getInt("worlds." + world + ".RoadHeight"); //
PlotMain.config.set("worlds." + world + ".road.height", height); PlotMain.config.set("worlds." + world + ".road.height", height);
} }
} } catch (final Exception e) {
catch (Exception e) {
} }
} }
for (String world : plots.keySet()) { for (final String world : plots.keySet()) {
int duplicate = 0; int duplicate = 0;
for (Plot plot : plots.get(world).values()) { for (final Plot plot : plots.get(world).values()) {
if (!PlotMain.getPlots(world).containsKey(plot.id)) { if (!PlotMain.getPlots(world).containsKey(plot.id)) {
createdPlots.add(plot); createdPlots.add(plot);
} } else {
else {
duplicate++; duplicate++;
} }
} }
@ -245,7 +239,6 @@ public class PlotMeConverter {
} }
} }
sendMessage("Creating plot DB"); sendMessage("Creating plot DB");
DBFunc.createPlots(createdPlots); DBFunc.createPlots(createdPlots);
sendMessage("Creating settings/helpers DB"); sendMessage("Creating settings/helpers DB");
@ -257,6 +250,10 @@ public class PlotMeConverter {
sendMessage(" - &cFailed to save configuration."); sendMessage(" - &cFailed to save configuration.");
} }
Bukkit.getScheduler().scheduleSyncDelayedTask(PlotMain.getMain(), new Runnable() {
@Override
public void run() {
try {
boolean MV = false; boolean MV = false;
boolean MW = false; boolean MW = false;
@ -302,12 +299,15 @@ public class PlotMeConverter {
PlotMain.setAllPlotsRaw(DBFunc.getPlots()); PlotMain.setAllPlotsRaw(DBFunc.getPlots());
sendMessage("Conversion has finished"); sendMessage("Conversion has finished");
PlotMain.sendConsoleSenderMessage("&cAlthough the server may be functional in it's current state, it is recommended that you restart the server and remove PlotMe to finalize the installation. Please make careful note of any warning messages that may have showed up during conversion."); PlotMain.sendConsoleSenderMessage("&cAlthough the server may be functional in it's current state, it is recommended that you restart the server and remove PlotMe to finalize the installation. Please make careful note of any warning messages that may have showed up during conversion.");
} catch (final Exception e) {
}
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
});
} catch (final Exception e) {
}
}
}, 20); }, 20);
} }
} }

View File

@ -253,10 +253,8 @@ import java.util.Set;
if (!isPlotWorld(q)) { if (!isPlotWorld(q)) {
if (isPlotWorld(f)) { if (isPlotWorld(f)) {
PWE.removeMask(p); PWE.removeMask(p);
return;
} else {
return;
} }
return;
} }
PWE.setMask(p, q); PWE.setMask(p, q);
} }

View File

@ -156,6 +156,9 @@ import java.util.Set;
public ArrayList<PlotComment> getComments(final int tier) { public ArrayList<PlotComment> getComments(final int tier) {
final ArrayList<PlotComment> c = new ArrayList<>(); final ArrayList<PlotComment> c = new ArrayList<>();
if (this.comments == null) {
return c;
}
for (final PlotComment comment : this.comments) { for (final PlotComment comment : this.comments) {
if (comment.tier == tier) { if (comment.tier == tier) {
c.add(comment); c.add(comment);

View File

@ -52,7 +52,9 @@ import org.bukkit.entity.Player;
} else { } else {
s = PlotMain.worldEdit.getSession(p); s = PlotMain.worldEdit.getSession(p);
} }
if (!PlotMain.isPlotWorld(p.getWorld())) {
removeMask(p);
}
final PlotId id = PlayerFunctions.getPlot(l); final PlotId id = PlayerFunctions.getPlot(l);
if (id != null) { if (id != null) {
final Plot plot = PlotMain.getPlots(l.getWorld()).get(id); final Plot plot = PlotMain.getPlots(l.getWorld()).get(id);
@ -95,6 +97,16 @@ import org.bukkit.entity.Player;
} }
} }
public static boolean hasMask(final Player p) {
LocalSession s;
if (PlotMain.worldEdit == null) {
s = WorldEdit.getInstance().getSession(p.getName());
} else {
s = PlotMain.worldEdit.getSession(p);
}
return !noMask(s);
}
public static boolean noMask(final LocalSession s) { public static boolean noMask(final LocalSession s) {
return s.getMask() == null; return s.getMask() == null;
} }