package com.supremewars.customconfigplugin;
import com.supremewars.customconfigplugin.Files.CustomConfig;
import com.supremewars.customconfigplugin.commands.Message;
import com.supremewars.customconfigplugin.commands.ReloadCommand;
import org.bukkit.plugin.java.JavaPlugin;
public final class CustomConfigPlugin extends JavaPlugin {
@Override
public void onEnable() {
// Plugin startup logic
getConfig().options().copyDefaults();
saveDefaultConfig();
CustomConfig.setup();
CustomConfig.get().addDefault("Message","This is the default message");
CustomConfig.get().options().copyDefaults(true);
CustomConfig.save();
getCommand("message").setExecutor(new Message());
getCommand("cusreload").setExecutor(new ReloadCommand());
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
}
name: CustomConfigPlugin
version: ${project.version}
main: com.supremewars.customconfigplugin.CustomConfigPlugin
api-version: 1.13
authors: [JackScott]
description: CustomConfigPlugin
website: supremewars.com
commands:
message:
description: Sends a messaged form the custom config.
usage: </message>
cusreload:
description: Reloaed the custom confin into the server when you have made a chae to the file
usage: </cusreload>
test: 'Yes'
package com.supremewars.customconfigplugin.Files;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
public class CustomConfig {
private static File file;
private static FileConfiguration customFile;
//Finds or genrates the cutom file
public static void setup () {
file = new File(Bukkit.getServer().getPluginManager().getPlugin("CustomConfigPlugin").getDataFolder(), "customconfig.yml");
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
System.out.println("Unable to create new file \n Error:" + e);
}
}
customFile = YamlConfiguration.loadConfiguration(file);
}
public static FileConfiguration get() {
return customFile;
}
public static void save (){
try {
customFile.save(file);
} catch (IOException e) {
System.out.println("Error saving the file, please try agian or cont plugin developer \n Error:" + e);
}
}
public static void reload() {
customFile = YamlConfiguration.loadConfiguration(file);
}
}
package com.supremewars.customconfigplugin.commands;
import com.supremewars.customconfigplugin.Files.CustomConfig;
import jdk.nashorn.internal.ir.ContinueNode;
import jdk.nashorn.internal.ir.ReturnNode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ReloadCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player) sender;
CustomConfig.reload();
return true;
}
}
package com.supremewars.customconfigplugin.commands;
import com.supremewars.customconfigplugin.Files.CustomConfig;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Message implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
player.sendMessage(CustomConfig.get().getString("Message"));
}
return true;
}
}