Disable plugin

Discussion in 'Spigot Plugin Development' started by Stevie212, Jun 7, 2017.

  1. Hello everyone. I want to check if my Minecraft server spigot.jar comtains gson and if it does not contain it, it disables the plugin. Someone showed me how to do it, but for some reason the Class.forName() Does not exist

    try {
    getLogger().info("Found Gson!");
    } catch (Exception e) {
    getLogger().info("Didn't find Gson! Disabling!");
    #1 Stevie212, Jun 7, 2017
    Last edited: Jun 7, 2017
  2. Why dont you just put the com.google.gson in to the Compiled jar?
  3. Because GSON is already included into spigot (and bukkit) servers.
    So this
    doesn't make any sense at all. GSON gets loaded by the minecraft server.

    Btw. you can't check "if the class contains gson". You could use Class#forName to check if it's loaded and known to your JRE instance.
    If you really want to check "if the class contains gson" (a class contains declared GSON type fields), you might need to iterate over all declared fields and check "typeof" or get all fields classes and compare those with the GSON class. Anyway this also doesn't make any sense at all.

    Be aware of the XY problem!
  4. The reason why I asked its because When I ran my 1.8 server and I used Gson in my plugin and it gave me this error
    java.lang.NoClassDefFoundError: com/google/gson/Gson
  5. Like I said in the other thread you made... Gson is in the jar. It's just in a different spot for early 1.8.x versions.

    In the new jars it's at /com/google/gson, exactly where you expect it to be.

    However, in the ok versions it's in /org/bukkit/craftbukkit/util/google/gson/ or some crap like that. Just open your jar in your favorite compression tool (winrar, 7zip, ark, etc) and browse around the old jars.

    Use your try/catch to test the location of gson and then use the appropriate one by using abstraction in your plugin.

    Disabling your plugin is not the answer if you are aiming to support all 1.8+ versions.
    • Agree Agree x 1
  6. Alright thanks bro. I understand what you are saying
  7. Can you explain to me the method that is used to abstract?
  8. I have check all over google for this and found nothing suitable to help my situation.

    If com/google/gson/Gson does not exit then it registers /org/bukkit/craftbukregisters/com/google/gson/

    If non exist then it shuts down the plugin. But I am having problems doing this.. Can someone help me?
  9. Consider getting PlugMan, a free plugin that can enable and disable plugins for you with ease.