RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
ExchangeSessionManager.java
1package com.osroyale.game.world.entity.mob.player.exchange;
2
3import com.osroyale.net.packet.out.SendMessage;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.util.MessageColor;
6
7import java.util.ArrayList;
8import java.util.List;
9import java.util.Optional;
10
48
49public final class ExchangeSessionManager {
50
54 public final List<Player> requested_players = new ArrayList<>();
55
59 public final Player player;
60
66 this.player = player;
67 }
68
73 public boolean request(ExchangeSession session) {
74 return session.request();
75 }
76
82 public boolean deposit(int slot, int amount) {
83 ExchangeSession session = ExchangeSession.getSession(player).orElse(null);
84
85 if(session == null) {
86 return false;
87 }
88
89 return session.add(player, slot, amount);
90 }
91
97 public boolean withdraw(int slot, int amount) {
98 ExchangeSession session = ExchangeSession.getSession(player).orElse(null);
99
100 if(session == null) {
101 return false;
102 }
103
104 return session.remove(player, slot, amount);
105 }
106
107
111 public void reset(ExchangeSessionType type) {
112 Optional<ExchangeSession> session = ExchangeSession.getSession(player, type);
113
114 if(!session.isPresent()) {
115 return;
116 }
117
118 session.get().forEach(p -> {
119 session.get().finalize(ExchangeCompletionType.RESTORE);
121 p.interfaceManager.close();
122 });
123
124 Player other = session.get().getOther(player);
125 other.send(new SendMessage("The other player has declined.", MessageColor.RED));
126 ExchangeSession.SESSIONS.remove(session.get());
127 }
128
132 public boolean reset() {
133 Optional<ExchangeSession> session = ExchangeSession.getSession(player);
134
135 if(!session.isPresent()) {
136 return false;
137 }
138
139 reset(session.get().type);
140 return true;
141 }
142
146 public void resetRequests() {
147 player.exchangeSession.requested_players.clear();
148 }
149}
final boolean remove(Player player, int slot, int amount)
final boolean add(Player player, int slot, int amount)
static Optional< ExchangeSession > getSession(Player player)