diff --git a/MnM-Utils b/MnM-Utils index fae8dc3..b93c054 160000 --- a/MnM-Utils +++ b/MnM-Utils @@ -1 +1 @@ -Subproject commit fae8dc32aac424dd8ac1e2f9e35c2d314181ded8 +Subproject commit b93c05446f3694a6ef75b863ecd1e6c581d7fff4 diff --git a/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/TabbyChat.java b/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/TabbyChat.java index 531922e..6c928a3 100644 --- a/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/TabbyChat.java +++ b/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/TabbyChat.java @@ -28,7 +28,6 @@ import mnm.mods.tabbychat.extra.ChatAddonAntiSpam; import mnm.mods.tabbychat.extra.ChatLogging; import mnm.mods.tabbychat.extra.filters.FilterAddon; -import mnm.mods.tabbychat.extra.spell.LangDict; import mnm.mods.tabbychat.extra.spell.Spellcheck; import mnm.mods.tabbychat.gui.settings.GuiSettingsScreen; import mnm.mods.tabbychat.settings.ServerSettings; @@ -127,7 +126,7 @@ protected void init() { addonManager = new TabbyAddonManager(); events = new TabbyEvents(addonManager); - spellcheck = new Spellcheck(LangDict.ENGLISH); + spellcheck = new Spellcheck(); // Set global settings settings = new TabbySettings(); diff --git a/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/extra/spell/Spellcheck.java b/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/extra/spell/Spellcheck.java index 6ea7a42..35a5c94 100644 --- a/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/extra/spell/Spellcheck.java +++ b/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/extra/spell/Spellcheck.java @@ -5,26 +5,40 @@ import java.io.InputStreamReader; import java.io.Reader; import java.util.List; +import java.util.Set; +import com.google.common.collect.Sets; import com.google.common.io.Closeables; import com.swabunga.spell.engine.SpellDictionary; import com.swabunga.spell.engine.SpellDictionaryHashMap; +import com.swabunga.spell.event.SpellCheckEvent; +import com.swabunga.spell.event.SpellCheckListener; import com.swabunga.spell.event.SpellChecker; +import com.swabunga.spell.event.StringWordTokenizer; import mnm.mods.tabbychat.TabbyChat; public class Spellcheck { private SpellChecker spellCheck; + private Set errors = Sets.newHashSet(); - public Spellcheck(LangDict lang) { + public Spellcheck() { InputStream in = null; Reader read = null; try { - in = lang.openStream(); + in = LangDict.ENGLISH.openStream(); read = new InputStreamReader(in); SpellDictionary dictionary = new SpellDictionaryHashMap(read); spellCheck = new SpellChecker(dictionary); + spellCheck.addSpellCheckListener(new SpellCheckListener() { + @Override + public synchronized void spellingError(SpellCheckEvent event) { + errors.add(event.getInvalidWord()); + // System.out.println(event.getWordContextPosition() + " " + + // event.getInvalidWord()); + } + }); } catch (IOException e) { TabbyChat.getLogger().warn("Error whie loading dictionary.", e); } finally { @@ -37,7 +51,13 @@ public List getSuggestions(String word, int threshold) { return this.spellCheck.getSuggestions(word, threshold); } + public void checkSpelling(String string) { + this.errors.clear(); + this.spellCheck.checkSpelling(new StringWordTokenizer(string)); + } + public boolean isCorrect(String word) { - return this.spellCheck.isCorrect(word); + return !errors.contains(word); } + } diff --git a/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/extra/spell/SpellingFormatter.java b/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/extra/spell/SpellingFormatter.java index 477d1a2..a7a50cb 100644 --- a/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/extra/spell/SpellingFormatter.java +++ b/TabbyChat-Common/src/main/java/mnm/mods/tabbychat/extra/spell/SpellingFormatter.java @@ -10,7 +10,7 @@ public class SpellingFormatter implements Function { - private Spellcheck spelling; + private final Spellcheck spelling; public SpellingFormatter(Spellcheck sp) { spelling = sp; @@ -20,15 +20,15 @@ public SpellingFormatter(Spellcheck sp) { public IChatComponent apply(String text) { if (!TabbyChat.getInstance().settings.general.spelling.enabled.getValue()) return new ChatComponentText(text); + spelling.checkSpelling(text); String[] split = text.split(" "); ChatBuilder b = new ChatBuilder(); for (String word : split) { - if (b.size() > 0) - b.text(" "); b.text(word); if (!spelling.isCorrect(word)) { b.underline(Color.RED); } + b.text(" "); } return b.build(); }