Fixed plot auto for mega plot
Fixed an issue with SQLManager and SQLite
Added config option for max claim area for a mega plot with plot auto
Fixed an issue with UUIDHandler + online mode and old minecraft
versions.
This commit is contained in:
boy0001 2014-12-15 12:04:13 +11:00
parent fd306bf0a9
commit 7029069e31
6 changed files with 85 additions and 53 deletions

View File

@ -924,7 +924,7 @@ public class PlotMain extends JavaPlugin {
final Map<String, Object> options = new HashMap<>(); final Map<String, Object> options = new HashMap<>();
options.put("auto_update", false); options.put("auto_update", false);
options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE);
options.put("UUID.offline", Settings.OFFLINE_MODE); options.put("UUID.offline", Settings.OFFLINE_MODE);
options.put("worldguard.enabled", Settings.WORLDGUARD); options.put("worldguard.enabled", Settings.WORLDGUARD);
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT); options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
@ -959,6 +959,7 @@ public class PlotMain extends JavaPlugin {
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding"); Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding");
Settings.METRICS = config.getBoolean("metrics"); Settings.METRICS = config.getBoolean("metrics");
Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days"); Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days");
Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area");
Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled"); Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled");
Settings.TITLES = config.getBoolean("titles"); Settings.TITLES = config.getBoolean("titles");
Settings.MOB_CAP_ENABLED = config.getBoolean("perm-based-mob-cap.enabled"); Settings.MOB_CAP_ENABLED = config.getBoolean("perm-based-mob-cap.enabled");

View File

@ -23,6 +23,7 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
@ -31,7 +32,9 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.PlotHelper;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -106,6 +109,8 @@ public class Auto extends SubCommand {
schematic = args[1]; schematic = args[1];
} }
} catch (final Exception e) { } catch (final Exception e) {
size_x = 1;
size_z = 1;
schematic = args[0]; schematic = args[0];
// PlayerFunctions.sendMessage(plr, // PlayerFunctions.sendMessage(plr,
// "&cError: Invalid size (X,Y)"); // "&cError: Invalid size (X,Y)");
@ -117,8 +122,19 @@ public class Auto extends SubCommand {
// return false; // return false;
} }
} }
if (PlayerFunctions.getPlayerPlotCount(world, plr) >= PlayerFunctions.getAllowedPlots(plr)) {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); if (size_x * size_z > Settings.MAX_AUTO_SIZE) {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
return false;
}
int diff = PlayerFunctions.getPlayerPlotCount(world, plr) - PlayerFunctions.getAllowedPlots(plr);
if (diff + (size_x * size_z) >= 0) {
if (diff < 0) {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, - diff - 1 + "");
}
else {
PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
return false; return false;
} }
final PlotWorld pWorld = PlotMain.getWorldSettings(world); final PlotWorld pWorld = PlotMain.getWorldSettings(world);
@ -136,16 +152,16 @@ public class Auto extends SubCommand {
} }
} }
if (!schematic.equals("")) { if (!schematic.equals("")) {
if (pWorld.SCHEMATIC_CLAIM_SPECIFY) { // if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
if (pWorld.SCHEMATICS.contains(schematic.toLowerCase())) { if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true; return true;
}
if (!PlotMain.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
}
} }
if (!PlotMain.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin")) {
PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
}
// }
} }
boolean br = false; boolean br = false;
if ((size_x == 1) && (size_z == 1)) { if ((size_x == 1) && (size_z == 1)) {
@ -165,23 +181,25 @@ public class Auto extends SubCommand {
Auto.lastPlot = getNextPlot(Auto.lastPlot, 1); Auto.lastPlot = getNextPlot(Auto.lastPlot, 1);
} }
} else { } else {
boolean lastPlot = true;
// Why does this need fixing, it should work fine for auto claiming mega plots PlotId lastId = Auto.lastPlot;
while (!br) { while (!br) {
final PlotId start = getNextPlot(Auto.lastPlot, 1); final PlotId start = getNextPlot(Auto.lastPlot, 1);
// Checking if the current set of plots is a viable option. // Checking if the current set of plots is a viable option.
{ Auto.lastPlot = start;
if ((PlotMain.getPlots(world).get(start) == null) || (PlotMain.getPlots(world).get(start).owner == null)) { if (lastPlot) {
Auto.lastPlot = start; lastId = start;
continue;
}
} }
if (PlotMain.getPlots(world).get(start) != null && PlotMain.getPlots(world).get(start).owner != null) {
continue;
}
else {
lastPlot = false;
}
System.out.print("UNOWNED: " + start);
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1); final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
if (isUnowned(world, start, end)) { if (isUnowned(world, start, end)) {
System.out.print("LAST PLOT: " + start);
for (int i = start.x; i <= end.x; i++) { for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) { for (int j = start.y; j <= end.y; j++) {
final Plot plot = PlotHelper.getPlot(world, new PlotId(i, j)); final Plot plot = PlotHelper.getPlot(world, new PlotId(i, j));

View File

@ -151,6 +151,7 @@ public enum C {
NO_PERMISSION("&cYou are lacking the permission node: &6%s"), NO_PERMISSION("&cYou are lacking the permission node: &6%s"),
NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"),
CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."),
CANT_CLAIM_MORE_PLOTS_NUM("&cYou can't claim more than &6%s &cplots at once"),
YOU_BE_DENIED("&cYou are not allowed to enter this plot"), YOU_BE_DENIED("&cYou are not allowed to enter this plot"),
NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"),

View File

@ -28,7 +28,10 @@ package com.intellectualcrafters.plot.config;
* @author Empire92 * @author Empire92
*/ */
public class Settings { public class Settings {
/**
*
*/
public static int MAX_AUTO_SIZE = 4;
/** /**
* Default worldedit-require-selection-in-mask: false * Default worldedit-require-selection-in-mask: false
*/ */

View File

@ -67,7 +67,8 @@ public class SQLManager implements AbstractDB {
connection = c; connection = c;
prefix = p; prefix = p;
// Set timout // Set timout
setTimout(); // setTimout();
// Public final // Public final
SET_OWNER = SET_OWNER =
"UPDATE `" + prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?"; "UPDATE `" + prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?";
@ -81,36 +82,38 @@ public class SQLManager implements AbstractDB {
"INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values "; "INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values ";
CREATE_PLOT = CREATE_PLOT =
"INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)";
//schedule reconnect
Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable(){
public void run(){
try {
connection = PlotMain.getMySQL().forceConnection();
}
catch (Exception e) {
e.printStackTrace();
}
}
}, 11000, 11000);
}
public void setTimout() { //schedule reconnect
runTask(new Runnable() { if (PlotMain.getMySQL() != null) {
@Override Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable(){
public void run() { public void run(){
try { try {
final PreparedStatement statement = connection.prepareStatement("SET GLOBAL wait_timeout =28800;"); connection = PlotMain.getMySQL().forceConnection();
statement.executeUpdate(); }
statement.close(); catch (Exception e) {
} catch (final SQLException e) { e.printStackTrace();
e.printStackTrace(); }
Logger.add(LogLevel.DANGER, "Could not reset MySQL timout.");
} }
} }, 11000, 11000);
}); }
} }
//
// public void setTimout() {
// runTask(new Runnable() {
// @Override
// public void run() {
// try {
// final PreparedStatement statement = connection.prepareStatement("SET GLOBAL wait_timeout =28800;");
// statement.executeQuery();
// statement.close();
// } catch (final SQLException e) {
// e.printStackTrace();
// Logger.add(LogLevel.DANGER, "Could not reset MySQL timout.");
// }
// }
// });
// }
/** /**
* Set Plot owner * Set Plot owner

View File

@ -325,6 +325,12 @@ public class UUIDHandler {
uuidWrapper = new OfflineUUIDWrapper(); uuidWrapper = new OfflineUUIDWrapper();
} }
} }
return uuidWrapper.getUUID(player); try {
return uuidWrapper.getUUID(player);
}
catch (Throwable e) {
uuidWrapper = new OfflineUUIDWrapper();
return uuidWrapper.getUUID(player);
}
} }
} }