diff --git a/src/main/java/me/ayunami2000/ayunEagVidMap/Main.java b/src/main/java/me/ayunami2000/ayunEagVidMap/Main.java index 4e2a823..f75e47e 100644 --- a/src/main/java/me/ayunami2000/ayunEagVidMap/Main.java +++ b/src/main/java/me/ayunami2000/ayunEagVidMap/Main.java @@ -25,6 +25,8 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener { private final int[] mapSize = {1, 1}; private int mapSizeCap = 10; private int mapOffset = 0; + private int interval = 10; + private int syncTask = -1; @Override public void onLoad(){ @@ -44,6 +46,17 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener { sendToAllPlayers(videoMapCodec.disableVideoBukkit()); } + private void stopSyncTask() { + if (syncTask != -1) { + this.getServer().getScheduler().cancelTask(syncTask); + syncTask = -1; + } + } + + private void createSyncTask() { + if (interval > 0) syncTask = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, this::syncToAllPlayers, 0, interval * 20L); + } + private void rlConfig() { MessageHandler.initMessages(); audioLoc.setX(this.getConfig().getDouble("audio.x")); @@ -53,6 +66,9 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener { mapOffset = this.getConfig().getInt("offset"); setSize(this.getConfig().getInt("size.width"), this.getConfig().getInt("size.height")); url = this.getConfig().getString("url"); + interval = this.getConfig().getInt("interval"); + stopSyncTask(); + createSyncTask(); } private void syncToPlayer(Player player) { @@ -205,6 +221,22 @@ public class Main extends JavaPlugin implements CommandExecutor, Listener { this.saveConfig(); MessageHandler.sendPrefixedMessage(sender, "setSize", mapSize[0], mapSize[1], mapSize[0] * mapSize[1]); break; + case "i": + case "int": + case "interval": + if (args.length < 2) { + MessageHandler.sendPrefixedMessage(sender, "currentInterval", interval); + break; + } + try { + interval = Math.max(0, Integer.parseInt(args[1])); + stopSyncTask(); + createSyncTask(); + MessageHandler.sendPrefixedMessage(sender, "setInterval"); + } catch (NumberFormatException e) { + MessageHandler.sendPrefixedMessage(sender, "notANumber", args[1], "integer"); + } + break; default: MessageHandler.sendPrefixedMessage(sender, "invalidUsage"); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a6041ee..6e325b8 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -8,6 +8,8 @@ size: cap: 10 # map ID offset offset: 0 +# sync interval, in seconds +interval: 10 # audio location audio: x: 0 diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 489940d..b6e217d 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -7,6 +7,7 @@ usage: - "&7&o/ayunvid [force] &3- Toggle playback of the video. This also loads the new video after the video URL is changed. Optionally force a reload of the video." - "&7&o/ayunvid [ ] &3- Sets or gets the size of video, in maps. E.g., a width of 2 and a height of 3 would result in a video using 6 maps." - "&7&o/ayunvid &3- Reloads the configuration file." + - "&7&o/ayunvid &3- Set the sync interval, in seconds, or 0 to disable." currentUrl: "&3Current URL: {0}" setUrl: "&3Successfully set URL." locFromConsole: "&cError: You must specify the coordinates when running this command from the console!" @@ -21,4 +22,6 @@ pausing: "&3Pausing video..." currentSize: "&3Current size: {0} maps wide by {1} maps tall ({2} maps total)" setSize: "&3Set size to {0} maps wide by {1} maps tall ({2} maps total)" invalidUsage: "&cError: That is not a valid subcommand! Try &n/ayunvid&c help for usage." -reloaded: "&3Successfully reloaded configuration!" \ No newline at end of file +reloaded: "&3Successfully reloaded configuration!" +currentInterval: "&3Current sync interval: {0} seconds" +setInterval: "&3Successfully set or disabled sync interval." \ No newline at end of file diff --git a/target/ayunEagVidMap-1.0-SNAPSHOT.jar b/target/ayunEagVidMap-1.0-SNAPSHOT.jar index 45a21fc..acb122a 100644 Binary files a/target/ayunEagVidMap-1.0-SNAPSHOT.jar and b/target/ayunEagVidMap-1.0-SNAPSHOT.jar differ