Skip to content

Commit

Permalink
SaveQueries / GetUUID Update
Browse files Browse the repository at this point in the history
This update adds functionality to save UUIDs / usernames into playerdata
when queries are made for those UUIDs (but not already saved,
afterwards, such as adding to whitelist).

This way, you can speed up future searches, without having to have that
player have been on the whitelist at some point. This is optional, and
can be turned off in the config. It is true, by default.

Additionally, there is now a 'getid' function, which will allow a user
to see search for a player's UUID by their username. This will hook into
SaveQueries, if enabled, and save that information to playerdata.

As you can see from an alias assembler in previous versions of
Executor.java, this was already a planned feature.
  • Loading branch information
FerusGrim committed Apr 29, 2014
1 parent fa9d1d6 commit ed45767
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 4 deletions.
101 changes: 101 additions & 0 deletions src/main/java/io/github/ferusgrim/GrimList/Commands/GetUUID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @author FerusGrim
* @website http://ferusgrim.github.io/
* Copyright under GPLv3 to Nicholas Badger (FerusGrim) - 2014
*/

package io.github.ferusgrim.GrimList.Commands;

import io.github.ferusgrim.GrimList.GrimList;
import io.github.ferusgrim.GrimList.utils.AsyncThenSyncOperation;
import io.github.ferusgrim.GrimList.utils.UUIDFetcher;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Arrays;
import java.util.Map;
import java.util.UUID;

public class GetUUID {
private GrimList plugin;

public GetUUID(GrimList plugin){
this.plugin = plugin;
}

public boolean run(CommandSender sender, String name){
switch(plugin.focusOn){
case "file":
String uuid = plugin.filem.getUUID(name);
if(uuid.isEmpty()){
runOperation(sender, name);
}else{
outputText(sender, uuid, name);
}
break;
}
return true;
}

public void outputText(CommandSender sender, String uuid, String name){
if (sender instanceof Player){
sender.sendMessage(plugin.mStart + "UUID of " + name + ":");
sender.sendMessage(plugin.mStart + uuid);
} else {
plugin.log("INFO", "UUID of " + name + ":");
plugin.log("INFO", uuid);
}
}

public void runOperation(CommandSender sender, String name){
if (sender instanceof Player) {
sender.sendMessage(plugin.mStart + "Looking up UUID. This can take a moment...");
} else {
plugin.log("INFO", "Looking up UUID. This can take a moment...");
}
new AsyncThenSyncOperation(plugin, true){
private Map<String, UUID> response = null;

@Override
protected void execAsyncFirst() {
try{
response = new UUIDFetcher(Arrays.asList(name.toLowerCase())).call();
} catch (Exception e) {
plugin.log("WARNING", "Exception while running UUIDFetcher!");
e.printStackTrace();
}
}

@Override
protected void execSyncThen() {
if (response.get(name.toLowerCase()) == null) {
if (sender instanceof Player) {
sender.sendMessage(plugin.mStart + "UUID Query returned null! Invalid username?");
} else {
plugin.log("WARNING", "UUID Query returned null! Username might not exist.?");
}
return;
}
String uuid = response.get(name.toLowerCase()).toString();
switch(plugin.focusOn){
case "file":
if (plugin.filem.recordExists(uuid)) {
outputText(sender, uuid, name);
} else {
if (!plugin.filem.recordExists(uuid) && plugin.getConfig().getBoolean("SaveQueries")) {
plugin.filem.newPlayerRecord(uuid, name);
outputText(sender, uuid, name);
return;
}
}
if (sender instanceof Player) {
sender.sendMessage(plugin.mStart + "Player record not found!");
}else{
plugin.log("WARNING", "Player record not found!");
}
break;
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ protected void execSyncThen() {
String uuid = response.get(name.toLowerCase()).toString();
switch(plugin.focusOn){
case "file":
if(!plugin.filem.recordExists(uuid) && plugin.getConfig().getBoolean("SaveQueries")){
plugin.filem.newPlayerRecord(uuid, name);
}
if(!plugin.filem.alreadyOnWhitelist(uuid)){
if(sender instanceof Player){
sender.sendMessage(plugin.mStart + "'" + name + "' isn't whitelisted!");
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/io/github/ferusgrim/GrimList/Commands/SetConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,43 @@ public boolean run(CommandSender sender, String[] args) {
plugin.log("INFO", "Debug messages are already disabled!");
}
return true;
case "queries":
switch(args[2].toLowerCase()) {
case "true":
if (plugin.getConfig().getBoolean("SaveQueries")) {
if (sender instanceof Player) {
sender.sendMessage(plugin.mStart + "Saving queries is already enabled!");
} else {
plugin.log("INFO", "Saving queries is already enabled!");
}
return true;
}
plugin.getConfig().set("SaveQueries", true);
plugin.saveConfig();
if (sender instanceof Player) {
sender.sendMessage(plugin.mStart + "Saving queries has been enabled!");
} else {
plugin.log("INFO", "Saving queries has been enabled!");
}
return true;
case "false":
if (plugin.getConfig().getBoolean("SaveQueries")) {
plugin.getConfig().set("SaveQueries", false);
plugin.saveConfig();
if (sender instanceof Player) {
sender.sendMessage(plugin.mStart + "Saving queries has been disabled!");
} else {
plugin.log("INFO", "Saving queries has been disabled!");
}
return true;
}
if (sender instanceof Player) {
sender.sendMessage(plugin.mStart + "Saving queries is already disabled!");
} else {
plugin.log("INFO", "Saving queries is already disabled!");
}
return true;
}
default:
if (sender instanceof Player) {
sender.sendMessage(plugin.mStart + "Please select between true or false!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public boolean run(CommandSender sender, String name) {
if(uuid.isEmpty()){
runOperation(sender, name);
}else{
if(plugin.filem.recordExists(uuid)){
outputText(sender, uuid);
}
outputText(sender, uuid);
}
break;
}
Expand Down Expand Up @@ -129,6 +127,12 @@ protected void execSyncThen() {
if(plugin.filem.recordExists(uuid)){
outputText(sender, uuid);
return;
}else{
if(!plugin.filem.recordExists(uuid) && plugin.getConfig().getBoolean("SaveQueries")){
plugin.filem.newPlayerRecord(uuid, name);
outputText(sender, uuid);
return;
}
}
if (sender instanceof Player) {
sender.sendMessage(plugin.mStart + "Player record not found!");
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/github/ferusgrim/GrimList/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
case "view":
ViewPlayer vp = new ViewPlayer(plugin);
return vp.run(sender, args[1]);
case "getid":
GetUUID gid = new GetUUID(plugin);
return gid.run(sender, args[1]);
case "set":
SetConfig sc = new SetConfig(plugin);
return sc.run(sender, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.List;

import io.github.ferusgrim.GrimList.GrimList;
import io.github.ferusgrim.GrimList.PlayerData;

public class FileManager {
private GrimList plugin;
Expand Down Expand Up @@ -104,6 +103,14 @@ public String getUUID(String name){
return "";
}

public void newPlayerRecord(String uuid, String name){
registerPaths(uuid);
plugin.playerData.get().createSection(path);
plugin.playerData.get().set(isWhitelisted, false);
plugin.playerData.get().set(lastUsername, name);
plugin.playerData.save();
}

public void toggleIsWhitelisted(String uuid, String name){
registerPaths(uuid);
if(alreadyOnWhitelist(uuid)){
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Whitelist: true
Metrics: true
Updater: true
DebugMessages: true
SaveQueries: true
Focus: 'file'
Notify:
Console: false
Expand Down

0 comments on commit ed45767

Please sign in to comment.