mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Optimized plot saving + plot music
Fixes #244 - Faster PlotMe conversion - faster uuid mode conversion
This commit is contained in:
parent
f46386bdb4
commit
d68f57efb8
@ -732,7 +732,7 @@ public class PlotSquared {
|
||||
final List<String> booleanFlags = Arrays.asList("notify-enter", "notify-leave", "item-drop", "invincible", "instabreak", "drop-protection", "forcefield", "titles", "pve", "pvp", "no-worldedit", "redstone", "keep");
|
||||
final List<String> intervalFlags = Arrays.asList("feed", "heal");
|
||||
final List<String> stringFlags = Arrays.asList("greeting", "farewell");
|
||||
final List<String> intFlags = Arrays.asList("entity-cap", "mob-cap", "animal-cap", "hostile-cap", "vehicle-cap");
|
||||
final List<String> 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":
|
||||
|
@ -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<T> 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<T> 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<T> 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<SettingsPair> mod = new StmtMod<SettingsPair>() {
|
||||
@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
|
||||
|
@ -11,9 +11,9 @@ public abstract class StmtMod<T> {
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,4 +144,9 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
this.meta.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user