💰 TimeIsMoney API 4.1/5.0 💰

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 @Inject on getLogger(), 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.Logger technically works, the intended class is org.slf4j.Logger.
  • Rather than checking the service providers, usually people just get the service from the ServiceManager whenever 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 and java.nio are recommended over Files and java.io for Configurate operations.
  • If you’ve injected the ConfigurationLoader, the configuration will always exists(). What I usually do is put a version node in the file, and check if it isVirtual().
  • 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 Timer class is not recommended in Sponge, as it won’t be on the main thread. Instead, Task is 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 = false in your @DefaultConfig, a new folder will be created for your plugin in config, containing your config file, rather than the file being in the root of config. 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 Text objects, just to call toPlain(). Why not just do tamad = path + "\\TimeIsMoneyLogs\\" + tarih + ".log"?
  • You should probably use primitive types like boolean and int instead of class wrappers like Boolean and Integer. 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 format that takes the BigDecimal and returns Text, so that the economy plugin can define a custom way of displaying it.
  • Important: Don’t store economy values in int. Ever. Store them in BigDecimal if possible, since it has infinite capacity, but if you find yourself needing to use a primitive, use double or float, since int will 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 implementing AutoCloseable, and automatically closes streams (like the PrintWriter, for example).
4 Likes