Exemplo n.º 1
0
 public static void loadAltars() {
   ResultSet r = null;
   try {
     r =
         (new SQLQuery(
                 new String(
                     "select a.god,a.type,l.x,l.y,l.z,l.world,a.id,a.owner from £.altar a, £.locations l where a.location=l.id;"),
                 msqlc))
             .excecuteQuery();
   } catch (MySQLSyntaxErrorException e1) {
     e1.printStackTrace();
   }
   try {
     if (r != null) {
       while (r.next()) {
         AltarManager.loadAltar(
             GodManager.getGod(Utility.getGodTypeFromDBNumber(r.getInt(1))),
             AltarType.valueOf(r.getString(2)),
             new Location(
                 Bukkit.getServer().getWorld(r.getString(6)),
                 r.getInt(3),
                 r.getInt(4),
                 r.getInt(5)),
             r.getInt(7),
             Bukkit.getPlayer(r.getString(8)));
       }
     }
   } catch (SQLException e) {
     return;
   }
 }
Exemplo n.º 2
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();
       }
     }
   }
 }
Exemplo n.º 3
0
 public static void loadChamps() {
   for (int i = 1; i <= GodManager.getActiveGods(); i++) {
     GodType t = Utility.getGodTypeFromDBNumber(i);
     ResultSet r = null;
     try {
       r =
           (new SQLQuery(
                   new String("select lastActivated,champ from £.gods where idGod=" + i + ";"),
                   msqlc))
               .excecuteQuery();
     } catch (MySQLSyntaxErrorException e1) {
       e1.printStackTrace();
     }
     try {
       while (r.next()) {
         GregorianCalendar c = null;
         Date d = r.getDate(1);
         if (d != null) {
           c = new GregorianCalendar();
           c.setTime(r.getDate(1));
         }
         God g = GodManager.getGod(t);
         if (g != null) {
           g.setLastActivated(c);
           String s = r.getString(2);
           if (s != null) {
             OfflinePlayer p = Bukkit.getOfflinePlayer(r.getString(2));
             g.setChamp(p);
           }
         }
       }
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
 }
Exemplo n.º 4
0
 public static FollowerData getFollower(OfflinePlayer p) {
   try {
     String sq =
         "select reputation,god,lastpray,lastheal,points from £.followers where follower like '"
             + p.getName()
             + "';";
     ResultSet r = (new SQLQuery(new String(sq), msqlc)).excecuteQuery();
     boolean empty = true;
     while (r.next()) {
       empty = false;
       break;
     }
     if (!empty) {
       r.first();
       GregorianCalendar c = new GregorianCalendar();
       Date c2 = r.getDate(3), d2 = r.getDate(4);
       if (c2 == null) c = null;
       else c.setTimeInMillis(c2.getTime());
       GregorianCalendar d = new GregorianCalendar();
       if (d2 == null) d = null;
       else d.setTimeInMillis(d2.getTime());
       return new FollowerData(
           r.getInt(1),
           r.getInt(5),
           GodManager.getGod(Utility.getGodTypeFromDBNumber(r.getInt(2))),
           c,
           d,
           true);
     }
   } catch (SQLException ex) {
     if (p.isOnline())
       p.getPlayer()
           .sendMessage(Utility.formattedMessage(Utility.getMessage("msg.followers.loadfail")));
   }
   return null;
 }
Exemplo n.º 5
0
  public static void saveThrones() {
    for (int i = 1; i < 5; i++) {
      God g = GodManager.getGod(Utility.getGodTypeFromDBNumber(i));
      if (g != null) {
        if (g.hasThrone()) {
          if (AltarManager.getAltar(g.getThrone()).getDBId() == 0) {
            Location l = g.getThrone().getLocation();
            String s =
                "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()
                    + ")";
            (new SQLQuery(s, msqlc)).excecuteUpdate();
            ResultSet r = null;
            try {
              r = (new SQLQuery("select max(id) from £.locations", msqlc)).excecuteQuery();
            } catch (MySQLSyntaxErrorException e1) {
              e1.printStackTrace();
            }
            try {
              r.first();
              s =
                  "update £.thrones set hasThrone=true, location="
                      + r.getInt(1)
                      + " where god="
                      + i;
              (new SQLQuery(s, msqlc)).excecuteUpdate();
            } catch (SQLException e) {
              e.printStackTrace();
            }
          }
        } else {
          Bukkit.getConsoleSender().sendMessage("2");

          String s = "select location from £.thrones where god=" + i + ";";
          ResultSet r = null;
          try {
            r = (new SQLQuery(s, msqlc)).excecuteQuery();
          } catch (MySQLSyntaxErrorException e1) {
            e1.printStackTrace();
          }
          s = "update £.thrones set hasThrone=false, location=NULL where god=" + i + ";";
          (new SQLQuery(s, msqlc)).excecuteUpdate();
          try {
            while (r.next()) {
              s = "delete from £.locations where id=" + r.getInt(1) + ";";
              (new SQLQuery(s, msqlc)).excecuteUpdate();
            }
          } catch (SQLException e) {
            e.printStackTrace();
          }
        }
        GregorianCalendar gc = g.getLastActivated();
        if (gc != null) {
          DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
          String s =
              "update £.gods set lastActivated='"
                  + df.format(gc.getTime())
                  + "' where idGod="
                  + i
                  + ";";
          (new SQLQuery(s, msqlc)).excecuteUpdate();
        }
      }
    }
  }