From 8b8ec96321aea86a4e25e95b1036d3efbe763730 Mon Sep 17 00:00:00 2001 From: Sean W Date: Tue, 1 Sep 2020 22:12:00 +0100 Subject: [PATCH] Vault integration implemented. Added vault support. Added config with placeholder for message. --- src/config.yml | 3 +- .../Listener/CommandListener.java | 3 ++ .../sean0402/projectlinks/ProjectLinks.java | 11 +++++++ src/me/sean0402/projectlinks/Vault/Vault.java | 31 +++++++++++++++++++ src/me/sean0402/projectlinks/utils/Utils.java | 5 +++ src/plugin.yml | 3 +- 6 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/me/sean0402/projectlinks/Vault/Vault.java diff --git a/src/config.yml b/src/config.yml index 8346a0b..6dbe80a 100644 --- a/src/config.yml +++ b/src/config.yml @@ -16,4 +16,5 @@ Commands: - "[sendMessage] &7Twitter link: &cTWITTER.COM" Messages: - onCooldown: "&c&l(!) &fYou are on cooldown for another &c%remaining% seconds&f." \ No newline at end of file + onCooldown: "&c&l(!) &fYou are on cooldown for another &c%remaining% seconds&f." + takenMoney: "&6&l(!) &6%price% &fhas been taken from your balance for running this command!" \ No newline at end of file diff --git a/src/me/sean0402/projectlinks/Listener/CommandListener.java b/src/me/sean0402/projectlinks/Listener/CommandListener.java index e0eaa4b..a05f254 100644 --- a/src/me/sean0402/projectlinks/Listener/CommandListener.java +++ b/src/me/sean0402/projectlinks/Listener/CommandListener.java @@ -28,7 +28,10 @@ public void onCommandSend(PlayerCommandPreprocessEvent e) { e.setCancelled(true); if (!manager.tryCooldown(e.getPlayer().getUniqueId(), command.getDelay())) { e.getPlayer().sendMessage(Utils.colour(ProjectLinks.getInstance().getConfig().getString("Messages.onCooldown").replace("%remaining%", String.valueOf(manager.getTimeReamining(e.getPlayer()))))); + return; } + ProjectLinks.getInstance().getVault().getEcon().withdrawPlayer(e.getPlayer(), command.getCost()); + e.getPlayer().sendMessage(Utils.colour(ProjectLinks.getInstance().getConfig().getString("Messages.takenMoney").replace("%price%", String.valueOf(command.getCost())))); } } } diff --git a/src/me/sean0402/projectlinks/ProjectLinks.java b/src/me/sean0402/projectlinks/ProjectLinks.java index c2af980..e570c2f 100644 --- a/src/me/sean0402/projectlinks/ProjectLinks.java +++ b/src/me/sean0402/projectlinks/ProjectLinks.java @@ -4,6 +4,8 @@ import me.sean0402.projectlinks.Listener.CommandListener; import me.sean0402.projectlinks.Listener.PlayerQuit; import me.sean0402.projectlinks.OOP.Command; +import me.sean0402.projectlinks.Vault.Vault; +import me.sean0402.projectlinks.utils.Utils; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.Listener; @@ -19,6 +21,7 @@ public class ProjectLinks extends JavaPlugin { private static ProjectLinks instance; + private final Vault vault = new Vault(); private final CooldownManager manager = new CooldownManager(); @@ -27,6 +30,10 @@ public class ProjectLinks extends JavaPlugin { @Override public void onEnable() { instance = this; + if (!vault.setupEconomy()) { + Utils.sendConsoleMessage("&cWARNING"); + Utils.sendConsoleMessage("&fVault not found! Please download an economy plugin to use the cost feature!"); + } saveDefaultConfig(); loadCommands(); registerListeners(new CommandListener(manager), new PlayerQuit(manager)); @@ -56,4 +63,8 @@ private void registerListeners(Listener... listeners) { public static ProjectLinks getInstance() { return instance; } + + public Vault getVault() { + return vault; + } } diff --git a/src/me/sean0402/projectlinks/Vault/Vault.java b/src/me/sean0402/projectlinks/Vault/Vault.java new file mode 100644 index 0000000..53eac12 --- /dev/null +++ b/src/me/sean0402/projectlinks/Vault/Vault.java @@ -0,0 +1,31 @@ +package me.sean0402.projectlinks.Vault; + +import net.milkbowl.vault.economy.Economy; +import org.bukkit.Bukkit; +import org.bukkit.plugin.RegisteredServiceProvider; + +/* + Created on 01/09/2020 at 21:59 + Author - Sean +*/ +public class Vault { + + private Economy econ; + + public boolean setupEconomy() { + if (Bukkit.getPluginManager().getPlugin("Vault") == null) { + return false; + } + + RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Economy.class); + if (rsp == null) return false; + econ = rsp.getProvider(); + return true; + } + + public Economy getEcon() { + return econ; + } + + +} diff --git a/src/me/sean0402/projectlinks/utils/Utils.java b/src/me/sean0402/projectlinks/utils/Utils.java index f5d034e..60b8a4e 100644 --- a/src/me/sean0402/projectlinks/utils/Utils.java +++ b/src/me/sean0402/projectlinks/utils/Utils.java @@ -3,6 +3,7 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -22,6 +23,10 @@ public static String colour(String message) { return message == null ? "String is null!" : ChatColor.translateAlternateColorCodes('&', message); } + public static void sendConsoleMessage(String... messages) { + for(String s : messages) Bukkit.getConsoleSender().sendMessage(colour(s)); + } + public static void sendTitle(Player p, String title, String subTitle, int fadeIn, int stay, int fadeOut) { //todo: add 1.8 fade in timers. p.sendTitle(colour(title), colour(subTitle), fadeIn, stay, fadeOut); diff --git a/src/plugin.yml b/src/plugin.yml index 32b1ebb..a3dcaae 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,4 +1,5 @@ name: ProjectLinks main: me.sean0402.projectlinks.ProjectLinks author: Sean0402 (Sean#4543) -version: 1.0.0-Alpha \ No newline at end of file +version: 1.0.0-Alpha +softdepend: [Vault] \ No newline at end of file