Simplix-Softworks / SimplixStorage

Library to store data in a better way
Apache License 2.0
138 stars 25 forks source link

doubts with the use of the plugin #38

Closed thefrogline closed 3 years ago

thefrogline commented 3 years ago

Hello! I am new to using everything that is Simplix Storage and I have a question, how can I get the data from a file? What I am doing is a constructor to create the configuration files easier, and I create them in my main plugin, but how can I access the config from another class? I would also like you to leave sample codes if possible, but mainly that is my question, since when using String aString = yaml.getString ("Key") ; // Default: "", I don't know how to use it well and also the "yaml" doesn't recognize me, maybe it's an easy question to answer but I don't know what to do, I am waiting for an answer, and thank you very much for reading! image Main Class: image

KotlinFactory commented 3 years ago

Hey thefrogline,

Thank you for using SimplixStorage and asking this question here,

The way you are creating your YAML is already fine.

You can retrieve data from is using

getString("PAtH-TO-VALUE")
getInteger("PATH-TO-VALUE");

What exactly do you mean by "the config is not recognizing me"?

We would love to help you.

If you have any further questions, feel free to ask. If you need real-time help, feel free to join our Discord: discord.simplixsoft.com

Regards, Leonhard

thefrogline commented 3 years ago

Hi! Thanks for answering, because with "the config is not recognizing me" I mean this, the yml does not detect me, I am trying to make a command block to test all this of the configuration system, I also leave you an image of how it looks my project, so you can see if I'm doing something wrong. or I don't know if I'm doing something wrong, I'm new to all this library stuff and it's still a bit hard for me to understand . I am trying to do this with a configuration already with comments and configurationI am trying to do this with a configuration already with comments and configuration image image

yoyosource commented 3 years ago

Hello thefrogline,

as Intelij gives you a hint what is wrong, is says 'Cannot resolve symbol [...]', this is why the field you specified with the name 'yaml' is not in your current context. This is because there is no field named the same way. Did you create this field somewhere, if yes where?

Other than that. If you 'getString()' from some kind of Configuration you get a String object on which no method with the name 'getStringList()' is available. This is because there is a difference in a String object and some kind of Configuration object specified by SimplixStorage.

Regards yoyosource

thefrogline commented 3 years ago

Hello! sorry for the delay in answering, I will explain all my code and if you do not understand something tell me, I speak Spanish and sometimes it is difficult for me to translate some things, but I will try also that I am something new in Java

1.- With my code first what I do is create a configmanager, which what it does is create all the configurations with a constructuctor called "create config": image

2.- In my OnEnable () I start to create all the configurations, for now I have 3 tests, and they are all created with the same .yml format image

3.- Now what I want to know is how from my main or my configmanager, get part of the configuration of some of my specific files, for example in security I want to get the blocked words, and in config.yml get the prefix of my plugin (it's just an example), perhaps because of the method by which I am doing it, it is not possible, or it would be better if they tell me how to use their api correctly, sorry for so much confusion when it comes to explaining myself and I understand very little, and perhaps misbehaving , but thank you very much for answering!

yoyosource commented 3 years ago

Hello thefrogline,

no problem. Your ConfigManager just creates a file and internally creates and Config object. So to access that object you need to have a field somewhere. I would consider a Map<String, Config> or a List<Config> for your use case. You should also read the Config if the config file exists, otherwise you just create a file on disk and never use it. Creating your config files in the onEnable() is fine. But your class CommandBlocker does not know the instances creates in ConfigManager or the onEnable() method. So creating a Field or saving in a Map, that is stored in a field, is your solution, I think. Maybe you could return a Config object from createConfig(String) so you can save it in the onEnable() method in some kind of field and access it in your BlockCommand class?

Regards yoyosource.

thefrogline commented 3 years ago

Thank you very much, what you recommended helped me and I was finally able to use the api, really good support, I haven't asked for support for a long time because I had a bad experience (in another plugin, I am not talking about any of their other plugins), but thank you very much for being patient and helping me! and sorry for delaying in answering :D, recommendation, that there be some example plugin of how to use the plugin well, for new people like me xd, how to do what I ask and things like that

yoyosource commented 3 years ago

No problem. One problem with example plugins is, that you do not learn how use the plugin but copy what others give you. That is not good if you want to use the plugin on your own without relying on others. So yeah example help but a whole example plugin would not be good, in my opinion.

Regards yoyosource.