Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
AfkTimeout: fix /afk command
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Nov 6, 2023
1 parent 27dcc93 commit b42f030
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/main/java/net/flectone/chat/module/commands/CommandAfk.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.flectone.chat.module.commands;

import net.flectone.chat.module.FCommand;
import net.flectone.chat.FlectoneChat;
import net.flectone.chat.model.player.FPlayer;
import net.flectone.chat.module.FCommand;
import net.flectone.chat.module.FModule;
import net.flectone.chat.module.player.afkTimeout.AfkTimeoutModule;
import net.flectone.chat.util.MessageUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -48,6 +50,12 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command

boolean isAfk = !fPlayer.isAfk();

FModule fModule = FlectoneChat.getModuleManager().get(AfkTimeoutModule.class);
if (fModule instanceof AfkTimeoutModule afkTimeoutModule) {
afkTimeoutModule.setAfk(player, isAfk, "/afk");
return true;
}

String afkSuffix = isAfk
? locale.getVaultString(player, "commands.afk.suffix")
: "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void playerChatEvent(@NotNull AsyncPlayerChatEvent event) {

@EventHandler
public void playerCommandSendEvent(@NotNull PlayerCommandPreprocessEvent event) {
if (event.getMessage().contains("/afk")) return;
((AfkTimeoutModule) getModule()).setAfk(event.getPlayer(), false, "commands");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public void setAfk(@NotNull Player player, boolean isAfk, @NotNull String takeOu
if (!list.contains(takeOutAction)) return;

LAST_BLOCK_MAP.put(player.getUniqueId(), null);
} else {

LAST_BLOCK_MAP.put(player.getUniqueId(), new Pair<>(TimeUtil.getCurrentTime(), player.getLocation().getBlock()));
}

FPlayer fPlayer = FPlayerManager.get(player);
Expand All @@ -56,12 +59,11 @@ public void setAfk(@NotNull Player player, boolean isAfk, @NotNull String takeOu

String afkMessage = locale.getVaultString(player, "commands.afk." + isAfk + "-message");
player.sendMessage(MessageUtil.formatAll(player, MessageUtil.formatPlayerString(player, afkMessage)));

fPlayer.playSound(player, player, this.toString());
}

public void checkAfk(@NotNull Player player) {
if (!isEnabledFor(player)) return;
if (hasNoPermission(player)) return;

FPlayer fPlayer = FPlayerManager.get(player);
if(fPlayer == null) return;

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ default:
time: 3000

take-out-actions:
- /afk
- commands
- chat
- move
Expand Down Expand Up @@ -337,6 +338,9 @@ default:

set-cancelled: false

sounds:
enable: true

chat-bubble:
enable: true
color: "#999999"
Expand Down

0 comments on commit b42f030

Please sign in to comment.