Skip to content

Commit

Permalink
Vault integration implemented.
Browse files Browse the repository at this point in the history
Added vault support.
Added config with placeholder for message.
  • Loading branch information
Sean1472 committed Sep 1, 2020
1 parent 5af9999 commit 8b8ec96
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Commands:
- "[sendMessage] &7Twitter link: &cTWITTER.COM"

Messages:
onCooldown: "&c&l(!) &fYou are on cooldown for another &c%remaining% seconds&f."
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!"
3 changes: 3 additions & 0 deletions src/me/sean0402/projectlinks/Listener/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()))));
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/me/sean0402/projectlinks/ProjectLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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));
Expand Down Expand Up @@ -56,4 +63,8 @@ private void registerListeners(Listener... listeners) {
public static ProjectLinks getInstance() {
return instance;
}

public Vault getVault() {
return vault;
}
}
31 changes: 31 additions & 0 deletions src/me/sean0402/projectlinks/Vault/Vault.java
Original file line number Diff line number Diff line change
@@ -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<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
if (rsp == null) return false;
econ = rsp.getProvider();
return true;
}

public Economy getEcon() {
return econ;
}


}
5 changes: 5 additions & 0 deletions src/me/sean0402/projectlinks/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: ProjectLinks
main: me.sean0402.projectlinks.ProjectLinks
author: Sean0402 (Sean#4543)
version: 1.0.0-Alpha
version: 1.0.0-Alpha
softdepend: [Vault]

0 comments on commit 8b8ec96

Please sign in to comment.