diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index 222f89457..34ce70754 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -732,7 +732,7 @@ public class PlotSquared { final List booleanFlags = Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles", "pve", "pvp", "no-worldedit", "redstone", "keep"); final List intervalFlags = Arrays.asList("feed", "heal"); final List stringFlags = Arrays.asList("greeting", "farewell"); - final List intFlags = Arrays.asList("entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap"); + final List intFlags = Arrays.asList("entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap", "music"); for (final String flag : stringFlags) { FlagManager.addFlag(new AbstractFlag(flag)); } @@ -798,6 +798,9 @@ public class PlotSquared { case "storm": case "on": return "rain"; + case "lightning": + case "thunder": + return "thunder"; case "clear": case "off": case "sun": diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 0403a3b92..d96b347d0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -329,56 +329,116 @@ public class SQLManager implements AbstractDB { } int packet; if (Settings.DB.USE_MYSQL) { - packet = Math.min(size, 50000); + packet = Math.min(size, 5000); } else { packet = Math.min(size, 50); } final int amount = size / packet; - for (int j = 0; j <= amount; j++) { - final List subList = objList.subList(j * packet, Math.min(size, (j + 1) * packet)); - if (subList.size() == 0) { - return; - } - String statement = mod.getCreateMySQL(subList.size()); - PreparedStatement stmt = null; - try { - stmt = this.connection.prepareStatement(statement.toString()); + + try { + int count = 0; + PreparedStatement preparedStmt = null; + String statement = null; + int last = -1; + for (int j = 0; j <= amount; j++) { + final List subList = objList.subList(j * packet, Math.min(size, (j + 1) * packet)); + if (subList.size() == 0) { + return; + } + if (last == -1) { + last = subList.size(); + statement = mod.getCreateMySQL(subList.size()); + preparedStmt = this.connection.prepareStatement(statement.toString()); + } + if (subList.size() != last || (count % 5000 == 0 && count > 0)) { + preparedStmt.executeBatch(); + preparedStmt.close(); + + statement = mod.getCreateMySQL(subList.size()); + preparedStmt = this.connection.prepareStatement(statement.toString()); + } for (int i = 0; i < subList.size(); i++) { + count++; final T obj = subList.get(i); - mod.setMySQL(stmt,i , obj); + mod.setMySQL(preparedStmt, i , obj); } - stmt.executeUpdate(); - stmt.close(); - } catch (final Exception e) { + last = subList.size(); + preparedStmt.addBatch(); + } + PlotSquared.log("&aSuccess 1: " + count + " | " + objList.get(0).getClass().getCanonicalName()); + preparedStmt.executeBatch(); + preparedStmt.clearParameters(); + preparedStmt.close(); + return; + } + catch (Exception e) { + if (Settings.DB.USE_MYSQL) { + e.printStackTrace(); + PlotSquared.log("&cERROR 1: " + " | " + objList.get(0).getClass().getCanonicalName()); + } + } + + try { + int count = 0; + PreparedStatement preparedStmt = null; + String statement = null; + int last = -1; + for (int j = 0; j <= amount; j++) { + final List subList = objList.subList(j * packet, Math.min(size, (j + 1) * packet)); + if (subList.size() == 0) { + return; + } + if (last == -1) { + last = subList.size(); + statement = mod.getCreateSQLite(subList.size()); + preparedStmt = this.connection.prepareStatement(statement.toString()); + } + if (subList.size() != last || (count % 5000 == 0 && count > 0)) { + preparedStmt.executeBatch(); + preparedStmt.close(); + + statement = mod.getCreateSQLite(subList.size()); + preparedStmt = this.connection.prepareStatement(statement.toString()); + } + for (int i = 0; i < subList.size(); i++) { + count++; + final T obj = subList.get(i); + mod.setSQLite(preparedStmt, i , obj); + } + last = subList.size(); + preparedStmt.addBatch(); + } + PlotSquared.log("&aSuccess 2: " + count + " | " + objList.get(0).getClass().getCanonicalName()); + preparedStmt.executeBatch(); + preparedStmt.clearParameters(); + preparedStmt.close(); + return; + } + catch (Exception e) { + e.printStackTrace(); + PlotSquared.log("&cERROR 2: " + " | " + objList.get(0).getClass().getCanonicalName()); + } + + PlotSquared.log("&6[WARN] " + "Could not bulk save!"); + try { + PreparedStatement preparedStmt = null; + String nonBulk = mod.getCreateSQL(); + preparedStmt = this.connection.prepareStatement(nonBulk.toString()); + for (final T obj : objList) { try { - String unionstmt = mod.getCreateSQLite(subList.size()); - stmt = this.connection.prepareStatement(unionstmt.toString()); - for (int i = 0; i < subList.size(); i++) { - mod.setSQLite(stmt, i, subList.get(i)); - } - stmt.executeUpdate(); - stmt.close(); - } - catch (Exception e2) { - e2.printStackTrace(); - PlotSquared.log("&6[WARN] " + "Could not bulk save!"); - try { - for (final T obj : subList) { - try { - stmt = connection.prepareStatement(mod.getCreateSQL()); - mod.setSQL(stmt, obj); - stmt.executeUpdate(); - stmt.close(); - } catch (final Exception e3) { - PlotSquared.log("&c[ERROR] " + "Failed to save " + obj + "!"); - } - } - } catch (final Exception e4) { - e4.printStackTrace(); - PlotSquared.log("&c[ERROR] " + "Failed to save all!"); - } + mod.setSQL(preparedStmt, obj); + preparedStmt.addBatch(); + } catch (final Exception e3) { + PlotSquared.log("&c[ERROR] " + "Failed to save " + obj + "!"); } } + PlotSquared.log("&aSuccess 3"); + preparedStmt.executeBatch(); + preparedStmt.close(); + } + catch (Exception e3) { + e3.printStackTrace(); + PlotSquared.log("&c[ERROR] " + "Failed to save all!"); } } @@ -386,7 +446,7 @@ public class SQLManager implements AbstractDB { final StmtMod mod = new StmtMod() { @Override public String getCreateMySQL(int size) { - return getCreateMySQL(size, CREATE_SETTINGS, 10); + return getCreateMySQL(size, "INSERT INTO `" + prefix + "plot_settings`(`plot_plot_id`,`biome`,`rain`,`custom_time`,`time`,`deny_entry`,`alias`,`flags`,`merged`,`position`) VALUES ", 10); } @Override @@ -397,7 +457,6 @@ public class SQLManager implements AbstractDB { @Override public String getCreateSQL() { return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`) VALUES(?)"; -// return "INSERT INTO `" + SQLManager.this.prefix + "plot_settings`(`plot_plot_id`,`biome`,`rain`,`custom_time`,`time`,`deny_entry`,`alias`,`flags`,`merged`,`position`) VALUES(?,?,?,?,?,?,?,?,?,?)"; } @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java index dc204ac60..09e7284c8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/StmtMod.java @@ -11,9 +11,9 @@ public abstract class StmtMod { public String getCreateMySQL(int size, String query, int params) { final StringBuilder statement = new StringBuilder(query); for (int i = 0; i < size - 1; i++) { - statement.append(StringUtils.repeat("(?),", params)); + statement.append("(" + StringUtils.repeat(",(?)", params).substring(1) + "),"); } - statement.append(StringUtils.repeat(",(?)", params).substring(1)); + statement.append("(" + StringUtils.repeat(",(?)", params).substring(1) + ")"); return statement.toString(); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index b654d1032..f65885567 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -179,6 +179,19 @@ public class FlagManager { DBFunc.setFlags(plot.world, plot, plot.settings.flags); return true; } + + public static boolean addPlotFlagAbs(final Plot plot, final Flag flag) { + final boolean result = EventUtil.manager.callFlagAdd(flag, plot); + if (!result) { + return false; + } + final Flag hasFlag = getPlotFlag(plot, flag.getKey()); + if (hasFlag != null) { + plot.settings.flags.remove(hasFlag); + } + plot.settings.flags.add(flag); + return true; + } public static boolean addClusterFlag(final PlotCluster cluster, final Flag flag) { //TODO plot cluster flag event diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java index 896198270..a8a97ba9f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java @@ -25,7 +25,9 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Effect; import org.bukkit.GameMode; +import org.bukkit.Material; import org.bukkit.WeatherType; import org.bukkit.entity.Player; @@ -65,12 +67,16 @@ public class PlotListener extends APlotListener { return name; } - private WeatherType getWeatherType(String str) { - str = str.toLowerCase(); - if (str.equals("rain")) { - return WeatherType.DOWNFALL; - } else { - return WeatherType.CLEAR; + private void setWeather(Player player, String str) { + switch (str.toLowerCase()) { + case "clear": { + player.setPlayerWeather(WeatherType.CLEAR); + return; + } + case "rain": { + player.setPlayerWeather(WeatherType.DOWNFALL); + return; + } } } @@ -109,7 +115,7 @@ public class PlotListener extends APlotListener { } final Flag weatherFlag = FlagManager.getPlotFlag(plot, "weather"); if (weatherFlag != null) { - player.setPlayerWeather(getWeatherType(weatherFlag.getValueString())); + setWeather(player, weatherFlag.getValueString()); } if ((FlagManager.isBooleanFlag(plot, "titles", Settings.TITLES)) && (C.TITLE_ENTERED_PLOT.s().length() > 2)) { Flag greetingFlag = FlagManager.getPlotFlag(plot, "greeting"); @@ -130,6 +136,14 @@ public class PlotListener extends APlotListener { final PlayerEnterPlotEvent callEvent = new PlayerEnterPlotEvent(player, plot); Bukkit.getPluginManager().callEvent(callEvent); } + Flag musicFlag = FlagManager.getPlotFlag(plot, "music"); + if (musicFlag != null) { + player.playEffect(player.getLocation(), Effect.RECORD_PLAY, 0); + Integer id = (Integer) musicFlag.getValue(); + if (id != 0) { + player.playEffect(player.getLocation(), Effect.RECORD_PLAY, Material.getMaterial(id)); + } + } CommentManager.sendTitle(pp, plot); } } @@ -150,6 +164,9 @@ public class PlotListener extends APlotListener { if (FlagManager.getPlotFlag(plot, "weather") != null) { player.resetPlayerWeather(); } + if (FlagManager.getPlotFlag(plot, "music") != null) { + player.playEffect(player.getLocation(), Effect.RECORD_PLAY, 0); + } } public boolean getFlagValue(final String value) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java index 20161dcfd..4363dcaac 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlotPlusListener.java @@ -51,6 +51,7 @@ import org.bukkit.plugin.java.JavaPlugin; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; +import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotHandler; @@ -143,9 +144,13 @@ public class PlotPlusListener extends PlotListener implements Listener { return; } if (meta != null) { + int id = meta.getMaterial().getId(); + FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id)); + player.playEffect(player.getLocation(), Effect.RECORD_PLAY, 0); for (final Player p : plotPlayers) { - p.playEffect(p.getLocation(), Effect.RECORD_PLAY, meta.getMaterial()); - MainUtil.sendMessage(pp, C.RECORD_PLAY.s().replaceAll("%player", player.getName()).replaceAll("%name", meta.toString())); + player.playEffect(player.getLocation(), Effect.RECORD_PLAY, 0); + player.playEffect(player.getLocation(), Effect.RECORD_PLAY, id); + APlotListener.manager.plotEntry(BukkitUtil.getPlayer(p), plot); } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index 3832ed22e..7509c106d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -144,4 +144,9 @@ public class BukkitPlayer implements PlotPlayer { this.meta.remove(key); } } + + @Override + public String toString() { + return getName(); + } }