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

Commit

Permalink
init push
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Jul 23, 2021
1 parent bf56c44 commit 154b580
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 563 deletions.
39 changes: 1 addition & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
18 changes: 10 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}


Expand Down Expand Up @@ -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{
Expand Down
12 changes: 6 additions & 6 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -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": []
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = "SurvivalPvpPlugin"
rootProject.name = "AfkPlugin"
88 changes: 88 additions & 0 deletions src/main/java/fr/xpdustry/plugins/afk/AfkPlugin.java
Original file line number Diff line number Diff line change
@@ -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<Player, PosWatcher> 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", "<time/status> [arg]", "Manage the AFK kicker.", (args) -> {
switch(args[0]){
case "time":
if(args.length == 1){
info("The current maximum afk time is @ minute@.", maxAfkPeriod, (maxAfkPeriod > 1 ? "s" : ""));
}else{
try{
maxAfkPeriod = Integer.parseInt(args[1]);
info("The new maximum afk period is @ minute@.", maxAfkPeriod, (maxAfkPeriod > 1 ? "s" : ""));
}catch(NumberFormatException e){
err("You inputted an invalid number.");
}
}
break;

case "status":
if(args.length == 1){
info("The AFK kicker is @.", enabled ? "enabled" : "disabled");
}else{
enabled = args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("enabled");
info("The AFK kicker is now @.", enabled ? "enabled" : "disabled");
}
break;

default:
info("Your command is invalid.");
}
});
}
}
197 changes: 0 additions & 197 deletions src/main/java/fr/xpdustry/plugins/survivalpvp/SurvivalPvpPlugin.java

This file was deleted.

Loading

0 comments on commit 154b580

Please sign in to comment.