Olyno/skent

File change

LeCraft2Ouf opened this issue · 2 comments

Describe your problem

Hello, the event "on file change at paths "plugins/Skript-Config/Shop/test.yml":" doesn't seem to work correctly. I put a broadcast behind nothing is displayed

Versions

Skript: 2.8.4
Server: git-Paper-493 (MC: 1.20.4)
Skent: 3.2.2

Code

on file change at paths "plugins/Claim/Messages.yml":
	send "[Claim] Actualisation des messages..." to console

Error

NONE

Investigation

I tried to search a bit by myself all the same and it turns out that "event.eventType()" in EvtWatching.java:81 returns only CREATION and DELETE, not MODIFY, I think the problem comes from there, maybe a too old version of directory-watcher?

[17:59:58] [ForkJoinPool.commonPool-worker-3/INFO]: [com.olyno.skent.skript.events.EvtWatching] Event received: CREATE for path: plugins/Skript-Config/Shop/test.yml.filepart
[17:59:59] [ForkJoinPool.commonPool-worker-3/INFO]: [com.olyno.skent.skript.events.EvtWatching] Event received: MODIFY for path: plugins/Skript-Config/Shop/test.yml.filepart
[17:59:59] [ForkJoinPool.commonPool-worker-3/INFO]: [com.olyno.skent.skript.events.EvtWatching] Event received: DELETE for path: plugins/Skript-Config/Shop/test.yml
[17:59:59] [ForkJoinPool.commonPool-worker-3/INFO]: [com.olyno.skent.skript.events.EvtWatching] DELETE
[17:59:59] [ForkJoinPool.commonPool-worker-3/INFO]: [com.olyno.skent.skript.events.EvtWatching] Event received: DELETE for path: plugins/Skript-Config/Shop/test.yml.filepart
[17:59:59] [ForkJoinPool.commonPool-worker-3/INFO]: [com.olyno.skent.skript.events.EvtWatching] Event received: CREATE for path: plugins/Skript-Config/Shop/test.yml
[17:59:59] [ForkJoinPool.commonPool-worker-3/INFO]: [com.olyno.skent.skript.events.EvtWatching] CREATE

The modify only triggers on the filepart, obviously.

except that it's not triggered because your condition "if (allPaths.contains(event.path()) || allPaths.contains(event.path().getParent()))" doesn't let it through, so here's the problem.

temporarily, I did the following:

this.watcher = DirectoryWatcher.builder()
                .paths(directories)
                .listener(event -> {
                    if (allPaths.contains(event.path()) || allPaths.contains(event.path().getParent())) {
                        switch (event.eventType()) {
                            case CREATE:
                                if (type == WatchType.CREATION || type == WatchType.EDITION || type == WatchType.ANY) {
                                    this.event.run(event.path());
                                }
                                break;
                            case DELETE:
                                if (type == WatchType.DELETION || type == WatchType.ANY) {
                                    this.event.run(event.path());
                                }
                                break;
                        }
                    }
                })
                .build();

Fixed 👍🏻