0

我一无所知...这只是不断抛出异常

       package com.rs.game.player.quests;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.rs.game.player.Player;
import com.rs.game.player.quests.impl.CooksAssistant;

/**
 * A component that is used for storing, and handling quests.
 * 
 * @author Thomas Le Godais <thomaslegodais@live.com>
 *
 */
public class NewQuestManager implements Serializable {

private static final long serialVersionUID = 4642641500529290457L;

/** The singleton instance for the component **/
private static NewQuestManager singleton = null;
private transient Player player;
private transient Quest<?, ?> quest;

/** A map containing current quests. **/
private Map<Integer, Quest<?, ?>> questMap = new HashMap<Integer, Quest<?, ?>>();

public void setPlayer(Player player) {
    this.player = player;
}

public Quest<?, ?> getQuest() {
    return quest;
}

/**
 * Constructs a new QuestComponent instance.
 */
public NewQuestManager() {
    questMap.put(1, new CooksAssistant());
}

/**
 * Starts a quest based on the id.
 * 
 * @param player The player.
 * @param questId The quest id.
 */
public void startQuest(int questId) {
    quest = questMap.get(questId);
    if (quest == null)
        return;
    quest.setPlayer(player);
    quest.handleQuest();
}


/**
 * Gets a certain quest from the map.
 * 
 * @param questIndex the index.
 * @return the quest.
 */
public Quest<?, ?> getQuest(int questIndex) {
    return questMap.get(questIndex);
}

/**
 * Gets the quests.
 * 
 * @return the quests.
 */
public Quest<?, ?> getQuests() {
    for(int index = 0; index < questMap.size();)
            return questMap.get(index);
    return null;
}

/**
 * Gets the singleton instance for the component.
 * 
 * @return The singleton instance.
 */
public NewQuestManager getSingleton() {
    if(singleton == null)
        singleton = new NewQuestManager();
    return singleton;
}
}

异常所指的第二类

 package com.rs.game.player.quests.impl;

import java.io.Serializable;

import com.rs.game.player.dialogues.Dialogue;
import com.rs.game.player.quests.Quest;

/**
 * Handles the cooks assistant quest.
 * 
 * @author Thomas Le Godais <thomaslegodais@live.com>
 *
 */
public class CooksAssistant extends Quest<CooksAssistant.Stage, CooksAssistant.Nodes> implements Serializable {

    /**
     * The current nodes of the quest.
     * 
     * @author Thomas Le Godais <thomaslegodais@live.com>
     *
     */
    public enum Nodes {
        /*
         * The chef node.
         */
        CHEF(false);


        /** The interaction value. **/
        private boolean value;

        /**
         * Constructs a new Nodes instance.
         * 
         * @param value the value.
         */
        private Nodes(boolean value) {
            this.value = value;
        }

        /**
         * Gets the value of the node.
         * 
         * @return the value.
         */
        public boolean getValue() {
            return value;
        }

        /**
         * Sets the value of the node.
         * 
         * @param newValue the new value to set.
         */
        public void setValue(boolean newValue) {
            this.value = newValue;
        }
    }

    /**
     * The different stages of the quest.
     * 
     * @author Thomas Le Godais <thomaslegodais@live.com>
     *
     */
    public enum Stage {
        /*
         * Start the quest.
         */
        START,

        /*
         * Gather the ingredients.
         */
        GATHER_INGREDIENTS, 

        /*
         * The talk to chef.
         */
        TALK_TO_CHEF, 

        /*
         * Finish the quest.
         */
        FINISH

    }

    /**
     * Constructs a new CooksAssistant instance.
     */
    public CooksAssistant() {
        super("Cooks' Assistant", 1, Stage.START, Nodes.CHEF);
    }


    @Override
    public void handleQuest() {
        switch(getQuestState()) {
        case START:
            player.getPackets().sendRunScript(1207, new Object[] { 5 });    
            player.getInterfaceManager().sendInterface(275);

            for(int i = 0; i < 21; i++)
                player.getPackets().sendIComponentText(275, i, "");

            player.getPackets().sendIComponentText(275, 1, this.getName());
            player.getPackets().sendIComponentText(275, 10, "Begin by speaking with the Cook in Lumbridge Castle.");

            player.getPackets().sendIComponentText(275, 12, "Requirments:");
            player.getPackets().sendIComponentText(275, 13, "<str>None.</str>");
            break;

        case GATHER_INGREDIENTS:
            player.getPackets().sendRunScript(1207, new Object[] { 5 });    
            player.getInterfaceManager().sendInterface(275);

            for(int i = 0; i < 21; i++)
                player.getPackets().sendIComponentText(275, i, "");

            player.getPackets().sendIComponentText(275, 1, this.getName());
            player.getPackets().sendIComponentText(275, 10, "Gather the ingrediants");
            break;

        case TALK_TO_CHEF:

            break;

        case FINISH:

            break;
        }
    }


