Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. //get the area and output the owers name
  2. @EventMethod
  3. public void onPlayerEnterChunk(PlayerEnterChunkEvent evt) throws SQLException{
  4. Player player = evt.getPlayer();
  5. String Playername = player.getName();
  6. GuiLabel Display = (GuiLabel) player.getAttribute("AreaDisplay");
  7. GuiLabel Display1 = (GuiLabel) player.getAttribute("AreaDisplay1");
  8. GuiLabel Display2 = (GuiLabel) player.getAttribute("AreaDisplay2");
  9. Display.setText("");
  10. Display1.setText("");
  11. Display2.setText("");
  12.  
  13. Vector3i AreaIDV = evt.getNewChunkCoordinates();
  14. int AreaIDx = (int) AreaIDV.x;
  15. int AreaIDy = (int) AreaIDV.y;
  16. int AreaIDz = (int) AreaIDV.z;
  17. String AreaID = ""+AreaIDx+AreaIDy+AreaIDz+"";
  18.  
  19.  
  20.  
  21. Database database = getSQLiteConnection(getPath() + "/" + "database.db");
  22.  
  23. try(ResultSet result = database.executeQuery("SELECT * FROM `AdminSettings` WHERE `ID` = '1'")){
  24. if(!result.next()){
  25. database.executeUpdate("INSERT INTO `AdminSettings` (AreaNum) VALUES ('1000');");
  26. }
  27. }
  28.  
  29.  
  30. // set the code to run every 3 sec
  31. Runnable reload = new Runnable() {
  32. public void run() {
  33.  
  34.  
  35. try(ResultSet result = database.executeQuery("SELECT * FROM `AdminSettings` WHERE `ID` = '1'")){
  36. String AreaNum = result.getString("AreaNum");
  37. Display1.setText(" Areas Allowed = "+AreaNum+" ");
  38. } catch (SQLException ex) {
  39. Logger.getLogger(WorldProtection.class.getName()).log(Level.SEVERE, null, ex);
  40. }
  41.  
  42. try(ResultSet result = database.executeQuery("SELECT COUNT(*) FROM `Areas` WHERE `AreaOwner` = '"+ Playername +"'")){
  43. String Count = result.getString("COUNT(*)");
  44. Display2.setText(" Areas owned = "+Count+" ");
  45. } catch (SQLException ex) {
  46. Logger.getLogger(WorldProtection.class.getName()).log(Level.SEVERE, null, ex);
  47. }
  48.  
  49. }
  50.  
  51. };
  52. ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
  53. executor.scheduleAtFixedRate(reload, 0, 3, TimeUnit.SECONDS);
  54. // end of time code
  55.  
  56. try(ResultSet result = database.executeQuery("SELECT * FROM `Areas` WHERE `AreaID` = '"+ AreaID +"'")){
  57. if(result.next()){
  58. String AreaOwner = result.getString("AreaOwner");
  59. Display.setText(" Area "+AreaID+" owned by "+AreaOwner+" ");
  60. return;
  61. }
  62.  
  63. if(!result.next()){
  64. Display.setText(" Area "+ AreaID +" Unprotected ");
  65. return;
  66. }
  67.  
  68. } catch (SQLException ex) {
  69. Logger.getLogger(WorldProtection.class.getName()).log(Level.SEVERE, null, ex);
  70. }
  71.  
  72.  
  73. }
  74.  
  75.  
  76. the error
  77. PLUGIN EXCEPTION (WorldProtection, 1.0.0, Yahgiggle) ---->
  78. java.lang.NullPointerException
  79. at worldprotection.WorldProtection.onPlayerEnterChunk(WorldProtection.java:191)
  80. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  81. at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  82. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  83. at java.lang.reflect.Method.invoke(Unknown Source)
  84. at pluginapi.PluginEventHandler.triggerEvent(SourceFile:201)
  85. at aU.f.a(SourceFile:315)
  86. at aU.f.messageReceived(SourceFile:119)
  87. at k.e.a(SourceFile:109)
  88. at k.c.run(SourceFile:65)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement