0

Fixed wrong data import

This commit is contained in:
Pepich 2017-02-07 20:42:02 +01:00
parent 4d311862b8
commit 92f54bba36

View File

@ -25,7 +25,7 @@ import com.redstoner.misc.Utils;
import com.redstoner.modules.Module; import com.redstoner.modules.Module;
@AutoRegisterListener @AutoRegisterListener
@Version(major = 1, minor = 0, revision = 3, compatible = 1) @Version(major = 1, minor = 0, revision = 5, compatible = 1)
public class Chatalias implements Module, Listener public class Chatalias implements Module, Listener
{ {
// to export chatalias data to json: // to export chatalias data to json:
@ -81,12 +81,14 @@ public class Chatalias implements Module, Listener
aliases.remove(event.getPlayer().getUniqueId().toString()); aliases.remove(event.getPlayer().getUniqueId().toString());
} }
@SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(AsyncPlayerChatEvent event) public void onPlayerChat(AsyncPlayerChatEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
JSONObject playerAliases = (JSONObject) aliases.get(uuid.toString()); JSONObject playerAliases = (JSONObject) aliases.get(uuid.toString());
boolean changed = false;
for (Object key : playerAliases.keySet()) for (Object key : playerAliases.keySet())
{ {
String keyword = (String) key; String keyword = (String) key;
@ -100,6 +102,11 @@ public class Chatalias implements Module, Listener
{ {
if (keyword.startsWith("N: ")) if (keyword.startsWith("N: "))
keyword = keyword.replace("N: ", ""); keyword = keyword.replace("N: ", "");
else
{
changed = true;
playerAliases.put(key, "N: " + keyword);
}
event.setMessage(event.getMessage().replace(keyword, replacement)); event.setMessage(event.getMessage().replace(keyword, replacement));
} }
int maxLength; int maxLength;
@ -118,6 +125,8 @@ public class Chatalias implements Module, Listener
return; return;
} }
} }
if (changed)
saveAliases(uuid);
} }
// @EventHandler // @EventHandler
@ -276,7 +285,14 @@ public class Chatalias implements Module, Listener
{ {
JSONObject temp = new JSONObject(); JSONObject temp = new JSONObject();
temp.put("dataFormat", "v1"); temp.put("dataFormat", "v1");
temp.put("data", playerAliases); JSONObject tempAliases = new JSONObject();
{
for (Object key : playerAliases.keySet())
{
tempAliases.put(key, "N: " + playerAliases.get(key));
}
}
temp.put("data", tempAliases);
aliases.put(uuid.toString(), temp.get("data")); aliases.put(uuid.toString(), temp.get("data"));
} }
else if (dataFormat.equals("v1")) else if (dataFormat.equals("v1"))