From 0961671eaf4f7539922dd987f46b3e44f0266f51 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Tue, 14 Oct 2014 16:16:05 +0200 Subject: [PATCH] Fixed the uuid saving functions, added ability to change caching methods. --- .../intellectualcrafters/plot/PlotMain.java | 14 ++++++- .../plot/UUIDHandler.java | 38 ------------------ .../plot/uuid/PlotUUIDSaver.java | 40 +++++++++++++++++++ .../plot/uuid/UUIDSaver.java | 1 + PlotSquared/src/plugin.yml | 2 +- 5 files changed, 55 insertions(+), 40 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index 549b7241f..ff9d4e102 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -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() { { 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); } /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java index ce4c5f7ec..440659316 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java @@ -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 diff --git a/PlotSquared/src/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java b/PlotSquared/src/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java index 086eddc87..d5bf55d7c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/uuid/PlotUUIDSaver.java @@ -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 map) { } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/uuid/UUIDSaver.java b/PlotSquared/src/com/intellectualcrafters/plot/uuid/UUIDSaver.java index 7e494d34f..860441e5b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/uuid/UUIDSaver.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/uuid/UUIDSaver.java @@ -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 map); public abstract void save(UUIDSet set); public abstract UUIDSet get(String name); diff --git a/PlotSquared/src/plugin.yml b/PlotSquared/src/plugin.yml index 671cdba1b..0f0b9b4dd 100644 --- a/PlotSquared/src/plugin.yml +++ b/PlotSquared/src/plugin.yml @@ -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: