CointentAPI ~

@SuppressWarnings("deprecation") //Description
This commit is contained in:
Tooze 2026-07-29 03:50:26 -04:00
parent c66a9f77fa
commit b829ebbea1
6 changed files with 56 additions and 17 deletions

View file

@ -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 {

View file

@ -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))
}

View file

@ -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);
}
/**

View file

@ -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

View file

@ -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);
}
}

View file

@ -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<Player> {
*/
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<Player> {
}
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<Player> {
}
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<Player> {
*/
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