SHARE
TWEET

Untitled

a guest Jan 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.mjdk99.main;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Material;
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.EventHandler;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.block.Action;
  12. import org.bukkit.event.player.AsyncPlayerChatEvent;
  13. import org.bukkit.event.player.PlayerInteractEvent;
  14. import org.bukkit.inventory.ItemStack;
  15.  
  16. import com.mjdk99.commands.commandapi.Command;
  17. import com.mjdk99.commands.commandapi.CommandArgs;
  18.  
  19.  
  20. public class BlackSmith implements Listener
  21. {
  22.  
  23.     public static ArrayList<Player> blackSmithPlayers = new ArrayList<Player>();
  24.  
  25.     @Command(name="Blacksmith", aliases={"bs"}, description="Blacksmith")
  26.     public void blackSmith(CommandArgs args)
  27.     {
  28.         CommandSender sender = args.getSender();
  29.         Player player = (Player)sender;
  30.         if ((sender instanceof Player))
  31.         {
  32.             if (player.getItemInHand().getType() == Material.AIR || player.getItemInHand().getType() == null)
  33.             {
  34.                 player.sendMessage(msg("&cYou must be holding an item!"));
  35.                 return;
  36.             }
  37.             if (isSpecialItem(player.getItemInHand()))
  38.             {
  39.                 player.sendMessage(msg("&cThis item cannot be repaired!"));
  40.                 return;
  41.             }
  42.             if (player.getItemInHand().getDurability() == (short)0)
  43.             {
  44.                 player.sendMessage(msg("&cThis item is already repaired"));
  45.                 blackSmithPlayers.remove(player);
  46.                 return;
  47.             }
  48.             if (isItem(player.getItemInHand()))
  49.             {
  50.                 blackSmithPlayers.add(player);
  51.                 player.sendMessage(" ");
  52.                 player.sendMessage(msg("&7Type &9Confirm &7to repair item for &9$1,000,000"));
  53.                 player.sendMessage(msg("&7Left click to &cCancel"));
  54.                 player.sendMessage(" ");
  55.             }
  56.             else
  57.             {
  58.                 player.sendMessage(msg("&cHeld item is not repairable!"));
  59.             }
  60.         }
  61.     }
  62.  
  63.     @EventHandler
  64.     public void onChatEvent(AsyncPlayerChatEvent event)
  65.     {
  66.         Player player = event.getPlayer();
  67.         if (blackSmithPlayers.contains(player))
  68.         {
  69.             event.setCancelled(true);
  70.             if (event.getMessage().equalsIgnoreCase("confirm"))
  71.             {
  72.                 //Check if player has $1,000,000
  73.                 //If not, send
  74.                 //player.sendmessage(msg("&cinsufficent funds"));
  75.                
  76.                 player.getItemInHand().setDurability((short)0);
  77.                 player.sendMessage(msg("&aSuccessfully repaired item!"));
  78.                 blackSmithPlayers.remove(player);
  79.             }
  80.         }
  81.  
  82.     }
  83.  
  84.     @EventHandler
  85.     public void interactEvent(PlayerInteractEvent event)
  86.     {
  87.         Player player = event.getPlayer();
  88.         if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR)
  89.             if (blackSmithPlayers.contains(player))
  90.             {
  91.                 blackSmithPlayers.remove(player);
  92.                 player.sendMessage(msg("&cRepair cancelled!"));
  93.             }
  94.     }
  95.    
  96.     public boolean isSpecialItem(ItemStack is)
  97.     {
  98.         if (is.getItemMeta().getLore() == null)
  99.             return false;
  100.         for(String s:is.getItemMeta().getLore())
  101.         {
  102.             if (s.contains("Condense") || s.contains("Autosell") || s.contains("Smelting") || s.contains("Shatter"))
  103.                 return true;
  104.            
  105.         }
  106.         return false;
  107.     }
  108.  
  109.     public boolean isItem(ItemStack is)
  110.     {
  111.         String name = ChatColor.stripColor(is.getType().toString());
  112.         if (name.contains("_SWORD") || name.contains("_PICKAXE") || name.contains("_AXE") || name.contains("_SHOVEL") ||
  113.                 name.contains("_HELMET") || name.contains("_CHESTPLATE") || name.contains("_LEGGINGS") || name.contains("_BOOTS"))
  114.         {
  115.             return true;
  116.         }
  117.         return false;
  118.     }
  119.  
  120.     private String msg(String s)
  121.     {
  122.         return ChatColor.translateAlternateColorCodes('&', s);
  123.     }
  124.  
  125. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top