Send pet away when player goes AFK
This commit is contained in:
parent
a862cbe21f
commit
4a21cb3d33
|
|
@ -44,4 +44,5 @@ tasks {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("com.alttd:Galaxy-API:1.20.1-R0.1-SNAPSHOT")
|
implementation("com.alttd:Galaxy-API:1.20.1-R0.1-SNAPSHOT")
|
||||||
|
compileOnly("de.keyle:mypet:3.11-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
@ -46,6 +46,8 @@ public class AFKDetector extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
public static MiniMessage miniMessage;
|
public static MiniMessage miniMessage;
|
||||||
|
|
||||||
|
public static boolean myPetEnabled = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -58,6 +60,7 @@ public class AFKDetector extends JavaPlugin implements Listener {
|
||||||
getCommand("afkcheck").setExecutor(new AFKCheckCommand(this));
|
getCommand("afkcheck").setExecutor(new AFKCheckCommand(this));
|
||||||
getCommand("reloadafkdetector").setExecutor(new ReloadCommand(this));
|
getCommand("reloadafkdetector").setExecutor(new ReloadCommand(this));
|
||||||
new AFKCheckTimer(this).init();
|
new AFKCheckTimer(this).init();
|
||||||
|
myPetEnabled = getServer().getPluginManager().isPluginEnabled("MyPet");
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
getLogger().severe("An error has occured while loading AFKDetector");
|
getLogger().severe("An error has occured while loading AFKDetector");
|
||||||
if (!(t instanceof ExceptionInInitializerError)) {
|
if (!(t instanceof ExceptionInInitializerError)) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ package com.alttd.afkdectector.afkplayer;
|
||||||
import com.alttd.afkdectector.AFKDetector;
|
import com.alttd.afkdectector.AFKDetector;
|
||||||
import com.alttd.afkdectector.config.Config;
|
import com.alttd.afkdectector.config.Config;
|
||||||
import com.alttd.afkdectector.config.Messages;
|
import com.alttd.afkdectector.config.Messages;
|
||||||
|
import de.Keyle.MyPet.MyPetApi;
|
||||||
|
import de.Keyle.MyPet.api.entity.MyPet;
|
||||||
|
import de.Keyle.MyPet.api.player.MyPetPlayer;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
@ -94,6 +97,7 @@ public class AFKPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAFK(Player player) {
|
public void setAFK(Player player) {
|
||||||
|
sendPetAway();
|
||||||
bossBar.setTitle(afkKickSoon);
|
bossBar.setTitle(afkKickSoon);
|
||||||
bossBar.setColor(BarColor.RED);
|
bossBar.setColor(BarColor.RED);
|
||||||
player.setAfk(true);
|
player.setAfk(true);
|
||||||
|
|
@ -113,7 +117,7 @@ public class AFKPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warnPlayer(Player player) {
|
public void warnPlayer(Player player) {
|
||||||
updateBossBarProgress(Config.TOGGLE_TIME);
|
if (AFKDetector.myPetEnabled) updateBossBarProgress(Config.TOGGLE_TIME);
|
||||||
if (isWarned)
|
if (isWarned)
|
||||||
return;
|
return;
|
||||||
bossBar.setColor(BarColor.PURPLE);
|
bossBar.setColor(BarColor.PURPLE);
|
||||||
|
|
@ -127,4 +131,14 @@ public class AFKPlayer {
|
||||||
double toggleSeconds = TimeUnit.MINUTES.toSeconds(totalAllowedMinutes);
|
double toggleSeconds = TimeUnit.MINUTES.toSeconds(totalAllowedMinutes);
|
||||||
bossBar.setProgress(Math.min(afkSeconds / toggleSeconds, 1));
|
bossBar.setProgress(Math.min(afkSeconds / toggleSeconds, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendPetAway() {
|
||||||
|
MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(player);
|
||||||
|
|
||||||
|
if (myPetPlayer == null || !myPetPlayer.hasMyPet() || !myPetPlayer.getMyPet().getStatus().equals(MyPet.PetState.Here))
|
||||||
|
return;
|
||||||
|
|
||||||
|
MyPet myPet = myPetPlayer.getMyPet();
|
||||||
|
myPet.removePet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ name: AFKDetector
|
||||||
version: 2.0
|
version: 2.0
|
||||||
api-version: 1.18
|
api-version: 1.18
|
||||||
author: Destro174
|
author: Destro174
|
||||||
|
softdepend:
|
||||||
|
- MyPet
|
||||||
|
|
||||||
description: Checks if a player is afk.
|
description: Checks if a player is afk.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user