001    /**
002     * Jetrix TetriNET Server
003     * Copyright (C) 2004  Emmanuel Bourg
004     *
005     * This program is free software; you can redistribute it and/or
006     * modify it under the terms of the GNU General Public License
007     * as published by the Free Software Foundation; either version 2
008     * of the License, or (at your option) any later version.
009     *
010     * This program is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018     */
019    
020    package net.jetrix.commands;
021    
022    import java.util.*;
023    import java.util.logging.*;
024    
025    import net.jetrix.*;
026    
027    /**
028     * Abstract command.
029     *
030     * @author Emmanuel Bourg
031     * @version $Revision: 794 $, $Date: 2009-02-17 20:08:39 +0100 (Tue, 17 Feb 2009) $
032     * @since 0.2
033     */
034    public abstract class AbstractCommand implements Command
035    {
036        protected int level = AccessLevel.PLAYER;
037        protected boolean hidden;
038    
039        protected static Logger log = Logger.getLogger("net.jetrix");
040    
041        public int getAccessLevel()
042        {
043            return level;
044        }
045    
046        public void setAccessLevel(int level)
047        {
048            this.level = level;
049        }
050    
051        public boolean isHidden()
052        {
053            return hidden;
054        }
055    
056        public void setHidden(boolean hidden)
057        {
058            this.hidden = hidden;
059        }
060    
061        public String getUsage(Locale locale)
062        {
063            return "/" + getAliases()[0];
064        }
065    
066        public String getDescription(Locale locale)
067        {
068            return Language.getText("command." + getAliases()[0] + ".description", locale);
069        }
070    
071        /**
072         * Return the command alias. This is a method to be overriden only
073         * by commands with a unique alias.
074         */
075        protected String getAlias()
076        {
077            return null;
078        }
079    
080        public String[] getAliases()
081        {
082            if (getAlias() != null)
083            {
084                return new String[] { getAlias() };
085            }
086            else
087            {
088                throw new UnsupportedOperationException("No alias defined for " + getClass());
089            }
090        }
091    
092    }