diff --git a/Server/src/main/content/global/skill/construction/HouseManager.java b/Server/src/main/content/global/skill/construction/HouseManager.java index 4db8e8191..be150fb6e 100644 --- a/Server/src/main/content/global/skill/construction/HouseManager.java +++ b/Server/src/main/content/global/skill/construction/HouseManager.java @@ -215,6 +215,7 @@ public final class HouseManager { if (house.isInHouse(player)) { player.animate(Animation.RESET); player.getProperties().setTeleportLocation(house.location.getExitLocation()); + player.removeAttribute("lastActivity"); } } diff --git a/Server/src/main/content/global/skill/construction/HouseZone.java b/Server/src/main/content/global/skill/construction/HouseZone.java index 31a57f6f8..a67de9791 100644 --- a/Server/src/main/content/global/skill/construction/HouseZone.java +++ b/Server/src/main/content/global/skill/construction/HouseZone.java @@ -67,6 +67,7 @@ public final class HouseZone extends MapZone { public boolean enter(Entity e) { if (e instanceof Player) { Player pl = (Player) e; + pl.setAttribute("/save:lastActivity","POH-Activity"); if (house == pl.getHouseManager()) { previousRegion = house.getHouseRegion().getId(); if (house.getDungeonRegion() != null) @@ -74,6 +75,7 @@ public final class HouseZone extends MapZone { } registerLogoutListener(pl, "houselogout", (p) -> { p.setLocation(house.getLocation().getExitLocation()); + p.removeAttribute("lastActivity"); return kotlin.Unit.INSTANCE; }); } @@ -142,13 +144,14 @@ public final class HouseZone extends MapZone { clearLogoutListener(p, "houselogout"); if (!getAttribute(p, "kidnapped-by-random", false)) { removeAttribute(p, "/save:original-loc"); + removeAttribute(p,"lastActivity"); } return true; } return true; } - private void remove_items(Player p) { + public static void remove_items(Player p) { for (int item = Items.KETTLE_7688; item <= Items.CHEFS_DELIGHT_7755; item++) {//Removes all PoH versions of tea and beer barrel-related items removeAll(p, item, Container.INVENTORY); removeAll(p, item, Container.BoB); diff --git a/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerActivity.kt b/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerActivity.kt index 1522316c6..92aef5977 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.sendMessage import core.game.node.entity.player.Player import core.game.system.task.Pulse import core.game.world.GameWorld @@ -66,6 +67,7 @@ class FishingTrawlerActivity : ActivityPlugin("fishing trawler",false,false,true override fun start(player: Player?, login: Boolean, vararg args: Any?): Boolean { player ?: return false waitingPlayers.add(player) + super.start(player, login, *args) return true } @@ -74,11 +76,14 @@ class FishingTrawlerActivity : ActivityPlugin("fishing trawler",false,false,true nextStart = GameWorld.ticks + WAIT_TIME player.dialogueInterpreter.sendDialogue("Trawler will leave in 2 minutes.","If you have a team get them on board now!") } - waitingPlayers.add(player) + //waitingPlayers.add(player) + start(player,true) } + fun removePlayer(player: Player){ waitingPlayers.remove(player) + player.removeAttribute("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 3cabb8d72..a66243842 100644 --- a/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerSession.kt +++ b/Server/src/main/content/minigame/fishingtrawler/FishingTrawlerSession.kt @@ -158,6 +158,7 @@ class FishingTrawlerSession(val activity: FishingTrawlerActivity? = null) : MapA player.removeAttribute("ft-session") player.setAttribute("/save:ft-rolls", rolls) clearLogoutListener(player, "ft-logout") + player.removeAttribute("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 f1fb680a0..f372a6567 100644 --- a/Server/src/main/content/minigame/pestcontrol/PestControlActivityPlugin.java +++ b/Server/src/main/content/minigame/pestcontrol/PestControlActivityPlugin.java @@ -252,9 +252,22 @@ public final class PestControlActivityPlugin extends ActivityPlugin { } waitingPlayers.add(p); openLanderInterface(p); + super.start(p, login, args); return true; } + /** + * Recovers the player from void should they get left there. + * Is called during login. + * @param player The player. + */ + @Override + public void recover(Player player) { + player.setLocation(getLeaveLocation()); + //player.setLocation(getSpawnLocation()); + player.removeAttribute("lastActivity"); + } + /** * Updates the lander interface. * @param p The player. diff --git a/Server/src/main/content/region/misthalin/draynor/handlers/DBRCutscenePlugin.java b/Server/src/main/content/region/misthalin/draynor/handlers/DBRCutscenePlugin.java index 78c30fa3e..ddd7e2116 100644 --- a/Server/src/main/content/region/misthalin/draynor/handlers/DBRCutscenePlugin.java +++ b/Server/src/main/content/region/misthalin/draynor/handlers/DBRCutscenePlugin.java @@ -1,5 +1,6 @@ package content.region.misthalin.draynor.handlers; +import core.ServerConstants; import core.game.component.Component; import core.game.activity.ActivityPlugin; import core.game.activity.CutscenePlugin; @@ -233,7 +234,7 @@ public final class DBRCutscenePlugin extends CutscenePlugin { @Override public Location getSpawnLocation() { - return null; + return Location.create(3087, 3248, 0); } @Override diff --git a/Server/src/main/content/region/misthalin/varrock/quest/whatliesbelow/WLBelowCutscene.java b/Server/src/main/content/region/misthalin/varrock/quest/whatliesbelow/WLBelowCutscene.java index d1c154c5d..940eceedc 100644 --- a/Server/src/main/content/region/misthalin/varrock/quest/whatliesbelow/WLBelowCutscene.java +++ b/Server/src/main/content/region/misthalin/varrock/quest/whatliesbelow/WLBelowCutscene.java @@ -291,7 +291,7 @@ public class WLBelowCutscene extends CutscenePlugin { @Override public Location getSpawnLocation() { - return null; + return Location.create(3209, 3495, 0); } @Override diff --git a/Server/src/main/content/region/wilderness/handlers/BorkNPC.java b/Server/src/main/content/region/wilderness/handlers/BorkNPC.java index 53bd862e5..06fd507b3 100644 --- a/Server/src/main/content/region/wilderness/handlers/BorkNPC.java +++ b/Server/src/main/content/region/wilderness/handlers/BorkNPC.java @@ -525,7 +525,7 @@ public class BorkNPC extends AbstractNPC { @Override public Location getSpawnLocation() { - return null; + return Location.create(3143, 5545, 0); } @Override diff --git a/Server/src/main/core/game/activity/ActivityManager.java b/Server/src/main/core/game/activity/ActivityManager.java index 15ab8ff39..66858ea56 100644 --- a/Server/src/main/core/game/activity/ActivityManager.java +++ b/Server/src/main/core/game/activity/ActivityManager.java @@ -1,5 +1,7 @@ package core.game.activity; +import content.global.skill.construction.HouseZone; +import core.ServerConstants; import core.game.node.entity.player.Player; import core.tools.Log; import core.tools.SystemLogger; @@ -8,7 +10,7 @@ import core.game.world.GameWorld; import java.util.HashMap; import java.util.Map; -import static core.api.ContentAPIKt.log; +import static core.api.ContentAPIKt.*; /** * Manages the activities. @@ -79,4 +81,33 @@ public final class ActivityManager { public static ActivityPlugin getActivity(String name) { return ACTIVITIES.get(name); } + + public static void ActivityRecover(Player player) { + String activityName = player.getAttribute("lastActivity", null); + if (activityName == null) return; + //sendMessage(player,player.getUsername() + " recovering from " + activityName); + if (activityName.equals("POH-Activity")) { + HouseZone.remove_items(player); + player.setLocation(player.getHouseManager().getLocation().getExitLocation()); + player.removeAttribute("/save:original-loc"); + player.removeAttribute("lastActivity"); + return; + } + try { + ActivityPlugin plugin = ACTIVITIES.get(activityName); + if (plugin != null) { + if (plugin.isInstanced()) { + plugin = plugin.newInstance(player); + } + plugin.recover(player); + } else { + player.setLocation(ServerConstants.HOME_LOCATION); + } + } catch (Throwable t) { + t.printStackTrace(); + player.setLocation(ServerConstants.HOME_LOCATION); + } + + player.removeAttribute("lastActivity"); + } } \ No newline at end of file diff --git a/Server/src/main/core/game/activity/ActivityPlugin.java b/Server/src/main/core/game/activity/ActivityPlugin.java index 50ea847f5..17986e9b0 100644 --- a/Server/src/main/core/game/activity/ActivityPlugin.java +++ b/Server/src/main/core/game/activity/ActivityPlugin.java @@ -11,6 +11,10 @@ import core.game.world.map.zone.impl.MultiwayCombatZone; import core.plugin.Plugin; import core.plugin.PluginManifest; import core.plugin.PluginType; +import core.tools.Log; + +import static core.api.ContentAPIKt.log; +import static core.api.ContentAPIKt.sendMessage; /** * A plugin implementation used for activity plugins. @@ -130,6 +134,8 @@ public abstract class ActivityPlugin extends MapZone implements Plugin { */ public boolean start(Player player, boolean login, Object... args) { this.player = player; + player.setAttribute("/save:lastActivity", this.getName()); + player.sendMessage(this.getName()); return true; } @@ -157,6 +163,7 @@ public abstract class ActivityPlugin extends MapZone implements Plugin { e.getProperties().setSafeZone(false); e.getProperties().safeRespawn = ServerConstants.HOME_LOCATION; e.removeAttribute("activity"); + e.removeAttribute("lastActivity"); return super.leave(e, logout); } @@ -166,6 +173,18 @@ public abstract class ActivityPlugin extends MapZone implements Plugin { public void register() { } + public void recover(Player player) { + Location spawn = getSpawnLocation(); + if (spawn == null) { + String lastActivity = player.getAttribute("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"); + } + @Override public Object fireEvent(String identifier, Object... args) { return null; diff --git a/Server/src/main/core/game/activity/CutscenePlugin.java b/Server/src/main/core/game/activity/CutscenePlugin.java index 043b7c179..49df8e2a3 100644 --- a/Server/src/main/core/game/activity/CutscenePlugin.java +++ b/Server/src/main/core/game/activity/CutscenePlugin.java @@ -142,6 +142,7 @@ public abstract class CutscenePlugin extends ActivityPlugin { player.getInterfaceManager().restoreTabs(); player.unlock();// incase he was locked. player.getWalkingQueue().reset(); + player.removeAttribute("lastActivity"); } /** diff --git a/Server/src/main/core/game/node/entity/player/Player.java b/Server/src/main/core/game/node/entity/player/Player.java index d21c591fc..8d399c864 100644 --- a/Server/src/main/core/game/node/entity/player/Player.java +++ b/Server/src/main/core/game/node/entity/player/Player.java @@ -7,6 +7,7 @@ import content.global.skill.construction.decoration.pohstorage.StorageState; import content.global.skill.runecrafting.PouchManager; import content.global.skill.slayer.SlayerEquipmentFlags; import core.api.ContentAPIKt; +import core.game.activity.ActivityManager; import core.game.component.Component; import core.game.container.Container; import core.game.container.impl.BankContainer; @@ -345,6 +346,7 @@ public class Player extends Entity { if (!artificial) { log(this.getClass(), Log.INFO, getUsername() + " initialising..."); getDetails().getSession().setObject(this); + ActivityManager.ActivityRecover(this); } super.init(); LoginConfiguration.configureLobby(this);