Skip to content

Commit 510257a

Browse files
committed
Added AFK system.
1 parent f39c016 commit 510257a

File tree

8 files changed

+155
-4
lines changed

8 files changed

+155
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
!/README.md
88
!/header.txt
99
!/todo.txt
10+
!/completed.txt
1011
!/.gitignore
1112
!/pom.xml
1213
!/src/

completed.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1) AwayFromKeyboard (afk) System
2+
a) Ability for other plugins to integrate with afk system
3+
b) Commands (and subcommands)
4+
1) aliases = 'afk'
5+
2) allows other players to afk others (with permission)

src/main/java/unomodding/canary/hawk/Hawk.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
public class Hawk extends Plugin {
3232
@Override
3333
public boolean enable() {
34-
// Enable Commands
34+
// Register Listener
35+
Canary.hooks().registerListener(new HawkPluginListener(), this);
36+
37+
// Register Commands
3538
try {
3639
Canary.commands().registerCommands(new HawkCommandListener(), this, true);
3740
} catch (CommandDependencyException e) {

src/main/java/unomodding/canary/hawk/HawkCommandListener.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,38 @@
2424
*/
2525
package unomodding.canary.hawk;
2626

27+
import unomodding.canary.hawk.afk.AwayFromKeyboard;
28+
import net.canarymod.Canary;
29+
import net.canarymod.chat.MessageReceiver;
30+
import net.canarymod.chat.TextFormat;
31+
import net.canarymod.commandsys.Command;
2732
import net.canarymod.commandsys.CommandListener;
2833

2934
public class HawkCommandListener implements CommandListener {
30-
35+
@Command(aliases = {"afk"},
36+
description = "afk command",
37+
permissions = {},
38+
toolTip = "/afk [player]",
39+
version = 2)
40+
public void afkCommand(MessageReceiver caller, String[] args) {
41+
if(args.length > 1) {
42+
AwayFromKeyboard.setAFK(caller.getName(), !AwayFromKeyboard.isAFK(caller.getName()));
43+
if(AwayFromKeyboard.isAFK(caller.getName())) {
44+
caller.message("You are now AFK.");
45+
Canary.getServer().broadcastMessage(TextFormat.YELLOW + caller.getName() + " is now AFK.");
46+
} else {
47+
caller.message("You are no longer AFK.");
48+
Canary.getServer().broadcastMessage(TextFormat.YELLOW + caller.getName() + " is no longer AFK.");
49+
}
50+
} else {
51+
AwayFromKeyboard.setAFK(args[0], !AwayFromKeyboard.isAFK(args[0]));
52+
if(AwayFromKeyboard.isAFK(args[0])) {
53+
caller.message(args[0] + " is now AFK.");
54+
Canary.getServer().broadcastMessage(TextFormat.YELLOW + args[0] + " is now AFK.");
55+
} else {
56+
caller.message(args[0] + " is no longer AFK.");
57+
Canary.getServer().broadcastMessage(TextFormat.YELLOW + args[0] + " is now AFK.");
58+
}
59+
}
60+
}
3161
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* This file is part of Hawk, a CanaryMod plugin, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) UnoModding <https://github.com/UnoModding>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package unomodding.canary.hawk;
26+
27+
import unomodding.canary.hawk.afk.AwayFromKeyboard;
28+
import net.canarymod.api.entity.living.humanoid.Player;
29+
import net.canarymod.hook.HookHandler;
30+
import net.canarymod.hook.player.ConnectionHook;
31+
import net.canarymod.hook.player.DisconnectionHook;
32+
import net.canarymod.plugin.PluginListener;
33+
34+
public class HawkPluginListener implements PluginListener {
35+
@HookHandler
36+
public void onPlayerJoin(ConnectionHook hook) { // Just incase
37+
Player player = hook.getPlayer();
38+
AwayFromKeyboard.setAFK(player, false);
39+
}
40+
41+
@HookHandler
42+
public void onPlayerQuit(DisconnectionHook hook) {
43+
Player player = hook.getPlayer();
44+
AwayFromKeyboard.setAFK(player, false);
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* This file is part of Hawk, a CanaryMod plugin, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) UnoModding <https://github.com/UnoModding>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package unomodding.canary.hawk.afk;
26+
27+
import java.util.ArrayList;
28+
import java.util.List;
29+
30+
import net.canarymod.Canary;
31+
import net.canarymod.api.entity.living.humanoid.Player;
32+
33+
public final class AwayFromKeyboard {
34+
private static List<Player> playerList = new ArrayList<Player>();
35+
36+
public static void setAFK(String playername, boolean set) {
37+
Player player = Canary.getServer().getPlayer(playername);
38+
setAFK(player, set);
39+
}
40+
41+
public static void setAFK(Player player, boolean set) {
42+
if(set) {
43+
if(!isAFK(player)) {
44+
playerList.add(player);
45+
}
46+
} else {
47+
if(playerList.contains(player)) {
48+
playerList.remove(player);
49+
}
50+
}
51+
}
52+
53+
public static boolean isAFK(String playername) {
54+
Player player = Canary.getServer().getPlayer(playername);
55+
return playerList.contains(player);
56+
}
57+
58+
public static boolean isAFK(Player player) {
59+
return playerList.contains(player);
60+
}
61+
62+
public static List<Player> getAfkPlayers() {
63+
return playerList;
64+
}
65+
}

src/main/resources/Canary.inf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name=Hawk
2-
main-class=unomodding.canary.hawk
2+
main-class=unomodding.canary.hawk.Hawk
33
author=UnoModding
44
version=0.1

todo.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
a) Clear structure
1919
b) Organised
2020
c) Ease of use
21-
4) Take time to make sure everything is done nicely!
21+
4) Add auto-afk system
22+
5) Take time to make sure everything is done nicely!

0 commit comments

Comments
 (0)