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

Commit

Permalink
New command: /afklist
Browse files Browse the repository at this point in the history
Shows a list of all players marked as AFK at the moment
  • Loading branch information
kiriDevs committed Dec 16, 2020
1 parent bf526bf commit b012132
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# kiriCore
`NOTE: The kiriCore is currently being rewritten. Please check back later for more information or a finished version!`

[Current version: 0.4.2]
[Current version: 0.5.0]

### Commands:
- /afk
Expand All @@ -10,6 +10,9 @@
- /isafk \<player name>
- Check if a specific player is marked as AFK at the moment!
- permission: kiri.core.afk.check
- /afklist
- Print a list of all players marked as AFK at the moment
- permission: kiri.core.afk.list
- /rename \<new item name>
- Rename your currently held item! (max. 32 characters of length)
- permission: kiri.core.rename
6 changes: 5 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
main: de.kiridevs.kiricore.main.Main

name: kiriCore
version: 0.4.2
version: 0.5.0
api-version: 1.16
author: kiriDevs

Expand All @@ -20,6 +20,10 @@ commands:
description: Check if a specific player is marked as AFK at the moment!
usage: /isafk <Playername>
permission: kiri.core.afk.check
afklist:
description: Print a list of all players marked as AFK at the moment!
usage: /afklist
permission: kiri.core.afk.list
rename:
description: Rename the currently held item
usage: /rename <new item name>
Expand Down
58 changes: 58 additions & 0 deletions src/de/kiridevs/kiricore/commands/CMDafkList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.kiridevs.kiricore.commands;

import de.kiridevs.kiricore.managers.AfkManager;
import de.kiridevs.kiricore.managers.MessageService;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

import javax.annotation.Nonnull;
import java.util.ArrayList;

public class CMDafkList implements CommandExecutor {
MessageService messageService;
public CMDafkList(MessageService messageService) {
this.messageService = messageService;
}

@Override
public boolean onCommand(@Nonnull CommandSender cmdSender, @Nonnull Command cmd, @Nonnull String label, @Nonnull String[] args) {
if (!(cmdSender.hasPermission("kiri.core.afk.list"))) {
ArrayList<String> completionList = new ArrayList<>();
completionList.add("kiri.core.afk.list");
messageService.sendErrorMessage(cmdSender, "noperm", completionList);
return true;
}

if (args.length != 0) {
ArrayList<String> completionList = new ArrayList<>();
completionList.add("/afklist");
messageService.sendErrorMessage(cmdSender, "badsyntax", completionList);
return true;
}

if (AfkManager.getAfkList().size() == 0) {
messageService.sendErrorMessage(cmdSender, "No one is marked as AFK at the moment!");
return true;
}

StringBuilder listBuilder = new StringBuilder();
boolean isFirstRun = true;
for (String playerName : AfkManager.getAfkList()) {
if (!isFirstRun) {
listBuilder.append(", ");
} else { isFirstRun = false; }

listBuilder.append("§r§3");
listBuilder.append(playerName);
listBuilder.append("§r§b");
}


String listString = listBuilder.toString();
messageService.sendInfoMessage(cmdSender, "These players are marked as AFK right now:");
messageService.sendInfoMessage(cmdSender, listString);

return true;
}
}
2 changes: 2 additions & 0 deletions src/de/kiridevs/kiricore/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.kiridevs.kiricore.Prefix;
import de.kiridevs.kiricore.commands.CMDafk;
import de.kiridevs.kiricore.commands.CMDafkList;
import de.kiridevs.kiricore.commands.CMDisAfk;
import de.kiridevs.kiricore.commands.CMDrename;
import de.kiridevs.kiricore.listeners.LISTonPlayerChangeAfkStatus;
Expand Down Expand Up @@ -43,6 +44,7 @@ public void onEnable() {
getCommand("afk").setExecutor(new CMDafk(messageService));
getCommand("isafk").setExecutor(new CMDisAfk(messageService));
getCommand("rename").setExecutor(new CMDrename(messageService));
getCommand("afklist").setExecutor(new CMDafkList(messageService));

// Listener registration
Bukkit.getPluginManager().registerEvents(new LISTonPlayerLeave(), this);
Expand Down

0 comments on commit b012132

Please sign in to comment.