Compare commits

...
32 Commits
Author SHA1 Message Date
Len 6d9def24e1 Update Gradle 2026-08-01 05:08:27 -05:00
Len cdb75366d4 Correct package com.alttd.afkdectector 2026-07-29 16:37:06 -05:00
Len 68632b7a24 Remove java toolchain 2026-07-29 04:34:15 -05:00
Len bee1048fc2 Remove unused Logger.java 2026-07-25 12:40:40 -05:00
Len b9a7e6a7e4 Refactor commands to use Brigadier. 2026-07-25 12:20:22 -05:00
Len f82160d7d3 Refactor to PaperPlugin 2026-07-25 10:43:58 -05:00
Len ea0d678c83 Update to 26.2 2026-07-23 14:56:32 -05:00
Len 02f89bceab Merge remote-tracking branch 'origin/1.21.10' 2026-07-23 14:52:34 -05:00
stijn e397bff34d Updated MyPet and Cosmos 2026-06-08 21:51:58 +02:00
Len d0c324594e Update to 26.1.X 2026-05-15 06:27:45 -05:00
Len afd95fd084 Add RelogCheckCommand 2026-04-06 14:41:34 +02:00
Len 6ac80610bf Update for Minecraft Version 1.21.9 2026-04-06 14:41:24 +02:00
Len 054f39407d Check if mypet is enabled 2025-07-07 16:18:48 +02:00
stijn 53569f0951 Fix typo in Gradle property name for Nexus credentials in Jenkinsfile 2025-06-28 03:01:02 +02:00
stijn 7d046a060e Use Jenkins credentials binding for Nexus snapshot authentication 2025-06-28 02:59:55 +02:00
stijn ef211c8de3 Use Jenkins credentials binding for Nexus snapshot authentication 2025-06-28 02:58:04 +02:00
stijn d156ee954a Pass Nexus snapshot credentials to Gradle build in Jenkinsfile 2025-06-28 02:54:15 +02:00
stijn 7876f92f62 Remove unused AbstractConfig class 2025-06-28 02:52:34 +02:00
stijn d0552271a3 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	build.gradle.kts
#	src/main/java/com/alttd/afkdectector/MessageTimer.java
#	src/main/java/com/alttd/afkdectector/config/Config.java
#	src/main/java/com/alttd/afkdectector/config/MessagesConfig.java
2025-06-28 02:50:07 +02:00
stijn b90fe7e288 Update to 1.21 with Cosmos 2025-06-28 02:47:49 +02:00
Len 064191f19b Update to 1.21.6 2025-06-15 14:10:07 +02:00
auto 2877ffd603 Change configuration file path
Updated the path of the configuration files in both MessagesConfig and Config classes. Instead of referencing the user's home directory, it now points to a dedicated directory under '/mnt/configs'.
2024-07-19 21:15:06 +02:00
Len 66276fbf47 Improve support for mypet 2024-04-20 15:12:13 +02:00
Len 1672fccced Automatically update version in plugin.yml 2023-12-30 22:37:03 +01:00
Len 1e7d3c7d93 Add Jenkinsfile 2023-12-30 21:34:09 +01:00
Len d179384954 Fix bossbar not working when mypet is not enabled 2023-12-30 13:52:33 +01:00
Len 687e063ad9 Add buildnumber 2023-12-25 14:35:44 +01:00
Len cf9619d0f9 Update .gitignore 2023-12-17 13:14:50 +01:00
Len a00d7cc599 Update to 1.20.4 2023-12-17 13:11:06 +01:00
Len 88ac1e40ad Do not set setSleepingIgnored, functionality is included in Galaxy 2023-08-11 20:55:03 +02:00
Len 25b9a6733e Do not kick staff while they are vanished 2023-07-31 13:29:28 +02:00
Len 4a21cb3d33 Send pet away when player goes AFK 2023-07-31 13:20:44 +02:00
23 changed files with 648 additions and 297 deletions
+5 -1
View File
@@ -36,4 +36,8 @@ target/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.gradle
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
*.bat
Vendored
+26
View File
@@ -0,0 +1,26 @@
pipeline {
agent any
stages {
stage('Gradle') {
steps {
withCredentials([usernamePassword(credentialsId: 'alttd-snapshot-user', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh '''
set +x
chmod +x gradlew
./gradlew build -PalttdSnapshotUsername=$USERNAME -PalttdSnapshotPassword=$PASSWORD
'''
}
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: 'build/libs/', followSymlinks: false
}
}
stage('discord') {
steps {
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
}
}
}
}
+79 -25
View File
@@ -1,21 +1,16 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
import net.minecrell.pluginyml.paper.PaperPluginDescription
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "7.1.0"
id("de.eldoria.plugin-yml.paper") version "0.9.0"
}
group = "com.alttd"
version = "2.1.5"
group = "com.alttd.afkdectector"
version = System.getenv("BUILD_NUMBER") ?: gitCommit()
description = "Altitude AFK Detector plugin."
apply<JavaLibraryPlugin>()
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
tasks {
withType<JavaCompile> {
options.encoding = Charsets.UTF_8.name()
@@ -25,23 +20,82 @@ tasks {
options.encoding = Charsets.UTF_8.name()
}
shadowJar {
dependsOn(getByName("relocateJars") as ConfigureShadowRelocation)
archiveFileName.set("${project.name}-${project.version}.jar")
minimize()
configurations = listOf(project.configurations.shadow.get())
}
build {
dependsOn(shadowJar)
}
create<ConfigureShadowRelocation>("relocateJars") {
target = shadowJar.get()
prefix = "${project.name}.lib"
jar {
archiveFileName.set("${rootProject.name}.jar")
}
}
dependencies {
implementation("com.alttd:Galaxy-API:1.20.1-R0.1-SNAPSHOT")
compileOnly("com.alttd.cosmos:cosmos-api:26.2.build.17-stable") {
isChanging = true
}
compileOnly("de.keyle:mypet-api:4.0.0-SNAPSHOT")
compileOnly("com.alttd:VillagerShopUI:1.1-SNAPSHOT") {
isChanging = true
}
}
fun gitCommit(): String {
return "FIXME"
}
paper {
name = rootProject.name
main = "$group.${rootProject.name}"
description = rootProject.description
bootstrapper = "$group.${rootProject.name}Bootstrap"
version = "${rootProject.version}"
apiVersion = "26.2"
authors = listOf("destro174")
serverDependencies {
register("MyPet") {
required = false
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
}
}
permissions {
register("afkdetector.admin") {
description = "Admin permission for the ${rootProject.name} plugin."
default = BukkitPluginDescription.Permission.Default.FALSE
children = listOf(
"afkdetector.bypass",
"afkdetector.afklist",
"afkdetector.afkcheck",
"afkdetector.notify",
"afkdetector.reload"
)
}
register("afkdetector.bypass") {
description = "Bypass permission for the ${rootProject.name} plugin."
default = BukkitPluginDescription.Permission.Default.FALSE
children = listOf(
"afkdetector.kickexempt"
)
}
register("afkdetector.reload") {
description = "Allows reloading the ${rootProject.name} plugin."
default = BukkitPluginDescription.Permission.Default.FALSE
}
register("afkdetector.kickexempt") {
description = "Bypass permission for being afk kicked."
default = BukkitPluginDescription.Permission.Default.FALSE
}
register("afkdetector.afktime") {
description = "Master permission for custom afk time in the ${rootProject.name} plugin."
default = BukkitPluginDescription.Permission.Default.FALSE
}
register("afkdetector.afkcheck") {
description = "Allows usage of the /afkcheck command."
default = BukkitPluginDescription.Permission.Default.FALSE
}
register("afkdetector.afklist") {
description = "Allows usage of the /afklist command."
default = BukkitPluginDescription.Permission.Default.FALSE
}
register("afkdetector.notify") {
description = "Get notified when a player is afk."
default = BukkitPluginDescription.Permission.Default.FALSE
}
}
}
Binary file not shown.
+7
View File
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+26 -18
View File
@@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +82,11 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -114,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -133,22 +132,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -165,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
@@ -193,16 +198,19 @@ if "$cygwin" || "$msys" ; then
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
Vendored
+14 -12
View File
@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@@ -26,6 +28,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -42,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
@@ -56,22 +59,21 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
+23 -1
View File
@@ -1,9 +1,31 @@
rootProject.name = "AFKDetector"
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").orNull ?: System.getenv("NEXUS_USERNAME")
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").orNull ?: System.getenv("NEXUS_PASSWORD")
dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
maven {
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
credentials {
username = nexusUser
password = nexusPass
}
}
maven {
url = uri("https://repo.alttd.com/repository/alttd/")
credentials {
username = nexusUser
password = nexusPass
}
}
maven("https://repo.papermc.io/repository/maven-public/")
maven {
name = "userderezzedRepoSnapshots"
url = uri("https://repo.userderezzed.dev/snapshots")
}
}
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}
@@ -87,7 +87,7 @@ public class AFKCheckTimer extends BukkitRunnable {
private void resetAFKPlayer(Location pastLocation, Player player, AFKPlayer afkPlayer) {
afkPlayer.setPlayerToSphereCenter(pastLocation);
afkPlayer.setStandingTime(System.currentTimeMillis());
player.setSleepingIgnored(false);
// player.setSleepingIgnored(false);
afkPlayer.resetAFK();
MessageTimer currentTimer = plugin.messageTimers.get(player.getUniqueId());
@@ -98,7 +98,7 @@ public class AFKCheckTimer extends BukkitRunnable {
private void setPlayerAFK(AFKPlayer afkPlayer, Player player) {
afkPlayer.setAFK(player);
player.setSleepingIgnored(true);
// player.setSleepingIgnored(true);
//player.setCanPickupItems(false);
if (Config.AFK_TOGGLE_MESSAGES) {
TagResolver placeholders = TagResolver.resolver(
@@ -4,13 +4,16 @@ import com.alttd.afkdectector.afkplayer.AFKPlayer;
import com.alttd.afkdectector.command.AFKCheckCommand;
import com.alttd.afkdectector.command.AFKListCommand;
import com.alttd.afkdectector.command.ReloadCommand;
import com.alttd.afkdectector.command.RelogCheckCommand;
import com.alttd.afkdectector.config.Config;
import com.alttd.afkdectector.config.Messages;
import com.alttd.afkdectector.config.MessagesConfig;
import com.alttd.afkdectector.trackers.AutoJoinTracker;
import com.alttd.afkdectector.trackers.SuspiciousKickTracker;
import com.alttd.afkdectector.util.Logger;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.event.player.AsyncChatEvent;
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
@@ -25,12 +28,12 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.ScoreboardManager;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -46,6 +49,8 @@ public class AFKDetector extends JavaPlugin implements Listener {
public static MiniMessage miniMessage;
public static boolean myPetEnabled = false;
@Override
public void onEnable() {
try {
@@ -53,11 +58,11 @@ public class AFKDetector extends JavaPlugin implements Listener {
miniMessage = MiniMessage.miniMessage();
loadConfig(null);
getServer().getPluginManager().registerEvents(this, this);
//getCommand("afk").setExecutor(new AFKCommand(this));
getCommand("afklist").setExecutor(new AFKListCommand(this));
getCommand("afkcheck").setExecutor(new AFKCheckCommand(this));
getCommand("reloadafkdetector").setExecutor(new ReloadCommand(this));
registerCommands();
new AFKCheckTimer(this).init();
myPetEnabled = getServer().getPluginManager().isPluginEnabled("MyPet");
} catch (Throwable t) {
getLogger().severe("An error has occured while loading AFKDetector");
if (!(t instanceof ExceptionInInitializerError)) {
@@ -67,6 +72,17 @@ public class AFKDetector extends JavaPlugin implements Listener {
}
}
private void registerCommands() {
LifecycleEventManager<Plugin> manager = this.getLifecycleManager();
manager.registerEventHandler(LifecycleEvents.COMMANDS, event -> {
final Commands commands = event.registrar();
new AFKListCommand().register(commands);
new AFKCheckCommand().register(commands);
new RelogCheckCommand().register(commands);
new ReloadCommand().register(commands);
});
}
@Override
public void onDisable() {
this.getServer().getScheduler().cancelTasks(this);
@@ -183,7 +199,7 @@ public class AFKDetector extends JavaPlugin implements Listener {
Config.reload();
MessagesConfig.reload();
if (sender != null) {
sender.sendMiniMessage("<green>Configuration reloaded", null);
sender.sendRichMessage("<green>Configuration reloaded");
}
}
}
@@ -0,0 +1,13 @@
package com.alttd.afkdectector;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
@SuppressWarnings("UnstableApiUsage")
public class AFKDetectorBootstrap implements PluginBootstrap {
@Override
public void bootstrap(BootstrapContext context) {}
}
@@ -11,6 +11,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Date;
@@ -49,7 +50,7 @@ public class MessageTimer extends BukkitRunnable {
public void run() {
Player player = Bukkit.getPlayer(uuid);
if (plugin.messageTimers.containsKey(uuid)) {
if (player == null || player.hasPermission("afkdetector.kickexempt")) {
if (player == null || player.hasPermission("afkdetector.kickexempt") || isVanished(player)) {
cancel();
return;
}
@@ -59,7 +60,7 @@ public class MessageTimer extends BukkitRunnable {
miniMessage.deserialize(Messages.COUNT_DOWN_TITLE_2.getMessage()));
//Title.Times.of(Config.FADEIN, Config.STAY, Config.STAY);
player.showTitle(title);
player.sendMessage(miniMessage.deserialize(Messages.COUNT_DOWN_MESSAGE.getMessage()));
player.sendRichMessage(Messages.COUNT_DOWN_MESSAGE.getMessage());
}
repeats = repeats - 1;
@@ -88,4 +89,12 @@ public class MessageTimer extends BukkitRunnable {
}
}
}
private boolean isVanished(Player player) {
for (MetadataValue meta : player.getMetadata("vanished")) {
if (meta.asBoolean()) return true;
}
return false;
}
}
@@ -3,6 +3,10 @@ package com.alttd.afkdectector.afkplayer;
import com.alttd.afkdectector.AFKDetector;
import com.alttd.afkdectector.config.Config;
import com.alttd.afkdectector.config.Messages;
import de.Keyle.MyPet.MyPetApi;
import de.Keyle.MyPet.api.entity.Pet;
import de.Keyle.MyPet.api.player.MyPetPlayer;
import de.Keyle.MyPet.api.plugin.MyPetPlugin;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
@@ -94,6 +98,9 @@ public class AFKPlayer {
}
public void setAFK(Player player) {
if (AFKDetector.myPetEnabled)
sendPetAway();
bossBar.setTitle(afkKickSoon);
bossBar.setColor(BarColor.RED);
player.setAfk(true);
@@ -127,4 +134,15 @@ public class AFKPlayer {
double toggleSeconds = TimeUnit.MINUTES.toSeconds(totalAllowedMinutes);
bossBar.setProgress(Math.min(afkSeconds / toggleSeconds, 1));
}
void sendPetAway() {
if (!AFKDetector.myPetEnabled) return;
MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(player);
if (myPetPlayer == null || !myPetPlayer.hasPet() || !myPetPlayer.getPet().getStatus().equals(Pet.PetState.Here))
return;
Pet myPet = myPetPlayer.getPet();
myPet.removePet();
}
}
@@ -3,6 +3,10 @@ package com.alttd.afkdectector.command;
import com.alttd.afkdectector.AFKDetector;
import com.alttd.afkdectector.afkplayer.AFKPlayer;
import com.alttd.afkdectector.config.Messages;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
@@ -21,45 +25,35 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class AFKCheckCommand implements CommandExecutor, TabCompleter {
public class AFKCheckCommand {
private final AFKDetector plugin;
public void register(Commands commands) {
commands.register(
Commands.literal("afkcheck")
.requires(commandSourceStack ->
commandSourceStack.getSender().hasPermission("afkdetector.afkcheck"))
.then(Commands.argument("player", ArgumentTypes.player())
.executes(commandContext -> {
CommandSourceStack sourceStack = commandContext.getSource();
Player target = commandContext.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
public AFKCheckCommand(AFKDetector plugin) {
this.plugin = plugin;
}
MiniMessage miniMessage = AFKDetector.miniMessage;
target.showTitle(Title.title(miniMessage.deserialize(Messages.AFK_CHECK_TITLE.getMessage()),
miniMessage.deserialize(Messages.AFK_CHECK_SUBTITLE.getMessage())));
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (!(args.length > 0)) {
sender.sendMessage(Component.text(command.getUsage(), NamedTextColor.RED));
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if (target == null) {
sender.sendMessage(Component.text(command.getUsage(), NamedTextColor.RED));
return true;
}
MiniMessage miniMessage = AFKDetector.miniMessage;
target.showTitle(Title.title(miniMessage.deserialize(Messages.AFK_CHECK_TITLE.getMessage()),
miniMessage.deserialize(Messages.AFK_CHECK_SUBTITLE.getMessage())));
if (sender instanceof Player player) {
String cmd = "msg " + args[0] + " " + Messages.AFK_CHECK_MESSAGE.getMessage();
PlayerCommandPreprocessEvent commandEvent = new PlayerCommandPreprocessEvent(player, "/" + cmd);
Bukkit.getPluginManager().callEvent(commandEvent);
player.performCommand(cmd);
} else {
Bukkit.dispatchCommand(sender, "msg " + args[0] + " " + Messages.AFK_CHECK_MESSAGE.getMessage());
}
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, String[] strings) {
List<String> completions = new ArrayList<>();
if (strings.length == 1) {
StringUtil.copyPartialMatches(strings[0], plugin.players.values().stream().filter(AFKPlayer::isAFK).map(AFKPlayer::getPlayerName).collect(Collectors.toList()), completions);
}
return null;
if (commandContext.getSource().getSender() instanceof Player player) {
String cmd = "msg " + target.getName() + " " + Messages.AFK_CHECK_MESSAGE.getMessage();
PlayerCommandPreprocessEvent commandEvent = new PlayerCommandPreprocessEvent(player, "/" + cmd);
Bukkit.getPluginManager().callEvent(commandEvent);
player.performCommand(cmd);
} else {
Bukkit.dispatchCommand(commandContext.getSource().getSender(), "msg " + target.getName() + " " + Messages.AFK_CHECK_MESSAGE.getMessage());
}
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
})
)
.build()
, "Perform an afk check on the target."
);
}
}
@@ -4,58 +4,64 @@ import com.alttd.afkdectector.AFKDetector;
import com.alttd.afkdectector.afkplayer.AFKPlayer;
import com.alttd.afkdectector.config.Config;
import com.alttd.afkdectector.config.Messages;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class AFKListCommand implements CommandExecutor, TabCompleter {
public class AFKListCommand {
private final AFKDetector plugin;
public void register(Commands commands) {
commands.register(
Commands.literal("afklist")
.requires(commandSourceStack ->
commandSourceStack.getSender().hasPermission("afkdetector.afkcheck"))
.executes(commandContext -> {
int afkPlayers = 0;
Component message = Component.empty();
MiniMessage miniMessage = AFKDetector.miniMessage;
for (AFKPlayer afkplayer : AFKDetector.getInstance().players.values()) {
long standingTime = afkplayer.getStandingTime();
if (System.currentTimeMillis() - standingTime <= TimeUnit.MINUTES.toMillis(Config.TOGGLE_TIME)) {
continue;
}
public AFKListCommand(AFKDetector plugin) {
this.plugin = plugin;
}
afkPlayers += 1;
message = message.append(Component.newline());
TagResolver templates = TagResolver.resolver(
Placeholder.parsed("player", afkplayer.getPlayerName()),
Placeholder.parsed("afktime", (System.currentTimeMillis() - standingTime) / 1000 + "")
);
Component userinfo = miniMessage.deserialize(Messages.AFK_LIST_ENTRY.getMessage(), templates);
message = message.append(userinfo);
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
int afkPlayers = 0;
Component message = Component.empty();
MiniMessage miniMessage = AFKDetector.miniMessage;
for (AFKPlayer afkplayer : plugin.players.values()) {
long standingTime = afkplayer.getStandingTime();
if (System.currentTimeMillis() - standingTime <= TimeUnit.MINUTES.toMillis(Config.TOGGLE_TIME)) {
continue;
}
TagResolver templates = TagResolver.resolver(
Placeholder.parsed("afkplayers", Integer.toString(afkPlayers))
);
Component component = miniMessage.deserialize(Messages.AFK_LIST.getMessage(), templates);
commandContext.getSource().getSender().sendMessage(component.append(message));
afkPlayers += 1;
message = message.append(Component.newline());
TagResolver templates = TagResolver.resolver(
Placeholder.parsed("player", afkplayer.getPlayerName()),
Placeholder.parsed("afktime", (System.currentTimeMillis() - standingTime) / 1000 + "")
);
Component userinfo = miniMessage.deserialize(Messages.AFK_LIST_ENTRY.getMessage(), templates);
message = message.append(userinfo);
}
TagResolver templates = TagResolver.resolver(
Placeholder.parsed("afkplayers", Integer.toString(afkPlayers))
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
})
.build()
, "List all players that are afk"
);
Component component = miniMessage.deserialize(Messages.AFK_LIST.getMessage(), templates);
sender.sendMessage(component.append(message));
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, String[] strings) {
return null;
}
}
@@ -1,6 +1,7 @@
package com.alttd.afkdectector.command;
import com.alttd.afkdectector.AFKDetector;
import io.papermc.paper.command.brigadier.Commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -9,22 +10,19 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public class ReloadCommand implements CommandExecutor, TabCompleter {
public class ReloadCommand {
private final AFKDetector plugin;
public ReloadCommand(AFKDetector plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
AFKDetector.getInstance().loadConfig(sender);
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, String[] strings) {
return null;
public void register(Commands commands) {
commands.register(
Commands.literal("reloadafkdetector")
.requires(commandSourceStack ->
commandSourceStack.getSender().hasPermission("afkdetector.reload"))
.executes(commandContext -> {
AFKDetector.getInstance().loadConfig(commandContext.getSource().getSender());
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
})
.build()
, "Reload the plugin configuration."
);
}
}
@@ -0,0 +1,59 @@
package com.alttd.afkdectector.command;
import com.alttd.afkdectector.AFKDetector;
import com.alttd.afkdectector.afkplayer.AFKPlayer;
import com.alttd.afkdectector.config.Messages;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class RelogCheckCommand {
public void register(Commands commands) {
commands.register(
Commands.literal("relogcheck")
.requires(commandSourceStack ->
commandSourceStack.getSender().hasPermission("afkdetector.relogcheck"))
.then(Commands.argument("player", ArgumentTypes.player())
.executes(commandContext -> {
CommandSourceStack sourceStack = commandContext.getSource();
Player target = commandContext.getArgument("player", PlayerSelectorArgumentResolver.class).resolve(sourceStack).getFirst();
MiniMessage miniMessage = AFKDetector.miniMessage;
target.showTitle(Title.title(miniMessage.deserialize(Messages.RELOG_CHECK_TITLE.getMessage()),
miniMessage.deserialize(Messages.RELOG_CHECK_SUBTITLE.getMessage())));
if (commandContext.getSource().getSender() instanceof Player player) {
String cmd = "msg " + target.getName() + " " + Messages.RELOG_CHECK_MESSAGE.getMessage();
PlayerCommandPreprocessEvent commandEvent = new PlayerCommandPreprocessEvent(player, "/" + cmd);
Bukkit.getPluginManager().callEvent(commandEvent);
player.performCommand(cmd);
} else {
Bukkit.dispatchCommand(commandContext.getSource().getSender(), "msg " + target.getName() + " " + Messages.RELOG_CHECK_MESSAGE.getMessage());
}
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
})
)
.build()
, "Perform a relog check on the target."
);
}
}
@@ -1,36 +1,172 @@
package com.alttd.afkdectector.config;
import com.alttd.afkdectector.AFKDetector;
import com.alttd.galaxy.configuration.AbstractConfiguration;
import io.leangen.geantyref.TypeToken;
import org.bukkit.Bukkit;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.ConfigurationOptions;
import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
@SuppressWarnings("unused")
public class Config extends AbstractConfiguration {
public class Config {
private Config() {
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + AFKDetector.getInstance().getName()), "config");
}
public static File CONFIG_PATH;
public static final Pattern PATH_PATTERN = Pattern.compile("\\.");
private static final String HEADER = "";
private static File CONFIG_FILE;
public static ConfigurationNode config;
public static YamlConfigurationLoader configLoader;
static Config config;
static int version;
static boolean verbose;
public static void reload() {
config = new Config();
CONFIG_PATH = new File(Bukkit.sharedConfigurationFile(), "AFKDetector");
CONFIG_FILE = new File(CONFIG_PATH, "config.yml");
version = config.getInt("config-version", 1);
config.set("config-version", 1);
configLoader = YamlConfigurationLoader.builder()
.file(CONFIG_FILE)
.nodeStyle(NodeStyle.BLOCK)
.build();
if (!CONFIG_FILE.getParentFile().exists()) {
if(!CONFIG_FILE.getParentFile().mkdirs()) {
return;
}
}
if (!CONFIG_FILE.exists()) {
try {
if(!CONFIG_FILE.createNewFile()) {
return;
}
} catch (IOException error) {
error.printStackTrace();
}
}
config.readConfig(Config.class, null);
try {
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER).shouldCopyDefaults(false));
} catch (IOException e) {
e.printStackTrace();
}
verbose = getBoolean("verbose", true);
version = getInt("config-version", 1);
readConfig(Config.class, null);
try {
configLoader.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void readConfig(Class<?> clazz, Object instance) {
for (Method method : clazz.getDeclaredMethods()) {
if (Modifier.isPrivate(method.getModifiers())) {
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
try {
method.setAccessible(true);
method.invoke(instance);
} catch (InvocationTargetException | IllegalAccessException ex) {
ex.printStackTrace();
}
}
}
}
try {
configLoader.save(config);
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static void saveConfig() {
try {
configLoader.save(config);
} catch (IOException ex) {
ex.printStackTrace();
}
}
private static Object[] splitPath(String key) {
return PATH_PATTERN.split(key);
}
static void set(String path, Object def) {
if(config.node(splitPath(path)).virtual()) {
try {
config.node(splitPath(path)).set(def);
} catch (SerializationException e) {
e.printStackTrace();
}
}
}
private static void setString(String path, String def) {
try {
if(config.node(splitPath(path)).virtual())
config.node(splitPath(path)).set(io.leangen.geantyref.TypeToken.get(String.class), def);
} catch(SerializationException ex) {
ex.printStackTrace();
}
}
private static boolean getBoolean(String path, boolean def) {
set(path, def);
return config.node(splitPath(path)).getBoolean(def);
}
private static double getDouble(String path, double def) {
set(path, def);
return config.node(splitPath(path)).getDouble(def);
}
private static int getInt(String path, int def) {
set(path, def);
return config.node(splitPath(path)).getInt(def);
}
private static String getString(String path, String def) {
setString(path, def);
return config.node(splitPath(path)).getString(def);
}
private static Long getLong(String path, Long def) {
set(path, def);
return config.node(splitPath(path)).getLong(def);
}
private static <T> List<String> getList(String path, T def) {
try {
set(path, def);
return config.node(splitPath(path)).getList(TypeToken.get(String.class));
} catch(SerializationException ex) {
ex.printStackTrace();
}
return new ArrayList<>();
}
protected static ConfigurationNode getNode(String path) {
return config.node(splitPath(path));
}
public static boolean DEBUG_MODE = false;
public static int MAX_DUPLICATE_HISTORY = 5;
private static void settings() {
DEBUG_MODE = config.getBoolean("debug-mode", DEBUG_MODE);
MAX_DUPLICATE_HISTORY = config.getInt("max-duplicate-history", MAX_DUPLICATE_HISTORY);
DEBUG_MODE = getBoolean("debug-mode", DEBUG_MODE);
MAX_DUPLICATE_HISTORY = getInt("max-duplicate-history", MAX_DUPLICATE_HISTORY);
}
public static boolean SLEEP_IGNORE = false;
@@ -47,17 +183,17 @@ public class Config extends AbstractConfiguration {
public static int MAX_REJOIN_FOR_TRACKING = 30;
private static void playerSettings() {
SLEEP_IGNORE = config.getBoolean("player.sleep", SLEEP_IGNORE);
RADIUS = config.getInt("player.radius", RADIUS);
WARNING_TIME = config.getInt("player.warning-time", WARNING_TIME);
TOGGLE_TIME = config.getInt("player.toggle-time", TOGGLE_TIME);
DEFAULT_AFK_TIME = config.getInt("player.afk-time", 5);
MAX_AFK_TIME = config.getInt("player.maxafk-time", 5);
SERVER_FULL = config.getBoolean("player.serverfull", false);
COMMAND_COOL_DOWN = config.getInt("player.commandcooldown", COMMAND_COOL_DOWN);
AFK_TOGGLE_MESSAGES = config.getBoolean("player.afk-toggle-messages", AFK_TOGGLE_MESSAGES);
NOTIFY_STAFF_ON_AFK_KICK = config.getBoolean("player.notify-staff-on-afk-kick", NOTIFY_STAFF_ON_AFK_KICK);
MAX_REJOIN_FOR_TRACKING = config.getInt("tracking.max-seconds-for-tracking", MAX_REJOIN_FOR_TRACKING);
SLEEP_IGNORE = getBoolean("player.sleep", SLEEP_IGNORE);
RADIUS = getInt("player.radius", RADIUS);
WARNING_TIME = getInt("player.warning-time", WARNING_TIME);
TOGGLE_TIME = getInt("player.toggle-time", TOGGLE_TIME);
DEFAULT_AFK_TIME = getInt("player.afk-time", 5);
MAX_AFK_TIME = getInt("player.maxafk-time", 5);
SERVER_FULL = getBoolean("player.serverfull", false);
COMMAND_COOL_DOWN = getInt("player.commandcooldown", COMMAND_COOL_DOWN);
AFK_TOGGLE_MESSAGES = getBoolean("player.afk-toggle-messages", AFK_TOGGLE_MESSAGES);
NOTIFY_STAFF_ON_AFK_KICK = getBoolean("player.notify-staff-on-afk-kick", NOTIFY_STAFF_ON_AFK_KICK);
MAX_REJOIN_FOR_TRACKING = getInt("tracking.max-seconds-for-tracking", MAX_REJOIN_FOR_TRACKING);
}
public static boolean COUNT_DOWN_ENABLED = false;
@@ -69,21 +205,21 @@ public class Config extends AbstractConfiguration {
public static String KICK_COMMAND = "kickfrombungee %player% &cYou have been afk for %afktime% minutes.";
private static void countdownSettings() {
COUNT_DOWN_ENABLED = config.getBoolean("countdown.enabled", COUNT_DOWN_ENABLED);
FADEIN = config.getInt("countdown.fadein", FADEIN);
STAY = config.getInt("countdown.stay", STAY);
FADEOUT = config.getInt("countdown.fadeout", FADEOUT);
MESSAGE_DELAY = config.getInt("countdown.message-delay", MESSAGE_DELAY);
MESSAGE_REPEATS = config.getInt("countdown.message-repeats", MESSAGE_REPEATS);
KICK_COMMAND = config.getString("countdown.kick-command", KICK_COMMAND);
COUNT_DOWN_ENABLED = getBoolean("countdown.enabled", COUNT_DOWN_ENABLED);
FADEIN = getInt("countdown.fadein", FADEIN);
STAY = getInt("countdown.stay", STAY);
FADEOUT = getInt("countdown.fadeout", FADEOUT);
MESSAGE_DELAY = getInt("countdown.message-delay", MESSAGE_DELAY);
MESSAGE_REPEATS = getInt("countdown.message-repeats", MESSAGE_REPEATS);
KICK_COMMAND = getString("countdown.kick-command", KICK_COMMAND);
}
public static boolean CHAT_WILL_CANCEL = true;
public static boolean COMMAND_WILL_CANCEL = true;
private static void eventSettings() {
CHAT_WILL_CANCEL = config.getBoolean("events.chat", CHAT_WILL_CANCEL);
COMMAND_WILL_CANCEL = config.getBoolean("events.commands", COMMAND_WILL_CANCEL);
CHAT_WILL_CANCEL = getBoolean("events.chat", CHAT_WILL_CANCEL);
COMMAND_WILL_CANCEL = getBoolean("events.commands", COMMAND_WILL_CANCEL);
}
public static int SPAWN_MAX_X = 250;
@@ -93,11 +229,11 @@ public class Config extends AbstractConfiguration {
public static int EXTRA_MIN_IN_SPAWN = 10;
private static void spawnSettings() {
SPAWN_MAX_X = config.getInt("spawn.max-x", SPAWN_MAX_X);
SPAWN_MIN_X = config.getInt("spawn.min-x", SPAWN_MIN_X);
SPAWN_MAX_Z = config.getInt("spawn.max-z", SPAWN_MAX_Z);
SPAWN_MIN_Z = config.getInt("spawn.min-z", SPAWN_MIN_Z);
EXTRA_MIN_IN_SPAWN = config.getInt("spawn.extra-time", EXTRA_MIN_IN_SPAWN);
SPAWN_MAX_X = getInt("spawn.max-x", SPAWN_MAX_X);
SPAWN_MIN_X = getInt("spawn.min-x", SPAWN_MIN_X);
SPAWN_MAX_Z = getInt("spawn.max-z", SPAWN_MAX_Z);
SPAWN_MIN_Z = getInt("spawn.min-z", SPAWN_MIN_Z);
EXTRA_MIN_IN_SPAWN = getInt("spawn.extra-time", EXTRA_MIN_IN_SPAWN);
}
}
@@ -19,6 +19,9 @@ public enum Messages {
AFK_CHECK_TITLE("afkcheck-title", "AFK CHECK"),
AFK_CHECK_SUBTITLE("afkcheck-subtitle", "Please respond to the dm from staff!"),
AFK_CHECK_MESSAGE("afkcheck-message", "Hey, since you're near a farm and not moving. I'm making sure you aren't afk. Please respond to me if you're not AFK."),
RELOG_CHECK_TITLE("relogcheck-title", "AFK CHECK"),
RELOG_CHECK_SUBTITLE("relogcheck-subtitle", "Please respond to the dm from staff!"),
RELOG_CHECK_MESSAGE("relogcheck-message", "Hey, since you're near a farm and not moving. I'm making sure you aren't afk. Please respond to me if you're not AFK."),
AFK_KICK_STAFF_MESSAGE("afkkick-staff-messsge", "<gold><player> got afk kicked after being afk for <afk_time> minutes."),
SUSPICIOUS_KICK_COUNT("afkkick-suspicious-message", "<gold><player> has had <count> suspicious AFK kicks since last reboot."),
AFK_SOON_BOSS_BAR("afk-soon-boss-bar", "<dark_aqua>Time until AFK.</dark_aqua>"),
@@ -1,37 +1,100 @@
package com.alttd.afkdectector.config;
import com.alttd.afkdectector.AFKDetector;
import com.alttd.galaxy.configuration.AbstractConfiguration;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.ConfigurationOptions;
import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File;
import java.io.IOException;
@SuppressWarnings("unused")
public class MessagesConfig extends AbstractConfiguration {
private MessagesConfig() {
super(new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + AFKDetector.getInstance().getName()), "messages");
}
public class MessagesConfig {
private static final String HEADER = "";
private static File CONFIG_FILE;
public static ConfigurationNode config;
public static YamlConfigurationLoader configLoader;
static MessagesConfig config;
static int version;
public static void reload() {
config = new MessagesConfig();
CONFIG_FILE = new File(Config.CONFIG_PATH, "messages.yml");
version = config.getInt("config-version", 1);
config.set("config-version", 1);
configLoader = YamlConfigurationLoader.builder()
.file(CONFIG_FILE)
.nodeStyle(NodeStyle.BLOCK)
.build();
if (!CONFIG_FILE.getParentFile().exists()) {
if(!CONFIG_FILE.getParentFile().mkdirs()) {
return;
}
}
if (!CONFIG_FILE.exists()) {
try {
if(!CONFIG_FILE.createNewFile()) {
return;
}
} catch (IOException error) {
error.printStackTrace();
}
}
config.readConfig(MessagesConfig.class, null);
try {
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER).shouldCopyDefaults(false));
} catch (IOException e) {
e.printStackTrace();
}
Config.readConfig(MessagesConfig.class, null);
try {
configLoader.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean DEBUG_MODE = false;
public static void saveConfig() {
try {
configLoader.save(config);
} catch (IOException ex) {
ex.printStackTrace();
}
}
private static void settings() {
DEBUG_MODE = config.getBoolean("debug-mode", DEBUG_MODE);
private static Object[] splitPath(String key) {
return Config.PATH_PATTERN.split(key);
}
private static void set(String path, Object def) {
if(config.node(splitPath(path)).virtual()) {
try {
config.node(splitPath(path)).set(def);
} catch (SerializationException e) {
e.printStackTrace();
}
}
}
private static void setString(String path, String def) {
try {
if(config.node(splitPath(path)).virtual())
config.node(splitPath(path)).set(io.leangen.geantyref.TypeToken.get(String.class), def);
} catch(SerializationException ex) {
ex.printStackTrace();
}
}
private static String getString(String path, String def) {
setString(path, def);
return config.node(splitPath(path)).getString(def);
}
private static void loadMessages() {
for (Messages message : Messages.values()) {
message.setMessage(config.getString(message.getKey(), message.getMessage()));
message.setMessage(getString(message.getKey(), message.getMessage()));
}
}
}
@@ -1,28 +0,0 @@
package com.alttd.afkdectector.util;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import java.util.logging.Level;
public class Logger {
public static void info(String str) {
log(Level.INFO, "&e" + str);
}
public static void warn(String str) {
log(Level.SEVERE, "&6" + str);
}
public static void severe(String str) {
log(Level.SEVERE, "&c" + str);
}
public static void log(Level level, String str) {
Bukkit.getLogger().log(level,
ChatColor.translateAlternateColorCodes('&',
"&r " + str));
}
}
View File
-59
View File
@@ -1,59 +0,0 @@
main: com.alttd.afkdectector.AFKDetector
name: AFKDetector
version: 2.0
api-version: 1.18
author: Destro174
description: Checks if a player is afk.
commands:
afklist:
description: Gives a list of all afk players
permission: afkdetector.afklist
permission-message: You do not have permission!
usage: /afklist
afkcheck:
description: Sends and afkcheck message to the target
permission: afkdetector.afkcheck
permission-message: You do not have permission!
usage: /afkcheck <target>
reloadafkdetector:
description: Reloads the plugin config
permission: afkdetector.reload
permission-message: You do not have permission!
usage: /afkdetectorreload
permissions:
afkdetector.admin:
default: op
description: Implies all permissions.
children:
afkdetector.bypass: true
afkdetector.afklist: true
afkdetector.afkcheck: true
afkdetector.notify: true
afkdetector.reload: true
afkdetector.bypass:
description: Bypass the AFKplugin.
default: op
children:
afkdetector.kickexempt: true
afkdetector.reload:
description: Allows reloading the afkdetector plugin config.
default: op
afkdetector.kickexempt:
description: Doesn't kick you automatically for AFK.
default: op
afkdetector.afktime:
description: Master permission for custom times.
default: false
afkdetector.afkcheck:
description: Allows the usage of /afkcheck command.
default: false
afkdetector.afklist:
description: Allows the usage of /afklist command.
default: false
afkdetector.notify:
description: Get output when a player goes afk.
default: false