22
33import com .mohistmc .MohistConfig ;
44import java .util .concurrent .ScheduledExecutorService ;
5+ import java .util .concurrent .ScheduledFuture ;
56import java .util .concurrent .ScheduledThreadPoolExecutor ;
67import java .util .concurrent .TimeUnit ;
78import java .util .concurrent .atomic .AtomicInteger ;
@@ -21,26 +22,38 @@ public class EntityClear {
2122
2223 public static final ScheduledExecutorService ENTITYCLEAR_ITEM = new ScheduledThreadPoolExecutor (1 , new NamedThreadFactory ("EntityClear - Item" ));
2324 public static final ScheduledExecutorService ENTITYCLEAR_MONSTER = new ScheduledThreadPoolExecutor (1 , new NamedThreadFactory ("EntityClear - Item" ));
25+ private static final ScheduledExecutorService COUNTDOWN_SERVICE = new ScheduledThreadPoolExecutor (1 , new NamedThreadFactory ("EntityClear-Countdown" ));
26+ private static final AtomicInteger countdownSeconds = new AtomicInteger (15 );
27+ private static ScheduledFuture <?> countdownFuture ;
2428
2529 public static void start () {
26- if (MohistConfig .clear_item ) {
30+ if (MohistConfig .clear_enable ) {
2731 ENTITYCLEAR_ITEM .scheduleAtFixedRate (() -> {
2832 if (MinecraftServer .getServer ().hasStopped ()) {
2933 return ;
3034 }
31- run_item ();
32- }, 1000 * 60 , 1000L * MohistConfig .clear_item_time , TimeUnit .MILLISECONDS );
33- }
34- if (MohistConfig .clear_monster ) {
35- ENTITYCLEAR_MONSTER .scheduleAtFixedRate (() -> {
36- if (MinecraftServer .getServer ().hasStopped ()) {
37- return ;
38- }
39- run_monster ();
40- }, 1000 * 60 , 1000L * MohistConfig .clear_monster_time , TimeUnit .MILLISECONDS );
35+ startCountdown ();
36+ }, MohistConfig .clear_time , MohistConfig .clear_time , TimeUnit .SECONDS );
4137 }
4238 }
4339
40+ public static void startCountdown () {
41+ countdownFuture = COUNTDOWN_SERVICE .scheduleAtFixedRate (() -> {
42+ int remaining = countdownSeconds .decrementAndGet ();
43+ if (remaining > 0 ) {
44+ String msg = MohistConfig .clear_countdown_msg
45+ .replace ("&" , "§" )
46+ .replace ("%seconds%" , String .valueOf (remaining ));
47+ if (remaining == 14 || remaining == 10 || remaining < 4 ) Bukkit .broadcastMessage (msg );
48+ } else {
49+ countdownSeconds .set (15 );
50+ if (MohistConfig .clear_item )run_item ();
51+ if (MohistConfig .clear_monster )run_monster ();
52+ countdownFuture .cancel (false );
53+ }
54+ }, 0 , 1 , TimeUnit .SECONDS );
55+ }
56+
4457 public static void stop () {
4558 ENTITYCLEAR_ITEM .shutdown ();
4659 ENTITYCLEAR_MONSTER .shutdown ();
0 commit comments