Exemplo n.º 1
0
 public static String getGroupName(int id) {
   String group = "NONE";
   try {
     final Query query =
         plugin
             .getDatabaseHandler()
             .select("SELECT * FROM " + Table.GROUPS.getName() + " WHERE id='" + id + "';");
     if (query.getResult().next()) {
       group = query.getResult().getString("groupname");
       if (query.getResult().wasNull()) {
         group = "NONE";
       }
     }
     query.closeQuery();
   } catch (SQLException e) {
     if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
       plugin.getLogger().warning("SQL Exception on getting group name for  id '" + id + "'");
     }
     e.printStackTrace();
   }
   if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
     plugin.getLogger().info("getGroupName(" + id + ") == " + group);
   }
   return group;
 }
Exemplo n.º 2
0
 public static int getGroupId(String group) {
   int id = -1;
   try {
     final Query query =
         plugin
             .getDatabaseHandler()
             .select(
                 "SELECT * FROM " + Table.GROUPS.getName() + " WHERE groupname='" + group + "';");
     if (query.getResult().next()) {
       id = query.getResult().getInt("id");
       if (query.getResult().wasNull()) {
         id = -1;
       }
     }
     query.closeQuery();
   } catch (SQLException e) {
     if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
       plugin.getLogger().warning("SQLException on getGroupId(" + group + ")");
     }
     plugin.getLogger().warning("SQL Exception on getting group '" + group + "' id");
     e.printStackTrace();
   }
   if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
     plugin.getLogger().info("getGroupId(" + group + ") == " + id);
   }
   return id;
 }
Exemplo n.º 3
0
 public static boolean validGroup(CommandSender sender, String group) {
   if (group.equals("global")) {
     if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
       plugin.getLogger().info("global group valid for " + sender.getName());
     }
     return true;
   } else if (group.equals("self_" + sender.getName().toLowerCase())) {
     if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
       plugin.getLogger().info("self group valid for " + sender.getName());
     }
     return true;
   }
   boolean valid = false;
   try {
     final Query rs =
         plugin
             .getDatabaseHandler()
             .select(
                 "SELECT * FROM " + Table.GROUPS.getName() + " WHERE groupname='" + group + "';");
     if (rs.getResult().next()) {
       if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
         plugin.getLogger().info(group + " group valid for " + sender.getName());
       }
       valid = true;
     }
     rs.closeQuery();
   } catch (SQLException e) {
     if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
       plugin
           .getLogger()
           .warning("SQLException on validGroup(" + sender.getName() + "," + group + ")");
     }
     sender.sendMessage(ChatColor.RED + KarmicShare.TAG + " SQL Exception");
     e.printStackTrace();
   }
   return valid;
 }
Exemplo n.º 4
0
 public static List<String> getPlayerGroups(CommandSender sender, String name) {
   List<String> list = new ArrayList<String>();
   boolean wasNull = false, initial = false;
   try {
     String groups = "";
     Query rs =
         plugin
             .getDatabaseHandler()
             .select(
                 "SELECT * FROM " + Table.PLAYERS.getName() + " WHERE playername='" + name + "';");
     if (rs.getResult().next()) {
       groups = rs.getResult().getString("groups");
       wasNull = rs.getResult().wasNull();
     }
     rs.closeQuery();
     if (wasNull) {
       initial = true;
     } else if (groups.equals("")) {
       initial = true;
     }
     if (initial) {
       if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
         plugin.getLogger().info("Initial groups for " + name);
       }
       // No groups, add in the global and self
       plugin
           .getDatabaseHandler()
           .standardQuery(
               "INSERT INTO "
                   + Table.GROUPS.getName()
                   + " (groupname) VALUES ('self_"
                   + name.toLowerCase()
                   + "');");
       groups = getGroupId("global") + "&" + getGroupId("self_" + name.toLowerCase());
       // Set groups for future reference
       plugin
           .getDatabaseHandler()
           .standardQuery(
               "UPDATE "
                   + Table.PLAYERS.getName()
                   + " SET groups='"
                   + groups
                   + "' WHERE playername='"
                   + name
                   + "';");
     }
     String[] split = groups.split("&");
     for (String s : split) {
       try {
         if (s != null && !s.equals("")) {
           list.add(getGroupName(Integer.parseInt(s)));
         }
       } catch (NumberFormatException n) {
         if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
           plugin.getLogger().warning("Bad group id '" + s + "'");
         }
         n.printStackTrace();
       }
     }
   } catch (SQLException e) {
     if (RootConfig.getBoolean(ConfigNode.DEBUG_KARMA)) {
       plugin
           .getLogger()
           .warning("SQLException on getPlayerGroups(" + sender.getName() + "," + name + ")");
     }
     sender.sendMessage(ChatColor.RED + KarmicShare.TAG + " SQL Exception");
     e.printStackTrace();
   }
   return list;
 }