Ceikry Work
- A whole lotta ceikry
This commit is contained in:
@@ -706,6 +706,10 @@ public abstract class Entity extends Node {
|
||||
attributes.setAttribute(key, value);
|
||||
}
|
||||
|
||||
public void setExpirableAttribute(String key, Object value, Long timeToLive){
|
||||
attributes.setExpirableAttribute(key,value,timeToLive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an attribute.
|
||||
* @param key The attribute name.
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Handles an entity's game attributes.
|
||||
@@ -27,6 +28,11 @@ public final class GameAttributes {
|
||||
*/
|
||||
private final List<String> savedAttributes = new ArrayList<>(250);
|
||||
|
||||
/**
|
||||
* The list of key expirations
|
||||
*/
|
||||
public final HashMap<String,Long> keyExpirations = new HashMap<>(250);
|
||||
|
||||
/**
|
||||
* Constructs a new {@code GameAttributes} {@code Object}.
|
||||
*/
|
||||
@@ -138,6 +144,17 @@ public final class GameAttributes {
|
||||
attributes.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an inherently temporary (but saved cross-session) key.
|
||||
* @param key the key to set
|
||||
* @param value the value to assign to the key
|
||||
* @param timeToLive the time (in milliseconds) that the key will be valid for
|
||||
*/
|
||||
public void setExpirableAttribute(String key, Object value, Long timeToLive){
|
||||
setAttribute(key,value);
|
||||
keyExpirations.put(key,System.currentTimeMillis() + timeToLive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an attribute.
|
||||
* @param key The attribute name.
|
||||
@@ -165,6 +182,9 @@ public final class GameAttributes {
|
||||
if (object != null) {
|
||||
return (T) object;
|
||||
}
|
||||
if(keyExpirations.containsKey(string) && keyExpirations.get(string) < System.currentTimeMillis()){
|
||||
return fail;
|
||||
}
|
||||
return fail;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user