Exemple #1
0
 public static OfflinePlayer getChamp(GodType type) {
   OfflinePlayer p = null;
   ResultSet r = null;
   try {
     r =
         (new SQLQuery(
                 (new String(
                     "select champ from £.gods where idGod="
                         + String.valueOf(Utility.getDBNumberFromGodType(type)))),
                 ConfigManager.getMySQLConfig())
             .excecuteQuery());
   } catch (MySQLSyntaxErrorException e1) {
     e1.printStackTrace();
   }
   try {
     while (r.next()) {
       String s = r.getString(1);
       if (s != null) {
         p = Bukkit.getPlayer(r.getString(1));
       }
     }
   } catch (SQLException e) {
     return null;
   }
   return p;
 }
Exemple #2
0
 public static void setChamp(God g, OfflinePlayer p) {
   String s =
       new String(
           "update £.gods set champ="
               + ((p == null) ? "NULL" : "'" + p.getName() + "'")
               + " where idGod="
               + (new Integer(Utility.getDBNumberFromGodType(g.getGodType()))));
   Bukkit.getServer().broadcastMessage(s);
   (new SQLQuery(s, msqlc)).excecuteUpdate();
 }
Exemple #3
0
 public static void saveAltars() {
   Set<Entry<Location, Altar>> sal = AltarManager.getAltars();
   for (Entry<Location, Altar> al : sal) {
     try {
       Altar a = al.getValue();
       if (a.marked()) {
         ResultSet r =
             new SQLQuery("select location from £.altar where id=" + a.getDBId() + ";", msqlc)
                 .excecuteQuery();
         while (r.next()) {
           new SQLQuery("delete from £.altar where id=" + a.getDBId() + ";", msqlc)
               .excecuteUpdate();
           new SQLQuery("delete from £.locations where id=" + r.getInt(1) + ";", msqlc)
               .excecuteUpdate();
         }
       } else {
         int idDB = a.getDBId();
         if (idDB == -1) {
           Location l = a.getLocation();
           new SQLQuery(
                   "insert into £.locations(world,chunkx,chunkz,x,y,z) values('"
                       + l.getWorld().getName()
                       + "',"
                       + l.getChunk().getX()
                       + ","
                       + l.getChunk().getZ()
                       + ","
                       + l.getBlockX()
                       + ","
                       + l.getBlockY()
                       + ","
                       + l.getBlockZ()
                       + ");",
                   msqlc)
               .excecuteUpdate();
           ResultSet r = new SQLQuery("select max(id) from £.locations", msqlc).excecuteQuery();
           while (r.next()) {
             new SQLQuery(
                     "insert into £.altar(god,type,location) values("
                         + Utility.getDBNumberFromGodType(a.getGod().getGodType())
                         + ",'"
                         + a.getType()
                         + "',"
                         + r.getInt(1)
                         + ")",
                     msqlc)
                 .excecuteUpdate();
           }
         }
       }
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
 }
Exemple #4
0
 public static OfflinePlayer getNewChampCandidate(GodType g) {
   try {
     ResultSet r =
         (new SQLQuery(
                 "select follower from £.followers where reputation>999 and god="
                     + Utility.getDBNumberFromGodType(g)
                     + " order by reputation,points,follower limit 1",
                 msqlc))
             .excecuteQuery();
     while (r.next()) {
       return Bukkit.getOfflinePlayer(r.getString(1));
     }
     return null;
   } catch (MySQLSyntaxErrorException e) {
     e.printStackTrace();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return null;
 }
Exemple #5
0
 public static void loadThrones() {
   for (GodType t : GodType.values()) {
     if (GodManager.isActive(t)) {
       String str =
           "select l.x,l.y,l.z,g.hasThrone,l.world from £.thrones g,£.locations l where g.location=l.id and god="
               + Utility.getDBNumberFromGodType(t)
               + ";";
       ResultSet r = null;
       try {
         r = (new SQLQuery(str, msqlc)).excecuteQuery();
       } catch (MySQLSyntaxErrorException e1) {
         e1.printStackTrace();
       }
       try {
         while (r.next()) {
           if (r.getBoolean(4)) {
             Location l =
                 new Location(
                     Bukkit.getServer().getWorld(r.getString(5)),
                     r.getInt(1),
                     r.getInt(2),
                     r.getInt(3));
             GodManager.getGod(t).setThrone((Sign) l.getBlock().getState());
             AltarManager.loadAltar(GodManager.getGod(t), AltarType.THRONE, l, 1, null);
             Sign s = (Sign) l.getBlock().getState();
             if (!s.getLine(1).equalsIgnoreCase(GodManager.getGod(t).getGodName()))
               s.setLine(1, GodManager.getGod(t).getGodName().toUpperCase());
           }
         }
       } catch (IndexOutOfBoundsException e) {
         e.printStackTrace();
       } catch (SQLException e) {
         e.printStackTrace();
       }
     }
   }
 }
Exemple #6
0
 public static ArrayList<Entry<String, Integer>> getTopFollowers(God g) {
   ArrayList<Entry<String, Integer>> list = new ArrayList<>();
   ResultSet r = null;
   try {
     r =
         (new SQLQuery(
                 "select follower,reputation from £.followers f where god="
                     + Utility.getDBNumberFromGodType(g.getGodType())
                     + " order by f.reputation limit 10;",
                 msqlc))
             .excecuteQuery();
   } catch (MySQLSyntaxErrorException e1) {
     e1.printStackTrace();
   }
   try {
     while (r.next()) {
       list.add(
           new AbstractMap.SimpleEntry<String, Integer>(r.getString(1), new Integer(r.getInt(2))));
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return list;
 }
Exemple #7
0
 public static void saveFollower(
     Player p,
     int rep,
     int points,
     God g,
     GregorianCalendar lastPrayed,
     GregorianCalendar lastHealed) {
   String sr = new String("select id from £.followers where follower like '" + p.getName() + "';");
   ResultSet r = null;
   try {
     r = (new SQLQuery(sr, msqlc)).excecuteQuery();
   } catch (MySQLSyntaxErrorException e) {
     e.printStackTrace();
   }
   boolean empty = true;
   try {
     String s;
     while (r.next()) {
       empty = false;
     }
     if (empty) {
       DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
       s =
           new String(
                   "insert into £.followers(follower,reputation,points,god,lastpray,lastheal) values('"
                       + p.getName())
               + "',"
               + rep
               + ","
               + points
               + ","
               + Utility.getDBNumberFromGodType(g.getGodType())
               + ",'"
               + df.format(lastPrayed.getTime())
               + "','"
               + df.format(lastHealed.getTime()).toString()
               + "');";
     } else if (rep == -1) {
       s = new String("delete from £.followers where id=" + r.getInt(1) + ";");
     } else {
       r.first();
       DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
       s =
           new String(
               "update £.followers set lastpray='"
                   + df.format(lastPrayed.getTime())
                   + "', points="
                   + points
                   + ", reputation="
                   + rep
                   + ", god="
                   + Utility.getDBNumberFromGodType(g.getGodType())
                   + ", lastheal='"
                   + df.format(lastHealed.getTime())
                   + "' where id="
                   + r.getInt(1)
                   + ";");
     }
     new SQLQuery(s, msqlc).excecuteUpdate();
   } catch (SQLException e2) {
     e2.printStackTrace();
   }
 }