/* */ package NET.worlds.console; /* */ /* */ import NET.worlds.core.IniFile; /* */ import NET.worlds.network.Galaxy; /* */ import NET.worlds.network.NetworkObject; /* */ import NET.worlds.network.ObjID; /* */ import NET.worlds.network.WorldServer; /* */ import NET.worlds.scape.Drone; /* */ import NET.worlds.scape.FrameEvent; /* */ import java.awt.Container; /* */ import java.awt.Event; /* */ import java.awt.MenuItem; /* */ import java.awt.Window; /* */ import java.text.MessageFormat; /* */ import java.util.Enumeration; /* */ import java.util.StringTokenizer; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class MuteListPart /* */ implements FramePart, NameListOwner /* */ { /* */ private static final String oldIniItemName = "Mutes"; /* */ private static final String iniItemName = "Mute"; /* */ private static final int maxMutes = 50; /* */ private static final String separator = ";"; /* */ private static MuteListPart active; /* */ private Vector mutes; /* 58 */ private Vector syncMutes = new Vector(); /* */ /* */ /* */ /* */ private MenuItem editItem; /* */ /* */ /* */ private MenuItem disableWhisperItem; /* */ /* */ /* */ private boolean rejectWhispers; /* */ /* */ /* */ private DefaultConsole console; /* */ /* */ /* */ private Galaxy galaxy; /* */ /* */ /* */ private IniFile serverSection; /* */ /* */ /* 80 */ private Object mutesMutex = new Object(); /* */ /* */ /* */ /* 84 */ private Vector updates = new Vector(); /* */ /* */ /* */ /* */ /* */ /* */ private void loadMutes() /* */ { /* 92 */ this.mutes = new Vector(); /* */ /* */ /* 95 */ for (int i = 0; i < 50; i++) { /* 96 */ String name = this.serverSection.getIniString("Mute" + i, ""); /* 97 */ if (name.length() == 0) /* */ break; /* 99 */ if ((FriendsListPart.isValidUserName(name)) && /* 100 */ (!FriendsListPart.icontains(this.mutes, name))) { /* 101 */ this.mutes.addElement(name); /* */ } /* */ } /* 104 */ if (this.mutes.size() == 0) /* */ { /* */ /* */ /* */ /* 109 */ String mutesStr = this.serverSection.getIniString("Mutes", ""); /* 110 */ StringTokenizer tokens = new StringTokenizer(mutesStr, ";"); /* 111 */ while ((tokens.hasMoreTokens()) && (this.mutes.size() < 50)) { /* 112 */ String name = tokens.nextToken(); /* */ /* */ /* 115 */ if ((FriendsListPart.isValidUserName(name)) && /* 116 */ (!FriendsListPart.icontains(this.mutes, name))) /* 117 */ this.mutes.addElement(name); /* */ } /* 119 */ if (this.mutes.size() != 0) { /* 120 */ saveMutes(); /* 121 */ this.serverSection.setIniString("Mutes", ""); /* */ } /* */ } /* */ } /* */ /* */ /* */ /* */ void saveMutes() /* */ { /* 130 */ int count = this.mutes.size(); /* 131 */ for (int i = 0; i < count; i++) /* 132 */ this.serverSection.setIniString("Mute" + i, /* 133 */ (String)this.mutes.elementAt(i)); /* 134 */ this.serverSection.setIniString("Mute" + count, ""); /* */ } /* */ /* */ private void setDisableWhisper() /* */ { /* 139 */ this.rejectWhispers = (IniFile.gamma().getIniInt("RejectWhispers", 0) == 1); /* 140 */ if (this.rejectWhispers) { /* 141 */ this.disableWhisperItem.setLabel(Console.message("Accept-Whispers")); /* */ } else { /* 143 */ this.disableWhisperItem.setLabel(Console.message("Reject-Whispers")); /* */ } /* */ } /* */ /* */ /* */ /* */ public void activate(Console c, Container f, Console prev) /* */ { /* 151 */ active = this; /* */ /* */ /* */ /* 155 */ this.console = ((DefaultConsole)c); /* */ /* */ /* 158 */ this.editItem = c.addMenuItem(Console.message("Edit-Mute-List"), "Options"); /* 159 */ this.editItem.setEnabled(this.mutes != null); /* */ /* */ /* 162 */ this.disableWhisperItem = c.addMenuItem(Console.message("Reject-Whispers"), /* 163 */ "Options"); /* 164 */ setDisableWhisper(); /* */ } /* */ /* */ /* */ public void deactivate() /* */ { /* 170 */ active = null; /* 171 */ this.editItem = null; /* */ } /* */ /* */ /* */ /* */ public boolean action(Event event, Object what) /* */ { /* 178 */ if (event.target == this.editItem) /* */ { /* */ /* */ /* 182 */ new EditNamesDialog(this, Console.message("Edit-Mute-List"), /* 183 */ Console.message("Add-Mute-List")); /* 184 */ return true; } /* 185 */ if (event.target == this.disableWhisperItem) /* */ { /* 187 */ IniFile.gamma().setIniInt("RejectWhispers", this.rejectWhispers ? 0 : 1); /* 188 */ setDisableWhisper(); /* */ } /* */ /* 191 */ return false; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public boolean handle(FrameEvent f) /* */ { /* 200 */ synchronized (this.mutesMutex) { /* 201 */ int count = this.updates.size(); /* 202 */ if (count != 0) { /* 203 */ WorldServer server = this.console.getServerNew(); /* 204 */ if (server != null) { /* 205 */ for (int i = 0; i < count; i++) { /* 206 */ String name = (String)this.updates.elementAt(i); /* 207 */ boolean muted = this.mutes.contains(name); /* */ /* */ /* */ /* 211 */ NetworkObject obj = server.getObject(new ObjID(name)); /* 212 */ if ((obj instanceof Drone)) { /* 213 */ Drone d = (Drone)obj; /* 214 */ d.muteStateChanged(); /* */ } /* */ /* */ /* 218 */ this.console.getFriends().changeMuteState(name, muted); /* */ } /* */ /* */ /* 222 */ this.updates.removeAllElements(); /* */ /* */ /* 225 */ this.syncMutes = ((Vector)this.mutes.clone()); /* */ } /* */ } /* */ } /* 229 */ return true; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void setServer(WorldServer server, IniFile serverSection) /* */ { /* 240 */ this.serverSection = serverSection; /* 241 */ this.galaxy = server.getGalaxy(); /* */ /* */ /* */ /* 245 */ loadMutes(); /* 246 */ if (this.editItem != null) /* 247 */ this.editItem.setEnabled(true); /* */ } /* */ /* */ public static boolean isMuted(WorldServer server, String name) { /* 251 */ if ((server != null) && (name != null)) { /* 252 */ Galaxy g = server.getGalaxy(); /* 253 */ Enumeration consoleList = g.getConsoles(); /* 254 */ while (consoleList.hasMoreElements()) { /* 255 */ Object c = consoleList.nextElement(); /* 256 */ if ((c instanceof DefaultConsole)) { /* 257 */ MuteListPart target = ((DefaultConsole)c).getMutes(); /* 258 */ if (target.mutes != null) /* 259 */ return FriendsListPart.icontains(target.mutes, name); /* */ } /* */ } /* */ } /* 263 */ return false; /* */ } /* */ /* */ public static boolean isRejecting(WorldServer server) { /* 267 */ if (server != null) { /* 268 */ Galaxy g = server.getGalaxy(); /* 269 */ Enumeration consoleList = g.getConsoles(); /* 270 */ while (consoleList.hasMoreElements()) { /* 271 */ Object c = consoleList.nextElement(); /* 272 */ if ((c instanceof DefaultConsole)) { /* 273 */ MuteListPart target = ((DefaultConsole)c).getMutes(); /* 274 */ if (target.rejectWhispers) /* 275 */ return true; /* */ } /* */ } /* */ } /* 279 */ return false; /* */ } /* */ /* */ /* */ /* */ public int getNameListCount() /* */ { /* 286 */ return this.mutes.size(); /* */ } /* */ /* */ public String getNameListName(int index) /* */ { /* 291 */ return (String)this.mutes.elementAt(index); /* */ } /* */ /* */ public void removeNameListName(int index) /* */ { /* 296 */ synchronized (this.mutesMutex) { /* 297 */ String name = (String)this.mutes.elementAt(index); /* 298 */ this.mutes.removeElementAt(index); /* 299 */ saveMutes(); /* */ /* */ /* 302 */ if (!this.updates.contains(name)) { /* 303 */ this.updates.addElement(name); /* */ } /* */ } /* */ } /* */ /* */ /* */ /* */ public boolean mayAddNameListName(Window currentWindow) /* */ { /* 312 */ if (this.mutes.size() < 50) /* 313 */ return true; /* 314 */ Object[] arguments = { new String("50") }; /* 315 */ new OkCancelDialog(currentWindow, null, /* 316 */ Console.message("Too-many-names"), null, Console.message("OK"), /* 317 */ MessageFormat.format(Console.message("You-are-limitedM"), /* 318 */ arguments), true); /* */ /* */ /* 321 */ return false; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public int addNameListName(String name) /* */ { /* 330 */ synchronized (this.mutesMutex) /* */ { /* 332 */ if (name.toLowerCase().startsWith("host")) { /* 333 */ return -1; /* */ } /* */ /* 336 */ int index = FriendsListPart.iindexOf(this.mutes, name); /* 337 */ if (index != -1) { /* 338 */ return index; /* */ } /* */ /* 341 */ this.mutes.addElement(name); /* 342 */ saveMutes(); /* */ /* */ /* 345 */ if (!this.updates.contains(name)) { /* 346 */ this.updates.addElement(name); /* */ } /* 348 */ return this.mutes.size() - 1; /* */ } /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\MuteListPart.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */