Changes for Distilling and 1.9

This commit is contained in:
Sn0wStorm 2016-04-23 17:45:01 +02:00
parent 82964cfd8c
commit 468b90be43
5 changed files with 899 additions and 877 deletions

View File

@ -15,6 +15,7 @@ import org.bukkit.potion.PotionEffectType;
public class Brew {
// represents the liquid in the brewed Potions
public static Map<Integer, Brew> potions = new HashMap<Integer, Brew>();
public static Boolean colorInBarrels; // color the Lore while in Barrels
public static Boolean colorInBrewer; // color the Lore while in Brewer
@ -307,6 +308,7 @@ public class Brew {
}
// Distilling section ---------------
// distill all custom potions in the brewer
public static void distillAll(BrewerInventory inv, Boolean[] contents) {
int slot = 0;
@ -369,6 +371,7 @@ public class Brew {
}
// Ageing Section ------------------
public void age(ItemStack item, float time, byte woodType) {
if (stat) {
return;
@ -452,6 +455,7 @@ public class Brew {
}
// Lore -----------
// Converts to/from qualitycolored Lore
public void convertLore(PotionMeta meta, Boolean toQuality) {
if (currentRecipe == null) {

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
// Workaround to remove unwanted potion effects
public class Compat1_9 implements Listener {
public class DrinkListener1_9 implements Listener {
@EventHandler
public void onPlayerDrink(PlayerItemConsumeEvent event) {

View File

@ -12,6 +12,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
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.
* 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
* set of ingredients in the brewer can be distilled.
* 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.
* Nothing here should interfere with vanilla brewing.
*
*
* 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
* two brews this way, just remove them before the "final" distillation or you will actually
* brew the potion as well.
*
*
* @author ProgrammerDan (1.9 distillation update only)
*/
public class InventoryListener implements Listener {
/* === Recreating manually the prior BrewEvent behavior. === */
private HashSet<UUID> trackedBrewmen = new HashSet<UUID>();
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.
* @param event
@ -60,11 +62,11 @@ public class InventoryListener implements Listener {
HumanEntity player = event.getPlayer();
Inventory inv = event.getInventory();
if (player == null || inv == null || !(inv instanceof BrewerInventory)) return;
P.p.debugLog("Starting brew inventory tracking");
trackedBrewmen.add(player.getUniqueId());
}
/**
* Stop tracking distillation for a person when they close the brewer window.
* @param event
@ -75,7 +77,7 @@ public class InventoryListener implements Listener {
HumanEntity player = event.getPlayer();
Inventory inv = event.getInventory();
if (player == null || inv == null || !(inv instanceof BrewerInventory)) return;
P.p.debugLog("Stopping brew inventory tracking");
trackedBrewmen.remove(player.getUniqueId());
}
@ -84,7 +86,7 @@ public class InventoryListener implements Listener {
* Clicking can either start or stop the new brew distillation tracking.
* Note that server restart will halt any ongoing brewing processes and
* they will _not_ restart until a new click event.
*
*
* @param event the Click event.
*/
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@ -93,53 +95,56 @@ public class InventoryListener implements Listener {
HumanEntity player = event.getWhoClicked();
Inventory inv = event.getInventory();
if (player == null || inv == null || !(inv instanceof BrewerInventory)) return;
UUID puid = player.getUniqueId();
if (!trackedBrewmen.contains(puid)) return;
if (InventoryType.BREWING != inv.getType()) return;
if (event.getAction() == InventoryAction.NOTHING) return; // Ignore clicks that do nothing
BrewerInventory brewer = (BrewerInventory) inv;
final Block brewery = brewer.getHolder().getBlock();
// If we were already tracking the brewer, cancel any ongoing event due to the click.
Integer curTask = trackedBrewers.get(brewery);
if (curTask != null) {
Bukkit.getScheduler().cancelTask(curTask); // cancel prior
}
// Now check if we should bother to track it.
trackedBrewers.put(brewery, new BukkitRunnable() {
private int brewTime = 401;
private int brewTime = DISTILLTIME;
@Override
public void run() {
BlockState now = brewery.getState();
if (now instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) now;
// check if still custom
BrewerInventory brewer = stand.getInventory();
if (isCustomAndDistill(brewer) ) {
// Still a valid brew distillation
brewTime = brewTime - 1; // count down.
stand.setBrewingTime(brewTime); // arbitrary for now
if (brewTime <= 1) { // Done!
BrewEvent doBrew = new BrewEvent(brewery, brewer);
Bukkit.getServer().getPluginManager().callEvent(doBrew);
if (!doBrew.isCancelled()) { // BrewEvent _wasn't_ cancelled.
this.cancel();
trackedBrewers.remove(brewery);
stand.setBrewingTime(0);
P.p.debugLog("All done distilling");
} else {
brewTime = 401; // go again.
P.p.debugLog("Can distill more! Continuing.");
}
if (brewTime == DISTILLTIME) { // only check at the beginning (and end) for distillables
if (!isCustomAndDistill(stand.getInventory())) {
this.cancel();
trackedBrewers.remove(brewery);
P.p.debugLog("nothing to distill");
return;
}
}
brewTime--; // count down.
stand.setBrewingTime(brewTime); // arbitrary for now
if (brewTime <= 1) { // Done!
//BrewEvent doBrew = new BrewEvent(brewery, brewer);
//Bukkit.getServer().getPluginManager().callEvent(doBrew);
BrewerInventory brewer = stand.getInventory();
if (!runDistill(brewer)) {
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 {
this.cancel();
@ -149,7 +154,7 @@ public class InventoryListener implements Listener {
}
}.runTaskTimer(P.p, 2l, 1l).getTaskId());
}
private boolean isCustomAndDistill(BrewerInventory brewer) {
ItemStack item = brewer.getItem(3); // ingredient
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;
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBrew(BrewEvent event) {
if (runDistill(event.getContents())) {
event.setCancelled(true);
}
}
private boolean runDistill(BrewerInventory inv) {
int slot = 0;
BrewerInventory inv = event.getContents();
ItemStack item;
boolean custom = false;
Boolean[] contents = new Boolean[3];
@ -200,10 +210,10 @@ public class InventoryListener implements Listener {
slot++;
}
if (custom) {
event.setCancelled(true);
Brew.distillAll(inv, contents);
return true;
}
return false;
}
// 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)
@EventHandler(ignoreCancelled = true)
public void onInventoryPickupItem(InventoryPickupItemEvent event){

View File

@ -70,6 +70,14 @@ public class PlayerListener implements Listener {
BCauldron.remove(clickedBlock);
}
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
@ -202,7 +210,7 @@ public class PlayerListener implements Listener {
public void onPlayerChat(AsyncPlayerChatEvent event) {
Words.playerChat(event);
}
// player commands while drunk, distort chat commands
@EventHandler(priority = EventPriority.LOWEST)
public void onCommandPreProcess(PlayerCommandPreprocessEvent event) {
@ -257,4 +265,4 @@ public class PlayerListener implements Listener {
bplayer.disconnecting();
}
}
}
}