Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:21:31+00:00 2026-06-07T17:21:31+00:00

Well I have this class for a game I’m making, and I’m trying to

  • 0

Well I have this class for a game I’m making, and I’m trying to save the ArrayList notes. When I logout, it properly print the size, for example if I have 5 notes, when I log out notes.getSize() would be 5, but when I log in, it gets reset back to nothing. Why isn’t notes saving?

public class Notes implements Serializable {

    private static final long serialVersionUID = -4947870743226160329L;
    private ArrayList<Note> notes = new ArrayList<Note>(30);

    public class Note implements Serializable {

        private static final long serialVersionUID = -4589885080580317958L;

        private int color = 0;
        private String text = "";

        public Note(int color, String text) {
            this.setColor(color);
            this.setText(text);
        }

        public void setText(String text) {
            this.text = text;
        }

        public String getText() {
            return text;
        }

        public void setColor(int color) {
            this.color = color;
        }

        public int getColor() {
            return color;
        }
    }

    private transient Player player;

    public Notes(Player p) {
        this.player = p;
    }

    public void addNote(String text) {
        System.out.println("Note Text: "+text);
        if (text.length() > 50) {
            player.getPackets().sendGameMessage("You can only enter notes up to 50 characters!");
            return;
        }
        if (notes.size() < 30) {
            notes.add(new Note(0, text));
        } else {
            player.getPackets().sendGameMessage("You cannot add more then 30 notes!");
            return;
        }
        int NoteId = notes.size() - 1;
        player.getPackets().sendConfig(1439, NoteId);
        player.getTemporaryAttributtes().put("selectedNote", NoteId);
        refreshNotes(false);
    }

    public void addNote(String text, int color) {
        notes.add(new Note(color, text));
    }

    public void loadNotes() {
        player.getPackets().sendIComponentSettings(34, 9, 0, 30, 2621470);
        player.getPackets().sendHideIComponent(34, 3, false);
        player.getPackets().sendHideIComponent(34, 44, false);
        player.getPackets().sendIComponentText(34, 13, "Loading notes<br>Please wait...");
        player.getPackets().sendConfig(1439, -1);
        refreshNotes(true);
    }

    public void refreshNotes(boolean sendStartConfigs) {
        for (int i = 0; i < 30; i++) {
            player.getPackets().sendGlobalString(149 + i, i < notes.size() ? notes.get(i).getText() : "");
        }
        if (sendStartConfigs) {
            for (int i = 1430; i < 1450; i++)
                player.getPackets().sendConfig(i, i);
        }
        player.getPackets().sendConfig(1440, getFirstTotalColorValue());
        player.getPackets().sendConfig(1441, getSecondTotalColorValue());
    }


    public int intColorValue(int color, int noteId) {
        return (int) (Math.pow(4, noteId) * color);
    }

    public int getFirstTotalColorValue() {
        int Color = 0;
        for (int i = 0; i < 15; i++) {
            if (notes.size() > i)
                Color += intColorValue(notes.get(i).getColor(), i);
        }
        return Color;
    }

    public int getSecondTotalColorValue() {
        int color = 0;
        for (int i = 0; i < 15; i++) {
            if (notes.size() > (i + 16))
                color += intColorValue(notes.get(i + 16).getColor(), i);
        }
        return color;
    }

    public void deleteSelectedNote() {
        if ((int)player.getTemporaryAttributtes().get("selectedNote") > -1) {
            int slot = (int) player.getTemporaryAttributtes().get("selectedNote");
            notes.remove(slot);
            player.getTemporaryAttributtes().put("selectedNote", -1);
            player.getPackets().sendConfig(1439, -1);
            refreshNotes(false);
        }
    }

    public void clear() {
        notes.clear();
        refreshNotes(false);
    }

    public void editNote(String string, int index) {
        notes.get(index).setText(string);
        refreshNotes(false);
    }

    public void setColor(int color, int index) {
        notes.get(index).setColor(color);
        refreshNotes(false);
    }

    public void deleteNote(int slot) {
        notes.remove(slot);
        refreshNotes(false);
    }

    public void setNotes(ArrayList<Note> setNotes) {
        notes = setNotes;
        refreshNotes(false);
    }

}

And here is the class I manage saving/loading in

public class SerializableFilesManager {

private static final String PATH = "data/characters/";
private static final String BACKUP_PATH = "data/charactersBackup/";

public synchronized static final boolean containsPlayer(String username) {
    return new File(PATH + username + ".p").exists();
}

public synchronized static Player loadPlayer(String username) {
    try {
        return (Player) loadSerializedFile(new File(PATH + username + ".p"));
    } catch (Throwable e) {
        Logger.handle(e);
    }
    try {
        Logger.log("SerializableFilesManager", "Recovering account: "
                + username);
        return (Player) loadSerializedFile(new File(BACKUP_PATH + username
                + ".p"));
    } catch (Throwable e) {
        Logger.handle(e);
    }
    return null;
}

public static boolean createBackup(String username) {
    try {
        Utils.copyFile(new File(PATH + username + ".p"), new File(
                BACKUP_PATH + username + ".p"));
        return true;
    } catch (Throwable e) {
        Logger.handle(e);
        return false;
    }
}

public synchronized static void savePlayer(Player player) {
    try {
        storeSerializableClass(player, new File(PATH + player.getUsername()
                + ".p"));
    } catch (ConcurrentModificationException e) {
        //happens because saving and logging out same time
    } catch (Throwable e) {
        Logger.handle(e);
    }
}

public static final Object loadSerializedFile(File f) throws IOException,
        ClassNotFoundException {
    if (!f.exists())
        return null;
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(f));
    Object object = in.readObject();
    in.close();
    return object;
}

public static final void storeSerializableClass(Serializable o, File f)
        throws IOException {

    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f));
    out.writeObject(o);
    out.close();
}

private SerializableFilesManager() {

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:21:34+00:00Added an answer on June 7, 2026 at 5:21 pm
    1. Do NOT mark Player as transient, cause you are saving it, transient will prevent if from
      getting saved, and will bring player to the default value of null, when deserialized.

    2. Have you made the player class serializable ?

    3. Its the Entire object graph that gets serialized or none… the purpose of transient is to make a particular member to be left off during serialization so that, the process of serialization goes smoothly.

    4. For example, Suppose in a game we want to keep the progress of the player and hours of play for that session, but not the starting and ending times. So the starting and ending time can be made transient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this scenario well, i'll let the model explain. public class ScheduleMonthlyPerDayModel {
I have a class extends NamedParameterJdbcDaoSupport. well this superclass has a final setDataSource method
Well I have this code in my Managed C++/Cli in Visual Studio 2008, I
Well currently I have this: <rich:fileUpload addLabel=Agregar clearAllLabel=Quitar todos clearLabel=Quitar deleteLabel=Quitar doneLabel=Completado uploadLabel=Subir archivos
I have this routine that works well, but it messes up as it counts
I have this linq query that works well (although it may be written better,
I have this code that works well: {livre:empty_name} $.ajax({ url: sent.php, type: post, dataType:
Well this is weird let me describe the scenario I have this mailer define
I have this structure in my html document: <p> <em>You</em> began the evening well,
i have this PHP code, and a DataBase with Question, answer1, answer2, Question_id well,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.