Thread: Help with Personal Stores

Results 1 to 4 of 4
  1. #1 Help with Personal Stores 
    Registered Member
    Join Date
    Dec 2018
    Posts
    11
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Hey,
    i've added personal store system to my rsps but it doesnot have a save and load function that whenever the server crashes it should save the latest personal stores and when i run the server it should load the saved personal stores.
    i added this code:

    public static void SavePersonalStores()
    {String json = GsonUtils.JSON_ALLOW_NULL.toJson(Store.getPersonal Shops());

    try(FileWriter writer = new FileWriter("./data/content/game/POSstoreSave.json")) {
    //write converted json data to a file named "POSstoreSave.json"

    writer.write(json);

    }
    catch(Exception e) { e.printStackTrace();

    }


    }
    this saves the personal stores like this:

    [{"rank":4,"title":"Adam's Store","caption":"No caption set","updating":false,"earnings":0,"name":"Adam", " container":{"listeners":[],"capacity":28,"policy":"STANDARD","items":[{"id":11802,"amount":1},null,null,null,null,nul l,n ull,null,null,null,null,null,null,null,null,null,n ull,null,null,null,null,null,null,null,null,null,n ull,null],"firingEvents":true},"currencyType":"COINS","i tem Cache":{},"players":[]}]
    now i typed this to load the saved stores:

    public static void LoadPersonalStores()
    { List<PersonalStore> personal_shops = new ArrayList<>();
    Path path = Paths.get("./data/content/game/POSstoreSave.json");

    if (!Files.exists(path)) {
    return;
    }
    try (FileReader reader = new FileReader(path.toFile())) {

    JsonParser parser = new JsonParser();
    personal_shops = (List<PersonalStore>) new GsonBuilder().create().fromJson(parser.parse(reade r), new TypeToken<List<PersonalStore>>() {}.getType());
    PersonalStore[] array = personal_shops.toArray(new PersonalStore[personal_shops.size()]);
    for (int i=0;i<personal_shops.size();i++)
    { Player player =new Player(array[i].name);

    Store.STORES.put(player.getName(), array[i]);





    } return;
    } catch (Exception e) {
    e.printStackTrace();
    }

    }
    now when i start the server it loads this

    [Only registered and activated users can see links. ]

    but when i press the store it doesnot open and i get this error in eclipse:

    ERROR: player=Adam error while handling event: PersonalStoreButtonPlugin
    [m java.lang.ClassCastException: [Lio.battlerune.game.world.items.Item; cannot be cast to [Lio.battlerune.content.store.StoreItem;
    at io.battlerune.content.store.impl.PersonalStore.ope n(PersonalStore.java:463) ~[bin/:?]
    at plugin.click.button.PersonalStoreButtonPlugin.onCl ick(PersonalStoreButtonPlugin.java:37) ~[bin/:?]
    at io.battlerune.game.plugin.PluginContext.handleButt onClickEvent(PluginContext.java:469) ~[bin/:?]
    at io.battlerune.game.plugin.PluginContext.accept(Plu ginContext.java:47) ~[bin/:?]
    at io.battlerune.game.event.bus.PlayerDataBus.publish (PlayerDataBus.java:98) ~[bin/:?]
    at io.battlerune.net.packet.in.ButtonClickPacketListe ner.handlePacket(ButtonClickPacketListener.java:49 ) ~[bin/:?]
    at io.battlerune.net.packet.PacketRepository.lambda$0 (PacketRepository.java:37) ~[bin/:?]
    at java.util.Optional.ifPresent(Unknown Source) ~[?:1.8.0_201]
    at io.battlerune.net.packet.PacketRepository.sendToLi stener(PacketRepository.java:37) ~[bin/:?]
    at io.battlerune.net.session.GameSession.processClien tPackets(GameSession.java:64) ~[bin/:?]
    at java.util.Optional.ifPresent(Unknown Source) ~[?:1.8.0_201]
    at io.battlerune.game.engine.GameEngine.lambda$0(Game Engine.java:74) ~[bin/:?]
    at io.battlerune.game.world.entity.MobList.forEach(Mo bList.java:174) [bin/:?]
    at io.battlerune.game.engine.GameEngine.runOneIterati on(GameEngine.java:73) [bin/:?]
    at com.google.common.util.concurrent.AbstractSchedule dService$ServiceDelegate$Task.run(AbstractSchedule dService.java:189) [guava-19.0.jar:?]
    at com.google.common.util.concurrent.Callables$3.run( Callables.java:100) [guava-19.0.jar:?]
    at java.util.concurrent.Executors$RunnableAdapter.cal l(Unknown Source) [?:1.8.0_201]
    at java.util.concurrent.FutureTask.runAndReset(Unknow n Source) [?:1.8.0_201]
    at java.util.concurrent.ScheduledThreadPoolExecutor$S cheduledFutureTask.access$301(Unknown Source) [?:1.8.0_201]
    at java.util.concurrent.ScheduledThreadPoolExecutor$S cheduledFutureTask.run(Unknown Source) [?:1.8.0_201]
    at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source) [?:1.8.0_201]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source) [?:1.8.0_201]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    Reply With Quote  
     

  2. #2  
    Registered Member

    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    30
    Posts
    12,429
    Thanks given
    155
    Thanks received
    3,924
    Rep Power
    5000
    how do u expect it to save if the server has crashed

    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Dec 2018
    Posts
    11
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Luke132 View Post
    how do u expect it to save if the server has crashed
    it saves after a player adds an item or removes or buys or make a store...
    Reply With Quote  
     

  4. #4  
    Registered Member
    arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,451
    Thanks given
    150
    Thanks received
    193
    Rep Power
    345
    Check the button in which you open another store and see so it sets or grab the right variable and not a different one.
    Cause it do look like you are trying to set a item class variable in a StoreItem class variable.


    "A fail act is something you do regular, but a dumb act is something you can learn from"
    Spoiler for Problem?:
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help with Point stores
    By Emre in forum Help
    Replies: 0
    Last Post: 06-26-2014, 09:27 PM
  2. Replies: 1
    Last Post: 08-07-2013, 06:08 AM
  3. Replies: 0
    Last Post: 08-07-2013, 05:38 AM
  4. need help with donator store [PI]
    By bandos beast in forum Help
    Replies: 7
    Last Post: 04-28-2013, 10:15 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •