diff --git a/README.md b/README.md index 7402b87..795b6d8 100644 --- a/README.md +++ b/README.md @@ -6,41 +6,4 @@ ## Description -Template stolen from **Anuken/ExamplePlugin** lol... - -This template features some cool stuff such as: -- [Jitpack](https://jitpack.io/) support. -- Gradle tasks for testing: - - `gradlew moveJar` Move the output jar to your server mod directory. - - `gradlew runServer` Start the server in a new cmd. - - `gradlew deployJar` Executes `moveJar` and `runServer`. -- GitHub action for easier release and Jitpack usage: - - You just have to run the `Release` workflow manually, - it will automatically take the plugin version in your plugin.json file and upload the jar. - -## Tips and nice things to know - -- When you use this template, make sure you change the information in `plugin.json` - and set the `serverDirectoryPath`, `group` and `mindustryVersion` properties in `build.gradle`. - There is also the `rootProject.name` property in `settings.gradle`. - -- The plugin compiles to java 8 for compatibility reasons, - but nothing keeps you to change the compiler target or source to a higher jdk. - -- For faster testing, I recommend you to add an exit statement at the end of your server startup script such as: - -`run_server.bat` -```batch -@echo off -java -jar server.jar -exit -``` - -`run_server.sh` -```shell -#!/usr/bin/env bash -java -jar server.jar -exit -``` - -Thank you for using this template ! +Kick your useless teammates... diff --git a/build.gradle b/build.gradle index 655e80a..d1d0dc1 100644 --- a/build.gradle +++ b/build.gradle @@ -54,9 +54,6 @@ dependencies{ compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion" compileOnly "com.github.Anuken.Mindustry:core:$mindustryVersion" - // Distributor Lib - implementation "fr.xpdustry.Distributor:core:v0.5" - // Unit Testing testImplementation "com.github.Anuken.Arc:arc-core:$mindustryVersion" testImplementation "com.github.Anuken.Mindustry:core:$mindustryVersion" @@ -77,15 +74,12 @@ java{ } jar{ - // Always include the plugin.json first when working with other plugins as dependencies - from "plugin.json" - // The following line is required from configurations.runtimeClasspath.collect{ it.isDirectory() ? it : zipTree(it) } - duplicatesStrategy = DuplicatesStrategy.EXCLUDE + from "plugin.json" } @@ -163,7 +157,15 @@ publishing{ name = metadata.displayName artifactId = metadata.name description = metadata.description - url = "https://github.com/$metadata.repo" + + url = { + if(metadata.repo != null && !metadata.repo.isEmpty()){ + return "https://github.com/$metadata.repo" + }else{ + println "Warning, the repo is unset" + return null + } + }.call() licenses{ license{ diff --git a/plugin.json b/plugin.json index feceb75..f3ec25e 100644 --- a/plugin.json +++ b/plugin.json @@ -1,13 +1,13 @@ { - "name": "survivalpvp-plugin", - "displayName": "Xpdustry SurvivalPvp Plugin", + "name": "xpdustry-afk-plugin", + "displayName": "Xpdustry AfkPlugin", "author": "Phinner", - "description": "Admin abuse lol...", - "version": "0.2", + "description": "Kick afk bois.", + "version": "1.0", "minGameVersion": "105", "hidden": true, "java": true, - "main": "fr.xpdustry.plugins.survivalpvp.SurvivalPvpPlugin", - "repo": "Xpdustry/SurvivalPvpPlugin", + "main": "fr.xpdustry.plugins.afk.AfkPlugin", + "repo": "Xpdustry/AfkPlugin", "dependencies": [] } diff --git a/settings.gradle b/settings.gradle index 2ae8810..3c4cea8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = "SurvivalPvpPlugin" +rootProject.name = "AfkPlugin" diff --git a/src/main/java/fr/xpdustry/plugins/afk/AfkPlugin.java b/src/main/java/fr/xpdustry/plugins/afk/AfkPlugin.java new file mode 100644 index 0000000..2c47cce --- /dev/null +++ b/src/main/java/fr/xpdustry/plugins/afk/AfkPlugin.java @@ -0,0 +1,88 @@ +package fr.xpdustry.plugins.afk; + +import arc.*; +import arc.struct.*; +import arc.util.*; + +import mindustry.gen.*; +import mindustry.mod.*; +import mindustry.game.EventType.*; + +import static arc.util.Log.*; +import static mindustry.Vars.*; + + +@SuppressWarnings("unused") // <- Only used for this template so IntelliJ stop screaming at me... +public class AfkPlugin extends Plugin{ + public static boolean enabled = true; + public static int maxAfkPeriod = 10; + public static final ObjectMap kicker = new ObjectMap<>(); + /** Don't need to iterate every tick, every second is enough... */ + public static final Interval updater = new Interval(); + + @Override + public void init(){ + Events.on(PlayerJoin.class, e -> { + kicker.put(e.player, new PosWatcher()); + }); + + Events.on(PlayerLeave.class, e -> { + kicker.remove(e.player); + }); + + Events.run(Trigger.update, () -> { + if(enabled && updater.get(Time.toSeconds)){ + kicker.each((player, watcher) -> { + if(watcher.isAFK(player)){ + player.kick("You have been AFK for " + maxAfkPeriod + "minute" + (maxAfkPeriod > 1 ? "s" : "")); + } + }); + } + }); + } + + public static class PosWatcher{ + /** Packed coordinates */ + private int lastPos = 0; + public final Interval timer = new Interval(); + + public boolean isAFK(Player player){ + int currentPos = (player.tileY() * world.height()) + player.tileX(); + if(currentPos != lastPos) timer.reset(0, 0); + lastPos = currentPos; + return timer.get(maxAfkPeriod * Time.toMinutes); + } + } + + @Override + public void registerServerCommands(CommandHandler handler){ + handler.register("kicker", "