Fixed the uuid saving functions, added ability to change caching methods.

This commit is contained in:
Sauilitired 2014-10-14 16:16:05 +02:00
parent 2bbcdb17bc
commit 0961671eaf
5 changed files with 55 additions and 40 deletions

View File

@ -502,18 +502,22 @@ public class PlotMain extends JavaPlugin {
@Override
@SuppressWarnings("deprecation")
public void onEnable() {
// Init the logger
setupLogger();
// Check for outdated java version.
if (getJavaVersion() < 1.7) {
sendConsoleSenderMessage(C.PREFIX.s() + "&cYour java version is outdated. Please update to at least 1.7.");
// Didn't know of any other link :D
sendConsoleSenderMessage(C.PREFIX.s() + "&cURL: &6https://java.com/en/download/index.jsp");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
// Setup configurations
configs();
// Setup metrics
if (Settings.METRICS) {
try {
Metrics metrics = new Metrics(this);
@ -525,13 +529,17 @@ public class PlotMain extends JavaPlugin {
}
}
// Kill mobs on roads?
if (Settings.KILL_ROAD_MOBS) {
killAllEntities();
}
// Enabled<3
if (C.ENABLED.s().length() > 0) {
Broadcast(C.ENABLED);
}
// Use mysql?
if (Settings.DB.USE_MYSQL) {
try {
mySQL =
@ -568,10 +576,12 @@ public class PlotMain extends JavaPlugin {
plots = DBFunc.getPlots();
}
// TODO: Implement mongo
else
if (Settings.DB.USE_MONGO) {
sendConsoleSenderMessage(C.PREFIX.s() + "MongoDB is not yet implemented");
}
// Use Sqlite :D<3
else
if (Settings.DB.USE_SQLITE) {
try {
@ -626,6 +636,7 @@ public class PlotMain extends JavaPlugin {
getCommand("plots").setAliases(new ArrayList<String>() {
{
add("p");
add("ps");
add("plotme");
add("plot");
}
@ -683,7 +694,8 @@ public class PlotMain extends JavaPlugin {
com.intellectualcrafters.plot.commands.plugin.setup(this);
setUUIDSaver(new PlotUUIDSaver());
UUIDHandler.startFetch(this);
getUUIDSaver().globalPopulate();
//UUIDHandler.startFetch(this);
}
/**

View File

@ -9,7 +9,6 @@ import com.intellectualcrafters.plot.uuid.UUIDSaver;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Arrays;
import java.util.UUID;
@ -54,43 +53,6 @@ public class UUIDHandler {
uuidMap.put(name, uuid);
}
/**
* @param plugin
*/
public static void startFetch(JavaPlugin plugin) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
int length = offlinePlayers.length;
long start = System.currentTimeMillis();
String name;
UUID uuid;
for (OfflinePlayer player : offlinePlayers) {
uuid = player.getUniqueId();
if (!uuidExists(uuid)) {
name = player.getName();
add(name, uuid);
}
}
long time = System.currentTimeMillis() - start;
int size = uuidMap.size();
double ups;
if(time == 0l || size == 0) {
ups = size;
} else {
ups = size / time;
}
//Plot Squared Only...
PlotMain.sendConsoleSenderMessage("&cFinished caching of offline player UUIDs! Took &6" + time + "&cms (&6" + ups + "&c per millisecond), &6"
+ length + " &cUUIDs were cached" + " and there is now a grand total of &6" + size
+ " &ccached.");
}
});
}
/**
* @param name

View File

@ -1,6 +1,11 @@
package com.intellectualcrafters.plot.uuid;
import com.google.common.collect.BiMap;
import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.UUIDHandler;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.UUID;
@ -9,6 +14,41 @@ import java.util.UUID;
*/
public class PlotUUIDSaver extends UUIDSaver {
public void globalPopulate() {
JavaPlugin.getPlugin(PlotMain.class).getServer().getScheduler().runTaskAsynchronously(JavaPlugin.getPlugin(PlotMain.class), new Runnable() {
@Override
public void run() {
OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
int length = offlinePlayers.length;
long start = System.currentTimeMillis();
String name;
UUID uuid;
for (OfflinePlayer player : offlinePlayers) {
uuid = player.getUniqueId();
if (!UUIDHandler.uuidExists(uuid)) {
name = player.getName();
UUIDHandler.add(name, uuid);
}
}
long time = System.currentTimeMillis() - start;
int size = UUIDHandler.getUuidMap().size();
double ups;
if(time == 0l || size == 0) {
ups = size;
} else {
ups = size / time;
}
//Plot Squared Only...
PlotMain.sendConsoleSenderMessage("&cFinished caching of offline player UUIDs! Took &6" + time + "&cms (&6" + ups + "&c per millisecond), &6"
+ length + " &cUUIDs were cached" + " and there is now a grand total of &6" + size
+ " &ccached.");
}
});
}
public void globalSave(BiMap<String, UUID> map) {
}

View File

@ -8,6 +8,7 @@ import java.util.UUID;
* Created by Citymonstret on 2014-10-13.
*/
public abstract class UUIDSaver {
public abstract void globalPopulate();
public abstract void globalSave(BiMap<String, UUID> map);
public abstract void save(UUIDSet set);
public abstract UUIDSet get(String name);

View File

@ -10,7 +10,7 @@ database: false
commands:
plots:
description: PlotMain PlotSquared command.
aliases: [p,plotme,plot]
aliases: [p,plotme,plot,ps]
permission: plots.use
permissions:
plots.use: