0

好的,所以我收到了这个错误。我试着让房子可序列化,但它仍然不起作用?我现在不知道该怎么做。如果有人可以提供帮助,我将不胜感激!

[GTLVote V1.1] Settings initializing...
[GTLVote V1.1] Connected to the database
[Launcher] Initing Cache...
[Launcher] Initing Data Files...
[ShopsHandler] Packing shops...
[Launcher] Initing Fishing Spots...
[Auto-Backup] The mainsave has already been backed up today.
[Launcher] Initing Fishing Spots...
[Launcher] Initing NPC Combat Scripts...
[Launcher] Initing Dialogues...
[Launcher] Initing Controlers...
[Launcher] Initing Cutscenes...
[Launcher] Initing Friend Chats Manager...
[Launcher] Initing Cores Manager...
[Launcher] Initing World...
[Launcher] Initing Region Builder...
[Launcher] Initing Server Channel Handler...
[Launcher] Server took 9624 milli seconds to launch.
ERROR! THREAD NAME: New I/O  worker #1
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException
: com.rs.game.player.content.construction.House
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at com.rs.utils.SerializableFilesManager.loadSerializedFile(Serializable
FilesManager.java:67)
    at com.rs.utils.SerializableFilesManager.loadPlayer(SerializableFilesMan
ager.java:25)
    at com.rs.net.decoders.LoginPacketsDecoder.decodeWorldLogin(LoginPackets
Decoder.java:169)
    at com.rs.net.decoders.LoginPacketsDecoder.decode(LoginPacketsDecoder.ja
va:43)
    at com.rs.net.ServerChannelHandler.messageReceived(ServerChannelHandler.
java:98)
    at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleCha
nnelHandler.java:95)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultCh
annelPipeline.java:563)
    at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultCh
annelPipeline.java:558)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:26
8)
    at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:25
5)
    at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:91)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedK
eys(AbstractNioWorker.java:373)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioW
orker.java:247)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)
    at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnabl
e.java:102)
    at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProof
Worker.java:42)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.NotSerializableException: com.rs.game.player.content.construc
tion.House
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at com.rs.utils.SerializableFilesManager.storeSerializableClass(Serializ
ableFilesManager.java:76)
    at com.rs.utils.SerializableFilesManager.savePlayer(SerializableFilesMan
ager.java:53)
    at com.rs.Launcher.saveFiles(Launcher.java:178)
    at com.rs.Launcher$3.run(Launcher.java:165)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
    at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
access$301(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
run(Unknown Source)
    ... 3 more

我明白了,我已经尝试让它可序列化。

这是我的房子.java

package com.rs.game.player.content.construction;

import java.util.ArrayList;
import java.util.List;

import com.rs.game.DynamicRegion;
import com.rs.game.Region;
import com.rs.game.RegionBuilder;
import com.rs.game.World;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.item.Item;
import com.rs.game.player.Player;
import com.rs.utils.Logger;
import java.io.Serializable;

public class House implements Serializable {

private static final long serialVersionUID = 7526472295622776147L;
private List<RoomReference> rooms;
private byte place, look;
private Player player;

public House(Player player) {
    this.player = player;
    rooms = player.getRooms();
    place = (byte) player.getPlace(); //desert
}

public void refresh(Player player, int[] boundChuncks) {
    player.setForceNextMapLoadRefresh(true);
    constructHouse(boundChuncks, true);
    player.loadMapRegions();
}

public void sendFurnitureInterface(Item[] items) {
    player.getPackets().sendItems(396, items);
}

public void constructHouse(int[] boundChuncks, boolean buildMode) {
    Logger.log(this, place);
    Object[][][][] data = new Object[4][8][8][];
    for(RoomReference reference : rooms) {
        data[reference.getPlane()][reference.getX()][reference.getY()] =
            new Object[] {reference.getRoom().getChunkX(),  reference.getRoom().getChunkY(),
                reference.getRotation(), reference.getRoom().isShowRoof()};
    }
    if(!buildMode) { //construct roof
        for(int x = 1; x < 7; x++) {
            skipY: for(int y = 1; y < 7; y++) {
                for(int plane = 2; plane >= 0; plane--) {
                    if(data[plane][x][y] != null) {
                        boolean hasRoof = (boolean) data[plane][x][y][3];
                        if(hasRoof) {
                            byte rotation = (byte) data[plane][x][y][2];           
                            //TODO find best Roof
                            data[plane+1][x][y] = new Object[] {
                                    Roof.ROOF1.getChunkX(),
                                    Roof.ROOF1.getChunkY(), rotation, true};
                            continue skipY;
                        }
                    }
                }
            }
        }
    }
    for(int plane = 0; plane < data.length; plane++) {
        for(int x = 0; x < data[plane].length; x++) {
            for(int y = 0; y < data[plane][x].length; y++) {
                if(data[plane][x][y] != null)
                    RegionBuilder.copyChunk((int)data[plane][x][y][0] +
                            ((boolean)data[plane][x][y][3] && look >= 4 ? 8 : 0)
                            , (int)data[plane][x][y][1],
                            (boolean)data[plane][x][y][3] ? look % 4 : place
                            , boundChuncks[0]+x, boundChuncks[1]+y, plane,(byte)data[plane][x][y][2]);
                else if (plane == 0)
                    RegionBuilder.copyChunk(LAND[0], LAND[1], place, boundChuncks[0]+x, boundChuncks[1]+y, plane, 0);
            }
        }
    }
    Region region = World.getRegion(RegionBuilder.getRegionHash(boundChuncks[0]/8, boundChuncks[1]/8));
    List<WorldObject> spawnedObjects = region.getSpawnedObjects();
    if(spawnedObjects != null)
        spawnedObjects.clear();
    List<WorldObject> removedObjects = region.getRemovedObjects();
    if(removedObjects != null)
        removedObjects.clear();
    for(RoomReference reference : rooms) {
        int boundX = reference.getX() * 8;
        int boundY = reference.getY() * 8;
        int boundX1 = boundChuncks[0] * 8;
        int boundY1 = boundChuncks[1] * 8;
        int chunkRotation = region.getRotation(reference.getPlane(), boundX, boundY);
        for(int x = boundX; x < boundX+8; x++) {
            for(int y = boundY; y < boundY+8; y++) {
                WorldObject[] objects = region.getObjects(reference.getPlane(), x, y);
                if(objects != null) {
                    for(WorldObject object : objects) {
                        /*
                         * Remove the build hotspots (not 100%)
                         */
                        if(!buildMode && object.getDefinitions().containsOption("Build")) {
                            object = new WorldObject(object.getId(), object.getType(), (object.getRotation() + chunkRotation) % 4, x + boundChuncks[0]*8,y + boundChuncks[1]*8, reference.getPlane());
                            /*if (object.getDefinitions().name.equalsIgnoreCase("door hotspot")) {
                                WorldObject object1 = new WorldObject(getDoorId(), object.getType(), object.getRotation() + 1, object.getX(), object.getY(), reference.getPlane());
                                    World.removeObject(object, true);
                            }*/
                            if (object.getDefinitions().name.equalsIgnoreCase("door hotspot")) {
                                /*if (!reference.getRoom().doesHaveDoors()) {
                                    World.removeObject(object, true);
                                }
                                if (player.getRoomFor(reference.getX() + 1, reference.getY()) != null) {
                                    World.removeObject(object, true);
                                }
                                if (player.getRoomFor(reference.getX() - 1, reference.getY()) != null) {
                                    World.removeObject(object, true);
                                }
                                if (player.getRoomFor(reference.getX(), reference.getY() + 1) != null) {
                                    World.removeObject(object, true);
                                }
                                if (player.getRoomFor(reference.getX(), reference.getY() - 1) != null) {
                                    World.removeObject(object, true);
                                }
                                System.out.println("removing door");
                                */
                                if (reference.getRoom().doesHaveDoors()) {
                                    World.spawnObject(new WorldObject(13100, object.getType(), object.getRotation(), object.getX(), object.getY(), object.getPlane()), true);
                                }
                            }
                            else if (object.getDefinitions().name.equalsIgnoreCase("window space")) {
                                System.out.println(object.getId());
                            } else {
                                World.removeObject(object, true);
                            }
                            try {
                                System.out.println("spawning portal");
                                WorldObject o = new WorldObject(13405, 10, 4, boundChuncks[0]*8 + 35, boundChuncks[1]*8 + 35, 0);
                                World.spawnObject(o, true);
                                for (WorldObject o1 : player.getConObjectsToBeLoaded()) {
                                    System.out.println(o1.getDefinitions().getOption(5));
                                    World.spawnObject(o1, true);
                                }
                            } catch (NullPointerException e) {
                                e.printStackTrace();
                            }
                        }
                        /*
                         * Spawn the objects & the hotspots
                         */
                        else if (object.getDefinitions().name.equals("Window")) {
                            object = new WorldObject(getWindowId(), object.getType(), (object.getRotation() + chunkRotation) % 4, x + boundChuncks[0]*8,y + boundChuncks[1]*8, reference.getPlane());
                            World.spawnObject(object, true);
                        }

                        else {
                            /*if (object.getDefinitions().name.equalsIgnoreCase("door hotspot")) {
                                if (reference.getRoom().doesHaveDoors()) {
                                    World.spawnObject(object, true);
                                }
                                if (player.getRoomFor(reference.getX() + 1, reference.getY()) == null) {
                                    World.spawnObject(object, true);
                                }
                                if (player.getRoomFor(reference.getX() - 1, reference.getY()) == null) {
                                    World.spawnObject(object, true);
                                }
                                if (player.getRoomFor(reference.getX(), reference.getY() + 1) == null) {
                                    World.spawnObject(object, true);
                                }
                                if (player.getRoomFor(reference.getX(), reference.getY() - 1) == null) {
                                    World.spawnObject(object, true);
                                }
                                System.out.println("removing door");
                            }*/
                            try {
                                for (WorldObject o1 : player.getConObjectsToBeLoaded()) {
                                    World.spawnObject(o1, true);
                                }
                                WorldObject o = new WorldObject(13405, 10, 4, boundChuncks[0]*8 + 35, boundChuncks[1]*8 + 35, 0);
                                World.spawnObject(o, true);
                            } catch (NullPointerException e) {
                                System.out.println("Player objects are null");
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    }
}

public void previewRoom(Player player, int[] boundChuncks, RoomReference reference, boolean remove) {
    int boundX = reference.getX() * 8;
    int boundY = reference.getY() * 8;
    Region region = World.getRegion(RegionBuilder.getRegionHash(reference.getRoom().getChunkX()/8, reference.getRoom().getChunkY()/8));
    int boundX2 = (reference.getRoom().getChunkX() - (reference.getRoom().getChunkX() / 8 * 8)) * 8;
    int boundY2 = (reference.getRoom().getChunkY() - (reference.getRoom().getChunkY() / 8 * 8)) * 8;
    DynamicRegion house = (DynamicRegion) World.getRegion(RegionBuilder.getRegionHash(player.getBoundChuncks()[0]/8, player.getBoundChuncks()[1]/8));
    house.getRegionCoords()[reference.getPlane()][reference.getX()][reference.getY()][3] = reference.getRotation();
    for(int x = 0; x < 8; x++) {
        for(int y = 0; y < 8; y++) {
            WorldObject[] objects = region.getObjects(reference.getPlane(), boundX2+x, boundY2+y);
            if(objects != null) {
                for(WorldObject object : objects) {
                    if(object.getDefinitions().containsOption("Build")) {
                        System.out.println("test");
                        int x2 = x;
                        int y2 = y;
                        for (int rotate = 0; rotate < reference.getRotation(); rotate++) {
                            int fakeChunckX = x2;
                            int fakeChunckY = y2;
                            x2 = fakeChunckY;
                            y2 = 7 - fakeChunckX;
                        }
                        object = new WorldObject(object.getId(), object.getType(), (object.getRotation() + reference.getRotation()) % 4, boundX + x2 + boundChuncks[0]*8, boundY + y2 + boundChuncks[1]*8, reference.getPlane());
                        if(remove)
                            player.getPackets().sendDestroyObject(object);
                        else
                            player.getPackets().sendSpawnedObject(object);
                    }
                }
            }
        }
    }
}

public int getWindowId() {
    switch(place) {
    case 0:
        return 13099;
    case 1:
        return 13115;
    case 2:
        return 0;
    case 3:
        return 0;
    default:
        return 13115;
    }
}

public int getDoorId() {
    switch(place) {
    case 0:
        return 13100;
    default:
        return 1058;
    }
}
private final static int[] LAND = {233, 632};

}

4

1 回答 1

2

要使该类Serializable既是它,它的超类和其中的所有内容都需要是 ,或者通过将其Serializable标记为标记为您不想成为的东西Serializabletransient

序列化跨越要序列化的类(即所有字段)以及超类(及其各自的字段)。

在你的情况下,我会检查两者RoomReference并且Player也是Serializable

查看有关序列化的Oracle 文档以获取更多信息。

于 2013-04-16T15:01:50.140 回答