mirror of
https://github.com/songoda/EpicEnchants.git
synced 2024-12-23 01:27:43 +01:00
Updated to support the Songoda core settings manager.
This commit is contained in:
parent
d4b2ecf487
commit
5e30669f2c
@ -4,6 +4,7 @@ import com.songoda.core.SongodaCore;
|
|||||||
import com.songoda.core.SongodaPlugin;
|
import com.songoda.core.SongodaPlugin;
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import com.songoda.core.configuration.Config;
|
import com.songoda.core.configuration.Config;
|
||||||
|
import com.songoda.core.gui.GuiManager;
|
||||||
import com.songoda.core.hooks.EconomyManager;
|
import com.songoda.core.hooks.EconomyManager;
|
||||||
import com.songoda.epicenchants.command.CommandManager;
|
import com.songoda.epicenchants.command.CommandManager;
|
||||||
import com.songoda.epicenchants.listeners.ArmorListener;
|
import com.songoda.epicenchants.listeners.ArmorListener;
|
||||||
@ -19,8 +20,7 @@ import com.songoda.epicenchants.utils.EnchantUtils;
|
|||||||
import com.songoda.epicenchants.utils.Metrics;
|
import com.songoda.epicenchants.utils.Metrics;
|
||||||
import com.songoda.epicenchants.utils.SpecialItems;
|
import com.songoda.epicenchants.utils.SpecialItems;
|
||||||
import com.songoda.epicenchants.utils.objects.FastInv;
|
import com.songoda.epicenchants.utils.objects.FastInv;
|
||||||
import com.songoda.epicenchants.utils.settings.Setting;
|
import com.songoda.epicenchants.utils.settings.Settings;
|
||||||
import com.songoda.epicenchants.utils.settings.SettingsManager;
|
|
||||||
import com.songoda.epicenchants.utils.single.ItemGroup;
|
import com.songoda.epicenchants.utils.single.ItemGroup;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
@ -28,19 +28,16 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
|
||||||
import static org.bukkit.Bukkit.getConsoleSender;
|
|
||||||
|
|
||||||
public class EpicEnchants extends SongodaPlugin {
|
public class EpicEnchants extends SongodaPlugin {
|
||||||
|
|
||||||
private static EpicEnchants INSTANCE;
|
private static EpicEnchants INSTANCE;
|
||||||
|
|
||||||
|
private final GuiManager guiManager = new GuiManager(this);
|
||||||
private EnchantManager enchantManager;
|
private EnchantManager enchantManager;
|
||||||
private InfoManager infoManager;
|
private InfoManager infoManager;
|
||||||
private GroupManager groupManager;
|
private GroupManager groupManager;
|
||||||
private FileManager fileManager;
|
private FileManager fileManager;
|
||||||
private HookManager hookManager;
|
private HookManager hookManager;
|
||||||
private SettingsManager settingsManager;
|
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
|
|
||||||
private SpecialItems specialItems;
|
private SpecialItems specialItems;
|
||||||
@ -61,12 +58,13 @@ public class EpicEnchants extends SongodaPlugin {
|
|||||||
// Run Songoda Updater
|
// Run Songoda Updater
|
||||||
SongodaCore.registerPlugin(this, 67, CompatibleMaterial.DIAMOND_SWORD);
|
SongodaCore.registerPlugin(this, 67, CompatibleMaterial.DIAMOND_SWORD);
|
||||||
|
|
||||||
// Setup Setting Manager
|
EconomyManager.load();
|
||||||
this.settingsManager = new SettingsManager(this);
|
|
||||||
this.settingsManager.setupConfig();
|
|
||||||
|
|
||||||
// Setup Language
|
// Setup Config
|
||||||
this.setLocale(getConfig().getString("System.Language Mode"), false);
|
Settings.setupConfig();
|
||||||
|
this.setLocale(Settings.LANGUGE_MODE.getString(), false);
|
||||||
|
|
||||||
|
EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString());
|
||||||
|
|
||||||
preload();
|
preload();
|
||||||
|
|
||||||
@ -84,9 +82,9 @@ public class EpicEnchants extends SongodaPlugin {
|
|||||||
infoManager.loadMenus();
|
infoManager.loadMenus();
|
||||||
hookManager.setup();
|
hookManager.setup();
|
||||||
|
|
||||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
|
||||||
|
|
||||||
// Listeners
|
// Listeners
|
||||||
|
guiManager.init();
|
||||||
|
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||||
pluginManager.registerEvents(new BookListener(this), this);
|
pluginManager.registerEvents(new BookListener(this), this);
|
||||||
pluginManager.registerEvents(new ArmorListener(), this);
|
pluginManager.registerEvents(new ArmorListener(), this);
|
||||||
pluginManager.registerEvents(new PlayerListener(this), this);
|
pluginManager.registerEvents(new PlayerListener(this), this);
|
||||||
@ -95,20 +93,6 @@ public class EpicEnchants extends SongodaPlugin {
|
|||||||
pluginManager.registerEvents(new BlackScrollListener(this), this);
|
pluginManager.registerEvents(new BlackScrollListener(this), this);
|
||||||
pluginManager.registerEvents(new DustListener(this), this);
|
pluginManager.registerEvents(new DustListener(this), this);
|
||||||
|
|
||||||
String economyPlugin = null;
|
|
||||||
|
|
||||||
// Setup Economy
|
|
||||||
if (Setting.VAULT_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Vault"))
|
|
||||||
economyPlugin = "Vault";
|
|
||||||
else if (Setting.RESERVE_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Reserve"))
|
|
||||||
economyPlugin = "Reserve";
|
|
||||||
else if (Setting.PLAYER_POINTS_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("PlayerPoints"))
|
|
||||||
economyPlugin = "PlayerPoints";
|
|
||||||
|
|
||||||
EconomyManager.load();
|
|
||||||
if (economyPlugin != null)
|
|
||||||
EconomyManager.getManager().setPreferredHook(economyPlugin);
|
|
||||||
|
|
||||||
// Start Metrics
|
// Start Metrics
|
||||||
new Metrics(this);
|
new Metrics(this);
|
||||||
|
|
||||||
@ -125,25 +109,10 @@ public class EpicEnchants extends SongodaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginDisable() {
|
public void onPluginDisable() {
|
||||||
getConsoleSender().sendMessage(color("&a============================="));
|
|
||||||
getConsoleSender().sendMessage(color("&7" + getDescription().getName() + " " + getDescription().getVersion() + " by &5Songoda <3&7!"));
|
|
||||||
getConsoleSender().sendMessage(color("&7Action: &cDisabling&7..."));
|
|
||||||
getConsoleSender().sendMessage(color("&a============================="));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigReload() {
|
public void onConfigReload() {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Config> getExtraConfig() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reload() {
|
|
||||||
reloadConfig();
|
|
||||||
|
|
||||||
fileManager.clear();
|
fileManager.clear();
|
||||||
fileManager.loadFiles();
|
fileManager.loadFiles();
|
||||||
|
|
||||||
@ -160,6 +129,12 @@ public class EpicEnchants extends SongodaPlugin {
|
|||||||
this.locale.reloadMessages();
|
this.locale.reloadMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Config> getExtraConfig() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public EnchantManager getEnchantManager() {
|
public EnchantManager getEnchantManager() {
|
||||||
return this.enchantManager;
|
return this.enchantManager;
|
||||||
}
|
}
|
||||||
@ -196,7 +171,7 @@ public class EpicEnchants extends SongodaPlugin {
|
|||||||
return commandManager;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SettingsManager getSettingsManager() {
|
public GuiManager getGuiManager() {
|
||||||
return settingsManager;
|
return guiManager;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public class CommandReload extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractCommand.ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
protected AbstractCommand.ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||||
instance.reload();
|
instance.reloadConfig();
|
||||||
instance.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
|
instance.getLocale().getMessage("command.reload").sendPrefixedMessage(sender);
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.songoda.epicenchants.command.commands;
|
package com.songoda.epicenchants.command.commands;
|
||||||
|
|
||||||
|
import com.songoda.core.configuration.editor.PluginConfigGui;
|
||||||
import com.songoda.epicenchants.EpicEnchants;
|
import com.songoda.epicenchants.EpicEnchants;
|
||||||
import com.songoda.epicenchants.command.AbstractCommand;
|
import com.songoda.epicenchants.command.AbstractCommand;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -15,7 +16,7 @@ public class CommandSettings extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
protected ReturnType runCommand(EpicEnchants instance, CommandSender sender, String... args) {
|
||||||
instance.getSettingsManager().openSettingsManager((Player) sender);
|
instance.getGuiManager().showGUI((Player) sender, new PluginConfigGui(instance));
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,13 +3,16 @@ package com.songoda.epicenchants.managers;
|
|||||||
import com.songoda.core.compatibility.ServerVersion;
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
import com.songoda.epicenchants.EpicEnchants;
|
import com.songoda.epicenchants.EpicEnchants;
|
||||||
import com.songoda.epicenchants.utils.objects.FileLocation;
|
import com.songoda.epicenchants.utils.objects.FileLocation;
|
||||||
import com.songoda.epicenchants.utils.settings.Setting;
|
import com.songoda.epicenchants.utils.settings.Settings;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -89,8 +92,7 @@ public class FileManager extends Manager<String, FileConfiguration> {
|
|||||||
files.forEach(fileLocation -> {
|
files.forEach(fileLocation -> {
|
||||||
File file = new File(instance.getDataFolder() + separator + fileLocation.getPath());
|
File file = new File(instance.getDataFolder() + separator + fileLocation.getPath());
|
||||||
|
|
||||||
if (!file.exists() && (fileLocation.isRequired() || Setting.FIRST_LOAD.getBoolean())) {
|
if (!file.exists() && (fileLocation.isRequired() || Settings.FIRST_LOAD.getBoolean())) {
|
||||||
file.getParentFile().mkdirs();
|
|
||||||
Bukkit.getConsoleSender().sendMessage("Creating file: " + fileLocation.getPath());
|
Bukkit.getConsoleSender().sendMessage("Creating file: " + fileLocation.getPath());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -114,7 +116,6 @@ public class FileManager extends Manager<String, FileConfiguration> {
|
|||||||
|
|
||||||
instance.getConfig().set("System.First Load", false);
|
instance.getConfig().set("System.First Load", false);
|
||||||
instance.saveConfig();
|
instance.saveConfig();
|
||||||
instance.getSettingsManager().reloadConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getConfiguration(String key) {
|
public FileConfiguration getConfiguration(String key) {
|
||||||
|
@ -3,13 +3,12 @@ package com.songoda.epicenchants.objects;
|
|||||||
import com.songoda.epicenchants.EpicEnchants;
|
import com.songoda.epicenchants.EpicEnchants;
|
||||||
import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
||||||
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
||||||
import com.songoda.epicenchants.utils.settings.Setting;
|
import com.songoda.epicenchants.utils.settings.Settings;
|
||||||
import com.songoda.epicenchants.utils.single.GeneralUtils;
|
import com.songoda.epicenchants.utils.single.GeneralUtils;
|
||||||
import com.songoda.epicenchants.utils.single.ItemGroup;
|
import com.songoda.epicenchants.utils.single.ItemGroup;
|
||||||
import com.songoda.epicenchants.utils.single.RomanNumber;
|
import com.songoda.epicenchants.utils.single.RomanNumber;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -74,7 +73,7 @@ public class BookItem {
|
|||||||
|
|
||||||
ItemBuilder itemBuilder = new ItemBuilder(material)
|
ItemBuilder itemBuilder = new ItemBuilder(material)
|
||||||
.name(color(displayName
|
.name(color(displayName
|
||||||
.replace("{level}", "" + (Setting.ROMAN.getBoolean() ? RomanNumber.toRoman(level) : level))
|
.replace("{level}", "" + (Settings.ROMAN.getBoolean() ? RomanNumber.toRoman(level) : level))
|
||||||
.replace("{enchant}", "" + enchant.getIdentifier())
|
.replace("{enchant}", "" + enchant.getIdentifier())
|
||||||
.replace("{group_color}", enchant.getGroup().getColor())
|
.replace("{group_color}", enchant.getGroup().getColor())
|
||||||
.replace("{group_name}", enchant.getGroup().getName())
|
.replace("{group_name}", enchant.getGroup().getName())
|
||||||
@ -128,4 +127,5 @@ public class BookItem {
|
|||||||
return "BookItem.BookItemBuilder(instance=" + this.instance + ", material=" + this.material + ", displayName=" + this.displayName + ", lore=" + this.lore + ")";
|
return "BookItem.BookItemBuilder(instance=" + this.instance + ", material=" + this.material + ", displayName=" + this.displayName + ", lore=" + this.lore + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import com.songoda.epicenchants.objects.Enchant;
|
|||||||
import com.songoda.epicenchants.utils.itemnbtapi.NBTCompound;
|
import com.songoda.epicenchants.utils.itemnbtapi.NBTCompound;
|
||||||
import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
||||||
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
||||||
import com.songoda.epicenchants.utils.settings.Setting;
|
import com.songoda.epicenchants.utils.settings.Settings;
|
||||||
import com.songoda.epicenchants.utils.single.GeneralUtils;
|
import com.songoda.epicenchants.utils.single.GeneralUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@ -70,8 +70,8 @@ public class EnchantUtils {
|
|||||||
itemBuilder.removeLore(instance.getSpecialItems().getWhiteScrollLore());
|
itemBuilder.removeLore(instance.getSpecialItems().getWhiteScrollLore());
|
||||||
}
|
}
|
||||||
|
|
||||||
itemBuilder.removeLore(enchant.getFormat(-1, Setting.ROMAN.getBoolean()).replace("-1", "").trim());
|
itemBuilder.removeLore(enchant.getFormat(-1, Settings.ROMAN.getBoolean()).replace("-1", "").trim());
|
||||||
itemBuilder.addLore(enchant.getFormat(level, Setting.ROMAN.getBoolean()));
|
itemBuilder.addLore(enchant.getFormat(level, Settings.ROMAN.getBoolean()));
|
||||||
|
|
||||||
if (hasProtection) {
|
if (hasProtection) {
|
||||||
itemBuilder.addLore(instance.getSpecialItems().getWhiteScrollLore());
|
itemBuilder.addLore(instance.getSpecialItems().getWhiteScrollLore());
|
||||||
|
@ -4,7 +4,7 @@ import com.songoda.epicenchants.EpicEnchants;
|
|||||||
import com.songoda.epicenchants.objects.Group;
|
import com.songoda.epicenchants.objects.Group;
|
||||||
import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
||||||
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
||||||
import com.songoda.epicenchants.utils.settings.Setting;
|
import com.songoda.epicenchants.utils.settings.Settings;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -33,7 +33,7 @@ public class SpecialItems {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getBlackScroll(int amount, int chance) {
|
public ItemStack getBlackScroll(int amount, int chance) {
|
||||||
int successRate = chance == -1 ? ThreadLocalRandom.current().nextInt(Setting.BLACK_MIN.getInt(), Setting.BLACK_MAX.getInt() + 1) : chance;
|
int successRate = chance == -1 ? ThreadLocalRandom.current().nextInt(Settings.BLACK_MIN.getInt(), Settings.BLACK_MAX.getInt() + 1) : chance;
|
||||||
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("black-scroll"), of("success-rate", successRate)).nbt();
|
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("black-scroll"), of("success-rate", successRate)).nbt();
|
||||||
|
|
||||||
nbtItem.setBoolean("black-scroll", true);
|
nbtItem.setBoolean("black-scroll", true);
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package com.songoda.epicenchants.utils.settings;
|
|
||||||
|
|
||||||
public enum Category {
|
|
||||||
|
|
||||||
MAIN("General settings and options."),
|
|
||||||
|
|
||||||
INTERFACES("These settings allow you to alter the way interfaces look.",
|
|
||||||
"They are used in GUI's to make patterns, change them up then open up a",
|
|
||||||
"GUI to see how it works."),
|
|
||||||
|
|
||||||
SYSTEM("System related settings.");
|
|
||||||
|
|
||||||
private String[] comments;
|
|
||||||
|
|
||||||
|
|
||||||
Category(String... comments) {
|
|
||||||
this.comments = comments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getComments() {
|
|
||||||
return comments;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,113 +0,0 @@
|
|||||||
package com.songoda.epicenchants.utils.settings;
|
|
||||||
|
|
||||||
|
|
||||||
import com.songoda.epicenchants.EpicEnchants;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public enum Setting {
|
|
||||||
|
|
||||||
ROMAN("Main.Roman Numerals", true),
|
|
||||||
|
|
||||||
BLACK_MIN("Main.Black Scroll Min", 20),
|
|
||||||
BLACK_MAX("Main.Black Scroll Max", 100),
|
|
||||||
|
|
||||||
VAULT_ECONOMY("Economy.Use Vault Economy", true,
|
|
||||||
"Should Vault be used?"),
|
|
||||||
|
|
||||||
RESERVE_ECONOMY("Economy.Use Reserve Economy", true,
|
|
||||||
"Should Reserve be used?"),
|
|
||||||
|
|
||||||
PLAYER_POINTS_ECONOMY("Economy.Use Player Points Economy", false,
|
|
||||||
"Should PlayerPoints be used?"),
|
|
||||||
|
|
||||||
GLASS_TYPE_1("Interfaces.Glass Type 1", 7),
|
|
||||||
GLASS_TYPE_2("Interfaces.Glass Type 2", 11),
|
|
||||||
GLASS_TYPE_3("Interfaces.Glass Type 3", 3),
|
|
||||||
|
|
||||||
FIRST_LOAD("System.First Load", true),
|
|
||||||
|
|
||||||
LANGUGE_MODE("System.Language Mode", "en_US",
|
|
||||||
"The enabled language file.",
|
|
||||||
"More language files (if available) can be found in the plugins data folder.");
|
|
||||||
|
|
||||||
private String setting;
|
|
||||||
private Object option;
|
|
||||||
private String[] comments;
|
|
||||||
|
|
||||||
Setting(String setting, Object option, String... comments) {
|
|
||||||
this.setting = setting;
|
|
||||||
this.option = option;
|
|
||||||
this.comments = comments;
|
|
||||||
}
|
|
||||||
|
|
||||||
Setting(String setting, Object option) {
|
|
||||||
this.setting = setting;
|
|
||||||
this.option = option;
|
|
||||||
this.comments = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Setting getSetting(String setting) {
|
|
||||||
List<Setting> settings = Arrays.stream(values()).filter(setting1 -> setting1.setting.equals(setting)).collect(Collectors.toList());
|
|
||||||
if (settings.isEmpty()) return null;
|
|
||||||
return settings.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSetting() {
|
|
||||||
return setting;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getOption() {
|
|
||||||
return option;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] getComments() {
|
|
||||||
return comments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Integer> getIntegerList() {
|
|
||||||
return EpicEnchants.getInstance().getConfig().getIntegerList(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getStringList() {
|
|
||||||
return EpicEnchants.getInstance().getConfig().getStringList(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getBoolean() {
|
|
||||||
return EpicEnchants.getInstance().getConfig().getBoolean(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInt() {
|
|
||||||
return EpicEnchants.getInstance().getConfig().getInt(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLong() {
|
|
||||||
return EpicEnchants.getInstance().getConfig().getLong(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString() {
|
|
||||||
return EpicEnchants.getInstance().getConfig().getString(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public char getChar() {
|
|
||||||
return EpicEnchants.getInstance().getConfig().getString(setting).charAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getDouble() {
|
|
||||||
return EpicEnchants.getInstance().getConfig().getDouble(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getMaterial() {
|
|
||||||
String materialStr = EpicEnchants.getInstance().getConfig().getString(setting);
|
|
||||||
Material material = Material.getMaterial(materialStr);
|
|
||||||
|
|
||||||
if (material == null) {
|
|
||||||
System.out.println(String.format("Config value \"%s\" has an invalid material name: \"%s\"", setting, materialStr));
|
|
||||||
}
|
|
||||||
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.songoda.epicenchants.utils.settings;
|
||||||
|
|
||||||
|
import com.songoda.core.configuration.Config;
|
||||||
|
import com.songoda.core.configuration.ConfigSetting;
|
||||||
|
import com.songoda.core.hooks.EconomyManager;
|
||||||
|
import com.songoda.epicenchants.EpicEnchants;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class Settings {
|
||||||
|
|
||||||
|
static final Config config = EpicEnchants.getInstance().getCoreConfig();
|
||||||
|
|
||||||
|
public static final ConfigSetting ROMAN = new ConfigSetting(config, "Main.Roman Numerals", true);
|
||||||
|
|
||||||
|
public static final ConfigSetting BLACK_MIN = new ConfigSetting(config, "Main.Black Scroll Min", 20);
|
||||||
|
public static final ConfigSetting BLACK_MAX = new ConfigSetting(config, "Main.Black Scroll Max", 100);
|
||||||
|
|
||||||
|
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
|
||||||
|
"Which economy plugin should be used?",
|
||||||
|
"Supported plugins you have installed: \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\".");
|
||||||
|
|
||||||
|
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(config, "Interfaces.Glass Type 1", 7);
|
||||||
|
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(config, "Interfaces.Glass Type 2", 11);
|
||||||
|
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(config, "Interfaces.Glass Type 3", 3);
|
||||||
|
|
||||||
|
public static final ConfigSetting FIRST_LOAD = new ConfigSetting(config, "System.First Load", true);
|
||||||
|
|
||||||
|
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(config, "System.Language Mode", "en_US",
|
||||||
|
"The enabled language file.",
|
||||||
|
"More language files (if available) can be found in the plugins data folder.");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In order to set dynamic economy comment correctly, this needs to be
|
||||||
|
* called after EconomyManager load
|
||||||
|
*/
|
||||||
|
public static void setupConfig() {
|
||||||
|
config.load();
|
||||||
|
config.setAutoremove(true).setAutosave(true);
|
||||||
|
|
||||||
|
// convert economy settings
|
||||||
|
if (config.getBoolean("Economy.Use Vault Economy") && EconomyManager.getManager().isEnabled("Vault")) {
|
||||||
|
config.set("Main.Economy", "Vault");
|
||||||
|
} else if (config.getBoolean("Economy.Use Reserve Economy") && EconomyManager.getManager().isEnabled("Reserve")) {
|
||||||
|
config.set("Main.Economy", "Reserve");
|
||||||
|
} else if (config.getBoolean("Economy.Use Player Points Economy") && EconomyManager.getManager().isEnabled("PlayerPoints")) {
|
||||||
|
config.set("Main.Economy", "PlayerPoints");
|
||||||
|
}
|
||||||
|
|
||||||
|
config.saveChanges();
|
||||||
|
}
|
||||||
|
}
|
@ -1,311 +0,0 @@
|
|||||||
package com.songoda.epicenchants.utils.settings;
|
|
||||||
|
|
||||||
import com.songoda.core.compatibility.ServerVersion;
|
|
||||||
import com.songoda.epicenchants.EpicEnchants;
|
|
||||||
import com.songoda.epicenchants.utils.Methods;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by songoda on 6/4/2017.
|
|
||||||
*/
|
|
||||||
public class SettingsManager implements Listener {
|
|
||||||
|
|
||||||
private final EpicEnchants plugin;
|
|
||||||
private Map<Player, String> cat = new HashMap<>();
|
|
||||||
private Map<Player, String> current = new HashMap<>();
|
|
||||||
|
|
||||||
public SettingsManager(EpicEnchants plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
|
||||||
if (event.getView().getType() != InventoryType.CHEST) return;
|
|
||||||
ItemStack clickedItem = event.getCurrentItem();
|
|
||||||
|
|
||||||
if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory()
|
|
||||||
|| clickedItem == null || !clickedItem.hasItemMeta()
|
|
||||||
|| !clickedItem.getItemMeta().hasDisplayName()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getView().getTitle().equals(plugin.getName() + " Settings Manager")) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
|
||||||
|
|
||||||
String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
|
||||||
this.cat.put((Player) event.getWhoClicked(), type);
|
|
||||||
this.openEditor((Player) event.getWhoClicked());
|
|
||||||
} else if (event.getView().getTitle().equals(plugin.getName() + " Settings Editor")) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (clickedItem.getType().name().contains("STAINED_GLASS")) return;
|
|
||||||
|
|
||||||
Player player = (Player) event.getWhoClicked();
|
|
||||||
|
|
||||||
String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
|
||||||
|
|
||||||
if (plugin.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
|
|
||||||
this.plugin.getConfig().set(key, !plugin.getConfig().getBoolean(key));
|
|
||||||
this.finishEditing(player);
|
|
||||||
} else {
|
|
||||||
this.editObject(player, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChat(AsyncPlayerChatEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (!current.containsKey(player)) return;
|
|
||||||
|
|
||||||
String value = current.get(player);
|
|
||||||
FileConfiguration config = plugin.getConfig();
|
|
||||||
if (config.isLong(value)) {
|
|
||||||
config.set(value, Long.parseLong(event.getMessage()));
|
|
||||||
} else if (config.isInt(value)) {
|
|
||||||
config.set(value, Integer.parseInt(event.getMessage()));
|
|
||||||
} else if (config.isDouble(value)) {
|
|
||||||
config.set(value, Double.parseDouble(event.getMessage()));
|
|
||||||
} else if (config.isString(value)) {
|
|
||||||
config.set(value, event.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicEnchants.getInstance(), () ->
|
|
||||||
this.finishEditing(player), 0L);
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void finishEditing(Player player) {
|
|
||||||
this.current.remove(player);
|
|
||||||
this.saveConfig();
|
|
||||||
this.openEditor(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void editObject(Player player, String current) {
|
|
||||||
this.current.put(player, ChatColor.stripColor(current));
|
|
||||||
|
|
||||||
player.closeInventory();
|
|
||||||
player.sendMessage("");
|
|
||||||
player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7."));
|
|
||||||
if (plugin.getConfig().isInt(current) || plugin.getConfig().isDouble(current)) {
|
|
||||||
player.sendMessage(Methods.formatText("&cUse only numbers."));
|
|
||||||
}
|
|
||||||
player.sendMessage("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openSettingsManager(Player player) {
|
|
||||||
Inventory inventory = Bukkit.createInventory(null, 27, plugin.getName() + " Settings Manager");
|
|
||||||
ItemStack glass = Methods.getGlass();
|
|
||||||
for (int i = 0; i < inventory.getSize(); i++) {
|
|
||||||
inventory.setItem(i, glass);
|
|
||||||
}
|
|
||||||
|
|
||||||
int slot = 10;
|
|
||||||
for (String key : plugin.getConfig().getDefaultSection().getKeys(false)) {
|
|
||||||
ItemStack item = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.LEGACY_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9));
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category.")));
|
|
||||||
meta.setDisplayName(Methods.formatText("&f&l" + key));
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
inventory.setItem(slot, item);
|
|
||||||
slot++;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.openInventory(inventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void openEditor(Player player) {
|
|
||||||
Inventory inventory = Bukkit.createInventory(null, 54, plugin.getName() + " Settings Editor");
|
|
||||||
FileConfiguration config = plugin.getConfig();
|
|
||||||
|
|
||||||
int slot = 0;
|
|
||||||
for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) {
|
|
||||||
String fKey = cat.get(player) + "." + key;
|
|
||||||
ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
meta.setDisplayName(Methods.formatText("&6" + key));
|
|
||||||
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
if (config.isBoolean(fKey)) {
|
|
||||||
item.setType(Material.LEVER);
|
|
||||||
lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse"));
|
|
||||||
} else if (config.isString(fKey)) {
|
|
||||||
item.setType(Material.PAPER);
|
|
||||||
lore.add(Methods.formatText("&7" + config.getString(fKey)));
|
|
||||||
} else if (config.isInt(fKey)) {
|
|
||||||
item.setType(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
|
||||||
lore.add(Methods.formatText("&7" + config.getInt(fKey)));
|
|
||||||
} else if (config.isLong(fKey)) {
|
|
||||||
item.setType(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
|
||||||
lore.add(Methods.formatText("&7" + config.getLong(fKey)));
|
|
||||||
} else if (config.isDouble(fKey)) {
|
|
||||||
item.setType(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH"));
|
|
||||||
lore.add(Methods.formatText("&7" + config.getDouble(fKey)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Setting setting = Setting.getSetting(fKey);
|
|
||||||
|
|
||||||
if (setting != null && setting.getComments() != null) {
|
|
||||||
lore.add("");
|
|
||||||
|
|
||||||
String comment = String.join(" ", setting.getComments());
|
|
||||||
|
|
||||||
int lastIndex = 0;
|
|
||||||
for (int n = 0; n < comment.length(); n++) {
|
|
||||||
if (n - lastIndex < 30)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (comment.charAt(n) == ' ') {
|
|
||||||
lore.add(Methods.formatText("&8" + comment.substring(lastIndex, n).trim()));
|
|
||||||
lastIndex = n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastIndex - comment.length() < 30)
|
|
||||||
lore.add(Methods.formatText("&8" + comment.substring(lastIndex).trim()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
meta.setLore(lore);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
inventory.setItem(slot, item);
|
|
||||||
slot++;
|
|
||||||
}
|
|
||||||
|
|
||||||
player.openInventory(inventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadConfig() {
|
|
||||||
plugin.reloadConfig();
|
|
||||||
this.setupConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setupConfig() {
|
|
||||||
FileConfiguration config = plugin.getConfig();
|
|
||||||
|
|
||||||
for (Setting setting : Setting.values()) {
|
|
||||||
config.addDefault(setting.getSetting(), setting.getOption());
|
|
||||||
}
|
|
||||||
plugin.getConfig().options().copyDefaults(true);
|
|
||||||
saveConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveConfig() {
|
|
||||||
String dump = plugin.getConfig().saveToString();
|
|
||||||
|
|
||||||
StringBuilder config = new StringBuilder();
|
|
||||||
|
|
||||||
BufferedReader bufReader = new BufferedReader(new StringReader(dump));
|
|
||||||
|
|
||||||
try {
|
|
||||||
boolean first = true;
|
|
||||||
|
|
||||||
String line;
|
|
||||||
int currentTab = 0;
|
|
||||||
String category = "";
|
|
||||||
|
|
||||||
while ((line = bufReader.readLine()) != null) {
|
|
||||||
if (line.trim().startsWith("#")) continue;
|
|
||||||
|
|
||||||
int tabChange = line.length() - line.trim().length();
|
|
||||||
if (currentTab != tabChange) {
|
|
||||||
category = category.contains(".") && tabChange != 0 ? category.substring(0, category.indexOf(".")) : "";
|
|
||||||
currentTab = tabChange;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.endsWith(":")) {
|
|
||||||
bufReader.mark(1000);
|
|
||||||
String found = bufReader.readLine();
|
|
||||||
bufReader.reset();
|
|
||||||
|
|
||||||
if (!found.trim().startsWith("-")) {
|
|
||||||
|
|
||||||
String newCategory = line.substring(0, line.length() - 1).trim();
|
|
||||||
|
|
||||||
if (category.equals(""))
|
|
||||||
category = newCategory;
|
|
||||||
else
|
|
||||||
category += "." + newCategory;
|
|
||||||
|
|
||||||
currentTab = tabChange + 2;
|
|
||||||
|
|
||||||
if (!first) {
|
|
||||||
config.append("\n\n");
|
|
||||||
} else {
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!category.contains("."))
|
|
||||||
config.append("#").append("\n");
|
|
||||||
try {
|
|
||||||
Category categoryObj = Category.valueOf(category.toUpperCase()
|
|
||||||
.replace(" ", "_")
|
|
||||||
.replace(".", "_"));
|
|
||||||
|
|
||||||
config.append(new String(new char[tabChange]).replace('\0', ' '));
|
|
||||||
for (String l : categoryObj.getComments())
|
|
||||||
config.append("# ").append(l).append("\n");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
config.append("# ").append(category).append("\n");
|
|
||||||
}
|
|
||||||
if (!category.contains("."))
|
|
||||||
config.append("#").append("\n");
|
|
||||||
|
|
||||||
config.append(line).append("\n");
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line.trim().startsWith("-")) {
|
|
||||||
config.append(line).append("\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String key = category + "." + (line.split(":")[0].trim());
|
|
||||||
for (Setting setting : Setting.values()) {
|
|
||||||
if (!setting.getSetting().equals(key) || setting.getComments() == null) continue;
|
|
||||||
config.append(" ").append("\n");
|
|
||||||
for (String l : setting.getComments()) {
|
|
||||||
config.append(new String(new char[currentTab]).replace('\0', ' '));
|
|
||||||
config.append("# ").append(l).append("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
config.append(line).append("\n");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!plugin.getDataFolder().exists())
|
|
||||||
plugin.getDataFolder().mkdir();
|
|
||||||
BufferedWriter writer =
|
|
||||||
new BufferedWriter(new FileWriter(new File(plugin.getDataFolder() + File.separator + "config.yml")));
|
|
||||||
writer.write(config.toString());
|
|
||||||
writer.flush();
|
|
||||||
writer.close();
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user