Optimized UUID caching + made Async

This commit is contained in:
boy0001 2015-06-25 00:32:27 +10:00
parent 8401c0dbcd
commit 7c55aa488c
10 changed files with 1166 additions and 116 deletions

View File

@ -524,7 +524,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
FlagManager.removeFlag(FlagManager.getFlag("titles")); FlagManager.removeFlag(FlagManager.getFlag("titles"));
} else { } else {
AbstractTitle.TITLE_CLASS = new DefaultTitle(); AbstractTitle.TITLE_CLASS = new DefaultTitle();
if (UUIDHandler.uuidWrapper instanceof DefaultUUIDWrapper) { if (UUIDHandler.uuidWrapper instanceof DefaultUUIDWrapper) {
Settings.TWIN_MODE_UUID = true; Settings.TWIN_MODE_UUID = true;
} }

View File

@ -718,9 +718,7 @@ public class PlotSquared {
for (final String flag : intFlags) { for (final String flag : intFlags) {
FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue())); FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue()));
} }
if (Settings.PHYSICS_LISTENER) { FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue()));
}
FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue()));
FlagManager.addFlag(new AbstractFlag("hostile-interact", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("hostile-interact", new FlagValue.BooleanValue()));
@ -806,7 +804,6 @@ public class PlotSquared {
options.put("protection.redstone.disable-offline", Settings.REDSTONE_DISABLER); options.put("protection.redstone.disable-offline", Settings.REDSTONE_DISABLER);
options.put("protection.tnt-listener.enabled", Settings.TNT_LISTENER); options.put("protection.tnt-listener.enabled", Settings.TNT_LISTENER);
options.put("protection.piston.falling-blocks", Settings.PISTON_FALLING_BLOCK_CHECK); options.put("protection.piston.falling-blocks", Settings.PISTON_FALLING_BLOCK_CHECK);
options.put("protection.physics-listener.enabled", Settings.PHYSICS_LISTENER);
// Clusters // Clusters
options.put("clusters.enabled", Settings.ENABLE_CLUSTERS); options.put("clusters.enabled", Settings.ENABLE_CLUSTERS);
@ -890,7 +887,6 @@ public class PlotSquared {
Settings.REDSTONE_DISABLER = config.getBoolean("protection.tnt-listener.enabled"); Settings.REDSTONE_DISABLER = config.getBoolean("protection.tnt-listener.enabled");
Settings.TNT_LISTENER = config.getBoolean("protection.tnt-listener.enabled"); Settings.TNT_LISTENER = config.getBoolean("protection.tnt-listener.enabled");
Settings.PISTON_FALLING_BLOCK_CHECK = config.getBoolean("protection.piston.falling-blocks"); Settings.PISTON_FALLING_BLOCK_CHECK = config.getBoolean("protection.piston.falling-blocks");
Settings.PHYSICS_LISTENER = config.getBoolean("protection.physics-listener.enabled");
// Clusters // Clusters
Settings.ENABLE_CLUSTERS = config.getBoolean("clusters.enabled"); Settings.ENABLE_CLUSTERS = config.getBoolean("clusters.enabled");
@ -902,7 +898,7 @@ public class PlotSquared {
// UUID // UUID
Settings.OFFLINE_MODE = config.getBoolean("UUID.offline"); Settings.OFFLINE_MODE = config.getBoolean("UUID.offline");
Settings.UUID_LOWERCASE = config.getBoolean("UUID.force-lowercase"); Settings.UUID_LOWERCASE = Settings.OFFLINE_MODE && config.getBoolean("UUID.force-lowercase");
Settings.UUID_FROM_DISK = config.getBoolean("uuid.read-from-disk"); Settings.UUID_FROM_DISK = config.getBoolean("uuid.read-from-disk");
// Mob stuff // Mob stuff

View File

@ -0,0 +1,14 @@
package com.intellectualcrafters.plot.commands;
public abstract class NamedSubCommand extends SubCommand {
public NamedSubCommand(Command command, String description, String usage, CommandCategory category, boolean isPlayer) {
super(command, description, usage, category, isPlayer);
}
public NamedSubCommand(String cmd, String permission, String description, String usage, CommandCategory category, boolean isPlayer, String[] aliases) {
super(cmd, permission, description, usage, category, isPlayer, aliases);
}
public NamedSubCommand(String cmd, String permission, String description, String usage, String alias, CommandCategory category, boolean isPlayer) {
super(cmd, permission, description, usage, alias, category, isPlayer);
}
}

View File

@ -288,9 +288,9 @@ public class list extends SubCommand {
} }
} }
i++; i++;
if (Settings.FANCY_CHAT) { if (player != null && Settings.FANCY_CHAT) {
ChatColor color; ChatColor color;
if (player == null) { if (plot.owner == null) {
color = ChatColor.GOLD; color = ChatColor.GOLD;
} }
else if (plot.isOwner(player.getUUID())) { else if (plot.isOwner(player.getUUID())) {
@ -397,7 +397,7 @@ public class list extends SubCommand {
MainUtil.sendMessage(player, message); MainUtil.sendMessage(player, message);
} }
} }
if (Settings.FANCY_CHAT) { if (player != null && Settings.FANCY_CHAT) {
if (page < totalPages && page > 0) { if (page < totalPages && page > 0) {
// back | next // back | next
new FancyMessage("") new FancyMessage("")

View File

@ -65,10 +65,6 @@ public class Settings {
* Check for falling blocks when pistons extend? * Check for falling blocks when pistons extend?
*/ */
public static boolean PISTON_FALLING_BLOCK_CHECK = true; public static boolean PISTON_FALLING_BLOCK_CHECK = true;
/**
* Physics listener
*/
public static boolean PHYSICS_LISTENER = false;
/** /**
* Max auto claiming size * Max auto claiming size
*/ */

View File

@ -123,7 +123,6 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (plot == null) { if (plot == null) {
return; return;
} }
if (Settings.REDSTONE_DISABLER) { if (Settings.REDSTONE_DISABLER) {
if (UUIDHandler.getPlayer(plot.owner) == null) { if (UUIDHandler.getPlayer(plot.owner) == null) {
boolean disable = true; boolean disable = true;
@ -225,7 +224,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
} }
if (Settings.PHYSICS_LISTENER && block.getType().hasGravity()) { if (block.getType().hasGravity()) {
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
if (plot == null) { if (plot == null) {
return; return;
@ -698,7 +697,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (MainUtil.isPlotRoad(loc)) { if (MainUtil.isPlotRoad(loc)) {
e.setCancelled(true); e.setCancelled(true);
} }
else if (Settings.PHYSICS_LISTENER) { else {
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) { if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
e.setCancelled(true); e.setCancelled(true);
@ -912,9 +911,6 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST) @EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onEntityFall(EntityChangeBlockEvent event) { public void onEntityFall(EntityChangeBlockEvent event) {
if (!Settings.PHYSICS_LISTENER) {
return;
}
if (event.getEntityType() != EntityType.FALLING_BLOCK) { if (event.getEntityType() != EntityType.FALLING_BLOCK) {
return; return;
} }
@ -1580,11 +1576,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
} }
if (Settings.PHYSICS_LISTENER) { if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) { Block block = event.getBlockPlaced();
Block block = event.getBlockPlaced(); sendBlockChange(block.getLocation(), block.getType(), block.getData());
sendBlockChange(block.getLocation(), block.getType(), block.getData());
}
} }
return; return;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,13 @@
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.nio.file.StandardOpenOption;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -11,6 +15,9 @@ import org.bukkit.OfflinePlayer;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import com.google.common.io.OutputSupplier;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
@ -21,6 +28,10 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.StringWrapper;
import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.NbtFactory;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.NbtFactory.NbtCompound;
import com.intellectualcrafters.plot.util.NbtFactory.StreamOptions;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper;
@ -111,106 +122,143 @@ public class UUIDHandler {
if (CACHED) { if (CACHED) {
return; return;
} }
PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching: " + world); final File container = Bukkit.getWorldContainer();
UUIDHandler.CACHED = true; UUIDHandler.CACHED = true;
add(new StringWrapper("*"), DBFunc.everyone); TaskManager.runTaskAsync(new Runnable() {
if (Settings.TWIN_MODE_UUID) { @Override
HashSet<UUID> all = getAllUUIDS(); public void run() {
final File playerdataFolder = new File(Bukkit.getWorldContainer(), world + File.separator + "playerdata"); PlotSquared.log(C.PREFIX.s() + "&6Starting player data caching for: " + world);
String[] dat = playerdataFolder.list(new FilenameFilter() { final HashMap<StringWrapper, UUID> toAdd = new HashMap<>();
@Override toAdd.put(new StringWrapper("*"), DBFunc.everyone);
public boolean accept(final File f, final String s) { if (Settings.TWIN_MODE_UUID) {
return s.endsWith(".dat"); HashSet<UUID> all = getAllUUIDS();
} PlotSquared.log("&aFast mod UUID caching enabled!");
}); final File playerdataFolder = new File(container, world + File.separator + "playerdata");
boolean check = all.size() == 0; String[] dat = playerdataFolder.list(new FilenameFilter() {
if (dat != null) { @Override
for (final String current : dat) { public boolean accept(final File f, final String s) {
final String s = current.replaceAll(".dat$", ""); return s.endsWith(".dat");
try {
final UUID uuid = UUID.fromString(s);
if (check || all.contains(uuid)) {
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
ExpireManager.dates.put(uuid, op.getLastPlayed());
add(new StringWrapper(op.getName()), uuid);
} }
} catch (final Exception e) { });
PlotSquared.log(C.PREFIX.s() + "Invalid playerdata: " + current); boolean check = all.size() == 0;
if (dat != null) {
for (final String current : dat) {
final String s = current.replaceAll(".dat$", "");
try {
UUID uuid = UUID.fromString(s);
if (check || all.contains(uuid)) {
File file = new File(playerdataFolder + File.separator + current);
InputSupplier<FileInputStream> is = Files.newInputStreamSupplier(file);
NbtCompound compound = NbtFactory.fromStream(is, StreamOptions.GZIP_COMPRESSION);
NbtCompound bukkit = (NbtCompound) compound.get("bukkit");
String name = (String) bukkit.get("lastKnownName");
long last = (long) bukkit.get("lastPlayed");
ExpireManager.dates.put(uuid, last);
toAdd.put(new StringWrapper(name), uuid);
}
} catch (final Exception e) {
e.printStackTrace();
PlotSquared.log(C.PREFIX.s() + "Invalid playerdata: " + current);
}
}
}
cache(toAdd);
return;
}
final HashSet<String> worlds = new HashSet<>();
worlds.add(world);
worlds.add("world");
final HashSet<UUID> uuids = new HashSet<>();
final HashSet<String> names = new HashSet<>();
File playerdataFolder = null;
for (final String worldname : worlds) {
// Getting UUIDs
playerdataFolder = new File(container, worldname + 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 && dat.length != 0) {
for (final String current : dat) {
final String s = current.replaceAll(".dat$", "");
try {
final UUID uuid = UUID.fromString(s);
uuids.add(uuid);
} catch (final Exception e) {
PlotSquared.log(C.PREFIX.s() + "Invalid playerdata: " + current);
}
}
break;
}
// Getting names
final File playersFolder = new File(worldname + File.separator + "players");
dat = playersFolder.list(new FilenameFilter() {
@Override
public boolean accept(final File f, final String s) {
return s.endsWith(".dat");
}
});
if (dat != null && dat.length != 0) {
for (final String current : dat) {
names.add(current.replaceAll(".dat$", ""));
}
break;
} }
} }
} for (UUID uuid : uuids) {
PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs");
return;
}
final HashSet<String> worlds = new HashSet<>();
worlds.add(world);
worlds.add("world");
final HashSet<UUID> uuids = new HashSet<>();
final HashSet<String> names = new HashSet<>();
for (final String worldname : worlds) {
// Getting UUIDs
final File playerdataFolder = new File(Bukkit.getWorldContainer(), worldname + 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 { try {
final UUID uuid = UUID.fromString(s); File file = new File(playerdataFolder + File.separator + uuid.toString() + ".dat");
uuids.add(uuid); InputSupplier<FileInputStream> is = Files.newInputStreamSupplier(file);
} catch (final Exception e) { NbtCompound compound = NbtFactory.fromStream(is, StreamOptions.GZIP_COMPRESSION);
PlotSquared.log(C.PREFIX.s() + "Invalid playerdata: " + current); NbtCompound bukkit = (NbtCompound) compound.get("bukkit");
String name = (String) bukkit.get("lastKnownName");
long last = (long) bukkit.get("lastPlayed");
if (Settings.OFFLINE_MODE) {
if (!Settings.UUID_LOWERCASE || !name.toLowerCase().equals(name)) {
long most = (long) compound.get("UUIDMost");
long least = (long) compound.get("UUIDLeast");
uuid = new UUID(most, least);
}
}
ExpireManager.dates.put(uuid, last);
toAdd.put(new StringWrapper(name), uuid);
} catch (final Throwable e) {
PlotSquared.log(C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat");
} }
} }
} for (final String name : names) {
// Getting names final UUID uuid = uuidWrapper.getUUID(name);
final File playersFolder = new File(worldname + File.separator + "players"); final StringWrapper nameWrap = new StringWrapper(name);
dat = playersFolder.list(new FilenameFilter() { toAdd.put(nameWrap, uuid);
@Override
public boolean accept(final File f, final String s) {
return s.endsWith(".dat");
} }
});
if (dat != null) {
for (final String current : dat) {
names.add(current.replaceAll(".dat$", ""));
}
}
}
final UUIDWrapper wrapper = new DefaultUUIDWrapper();
for (UUID uuid : uuids) {
try {
final OfflinePlotPlayer player = wrapper.getOfflinePlayer(uuid);
ExpireManager.dates.put(uuid, player.getLastPlayed());
uuid = UUIDHandler.uuidWrapper.getUUID(player);
final StringWrapper name = new StringWrapper(player.getName());
add(name, uuid);
} catch (final Throwable e) {
PlotSquared.log(C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat");
}
}
for (final String name : names) {
final UUID uuid = uuidWrapper.getUUID(name);
final StringWrapper nameWrap = new StringWrapper(name);
add(nameWrap, uuid);
}
if (uuidMap.size() == 0) {
if (uuidMap.size() == 0) { for (OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) {
for (OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) { if (op.getLastPlayed() != 0) {
if (op.getLastPlayed() != 0) { String name = op.getName();
String name = op.getName(); StringWrapper wrap = new StringWrapper(name);
StringWrapper wrap = new StringWrapper(name); UUID uuid = uuidWrapper.getUUID(op);
UUID uuid = uuidWrapper.getUUID(op); toAdd.put(wrap, uuid);
add(wrap, uuid); }
}
} }
cache(toAdd);
} }
} });
PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs"); }
public static void cache(final HashMap<StringWrapper, UUID> toAdd) {
TaskManager.runTask(new Runnable() {
@Override
public void run() {
for (Entry<StringWrapper, UUID> entry : toAdd.entrySet()) {
add(entry.getKey(), entry.getValue());
}
PlotSquared.log(C.PREFIX.s() + "&6Cached a total of: " + UUIDHandler.uuidMap.size() + " UUIDs");
}
});
} }
public static UUID getUUID(final PlotPlayer player) { public static UUID getUUID(final PlotPlayer player) {