123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- package com.gmail.nossr50;
- import org.bukkit.ChatColor;
- import org.bukkit.block.Block;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- public class mcRepair {
- private static mcMMO plugin;
- public mcRepair(mcMMO instance) {
- plugin = instance;
- }
- private static volatile mcRepair instance;
- public static mcRepair getInstance() {
- if (instance == null) {
- instance = new mcRepair(plugin);
- }
- return instance;
- }
- public void repairCheck(Player player, ItemStack is, Block block){
- player.sendMessage("mcMMO Debug: The block is an Anvil.");
- if(block != null
- && mcPermissions.getInstance().repair(player)){
- player.sendMessage("mcMMO Debug: The block is not null and the player has access to repair.");
- if(player.getItemInHand().getDurability() > 0){
- player.sendMessage("mcMMO Debug: The item is not at full durability.");
- /*
- * ARMOR
- */
- if(isArmor(is)){
- player.sendMessage("mcMMO Debug: The item is armor.");
- /*
- * DIAMOND ARMOR
- */
- if(isDiamondArmor(is) && hasDiamond(player) && mcUsers.getProfile(player).getRepairInt() >= 50){
- player.sendMessage("mcMMO Debug: CODE 1");
- removeDiamond(player);
- player.getItemInHand().setDurability(getArmorRepairAmount(is, player));
- mcUsers.getProfile(player).addRepairGather(75);
- } else if (isIronArmor(is) && hasIron(player)){
- player.sendMessage("mcMMO Debug: CODE 2");
- /*
- * IRON ARMOR
- */
- removeIron(player);
- player.getItemInHand().setDurability(getArmorRepairAmount(is, player));
- mcUsers.getProfile(player).addRepairGather(20);
- //GOLD ARMOR
- } else if (isGoldArmor(is) && hasGold(player)){
- player.sendMessage("mcMMO Debug: CODE 3");
- removeGold(player);
- player.getItemInHand().setDurability(getArmorRepairAmount(is, player));
- mcUsers.getProfile(player).addRepairGather(50);
- } else {
- needMoreVespeneGas(is, player);
- }
- }
- /*
- * TOOLS
- */
- if(isTools(is)){
- /*
- * IRON TOOLS
- */
- if(isIronTools(is) && hasIron(player)){
- player.sendMessage("mcMMO Debug: CODE 4");
- is.setDurability(getToolRepairAmount(is, player));
- removeIron(player);
- mcUsers.getProfile(player).addRepairGather(20);
- } else if (isDiamondTools(is) && hasDiamond(player) && mcUsers.getProfile(player).getRepairInt() >= 50){ //Check if its diamond and the player has diamonds
- /*
- * DIAMOND TOOLS
- */
- player.sendMessage("mcMMO Debug: CODE 5");
- is.setDurability(getToolRepairAmount(is, player));
- removeDiamond(player);
- mcUsers.getProfile(player).addRepairGather(75);
- } else if(isGoldTools(is) && hasGold(player)){
- player.sendMessage("mcMMO Debug: CODE 6");
- is.setDurability(getToolRepairAmount(is, player));
- removeGold(player);
- mcUsers.getProfile(player).addRepairGather(50);
- } else {
- player.sendMessage("mcMMO Debug: CODE 7");
- needMoreVespeneGas(is, player);
- }
- }
-
- } else {
- player.sendMessage("That is at full durability.");
- }
- player.updateInventory();
- /*
- * GIVE SKILL IF THERE IS ENOUGH XP
- */
- if(mcUsers.getProfile(player).getRepairGatherInt() >= mcUsers.getProfile(player).getXpToLevel("repair")){
- int skillups = 0;
- while(mcUsers.getProfile(player).getRepairGatherInt() >= mcUsers.getProfile(player).getXpToLevel("repair")){
- skillups++;
- mcUsers.getProfile(player).removeRepairGather(mcUsers.getProfile(player).getXpToLevel("repair"));
- mcUsers.getProfile(player).skillUpRepair(1);
- }
- player.sendMessage(ChatColor.YELLOW+"Repair skill increased by "+skillups+"."+" Total ("+mcUsers.getProfile(player).getRepair()+")");
- }
- }
- }
- public boolean isArmor(ItemStack is){
- if(is.getTypeId() == 306 || is.getTypeId() == 307 ||is.getTypeId() == 308 ||is.getTypeId() == 309 ||
- is.getTypeId() == 310 ||is.getTypeId() == 311 ||is.getTypeId() == 312 ||is.getTypeId() == 313 ||
- is.getTypeId() == 314 || is.getTypeId() == 315 || is.getTypeId() == 316 || is.getTypeId() == 317){
- return true;
- } else {
- return false;
- }
- }
- public boolean isGoldArmor(ItemStack is){
- if(is.getTypeId() == 314 || is.getTypeId() == 315 || is.getTypeId() == 316 || is.getTypeId() == 317){
- return true;
- } else {
- return false;
- }
- }
- public boolean isIronArmor(ItemStack is){
- if(is.getTypeId() == 306 || is.getTypeId() == 307 || is.getTypeId() == 308 || is.getTypeId() == 309)
- {
- return true;
- } else {
- return false;
- }
- }
- public boolean isDiamondArmor(ItemStack is){
- if(is.getTypeId() == 310 || is.getTypeId() == 311 || is.getTypeId() == 312 || is.getTypeId() == 313)
- {
- return true;
- } else {
- return false;
- }
- }
- public boolean isTools(ItemStack is){
- if(is.getTypeId() == 256 || is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267 || is.getTypeId() == 292 || //IRON
- is.getTypeId() == 276 || is.getTypeId() == 277 || is.getTypeId() == 278 || is.getTypeId() == 279 || is.getTypeId() == 293 || //DIAMOND
- is.getTypeId() == 283 || is.getTypeId() == 285 || is.getTypeId() == 286 || is.getTypeId() == 284) //GOLD
- {
- return true;
- } else {
- return false;
- }
- }
- public boolean isGoldTools(ItemStack is){
- if(is.getTypeId() == 283 || is.getTypeId() == 285 || is.getTypeId() == 286 || is.getTypeId() == 284 || is.getTypeId() == 294){
- return true;
- } else {
- return false;
- }
- }
- public boolean isIronTools(ItemStack is){
- if(is.getTypeId() == 256 || is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267 || is.getTypeId() == 292)
- {
- return true;
- } else {
- return false;
- }
- }
-
- public boolean isDiamondTools(ItemStack is){
- if(is.getTypeId() == 276 || is.getTypeId() == 277 || is.getTypeId() == 278 || is.getTypeId() == 279 || is.getTypeId() == 293)
- {
- return true;
- } else {
- return false;
- }
- }
- public void removeIron(Player player){
- ItemStack[] inventory = player.getInventory().getContents();
- for(ItemStack x : inventory){
- if(x.getTypeId() == 265){
- if(x.getAmount() == 1){
- x.setTypeId(0);
- x.setAmount(0);
- player.getInventory().setContents(inventory);
- } else{
- x.setAmount(x.getAmount() - 1);
- player.getInventory().setContents(inventory);
- }
- return;
- }
- }
- }
- public void removeGold(Player player){
- ItemStack[] inventory = player.getInventory().getContents();
- for(ItemStack x : inventory){
- if(x.getTypeId() == 266){
- if(x.getAmount() == 1){
- x.setTypeId(0);
- x.setAmount(0);
- player.getInventory().setContents(inventory);
- } else{
- x.setAmount(x.getAmount() - 1);
- player.getInventory().setContents(inventory);
- }
- return;
- }
- }
- }
- public void removeDiamond(Player player){
- ItemStack[] inventory = player.getInventory().getContents();
- for(ItemStack x : inventory){
- if(x.getTypeId() == 264){
- if(x.getAmount() == 1){
- x.setTypeId(0);
- x.setAmount(0);
- player.getInventory().setContents(inventory);
- } else{
- x.setAmount(x.getAmount() - 1);
- player.getInventory().setContents(inventory);
- }
- return;
- }
- }
- }
- public boolean hasGold(Player player){
- ItemStack[] inventory = player.getInventory().getContents();
- for(ItemStack x : inventory){
- if(x.getTypeId() == 266){
- return true;
- }
- }
- return false;
- }
- public boolean hasDiamond(Player player){
- ItemStack[] inventory = player.getInventory().getContents();
- for(ItemStack x : inventory){
- if(x.getTypeId() == 264){
- return true;
- }
- }
- return false;
- }
- public boolean hasIron(Player player){
- ItemStack[] inventory = player.getInventory().getContents();
- for(ItemStack x : inventory){
- if(x.getTypeId() == 265){
- return true;
- }
- }
- return false;
- }
- public short getToolRepairAmount(ItemStack is, Player player){
- short durability = is.getDurability();
- switch(is.getTypeId())
- {
- case 284:
- durability = 0;
- break;
- case 256:
- durability = 0;
- break;
- case 277:
- durability = 0;
- break;
- case 257:
- durability -= 84;
- break;
- case 258:
- durability -= 84;
- break;
- case 267:
- durability -= 84;
- break;
- case 292:
- durability -= 84;
- break;
- case 276:
- durability -= 509;
- break;
- case 278:
- durability -= 509;
- break;
- case 279:
- durability -= 509;
- break;
- case 293:
- durability -= 509;
- break;
- case 283:
- durability -= 13;
- break;
- case 285:
- durability -= 13;
- break;
- case 286:
- durability -= 13;
- break;
- case 294:
- durability -= 13;
- break;
- }
- if(durability < 0)
- durability = 0;
- if(checkPlayerProcRepair(player))
- durability = 0;
- return durability;
- }
- //This determines how much we repair
- public short getArmorRepairAmount(ItemStack is, Player player){
- short durability = is.getDurability();
- switch(is.getTypeId())
- {
- case 306:
- durability -= 27;
- break;
- case 310:
- durability -= 55;
- break;
- case 307:
- durability -= 24;
- break;
- case 311:
- durability -= 48;
- break;
- case 308:
- durability -= 27;
- break;
- case 312:
- durability -= 53;
- break;
- case 309:
- durability -= 40;
- break;
- case 313:
- durability -= 80;
- break;
- }
- if(durability < 0)
- durability = 0;
- if(checkPlayerProcRepair(player))
- durability = 0;
- return durability;
- }
- public void needMoreVespeneGas(ItemStack is, Player player){
- if ((isDiamondTools(is) || isDiamondArmor(is)) && mcUsers.getProfile(player).getRepairInt() < 50){
- player.sendMessage(ChatColor.DARK_RED +"You're not adept enough to repair Diamond");
- } else if (isDiamondTools(is) && !hasDiamond(player) || isIronTools(is) && !hasIron(player) || isGoldTools(is) && !hasGold(player)){
- if(isDiamondTools(is) && !hasDiamond(player))
- player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.BLUE+ "Diamonds");
- if(isIronTools(is) && !hasIron(player))
- player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.GRAY+ "Iron");
- //herp
- if(isGoldTools(is) && !hasGold(player))
- player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.GOLD+"Gold");
- } else if (isDiamondArmor(is) && !hasDiamond(player)){
- player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.BLUE+ "Diamonds");
- } else if (isIronArmor(is) && !hasIron(player)){
- player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.GRAY+ "Iron");
- } else if (isGoldArmor(is) && !hasGold(player))
- player.sendMessage(ChatColor.DARK_RED+"You need more "+ChatColor.GOLD+"Gold");
- }
- public boolean checkPlayerProcRepair(Player player){
- if(mcUsers.getProfile(player).getRepairInt() >= 750){
- if(Math.random() * 10 > 2){
- player.sendMessage(ChatColor.GRAY + "That took no effort.");
- return true;
- }
- } else if (mcUsers.getProfile(player).getRepairInt() >= 450 && mcUsers.getProfile(player).getRepairInt() < 750){
- if(Math.random() * 10 > 4){
- player.sendMessage(ChatColor.GRAY + "That felt really easy.");
- return true;
- }
- } else if (mcUsers.getProfile(player).getRepairInt() >= 150 && mcUsers.getProfile(player).getRepairInt() < 450){
- if(Math.random() * 10 > 6){
- player.sendMessage(ChatColor.GRAY + "That felt pretty easy.");
- return true;
- }
- } else if (mcUsers.getProfile(player).getRepairInt() >= 50 && mcUsers.getProfile(player).getRepairInt() < 150){
- if(Math.random() * 10 > 8){
- player.sendMessage(ChatColor.GRAY + "That felt easy.");
- return true;
- }
- }
- return false;
- }
- }
|