001    import java.sql.Connection;
002    import java.sql.PreparedStatement;
003    import java.sql.ResultSet;
004    import java.sql.SQLException;
005    import java.sql.Statement;
006    import java.util.ArrayList;
007    import java.util.HashMap;
008    import java.util.logging.Level;
009    
010    /**
011     * MySQLSource.java - Used for accessing users and such from a mysql database
012     * 
013     * @author James
014     */
015    public class MySQLSource extends DataSource {
016    
017        private String table_groups, table_users, table_items, table_kits, table_warps, table_homes, table_reservelist, table_whitelist, table_bans;
018    
019        public void initialize() {
020            PropertiesFile properties = new PropertiesFile("mysql.properties");
021            table_groups = properties.getString("groups", "groups");
022            table_users = properties.getString("users", "users");
023            table_items = properties.getString("items", "items");
024            table_kits = properties.getString("kits", "kits");
025            table_warps = properties.getString("warps", "warps");
026            table_homes = properties.getString("homes", "homes");
027            table_reservelist = properties.getString("reservelist", "reservelist");
028            table_whitelist = properties.getString("whitelist", "whitelist");
029            table_bans = properties.getString("bans", "bans");
030            loadGroups();
031            loadKits();
032            loadHomes();
033            loadWarps();
034            loadItems();
035            // loadBanList();
036        }
037    
038        public void loadGroups() {
039            synchronized (groupLock) {
040                Connection conn = null;
041                PreparedStatement ps = null;
042                ResultSet rs = null;
043                try {
044                    conn = etc.getSQLConnection();
045                    groups = new ArrayList<Group>();
046                    ps = conn.prepareStatement("SELECT * FROM " + table_groups);
047                    rs = ps.executeQuery();
048                    while (rs.next()) {
049                        Group group = new Group();
050                        group.Administrator = rs.getBoolean("admin");
051                        group.CanModifyWorld = rs.getBoolean("canmodifyworld");
052                        group.Commands = rs.getString("commands").split(",");
053                        group.DefaultGroup = rs.getBoolean("defaultgroup");
054                        group.ID = rs.getInt("id");
055                        group.IgnoreRestrictions = rs.getBoolean("ignoresrestrictions");
056                        group.InheritedGroups = rs.getString("inheritedgroups").split(",");
057                        group.Name = rs.getString("name");
058                        group.Prefix = rs.getString("prefix");
059                        if (group.InheritedGroups.length == 1) {
060                            if (group.InheritedGroups[0].equalsIgnoreCase(group.Name)) {
061                                group.InheritedGroups = new String[]{""};
062                            }
063                        }
064                        groups.add(group);
065                    }
066                } catch (SQLException ex) {
067                    log.log(Level.SEVERE, "Unable to retreive groups from group table", ex);
068                } finally {
069                    try {
070                        if (ps != null) {
071                            ps.close();
072                        }
073                        if (rs != null) {
074                            rs.close();
075                        }
076                        if (conn != null) {
077                            conn.close();
078                        }
079                    } catch (SQLException ex) {
080                    }
081                }
082            }
083        }
084    
085        public void loadKits() {
086            synchronized (kitLock) {
087                Connection conn = null;
088                PreparedStatement ps = null;
089                ResultSet rs = null;
090                try {
091                    conn = etc.getSQLConnection();
092                    kits = new ArrayList<Kit>();
093                    ps = conn.prepareStatement("SELECT * FROM " + table_kits);
094                    rs = ps.executeQuery();
095                    while (rs.next()) {
096                        Kit kit = new Kit();
097                        kit.Delay = rs.getInt("delay");
098                        kit.Group = rs.getString("group");
099                        kit.ID = rs.getInt("id");
100                        kit.Name = rs.getString("name");
101                        kit.IDs = new HashMap<String, Integer>();
102    
103                        String[] ids = rs.getString("items").split(",");
104                        for (String str : ids) {
105                            String id = "";
106                            int amount = 1;
107                            if (str.contains(" ")) {
108                                id = str.split(" ")[0];
109                                amount = Integer.parseInt(str.split(" ")[1]);
110                            } else {
111                                id = str;
112                            }
113                            kit.IDs.put(id, amount);
114                        }
115                        kits.add(kit);
116                    }
117                } catch (SQLException ex) {
118                    log.log(Level.SEVERE, "Unable to retreive kits from kit table", ex);
119                } finally {
120                    try {
121                        if (ps != null) {
122                            ps.close();
123                        }
124                        if (rs != null) {
125                            rs.close();
126                        }
127                        if (conn != null) {
128                            conn.close();
129                        }
130                    } catch (SQLException ex) {
131                    }
132                }
133            }
134        }
135    
136        public void loadHomes() {
137            synchronized (homeLock) {
138                if (!etc.getInstance().canSaveHomes()) {
139                    return;
140                }
141                Connection conn = null;
142                PreparedStatement ps = null;
143                ResultSet rs = null;
144                try {
145                    conn = etc.getSQLConnection();
146                    homes = new ArrayList<Warp>();
147                    ps = conn.prepareStatement("SELECT * FROM " + table_homes);
148                    rs = ps.executeQuery();
149                    while (rs.next()) {
150                        Location location = new Location();
151                        location.x = rs.getDouble("x");
152                        location.y = rs.getDouble("y");
153                        location.z = rs.getDouble("z");
154                        location.rotX = rs.getFloat("rotX");
155                        location.rotY = rs.getFloat("rotY");
156                        Warp home = new Warp();
157                        home.ID = rs.getInt("id");
158                        home.Location = location;
159                        home.Name = rs.getString("name");
160                        home.Group = rs.getString("group");
161                        homes.add(home);
162                    }
163                } catch (SQLException ex) {
164                    log.log(Level.SEVERE, "Unable to retreive homes from home table", ex);
165                } finally {
166                    try {
167                        if (ps != null) {
168                            ps.close();
169                        }
170                        if (rs != null) {
171                            rs.close();
172                        }
173                        if (conn != null) {
174                            conn.close();
175                        }
176                    } catch (SQLException ex) {
177                    }
178                }
179            }
180        }
181    
182        public void loadWarps() {
183            synchronized (warpLock) {
184                Connection conn = null;
185                PreparedStatement ps = null;
186                ResultSet rs = null;
187                try {
188                    conn = etc.getSQLConnection();
189                    warps = new ArrayList<Warp>();
190                    ps = conn.prepareStatement("SELECT * FROM " + table_warps);
191                    rs = ps.executeQuery();
192                    while (rs.next()) {
193                        Location location = new Location();
194                        location.x = rs.getDouble("x");
195                        location.y = rs.getDouble("y");
196                        location.z = rs.getDouble("z");
197                        location.rotX = rs.getFloat("rotX");
198                        location.rotY = rs.getFloat("rotY");
199                        Warp warp = new Warp();
200                        warp.ID = rs.getInt("id");
201                        warp.Location = location;
202                        warp.Name = rs.getString("name");
203                        warp.Group = rs.getString("group");
204                        warps.add(warp);
205                    }
206                } catch (SQLException ex) {
207                    log.log(Level.SEVERE, "Unable to retreive warps from warp table", ex);
208                } finally {
209                    try {
210                        if (ps != null) {
211                            ps.close();
212                        }
213                        if (rs != null) {
214                            rs.close();
215                        }
216                        if (conn != null) {
217                            conn.close();
218                        }
219                    } catch (SQLException ex) {
220                    }
221                }
222            }
223        }
224    
225        public void loadItems() {
226            synchronized (itemLock) {
227                Connection conn = null;
228                PreparedStatement ps = null;
229                ResultSet rs = null;
230                try {
231                    conn = etc.getSQLConnection();
232                    items = new HashMap<String, Integer>();
233                    ps = conn.prepareStatement("SELECT * FROM " + table_items);
234                    rs = ps.executeQuery();
235                    while (rs.next()) {
236                        items.put(rs.getString("name"), rs.getInt("itemid"));
237                    }
238                } catch (SQLException ex) {
239                    log.log(Level.SEVERE, "Unable to retreive items from item table", ex);
240                } finally {
241                    try {
242                        if (ps != null) {
243                            ps.close();
244                        }
245                        if (rs != null) {
246                            rs.close();
247                        }
248                        if (conn != null) {
249                            conn.close();
250                        }
251                    } catch (SQLException ex) {
252                    }
253                }
254            }
255        }
256    
257        // Users
258        public void addPlayer(Player player) {
259            Connection conn = null;
260            PreparedStatement ps = null;
261            ResultSet rs = null;
262            try {
263                conn = etc.getSQLConnection();
264                ps = conn.prepareStatement("INSERT INTO " + table_users + " (name, groups, prefix, commands, admin, canmodifyworld, ignoresrestrictions) VALUES (?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS);
265                ps.setString(1, player.getName());
266                ps.setString(2, etc.combineSplit(0, player.getGroups(), ","));
267                ps.setString(3, player.getPrefix());
268                ps.setString(4, etc.combineSplit(0, player.getCommands(), ","));
269                ps.setBoolean(5, player.getAdmin());
270                ps.setBoolean(6, player.canModifyWorld());
271                ps.setBoolean(7, player.ignoreRestrictions());
272                ps.executeUpdate();
273    
274                rs = ps.getGeneratedKeys();
275                if (rs.next()) {
276                    player.setSqlId(rs.getInt(1));
277                }
278            } catch (SQLException ex) {
279                log.log(Level.SEVERE, "Unable to insert user into users table", ex);
280            } finally {
281                try {
282                    if (ps != null) {
283                        ps.close();
284                    }
285                    if (rs != null) {
286                        rs.close();
287                    }
288                    if (conn != null) {
289                        conn.close();
290                    }
291                } catch (SQLException ex) {
292                }
293            }
294        }
295    
296        public void modifyPlayer(Player player) {
297            Connection conn = null;
298            PreparedStatement ps = null;
299            try {
300                conn = etc.getSQLConnection();
301                ps = conn.prepareStatement("UPDATE " + table_users + " SET groups = ?, prefix = ?, commands = ?, admin = ?, canmodifyworld = ?, ignoresrestrictions = ? WHERE id = ?");
302                ps.setString(1, etc.combineSplit(0, player.getGroups(), ","));
303                ps.setString(2, player.getPrefix());
304                ps.setString(3, etc.combineSplit(0, player.getCommands(), ","));
305                ps.setBoolean(4, player.getAdmin());
306                ps.setBoolean(5, player.canModifyWorld());
307                ps.setBoolean(6, player.ignoreRestrictions());
308                ps.setInt(7, player.getSqlId());
309                ps.executeUpdate();
310            } catch (SQLException ex) {
311                log.log(Level.SEVERE, "Unable to update user in users table", ex);
312            } finally {
313                try {
314                    if (ps != null) {
315                        ps.close();
316                    }
317                    if (conn != null) {
318                        conn.close();
319                    }
320                } catch (SQLException ex) {
321                }
322            }
323        }
324    
325        public boolean doesPlayerExist(String player) {
326            boolean exists = false;
327            Connection conn = null;
328            PreparedStatement ps = null;
329            ResultSet rs = null;
330            try {
331                conn = etc.getSQLConnection();
332                ps = conn.prepareStatement("SELECT * FROM " + table_users + " WHERE name = ?");
333                ps.setString(1, player);
334                rs = ps.executeQuery();
335                if (rs.next()) {
336                    exists = true;
337                }
338            } catch (SQLException ex) {
339                log.log(Level.SEVERE, "Unable to check if user exists", ex);
340            } finally {
341                try {
342                    if (ps != null) {
343                        ps.close();
344                    }
345                    if (rs != null) {
346                        rs.close();
347                    }
348                    if (conn != null) {
349                        conn.close();
350                    }
351                } catch (SQLException ex) {
352                }
353            }
354            return exists;
355        }
356    
357        // Groups
358        public void addGroup(Group group) {
359            throw new UnsupportedOperationException("Not supported yet.");
360        }
361    
362        public void modifyGroup(Group group) {
363            throw new UnsupportedOperationException("Not supported yet.");
364        }
365    
366        // Kits
367        public void addKit(Kit kit) {
368            throw new UnsupportedOperationException("Not supported yet.");
369        }
370    
371        public void modifyKit(Kit kit) {
372            throw new UnsupportedOperationException("Not supported yet.");
373        }
374    
375        // Homes
376        public void addHome(Warp home) {
377            Connection conn = null;
378            PreparedStatement ps = null;
379            ResultSet rs = null;
380            try {
381                conn = etc.getSQLConnection();
382                ps = conn.prepareStatement("INSERT INTO " + table_homes + " (name, x, y, z, rotX, rotY, `group`) VALUES(?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
383                ps.setString(1, home.Name);
384                ps.setDouble(2, home.Location.x);
385                ps.setDouble(3, home.Location.y);
386                ps.setDouble(4, home.Location.z);
387                ps.setFloat(5, home.Location.rotX);
388                ps.setFloat(6, home.Location.rotY);
389                ps.setString(7, home.Group);
390                ps.executeUpdate();
391    
392                rs = ps.getGeneratedKeys();
393                if (rs.next()) {
394                    home.ID = rs.getInt(1);
395                    synchronized (homeLock) {
396                        homes.add(home);
397                    }
398                }
399            } catch (SQLException ex) {
400                log.log(Level.SEVERE, "Unable to insert home into homes table", ex);
401            } finally {
402                try {
403                    if (ps != null) {
404                        ps.close();
405                    }
406                    if (rs != null) {
407                        rs.close();
408                    }
409                    if (conn != null) {
410                        conn.close();
411                    }
412                } catch (SQLException ex) {
413                }
414            }
415        }
416    
417        public void changeHome(Warp home) {
418            Connection conn = null;
419            PreparedStatement ps = null;
420            try {
421                conn = etc.getSQLConnection();
422                ps = conn.prepareStatement("UPDATE " + table_homes + " SET x = ?, y = ?, z = ?, rotX = ?, rotY = ?, `group` = ? WHERE name = ?");
423                ps.setDouble(1, home.Location.x);
424                ps.setDouble(2, home.Location.y);
425                ps.setDouble(3, home.Location.z);
426                ps.setFloat(4, home.Location.rotX);
427                ps.setFloat(5, home.Location.rotY);
428                ps.setString(6, home.Group);
429                ps.setString(7, home.Name);
430                ps.executeUpdate();
431    
432                synchronized (homeLock) {
433                    Warp toRem = null;
434                    for (Warp h : homes) {
435                        if (h.Name.equalsIgnoreCase(home.Name)) {
436                            toRem = h;
437                        }
438                    }
439                    if (toRem != null) {
440                        homes.remove(toRem);
441                    }
442                    homes.add(home);
443                }
444            } catch (SQLException ex) {
445                log.log(Level.SEVERE, "Unable to update home in homes table", ex);
446            } finally {
447                try {
448                    if (ps != null) {
449                        ps.close();
450                    }
451                    if (conn != null) {
452                        conn.close();
453                    }
454                } catch (SQLException ex) {
455                }
456            }
457        }
458    
459        // Warps
460        public void addWarp(Warp warp) {
461            Connection conn = null;
462            PreparedStatement ps = null;
463            ResultSet rs = null;
464            try {
465                conn = etc.getSQLConnection();
466                ps = conn.prepareStatement("INSERT INTO " + table_warps + " (name, x, y, z, rotX, rotY, `group`) VALUES(?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
467                ps.setString(1, warp.Name);
468                ps.setDouble(2, warp.Location.x);
469                ps.setDouble(3, warp.Location.y);
470                ps.setDouble(4, warp.Location.z);
471                ps.setFloat(5, warp.Location.rotX);
472                ps.setFloat(6, warp.Location.rotY);
473                ps.setString(7, warp.Group);
474                ps.executeUpdate();
475    
476                rs = ps.getGeneratedKeys();
477                if (rs.next()) {
478                    warp.ID = rs.getInt(1);
479                    synchronized (warpLock) {
480                        warps.add(warp);
481                    }
482                }
483            } catch (SQLException ex) {
484                log.log(Level.SEVERE, "Unable to insert warp into warps table", ex);
485            } finally {
486                try {
487                    if (ps != null) {
488                        ps.close();
489                    }
490                    if (rs != null) {
491                        rs.close();
492                    }
493                    if (conn != null) {
494                        conn.close();
495                    }
496                } catch (SQLException ex) {
497                }
498            }
499        }
500    
501        public void changeWarp(Warp warp) {
502            Connection conn = null;
503            PreparedStatement ps = null;
504            try {
505                conn = etc.getSQLConnection();
506                ps = conn.prepareStatement("UPDATE " + table_warps + " SET x = ?, y = ?, z = ?, rotX = ?, rotY = ?, `group` = ? WHERE name = ?");
507                ps.setDouble(1, warp.Location.x);
508                ps.setDouble(2, warp.Location.y);
509                ps.setDouble(3, warp.Location.z);
510                ps.setFloat(4, warp.Location.rotX);
511                ps.setFloat(5, warp.Location.rotY);
512                ps.setString(6, warp.Group);
513                ps.setString(7, warp.Name);
514                ps.executeUpdate();
515    
516                synchronized (warpLock) {
517                    Warp toRem = null;
518                    for (Warp h : warps) {
519                        if (h.Name.equalsIgnoreCase(warp.Name)) {
520                            toRem = h;
521                        }
522                    }
523                    if (toRem != null) {
524                        warps.remove(toRem);
525                    }
526                    warps.add(warp);
527                }
528            } catch (SQLException ex) {
529                log.log(Level.SEVERE, "Unable to update warp in warps table", ex);
530            } finally {
531                try {
532                    if (ps != null) {
533                        ps.close();
534                    }
535                    if (conn != null) {
536                        conn.close();
537                    }
538                } catch (SQLException ex) {
539                }
540            }
541        }
542    
543        public void removeWarp(Warp warp) {
544            Connection conn = null;
545            PreparedStatement ps = null;
546            try {
547                conn = etc.getSQLConnection();
548                ps = conn.prepareStatement("DELETE FROM " + table_warps + " WHERE id = ?");
549                ps.setDouble(1, warp.ID);
550                ps.executeUpdate();
551            } catch (SQLException ex) {
552                log.log(Level.SEVERE, "Unable to delete warp from warps table", ex);
553            } finally {
554                try {
555                    if (ps != null) {
556                        ps.close();
557                    }
558                    if (conn != null) {
559                        conn.close();
560                    }
561                } catch (SQLException ex) {
562                }
563            }
564            synchronized (warpLock) {
565                warps.remove(warp);
566            }
567        }
568    
569        // Whitelist
570        public void addToWhitelist(String name) {
571            if (isUserOnWhitelist(name)) {
572                return;
573            }
574    
575            Connection conn = null;
576            PreparedStatement ps = null;
577            try {
578                conn = etc.getSQLConnection();
579                ps = conn.prepareStatement("INSERT INTO " + table_whitelist + " VALUES(?)");
580                ps.setString(1, name);
581                ps.executeUpdate();
582            } catch (SQLException ex) {
583                log.log(Level.SEVERE, "Unable to update whitelist", ex);
584            } finally {
585                try {
586                    if (ps != null) {
587                        ps.close();
588                    }
589                    if (conn != null) {
590                        conn.close();
591                    }
592                } catch (SQLException ex) {
593                }
594            }
595        }
596    
597        public void removeFromWhitelist(String name) {
598            if (!isUserOnWhitelist(name)) {
599                return;
600            }
601    
602            Connection conn = null;
603            PreparedStatement ps = null;
604            try {
605                conn = etc.getSQLConnection();
606                ps = conn.prepareStatement("DELETE FROM " + table_whitelist + " WHERE name = ?");
607                ps.setString(1, name);
608                ps.executeUpdate();
609            } catch (SQLException ex) {
610                log.log(Level.SEVERE, "Unable to update whitelist", ex);
611            } finally {
612                try {
613                    if (ps != null) {
614                        ps.close();
615                    }
616                    if (conn != null) {
617                        conn.close();
618                    }
619                } catch (SQLException ex) {
620                }
621            }
622        }
623    
624        // Reservelist
625        public void addToReserveList(String name) {
626            if (isUserOnReserveList(name)) {
627                return;
628            }
629    
630            Connection conn = null;
631            PreparedStatement ps = null;
632            try {
633                conn = etc.getSQLConnection();
634                ps = conn.prepareStatement("INSERT INTO " + table_reservelist + " VALUES(?)");
635                ps.setString(1, name);
636                ps.executeUpdate();
637            } catch (SQLException ex) {
638                log.log(Level.SEVERE, "Unable to update reservelist", ex);
639            } finally {
640                try {
641                    if (ps != null) {
642                        ps.close();
643                    }
644                    if (conn != null) {
645                        conn.close();
646                    }
647                } catch (SQLException ex) {
648                }
649            }
650        }
651    
652        public void removeFromReserveList(String name) {
653            if (!isUserOnReserveList(name)) {
654                return;
655            }
656    
657            Connection conn = null;
658            PreparedStatement ps = null;
659            try {
660                conn = etc.getSQLConnection();
661                ps = conn.prepareStatement("DELETE FROM " + table_reservelist + " WHERE name = ?");
662                ps.setString(1, name);
663                ps.executeUpdate();
664            } catch (SQLException ex) {
665                log.log(Level.SEVERE, "Unable to update reservelist", ex);
666            } finally {
667                try {
668                    if (ps != null) {
669                        ps.close();
670                    }
671                    if (conn != null) {
672                        conn.close();
673                    }
674                } catch (SQLException ex) {
675                }
676            }
677        }
678    
679        public Player getPlayer(String name) {
680            Player player = new Player();
681            Connection conn = null;
682            PreparedStatement ps = null;
683            ResultSet rs = null;
684            try {
685                conn = etc.getSQLConnection();
686                ps = conn.prepareStatement("SELECT * FROM " + table_users + " WHERE name = ?");
687                ps.setString(1, name);
688                rs = ps.executeQuery();
689                if (rs.next()) {
690                    player.setSqlId(rs.getInt("id"));
691                    player.setGroups(rs.getString("groups").split(","));
692                    player.setCommands(rs.getString("commands").split(","));
693                    player.setPrefix(rs.getString("prefix"));
694                    player.setAdmin(rs.getBoolean("admin"));
695                    player.setCanModifyWorld(rs.getBoolean("canmodifyworld"));
696                    player.setIgnoreRestrictions(rs.getBoolean("ignoresrestrictions"));
697                    player.setIps(rs.getString("ip").split(","));
698                }
699            } catch (SQLException ex) {
700                log.log(Level.SEVERE, "Unable to retreive users from user table", ex);
701            } finally {
702                try {
703                    if (ps != null) {
704                        ps.close();
705                    }
706                    if (rs != null) {
707                        rs.close();
708                    }
709                    if (conn != null) {
710                        conn.close();
711                    }
712                } catch (SQLException ex) {
713                }
714            }
715            return player;
716        }
717    
718        public void loadBanList() {
719            synchronized (banLock) {
720                bans = new ArrayList<Ban>();
721                Connection conn = null;
722                PreparedStatement ps = null;
723                ResultSet rs = null;
724                try {
725                    conn = etc.getSQLConnection();
726                    ps = conn.prepareStatement("SELECT * FROM " + table_bans);
727                    rs = ps.executeQuery();
728                    while (rs.next()) {
729                        Ban ban = new Ban();
730                        ban.setName(rs.getString("name"));
731                        ban.setIp(rs.getString("ip"));
732                        ban.setReason(rs.getString("reason"));
733                        ban.setTimestamp(rs.getInt("length"));
734                        bans.add(ban);
735                    }
736                } catch (SQLException ex) {
737                    log.log(Level.SEVERE, "Unable to retreive bans from ban table", ex);
738                } finally {
739                    try {
740                        if (ps != null) {
741                            ps.close();
742                        }
743                        if (rs != null) {
744                            rs.close();
745                        }
746                        if (conn != null) {
747                            conn.close();
748                        }
749                    } catch (SQLException ex) {
750                    }
751                }
752            }
753        }
754    
755        public boolean isUserOnWhitelist(String user) {
756            boolean toRet = false;
757            Connection conn = null;
758            PreparedStatement ps = null;
759            ResultSet rs = null;
760            try {
761                conn = etc.getSQLConnection();
762                ps = conn.prepareStatement("SELECT * FROM " + table_whitelist + " WHERE name = ?");
763                ps.setString(1, user);
764                rs = ps.executeQuery();
765                if (rs.next()) {
766                    toRet = true;
767                }
768            } catch (SQLException ex) {
769                log.log(Level.SEVERE, "Unable to check if user is on whitelist", ex);
770            } finally {
771                try {
772                    if (ps != null) {
773                        ps.close();
774                    }
775                    if (rs != null) {
776                        rs.close();
777                    }
778                    if (conn != null) {
779                        conn.close();
780                    }
781                } catch (SQLException ex) {
782                }
783            }
784            return toRet;
785        }
786    
787        public boolean isUserOnReserveList(String user) {
788            boolean toRet = false;
789            Connection conn = null;
790            PreparedStatement ps = null;
791            ResultSet rs = null;
792            try {
793                conn = etc.getSQLConnection();
794                ps = conn.prepareStatement("SELECT * FROM " + table_reservelist + " WHERE name = ?");
795                ps.setString(1, user);
796                rs = ps.executeQuery();
797                if (rs.next()) {
798                    toRet = true;
799                }
800            } catch (SQLException ex) {
801                log.log(Level.SEVERE, "Unable to check if user is on reservelist", ex);
802            } finally {
803                try {
804                    if (ps != null) {
805                        ps.close();
806                    }
807                    if (rs != null) {
808                        rs.close();
809                    }
810                    if (conn != null) {
811                        conn.close();
812                    }
813                } catch (SQLException ex) {
814                }
815            }
816            if (toRet || user.charAt(0) == '@')
817                return toRet;
818            Player pl = getPlayer(user);
819            String[] groups = pl.getGroups();
820            for (int i = 0; i < groups.length; ++i) {
821                if (isUserOnReserveList("@" + groups[i]))
822                    return true;
823            }
824            return toRet;
825        }
826    
827        public void modifyBan(Ban ban) {
828            throw new UnsupportedOperationException("Not supported yet.");
829        }
830    }