From 982190b7306dc2b262fac5035e27f393005b888b Mon Sep 17 00:00:00 2001 From: Ruakij Date: Tue, 11 May 2021 12:42:42 +0200 Subject: [PATCH] Implemented config-option locationCheck --- .../eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java | 6 +++--- .../CustomPlayerMoveEventHandler.java | 10 +++++----- src/main/resources/config.yml | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java index f1bd4b8..74a48d6 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java @@ -35,11 +35,11 @@ public class Main extends JavaPlugin { pluginManager.registerEvents(new OnBlockPlace(), this); pluginManager.registerEvents(new OnCraftItemEvent(), this); - CustomPlayerMoveEventHandler cpmHandler = new CustomPlayerMoveEventHandler(this, true); - cpmHandler.registerListener(new OnCustomPlayerMove()); - loadConfigs(); + CustomPlayerMoveEventHandler cpmHandler = new CustomPlayerMoveEventHandler(this, config.getInt("locationCheck.interval"), true); + cpmHandler.registerListener(new OnCustomPlayerMove()); + LinkedBeaconTeleporterManager.init(); initAutoSave(); diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/customPlayerMoveEvent/CustomPlayerMoveEventHandler.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/customPlayerMoveEvent/CustomPlayerMoveEventHandler.java index d95da8e..67fac02 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/customPlayerMoveEvent/CustomPlayerMoveEventHandler.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/customPlayerMoveEvent/CustomPlayerMoveEventHandler.java @@ -17,16 +17,16 @@ public class CustomPlayerMoveEventHandler { HashMap oldPlayerLoc = new HashMap<>(); boolean locationChangeOnBlockChange; - public CustomPlayerMoveEventHandler(Plugin plugin, boolean locationChangeOnBlockChange){ + public CustomPlayerMoveEventHandler(Plugin plugin, int interval, boolean locationChangeOnBlockChange){ this.locationChangeOnBlockChange = locationChangeOnBlockChange; - startRunnable(plugin); + startRunnable(plugin, interval); } public CustomPlayerMoveEventHandler(Plugin plugin){ - this(plugin, false); + this(plugin, 5, false); } - void startRunnable(Plugin plugin){ + void startRunnable(Plugin plugin, int interval){ Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> { // Dont do anything without listeners @@ -64,7 +64,7 @@ public class CustomPlayerMoveEventHandler { oldPlayerLoc.put(uuid, loc); } - }, 20, 10); + }, interval, interval); } boolean blockLocationChanged(Location loc, Location oldLoc){ diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3ce29c6..2d377a5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -14,7 +14,7 @@ id: # TODO # If its too short, ids will "collide" more often (e.g. 2 players generating same linked-teleporters independently), but maybe thats a gameplay-feature for you :) length: 10 -locationCheck: # TODO +locationCheck: # Interval [in ticks] to check if a player is on a beacon # 5 (= 4 times/s) is usually responsive enough for most interactions interval: 5