API Learning & Questions!

  • Ok so two more questions for anyone in the know... I'm using Raycasts to allow right clicking on objects for custom interactions but sometimes they get 'stuck' and so the raycast will act as if it's touching an object like a tree even when I'm facing the sky or a rock for the example... Secondly with saving user data to database how is best to store information so it is save specific seems like an obvious question but currently I can do stuff in one save and have the same progress in my other one as it's only looking at the playeruid... Should I save the server/save name alongside so it stores uniquely to each? How do other people do this?


    Thanks again!

  • I'm using Raycasts to allow right clicking on objects for custom interactions but sometimes they get 'stuck' and so the raycast will act as if it's touching an object like a tree even when I'm facing the sky or a rock for the example...

    Do you mind sharing your raycast code? ^^


    Secondly with saving user data to database how is best to store information so it is save specific seems like an obvious question but currently I can do stuff in one save and have the same progress in my other one as it's only looking at the playeruid... Should I save the server/save name alongside so it stores uniquely to each?

    There are basically various ways how to handle that. The best way is usually to store it in a specific subfolder in your plugin folder. E.g. instead of this...

    Java
    Database database = getSQLiteConnection(getPath() + "/MyDatabase.db");


    ... you could create a subfolder with the world name in your plugin folder (to get the world name, you can call World.getName()), like this:

    Java
    String worldName = World.getName();
    Database database = getSQLiteConnection(getPath() + "/" + worldName + "/MyDatabase.db");


    Alternatively you could store the database in the world folder (you can get the world folder via World.getWorldFolder()) or directly in the world database, although that could cause trouble if another plugin had the same idea and saves a database with the same name there. So the safest way is usually to store it in the plugin folder (using separate world subfolders there) ^^

  • Ok great thanks, yeah I did in the end get the raycast code working I didn’t realise raycast callbacks are called either way whether it’s in that layer or not, so created a separate check for the stuff I wanted to click on. And then yeah I put my database in the plugin folder so that bit was okay was more just making sure different saves had unique data not the same data on each save for obvious reasons, so yeah world name seems logical as that way if it’s on the server end I guess the game checks for multiple worlds of the same name. Thanks ;)

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!