    @Override
    public void handleDialogue(int npcId) {
        switch(npcId) {
        case 847:
            player.getDialogueManager().startDialogue(new Dialogue() {

                private int npcId;

                @Override
                public void start() {                   
                    npcId = 847;

                    if(hasInteracted(Nodes.CHEF))
                        sendNPCDialogue(npcId, 9827, "Have you gathered my ingredients?.");
                    else
                        sendNPCDialogue(npcId, 9827, "Waahh, what am I to do? I'm so done for!!");
                }

                @Override
                public void run(int interfaceId, int componentId) {
                    if (!(hasInteracted(Nodes.CHEF))) {
                        switch (stage) {
                        case -1:
                            this.sendOptionsDialogue("What would you like?", new String[] { "What's wrong, chef?", "Grow up, you big baby!", "Nevermind, I'll leave you alone." });
                            stage = 0;
                            break;
                        case 0:
                            if (componentId == OPTION_1) {
                                sendPlayerDialogue(9827, "What's wrong, chef?");
                                stage = 1;
                            } else if (componentId == OPTION_2) {
                                sendPlayerDialogue(9827, "Grow up, you big baby!");
                            } else if (componentId == OPTION_3) {
                                sendPlayerDialogue(9827, "Nevermind, I'll leave you alone.");
                            }
                            break;
                            /*
                             * I need some ingredients for the kings birthday cake.
                             */
                        case 1:
                            sendNPCDialogue(npcId, 9827, "I need some ingredients for the kings birthday cake, and I do not have enough time to go get them myself.");
                            stage = 2;
                            break;
                            /*
                             * What do you need?
                             */
                        case 2:
                            sendPlayerDialogue(9827, "Well maybe I could be of assistance, what do you need?");
                            stage = 3;
                            break;
                            /*
                             * I need milk, eggs, and flour.
                             */
                        case 3:
                            sendNPCDialogue(npcId, 9827, "Well I have the frosting, so I guess that just leaves milk, eggs, and flour. Do you think you could help me out, there will be a small reward.");
                            stage = 4;
                            break;
                            /*
                             * That shouldn't be too hard to get.
                             */
                        case 4:
                            sendPlayerDialogue(9827, "That shouldn't be too hard for me to gather, I'll be back in a jiffy!");
                            stage = 5;
                            break;
                            /*
                             * Oh my god, that you so much.
                             */
                        case 5:
                            sendNPCDialogue(npcId, 9827, "Thank you so much, " + player.getUsername() + ", I owe you big time!");
                            setQuestState(Stage.GATHER_INGREDIENTS);
                            for(Nodes node : Nodes.values()) {
                                if(node.equals(Nodes.CHEF)) {
                                    node.setValue(true);
                                    end();
                                }
                            }
                            stage = 15;
                            break;
                            /*
                             * This is where we end the current dialogue.
                             */
                        case 15:
                            end();
                            break;
                        }
                    } else {
                        switch(stage) {
                        case -1:
                            break;
                        }
                    }
                }

                @Override
                public void finish() {                  
                }
            });
            break;
        }
    }


    @Override
    public void handleObjectClick(int objectId, boolean firstClick, boolean secondClick, boolean thirdClick) {      
        if(firstClick) {
            switch(objectId) {

            }
            return;
        } else if(secondClick) {
            switch(objectId) {

            }
            return;
        } else if(thirdClick) {
            switch(objectId) {

            }
            return;
        }
    }


    @Override
    public boolean hasDialogue() {
        return true;
    }


    @Override
    public boolean hasObjectClick() {
        return false;
    }


    @Override
    public boolean hasInteracted(Nodes node) {
        if(node.getValue() == true)
            return true;
        return false;
    }
}

那是两个类继承人例外

java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.rs.game.player.quests.impl.CooksAssistant
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.util.HashMap.readObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(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.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.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(SerializableFilesManager.java:69)
at com.rs.utils.SerializableFilesManager.loadPlayer(SerializableFilesManager.java:26)
at com.rs.net.decoders.LoginPacketsDecoder.decodeWorldLogin(LoginPacketsDecoder.java:188)
at com.rs.net.decoders.LoginPacketsDecoder.decode(LoginPacketsDecoder.java:46)
at com.rs.net.ServerChannelHandler.messageReceived(ServerChannelHandler.java:98)
at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:95)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:558)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:91)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedKeys(AbstractNioWorker.java:373)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:247)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.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)

请帮忙,我不知道如何解决这个问题,而且我越来越生气......

4

1 回答 1

0

Serializable在课堂上实施CooksAssistant。确保超类中的所有字段都是Serializable. 将不可序列化的字段标记为transient

public class CooksAssistant extends Quest<CooksAssistant.Stage, CooksAssistant.Nodes> implements Serializable {
于 2013-09-08T19:56:59.927 回答