mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-09-29 04:07:30 +02:00
Changes for Distilling and 1.9
This commit is contained in:
parent
82964cfd8c
commit
468b90be43
@ -15,6 +15,7 @@ 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
|
||||||
@ -307,6 +308,7 @@ public class Brew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
@ -369,6 +371,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;
|
||||||
@ -452,6 +455,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) {
|
||||||
|
@ -35,7 +35,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public class P extends JavaPlugin {
|
public class P extends JavaPlugin {
|
||||||
public static P p;
|
public static P p;
|
||||||
public static String configVersion = "1.3.1";
|
public static final String configVersion = "1.3.1";
|
||||||
public static boolean debug;
|
public static boolean debug;
|
||||||
public static boolean useUUID;
|
public static boolean useUUID;
|
||||||
public static boolean use1_9;
|
public static boolean use1_9;
|
||||||
@ -55,7 +55,7 @@ public class P extends JavaPlugin {
|
|||||||
public EntityListener entityListener;
|
public EntityListener entityListener;
|
||||||
public InventoryListener inventoryListener;
|
public InventoryListener inventoryListener;
|
||||||
public WorldListener worldListener;
|
public WorldListener worldListener;
|
||||||
public Compat1_9 compat1_9;
|
public DrinkListener1_9 drinkListener1_9;
|
||||||
|
|
||||||
// Language
|
// Language
|
||||||
public String language;
|
public String language;
|
||||||
@ -97,7 +97,7 @@ public class P extends JavaPlugin {
|
|||||||
entityListener = new EntityListener();
|
entityListener = new EntityListener();
|
||||||
inventoryListener = new InventoryListener();
|
inventoryListener = new InventoryListener();
|
||||||
worldListener = new WorldListener();
|
worldListener = new WorldListener();
|
||||||
compat1_9 = new Compat1_9();
|
drinkListener1_9 = new DrinkListener1_9();
|
||||||
getCommand("Brewery").setExecutor(new CommandListener());
|
getCommand("Brewery").setExecutor(new CommandListener());
|
||||||
|
|
||||||
p.getServer().getPluginManager().registerEvents(blockListener, p);
|
p.getServer().getPluginManager().registerEvents(blockListener, p);
|
||||||
@ -106,7 +106,7 @@ public class P extends JavaPlugin {
|
|||||||
p.getServer().getPluginManager().registerEvents(inventoryListener, p);
|
p.getServer().getPluginManager().registerEvents(inventoryListener, p);
|
||||||
p.getServer().getPluginManager().registerEvents(worldListener, p);
|
p.getServer().getPluginManager().registerEvents(worldListener, p);
|
||||||
if (use1_9) {
|
if (use1_9) {
|
||||||
p.getServer().getPluginManager().registerEvents(compat1_9, p);
|
p.getServer().getPluginManager().registerEvents(drinkListener1_9, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Heartbeat
|
// Heartbeat
|
||||||
|
@ -11,7 +11,7 @@ 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
|
||||||
public void onPlayerDrink(PlayerItemConsumeEvent event) {
|
public void onPlayerDrink(PlayerItemConsumeEvent event) {
|
@ -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;
|
||||||
@ -49,6 +50,7 @@ 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.
|
||||||
@ -98,6 +100,7 @@ public class InventoryListener implements Listener {
|
|||||||
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();
|
||||||
@ -110,36 +113,38 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
// 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();
|
||||||
@ -174,8 +179,13 @@ public class InventoryListener implements Listener {
|
|||||||
|
|
||||||
@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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user