Advertisement
williambriggs

java

Aug 3rd, 2022
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package me.will.randomthings;
  2.  
  3. import com.moandjiezana.toml.Toml;
  4. import me.will.randomthings.listeners.BlockBreak;
  5. import org.bukkit.plugin.PluginManager;
  6.  
  7. import org.bukkit.plugin.java.JavaPlugin;
  8.  
  9. import java.io.File;
  10. import java.io.IOException;
  11. import java.nio.file.Files;
  12.  
  13. public final class RandomThings extends JavaPlugin {
  14.  
  15.     private static RandomThings plugin;
  16.     private Toml config;
  17.  
  18.     @Override
  19.     public void onEnable() {
  20.         // Plugin startup logic
  21.         plugin = this;
  22.         registerListeners();
  23.  
  24.         config = loadConfig();
  25.  
  26.     }
  27.  
  28.     @SuppressWarnings("ResultOfMethodCallIgnored")
  29.     public Toml loadConfig() {
  30.         if(!getDataFolder().exists()) {
  31.             getDataFolder().mkdirs(); // Creating the directory as it may not exist
  32.         }
  33.         File file = new File(getDataFolder(), "config.toml"); // Assign a variable to the file
  34.         if(!file.exists()) {
  35.             try {
  36.                 Files.copy(getResource("config.toml"), file.toPath()); // Copy the file out of our jar into our plugins Data Folder
  37.             } catch (IOException ex) {
  38.                 ex.printStackTrace();
  39.             }
  40.         }
  41.         return new Toml(
  42.                 new Toml().read(getResource("config.toml"))) // We'll use our internal file as default to prevent errors
  43.                 .read(file); // Reads the file from the Data Folder of our plugin
  44.     }
  45.  
  46.     public Toml getTomlConfig() { return config; }
  47.  
  48.     private void registerListeners() {
  49.         PluginManager pm = getServer().getPluginManager();
  50.         pm.registerEvents(new BlockBreak(), this);
  51.     }
  52.  
  53.     public static RandomThings getPlugin() {
  54.         return plugin;
  55.     }
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement