Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.limework;
- import org.bukkit.Bukkit;
- import java.io.IOException;
- import java.nio.file.*;
- public class FileWatcherProcessTest implements Runnable {
- private volatile String database;
- private volatile String splitter;
- public FileWatcherProcessTest(String database, String splitter) throws IOException {
- this.database = database;
- this.splitter = splitter;
- }
- public void run(){
- WatchService watchService
- = null;
- try {
- watchService = FileSystems.getDefault().newWatchService();
- } catch (IOException e) {
- e.printStackTrace();
- }
- Path path = Paths.get(database);
- try {
- path.register(
- watchService,
- StandardWatchEventKinds.ENTRY_CREATE,
- StandardWatchEventKinds.ENTRY_MODIFY);
- } catch (IOException e) {
- e.printStackTrace();
- }
- WatchKey key = null;
- while (true) {
- try {
- if ((key = watchService.take()) == null) break;
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- for (WatchEvent<?> event : key.pollEvents()) {
- System.out.println(
- "Event kind:" + event.kind()
- + ". File affected: " + event.context());
- net.limework.DatabaseUpdateEvent update = new net.limework.DatabaseUpdateEvent("testvalue");
- Bukkit.getServer().getPluginManager().callEvent(update);
- }
- key.reset();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement