Ejemplo n.º 1
0
 public List<Zone> getWorld(String world) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   List<Zone> zones = new ArrayList<Zone>();
   try {
     conn = getConnection();
     st = conn.prepareStatement(SELECT_ZONES);
     st.setString(1, world);
     rs = st.executeQuery();
     Zone z = null;
     while (rs.next()) {
       if (z == null || z.getId() != rs.getInt("id")) {
         if (z != null) {
           zones.add(z);
         }
         z = new Zone();
         z.setId(rs.getInt("id"));
         z.setName(rs.getString("name"));
         z.setZonetype(rs.getString("zonetype"));
         z.setFormtype(rs.getString("formtype"));
         z.setWorld(rs.getString("world"));
         z.setAdmins(rs.getString("admins"));
         z.setUsers(rs.getString("users"));
         z.setSettings(rs.getString("settings"));
         z.setMinY(rs.getInt("minz"));
         z.setMaxY(rs.getInt("maxz"));
         z.setSize(rs.getInt("size"));
         z.setConfig(rs.getString("config"));
       }
       z.addVertice(Vertice.from(z, rs));
     }
     if (z != null) {
       zones.add(z);
     }
   } catch (Exception e) {
     Zones.log.warning("[Zones]Error loading zones of world " + world + ":");
     e.printStackTrace();
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   return zones;
 }
Ejemplo n.º 2
0
 public boolean save(Zone zone) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   try {
     conn = getConnection();
     st = conn.prepareStatement(SAVE_ZONE, Statement.RETURN_GENERATED_KEYS);
     st.setString(1, zone.getName());
     st.setString(2, zone.getZonetype());
     st.setString(3, zone.getFormtype());
     st.setString(4, zone.getWorld());
     st.setString(5, zone.getAdmins());
     st.setString(6, zone.getUsers());
     st.setString(7, zone.getSettings());
     st.setInt(8, zone.getMiny());
     st.setInt(9, zone.getMaxy());
     st.setInt(10, zone.getSize());
     st.setString(11, zone.getConfig().toString());
     st.execute();
     rs = st.getGeneratedKeys();
     if (rs.next()) {
       zone.setId(rs.getInt(1));
     }
   } catch (Exception e) {
     Zones.log.warning("[Zones]Error deleting " + zone.getName() + "[" + zone.getId() + "] :");
     e.printStackTrace();
     return false;
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   if (zone.getId() == 0) return false;
   for (Vertice vertice : zone.getVertices()) {
     vertice.setId(zone.getId());
     save(vertice);
   }
   return true;
 }
Ejemplo n.º 3
0
 public Zone get(int id) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   try {
     conn = getConnection();
     st = conn.prepareStatement(SELECT_ZONE);
     st.setInt(1, id);
     rs = st.executeQuery();
     if (rs.next()) {
       Zone z = new Zone();
       z.setId(rs.getInt(1));
       z.setName(rs.getString("name"));
       z.setZonetype(rs.getString("zonetype"));
       z.setFormtype(rs.getString("formtype"));
       z.setWorld(rs.getString("world"));
       z.setAdmins(rs.getString("admins"));
       z.setUsers(rs.getString("users"));
       z.setSettings(rs.getString("settings"));
       z.setMinY(rs.getInt("minz"));
       z.setMaxY(rs.getInt("maxz"));
       z.setSize(rs.getInt("size"));
       z.setConfig(rs.getString("config"));
       z.setVertices(get(z));
       return z;
     }
   } catch (Exception e) {
     Zones.log.warning("[Zones]Error getting zone with id " + id + ":");
     e.printStackTrace();
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   return null;
 }