Switch to BukkitRunnable for Alchemy tasks, split Ingredients among 8 tiers instead of 5, related changes, and small bugfixes.

This commit is contained in:
Eric Hildebrand 2013-11-16 11:35:04 -05:00
parent afb5c9ab5c
commit c3801c7118
12 changed files with 77 additions and 39 deletions

View File

@ -17,7 +17,8 @@ public class AlchemyCommand extends SkillCommand {
private String brewSpeedLucky; private String brewSpeedLucky;
private int tier; private int tier;
private String ingredients; private int ingredientCount;
private String ingredientList;
private boolean canCatalysis; private boolean canCatalysis;
private boolean canConcoctions; private boolean canConcoctions;
@ -37,17 +38,18 @@ public class AlchemyCommand extends SkillCommand {
@Override @Override
protected void dataCalculations(Player player, float skillValue, boolean isLucky) { protected void dataCalculations(Player player, float skillValue, boolean isLucky) {
// DODGE // CATALYSIS
if (canCatalysis) { if (canCatalysis) {
String[] catalysisStrings = calculateAbilityDisplayValues(player, skillValue, isLucky); String[] catalysisStrings = calculateAbilityDisplayValues(player, skillValue, isLucky);
brewSpeed = catalysisStrings[0]; brewSpeed = catalysisStrings[0];
brewSpeedLucky = catalysisStrings[1]; brewSpeedLucky = catalysisStrings[1];
} }
// ROLL // CONCOCTIONS
if (canConcoctions) { if (canConcoctions) {
tier = UserManager.getPlayer(player).getAlchemyManager().getTier(); tier = UserManager.getPlayer(player).getAlchemyManager().getTier();
ingredients = UserManager.getPlayer(player).getAlchemyManager().getIngredientList(); ingredientCount = UserManager.getPlayer(player).getAlchemyManager().getIngredients().size();
ingredientList = UserManager.getPlayer(player).getAlchemyManager().getIngredientList();
} }
} }
@ -88,8 +90,8 @@ public class AlchemyCommand extends SkillCommand {
} }
if (canConcoctions) { if (canConcoctions) {
messages.add(LocaleLoader.getString("Alchemy.Concoctions.Rank", tier, Tier.FIVE.toNumerical())); messages.add(LocaleLoader.getString("Alchemy.Concoctions.Rank", tier, Tier.values().length));
messages.add(LocaleLoader.getString("Alchemy.Concoctions.Ingredients", ingredients)); messages.add(LocaleLoader.getString("Alchemy.Concoctions.Ingredients", ingredientCount, ingredientList));
} }
return messages; return messages;

View File

@ -100,7 +100,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
reason.add("Skills.Alchemy.Rank_Levels.Rank_" + tier.toNumerical() + " should be at least 0!"); reason.add("Skills.Alchemy.Rank_Levels.Rank_" + tier.toNumerical() + " should be at least 0!");
} }
if (tier != Alchemy.Tier.FIVE) { if (tier != Alchemy.Tier.fromNumerical(Alchemy.Tier.values().length)) {
Alchemy.Tier nextTier = alchemyTierList.get(alchemyTierList.indexOf(tier) - 1); Alchemy.Tier nextTier = alchemyTierList.get(alchemyTierList.indexOf(tier) - 1);
if (getConcoctionsTierLevel(tier) >= getConcoctionsTierLevel(nextTier)) { if (getConcoctionsTierLevel(tier) >= getConcoctionsTierLevel(nextTier)) {

View File

@ -23,6 +23,9 @@ public class PotionConfig extends ConfigLoader {
public List<ItemStack> concoctionsIngredientsTierThree = new ArrayList<ItemStack>(); public List<ItemStack> concoctionsIngredientsTierThree = new ArrayList<ItemStack>();
public List<ItemStack> concoctionsIngredientsTierFour = new ArrayList<ItemStack>(); public List<ItemStack> concoctionsIngredientsTierFour = new ArrayList<ItemStack>();
public List<ItemStack> concoctionsIngredientsTierFive = new ArrayList<ItemStack>(); public List<ItemStack> concoctionsIngredientsTierFive = new ArrayList<ItemStack>();
public List<ItemStack> concoctionsIngredientsTierSix = new ArrayList<ItemStack>();
public List<ItemStack> concoctionsIngredientsTierSeven = new ArrayList<ItemStack>();
public List<ItemStack> concoctionsIngredientsTierEight = new ArrayList<ItemStack>();
public Map<Short, AlchemyPotion> potionMap = new HashMap<Short, AlchemyPotion>(); public Map<Short, AlchemyPotion> potionMap = new HashMap<Short, AlchemyPotion>();
@ -53,11 +56,17 @@ public class PotionConfig extends ConfigLoader {
loadConcoctionsTier(concoctionsIngredientsTierThree, concoctionSection.getStringList("Tier_Three_Ingredients")); loadConcoctionsTier(concoctionsIngredientsTierThree, concoctionSection.getStringList("Tier_Three_Ingredients"));
loadConcoctionsTier(concoctionsIngredientsTierFour, concoctionSection.getStringList("Tier_Four_Ingredients")); loadConcoctionsTier(concoctionsIngredientsTierFour, concoctionSection.getStringList("Tier_Four_Ingredients"));
loadConcoctionsTier(concoctionsIngredientsTierFive, concoctionSection.getStringList("Tier_Five_Ingredients")); loadConcoctionsTier(concoctionsIngredientsTierFive, concoctionSection.getStringList("Tier_Five_Ingredients"));
loadConcoctionsTier(concoctionsIngredientsTierSix, concoctionSection.getStringList("Tier_Six_Ingredients"));
loadConcoctionsTier(concoctionsIngredientsTierSeven, concoctionSection.getStringList("Tier_Seven_Ingredients"));
loadConcoctionsTier(concoctionsIngredientsTierEight, concoctionSection.getStringList("Tier_Eight_Ingredients"));
concoctionsIngredientsTierTwo.addAll(concoctionsIngredientsTierOne); concoctionsIngredientsTierTwo.addAll(concoctionsIngredientsTierOne);
concoctionsIngredientsTierThree.addAll(concoctionsIngredientsTierTwo); concoctionsIngredientsTierThree.addAll(concoctionsIngredientsTierTwo);
concoctionsIngredientsTierFour.addAll(concoctionsIngredientsTierThree); concoctionsIngredientsTierFour.addAll(concoctionsIngredientsTierThree);
concoctionsIngredientsTierFive.addAll(concoctionsIngredientsTierFour); concoctionsIngredientsTierFive.addAll(concoctionsIngredientsTierFour);
concoctionsIngredientsTierSix.addAll(concoctionsIngredientsTierFive);
concoctionsIngredientsTierSeven.addAll(concoctionsIngredientsTierSix);
concoctionsIngredientsTierEight.addAll(concoctionsIngredientsTierSeven);
} }
private void loadConcoctionsTier(List<ItemStack> ingredientList, List<String> ingredientStrings) { private void loadConcoctionsTier(List<ItemStack> ingredientList, List<String> ingredientStrings) {

View File

@ -31,6 +31,7 @@ import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.ParticleEffectUtils; import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
public enum SkillType { public enum SkillType {

View File

@ -138,7 +138,7 @@ public class BlockListener implements Listener {
/* ALCHEMY - Cancel any brew in progress for that BrewingStand */ /* ALCHEMY - Cancel any brew in progress for that BrewingStand */
if (blockState instanceof BrewingStand && Alchemy.brewingStandMap.containsKey(event.getBlock())) { if (blockState instanceof BrewingStand && Alchemy.brewingStandMap.containsKey(event.getBlock())) {
Alchemy.brewingStandMap.get(event.getBlock()).cancel(); Alchemy.brewingStandMap.get(event.getBlock()).cancelBrew();
} }
Player player = event.getPlayer(); Player player = event.getPlayer();

View File

@ -6,11 +6,12 @@ import org.bukkit.block.Block;
import org.bukkit.block.BrewingStand; import org.bukkit.block.BrewingStand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.skills.alchemy.Alchemy; import com.gmail.nossr50.skills.alchemy.Alchemy;
import com.gmail.nossr50.skills.alchemy.AlchemyPotionBrewer; import com.gmail.nossr50.skills.alchemy.AlchemyPotionBrewer;
public class AlchemyBrewCheckTask implements Runnable { public class AlchemyBrewCheckTask extends BukkitRunnable {
private final static int INGREDIENT_SLOT = 3; private final static int INGREDIENT_SLOT = 3;
private Player player; private Player player;
@ -30,7 +31,7 @@ public class AlchemyBrewCheckTask implements Runnable {
if (Alchemy.brewingStandMap.containsKey(brewingStand)) { if (Alchemy.brewingStandMap.containsKey(brewingStand)) {
if (oldInventory[INGREDIENT_SLOT] == null || newInventory[INGREDIENT_SLOT] == null || !oldInventory[INGREDIENT_SLOT].isSimilar(newInventory[INGREDIENT_SLOT]) || !AlchemyPotionBrewer.isValidBrew(player, newInventory)) { if (oldInventory[INGREDIENT_SLOT] == null || newInventory[INGREDIENT_SLOT] == null || !oldInventory[INGREDIENT_SLOT].isSimilar(newInventory[INGREDIENT_SLOT]) || !AlchemyPotionBrewer.isValidBrew(player, newInventory)) {
Alchemy.brewingStandMap.get(brewingStand).cancel(); Alchemy.brewingStandMap.get(brewingStand).cancelBrew();
} }
} }
if (!Alchemy.brewingStandMap.containsKey(brewingStand) && AlchemyPotionBrewer.isValidBrew(player, newInventory)) { if (!Alchemy.brewingStandMap.containsKey(brewingStand) && AlchemyPotionBrewer.isValidBrew(player, newInventory)) {

View File

@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BrewingStand; import org.bukkit.block.BrewingStand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
@ -15,12 +16,10 @@ import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
public class AlchemyBrewTask implements Runnable { public class AlchemyBrewTask extends BukkitRunnable {
private final double DEFAULT_BREW_SPEED = 1.0; private final double DEFAULT_BREW_SPEED = 1.0;
private final int DEFAULT_BREW_TICKS = 400; private final int DEFAULT_BREW_TICKS = 400;
private int taskId = -1;
private Block brewingStand; private Block brewingStand;
private double brewSpeed; private double brewSpeed;
private double brewTimer; private double brewTimer;
@ -52,20 +51,20 @@ public class AlchemyBrewTask implements Runnable {
} }
Alchemy.brewingStandMap.put(brewingStand, this); Alchemy.brewingStandMap.put(brewingStand, this);
taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(mcMMO.p, this, 1); this.runTaskTimer(mcMMO.p, 1, 1);
} }
@Override @Override
public void run() { public void run() {
brewTimer -= brewSpeed; brewTimer -= brewSpeed;
// Vanilla potion brewing completes when BrewingTime == 1
if (brewTimer < Math.max(brewSpeed, 2)) { if (brewTimer < Math.max(brewSpeed, 2)) {
taskId = -1; this.cancel();
finish(); finish();
} }
else { else {
((BrewingStand) brewingStand.getState()).setBrewingTime((int) brewTimer); ((BrewingStand) brewingStand.getState()).setBrewingTime((int) brewTimer);
taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(mcMMO.p, this, 1);
} }
} }
@ -81,16 +80,16 @@ public class AlchemyBrewTask implements Runnable {
} }
public void finishImmediately() { public void finishImmediately() {
AlchemyPotionBrewer.finishBrewing(brewingStand, player, true); this.cancel();
AlchemyPotionBrewer.finishBrewing(brewingStand, player, true);
Alchemy.brewingStandMap.remove(brewingStand); Alchemy.brewingStandMap.remove(brewingStand);
} }
public void cancel() { public void cancelBrew() {
Bukkit.getScheduler().cancelTask(taskId); this.cancel();
((BrewingStand) brewingStand.getState()).setBrewingTime(-1); ((BrewingStand) brewingStand.getState()).setBrewingTime(-1);
Alchemy.brewingStandMap.remove(brewingStand); Alchemy.brewingStandMap.remove(brewingStand);
} }
} }

View File

@ -13,6 +13,9 @@ import com.gmail.nossr50.runnables.skills.AlchemyBrewTask;
public final class Alchemy { public final class Alchemy {
public enum Tier { public enum Tier {
EIGHT(8),
SEVEN(7),
SIX(6),
FIVE(5), FIVE(5),
FOUR(4), FOUR(4),
THREE(3), THREE(3),

View File

@ -44,6 +44,12 @@ public class AlchemyManager extends SkillManager {
public List<ItemStack> getIngredients() { public List<ItemStack> getIngredients() {
switch (Alchemy.Tier.fromNumerical(getTier())) { switch (Alchemy.Tier.fromNumerical(getTier())) {
case EIGHT:
return PotionConfig.getInstance().concoctionsIngredientsTierEight;
case SEVEN:
return PotionConfig.getInstance().concoctionsIngredientsTierSeven;
case SIX:
return PotionConfig.getInstance().concoctionsIngredientsTierSix;
case FIVE: case FIVE:
return PotionConfig.getInstance().concoctionsIngredientsTierFive; return PotionConfig.getInstance().concoctionsIngredientsTierFive;
case FOUR: case FOUR:

View File

@ -64,10 +64,13 @@ Skills:
# Rank_Levels: Alchemy level where rank gets unlocked # Rank_Levels: Alchemy level where rank gets unlocked
Rank_Levels: Rank_Levels:
Rank_1: 0 Rank_1: 0
Rank_2: 200 Rank_2: 125
Rank_3: 400 Rank_3: 250
Rank_4: 600 Rank_4: 375
Rank_5: 800 Rank_5: 500
Rank_6: 625
Rank_7: 750
Rank_8: 875
# #
# Settings for Archery # Settings for Archery
### ###

View File

@ -41,7 +41,7 @@ Alchemy.Listener=Alchemy:
Alchemy.Ability.Locked.0=LOCKED UNTIL {0}+ SKILL (CATALYSIS) Alchemy.Ability.Locked.0=LOCKED UNTIL {0}+ SKILL (CATALYSIS)
Alchemy.Catalysis.Speed=[[RED]]Brewing Speed: [[YELLOW]]{0} Alchemy.Catalysis.Speed=[[RED]]Brewing Speed: [[YELLOW]]{0}
Alchemy.Concoctions.Rank=[[RED]]Concoctions Rank: [[YELLOW]]{0} Alchemy.Concoctions.Rank=[[RED]]Concoctions Rank: [[YELLOW]]{0}
Alchemy.Concoctions.Ingredients=[[RED]]Ingredients: [[YELLOW]]{0} Alchemy.Concoctions.Ingredients=[[RED]]Ingredients [[[YELLOW]]{0}[[RED]]]: [[YELLOW]]{1}
Alchemy.SkillName=ALCHEMY Alchemy.SkillName=ALCHEMY
Alchemy.Skillup=[[YELLOW]]Alchemy skill increased by {0}. Total ({1}) Alchemy.Skillup=[[YELLOW]]Alchemy skill increased by {0}. Total ({1})

View File

@ -23,15 +23,18 @@ Concoctions:
Tier_Three_Ingredients: Tier_Three_Ingredients:
- QUARTZ - QUARTZ
- RED_MUSHROOM - RED_MUSHROOM
- ROTTEN_FLESH
Tier_Four_Ingredients: Tier_Four_Ingredients:
- APPLE - APPLE
- ROTTEN_FLESH
Tier_Five_Ingredients:
- BROWN_MUSHROOM - BROWN_MUSHROOM
- 'INK_SACK:0' - 'INK_SACK:0'
Tier_Five_Ingredients: Tier_Six_Ingredients:
- 'GOLDEN_APPLE:0'
- 'LONG_GRASS:2' - 'LONG_GRASS:2'
Tier_Seven_Ingredients:
- POISONOUS_POTATO - POISONOUS_POTATO
Tier_Eight_Ingredients:
- 'GOLDEN_APPLE:0'
# #
# Settings for Potions # Settings for Potions
@ -43,6 +46,17 @@ Concoctions:
# <INGREDIENT>: <NEW_DV> The ingredient used, and resultant potion's new data value # <INGREDIENT>: <NEW_DV> The ingredient used, and resultant potion's new data value
# Effects: List of strings for the potion's effects (section is optional) # Effects: List of strings for the potion's effects (section is optional)
# - "<POTION_EFFECT> [EFFECT_TIER] [DURATION_TICKS]" # - "<POTION_EFFECT> [EFFECT_TIER] [DURATION_TICKS]"
#
# DataValues - These potions follow the normal data value pattern except for bits 8-12:
# Bits 0-3: Liquid Color (http://minecraft.gamepedia.com/Data_values#Potions)
# Bit 4: (Unused)
# Bit 5: Power
# Bit 6: Extended
# Bit 7: (Unused)
# Bits 8-12: Custom Status Effect (http://minecraft.gamepedia.com/Data_values#Status_effects)
# Bit 13: Can become splash
# Bit 14: Splash
# Bit 15: (Unused)
### ###
Potions: Potions:
@ -50,16 +64,16 @@ Potions:
0: # Water Bottle 0: # Water Bottle
Children: Children:
BLAZE_POWDER: 128 # Mundane Potion BLAZE_POWDER: 8192 # Mundane Potion
FERMENTED_SPIDER_EYE: 4616 # Potion of Weakness FERMENTED_SPIDER_EYE: 4616 # Potion of Weakness
GHAST_TEAR: 128 # Mundane Potion GHAST_TEAR: 8192 # Mundane Potion
GLOWSTONE_DUST: 32 # Thick Potion GLOWSTONE_DUST: 32 # Thick Potion
MAGMA_CREAM: 128 # Mundane Potion MAGMA_CREAM: 8192 # Mundane Potion
NETHER_STALK: 16 # Awkward Potion NETHER_STALK: 16 # Awkward Potion
REDSTONE: 64 # Mundane Potion Extended REDSTONE: 64 # Mundane Potion Extended
SPECKLED_MELON: 128 # Mundane Potion SPECKLED_MELON: 8192 # Mundane Potion
SPIDER_EYE: 128 # Mundane Potion SPIDER_EYE: 8192 # Mundane Potion
SUGAR: 128 # Mundane Potion SUGAR: 8192 # Mundane Potion
16: # Awkward Potion 16: # Awkward Potion
Children: Children:
@ -93,7 +107,7 @@ Potions:
Children: Children:
FERMENTED_SPIDER_EYE: 4680 FERMENTED_SPIDER_EYE: 4680
128: # Mundane Potion 8192: # Mundane Potion
Children: Children:
FERMENTED_SPIDER_EYE: 4616 FERMENTED_SPIDER_EYE: 4616
SULPHUR: 16384 SULPHUR: 16384
@ -611,11 +625,11 @@ Potions:
19725: # Splash Potion of Water Breathing 19725: # Splash Potion of Water Breathing
Effects: ["WATER_BREATHING 0 2700"] Effects: ["WATER_BREATHING 0 2700"]
Children: Children:
REDSTONE: 19776 REDSTONE: 19789
19789: # Splash Potion of Water Breathing Extended 19789: # Splash Potion of Water Breathing Extended
Effects: ["WATER_BREATHING 0 7200"] Effects: ["WATER_BREATHING 0 7200"]
Children: Children:
GLOWSTONE_DUST: 19712 GLOWSTONE_DUST: 19725
19982: # Splash Potion of Invisibility 19982: # Splash Potion of Invisibility
Effects: ["INVISIBILITY 0 2700"] Effects: ["INVISIBILITY 0 2700"]