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;
/**
* If plotme converter is enabled
*/
private static boolean CONVERT_PLOTME = enablePlotMe();
/**
* Return an instance of MySQL
*/
@ -899,7 +895,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
public static void worldLoad(WorldLoadEvent event) {
if (!UUIDHandler.CACHED) {
UUIDHandler.cacheAll();
if (CONVERT_PLOTME) {
if (Settings.CONVERT_PLOTME && Bukkit.getPluginManager().getPlugin("PlotMe") != null) {
try {
new PlotMeConverter(PlotMain.getMain()).runAsync();
} catch (final Exception e) {
@ -1322,50 +1318,12 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
Logger.setup(log);
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.
*/
@Override
final public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("PlotMe") != null) {
CONVERT_PLOTME = true;
}
PlotMain.main = this;
// Setup the logger mechanics
setupLogger();

View File

@ -30,7 +30,7 @@ import org.bukkit.entity.Player;
public class WE_Anywhere extends SubCommand {
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
@ -39,9 +39,15 @@ public class WE_Anywhere extends SubCommand {
PlayerFunctions.sendMessage(plr, "&cWorldEdit is not enabled on this server");
return false;
}
PWE.removeMask(plr);
PlayerFunctions.sendMessage(plr, "&6Removed your WorldEdit mask");
if (PWE.hasMask(plr)) {
PWE.removeMask(plr);
PlayerFunctions.sendMessage(plr, "&6Cleared your WorldEdit mask");
}
else {
PWE.setMask(plr, plr.getLocation());
PlayerFunctions.sendMessage(plr, "&6Updated your WorldEdit mask");
}
return true;
}
}

View File

@ -21,26 +21,29 @@
package com.intellectualcrafters.plot.database;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.sk89q.worldedit.util.YAMLConfiguration;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
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.World;
import org.bukkit.WorldCreator;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.UUIDHandler;
/**
* Created 2014-08-17 for PlotSquared
@ -49,11 +52,12 @@ import java.util.*;
* @author Empire92
*/
public class PlotMeConverter {
/**
* PlotMain Object
*/
private final PlotMain plugin;
/**
* Constructor
*
@ -62,56 +66,51 @@ public class PlotMeConverter {
public PlotMeConverter(final PlotMain plugin) {
this.plugin = plugin;
}
private void sendMessage(final String message) {
PlotMain.sendConsoleSenderMessage("&3PlotMe&8->&3PlotSquared&8: &7" + message);
}
public void runAsync() throws Exception {
// 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
public void run() {
try {
sendMessage("Conversion has started");
sendMessage("Connecting to PlotMe DB");
final ArrayList<Plot> createdPlots = new ArrayList<>();
String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
File plotMeFile = new File(dataFolder + "config.yml");
final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
final File plotMeFile = new File(dataFolder + "config.yml");
final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile);
int count = 0;
Connection connection;
if (plotConfig.getBoolean("usemySQL")) {
String user = plotConfig.getString("mySQLuname");
String password = plotConfig.getString("mySQLpass");
String con = plotConfig.getString("mySQLconn").replaceAll("jdbc:mysql://", "");
String host = con.split(":")[0];
String port = con.split(":")[1].split("/")[0];
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();
final String user = plotConfig.getString("mySQLuname");
final String password = plotConfig.getString("mySQLpass");
final String con = plotConfig.getString("mySQLconn");
connection = DriverManager.getConnection(con, user, password);
} else {
connection = new SQLite(PlotMain.getMain(), dataFolder + File.separator + "plots.db").openConnection();
}
sendMessage("Collecting plot data");
ResultSet r;
Statement stmt;
HashMap<String, Integer> plotSize = new HashMap<>();
HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
Set<String> worlds = plotConfig.getConfigurationSection("worlds").getKeys(false);
final HashMap<String, Integer> plotSize = new HashMap<>();
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
final Set<String> worlds = plotConfig.getConfigurationSection("worlds").getKeys(false);
stmt = connection.createStatement();
r = stmt.executeQuery("SELECT * FROM `plotmePlots`");
while (r.next()) {
count++;
PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
String name = r.getString("owner");
String world = r.getString("world");
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
final String name = r.getString("owner");
final String world = r.getString("world");
if (!plotSize.containsKey(world)) {
int size = r.getInt("topZ") - r.getInt("bottomZ");
plotSize.put(world,size);
final int size = r.getInt("topZ") - r.getInt("bottomZ");
plotSize.put(world, size);
plots.put(world, new HashMap<PlotId, Plot>());
}
@ -119,28 +118,26 @@ public class PlotMeConverter {
if (owner == null) {
if (name.equals("*")) {
owner = DBFunc.everyone;
}
else {
sendMessage("&cCould not identify owner for plot: "+id);
} else {
sendMessage("&cCould not identify owner for plot: " + id);
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);
}
r = stmt.executeQuery("SELECT * FROM `plotmeAllowed`");
while (r.next()) {
PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
String name = r.getString("player");
String world = r.getString("world");
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
final String name = r.getString("player");
final String world = r.getString("world");
UUID helper = UUIDHandler.getUUID(name);
if (helper == null) {
if (name.equals("*")) {
helper = DBFunc.everyone;
}
else {
sendMessage("&6Could not identify helper for plot: "+id);
} else {
sendMessage("&6Could not identify helper for plot: " + id);
continue;
}
}
@ -151,16 +148,15 @@ public class PlotMeConverter {
r = stmt.executeQuery("SELECT * FROM `plotmeDenied`");
while (r.next()) {
PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
String name = r.getString("player");
String world = r.getString("world");
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
final String name = r.getString("player");
final String world = r.getString("world");
UUID denied = UUIDHandler.getUUID(name);
if (denied == null) {
if (name.equals("*")) {
denied = DBFunc.everyone;
}
else {
sendMessage("&6Could not identify denied for plot: "+id);
} else {
sendMessage("&6Could not identify denied for plot: " + id);
continue;
}
}
@ -171,27 +167,27 @@ public class PlotMeConverter {
sendMessage("Collected " + count + " plots from PlotMe");
for (String world : plots.keySet()) {
sendMessage("Copying config for: "+world);
for (final String world : plots.keySet()) {
sendMessage("Copying config for: " + world);
try {
final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
PlotMain.config.set("worlds." + world + ".road.width", pathwidth);
final Integer plotsize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
PlotMain.config.set("worlds." + world + ".plot.size", plotsize);
final String wallblock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
PlotMain.config.set("worlds." + world + ".wall.block", wallblock);
final String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
PlotMain.config.set("worlds." + world + ".plot.floor", Arrays.asList(floor));
final String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
PlotMain.config.set("worlds." + world + ".plot.filling", Arrays.asList(filling));
final String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
PlotMain.config.set("worlds." + world + ".road.block", road);
final Integer height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
PlotMain.config.set("worlds." + world + ".road.height", height);
} catch (final Exception e) {
@ -199,44 +195,42 @@ 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()) {
YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
try {
for (String world : plots.keySet()) {
for (final String world : plots.keySet()) {
final Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + world + ".PathWidth"); //
PlotMain.config.set("worlds." + world + ".road.width", pathwidth);
final Integer plotsize = PLOTME_DG_YML.getInt("worlds." + world + ".PlotSize"); //
PlotMain.config.set("worlds." + world + ".plot.size", plotsize);
final String wallblock = PLOTME_DG_YML.getString("worlds." + world + ".WallBlock"); //
PlotMain.config.set("worlds." + world + ".wall.block", wallblock);
final String floor = PLOTME_DG_YML.getString("worlds." + world + ".PlotFloorBlock"); //
PlotMain.config.set("worlds." + world + ".plot.floor", Arrays.asList(floor));
final String filling = PLOTME_DG_YML.getString("worlds." + world + ".FillBlock"); //
PlotMain.config.set("worlds." + world + ".plot.filling", Arrays.asList(filling));
final String road = PLOTME_DG_YML.getString("worlds." + world + ".RoadMainBlock");
PlotMain.config.set("worlds." + world + ".road.block", road);
final Integer height = PLOTME_DG_YML.getInt("worlds." + world + ".RoadHeight"); //
PlotMain.config.set("worlds." + world + ".road.height", height);
}
}
catch (Exception e) {
} catch (final Exception e) {
}
}
for (String world : plots.keySet()) {
for (final String world : plots.keySet()) {
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)) {
createdPlots.add(plot);
}
else {
} else {
duplicate++;
}
}
@ -245,7 +239,6 @@ public class PlotMeConverter {
}
}
sendMessage("Creating plot DB");
DBFunc.createPlots(createdPlots);
sendMessage("Creating settings/helpers DB");
@ -256,56 +249,63 @@ public class PlotMeConverter {
} catch (final IOException e) {
sendMessage(" - &cFailed to save configuration.");
}
boolean MV = false;
boolean MW = false;
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
MV = true;
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
MW = true;
}
for (final String worldname : worlds) {
final World world = Bukkit.getWorld(worldname);
sendMessage("Reloading generator for world: '" + worldname + "'...");
PlotMain.removePlotWorld(worldname);
if (MV) {
// unload
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + worldname);
try {
Thread.sleep(1000);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
// load
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + worldname + " normal -g PlotSquared");
} else if (MW) {
// unload
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + worldname);
try {
Thread.sleep(1000);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
// load
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + worldname + " plugin:PlotSquared");
} else {
Bukkit.getServer().unloadWorld(world, true);
final World myworld = WorldCreator.name(worldname).generator(new HybridGen(worldname)).createWorld();
myworld.save();
}
}
PlotMain.setAllPlotsRaw(DBFunc.getPlots());
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.");
}
catch (Exception e) {
e.printStackTrace();
Bukkit.getScheduler().scheduleSyncDelayedTask(PlotMain.getMain(), new Runnable() {
@Override
public void run() {
try {
boolean MV = false;
boolean MW = false;
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
MV = true;
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
MW = true;
}
for (final String worldname : worlds) {
final World world = Bukkit.getWorld(worldname);
sendMessage("Reloading generator for world: '" + worldname + "'...");
PlotMain.removePlotWorld(worldname);
if (MV) {
// unload
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + worldname);
try {
Thread.sleep(1000);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
// load
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + worldname + " normal -g PlotSquared");
} else if (MW) {
// unload
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + worldname);
try {
Thread.sleep(1000);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
// load
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + worldname + " plugin:PlotSquared");
} else {
Bukkit.getServer().unloadWorld(world, true);
final World myworld = WorldCreator.name(worldname).generator(new HybridGen(worldname)).createWorld();
myworld.save();
}
}
PlotMain.setAllPlotsRaw(DBFunc.getPlots());
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.");
} catch (final Exception e) {
e.printStackTrace();
}
}
});
} catch (final Exception e) {
}
}
}, 20);

View File

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

View File

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

View File

@ -52,7 +52,9 @@ import org.bukkit.entity.Player;
} else {
s = PlotMain.worldEdit.getSession(p);
}
if (!PlotMain.isPlotWorld(p.getWorld())) {
removeMask(p);
}
final PlotId id = PlayerFunctions.getPlot(l);
if (id != null) {
final Plot plot = PlotMain.getPlots(l.getWorld()).get(id);
@ -94,6 +96,16 @@ import org.bukkit.entity.Player;
// "WorldEdit == Null?");
}
}
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) {
return s.getMask() == null;