-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to temporarily disable announcing your afk status to the wh…
…ole server. It's temporarily because it doesn't remember after restarting your server.
- Loading branch information
1 parent
948ba4a
commit d5267d8
Showing
7 changed files
with
129 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/main/java/com/andrew121410/mc/world16essentials/commands/afk/IgnoreAfkCMD.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.andrew121410.mc.world16essentials.commands.afk; | ||
|
||
import com.andrew121410.mc.world16essentials.World16Essentials; | ||
import com.andrew121410.mc.world16essentials.objects.AfkObject; | ||
import com.andrew121410.mc.world16essentials.utils.API; | ||
import com.andrew121410.mc.world16utils.chat.Translate; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
public class IgnoreAfkCMD implements CommandExecutor { | ||
|
||
private final World16Essentials plugin; | ||
private final API api; | ||
|
||
public IgnoreAfkCMD(World16Essentials getPlugin) { | ||
this.plugin = getPlugin; | ||
this.api = this.plugin.getApi(); | ||
|
||
this.plugin.getCommand("ignoreafk").setExecutor(this); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||
if (!sender.hasPermission("world16.ignoreafk")) { | ||
api.sendPermissionErrorMessage(sender); | ||
return true; | ||
} | ||
|
||
if (args.length == 0) { | ||
if (!(sender instanceof Player)) { | ||
sender.sendMessage(Translate.miniMessage("<red>Consoles can do /ignoreafk <player>.")); | ||
return true; | ||
} | ||
|
||
handleIgnoreAfk(sender, null); | ||
} else if (args.length == 1) { // /ignoreafk <player> | ||
Player target = this.plugin.getServer().getPlayerExact(args[0]); | ||
if (target == null) { | ||
sender.sendMessage(Translate.miniMessage("<red>Player not found.")); | ||
return true; | ||
} | ||
handleIgnoreAfk(sender, target); | ||
} else { | ||
sender.sendMessage(Translate.miniMessage("<red>Usage: /ignoreafk <optional:player>")); | ||
} | ||
return true; | ||
} | ||
|
||
private void handleIgnoreAfk(CommandSender sender, Player target) { | ||
AfkObject afkObject; | ||
if (target == null) { | ||
Player player = (Player) sender; | ||
afkObject = this.plugin.getMemoryHolder().getAfkMap().get(player.getUniqueId()); | ||
} else { | ||
afkObject = this.plugin.getMemoryHolder().getAfkMap().get(target.getUniqueId()); | ||
} | ||
|
||
// Should never be null. But just in case. | ||
if (afkObject == null) { | ||
sender.sendMessage(Translate.miniMessage("<red>Something went wrong.")); | ||
return; | ||
} | ||
|
||
if (afkObject.isIgnore()) { | ||
afkObject.setIgnore(false); | ||
|
||
if (target != null) { | ||
target.sendMessage(Translate.miniMessage("<green>Your AFK Status is no longer being ignored.")); | ||
sender.sendMessage(Translate.miniMessage("<green>" + target.getName() + " AFK Status is no longer being ignored.")); | ||
} else { | ||
sender.sendMessage(Translate.miniMessage("<green>Your AFK Status is no longer being ignored.")); | ||
} | ||
} else { | ||
afkObject.setIgnore(true); | ||
|
||
if (target != null) { | ||
target.sendMessage(Translate.miniMessage("<red>Your AFK Status is now being ignored.")); | ||
sender.sendMessage(Translate.miniMessage("<red>" + target.getName() + " AFK Status is now being ignored.")); | ||
} else { | ||
sender.sendMessage(Translate.miniMessage("<red>Your AFK Status is now being ignored.")); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters