Improved constructors

This commit is contained in:
kuroppoi 2021-04-24 20:31:14 +02:00
parent aef8eb4e46
commit 46f3fb1906
3 changed files with 14 additions and 14 deletions

View file

@ -90,14 +90,14 @@ public class Player extends Entity implements CommandExecutor {
private final Map<Skill, Integer> skills = new HashMap<>();
private final Map<Integer, Long> activeChunks = new HashMap<>();
private final Map<Integer, ConfigurableDialog> dialogs = new HashMap<>();
private final Inventory inventory = new Inventory();
private Item heldItem = Item.AIR; // TODO send on entity add
private int teleportX;
private int teleportY;
private long lastHeartbeat;
private Connection connection;
public Player(String documentId, String name, Zone zone) {
@ConstructorProperties({"documentId", "name", "current_zone"})
public Player(@JacksonInject("documentId") String documentId, String name, Zone zone) {
super(zone);
for(Skill skill : Skill.values()) {
@ -120,18 +120,6 @@ public class Player extends Entity implements CommandExecutor {
settings.put("appearance", test);
}
@JsonCreator
private static Player create(@JacksonInject("documentId") String documentId, @JsonProperty("name") String name, @JsonProperty("current_zone") String currentZone) {
ZoneManager zoneManager = GameServer.getInstance().getZoneManager();
Zone zone = zoneManager.getZone(currentZone);
if(zone == null) {
zone = zoneManager.getRandomZone();
}
return new Player(documentId, name, zone);
}
@Override
public EntityType getType() {
return EntityType.PLAYER;

View file

@ -56,6 +56,11 @@ public class PlayerManager {
try {
Player player = mapper.readValue(file, Player.class);
if(player.getZone() == null) {
player.setZone(GameServer.getInstance().getZoneManager().getRandomZone());
}
String name = player.getName();
if(playersByName.containsKey(name)) {

View file

@ -13,9 +13,11 @@ import java.util.Map.Entry;
import java.util.Set;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import com.fasterxml.jackson.annotation.JsonValue;
import brainwine.gameserver.GameServer;
import brainwine.gameserver.entity.Entity;
import brainwine.gameserver.entity.EntityStatus;
import brainwine.gameserver.entity.player.ChatType;
@ -96,6 +98,11 @@ public class Zone {
Arrays.fill(sunlight, height);
}
@JsonCreator
private static Zone fromId(String id) {
return GameServer.getInstance().getZoneManager().getZone(id);
}
public void tick() {
for(Entity entity : getEntities()) {
entity.tick();