Advertisement
Guest User

source code

a guest
Sep 3rd, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.00 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 /* makes it recognisable to bukkit as a plugin */ 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.             sender.sendMessage("DEBUG: Command was been excuted"); // TODO remove this debug message at production code
  57.                 /* gets the player name */
  58.             Player player = (Player) sender;
  59.             /* gets the name of the player */
  60.             String playername = player.getDisplayName();
  61.             /* sets wht  you type in after the slash to activate this plugins features */
  62.             if(args.length == 1 && player.hasPermission("enchant.use") && CommandLabel.equalsIgnoreCase("enchant4cash")){
  63.                 player.getInventory();
  64.                 /* enchans the item that the player is holding after checking what enchantment he wants */
  65.                 switch(args[1]){
  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.                    
  99.                     break;
  100.                 case "fireaspect":
  101.                     EconomyResponse r3 =  econ.withdrawPlayer(playername, getConfig().getDouble("pricefireaspect"));
  102.                     if(r3.transactionSuccess()){
  103.                        
  104.                     player.getInventory().getItemInHand().addEnchantment(Enchantment.FIRE_ASPECT, getConfig().getInt("enchantlevel"));
  105.                    
  106.                     player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricefireaspect"));
  107.                     }else{
  108.                         player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
  109.                     }
  110.                     break;
  111.                 case "knockback":
  112.                     EconomyResponse r4 = econ.withdrawPlayer(playername, getConfig().getDouble("priceknockback"));
  113.                     if(r4.transactionSuccess()){
  114.                     player.getInventory().getItemInHand().addEnchantment(Enchantment.KNOCKBACK, getConfig().getInt("enchantlevel"));
  115.                    
  116.                     player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("priceknockback"));
  117.                     }else{
  118.                         player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
  119.                     }
  120.                     break;
  121.                 case "smite":
  122.                     EconomyResponse r5 = econ.withdrawPlayer(playername, getConfig().getDouble("pricesmite"));
  123.                     if(r5.transactionSuccess()){
  124.                        
  125.                     player.getInventory().getItemInHand().addEnchantment(Enchantment.DAMAGE_ALL, getConfig().getInt("enchantlevel"));
  126.                    
  127.                     player.sendMessage(ChatColor.GREEN + "your item has been enchanted for the sum of" + getConfig().getDouble("pricesmite"));
  128.                     }else{
  129.                         player.sendMessage(ChatColor.RED + "The transaction wasnt successful");
  130.                     }
  131.                     break;
  132.                 }
  133.                
  134.                     /* sends a message to the player if they dont have the correct perms */
  135.                 }else if (!player.hasPermission("enchant.use")){
  136.                     player.sendMessage(ChatColor.RED + "You do not have permission to enchant items this way sorry." );
  137.                 }else{
  138.                     player.sendMessage(ChatColor.RED + "wrong number of args");
  139.                 }
  140.                
  141.            
  142.             return true;
  143.            
  144.         }
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement