From 184b414dd594d430247d3465dacfd37877c3c7a3 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 9 Apr 2018 17:41:53 +0800 Subject: [PATCH] Minor microoptimisation --- .../main/java/net/citizensnpcs/trait/text/Text.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/trait/text/Text.java b/main/src/main/java/net/citizensnpcs/trait/text/Text.java index 152b53212..6035487cf 100644 --- a/main/src/main/java/net/citizensnpcs/trait/text/Text.java +++ b/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; @@ -38,7 +37,7 @@ import net.citizensnpcs.util.Util; @TraitName("text") public class Text extends Trait implements Runnable, Toggleable, Listener, ConversationAbandonedListener { - private final Map cooldowns = Maps.newHashMap(); + private final Map 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); } }