Advertisement
Guest User

Untitled

a guest
Sep 4th, 2012
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.32 KB | None | 0 0
  1. package me.tommycake50.enchant4cash;
  2.  
  3. import java.util.logging.Logger;
  4.  
  5. import net.milkbowl.vault.economy.Economy;
  6. import net.milkbowl.vault.economy.EconomyResponse;
  7.  
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.enchantments.Enchantment;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.plugin.PluginDescriptionFile;
  14. import org.bukkit.plugin.RegisteredServiceProvider;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class Enchant4cash extends JavaPlugin{
  18.     /* gets the minecraft logger */
  19.     public final Logger logger = Logger.getLogger("Minecraft");
  20.     /* declares the variable econ for further use */
  21.     public Economy econ;
  22.     /* does the stuff in the body when the plugin gets enabled */
  23.     @Override
  24.     public void onEnable() {
  25.        
  26.         PluginDescriptionFile pdffile = getDescription();
  27.         logger.info("[" + pdffile.getName()+ "]" + " version: " + pdffile.getVersion() + " has been enabled!");
  28.        
  29.         loadConfig();
  30.  
  31.         setupEconomy();
  32.     }
  33.    
  34.     public void loadConfig() {
  35.         this.getConfig();
  36.             saveDefaultConfig();
  37.          this.reloadConfig();
  38.     }
  39.  
  40.     public boolean setupEconomy()
  41.     {
  42.         RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
  43.         if(rsp == null)
  44.         {
  45.             return false;
  46.         }
  47.         econ = rsp.getProvider();
  48.         return econ != null;
  49.     }
  50.     @Override
  51.     public void onDisable(){
  52.         PluginDescriptionFile pdffile = getDescription();
  53.             logger.info("[" + pdffile.getName() + "]" + " Has been disabled");
  54.     }
  55.         public boolean OnCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
  56.                 /* gets the player name */
  57.             Player player = (Player) sender;
  58.             /* gets the name of the player */
  59.             String playername = player.getDisplayName();
  60.             /* sets what you type in after the slash to activate this plugins features */
  61.             if(player.hasPermission("enchant.use") && CommandLabel.equalsIgnoreCase("enchant4cash")){
  62.                 if (args.length == 1) {
  63.                     player.getInventory();
  64.                     /* enchans the item that the player is holding after checking what enchantment he wants */
  65.                     switch(args[0]){
  66.                     case "unbreaking":
  67.                          /* withdraws money from the sender's account */
  68.                         EconomyResponse r = econ.withdrawPlayer(playername, getConfig().getDouble("priceunbreaking"));
  69.                         if(r.transactionSuccess()){
  70.                             /* enchants the item */
  71.                             player.getInventory().getItemInHand().addEnchantment(Enchantment.DURABILITY, getConfig().getInt("enchantlevel"));
  72.                             /* sends a notifying message */
  73.                             player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceunbreaking"));
  74.                         }else{
  75.                         player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
  76.                         }
  77.                         break;
  78.                     case "efficiency":
  79.                         EconomyResponse r1 = econ.withdrawPlayer(playername, getConfig().getDouble("priceefficiency"));
  80.                         if(r1.transactionSuccess()){
  81.                             player.getInventory().getItemInHand().addEnchantment(Enchantment.DIG_SPEED, getConfig().getInt("enchantlevel"));
  82.                    
  83.                             player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceefficiency"));
  84.                         }else{
  85.                             player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
  86.                         }
  87.                         break;
  88.                     case "silktouch":
  89.                    
  90.                         EconomyResponse r2 = econ.withdrawPlayer(playername, getConfig().getDouble("pricesilktouch"));
  91.                         if(r2.transactionSuccess()){
  92.                             player.getInventory().getItemInHand().addEnchantment(Enchantment.SILK_TOUCH, getConfig().getInt("enchantlevel"));
  93.                        
  94.                             player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricesilktouch"));
  95.                         }else{
  96.                             player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
  97.                         }
  98.                         break;
  99.                     case "fireaspect":
  100.                         EconomyResponse r3 =  econ.withdrawPlayer(playername, getConfig().getDouble("pricefireaspect"));
  101.                         if(r3.transactionSuccess()){
  102.                             player.getInventory().getItemInHand().addEnchantment(Enchantment.FIRE_ASPECT, getConfig().getInt("enchantlevel"));
  103.                    
  104.                             player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricefireaspect"));
  105.                         }else{
  106.                             player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
  107.                         }
  108.                         break;
  109.                     case "knockback":
  110.                         EconomyResponse r4 = econ.withdrawPlayer(playername, getConfig().getDouble("priceknockback"));
  111.                         if(r4.transactionSuccess()){
  112.                             player.getInventory().getItemInHand().addEnchantment(Enchantment.KNOCKBACK, getConfig().getInt("enchantlevel"));
  113.                    
  114.                             player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceknockback"));
  115.                         }else{
  116.                             player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
  117.                         }
  118.                         break;
  119.                     case "smite":
  120.                         EconomyResponse r5 = econ.withdrawPlayer(playername, getConfig().getDouble("pricesmite"));
  121.                         if(r5.transactionSuccess()){
  122.                         player.getInventory().getItemInHand().addEnchantment(Enchantment.DAMAGE_ALL, getConfig().getInt("enchantlevel"));
  123.                    
  124.                         player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricesmite"));
  125.                         }else{
  126.                             player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
  127.                         }
  128.                         break;
  129.                     }
  130.                 }else{
  131.                     player.sendMessage(ChatColor.RED + "wrong number of args");
  132.                 }
  133.                     /* sends a message to the player if they dont have the correct perms */
  134.                 }else if (!player.hasPermission("enchant.use")){
  135.                     player.sendMessage(ChatColor.RED + "You do not have permission to enchant items this way sorry." );
  136.                 }
  137.            
  138.             return true;
  139.         }
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement