diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5b6c006..5827fd6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "EpicHeads" path: "/builds/$CI_PROJECT_PATH" - version: "3.0.19" + version: "3.1" build: stage: build diff --git a/pom.xml b/pom.xml index 326c121..20681a5 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ false - com.songoda:songodaupdater + com.songoda:SongodaCore @@ -45,6 +45,12 @@ + + + com.songoda.core + ${project.groupId}.epicheads.core + + @@ -54,7 +60,7 @@ private - http://repo.songoda.com/artifactory/private/ + https://repo.songoda.com/artifactory/private/ reserve-repo @@ -69,25 +75,9 @@ com.songoda - songodaupdater - 1 - - - net.milkbowl - vault - 1.7.1 - provided - - - org.black_ixx - playerpoints - 2.1.4 - - - net.tnemc - Reserve - 0.1.3.0 - provided + SongodaCore + LATEST + compile diff --git a/src/main/java/com/songoda/epicheads/EpicHeads.java b/src/main/java/com/songoda/epicheads/EpicHeads.java index b342feb..4318e92 100644 --- a/src/main/java/com/songoda/epicheads/EpicHeads.java +++ b/src/main/java/com/songoda/epicheads/EpicHeads.java @@ -1,7 +1,15 @@ package com.songoda.epicheads; -import com.songoda.epicheads.command.CommandManager; -import com.songoda.epicheads.economy.*; +import com.songoda.core.SongodaCore; +import com.songoda.core.SongodaPlugin; +import com.songoda.core.commands.CommandManager; +import com.songoda.core.compatibility.LegacyMaterials; +import com.songoda.core.configuration.Config; +import com.songoda.core.gui.GuiManager; +import com.songoda.core.hooks.EconomyManager; +import com.songoda.core.hooks.PluginHook; +import com.songoda.core.hooks.economies.Economy; +import com.songoda.epicheads.commands.*; import com.songoda.epicheads.head.Category; import com.songoda.epicheads.head.Head; import com.songoda.epicheads.head.HeadManager; @@ -10,24 +18,13 @@ import com.songoda.epicheads.listeners.ItemListeners; import com.songoda.epicheads.listeners.LoginListeners; import com.songoda.epicheads.players.EPlayer; import com.songoda.epicheads.players.PlayerManager; -import com.songoda.epicheads.utils.Methods; +import com.songoda.epicheads.settings.Settings; import com.songoda.epicheads.utils.Metrics; -import com.songoda.epicheads.utils.ServerVersion; -import com.songoda.epicheads.utils.gui.AbstractGUI; -import com.songoda.epicheads.utils.locale.Locale; -import com.songoda.epicheads.utils.settings.Setting; -import com.songoda.epicheads.utils.settings.SettingsManager; import com.songoda.epicheads.utils.storage.Storage; import com.songoda.epicheads.utils.storage.StorageRow; import com.songoda.epicheads.utils.storage.types.StorageYaml; -import com.songoda.epicheads.utils.updateModules.LocaleModule; -import com.songoda.update.Plugin; -import com.songoda.update.SongodaUpdate; -import org.apache.commons.lang.ArrayUtils; import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -40,70 +37,76 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -public class EpicHeads extends JavaPlugin { - private static CommandSender console = Bukkit.getConsoleSender(); +public class EpicHeads extends SongodaPlugin { + private static EpicHeads INSTANCE; - private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName()); - + private GuiManager guiManager = new GuiManager(this); private HeadManager headManager; private PlayerManager playerManager; - private SettingsManager settingsManager; private CommandManager commandManager; - private Locale locale; private Storage storage; - private Economy economy; public static EpicHeads getInstance() { return INSTANCE; } @Override - public void onEnable() { + public void onPluginLoad() { INSTANCE = this; + PluginHook.addHook(Economy.class, "EpicHeads", com.songoda.epicheads.economy.ItemEconomy.class); + } - console.sendMessage(Methods.formatText("&a=============================")); - console.sendMessage(Methods.formatText("&7EpicHeads " + this.getDescription().getVersion() + " by &5Songoda <3!")); - console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); + @Override + public void onPluginDisable() { + this.storage.closeConnection(); + this.saveToFile(); + } - this.settingsManager = new SettingsManager(this); - this.settingsManager.setupConfig(); + @Override + public void onPluginEnable() { + // Run Songoda Updater + SongodaCore.registerPlugin(this, 26, LegacyMaterials.PLAYER_HEAD); - // Setup language - new Locale(this, "en_US"); - this.locale = Locale.getLocale(getConfig().getString("System.Language Mode")); + // Load Economy + EconomyManager.load(); - //Running Songoda Updater - Plugin plugin = new Plugin(this, 26); - plugin.addModule(new LocaleModule()); - SongodaUpdate.load(plugin); + // Setup Config + Settings.setupConfig(); + this.setLocale(Settings.LANGUGE_MODE.getString(), false); + + // Set economy preference + EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString()); + + // Register commands + this.commandManager = new CommandManager(this); + this.commandManager.addCommand(new CommandEpicHeads(this)) + .addSubCommands( + new CommandAdd(this), + new CommandBase64(this), + new CommandGive(this), + new CommandGiveToken(this), + new CommandHelp(this), + new CommandReload(this), + new CommandSearch(this), + new CommandSettings(this), + new CommandUrl(this) + ); this.storage = new StorageYaml(this); // Setup Managers this.headManager = new HeadManager(); this.playerManager = new PlayerManager(); - this.commandManager = new CommandManager(this); - - PluginManager pluginManager = Bukkit.getPluginManager(); // Register Listeners - AbstractGUI.initializeListeners(this); + guiManager.init(); + PluginManager pluginManager = Bukkit.getPluginManager(); pluginManager.registerEvents(new DeathListeners(this), this); pluginManager.registerEvents(new ItemListeners(this), this); pluginManager.registerEvents(new LoginListeners(this), this); - // Setup Economy - if (Setting.VAULT_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Vault")) - this.economy = new VaultEconomy(); - else if (Setting.RESERVE_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("Reserve")) - this.economy = new ReserveEconomy(); - else if (Setting.PLAYER_POINTS_ECONOMY.getBoolean() && pluginManager.isPluginEnabled("PlayerPoints")) - this.economy = new PlayerPointsEconomy(); - else if (Setting.ITEM_ECONOMY.getBoolean()) - this.economy = new ItemEconomy(); - // Download Heads downloadHeads(); @@ -113,23 +116,11 @@ public class EpicHeads extends JavaPlugin { // Load Favorites loadData(); - int timeout = Setting.AUTOSAVE.getInt() * 60 * 20; + int timeout = Settings.AUTOSAVE.getInt() * 60 * 20; Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, timeout, timeout); // Start Metrics new Metrics(this); - - console.sendMessage(Methods.formatText("&a=============================")); - } - - @Override - public void onDisable() { - this.storage.closeConnection(); - this.saveToFile(); - console.sendMessage(Methods.formatText("&a=============================")); - console.sendMessage(Methods.formatText("&7EpicHeads " + this.getDescription().getVersion() + " by &5Songoda <3!")); - console.sendMessage(Methods.formatText("&7Action: &cDisabling&7...")); - console.sendMessage(Methods.formatText("&a=============================")); } private void saveToFile() { @@ -145,7 +136,7 @@ public class EpicHeads extends JavaPlugin { EPlayer player = new EPlayer( UUID.fromString(row.get("uuid").asString()), - (List)row.get("favorites").asObject()); + (List) row.get("favorites").asObject()); this.playerManager.addPlayer(player); } @@ -190,7 +181,7 @@ public class EpicHeads extends JavaPlugin { int id = Integer.parseInt((String) jsonObject.get("id")); - if (Setting.DISABLED_HEADS.getIntegerList().contains(id)) continue; + if (Settings.DISABLED_HEADS.getIntegerList().contains(id)) continue; Head head = new Head(id, (String) jsonObject.get("name"), @@ -250,38 +241,29 @@ public class EpicHeads extends JavaPlugin { return sb.toString(); } - - public ServerVersion getServerVersion() { - return serverVersion; - } - - public boolean isServerVersion(ServerVersion version) { - return serverVersion == version; - } - public boolean isServerVersion(ServerVersion... versions) { - return ArrayUtils.contains(versions, serverVersion); - } - - public boolean isServerVersionAtLeast(ServerVersion version) { - return serverVersion.ordinal() >= version.ordinal(); - } - - public void reload() { + @Override + public void onConfigReload() { saveToFile(); - this.locale = Locale.getLocale(getConfig().getString("System.Language Mode")); + + this.setLocale(getConfig().getString("System.Language Mode"), true); this.locale.reloadMessages(); - settingsManager.reloadConfig(); + saveToFile(); downloadHeads(); loadHeads(); } - public Locale getLocale() { - return locale; + @Override + public List getExtraConfig() { + return null; } - public Economy getEconomy() { - return economy; + public CommandManager getCommandManager() { + return commandManager; + } + + public GuiManager getGuiManager() { + return guiManager; } public HeadManager getHeadManager() { @@ -291,12 +273,4 @@ public class EpicHeads extends JavaPlugin { public PlayerManager getPlayerManager() { return playerManager; } - - public CommandManager getCommandManager() { - return commandManager; - } - - public SettingsManager getSettingsManager() { - return settingsManager; - } } diff --git a/src/main/java/com/songoda/epicheads/command/AbstractCommand.java b/src/main/java/com/songoda/epicheads/command/AbstractCommand.java deleted file mode 100644 index 2f43194..0000000 --- a/src/main/java/com/songoda/epicheads/command/AbstractCommand.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.songoda.epicheads.command; - -import com.songoda.epicheads.EpicHeads; -import org.bukkit.command.CommandSender; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public abstract class AbstractCommand { - - private final boolean noConsole; - private AbstractCommand parent = null; - private boolean hasArgs = false; - private String command; - - private List subCommand = new ArrayList<>(); - - protected AbstractCommand(AbstractCommand parent, boolean noConsole, String... command) { - if (parent != null) { - this.subCommand = Arrays.asList(command); - } else { - this.command = Arrays.asList(command).get(0); - } - this.parent = parent; - this.noConsole = noConsole; - } - - protected AbstractCommand(boolean noConsole, boolean hasArgs, String... command) { - this.command = Arrays.asList(command).get(0); - - this.hasArgs = hasArgs; - this.noConsole = noConsole; - } - - public AbstractCommand getParent() { - return parent; - } - - public String getCommand() { - return command; - } - - public List getSubCommand() { - return subCommand; - } - - public void addSubCommand(String command) { - subCommand.add(command); - } - - protected abstract ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args); - - protected abstract List onTab(EpicHeads instance, CommandSender sender, String... args); - - public abstract String getPermissionNode(); - - public abstract String getSyntax(); - - public abstract String getDescription(); - - public boolean hasArgs() { - return hasArgs; - } - - public boolean isNoConsole() { - return noConsole; - } - - public enum ReturnType {SUCCESS, FAILURE, SYNTAX_ERROR} -} diff --git a/src/main/java/com/songoda/epicheads/command/CommandManager.java b/src/main/java/com/songoda/epicheads/command/CommandManager.java deleted file mode 100644 index 92e1d9f..0000000 --- a/src/main/java/com/songoda/epicheads/command/CommandManager.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.songoda.epicheads.command; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.commands.*; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class CommandManager implements CommandExecutor { - - private EpicHeads instance; - private TabManager tabManager; - - private List commands = new ArrayList<>(); - - public CommandManager(EpicHeads instance) { - this.instance = instance; - this.tabManager = new TabManager(this); - - instance.getCommand("EpicHeads").setExecutor(this); - - AbstractCommand commandEpicHeads = addCommand(new CommandEpicHeads()); - - addCommand(new CommandSettings(commandEpicHeads)); - addCommand(new CommandHelp(commandEpicHeads)); - addCommand(new CommandReload(commandEpicHeads)); - addCommand(new CommandUrl(commandEpicHeads)); - addCommand(new CommandBase64(commandEpicHeads)); - addCommand(new CommandGive(commandEpicHeads)); - addCommand(new CommandGiveToken(commandEpicHeads)); - addCommand(new CommandAdd(commandEpicHeads)); - addCommand(new CommandSearch(commandEpicHeads)); - - for (AbstractCommand abstractCommand : commands) { - if (abstractCommand.getParent() != null) continue; - instance.getCommand(abstractCommand.getCommand()).setTabCompleter(tabManager); - } - } - - private AbstractCommand addCommand(AbstractCommand abstractCommand) { - commands.add(abstractCommand); - return abstractCommand; - } - - @Override - public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { - for (AbstractCommand abstractCommand : commands) { - if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) { - if (strings.length == 0 || abstractCommand.hasArgs()) { - processRequirements(abstractCommand, commandSender, strings); - return true; - } - } else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) { - String cmd = strings[0]; - String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null; - for (String cmds : abstractCommand.getSubCommand()) { - if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) { - processRequirements(abstractCommand, commandSender, strings); - return true; - } - } - } - } - instance.getLocale().newMessage("&7The command you entered does not exist or is spelt incorrectly.").sendPrefixedMessage(commandSender); - return true; - } - - private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) { - if (!(sender instanceof Player) && command.isNoConsole()) { - sender.sendMessage("You must be a player to use this commands."); - return; - } - if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { - AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings); - if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) { - instance.getLocale().newMessage("&cInvalid Syntax!").sendPrefixedMessage(sender); - instance.getLocale().newMessage("&7The valid syntax is: &6" + command.getSyntax() + "&7.").sendPrefixedMessage(sender); - } - return; - } - instance.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender); - } - - public List getCommands() { - return Collections.unmodifiableList(commands); - } -} diff --git a/src/main/java/com/songoda/epicheads/command/TabManager.java b/src/main/java/com/songoda/epicheads/command/TabManager.java deleted file mode 100644 index 99900ae..0000000 --- a/src/main/java/com/songoda/epicheads/command/TabManager.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.songoda.epicheads.command; - -import com.songoda.epicheads.EpicHeads; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; - -import java.util.ArrayList; -import java.util.List; - -public class TabManager implements TabCompleter { - - private final CommandManager commandManager; - - TabManager(CommandManager commandManager) { - this.commandManager = commandManager; - } - - @Override - public List onTabComplete(CommandSender sender, Command command, String alias, String[] strings) { - for (AbstractCommand abstractCommand : commandManager.getCommands()) { - if (abstractCommand.getCommand() != null && abstractCommand.getCommand().equalsIgnoreCase(command.getName()) && !abstractCommand.hasArgs()) { - if (strings.length == 1) { - List subs = new ArrayList<>(); - for (AbstractCommand ac : commandManager.getCommands()) { - if (ac.getSubCommand() == null) continue; - subs.addAll(ac.getSubCommand()); - } - subs.removeIf(s -> !s.toLowerCase().startsWith(strings[0].toLowerCase())); - return subs; - } - } else if (strings.length != 0 - && abstractCommand.getCommand() != null - && abstractCommand.getCommand().equalsIgnoreCase(command.getName().toLowerCase())) { - String cmd = strings[0]; - String cmd2 = strings.length >= 2 ? String.join(" ", strings[0], strings[1]) : null; - if (abstractCommand.hasArgs()) { - return onCommand(abstractCommand, strings, sender); - } else { - for (String cmds : abstractCommand.getSubCommand()) { - if (cmd.equalsIgnoreCase(cmds) || (cmd2 != null && cmd2.equalsIgnoreCase(cmds))) { - return onCommand(abstractCommand, strings, sender); - } - } - } - } - } - return null; - } - - - private List onCommand(AbstractCommand abstractCommand, String[] strings, CommandSender sender) { - List list = abstractCommand.onTab(EpicHeads.getInstance(), sender, strings); - String str = strings[strings.length - 1]; - if (list != null && str != null && str.length() >= 1) { - try { - list.removeIf(s -> !s.toLowerCase().startsWith(str.toLowerCase())); - } catch (UnsupportedOperationException ignored) { - } - } - return list; - } -} diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandAdd.java b/src/main/java/com/songoda/epicheads/commands/CommandAdd.java similarity index 71% rename from src/main/java/com/songoda/epicheads/command/commands/CommandAdd.java rename to src/main/java/com/songoda/epicheads/commands/CommandAdd.java index 8937968..48b68bf 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandAdd.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandAdd.java @@ -1,7 +1,7 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; import com.songoda.epicheads.head.Category; import com.songoda.epicheads.head.Head; import com.songoda.epicheads.head.HeadManager; @@ -12,17 +12,20 @@ import java.util.stream.Collectors; public class CommandAdd extends AbstractCommand { - public CommandAdd(AbstractCommand parent) { - super(parent, false, "add"); + final EpicHeads instance; + + public CommandAdd(EpicHeads instance) { + super(false, "add"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - if (args.length != 4) return ReturnType.SYNTAX_ERROR; + protected ReturnType runCommand(CommandSender sender, String... args) { + if (args.length != 3) return ReturnType.SYNTAX_ERROR; - String url = args[1]; - String name = args[2].replace("_", " "); - String categoryStr = args[3].replace("_", " "); + String url = args[0]; + String name = args[1].replace("_", " "); + String categoryStr = args[2].replace("_", " "); HeadManager headManager = instance.getHeadManager(); @@ -35,18 +38,18 @@ public class CommandAdd extends AbstractCommand { Category category = categories.isEmpty() ? new Category(categoryStr) : categories.get(0); - headManager.addLocalHead(new Head(headManager.getNextLocalId(), name, url, category, null, (byte)0)); + headManager.addLocalHead(new Head(headManager.getNextLocalId(), name, url, category, null, (byte) 0)); instance.getLocale().getMessage("command.add.success") .processPlaceholder("name", name).sendPrefixedMessage(sender); if (categories.isEmpty()) { - instance.reload(); + instance.reloadConfig(); } return ReturnType.SUCCESS; } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandBase64.java b/src/main/java/com/songoda/epicheads/commands/CommandBase64.java similarity index 72% rename from src/main/java/com/songoda/epicheads/command/commands/CommandBase64.java rename to src/main/java/com/songoda/epicheads/commands/CommandBase64.java index b471838..e4718f5 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandBase64.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandBase64.java @@ -1,7 +1,7 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; import com.songoda.epicheads.utils.Methods; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -12,14 +12,17 @@ import java.util.List; public class CommandBase64 extends AbstractCommand { - public CommandBase64(AbstractCommand parent) { - super(parent, true, "base64"); + final EpicHeads instance; + + public CommandBase64(EpicHeads instance) { + super(true, "base64"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { + protected ReturnType runCommand(CommandSender sender, String... args) { - Player player = (Player)sender; + Player player = (Player) sender; ItemStack item = player.getItemInHand(); @@ -35,7 +38,7 @@ public class CommandBase64 extends AbstractCommand { } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } @@ -53,4 +56,5 @@ public class CommandBase64 extends AbstractCommand { public String getDescription() { return "Gives you the base64 code of the head you are holding."; } + } diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandEpicHeads.java b/src/main/java/com/songoda/epicheads/commands/CommandEpicHeads.java similarity index 55% rename from src/main/java/com/songoda/epicheads/command/commands/CommandEpicHeads.java rename to src/main/java/com/songoda/epicheads/commands/CommandEpicHeads.java index 0b1ac93..dbb3b40 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandEpicHeads.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandEpicHeads.java @@ -1,7 +1,7 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; import com.songoda.epicheads.gui.GUIOverview; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -10,18 +10,21 @@ import java.util.List; public class CommandEpicHeads extends AbstractCommand { - public CommandEpicHeads() { - super(true, false, "EpicHeads"); + final EpicHeads instance; + + public CommandEpicHeads(EpicHeads instance) { + super(false, "EpicHeads"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - new GUIOverview(instance, (Player)sender); + protected ReturnType runCommand(CommandSender sender, String... args) { + instance.getGuiManager().showGUI((Player) sender, new GUIOverview(instance, (Player) sender)); return ReturnType.SUCCESS; } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandGive.java b/src/main/java/com/songoda/epicheads/commands/CommandGive.java similarity index 85% rename from src/main/java/com/songoda/epicheads/command/commands/CommandGive.java rename to src/main/java/com/songoda/epicheads/commands/CommandGive.java index 2f826f4..f6d539a 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandGive.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandGive.java @@ -1,7 +1,7 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; import com.songoda.epicheads.head.Head; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -15,19 +15,21 @@ import java.util.Optional; public class CommandGive extends AbstractCommand { - public CommandGive(AbstractCommand parent) { - super(parent, false, "give"); + final EpicHeads instance; + + public CommandGive(EpicHeads instance) { + super(false, "give"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { + protected ReturnType runCommand(CommandSender sender, String... args) { + if (args.length != 3) return ReturnType.SYNTAX_ERROR; - if (args.length != 4) return ReturnType.SYNTAX_ERROR; - - String playerStr = args[1].toLowerCase(); + String playerStr = args[0].toLowerCase(); Player player = Bukkit.getPlayer(playerStr); - String archive = args[2]; - int headId = Integer.parseInt(args[3]); + String archive = args[1]; + int headId = Integer.parseInt(args[2]); if (player == null && !playerStr.equals("all")) { instance.getLocale().getMessage("command.give.notonline") @@ -85,7 +87,7 @@ public class CommandGive extends AbstractCommand { } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandGiveToken.java b/src/main/java/com/songoda/epicheads/commands/CommandGiveToken.java similarity index 72% rename from src/main/java/com/songoda/epicheads/command/commands/CommandGiveToken.java rename to src/main/java/com/songoda/epicheads/commands/CommandGiveToken.java index 7ae8427..d228511 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandGiveToken.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandGiveToken.java @@ -1,7 +1,7 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; import com.songoda.epicheads.utils.Methods; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -11,15 +11,19 @@ import java.util.List; public class CommandGiveToken extends AbstractCommand { - public CommandGiveToken(AbstractCommand parent) { - super(parent, false, "givetoken"); + final EpicHeads instance; + + public CommandGiveToken(EpicHeads instance) { + super(false, "givetoken"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { + protected ReturnType runCommand(CommandSender sender, String... args) { + if (args.length != 2) return ReturnType.SYNTAX_ERROR; - Player player = Bukkit.getPlayer(args[1]); - int amount = Integer.valueOf(args[2]); + Player player = Bukkit.getPlayer(args[0]); + int amount = Integer.parseInt(args[1]); if (player == null) { instance.getLocale().getMessage("command.give.notonline") @@ -41,7 +45,7 @@ public class CommandGiveToken extends AbstractCommand { } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandHelp.java b/src/main/java/com/songoda/epicheads/commands/CommandHelp.java similarity index 68% rename from src/main/java/com/songoda/epicheads/command/commands/CommandHelp.java rename to src/main/java/com/songoda/epicheads/commands/CommandHelp.java index 7387b4e..ba3d449 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandHelp.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandHelp.java @@ -1,20 +1,24 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; import com.songoda.epicheads.utils.Methods; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import java.util.List; public class CommandHelp extends AbstractCommand { - public CommandHelp(AbstractCommand parent) { - super(parent, false, "help"); + final EpicHeads instance; + + public CommandHelp(EpicHeads instance) { + super(false, "help"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { + protected ReturnType runCommand(CommandSender sender, String... args) { sender.sendMessage(""); instance.getLocale().newMessage("&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda").sendPrefixedMessage(sender); @@ -22,9 +26,9 @@ public class CommandHelp extends AbstractCommand { sender.sendMessage(Methods.formatText("&7Welcome to EpicHeads! To get started try using the /heads command to access the heads panel.")); sender.sendMessage(""); sender.sendMessage(Methods.formatText("&6Commands:")); - for (AbstractCommand command : instance.getCommandManager().getCommands()) { + for (AbstractCommand command : instance.getCommandManager().getAllCommands()) { if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { - sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); } } sender.sendMessage(""); @@ -33,7 +37,7 @@ public class CommandHelp extends AbstractCommand { } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandReload.java b/src/main/java/com/songoda/epicheads/commands/CommandReload.java similarity index 60% rename from src/main/java/com/songoda/epicheads/command/commands/CommandReload.java rename to src/main/java/com/songoda/epicheads/commands/CommandReload.java index 5b88661..a3a83bf 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandReload.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandReload.java @@ -1,27 +1,29 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; -import com.songoda.epicheads.utils.Methods; import org.bukkit.command.CommandSender; import java.util.List; public class CommandReload extends AbstractCommand { - public CommandReload(AbstractCommand parent) { - super(parent, false, "reload"); + final EpicHeads instance; + + public CommandReload(EpicHeads instance) { + super(false, "reload"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - instance.reload(); + protected ReturnType runCommand(CommandSender sender, String... args) { + instance.reloadConfig(); instance.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender); return ReturnType.SUCCESS; } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandSearch.java b/src/main/java/com/songoda/epicheads/commands/CommandSearch.java similarity index 50% rename from src/main/java/com/songoda/epicheads/command/commands/CommandSearch.java rename to src/main/java/com/songoda/epicheads/commands/CommandSearch.java index ece444f..42a2702 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandSearch.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandSearch.java @@ -1,34 +1,30 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; import com.songoda.epicheads.gui.GUIHeads; -import com.songoda.epicheads.head.Head; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayList; import java.util.List; -import java.util.Optional; public class CommandSearch extends AbstractCommand { - public CommandSearch(AbstractCommand parent) { - super(parent, true, "search"); + final EpicHeads instance; + + public CommandSearch(EpicHeads instance) { + super(true, "search"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - - GUIHeads.doSearch((Player)sender); + protected AbstractCommand.ReturnType runCommand(CommandSender sender, String... args) { + GUIHeads.doSearch(instance, (Player) sender); return ReturnType.SUCCESS; } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandSettings.java b/src/main/java/com/songoda/epicheads/commands/CommandSettings.java similarity index 52% rename from src/main/java/com/songoda/epicheads/command/commands/CommandSettings.java rename to src/main/java/com/songoda/epicheads/commands/CommandSettings.java index 9940b6a..1dedce9 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandSettings.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandSettings.java @@ -1,7 +1,8 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; +import com.songoda.core.configuration.editor.PluginConfigGui; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -9,19 +10,21 @@ import java.util.List; public class CommandSettings extends AbstractCommand { - public CommandSettings(AbstractCommand parent) { - super(parent, true, "settings"); + final EpicHeads instance; + + public CommandSettings(EpicHeads instance) { + super(true, "settings"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - Player player = (Player) sender; - instance.getSettingsManager().openSettingsManager(player); + protected ReturnType runCommand(CommandSender sender, String... args) { + instance.getGuiManager().showGUI((Player) sender, new PluginConfigGui(instance)); return ReturnType.SUCCESS; } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/epicheads/command/commands/CommandUrl.java b/src/main/java/com/songoda/epicheads/commands/CommandUrl.java similarity index 73% rename from src/main/java/com/songoda/epicheads/command/commands/CommandUrl.java rename to src/main/java/com/songoda/epicheads/commands/CommandUrl.java index 92865e5..cca1e92 100644 --- a/src/main/java/com/songoda/epicheads/command/commands/CommandUrl.java +++ b/src/main/java/com/songoda/epicheads/commands/CommandUrl.java @@ -1,7 +1,7 @@ -package com.songoda.epicheads.command.commands; +package com.songoda.epicheads.commands; +import com.songoda.core.commands.AbstractCommand; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.command.AbstractCommand; import com.songoda.epicheads.utils.Methods; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -12,14 +12,16 @@ import java.util.List; public class CommandUrl extends AbstractCommand { - public CommandUrl(AbstractCommand parent) { - super(parent, true, "url"); + final EpicHeads instance; + + public CommandUrl(EpicHeads instance) { + super(true, "url"); + this.instance = instance; } @Override - protected ReturnType runCommand(EpicHeads instance, CommandSender sender, String... args) { - - Player player = (Player)sender; + protected AbstractCommand.ReturnType runCommand(CommandSender sender, String... args) { + Player player = (Player) sender; ItemStack item = player.getItemInHand(); @@ -37,7 +39,7 @@ public class CommandUrl extends AbstractCommand { } @Override - protected List onTab(EpicHeads instance, CommandSender sender, String... args) { + protected List onTab(CommandSender sender, String... args) { return null; } diff --git a/src/main/java/com/songoda/epicheads/economy/Economy.java b/src/main/java/com/songoda/epicheads/economy/Economy.java deleted file mode 100644 index e5e1248..0000000 --- a/src/main/java/com/songoda/epicheads/economy/Economy.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.songoda.epicheads.economy; - -import org.bukkit.OfflinePlayer; - -public interface Economy { - - boolean hasBalance(OfflinePlayer player, double cost); - - boolean withdrawBalance(OfflinePlayer player, double cost); - - boolean deposit(OfflinePlayer player, double amount); -} diff --git a/src/main/java/com/songoda/epicheads/economy/PlayerPointsEconomy.java b/src/main/java/com/songoda/epicheads/economy/PlayerPointsEconomy.java deleted file mode 100644 index e2b683c..0000000 --- a/src/main/java/com/songoda/epicheads/economy/PlayerPointsEconomy.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.songoda.epicheads.economy; - -import org.black_ixx.playerpoints.PlayerPoints; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; - -public class PlayerPointsEconomy implements Economy { - - private final PlayerPoints playerPoints; - - public PlayerPointsEconomy() { - this.playerPoints = (PlayerPoints) Bukkit.getServer().getPluginManager().getPlugin("PlayerPoints"); - } - - private int convertAmount(double amount) { - return (int) Math.ceil(amount); - } - - @Override - public boolean hasBalance(OfflinePlayer player, double cost) { - int amount = convertAmount(cost); - return playerPoints.getAPI().look(player.getUniqueId()) >= amount; - - } - - @Override - public boolean withdrawBalance(OfflinePlayer player, double cost) { - int amount = convertAmount(cost); - return playerPoints.getAPI().take(player.getUniqueId(), amount); - - } - - @Override - public boolean deposit(OfflinePlayer player, double amount) { - int amt = convertAmount(amount); - return playerPoints.getAPI().give(player.getUniqueId(), amt); - } -} diff --git a/src/main/java/com/songoda/epicheads/economy/ReserveEconomy.java b/src/main/java/com/songoda/epicheads/economy/ReserveEconomy.java deleted file mode 100644 index 297e68f..0000000 --- a/src/main/java/com/songoda/epicheads/economy/ReserveEconomy.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.songoda.epicheads.economy; - -import net.tnemc.core.Reserve; -import net.tnemc.core.economy.EconomyAPI; -import org.bukkit.OfflinePlayer; - -import java.math.BigDecimal; - -public class ReserveEconomy implements Economy { - - EconomyAPI economyAPI; - - public ReserveEconomy() { - if (Reserve.instance().economyProvided()) - economyAPI = Reserve.instance().economy(); - } - - @Override - public boolean hasBalance(OfflinePlayer player, double cost) { - return economyAPI.hasHoldings(player.getUniqueId(), new BigDecimal(cost)); - } - - @Override - public boolean withdrawBalance(OfflinePlayer player, double cost) { - return economyAPI.removeHoldings(player.getUniqueId(), new BigDecimal(cost)); - } - - @Override - public boolean deposit(OfflinePlayer player, double amount) { - return economyAPI.addHoldings(player.getUniqueId(), new BigDecimal(amount)); - } -} diff --git a/src/main/java/com/songoda/epicheads/economy/VaultEconomy.java b/src/main/java/com/songoda/epicheads/economy/VaultEconomy.java deleted file mode 100644 index fc54762..0000000 --- a/src/main/java/com/songoda/epicheads/economy/VaultEconomy.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.songoda.epicheads.economy; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; - -public class VaultEconomy implements Economy { - private final net.milkbowl.vault.economy.Economy vault; - - public VaultEconomy() { - this.vault = Bukkit.getServicesManager(). - getRegistration(net.milkbowl.vault.economy.Economy.class).getProvider(); - } - - @Override - public boolean hasBalance(OfflinePlayer player, double cost) { - return vault.has(player, cost); - } - - @Override - public boolean withdrawBalance(OfflinePlayer player, double cost) { - return vault.withdrawPlayer(player, cost).transactionSuccess(); - } - - @Override - public boolean deposit(OfflinePlayer player, double amount) { - return vault.depositPlayer(player, amount).transactionSuccess(); - } -} diff --git a/src/main/java/com/songoda/epicheads/gui/GUIHeads.java b/src/main/java/com/songoda/epicheads/gui/GUIHeads.java index fc9eb58..9b48f15 100644 --- a/src/main/java/com/songoda/epicheads/gui/GUIHeads.java +++ b/src/main/java/com/songoda/epicheads/gui/GUIHeads.java @@ -1,16 +1,18 @@ package com.songoda.epicheads.gui; +import com.songoda.core.compatibility.LegacyMaterials; +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiUtils; +import com.songoda.core.hooks.EconomyManager; +import com.songoda.core.input.ChatPrompt; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.economy.Economy; import com.songoda.epicheads.head.Category; import com.songoda.epicheads.head.Head; import com.songoda.epicheads.players.EPlayer; -import com.songoda.epicheads.utils.AbstractChatConfirm; -import com.songoda.epicheads.utils.gui.AbstractGUI; -import com.songoda.epicheads.utils.settings.Setting; +import com.songoda.epicheads.settings.Settings; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.GameMode; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; @@ -21,9 +23,10 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; -public class GUIHeads extends AbstractGUI { +public class GUIHeads extends Gui { private final EpicHeads plugin; + private final Player player; private List heads; private int page = 0; @@ -34,8 +37,8 @@ public class GUIHeads extends AbstractGUI { private final QueryTypes type; public GUIHeads(EpicHeads plugin, Player player, String query, QueryTypes type, List heads) { - super(player); this.plugin = plugin; + this.player = player; this.query = query; this.type = type; @@ -73,77 +76,108 @@ public class GUIHeads extends AbstractGUI { } this.maxPage = (int) Math.floor(numHeads / 45.0); - init(name + " (" + numHeads + ") " + plugin.getLocale().getMessage("general.word.page") + " " + (page + 1) + "/" + (maxPage + 1), 54); - constructGUI(); + + this.setDefaultItem(null); + this.setRows(6); + this.setTitle(name + " (" + numHeads + ") " + plugin.getLocale().getMessage("general.word.page") + " " + (page + 1) + "/" + (maxPage + 1)); + showPage(); } - @Override - protected void constructGUI() { - resetClickables(); - registerClickables(); + void showPage() { List heads = this.heads.stream().skip(page * 45).limit(45) .collect(Collectors.toList()); if (page - 2 > 0) { - createButton(0, Material.ARROW, "&c" + plugin.getLocale().getMessage("general.word.page") + " " + (page - 2)); - registerClickable(0, ((player1, inventory1, cursor, slot, type) -> { - page -= 3; - updateTitle(); - })); - inventory.getItem(0).setAmount(page - 2); + ItemStack arrow = GuiUtils.createButtonItem(LegacyMaterials.ARROW, + ChatColor.RED.toString() + plugin.getLocale().getMessage("general.word.page") + " " + (page - 2)); + arrow.setAmount(page - 2); + setButton(0, arrow, + (event) -> { + page -= 3; + updateTitle(); + }); } if (page - 1 > 0) { - createButton(1, Material.ARROW, "&c" + plugin.getLocale().getMessage("general.word.page") + " " + (page - 1)); - registerClickable(1, ((player1, inventory1, cursor, slot, type) -> { - page -= 2; - updateTitle(); - })); - inventory.getItem(1).setAmount(page - 1); + ItemStack arrow = GuiUtils.createButtonItem(LegacyMaterials.ARROW, + ChatColor.RED.toString() + plugin.getLocale().getMessage("general.word.page") + " " + (page - 1)); + arrow.setAmount(page - 1); + setButton(1, arrow, + (event) -> { + page -= 2; + updateTitle(); + }); } if (page != 0) { - createButton(2, Material.ARROW, "&c" + plugin.getLocale().getMessage("general.word.page") + " " + page); - registerClickable(2, ((player1, inventory1, cursor, slot, type) -> { - page--; - updateTitle(); - })); - inventory.getItem(2).setAmount(page); + ItemStack arrow = GuiUtils.createButtonItem(LegacyMaterials.ARROW, + ChatColor.RED.toString() + plugin.getLocale().getMessage("general.word.page") + " " + page); + arrow.setAmount(page); + setButton(2, arrow, + (event) -> { + page--; + updateTitle(); + }); } - createButton(3, Material.COMPASS, plugin.getLocale().getMessage("gui.heads.search").getMessage()); + setButton(3, GuiUtils.createButtonItem(LegacyMaterials.COMPASS, + plugin.getLocale().getMessage("gui.heads.search").getMessage()), + (event) -> doSearch(plugin, event.player)); + + ItemStack map = GuiUtils.createButtonItem(LegacyMaterials.MAP, + plugin.getLocale().getMessage("gui.heads.categories").getMessage()); + map.setAmount(page + 1); + setButton(4, map, (event) -> plugin.getGuiManager().showGUI(player, new GUIOverview(plugin, event.player))); - createButton(4, Material.MAP, plugin.getLocale().getMessage("gui.heads.categories").getMessage()); - inventory.getItem(4).setAmount(page + 1); if (heads.size() > 1) - createButton(5, Material.COMPASS, plugin.getLocale().getMessage("gui.heads.refine").getMessage()); + setButton(5, GuiUtils.createButtonItem(LegacyMaterials.COMPASS, + plugin.getLocale().getMessage("gui.heads.refine").getMessage()), + (event) -> { + plugin.getLocale().getMessage("general.search.refine").sendPrefixedMessage(event.player); + ChatPrompt chatPrompt = ChatPrompt.showPrompt(plugin, event.player, promptEvent -> { + this.page = 0; + this.heads = this.heads.stream().filter(head -> head.getName().toLowerCase() + .contains(promptEvent.getMessage().toLowerCase())).collect(Collectors.toList()); + if (query == null) + this.query = promptEvent.getMessage(); + else + this.query += ", " + promptEvent.getMessage(); + }); + chatPrompt.setOnClose(this::updateTitle); + }); if (page != maxPage) { - createButton(6, Material.ARROW, "&c" + plugin.getLocale().getMessage("general.word.page") + " " + (page + 2)); - registerClickable(6, ((player1, inventory1, cursor, slot, type) -> { - page++; - updateTitle(); - })); - inventory.getItem(6).setAmount(page + 2); + ItemStack arrow = GuiUtils.createButtonItem(LegacyMaterials.ARROW, + ChatColor.RED.toString() + plugin.getLocale().getMessage("general.word.page") + " " + (page + 2)); + arrow.setAmount(page + 2); + setButton(6, arrow, + (event) -> { + page++; + updateTitle(); + }); } if (page + 1 < maxPage) { - createButton(7, Material.ARROW, "&c" + plugin.getLocale().getMessage("general.word.page") + " " + (page + 3)); - registerClickable(7, ((player1, inventory1, cursor, slot, type) -> { - page += 2; - updateTitle(); - })); - inventory.getItem(7).setAmount(page + 3); + ItemStack arrow = GuiUtils.createButtonItem(LegacyMaterials.ARROW, + ChatColor.RED.toString() + plugin.getLocale().getMessage("general.word.page") + " " + (page + 3)); + arrow.setAmount(page + 3); + setButton(7, arrow, + (event) -> { + page += 2; + updateTitle(); + }); } if (page + 2 < maxPage) { - createButton(8, Material.ARROW, "&c" + plugin.getLocale().getMessage("general.word.page") + " " + (page + 4)); - registerClickable(8, ((player1, inventory1, cursor, slot, type) -> { - page += 3; - updateTitle(); - })); - inventory.getItem(8).setAmount(page + 4); + ItemStack arrow = GuiUtils.createButtonItem(LegacyMaterials.ARROW, + ChatColor.RED.toString() + plugin.getLocale().getMessage("general.word.page") + " " + (page + 4)); + arrow.setAmount(page + 4); + setButton(8, arrow, + (event) -> { + page += 3; + updateTitle(); + }); } List favorites = plugin.getPlayerManager().getPlayer(player).getFavorites(); @@ -154,16 +188,14 @@ public class GUIHeads extends AbstractGUI { if (head.getName() == null) continue; boolean free = player.hasPermission("epicheads.bypasscost") - || (Setting.FREE_IN_CREATIVE.getBoolean() && player.getGameMode() == GameMode.CREATIVE); + || (Settings.FREE_IN_CREATIVE.getBoolean() && player.getGameMode() == GameMode.CREATIVE); ItemStack item = head.asItemStack(favorites.contains(head.getURL()), free); - inventory.setItem(i + 9, item); + double cost = Settings.HEAD_COST.getDouble(); - double cost = Setting.HEAD_COST.getDouble(); - - registerClickable(i + 9, ((player1, inventory1, cursor, slot, type) -> { - if (type == ClickType.SHIFT_LEFT || type == ClickType.SHIFT_RIGHT) { + setButton(i + 9, item, (event) -> { + if (event.clickType == ClickType.SHIFT_LEFT || event.clickType == ClickType.SHIFT_RIGHT) { EPlayer ePlayer = plugin.getPlayerManager().getPlayer(player); if (!ePlayer.getFavorites().contains(head.getURL())) ePlayer.addFavorite(head.getURL()); @@ -179,10 +211,9 @@ public class GUIHeads extends AbstractGUI { if (!free) { - if (plugin.getEconomy() != null) { - Economy economy = plugin.getEconomy(); - if (economy.hasBalance(player, cost)) { - economy.withdrawBalance(player, cost); + if (EconomyManager.isEnabled()) { + if (EconomyManager.hasBalance(player, cost)) { + EconomyManager.withdrawBalance(player, cost); } else { player.sendMessage(plugin.getLocale().getMessage("event.buyhead.cannotafford").getMessage()); return; @@ -192,51 +223,19 @@ public class GUIHeads extends AbstractGUI { return; } } - player.getInventory().addItem(item); - })); + }); } } - @Override - protected void registerClickables() { - registerClickable(4, ((player1, inventory1, cursor, slot, type) -> - new GUIOverview(plugin, player))); - - registerClickable(3, ((player1, inventory1, cursor, slot, type) -> - doSearch(player1))); - - if (heads.size() > 1) { - registerClickable(5, ((player1, inventory1, cursor, slot, type) -> { - - plugin.getLocale().getMessage("general.search.refine").sendPrefixedMessage(player); - AbstractChatConfirm abstractChatConfirm = new AbstractChatConfirm(player, event -> { - this.page = 0; - this.heads = this.heads.stream().filter(head -> head.getName().toLowerCase() - .contains(event.getMessage().toLowerCase())).collect(Collectors.toList()); - if (query == null) - this.query = event.getMessage(); - else - this.query += ", " + event.getMessage(); - }); - abstractChatConfirm.setOnClose(this::updateTitle); - })); - } - } - - @Override - protected void registerOnCloses() { - - } - - public static void doSearch(Player player) { - EpicHeads.getInstance().getLocale().getMessage("general.search.global").sendPrefixedMessage(player); - new AbstractChatConfirm(player, event -> { - List heads = EpicHeads.getInstance().getHeadManager().getHeads().stream() + public static void doSearch(EpicHeads plugin, Player player) { + plugin.getLocale().getMessage("general.search.global").sendPrefixedMessage(player); + ChatPrompt.showPrompt(plugin, player, event -> { + List heads = plugin.getHeadManager().getHeads().stream() .filter(head -> head.getName().toLowerCase().contains(event.getMessage().toLowerCase())) .collect(Collectors.toList()); Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHeads.getInstance(), () -> - new GUIHeads(EpicHeads.getInstance(), player, event.getMessage(), QueryTypes.SEARCH, heads), 0L); + plugin.getGuiManager().showGUI(player, new GUIHeads(plugin, player, event.getMessage(), QueryTypes.SEARCH, heads)), 0L); }); } diff --git a/src/main/java/com/songoda/epicheads/gui/GUIOverview.java b/src/main/java/com/songoda/epicheads/gui/GUIOverview.java index 16e5213..27024a1 100644 --- a/src/main/java/com/songoda/epicheads/gui/GUIOverview.java +++ b/src/main/java/com/songoda/epicheads/gui/GUIOverview.java @@ -1,13 +1,13 @@ package com.songoda.epicheads.gui; +import com.songoda.core.compatibility.LegacyMaterials; +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiUtils; import com.songoda.epicheads.EpicHeads; import com.songoda.epicheads.head.Category; import com.songoda.epicheads.head.Head; +import com.songoda.epicheads.settings.Settings; import com.songoda.epicheads.utils.Methods; -import com.songoda.epicheads.utils.ServerVersion; -import com.songoda.epicheads.utils.gui.AbstractGUI; -import com.songoda.epicheads.utils.settings.Setting; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -16,54 +16,43 @@ import java.util.List; import java.util.Random; import java.util.stream.Collectors; -public class GUIOverview extends AbstractGUI { - - private final EpicHeads plugin; - private int page = 0; - - public GUIOverview(EpicHeads plugin, Player player) { - super(player); - this.plugin = plugin; +public class GUIOverview extends Gui { - init(plugin.getLocale().getMessage("gui.overview.title") + private final EpicHeads plugin; + private final Player player; + private int page = 0; + + public GUIOverview(EpicHeads plugin, Player player) { + this.plugin = plugin; + this.player = player; + + this.setDefaultItem(null); + this.setRows(5); + this.setTitle(plugin.getLocale().getMessage("gui.overview.title") .processPlaceholder("count", plugin.getHeadManager().getHeads().size()) - .getMessage(), 45); + .getMessage()); + showPage(); } - @Override - protected void constructGUI() { - inventory.clear(); - resetClickables(); - registerClickables(); - + void showPage() { ArrayList lore = new ArrayList<>(); String[] parts = plugin.getLocale().getMessage("gui.overview.favoriteslore").getMessage().split("\\|"); for (String line : parts) lore.add(Methods.formatText(line)); - createButton(4, Material.GOLDEN_APPLE, plugin.getLocale().getMessage("gui.overview.viewfavorites") - .getMessage(), lore); + setButton(4, GuiUtils.createButtonItem(LegacyMaterials.GOLDEN_APPLE, + plugin.getLocale().getMessage("gui.overview.viewfavorites").getMessage(), lore), + (event) -> plugin.getGuiManager().showGUI(player, new GUIHeads(plugin, player, null, GUIHeads.QueryTypes.FAVORITES, + plugin.getPlayerManager().getPlayer(player).getFavoritesAsHeads()))); - inventory.setItem(0, Methods.getBackgroundGlass(true)); - inventory.setItem(1, Methods.getBackgroundGlass(true)); - inventory.setItem(9, Methods.getBackgroundGlass(true)); - inventory.setItem(7, Methods.getBackgroundGlass(true)); - inventory.setItem(8, Methods.getBackgroundGlass(true)); - inventory.setItem(17, Methods.getBackgroundGlass(true)); + ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial()); + ItemStack glass3 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_3.getMaterial()); - inventory.setItem(27, Methods.getBackgroundGlass(true)); - inventory.setItem(36, Methods.getBackgroundGlass(true)); - inventory.setItem(37, Methods.getBackgroundGlass(true)); - - inventory.setItem(35, Methods.getBackgroundGlass(true)); - inventory.setItem(43, Methods.getBackgroundGlass(true)); - inventory.setItem(44, Methods.getBackgroundGlass(true)); - - inventory.setItem(2, Methods.getBackgroundGlass(false)); - inventory.setItem(6, Methods.getBackgroundGlass(false)); - inventory.setItem(38, Methods.getBackgroundGlass(false)); - inventory.setItem(42, Methods.getBackgroundGlass(false)); + GuiUtils.mirrorFill(this, 0, 0, true, true, glass2); + GuiUtils.mirrorFill(this, 1, 0, true, true, glass2); + GuiUtils.mirrorFill(this, 0, 1, true, true, glass2); + GuiUtils.mirrorFill(this, 0, 2, true, true, glass3); int numTemplates = plugin.getHeadManager().getCategories().size(); int maxPage = (int) Math.floor(numTemplates / 21.0); @@ -71,23 +60,22 @@ public class GUIOverview extends AbstractGUI { List categories = plugin.getHeadManager().getCategories().stream().skip(page * 21).limit(21) .collect(Collectors.toList()); - if (page != 0) { - createButton(37, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous") - .getMessage()); - registerClickable(37, ((player1, inventory1, cursor, slot, type) -> { - page --; - constructGUI(); - })); - } + if (page != 0) + setButton(37, GuiUtils.createButtonItem(LegacyMaterials.ARROW, + plugin.getLocale().getMessage("gui.general.previous").getMessage()), + (event) -> { + page--; + showPage(); + }); + + if (page != maxPage) + setButton(43, GuiUtils.createButtonItem(LegacyMaterials.ARROW, + plugin.getLocale().getMessage("gui.general.next").getMessage()), + (event) -> { + page++; + showPage(); + }); - if (page != maxPage) { - createButton(43, Material.ARROW, plugin.getLocale().getMessage("gui.general.next") - .getMessage()); - registerClickable(43, ((player1, inventory1, cursor, slot, type) -> { - page ++; - constructGUI(); - })); - } int add = 0; for (int i = 0; i < categories.size(); i++) { if (i + add == 7 || i + add == 16) add = add + 2; @@ -100,8 +88,7 @@ public class GUIOverview extends AbstractGUI { if (!player.hasPermission("epicheads.category." + category.getName().replace(" ", "_"))) continue; - createButton(i + 10 + add, Methods.addTexture(new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) - ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3), firstHead.getURL()), + setButton(i + 10 + add, GuiUtils.createButtonItem(Methods.addTexture(new ItemStack(LegacyMaterials.PLAYER_HEAD.getMaterial(), 1, (byte) 3), firstHead.getURL()), plugin.getLocale().getMessage("gui.overview.headname") .processPlaceholder("name", Color.getRandomColor() + category.getName()) .getMessage(), @@ -109,53 +96,35 @@ public class GUIOverview extends AbstractGUI { .processPlaceholder("pack", firstHead.getPack()).getMessage() : plugin.getLocale().getMessage("gui.overview.headlore") .processPlaceholder("count", String.format("%,d", category.getCount())) - .getMessage()); - - registerClickable(i + 10 + add, ((player1, inventory1, cursor, slot, type) -> - new GUIHeads(plugin, player, category.isLatestPack() ? category.getName() : null, - category.isLatestPack() ? GUIHeads.QueryTypes.PACK : GUIHeads.QueryTypes.CATEGORY, heads))); + .getMessage()), + (event) -> + plugin.getGuiManager().showGUI(player, new GUIHeads(plugin, player, category.isLatestPack() ? category.getName() : null, + category.isLatestPack() ? GUIHeads.QueryTypes.PACK : GUIHeads.QueryTypes.CATEGORY, heads))); } - createButton(Setting.DISCORD.getBoolean() ? 39 : 40, Material.COMPASS, plugin.getLocale().getMessage("gui.overview.search").getMessage()); + setButton(Settings.DISCORD.getBoolean() ? 39 : 40, GuiUtils.createButtonItem(LegacyMaterials.COMPASS, + plugin.getLocale().getMessage("gui.overview.search").getMessage()), + (event) -> GUIHeads.doSearch(plugin, event.player)); - if (Setting.DISCORD.getBoolean()) { + if (Settings.DISCORD.getBoolean()) { ArrayList lore2 = new ArrayList<>(); String[] parts2 = plugin.getLocale().getMessage("gui.overview.discordlore") .getMessage().split("\\|"); for (String line : parts2) lore2.add(Methods.formatText(line)); - createButton(41, Methods.addTexture(new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) - ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3), + setButton(41, GuiUtils.createButtonItem(Methods.addTexture(new ItemStack(LegacyMaterials.PLAYER_HEAD.getMaterial(), 1, (byte) 3), "a3b183b148b9b4e2b158334aff3b5bb6c2c2dbbc4d67f76a7be856687a2b623"), plugin.getLocale().getMessage("gui.overview.discord").getMessage(), - lore2); + lore2), + (event) -> { + plugin.getLocale().newMessage("&9https://discord.gg/A9TRJQb").sendPrefixedMessage(player); + player.closeInventory(); + }); } } - @Override - protected void registerClickables() { - registerClickable(4, ((player1, inventory1, cursor, slot, type) -> - new GUIHeads(plugin, player, null, GUIHeads.QueryTypes.FAVORITES, - plugin.getPlayerManager().getPlayer(player).getFavoritesAsHeads()))); - - registerClickable(Setting.DISCORD.getBoolean() ? 39 : 40, ((player1, inventory1, cursor, slot, type) -> - GUIHeads.doSearch(player1))); - - if (Setting.DISCORD.getBoolean()) { - registerClickable(41, ((player1, inventory1, cursor, slot, type) -> { - plugin.getLocale().newMessage("&9https://discord.gg/A9TRJQb").sendPrefixedMessage(player); - player.closeInventory(); - })); - } - } - - @Override - protected void registerOnCloses() { - - } - public enum Color { C9("&9&l"), CA("&a&l"), diff --git a/src/main/java/com/songoda/epicheads/head/Head.java b/src/main/java/com/songoda/epicheads/head/Head.java index 543f69a..ea26808 100644 --- a/src/main/java/com/songoda/epicheads/head/Head.java +++ b/src/main/java/com/songoda/epicheads/head/Head.java @@ -1,11 +1,10 @@ package com.songoda.epicheads.head; +import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.epicheads.EpicHeads; +import com.songoda.epicheads.settings.Settings; import com.songoda.epicheads.utils.Methods; -import com.songoda.epicheads.utils.ServerVersion; -import com.songoda.epicheads.utils.settings.Setting; -import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -39,7 +38,9 @@ public class Head { return name; } - public String getPack() { return pack; } + public String getPack() { + return pack; + } public String getURL() { return URL; @@ -57,14 +58,15 @@ public class Head { return asItemStack(false, false); } - public ItemStack asItemStack(boolean favorite) { return asItemStack(favorite, false); } + public ItemStack asItemStack(boolean favorite) { + return asItemStack(favorite, false); + } public ItemStack asItemStack(boolean favorite, boolean free) { EpicHeads plugin = EpicHeads.getInstance(); - ItemStack item = Methods.addTexture(new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) - ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3), this.URL); + ItemStack item = Methods.addTexture(new ItemStack(LegacyMaterials.PLAYER_HEAD.getMaterial(), 1, (byte) 3), this.URL); - double cost = Setting.HEAD_COST.getDouble(); + double cost = Settings.HEAD_COST.getDouble(); ItemMeta meta = item.getItemMeta(); meta.setDisplayName(Methods.formatText((favorite ? "&6⭐ " : "") + "&9" + name)); List lore = new ArrayList<>(); diff --git a/src/main/java/com/songoda/epicheads/listeners/DeathListeners.java b/src/main/java/com/songoda/epicheads/listeners/DeathListeners.java index afc1a13..3f63ed3 100644 --- a/src/main/java/com/songoda/epicheads/listeners/DeathListeners.java +++ b/src/main/java/com/songoda/epicheads/listeners/DeathListeners.java @@ -1,12 +1,11 @@ package com.songoda.epicheads.listeners; +import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.epicheads.EpicHeads; import com.songoda.epicheads.head.Head; +import com.songoda.epicheads.settings.Settings; import com.songoda.epicheads.utils.HeadType; import com.songoda.epicheads.utils.Methods; -import com.songoda.epicheads.utils.ServerVersion; -import com.songoda.epicheads.utils.settings.Setting; -import org.bukkit.Material; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -29,19 +28,18 @@ public class DeathListeners implements Listener { @EventHandler public void onDeath(EntityDeathEvent event) { - double ch = Double.parseDouble(Setting.DROP_CHANCE.getString().replace("%", "")); + double ch = Double.parseDouble(Settings.DROP_CHANCE.getString().replace("%", "")); double rand = Math.random() * 100; if (rand - ch < 0 || ch == 100) { ItemStack itemNew; if (event.getEntity() instanceof Player) { - if (!Setting.DROP_PLAYER_HEADS.getBoolean()) return; + if (!Settings.DROP_PLAYER_HEADS.getBoolean()) return; String encodededStr = Methods.getEncodedTexture((Player) event.getEntity()); if (encodededStr == null) { - itemNew = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) - ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3); + itemNew = new ItemStack(LegacyMaterials.PLAYER_HEAD.getMaterial(), 1, (byte) 3); ItemMeta meta = itemNew.getItemMeta(); meta.setDisplayName(Methods.formatText("&9" + ((Player) event.getEntity()).getDisplayName())); @@ -56,7 +54,7 @@ public class DeathListeners implements Listener { itemNew = optional.get().asItemStack(); } } else { - if (!Setting.DROP_MOB_HEADS.getBoolean() || event.getEntity() instanceof ArmorStand) return; + if (!Settings.DROP_MOB_HEADS.getBoolean() || event.getEntity() instanceof ArmorStand) return; Head head = new Head(-1, Methods.formatText(event.getEntity().getType().name().toLowerCase() .replace("_", " "), true), diff --git a/src/main/java/com/songoda/epicheads/listeners/ItemListeners.java b/src/main/java/com/songoda/epicheads/listeners/ItemListeners.java index 1214f83..13818aa 100644 --- a/src/main/java/com/songoda/epicheads/listeners/ItemListeners.java +++ b/src/main/java/com/songoda/epicheads/listeners/ItemListeners.java @@ -1,10 +1,9 @@ package com.songoda.epicheads.listeners; +import com.songoda.core.compatibility.LegacyMaterials; import com.songoda.epicheads.EpicHeads; import com.songoda.epicheads.head.Head; import com.songoda.epicheads.utils.Methods; -import com.songoda.epicheads.utils.ServerVersion; -import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -27,7 +26,7 @@ public class ItemListeners implements Listener { public void itemSpawnEvent(ItemSpawnEvent event) { ItemStack item = event.getEntity().getItemStack(); - if (item.getType() != (plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"))) return; + if (item.getType() != LegacyMaterials.PLAYER_HEAD.getMaterial()) return; String encodededStr = Methods.getEncodedTexture(item); diff --git a/src/main/java/com/songoda/epicheads/settings/Settings.java b/src/main/java/com/songoda/epicheads/settings/Settings.java new file mode 100644 index 0000000..7361439 --- /dev/null +++ b/src/main/java/com/songoda/epicheads/settings/Settings.java @@ -0,0 +1,114 @@ +package com.songoda.epicheads.settings; + +import com.songoda.core.compatibility.LegacyMaterials; +import com.songoda.core.compatibility.ServerVersion; +import com.songoda.core.configuration.Config; +import com.songoda.core.configuration.ConfigSetting; +import com.songoda.core.hooks.EconomyManager; +import com.songoda.epicheads.EpicHeads; + +import java.util.Arrays; +import java.util.stream.Collectors; + +/** + * Static config node accessors + */ +public class Settings { + + static final Config config = EpicHeads.getInstance().getConfig().getCoreConfig(); + + public static final ConfigSetting AUTOSAVE = new ConfigSetting(config, "Main.Auto Save Interval In Seconds", 15, + "The amount of time in between saving to file.", + "This is purely a safety function to prevent against unplanned crashes or", + "restarts. With that said it is advised to keep this enabled.", + "If however you enjoy living on the edge, feel free to turn it off."); + + public static final ConfigSetting DISCORD = new ConfigSetting(config, "Main.Show Discord Button", true, + "This is the discord button displayed in the main GUI", + "Clicking this button will bring you to a discord where you can", + "add or remove heads to the global library this plugin uses.", + "AS well as get updates on future releases and features."); + + public static final ConfigSetting FREE_IN_CREATIVE = new ConfigSetting(config, "Main.Heads Free In Creative Mode", false, + "Enabling this will make it so that a player can get all heads", + "for free as long as they are in the creative game mode."); + + public static final ConfigSetting DROP_MOB_HEADS = new ConfigSetting(config, "Main.Drop Mob Heads", true, + "Should heads drop after a monster is killed?"); + + public static final ConfigSetting DROP_PLAYER_HEADS = new ConfigSetting(config, "Main.Drop Player Heads", true, + "Should a players drop their head on death?"); + + public static final ConfigSetting DROP_CHANCE = new ConfigSetting(config, "Main.Head Drop Chance", "25%", + "When a player or monster is killed what should be", + "the chance that their head drops?"); + + public static final ConfigSetting DISABLED_HEADS = new ConfigSetting(config, "Main.Disabled Global Heads", Arrays.asList(34567, 34568, 34569), + "These are head ID's from the global database that are disabled.", + "By default this is filled with non existent ID's."); + + public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Economy.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 HEAD_COST = new ConfigSetting(config, "Economy.Head Cost", 24.99, + "The cost the of the head. If you wan't to use PlayerPoints", + "or item tokens you need to use whole numbers."); + + public static final ConfigSetting ITEM_TOKEN_TYPE = new ConfigSetting(config, "Economy.Item.Type", ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? "PLAYER_HEAD" : "SKULL_ITEM", + "Which item material type should be used?", + "You can use any of the materials from the following link:", + "https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html"); + + public static final ConfigSetting ITEM_TOKEN_ID = new ConfigSetting(config, "Economy.Item.Head ID", 14395, + "If a player head is used as the token which head ID should be used?", + "This can be any head from the global database."); + + public static final ConfigSetting ITEM_TOKEN_NAME = new ConfigSetting(config, "Economy.Item.Name", "&6Player Head Token", + "What should the token be named?"); + + public static final ConfigSetting ITEM_TOKEN_LORE = new ConfigSetting(config, "Economy.Item.Lore", Arrays.asList("&8Use in /Heads!"), + "What should the tokens lore be?"); + + 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."); + + public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(config, "Interfaces.Glass Type 1", "GRAY_STAINED_GLASS_PANE"); + public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(config, "Interfaces.Glass Type 2", "BLUE_STAINED_GLASS_PANE"); + public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(config, "Interfaces.Glass Type 3", "LIGHT_BLUE_STAINED_GLASS_PANE"); + + /** + * 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 glass pane settings + int color; + if ((color = GLASS_TYPE_1.getInt(-1)) != -1) { + config.set(GLASS_TYPE_1.getKey(), LegacyMaterials.getGlassPaneColor(color).name()); + } + if ((color = GLASS_TYPE_2.getInt(-1)) != -1) { + config.set(GLASS_TYPE_2.getKey(), LegacyMaterials.getGlassPaneColor(color).name()); + } + if ((color = GLASS_TYPE_3.getInt(-1)) != -1) { + config.set(GLASS_TYPE_3.getKey(), LegacyMaterials.getGlassPaneColor(color).name()); + } + + // convert economy settings + if (config.getBoolean("Economy.Use Vault Economy") && EconomyManager.getManager().isEnabled("Vault")) { + config.set("Economy.Economy", "Vault"); + } else if (config.getBoolean("Economy.Use Reserve Economy") && EconomyManager.getManager().isEnabled("Reserve")) { + config.set("Economy.Economy", "Reserve"); + } else if (config.getBoolean("Economy.Use Player Points Economy") && EconomyManager.getManager().isEnabled("PlayerPoints")) { + config.set("Economy.Economy", "PlayerPoints"); + } else if (config.getBoolean("Economy.Use Item Economy")) { + config.set("Economy.Economy", "Item"); + } + + config.saveChanges(); + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicheads/utils/AbstractChatConfirm.java b/src/main/java/com/songoda/epicheads/utils/AbstractChatConfirm.java deleted file mode 100644 index ca97dc7..0000000 --- a/src/main/java/com/songoda/epicheads/utils/AbstractChatConfirm.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.songoda.epicheads.utils; - -import com.songoda.epicheads.EpicHeads; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class AbstractChatConfirm implements Listener { - - private static final List registered = new ArrayList<>(); - - private final Player player; - private final ChatConfirmHandler handler; - - private OnClose onClose = null; - - public AbstractChatConfirm(Player player, ChatConfirmHandler hander) { - this.player = player; - this.handler = hander; - player.closeInventory(); - initializeListeners(EpicHeads.getInstance()); - registered.add(player.getUniqueId()); - } - - private Listener listener; - - public void initializeListeners(JavaPlugin plugin) { - - this.listener = new Listener() { - @EventHandler - public void onChat(AsyncPlayerChatEvent event) { - Player player = event.getPlayer(); - if (!AbstractChatConfirm.isRegistered(player)) return; - - AbstractChatConfirm.unregister(player); - event.setCancelled(true); - - ChatConfirmEvent chatConfirmEvent = new ChatConfirmEvent(player, event.getMessage()); - - handler.onChat(chatConfirmEvent); - - if (onClose != null) { - Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHeads.getInstance(), () -> - onClose.onClose(), 0L); - } - HandlerList.unregisterAll(listener); - } - }; - - - Bukkit.getPluginManager().registerEvents(listener, EpicHeads.getInstance()); - } - - public static boolean isRegistered(Player player) { - return registered.contains(player.getUniqueId()); - } - - public static boolean unregister(Player player) { - return registered.remove(player.getUniqueId()); - } - - public interface ChatConfirmHandler { - void onChat(ChatConfirmEvent event); - } - - public void setOnClose(OnClose onClose) { - this.onClose = onClose; - } - - public interface OnClose { - void onClose(); - } - - public class ChatConfirmEvent { - - private final Player player; - private final String message; - - public ChatConfirmEvent(Player player, String message) { - this.player = player; - this.message = message; - } - - public Player getPlayer() { - return player; - } - - public String getMessage() { - return message; - } - } - -} diff --git a/src/main/java/com/songoda/epicheads/economy/ItemEconomy.java b/src/main/java/com/songoda/epicheads/utils/ItemEconomy.java similarity index 88% rename from src/main/java/com/songoda/epicheads/economy/ItemEconomy.java rename to src/main/java/com/songoda/epicheads/utils/ItemEconomy.java index a8e604e..00ab604 100644 --- a/src/main/java/com/songoda/epicheads/economy/ItemEconomy.java +++ b/src/main/java/com/songoda/epicheads/utils/ItemEconomy.java @@ -1,10 +1,11 @@ package com.songoda.epicheads.economy; +import com.songoda.core.hooks.economies.Economy; import com.songoda.epicheads.utils.Methods; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.ItemStack; -public class ItemEconomy implements Economy { +public class ItemEconomy extends Economy { public boolean isItem(ItemStack itemStack) { @@ -62,4 +63,14 @@ public class ItemEconomy implements Economy { public boolean deposit(OfflinePlayer player, double amount) { return false; } + + @Override + public String getName() { + return "Item"; + } + + @Override + public boolean isEnabled() { + return false; + } } diff --git a/src/main/java/com/songoda/epicheads/utils/Methods.java b/src/main/java/com/songoda/epicheads/utils/Methods.java index c4a39bb..954b8dd 100644 --- a/src/main/java/com/songoda/epicheads/utils/Methods.java +++ b/src/main/java/com/songoda/epicheads/utils/Methods.java @@ -2,8 +2,9 @@ package com.songoda.epicheads.utils; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; +import com.songoda.core.compatibility.ServerVersion; import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.utils.settings.Setting; +import com.songoda.epicheads.settings.Settings; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -91,20 +92,20 @@ public class Methods { } public static ItemStack createToken(int amount) { - ItemStack itemStack = new ItemStack(Material.valueOf(Setting.ITEM_TOKEN_TYPE.getString())); + ItemStack itemStack = new ItemStack(Material.valueOf(Settings.ITEM_TOKEN_TYPE.getString())); - if (itemStack.getType() == (EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) + if (itemStack.getType() == (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"))) { itemStack = EpicHeads.getInstance().getHeadManager().getHeads().stream() - .filter(head -> head.getId() == Setting.ITEM_TOKEN_ID.getInt()) + .filter(head -> head.getId() == Settings.ITEM_TOKEN_ID.getInt()) .findFirst().get().asItemStack(); } itemStack.setAmount(amount); ItemMeta meta = itemStack.getItemMeta(); - meta.setDisplayName(formatText(Setting.ITEM_TOKEN_NAME.getString())); + meta.setDisplayName(formatText(Settings.ITEM_TOKEN_NAME.getString())); List lore = new ArrayList<>(); - for (String line : Setting.ITEM_TOKEN_LORE.getStringList()) + for (String line : Settings.ITEM_TOKEN_LORE.getStringList()) if (!line.equals("")) lore.add(formatText(line)); if (lore != null) meta.setLore(lore); @@ -112,36 +113,6 @@ public class Methods { return itemStack; } - public static ItemStack getGlass() { - EpicHeads instance = EpicHeads.getInstance(); - return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1")); - } - - public static ItemStack getBackgroundGlass(boolean type) { - EpicHeads instance = EpicHeads.getInstance(); - if (type) - return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2")); - else - return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3")); - } - - private static ItemStack getGlass(Boolean rainbow, int type) { - int randomNum = 1 + (int) (Math.random() * 6); - ItemStack glass; - if (rainbow) { - glass = new ItemStack(EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? - Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum); - } else { - glass = new ItemStack(EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? - Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type); - } - ItemMeta glassmeta = glass.getItemMeta(); - glassmeta.setDisplayName("§l"); - glass.setItemMeta(glassmeta); - return glass; - } - - public static String formatText(String text) { if (text == null || text.equals("")) return ""; @@ -159,7 +130,7 @@ public class Methods { public static String formatTitle(String text) { if (text == null || text.equals("")) return ""; - if (!EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) { + if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) { if (text.length() > 31) text = text.substring(0, 29) + "..."; } diff --git a/src/main/java/com/songoda/epicheads/utils/ServerVersion.java b/src/main/java/com/songoda/epicheads/utils/ServerVersion.java deleted file mode 100644 index 6add908..0000000 --- a/src/main/java/com/songoda/epicheads/utils/ServerVersion.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.songoda.epicheads.utils; - -public enum ServerVersion { - - UNKNOWN("unknown_server_version"), - V1_7("org.bukkit.craftbukkit.v1_7"), - V1_8("org.bukkit.craftbukkit.v1_8"), - V1_9("org.bukkit.craftbukkit.v1_9"), - V1_10("org.bukkit.craftbukkit.v1_10"), - V1_11("org.bukkit.craftbukkit.v1_11"), - V1_12("org.bukkit.craftbukkit.v1_12"), - V1_13("org.bukkit.craftbukkit.v1_13"), - V1_14("org.bukkit.craftbukkit.v1_14"); - - - private final String packagePrefix; - - private ServerVersion(String packagePrefix) { - this.packagePrefix = packagePrefix; - } - - public static ServerVersion fromPackageName(String packageName) { - for (ServerVersion version : values()) - if (packageName.startsWith(version.packagePrefix)) return version; - return ServerVersion.UNKNOWN; - } -} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicheads/utils/gui/AbstractGUI.java b/src/main/java/com/songoda/epicheads/utils/gui/AbstractGUI.java deleted file mode 100644 index 4c2d9e0..0000000 --- a/src/main/java/com/songoda/epicheads/utils/gui/AbstractGUI.java +++ /dev/null @@ -1,245 +0,0 @@ -package com.songoda.epicheads.utils.gui; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.utils.Methods; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public abstract class AbstractGUI implements Listener { - - private static boolean listenersInitialized = false; - protected final Player player; - protected Inventory inventory = null; - protected String setTitle = null; - protected boolean cancelBottom = false; - private Map clickables = new HashMap<>(); - private List onCloses = new ArrayList<>(); - private Map draggableRanges = new HashMap<>(); - - public AbstractGUI(Player player) { - this.player = player; - } - - public static void initializeListeners(JavaPlugin plugin) { - if (listenersInitialized) return; - - Bukkit.getPluginManager().registerEvents(new Listener() { - @EventHandler - public void onClickGUI(InventoryClickEvent event) { - Inventory inventory = event.getClickedInventory(); - if (inventory == null) return; - AbstractGUI gui = getGUIFromInventory(inventory); - Player player = (Player) event.getWhoClicked(); - - boolean bottom = false; - - InventoryType type = event.getClickedInventory().getType(); - if (type != InventoryType.CHEST && type != InventoryType.PLAYER) return; - - if (gui == null && event.getWhoClicked().getOpenInventory().getTopInventory() != null) { - Inventory top = event.getWhoClicked().getOpenInventory().getTopInventory(); - gui = getGUIFromInventory(top); - - if (gui != null && gui.cancelBottom) event.setCancelled(true); - bottom = true; - } - - if (gui == null) return; - - if (!bottom) event.setCancelled(true); - - if (!gui.draggableRanges.isEmpty() && !bottom) { - for (Map.Entry entry : gui.draggableRanges.entrySet()) { - Range range = entry.getKey(); - if (range.getMax() == range.getMin() && event.getSlot() == range.getMin() - || event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) { - event.setCancelled(!entry.getValue()); - if (!entry.getValue()) break; - } - } - } - - Map entries = new HashMap<>(gui.clickables); - - for (Map.Entry entry : entries.entrySet()) { - Range range = entry.getKey(); - if (range.isBottom() && !bottom || !range.isBottom() && bottom || range.getClickType() != null && range.getClickType() != event.getClick()) - continue; - if (event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) { - entry.getValue().Clickable(player, inventory, event.getCursor(), event.getSlot(), event.getClick()); - player.playSound(player.getLocation(), entry.getKey().getOnClickSound(), 1F, 1F); - } - } - } - - @EventHandler - public void onCloseGUI(InventoryCloseEvent event) { - Inventory inventory = event.getInventory(); - AbstractGUI gui = getGUIFromInventory(inventory); - - if (gui == null || gui.inventory == null) return; - - for (OnClose onClose : gui.onCloses) { - onClose.OnClose((Player) event.getPlayer(), inventory); - } - gui.destory(); - } - - private AbstractGUI getGUIFromInventory(Inventory inventory) { - if (inventory.getHolder() == null) return null; - InventoryHolder holder = inventory.getHolder(); - if (!(holder instanceof GUIHolder)) return null; - - return ((AbstractGUI.GUIHolder) holder).getGUI(); - } - }, plugin); - listenersInitialized = true; - } - - public void init(String title, int slots) { - if (inventory == null - || inventory.getSize() != slots - || Methods.formatTitle(title) != player.getOpenInventory().getTitle()) { - this.inventory = Bukkit.getServer().createInventory(new GUIHolder(), slots, Methods.formatTitle(title)); - this.setTitle = Methods.formatTitle(title); - if (this.clickables.size() == 0) - registerClickables(); - if (this.onCloses.size() == 0) - registerOnCloses(); - } - constructGUI(); - initializeListeners(EpicHeads.getInstance()); - player.openInventory(inventory); - } - - private void destory() { - onCloses.clear(); - clickables.clear(); - draggableRanges.clear(); - } - - protected abstract void constructGUI(); - - protected void addDraggable(Range range, boolean option) { - this.draggableRanges.put(range, option); - } - - protected void removeDraggable() { - this.draggableRanges.clear(); - } - - protected abstract void registerClickables(); - - protected abstract void registerOnCloses(); - - protected ItemStack createButton(int slot, Inventory inventory, ItemStack item, String name, String... lore) { - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); - if (lore != null && lore.length != 0) { - List newLore = new ArrayList<>(); - for (String line : lore) newLore.add(ChatColor.translateAlternateColorCodes('&', line)); - meta.setLore(newLore); - } - item.setItemMeta(meta); - inventory.setItem(slot, item); - return item; - } - - protected ItemStack createButton(int slot, ItemStack item, String name, ArrayList lore) { - return createButton(slot, inventory, item, name, lore.toArray(new String[0])); - } - - - protected ItemStack createButton(int slot, ItemStack item, String name, String... lore) { - return createButton(slot, inventory, item, name, lore); - } - - protected ItemStack createButton(int slot, Object item, String name, String... lore) { - if (item instanceof ItemStack) - return createButton(slot, inventory, (ItemStack)item, name, lore); - else - return createButton(slot, inventory, (Material)item, name, lore); - } - - protected ItemStack createButton(int slot, Inventory inventory, Material material, String name, String... lore) { - return createButton(slot, inventory, new ItemStack(material), name, lore); - } - - protected ItemStack createButton(int slot, Material material, String name, String... lore) { - return createButton(slot, inventory, new ItemStack(material), name, lore); - } - - protected ItemStack createButton(int slot, Material material, String name, ArrayList lore) { - return createButton(slot, material, name, lore.toArray(new String[0])); - } - - protected void registerClickable(int min, int max, ClickType clickType, boolean bottom, Clickable clickable) { - clickables.put(new Range(min, max, clickType, bottom), clickable); - } - - protected void registerClickable(int min, int max, ClickType clickType, Clickable clickable) { - registerClickable(min, max, clickType, false, clickable); - } - - protected void registerClickable(int slot, ClickType clickType, Clickable clickable) { - registerClickable(slot, slot, clickType, false, clickable); - } - - protected void registerClickable(int min, int max, Clickable clickable) { - registerClickable(min, max, null, false, clickable); - } - - protected void registerClickable(int slot, boolean bottom, Clickable clickable) { - registerClickable(slot, slot, null, bottom, clickable); - } - - protected void registerClickable(int slot, Clickable clickable) { - registerClickable(slot, slot, null, false, clickable); - } - - protected void resetClickables() { - clickables.clear(); - } - - protected void registerOnClose(OnClose onClose) { - onCloses.add(onClose); - } - - public Inventory getInventory() { - return inventory; - } - - public class GUIHolder implements InventoryHolder { - - @Override - public Inventory getInventory() { - return inventory; - } - - public AbstractGUI getGUI() { - return AbstractGUI.this; - } - } - - public String getSetTitle() { - return setTitle; - } -} diff --git a/src/main/java/com/songoda/epicheads/utils/gui/Clickable.java b/src/main/java/com/songoda/epicheads/utils/gui/Clickable.java deleted file mode 100644 index e828e24..0000000 --- a/src/main/java/com/songoda/epicheads/utils/gui/Clickable.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.songoda.epicheads.utils.gui; - -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -public interface Clickable { - - void Clickable(Player player, Inventory inventory, ItemStack cursor, int slot, ClickType type); -} diff --git a/src/main/java/com/songoda/epicheads/utils/gui/OnClose.java b/src/main/java/com/songoda/epicheads/utils/gui/OnClose.java deleted file mode 100644 index b377186..0000000 --- a/src/main/java/com/songoda/epicheads/utils/gui/OnClose.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.songoda.epicheads.utils.gui; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -public interface OnClose { - - void OnClose(Player player, Inventory inventory); - -} diff --git a/src/main/java/com/songoda/epicheads/utils/gui/Range.java b/src/main/java/com/songoda/epicheads/utils/gui/Range.java deleted file mode 100644 index 3d65911..0000000 --- a/src/main/java/com/songoda/epicheads/utils/gui/Range.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.songoda.epicheads.utils.gui; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.utils.ServerVersion; -import org.bukkit.Sound; -import org.bukkit.event.inventory.ClickType; - -public class Range { - - private int min; - private int max; - private ClickType clickType; - private boolean bottom; - private Sound onClickSound; - - public Range(int min, int max, ClickType clickType, boolean bottom) { - this.min = min; - this.max = max; - this.clickType = clickType; - this.bottom = bottom; - if (EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) onClickSound = Sound.UI_BUTTON_CLICK; - } - - public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) { - this.min = min; - this.max = max; - this.onClickSound = onClickSound; - this.clickType = clickType; - this.bottom = bottom; - } - - public int getMin() { - return min; - } - - public int getMax() { - return max; - } - - public ClickType getClickType() { - return clickType; - } - - public boolean isBottom() { - return bottom; - } - - public Sound getOnClickSound() { - return onClickSound; - } -} diff --git a/src/main/java/com/songoda/epicheads/utils/locale/Locale.java b/src/main/java/com/songoda/epicheads/utils/locale/Locale.java deleted file mode 100644 index 9546be1..0000000 --- a/src/main/java/com/songoda/epicheads/utils/locale/Locale.java +++ /dev/null @@ -1,302 +0,0 @@ -package com.songoda.epicheads.utils.locale; - -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -/** - * Assists in the utilization of localization files. - * Created to be used by the Songoda Team. - * - * @author Brianna O'Keefe - Songoda - */ -public class Locale { - - private static final List LOCALES = new ArrayList<>(); - private static final Pattern NODE_PATTERN = Pattern.compile("(\\w+(?:\\.{1}\\w+)*)\\s*=\\s*\"(.*)\""); - private static final String FILE_EXTENSION = ".lang"; - private static JavaPlugin plugin; - private static File localeFolder; - - private final Map nodes = new HashMap<>(); - - private static String defaultLocale; - - private File file; - private String name; - - /** - * Instantiate the Locale class for future use - * - * @param name the name of the instantiated language - */ - private Locale(String name) { - if (plugin == null) - return; - - this.name = name; - - String fileName = name + FILE_EXTENSION; - this.file = new File(localeFolder, fileName); - - if (!this.reloadMessages()) return; - - plugin.getLogger().info("Loaded locale \"" + fileName + "\""); - } - - /** - * Initialize the class to load all existing language files and update them. - * This must be called before any other methods in this class as otherwise - * the methods will fail to invoke - * - * @param plugin the plugin instance - * @param defaultLocale the default language - */ - public Locale(JavaPlugin plugin, String defaultLocale) { - - Locale.plugin = plugin; - Locale.localeFolder = new File(plugin.getDataFolder(), "locales/"); - - if (!localeFolder.exists()) localeFolder.mkdirs(); - - //Save the default locale file. - Locale.defaultLocale = defaultLocale; - saveLocale(defaultLocale); - - for (File file : localeFolder.listFiles()) { - String fileName = file.getName(); - if (!fileName.endsWith(FILE_EXTENSION)) continue; - - String name = fileName.substring(0, fileName.lastIndexOf('.')); - - if (name.split("_").length != 2) continue; - if (localeLoaded(name)) continue; - - LOCALES.add(new Locale(name)); - } - } - - /** - * Save a locale file from the InputStream, to the locale folder - * - * @param fileName the name of the file to save - * @return true if the operation was successful, false otherwise - */ - public static boolean saveLocale(String fileName) { - return saveLocale(plugin.getResource(defaultLocale + FILE_EXTENSION), fileName); - } - - - /** - * Save a locale file from the InputStream, to the locale folder - * - * @param in file to save - * @param fileName the name of the file to save - * @return true if the operation was successful, false otherwise - */ - public static boolean saveLocale(InputStream in, String fileName) { - if (!localeFolder.exists()) localeFolder.mkdirs(); - - if (!fileName.endsWith(FILE_EXTENSION)) - fileName = (fileName.lastIndexOf(".") == -1 ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + FILE_EXTENSION; - - File destinationFile = new File(localeFolder, fileName); - if (destinationFile.exists()) - return compareFiles(in, destinationFile); - - try (OutputStream outputStream = new FileOutputStream(destinationFile)) { - copy(in, outputStream); - - fileName = fileName.substring(0, fileName.lastIndexOf('.')); - - if (fileName.split("_").length != 2) return false; - - LOCALES.add(new Locale(fileName)); - if (defaultLocale == null) defaultLocale = fileName; - return true; - } catch (IOException e) { - return false; - } - } - - // Write new changes to existing files, if any at all - private static boolean compareFiles(InputStream in, File existingFile) { - InputStream defaultFile = - in == null ? plugin.getResource((defaultLocale != null ? defaultLocale : "en_US") + FILE_EXTENSION) : in; - - boolean changed = false; - - List defaultLines, existingLines; - try (BufferedReader defaultReader = new BufferedReader(new InputStreamReader(defaultFile)); - BufferedReader existingReader = new BufferedReader(new FileReader(existingFile)); - BufferedWriter writer = new BufferedWriter(new FileWriter(existingFile, true))) { - defaultLines = defaultReader.lines().collect(Collectors.toList()); - existingLines = existingReader.lines().map(s -> s.split("\\s*=")[0]).collect(Collectors.toList()); - - for (String defaultValue : defaultLines) { - if (defaultValue.isEmpty() || defaultValue.startsWith("#")) continue; - - String key = defaultValue.split("\\s*=")[0]; - - if (!existingLines.contains(key)) { - if (!changed) { - writer.newLine(); - writer.newLine(); - // Leave a note alerting the user of the newly added messages. - writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion() + "."); - - // If changes were found outside of the default file leave a note explaining that. - if (in == null) { - writer.newLine(); - writer.write("# These translations were found untranslated, join"); - writer.newLine(); - writer.write("# our translation Discord https://discord.gg/f7fpZEf"); - writer.newLine(); - writer.write("# to request an official update!"); - } - } - - writer.newLine(); - writer.write(defaultValue); - - changed = true; - } - } - if (in != null && !changed) compareFiles(null, existingFile); - } catch (IOException e) { - return false; - } - - return changed; - } - - - /** - * Check whether a locale exists and is registered or not - * - * @param name the whole language tag (i.e. "en_US") - * @return true if it exists - */ - public static boolean localeLoaded(String name) { - for (Locale locale : LOCALES) - if (locale.getName().equals(name)) return true; - return false; - } - - - /** - * Get a locale by its entire proper name (i.e. "en_US") - * - * @param name the full name of the locale - * @return locale of the specified name - */ - public static Locale getLocale(String name) { - for (Locale locale : LOCALES) - if (locale.getName().equalsIgnoreCase(name)) return locale; - return null; - } - - /** - * Clear the previous message cache and load new messages directly from file - * - * @return reload messages from file - */ - public boolean reloadMessages() { - if (!this.file.exists()) { - plugin.getLogger().warning("Could not find file for locale \"" + this.name + "\""); - return false; - } - - this.nodes.clear(); // Clear previous data (if any) - - try (BufferedReader reader = new BufferedReader(new FileReader(file))) { - String line; - for (int lineNumber = 0; (line = reader.readLine()) != null; lineNumber++) { - if (line.trim().isEmpty() || line.startsWith("#") /* Comment */) continue; - - Matcher matcher = NODE_PATTERN.matcher(line); - if (!matcher.find()) { - System.err.println("Invalid locale syntax at (line=" + lineNumber + ")"); - continue; - } - - nodes.put(matcher.group(1), matcher.group(2)); - } - } catch (IOException e) { - e.printStackTrace(); - return false; - } - return true; - } - - /** - * Supply the Message object with the plugins prefix. - * - * @param message message to be applied - * @return applied message - */ - private Message supplyPrefix(Message message) { - return message.setPrefix(this.nodes.getOrDefault("general.nametag.prefix", "[Plugin]")); - } - - /** - * Create a new unsaved Message - * - * @param message the message to create - * @return the created message - */ - public Message newMessage(String message) { - return supplyPrefix(new Message(message)); - } - - /** - * Get a message set for a specific node. - * - * @param node the node to get - * @return the message for the specified node - */ - public Message getMessage(String node) { - return this.getMessageOrDefault(node, node); - } - - /** - * Get a message set for a specific node - * - * @param node the node to get - * @param defaultValue the default value given that a value for the node was not found - * @return the message for the specified node. Default if none found - */ - public Message getMessageOrDefault(String node, String defaultValue) { - return supplyPrefix(new Message(this.nodes.getOrDefault(node, defaultValue))); - } - - /** - * Return the locale name (i.e. "en_US") - * - * @return the locale name - */ - public String getName() { - return name; - } - - private static void copy(InputStream input, OutputStream output) { - int n; - byte[] buffer = new byte[1024 * 4]; - - try { - while ((n = input.read(buffer)) != -1) { - output.write(buffer, 0, n); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - -} diff --git a/src/main/java/com/songoda/epicheads/utils/locale/Message.java b/src/main/java/com/songoda/epicheads/utils/locale/Message.java deleted file mode 100644 index 5041590..0000000 --- a/src/main/java/com/songoda/epicheads/utils/locale/Message.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.songoda.epicheads.utils.locale; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -/** - * The Message object. This holds the message to be sent - * as well as the plugins prefix so that they can both be - * easily manipulated then deployed - */ -public class Message { - - private String prefix = null; - private String message; - - /** - * create a new message - * - * @param message the message text - */ - public Message(String message) { - this.message = message; - } - - /** - * Format and send the held message to a player - * - * @param player player to send the message to - */ - public void sendMessage(Player player) { - player.sendMessage(this.getMessage()); - } - - /** - * Format and send the held message with the - * appended plugin prefix to a player - * - * @param player player to send the message to - */ - public void sendPrefixedMessage(Player player) { - player.sendMessage(this.getPrefixedMessage()); - } - - /** - * Format and send the held message to a player - * - * @param sender command sender to send the message to - */ - public void sendMessage(CommandSender sender) { - sender.sendMessage(this.getMessage()); - } - - /** - * Format and send the held message with the - * appended plugin prefix to a command sender - * - * @param sender command sender to send the message to - */ - public void sendPrefixedMessage(CommandSender sender) { - sender.sendMessage(this.getPrefixedMessage()); - } - - /** - * Format the held message and append the plugins - * prefix - * - * @return the prefixed message - */ - public String getPrefixedMessage() { - return ChatColor.translateAlternateColorCodes('&',(prefix == null ? "" : this.prefix) - + " " + this.message); - } - - /** - * Get and format the held message - * - * @return the message - */ - public String getMessage() { - return ChatColor.translateAlternateColorCodes('&', this.message); - } - - /** - * Get the held message - * - * @return the message - */ - public String getUnformattedMessage() { - return this.message; - } - - /** - * Replace the provided placeholder with the - * provided object - * - * @param placeholder the placeholder to replace - * @param replacement the replacement object - * @return the modified Message - */ - public Message processPlaceholder(String placeholder, Object replacement) { - this.message = message.replace("%" + placeholder + "%", replacement.toString()); - return this; - } - - Message setPrefix(String prefix) { - this.prefix = prefix; - return this; - } - - @Override - public String toString() { - return this.message; - } -} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicheads/utils/settings/Category.java b/src/main/java/com/songoda/epicheads/utils/settings/Category.java deleted file mode 100644 index d72cfdf..0000000 --- a/src/main/java/com/songoda/epicheads/utils/settings/Category.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.songoda.epicheads.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 paterns, change them up then open up a", - "GUI to see how it works."), - - ECONOMY("Settings regarding economy.", - "Only one economy option can be used at a time. If you enable more than", - "one of these the first one will be used."), - - ECONOMY_ITEM("Item token options."), - - SYSTEM("System related settings."); - - private String[] comments; - - - Category(String... comments) { - this.comments = comments; - } - - public String[] getComments() { - return comments; - } -} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicheads/utils/settings/Setting.java b/src/main/java/com/songoda/epicheads/utils/settings/Setting.java deleted file mode 100644 index dab6c92..0000000 --- a/src/main/java/com/songoda/epicheads/utils/settings/Setting.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.songoda.epicheads.utils.settings; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.utils.ServerVersion; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public enum Setting { - - AUTOSAVE("Main.Auto Save Interval In Seconds", 15, - "The amount of time in between saving to file.", - "This is purely a safety function to prevent against unplanned crashes or", - "restarts. With that said it is advised to keep this enabled.", - "If however you enjoy living on the edge, feel free to turn it off."), - - DISCORD("Main.Show Discord Button", true, - "This is the discord button displayed in the main GUI", - "Clicking this button will bring you to a discord where you can", - "add or remove heads to the global library this plugin uses.", - "AS well as get updates on future releases and features."), - - FREE_IN_CREATIVE("Main.Heads Free In Creative Mode", false, - "Enabling this will make it so that a player can get all heads", - "for free as long as they are in the creative game mode."), - - DROP_MOB_HEADS("Main.Drop Mob Heads", true, - "Should heads drop after a monster is killed?"), - - DROP_PLAYER_HEADS("Main.Drop Player Heads", true, - "Should a players drop their head on death?"), - - DROP_CHANCE("Main.Head Drop Chance", "25%", - "When a player or monster is killed what should be", - "the chance that their head drops?"), - - DISABLED_HEADS("Main.Disabled Global Heads", Arrays.asList(34567, 34568, 34569), - "These are head ID's from the global database that are disabled.", - "By default this is filled with non existent ID's."), - - GLASS_TYPE_1("Interfaces.Glass Type 1", 7), - GLASS_TYPE_2("Interfaces.Glass Type 2", 11), - GLASS_TYPE_3("Interfaces.Glass Type 3", 3), - - HEAD_COST("Economy.Head Cost", 24.99, - "The cost the of the head. If you wan't to use PlayerPoints", - "or item tokens you need to use whole numbers."), - - 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?"), - - ITEM_ECONOMY("Economy.Use Item Economy", false, - "Should item tokens be used?"), - - ITEM_TOKEN_TYPE("Economy.Item.Type", EpicHeads.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "PLAYER_HEAD" : "SKULL_ITEM", - "Which item material type should be used?", - "You can use any of the materials from the following link:", - "https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html"), - - ITEM_TOKEN_ID("Economy.Item.Head ID", 14395, - "If a player head is used as the token which head ID should be used?", - "This can be any head from the global database."), - - ITEM_TOKEN_NAME("Economy.Item.Name", "&6Player Head Token", - "What should the token be named?"), - - ITEM_TOKEN_LORE("Economy.Item.Lore", Arrays.asList("&8Use in /Heads!"), - "What should the tokens lore be?"), - - 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 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 getIntegerList() { - return EpicHeads.getInstance().getConfig().getIntegerList(setting); - } - - public List getStringList() { - return EpicHeads.getInstance().getConfig().getStringList(setting); - } - - public boolean getBoolean() { - return EpicHeads.getInstance().getConfig().getBoolean(setting); - } - - public int getInt() { - return EpicHeads.getInstance().getConfig().getInt(setting); - } - - public long getLong() { - return EpicHeads.getInstance().getConfig().getLong(setting); - } - - public String getString() { - return EpicHeads.getInstance().getConfig().getString(setting); - } - - public char getChar() { - return EpicHeads.getInstance().getConfig().getString(setting).charAt(0); - } - - public double getDouble() { - return EpicHeads.getInstance().getConfig().getDouble(setting); - } -} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicheads/utils/settings/SettingsManager.java b/src/main/java/com/songoda/epicheads/utils/settings/SettingsManager.java deleted file mode 100644 index 6837a09..0000000 --- a/src/main/java/com/songoda/epicheads/utils/settings/SettingsManager.java +++ /dev/null @@ -1,311 +0,0 @@ -package com.songoda.epicheads.utils.settings; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.epicheads.utils.Methods; -import com.songoda.epicheads.utils.ServerVersion; -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 EpicHeads plugin; - private Map cat = new HashMap<>(); - private Map current = new HashMap<>(); - - public SettingsManager(EpicHeads 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(EpicHeads.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(plugin.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 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(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); - lore.add(Methods.formatText("&7" + config.getInt(fKey))); - } else if (config.isLong(fKey)) { - item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); - lore.add(Methods.formatText("&7" + config.getLong(fKey))); - } else if (config.isDouble(fKey)) { - item.setType(plugin.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(); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicheads/utils/updateModules/LocaleModule.java b/src/main/java/com/songoda/epicheads/utils/updateModules/LocaleModule.java deleted file mode 100644 index 6a68961..0000000 --- a/src/main/java/com/songoda/epicheads/utils/updateModules/LocaleModule.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.songoda.epicheads.utils.updateModules; - -import com.songoda.epicheads.EpicHeads; -import com.songoda.update.Module; -import com.songoda.update.Plugin; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; - -public class LocaleModule implements Module { - - @Override - public void run(Plugin plugin) { - JSONObject json = plugin.getJson(); - try { - JSONArray files = (JSONArray) json.get("neededFiles"); - for (Object o : files) { - JSONObject file = (JSONObject) o; - - if (file.get("type").equals("locale")) { - InputStream in = new URL((String) file.get("link")).openStream(); - EpicHeads.getInstance().getLocale().saveLocale(in, (String) file.get("name")); - } - } - } catch (IOException e) { - e.printStackTrace(); - } - } -}