diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2ddfa07 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +Copyright (c) 2018 Brianna O’Keefe + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software with minimal restriction, including the rights to use, copy, modify or merge while excluding the rights to publish, (re)distribute, sub-license, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The same distribution rights and limitations above shall similarly apply to any and all source code, and other means that can be used to emulate this work. + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 99f2d2c..a0d776a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -## DeluxeVouchers -DeluxeVouchers is the best solution for vouchers on any server with amazing features updated everyday by me (Marido).
+## EpicVouchers +EpicVouchers is the best solution for vouchers on any server with amazing features updated everyday by me (Songoda).
Quality, performance, and support are my priorities for this resource. Purchase it for $2.99 (sometimes cheaper with sales). > **Note:** Please consider purchasing this resource on Spigot if you want to really support me.
## Developers -Here is an example with built-in methods for developers that want to use the DeluxeVouchers API for their own resources.
+Here is an example with built-in methods for developers that want to use the EpicVouchers API for their own resources.
This is a kinda long example so think about that too but I am sure that you will understand the usage of it quick and easy. ```ruby @EventHandler diff --git a/src/config.yml b/src/config.yml deleted file mode 100644 index 45ab611..0000000 --- a/src/config.yml +++ /dev/null @@ -1,92 +0,0 @@ -check-updates: true -debugger-mode: true -outdated-version: - sound: "NOTE_BASS" - pitch: 1 -cooldown-delay: 10 -editor-settings: - editor-title: "&6Editor" - editor-slots: 27 - editor-sounds: - sound: "NOTE_BASS" - pitch: 1 - back-item: - slot: 18 - material: "BARRIER" - data: 0 - name: "&4Return" - lore: - - "&cReturn to the main menu of the editor." - glow: true - unbreakable: false - hide-attributes: false - sounds: - sound: "" - pitch: 1 - rename-item: - slot: 8 - material: "NAME_TAG" - data: 0 - name: "&6Rename" - lore: - - "&eRename the display name of the voucher." - glow: true - unbreakable: false - hide-attributes: false - sounds: - sound: "NOTE_BASS" - pitch: 1 - receive-item: - slot: 0 - material: "FEATHER" - data: 0 - name: "&2Receive" - lore: - - "&aReceive a clone item of this voucher." - glow: true - unbreakable: false - hide-attributes: false - sounds: - sound: "LEVEL_UP" - pitch: 1 - fill-glass: true - editor-voucher: - title: "&6Editor [&e%voucher%&6]" - slots: 27 - voucher-slot: 13 - sound: "NOTE_PIANO" - pitch: 1 - fill-glass: true -confirm-settings: - confirm-title: "&6Confirmation" - confirm-slots: 27 - confirm-sounds: - sound: "NOTE_PIANO" - pitch: 1 - fill-glass: true - confirm-item: - slot: 11 - material: "EMERALD_BLOCK" - data: 0 - name: "&2&lREDEEM" - lore: - - "&aClick here if you want to confirm your redeem." - glow: true - unbreakable: false - hide-attributes: false - sounds: - sound: "LEVEL_UP" - pitch: 1 - cancel-item: - slot: 15 - material: "REDSTONE_BLOCK" - data: 0 - name: "&4&lCANCEL" - lore: - - "&cClick here if you want to cancel your redeem." - glow: true - unbreakable: false - hide-attributes: false - sounds: - sound: "CLICK" - pitch: 1 \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/EpicVouchers.java b/src/main/java/com/songoda/epicvouchers/EpicVouchers.java new file mode 100644 index 0000000..2729bc9 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/EpicVouchers.java @@ -0,0 +1,250 @@ +package com.songoda.epicvouchers; + +import com.songoda.epicvouchers.command.CommandManager; +import com.songoda.epicvouchers.handlers.Connections; +import com.songoda.epicvouchers.handlers.PreventHacks; +import com.songoda.epicvouchers.inventory.Confirmation; +import com.songoda.epicvouchers.inventory.VoucherEditor; +import com.songoda.epicvouchers.liberaries.Bountiful; +import com.songoda.epicvouchers.utils.ConfigWrapper; +import com.songoda.epicvouchers.utils.Methods; +import com.songoda.epicvouchers.utils.ServerVersion; +import com.songoda.epicvouchers.utils.SettingsManager; +import com.songoda.epicvouchers.voucher.ClickListener; +import com.songoda.epicvouchers.voucher.Cooldowns; +import com.songoda.epicvouchers.voucher.Voucher; +import com.songoda.epicvouchers.voucher.VoucherManager; +import org.apache.commons.lang.ArrayUtils; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; + +public class EpicVouchers extends JavaPlugin { + + private static EpicVouchers INSTANCE; + private ConsoleCommandSender console; + private CommandManager commandManager; + private References references; + private Locale locale; + private VoucherEditor voucherEditor; + private Confirmation confirmation; + private VoucherManager voucherManager; + private Connections connections; + private Cooldowns cooldowns; + private SettingsManager settingsManager; + + private ConfigWrapper vouchersFile = new ConfigWrapper(this, "", "vouchers.yml"); + + private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName()); + + public static EpicVouchers getInstance() { + return INSTANCE; + } + + @Override + public void onEnable() { + INSTANCE = this; + console = this.getServer().getConsoleSender(); + console.sendMessage(Methods.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&7EpicVouchers " + this.getDescription().getVersion() + " by &5Brianna <3&7!")); + console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); + console = getServer().getConsoleSender(); + + // Locales + Locale.init(this); + Locale.saveDefaultLocale("en_US"); + this.locale = Locale.getLocale(getConfig().getString("Locale", "en_US")); + + + this.settingsManager = new SettingsManager(this); + this.settingsManager.updateSettings(); + getConfig().options().copyDefaults(true); + saveConfig(); + + this.references = new References(); + this.voucherEditor = new VoucherEditor(this); + this.commandManager = new CommandManager(this); + this.confirmation = new Confirmation(this); + this.voucherManager = new VoucherManager(); + this.connections = new Connections(this); + this.cooldowns = new Cooldowns(); + + PluginManager manager = Bukkit.getServer().getPluginManager(); + manager.registerEvents(new ClickListener(this), EpicVouchers.getInstance()); + manager.registerEvents(voucherEditor, EpicVouchers.getInstance()); + manager.registerEvents(new Confirmation(this), EpicVouchers.getInstance()); + manager.registerEvents(new PreventHacks(), EpicVouchers.getInstance()); + + File folder = getDataFolder(); + File voucherfile = new File(folder, "vouchers.yml"); + if (!voucherfile.exists()) { + saveResource("vouchers.yml", true); + } + + loadVouchersFromFile(); + + Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000); + + Bountiful.findVersion(); + connections.openMySQL(); + console.sendMessage(Methods.formatText("&a=============================")); + } + + private void loadVouchersFromFile() { + /* + * Register Vouchers into VoucherManger from configuration + */ + if (vouchersFile.getConfig().contains("vouchers")) { + for (String key : vouchersFile.getConfig().getConfigurationSection("vouchers").getKeys(false)) { + + Voucher voucher = new Voucher(key); + ConfigurationSection cs = vouchersFile.getConfig().getConfigurationSection("vouchers." + key); + + voucher.setPermission(cs.getString("permission")); + voucher.setMaterial(Material.valueOf(cs.getString("material"))); + voucher.setData((short) cs.getInt("data")); + voucher.setName(cs.getString("name")); + voucher.setLore(cs.getStringList("lore")); + voucher.setGlow(cs.getBoolean("glow")); + voucher.setConfirm(cs.getBoolean("confirm")); + voucher.setUnbreakable(cs.getBoolean("unbreakable")); + voucher.setHideAttributes(cs.getBoolean("hide-attributes")); + voucher.setRemoveItem(cs.getBoolean("remove-item")); + voucher.setHealPlayer(cs.getBoolean("heal-player")); + voucher.setSmiteEffect(cs.getBoolean("smite-effect")); + voucher.setCooldown(cs.getInt("cooldown")); + voucher.setBroadcasts(cs.getStringList("broadcasts")); + voucher.setMessages(cs.getStringList("messages")); + voucher.setCommands(cs.getStringList("commands")); + voucher.setActionBar(cs.getString("actionbar")); + voucher.setTitle(cs.getString("titles.title")); + voucher.setSubTitle(cs.getString("titles.subtitle")); + voucher.setTitleFadeIn(cs.getInt("titles.fade-in")); + voucher.setTitleStay(cs.getInt("titles.stay")); + voucher.setTitleFadeOut(cs.getInt("titles.fade-out")); + voucher.setSound(cs.getString("sounds.sound")); + voucher.setSoundPitch(cs.getInt("sounds.pitch")); + voucher.setParticle(cs.getString("particles.particle")); + voucher.setParticleAmount(cs.getInt("particles.amount")); + voucher.setEffect(cs.getString("effects.effect")); + voucher.setEffectAmplifer(cs.getInt("effects.amplifier")); + + voucherManager.addVoucher(key, voucher); + } + } + } + + private void saveToFile() { + + vouchersFile.getConfig().set("vouchers", null); + + for (Voucher voucher : voucherManager.getVouchers()) { + ConfigurationSection cs = vouchersFile.getConfig().createSection("vouchers." + voucher.getKey()); + + cs.set("permission", voucher.getPermission()); + cs.set("material", voucher.getMaterial().name()); + cs.set("data", voucher.getData()); + cs.set("name", voucher.getName()); + cs.set("lore", voucher.getLore()); + cs.set("glow", voucher.isGlow()); + cs.set("confirm", voucher.isConfirm()); + cs.set("unbreakable", voucher.isUnbreakable()); + cs.set("hide-attributes", voucher.isHideAttributes()); + cs.set("remove-item", voucher.isRemoveItem()); + cs.set("heal-player", voucher.isHealPlayer()); + cs.set("smite-effect", voucher.isSmiteEffect()); + cs.set("cooldown", voucher.getCooldown()); + cs.set("broadcasts", voucher.getBroadcasts()); + cs.set("messages", voucher.getMessages()); + cs.set("commands", voucher.getCommands()); + cs.set("actionbar", voucher.getActionBar()); + cs.set("titles.title", voucher.getTitle()); + cs.set("titles.subtitle", voucher.getSubTitle()); + cs.set("titles.fade-in", voucher.getTitleFadeIn()); + cs.set("titles.stay", voucher.getTitleStay()); + cs.set("titles.fade-out", voucher.getTitleFadeOut()); + cs.set("sounds.sound", voucher.getSound()); + cs.set("sounds.pitch", voucher.getSoundPitch()); + cs.set("particles.particles", voucher.getParticle()); + cs.set("particles.amount", voucher.getParticleAmount()); + cs.set("effects.effect", voucher.getEffect()); + cs.set("effects.amplifier", voucher.getEffectAmplifer()); + } + + this.vouchersFile.saveConfig(); + } + + public void reload() { + loadVouchersFromFile(); + locale.reloadMessages(); + references = new References(); + reloadConfig(); + saveConfig(); + } + + @Override + public void onDisable() { + this.saveToFile(); + connections.closeMySQL(); + vouchersFile.saveConfig(); + console.sendMessage(Methods.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&7EpicVouchers " + this.getDescription().getVersion() + " by &5Brianna <3&7!")); + console.sendMessage(Methods.formatText("&7Action: &cDisabling&7...")); + console.sendMessage(Methods.formatText("&a=============================")); + + } + + 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 Locale getLocale() { + return locale; + } + + public References getReferences() { + return references; + } + + public Confirmation getConfirmation() { + return confirmation; + } + + public CommandManager getCommandManager() { + return commandManager; + } + + public VoucherEditor getVoucherEditor() { + return voucherEditor; + } + + public VoucherManager getVoucherManager() { + return voucherManager; + } + + public Cooldowns getCooldowns() { + return cooldowns; + } + + public Connections getConnections() { + return connections; + } + +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/Locale.java b/src/main/java/com/songoda/epicvouchers/Locale.java new file mode 100644 index 0000000..04aefc4 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/Locale.java @@ -0,0 +1,375 @@ +package com.songoda.epicvouchers; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import org.bukkit.ChatColor; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.*; +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 creation of multiple localizations and languages, + * as well as the generation of default .lang files + * + * @author Parker Hawke - 2008Choco + */ +public class Locale { + + private static final List LOCALES = Lists.newArrayList(); + 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 static String defaultLocale; + + private final Map nodes = new HashMap<>(); + + private final File file; + private final String name, region; + + private Locale(String name, String region) { + if (plugin == null) + throw new IllegalStateException("Cannot generate locales without first initializing the class (Locale#init(JavaPlugin))"); + + this.name = name.toLowerCase(); + this.region = region.toUpperCase(); + + String fileName = name + "_" + region + FILE_EXTENSION; + this.file = new File(localeFolder, fileName); + + if (this.reloadMessages()) return; + + plugin.getLogger().info("Loaded locale " + fileName); + } + + /** + * Initialize the locale class to generate information and search for localizations. + * This must be called before any other methods in the Locale class can be invoked. + * Note that this will also call {@link #searchForLocales()}, so there is no need to + * invoke it for yourself after the initialization + * + * @param plugin the plugin instance + */ + public static void init(JavaPlugin plugin) { + Locale.plugin = plugin; + + if (localeFolder == null) { + localeFolder = new File(plugin.getDataFolder(), "locales/"); + } + + localeFolder.mkdirs(); + Locale.searchForLocales(); + } + + /** + * Find all .lang file locales under the "locales" folder + */ + public static void searchForLocales() { + if (!localeFolder.exists()) localeFolder.mkdirs(); + + for (File file : localeFolder.listFiles()) { + String name = file.getName(); + if (!name.endsWith(".lang")) continue; + + String fileName = name.substring(0, name.lastIndexOf('.')); + String[] localeValues = fileName.split("_"); + + if (localeValues.length != 2) continue; + if (localeExists(localeValues[0] + "_" + localeValues[1])) continue; + + LOCALES.add(new Locale(localeValues[0], localeValues[1])); + plugin.getLogger().info("Found and loaded locale \"" + fileName + "\""); + } + } + + /** + * 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.getLanguageTag().equalsIgnoreCase(name)) return locale; + return null; + } + + /** + * Get a locale from the cache by its name (i.e. "en" from "en_US") + * + * @param name the name of the language + * @return locale of the specified language. Null if not cached + */ + public static Locale getLocaleByName(String name) { + for (Locale locale : LOCALES) + if (locale.getName().equalsIgnoreCase(name)) return locale; + return null; + } + + /** + * Get a locale from the cache by its region (i.e. "US" from "en_US") + * + * @param region the name of the region + * @return locale of the specified region. Null if not cached + */ + public static Locale getLocaleByRegion(String region) { + for (Locale locale : LOCALES) + if (locale.getRegion().equalsIgnoreCase(region)) return locale; + return null; + } + + /** + * 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 localeExists(String name) { + for (Locale locale : LOCALES) + if (locale.getLanguageTag().equals(name)) return true; + return false; + } + + /** + * Get an immutable list of all currently loaded locales + * + * @return list of all locales + */ + public static List getLocales() { + return ImmutableList.copyOf(LOCALES); + } + + /** + * Save a default locale file from the project source directory, to the locale folder + * + * @param path the path to the file to save + * @param fileName the name of the file to save + * @return true if the operation was successful, false otherwise + */ + public static boolean saveDefaultLocale(String path, 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(plugin.getResource(fileName), destinationFile); + } + + try (OutputStream outputStream = new FileOutputStream(destinationFile)) { + copy(plugin.getResource(fileName), outputStream); + + fileName = fileName.substring(0, fileName.lastIndexOf('.')); + String[] localeValues = fileName.split("_"); + + if (localeValues.length != 2) return false; + + LOCALES.add(new Locale(localeValues[0], localeValues[1])); + if (defaultLocale == null) defaultLocale = fileName; + + return true; + } catch (IOException e) { + return false; + } + } + + /** + * Save a default locale file from the project source directory, 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 saveDefaultLocale(String fileName) { + return saveDefaultLocale("", fileName); + } + + /** + * Clear all current locale data + */ + public static void clearLocaleData() { + for (Locale locale : LOCALES) + locale.nodes.clear(); + LOCALES.clear(); + } + + // Write new changes to existing files, if any at all + private static boolean compareFiles(InputStream defaultFile, File existingFile) { + // Look for default + if (defaultFile == null) { + defaultFile = plugin.getResource(defaultLocale != null ? defaultLocale : "en_US"); + if (defaultFile == null) return false; // No default at all + } + + 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(); + writer.write("# New messages for " + plugin.getName() + " v" + plugin.getDescription().getVersion()); + } + + writer.newLine(); + writer.write(defaultValue); + + changed = true; + } + } + } catch (IOException e) { + return false; + } + + return changed; + } + + 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(); + } + } + + /** + * Get the name of the language that this locale is based on. + * (i.e. "en" for English, or "fr" for French) + * + * @return the name of the language + */ + public String getName() { + return name; + } + + /** + * Get the name of the region that this locale is from. + * (i.e. "US" for United States or "CA" for Canada) + * + * @return the name of the region + */ + public String getRegion() { + return region; + } + + /** + * Return the entire locale tag (i.e. "en_US") + * + * @return the language tag + */ + public String getLanguageTag() { + return name + "_" + region; + } + + /** + * Get the file that represents this locale + * + * @return the locale file (.lang) + */ + public File getFile() { + return file; + } + + /** + * Get a message set for a specific node + * + * @param node the node to get + * @return the message for the specified node + */ + public String getMessage(String node) { + return ChatColor.translateAlternateColorCodes('&', this.getMessageOrDefault(node, node)); + } + + /** + * Get a message set for a specific node and replace its params with a supplied arguments. + * + * @param node the node to get + * @param args the replacement arguments + * @return the message for the specified node + */ + public String getMessage(String node, Object... args) { + String message = getMessage(node); + for (Object arg : args) { + message = message.replaceFirst("\\%.*?\\%", arg.toString()); + } + return message; + } + + /** + * 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 String getMessageOrDefault(String node, String defaultValue) { + return this.nodes.getOrDefault(node, defaultValue); + } + + /** + * Get the key-value map of nodes to messages + * + * @return node-message map + */ + public Map getMessageNodeMap() { + return ImmutableMap.copyOf(nodes); + } + + /** + * 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.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; + } + +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/References.java b/src/main/java/com/songoda/epicvouchers/References.java new file mode 100644 index 0000000..35f4092 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/References.java @@ -0,0 +1,14 @@ +package com.songoda.epicvouchers; + +public class References { + + private String prefix; + + public References() { + prefix = EpicVouchers.getInstance().getLocale().getMessage("general.nametag.prefix") + " "; + } + + public String getPrefix() { + return this.prefix; + } +} diff --git a/src/main/java/com/songoda/epicvouchers/command/AbstractCommand.java b/src/main/java/com/songoda/epicvouchers/command/AbstractCommand.java new file mode 100644 index 0000000..4f30e90 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/command/AbstractCommand.java @@ -0,0 +1,41 @@ +package com.songoda.epicvouchers.command; + +import com.songoda.epicvouchers.EpicVouchers; +import org.bukkit.command.CommandSender; + +public abstract class AbstractCommand { + + public enum ReturnType { SUCCESS, FAILURE, SYNTAX_ERROR, NO_CONSOLE } + + private final AbstractCommand parent; + + private final String command; + + private final boolean noConsole; + + protected AbstractCommand(String command, AbstractCommand parent, boolean noConsole) { + this.command = command; + this.parent = parent; + this.noConsole = noConsole; + } + + public AbstractCommand getParent() { + return parent; + } + + public String getCommand() { + return command; + } + + public boolean isNoConsole() { + return noConsole; + } + + protected abstract ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args); + + public abstract String getPermissionNode(); + + public abstract String getSyntax(); + + public abstract String getDescription(); +} diff --git a/src/main/java/com/songoda/epicvouchers/command/CommandManager.java b/src/main/java/com/songoda/epicvouchers/command/CommandManager.java new file mode 100644 index 0000000..56db037 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/command/CommandManager.java @@ -0,0 +1,83 @@ +package com.songoda.epicvouchers.command; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.command.commands.*; +import com.songoda.epicvouchers.utils.Methods; +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 EpicVouchers instance; + + private List commands = new ArrayList<>(); + + public CommandManager(EpicVouchers instance) { + this.instance = instance; + + instance.getCommand("EpicVouchers").setExecutor(this); + + AbstractCommand commandEpicVouchers = addCommand(new CommandEpicVouchers()); + + addCommand(new CommandReload(commandEpicVouchers)); + addCommand(new CommandEditor(commandEpicVouchers)); + addCommand(new CommandList(commandEpicVouchers)); + addCommand(new CommandGive(commandEpicVouchers)); + addCommand(new CommandForce(commandEpicVouchers)); + } + + 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().equalsIgnoreCase(command.getName())) { + if (strings.length == 0) { + processRequirements(abstractCommand, commandSender, strings); + return true; + } + } else if (strings.length != 0 && abstractCommand.getParent() != null && abstractCommand.getParent().getCommand().equalsIgnoreCase(command.getName())) { + String cmd = strings[0]; + if (cmd.equalsIgnoreCase(abstractCommand.getCommand())) { + processRequirements(abstractCommand, commandSender, strings); + return true; + } + } + } + commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText(instance.getLocale().getMessage("command.error.notexist"))); + return true; + } + + private void processRequirements(AbstractCommand command, CommandSender sender, String[] strings) { + if (!(sender instanceof Player) && command.isNoConsole() ) { + sender.sendMessage(instance.getLocale().getMessage("command.error.noconsole")); + return; + } + if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { + AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings); + if (returnType == AbstractCommand.ReturnType.NO_CONSOLE) { + sender.sendMessage(instance.getLocale().getMessage("command.error.noconsole")); + return; + } + if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) { + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!")); + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7.")); + } + return; + } + sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.general.nopermission")); + } + + public List getCommands() { + return Collections.unmodifiableList(commands); + } +} diff --git a/src/main/java/com/songoda/epicvouchers/command/commands/CommandEditor.java b/src/main/java/com/songoda/epicvouchers/command/commands/CommandEditor.java new file mode 100644 index 0000000..60262ef --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/command/commands/CommandEditor.java @@ -0,0 +1,39 @@ +package com.songoda.epicvouchers.command.commands; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.command.AbstractCommand; +import com.songoda.epicvouchers.inventory.VoucherEditor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandEditor extends AbstractCommand { + + public CommandEditor(AbstractCommand parent) { + super("editor", parent, true); + } + + @Override + protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) { + if (args.length != 1) return ReturnType.SYNTAX_ERROR; + + instance.reload(); + instance.getVoucherEditor().openMenu((Player) sender); + return ReturnType.SUCCESS; + } + + + @Override + public String getPermissionNode() { + return "epicvouchers.admin"; + } + + @Override + public String getSyntax() { + return "/epicvouchers editor"; + } + + @Override + public String getDescription() { + return "Edit vouchers in a gui."; + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/command/commands/CommandEpicVouchers.java b/src/main/java/com/songoda/epicvouchers/command/commands/CommandEpicVouchers.java new file mode 100644 index 0000000..c7667e1 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/command/commands/CommandEpicVouchers.java @@ -0,0 +1,43 @@ +package com.songoda.epicvouchers.command.commands; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.command.AbstractCommand; +import com.songoda.epicvouchers.utils.Methods; +import org.bukkit.command.CommandSender; + +public class CommandEpicVouchers extends AbstractCommand { + + public CommandEpicVouchers() { + super("EpicVouchers", null, false); + } + + @Override + protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) { + sender.sendMessage(""); + sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna")); + + for (AbstractCommand command : instance.getCommandManager().getCommands()) { + if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { + sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); + } + } + sender.sendMessage(""); + + return ReturnType.SUCCESS; + } + + @Override + public String getPermissionNode() { + return null; + } + + @Override + public String getSyntax() { + return "/EpicVouchers"; + } + + @Override + public String getDescription() { + return "Displays this page."; + } +} diff --git a/src/main/java/com/songoda/epicvouchers/command/commands/CommandForce.java b/src/main/java/com/songoda/epicvouchers/command/commands/CommandForce.java new file mode 100644 index 0000000..8ae2ae8 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/command/commands/CommandForce.java @@ -0,0 +1,85 @@ +package com.songoda.epicvouchers.command.commands; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.command.AbstractCommand; +import com.songoda.epicvouchers.events.ForceRedeemEvent; +import com.songoda.epicvouchers.utils.Debugger; +import com.songoda.epicvouchers.voucher.Voucher; +import com.songoda.epicvouchers.voucher.VoucherExecutor; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandForce extends AbstractCommand { + + public CommandForce(AbstractCommand parent) { + super("force", parent, true); + } + + @Override + protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) { + if (args.length != 4) return ReturnType.SYNTAX_ERROR; + + if (!args[1].equalsIgnoreCase("everyone") && Bukkit.getPlayer(args[1]) == null) { + sender.sendMessage(instance.getLocale().getMessage("command.error.noplayer")); + return ReturnType.FAILURE; + } + Voucher voucher = instance.getVoucherManager().getVoucher(args[2]); + if (voucher == null) { + sender.sendMessage(instance.getLocale().getMessage("command.error.novoucher")); + return ReturnType.FAILURE; + } + try { + int amount = Integer.parseInt(args[3]); + String output; + if (args[1].equalsIgnoreCase("everyone")) { + output = "everyone"; + for (Player player : Bukkit.getOnlinePlayers()) { + if (player != sender) { + ForceRedeemEvent event = new ForceRedeemEvent(player, voucher.getName(), amount, sender); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return ReturnType.FAILURE; + } + for (int times = 0; times < amount; times++) { + VoucherExecutor.redeemVoucher(player, voucher, player.getItemInHand(), false); + } + } + } + } else { + Player player = Bukkit.getPlayer(args[1]); + ForceRedeemEvent event = new ForceRedeemEvent(player, voucher.getName(), amount, sender); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return ReturnType.FAILURE; + } + output = player.getName(); + for (int times = 0; times < amount; times++) { + VoucherExecutor.redeemVoucher(player, voucher, player.getItemInHand(), false); + } + } + String message = instance.getLocale().getMessage("command.force.send", output, voucher.getName(), String.valueOf(amount)); + sender.sendMessage(message); + } catch (Exception error) { + sender.sendMessage(instance.getLocale().getMessage("command.error.notnumber")); + Debugger.runReport(error); + } + return ReturnType.SUCCESS; + } + + + @Override + public String getPermissionNode() { + return "epicvouchers.admin"; + } + + @Override + public String getSyntax() { + return "/epicvouchers force [player/everyone] [section] [amount]"; + } + + @Override + public String getDescription() { + return "Force someone or everyone to redeem a specific voucher."; + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/command/commands/CommandGive.java b/src/main/java/com/songoda/epicvouchers/command/commands/CommandGive.java new file mode 100644 index 0000000..8ef9382 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/command/commands/CommandGive.java @@ -0,0 +1,91 @@ +package com.songoda.epicvouchers.command.commands; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.command.AbstractCommand; +import com.songoda.epicvouchers.events.VoucherReceiveEvent; +import com.songoda.epicvouchers.voucher.Voucher; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class CommandGive extends AbstractCommand { + + public CommandGive(AbstractCommand parent) { + super("give", parent, false); + } + + @Override + protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) { + if (args.length != 4) return ReturnType.SYNTAX_ERROR; + if (!args[1].equalsIgnoreCase("everyone") && Bukkit.getPlayer(args[1]) == null) { + sender.sendMessage(instance.getLocale().getMessage("command.error.noplayer")); + return ReturnType.FAILURE; + } + Voucher voucher = instance.getVoucherManager().getVoucher(args[2]); + if (voucher == null) { + sender.sendMessage(instance.getLocale().getMessage("command.error.novoucher")); + return ReturnType.FAILURE; + } + try { + String givemessage = instance.getLocale().getMessage("command.give.send"); + String receivemessage = instance.getLocale().getMessage("command.give.receive"); + int amount = Integer.parseInt(args[3]); + ItemStack item = voucher.toItemStack(amount); + String output; + receivemessage = receivemessage.replaceAll("%voucher%", voucher.getName()); + receivemessage = receivemessage.replaceAll("%amount%", String.valueOf(amount)); + if (args[1].equalsIgnoreCase("everyone")) { + for (Player player : Bukkit.getOnlinePlayers()) { + if (player != sender) { + VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher.getName(), item, amount, sender); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return ReturnType.FAILURE; + } + player.sendMessage(receivemessage); + player.getInventory().addItem(item); + player.updateInventory(); + } + } + output = "everyone"; + } else { + Player player = Bukkit.getPlayer(args[1]); + receivemessage = receivemessage.replaceAll("%player%", player.getName()); + VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher.getName(), item, amount, sender); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return ReturnType.FAILURE; + } + player.sendMessage(receivemessage); + player.getInventory().addItem(item); + player.updateInventory(); + output = player.getName(); + } + givemessage = givemessage.replaceAll("%player%", output); + givemessage = givemessage.replaceAll("%voucher%", voucher.getName()); + givemessage = givemessage.replaceAll("%amount%", String.valueOf(amount)); + sender.sendMessage(givemessage); + } catch (Exception error) { + sender.sendMessage(instance.getLocale().getMessage("command.error.notnumber")); + } + + return ReturnType.SUCCESS; + } + + + @Override + public String getPermissionNode() { + return "epicvouchers.admin"; + } + + @Override + public String getSyntax() { + return "/epicvouchers give [player/everyone] [section] [amount]"; + } + + @Override + public String getDescription() { + return "Give someone or everyone a voucher from your parameters."; + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/command/commands/CommandList.java b/src/main/java/com/songoda/epicvouchers/command/commands/CommandList.java new file mode 100644 index 0000000..60110e6 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/command/commands/CommandList.java @@ -0,0 +1,41 @@ +package com.songoda.epicvouchers.command.commands; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.command.AbstractCommand; +import org.bukkit.command.CommandSender; + +public class CommandList extends AbstractCommand { + + public CommandList(AbstractCommand parent) { + super("list", parent, false); + } + + @Override + protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) { + if (args.length != 1) return ReturnType.SYNTAX_ERROR; + + String message = instance.getLocale().getMessage("command.list.list"); + String list = instance.getVoucherManager().getVouchers().toString(); + list = list.replaceAll("[()\\[\\]]", ""); + message = message.replaceAll("%list%", list); + sender.sendMessage(message); + + return ReturnType.SUCCESS; + } + + + @Override + public String getPermissionNode() { + return "epicvouchers.admin"; + } + + @Override + public String getSyntax() { + return "/epicvouchers list"; + } + + @Override + public String getDescription() { + return "Displays a list of all vouchers from the vouchers file."; + } +} diff --git a/src/main/java/com/songoda/epicvouchers/command/commands/CommandReload.java b/src/main/java/com/songoda/epicvouchers/command/commands/CommandReload.java new file mode 100644 index 0000000..33af71c --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/command/commands/CommandReload.java @@ -0,0 +1,38 @@ +package com.songoda.epicvouchers.command.commands; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.command.AbstractCommand; +import org.bukkit.command.CommandSender; + +public class CommandReload extends AbstractCommand { + + public CommandReload(AbstractCommand parent) { + super("reload", parent, false); + } + + @Override + protected ReturnType runCommand(EpicVouchers instance, CommandSender sender, String... args) { + if (args.length != 1) return ReturnType.SYNTAX_ERROR; + + instance.reload(); + + sender.sendMessage(instance.getLocale().getMessage("command.reload.success")); + return ReturnType.SUCCESS; + } + + + @Override + public String getPermissionNode() { + return "epicvouchers.admin"; + } + + @Override + public String getSyntax() { + return "/epicvouchers reload"; + } + + @Override + public String getDescription() { + return "Reload the config files."; + } +} diff --git a/src/nl/marido/deluxevouchers/events/ForceRedeemEvent.java b/src/main/java/com/songoda/epicvouchers/events/ForceRedeemEvent.java similarity index 91% rename from src/nl/marido/deluxevouchers/events/ForceRedeemEvent.java rename to src/main/java/com/songoda/epicvouchers/events/ForceRedeemEvent.java index 38b94aa..476f481 100644 --- a/src/nl/marido/deluxevouchers/events/ForceRedeemEvent.java +++ b/src/main/java/com/songoda/epicvouchers/events/ForceRedeemEvent.java @@ -1,55 +1,55 @@ -package nl.marido.deluxevouchers.events; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class ForceRedeemEvent extends Event implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - - private Player player; - private String voucher; - private int amount; - private CommandSender sender; - private boolean cancelled; - - public ForceRedeemEvent(Player player, String voucher, int amount, CommandSender sender) { - this.player = player; - this.voucher = voucher; - this.amount = amount; - this.sender = sender; - this.cancelled = false; - } - - public Player getPlayer() { - return player; - } - - public String getVoucher() { - return voucher; - } - - public int getAmount() { - return amount; - } - - public CommandSender getSender() { - return sender; - } - - public boolean isCancelled() { - return cancelled; - } - - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - - public HandlerList getHandlers() { - return handlers; - } - +package com.songoda.epicvouchers.events; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ForceRedeemEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + + private Player player; + private String voucher; + private int amount; + private CommandSender sender; + private boolean cancelled; + + public ForceRedeemEvent(Player player, String voucher, int amount, CommandSender sender) { + this.player = player; + this.voucher = voucher; + this.amount = amount; + this.sender = sender; + this.cancelled = false; + } + + public Player getPlayer() { + return player; + } + + public String getVoucher() { + return voucher; + } + + public int getAmount() { + return amount; + } + + public CommandSender getSender() { + return sender; + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + public HandlerList getHandlers() { + return handlers; + } + } \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/events/VoucherReceiveEvent.java b/src/main/java/com/songoda/epicvouchers/events/VoucherReceiveEvent.java similarity index 92% rename from src/nl/marido/deluxevouchers/events/VoucherReceiveEvent.java rename to src/main/java/com/songoda/epicvouchers/events/VoucherReceiveEvent.java index 02bb8a7..1bb8c53 100644 --- a/src/nl/marido/deluxevouchers/events/VoucherReceiveEvent.java +++ b/src/main/java/com/songoda/epicvouchers/events/VoucherReceiveEvent.java @@ -1,62 +1,62 @@ -package nl.marido.deluxevouchers.events; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; - -public class VoucherReceiveEvent extends Event implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - - private Player player; - private String voucher; - private ItemStack item; - private int amount; - private CommandSender sender; - private boolean cancelled; - - public VoucherReceiveEvent(Player player, String voucher, ItemStack item, int amount, CommandSender sender) { - this.player = player; - this.voucher = voucher; - this.item = item; - this.amount = amount; - this.sender = sender; - this.cancelled = false; - } - - public Player getPlayer() { - return player; - } - - public String getVoucher() { - return voucher; - } - - public ItemStack getItem() { - return item; - } - - public int getAmount() { - return amount; - } - - public CommandSender getSender() { - return sender; - } - - public boolean isCancelled() { - return cancelled; - } - - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - - public HandlerList getHandlers() { - return handlers; - } - +package com.songoda.epicvouchers.events; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; + +public class VoucherReceiveEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + + private Player player; + private String voucher; + private ItemStack item; + private int amount; + private CommandSender sender; + private boolean cancelled; + + public VoucherReceiveEvent(Player player, String voucher, ItemStack item, int amount, CommandSender sender) { + this.player = player; + this.voucher = voucher; + this.item = item; + this.amount = amount; + this.sender = sender; + this.cancelled = false; + } + + public Player getPlayer() { + return player; + } + + public String getVoucher() { + return voucher; + } + + public ItemStack getItem() { + return item; + } + + public int getAmount() { + return amount; + } + + public CommandSender getSender() { + return sender; + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + public HandlerList getHandlers() { + return handlers; + } + } \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/events/VoucherRedeemEvent.java b/src/main/java/com/songoda/epicvouchers/events/VoucherRedeemEvent.java similarity index 91% rename from src/nl/marido/deluxevouchers/events/VoucherRedeemEvent.java rename to src/main/java/com/songoda/epicvouchers/events/VoucherRedeemEvent.java index bd18384..6c90d2c 100644 --- a/src/nl/marido/deluxevouchers/events/VoucherRedeemEvent.java +++ b/src/main/java/com/songoda/epicvouchers/events/VoucherRedeemEvent.java @@ -1,55 +1,55 @@ -package nl.marido.deluxevouchers.events; - -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.ItemStack; - -public class VoucherRedeemEvent extends Event implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - - private Player player; - private String voucher; - private ItemStack item; - private boolean manual; - private boolean cancelled; - - public VoucherRedeemEvent(Player player, String voucher, ItemStack item, boolean manual) { - this.player = player; - this.voucher = voucher; - this.item = item; - this.manual = manual; - this.cancelled = false; - } - - public Player getPlayer() { - return player; - } - - public String getVoucher() { - return voucher; - } - - public ItemStack getItem() { - return item; - } - - public boolean getManual() { - return manual; - } - - public boolean isCancelled() { - return cancelled; - } - - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - - public HandlerList getHandlers() { - return handlers; - } - +package com.songoda.epicvouchers.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; + +public class VoucherRedeemEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + + private Player player; + private String voucher; + private ItemStack item; + private boolean manual; + private boolean cancelled; + + public VoucherRedeemEvent(Player player, String voucher, ItemStack item, boolean manual) { + this.player = player; + this.voucher = voucher; + this.item = item; + this.manual = manual; + this.cancelled = false; + } + + public Player getPlayer() { + return player; + } + + public String getVoucher() { + return voucher; + } + + public ItemStack getItem() { + return item; + } + + public boolean getManual() { + return manual; + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + public HandlerList getHandlers() { + return handlers; + } + } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/handlers/Connections.java b/src/main/java/com/songoda/epicvouchers/handlers/Connections.java new file mode 100644 index 0000000..15e0458 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/handlers/Connections.java @@ -0,0 +1,71 @@ +package com.songoda.epicvouchers.handlers; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.utils.Debugger; +import com.songoda.epicvouchers.utils.Methods; +import org.bukkit.entity.Player; + +import java.sql.*; + +public class Connections { + + private EpicVouchers instance; + private Connection connection; + + public Connections(EpicVouchers instance) { + this.instance = instance; + } + + public void openMySQL() { + if (!instance.getConfig().getBoolean("Database.Activate Mysql Support") || connection == null) { + return; + } + try { + String mysqlIP = instance.getConfig().getString("Database.IP"); + String mysqlPort = instance.getConfig().getString("Database.PORT"); + String mysqlDatabase = instance.getConfig().getString("Database.Database Name"); + String mysqlUsername = instance.getConfig().getString("Database.Username"); + String mysqlPassword = instance.getConfig().getString("Database.Password"); + + + connection = DriverManager.getConnection("jdbc:mysql://" + mysqlIP + ":" + mysqlPort + "/" + mysqlDatabase + "?useSSL=true?autoReconnect=true", mysqlUsername, mysqlPassword); + System.out.println(Methods.formatText("&fSuccessfully created a connection with MySQL.")); + } catch (Exception error) { + System.out.println(Methods.formatText("&cFailed to create a connection with MySQL.")); + Debugger.runReport(error); + } + } + + public void closeMySQL() { + if (!instance.getConfig().getBoolean("Database.Activate Mysql Support") || connection == null) { + return; + } + try { + connection.close(); + System.out.println(Methods.formatText("&fSuccessfully closed the MySQL connection.")); + } catch (Exception error) { + System.out.println(Methods.formatText("&cFailed to close the MySQL connection.")); + Debugger.runReport(error); + } + } + + public void saveRedeem(Player player, String voucher) { + if (!instance.getConfig().getBoolean("Database.Activate Mysql Support") || connection == null) { + return; + } + Timestamp stamp = new Timestamp(System.currentTimeMillis()); + Date date = new Date(stamp.getTime()); + String time = date.toString(); + try { + Statement statement = connection.createStatement(); + statement.execute("CREATE TABLE IF NOT EXISTS redeems (id INT NOT NULL AUTO_INCREMENT, player varchar(120) NOT NULL, voucher varchar(120) NOT NULL, timestamp varchar(120) NOT NULL, PRIMARY KEY (ID));"); + statement.execute("INSERT INTO redeems VALUES (default, '" + player.getName() + "', '" + voucher + "', '" + time + "');"); + statement.close(); + System.out.println(Methods.formatText("&fSuccessfully saved the redeem in the MySQL database.")); + } catch (Exception error) { + System.out.println(Methods.formatText("&cFailed to save the redeem data in the MySQL database.")); + Debugger.runReport(error); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/handlers/PreventHacks.java b/src/main/java/com/songoda/epicvouchers/handlers/PreventHacks.java new file mode 100644 index 0000000..b593a09 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/handlers/PreventHacks.java @@ -0,0 +1,31 @@ +package com.songoda.epicvouchers.handlers; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.util.HashMap; +import java.util.UUID; + +public class PreventHacks implements Listener { + + private static HashMap commands = new HashMap(); + + @EventHandler + public static void preventCommands(PlayerCommandPreprocessEvent event) { + if (!commands.containsKey(event.getPlayer().getUniqueId()) + || event.getMessage().equalsIgnoreCase(commands.get(event.getPlayer().getUniqueId()))) { + return; + } + event.setCancelled(true); + } + + public static void addCommand(UUID uuid, String command) { + commands.put(uuid, command); + } + public static void removeCommand(UUID uuid) { + commands.remove(uuid); + } + + +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/inventory/Confirmation.java b/src/main/java/com/songoda/epicvouchers/inventory/Confirmation.java new file mode 100644 index 0000000..fbf9fcf --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/inventory/Confirmation.java @@ -0,0 +1,116 @@ +package com.songoda.epicvouchers.inventory; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.UUID; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.utils.Debugger; +import com.songoda.epicvouchers.utils.Methods; +import com.songoda.epicvouchers.voucher.Voucher; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +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.inventory.Inventory; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import com.songoda.epicvouchers.utils.SoundUtils; +import com.songoda.epicvouchers.voucher.VoucherExecutor; + +public class Confirmation implements Listener { + + private EpicVouchers instance; + + private static HashMap vouchercache = new HashMap<>(); + private static HashMap itemcache = new HashMap<>(); + + public Confirmation(EpicVouchers instance) { + this.instance = instance; + } + + public void confirmVoucher(Player player, Voucher voucher, ItemStack item) { + Inventory confirmmenu = Bukkit.createInventory(null, 27, instance.getLocale().getMessage("interface.confirmsettings.title")); + SoundUtils.playSound(player, "NOTE_PIANO", 1); + ItemStack confirmitem = new ItemStack(Material.EMERALD, 1, (short) 0); + ItemMeta confirmitemmeta = confirmitem.getItemMeta(); + confirmitemmeta.setDisplayName(instance.getLocale().getMessage("interface.confirmsettings.confirmitemname")); + confirmitemmeta.setLore(Arrays.asList(instance.getLocale().getMessage("interface.confirmsettings.confirmitemlore"))); + + confirmitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); + confirmitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + + confirmitem.setItemMeta(confirmitemmeta); + confirmmenu.setItem(11, confirmitem); + ItemStack cancelitem = new ItemStack(Material.REDSTONE_BLOCK, 1, (short) 0); + ItemMeta cancelitemmeta = cancelitem.getItemMeta(); + cancelitemmeta.setDisplayName(instance.getLocale().getMessage("interface.confirmsettings.cancelitemname")); + cancelitemmeta.setLore(Arrays.asList(instance.getLocale().getMessage("interface.confirmsettings.cancelitemlore"))); + + cancelitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); + cancelitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + + cancelitem.setItemMeta(cancelitemmeta); + confirmmenu.setItem(15, cancelitem); + if (instance.getConfig().getBoolean("Interface.Fill Interfaces With Glass")) { + ItemStack fillitem; + try { + fillitem = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7); + } catch (Exception error) { + fillitem = new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE")); + } + ItemMeta fillitemmeta = fillitem.getItemMeta(); + fillitemmeta.setDisplayName(Methods.formatText("&r")); + fillitem.setItemMeta(fillitemmeta); + for (int empty = 0; empty < confirmmenu.getSize(); empty++) { + if (confirmmenu.getItem(empty) == null) { + confirmmenu.setItem(empty, fillitem); + } + } + } + UUID uuid = player.getUniqueId(); + vouchercache.put(uuid, voucher); + itemcache.put(uuid, item); + player.openInventory(confirmmenu); + } + + @EventHandler + public void clickListener(InventoryClickEvent event) { + try { + if (event.getInventory().getType() != InventoryType.CHEST || !event.getInventory().getTitle().equals(instance.getLocale().getMessage("interface.confirmsettings.title"))) { + return; + } + + Player player = (Player) event.getWhoClicked(); + ItemStack clicked = event.getCurrentItem(); + if (clicked == null) return; + event.setCancelled(true); + if (!clicked.getItemMeta().hasDisplayName()) + return; + if (clicked.getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.confirmsettings.confirmitemname"))) { + SoundUtils.playSound(player, "LEVEL_UP", 1); + player.closeInventory(); + UUID uuid = player.getUniqueId(); + Voucher voucher = vouchercache.get(uuid); + ItemStack item = itemcache.get(uuid); + VoucherExecutor.redeemVoucher(player, voucher, item, true); + } else if (clicked.getItemMeta().getDisplayName().equals(instance.getLocale().getMessage("interface.confirmsettings.cancelitemname"))) { + UUID uuid = player.getUniqueId(); + vouchercache.remove(uuid); + itemcache.remove(uuid); + SoundUtils.playSound(player, "CLICK", 1); + player.closeInventory(); + } + } catch (Exception error) { + Debugger.runReport(error); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/inventory/VoucherEditor.java b/src/main/java/com/songoda/epicvouchers/inventory/VoucherEditor.java new file mode 100644 index 0000000..86f1d5e --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/inventory/VoucherEditor.java @@ -0,0 +1,221 @@ +package com.songoda.epicvouchers.inventory; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.UUID; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.utils.Debugger; +import com.songoda.epicvouchers.utils.Methods; +import com.songoda.epicvouchers.voucher.Voucher; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +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.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import com.songoda.epicvouchers.utils.SoundUtils; + +public class VoucherEditor implements Listener { + + private HashMap editor = new HashMap<>(); + private HashMap type = new HashMap<>(); + + public EpicVouchers instance; + + public VoucherEditor(EpicVouchers instance) { + this.instance = instance; + } + + public void openMenu(Player player) { + Inventory editormenu = Bukkit.createInventory(null, 27, instance.getLocale().getMessage("interface.editor.title")); + SoundUtils.playSound(player, "NOTE_BASS", 1); + for (Voucher voucher : instance.getVoucherManager().getVouchers()) { + ItemStack item = voucher.toItemStack(); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(meta.getDisplayName() + Methods.formatText(" &b&l[CLICK TO EDIT]")); + item.setItemMeta(meta); + editormenu.setItem(editormenu.firstEmpty(), item); + } + if (instance.getConfig().getBoolean("Interface.Fill Interfaces With Glass")) { + ItemStack fillitem; + try { + fillitem = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7); + } catch (Exception error) { + fillitem = new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE")); + } + ItemMeta fillitemmeta = fillitem.getItemMeta(); + fillitemmeta.setDisplayName(Methods.formatText("&r")); + fillitem.setItemMeta(fillitemmeta); + for (int empty = 0; empty < editormenu.getSize(); empty++) { + if (editormenu.getItem(empty) == null) { + editormenu.setItem(empty, fillitem); + } + } + } + + player.openInventory(editormenu); + } + + private void editVoucher(Player player, Voucher voucher, ItemStack item) { + String title = instance.getLocale().getMessage("interface.editvoucher.title"); + title = title.replaceAll("%voucher%", voucher.getKey()); + Inventory editormenu = Bukkit.createInventory(null, 27, title); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(Methods.formatText(voucher.getName())); + item.setItemMeta(meta); + editormenu.setItem(13, item); + + ItemStack backitem = new ItemStack(Material.BARRIER, 1, (short) 0); + ItemMeta backitemmeta = backitem.getItemMeta(); + backitemmeta.setDisplayName(instance.getLocale().getMessage("interface.editvoucher.backtitle")); + backitemmeta.setLore(Collections.singletonList(instance.getLocale().getMessage("interface.editvoucher.backlore"))); + backitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); + backitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + backitem.setItemMeta(backitemmeta); + editormenu.setItem(18, backitem); + + ItemStack cloneitem = new ItemStack(Material.FEATHER, 1, (short) 0); + ItemMeta cloneitemmeta = cloneitem.getItemMeta(); + cloneitemmeta.setDisplayName(instance.getLocale().getMessage("interface.editvoucher.recivetitle")); + cloneitemmeta.setLore(Collections.singletonList(instance.getLocale().getMessage("interface.editvoucher.recivelore"))); + cloneitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); + cloneitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + cloneitem.setItemMeta(cloneitemmeta); + editormenu.setItem(0, cloneitem); + ItemStack renameitem = new ItemStack(Material.NAME_TAG, 1, (short) 0); + ItemMeta renameitemmeta = renameitem.getItemMeta(); + renameitemmeta.setDisplayName(instance.getLocale().getMessage("interface.editvoucher.renametitle")); + renameitemmeta.setLore(Collections.singletonList(instance.getLocale().getMessage("interface.editvoucher.renamelore"))); + renameitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); + renameitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + renameitem.setItemMeta(renameitemmeta); + editormenu.setItem(8, renameitem); + if (instance.getConfig().getBoolean("Interface.Fill Interfaces With Glass")) { + ItemStack fillitem; + try { + fillitem = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7); + } catch (Exception error) { + fillitem = new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE")); + } + ItemMeta fillitemmeta = fillitem.getItemMeta(); + fillitemmeta.setDisplayName(Methods.formatText("&r")); + fillitem.setItemMeta(fillitemmeta); + for (int empty = 0; empty < editormenu.getSize(); empty++) { + if (editormenu.getItem(empty) == null) { + editormenu.setItem(empty, fillitem); + } + } + } + player.openInventory(editormenu); + editor.put(player.getUniqueId(), voucher); + } + + @EventHandler + public void click2Listener(InventoryClickEvent event) { + try { + if (event.getInventory().getType() != InventoryType.CHEST || !event.getInventory().getTitle().equals(instance.getLocale().getMessage("interface.editor.title"))) { + return; + } + event.setCancelled(true); + for (Voucher voucher : instance.getVoucherManager().getVouchers()) { + ItemStack item = event.getCurrentItem(); + + //ToDO: this is awful + if (item == null) return; + if (item.getType() != voucher.getMaterial() || + item.getDurability() != voucher.getData()) { + continue; + } + ItemMeta meta = item.getItemMeta(); + if (!meta.hasLore() || !meta.getLore().equals(voucher.getLore())) { + continue; + } + Player player = (Player) event.getWhoClicked(); + SoundUtils.playSound(player, "NOTE_PIANO", 1); + editVoucher(player, voucher, item); + } + } catch (Exception error) { + Debugger.runReport(error); + } + } + + @EventHandler + public void clickListener(InventoryClickEvent event) { + try { + Player player = (Player) event.getWhoClicked(); + if (event.getInventory().getType() != InventoryType.CHEST || !editor.containsKey(player.getUniqueId())) { + return; + } + event.setCancelled(true); + + ItemStack item = event.getCurrentItem(); + if (item == null || !item.hasItemMeta()) return; + ItemMeta meta = item.getItemMeta(); + + if (!meta.hasDisplayName() || !meta.hasLore()) { + return; + } + + if (meta.getDisplayName().equals(instance.getLocale().getMessage("interface.editvoucher.recivetitle"))) { + SoundUtils.playSound(player, "LEVEL_UP", 1); + player.getInventory().addItem(editor.get(player.getUniqueId()).toItemStack()); + player.updateInventory(); + String message = instance.getLocale().getMessage("interface.editvoucher.recivemessage"); + message = message.replaceAll("%voucher%", editor.get(player.getUniqueId()).getName()); + player.sendMessage(message); + } else if (meta.getDisplayName().equals(instance.getLocale().getMessage("interface.editvoucher.backtitle"))) { + openMenu(player); + } else if (meta.getDisplayName().equals(instance.getLocale().getMessage("interface.editvoucher.renametitle"))) { + SoundUtils.playSound((Player) event.getWhoClicked(), "NOTE_BASS", 1); + Voucher cache = editor.get(event.getWhoClicked().getUniqueId()); + event.getWhoClicked().closeInventory(); + editor.put(event.getWhoClicked().getUniqueId(), cache); + type.put(event.getWhoClicked().getUniqueId(), "rename"); + event.getWhoClicked().sendMessage(instance.getLocale().getMessage("interface.editvoucher.renamemessage")); + } + } catch (Exception error) { + Debugger.runReport(error); + } + } + + @EventHandler + public void chatListener(AsyncPlayerChatEvent event) { + if (!editor.containsKey(event.getPlayer().getUniqueId()) + || !type.containsKey(event.getPlayer().getUniqueId()) + || !type.get(event.getPlayer().getUniqueId()).equals("rename")) { + return; + } + type.remove(event.getPlayer().getUniqueId()); + Voucher voucher = editor.get(event.getPlayer().getUniqueId()); + voucher.setName(event.getMessage()); + String message = instance.getLocale().getMessage("interface.editvoucher.renamefinish", event.getMessage()); + message = Methods.formatText(message); + event.getPlayer().sendMessage(message); + editVoucher(event.getPlayer(), editor.get(event.getPlayer().getUniqueId()), voucher.toItemStack()); + SoundUtils.playSound(event.getPlayer(), "NOTE_PIANO", 1); + event.setCancelled(true); + } + + @EventHandler + public void closeListener(InventoryCloseEvent event) { + editor.remove(event.getPlayer().getUniqueId()); + } + + @EventHandler + public void leaveListener(PlayerQuitEvent event) { + editor.remove(event.getPlayer().getUniqueId()); + } + +} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/liberaries/Bountiful.java b/src/main/java/com/songoda/epicvouchers/liberaries/Bountiful.java similarity index 93% rename from src/nl/marido/deluxevouchers/liberaries/Bountiful.java rename to src/main/java/com/songoda/epicvouchers/liberaries/Bountiful.java index 9c0c16a..a8b689a 100644 --- a/src/nl/marido/deluxevouchers/liberaries/Bountiful.java +++ b/src/main/java/com/songoda/epicvouchers/liberaries/Bountiful.java @@ -1,154 +1,143 @@ -package nl.marido.deluxevouchers.liberaries; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import nl.marido.deluxevouchers.handlers.DataHandler; - -public class Bountiful { - - public static boolean oldmethod; - public static String nmsversion; - - public static void findVersion() { - nmsversion = Bukkit.getServer().getClass().getPackage().getName(); - nmsversion = nmsversion.substring(nmsversion.lastIndexOf(".") + 1); - } - - public static Integer getPlayerProtocol(Player player) { - return Integer.valueOf(47); - } - - public static void sendPacket(Player player, Object packet) { - try { - Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player, new Object[0]); - Object playerConnection = handle.getClass().getField("playerConnection").get(handle); - playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") }).invoke(playerConnection, new Object[] { packet }); - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - - public static Class getNMSClass(String name) { - String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; - try { - return Class.forName("net.minecraft.server." + version + "." + name); - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - return null; - } - - public static void sendTitle(Player player, Integer fadein, Integer stay, Integer fadeout, String title, String subtitle) { - try { - if (title != null) { - Object field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); - Object chattitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); - Constructor subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); - Object titlepacket = subtitleconstructor.newInstance(new Object[] { field, chattitle, fadein, stay, fadeout }); - sendPacket(player, titlepacket); - field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null); - chattitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); - subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent") }); - titlepacket = subtitleconstructor.newInstance(new Object[] { field, chattitle }); - sendPacket(player, titlepacket); - } - if (subtitle != null) { - Object field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); - Object chatsubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); - Constructor subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); - Object subtitlepacket = subtitleconstructor.newInstance(new Object[] { field, chatsubtitle, fadein, stay, fadeout }); - sendPacket(player, subtitlepacket); - field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null); - chatsubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + subtitle + "\"}" }); - subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); - subtitlepacket = subtitleconstructor.newInstance(new Object[] { field, chatsubtitle, fadein, stay, fadeout }); - sendPacket(player, subtitlepacket); - } - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - - public static void sendActionBar(Player player, String message) { - if (nmsversion.startsWith("v1_12_")) { - sendActionbarBefore(player, message); - } else { - sendActionbarAfter(player, message); - } - } - - public static void sendActionbarBefore(Player player, String message) { - try { - Class craftplayerclass = Class.forName("org.bukkit.craftbukkit." + nmsversion + ".entity.CraftPlayer"); - Object craftplayer = craftplayerclass.cast(player); - Class playoutchat = Class.forName("net.minecraft.server." + nmsversion + ".PacketPlayOutChat"); - Class simplepacket = Class.forName("net.minecraft.server." + nmsversion + ".Packet"); - Class chatcomponent = Class.forName("net.minecraft.server." + nmsversion + ".ChatComponentText"); - Class basecomponent = Class.forName("net.minecraft.server." + nmsversion + ".IChatBaseComponent"); - Class chatmessagetypeclass = Class.forName("net.minecraft.server." + nmsversion + ".ChatMessageType"); - Object[] chatmessagetypes = chatmessagetypeclass.getEnumConstants(); - Object chatmessagetype = null; - for (Object object : chatmessagetypes) { - if (object.toString().equals("GAME_INFO")) { - chatmessagetype = object; - } - } - Object object = chatcomponent.getConstructor(new Class[] { String.class }).newInstance(new Object[] { message }); - Object customobject = playoutchat.getConstructor(new Class[] { basecomponent, chatmessagetypeclass }).newInstance(new Object[] { object, chatmessagetype }); - Method method = craftplayerclass.getDeclaredMethod("getHandle", new Class[0]); - Object invokedmethod = method.invoke(craftplayer, new Object[0]); - Field field = invokedmethod.getClass().getDeclaredField("playerConnection"); - Object packetchat = field.get(invokedmethod); - Method methodclass = packetchat.getClass().getDeclaredMethod("sendPacket", new Class[] { simplepacket }); - methodclass.invoke(packetchat, new Object[] { customobject }); - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - - public static void sendActionbarAfter(Player player, String message) { - try { - Class craftplayerclass = Class.forName("org.bukkit.craftbukkit." + nmsversion + ".entity.CraftPlayer"); - Object craftplayer = craftplayerclass.cast(player); - Class playoutchat = Class.forName("net.minecraft.server." + nmsversion + ".PacketPlayOutChat"); - Class simplepacket = Class.forName("net.minecraft.server." + nmsversion + ".Packet"); - Object customobject; - if (oldmethod) { - Class chatserializer = Class.forName("net.minecraft.server." + nmsversion + ".ChatSerializer"); - Class basecomponent = Class.forName("net.minecraft.server." + nmsversion + ".IChatBaseComponent"); - Method method = chatserializer.getDeclaredMethod("a", new Class[] { String.class }); - Object baseinvoke = basecomponent.cast(method.invoke(chatserializer, new Object[] { "{\"text\": \"" + message + "\"}" })); - customobject = playoutchat.getConstructor(new Class[] { basecomponent, Byte.TYPE }).newInstance(new Object[] { baseinvoke, Byte.valueOf((byte) 2) }); - } else { - Class componenttext = Class.forName("net.minecraft.server." + nmsversion + ".ChatComponentText"); - Class chatbase = Class.forName("net.minecraft.server." + nmsversion + ".IChatBaseComponent"); - Object object = componenttext.getConstructor(new Class[] { String.class }).newInstance(new Object[] { message }); - customobject = playoutchat.getConstructor(new Class[] { chatbase, Byte.TYPE }).newInstance(new Object[] { object, Byte.valueOf((byte) 2) }); - } - Method handlemethod = craftplayerclass.getDeclaredMethod("getHandle", new Class[0]); - Object objectinvoked = handlemethod.invoke(craftplayer, new Object[0]); - Field field = objectinvoked.getClass().getDeclaredField("playerConnection"); - Object fieldinvoked = field.get(objectinvoked); - Method methodclass = fieldinvoked.getClass().getDeclaredMethod("sendPacket", new Class[] { simplepacket }); - methodclass.invoke(fieldinvoked, new Object[] { customobject }); - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - +package com.songoda.epicvouchers.liberaries; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import com.songoda.epicvouchers.utils.Debugger; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class Bountiful { + + public static boolean oldmethod; + public static String nmsversion; + + public static void findVersion() { + nmsversion = Bukkit.getServer().getClass().getPackage().getName(); + nmsversion = nmsversion.substring(nmsversion.lastIndexOf(".") + 1); + } + + public static Integer getPlayerProtocol(Player player) { + return Integer.valueOf(47); + } + + public static void sendPacket(Player player, Object packet) { + try { + Object handle = player.getClass().getMethod("getHandle", new Class[0]).invoke(player, new Object[0]); + Object playerConnection = handle.getClass().getField("playerConnection").get(handle); + playerConnection.getClass().getMethod("sendPacket", new Class[] { getNMSClass("Packet") }).invoke(playerConnection, new Object[] { packet }); + } catch (Exception error) { + Debugger.runReport(error); + } + } + + public static Class getNMSClass(String name) { + String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + try { + return Class.forName("net.minecraft.server." + version + "." + name); + } catch (Exception error) { + Debugger.runReport(error); + } + return null; + } + + public static void sendTitle(Player player, Integer fadein, Integer stay, Integer fadeout, String title, String subtitle) { + try { + if (title != null) { + Object field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); + Object chattitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); + Constructor subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); + Object titlepacket = subtitleconstructor.newInstance(new Object[] { field, chattitle, fadein, stay, fadeout }); + sendPacket(player, titlepacket); + field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null); + chattitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); + subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent") }); + titlepacket = subtitleconstructor.newInstance(new Object[] { field, chattitle }); + sendPacket(player, titlepacket); + } + if (subtitle != null) { + Object field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null); + Object chatsubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + title + "\"}" }); + Constructor subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); + Object subtitlepacket = subtitleconstructor.newInstance(new Object[] { field, chatsubtitle, fadein, stay, fadeout }); + sendPacket(player, subtitlepacket); + field = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null); + chatsubtitle = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", new Class[] { String.class }).invoke(null, new Object[] { "{\"text\":\"" + subtitle + "\"}" }); + subtitleconstructor = getNMSClass("PacketPlayOutTitle").getConstructor(new Class[] { getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE }); + subtitlepacket = subtitleconstructor.newInstance(new Object[] { field, chatsubtitle, fadein, stay, fadeout }); + sendPacket(player, subtitlepacket); + } + } catch (Exception error) { + Debugger.runReport(error); + } + } + + public static void sendActionBar(Player player, String message) { + if (nmsversion.startsWith("v1_12_")) { + sendActionbarBefore(player, message); + } else { + sendActionbarAfter(player, message); + } + } + + public static void sendActionbarBefore(Player player, String message) { + try { + Class craftplayerclass = Class.forName("org.bukkit.craftbukkit." + nmsversion + ".entity.CraftPlayer"); + Object craftplayer = craftplayerclass.cast(player); + Class playoutchat = Class.forName("net.minecraft.server." + nmsversion + ".PacketPlayOutChat"); + Class simplepacket = Class.forName("net.minecraft.server." + nmsversion + ".Packet"); + Class chatcomponent = Class.forName("net.minecraft.server." + nmsversion + ".ChatComponentText"); + Class basecomponent = Class.forName("net.minecraft.server." + nmsversion + ".IChatBaseComponent"); + Class chatmessagetypeclass = Class.forName("net.minecraft.server." + nmsversion + ".ChatMessageType"); + Object[] chatmessagetypes = chatmessagetypeclass.getEnumConstants(); + Object chatmessagetype = null; + for (Object object : chatmessagetypes) { + if (object.toString().equals("GAME_INFO")) { + chatmessagetype = object; + } + } + Object object = chatcomponent.getConstructor(new Class[] { String.class }).newInstance(new Object[] { message }); + Object customobject = playoutchat.getConstructor(new Class[] { basecomponent, chatmessagetypeclass }).newInstance(new Object[] { object, chatmessagetype }); + Method method = craftplayerclass.getDeclaredMethod("getHandle", new Class[0]); + Object invokedmethod = method.invoke(craftplayer, new Object[0]); + Field field = invokedmethod.getClass().getDeclaredField("playerConnection"); + Object packetchat = field.get(invokedmethod); + Method methodclass = packetchat.getClass().getDeclaredMethod("sendPacket", new Class[] { simplepacket }); + methodclass.invoke(packetchat, new Object[] { customobject }); + } catch (Exception error) { + Debugger.runReport(error); + } + } + + public static void sendActionbarAfter(Player player, String message) { + try { + Class craftplayerclass = Class.forName("org.bukkit.craftbukkit." + nmsversion + ".entity.CraftPlayer"); + Object craftplayer = craftplayerclass.cast(player); + Class playoutchat = Class.forName("net.minecraft.server." + nmsversion + ".PacketPlayOutChat"); + Class simplepacket = Class.forName("net.minecraft.server." + nmsversion + ".Packet"); + Object customobject; + if (oldmethod) { + Class chatserializer = Class.forName("net.minecraft.server." + nmsversion + ".ChatSerializer"); + Class basecomponent = Class.forName("net.minecraft.server." + nmsversion + ".IChatBaseComponent"); + Method method = chatserializer.getDeclaredMethod("a", new Class[] { String.class }); + Object baseinvoke = basecomponent.cast(method.invoke(chatserializer, new Object[] { "{\"text\": \"" + message + "\"}" })); + customobject = playoutchat.getConstructor(new Class[] { basecomponent, Byte.TYPE }).newInstance(new Object[] { baseinvoke, Byte.valueOf((byte) 2) }); + } else { + Class componenttext = Class.forName("net.minecraft.server." + nmsversion + ".ChatComponentText"); + Class chatbase = Class.forName("net.minecraft.server." + nmsversion + ".IChatBaseComponent"); + Object object = componenttext.getConstructor(new Class[] { String.class }).newInstance(new Object[] { message }); + customobject = playoutchat.getConstructor(new Class[] { chatbase, Byte.TYPE }).newInstance(new Object[] { object, Byte.valueOf((byte) 2) }); + } + Method handlemethod = craftplayerclass.getDeclaredMethod("getHandle", new Class[0]); + Object objectinvoked = handlemethod.invoke(craftplayer, new Object[0]); + Field field = objectinvoked.getClass().getDeclaredField("playerConnection"); + Object fieldinvoked = field.get(objectinvoked); + Method methodclass = fieldinvoked.getClass().getDeclaredMethod("sendPacket", new Class[] { simplepacket }); + methodclass.invoke(fieldinvoked, new Object[] { customobject }); + } catch (Exception error) { + Debugger.runReport(error); + } + } + } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/utils/ConfigWrapper.java b/src/main/java/com/songoda/epicvouchers/utils/ConfigWrapper.java new file mode 100644 index 0000000..0cd7f97 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/utils/ConfigWrapper.java @@ -0,0 +1,67 @@ +package com.songoda.epicvouchers.utils; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; + +/** + * ConfigWrapper made by @clip + */ +public class ConfigWrapper { + + private final JavaPlugin plugin; + private FileConfiguration config; + private File configFile; + private final String folderName, fileName; + + public ConfigWrapper(final JavaPlugin instance, final String folderName, final String fileName) { + this.plugin = instance; + this.folderName = folderName; + this.fileName = fileName; + } + + public void createNewFile(final String message, final String header) { + reloadConfig(); + saveConfig(); + loadConfig(header); + + if (message != null) { + plugin.getLogger().info(message); + } + } + + public FileConfiguration getConfig() { + if (config == null) { + reloadConfig(); + } + return config; + } + + public void loadConfig(final String header) { + config.options().header(header); + config.options().copyDefaults(true); + saveConfig(); + } + + public void reloadConfig() { + if (configFile == null) { + configFile = new File(plugin.getDataFolder() + folderName, fileName); + } + config = YamlConfiguration.loadConfiguration(configFile); + } + + public void saveConfig() { + if (config == null || configFile == null) { + return; + } + try { + getConfig().save(configFile); + } catch (final IOException ex) { + plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/utils/Debugger.java b/src/main/java/com/songoda/epicvouchers/utils/Debugger.java new file mode 100644 index 0000000..4740f29 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/utils/Debugger.java @@ -0,0 +1,31 @@ +package com.songoda.epicvouchers.utils; + +import com.songoda.epicvouchers.EpicVouchers; + +/** + * Created by songoda on 3/21/2017. + */ +public class Debugger { + + + public static void runReport(Exception e) { + if (isDebug()) { + System.out.println("=============================================================="); + System.out.println("The following is an error encountered in EpicVouchers."); + System.out.println("--------------------------------------------------------------"); + e.printStackTrace(); + System.out.println("=============================================================="); + } + sendReport(e); + } + + public static void sendReport(Exception e) { + + } + + public static boolean isDebug() { + EpicVouchers plugin = EpicVouchers.getInstance(); + return plugin.getConfig().getBoolean("System.Debugger Enabled"); + } + +} diff --git a/src/main/java/com/songoda/epicvouchers/utils/Methods.java b/src/main/java/com/songoda/epicvouchers/utils/Methods.java new file mode 100644 index 0000000..935c1fb --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/utils/Methods.java @@ -0,0 +1,21 @@ +package com.songoda.epicvouchers.utils; + +import org.bukkit.ChatColor; + +public class Methods { + + public static String formatText(String text) { + if (text == null || text.equals("")) + return ""; + return formatText(text, false); + } + + public static String formatText(String text, boolean cap) { + if (text == null || text.equals("")) + return ""; + if (cap) + text = text.substring(0, 1).toUpperCase() + text.substring(1); + return ChatColor.translateAlternateColorCodes('&', text); + } + +} diff --git a/src/main/java/com/songoda/epicvouchers/utils/ServerVersion.java b/src/main/java/com/songoda/epicvouchers/utils/ServerVersion.java new file mode 100644 index 0000000..5f8a28a --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/utils/ServerVersion.java @@ -0,0 +1,26 @@ +package com.songoda.epicvouchers.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"); + + + 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/epicvouchers/utils/SettingsManager.java b/src/main/java/com/songoda/epicvouchers/utils/SettingsManager.java new file mode 100644 index 0000000..595361a --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/utils/SettingsManager.java @@ -0,0 +1,47 @@ +package com.songoda.epicvouchers.utils; + +import com.songoda.epicvouchers.EpicVouchers; +import org.bukkit.event.Listener; + +/** + * Created by songo on 6/4/2017. + */ +public class SettingsManager implements Listener { + + private final EpicVouchers instance; + + public SettingsManager(EpicVouchers instance) { + this.instance = instance; + instance.getServer().getPluginManager().registerEvents(this, instance); + } + + public void updateSettings() { + for (settings s : settings.values()) { + instance.getConfig().addDefault(s.setting, s.option); + } + } + + public enum settings { + + CONFIRM_FILL_GLASS("Interface.Fill Interfaces With Glass", true), + COOLDOWN_DELAY("Main.Cooldown Delay", 10), + + DATABASE_SUPPORT("Database.Activate Mysql Support", false), + DATABASE_IP("Database.IP", "127.0.0.1"), + DATABASE_PORT("Database.Port", 3306), + DATABASE_NAME("Database.Database Name", "EpicHoppers"), + DATABASE_USERNAME("Database.Username", "PUT_USERNAME_HERE"), + DATABASE_PASSWORD("Database.Password", "PUT_PASSWORD_HERE"), + + DEBUGGER_ENABLED("System.Debugger Enabled", false); + + private String setting; + private Object option; + + settings(String setting, Object option) { + this.setting = setting; + this.option = option; + } + + } +} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/handlers/SoundHandler.java b/src/main/java/com/songoda/epicvouchers/utils/SoundUtils.java similarity index 95% rename from src/nl/marido/deluxevouchers/handlers/SoundHandler.java rename to src/main/java/com/songoda/epicvouchers/utils/SoundUtils.java index 9dce630..9e9895c 100644 --- a/src/nl/marido/deluxevouchers/handlers/SoundHandler.java +++ b/src/main/java/com/songoda/epicvouchers/utils/SoundUtils.java @@ -1,231 +1,229 @@ -package nl.marido.deluxevouchers.handlers; - -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import nl.marido.deluxevouchers.DeluxeVouchers; - -public enum SoundHandler { - - AMBIENCE_CAVE("AMBIENCE_CAVE", "AMBIENT_CAVE"), - AMBIENCE_RAIN("AMBIENCE_RAIN", "WEATHER_RAIN"), - AMBIENCE_THUNDER("AMBIENCE_THUNDER", "ENTITY_LIGHTNING_THUNDER", "ENTITY_LIGHTNING_BOLT_THUNDER"), - ANVIL_BREAK("ANVIL_BREAK", "BLOCK_ANVIL_BREAK"), - ANVIL_LAND("ANVIL_LAND", "BLOCK_ANVIL_LAND"), - ANVIL_USE("ANVIL_USE", "BLOCK_ANVIL_USE"), - ARROW_HIT("ARROW_HIT", "ENTITY_ARROW_HIT"), - BURP("BURP", "ENTITY_PLAYER_BURP"), - CHEST_CLOSE("CHEST_CLOSE", "ENTITY_CHEST_CLOSE", "BLOCK_CHEST_CLOSE"), - CHEST_OPEN("CHEST_OPEN", "ENTITY_CHEST_OPEN", "BLOCK_CHEST_OPEN"), - CLICK("CLICK", "UI_BUTTON_CLICK"), - DOOR_CLOSE("DOOR_CLOSE", "BLOCK_WOODEN_DOOR_CLOSE"), - DOOR_OPEN("DOOR_OPEN", "BLOCK_WOODEN_DOOR_OPEN"), - DRINK("DRINK", "ENTITY_GENERIC_DRINK"), - EAT("EAT", "ENTITY_GENERIC_EAT"), - EXPLODE("EXPLODE", "ENTITY_GENERIC_EXPLODE"), - FALL_BIG("FALL_BIG", "ENTITY_GENERIC_BIG_FALL"), - FALL_SMALL("FALL_SMALL", "ENTITY_GENERIC_SMALL_FALL"), - FIRE("FIRE", "BLOCK_FIRE_AMBIENT"), - FIRE_IGNITE("FIRE_IGNITE", "ITEM_FLINTANDSTEEL_USE"), - FIZZ("FIZZ", "BLOCK_FIRE_EXTINGUISH"), - FUSE("FUSE", "ENTITY_TNT_PRIMED"), - GLASS("GLASS", "BLOCK_GLASS_BREAK"), - HURT_FLESH("HURT_FLESH", "ENTITY_PLAYER_HURT"), - ITEM_BREAK("ITEM_BREAK", "ENTITY_ITEM_BREAK"), - ITEM_PICKUP("ITEM_PICKUP", "ENTITY_ITEM_PICKUP"), - LAVA("LAVA", "BLOCK_LAVA_AMBIENT"), - LAVA_POP("LAVA_POP", "BLOCK_LAVA_POP"), - LEVEL_UP("LEVEL_UP", "ENTITY_PLAYER_LEVELUP"), - MINECART_BASE("MINECART_BASE", "ENTITY_MINECART_RIDING"), - MINECART_INSIDE("MINECART_INSIDE", "ENTITY_MINECART_RIDING"), - NOTE_BASS("NOTE_BASS", "BLOCK_NOTE_BASS", "BLOCK_NOTE_BLOCK_BASS"), - NOTE_PIANO("NOTE_PIANO", "BLOCK_NOTE_HARP", "BLOCK_NOTE_BLOCK_HARP"), - NOTE_BASS_DRUM("NOTE_BASS_DRUM", "BLOCK_NOTE_BASEDRUM", "BLOCK_NOTE_BLOCK_BASEDRUM"), - NOTE_STICKS("NOTE_STICKS", "BLOCK_NOTE_HAT", "BLOCK_NOTE_BLOCK_HAT"), - NOTE_BASS_GUITAR("NOTE_BASS_GUITAR", "BLOCK_NOTE_GUITAR", "BLOCK_NOTE_BLOCK_GUITAR", "BLOCK_NOTE_BASS" /* 1.10 doesn't know guitar... */), - NOTE_SNARE_DRUM("NOTE_SNARE_DRUM", "BLOCK_NOTE_SNARE", "BLOCK_NOTE_BLOCK_SNARE"), - NOTE_PLING("NOTE_PLING", "BLOCK_NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING"), - ORB_PICKUP("ORB_PICKUP", "ENTITY_EXPERIENCE_ORB_PICKUP"), - PISTON_EXTEND("PISTON_EXTEND", "BLOCK_PISTON_EXTEND"), - PISTON_RETRACT("PISTON_RETRACT", "BLOCK_PISTON_CONTRACT"), - PORTAL("PORTAL", "BLOCK_PORTAL_AMBIENT"), - PORTAL_TRAVEL("PORTAL_TRAVEL", "BLOCK_PORTAL_TRAVEL"), - PORTAL_TRIGGER("PORTAL_TRIGGER", "BLOCK_PORTAL_TRIGGER"), - SHOOT_ARROW("SHOOT_ARROW", "ENTITY_ARROW_SHOOT"), - SPLASH("SPLASH", "ENTITY_GENERIC_SPLASH"), - SPLASH2("SPLASH2", "ENTITY_BOBBER_SPLASH", "ENTITY_FISHING_BOBBER_SPLASH"), - STEP_GRASS("STEP_GRASS", "BLOCK_GRASS_STEP"), - STEP_GRAVEL("STEP_GRAVEL", "BLOCK_GRAVEL_STEP"), - STEP_LADDER("STEP_LADDER", "BLOCK_LADDER_STEP"), - STEP_SAND("STEP_SAND", "BLOCK_SAND_STEP"), - STEP_SNOW("STEP_SNOW", "BLOCK_SNOW_STEP"), - STEP_STONE("STEP_STONE", "BLOCK_STONE_STEP"), - STEP_WOOD("STEP_WOOD", "BLOCK_WOOD_STEP"), - STEP_WOOL("STEP_WOOL", "BLOCK_CLOTH_STEP", "BLOCK_WOOL_STEP"), - SWIM("SWIM", "ENTITY_GENERIC_SWIM"), - WATER("WATER", "BLOCK_WATER_AMBIENT"), - WOOD_CLICK("WOOD_CLICK", "BLOCK_WOOD_BUTTON_CLICK_ON", "BLOCK_WOODEN_BUTTON_CLICK_ON"), - BAT_DEATH("BAT_DEATH", "ENTITY_BAT_DEATH"), - BAT_HURT("BAT_HURT", "ENTITY_BAT_HURT"), - BAT_IDLE("BAT_IDLE", "ENTITY_BAT_AMBIENT"), - BAT_LOOP("BAT_LOOP", "ENTITY_BAT_LOOP"), - BAT_TAKEOFF("BAT_TAKEOFF", "ENTITY_BAT_TAKEOFF"), - BLAZE_BREATH("BLAZE_BREATH", "ENTITY_BLAZE_AMBIENT"), - BLAZE_DEATH("BLAZE_DEATH", "ENTITY_BLAZE_DEATH"), - BLAZE_HIT("BLAZE_HIT", "ENTITY_BLAZE_HURT"), - CAT_HISS("CAT_HISS", "ENTITY_CAT_HISS"), - CAT_HIT("CAT_HIT", "ENTITY_CAT_HURT"), - CAT_MEOW("CAT_MEOW", "ENTITY_CAT_AMBIENT"), - CAT_PURR("CAT_PURR", "ENTITY_CAT_PURR"), - CAT_PURREOW("CAT_PURREOW", "ENTITY_CAT_PURREOW"), - CHICKEN_IDLE("CHICKEN_IDLE", "ENTITY_CHICKEN_AMBIENT"), - CHICKEN_HURT("CHICKEN_HURT", "ENTITY_CHICKEN_HURT"), - CHICKEN_EGG_POP("CHICKEN_EGG_POP", "ENTITY_CHICKEN_EGG"), - CHICKEN_WALK("CHICKEN_WALK", "ENTITY_CHICKEN_STEP"), - COW_IDLE("COW_IDLE", "ENTITY_COW_AMBIENT"), - COW_HURT("COW_HURT", "ENTITY_COW_HURT"), - COW_WALK("COW_WALK", "ENTITY_COW_STEP"), - CREEPER_HISS("CREEPER_HISS", "ENTITY_CREEPER_PRIMED"), - CREEPER_DEATH("CREEPER_DEATH", "ENTITY_CREEPER_DEATH"), - ENDERDRAGON_DEATH("ENDERDRAGON_DEATH", "ENTITY_ENDERDRAGON_DEATH", "ENTITY_ENDER_DRAGON_DEATH"), - ENDERDRAGON_GROWL("ENDERDRAGON_GROWL", "ENTITY_ENDERDRAGON_GROWL", "ENTITY_ENDER_DRAGON_GROWL"), - ENDERDRAGON_HIT("ENDERDRAGON_HIT", "ENTITY_ENDERDRAGON_HURT", "ENTITY_ENDER_DRAGON_HURT"), - ENDERDRAGON_WINGS("ENDERDRAGON_WINGS", "ENTITY_ENDERDRAGON_FLAP", "ENTITY_ENDER_DRAGON_FLAP"), - ENDERMAN_DEATH("ENDERMAN_DEATH", "ENTITY_ENDERMEN_DEATH", "ENTITY_ENDERMAN_DEATH"), - ENDERMAN_HIT("ENDERMAN_HIT", "ENTITY_ENDERMEN_HURT", "ENTITY_ENDERMAN_HURT"), - ENDERMAN_IDLE("ENDERMAN_IDLE", "ENTITY_ENDERMEN_AMBIENT", "ENTITY_ENDERMAN_AMBIENT"), - ENDERMAN_TELEPORT("ENDERMAN_TELEPORT", "ENTITY_ENDERMEN_TELEPORT", "ENTITY_ENDERMAN_TELEPORT"), - ENDERMAN_SCREAM("ENDERMAN_SCREAM", "ENTITY_ENDERMEN_SCREAM", "ENTITY_ENDERMAN_SCREAM"), - ENDERMAN_STARE("ENDERMAN_STARE", "ENTITY_ENDERMEN_STARE", "ENTITY_ENDERMAN_STARE"), - GHAST_SCREAM("GHAST_SCREAM", "ENTITY_GHAST_SCREAM"), - GHAST_SCREAM2("GHAST_SCREAM2", "ENTITY_GHAST_HURT"), - GHAST_CHARGE("GHAST_CHARGE", "ENTITY_GHAST_WARN"), - GHAST_DEATH("GHAST_DEATH", "ENTITY_GHAST_DEATH"), - GHAST_FIREBALL("GHAST_FIREBALL", "ENTITY_GHAST_SHOOT"), - GHAST_MOAN("GHAST_MOAN", "ENTITY_GHAST_AMBIENT"), - IRONGOLEM_ATTACK("IRONGOLEM_THROW", "ENTITY_IRONGOLEM_ATTACK", "ENTITY_IRON_GOLEM_ATTACK"), - IRONGOLEM_DEATH("IRONGOLEM_DEATH", "ENTITY_IRONGOLEM_DEATH", "ENTITY_IRON_GOLEM_DEATH"), - IRONGOLEM_HIT("IRONGOLEM_HIT", "ENTITY_IRONGOLEM_HURT", "ENTITY_IRON_GOLEM_HURT"), - IRONGOLEM_WALK("IRONGOLEM_WALK", "ENTITY_IRONGOLEM_STEP", "ENTITY_IRON_GOLEM_STEP"), - MAGMACUBE_WALK("MAGMACUBE_WALK", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH"), - MAGMACUBE_WALK2("MAGMACUBE_WALK2", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH_SMALL"), - MAGMACUBE_JUMP("MAGMACUBE_JUMP", "ENTITY_MAGMACUBE_JUMP", "ENTITY_MAGMA_CUBE_JUMP"), - PIG_IDLE("PIG_IDLE", "ENTITY_PIG_AMBIENT"), - PIG_DEATH("PIG_DEATH", "ENTITY_PIG_DEATH"), - PIG_WALK("PIG_WALK", "ENTITY_PIG_STEP"), - SHEEP_IDLE("SHEEP_IDLE", "ENTITY_SHEEP_AMBIENT"), - SHEEP_SHEAR("SHEEP_SHEAR", "ENTITY_SHEEP_SHEAR"), - SHEEP_WALK("SHEEP_WALK", "ENTITY_SHEEP_STEP"), - SILVERFISH_HIT("SILVERFISH_HIT", "ENTITY_SILVERFISH_HURT"), - SILVERFISH_KILL("SILVERFISH_KILL", "ENTITY_SILVERFISH_DEATH"), - SILVERFISH_IDLE("SILVERFISH_IDLE", "ENTITY_SILVERFISH_AMBIENT"), - SILVERFISH_WALK("SILVERFISH_WALK", "ENTITY_SILVERFISH_STEP"), - SKELETON_IDLE("SKELETON_IDLE", "ENTITY_SKELETON_AMBIENT"), - SKELETON_DEATH("SKELETON_DEATH", "ENTITY_SKELETON_DEATH"), - SKELETON_HURT("SKELETON_HURT", "ENTITY_SKELETON_HURT"), - SKELETON_WALK("SKELETON_WALK", "ENTITY_SKELETON_STEP"), - SLIME_ATTACK("SLIME_ATTACK", "ENTITY_SLIME_ATTACK"), - SLIME_WALK("SLIME_WALK", "ENTITY_SLIME_JUMP"), - SLIME_WALK2("SLIME_WALK2", "ENTITY_SLIME_SQUISH"), - SPIDER_IDLE("SPIDER_IDLE", "ENTITY_SPIDER_AMBIENT"), - SPIDER_DEATH("SPIDER_DEATH", "ENTITY_SPIDER_DEATH"), - SPIDER_WALK("SPIDER_WALK", "ENTITY_SPIDER_STEP"), - WITHER_DEATH("WITHER_DEATH", "ENTITY_WITHER_DEATH"), - WITHER_HURT("WITHER_HURT", "ENTITY_WITHER_HURT"), - WITHER_IDLE("WITHER_IDLE", "ENTITY_WITHER_AMBIENT"), - WITHER_SHOOT("WITHER_SHOOT", "ENTITY_WITHER_SHOOT"), - WITHER_SPAWN("WITHER_SPAWN", "ENTITY_WITHER_SPAWN"), - WOLF_BARK("WOLF_BARK", "ENTITY_WOLF_AMBIENT"), - WOLF_DEATH("WOLF_DEATH", "ENTITY_WOLF_DEATH"), - WOLF_GROWL("WOLF_GROWL", "ENTITY_WOLF_GROWL"), - WOLF_HOWL("WOLF_HOWL", "ENTITY_WOLF_HOWL"), - WOLF_HURT("WOLF_HURT", "ENTITY_WOLF_HURT"), - WOLF_PANT("WOLF_PANT", "ENTITY_WOLF_PANT"), - WOLF_SHAKE("WOLF_SHAKE", "ENTITY_WOLF_SHAKE"), - WOLF_WALK("WOLF_WALK", "ENTITY_WOLF_STEP"), - WOLF_WHINE("WOLF_WHINE", "ENTITY_WOLF_WHINE"), - ZOMBIE_METAL("ZOMBIE_METAL", "ENTITY_ZOMBIE_ATTACK_IRON_DOOR"), - ZOMBIE_WOOD("ZOMBIE_WOOD", "ENTITY_ZOMBIE_ATTACK_DOOR_WOOD", "ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR"), - ZOMBIE_WOODBREAK("ZOMBIE_WOODBREAK", "ENTITY_ZOMBIE_BREAK_DOOR_WOOD", "ENTITY_ZOMBIE_BREAK_WOODEN_DOOR"), - ZOMBIE_IDLE("ZOMBIE_IDLE", "ENTITY_ZOMBIE_AMBIENT"), - ZOMBIE_DEATH("ZOMBIE_DEATH", "ENTITY_ZOMBIE_DEATH"), - ZOMBIE_HURT("ZOMBIE_HURT", "ENTITY_ZOMBIE_HURT"), - ZOMBIE_INFECT("ZOMBIE_INFECT", "ENTITY_ZOMBIE_INFECT"), - ZOMBIE_UNFECT("ZOMBIE_UNFECT", "ENTITY_ZOMBIE_VILLAGER_CONVERTED"), - ZOMBIE_REMEDY("ZOMBIE_REMEDY", "ENTITY_ZOMBIE_VILLAGER_CURE"), - ZOMBIE_WALK("ZOMBIE_WALK", "ENTITY_ZOMBIE_STEP"), - ZOMBIE_PIG_IDLE("ZOMBIE_PIG_IDLE", "ENTITY_ZOMBIE_PIG_AMBIENT", "ENTITY_ZOMBIE_PIGMAN_AMBIENT"), - ZOMBIE_PIG_ANGRY("ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIGMAN_ANGRY"), - ZOMBIE_PIG_DEATH("ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIGMAN_DEATH"), - ZOMBIE_PIG_HURT("ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIGMAN_HURT"), - DIG_WOOL("DIG_WOOL", "BLOCK_CLOTH_BREAK", "BLOCK_WOOL_BREAK"), - DIG_GRASS("DIG_GRASS", "BLOCK_GRASS_BREAK"), - DIG_GRAVEL("DIG_GRAVEL", "BLOCK_GRAVEL_BREAK"), - DIG_SAND("DIG_SAND", "BLOCK_SAND_BREAK"), - DIG_SNOW("DIG_SNOW", "BLOCK_SNOW_BREAK"), - DIG_STONE("DIG_STONE", "BLOCK_STONE_BREAK"), - DIG_WOOD("DIG_WOOD", "BLOCK_WOOD_BREAK"), - FIREWORK_BLAST("FIREWORK_BLAST", "ENTITY_FIREWORK_BLAST", "ENTITY_FIREWORK_ROCKET_BLAST"), - FIREWORK_BLAST2("FIREWORK_BLAST2", "ENTITY_FIREWORK_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_BLAST_FAR"), - FIREWORK_LARGE_BLAST("FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST"), - FIREWORK_LARGE_BLAST2("FIREWORK_LARGE_BLAST2", "ENTITY_FIREWORK_LARGE_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR"), - FIREWORK_LAUNCH("FIREWORK_LAUNCH", "ENTITY_FIREWORK_LAUNCH", "ENTITY_FIREWORK_ROCKET_LAUNCH"), - FIREWORK_TWINKLE("FIREWORK_TWINKLE", "ENTITY_FIREWORK_TWINKLE", "ENTITY_FIREWORK_ROCKET_TWINKLE"), - FIREWORK_TWINKLE2("FIREWORK_TWINKLE2", "ENTITY_FIREWORK_TWINKLE_FAR", "ENTITY_FIREWORK_ROCKET_TWINKLE_FAR"), - SUCCESSFUL_HIT("SUCCESSFUL_HIT", "ENTITY_PLAYER_ATTACK_STRONG"), - HORSE_ANGRY("HORSE_ANGRY", "ENTITY_HORSE_ANGRY"), - HORSE_ARMOR("HORSE_ARMOR", "ENTITY_HORSE_ARMOR"), - HORSE_BREATHE("HORSE_BREATHE", "ENTITY_HORSE_BREATHE"), - HORSE_DEATH("HORSE_DEATH", "ENTITY_HORSE_DEATH"), - HORSE_GALLOP("HORSE_GALLOP", "ENTITY_HORSE_GALLOP"), - HORSE_HIT("HORSE_HIT", "ENTITY_HORSE_HURT"), - HORSE_IDLE("HORSE_IDLE", "ENTITY_HORSE_AMBIENT"), - HORSE_JUMP("HORSE_JUMP", "ENTITY_HORSE_JUMP"), - HORSE_LAND("HORSE_LAND", "ENTITY_HORSE_LAND"), - HORSE_SADDLE("HORSE_SADDLE", "ENTITY_HORSE_SADDLE"), - HORSE_SOFT("HORSE_SOFT", "ENTITY_HORSE_STEP"), - HORSE_WOOD("HORSE_WOOD", "ENTITY_HORSE_STEP_WOOD"), - DONKEY_ANGRY("DONKEY_ANGRY", "ENTITY_DONKEY_ANGRY"), - DONKEY_DEATH("DONKEY_DEATH", "ENTITY_DONKEY_DEATH"), - DONKEY_HIT("DONKEY_HIT", "ENTITY_DONKEY_HURT"), - DONKEY_IDLE("DONKEY_IDLE", "ENTITY_DONKEY_AMBIENT"), - HORSE_SKELETON_DEATH("HORSE_SKELETON_DEATH", "ENTITY_SKELETON_HORSE_DEATH"), - HORSE_SKELETON_HIT("HORSE_SKELETON_HIT", "ENTITY_SKELETON_HORSE_HURT"), - HORSE_SKELETON_IDLE("HORSE_SKELETON_IDLE", "ENTITY_SKELETON_HORSE_AMBIENT"), - HORSE_ZOMBIE_DEATH("HORSE_ZOMBIE_DEATH", "ENTITY_ZOMBIE_HORSE_DEATH"), - HORSE_ZOMBIE_HIT("HORSE_ZOMBIE_HIT", "ENTITY_ZOMBIE_HORSE_HURT"), - HORSE_ZOMBIE_IDLE("HORSE_ZOMBIE_IDLE", "ENTITY_ZOMBIE_HORSE_AMBIENT"), - VILLAGER_DEATH("VILLAGER_DEATH", "ENTITY_VILLAGER_DEATH"), - VILLAGER_TRADE("VILLAGER_HAGGLE", "ENTITY_VILLAGER_TRADING", "ENTITY_VILLAGER_TRADE"), - VILLAGER_HIT("VILLAGER_HIT", "ENTITY_VILLAGER_HURT"), - VILLAGER_IDLE("VILLAGER_IDLE", "ENTITY_VILLAGER_AMBIENT"), - VILLAGER_NO("VILLAGER_NO", "ENTITY_VILLAGER_NO"), - VILLAGER_YES("VILLAGER_YES", "ENTITY_VILLAGER_YES"); - - private String[] versionname; - private Sound cached = null; - - SoundHandler(String... versionname) { - this.versionname = versionname; - } - - public Sound bukkitSound() { - if (cached != null) - return cached; - for (String name : versionname) { - try { - return cached = Sound.valueOf(name); - } catch (Exception error) { - } - } - DeluxeVouchers.printConsole("&cFailed to find the sound enum called " + cached + "."); - return null; - } - - public static void playSound(Player player, String sound, int pitch) { - if (!sound.isEmpty()) { - player.playSound(player.getLocation(), SoundHandler.valueOf(sound).bukkitSound(), Integer.MAX_VALUE, pitch); - } - } - +package com.songoda.epicvouchers.utils; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +public enum SoundUtils { + + AMBIENCE_CAVE("AMBIENCE_CAVE", "AMBIENT_CAVE"), + AMBIENCE_RAIN("AMBIENCE_RAIN", "WEATHER_RAIN"), + AMBIENCE_THUNDER("AMBIENCE_THUNDER", "ENTITY_LIGHTNING_THUNDER", "ENTITY_LIGHTNING_BOLT_THUNDER"), + ANVIL_BREAK("ANVIL_BREAK", "BLOCK_ANVIL_BREAK"), + ANVIL_LAND("ANVIL_LAND", "BLOCK_ANVIL_LAND"), + ANVIL_USE("ANVIL_USE", "BLOCK_ANVIL_USE"), + ARROW_HIT("ARROW_HIT", "ENTITY_ARROW_HIT"), + BURP("BURP", "ENTITY_PLAYER_BURP"), + CHEST_CLOSE("CHEST_CLOSE", "ENTITY_CHEST_CLOSE", "BLOCK_CHEST_CLOSE"), + CHEST_OPEN("CHEST_OPEN", "ENTITY_CHEST_OPEN", "BLOCK_CHEST_OPEN"), + CLICK("CLICK", "UI_BUTTON_CLICK"), + DOOR_CLOSE("DOOR_CLOSE", "BLOCK_WOODEN_DOOR_CLOSE"), + DOOR_OPEN("DOOR_OPEN", "BLOCK_WOODEN_DOOR_OPEN"), + DRINK("DRINK", "ENTITY_GENERIC_DRINK"), + EAT("EAT", "ENTITY_GENERIC_EAT"), + EXPLODE("EXPLODE", "ENTITY_GENERIC_EXPLODE"), + FALL_BIG("FALL_BIG", "ENTITY_GENERIC_BIG_FALL"), + FALL_SMALL("FALL_SMALL", "ENTITY_GENERIC_SMALL_FALL"), + FIRE("FIRE", "BLOCK_FIRE_AMBIENT"), + FIRE_IGNITE("FIRE_IGNITE", "ITEM_FLINTANDSTEEL_USE"), + FIZZ("FIZZ", "BLOCK_FIRE_EXTINGUISH"), + FUSE("FUSE", "ENTITY_TNT_PRIMED"), + GLASS("GLASS", "BLOCK_GLASS_BREAK"), + HURT_FLESH("HURT_FLESH", "ENTITY_PLAYER_HURT"), + ITEM_BREAK("ITEM_BREAK", "ENTITY_ITEM_BREAK"), + ITEM_PICKUP("ITEM_PICKUP", "ENTITY_ITEM_PICKUP"), + LAVA("LAVA", "BLOCK_LAVA_AMBIENT"), + LAVA_POP("LAVA_POP", "BLOCK_LAVA_POP"), + LEVEL_UP("LEVEL_UP", "ENTITY_PLAYER_LEVELUP"), + MINECART_BASE("MINECART_BASE", "ENTITY_MINECART_RIDING"), + MINECART_INSIDE("MINECART_INSIDE", "ENTITY_MINECART_RIDING"), + NOTE_BASS("NOTE_BASS", "BLOCK_NOTE_BASS", "BLOCK_NOTE_BLOCK_BASS"), + NOTE_PIANO("NOTE_PIANO", "BLOCK_NOTE_HARP", "BLOCK_NOTE_BLOCK_HARP"), + NOTE_BASS_DRUM("NOTE_BASS_DRUM", "BLOCK_NOTE_BASEDRUM", "BLOCK_NOTE_BLOCK_BASEDRUM"), + NOTE_STICKS("NOTE_STICKS", "BLOCK_NOTE_HAT", "BLOCK_NOTE_BLOCK_HAT"), + NOTE_BASS_GUITAR("NOTE_BASS_GUITAR", "BLOCK_NOTE_GUITAR", "BLOCK_NOTE_BLOCK_GUITAR", "BLOCK_NOTE_BASS" /* 1.10 doesn't know guitar... */), + NOTE_SNARE_DRUM("NOTE_SNARE_DRUM", "BLOCK_NOTE_SNARE", "BLOCK_NOTE_BLOCK_SNARE"), + NOTE_PLING("NOTE_PLING", "BLOCK_NOTE_PLING", "BLOCK_NOTE_BLOCK_PLING"), + ORB_PICKUP("ORB_PICKUP", "ENTITY_EXPERIENCE_ORB_PICKUP"), + PISTON_EXTEND("PISTON_EXTEND", "BLOCK_PISTON_EXTEND"), + PISTON_RETRACT("PISTON_RETRACT", "BLOCK_PISTON_CONTRACT"), + PORTAL("PORTAL", "BLOCK_PORTAL_AMBIENT"), + PORTAL_TRAVEL("PORTAL_TRAVEL", "BLOCK_PORTAL_TRAVEL"), + PORTAL_TRIGGER("PORTAL_TRIGGER", "BLOCK_PORTAL_TRIGGER"), + SHOOT_ARROW("SHOOT_ARROW", "ENTITY_ARROW_SHOOT"), + SPLASH("SPLASH", "ENTITY_GENERIC_SPLASH"), + SPLASH2("SPLASH2", "ENTITY_BOBBER_SPLASH", "ENTITY_FISHING_BOBBER_SPLASH"), + STEP_GRASS("STEP_GRASS", "BLOCK_GRASS_STEP"), + STEP_GRAVEL("STEP_GRAVEL", "BLOCK_GRAVEL_STEP"), + STEP_LADDER("STEP_LADDER", "BLOCK_LADDER_STEP"), + STEP_SAND("STEP_SAND", "BLOCK_SAND_STEP"), + STEP_SNOW("STEP_SNOW", "BLOCK_SNOW_STEP"), + STEP_STONE("STEP_STONE", "BLOCK_STONE_STEP"), + STEP_WOOD("STEP_WOOD", "BLOCK_WOOD_STEP"), + STEP_WOOL("STEP_WOOL", "BLOCK_CLOTH_STEP", "BLOCK_WOOL_STEP"), + SWIM("SWIM", "ENTITY_GENERIC_SWIM"), + WATER("WATER", "BLOCK_WATER_AMBIENT"), + WOOD_CLICK("WOOD_CLICK", "BLOCK_WOOD_BUTTON_CLICK_ON", "BLOCK_WOODEN_BUTTON_CLICK_ON"), + BAT_DEATH("BAT_DEATH", "ENTITY_BAT_DEATH"), + BAT_HURT("BAT_HURT", "ENTITY_BAT_HURT"), + BAT_IDLE("BAT_IDLE", "ENTITY_BAT_AMBIENT"), + BAT_LOOP("BAT_LOOP", "ENTITY_BAT_LOOP"), + BAT_TAKEOFF("BAT_TAKEOFF", "ENTITY_BAT_TAKEOFF"), + BLAZE_BREATH("BLAZE_BREATH", "ENTITY_BLAZE_AMBIENT"), + BLAZE_DEATH("BLAZE_DEATH", "ENTITY_BLAZE_DEATH"), + BLAZE_HIT("BLAZE_HIT", "ENTITY_BLAZE_HURT"), + CAT_HISS("CAT_HISS", "ENTITY_CAT_HISS"), + CAT_HIT("CAT_HIT", "ENTITY_CAT_HURT"), + CAT_MEOW("CAT_MEOW", "ENTITY_CAT_AMBIENT"), + CAT_PURR("CAT_PURR", "ENTITY_CAT_PURR"), + CAT_PURREOW("CAT_PURREOW", "ENTITY_CAT_PURREOW"), + CHICKEN_IDLE("CHICKEN_IDLE", "ENTITY_CHICKEN_AMBIENT"), + CHICKEN_HURT("CHICKEN_HURT", "ENTITY_CHICKEN_HURT"), + CHICKEN_EGG_POP("CHICKEN_EGG_POP", "ENTITY_CHICKEN_EGG"), + CHICKEN_WALK("CHICKEN_WALK", "ENTITY_CHICKEN_STEP"), + COW_IDLE("COW_IDLE", "ENTITY_COW_AMBIENT"), + COW_HURT("COW_HURT", "ENTITY_COW_HURT"), + COW_WALK("COW_WALK", "ENTITY_COW_STEP"), + CREEPER_HISS("CREEPER_HISS", "ENTITY_CREEPER_PRIMED"), + CREEPER_DEATH("CREEPER_DEATH", "ENTITY_CREEPER_DEATH"), + ENDERDRAGON_DEATH("ENDERDRAGON_DEATH", "ENTITY_ENDERDRAGON_DEATH", "ENTITY_ENDER_DRAGON_DEATH"), + ENDERDRAGON_GROWL("ENDERDRAGON_GROWL", "ENTITY_ENDERDRAGON_GROWL", "ENTITY_ENDER_DRAGON_GROWL"), + ENDERDRAGON_HIT("ENDERDRAGON_HIT", "ENTITY_ENDERDRAGON_HURT", "ENTITY_ENDER_DRAGON_HURT"), + ENDERDRAGON_WINGS("ENDERDRAGON_WINGS", "ENTITY_ENDERDRAGON_FLAP", "ENTITY_ENDER_DRAGON_FLAP"), + ENDERMAN_DEATH("ENDERMAN_DEATH", "ENTITY_ENDERMEN_DEATH", "ENTITY_ENDERMAN_DEATH"), + ENDERMAN_HIT("ENDERMAN_HIT", "ENTITY_ENDERMEN_HURT", "ENTITY_ENDERMAN_HURT"), + ENDERMAN_IDLE("ENDERMAN_IDLE", "ENTITY_ENDERMEN_AMBIENT", "ENTITY_ENDERMAN_AMBIENT"), + ENDERMAN_TELEPORT("ENDERMAN_TELEPORT", "ENTITY_ENDERMEN_TELEPORT", "ENTITY_ENDERMAN_TELEPORT"), + ENDERMAN_SCREAM("ENDERMAN_SCREAM", "ENTITY_ENDERMEN_SCREAM", "ENTITY_ENDERMAN_SCREAM"), + ENDERMAN_STARE("ENDERMAN_STARE", "ENTITY_ENDERMEN_STARE", "ENTITY_ENDERMAN_STARE"), + GHAST_SCREAM("GHAST_SCREAM", "ENTITY_GHAST_SCREAM"), + GHAST_SCREAM2("GHAST_SCREAM2", "ENTITY_GHAST_HURT"), + GHAST_CHARGE("GHAST_CHARGE", "ENTITY_GHAST_WARN"), + GHAST_DEATH("GHAST_DEATH", "ENTITY_GHAST_DEATH"), + GHAST_FIREBALL("GHAST_FIREBALL", "ENTITY_GHAST_SHOOT"), + GHAST_MOAN("GHAST_MOAN", "ENTITY_GHAST_AMBIENT"), + IRONGOLEM_ATTACK("IRONGOLEM_THROW", "ENTITY_IRONGOLEM_ATTACK", "ENTITY_IRON_GOLEM_ATTACK"), + IRONGOLEM_DEATH("IRONGOLEM_DEATH", "ENTITY_IRONGOLEM_DEATH", "ENTITY_IRON_GOLEM_DEATH"), + IRONGOLEM_HIT("IRONGOLEM_HIT", "ENTITY_IRONGOLEM_HURT", "ENTITY_IRON_GOLEM_HURT"), + IRONGOLEM_WALK("IRONGOLEM_WALK", "ENTITY_IRONGOLEM_STEP", "ENTITY_IRON_GOLEM_STEP"), + MAGMACUBE_WALK("MAGMACUBE_WALK", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH"), + MAGMACUBE_WALK2("MAGMACUBE_WALK2", "ENTITY_MAGMACUBE_SQUISH", "ENTITY_MAGMA_CUBE_SQUISH_SMALL"), + MAGMACUBE_JUMP("MAGMACUBE_JUMP", "ENTITY_MAGMACUBE_JUMP", "ENTITY_MAGMA_CUBE_JUMP"), + PIG_IDLE("PIG_IDLE", "ENTITY_PIG_AMBIENT"), + PIG_DEATH("PIG_DEATH", "ENTITY_PIG_DEATH"), + PIG_WALK("PIG_WALK", "ENTITY_PIG_STEP"), + SHEEP_IDLE("SHEEP_IDLE", "ENTITY_SHEEP_AMBIENT"), + SHEEP_SHEAR("SHEEP_SHEAR", "ENTITY_SHEEP_SHEAR"), + SHEEP_WALK("SHEEP_WALK", "ENTITY_SHEEP_STEP"), + SILVERFISH_HIT("SILVERFISH_HIT", "ENTITY_SILVERFISH_HURT"), + SILVERFISH_KILL("SILVERFISH_KILL", "ENTITY_SILVERFISH_DEATH"), + SILVERFISH_IDLE("SILVERFISH_IDLE", "ENTITY_SILVERFISH_AMBIENT"), + SILVERFISH_WALK("SILVERFISH_WALK", "ENTITY_SILVERFISH_STEP"), + SKELETON_IDLE("SKELETON_IDLE", "ENTITY_SKELETON_AMBIENT"), + SKELETON_DEATH("SKELETON_DEATH", "ENTITY_SKELETON_DEATH"), + SKELETON_HURT("SKELETON_HURT", "ENTITY_SKELETON_HURT"), + SKELETON_WALK("SKELETON_WALK", "ENTITY_SKELETON_STEP"), + SLIME_ATTACK("SLIME_ATTACK", "ENTITY_SLIME_ATTACK"), + SLIME_WALK("SLIME_WALK", "ENTITY_SLIME_JUMP"), + SLIME_WALK2("SLIME_WALK2", "ENTITY_SLIME_SQUISH"), + SPIDER_IDLE("SPIDER_IDLE", "ENTITY_SPIDER_AMBIENT"), + SPIDER_DEATH("SPIDER_DEATH", "ENTITY_SPIDER_DEATH"), + SPIDER_WALK("SPIDER_WALK", "ENTITY_SPIDER_STEP"), + WITHER_DEATH("WITHER_DEATH", "ENTITY_WITHER_DEATH"), + WITHER_HURT("WITHER_HURT", "ENTITY_WITHER_HURT"), + WITHER_IDLE("WITHER_IDLE", "ENTITY_WITHER_AMBIENT"), + WITHER_SHOOT("WITHER_SHOOT", "ENTITY_WITHER_SHOOT"), + WITHER_SPAWN("WITHER_SPAWN", "ENTITY_WITHER_SPAWN"), + WOLF_BARK("WOLF_BARK", "ENTITY_WOLF_AMBIENT"), + WOLF_DEATH("WOLF_DEATH", "ENTITY_WOLF_DEATH"), + WOLF_GROWL("WOLF_GROWL", "ENTITY_WOLF_GROWL"), + WOLF_HOWL("WOLF_HOWL", "ENTITY_WOLF_HOWL"), + WOLF_HURT("WOLF_HURT", "ENTITY_WOLF_HURT"), + WOLF_PANT("WOLF_PANT", "ENTITY_WOLF_PANT"), + WOLF_SHAKE("WOLF_SHAKE", "ENTITY_WOLF_SHAKE"), + WOLF_WALK("WOLF_WALK", "ENTITY_WOLF_STEP"), + WOLF_WHINE("WOLF_WHINE", "ENTITY_WOLF_WHINE"), + ZOMBIE_METAL("ZOMBIE_METAL", "ENTITY_ZOMBIE_ATTACK_IRON_DOOR"), + ZOMBIE_WOOD("ZOMBIE_WOOD", "ENTITY_ZOMBIE_ATTACK_DOOR_WOOD", "ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR"), + ZOMBIE_WOODBREAK("ZOMBIE_WOODBREAK", "ENTITY_ZOMBIE_BREAK_DOOR_WOOD", "ENTITY_ZOMBIE_BREAK_WOODEN_DOOR"), + ZOMBIE_IDLE("ZOMBIE_IDLE", "ENTITY_ZOMBIE_AMBIENT"), + ZOMBIE_DEATH("ZOMBIE_DEATH", "ENTITY_ZOMBIE_DEATH"), + ZOMBIE_HURT("ZOMBIE_HURT", "ENTITY_ZOMBIE_HURT"), + ZOMBIE_INFECT("ZOMBIE_INFECT", "ENTITY_ZOMBIE_INFECT"), + ZOMBIE_UNFECT("ZOMBIE_UNFECT", "ENTITY_ZOMBIE_VILLAGER_CONVERTED"), + ZOMBIE_REMEDY("ZOMBIE_REMEDY", "ENTITY_ZOMBIE_VILLAGER_CURE"), + ZOMBIE_WALK("ZOMBIE_WALK", "ENTITY_ZOMBIE_STEP"), + ZOMBIE_PIG_IDLE("ZOMBIE_PIG_IDLE", "ENTITY_ZOMBIE_PIG_AMBIENT", "ENTITY_ZOMBIE_PIGMAN_AMBIENT"), + ZOMBIE_PIG_ANGRY("ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIG_ANGRY", "ENTITY_ZOMBIE_PIGMAN_ANGRY"), + ZOMBIE_PIG_DEATH("ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIG_DEATH", "ENTITY_ZOMBIE_PIGMAN_DEATH"), + ZOMBIE_PIG_HURT("ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIG_HURT", "ENTITY_ZOMBIE_PIGMAN_HURT"), + DIG_WOOL("DIG_WOOL", "BLOCK_CLOTH_BREAK", "BLOCK_WOOL_BREAK"), + DIG_GRASS("DIG_GRASS", "BLOCK_GRASS_BREAK"), + DIG_GRAVEL("DIG_GRAVEL", "BLOCK_GRAVEL_BREAK"), + DIG_SAND("DIG_SAND", "BLOCK_SAND_BREAK"), + DIG_SNOW("DIG_SNOW", "BLOCK_SNOW_BREAK"), + DIG_STONE("DIG_STONE", "BLOCK_STONE_BREAK"), + DIG_WOOD("DIG_WOOD", "BLOCK_WOOD_BREAK"), + FIREWORK_BLAST("FIREWORK_BLAST", "ENTITY_FIREWORK_BLAST", "ENTITY_FIREWORK_ROCKET_BLAST"), + FIREWORK_BLAST2("FIREWORK_BLAST2", "ENTITY_FIREWORK_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_BLAST_FAR"), + FIREWORK_LARGE_BLAST("FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_LARGE_BLAST", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST"), + FIREWORK_LARGE_BLAST2("FIREWORK_LARGE_BLAST2", "ENTITY_FIREWORK_LARGE_BLAST_FAR", "ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR"), + FIREWORK_LAUNCH("FIREWORK_LAUNCH", "ENTITY_FIREWORK_LAUNCH", "ENTITY_FIREWORK_ROCKET_LAUNCH"), + FIREWORK_TWINKLE("FIREWORK_TWINKLE", "ENTITY_FIREWORK_TWINKLE", "ENTITY_FIREWORK_ROCKET_TWINKLE"), + FIREWORK_TWINKLE2("FIREWORK_TWINKLE2", "ENTITY_FIREWORK_TWINKLE_FAR", "ENTITY_FIREWORK_ROCKET_TWINKLE_FAR"), + SUCCESSFUL_HIT("SUCCESSFUL_HIT", "ENTITY_PLAYER_ATTACK_STRONG"), + HORSE_ANGRY("HORSE_ANGRY", "ENTITY_HORSE_ANGRY"), + HORSE_ARMOR("HORSE_ARMOR", "ENTITY_HORSE_ARMOR"), + HORSE_BREATHE("HORSE_BREATHE", "ENTITY_HORSE_BREATHE"), + HORSE_DEATH("HORSE_DEATH", "ENTITY_HORSE_DEATH"), + HORSE_GALLOP("HORSE_GALLOP", "ENTITY_HORSE_GALLOP"), + HORSE_HIT("HORSE_HIT", "ENTITY_HORSE_HURT"), + HORSE_IDLE("HORSE_IDLE", "ENTITY_HORSE_AMBIENT"), + HORSE_JUMP("HORSE_JUMP", "ENTITY_HORSE_JUMP"), + HORSE_LAND("HORSE_LAND", "ENTITY_HORSE_LAND"), + HORSE_SADDLE("HORSE_SADDLE", "ENTITY_HORSE_SADDLE"), + HORSE_SOFT("HORSE_SOFT", "ENTITY_HORSE_STEP"), + HORSE_WOOD("HORSE_WOOD", "ENTITY_HORSE_STEP_WOOD"), + DONKEY_ANGRY("DONKEY_ANGRY", "ENTITY_DONKEY_ANGRY"), + DONKEY_DEATH("DONKEY_DEATH", "ENTITY_DONKEY_DEATH"), + DONKEY_HIT("DONKEY_HIT", "ENTITY_DONKEY_HURT"), + DONKEY_IDLE("DONKEY_IDLE", "ENTITY_DONKEY_AMBIENT"), + HORSE_SKELETON_DEATH("HORSE_SKELETON_DEATH", "ENTITY_SKELETON_HORSE_DEATH"), + HORSE_SKELETON_HIT("HORSE_SKELETON_HIT", "ENTITY_SKELETON_HORSE_HURT"), + HORSE_SKELETON_IDLE("HORSE_SKELETON_IDLE", "ENTITY_SKELETON_HORSE_AMBIENT"), + HORSE_ZOMBIE_DEATH("HORSE_ZOMBIE_DEATH", "ENTITY_ZOMBIE_HORSE_DEATH"), + HORSE_ZOMBIE_HIT("HORSE_ZOMBIE_HIT", "ENTITY_ZOMBIE_HORSE_HURT"), + HORSE_ZOMBIE_IDLE("HORSE_ZOMBIE_IDLE", "ENTITY_ZOMBIE_HORSE_AMBIENT"), + VILLAGER_DEATH("VILLAGER_DEATH", "ENTITY_VILLAGER_DEATH"), + VILLAGER_TRADE("VILLAGER_HAGGLE", "ENTITY_VILLAGER_TRADING", "ENTITY_VILLAGER_TRADE"), + VILLAGER_HIT("VILLAGER_HIT", "ENTITY_VILLAGER_HURT"), + VILLAGER_IDLE("VILLAGER_IDLE", "ENTITY_VILLAGER_AMBIENT"), + VILLAGER_NO("VILLAGER_NO", "ENTITY_VILLAGER_NO"), + VILLAGER_YES("VILLAGER_YES", "ENTITY_VILLAGER_YES"); + + private String[] versionname; + private Sound cached = null; + + SoundUtils(String... versionname) { + this.versionname = versionname; + } + + public Sound bukkitSound() { + if (cached != null) + return cached; + for (String name : versionname) { + try { + return cached = Sound.valueOf(name); + } catch (Exception error) { + } + } + System.out.println(Methods.formatText("&cFailed to find the sound enum called " + cached + ".")); + return null; + } + + public static void playSound(Player player, String sound, int pitch) { + if (!sound.isEmpty()) { + player.playSound(player.getLocation(), SoundUtils.valueOf(sound).bukkitSound(), Integer.MAX_VALUE, pitch); + } + } + } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/voucher/ClickListener.java b/src/main/java/com/songoda/epicvouchers/voucher/ClickListener.java new file mode 100644 index 0000000..dd780ba --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/voucher/ClickListener.java @@ -0,0 +1,58 @@ +package com.songoda.epicvouchers.voucher; + +import com.mysql.jdbc.Buffer; +import com.songoda.epicvouchers.EpicVouchers; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.UUID; + +public class ClickListener implements Listener { + + private final EpicVouchers instance; + + public ClickListener(EpicVouchers instance) { + this.instance = instance; + } + + @EventHandler + public void voucherListener(PlayerInteractEvent event) { + Action action = event.getAction(); + if (action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) { + return; + } + for (Voucher voucher : instance.getVoucherManager().getVouchers()) { + Player player = event.getPlayer(); + if (!player.hasPermission(voucher.getPermission())) { + return; + } + ItemStack item = event.getPlayer().getItemInHand(); + if (item.getType() != voucher.getMaterial() || item.getDurability() != voucher.getData()) { + return; + } + + ItemMeta meta = item.getItemMeta(); + if (!meta.hasDisplayName() || !meta.getDisplayName().equals(voucher.getName()) || !meta.getLore().equals(voucher.getLore())) { + return; + } + UUID uuid = player.getUniqueId(); + if (!instance.getCooldowns().getEntries().containsKey(uuid)) { + if (voucher.isConfirm()) { + EpicVouchers.getInstance().getConfirmation().confirmVoucher(player, voucher, item); + } else { + VoucherExecutor.redeemVoucher(player, voucher, item, true); + } + event.setCancelled(true); + } else { + String message = instance.getLocale().getMessage("event.general.cooldown", String.valueOf(instance.getCooldowns().getEntries().get(uuid) + 1), voucher.getName()); + player.sendMessage(message); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/voucher/Cooldowns.java b/src/main/java/com/songoda/epicvouchers/voucher/Cooldowns.java new file mode 100644 index 0000000..f0a19f3 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/voucher/Cooldowns.java @@ -0,0 +1,47 @@ +package com.songoda.epicvouchers.voucher; + +import java.util.Collections; +import java.util.HashMap; +import java.util.UUID; + +import com.songoda.epicvouchers.utils.Debugger; +import com.songoda.epicvouchers.utils.Methods; +import org.bukkit.Bukkit; +import org.bukkit.scheduler.BukkitRunnable; + +import com.songoda.epicvouchers.EpicVouchers; + +public class Cooldowns { + + private HashMap entries = new HashMap(); + + public void addCooldown(final UUID uuid, Voucher voucher) { + try { + if (Bukkit.getPlayer(uuid).hasPermission("epicvouchers.bypass")) { + return; + } + if (voucher.getCooldown() != 0) { + entries.put(uuid, voucher.getCooldown()); + } else { + entries.put(uuid, EpicVouchers.getInstance().getConfig().getInt("Main.Cooldown Delay")); + } + new BukkitRunnable() { + public void run() { + if (entries.get(uuid) <= 0) { + entries.remove(uuid); + cancel(); + } else { + entries.put(uuid, entries.get(uuid) - 1); + } + } + }.runTaskTimer(EpicVouchers.getInstance(), 0, 20); + } catch (Exception error) { + System.out.println(Methods.formatText("�cFailed to add cooldown to the UUID " + uuid + ".")); + Debugger.runReport(error); + } + } + + public HashMap getEntries() { + return new HashMap<>(entries); + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/voucher/Voucher.java b/src/main/java/com/songoda/epicvouchers/voucher/Voucher.java new file mode 100644 index 0000000..77ac6bf --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/voucher/Voucher.java @@ -0,0 +1,345 @@ +package com.songoda.epicvouchers.voucher; + +import com.songoda.epicvouchers.utils.Methods; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.List; + +public class Voucher { + + private final String key; + private String permission; + private Material material = Material.COOKIE; + private short data = 0; + private int cooldown = 0; + private String name; + private List lore = new ArrayList(); + private boolean glow = true; + private boolean confirm = true; + private boolean unbreakable = true; + private boolean hideAttributes = false; + private boolean removeItem = true; + private boolean feedPlayer = true; + private boolean healPlayer = true; + private boolean smiteEffect = true; + + private List broadcasts = new ArrayList(); + private List messages = new ArrayList<>(); + private List commands = new ArrayList<>(); + + private String actionBar; + + private String title = "&6Thank you."; + private String subTitle = "&eYou have redeemed the voucher %voucher%."; + private int titleFadeIn = 10; + private int titleStay = 50; + private int titleFadeOut = 10; + + private String sound = "NOTE_PLING"; + private int soundPitch = 1; + + private String particle = "FLAME"; + private int particleAmount = 100; + + private String effect = "SPEED"; + private int effectAmplifer = 2; + private int effectDuration = 10; + + public Voucher(String key) { + this.key = key; + } + + public ItemStack toItemStack() { + return toItemStack(1); + } + + public ItemStack toItemStack(int amount) { + ItemStack item = new ItemStack(material, amount, data); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(Methods.formatText(name)); + if (lore != null) { + meta.setLore(getLore()); + } + if (glow) { + meta.addEnchant(Enchantment.DURABILITY, 1, false); + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + } + if (unbreakable) { + meta.spigot().setUnbreakable(true); + } + if (hideAttributes) { + meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); + } + item.setItemMeta(meta); + return item; + } + + public String getKey() { + return key; + } + + public String getPermission() { + return permission; + } + + public void setPermission(String permission) { + this.permission = permission; + } + + public Material getMaterial() { + return material; + } + + public void setMaterial(Material material) { + this.material = material; + } + + public short getData() { + return data; + } + + public void setData(short data) { + this.data = data; + } + + public String getName() { + return Methods.formatText(name); + } + + public void setName(String name) { + this.name = name; + } + + public List getLore() { + List itemLore = new ArrayList<>(); + for (String line : lore) { + itemLore.add(Methods.formatText(line)); + } + return itemLore; + } + + public void setLore(List lore) { + this.lore = lore; + } + + public boolean isGlow() { + return glow; + } + + public void setGlow(boolean glow) { + this.glow = glow; + } + + public boolean isConfirm() { + return confirm; + } + + public void setConfirm(boolean confirm) { + this.confirm = confirm; + } + + public boolean isUnbreakable() { + return unbreakable; + } + + public void setUnbreakable(boolean unbreakable) { + this.unbreakable = unbreakable; + } + + public boolean isHideAttributes() { + return hideAttributes; + } + + public void setHideAttributes(boolean hideAttributes) { + this.hideAttributes = hideAttributes; + } + + public boolean isRemoveItem() { + return removeItem; + } + + public void setRemoveItem(boolean removeItem) { + this.removeItem = removeItem; + } + + public boolean isFeedPlayer() { + return feedPlayer; + } + + public void setFeedPlayer(boolean feedPlayer) { + this.feedPlayer = feedPlayer; + } + + public boolean isHealPlayer() { + return healPlayer; + } + + public void setHealPlayer(boolean healPlayer) { + this.healPlayer = healPlayer; + } + + public boolean isSmiteEffect() { + return smiteEffect; + } + + public void setSmiteEffect(boolean smiteEffect) { + this.smiteEffect = smiteEffect; + } + + public List getBroadcasts() { + List itemBroadcasts = new ArrayList<>(); + for (String line : broadcasts) { + itemBroadcasts.add(Methods.formatText(line)); + } + return itemBroadcasts; + } + + public void setBroadcasts(List broadcasts) { + this.broadcasts = broadcasts; + } + + public int getCooldown() { + return cooldown; + } + + public void setCooldown(int cooldown) { + this.cooldown = cooldown; + } + + public List getMessages() { + List itemMessages = new ArrayList<>(); + for (String line : lore) { + itemMessages.add(Methods.formatText(line)); + } + return itemMessages; + } + + public void setMessages(List messages) { + this.messages = messages; + } + + public List getCommands() { + return commands; + } + + public void setCommands(List commands) { + this.commands = commands; + } + + public String getActionBar() { + return Methods.formatText(actionBar); + } + + public void setActionBar(String actionBar) { + this.actionBar = actionBar; + } + + public String getTitle() { + return Methods.formatText(title); + } + + public void setTitle(String title) { + this.title = title; + } + + public String getSubTitle() { + return Methods.formatText(subTitle); + } + + public void setSubTitle(String subTitle) { + this.subTitle = subTitle; + } + + public int getTitleFadeIn() { + return titleFadeIn; + } + + public void setTitleFadeIn(int titleFadeIn) { + this.titleFadeIn = titleFadeIn; + } + + public int getTitleStay() { + return titleStay; + } + + public void setTitleStay(int titleStay) { + this.titleStay = titleStay; + } + + public int getTitleFadeOut() { + return titleFadeOut; + } + + public void setTitleFadeOut(int titleFadeOut) { + this.titleFadeOut = titleFadeOut; + } + + public String getSound() { + return sound; + } + + public void setSound(String sound) { + this.sound = sound; + } + + public int getSoundPitch() { + return soundPitch; + } + + public void setSoundPitch(int soundPitch) { + this.soundPitch = soundPitch; + } + + public String getParticle() { + return particle; + } + + public void setParticle(String particle) { + this.particle = particle; + } + + public int getParticleAmount() { + return particleAmount; + } + + public void setParticleAmount(int particleAmount) { + this.particleAmount = particleAmount; + } + + public String getEffect() { + return effect; + } + + public void setEffect(String effect) { + this.effect = effect; + } + + public int getEffectAmplifer() { + return effectAmplifer; + } + + public void setEffectAmplifer(int effectAmplifer) { + this.effectAmplifer = effectAmplifer; + } + + public int getEffectDuration() { + return effectDuration; + } + + public void setEffectDuration(int effectDuration) { + this.effectDuration = effectDuration; + } + + @Override + public String toString() { + return key; + } + +} diff --git a/src/main/java/com/songoda/epicvouchers/voucher/VoucherExecutor.java b/src/main/java/com/songoda/epicvouchers/voucher/VoucherExecutor.java new file mode 100644 index 0000000..5377306 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/voucher/VoucherExecutor.java @@ -0,0 +1,135 @@ +package com.songoda.epicvouchers.voucher; + +import com.songoda.epicvouchers.EpicVouchers; +import com.songoda.epicvouchers.events.VoucherRedeemEvent; +import com.songoda.epicvouchers.handlers.Connections; +import com.songoda.epicvouchers.handlers.PreventHacks; +import com.songoda.epicvouchers.utils.Debugger; +import com.songoda.epicvouchers.utils.SoundUtils; +import com.songoda.epicvouchers.liberaries.Bountiful; +import com.songoda.epicvouchers.utils.Methods; +import org.bukkit.Bukkit; +import org.bukkit.Effect; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class VoucherExecutor { + + public static void redeemVoucher(Player player, Voucher voucher, ItemStack item, boolean manual) { + EpicVouchers instance = EpicVouchers.getInstance(); + try { + VoucherRedeemEvent event = new VoucherRedeemEvent(player, voucher.getName(), item, manual); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + boolean duplication = false; + if (!player.getItemInHand().isSimilar(item)) { + duplication = true; + } + if (!duplication) { + if (manual) { + instance.getCooldowns().addCooldown(player.getUniqueId(), voucher); + if (voucher.isRemoveItem()) { + ItemStack clone = player.getItemInHand().clone(); + if (clone.getAmount() <= 1) { + clone.setType(Material.AIR); + } else { + clone.setAmount(clone.getAmount() - 1); + } + player.setItemInHand(clone); + player.updateInventory(); + } + } + if (voucher.isFeedPlayer()) { + player.setFoodLevel(20); + } + if (voucher.isFeedPlayer()) { + player.setHealth(player.getMaxHealth()); + } + if (voucher.isSmiteEffect()) { + player.getWorld().strikeLightningEffect(player.getLocation()); + } + String name = player.getName(); + for (String broadcast : voucher.getBroadcasts()) { + broadcast = broadcast.replaceAll("%player%", name); + broadcast = broadcast.replaceAll("%voucher%", voucher.getName()); + for (Player everyone : Bukkit.getOnlinePlayers()) { + everyone.sendMessage(broadcast); + } + } + for (String message : voucher.getMessages()) { + message = message.replaceAll("%player%", name); + message = message.replaceAll("%voucher%", voucher.getName()); + player.sendMessage(message); + } + for (String command : voucher.getCommands()) { + command = command.replaceAll("%player%", name); + command = command.replaceAll("%voucher%", voucher.getName()); + if (command.startsWith("[player]")) { + command = command.replace("[player]", ""); + player.performCommand(command); + } else if (command.startsWith("[op]")) { + command = command.replace("[op]", ""); + boolean wasop = player.isOp(); + PreventHacks.addCommand(player.getUniqueId(), command); + player.setOp(true); + player.performCommand(command); + if (!wasop) { + player.setOp(false); + } + PreventHacks.removeCommand(player.getUniqueId()); + } else if (command.startsWith("[chat]")) { + command = command.replace("[chat]", ""); + player.chat(command); + } else if (command.startsWith("[delay]")) { + command = command.replace("[delay]", ""); + throw new UnsupportedOperationException("delay is not supported yet"); + } else { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); + } + } + String actionbar = voucher.getActionBar(); + actionbar = actionbar.replaceAll("%player%", name); + actionbar = actionbar.replaceAll("%voucher%", voucher.getName()); + Bountiful.sendActionBar(player, actionbar); + String title = voucher.getTitle(); + title = title.replaceAll("%player%", name); + title = title.replaceAll("%voucher%", voucher.getName()); + String subtitle = voucher.getSubTitle(); + subtitle = subtitle.replaceAll("%player%", name); + subtitle = subtitle.replaceAll("%voucher%", voucher.getName()); + int fadein = voucher.getTitleFadeIn(); + int stay = voucher.getTitleStay(); + int fadeout = voucher.getTitleFadeOut(); + + Bountiful.sendTitle(player, fadein, stay, fadeout, title, subtitle); + String sound = voucher.getSound(); + int pitch = voucher.getSoundPitch(); + SoundUtils.playSound(player, sound, pitch); + String particle = voucher.getParticle(); + if (particle != null && !particle.isEmpty()) { + int amount = voucher.getParticleAmount(); + player.getWorld().playEffect(player.getLocation(), Effect.valueOf(particle), amount); + } + String effect = voucher.getEffect(); + if (!effect.isEmpty()) { + int amplifier = voucher.getEffectAmplifer(); + int duration = voucher.getEffectDuration() * 20; + player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(effect), duration, amplifier)); + } + System.out.println(Methods.formatText("&f" + player.getName() + " has successfully redeemed the voucher " + voucher.getKey() + ".")); + instance.getConnections().saveRedeem(player, voucher.getName()); + } else { + System.out.println(Methods.formatText("&c" + player.getName() + " has failed to duplicate the voucher " + voucher.getKey() + ".")); + } + } catch (Exception error) { + System.out.println(Methods.formatText("&cFailed to redeem the voucher " + voucher.getKey() + " for the player " + player.getName() + ".")); + Debugger.runReport(error); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicvouchers/voucher/VoucherManager.java b/src/main/java/com/songoda/epicvouchers/voucher/VoucherManager.java new file mode 100644 index 0000000..e19d201 --- /dev/null +++ b/src/main/java/com/songoda/epicvouchers/voucher/VoucherManager.java @@ -0,0 +1,30 @@ +package com.songoda.epicvouchers.voucher; + +import org.bukkit.Bukkit; + +import java.util.*; + +public class VoucherManager { + + private final Map registeredVouchers = new HashMap<>(); + + public Voucher addVoucher(String name, Voucher voucher) { + return registeredVouchers.put(name, voucher); + } + + public Voucher removeVoucher(Voucher voucher) { + return registeredVouchers.remove(voucher); + } + + public Voucher getVoucher(String name) { + for (Voucher voucher : registeredVouchers.values()) { + if (voucher.getKey().equalsIgnoreCase(name.trim())) return voucher; + } + return null; + } + + public List getVouchers() { + return new ArrayList<>(registeredVouchers.values()); + } + +} diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang new file mode 100644 index 0000000..6f0f426 --- /dev/null +++ b/src/main/resources/en_US.lang @@ -0,0 +1,38 @@ +#General Messages + +general.nametag.prefix = "&8[&6EpicVouchers&8]" + +#Interface Messages + +interface.confirmsettings.title = "&6Confirmation" +interface.confirmsettings.confirmitemname = "&2&lREDEEM" +interface.confirmsettings.confirmitemlore = "&aClick here if you want to confirm your redeem." +interface.confirmsettings.cancelitemname = "&4&lCANCEL" +interface.confirmsettings.cancelitemlore = "&cClick here if you want to cancel your redeem." +interface.editor.title = "&6Editor" +interface.editvoucher.title = "&6Editor [&e%voucher%&6]"; +interface.editvoucher.backtitle = "&4Return"; +interface.editvoucher.backlore = "&cReturn to the main menu of the editor." +interface.editvoucher.recivetitle = "&2Receive" +interface.editvoucher.recivelore = "&aReceive a clone item of this voucher." +interface.editvoucher.recivemessage = "&7You have received the voucher &6%voucher%&7." +interface.editvoucher.renametitle = "&6Rename" +interface.editvoucher.renamelore = "&eRename the display name of the voucher." +interface.editvoucher.renamemessage = "&7Please enter the name that this voucher should be renamed to." +interface.editvoucher.renamefinish = "&7Successfully renamed the voucher to &r%renamed%&7." + +#Command Messages + +command.error.noplayer = "&7That user either does not exist or is not online"; +command.error.novoucher = "&cThat voucher does not exist."; +command.error.notnumber = "&7Failed to parse that number into a valid amount." +command.reload.success = "&7Config Reloaded" +command.give.send = "&7You have received the voucher &6%voucher% &7(&6x%amount%&7)." +command.give.receive = "&7You have given &6%player% &7the voucher &6%voucher% &7(&6x%amount%&7)." +command.force.send = "&7You have forced &6%player% &7to redeem the voucher &6%voucher% &7(&6x%amount%&7)."; +command.list.list = "&7List of all vouchers: &6%list%&7." + +#Event Messages + +event.general.nopermission = "&cYou do not have permission to do that." +event.general.cooldown = "&7Please wait &6%time%&7 seconds before redeeming a new voucher." \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..67e0b52 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: EpicVouchers +main: com.songoda.epicvouchers.EpicVouchers +version: 1 +author: Songoda +website: https://songoda.host/epicvouchers +description: Enhance your server with awesome customizable vouchers with a lot of features. +api-version: 1.13 +commands: + epicvouchers: + description: Administrator commands for the EpicVouchers resource. + aliases: [dv, deluxev, dvouchers, deluxevoucher] \ No newline at end of file diff --git a/src/vouchers.yml b/src/main/resources/vouchers.yml similarity index 79% rename from src/vouchers.yml rename to src/main/resources/vouchers.yml index 0bba34f..de2bc85 100644 --- a/src/vouchers.yml +++ b/src/main/resources/vouchers.yml @@ -1,52 +1,54 @@ -vouchers: - example: - permission: "deluxevouchers.example" - material: "COOKIE" - # Keep data on 0 if you are on 1.13 or higher. - data: 0 - name: "&6Example Voucher" - lore: - - "&eThank you so much for purchasing my resource DeluxeVouchers." - - "&eListen to the wise words that this nice cookie will tell you." - - "" - - "&cWhat could be inside this voucher?" - - "&6- Marido" - glow: true - confirm: true - unbreakable: true - hide-attributes: false - remove-item: true - feed-player: true - heal-player: true - smite-effect: true - # Enter a custom cooldown if you wish to. - # cooldown: 0 - broadcasts: - - "&6&l> &e%player% has redeemed the voucher &6%voucher%&e. &6&l<" - - "&cUseful addons: [chat] [player], and [op]." - - "&cDo not add them to let the console execute it." - messages: - - "&bYou have redeemed the voucher &6%voucher% &bsuccessfully." - commands: - - "give %player% stick 1" - - "[chat]I love DeluxeVouchers!" - # You can use [chat], [player] and [op]. - # Also use [delay-10] for 10 seconds delay. - # Change 10 to any number you want to have. - actionbar: "&6Actionbar works on every version." - titles: - title: "&6Thank you." - subtitle: "&eYou have redeemed the voucher %voucher%." - fade-in: 10 - stay: 50 - fade-out: 10 - sounds: - sound: "NOTE_PLING" - pitch: 1 - particles: - particle: "FLAME" - amount: 100 - effects: - effect: "SPEED" - amplifier: 2 +vouchers: + example: + permission: "epicvouchers.example" + material: "COOKIE" + # Keep data on 0 if you are on 1.13 or higher. + data: 0 + name: "&6Example Voucher" + lore: + - "&eThank you so much for purchasing" + - "&emy resource EpicVouchers." + - "&eListen to the wise words that" + - "ðis nice cookie will tell you." + - "" + - "&cWhat could be inside this voucher?" + - "&6- Songoda" + glow: true + confirm: true + unbreakable: true + hide-attributes: false + remove-item: true + feed-player: true + heal-player: true + smite-effect: true + # Enter a custom cooldown if you wish to. + cooldown: 0 + broadcasts: + - "&6&l> &e%player% has redeemed the voucher &6%voucher%&e. &6&l<" + - "&cUseful addons: [chat] [player], and [op]." + - "&cDo not add them to let the console execute it." + messages: + - "&bYou have redeemed the voucher &6%voucher% &bsuccessfully." + commands: + - "give %player% stick 1" + - "[chat]I love EpicVouchers!" + # You can use [chat], [player] and [op]. + # Also use [delay-10] for 10 seconds delay. + # Change 10 to any number you want to have. + actionbar: "&6Actionbar works on every version." + titles: + title: "&6Thank you." + subtitle: "&eYou have redeemed the voucher %voucher%." + fade-in: 10 + stay: 50 + fade-out: 10 + sounds: + sound: "NOTE_PLING" + pitch: 1 + particles: + particle: "FLAME" + amount: 100 + effects: + effect: "SPEED" + amplifier: 2 duration: 10 \ No newline at end of file diff --git a/src/messages.yml b/src/messages.yml deleted file mode 100644 index 790c2fb..0000000 --- a/src/messages.yml +++ /dev/null @@ -1,43 +0,0 @@ -outdated-version: - - "&7Outdated version of &6DeluxeVouchers&7 detected: &c%version%&7." - - "&7Update to the latest version for the latest patches." -cooldown-message: "&7Please wait &6%time%&7 seconds before redeeming a new voucher." -editor-renamer: "&7Please enter the name that this voucher should be renamed to." -editor-renamed: "&7Successfully renamed the voucher to &r%renamed%&7." -editor-cloned: "&7You have received an clone item of the voucher &6%voucher%&7." -command-receive: "&7You have received the voucher &6%voucher% &7(&6x%amount%&7)." -command-give: "&7You have given &6%player% &7the voucher &6%voucher% &7(&6x%amount%&7)." -command-force: "&7You have forced &6%player% &7to redeem the voucher &6%voucher% &7(&6x%amount%&7)." -command-noplayer: "&7Failed to find that online player on this server." -command-novoucher: "&7Failed to find that voucher in the vouchers file." -command-nonumber: "&7Failed to parse that number into a valid amount." -command-reload: "&7You have successfully reloaded all files." -command-reset: "&7You have resetted the files to the default settings." -command-disable: "&7You have disabled &6DeluxeVouchers &7until the next restart." -command-license: "&7Your personal verified license key is &6%license%&7." -command-list: "&7List of all vouchers: &6%list%&7." -command-permission: "&7You do not have the permission to do this." -command-backup: "&7You have created a backup of the configuration files." -command-invalid: "&7Please use &6/deluxevouchers help &7for all commands." -command-help: - - "&8&m----------------[&r &6DeluxeVouchers &8&m]----------------" - - "&c/deluxevouchers reload" - - "&7Reload all files or generate them if they do not exist." - - "&c/deluxevouchers list" - - "&7Displays a list of all vouchers from the vouchers file." - - "&c/deluxevouchers give [player/everyone] [section] [amount]" - - "&7Give someone or everyone a voucher from your parameters." - - "&c/deluxevouchers reset" - - "&7Reset all files and wipe every changed setting from them." - - "&c/deluxevouchers help" - - "&7Displays a list of all useful commands for this resource." - - "&c/deluxevouchers license" - - "&7Displays your personal license key for DeluxeVouchers." - - "&c/deluxevouchers force [player/everyone] [section] [amount]" - - "&7Force someone or everyone to redeem a specific voucher." - - "&c/deluxevouchers backup" - - "&7Backup every configuration file in a randomly created folder." - - "&c/deluxevouchers disable" - - "&7Disable DeluxeVouchers until the next startup or reload." - - "&c/deluxevouchers editor" - - "&7Edit vouchers with an amazing GUI (experimental feature)." \ No newline at end of file diff --git a/src/mysql.yml b/src/mysql.yml deleted file mode 100644 index aca545c..0000000 --- a/src/mysql.yml +++ /dev/null @@ -1,7 +0,0 @@ -use-mysql: false -mysqlhost: "127.0.0.1" -mysqlport: "3306" -mysqluser: "root" -mysqlpass: "banana" -mysqldata: "deluxevouchers" -additions: "?useSSL=true?autoReconnect=true" \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/DeluxeVouchers.java b/src/nl/marido/deluxevouchers/DeluxeVouchers.java deleted file mode 100644 index 41c23b4..0000000 --- a/src/nl/marido/deluxevouchers/DeluxeVouchers.java +++ /dev/null @@ -1,75 +0,0 @@ -package nl.marido.deluxevouchers; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - -import nl.marido.deluxevouchers.handlers.Commandos; -import nl.marido.deluxevouchers.handlers.Connections; -import nl.marido.deluxevouchers.handlers.DataHandler; -import nl.marido.deluxevouchers.handlers.PreventHacks; -import nl.marido.deluxevouchers.handlers.UpdateHandler; -import nl.marido.deluxevouchers.inventory.Confirmation; -import nl.marido.deluxevouchers.inventory.VoucherEditor; -import nl.marido.deluxevouchers.liberaries.Bountiful; -import nl.marido.deluxevouchers.vouchers.ClickListener; - -public class DeluxeVouchers extends JavaPlugin { - - public static DeluxeVouchers instance; - public static ConsoleCommandSender console; - - // Thank you for purchasing DeluxeVouchers. - public static String user = "%%__USER__%%"; - - public void onEnable() { - instance = this; - console = getServer().getConsoleSender(); - DeluxeVouchers.enable(); - DeluxeVouchers.events(); - DataHandler.cacheData(); - Bountiful.findVersion(); - UpdateHandler.checker(); - Connections.openMySQL(); - } - - public void onDisable() { - Connections.closeMySQL(); - DeluxeVouchers.disable(); - } - - public static void enable() { - String version = DeluxeVouchers.getInstance().getDescription().getVersion(); - DeluxeVouchers.printConsole("§eDeluxeVouchers " + version + " has been enabled successfully."); - } - - public static void disable() { - String version = DeluxeVouchers.getInstance().getDescription().getVersion(); - DeluxeVouchers.printConsole("§eDeluxeVouchers " + version + " has been disabled successfully."); - } - - public static void events() { - Bukkit.getServer().getPluginCommand("deluxevouchers").setExecutor(new Commandos()); - PluginManager manager = Bukkit.getServer().getPluginManager(); - manager.registerEvents(new ClickListener(), DeluxeVouchers.getInstance()); - manager.registerEvents(new VoucherEditor(), DeluxeVouchers.getInstance()); - manager.registerEvents(new UpdateHandler(), DeluxeVouchers.getInstance()); - manager.registerEvents(new Confirmation(), DeluxeVouchers.getInstance()); - manager.registerEvents(new PreventHacks(), DeluxeVouchers.getInstance()); - } - - public static DeluxeVouchers getInstance() { - return instance; - } - - public static String applyColor(String message) { - return ChatColor.translateAlternateColorCodes('&', message); - } - - public static void printConsole(String message) { - console.sendMessage(applyColor(message)); - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/handlers/Commandos.java b/src/nl/marido/deluxevouchers/handlers/Commandos.java deleted file mode 100644 index b85ae95..0000000 --- a/src/nl/marido/deluxevouchers/handlers/Commandos.java +++ /dev/null @@ -1,225 +0,0 @@ -package nl.marido.deluxevouchers.handlers; - -import java.io.File; -import java.sql.Date; -import java.sql.Timestamp; - -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import nl.marido.deluxevouchers.DeluxeVouchers; -import nl.marido.deluxevouchers.events.ForceRedeemEvent; -import nl.marido.deluxevouchers.events.VoucherReceiveEvent; -import nl.marido.deluxevouchers.inventory.VoucherEditor; -import nl.marido.deluxevouchers.vouchers.VoucherBuilder; -import nl.marido.deluxevouchers.vouchers.VoucherExecutor; - -public class Commandos implements CommandExecutor { - - public boolean onCommand(CommandSender sender, Command alias, String command, String[] args) { - try { - if (sender.hasPermission("deluxevouchers.admin") || sender.isOp()) { - if (args.length == 1) { - if (args[0].equalsIgnoreCase("reload")) { - DataHandler.cacheData(); - sender.sendMessage(DataHandler.commandreload); - return true; - } - if (args[0].equalsIgnoreCase("editor")) { - if (sender instanceof Player) { - VoucherEditor.openMenu((Player) sender); - return true; - } - DeluxeVouchers.printConsole("§cYou can not use this command as a console."); - return true; - } - if (args[0].equalsIgnoreCase("disable")) { - sender.sendMessage(DataHandler.commanddisable); - DeluxeVouchers.getInstance().getPluginLoader().disablePlugin(DeluxeVouchers.getInstance()); - return true; - } - if (args[0].equalsIgnoreCase("list")) { - String message = DataHandler.commandlist; - String list = DataHandler.getSection(DataHandler.vouchers, "vouchers").toString(); - list = list.replaceAll("[()\\[\\]]", ""); - message = message.replaceAll("%list%", list); - sender.sendMessage(message); - return true; - } - if (args[0].equalsIgnoreCase("reset")) { - DeluxeVouchers.getInstance().saveResource("config.yml", true); - DeluxeVouchers.getInstance().saveResource("vouchers.yml", true); - DeluxeVouchers.getInstance().saveResource("mysql.yml", true); - DataHandler.cacheData(); - sender.sendMessage(DataHandler.commandreset); - return true; - } - if (args[0].equalsIgnoreCase("backup")) { - try { - Timestamp stamp = new Timestamp(System.currentTimeMillis()); - Date date = new Date(stamp.getTime()); - String time = date.toString(); - String folder = String.valueOf(DeluxeVouchers.getInstance().getDataFolder()) + "/" + time; - new File(folder).mkdir(); - File configfile = new File(folder, "config.yml"); - File vouchersfile = new File(folder, "vouchers.yml"); - File mysqlfile = new File(folder, "mysql.yml"); - configfile.createNewFile(); - vouchersfile.createNewFile(); - mysqlfile.createNewFile(); - DataHandler.config.save(configfile); - DataHandler.vouchers.save(vouchersfile); - DataHandler.mysql.save(mysqlfile); - sender.sendMessage(DataHandler.commandbackup); - } catch (Exception error) { - error.printStackTrace(); - } - return true; - } - if (args[0].equalsIgnoreCase("license")) { - String message = DataHandler.commandlicense; - message = message.replaceAll("%license%", "DV" + DeluxeVouchers.user); - sender.sendMessage(message); - return true; - } - if (args[0].equalsIgnoreCase("help")) { - for (String message : DataHandler.commandhelp) { - sender.sendMessage(message); - } - return true; - } - sender.sendMessage(DataHandler.commandinvalid); - return true; - } - if (args.length == 4) { - if (args[0].equalsIgnoreCase("give")) { - if (args[1].equalsIgnoreCase("everyone") || Bukkit.getPlayer(args[1]) != null) { - if (DataHandler.stringExist(DataHandler.vouchers, "vouchers." + args[2])) { - String voucher = args[2]; - try { - String givemessage = DataHandler.commandgive; - String receivemessage = DataHandler.commandreceive; - int amount = Integer.parseInt(args[3]); - ItemStack item = VoucherBuilder.getVoucher(voucher, amount); - String output; - receivemessage = receivemessage.replaceAll("%voucher%", voucher); - receivemessage = receivemessage.replaceAll("%amount%", String.valueOf(amount)); - if (args[1].equalsIgnoreCase("everyone")) { - for (Player player : Bukkit.getOnlinePlayers()) { - if (player != sender) { - VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher, item, amount, sender); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return true; - } - player.sendMessage(receivemessage); - player.getInventory().addItem(item); - player.updateInventory(); - } - } - output = "everyone"; - } else { - Player player = Bukkit.getPlayer(args[1]); - VoucherReceiveEvent event = new VoucherReceiveEvent(player, voucher, item, amount, sender); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return true; - } - player.sendMessage(receivemessage); - player.getInventory().addItem(item); - player.updateInventory(); - output = player.getName(); - } - givemessage = givemessage.replaceAll("%player%", output); - givemessage = givemessage.replaceAll("%voucher%", voucher); - givemessage = givemessage.replaceAll("%amount%", String.valueOf(amount)); - sender.sendMessage(givemessage); - } catch (Exception error) { - sender.sendMessage(DataHandler.commandnonumber); - } - return true; - } - sender.sendMessage(DataHandler.commandnovoucher); - return true; - } - sender.sendMessage(DataHandler.commandnoplayer); - return true; - } - if (args[0].equalsIgnoreCase("force")) { - if (args[1].equalsIgnoreCase("everyone") || Bukkit.getPlayer(args[1]) != null) { - if (DataHandler.stringExist(DataHandler.vouchers, "vouchers." + args[2])) { - String voucher = args[2]; - try { - int amount = Integer.parseInt(args[3]); - String output; - if (args[1].equalsIgnoreCase("everyone")) { - output = "everyone"; - for (Player player : Bukkit.getOnlinePlayers()) { - if (player != sender) { - ForceRedeemEvent event = new ForceRedeemEvent(player, voucher, amount, sender); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return true; - } - for (int times = 0; times < amount; times++) { - VoucherExecutor.redeemVoucher(player, voucher, player.getItemInHand(), false); - } - } - } - } else { - Player player = Bukkit.getPlayer(args[1]); - ForceRedeemEvent event = new ForceRedeemEvent(player, voucher, amount, sender); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return true; - } - output = player.getName(); - for (int times = 0; times < amount; times++) { - VoucherExecutor.redeemVoucher(player, voucher, player.getItemInHand(), false); - } - } - String message = DataHandler.commandforce; - message = message.replaceAll("%player%", output); - message = message.replaceAll("%voucher%", voucher); - message = message.replaceAll("%amount%", String.valueOf(amount)); - sender.sendMessage(message); - } catch (Exception error) { - sender.sendMessage(DataHandler.commandnonumber); - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - return true; - } - sender.sendMessage(DataHandler.commandnovoucher); - return true; - } - sender.sendMessage(DataHandler.commandnoplayer); - return true; - } - sender.sendMessage(DataHandler.commandinvalid); - return true; - } - sender.sendMessage(DataHandler.commandinvalid); - return true; - } - sender.sendMessage(DataHandler.commandpermission); - return true; - } catch (Exception error) { - String fullcommand = "/deluxevouchers"; - for (int argint = 0; argint < args.length; argint++) { - fullcommand = fullcommand + " " + args[argint]; - } - DeluxeVouchers.printConsole("§cFailed to execute the command " + fullcommand + " by " + sender.getName() + "."); - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - return false; - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/handlers/Connections.java b/src/nl/marido/deluxevouchers/handlers/Connections.java deleted file mode 100644 index 21b4277..0000000 --- a/src/nl/marido/deluxevouchers/handlers/Connections.java +++ /dev/null @@ -1,71 +0,0 @@ -package nl.marido.deluxevouchers.handlers; - -import java.sql.Connection; -import java.sql.Date; -import java.sql.DriverManager; -import java.sql.Statement; -import java.sql.Timestamp; - -import org.bukkit.entity.Player; - -import nl.marido.deluxevouchers.DeluxeVouchers; - -public class Connections { - - public static Connection connection; - - public static void saveRedeem(Player player, String voucher) { - if (DataHandler.mysqlenabled) { - if (connection != null) { - Timestamp stamp = new Timestamp(System.currentTimeMillis()); - Date date = new Date(stamp.getTime()); - String time = date.toString(); - try { - Statement statement = connection.createStatement(); - statement.execute("CREATE TABLE IF NOT EXISTS redeems (id INT NOT NULL AUTO_INCREMENT, player varchar(120) NOT NULL, voucher varchar(120) NOT NULL, timestamp varchar(120) NOT NULL, PRIMARY KEY (ID));"); - statement.execute("INSERT INTO redeems VALUES (default, '" + player.getName() + "', '" + voucher + "', '" + time + "');"); - statement.close(); - DeluxeVouchers.printConsole("§fSuccessfully saved the redeem in the MySQL database."); - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to save the redeem data in the MySQL database."); - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - } - } - - public static void openMySQL() { - if (DataHandler.mysqlenabled) { - if (connection == null) { - try { - connection = DriverManager.getConnection("jdbc:mysql://" + DataHandler.mysqlhost + ":" + DataHandler.mysqlport + "/" + DataHandler.mysqldata + DataHandler.additions, DataHandler.mysqluser, DataHandler.mysqlpass); - DeluxeVouchers.printConsole("§fSuccessfully created a connection with MySQL."); - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to create a connection with MySQL."); - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - } - } - - public static void closeMySQL() { - if (DataHandler.mysqlenabled) { - if (connection != null) { - try { - connection.close(); - DeluxeVouchers.printConsole("§fSuccessfully closed the MySQL connection."); - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to close the MySQL connection."); - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - } - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/handlers/DataHandler.java b/src/nl/marido/deluxevouchers/handlers/DataHandler.java deleted file mode 100644 index ae0cb37..0000000 --- a/src/nl/marido/deluxevouchers/handlers/DataHandler.java +++ /dev/null @@ -1,335 +0,0 @@ -package nl.marido.deluxevouchers.handlers; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -import nl.marido.deluxevouchers.DeluxeVouchers; - -public class DataHandler { - - public static String editorrenamestart; - public static String editorrenamedone; - public static String editorreceiveitem; - public static boolean checkupdates; - public static boolean debugerrors; - public static String oldversionsound; - public static int oldversionpitch; - public static List oldversionmessage; - public static int cooldowndelay; - public static String cooldownmessage; - public static int editorbackitemslot; - public static String editorbackitemmaterial; - public static int editorbackitemdata; - public static String editorbackitemname; - public static List editorbackitemlore; - public static boolean editorbackitemglow; - public static boolean editorbackitemunbreakable; - public static boolean editorbackitemhideattributes; - public static String editorbackitemsound; - public static int editorbackitempitch; - public static int editorcloneitemslot; - public static String editorcloneitemmaterial; - public static int editorcloneitemdata; - public static String editorcloneitemname; - public static List editorcloneitemlore; - public static boolean editorcloneitemglow; - public static boolean editorcloneitemunbreakable; - public static boolean editorcloneitemhideattributes; - public static String editorcloneitemsound; - public static int editorcloneitempitch; - public static int editorrenameitemslot; - public static String editorrenameitemmaterial; - public static int editorrenameitemdata; - public static String editorrenameitemname; - public static List editorrenameitemlore; - public static boolean editorrenameitemglow; - public static boolean editorrenameitemunbreakable; - public static boolean editorrenameitemhideattributes; - public static String editorrenameitemsound; - public static int editorrenameitempitch; - public static String editortitle; - public static int editorslots; - public static String editorsound; - public static int editorpitch; - public static boolean editorfill; - public static String editorvouchertitle; - public static int editorvoucherslot; - public static int editorvoucherslots; - public static String editorvouchersound; - public static int editorvoucherpitch; - public static boolean editorvoucherfill; - public static String confirmtitle; - public static int confirmslots; - public static String confirmsound; - public static int confirmpitch; - public static boolean confirmfill; - public static int confirmitemslot; - public static String confirmitemmaterial; - public static int confirmitemdata; - public static String confirmitemname; - public static List confirmitemlore; - public static boolean confirmitemglow; - public static boolean confirmitemunbreakable; - public static boolean confirmitemhideattributes; - public static String confirmitemsound; - public static int confirmitempitch; - public static int cancelitemslot; - public static String cancelitemmaterial; - public static int cancelitemdata; - public static String cancelitemname; - public static List cancelitemlore; - public static boolean cancelitemglow; - public static boolean cancelitemunbreakable; - public static boolean cancelitemhideattributes; - public static String cancelitemsound; - public static int cancelitempitch; - public static String commandreceive; - public static String commandgive; - public static String commandforce; - public static String commandnoplayer; - public static String commandnovoucher; - public static String commandnonumber; - public static String commandreload; - public static String commandreset; - public static String commandlicense; - public static String commandlist; - public static String commanddisable; - public static String commandbackup; - public static String commandpermission; - public static String commandinvalid; - public static List commandhelp; - public static boolean mysqlenabled; - public static String mysqlhost; - public static String mysqlport; - public static String mysqluser; - public static String mysqlpass; - public static String mysqldata; - public static String additions; - - public static File configfile; - public static File vouchersfile; - public static File mysqlfile; - public static File messagesfile; - - public static FileConfiguration config; - public static FileConfiguration vouchers; - public static FileConfiguration mysql; - public static FileConfiguration messages; - - // TODO: Switch to enums. - public static void cacheData() { - try { - File folder = DeluxeVouchers.getInstance().getDataFolder(); - configfile = new File(folder, "config.yml"); - vouchersfile = new File(folder, "vouchers.yml"); - mysqlfile = new File(folder, "mysql.yml"); - messagesfile = new File(folder, "messages.yml"); - if (!configfile.exists()) { - DeluxeVouchers.getInstance().saveResource("config.yml", true); - DeluxeVouchers.printConsole("§fFailed to find the config.yml file. Generating..."); - } - if (!vouchersfile.exists()) { - DeluxeVouchers.getInstance().saveResource("vouchers.yml", true); - DeluxeVouchers.printConsole("§fFailed to find the vouchers.yml file. Generating..."); - } - if (!mysqlfile.exists()) { - DeluxeVouchers.getInstance().saveResource("mysql.yml", true); - DeluxeVouchers.printConsole("§fFailed to find the mysql.yml file. Generating..."); - } - if (!messagesfile.exists()) { - DeluxeVouchers.getInstance().saveResource("messages.yml", true); - DeluxeVouchers.printConsole("§fFailed to find the messages.yml file. Generating..."); - } - config = YamlConfiguration.loadConfiguration(configfile); - vouchers = YamlConfiguration.loadConfiguration(vouchersfile); - mysql = YamlConfiguration.loadConfiguration(mysqlfile); - messages = YamlConfiguration.loadConfiguration(messagesfile); - checkupdates = getBoolean(config, "check-updates"); - debugerrors = getBoolean(config, "debugger-mode"); - oldversionsound = getString(config, "outdated-version.sound"); - oldversionpitch = getInt(config, "outdated-version.pitch"); - oldversionmessage = getStringList(messages, "outdated-version"); - cooldowndelay = getInt(config, "cooldown-delay"); - cooldownmessage = getString(messages, "cooldown-message"); - editorbackitemslot = getInt(config, "editor-settings.back-item.slot"); - editorbackitemmaterial = getString(config, "editor-settings.back-item.material"); - editorbackitemdata = getInt(config, "editor-settings.back-item.data"); - editorbackitemname = getString(config, "editor-settings.back-item.name"); - editorbackitemlore = getStringList(config, "editor-settings.back-item.lore"); - editorbackitemglow = getBoolean(config, "editor-settings.back-item.glow"); - editorbackitemunbreakable = getBoolean(config, "editor-settings.back-item.unbreakable"); - editorbackitemhideattributes = getBoolean(config, "editor-settings.back-item.hide-attributes"); - editorbackitemsound = getString(config, "editor-settings.back-item.sounds.sound"); - editorbackitempitch = getInt(config, "editor-settings.back-item.sounds.pitch"); - editorcloneitemslot = getInt(config, "editor-settings.receive-item.slot"); - editorcloneitemmaterial = getString(config, "editor-settings.receive-item.material"); - editorcloneitemdata = getInt(config, "editor-settings.receive-item.data"); - editorcloneitemname = getString(config, "editor-settings.receive-item.name"); - editorcloneitemlore = getStringList(config, "editor-settings.receive-item.lore"); - editorcloneitemglow = getBoolean(config, "editor-settings.receive-item.glow"); - editorcloneitemunbreakable = getBoolean(config, "editor-settings.receive-item.unbreakable"); - editorcloneitemhideattributes = getBoolean(config, "editor-settings.receive-item.hide-attributes"); - editorcloneitemsound = getString(config, "editor-settings.receive-item.sounds.sound"); - editorcloneitempitch = getInt(config, "editor-settings.receive-item.sounds.pitch"); - editorrenameitemslot = getInt(config, "editor-settings.rename-item.slot"); - editorrenameitemmaterial = getString(config, "editor-settings.rename-item.material"); - editorrenameitemdata = getInt(config, "editor-settings.rename-item.data"); - editorrenameitemname = getString(config, "editor-settings.rename-item.name"); - editorrenamestart = getString(messages, "editor-renamer"); - editorrenamedone = getString(messages, "editor-renamed"); - editorreceiveitem = getString(messages, "editor-cloned"); - editorrenameitemlore = getStringList(config, "editor-settings.rename-item.lore"); - editorrenameitemglow = getBoolean(config, "editor-settings.rename-item.glow"); - editorrenameitemunbreakable = getBoolean(config, "editor-settings.rename-item.unbreakable"); - editorrenameitemhideattributes = getBoolean(config, "editor-settings.rename-item.hide-attributes"); - editorrenameitemsound = getString(config, "editor-settings.rename-item.sounds.sound"); - editorrenameitempitch = getInt(config, "editor-settings.rename-item.sounds.pitch"); - editortitle = getString(config, "editor-settings.editor-title"); - editorslots = getInt(config, "editor-settings.editor-slots"); - editorsound = getString(config, "editor-settings.editor-sounds.sound"); - editorpitch = getInt(config, "editor-settings.editor-sounds.pitch"); - editorfill = getBoolean(config, "editor-settings.fill-glass"); - editorvouchertitle = getString(config, "editor-settings.editor-voucher.title"); - editorvoucherslot = getInt(config, "editor-settings.editor-voucher.voucher-slot"); - editorvoucherslots = getInt(config, "editor-settings.editor-voucher.slots"); - editorvouchersound = getString(config, "editor-settings.editor-voucher.sound"); - editorvoucherpitch = getInt(config, "editor-settings.editor-voucher.pitch"); - editorvoucherfill = getBoolean(config, "editor-settings.editor-voucher.fill-glass"); - confirmtitle = getString(config, "confirm-settings.confirm-title"); - confirmslots = getInt(config, "confirm-settings.confirm-slots"); - confirmsound = getString(config, "confirm-settings.confirm-sounds.sound"); - confirmpitch = getInt(config, "confirm-settings.confirm-sounds.pitch"); - confirmfill = getBoolean(config, "confirm-settings.fill-glass"); - confirmitemslot = getInt(config, "confirm-settings.confirm-item.slot"); - confirmitemmaterial = getString(config, "confirm-settings.confirm-item.material"); - confirmitemdata = getInt(config, "confirm-settings.confirm-item.data"); - confirmitemname = getString(config, "confirm-settings.confirm-item.name"); - confirmitemlore = getStringList(config, "confirm-settings.confirm-item.lore"); - confirmitemglow = getBoolean(config, "confirm-settings.confirm-item.glow"); - confirmitemunbreakable = getBoolean(config, "confirm-settings.confirm-item.unbreakable"); - confirmitemhideattributes = getBoolean(config, "confirm-settings.confirm-item.hide-attributes"); - confirmitemsound = getString(config, "confirm-settings.confirm-item.sounds.sound"); - confirmitempitch = getInt(config, "confirm-settings.confirm-item.sounds.pitch"); - cancelitemslot = getInt(config, "confirm-settings.cancel-item.slot"); - cancelitemmaterial = getString(config, "confirm-settings.cancel-item.material"); - cancelitemdata = getInt(config, "confirm-settings.cancel-item.data"); - cancelitemname = getString(config, "confirm-settings.cancel-item.name"); - cancelitemlore = getStringList(config, "confirm-settings.cancel-item.lore"); - cancelitemglow = getBoolean(config, "confirm-settings.cancel-item.glow"); - cancelitemunbreakable = getBoolean(config, "confirm-settings.cancel-item.unbreakable"); - cancelitemhideattributes = getBoolean(config, "confirm-settings.cancel-item.hide-attributes"); - cancelitemsound = getString(config, "confirm-settings.cancel-item.sounds.sound"); - cancelitempitch = getInt(config, "confirm-settings.cancel-item.sounds.pitch"); - commandreceive = getString(messages, "command-receive"); - commandgive = getString(messages, "command-give"); - commandforce = getString(messages, "command-force"); - commandnoplayer = getString(messages, "command-noplayer"); - commandnovoucher = getString(messages, "command-novoucher"); - commandnonumber = getString(messages, "command-nonumber"); - commandreload = getString(messages, "command-reload"); - commandreset = getString(messages, "command-reset"); - commandlicense = getString(messages, "command-license"); - commandlist = getString(messages, "command-list"); - commanddisable = getString(messages, "command-disable"); - commandbackup = getString(messages, "command-backup"); - commandpermission = getString(messages, "command-permission"); - commandinvalid = getString(messages, "command-invalid"); - commandhelp = getStringList(messages, "command-help"); - mysqlenabled = getBoolean(mysql, "use-mysql"); - mysqlhost = getString(mysql, "mysqlhost"); - mysqlport = getString(mysql, "mysqlport"); - mysqluser = getString(mysql, "mysqluser"); - mysqlpass = getString(mysql, "mysqlpass"); - mysqldata = getString(mysql, "mysqldata"); - additions = getString(mysql, "additions"); - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to copy the configuration options to the cache memory."); - DeluxeVouchers.printConsole("§cMake sure to update your configuration options or reset it."); - if (debugerrors) { - error.printStackTrace(); - } - } - } - - public static boolean stringExist(FileConfiguration datafile, String path) { - try { - return datafile.getString(path) != null; - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); - if (debugerrors) { - error.printStackTrace(); - } - } - return false; - } - - public static boolean getBoolean(FileConfiguration datafile, String path) { - try { - return datafile.getBoolean(path); - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); - if (debugerrors) { - error.printStackTrace(); - } - } - return false; - } - - public static int getInt(FileConfiguration datafile, String path) { - try { - return datafile.getInt(path); - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); - if (debugerrors) { - error.printStackTrace(); - } - } - return 0; - } - - public static String getString(FileConfiguration datafile, String path) { - try { - return DeluxeVouchers.applyColor(datafile.getString(path)); - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); - if (debugerrors) { - error.printStackTrace(); - } - } - return null; - } - - public static Set getSection(FileConfiguration datafile, String path) { - try { - return datafile.getConfigurationSection(path).getKeys(false); - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); - if (debugerrors) { - error.printStackTrace(); - } - } - return null; - } - - public static ArrayList getStringList(FileConfiguration datafile, String path) { - try { - ArrayList stringlist = new ArrayList(); - for (String line : datafile.getStringList(path)) { - stringlist.add(DeluxeVouchers.applyColor(line)); - } - return stringlist; - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to find the path " + path + "."); - if (debugerrors) { - error.printStackTrace(); - } - } - return null; - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/handlers/PreventHacks.java b/src/nl/marido/deluxevouchers/handlers/PreventHacks.java deleted file mode 100644 index f7b2014..0000000 --- a/src/nl/marido/deluxevouchers/handlers/PreventHacks.java +++ /dev/null @@ -1,23 +0,0 @@ -package nl.marido.deluxevouchers.handlers; - -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -public class PreventHacks implements Listener { - - public static HashMap commands = new HashMap(); - - @EventHandler - public void preventCommands(PlayerCommandPreprocessEvent event) { - if (commands.containsKey(event.getPlayer().getUniqueId())) { - if (!event.getMessage().equalsIgnoreCase(commands.get(event.getPlayer().getUniqueId()))) { - event.setCancelled(true); - } - } - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/handlers/UpdateHandler.java b/src/nl/marido/deluxevouchers/handlers/UpdateHandler.java deleted file mode 100644 index 890fba3..0000000 --- a/src/nl/marido/deluxevouchers/handlers/UpdateHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -package nl.marido.deluxevouchers.handlers; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.scheduler.BukkitRunnable; - -import nl.marido.deluxevouchers.DeluxeVouchers; - -public class UpdateHandler implements Listener { - - public static boolean oldversion = false; - - public static void checker() { - if (DataHandler.checkupdates) { - new BukkitRunnable() { - public void run() { - try { - URL checkurl = new URL("https://api.spigotmc.org/legacy/update.php?resource=52480"); - URLConnection connection = checkurl.openConnection(); - String latestversion = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine(); - String currentversion = DeluxeVouchers.getInstance().getDescription().getVersion(); - if (latestversion.equals(currentversion)) { - DeluxeVouchers.printConsole("§fLatest version of DeluxeVouchers detected (" + currentversion + ")."); - oldversion = false; - } else { - DeluxeVouchers.printConsole("§cOutdated version of DeluxeVouchers detected (" + currentversion + ")."); - DeluxeVouchers.printConsole("§cDownload " + latestversion + ": https://spigotmc.org/resources/52480"); - oldversion = true; - } - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to create a connection with the updater host."); - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - }.runTaskAsynchronously(DeluxeVouchers.getInstance()); - } - } - - @EventHandler - public void updateWarning(PlayerJoinEvent event) { - Player player = event.getPlayer(); - if (player.hasPermission("deluxevouchers.admin")) { - if (oldversion) { - SoundHandler.playSound(player, DataHandler.oldversionsound, DataHandler.oldversionpitch); - for (String message : DataHandler.oldversionmessage) { - message = message.replaceAll("%version%", DeluxeVouchers.getInstance().getDescription().getVersion()); - player.sendMessage(message); - } - } - } - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/inventory/Confirmation.java b/src/nl/marido/deluxevouchers/inventory/Confirmation.java deleted file mode 100644 index 0c8a18a..0000000 --- a/src/nl/marido/deluxevouchers/inventory/Confirmation.java +++ /dev/null @@ -1,126 +0,0 @@ -package nl.marido.deluxevouchers.inventory; - -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -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.inventory.Inventory; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import nl.marido.deluxevouchers.handlers.DataHandler; -import nl.marido.deluxevouchers.handlers.SoundHandler; -import nl.marido.deluxevouchers.vouchers.VoucherExecutor; - -public class Confirmation implements Listener { - - public static HashMap vouchercache = new HashMap(); - public static HashMap itemcache = new HashMap(); - public static HashMap slotcache = new HashMap(); - - public static void confirmVoucher(Player player, String voucher, ItemStack item) { - Inventory confirmmenu = Bukkit.createInventory(null, DataHandler.confirmslots, DataHandler.confirmtitle); - SoundHandler.playSound(player, DataHandler.confirmsound, DataHandler.confirmpitch); - ItemStack confirmitem = new ItemStack(Material.valueOf(DataHandler.confirmitemmaterial), 1, (short) DataHandler.confirmitemdata); - ItemMeta confirmitemmeta = confirmitem.getItemMeta(); - confirmitemmeta.setDisplayName(DataHandler.confirmitemname); - confirmitemmeta.setLore(DataHandler.confirmitemlore); - if (DataHandler.confirmitemglow) { - confirmitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); - confirmitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - } - if (DataHandler.confirmitemunbreakable) { - confirmitemmeta.spigot().setUnbreakable(true); - } - if (DataHandler.confirmitemhideattributes) { - confirmitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); - confirmitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); - } - confirmitem.setItemMeta(confirmitemmeta); - confirmmenu.setItem(DataHandler.confirmitemslot, confirmitem); - ItemStack cancelitem = new ItemStack(Material.valueOf(DataHandler.cancelitemmaterial), 1, (short) DataHandler.cancelitemdata); - ItemMeta cancelitemmeta = cancelitem.getItemMeta(); - cancelitemmeta.setDisplayName(DataHandler.cancelitemname); - cancelitemmeta.setLore(DataHandler.cancelitemlore); - if (DataHandler.cancelitemglow) { - cancelitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); - cancelitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - } - if (DataHandler.cancelitemunbreakable) { - cancelitemmeta.spigot().setUnbreakable(true); - } - if (DataHandler.cancelitemhideattributes) { - cancelitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); - cancelitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); - } - cancelitem.setItemMeta(cancelitemmeta); - confirmmenu.setItem(DataHandler.cancelitemslot, cancelitem); - if (DataHandler.confirmfill) { - ItemStack fillitem; - try { - fillitem = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7); - } catch (Exception error) { - fillitem = new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE")); - } - ItemMeta fillitemmeta = fillitem.getItemMeta(); - fillitemmeta.setDisplayName("§r"); - fillitem.setItemMeta(fillitemmeta); - for (int empty = 0; empty < confirmmenu.getSize(); empty++) { - if (confirmmenu.getItem(empty) == null) { - confirmmenu.setItem(empty, fillitem); - } - } - } - UUID uuid = player.getUniqueId(); - vouchercache.put(uuid, voucher); - itemcache.put(uuid, item); - player.openInventory(confirmmenu); - } - - @EventHandler - public void clickListener(InventoryClickEvent event) { - try { - if (event.getInventory().getType() == InventoryType.CHEST) { - if (event.getInventory().getTitle().equals(DataHandler.confirmtitle)) { - Player player = (Player) event.getWhoClicked(); - ItemStack clicked = event.getCurrentItem(); - if (clicked != null) { - if (clicked.getItemMeta().hasDisplayName()) { - if (clicked.getItemMeta().getDisplayName().equals(DataHandler.confirmitemname)) { - SoundHandler.playSound(player, DataHandler.confirmitemsound, DataHandler.confirmitempitch); - player.closeInventory(); - UUID uuid = player.getUniqueId(); - String voucher = vouchercache.get(uuid); - ItemStack item = itemcache.get(uuid); - VoucherExecutor.redeemVoucher(player, voucher, item, true); - } - } - if (clicked.getItemMeta().hasDisplayName()) { - if (clicked.getItemMeta().getDisplayName().equals(DataHandler.cancelitemname)) { - UUID uuid = player.getUniqueId(); - vouchercache.remove(uuid); - itemcache.remove(uuid); - SoundHandler.playSound(player, DataHandler.cancelitemsound, DataHandler.cancelitempitch); - player.closeInventory(); - } - } - event.setCancelled(true); - } - } - } - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/inventory/VoucherEditor.java b/src/nl/marido/deluxevouchers/inventory/VoucherEditor.java deleted file mode 100644 index caaf648..0000000 --- a/src/nl/marido/deluxevouchers/inventory/VoucherEditor.java +++ /dev/null @@ -1,333 +0,0 @@ -package nl.marido.deluxevouchers.inventory; - -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -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.InventoryCloseEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import nl.marido.deluxevouchers.DeluxeVouchers; -import nl.marido.deluxevouchers.handlers.DataHandler; -import nl.marido.deluxevouchers.handlers.SoundHandler; -import nl.marido.deluxevouchers.vouchers.VoucherBuilder; - -public class VoucherEditor implements Listener { - - public static HashMap editor = new HashMap(); - public static HashMap type = new HashMap(); - - public static void openMenu(Player player) { - Inventory editormenu = Bukkit.createInventory(null, DataHandler.editorslots, DataHandler.editortitle); - SoundHandler.playSound(player, DataHandler.editorsound, DataHandler.editorpitch); - for (String voucher : DataHandler.getSection(DataHandler.vouchers, "vouchers")) { - ItemStack item = VoucherBuilder.getVoucher(voucher, 1); - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(meta.getDisplayName() + " §b§l[CLICK TO EDIT]"); - item.setItemMeta(meta); - editormenu.setItem(editormenu.firstEmpty(), item); - } - if (DataHandler.confirmfill) { - ItemStack fillitem; - try { - fillitem = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7); - } catch (Exception error) { - fillitem = new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE")); - } - ItemMeta fillitemmeta = fillitem.getItemMeta(); - fillitemmeta.setDisplayName("§r"); - fillitem.setItemMeta(fillitemmeta); - for (int empty = 0; empty < editormenu.getSize(); empty++) { - if (editormenu.getItem(empty) == null) { - editormenu.setItem(empty, fillitem); - } - } - } - player.closeInventory(); - player.openInventory(editormenu); - } - - public static void editVoucher(Player player, String voucher, ItemStack item) { - String title = DataHandler.editorvouchertitle; - title = title.replaceAll("%voucher%", voucher); - Inventory editormenu = Bukkit.createInventory(null, DataHandler.editorvoucherslots, title); - ItemMeta meta = item.getItemMeta(); - String name = meta.getDisplayName(); - name = DataHandler.getString(DataHandler.vouchers, "vouchers." + voucher + ".name"); - meta.setDisplayName(name); - item.setItemMeta(meta); - editormenu.setItem(DataHandler.editorvoucherslot, item); - ItemStack backitem = new ItemStack(Material.valueOf(DataHandler.editorbackitemmaterial), 1, (short) DataHandler.editorbackitemdata); - ItemMeta backitemmeta = backitem.getItemMeta(); - backitemmeta.setDisplayName(DataHandler.editorbackitemname); - backitemmeta.setLore(DataHandler.editorbackitemlore); - if (DataHandler.editorbackitemglow) { - backitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); - backitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - } - if (DataHandler.editorbackitemunbreakable) { - backitemmeta.spigot().setUnbreakable(true); - } - if (DataHandler.editorbackitemhideattributes) { - backitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); - backitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); - } - backitem.setItemMeta(backitemmeta); - editormenu.setItem(DataHandler.editorbackitemslot, backitem); - ItemStack cloneitem = new ItemStack(Material.valueOf(DataHandler.editorcloneitemmaterial), 1, (short) DataHandler.editorcloneitemdata); - ItemMeta cloneitemmeta = cloneitem.getItemMeta(); - cloneitemmeta.setDisplayName(DataHandler.editorcloneitemname); - cloneitemmeta.setLore(DataHandler.editorcloneitemlore); - if (DataHandler.editorcloneitemglow) { - cloneitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); - cloneitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - } - if (DataHandler.editorcloneitemunbreakable) { - cloneitemmeta.spigot().setUnbreakable(true); - } - if (DataHandler.editorcloneitemhideattributes) { - cloneitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); - cloneitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); - } - cloneitem.setItemMeta(cloneitemmeta); - editormenu.setItem(DataHandler.editorcloneitemslot, cloneitem); - ItemStack renameitem = new ItemStack(Material.valueOf(DataHandler.editorrenameitemmaterial), 1, (short) DataHandler.editorrenameitemdata); - ItemMeta renameitemmeta = renameitem.getItemMeta(); - renameitemmeta.setDisplayName(DataHandler.editorrenameitemname); - renameitemmeta.setLore(DataHandler.editorrenameitemlore); - if (DataHandler.editorrenameitemglow) { - renameitemmeta.addEnchant(Enchantment.DURABILITY, 1, false); - renameitemmeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - } - if (DataHandler.editorrenameitemunbreakable) { - renameitemmeta.spigot().setUnbreakable(true); - } - if (DataHandler.editorrenameitemhideattributes) { - renameitemmeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); - renameitemmeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); - } - renameitem.setItemMeta(renameitemmeta); - editormenu.setItem(DataHandler.editorrenameitemslot, renameitem); - if (DataHandler.editorvoucherfill) { - ItemStack fillitem; - try { - fillitem = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 7); - } catch (Exception error) { - fillitem = new ItemStack(Material.valueOf("GRAY_STAINED_GLASS_PANE")); - } - ItemMeta fillitemmeta = fillitem.getItemMeta(); - fillitemmeta.setDisplayName("§r"); - fillitem.setItemMeta(fillitemmeta); - for (int empty = 0; empty < editormenu.getSize(); empty++) { - if (editormenu.getItem(empty) == null) { - editormenu.setItem(empty, fillitem); - } - } - } - player.closeInventory(); - editor.put(player.getUniqueId(), voucher); - player.openInventory(editormenu); - } - - @EventHandler - public void clickListener(InventoryClickEvent event) { - try { - if (event.getInventory().getType() == InventoryType.CHEST) { - if (event.getInventory().getTitle().equals(DataHandler.editortitle)) { - for (String voucher : DataHandler.getSection(DataHandler.vouchers, "vouchers")) { - String path = "vouchers." + voucher + "."; - ItemStack item = event.getCurrentItem(); - if (item.getType() == Material.valueOf(DataHandler.getString(DataHandler.vouchers, path + "material"))) { - if (item.getDurability() == (short) DataHandler.getInt(DataHandler.vouchers, path + "data")) { - ItemMeta meta = item.getItemMeta(); - if (meta.hasLore()) { - if (meta.getLore().equals(DataHandler.getStringList(DataHandler.vouchers, path + "lore"))) { - Player player = (Player) event.getWhoClicked(); - SoundHandler.playSound(player, DataHandler.editorvouchersound, DataHandler.editorvoucherpitch); - event.getWhoClicked().closeInventory(); - editVoucher(player, voucher, item); - } - } - } - } - } - event.setCancelled(true); - } - } - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - - @EventHandler - public void editListener(InventoryClickEvent event) { - try { - if (event.getInventory().getType() == InventoryType.CHEST) { - if (editor.containsKey(event.getWhoClicked().getUniqueId())) { - event.setCancelled(true); - } - } - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - - @EventHandler - public void renameListener(InventoryClickEvent event) { - try { - if (event.getInventory().getType() == InventoryType.CHEST) { - if (editor.containsKey(event.getWhoClicked().getUniqueId())) { - ItemStack item = event.getCurrentItem(); - if (item.getType() == Material.valueOf(DataHandler.editorrenameitemmaterial)) { - if (item.getDurability() == DataHandler.editorrenameitemdata) { - ItemMeta meta = item.getItemMeta(); - if (meta.hasDisplayName()) { - if (meta.getDisplayName().equals(DataHandler.editorrenameitemname)) { - if (meta.hasLore()) { - if (meta.getLore().equals(DataHandler.editorrenameitemlore)) { - SoundHandler.playSound((Player) event.getWhoClicked(), DataHandler.editorrenameitemsound, DataHandler.editorrenameitempitch); - String cache = editor.get(event.getWhoClicked().getUniqueId()); - event.getWhoClicked().closeInventory(); - editor.put(event.getWhoClicked().getUniqueId(), cache); - type.put(event.getWhoClicked().getUniqueId(), "rename"); - event.getWhoClicked().sendMessage(DataHandler.editorrenamestart); - } - } - } - } - } - } - } - } - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - - @EventHandler - public void cloneListener(InventoryClickEvent event) { - try { - if (event.getInventory().getType() == InventoryType.CHEST) { - if (editor.containsKey(event.getWhoClicked().getUniqueId())) { - ItemStack item = event.getCurrentItem(); - if (item.getType() == Material.valueOf(DataHandler.editorcloneitemmaterial)) { - if (item.getDurability() == DataHandler.editorcloneitemdata) { - ItemMeta meta = item.getItemMeta(); - if (meta.hasDisplayName()) { - if (meta.getDisplayName().equals(DataHandler.editorcloneitemname)) { - if (meta.hasLore()) { - if (meta.getLore().equals(DataHandler.editorcloneitemlore)) { - SoundHandler.playSound((Player) event.getWhoClicked(), DataHandler.editorcloneitemsound, DataHandler.editorcloneitempitch); - event.getWhoClicked().getInventory().addItem(VoucherBuilder.getVoucher(editor.get(event.getWhoClicked().getUniqueId()), 1)); - ((Player) event.getWhoClicked()).updateInventory(); - String message = DataHandler.editorreceiveitem; - message = message.replaceAll("%voucher%", editor.get(event.getWhoClicked().getUniqueId())); - event.getWhoClicked().sendMessage(message); - event.getWhoClicked().closeInventory(); - } - } - } - } - } - } - } - } - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - - @EventHandler - public void chatListener(AsyncPlayerChatEvent event) { - if (editor.containsKey(event.getPlayer().getUniqueId())) { - if (type.containsKey(event.getPlayer().getUniqueId())) { - if (type.get(event.getPlayer().getUniqueId()).equals("rename")) { - type.remove(event.getPlayer().getUniqueId()); - String renamed = "&r" + event.getMessage(); - String path = "vouchers." + editor.get(event.getPlayer().getUniqueId()) + ".name"; - DataHandler.vouchers.set(path, renamed); - try { - DataHandler.config.save(DataHandler.configfile); - DataHandler.vouchers.save(DataHandler.vouchersfile); - DataHandler.mysql.save(DataHandler.mysqlfile); - } catch (Exception error) { - error.printStackTrace(); - } - DataHandler.cacheData(); - String message = DataHandler.editorrenamedone; - message = DeluxeVouchers.applyColor(message); - event.getPlayer().sendMessage(message); - editVoucher(event.getPlayer(), editor.get(event.getPlayer().getUniqueId()), VoucherBuilder.getVoucher(editor.get(event.getPlayer().getUniqueId()), 1)); - SoundHandler.playSound(event.getPlayer(), DataHandler.editorvouchersound, DataHandler.editorvoucherpitch); - event.setCancelled(true); - } - } - } - } - - @EventHandler - public void returnListener(InventoryClickEvent event) { - try { - if (event.getInventory().getType() == InventoryType.CHEST) { - if (editor.containsKey(event.getWhoClicked().getUniqueId())) { - ItemStack item = event.getCurrentItem(); - if (item.getType() == Material.valueOf(DataHandler.editorbackitemmaterial)) { - if (item.getDurability() == DataHandler.editorbackitemdata) { - ItemMeta meta = item.getItemMeta(); - if (meta.hasDisplayName()) { - if (meta.getDisplayName().equals(DataHandler.editorbackitemname)) { - if (meta.hasLore()) { - if (meta.getLore().equals(DataHandler.editorbackitemlore)) { - SoundHandler.playSound((Player) event.getWhoClicked(), DataHandler.editorbackitemsound, DataHandler.editorbackitempitch); - event.getWhoClicked().closeInventory(); - openMenu((Player) event.getWhoClicked()); - } - } - } - } - } - } - } - } - } catch (Exception error) { - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - - @EventHandler - public void closeListener(InventoryCloseEvent event) { - if (editor.containsKey(event.getPlayer().getUniqueId())) { - editor.remove(event.getPlayer().getUniqueId()); - } - } - - @EventHandler - public void leaveListener(PlayerQuitEvent event) { - if (editor.containsKey(event.getPlayer().getUniqueId())) { - editor.remove(event.getPlayer().getUniqueId()); - } - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/vouchers/ClickListener.java b/src/nl/marido/deluxevouchers/vouchers/ClickListener.java deleted file mode 100644 index 5616250..0000000 --- a/src/nl/marido/deluxevouchers/vouchers/ClickListener.java +++ /dev/null @@ -1,60 +0,0 @@ -package nl.marido.deluxevouchers.vouchers; - -import java.util.UUID; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import nl.marido.deluxevouchers.handlers.DataHandler; -import nl.marido.deluxevouchers.inventory.Confirmation; - -public class ClickListener implements Listener { - - @EventHandler - public void voucherListener(PlayerInteractEvent event) { - Action action = event.getAction(); - if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { - for (String voucher : DataHandler.getSection(DataHandler.vouchers, "vouchers")) { - String path = "vouchers." + voucher + "."; - Player player = event.getPlayer(); - if (player.hasPermission(DataHandler.getString(DataHandler.vouchers, path + "permission"))) { - ItemStack item = event.getPlayer().getItemInHand(); - if (item.getType() == Material.valueOf(DataHandler.getString(DataHandler.vouchers, path + "material"))) { - if (item.getDurability() == (short) DataHandler.getInt(DataHandler.vouchers, path + "data")) { - ItemMeta meta = item.getItemMeta(); - if (meta.hasDisplayName()) { - if (meta.getDisplayName().equals(DataHandler.getString(DataHandler.vouchers, path + "name"))) { - if (meta.hasLore()) { - if (meta.getLore().equals(DataHandler.getStringList(DataHandler.vouchers, path + "lore"))) { - UUID uuid = player.getUniqueId(); - if (!Cooldowns.entries.containsKey(uuid)) { - if (DataHandler.getBoolean(DataHandler.vouchers, path + "confirm")) { - Confirmation.confirmVoucher(player, voucher, item); - } else { - VoucherExecutor.redeemVoucher(player, voucher, item, true); - } - event.setCancelled(true); - } else { - String message = DataHandler.cooldownmessage; - message = message.replaceAll("%time%", String.valueOf(Cooldowns.entries.get(uuid) + 1)); - message = message.replaceAll("%voucher%", voucher); - player.sendMessage(message); - } - } - } - } - } - } - } - } - } - } - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/vouchers/Cooldowns.java b/src/nl/marido/deluxevouchers/vouchers/Cooldowns.java deleted file mode 100644 index 087e332..0000000 --- a/src/nl/marido/deluxevouchers/vouchers/Cooldowns.java +++ /dev/null @@ -1,44 +0,0 @@ -package nl.marido.deluxevouchers.vouchers; - -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.scheduler.BukkitRunnable; - -import nl.marido.deluxevouchers.DeluxeVouchers; -import nl.marido.deluxevouchers.handlers.DataHandler; - -public class Cooldowns { - - public static HashMap entries = new HashMap(); - - public static void addCooldown(final UUID uuid, String voucher) { - try { - if (Bukkit.getPlayer(uuid).hasPermission("deluxevouchers.bypass")) { - return; - } - if (DataHandler.getString(DataHandler.vouchers, "vouchers." + voucher + ".cooldown") != null) { - entries.put(uuid, DataHandler.getInt(DataHandler.vouchers, "vouchers." + voucher + ".cooldown")); - } else { - entries.put(uuid, DataHandler.cooldowndelay); - } - new BukkitRunnable() { - public void run() { - if (entries.get(uuid) <= 0) { - entries.remove(uuid); - cancel(); - } else { - entries.put(uuid, entries.get(uuid) - 1); - } - } - }.runTaskTimer(DeluxeVouchers.getInstance(), 0, 20); - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to add cooldown to the UUID " + uuid + "."); - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/vouchers/VoucherBuilder.java b/src/nl/marido/deluxevouchers/vouchers/VoucherBuilder.java deleted file mode 100644 index cd6cf8c..0000000 --- a/src/nl/marido/deluxevouchers/vouchers/VoucherBuilder.java +++ /dev/null @@ -1,50 +0,0 @@ -package nl.marido.deluxevouchers.vouchers; - -import java.util.ArrayList; - -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import nl.marido.deluxevouchers.DeluxeVouchers; -import nl.marido.deluxevouchers.handlers.DataHandler; - -public class VoucherBuilder { - - public static ItemStack getVoucher(String voucher, int amount) { - try { - String path = "vouchers." + voucher + "."; - String material = DataHandler.getString(DataHandler.vouchers, path + "material"); - String name = DataHandler.getString(DataHandler.vouchers, path + "name"); - ArrayList lore = DataHandler.getStringList(DataHandler.vouchers, path + "lore"); - short data = (short) DataHandler.getInt(DataHandler.vouchers, path + "data"); - ItemStack item = new ItemStack(Material.valueOf(material), amount, data); - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(name); - meta.setLore(lore); - if (DataHandler.getBoolean(DataHandler.vouchers, path + "glow")) { - meta.addEnchant(Enchantment.DURABILITY, 1, false); - meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - } - if (DataHandler.getBoolean(DataHandler.vouchers, path + "unbreakable")) { - meta.spigot().setUnbreakable(true); - } - if (DataHandler.getBoolean(DataHandler.vouchers, path + "hide-attributes")) { - meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); - meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); - } - item.setItemMeta(meta); - return item; - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to build and create the voucher " + voucher + "."); - DeluxeVouchers.printConsole("§cMake sure to update your voucher options or reset it."); - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - return null; - } - -} \ No newline at end of file diff --git a/src/nl/marido/deluxevouchers/vouchers/VoucherExecutor.java b/src/nl/marido/deluxevouchers/vouchers/VoucherExecutor.java deleted file mode 100644 index e5d5896..0000000 --- a/src/nl/marido/deluxevouchers/vouchers/VoucherExecutor.java +++ /dev/null @@ -1,136 +0,0 @@ -package nl.marido.deluxevouchers.vouchers; - -import org.bukkit.Bukkit; -import org.bukkit.Effect; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import nl.marido.deluxevouchers.DeluxeVouchers; -import nl.marido.deluxevouchers.events.VoucherRedeemEvent; -import nl.marido.deluxevouchers.handlers.Connections; -import nl.marido.deluxevouchers.handlers.DataHandler; -import nl.marido.deluxevouchers.handlers.PreventHacks; -import nl.marido.deluxevouchers.handlers.SoundHandler; -import nl.marido.deluxevouchers.liberaries.Bountiful; - -public class VoucherExecutor { - - public static void redeemVoucher(Player player, String voucher, ItemStack item, boolean manual) { - try { - VoucherRedeemEvent event = new VoucherRedeemEvent(player, voucher, item, manual); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return; - } - String path = "vouchers." + voucher + "."; - boolean duplication = false; - if (!player.getItemInHand().isSimilar(item)) { - duplication = true; - } - if (!duplication) { - if (manual) { - Cooldowns.addCooldown(player.getUniqueId(), voucher); - if (DataHandler.getBoolean(DataHandler.vouchers, path + "remove-item")) { - ItemStack clone = player.getItemInHand().clone(); - if (clone.getAmount() <= 1) { - clone.setType(Material.AIR); - } else { - clone.setAmount(clone.getAmount() - 1); - } - player.setItemInHand(clone); - player.updateInventory(); - } - } - if (DataHandler.getBoolean(DataHandler.vouchers, path + "feed-player")) { - player.setFoodLevel(20); - } - if (DataHandler.getBoolean(DataHandler.vouchers, path + "heal-player")) { - player.setHealth(player.getMaxHealth()); - } - if (DataHandler.getBoolean(DataHandler.vouchers, path + "smite-effect")) { - player.getWorld().strikeLightningEffect(player.getLocation()); - } - String name = player.getName(); - for (String broadcast : DataHandler.getStringList(DataHandler.vouchers, path + "broadcasts")) { - broadcast = broadcast.replaceAll("%player%", name); - broadcast = broadcast.replaceAll("%voucher%", voucher); - for (Player everyone : Bukkit.getOnlinePlayers()) { - everyone.sendMessage(broadcast); - } - } - for (String message : DataHandler.getStringList(DataHandler.vouchers, path + "messages")) { - message = message.replaceAll("%player%", name); - message = message.replaceAll("%voucher%", voucher); - player.sendMessage(message); - } - for (String command : DataHandler.getStringList(DataHandler.vouchers, path + "commands")) { - command = command.replaceAll("%player%", name); - command = command.replaceAll("%voucher%", voucher); - if (command.startsWith("[player]")) { - command = command.replace("[player]", ""); - player.performCommand(command); - } else if (command.startsWith("[op]")) { - command = command.replace("[op]", ""); - boolean wasop = player.isOp(); - PreventHacks.commands.put(player.getUniqueId(), command); - player.setOp(true); - player.performCommand(command); - if (!wasop) { - player.setOp(false); - } - PreventHacks.commands.remove(player.getUniqueId()); - } else if (command.startsWith("[chat]")) { - command = command.replace("[chat]", ""); - player.chat(command); - } else if (command.startsWith("[delay]")) { - command = command.replace("[delay]", ""); - throw new UnsupportedOperationException("delay is not supported yet"); - } else { - Bukkit.getServer().dispatchCommand(DeluxeVouchers.console, command); - } - } - String actionbar = DataHandler.getString(DataHandler.vouchers, path + "actionbar"); - actionbar = actionbar.replaceAll("%player%", name); - actionbar = actionbar.replaceAll("%voucher%", voucher); - Bountiful.sendActionBar(player, actionbar); - String title = DataHandler.getString(DataHandler.vouchers, path + "titles.title"); - title = title.replaceAll("%player%", name); - title = title.replaceAll("%voucher%", voucher); - String subtitle = DataHandler.getString(DataHandler.vouchers, path + "titles.subtitle"); - subtitle = subtitle.replaceAll("%player%", name); - subtitle = subtitle.replaceAll("%voucher%", voucher); - int fadein = DataHandler.getInt(DataHandler.vouchers, path + "titles.fade-in"); - int stay = DataHandler.getInt(DataHandler.vouchers, path + "titles.stay"); - int fadeout = DataHandler.getInt(DataHandler.vouchers, path + "titles.fade-out"); - Bountiful.sendTitle(player, fadein, stay, fadeout, title, subtitle); - String sound = DataHandler.getString(DataHandler.vouchers, path + "sounds.sound"); - int pitch = DataHandler.getInt(DataHandler.vouchers, path + "sounds.pitch"); - SoundHandler.playSound(player, sound, pitch); - String particle = DataHandler.getString(DataHandler.vouchers, path + "particles.particle"); - if (!particle.isEmpty()) { - int amount = DataHandler.getInt(DataHandler.vouchers, path + "particles.amount"); - player.getWorld().playEffect(player.getLocation(), Effect.valueOf(particle), amount); - } - String effect = DataHandler.getString(DataHandler.vouchers, path + "effects.effect"); - if (!effect.isEmpty()) { - int amplifier = DataHandler.getInt(DataHandler.vouchers, path + "particles.amplifier"); - int duration = DataHandler.getInt(DataHandler.vouchers, path + "particles.duration") * 20; - player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(effect), duration, amplifier)); - } - DeluxeVouchers.printConsole("§f" + player.getName() + " has successfully redeemed the voucher " + voucher + "."); - Connections.saveRedeem(player, voucher); - } else { - DeluxeVouchers.printConsole("§c" + player.getName() + " has failed to duplicate the voucher " + voucher + "."); - } - } catch (Exception error) { - DeluxeVouchers.printConsole("§cFailed to redeem the voucher " + voucher + " for the player " + player.getName() + "."); - if (DataHandler.debugerrors) { - error.printStackTrace(); - } - } - } - -} \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml deleted file mode 100644 index 5438d59..0000000 --- a/src/plugin.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: DeluxeVouchers -main: nl.marido.deluxevouchers.DeluxeVouchers -version: 6.0.7 -author: Marido -website: https://marido.host/deluxevouchers -description: Enhance your server with awesome customizable vouchers with a lot of features. -commands: - deluxevouchers: - description: Administrator commands for the DeluxeVouchers resource. - aliases: [dv, deluxev, dvouchers, deluxevoucher] \ No newline at end of file