From 346c9f5285c26f44a9fb8c4445bca5ad3980cade Mon Sep 17 00:00:00 2001 From: Badhad <46411657+BadHad@users.noreply.github.com> Date: Thu, 8 Apr 2021 19:01:30 -0400 Subject: [PATCH] Ceikry Work - A whole lotta ceikry --- .../java/core/game/node/entity/Entity.java | 4 ++++ .../game/node/entity/impl/GameAttributes.java | 20 +++++++++++++++++ .../player/info/login/PlayerSaveParser.kt | 7 ++++++ .../entity/player/info/login/PlayerSaver.kt | 5 +++++ .../system/command/sets/MiscCommandSet.kt | 22 ++++++------------- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/Server/src/main/java/core/game/node/entity/Entity.java b/Server/src/main/java/core/game/node/entity/Entity.java index af22dead8..68f826c75 100644 --- a/Server/src/main/java/core/game/node/entity/Entity.java +++ b/Server/src/main/java/core/game/node/entity/Entity.java @@ -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. diff --git a/Server/src/main/java/core/game/node/entity/impl/GameAttributes.java b/Server/src/main/java/core/game/node/entity/impl/GameAttributes.java index 46b42c0d5..df82a0e9b 100644 --- a/Server/src/main/java/core/game/node/entity/impl/GameAttributes.java +++ b/Server/src/main/java/core/game/node/entity/impl/GameAttributes.java @@ -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 savedAttributes = new ArrayList<>(250); + /** + * The list of key expirations + */ + public final HashMap 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; } diff --git a/Server/src/main/kotlin/rs09/game/node/entity/player/info/login/PlayerSaveParser.kt b/Server/src/main/kotlin/rs09/game/node/entity/player/info/login/PlayerSaveParser.kt index b0eb96482..8c4a1d4ed 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/player/info/login/PlayerSaveParser.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/player/info/login/PlayerSaveParser.kt @@ -104,6 +104,13 @@ class PlayerSaveParser(val player: Player) { val attr = a as JSONObject val key = attr["key"].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.attributes.put(key, when (type) { "int" -> attr["value"].toString().toInt() diff --git a/Server/src/main/kotlin/rs09/game/node/entity/player/info/login/PlayerSaver.kt b/Server/src/main/kotlin/rs09/game/node/entity/player/info/login/PlayerSaver.kt index 8d7b1247a..92dc0c733 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/player/info/login/PlayerSaver.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/player/info/login/PlayerSaver.kt @@ -109,6 +109,7 @@ class PlayerSaver (val player: Player){ for(key in player.gameAttributes.savedAttributes){ val value = player.gameAttributes.attributes[key] value ?: continue + val isExpirable = player.gameAttributes.keyExpirations.containsKey(key); val attr = JSONObject() val type = when(value){ is Int -> "int" @@ -127,6 +128,10 @@ class PlayerSaver (val player: Player){ } else { 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) } root.put("attributes",attrs) diff --git a/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt b/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt index a5d97ef88..91da57d32 100644 --- a/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt +++ b/Server/src/main/kotlin/rs09/game/system/command/sets/MiscCommandSet.kt @@ -34,6 +34,7 @@ import rs09.tools.stringtools.colorize import java.awt.Toolkit import java.awt.datatransfer.StringSelection import java.util.* +import java.util.concurrent.TimeUnit @Initializable class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){ @@ -112,20 +113,11 @@ class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){ } val red = "" player.packetDispatch.sendString("" + "Players" + "", 275, 2) - val builder = StringBuilder("
") - var count = 0 - for (p in Repository.players) { - if (count > 45) { - builder.append("
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 + "" + p.username + if(rights > 0) " [ip=" + p.details.ipAddress + ", name=" + p.details.compName + "]

" else "

") - count++ + var lineStart = 11 + for(p in Repository.players){ + if(!p.isArtificial) + player.packetDispatch.sendString(red + "" + p.username + if(rights > 0) " [ip=" + p.details.ipAddress + ", name=" + p.details.compName + "]" else "",275,lineStart++) } - player.packetDispatch.sendString(builder.toString(), 275, 11) } /** * =================================================================================== @@ -506,9 +498,9 @@ class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){ pl.sendMessage("You dig and find nothing.") 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.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}")