mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
Update PR to changes in master
- Special thanks, instead of in dev team - Fix formatting issues * Remove trailing whitespaces * Rename method names of event listeners * Check for negative instead of positive - Added Alchemy skill guide
This commit is contained in:
@ -2,13 +2,11 @@ package com.gmail.nossr50.skills.alchemy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.runnables.skills.AlchemyBrewTask;
|
||||
|
||||
public final class Alchemy {
|
||||
@ -31,7 +29,7 @@ public final class Alchemy {
|
||||
public int toNumerical() {
|
||||
return numerical;
|
||||
}
|
||||
|
||||
|
||||
public static Tier fromNumerical(int numerical) {
|
||||
for (Tier tier : Tier.values()) {
|
||||
if (tier.toNumerical() == numerical) {
|
||||
@ -45,22 +43,21 @@ public final class Alchemy {
|
||||
return AdvancedConfig.getInstance().getConcoctionsTierLevel(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int catalysisUnlockLevel = AdvancedConfig.getInstance().getCatalysisUnlockLevel();
|
||||
public static int catalysisMaxBonusLevel = AdvancedConfig.getInstance().getCatalysisMaxBonusLevel();
|
||||
public static double catalysisMinSpeed = AdvancedConfig.getInstance().getCatalysisMinSpeed();
|
||||
public static double catalysisMaxSpeed = AdvancedConfig.getInstance().getCatalysisMaxSpeed();
|
||||
|
||||
public static double potionXp = ExperienceConfig.getInstance().getPotionXP();
|
||||
|
||||
public static Map<Block, AlchemyBrewTask> brewingStandMap = new HashMap<Block, AlchemyBrewTask>();
|
||||
|
||||
private Alchemy() {};
|
||||
|
||||
private Alchemy() {}
|
||||
|
||||
/**
|
||||
* Calculate base brewing speed, given a skill level and ignoring all perks.
|
||||
*
|
||||
*
|
||||
* @param skillLevel Skill level used for calculation.
|
||||
*
|
||||
* @return Base brewing speed for the level.
|
||||
*/
|
||||
public static double calculateBrewSpeed(int skillLevel) {
|
||||
@ -70,14 +67,14 @@ public final class Alchemy {
|
||||
|
||||
return Math.min(catalysisMaxSpeed, catalysisMinSpeed + (catalysisMaxSpeed - catalysisMinSpeed) * (skillLevel - catalysisUnlockLevel) / (catalysisMaxBonusLevel - catalysisUnlockLevel));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finish all active brews. Used upon Disable to prevent vanilla potions from being brewed upon next Enable.
|
||||
*/
|
||||
public static void finishAllBrews() {
|
||||
mcMMO.p.getLogger().info("Completing " + brewingStandMap.size() + " unfinished Alchemy brews.");
|
||||
for (Entry<Block, AlchemyBrewTask> entry : brewingStandMap.entrySet()) {
|
||||
entry.getValue().finishImmediately();
|
||||
mcMMO.p.debug("Completing " + brewingStandMap.size() + " unfinished Alchemy brews.");
|
||||
for (AlchemyBrewTask alchemyBrewTask : brewingStandMap.values()) {
|
||||
alchemyBrewTask.finishImmediately();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.config.potion.PotionConfig;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@ -20,7 +21,11 @@ public class AlchemyManager extends SkillManager {
|
||||
}
|
||||
|
||||
public boolean canCatalysis() {
|
||||
return Permissions.catalysis(getPlayer());
|
||||
return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.CATALYSIS);
|
||||
}
|
||||
|
||||
public boolean canConcoctions() {
|
||||
return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.CONCOCTIONS);
|
||||
}
|
||||
|
||||
public boolean canUseIngredient(ItemStack item) {
|
||||
@ -66,21 +71,28 @@ public class AlchemyManager extends SkillManager {
|
||||
public String getIngredientList() {
|
||||
String list = "";
|
||||
for (ItemStack ingredient : getIngredients()) {
|
||||
list += ", " + StringUtils.getPrettyItemString(ingredient.getType()) + (ingredient.getDurability() != 0 ? ":" + ingredient.getDurability() : "");
|
||||
String string = StringUtils.getPrettyItemString(ingredient.getType()) + (ingredient.getDurability() != 0 ? ":" + ingredient.getDurability() : "");
|
||||
if (string.equals("LONG_GRASS:2")) {
|
||||
string = "Fern";
|
||||
}
|
||||
else if (string.equals("RAW_FISH:3")) {
|
||||
string = "Pufferfish";
|
||||
}
|
||||
|
||||
list += ", " + string;
|
||||
}
|
||||
return list.substring(2);
|
||||
}
|
||||
|
||||
public double getBrewSpeed() {
|
||||
public double getBrewSpeed() {
|
||||
return Alchemy.calculateBrewSpeed(getSkillLevel());
|
||||
}
|
||||
|
||||
|
||||
public double getBrewSpeedLucky() {
|
||||
return LUCKY_MODIFIER * Alchemy.calculateBrewSpeed(getSkillLevel());
|
||||
}
|
||||
|
||||
|
||||
public void handlePotionBrewSuccesses(int amount) {
|
||||
applyXpGain((float) (ExperienceConfig.getInstance().getPotionXP() * amount));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,36 +21,40 @@ import org.bukkit.inventory.ItemStack;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.potion.PotionConfig;
|
||||
import com.gmail.nossr50.datatypes.AlchemyPotion;
|
||||
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
|
||||
import com.gmail.nossr50.runnables.PlayerUpdateInventoryTask;
|
||||
import com.gmail.nossr50.runnables.skills.AlchemyBrewCheckTask;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
public final class AlchemyPotionBrewer {
|
||||
private final static int[] BOTTLE_SLOTS = new int[] { 0, 1, 2 };
|
||||
private final static int[] BOTTLE_SLOTS = new int[]{0, 1, 2};
|
||||
private final static int INGREDIENT_SLOT = 3;
|
||||
|
||||
public static boolean isValidBrew(Player player, ItemStack[] contents) {
|
||||
if (isValidIngredient(player, contents[INGREDIENT_SLOT])) {
|
||||
for (int bottle : BOTTLE_SLOTS) {
|
||||
if (contents[bottle] != null && contents[bottle].getType() == Material.POTION) {
|
||||
AlchemyPotion potion = PotionConfig.getInstance().potionMap.get(contents[bottle].getDurability());
|
||||
|
||||
if (getChildPotion(potion, contents[INGREDIENT_SLOT]) != null) {
|
||||
return true;
|
||||
}
|
||||
if (!isValidIngredient(player, contents[INGREDIENT_SLOT])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int bottle : BOTTLE_SLOTS) {
|
||||
if (contents[bottle] != null && contents[bottle].getType() == Material.POTION) {
|
||||
AlchemyPotion potion = PotionConfig.getInstance().potionMap.get(contents[bottle].getDurability());
|
||||
|
||||
if (getChildPotion(potion, contents[INGREDIENT_SLOT]) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private static AlchemyPotion getChildPotion(AlchemyPotion potion, ItemStack ingredient) {
|
||||
if (potion != null && potion.getChildDataValue(ingredient) != -1) {
|
||||
return PotionConfig.getInstance().potionMap.get(potion.getChildDataValue(ingredient));
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -60,19 +64,19 @@ public final class AlchemyPotionBrewer {
|
||||
|
||||
private static boolean removeIngredient(BrewerInventory inventory, Player player) {
|
||||
ItemStack ingredient = inventory.getIngredient();
|
||||
|
||||
|
||||
if (isEmpty(ingredient) || !isValidIngredient(player, ingredient)) {
|
||||
return false;
|
||||
}
|
||||
else if (ingredient.getAmount() <= 1) {
|
||||
inventory.setItem(INGREDIENT_SLOT, null);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
ingredient.setAmount(ingredient.getAmount() - 1);
|
||||
inventory.setItem(INGREDIENT_SLOT, ingredient);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -81,21 +85,21 @@ public final class AlchemyPotionBrewer {
|
||||
if (isEmpty(item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
for (ItemStack ingredient : getValidIngredients(player)) {
|
||||
if (item.isSimilar(ingredient)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<ItemStack> getValidIngredients(Player player) {
|
||||
if (player == null || !Permissions.concoctions(player)) {
|
||||
if (player == null || !Permissions.secondaryAbilityEnabled(player, SecondaryAbility.CONCOCTIONS)) {
|
||||
return PotionConfig.getInstance().concoctionsIngredientsTierOne;
|
||||
}
|
||||
|
||||
|
||||
switch (UserManager.getPlayer(player).getAlchemyManager().getTier()) {
|
||||
case 5:
|
||||
return PotionConfig.getInstance().concoctionsIngredientsTierFive;
|
||||
@ -114,38 +118,38 @@ public final class AlchemyPotionBrewer {
|
||||
if (!(brewingStand.getState() instanceof BrewingStand)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
BrewerInventory inventory = ((BrewingStand) brewingStand.getState()).getInventory();
|
||||
ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone();
|
||||
|
||||
if (removeIngredient(inventory, player)) {
|
||||
for (int bottle : BOTTLE_SLOTS) {
|
||||
if (!isEmpty(inventory.getItem(bottle)) && PotionConfig.getInstance().potionMap.containsKey(inventory.getItem(bottle).getDurability())) {
|
||||
AlchemyPotion input = PotionConfig.getInstance().potionMap.get(inventory.getItem(bottle).getDurability());
|
||||
AlchemyPotion output = PotionConfig.getInstance().potionMap.get(input.getChildDataValue(ingredient));
|
||||
|
||||
if (output != null) {
|
||||
inventory.setItem(bottle, output.toItemStack(inventory.getItem(bottle).getAmount()).clone());
|
||||
|
||||
if (player != null) {
|
||||
UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(1);
|
||||
}
|
||||
|
||||
if (!removeIngredient(inventory, player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int bottle : BOTTLE_SLOTS) {
|
||||
if (!isEmpty(inventory.getItem(bottle)) && PotionConfig.getInstance().potionMap.containsKey(inventory.getItem(bottle).getDurability())) {
|
||||
AlchemyPotion input = PotionConfig.getInstance().potionMap.get(inventory.getItem(bottle).getDurability());
|
||||
AlchemyPotion output = PotionConfig.getInstance().potionMap.get(input.getChildDataValue(ingredient));
|
||||
|
||||
if (output != null) {
|
||||
inventory.setItem(bottle, output.toItemStack(inventory.getItem(bottle).getAmount()).clone());
|
||||
|
||||
if (player != null) {
|
||||
UserManager.getPlayer(player).getAlchemyManager().handlePotionBrewSuccesses(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!forced) {
|
||||
scheduleUpdate(inventory);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!forced) {
|
||||
scheduleUpdate(inventory);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean transferOneItem(InventoryView view, int fromSlot, int toSlot) {
|
||||
ItemStack from = view.getItem(fromSlot).clone();
|
||||
ItemStack to = view.getItem(toSlot).clone();
|
||||
|
||||
|
||||
if (isEmpty(from)) {
|
||||
return false;
|
||||
}
|
||||
@ -160,14 +164,14 @@ public final class AlchemyPotionBrewer {
|
||||
else {
|
||||
to.setAmount(to.getAmount() + 1);
|
||||
}
|
||||
|
||||
|
||||
from.setAmount(from.getAmount() - 1);
|
||||
view.setItem(toSlot, isEmpty(to) ? null : to);
|
||||
view.setItem(fromSlot, isEmpty(from) ? null : from);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -181,29 +185,29 @@ public final class AlchemyPotionBrewer {
|
||||
else if (isEmpty(view.getItem(toSlot))) {
|
||||
view.setItem(toSlot, view.getItem(fromSlot).clone());
|
||||
view.setItem(fromSlot, null);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (view.getItem(fromSlot).isSimilar(view.getItem(toSlot))) {
|
||||
if (view.getItem(fromSlot).getAmount() + view.getItem(toSlot).getAmount() > view.getItem(toSlot).getType().getMaxStackSize()) {
|
||||
int left = view.getItem(fromSlot).getAmount() + view.getItem(toSlot).getAmount() - view.getItem(toSlot).getType().getMaxStackSize();
|
||||
|
||||
|
||||
ItemStack to = new ItemStack(view.getItem(toSlot));
|
||||
to.setAmount(to.getType().getMaxStackSize());
|
||||
view.setItem(toSlot, to);
|
||||
|
||||
|
||||
ItemStack from = new ItemStack(view.getItem(fromSlot));
|
||||
from.setAmount(left);
|
||||
view.setItem(fromSlot, from);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
ItemStack to = new ItemStack(view.getItem(toSlot));
|
||||
to.setAmount(view.getItem(fromSlot).getAmount() + view.getItem(toSlot).getAmount());
|
||||
view.setItem(fromSlot, null);
|
||||
view.setItem(toSlot, to);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -214,12 +218,13 @@ public final class AlchemyPotionBrewer {
|
||||
}
|
||||
|
||||
private static void scheduleUpdate(Inventory inventory) {
|
||||
for (HumanEntity he : inventory.getViewers()) {
|
||||
if (he instanceof Player) {
|
||||
scheduleUpdate((Player) he);
|
||||
for (HumanEntity humanEntity : inventory.getViewers()) {
|
||||
if (humanEntity instanceof Player) {
|
||||
scheduleUpdate((Player) humanEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void scheduleUpdate(Player player) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(mcMMO.p, new PlayerUpdateInventoryTask(player));
|
||||
}
|
||||
@ -227,19 +232,19 @@ public final class AlchemyPotionBrewer {
|
||||
public static void handleInventoryClick(InventoryClickEvent event) {
|
||||
Player player = event.getWhoClicked() instanceof Player ? (Player) event.getWhoClicked() : null;
|
||||
BrewingStand brewingStand = (BrewingStand) event.getInventory().getHolder();
|
||||
|
||||
|
||||
ItemStack cursor = event.getCursor();
|
||||
ItemStack clicked = event.getCurrentItem();
|
||||
|
||||
|
||||
if (clicked != null && clicked.getType() == Material.POTION) {
|
||||
scheduleCheck(player, brewingStand);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
if (event.isShiftClick()) {
|
||||
if (event.getSlotType() == SlotType.FUEL) {
|
||||
scheduleCheck(player, brewingStand);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
else if (event.getSlotType() == SlotType.CONTAINER || event.getSlotType() == SlotType.QUICKBAR) {
|
||||
@ -250,12 +255,12 @@ public final class AlchemyPotionBrewer {
|
||||
else if (event.isRightClick()) {
|
||||
transferOneItem(event.getView(), event.getRawSlot(), INGREDIENT_SLOT);
|
||||
}
|
||||
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
|
||||
scheduleUpdate(brewingStand.getInventory());
|
||||
scheduleCheck(player, brewingStand);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -266,37 +271,37 @@ public final class AlchemyPotionBrewer {
|
||||
}
|
||||
else if (isEmpty(cursor)) {
|
||||
scheduleCheck(player, brewingStand);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
else if (isEmpty(clicked)) {
|
||||
if (isValidIngredient(player, event.getCursor())) {
|
||||
if (event.getClick() == ClickType.LEFT || (event.getClick() == ClickType.RIGHT && event.getCursor().getAmount() == 1)) {
|
||||
event.setCancelled(true);
|
||||
|
||||
|
||||
event.setCurrentItem(event.getCursor().clone());
|
||||
event.setCursor(null);
|
||||
|
||||
|
||||
scheduleUpdate(brewingStand.getInventory());
|
||||
scheduleCheck(player, brewingStand);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
else if (event.getClick() == ClickType.RIGHT) {
|
||||
event.setCancelled(true);
|
||||
|
||||
|
||||
ItemStack one = event.getCursor().clone();
|
||||
one.setAmount(1);
|
||||
|
||||
|
||||
ItemStack rest = event.getCursor().clone();
|
||||
rest.setAmount(event.getCursor().getAmount() - 1);
|
||||
|
||||
|
||||
event.setCurrentItem(one);
|
||||
event.setCursor(rest);
|
||||
|
||||
|
||||
scheduleUpdate(brewingStand.getInventory());
|
||||
scheduleCheck(player, brewingStand);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -308,41 +313,44 @@ public final class AlchemyPotionBrewer {
|
||||
public static void handleInventoryDrag(InventoryDragEvent event) {
|
||||
Player player = event.getWhoClicked() instanceof Player ? (Player) event.getWhoClicked() : null;
|
||||
BrewingStand brewingStand = (BrewingStand) event.getInventory().getHolder();
|
||||
|
||||
|
||||
ItemStack cursor = event.getCursor();
|
||||
ItemStack ingredient = brewingStand.getInventory().getIngredient();
|
||||
|
||||
if (event.getInventorySlots().contains(INGREDIENT_SLOT)) {
|
||||
if (isEmpty(ingredient) || ingredient.isSimilar(cursor)) {
|
||||
if (isValidIngredient(player, cursor)) {
|
||||
// Not handled: dragging custom ingredients over ingredient slot (does not trigger any event)
|
||||
scheduleCheck(player, brewingStand);
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
|
||||
scheduleUpdate(brewingStand.getInventory());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getInventorySlots().contains(INGREDIENT_SLOT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEmpty(ingredient) || ingredient.isSimilar(cursor)) {
|
||||
if (isValidIngredient(player, cursor)) {
|
||||
// Not handled: dragging custom ingredients over ingredient slot (does not trigger any event)
|
||||
scheduleCheck(player, brewingStand);
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
|
||||
scheduleUpdate(brewingStand.getInventory());
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void handleInventoryMoveItem(InventoryMoveItemEvent event) {
|
||||
Player player = null;
|
||||
BrewingStand brewingStand = (BrewingStand) event.getDestination().getHolder();
|
||||
|
||||
|
||||
if (isValidIngredient(player, event.getItem())) {
|
||||
scheduleCheck(player, brewingStand);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user