Merge pull request #4 from DieReicheErethons/master

Pulling in SnowStorm's fixes
This commit is contained in:
Daniel Boston
2016-05-11 01:05:47 -04:00
9 changed files with 965 additions and 969 deletions
+6 -25
View File
@@ -1,16 +1,13 @@
package com.dre.brewery; package com.dre.brewery;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import java.util.*;
public class BIngredients { public class BIngredients {
public static Set<Material> possibleIngredients = new HashSet<Material>(); public static Set<Material> possibleIngredients = new HashSet<Material>();
public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>(); public static ArrayList<BRecipe> recipes = new ArrayList<BRecipe>();
@@ -83,11 +80,7 @@ public class BIngredients {
Brew.addOrReplaceEffects(potionMeta, brew.getEffects(), brew.getQuality()); Brew.addOrReplaceEffects(potionMeta, brew.getEffects(), brew.getQuality());
cookedName = cookRecipe.getName(quality); cookedName = cookRecipe.getName(quality);
if (P.use1_9) { Brew.PotionColor.valueOf(cookRecipe.getColor()).colorBrew(potionMeta, potion, false);
potionMeta.setMainEffect(Brew.PotionColor.valueOf(cookRecipe.getColor()).getEffect());
} else {
potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));
}
} else { } else {
// new base potion // new base potion
@@ -95,22 +88,14 @@ public class BIngredients {
if (state <= 1) { if (state <= 1) {
cookedName = P.p.languageReader.get("Brew_ThickBrew"); cookedName = P.p.languageReader.get("Brew_ThickBrew");
if (P.use1_9) { Brew.PotionColor.BLUE.colorBrew(potionMeta, potion, false);
potionMeta.setMainEffect(Brew.PotionColor.BLUE.getEffect());
} else {
potion.setDurability(Brew.PotionColor.BLUE.getColorId(false));
}
} else { } else {
for (Material ingredient : materials.keySet()) { for (Material ingredient : materials.keySet()) {
if (cookedNames.containsKey(ingredient)) { if (cookedNames.containsKey(ingredient)) {
// if more than half of the ingredients is of one kind // if more than half of the ingredients is of one kind
if (materials.get(ingredient) > (getIngredientsCount() / 2)) { if (materials.get(ingredient) > (getIngredientsCount() / 2)) {
cookedName = cookedNames.get(ingredient); cookedName = cookedNames.get(ingredient);
if (P.use1_9) { Brew.PotionColor.CYAN.colorBrew(potionMeta, potion, true);
potionMeta.setMainEffect(Brew.PotionColor.CYAN.getEffect());
} else {
potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
}
} }
} }
} }
@@ -119,11 +104,7 @@ public class BIngredients {
if (cookedName == null) { if (cookedName == null) {
// if no name could be found // if no name could be found
cookedName = P.p.languageReader.get("Brew_Undefined"); cookedName = P.p.languageReader.get("Brew_Undefined");
if (P.use1_9) { Brew.PotionColor.CYAN.colorBrew(potionMeta, potion, true);
potionMeta.setMainEffect(Brew.PotionColor.CYAN.getEffect());
} else {
potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
}
} }
potionMeta.setDisplayName(P.p.color("&f" + cookedName)); potionMeta.setDisplayName(P.p.color("&f" + cookedName));
+8 -3
View File
@@ -229,8 +229,13 @@ public class BPlayer {
if (time == 0) { if (time == 0) {
// push him only to the side? or any direction // push him only to the side? or any direction
// like now // like now
push.setX(Math.random() - 0.5); if (P.use1_9) { // Pushing is way stronger in 1.9
push.setZ(Math.random() - 0.5); push.setX((Math.random() - 0.5) / 2.0);
push.setZ((Math.random() - 0.5) / 2.0);
} else {
push.setX(Math.random() - 0.5);
push.setZ(Math.random() - 0.5);
}
player.setVelocity(push); player.setVelocity(push);
} else if (time < 0 && time > -10) { } else if (time < 0 && time > -10) {
// push him some more in the same direction // push him some more in the same direction
@@ -574,4 +579,4 @@ public class BPlayer {
return -getQuality() + 11; return -getQuality() + 11;
} }
} }
+4 -7
View File
@@ -1,13 +1,14 @@
package com.dre.brewery; package com.dre.brewery;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.List;
public class BRecipe { public class BRecipe {
private String[] name; private String[] name;
@@ -204,11 +205,7 @@ public class BRecipe {
Brew brew = new Brew(uid, bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false, true); Brew brew = new Brew(uid, bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false, true);
if (P.use1_9) { Brew.PotionColor.valueOf(getColor()).colorBrew(potionMeta, potion, false);
potionMeta.setMainEffect(Brew.PotionColor.valueOf(getColor()).getEffect());
} else {
potion.setDurability(Brew.PotionColor.valueOf(getColor()).getColorId(false));
}
potionMeta.setDisplayName(P.p.color("&f" + getName(quality))); potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
// This effect stores the UID in its Duration // This effect stores the UID in its Duration
potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true); potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
+2 -2
View File
@@ -129,7 +129,7 @@ public class Barrel implements InventoryHolder {
} }
} catch (Throwable e) { } catch (Throwable e) {
P.p.errorLog("Failed to Check WorldGuard for Barrel Open Permissions!"); P.p.errorLog("Failed to Check WorldGuard for Barrel Open Permissions!");
P.p.errorLog("Brewery was tested with version 5.8 to 6.0 of WorldGuard!"); P.p.errorLog("Brewery was tested with version 5.8 to 6.1 of WorldGuard!");
P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload"); P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
e.printStackTrace(); e.printStackTrace();
P.p.msg(player, "&cError opening Barrel, please report to an Admin!"); P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
@@ -146,7 +146,7 @@ public class Barrel implements InventoryHolder {
} }
} catch (Throwable e) { } catch (Throwable e) {
P.p.errorLog("Failed to Check GriefPrevention for Barrel Open Permissions!"); P.p.errorLog("Failed to Check GriefPrevention for Barrel Open Permissions!");
P.p.errorLog("Brewery only works with the latest release of GriefPrevention (7.8)"); P.p.errorLog("Brewery was tested with GriefPrevention 14.5.1");
P.p.errorLog("Disable the GriefPrevention support in the config and do /brew reload"); P.p.errorLog("Disable the GriefPrevention support in the config and do /brew reload");
e.printStackTrace(); e.printStackTrace();
P.p.msg(player, "&cError opening Barrel, please report to an Admin!"); P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
+48 -54
View File
@@ -1,20 +1,25 @@
package com.dre.brewery; package com.dre.brewery;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class Brew { public class Brew {
// represents the liquid in the brewed Potions // represents the liquid in the brewed Potions
public static Map<Integer, Brew> potions = new HashMap<Integer, Brew>(); public static Map<Integer, Brew> potions = new HashMap<Integer, Brew>();
public static Boolean colorInBarrels; // color the Lore while in Barrels public static Boolean colorInBarrels; // color the Lore while in Barrels
public static Boolean colorInBrewer; // color the Lore while in Brewer public static Boolean colorInBrewer; // color the Lore while in Brewer
@@ -237,6 +242,7 @@ public class Brew {
} }
public boolean canDistill() { public boolean canDistill() {
if (stat) return false;
if (currentRecipe != null) { if (currentRecipe != null) {
return currentRecipe.getDistillRuns() > distillRuns; return currentRecipe.getDistillRuns() > distillRuns;
} else if (distillRuns >= 6) { } else if (distillRuns >= 6) {
@@ -291,22 +297,15 @@ public class Brew {
this.stat = stat; this.stat = stat;
if (currentRecipe != null && canDistill()) { if (currentRecipe != null && canDistill()) {
if (stat) { if (stat) {
if (P.use1_9) { PotionColor.valueOf(currentRecipe.getColor()).colorBrew(((PotionMeta) potion.getItemMeta()), potion, false);
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
potionMeta.setMainEffect(PotionColor.valueOf(currentRecipe.getColor()).getEffect());
} else {
potion.setDurability(PotionColor.valueOf(currentRecipe.getColor()).getColorId(false));
}
} else if (P.use1_9) {
PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();
potionMeta.setMainEffect(PotionColor.valueOf(currentRecipe.getColor()).getEffect());
} else { } else {
potion.setDurability(PotionColor.valueOf(currentRecipe.getColor()).getColorId(true)); PotionColor.valueOf(currentRecipe.getColor()).colorBrew(((PotionMeta) potion.getItemMeta()), potion, true);
} }
} }
} }
// Distilling section --------------- // Distilling section ---------------
// distill all custom potions in the brewer // distill all custom potions in the brewer
public static void distillAll(BrewerInventory inv, Boolean[] contents) { public static void distillAll(BrewerInventory inv, Boolean[] contents) {
int slot = 0; int slot = 0;
@@ -336,21 +335,13 @@ public class Brew {
addOrReplaceEffects(potionMeta, getEffects(), quality); addOrReplaceEffects(potionMeta, getEffects(), quality);
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
if (P.use1_9) { PotionColor.valueOf(recipe.getColor()).colorBrew(potionMeta, slotItem, canDistill());
potionMeta.setMainEffect(PotionColor.valueOf(recipe.getColor()).getEffect());
} else {
slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
}
} else { } else {
quality = 0; quality = 0;
removeEffects(potionMeta); removeEffects(potionMeta);
potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_DistillUndefined"))); potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_DistillUndefined")));
if (P.use1_9) { PotionColor.GREY.colorBrew(potionMeta, slotItem, canDistill());
potionMeta.setMainEffect(PotionColor.GREY.getEffect());
} else {
slotItem.setDurability(PotionColor.GREY.getColorId(canDistill()));
}
} }
// Distill Lore // Distill Lore
@@ -369,6 +360,7 @@ public class Brew {
} }
// Ageing Section ------------------ // Ageing Section ------------------
public void age(ItemStack item, float time, byte woodType) { public void age(ItemStack item, float time, byte woodType) {
if (stat) { if (stat) {
return; return;
@@ -391,20 +383,12 @@ public class Brew {
addOrReplaceEffects(potionMeta, getEffects(), quality); addOrReplaceEffects(potionMeta, getEffects(), quality);
potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality)));
if (P.use1_9) { PotionColor.valueOf(recipe.getColor()).colorBrew(potionMeta, item, canDistill());
potionMeta.setMainEffect(PotionColor.valueOf(recipe.getColor()).getEffect());
} else {
item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill()));
}
} else { } else {
quality = 0; quality = 0;
removeEffects(potionMeta); removeEffects(potionMeta);
potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_BadPotion"))); potionMeta.setDisplayName(P.p.color("&f" + P.p.languageReader.get("Brew_BadPotion")));
if (P.use1_9) { PotionColor.GREY.colorBrew(potionMeta, item, canDistill());
potionMeta.setMainEffect(PotionColor.GREY.getEffect());
} else {
item.setDurability(PotionColor.GREY.getColorId(canDistill()));
}
} }
} }
@@ -452,6 +436,7 @@ public class Brew {
} }
// Lore ----------- // Lore -----------
// Converts to/from qualitycolored Lore // Converts to/from qualitycolored Lore
public void convertLore(PotionMeta meta, Boolean toQuality) { public void convertLore(PotionMeta meta, Boolean toQuality) {
if (currentRecipe == null) { if (currentRecipe == null) {
@@ -660,25 +645,25 @@ public class Brew {
} }
public static enum PotionColor { public static enum PotionColor {
PINK(1, PotionEffectType.REGENERATION), PINK(1, PotionType.REGEN),
CYAN(2, PotionEffectType.SPEED), CYAN(2, PotionType.SPEED),
ORANGE(3, PotionEffectType.FIRE_RESISTANCE), ORANGE(3, PotionType.FIRE_RESISTANCE),
GREEN(4, PotionEffectType.POISON), GREEN(4, PotionType.POISON),
BRIGHT_RED(5, PotionEffectType.HEAL), BRIGHT_RED(5, PotionType.INSTANT_HEAL),
BLUE(6, PotionEffectType.NIGHT_VISION), BLUE(6, PotionType.NIGHT_VISION),
BLACK(8, PotionEffectType.WEAKNESS), BLACK(8, PotionType.WEAKNESS),
RED(9, PotionEffectType.INCREASE_DAMAGE), RED(9, PotionType.STRENGTH),
GREY(10, PotionEffectType.SLOW), GREY(10, PotionType.SLOWNESS),
WATER(11, PotionEffectType.WATER_BREATHING), WATER(11, PotionType.WATER_BREATHING),
DARK_RED(12, PotionEffectType.HARM), DARK_RED(12, PotionType.INSTANT_DAMAGE),
BRIGHT_GREY(14, PotionEffectType.INVISIBILITY); BRIGHT_GREY(14, PotionType.INVISIBILITY);
private final int colorId; private final int colorId;
private final PotionEffectType effect; private final PotionType type;
private PotionColor(int colorId, PotionEffectType effect) { private PotionColor(int colorId, PotionType type) {
this.colorId = colorId; this.colorId = colorId;
this.effect = effect; this.type = type;
} }
// gets the Damage Value, that sets a color on the potion // gets the Damage Value, that sets a color on the potion
@@ -690,8 +675,17 @@ public class Brew {
return (short) (colorId + 32); return (short) (colorId + 32);
} }
public PotionEffectType getEffect() { public PotionType getType() {
return effect; return type;
}
public void colorBrew(PotionMeta meta, ItemStack potion, boolean destillable) {
if (P.use1_9) {
meta.setBasePotionData(new PotionData(getType()));
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
} else {
potion.setDurability(getColorId(destillable));
}
} }
} }
+829 -829
View File
File diff suppressed because it is too large Load Diff
@@ -3,6 +3,7 @@ package com.dre.brewery.listeners;
import com.dre.brewery.Brew; import com.dre.brewery.Brew;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -11,9 +12,9 @@ import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
// Workaround to remove unwanted potion effects // Workaround to remove unwanted potion effects
public class Compat1_9 implements Listener { public class DrinkListener1_9 implements Listener {
@EventHandler @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerDrink(PlayerItemConsumeEvent event) { public void onPlayerDrink(PlayerItemConsumeEvent event) {
ItemStack item = event.getItem(); ItemStack item = event.getItem();
Brew brew = Brew.get(item); Brew brew = Brew.get(item);
@@ -12,6 +12,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.BrewEvent; import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
@@ -33,23 +34,24 @@ import com.dre.brewery.integration.LogBlockBarrel;
/** /**
* Updated for 1.9 to replicate the "Brewing" process for distilling. * Updated for 1.9 to replicate the "Brewing" process for distilling.
* Because of how metadata has changed, the brewer no longer triggers as previously described. * Because of how metadata has changed, the brewer no longer triggers as previously described.
* So, I've added some event tracking and manual forcing of the brewing "animation" if the * So, I've added some event tracking and manual forcing of the brewing "animation" if the
* set of ingredients in the brewer can be distilled. * set of ingredients in the brewer can be distilled.
* Nothing here should interfere with vanilla brewing. * Nothing here should interfere with vanilla brewing.
* *
* Note in testing I did discover a few ways to "hack" brewing to distill your brews alongside * Note in testing I did discover a few ways to "hack" brewing to distill your brews alongside
* potions; put fuel and at least one "valid" water bottle w/ a brewing component. You can distill * potions; put fuel and at least one "valid" water bottle w/ a brewing component. You can distill
* two brews this way, just remove them before the "final" distillation or you will actually * two brews this way, just remove them before the "final" distillation or you will actually
* brew the potion as well. * brew the potion as well.
* *
* @author ProgrammerDan (1.9 distillation update only) * @author ProgrammerDan (1.9 distillation update only)
*/ */
public class InventoryListener implements Listener { public class InventoryListener implements Listener {
/* === Recreating manually the prior BrewEvent behavior. === */ /* === Recreating manually the prior BrewEvent behavior. === */
private HashSet<UUID> trackedBrewmen = new HashSet<UUID>(); private HashSet<UUID> trackedBrewmen = new HashSet<UUID>();
private HashMap<Block, Integer> trackedBrewers = new HashMap<Block, Integer>(); private HashMap<Block, Integer> trackedBrewers = new HashMap<Block, Integer>();
private static final int DISTILLTIME = 401;
/** /**
* Start tracking distillation for a person when they open the brewer window. * Start tracking distillation for a person when they open the brewer window.
* @param event * @param event
@@ -60,11 +62,11 @@ public class InventoryListener implements Listener {
HumanEntity player = event.getPlayer(); HumanEntity player = event.getPlayer();
Inventory inv = event.getInventory(); Inventory inv = event.getInventory();
if (player == null || inv == null || !(inv instanceof BrewerInventory)) return; if (player == null || inv == null || !(inv instanceof BrewerInventory)) return;
P.p.debugLog("Starting brew inventory tracking"); P.p.debugLog("Starting brew inventory tracking");
trackedBrewmen.add(player.getUniqueId()); trackedBrewmen.add(player.getUniqueId());
} }
/** /**
* Stop tracking distillation for a person when they close the brewer window. * Stop tracking distillation for a person when they close the brewer window.
* @param event * @param event
@@ -75,7 +77,7 @@ public class InventoryListener implements Listener {
HumanEntity player = event.getPlayer(); HumanEntity player = event.getPlayer();
Inventory inv = event.getInventory(); Inventory inv = event.getInventory();
if (player == null || inv == null || !(inv instanceof BrewerInventory)) return; if (player == null || inv == null || !(inv instanceof BrewerInventory)) return;
P.p.debugLog("Stopping brew inventory tracking"); P.p.debugLog("Stopping brew inventory tracking");
trackedBrewmen.remove(player.getUniqueId()); trackedBrewmen.remove(player.getUniqueId());
} }
@@ -84,7 +86,7 @@ public class InventoryListener implements Listener {
* Clicking can either start or stop the new brew distillation tracking. * Clicking can either start or stop the new brew distillation tracking.
* Note that server restart will halt any ongoing brewing processes and * Note that server restart will halt any ongoing brewing processes and
* they will _not_ restart until a new click event. * they will _not_ restart until a new click event.
* *
* @param event the Click event. * @param event the Click event.
*/ */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@@ -93,53 +95,56 @@ public class InventoryListener implements Listener {
HumanEntity player = event.getWhoClicked(); HumanEntity player = event.getWhoClicked();
Inventory inv = event.getInventory(); Inventory inv = event.getInventory();
if (player == null || inv == null || !(inv instanceof BrewerInventory)) return; if (player == null || inv == null || !(inv instanceof BrewerInventory)) return;
UUID puid = player.getUniqueId(); UUID puid = player.getUniqueId();
if (!trackedBrewmen.contains(puid)) return; if (!trackedBrewmen.contains(puid)) return;
if (InventoryType.BREWING != inv.getType()) return; if (InventoryType.BREWING != inv.getType()) return;
if (event.getAction() == InventoryAction.NOTHING) return; // Ignore clicks that do nothing
BrewerInventory brewer = (BrewerInventory) inv; BrewerInventory brewer = (BrewerInventory) inv;
final Block brewery = brewer.getHolder().getBlock(); final Block brewery = brewer.getHolder().getBlock();
// If we were already tracking the brewer, cancel any ongoing event due to the click. // If we were already tracking the brewer, cancel any ongoing event due to the click.
Integer curTask = trackedBrewers.get(brewery); Integer curTask = trackedBrewers.get(brewery);
if (curTask != null) { if (curTask != null) {
Bukkit.getScheduler().cancelTask(curTask); // cancel prior Bukkit.getScheduler().cancelTask(curTask); // cancel prior
} }
// Now check if we should bother to track it. // Now check if we should bother to track it.
trackedBrewers.put(brewery, new BukkitRunnable() { trackedBrewers.put(brewery, new BukkitRunnable() {
private int brewTime = 401; private int brewTime = DISTILLTIME;
@Override @Override
public void run() { public void run() {
BlockState now = brewery.getState(); BlockState now = brewery.getState();
if (now instanceof BrewingStand) { if (now instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) now; BrewingStand stand = (BrewingStand) now;
// check if still custom if (brewTime == DISTILLTIME) { // only check at the beginning (and end) for distillables
BrewerInventory brewer = stand.getInventory(); if (!isCustomAndDistill(stand.getInventory())) {
if (isCustomAndDistill(brewer) ) { this.cancel();
trackedBrewers.remove(brewery);
// Still a valid brew distillation P.p.debugLog("nothing to distill");
brewTime = brewTime - 1; // count down. return;
stand.setBrewingTime(brewTime); // arbitrary for now }
}
if (brewTime <= 1) { // Done!
BrewEvent doBrew = new BrewEvent(brewery, brewer); brewTime--; // count down.
Bukkit.getServer().getPluginManager().callEvent(doBrew); stand.setBrewingTime(brewTime); // arbitrary for now
if (!doBrew.isCancelled()) { // BrewEvent _wasn't_ cancelled.
this.cancel(); if (brewTime <= 1) { // Done!
trackedBrewers.remove(brewery); //BrewEvent doBrew = new BrewEvent(brewery, brewer);
stand.setBrewingTime(0); //Bukkit.getServer().getPluginManager().callEvent(doBrew);
P.p.debugLog("All done distilling");
} else { BrewerInventory brewer = stand.getInventory();
brewTime = 401; // go again. if (!runDistill(brewer)) {
P.p.debugLog("Can distill more! Continuing."); this.cancel();
} trackedBrewers.remove(brewery);
stand.setBrewingTime(0);
P.p.debugLog("All done distilling");
} else {
brewTime = DISTILLTIME; // go again.
P.p.debugLog("Can distill more! Continuing.");
} }
} else {
this.cancel();
trackedBrewers.remove(brewery);
} }
} else { } else {
this.cancel(); this.cancel();
@@ -149,7 +154,7 @@ public class InventoryListener implements Listener {
} }
}.runTaskTimer(P.p, 2l, 1l).getTaskId()); }.runTaskTimer(P.p, 2l, 1l).getTaskId());
} }
private boolean isCustomAndDistill(BrewerInventory brewer) { private boolean isCustomAndDistill(BrewerInventory brewer) {
ItemStack item = brewer.getItem(3); // ingredient ItemStack item = brewer.getItem(3); // ingredient
if (item == null || Material.GLOWSTONE_DUST != item.getType()) return false; // need dust in the top slot. if (item == null || Material.GLOWSTONE_DUST != item.getType()) return false; // need dust in the top slot.
@@ -171,11 +176,16 @@ public class InventoryListener implements Listener {
} }
return false; return false;
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBrew(BrewEvent event) { public void onBrew(BrewEvent event) {
if (runDistill(event.getContents())) {
event.setCancelled(true);
}
}
private boolean runDistill(BrewerInventory inv) {
int slot = 0; int slot = 0;
BrewerInventory inv = event.getContents();
ItemStack item; ItemStack item;
boolean custom = false; boolean custom = false;
Boolean[] contents = new Boolean[3]; Boolean[] contents = new Boolean[3];
@@ -200,10 +210,10 @@ public class InventoryListener implements Listener {
slot++; slot++;
} }
if (custom) { if (custom) {
event.setCancelled(true);
Brew.distillAll(inv, contents); Brew.distillAll(inv, contents);
return true;
} }
return false;
} }
// convert to non colored Lore when taking out of Barrel/Brewer // convert to non colored Lore when taking out of Barrel/Brewer
@@ -233,7 +243,7 @@ public class InventoryListener implements Listener {
} }
} }
} }
// block the pickup of items where getPickupDelay is > 1000 (puke) // block the pickup of items where getPickupDelay is > 1000 (puke)
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onInventoryPickupItem(InventoryPickupItemEvent event){ public void onInventoryPickupItem(InventoryPickupItemEvent event){
@@ -70,6 +70,14 @@ public class PlayerListener implements Listener {
BCauldron.remove(clickedBlock); BCauldron.remove(clickedBlock);
} }
return; return;
// Its possible to empty a Cauldron with a Bucket in 1.9
} else if (P.use1_9 && materialInHand == Material.BUCKET) {
if (BCauldron.getFillLevel(clickedBlock) == 2) {
// will only remove when existing
BCauldron.remove(clickedBlock);
}
return;
} }
// Check if fire alive below cauldron when adding ingredients // Check if fire alive below cauldron when adding ingredients
@@ -202,7 +210,7 @@ public class PlayerListener implements Listener {
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
Words.playerChat(event); Words.playerChat(event);
} }
// player commands while drunk, distort chat commands // player commands while drunk, distort chat commands
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onCommandPreProcess(PlayerCommandPreprocessEvent event) { public void onCommandPreProcess(PlayerCommandPreprocessEvent event) {
@@ -257,4 +265,4 @@ public class PlayerListener implements Listener {
bplayer.disconnecting(); bplayer.disconnecting();
} }
} }
} }