View Javadoc

1   /***
2    * Jetrix TetriNET Server
3    * Copyright (C) 2004  Emmanuel Bourg
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  
20  package net.jetrix.commands;
21  
22  import java.util.*;
23  import java.util.logging.*;
24  
25  import net.jetrix.*;
26  
27  /***
28   * Abstract command.
29   *
30   * @author Emmanuel Bourg
31   * @version $Revision: 794 $, $Date: 2009-02-17 20:08:39 +0100 (Tue, 17 Feb 2009) $
32   * @since 0.2
33   */
34  public abstract class AbstractCommand implements Command
35  {
36      protected int level = AccessLevel.PLAYER;
37      protected boolean hidden;
38  
39      protected static Logger log = Logger.getLogger("net.jetrix");
40  
41      public int getAccessLevel()
42      {
43          return level;
44      }
45  
46      public void setAccessLevel(int level)
47      {
48          this.level = level;
49      }
50  
51      public boolean isHidden()
52      {
53          return hidden;
54      }
55  
56      public void setHidden(boolean hidden)
57      {
58          this.hidden = hidden;
59      }
60  
61      public String getUsage(Locale locale)
62      {
63          return "/" + getAliases()[0];
64      }
65  
66      public String getDescription(Locale locale)
67      {
68          return Language.getText("command." + getAliases()[0] + ".description", locale);
69      }
70  
71      /***
72       * Return the command alias. This is a method to be overriden only
73       * by commands with a unique alias.
74       */
75      protected String getAlias()
76      {
77          return null;
78      }
79  
80      public String[] getAliases()
81      {
82          if (getAlias() != null)
83          {
84              return new String[] { getAlias() };
85          }
86          else
87          {
88              throw new UnsupportedOperationException("No alias defined for " + getClass());
89          }
90      }
91  
92  }