Minor microoptimisation

This commit is contained in:
fullwall 2018-04-09 17:41:53 +08:00
parent 74989cd93e
commit 184b414dd5

View File

@ -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;
@ -38,7 +37,7 @@ import net.citizensnpcs.util.Util;
@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";
@ -139,9 +138,9 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
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());
@ -149,15 +148,13 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
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);
}
}