From dea069ca52c79e652448a7a5f6e3f6b7fafe110f Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Mon, 27 Oct 2014 22:00:24 +0100 Subject: [PATCH] Ability to disable the usage of the custom UUID API --- .../intellectualcrafters/plot/PlotMain.java | 2 + .../intellectualcrafters/plot/Settings.java | 1 + .../plot/UUIDHandler.java | 53 +++++++++++++++---- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index bbb652595..61403c8d7 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -940,6 +940,7 @@ public class PlotMain extends JavaPlugin { Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days"); Settings.DELETE_PLOTS_ON_BAN = config.getBoolean("clear.on.ban"); Settings.API_URL = config.getString("api.location"); + Settings.CUSTOM_API = config.getBoolean("api.custom"); } if (Settings.DEBUG) { Map settings = new HashMap<>(); @@ -1087,6 +1088,7 @@ public class PlotMain extends JavaPlugin { options.put("max_plots", Settings.MAX_PLOTS); options.put("schematics.save_path", Settings.SCHEMATIC_SAVE_PATH); options.put("api.location", Settings.API_URL); + options.put("api.custom", Settings.CUSTOM_API); for (Entry node : options.entrySet()) { if (!config.contains(node.getKey())) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Settings.java b/PlotSquared/src/com/intellectualcrafters/plot/Settings.java index 09e9dfe1e..9419bca51 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Settings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Settings.java @@ -61,6 +61,7 @@ public class Settings { public static boolean AUTO_CLEAR = false; public static int AUTO_CLEAR_DAYS = 365; public static String API_URL = "http://www.intellectualsites.com/minecraft.php"; + public static boolean CUSTOM_API = true; public static class Update { /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java index aa7ae3741..b6a1cc280 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/UUIDHandler.java @@ -73,19 +73,29 @@ public class UUIDHandler { } UUID uuid; if (online) { - if ((uuid = getUuidOnlinePlayer(nameWrap)) != null) { - return uuid; - } - try { - return PlotMain.getUUIDSaver().mojangUUID(name); - } - catch(Exception e) { + if(Settings.CUSTOM_API) { + if ((uuid = getUuidOnlinePlayer(nameWrap)) != null) { + return uuid; + } + try { + return PlotMain.getUUIDSaver().mojangUUID(name); + } + catch(Exception e) { + try { + UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); + uuid = fetcher.call().get(name); + add(nameWrap, uuid); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + } else { try { UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); uuid = fetcher.call().get(name); add(nameWrap, uuid); - } - catch (Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); } } @@ -120,6 +130,29 @@ public class UUIDHandler { return name; } if (online) { + if(!Settings.CUSTOM_API) { + try { + NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); + name = fetcher.call().get(uuid); + add(new StringWrapper(name), uuid); + return name; + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + try { + return PlotMain.getUUIDSaver().mojangName(uuid); + } catch(Exception e) { + try { + NameFetcher fetcher = new NameFetcher(Arrays.asList(uuid)); + name = fetcher.call().get(uuid); + add(new StringWrapper(name), uuid); + return name; + } catch (Exception ex) { + e.printStackTrace(); + } + } + } try { return PlotMain.getUUIDSaver().mojangName(uuid); } catch(Exception e) { @@ -129,7 +162,7 @@ public class UUIDHandler { add(new StringWrapper(name), uuid); return name; } catch (Exception ex) { - e.printStackTrace(); + ex.printStackTrace(); } } }