[{"data":1,"prerenderedAt":139},["ShallowReactive",2],{"project--27-08-2024-dev-blog-4-build-a-skyblock-plugin":3},{"id":4,"title":5,"body":6,"description":121,"extension":122,"meta":123,"navigation":134,"path":135,"seo":136,"stem":137,"__hash__":138},"blog\u002Fblog\u002F27-08-2024-dev-blog-4-build-a-skyblock-plugin.md","Build a Skyblock Plugin (part 4): Cross server auctions",{"type":7,"value":8,"toc":109},"minimark",[9,14,18,23,39,43,46,49,52,57,60,63,70,73,76,80,83,86,89,93,96,100,103,106],[10,11,13],"h1",{"id":12},"dev-blog-4-build-a-skyblock-plugin-part-4-cross-server-auctions","Dev Blog #4: Build a Skyblock Plugin (part 4): Cross server auctions",[15,16,17],"p",{},"In the last article, we talked about the inventory synchronization between the servers.\nIn this article, we will talk about the cross server auctions.",[19,20,22],"h2",{"id":21},"considerations-requirements","Considerations \u002F Requirements",[24,25,26,30,33,36],"ul",{},[27,28,29],"li",{},"Once an item is sold, if you try to buy 2ms after it, you won't be able to",[27,31,32],{},"Transactional system",[27,34,35],{},"Should be compatible with ItemAdder items",[27,37,38],{},"Present on all servers",[19,40,42],{"id":41},"cross-server-auctions","Cross server auctions",[15,44,45],{},"I already done an auction system in the past. So I knew how to make the inventory system fast and reliable.\nThe only challenge was to handle the cross server part.",[15,47,48],{},"What happens if a player tries to buy an item on server 1 and the item is on server 2?\nWhat happens if a player buy an item on server 1 and another one on server 2 while the seller is removing the item?",[15,50,51],{},"For storage, I used Redis for caching and MySQL for persistent storage. I reused my class of the Inventory Sync System\nto store the items in the database.",[53,54,56],"h3",{"id":55},"the-solution","The solution",[15,58,59],{},"As always, my solution is to use a pubs\u002Fsubs system with Redis.",[15,61,62],{},"When a player puts an item on the auction house, the plugin will send a message to the Redis channel to notify all the\nservers that an item has been put on the auction house.\nWhen a player buys an item, the plugin will send a message to the Redis channel with the current timestamp and the\nitem id.",[15,64,65,66,69],{},"With my transactional system, I can ensure that the item is not bought twice because the timestamp is unique and if\nthe timestamp of another attempt is lower than the current one, the transaction will be canceled for the highest\ntimestamp.\nThe player with the lower timestamp always wins ",[67,68],"d",{},".",[15,71,72],{},"Plus there is a small delay to let the transaction be processed.",[15,74,75],{},"Then we just have to notify all the servers that the item has been bought and remove it from the auction house.",[53,77,79],{"id":78},"i-know-i-didnt-talk-about-player-money","I know I didn't talk about player money..",[15,81,82],{},"Users are not always loaded on the server so it is a little bit more complex than the auction system itself.",[15,84,85],{},"If the player is on the server when the transaction happens, no problems, but if the player is on another server,\nwe need to send a pubsub to that server to modify the money of the player.",[15,87,88],{},"If offline, we need to load the user from the database, modify the money and save it back.",[19,90,92],{"id":91},"speed","Speed ?",[15,94,95],{},"Of course, there is some delay between the click and the item appearing in the inventory.\nBut in under 5s you can have the item in your inventory.",[19,97,99],{"id":98},"conclusion","Conclusion",[15,101,102],{},"Nothing too complicated, when I first thought about it, I was like \"It is going to be tough, but it is doable\".\nBut in the end, it was pretty easy to do.",[15,104,105],{},"If you're interested in the code, I can make a more detailed article about it, just send me a message on discord (\nFarmeurimmo), via the contact form or by email.",[15,107,108],{},"Next time, I will maybe talk about cross server teleportation with coordinates and fast server switching.\n(For example, you want to go to the pvp warp or you got tpa to another server)",{"title":110,"searchDepth":111,"depth":111,"links":112},"",2,[113,114,119,120],{"id":21,"depth":111,"text":22},{"id":41,"depth":111,"text":42,"children":115},[116,118],{"id":55,"depth":117,"text":56},3,{"id":78,"depth":117,"text":79},{"id":91,"depth":111,"text":92},{"id":98,"depth":111,"text":99},"This article explores the Skyblock plugin's auction system, detailing how players can sell and buy items across servers.","md",{"image":124,"date":125,"tags":126,"author":131},"https:\u002F\u002Fcdn.farmeurimmo.fr\u002Fimg\u002Fblog\u002F27-08-2024-dev-blog-4-build-a-skyblock-plugin.jpeg","2024-08-27T11:00:00.000Z",[127,128,129,130],"Minecraft","Spigot","Plugin Development","Skyblock",{"name":132,"picture":133},"Farmeurimmo","https:\u002F\u002Fcdn.farmeurimmo.fr\u002Fimg\u002Flogo.png",true,"\u002Fblog\u002F27-08-2024-dev-blog-4-build-a-skyblock-plugin",{"title":5,"description":121},"blog\u002F27-08-2024-dev-blog-4-build-a-skyblock-plugin","oHG1GJigxY3kHz2OAvorXH2N_mD2veSJtI8qIt7Cb5c",1794558958105]