Advertisement
ThatBenderGuy

Alchemy Class

Jun 28th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. public class AlchemyListener implements Listener {
  2.     GRPG plugin = GRPG.getPlugin(GRPG.class);
  3.    
  4.     ArrayList<Material> lvl1Pots = new ArrayList<Material>(Arrays.asList(Material.NETHER_WARTS, Material.SPECKLED_MELON, Material.SUGAR));
  5.     ArrayList<Material> lvl5Pots = new ArrayList<Material>(Arrays.asList(Material.RABBIT_FOOT, Material.SPIDER_EYE));
  6.     ArrayList<Material> lvl10Pots = new ArrayList<Material>(Arrays.asList(Material.GOLDEN_CARROT, Material.BLAZE_POWDER));
  7.     ArrayList<Material> lvl15Pots = new ArrayList<Material>(Arrays.asList(Material.RAW_FISH, Material.GHAST_TEAR));
  8.     ArrayList<Material> lvl20Pots = new ArrayList<Material>(Arrays.asList(Material.MAGMA_CREAM, Material.FERMENTED_SPIDER_EYE));
  9.    
  10.    
  11.     @EventHandler
  12.     public void brewEvent(BrewEvent e) {
  13.         Player p = Bukkit.getPlayer(BlockLockerAPI.getOwner(e.getBlock()).get().getUniqueId());
  14.         if(p != null) {
  15.             Material ingredient = e.getContents().getIngredient().getType();
  16.            
  17.             if(ingredient != null && !ingredient.equals(Material.AIR)) {
  18.                 int alchLvl = GRPG.levelManagerHashMap.get(p.getUniqueId()).getSkillLevelWithBonus(SKILLS.ALCHEMY);
  19.                 if(alchLvl < 1) alchLvl = 1;
  20.                 if(canBrew(ingredient, alchLvl)) {
  21.                     int potions = countPotions(e.getContents());
  22.                     int[] minMax = new int[2];
  23.                     minMax[0] = plugin.getExpConfig().getExp(ExpConfig.alchemyPath + "min");
  24.                     minMax[1] = plugin.getExpConfig().getExp(ExpConfig.alchemyPath + "max");
  25.                     int rXp = GRPG.randomXp(minMax[0], minMax[1]) * potions;
  26.                     p.sendMessage(GRPG.gaiaPrefix + "You recieved " + rXp + " xp in alchemy for crafting " + ChatColor.BLUE + potions + ChatColor.WHITE + " potions.");
  27.                     Utilities.giveExperience(SKILLS.ALCHEMY, p, rXp);
  28.                 } else {
  29.                     e.setCancelled(true);
  30.                     p.sendMessage(GRPG.gaiaPrefix + ChatColor.RED + "You do not have the alchemy level to brew this potion.");
  31.                 }
  32.             }
  33.         }
  34.     }
  35.    
  36.     private boolean canBrew(Material ingr, int lvl) {
  37.         if(lvl1Pots.contains(ingr) && lvl >= 1) return true;
  38.         if(lvl5Pots.contains(ingr) && lvl >= 5) return true;
  39.         if(lvl10Pots.contains(ingr) && lvl >= 10) return true;
  40.         if(lvl15Pots.contains(ingr) && lvl >= 15) return true;
  41.         if(lvl20Pots.contains(ingr) && lvl >= 20) return true;
  42.         return false;
  43.     }
  44.    
  45.     private int countPotions(BrewerInventory i) {
  46.         int count = 0;
  47.         if(i.getItem(0).getType() == Material.POTION) count++;
  48.         if(i.getItem(1).getType() == Material.POTION) count++;
  49.         if(i.getItem(2).getType() == Material.POTION) count++;
  50.         return count;
  51.     }
  52.    
  53.    
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement