Added boss bar and blocked more spawning
This commit is contained in:
parent
a482064e50
commit
9bbc4882a0
|
|
@ -3,7 +3,7 @@ rootProject.name = "AFKDetector"
|
|||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
||||
maven("https://dev.alttd.com/snapshots") // Altitude - Galaxy
|
||||
}
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@ public class AFKCheckTimer extends BukkitRunnable {
|
|||
private void resetAFKPlayer(Location pastLocation, Player player, AFKPlayer afkPlayer) {
|
||||
afkPlayer.setPlayerToSphereCenter(pastLocation);
|
||||
afkPlayer.setStandingTime(System.currentTimeMillis());
|
||||
afkPlayer.unWarnPlayer(player);
|
||||
afkPlayer.unWarnPlayer();
|
||||
player.setSleepingIgnored(false);
|
||||
plugin.AFKPlayers.removeEntry(player.getName());
|
||||
afkPlayer.ResetAFK();
|
||||
afkPlayer.ResetAFK(player);
|
||||
|
||||
MessageTimer currentTimer = plugin.messageTimers.get(player.getUniqueId());
|
||||
if (currentTimer != null) {
|
||||
|
|
@ -80,7 +80,7 @@ public class AFKCheckTimer extends BukkitRunnable {
|
|||
}
|
||||
|
||||
private void setPlayerAFK(AFKPlayer afkPlayer, Player player) {
|
||||
afkPlayer.setAFK(true);
|
||||
afkPlayer.setAFK(player);
|
||||
player.setSleepingIgnored(true);
|
||||
//player.setCanPickupItems(false);
|
||||
plugin.AFKPlayers.addEntry(player.getName());
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ public class AFKDetector extends JavaPlugin implements Listener {
|
|||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
getPlayer(player).ResetAFK();
|
||||
getPlayer(player).ResetAFK(player);
|
||||
messageHistory.addEntry(uuid, message);
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ public class AFKDetector extends JavaPlugin implements Listener {
|
|||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
getPlayer(player).ResetAFK();
|
||||
getPlayer(player).ResetAFK(player);
|
||||
commandHistory.addEntry(uuid, command);
|
||||
}
|
||||
|
||||
|
|
@ -222,7 +222,12 @@ public class AFKDetector extends JavaPlugin implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onMobSpawn(CreatureSpawnEvent event) {
|
||||
if (!event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL))
|
||||
CreatureSpawnEvent.SpawnReason spawnReason = event.getSpawnReason();
|
||||
if (!spawnReason.equals(CreatureSpawnEvent.SpawnReason.NATURAL)
|
||||
&& !spawnReason.equals(CreatureSpawnEvent.SpawnReason.RAID)
|
||||
&& !spawnReason.equals(CreatureSpawnEvent.SpawnReason.SPAWNER)
|
||||
&& !spawnReason.equals(CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE)
|
||||
&& !spawnReason.equals(CreatureSpawnEvent.SpawnReason.VILLAGE_INVASION))
|
||||
return;
|
||||
List<UUID> players = event.getEntity().getLocation().getNearbyPlayers(96).stream().map(Player::getUniqueId).collect(Collectors.toList()); //assuming 6 render distance
|
||||
if (afkPlayers.containsNonAfkPlayer(players)) {
|
||||
|
|
|
|||
|
|
@ -4,13 +4,19 @@ import com.alttd.afkdectector.AFKDetector;
|
|||
import com.alttd.afkdectector.config.Config;
|
||||
import com.alttd.afkdectector.config.Messages;
|
||||
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.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AFKPlayer {
|
||||
|
||||
|
|
@ -22,6 +28,7 @@ public class AFKPlayer {
|
|||
private boolean isAFK;
|
||||
private boolean isWarned;
|
||||
private final AFKPlayers afkPlayers;
|
||||
private final BossBar bossBar;
|
||||
|
||||
public AFKPlayer(Player player, AFKDetector plugin, AFKPlayers afkPlayers) {
|
||||
this.playerName = player.getName();
|
||||
|
|
@ -31,6 +38,7 @@ public class AFKPlayer {
|
|||
this.afkTime = plugin.getAllowedAFKTime(player);
|
||||
this.isAFK = false;
|
||||
this.afkPlayers = afkPlayers;
|
||||
this.bossBar = Bukkit.createBossBar("Time until AFK", BarColor.PURPLE, BarStyle.SOLID);
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
|
|
@ -69,8 +77,10 @@ public class AFKPlayer {
|
|||
return x < Config.SPAWN_MAX_X && x > Config.SPAWN_MIN_X && z < Config.SPAWN_MAX_Z && z > Config.SPAWN_MIN_Z;
|
||||
}
|
||||
|
||||
public void setAFK(boolean bool) {
|
||||
isAFK = bool;
|
||||
public void setAFK(Player player) {
|
||||
bossBar.setTitle("§cAFK");
|
||||
// player.setAfk(true);
|
||||
isAFK = true;
|
||||
afkPlayers.addAFKPlayer(uuid);
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +88,7 @@ public class AFKPlayer {
|
|||
return isAFK;
|
||||
}
|
||||
|
||||
public void ResetAFK() {
|
||||
public void ResetAFK(Player player) {
|
||||
if (isAFK && Config.AFK_TOGGLE_MESSAGES) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("player", playerName)
|
||||
|
|
@ -87,21 +97,35 @@ public class AFKPlayer {
|
|||
Bukkit.broadcast(component, "afkdetector.notify");
|
||||
}
|
||||
standingTime = System.currentTimeMillis();
|
||||
Player player = Bukkit.getPlayer(getPlayerUuid());
|
||||
playerToSphereCenter = (player == null) ? null : player.getLocation();
|
||||
// player.setAfk(false);
|
||||
playerToSphereCenter = player.getLocation();
|
||||
isAFK = false;
|
||||
bossBar.removeAll();
|
||||
afkPlayers.removeAFKPlayer(uuid);
|
||||
}
|
||||
|
||||
public void warnPlayer(Player player) {
|
||||
updateBossBar();
|
||||
if (isWarned)
|
||||
return;
|
||||
player.sendMessage("You will go afk in a bit (placeholder message)");
|
||||
Component deserialize = MiniMessage.miniMessage().deserialize("<dark_aqua>Time until AFK.</dark_aqua>");
|
||||
String text = LegacyComponentSerializer.builder().build().serialize(deserialize);
|
||||
bossBar.setTitle(text);
|
||||
bossBar.addPlayer(player);
|
||||
isWarned = true;
|
||||
}
|
||||
|
||||
public void unWarnPlayer(Player player) {
|
||||
player.sendMessage("You won't be going afk for another 7 min (placeholder message)");
|
||||
public void updateBossBar() {
|
||||
double afkSeconds = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - getStandingTime());
|
||||
double toggleSeconds = TimeUnit.MINUTES.toSeconds(Config.TOGGLE_TIME);
|
||||
double percentageAFK = Math.min(afkSeconds / toggleSeconds, 1);
|
||||
bossBar.setProgress(percentageAFK);
|
||||
}
|
||||
|
||||
public void unWarnPlayer() {
|
||||
if (!isWarned)
|
||||
return;
|
||||
bossBar.removeAll();
|
||||
isWarned = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user