Skip to content

Commit

Permalink
Finalize alert repeat timeout feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalTurtle18 committed Jul 30, 2022
1 parent a2faa63 commit ebfcedc
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ public boolean runCommand(Player player, String[] args) {
ConfigManager configManager = IdleBot.getPlugin().getConfigManager();
if (!configManager.ALERT_AUTO_TIMEOUT_ENABLED) {
MessageHelper.sendMessage(player, "You are not allowed to change your auto alert timeout settings on this server!", MessageLevel.INCORRECT_COMMAND_USAGE);
PersistentDataUtils.removeData(player, DataValue.ALERT_REPEAT_TIMEOUT);
return true;
}
if (args.length >= 2 && IdleBotUtils.isInteger(args[1]) && Integer.parseInt(args[1]) >= configManager.MINIMUM_ALERT_REPEAT_TIMEOUT && Integer.parseInt(args[1]) <= configManager.MAXIMUM_ALERT_REPEAT_TIMEOUT) {
if (args.length >= 2 && IdleBotUtils.isInteger(args[1]) && (Integer.parseInt(args[1]) == 0 || (Integer.parseInt(args[1]) >= configManager.MINIMUM_ALERT_REPEAT_TIMEOUT && Integer.parseInt(args[1]) <= configManager.MAXIMUM_ALERT_REPEAT_TIMEOUT))) {
PersistentDataUtils.setData(player, DataValue.ALERT_REPEAT_TIMEOUT, Integer.parseInt(args[1]));
MessageHelper.sendMessage(player, "Set your auto alert timeout to " + args[1], MessageLevel.INFO);
return true;
} else if (args.length >= 2 && IdleBotUtils.isInteger(args[1])) {
MessageHelper.sendMessage(player, "Your auto alert timeout must be between " + configManager.MINIMUM_ALERT_REPEAT_TIMEOUT + " and " + configManager.MAXIMUM_ALERT_REPEAT_TIMEOUT + " seconds!", MessageLevel.INCORRECT_COMMAND_USAGE);
MessageHelper.sendMessage(player, "Your auto alert timeout must be between " + configManager.MINIMUM_ALERT_REPEAT_TIMEOUT + " and " + configManager.MAXIMUM_ALERT_REPEAT_TIMEOUT + " seconds, or 0 to disable the timeout!", MessageLevel.INCORRECT_COMMAND_USAGE);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public IdleBotCommandManager() {
// Add /idlebot commands to list of commands
idleBotCommands.add(new AFKModeCommand());
idleBotCommands.add(new AFKTimeCommand());
idleBotCommands.add(new AlertTimeoutCommand());
idleBotCommands.add(new AlertCommand());
idleBotCommands.add(new LinkCommand());
idleBotCommands.add(new SetAFKCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public boolean runCommand(Player player, String[] args) {
player.sendMessage(ChatColor.AQUA + "Message channel: " + (PersistentDataUtils.getBooleanData(player, DataValue.DIRECT_MESSAGE_MODE) ? "direct message" : "public channel"));
player.sendMessage(ChatColor.AQUA + "AFK mode: " + (PersistentDataUtils.getBooleanData(player, DataValue.AUTO_AFK) ? "auto" : ("manual (Set AFK: " + PersistentDataUtils.getBooleanData(player, DataValue.IS_SET_AFK) + ")")));
player.sendMessage(ChatColor.AQUA + "AFK time: " + PersistentDataUtils.getIntData(player, DataValue.AFK_TIME));
player.sendMessage(ChatColor.AQUA + "Alert repeat timeout: " + PersistentDataUtils.getIntData(player, DataValue.ALERT_REPEAT_TIMEOUT));
player.sendMessage(ChatColor.AQUA + "Damage alert: " + PersistentDataUtils.getBooleanData(player, DataValue.DAMAGE_ALERT));
player.sendMessage(ChatColor.AQUA + "Death alert: " + PersistentDataUtils.getBooleanData(player, DataValue.DEATH_ALERT));
boolean locationAlertX = PersistentDataUtils.getBooleanData(player, DataValue.LOCATION_ALERT_X);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public void run() {
// Remove players from alerted lists if their alert timeout has been reached
for (HashMap<Player, Integer> map : alertedLists) {
for (Player player : map.keySet()) {
if (map.get(player) >= PersistentDataUtils.getIntData(player, DataValue.ALERT_REPEAT_TIMEOUT)) {
map.put(player, map.get(player) + 1); // Increment the timeout tracker
int timeout = PersistentDataUtils.getIntData(player, DataValue.ALERT_REPEAT_TIMEOUT);
if (timeout > 0 && map.get(player) >= timeout) {
map.remove(player);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public enum CommandTabCompletion {
AFKMODE(new String[]{"auto", "manual"}),
AFKTIME(),
ALERTTIMEOUT(),
ALERT(new String[]{"damage", "death", "xlocation", "zlocation", "xp", "inventory", "advancement", "toolbreak"}, new String[]{"true", "false"}),
CHANNEL(new String[]{"public", "private"}),
CLEARDATA(),
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ alertRepeatTimeout:
# (s) The default time between alerts for players who do not set their own | this must be between minimum and maximum alert repeat timeout set below | default: 20
defaultAlertRepeatTimeout: 20
# (s) The minimum time between alerts a players can set for themselves | you can set this to a minimum of 5 seconds | default: 10
# Users will be able to set their time to 0 regardless of what you set here. This disables alerts from repeating for the player.
minimumAlertRepeatTimeout: 10
# (s) The maximum time between alerts a players can set for themselves | you can set this to a maximum of 86400 seconds (1 day) | default: 120
maximumAlertRepeatTimeout: 120

0 comments on commit ebfcedc

Please sign in to comment.