mirror of
https://github.com/ayunami2000/ayunEagVidMap.git
synced 2024-12-20 22:04:10 -08:00
add syncing as a config option/command
This commit is contained in:
parent
6048af89f3
commit
52d0540c3a
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ size:
|
|||
cap: 10
|
||||
# map ID offset
|
||||
offset: 0
|
||||
# sync interval, in seconds
|
||||
interval: 10
|
||||
# audio location
|
||||
audio:
|
||||
x: 0
|
||||
|
|
|
@ -7,6 +7,7 @@ usage:
|
|||
- "&7&o/ayunvid <p|play|pause> [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 <s|size> [<width> <height>] &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 <rl|reload> &3- Reloads the configuration file."
|
||||
- "&7&o/ayunvid <i|int|interval> &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!"
|
||||
reloaded: "&3Successfully reloaded configuration!"
|
||||
currentInterval: "&3Current sync interval: {0} seconds"
|
||||
setInterval: "&3Successfully set or disabled sync interval."
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user