package NET.worlds.console; import NET.worlds.network.NetUpdate; import NET.worlds.scape.InventoryManager; import java.util.Enumeration; import java.util.Hashtable; public class WhisperManager { private static WhisperManager manager_; private Hashtable dialogs_; private Hashtable tradeDialogs_; private java.awt.Window parent; private String inventory = ""; final String tradeServerName = "TRADE"; static GiftDialog outstandingGift; private WhisperManager() { this.dialogs_ = new Hashtable(); this.tradeDialogs_ = new Hashtable(); } public static WhisperManager whisperManager() { if (manager_ == null) { manager_ = new WhisperManager(); } return manager_; } void setParent(java.awt.Window p) { this.parent = p; } public Hashtable dialogs() { return this.dialogs_; } public Hashtable tradeDialogs() { return this.tradeDialogs_; } private WhisperDialog findWhisperDialog(String to) { return !this.dialogs_.containsKey(to) ? null : this.dialogs_.get(to); } private TradeDialog findTradeDialog(String to) { return !this.tradeDialogs_.containsKey(to) ? null : this.tradeDialogs_.get(to); } private WhisperDialog start(String to, boolean takeFocus) { WhisperDialog wd = this.findWhisperDialog(to); if (wd == null) { this.dialogs_.put(to, wd = new WhisperDialog(this.parent, to)); } if (takeFocus) { wd.takeFocus(); } wd.ready(); return wd; } public void remove(String name) { this.dialogs_.remove(name); } public void startTo(String to) { WhisperDialog wd = this.start(to, true); } public TradeDialog startToTrade(String to) { TradeDialog wd = this.findTradeDialog(to); if (wd == null) { this.tradeDialogs_.put(to, wd = new TradeDialog(this.parent, to)); } wd.takeFocus(); wd.ready(); wd.setTrading(true); wd.whisperPart.println(Console.message("trade-start")); return wd; } public void printFrom(String from, String msg) { if (!msg.startsWith("&|+")) { WhisperDialog it = this.findWhisperDialog(from); if (msg.equals("&|+trade>cancel") && (it == null || !it.isActive() || !it.isTrading)) { return; } it = this.start(from, false); it.print(msg); } else if (msg.startsWith("&|+gift>") && from.equalsIgnoreCase("TRADE")) { maybeQueryGift(msg.substring(8)); } else if (msg.startsWith("&|+inv>") && from.equalsIgnoreCase("TRADE")) { this.tradeMsg(msg.substring(7)); } else if (msg.startsWith("&|+trade>")) { TradeDialog it = this.findTradeDialog(from); if (msg.equals("&|+trade>cancel") && (it == null || !it.isActive() || !it.isTrading)) { return; } it = this.startToTrade(from); it.print(msg); } } public void tradeMsg(String newInv) { if (!newInv.equals(this.inventory)) { Enumeration e = this.tradeDialogs_.elements(); while (e.hasMoreElements()) { TradeDialog wd = e.nextElement(); wd.doneDeal(); } InventoryManager.getInventoryManager().setInventory(newInv); } } public void printTo(String to, String msg) { if (!to.equals("world") && !to.equals("TRADE")) { if (!msg.startsWith("&|+") || msg.startsWith("&|+trade>")) { WhisperDialog it = this.start(to, false); it.send(msg); } } } public void giftDialogDone() { outstandingGift = null; } public static void maybeQueryGift(String inv) { if (NetUpdate.isInternalVersion()) { Console c = Console.getActive(); if (c != null && outstandingGift == null && !c.isSleeping()) { outstandingGift = new GiftDialog(inv, 3000000); } } } }