Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. package net.limework;
  2.  
  3. import org.bukkit.Bukkit;
  4.  
  5. import java.io.IOException;
  6. import java.nio.file.*;
  7.  
  8. public class FileWatcherProcessTest implements Runnable {
  9. private volatile String database;
  10. private volatile String splitter;
  11.  
  12. public FileWatcherProcessTest(String database, String splitter) throws IOException {
  13. this.database = database;
  14. this.splitter = splitter;
  15. }
  16.  
  17. public void run(){
  18. WatchService watchService
  19. = null;
  20. try {
  21. watchService = FileSystems.getDefault().newWatchService();
  22. } catch (IOException e) {
  23. e.printStackTrace();
  24. }
  25.  
  26. Path path = Paths.get(database);
  27.  
  28. try {
  29. path.register(
  30. watchService,
  31. StandardWatchEventKinds.ENTRY_CREATE,
  32. StandardWatchEventKinds.ENTRY_MODIFY);
  33. } catch (IOException e) {
  34. e.printStackTrace();
  35. }
  36.  
  37. WatchKey key = null;
  38. while (true) {
  39. try {
  40. if ((key = watchService.take()) == null) break;
  41. } catch (InterruptedException e) {
  42. e.printStackTrace();
  43. }
  44. for (WatchEvent<?> event : key.pollEvents()) {
  45. System.out.println(
  46. "Event kind:" + event.kind()
  47. + ". File affected: " + event.context());
  48. net.limework.DatabaseUpdateEvent update = new net.limework.DatabaseUpdateEvent("testvalue");
  49. Bukkit.getServer().getPluginManager().callEvent(update);
  50.  
  51.  
  52. }
  53. key.reset();
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement