Skip to content

Commit

Permalink
Minor microoptimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 9, 2018
1 parent 74989cd commit 184b414
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions main/src/main/java/net/citizensnpcs/trait/text/Text.java
@@ -1,7 +1,6 @@
package net.citizensnpcs.trait.text;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
Expand Down Expand Up @@ -38,7 +37,7 @@

@TraitName("text")
public class Text extends Trait implements Runnable, Toggleable, Listener, ConversationAbandonedListener {
private final Map<UUID, Date> cooldowns = Maps.newHashMap();
private final Map<UUID, Long> cooldowns = Maps.newHashMap();
private int currentIndex;
private int delay = -1;
private String itemInHandPattern = "default";
Expand Down Expand Up @@ -139,25 +138,23 @@ public void run() {
continue;
Player player = (Player) search;
// If the cooldown is not expired, do not send text
Date cooldown = cooldowns.get(player.getUniqueId());
Long cooldown = cooldowns.get(player.getUniqueId());
if (cooldown != null) {
if (!new Date().after(cooldown)) {
if (System.currentTimeMillis() < cooldown) {
return;
}
cooldowns.remove(player.getUniqueId());
}
if (!sendText(player))
return;
// Add a cooldown if the text was successfully sent
Date wait = new Date();
int secondsDelta = delay != -1 ? delay
: RANDOM.nextInt(Setting.TALK_CLOSE_MAXIMUM_COOLDOWN.asInt())
+ Setting.TALK_CLOSE_MINIMUM_COOLDOWN.asInt();
if (secondsDelta <= 0)
return;
long millisecondsDelta = TimeUnit.MILLISECONDS.convert(secondsDelta, TimeUnit.SECONDS);
wait.setTime(wait.getTime() + millisecondsDelta);
cooldowns.put(player.getUniqueId(), wait);
cooldowns.put(player.getUniqueId(), System.currentTimeMillis() + millisecondsDelta);
}
}

Expand Down

0 comments on commit 184b414

Please sign in to comment.