diff options
Diffstat (limited to 'NET/worlds/console/EmoteHandler.java')
| -rw-r--r-- | NET/worlds/console/EmoteHandler.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/NET/worlds/console/EmoteHandler.java b/NET/worlds/console/EmoteHandler.java new file mode 100644 index 0000000..96d3ec5 --- /dev/null +++ b/NET/worlds/console/EmoteHandler.java @@ -0,0 +1,78 @@ +package NET.worlds.console; + +import NET.worlds.network.Cache; +import NET.worlds.network.CacheFile; +import NET.worlds.network.NetUpdate; +import NET.worlds.network.URL; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.Hashtable; + +public class EmoteHandler { + private Hashtable<String, String> emoteHash = new Hashtable<String, String>(); + + public EmoteHandler() { + this.Load("EmoteList.txt"); + } + + public EmoteHandler(String filename) { + this.Load(filename); + } + + public void Load(String filename) { + File file = null; + + try { + CacheFile cf = Cache.getFile(URL.make(NetUpdate.getUpgradeServerURL() + filename)); + if (cf != null) { + file = new File(cf.getLocalName()); + cf.waitUntilLoaded(); + } + + if (file != null) { + this.LoadFile(file); + } + } catch (Exception var4) { + } + + file = new File(filename); + if (file != null) { + this.LoadFile(file); + } + } + + private void LoadFile(File file) { + if (file != null && file.exists()) { + try { + BufferedReader reader = new BufferedReader(new FileReader(file)); + String line = ""; + + while ((line = reader.readLine()) != null) { + String[] words = line.split("[ \t]"); + + for (int i = 1; i < words.length; i++) { + this.put(words[i].toLowerCase(), words[0]); + } + } + + reader.close(); + } catch (Exception var6) { + var6.printStackTrace(); + } + } + } + + public void put(String emote, String imagename) { + this.emoteHash.put(emote, imagename); + } + + public String get(String emote) { + return this.emoteHash.get(emote); + } + + public ImageCanvas getImage(String emote) { + String imagename = this.get(emote); + return imagename != null && imagename.length() > 0 ? new ImageCanvas(imagename) : null; + } +} |