From 887957756e1726ed0d544bbb41fec1bfd92164d2 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 19 Apr 2014 02:03:39 +0100 Subject: [PATCH] [Breaking] Fix ECO NPC's. This is a work around of CB's recent changes blocking invalid uuid lookups. NPC's converted with the previous version will need manual changes. --- .../earth2me/essentials/EssentialsUpgrade.java | 16 ++++++++-------- .../src/com/earth2me/essentials/api/Economy.java | 7 ++++++- .../test/com/earth2me/essentials/FakeServer.java | 4 ++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index d14cdd676..1e003df21 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.craftbukkit.FakeWorld; import com.earth2me.essentials.settings.Spawns; import com.earth2me.essentials.storage.YamlStorageWriter; import com.earth2me.essentials.utils.StringUtil; +import com.google.common.base.Charsets; import java.io.*; import java.math.BigInteger; import java.security.DigestInputStream; @@ -567,6 +568,12 @@ public class EssentialsUpgrade } catch (Exception ex2) { + if (conf.getBoolean("npc", false)) + { + uuid = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8)); + break; + } + org.bukkit.OfflinePlayer player = ess.getServer().getOfflinePlayer(name); uuid = player.getUniqueId(); } @@ -575,16 +582,9 @@ public class EssentialsUpgrade { countBukkit++; break; - } - - if (uuid == null && conf.getBoolean("npc", false)) - { - uuid = UUID.randomUUID(); - break; - } + } } - if (uuid != null) { conf.forceSave(); diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java index edfb78731..f0c46f860 100644 --- a/Essentials/src/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/com/earth2me/essentials/api/Economy.java @@ -16,9 +16,11 @@ import static com.earth2me.essentials.api.Economy.setMoney; import static com.earth2me.essentials.api.Economy.substract; import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.StringUtil; +import com.google.common.base.Charsets; import java.io.File; import java.math.BigDecimal; import java.math.MathContext; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; import net.ess3.api.IEssentials; @@ -53,11 +55,14 @@ public class Economy { folder.mkdirs(); } - EssentialsUserConf npcConfig = new EssentialsUserConf(name, null, new File(folder, name + ".yml")); + UUID npcUUID = UUID.nameUUIDFromBytes(("NPC:" + name).getBytes(Charsets.UTF_8)); + EssentialsUserConf npcConfig = new EssentialsUserConf(name, npcUUID, new File(folder, npcUUID.toString() + ".yml")); npcConfig.load(); npcConfig.setProperty("npc", true); + npcConfig.setProperty("lastAccountName", name); npcConfig.setProperty("money", ess.getSettings().getStartingBalance()); npcConfig.forceSave(); + ess.getUserMap().trackUUID(npcUUID, name); } private static void deleteNPC(String name) diff --git a/Essentials/test/com/earth2me/essentials/FakeServer.java b/Essentials/test/com/earth2me/essentials/FakeServer.java index 55313d60c..b6a4b5b4a 100644 --- a/Essentials/test/com/earth2me/essentials/FakeServer.java +++ b/Essentials/test/com/earth2me/essentials/FakeServer.java @@ -1244,6 +1244,10 @@ public class FakeServer implements Server { return createOPlayer("testPlayer1"); } + if (arg0.toString().equalsIgnoreCase("f4a37409-5c40-3b2c-9cd6-57d3c5abdc76")) + { + return createOPlayer("npc1"); + } throw new UnsupportedOperationException("Not supported yet."); } }