mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
The damn reflection doesn't want to work.
Why did zachbora think it was a good idea to convert the UUIDs to player names before returning them? Anywho, I added a slower method that now works at okay speeds. (22 seconds for 2549 user checks)
This commit is contained in:
parent
c4d328455e
commit
97c452e311
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
@ -65,38 +66,90 @@ public class DBFunc {
|
||||
});
|
||||
}
|
||||
|
||||
public static void createAllSettings() {
|
||||
final ArrayList<Integer> ids = new ArrayList<Integer>();
|
||||
public static void createAllSettingsAndHelpers(ArrayList<Plot> plots) {
|
||||
HashMap<String, HashMap<PlotId, Integer>> stored = new HashMap< String, HashMap<PlotId, Integer>>();
|
||||
HashMap<Integer, ArrayList<UUID>> helpers = new HashMap<Integer, ArrayList<UUID>>();
|
||||
try {
|
||||
PreparedStatement stmt = connection.prepareStatement("SELECT `id` FROM `plot`");
|
||||
PreparedStatement stmt = connection.prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z`, `world` FROM `plot`");
|
||||
ResultSet result = stmt.executeQuery();
|
||||
while (result.next()) {
|
||||
int id = result.getInt("id");
|
||||
ids.add(id);
|
||||
int idx = result.getInt("plot_id_x");
|
||||
int idz = result.getInt("plot_id_z");
|
||||
String world = result.getString("world");
|
||||
|
||||
if (!stored.containsKey(world)) {
|
||||
stored.put(world,new HashMap<PlotId, Integer>());
|
||||
}
|
||||
stored.get(world).put(new PlotId(idx,idz), id);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (ids.size()==0) {
|
||||
System.out.print("ERROR: No plots found");
|
||||
|
||||
for (Plot plot:plots) {
|
||||
String world = Bukkit.getWorld(plot.world).getName();
|
||||
if (stored.containsKey(world)) {
|
||||
Integer id = stored.get(world).get(plot.id);
|
||||
if (id!=null) {
|
||||
helpers.put(id,plot.helpers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (helpers.size()==0) {
|
||||
return;
|
||||
}
|
||||
final StringBuilder statement = new StringBuilder("INSERT INTO `plot_settings`(`plot_plot_id`) values ");
|
||||
for (int i = 0; i<ids.size()-1; i++) {
|
||||
|
||||
// add plot settings
|
||||
Integer[] ids = helpers.keySet().toArray(new Integer[0]);
|
||||
StringBuilder statement = new StringBuilder("INSERT INTO `plot_settings` (`plot_plot_id`) values ");
|
||||
for (int i = 0; i<ids.length-1; i++) {
|
||||
statement.append("(?),");
|
||||
}
|
||||
statement.append("(?)");
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
stmt = connection.prepareStatement(statement.toString());
|
||||
for (int i = 0; i<ids.size(); i++) {
|
||||
stmt.setInt(i+1, ids.get(i));
|
||||
for (int i = 0; i<ids.length; i++) {
|
||||
stmt.setInt(i+1, ids[i]);
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// add plot helpers
|
||||
String prefix = "";
|
||||
statement = new StringBuilder("INSERT INTO `plot_helpers` (`plot_plot_id`, `user_uuid`) values ");
|
||||
for (Integer id:helpers.keySet()) {
|
||||
for (UUID helper:helpers.get(id)) {
|
||||
statement.append(prefix+"(?, ?)");
|
||||
prefix = ",";
|
||||
}
|
||||
}
|
||||
if (prefix.equals("")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
stmt = connection.prepareStatement(statement.toString());
|
||||
int counter = 0;
|
||||
for (Integer id:helpers.keySet()) {
|
||||
for (UUID helper:helpers.get(id)) {
|
||||
|
||||
stmt.setInt(counter*2+1, id);
|
||||
stmt.setString(counter*2+2, helper.toString());
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
Logger.add(LogLevel.WARNING, "Failed to set helper for plots");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,10 +13,12 @@ import org.bukkit.World;
|
||||
import com.intellectualcrafters.plot.PlotHomePosition;
|
||||
import com.intellectualcrafters.plot.PlotId;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.api.PlotAPI;
|
||||
import com.sun.org.apache.xerces.internal.impl.dv.DVFactoryException;
|
||||
import com.worldcretornica.plotme.PlayerList;
|
||||
import com.worldcretornica.plotme.Plot;
|
||||
import com.worldcretornica.plotme.PlotManager;
|
||||
import com.worldcretornica.plotme.PlotMe;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-08-17.
|
||||
@ -37,7 +39,7 @@ public class PlotMeConverter {
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<com.intellectualcrafters.plot.Plot> createdPlots = new ArrayList<com.intellectualcrafters.plot.Plot>();
|
||||
ArrayList<Integer> createdIds = new ArrayList<Integer>();
|
||||
HashMap<String, UUID> uuidMap = new HashMap<String, UUID>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
HashMap<String, Plot> plots = PlotManager.getPlots(world);
|
||||
if (plots!=null) {
|
||||
@ -57,7 +59,10 @@ public class PlotMeConverter {
|
||||
}
|
||||
long eR3040bl230 = 22392948l;
|
||||
try {
|
||||
Field fAdded = plot.getClass().getField("added");
|
||||
|
||||
// TODO It just comes up with a NoSuchFieldException. Y U NO WORK!!! (I didn't change anything here btw)
|
||||
|
||||
Field fAdded = plot.getClass().getField("allowed");
|
||||
Field fDenied = plot.getClass().getField("denied");
|
||||
fAdded.setAccessible(true);
|
||||
fDenied.setAccessible(true);
|
||||
@ -78,6 +83,41 @@ public class PlotMeConverter {
|
||||
psDenied.add(set.getValue());
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
// Doing it the slow way like a n00b.
|
||||
for (String user:plot.getAllowed().split(",")) {
|
||||
try {
|
||||
if (user.equals("*")) {
|
||||
psAdded.add(DBFunc.everyone);
|
||||
}
|
||||
else if (uuidMap.containsKey(user)) {
|
||||
psAdded.add(uuidMap.get(user));
|
||||
}
|
||||
else {
|
||||
UUID uuid = Bukkit.getOfflinePlayer(user).getUniqueId();
|
||||
uuidMap.put(user, uuid);
|
||||
psAdded.add(uuid);
|
||||
}
|
||||
}
|
||||
catch (Exception e2) {
|
||||
}
|
||||
}
|
||||
for (String user:plot.getDenied().split(",")) {
|
||||
try {
|
||||
if (user.equals("*")) {
|
||||
psDenied.add(DBFunc.everyone);
|
||||
}
|
||||
else if (uuidMap.containsKey(user)) {
|
||||
psDenied.add(uuidMap.get(user));
|
||||
}
|
||||
else {
|
||||
UUID uuid = Bukkit.getOfflinePlayer(user).getUniqueId();
|
||||
uuidMap.put(user, uuid);
|
||||
psDenied.add(uuid);
|
||||
}
|
||||
}
|
||||
catch (Exception e2) {
|
||||
}
|
||||
}
|
||||
eR3040bl230 = 232000499888388747l;
|
||||
} finally {
|
||||
eR3040bl230 = 232999304998392004l;
|
||||
@ -92,9 +132,11 @@ public class PlotMeConverter {
|
||||
}
|
||||
}
|
||||
}
|
||||
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Saving to DB");
|
||||
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Creating plot DB");
|
||||
DBFunc.createPlots(createdPlots);
|
||||
DBFunc.createAllSettings();
|
||||
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Creating settings/helpers DB");
|
||||
DBFunc.createAllSettingsAndHelpers(createdPlots);
|
||||
|
||||
stream.close();
|
||||
PlotMain.sendConsoleSenderMessage("PlotMe->PlotSquared Conversion has finished");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user