Add API method for adding and removing logout listeners and converted existing usages.
This commit is contained in:
@@ -287,10 +287,12 @@ public final class RugMerchantDialogue extends DialoguePlugin {
|
||||
player.getInterfaceManager().hideTabs(0,1,2,3,4,5,6,7,8,9,10,11,12,13);
|
||||
player.getEquipment().replace(new Item(Items.MAGIC_CARPET_5614),EquipmentContainer.SLOT_WEAPON);
|
||||
player.getPacketDispatch().sendInterfaceConfig(548,69,true);
|
||||
player.logoutListeners.put("magic-carpet", (pl) -> {
|
||||
|
||||
ContentAPI.registerLogoutListener(player, "magic-carpet", (pl) -> {
|
||||
ContentAPI.removeItem(pl, Items.MAGIC_CARPET_5614, Container.EQUIPMENT);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
GameWorld.getPulser().submit(new Pulse(1, player) {
|
||||
int count;
|
||||
int index;
|
||||
@@ -330,7 +332,9 @@ public final class RugMerchantDialogue extends DialoguePlugin {
|
||||
player.unlock();
|
||||
player.animate(new Animation(-1));
|
||||
player.getConfigManager().set(499, 0);
|
||||
player.logoutListeners.remove("magic-carpet");
|
||||
|
||||
ContentAPI.clearLogoutListener(player, "magic-carpet");
|
||||
|
||||
break;
|
||||
case 902:
|
||||
player.moveStep();
|
||||
|
||||
@@ -1369,12 +1369,4 @@ public class Player extends Entity {
|
||||
state.getPulse().stop();
|
||||
states.remove(key);
|
||||
}
|
||||
|
||||
public void addLogoutListener(String key, Function1<Player,Unit> listener){
|
||||
logoutListeners.put(key,listener);
|
||||
}
|
||||
|
||||
public void removeLogoutListener(String key){
|
||||
logoutListeners.remove(key);
|
||||
}
|
||||
}
|
||||
@@ -898,4 +898,24 @@ object ContentAPI {
|
||||
fun sendAnimationOnInterface(player: Player, anim: Int, iface: Int, child: Int){
|
||||
player.packetDispatch.sendAnimationInterface(anim,iface,child)
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a logout listener to a player. Logout listeners are methods that run when a player logs out.
|
||||
* @param player the player to register the listener for
|
||||
* @param handler the method to run when the listener is invoked (when the player logs out)
|
||||
*/
|
||||
@JvmStatic
|
||||
fun registerLogoutListener(player: Player, key: String, handler: (p: Player) -> Unit){
|
||||
player.logoutListeners[key] = handler
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a logout listener based on the key from a player
|
||||
* @param player the player to remove the logout listner from
|
||||
* @param key the key of the logout listener to remove.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun clearLogoutListener(player: Player, key: String){
|
||||
player.logoutListeners.remove(key)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package rs09.game.content.ame.events.drilldemon
|
||||
|
||||
import api.ContentAPI
|
||||
import core.game.content.dialogue.FacialExpression
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.item.GroundItemManager
|
||||
@@ -24,9 +25,11 @@ object DrillDemonUtils {
|
||||
fun teleport(player: Player){
|
||||
player.setAttribute(DD_KEY_RETURN_LOC,player.location)
|
||||
player.properties.teleportLocation = Location.create(3163, 4819, 0)
|
||||
player.addLogoutListener("drilldemon") { p ->
|
||||
p.location = player.getAttribute(DD_KEY_RETURN_LOC,p.location)
|
||||
|
||||
ContentAPI.registerLogoutListener(player, "drilldemon"){p ->
|
||||
ContentAPI.teleport(p, player.getAttribute(DD_KEY_RETURN_LOC, p.location))
|
||||
}
|
||||
|
||||
changeSignsAndAssignTask(player)
|
||||
}
|
||||
|
||||
@@ -72,7 +75,7 @@ object DrillDemonUtils {
|
||||
}
|
||||
|
||||
fun cleanup(player: Player){
|
||||
player.removeLogoutListener("drilldemon")
|
||||
ContentAPI.clearLogoutListener(player, "drilldemon")
|
||||
player.properties.teleportLocation = player.getAttribute(DD_KEY_RETURN_LOC)
|
||||
player.removeAttribute(DD_KEY_NPC)
|
||||
player.removeAttribute(DD_KEY_RETURN_LOC)
|
||||
|
||||
+6
-3
@@ -1,5 +1,6 @@
|
||||
package rs09.game.content.ame.events.supriseexam
|
||||
|
||||
import api.ContentAPI
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.item.GroundItemManager
|
||||
import core.game.node.item.Item
|
||||
@@ -28,15 +29,17 @@ object SurpriseExamUtils {
|
||||
|
||||
fun teleport(player: Player){
|
||||
player.setAttribute(SE_KEY_LOC,player.location)
|
||||
player.addLogoutListener(SE_LOGOUT_KEY){p ->
|
||||
p.location = p.getAttribute(SE_KEY_LOC,null)
|
||||
|
||||
ContentAPI.registerLogoutListener(player, SE_LOGOUT_KEY){p ->
|
||||
ContentAPI.teleport(p, p.getAttribute(SE_KEY_LOC, p.location))
|
||||
}
|
||||
|
||||
player.properties.teleportLocation = Location.create(1886, 5025, 0)
|
||||
}
|
||||
|
||||
fun cleanup(player: Player){
|
||||
player.properties.teleportLocation = player.getAttribute(SE_KEY_LOC,null)
|
||||
player.removeLogoutListener(SE_LOGOUT_KEY)
|
||||
ContentAPI.clearLogoutListener(player, SE_LOGOUT_KEY)
|
||||
player.removeAttribute(SE_KEY_LOC)
|
||||
player.removeAttribute(SE_KEY_INDEX)
|
||||
player.removeAttribute(SE_KEY_CORRECT)
|
||||
|
||||
+7
-2
@@ -1,5 +1,6 @@
|
||||
package rs09.game.interaction.region.dungeons.brimhaven
|
||||
|
||||
import api.ContentAPI
|
||||
import core.game.content.global.action.ClimbActionHandler
|
||||
import core.game.node.`object`.Scenery
|
||||
import core.game.node.`object`.SceneryBuilder
|
||||
@@ -47,7 +48,11 @@ object BrimhavenUtils {
|
||||
player.lock(12)
|
||||
val dir = AgilityHandler.forceWalk(player, -1, player.location, node.location, Animation.create(769), 10, 0.0, null).direction
|
||||
val loc = player.location
|
||||
player.logoutListeners["steppingstone"] = { p -> p.properties.teleportLocation = loc }
|
||||
|
||||
ContentAPI.registerLogoutListener(player, "steppingstone"){p ->
|
||||
ContentAPI.teleport(p, loc)
|
||||
}
|
||||
|
||||
GameWorld.Pulser.submit(object : Pulse(3, player) {
|
||||
var stage = if (dir == Direction.NORTH) -1 else 0
|
||||
var direction = dir
|
||||
@@ -62,7 +67,7 @@ object BrimhavenUtils {
|
||||
}
|
||||
if (stage == 6) {
|
||||
player.achievementDiaryManager.finishTask(player, DiaryType.KARAMJA, 1, 15)
|
||||
player.logoutListeners.remove("steppingstone")
|
||||
ContentAPI.clearLogoutListener(player, "steppingstone")
|
||||
}
|
||||
AgilityHandler.forceWalk(player, -1, l, l.transform(direction), Animation.create(769), 10, 0.0, null)
|
||||
return stage == 6
|
||||
|
||||
Reference in New Issue
Block a user