mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-16 03:20:19 -07:00
Teleblock now persists across login sessions
This commit is contained in:
parent
419533e6c8
commit
67e54d5429
1 changed files with 35 additions and 4 deletions
|
|
@ -1,8 +1,12 @@
|
||||||
package core.game.node.entity.state.impl;
|
package core.game.node.entity.state.impl;
|
||||||
|
|
||||||
|
import api.PersistPlayer;
|
||||||
import core.game.node.entity.Entity;
|
import core.game.node.entity.Entity;
|
||||||
import core.game.node.entity.player.Player;
|
import core.game.node.entity.player.Player;
|
||||||
|
import core.game.node.entity.state.EntityState;
|
||||||
import core.game.node.entity.state.StatePulse;
|
import core.game.node.entity.state.StatePulse;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
|
@ -10,17 +14,17 @@ import java.nio.ByteBuffer;
|
||||||
* Handles the teleblock state pulse.
|
* Handles the teleblock state pulse.
|
||||||
* @author Vexia
|
* @author Vexia
|
||||||
*/
|
*/
|
||||||
public final class TeleblockStatePulse extends StatePulse {
|
public final class TeleblockStatePulse extends StatePulse implements PersistPlayer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ticks needed to pass.
|
* The ticks needed to pass.
|
||||||
*/
|
*/
|
||||||
private final int ticks;
|
public int ticks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current tick.
|
* The current tick.
|
||||||
*/
|
*/
|
||||||
private int currentTick;
|
public int currentTick;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new {@Code TeleblockStatePulse} {@Code Object}
|
* Constructs a new {@Code TeleblockStatePulse} {@Code Object}
|
||||||
|
|
@ -34,6 +38,33 @@ public final class TeleblockStatePulse extends StatePulse {
|
||||||
this.currentTick = currentTick;
|
this.currentTick = currentTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Required to be instantiated as a ContentListener for PersistPlayer
|
||||||
|
public TeleblockStatePulse() {
|
||||||
|
super(null, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void savePlayer(@NotNull Player player, @NotNull JSONObject save) {
|
||||||
|
TeleblockStatePulse tbPulse = (TeleblockStatePulse) player.getStateManager().get(EntityState.TELEBLOCK);
|
||||||
|
|
||||||
|
if (tbPulse != null && tbPulse.isSaveRequired()) {
|
||||||
|
JSONObject tbObj = new JSONObject();
|
||||||
|
tbObj.put("tb-state-current", "" + tbPulse.currentTick);
|
||||||
|
tbObj.put("tb-state-total", "" + tbPulse.ticks);
|
||||||
|
save.put("teleblock-state", tbObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parsePlayer(@NotNull Player player, @NotNull JSONObject data) {
|
||||||
|
if (data.containsKey("teleblock-state")) {
|
||||||
|
JSONObject tbData = (JSONObject) data.get("teleblock-state");
|
||||||
|
int currentTick = Integer.parseInt(tbData.get("tb-state-current").toString());
|
||||||
|
int totalTicks = Integer.parseInt(tbData.get("tb-state-total").toString());
|
||||||
|
player.getStateManager().set(EntityState.TELEBLOCK, totalTicks, currentTick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSaveRequired() {
|
public boolean isSaveRequired() {
|
||||||
return currentTick < ticks;
|
return currentTick < ticks;
|
||||||
|
|
@ -68,7 +99,7 @@ public final class TeleblockStatePulse extends StatePulse {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StatePulse create(Entity entity, Object... args) {
|
public StatePulse create(Entity entity, Object... args) {
|
||||||
return new TeleblockStatePulse(entity, (int) args[0], 0);
|
return new TeleblockStatePulse(entity, (int) args[0], args.length > 1 ? (int) args[1] : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue