⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usercommands.java

📁 piweurrrrq i o fhsadhfka fd dskajc zxkjcnkjsahc
💻 JAVA
字号:
/* * Copyright (c) 2000 Lyrisoft Solutions, Inc. * Used by permission */package com.lyrisoft.chat.client;import java.util.Hashtable;import java.util.StringTokenizer;import java.util.Properties;import java.util.Enumeration;import com.lyrisoft.chat.Translator;import com.lyrisoft.chat.ICommands;import com.lyrisoft.chat.client.command.*;/** * This class processes command typed by the user. * * This class maintains a registry of UserCommandProcessor instances.  When the process * method is called, the appropriate UserCommandProcessor is invoked.  If no processor * is found, then the default (SayToRoom) is invoked. * * * @see com.lyrisoft.chat.client.command.UserCommandProcessor */public class UserCommands {    private Hashtable _processors;    private UserCommandProcessor defaultProcessor = new SayToRoom();    public UserCommands(Properties p) {        _processors = new Hashtable();        for (Enumeration e = p.propertyNames(); e.hasMoreElements(); ) {            String name = (String)e.nextElement();            try {                String className = p.getProperty(name);                UserCommandProcessor cp = (UserCommandProcessor)Class.forName(className).newInstance();                extendCommandSet("/" + name, cp);//                System.err.println("Initiliazed " + name + " user command");            }            catch (Exception ex) {                ex.printStackTrace();                System.err.println("Failed to initialize " + name + " user command");            }        }    }    public void extendCommandSet(String command, UserCommandProcessor p) {        _processors.put(command, p);    }    /**     * Process some user input.  Use the first word in the input string     * to look up the appropriate UserCommandProcessor (the default UserCommandProcessor,     * if none are found, is SayToRoom), and invoke its process() method.     *     * @param input the text that the user typed     * @param arg an argument (may be null).  Typically the room the message was typed in     * @param client the instance of the Client     *     * @see com.lyrisoft.chat.client.command.UserCommandProcessor     * @see com.lyrisoft.chat.client.command     * @see com.lyrisoft.chat.client.command.SayToRoom     */    public void process(String input, String arg, Client client) {        input = input.trim();        if (input.length() == 0) {            return;        }        StringTokenizer st = new StringTokenizer(input, " ");        String key = st.nextToken();        UserCommandProcessor processor = (UserCommandProcessor)_processors.get(key);        try {            if (processor != null) {                processor.process(input, arg, client);            } else {                if (key.charAt(0) != '/') {                    defaultProcessor.process(input, arg, client);                } else {                    client.generalError(Translator.getMessage("no.such.command", key));                }            }        }        catch (NotEnoughArgumentsException e) {            client.generalError(e.getMessage());            client.getServerInterface().help(key);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -