|
3 | 3 | import java.io.File; |
4 | 4 | import java.sql.Connection; |
5 | 5 | import java.sql.DriverManager; |
| 6 | +import java.sql.PreparedStatement; |
6 | 7 | import java.sql.ResultSet; |
7 | 8 | import java.sql.SQLException; |
8 | 9 | import java.sql.Statement; |
@@ -342,32 +343,126 @@ else if (args[2].equalsIgnoreCase("3")) // Tabe & userlib |
342 | 343 | } |
343 | 344 | else if (args[0].equalsIgnoreCase("removeName")) |
344 | 345 | { |
345 | | - if (args.length == 2) |
| 346 | + if (args.length >= 2) |
346 | 347 | { |
347 | | - |
348 | | - Connection dbCon = null; |
349 | | - Statement stmt = null; |
| 348 | + if (args.length == 3) |
| 349 | + { |
| 350 | + |
| 351 | + if (args[2].equalsIgnoreCase("1")) |
| 352 | + { |
| 353 | + Connection dbCon = null; |
| 354 | + Statement stmt = null; |
350 | 355 |
|
351 | | - try { |
352 | | - String query = "DELETE FROM userUUID WHERE username = '"+args[1].toString()+"'"; |
353 | | - dbCon = DriverManager.getConnection( |
354 | | - dbInformation[0], dbInformation[1], |
355 | | - dbInformation[2]); |
| 356 | + try { |
| 357 | + String query = "DELETE FROM userUUID WHERE username = '"+args[1].toString()+"'"; |
| 358 | + dbCon = DriverManager.getConnection( |
| 359 | + dbInformation[0], dbInformation[1], |
| 360 | + dbInformation[2]); |
356 | 361 |
|
357 | | - stmt = dbCon.prepareStatement(query); |
358 | | - stmt.executeUpdate(query); |
359 | | - sender.sendMessage("[UUIDSql]Row deleted !"); |
360 | | - dbCon.close(); |
361 | | - } catch (SQLException e) { |
362 | | - // TODO Auto-generated catch block |
363 | | - this.getLogger().warning("[UUIDSql]An error occured ."); |
364 | | - this.getLogger().severe("Cause: " + e.getMessage()); |
| 362 | + stmt = dbCon.prepareStatement(query); |
| 363 | + stmt.executeUpdate(query); |
| 364 | + sender.sendMessage("[UUIDSql]Row deleted !"); |
| 365 | + dbCon.close(); |
| 366 | + } catch (SQLException e) { |
| 367 | + // TODO Auto-generated catch block |
| 368 | + this.getLogger().warning("[UUIDSql]An error occured ."); |
| 369 | + this.getLogger().severe("Cause: " + e.getMessage()); |
| 370 | + |
| 371 | + } |
| 372 | + } |
| 373 | + else if(args[2].equalsIgnoreCase("2")) |
| 374 | + { |
| 375 | + String uuidFound = ""; |
| 376 | + try { |
| 377 | + |
| 378 | + String query = "SELECT uuid FROM userUUID WHERE username = '" |
| 379 | + + args[1].toString() + "' "; |
| 380 | + Connection dbCon = DriverManager.getConnection( |
| 381 | + dbInformation[0], dbInformation[1], |
| 382 | + dbInformation[2]); |
| 383 | + |
| 384 | + PreparedStatement stmt = dbCon.prepareStatement(query); |
| 385 | + ResultSet rs = stmt.executeQuery(query); |
| 386 | + while (rs.next()) { |
| 387 | + uuidFound = rs.getString(0); |
| 388 | + } |
| 389 | + dbCon.close(); |
| 390 | + } catch (SQLException e) { |
| 391 | + // TODO Auto-generated catch block |
| 392 | + this.getLogger().warning("[UUIDSql]An error occured"); |
| 393 | + this.getLogger().severe("Cause: " + e.getMessage()); |
| 394 | + } |
| 395 | + File f = new File("world"+File.separator+"playerdata"+File.separator+uuidFound+".dat"); |
| 396 | + if (f.delete()) |
| 397 | + { |
| 398 | + sender.sendMessage("[UUIDSql] File for "+args[1].toString()+" has been deleted"); |
| 399 | + } |
| 400 | + else { |
| 401 | + sender.sendMessage("[UUIDSql] An error occured"); |
| 402 | + } |
| 403 | + } |
| 404 | + else if (args[2].equalsIgnoreCase("3")) // Tabe & userlib |
| 405 | + { |
| 406 | + String uuidFound = ""; |
| 407 | + try { |
| 408 | + |
| 409 | + String query = "SELECT uuid FROM userUUID WHERE username = '" |
| 410 | + + args[1].toString() + "' "; |
| 411 | + Connection dbCon = DriverManager.getConnection( |
| 412 | + dbInformation[0], dbInformation[1], |
| 413 | + dbInformation[2]); |
| 414 | + |
| 415 | + PreparedStatement stmt = dbCon.prepareStatement(query); |
| 416 | + ResultSet rs = stmt.executeQuery(query); |
| 417 | + while (rs.next()) { |
| 418 | + uuidFound = rs.getString(1); |
| 419 | + } |
| 420 | + dbCon.close(); |
| 421 | + } catch (SQLException e) { |
| 422 | + // TODO Auto-generated catch block |
| 423 | + this.getLogger().warning("[UUIDSql]An error occured"); |
| 424 | + this.getLogger().severe("Cause: " + e.getMessage()); |
| 425 | + } |
| 426 | + File f = new File("world"+File.separator+"playerdata"+File.separator+uuidFound+".dat"); |
| 427 | + if (f.delete()) |
| 428 | + { |
| 429 | + sender.sendMessage("[UUIDSql] File for "+args[1].toString()+" has been deleted"); |
| 430 | + |
| 431 | + try { |
| 432 | + String query = "DELETE FROM userUUID WHERE username = '"+args[1].toString()+"'"; |
| 433 | + Connection dbCon = DriverManager.getConnection( |
| 434 | + dbInformation[0], dbInformation[1], |
| 435 | + dbInformation[2]); |
| 436 | + |
| 437 | + PreparedStatement stmt = dbCon.prepareStatement(query); |
| 438 | + stmt.executeUpdate(query); |
| 439 | + sender.sendMessage("[UUIDSql]Row deleted !"); |
| 440 | + dbCon.close(); |
| 441 | + } catch (SQLException e) { |
| 442 | + // TODO Auto-generated catch block |
| 443 | + this.getLogger().warning("[UUIDSql]An error occured ."); |
| 444 | + this.getLogger().severe("Cause: " + e.getMessage()); |
| 445 | + |
| 446 | + } |
| 447 | + } |
| 448 | + else { |
| 449 | + sender.sendMessage("[UUIDSql] An error occured"); |
| 450 | + } |
| 451 | + } |
| 452 | + |
| 453 | + } |
| 454 | + else { |
| 455 | + sender.sendMessage("[UUIDSql] What do you wan't to remove for "+args[1].toString()+" ?"); |
| 456 | + sender.sendMessage("[UUIDSql] 1. Table"); |
| 457 | + sender.sendMessage("[UUIDSql] 2. User Library"); |
| 458 | + sender.sendMessage("[UUIDSql] 3. Table & User Library"); |
| 459 | + sender.sendMessage("[UUIDSql] To perform the action, type : /uuidsql removename "+args[1].toString()+" <1,2,3>"); |
365 | 460 |
|
366 | 461 | } |
| 462 | + |
367 | 463 | } |
368 | | - else |
369 | | - { |
370 | | - sender.sendMessage("[UUIDSql]You myst specify a name !"); |
| 464 | + else { |
| 465 | + sender.sendMessage("[UUIDSql]You myst secify a username !"); |
371 | 466 | } |
372 | 467 |
|
373 | 468 | } |
|
0 commit comments