This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
generated from xpdustry/template-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
106 additions
and
563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rootProject.name = "SurvivalPvpPlugin" | ||
rootProject.name = "AfkPlugin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
197
src/main/java/fr/xpdustry/plugins/survivalpvp/SurvivalPvpPlugin.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.