diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/WhisperManager.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/WhisperManager.java')
| -rw-r--r-- | NET/worlds/console/WhisperManager.java | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/NET/worlds/console/WhisperManager.java b/NET/worlds/console/WhisperManager.java new file mode 100644 index 0000000..180fa10 --- /dev/null +++ b/NET/worlds/console/WhisperManager.java @@ -0,0 +1,143 @@ +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<String, WhisperDialog> dialogs_; + private Hashtable<String, TradeDialog> tradeDialogs_; + private java.awt.Window parent; + private String inventory = ""; + final String tradeServerName = "TRADE"; + static GiftDialog outstandingGift; + + private WhisperManager() { + this.dialogs_ = new Hashtable<String, WhisperDialog>(); + this.tradeDialogs_ = new Hashtable<String, TradeDialog>(); + } + + public static WhisperManager whisperManager() { + if (manager_ == null) { + manager_ = new WhisperManager(); + } + + return manager_; + } + + void setParent(java.awt.Window p) { + this.parent = p; + } + + public Hashtable<String, WhisperDialog> dialogs() { + return this.dialogs_; + } + + public Hashtable<String, TradeDialog> 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<TradeDialog> 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); + } + } + } +} |