This repository was archived by the owner on Jul 22, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-13
lines changed
src/main/java/me/darki/simplecommandcooldown Expand file tree Collapse file tree 2 files changed +10
-13
lines changed Original file line number Diff line number Diff line change 1010
1111import java .util .UUID ;
1212import java .util .concurrent .ConcurrentHashMap ;
13- import java .util .concurrent .locks .ReentrantLock ;
1413
1514public class CommandListener implements Listener {
1615
1716 final private ConcurrentHashMap <Data , Long > cooldownMap ;
18- final private ReentrantLock mutex ;
1917
2018 public CommandListener () {
2119 cooldownMap = new ConcurrentHashMap <>();
22- mutex = new ReentrantLock ();
2320 }
2421
2522 @ EventHandler (priority = EventPriority .HIGHEST , ignoreCancelled = true )
@@ -29,19 +26,15 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
2926 String commandName = event .getMessage ().split (" " )[0 ];
3027 Data data = new Data (player .getUniqueId (), commandName );
3128
32- mutex .lock ();
33-
3429 if (!cooldownMap .containsKey (data ) || System .currentTimeMillis () - cooldownMap .get (data ) > SimpleCommandCooldown .cooldown ) {
35- // command off cooldown
30+ // off cooldown
3631 cooldownMap .put (data , System .currentTimeMillis ());
3732 } else {
38- // command on fresh cooldown
33+ // on cooldown
3934 event .setCancelled (true );
40- player .sendMessage (ChatColor .RED + "Please wait a bit before using this command again!" );
35+ player .sendMessage (ChatColor .RED + SimpleCommandCooldown . message );
4136 }
4237
43- mutex .unlock ();
44-
4538 }
4639
4740 @ EventHandler (ignoreCancelled = true )
Original file line number Diff line number Diff line change 66public final class SimpleCommandCooldown extends JavaPlugin {
77
88 public static long cooldown = 0L ;
9+ public static String message = "" ;
910
1011 public void onEnable () {
12+ initConfig ();
13+ Bukkit .getServer ().getPluginManager ().registerEvents (new CommandListener (), this );
14+ }
1115
16+ private void initConfig () {
1217 getConfig ().addDefault ("cooldown" , 3000 );
18+ getConfig ().addDefault ("message" , "Please wait a bit before using this command again!" );
1319 getConfig ().options ().copyDefaults (true );
1420 saveConfig ();
15-
16- Bukkit .getServer ().getPluginManager ().registerEvents (new CommandListener (), this );
1721 cooldown = getConfig ().getLong ("cooldown" );
18-
22+ message = getConfig (). getString ( "message" );
1923 }
2024
2125}
You can’t perform that action at this time.
0 commit comments