Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.tommycake50.enchant4cash;
- import java.util.logging.Logger;
- import net.milkbowl.vault.economy.Economy;
- import net.milkbowl.vault.economy.EconomyResponse;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Enchant4cash extends JavaPlugin{
- /* gets the minecraft logger */
- public final Logger logger = Logger.getLogger("Minecraft");
- /* declares the variable econ for further use */
- public Economy econ;
- /* does the stuff in the body when the plugin gets enabled */
- @Override
- public void onEnable() {
- PluginDescriptionFile pdffile = getDescription();
- logger.info("[" + pdffile.getName()+ "]" + " version: " + pdffile.getVersion() + " has been enabled!");
- loadConfig();
- setupEconomy();
- }
- public void loadConfig() {
- this.getConfig();
- saveDefaultConfig();
- this.reloadConfig();
- }
- public boolean setupEconomy()
- {
- RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
- if(rsp == null)
- {
- return false;
- }
- econ = rsp.getProvider();
- return econ != null;
- }
- @Override
- public void onDisable(){
- PluginDescriptionFile pdffile = getDescription();
- logger.info("[" + pdffile.getName() + "]" + " Has been disabled");
- }
- public boolean OnCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
- /* gets the player name */
- Player player = (Player) sender;
- /* gets the name of the player */
- String playername = player.getDisplayName();
- /* sets what you type in after the slash to activate this plugins features */
- if(player.hasPermission("enchant.use") && CommandLabel.equalsIgnoreCase("enchant4cash")){
- if (args.length == 1) {
- player.getInventory();
- /* enchans the item that the player is holding after checking what enchantment he wants */
- switch(args[0]){
- case "unbreaking":
- /* withdraws money from the sender's account */
- EconomyResponse r = econ.withdrawPlayer(playername, getConfig().getDouble("priceunbreaking"));
- if(r.transactionSuccess()){
- /* enchants the item */
- player.getInventory().getItemInHand().addEnchantment(Enchantment.DURABILITY, getConfig().getInt("enchantlevel"));
- /* sends a notifying message */
- player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceunbreaking"));
- }else{
- player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
- }
- break;
- case "efficiency":
- EconomyResponse r1 = econ.withdrawPlayer(playername, getConfig().getDouble("priceefficiency"));
- if(r1.transactionSuccess()){
- player.getInventory().getItemInHand().addEnchantment(Enchantment.DIG_SPEED, getConfig().getInt("enchantlevel"));
- player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceefficiency"));
- }else{
- player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
- }
- break;
- case "silktouch":
- EconomyResponse r2 = econ.withdrawPlayer(playername, getConfig().getDouble("pricesilktouch"));
- if(r2.transactionSuccess()){
- player.getInventory().getItemInHand().addEnchantment(Enchantment.SILK_TOUCH, getConfig().getInt("enchantlevel"));
- player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricesilktouch"));
- }else{
- player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
- }
- break;
- case "fireaspect":
- EconomyResponse r3 = econ.withdrawPlayer(playername, getConfig().getDouble("pricefireaspect"));
- if(r3.transactionSuccess()){
- player.getInventory().getItemInHand().addEnchantment(Enchantment.FIRE_ASPECT, getConfig().getInt("enchantlevel"));
- player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricefireaspect"));
- }else{
- player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
- }
- break;
- case "knockback":
- EconomyResponse r4 = econ.withdrawPlayer(playername, getConfig().getDouble("priceknockback"));
- if(r4.transactionSuccess()){
- player.getInventory().getItemInHand().addEnchantment(Enchantment.KNOCKBACK, getConfig().getInt("enchantlevel"));
- player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceknockback"));
- }else{
- player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
- }
- break;
- case "smite":
- EconomyResponse r5 = econ.withdrawPlayer(playername, getConfig().getDouble("pricesmite"));
- if(r5.transactionSuccess()){
- player.getInventory().getItemInHand().addEnchantment(Enchantment.DAMAGE_ALL, getConfig().getInt("enchantlevel"));
- player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricesmite"));
- }else{
- player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
- }
- break;
- }
- }else{
- player.sendMessage(ChatColor.RED + "wrong number of args");
- }
- /* sends a message to the player if they dont have the correct perms */
- }else if (!player.hasPermission("enchant.use")){
- player.sendMessage(ChatColor.RED + "You do not have permission to enchant items this way sorry." );
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement