Ah… I assume you were responding to the plugin request thread for this very thing. I had a project almost entirely done for the same thing.
I have a few comments on this, click to view.
Comments
- The
@InjectongetLogger(), is unnecessary, as nothing is actually injected. - It’s a bad idea to use * imports (but that’s just a personal thing).
- While
java.util.logging.Loggertechnically works, the intended class isorg.slf4j.Logger. - Rather than checking the service providers, usually people just get the service from the
ServiceManagerwhenever they need it. No need to store it in a global variable anyway. - You shouldn’t initialize injected variables with
null. Just leave them undefined. - No need to put load and unload log messages either, since Sponge does that automatically.
-
Paths andjava.nioare recommended overFiles andjava.iofor Configurate operations. - If you’ve injected the
ConfigurationLoader, the configuration will alwaysexists(). What I usually do is put aversionnode in the file, and check if itisVirtual(). - The HOCON spec defines key names as being all lowercase, and hyphen separated. Again, though, this is a personal thing. Doesn’t directly break anything.
- The
Timerclass is not recommended in Sponge, as it won’t be on the main thread. Instead,Taskis recommended. - I would definitely not recommend doing an IO operation so often. Instead, cache the root node in a variable (like you are doing), and load it again on
GameReloadEvent. - It’s not recommended to find paths yourself. If you use
sharedRoot = falsein your@DefaultConfig, a new folder will be created for your plugin inconfig, containing your config file, rather than the file being in the root ofconfig. You can then get the folder with@Inject @ConfigDir(sharedRoot = false). - Any time you are creating files, they return a boolean. A creation failure won’t always throw an exception; if it returns false, it failed.
- I am confused as to why you are creating
Textobjects, just to calltoPlain(). Why not just dotamad = path + "\\TimeIsMoneyLogs\\" + tarih + ".log"? - You should probably use primitive types like
booleanandintinstead of class wrappers likeBooleanandInteger. If they’re never intended to be null, the extra memory makes no sense. - Don’t just use the number and the symbol. Currencies have a method
formatthat takes theBigDecimaland returnsText, so that the economy plugin can define a custom way of displaying it. - Important: Don’t store economy values in
int. Ever. Store them inBigDecimalif possible, since it has infinite capacity, but if you find yourself needing to use a primitive, usedoubleorfloat, sinceintwill remove the decimal point, and custom currencies may really need that fractional component. - Tip:
try (PrintWriter printer = new PrintWriter(new FileWriter(file, false))) {Called ‘try with resources’, it applies to anything implementingAutoCloseable, and automatically closes streams (like thePrintWriter, for example).