Last active
August 29, 2015 13:55
-
-
Save codermason/8721601 to your computer and use it in GitHub Desktop.
plugin request by user on Spigot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codermason.bt; | |
import net.milkbowl.vault.economy.Economy; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.EventPriority; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.player.AsyncPlayerChatEvent; | |
import org.bukkit.plugin.RegisteredServiceProvider; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class BalanceTag extends JavaPlugin { | |
private Economy econ; | |
public void onEnable() { | |
if(!setupEconomy()) { | |
this.getLogger().warning("Could not hook into Vault! Disabling..."); | |
this.getPluginLoader().disablePlugin(this); | |
}else{ | |
this.getLogger().info("Hooked into Vault! "); | |
} | |
this.getServer().getPluginManager().registerEvents(new Listener() { | |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) | |
public void onChat(AsyncPlayerChatEvent e) { | |
if(e.isCancelled()) return; | |
if(e.getFormat().contains("{BALANCE}")) | |
e.setFormat(e.getFormat().replace("{BALANCE}", getBalance(e.getPlayer())+"")); | |
} | |
}, this); | |
} | |
private boolean setupEconomy() { | |
if(getServer().getPluginManager().getPlugin("Vault") == null) | |
return false; | |
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class); | |
if(rsp == null) | |
return false; | |
econ = rsp.getProvider(); | |
return econ != null; | |
} | |
private int getBalance(Player p) { | |
return (int) (econ.getBalance(p.getName())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment