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);
|
attributes.setAttribute(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setExpirableAttribute(String key, Object value, Long timeToLive){
|
||||||
|
attributes.setExpirableAttribute(key,value,timeToLive);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an attribute.
|
* Gets an attribute.
|
||||||
* @param key The attribute name.
|
* @param key The attribute name.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles an entity's game attributes.
|
* Handles an entity's game attributes.
|
||||||
@@ -27,6 +28,11 @@ public final class GameAttributes {
|
|||||||
*/
|
*/
|
||||||
private final List<String> savedAttributes = new ArrayList<>(250);
|
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}.
|
* Constructs a new {@code GameAttributes} {@code Object}.
|
||||||
*/
|
*/
|
||||||
@@ -138,6 +144,17 @@ public final class GameAttributes {
|
|||||||
attributes.put(key, value);
|
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.
|
* Gets an attribute.
|
||||||
* @param key The attribute name.
|
* @param key The attribute name.
|
||||||
@@ -165,6 +182,9 @@ public final class GameAttributes {
|
|||||||
if (object != null) {
|
if (object != null) {
|
||||||
return (T) object;
|
return (T) object;
|
||||||
}
|
}
|
||||||
|
if(keyExpirations.containsKey(string) && keyExpirations.get(string) < System.currentTimeMillis()){
|
||||||
|
return fail;
|
||||||
|
}
|
||||||
return fail;
|
return fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,6 +104,13 @@ class PlayerSaveParser(val player: Player) {
|
|||||||
val attr = a as JSONObject
|
val attr = a as JSONObject
|
||||||
val key = attr["key"].toString()
|
val key = attr["key"].toString()
|
||||||
val type = attr["type"].toString()
|
val type = attr["type"].toString()
|
||||||
|
val isExpirable = attr.getOrDefault("expirable",false) as Boolean
|
||||||
|
if(isExpirable){
|
||||||
|
val expireTime = attr["expiration-time"].toString().toLong()
|
||||||
|
if(expireTime < System.currentTimeMillis()) continue
|
||||||
|
|
||||||
|
player.gameAttributes.keyExpirations[key] = expireTime
|
||||||
|
}
|
||||||
player.gameAttributes.savedAttributes.add(key)
|
player.gameAttributes.savedAttributes.add(key)
|
||||||
player.gameAttributes.attributes.put(key, when (type) {
|
player.gameAttributes.attributes.put(key, when (type) {
|
||||||
"int" -> attr["value"].toString().toInt()
|
"int" -> attr["value"].toString().toInt()
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ class PlayerSaver (val player: Player){
|
|||||||
for(key in player.gameAttributes.savedAttributes){
|
for(key in player.gameAttributes.savedAttributes){
|
||||||
val value = player.gameAttributes.attributes[key]
|
val value = player.gameAttributes.attributes[key]
|
||||||
value ?: continue
|
value ?: continue
|
||||||
|
val isExpirable = player.gameAttributes.keyExpirations.containsKey(key);
|
||||||
val attr = JSONObject()
|
val attr = JSONObject()
|
||||||
val type = when(value){
|
val type = when(value){
|
||||||
is Int -> "int"
|
is Int -> "int"
|
||||||
@@ -127,6 +128,10 @@ class PlayerSaver (val player: Player){
|
|||||||
} else {
|
} else {
|
||||||
attr.put("value", if (value is Boolean) value else value.toString())
|
attr.put("value", if (value is Boolean) value else value.toString())
|
||||||
}
|
}
|
||||||
|
if(isExpirable){
|
||||||
|
attr.put("expirable",true)
|
||||||
|
attr.put("expiration-time",player.gameAttributes.keyExpirations[key].toString())
|
||||||
|
}
|
||||||
attrs.add(attr)
|
attrs.add(attr)
|
||||||
}
|
}
|
||||||
root.put("attributes",attrs)
|
root.put("attributes",attrs)
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import rs09.tools.stringtools.colorize
|
|||||||
import java.awt.Toolkit
|
import java.awt.Toolkit
|
||||||
import java.awt.datatransfer.StringSelection
|
import java.awt.datatransfer.StringSelection
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
@Initializable
|
@Initializable
|
||||||
class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){
|
class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){
|
||||||
@@ -112,20 +113,11 @@ class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){
|
|||||||
}
|
}
|
||||||
val red = "<col=8A0808>"
|
val red = "<col=8A0808>"
|
||||||
player.packetDispatch.sendString("<col=8A0808>" + "Players" + "</col>", 275, 2)
|
player.packetDispatch.sendString("<col=8A0808>" + "Players" + "</col>", 275, 2)
|
||||||
val builder = StringBuilder("<br>")
|
var lineStart = 11
|
||||||
var count = 0
|
for(p in Repository.players){
|
||||||
for (p in Repository.players) {
|
if(!p.isArtificial)
|
||||||
if (count > 45) {
|
player.packetDispatch.sendString(red + "<img=" + (Rights.getChatIcon(p) - 1) + ">" + p.username + if(rights > 0) " [ip=" + p.details.ipAddress + ", name=" + p.details.compName + "]" else "",275,lineStart++)
|
||||||
builder.append("<br>Max amount we can show on this interface.")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if (p == null || p.isAdmin && GameWorld.settings?.isDevMode != true && !player.isAdmin || p.isArtificial) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
builder.append(red + "<img=" + (Rights.getChatIcon(p) - 1) + ">" + p.username + if(rights > 0) " [ip=" + p.details.ipAddress + ", name=" + p.details.compName + "]<br><br>" else "<br><br>")
|
|
||||||
count++
|
|
||||||
}
|
}
|
||||||
player.packetDispatch.sendString(builder.toString(), 275, 11)
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* ===================================================================================
|
* ===================================================================================
|
||||||
@@ -506,9 +498,9 @@ class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){
|
|||||||
pl.sendMessage("You dig and find nothing.")
|
pl.sendMessage("You dig and find nothing.")
|
||||||
return@registerListener
|
return@registerListener
|
||||||
}
|
}
|
||||||
pl.sendMessage("You dig and find a ${def.name}!")
|
pl.dialogueInterpreter.sendDialogue("You dig and find a ${def.name}!")
|
||||||
player.inventory.add(Item(itemId))
|
player.inventory.add(Item(itemId))
|
||||||
player.setAttribute("/save:${player.location.toString()}:$itemId",true)
|
player.setExpirableAttribute("/save:${player.location.toString()}:$itemId",true,TimeUnit.SECONDS.toMillis(10))
|
||||||
}
|
}
|
||||||
|
|
||||||
notify(player,"You buried a ${def.name} at ${player.location}")
|
notify(player,"You buried a ${def.name} at ${player.location}")
|
||||||
|
|||||||
Reference in New Issue
Block a user