44import me .nik .combatplus .files .Config ;
55import me .nik .combatplus .managers .MsgType ;
66import me .nik .combatplus .utils .Messenger ;
7- import me .nik .combatplus .utils .MiscUtils ;
87import me .nik .combatplus .utils .WorldUtils ;
98import net .md_5 .bungee .api .ChatMessageType ;
109import net .md_5 .bungee .api .chat .TextComponent ;
@@ -25,30 +24,28 @@ public class GoldenApple implements Listener {
2524 private final CombatPlus plugin ;
2625 private final WorldUtils worldUtils = new WorldUtils ();
2726
28- private final HashMap <UUID , Long > cooldown = new HashMap <>();
29-
30- public static String papiCooldown = "Ready" ;
27+ private static final HashMap <UUID , Long > cooldown = new HashMap <>();
3128
3229 public GoldenApple (CombatPlus plugin ) {
3330 this .plugin = plugin ;
3431 }
3532
36- private void taskRun ( UUID uuid ) {
37- cooldown . put ( uuid , System . currentTimeMillis ());
38- new BukkitRunnable () {
33+ /*
34+ This Listener adds a cooldown between eating Golden Apples
35+ */
3936
40- @ Override
41- public void run () {
37+ public static String getCooldown (UUID uuid ) {
38+ if (cooldown .containsKey (uuid )) {
39+ long secondsleft = ((cooldown .get (uuid ) / 1000 ) + Config .Setting .COOLDOWN_GOLDEN_APPLE_COOLDOWN .getInt ()) - (System .currentTimeMillis () / 1000 );
40+ if (secondsleft < 1 ) {
4241 cooldown .remove (uuid );
43- papiCooldown = "Ready" ;
42+ return "Ready" ;
4443 }
45- }.runTaskLaterAsynchronously (plugin , Config .Setting .COOLDOWN_GOLDEN_APPLE_COOLDOWN .getInt () * 20 );
44+ return secondsleft + "s" ;
45+ }
46+ return "Ready" ;
4647 }
4748
48- /*
49- This Listener adds a cooldown between eating Golden Apples
50- */
51-
5249 @ EventHandler (ignoreCancelled = true )
5350 public void onEatGoldenApple (PlayerItemConsumeEvent e ) {
5451 if (worldUtils .gappleDisabledWorlds (e .getPlayer ())) return ;
@@ -59,12 +56,13 @@ public void onEatGoldenApple(PlayerItemConsumeEvent e) {
5956 if (cooldown .containsKey (p )) {
6057 e .setCancelled (true );
6158 long secondsleft = ((cooldown .get (p ) / 1000 ) + Config .Setting .COOLDOWN_GOLDEN_APPLE_COOLDOWN .getInt ()) - (System .currentTimeMillis () / 1000 );
59+ if (secondsleft < 1 ) {
60+ cooldown .remove (p );
61+ return ;
62+ }
6263 player .sendMessage (MsgType .GOLDEN_APPLE_COOLDOWN .getMessage ().replaceAll ("%seconds%" , String .valueOf (secondsleft )));
6364 } else {
64- taskRun (p );
65- if (MiscUtils .isPlaceholderApiEnabled ()) {
66- setupPlaceholder (p );
67- }
65+ cooldown .put (p , System .currentTimeMillis ());
6866 Messenger .debug (player , "&3Golden Apple Cooldown &f&l>> &6Added to cooldown: &atrue" );
6967 if (Config .Setting .COOLDOWN_GOLDEN_APPLE_ACTIONBAR .getBoolean ()) {
7068 new BukkitRunnable () {
@@ -73,6 +71,10 @@ public void onEatGoldenApple(PlayerItemConsumeEvent e) {
7371 public void run () {
7472 if (cooldown .containsKey (p )) {
7573 long secondsleft = ((cooldown .get (p ) / 1000 ) + Config .Setting .COOLDOWN_GOLDEN_APPLE_COOLDOWN .getInt ()) - (System .currentTimeMillis () / 1000 );
74+ if (secondsleft < 1 ) {
75+ cooldown .remove (p );
76+ cancel ();
77+ }
7678 String message = MsgType .GOLDEN_APPLE_COOLDOWN_ACTIONBAR .getMessage ().replaceAll ("%seconds%" , String .valueOf (secondsleft ));
7779 player .spigot ().sendMessage (ChatMessageType .ACTION_BAR , TextComponent .fromLegacyText (message ));
7880 } else {
@@ -85,22 +87,6 @@ public void run() {
8587 }
8688 }
8789
88- private void setupPlaceholder (UUID p ) {
89-
90- new BukkitRunnable () {
91-
92- @ Override
93- public void run () {
94- if (cooldown .containsKey (p )) {
95- long secondsleft = ((cooldown .get (p ) / 1000 ) + Config .Setting .COOLDOWN_GOLDEN_APPLE_COOLDOWN .getInt ()) - (System .currentTimeMillis () / 1000 );
96- papiCooldown = secondsleft + "s" ;
97- } else {
98- cancel ();
99- }
100- }
101- }.runTaskTimerAsynchronously (plugin , 0 , 20 );
102- }
103-
10490 private boolean isGoldenApple (PlayerItemConsumeEvent e ) {
10591 ItemStack goldenApple = new ItemStack (Material .GOLDEN_APPLE );
10692 ItemStack consumedItem = e .getItem ();
@@ -109,7 +95,7 @@ private boolean isGoldenApple(PlayerItemConsumeEvent e) {
10995 || plugin .serverVersion ("1.10" )
11096 || plugin .serverVersion ("1.11" )
11197 || plugin .serverVersion ("1.12" )) {
112- return consumedItem .getType ().name ().contains ("GOLDEN_APPLE" ) &&
98+ return consumedItem .getType ().name ().equals ("GOLDEN_APPLE" ) &&
11399 Objects .equals (goldenApple .getData (), consumedItem .getData ());
114100 } else {
115101 return consumedItem .getType () == Material .GOLDEN_APPLE ;
0 commit comments