From b829ebbea13e00111eb1af9f747e48470fccb9ac Mon Sep 17 00:00:00 2001 From: Tooze Date: Wed, 29 Jul 2026 03:50:26 -0400 Subject: [PATCH] CointentAPI ~ @SuppressWarnings("deprecation") //Description --- .../fishingtrawler/FishingTrawlerActivity.kt | 3 +- .../fishingtrawler/FishingTrawlerSession.kt | 2 +- .../PestControlActivityPlugin.java | 2 +- Server/src/main/core/api/ContentAPI.kt | 35 +++++++++++++++++++ .../core/game/activity/ActivityManager.java | 13 ++++--- .../core/game/activity/ActivityPlugin.java | 18 +++++----- 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerActivity.kt b/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerActivity.kt index 4b04ed009..b290c5b59 100644 --- a/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerActivity.kt +++ b/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerActivity.kt @@ -1,6 +1,7 @@ package content.minigame.fishingtrawler import core.api.MapArea +import core.api.removeAttribute import core.game.node.entity.player.Player import core.game.system.task.Pulse import core.game.world.GameWorld @@ -82,7 +83,7 @@ class FishingTrawlerActivity : ActivityPlugin("fishing trawler",false,false,true fun removePlayer(player: Player){ waitingPlayers.remove(player) - player.removeAttribute(lastActivity) + removeAttribute(player,lastActivity) } override fun newInstance(p: Player?): ActivityPlugin { diff --git a/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerSession.kt b/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerSession.kt index 089a3ea1a..75868b1b5 100644 --- a/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerSession.kt +++ b/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerSession.kt @@ -159,7 +159,7 @@ class FishingTrawlerSession(val activity: FishingTrawlerActivity? = null) : MapA removeAttribute(player,"ft-session") setAttribute(player, "/save:ft-rolls", rolls) clearLogoutListener(player, "ft-logout") - player.removeAttribute(lastActivity) + removeAttribute(player,lastActivity) } session.zone.unregister(getRegionBorders(session.region.id)) } diff --git a/Server/src/main/content/minigame/pestcontrol/PestControlActivityPlugin.java b/Server/src/main/content/minigame/pestcontrol/PestControlActivityPlugin.java index 556ff17ca..8f4b3fcfa 100644 --- a/Server/src/main/content/minigame/pestcontrol/PestControlActivityPlugin.java +++ b/Server/src/main/content/minigame/pestcontrol/PestControlActivityPlugin.java @@ -265,7 +265,7 @@ public final class PestControlActivityPlugin extends ActivityPlugin { @Override public void recover(Player player) { player.setLocation(getLeaveLocation()); - player.removeAttribute(lastActivity); + removeAttribute(player,lastActivity); } /** diff --git a/Server/src/main/core/api/ContentAPI.kt b/Server/src/main/core/api/ContentAPI.kt index 7423518a7..0c4fb1cef 100644 --- a/Server/src/main/core/api/ContentAPI.kt +++ b/Server/src/main/core/api/ContentAPI.kt @@ -1660,6 +1660,41 @@ fun runWorldTask(task: () -> Unit): Pulse { return pulse } +/** + * Attribute key containing the player's location before entering an instanced activity. + */ +const val ORIGINAL_LOC = "original-loc" + +/** + * Persistent save key for the player's original location. + */ +const val SAVE_ORIGINAL_LOC = "/save:$ORIGINAL_LOC" + +/** + * Gets the player's original location before they entered an instanced activity / cutscene / AME + * + * @param player The player. + * @return The stored location, or {@code null} if none exists. + */ +fun getOriginalLocation(player: Player): Location? = getAttribute(player, ORIGINAL_LOC, null) + +/** + * Sets player's original location before entering an instanced activity / cutscene / AME + * + * @param player The player. + * @param location The location to store. + */ +fun setOriginalLocation(player: Player, location: Location) = setAttribute(player, SAVE_ORIGINAL_LOC, location) + +/** + * Removes the player's stored original location. + * + * This should be called once the player has safely left the activity / cutscene / AME + * + * @param player The player. + */ +fun removeOriginalLocation(player: Player) = removeAttribute(player, ORIGINAL_LOC) + /** * Teleports or "instantly moves" an entity to a given Location object. * @param entity the entity to move diff --git a/Server/src/main/core/game/activity/ActivityManager.java b/Server/src/main/core/game/activity/ActivityManager.java index 671249706..6b540ed5f 100644 --- a/Server/src/main/core/game/activity/ActivityManager.java +++ b/Server/src/main/core/game/activity/ActivityManager.java @@ -86,8 +86,9 @@ public final class ActivityManager { } @SuppressWarnings("deprecation") + // Intentionally uses the deprecated setLocation: the player must be moved before rendering to prevent client crashes public static void ActivityRecover(Player player) { - String activityName = player.getAttribute(lastActivity, null); + String activityName = getAttribute(player,lastActivity, null); if (activityName == null) { int yLoc = player.getLocation().getY(); if (yLoc < 2000) { //credits to PlayerName @@ -99,10 +100,11 @@ public final class ActivityManager { if (activityName.equals(POH_Activity)) { HouseZone.remove_items(player); player.setLocation(player.getHouseManager().getLocation().getExitLocation()); - removeAttribute(player,"original-loc"); + removeOriginalLocation(player); removeAttribute(player,lastActivity); return; } + // Fail-safe: don't let a broken activity trap the player. try { ActivityPlugin plugin = ACTIVITIES.get(activityName); if (plugin != null) { @@ -112,15 +114,16 @@ public final class ActivityManager { plugin.recover(player); } else { sendMessage(player, "You were safely removed from an invalid location."); - sendMessage(player, "Activity: NULL, please report this!"); + sendMessage(player, "Activity: " +activityName+ ", please report this!"); player.setLocation(ServerConstants.HOME_LOCATION); } } catch (Throwable t) { t.printStackTrace(); sendMessage(player, "You were safely removed from an invalid location."); - sendMessage(player, "Activity: THROWABLE, please report this!"); + sendMessage(player, "This activity has something bad or broken!!"); + sendMessage(player, "Activity: " +activityName+ ", please report this!"); player.setLocation(ServerConstants.HOME_LOCATION); } - player.removeAttribute(lastActivity); + removeAttribute(player,lastActivity); } } diff --git a/Server/src/main/core/game/activity/ActivityPlugin.java b/Server/src/main/core/game/activity/ActivityPlugin.java index 69498dfc8..8969701bc 100644 --- a/Server/src/main/core/game/activity/ActivityPlugin.java +++ b/Server/src/main/core/game/activity/ActivityPlugin.java @@ -13,8 +13,7 @@ import core.plugin.PluginManifest; import core.plugin.PluginType; import core.tools.Log; -import static core.api.ContentAPIKt.log; -import static core.api.ContentAPIKt.sendMessage; +import static core.api.ContentAPIKt.*; import static core.game.activity.ActivityManager.lastActivity; import static core.game.activity.ActivityManager.saveLastActivity; @@ -136,7 +135,7 @@ public abstract class ActivityPlugin extends MapZone implements Plugin { */ public boolean start(Player player, boolean login, Object... args) { this.player = player; - player.setAttribute(saveLastActivity, this.getName()); + setAttribute(player,saveLastActivity, this.getName()); return true; } @@ -148,7 +147,7 @@ public abstract class ActivityPlugin extends MapZone implements Plugin { } e.getProperties().setSafeZone(safe); e.getProperties().safeRespawn = this.safeRespawn; - e.setAttribute("activity", this); + setAttribute(e,"activity", this); return super.enter(e); } @@ -163,8 +162,8 @@ public abstract class ActivityPlugin extends MapZone implements Plugin { } e.getProperties().setSafeZone(false); e.getProperties().safeRespawn = ServerConstants.HOME_LOCATION; - e.removeAttribute("activity"); - e.removeAttribute(lastActivity); + removeAttribute(e,"activity"); + removeAttribute(e,lastActivity); return super.leave(e, logout); } @@ -173,17 +172,18 @@ public abstract class ActivityPlugin extends MapZone implements Plugin { */ public void register() { } - + // Intentionally uses the deprecated setLocation: the player must be moved before rendering to prevent client crashes + @SuppressWarnings("deprecation") public void recover(Player player) { Location spawn = getSpawnLocation(); if (spawn == null) { - String lastActivity = player.getAttribute(core.game.activity.ActivityManager.lastActivity, null); + String lastActivity = getAttribute(player,core.game.activity.ActivityManager.lastActivity, null); sendMessage(player, "You were safely removed from an invalid location."); sendMessage(player, "Activity: " + lastActivity + ", please report this!"); spawn = ServerConstants.HOME_LOCATION; } player.setLocation(spawn); - player.removeAttribute(lastActivity); + removeAttribute(player,lastActivity); } @Override