Started working on functions that will allow for a saved UUID cache (i.e mysql, sqlite, txt file etc...) for faster reading and in-caching.

This commit is contained in:
Sauilitired 2014-10-13 21:22:19 +02:00
parent 4ba147b95f
commit 2bbcdb17bc
5 changed files with 115 additions and 36 deletions

View File

@ -8,42 +8,7 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import me.confuser.barapi.BarAPI;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import ca.mera.CameraAPI; import ca.mera.CameraAPI;
import com.intellectualcrafters.plot.Logger.LogLevel; import com.intellectualcrafters.plot.Logger.LogLevel;
import com.intellectualcrafters.plot.Settings.Web; import com.intellectualcrafters.plot.Settings.Web;
import com.intellectualcrafters.plot.commands.Camera; import com.intellectualcrafters.plot.commands.Camera;
@ -60,14 +25,39 @@ import com.intellectualcrafters.plot.generator.WorldGenerator;
import com.intellectualcrafters.plot.listeners.PlayerEvents; import com.intellectualcrafters.plot.listeners.PlayerEvents;
import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.intellectualcrafters.plot.listeners.WorldEditListener;
import com.intellectualcrafters.plot.listeners.WorldGuardListener; import com.intellectualcrafters.plot.listeners.WorldGuardListener;
import com.intellectualcrafters.plot.uuid.PlotUUIDSaver;
import com.intellectualcrafters.plot.uuid.UUIDSaver;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import me.confuser.barapi.BarAPI;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.*;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.Map.Entry;
/** /**
* @awesome @author Citymonstret, Empire92 PlotMain class. * @awesome @author Citymonstret, Empire92 PlotMain class.
*/ */
public class PlotMain extends JavaPlugin { public class PlotMain extends JavaPlugin {
private static UUIDSaver uuidSaver;
/** /**
* settings.properties * settings.properties
*/ */
@ -162,7 +152,7 @@ public class PlotMain extends JavaPlugin {
* - checks for '*' nodes * - checks for '*' nodes
* *
* @param player * @param player
* @param perm * @param perms
* @return * @return
*/ */
public static boolean hasPermissions(Player player, String[] perms) { public static boolean hasPermissions(Player player, String[] perms) {
@ -193,6 +183,14 @@ public class PlotMain extends JavaPlugin {
return true; return true;
} }
public static void setUUIDSaver(UUIDSaver saver) {
uuidSaver = saver;
}
public static UUIDSaver getUUIDSaver() {
return uuidSaver;
}
/** /**
* Check a player for a permission<br> * Check a player for a permission<br>
* - Op has all permissions <br> * - Op has all permissions <br>
@ -684,6 +682,7 @@ public class PlotMain extends JavaPlugin {
//Setup version + downloads, will not be updated... maybe setup runnable? TODO Let jesse decide... //Setup version + downloads, will not be updated... maybe setup runnable? TODO Let jesse decide...
com.intellectualcrafters.plot.commands.plugin.setup(this); com.intellectualcrafters.plot.commands.plugin.setup(this);
setUUIDSaver(new PlotUUIDSaver());
UUIDHandler.startFetch(this); UUIDHandler.startFetch(this);
} }

View File

@ -5,6 +5,7 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.intellectualcrafters.plot.uuid.NameFetcher; import com.intellectualcrafters.plot.uuid.NameFetcher;
import com.intellectualcrafters.plot.uuid.UUIDFetcher; import com.intellectualcrafters.plot.uuid.UUIDFetcher;
import com.intellectualcrafters.plot.uuid.UUIDSaver;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -223,4 +224,12 @@ public class UUIDHandler {
add(name, uuid); add(name, uuid);
return uuid; return uuid;
} }
/* Save UUIDS */
public static void handleSaving() {
UUIDSaver saver = PlotMain.getUUIDSaver();
// Should it save per UUIDSet or all of them? TODO: Let Jesse decide xD
saver.globalSave(getUuidMap());
}
} }

View File

@ -0,0 +1,27 @@
package com.intellectualcrafters.plot.uuid;
import com.google.common.collect.BiMap;
import java.util.UUID;
/**
* Created by Citymonstret on 2014-10-13.
*/
public class PlotUUIDSaver extends UUIDSaver {
public void globalSave(BiMap<String, UUID> map) {
}
public void save(UUIDSet set) {
}
public UUIDSet get(String name) {
return null;
}
public UUIDSet get(UUID uuid) {
return null;
}
}

View File

@ -0,0 +1,15 @@
package com.intellectualcrafters.plot.uuid;
import com.google.common.collect.BiMap;
import java.util.UUID;
/**
* Created by Citymonstret on 2014-10-13.
*/
public abstract class UUIDSaver {
public abstract void globalSave(BiMap<String, UUID> map);
public abstract void save(UUIDSet set);
public abstract UUIDSet get(String name);
public abstract UUIDSet get(UUID uuid);
}

View File

@ -0,0 +1,29 @@
package com.intellectualcrafters.plot.uuid;
import java.util.UUID;
/**
* Created by Citymonstret on 2014-10-13.
*/
public class UUIDSet {
private String name;
private UUID uuid;
public UUIDSet(String name, UUID uuid) {
this.name = name;
this.uuid = uuid;
}
@Override
public String toString() {
return getName();
}
public String getName() {
return name;
}
public UUID getUUID() {
return uuid;
}
}