mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 08:36:45 +01:00
Optimized UUID caching
This commit is contained in:
parent
333128b203
commit
0243f423f6
@ -445,13 +445,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
@Override
|
||||
public UUIDWrapper initUUIDHandler() {
|
||||
final boolean checkVersion = checkVersion(1, 7, 6);
|
||||
if (!checkVersion) {
|
||||
log(C.PREFIX.s() + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
||||
Settings.TITLES = false;
|
||||
FlagManager.removeFlag(FlagManager.getFlag("titles"));
|
||||
} else {
|
||||
AbstractTitle.TITLE_CLASS = new DefaultTitle();
|
||||
}
|
||||
if (Settings.OFFLINE_MODE) {
|
||||
if (Settings.UUID_LOWERCASE) {
|
||||
UUIDHandler.uuidWrapper = new LowerOfflineUUIDWrapper();
|
||||
@ -472,6 +465,20 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
}
|
||||
Settings.OFFLINE_MODE = true;
|
||||
}
|
||||
if (!checkVersion) {
|
||||
log(C.PREFIX.s() + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
||||
Settings.TITLES = false;
|
||||
FlagManager.removeFlag(FlagManager.getFlag("titles"));
|
||||
} else {
|
||||
AbstractTitle.TITLE_CLASS = new DefaultTitle();
|
||||
|
||||
if (UUIDHandler.uuidWrapper instanceof DefaultUUIDWrapper) {
|
||||
Settings.TWIN_MODE_UUID = true;
|
||||
}
|
||||
else if (UUIDHandler.uuidWrapper instanceof OfflineUUIDWrapper && !Bukkit.getOnlineMode()) {
|
||||
Settings.TWIN_MODE_UUID = true;
|
||||
}
|
||||
}
|
||||
if (Settings.OFFLINE_MODE) {
|
||||
log(C.PREFIX.s() + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit");
|
||||
} else {
|
||||
|
@ -149,6 +149,7 @@ public class Settings {
|
||||
/**
|
||||
* Use offline mode storage
|
||||
*/
|
||||
public static boolean TWIN_MODE_UUID = false;
|
||||
public static boolean OFFLINE_MODE = false;
|
||||
public static boolean UUID_LOWERCASE = false;
|
||||
/**
|
||||
|
@ -6,6 +6,9 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
@ -14,6 +17,7 @@ import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
|
||||
@ -83,14 +87,62 @@ public class UUIDHandler {
|
||||
return uuidMap.containsKey(name);
|
||||
}
|
||||
|
||||
public static HashSet<UUID> getAllUUIDS() {
|
||||
HashSet<UUID> uuids = new HashSet<UUID>();
|
||||
for (Plot plot : PlotSquared.getPlotsRaw()) {
|
||||
for (UUID uuid : plot.helpers) {
|
||||
uuids.add(uuid);
|
||||
}
|
||||
for (UUID uuid : plot.trusted) {
|
||||
uuids.add(uuid);
|
||||
}
|
||||
for (UUID uuid : plot.denied) {
|
||||
uuids.add(uuid);
|
||||
}
|
||||
if (plot.owner != null) {
|
||||
uuids.add(plot.owner);
|
||||
}
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
|
||||
public static void cacheAll(final String world) {
|
||||
if (CACHED) {
|
||||
return;
|
||||
}
|
||||
PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching");
|
||||
long start = System.currentTimeMillis();
|
||||
UUIDHandler.CACHED = true;
|
||||
|
||||
// OLD UUID CACHING SYSTEM
|
||||
if (Settings.TWIN_MODE_UUID) {
|
||||
HashSet<UUID> all = getAllUUIDS();
|
||||
final File playerdataFolder = new File(world + File.separator + "playerdata");
|
||||
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f, final String s) {
|
||||
return s.endsWith(".dat");
|
||||
}
|
||||
});
|
||||
if (dat != null) {
|
||||
for (final String current : dat) {
|
||||
final String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
final UUID uuid = UUID.fromString(s);
|
||||
if (all.contains(uuid)) {
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
|
||||
add(new StringWrapper(op.getName()), uuid);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
PlotSquared.log(C.PREFIX.s() + "Invalid playerdata: " + current);
|
||||
}
|
||||
}
|
||||
}
|
||||
PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs");
|
||||
System.out.print(System.currentTimeMillis() - start);
|
||||
System.out.print(Settings.TWIN_MODE_UUID);
|
||||
return;
|
||||
}
|
||||
|
||||
final HashSet<String> worlds = new HashSet<>();
|
||||
worlds.add(world);
|
||||
worlds.add("world");
|
||||
@ -161,6 +213,8 @@ public class UUIDHandler {
|
||||
// add the Everyone '*' UUID
|
||||
add(new StringWrapper("*"), DBFunc.everyone);
|
||||
PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs");
|
||||
System.out.print(System.currentTimeMillis() - start);
|
||||
System.out.print(Settings.TWIN_MODE_UUID);
|
||||
}
|
||||
|
||||
public static UUID getUUID(final PlotPlayer player) {
|
||||
|
Loading…
Reference in New Issue
Block a user