Bugfix: On join cooldowns not working correctly

This commit is contained in:
GeorgH93 2017-06-03 14:14:10 +02:00
parent f197bc2667
commit 669f94493f
2 changed files with 8 additions and 12 deletions

View File

@ -33,7 +33,7 @@
public class EventListener implements Listener public class EventListener implements Listener
{ {
private MinePacks plugin; private MinePacks plugin;
private boolean drop_on_death, showCloseMessageOwn, showCloseMessageOther, onJoinCooldown; private boolean drop_on_death, showCloseMessageOwn, showCloseMessageOther;
private long joinCooldown; private long joinCooldown;
private String message_OwnBPClose, message_PlayerBPClose; private String message_OwnBPClose, message_PlayerBPClose;
@ -46,7 +46,6 @@ public EventListener(MinePacks mp)
showCloseMessageOther = message_PlayerBPClose != null && plugin.config.getShowCloseMessage(); showCloseMessageOther = message_PlayerBPClose != null && plugin.config.getShowCloseMessage();
showCloseMessageOwn = message_OwnBPClose != null && plugin.config.getShowCloseMessage(); showCloseMessageOwn = message_OwnBPClose != null && plugin.config.getShowCloseMessage();
joinCooldown = plugin.config.getCommandCooldownAfterJoin(); joinCooldown = plugin.config.getCommandCooldownAfterJoin();
onJoinCooldown = joinCooldown > 0;
} }
@EventHandler @EventHandler
@ -135,9 +134,9 @@ public void onClick(InventoryClickEvent event)
public void onPlayerLoginEvent(PlayerJoinEvent event) public void onPlayerLoginEvent(PlayerJoinEvent event)
{ {
plugin.DB.updatePlayerAndLoadBackpack(event.getPlayer()); plugin.DB.updatePlayerAndLoadBackpack(event.getPlayer());
if(onJoinCooldown) if(joinCooldown > 0 && !event.getPlayer().hasPermission("backpack.noCooldown"))
{ {
plugin.cooldowns.put(event.getPlayer(), joinCooldown); plugin.cooldowns.put(event.getPlayer(), System.currentTimeMillis() + joinCooldown);
} }
} }

View File

@ -69,17 +69,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String arg, String[]
{ {
if(gameModes.contains(player.getGameMode()) || player.hasPermission("backpack.ignoreGameMode")) if(gameModes.contains(player.getGameMode()) || player.hasPermission("backpack.ignoreGameMode"))
{ {
if(cooldown > 0 && !player.hasPermission("backpack.noCooldown")) if(!player.hasPermission("backpack.noCooldown"))
{ {
if(plugin.cooldowns.containsKey(player)) if(plugin.cooldowns.containsKey(player) && (System.currentTimeMillis() - plugin.cooldowns.get(player)) < 0)
{
if((System.currentTimeMillis() - plugin.cooldowns.get(player)) < cooldown)
{ {
sender.sendMessage(messageCooldown); sender.sendMessage(messageCooldown);
return true; return true;
} }
} if(cooldown > 0) plugin.cooldowns.put(player, System.currentTimeMillis() + cooldown);
plugin.cooldowns.put(player, System.currentTimeMillis());
} }
plugin.openBackpack(player, player, true); plugin.openBackpack(player, player, true);
} }