falyptus

Faith - Fast Command

Jun 9th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. /**
  2. * @author Keal
  3. * La classe suivante ainsi que les méthodes getCommand()/isCommand()/addCommand() vont dans World.java
  4. */
  5. public static class FastCmd
  6. {
  7.     private String name;
  8.     private int actionId;
  9.     private String args;
  10.    
  11.     public FastCmd(String name, int actionId, String args)
  12.     {
  13.         this.name = name;
  14.         this.actionId = actionId;
  15.         this.args = args;
  16.     }
  17.  
  18.     public String getName() {
  19.             return name;
  20.         }
  21.  
  22.     public int getActionId() {
  23.             return actionId;
  24.         }
  25.    
  26.     public String getArgs() {
  27.             return args;
  28.         }
  29. }
  30.    
  31. public static FastCmd getCommand(String name)
  32. {
  33.     for(Entry<String, FastCmd> curCmd : Commands.entrySet())
  34.     {
  35.         if(curCmd.getKey() == name)
  36.         {
  37.             return curCmd.getValue();
  38.         }
  39.     }
  40.     return null;
  41. }
  42.    
  43. public static boolean isCommand(String name)
  44. {
  45.     return Commands.containsKey(name);
  46. }
  47.  
  48. public static void addFastCmd(FastCmd fastCmd)
  49. {
  50.     Commands.put(fastCmd.getName(), fastCmd);
  51. }
  52.  
  53. //Dans SQLManager.java
  54.  
  55. public static void LOAD_FAST_COMMANDS()
  56. {
  57.     try {
  58.         ResultSet RS = SQLManager.executeQuery("SELECT * from commands;", Faith.STATIC_DB_NAME);
  59.         while (RS.next())
  60.         {
  61.             World.addFastCmd(new World.FastCmd(
  62.                     RS.getString("commandName"),
  63.                     RS.getInt("actionId"),
  64.                     RS.getString("args")
  65.             ));
  66.         }
  67.         closeResultSet(RS);
  68.     } catch (SQLException e) {
  69.         System.out.println("Game: SQL ERROR: " + e.getMessage());
  70.         System.exit(1);
  71.     }
  72. }
  73.  
  74. //Dans GameThread.java dans la méthode Basic_chatMessage après if (msg.charAt(0) == '.') {
  75.  
  76. if(World.isCommand(msg))
  77. {
  78.     FastCmd cmd = World.getCommand(msg);
  79.     new Action(cmd.getActionId(), cmd.getArgs(), "").apply(_perso, null, 0, -1);
  80.     return;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment