Convert Potions for 1.9

Convert existing brews to show correct color and lore
This commit is contained in:
Sn0wStorm
2016-05-18 20:28:28 +02:00
parent e015b29c1c
commit 024c05b817
6 changed files with 63 additions and 37 deletions
+6 -6
View File
@@ -146,7 +146,7 @@ public class Barrel implements InventoryHolder {
}
} catch (Throwable e) {
P.p.errorLog("Failed to Check GriefPrevention for Barrel Open Permissions!");
P.p.errorLog("Brewery was tested with GriefPrevention 14.5.1");
P.p.errorLog("Brewery was tested with GriefPrevention 14.5.4");
P.p.errorLog("Disable the GriefPrevention support in the config and do /brew reload");
e.printStackTrace();
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
@@ -168,7 +168,7 @@ public class Barrel implements InventoryHolder {
return LWCBarrel.checkAccess(player, sign, event, plugin);
} catch (Throwable e) {
P.p.errorLog("Failed to Check LWC for Barrel Open Permissions!");
P.p.errorLog("Brewery was tested with version 4.3.1 of LWC!");
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
e.printStackTrace();
P.p.msg(player, "&cError opening Barrel, please report to an Admin!");
@@ -193,7 +193,7 @@ public class Barrel implements InventoryHolder {
return LWCBarrel.checkDestroy(player, this);
} catch (Throwable e) {
P.p.errorLog("Failed to Check LWC for Barrel Break Permissions!");
P.p.errorLog("Brewery was tested with version 4.3.1 of LWC!");
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
P.p.errorLog("Disable the LWC support in the config and do /brew reload");
e.printStackTrace();
P.p.msg(player, "&cError breaking Barrel, please report to an Admin!");
@@ -211,7 +211,7 @@ public class Barrel implements InventoryHolder {
LWCBarrel.remove(this);
} catch (Throwable e) {
P.p.errorLog("Failed to Remove LWC Lock from Barrel!");
P.p.errorLog("Brewery was tested with version 4.3.1 of LWC!");
P.p.errorLog("Brewery was tested with version 4.5.0 of LWC!");
e.printStackTrace();
}
}
@@ -256,7 +256,7 @@ public class Barrel implements InventoryHolder {
LogBlockBarrel.openBarrel(player, inventory, spigot.getLocation());
} catch (Throwable e) {
P.p.errorLog("Failed to Log Barrel to LogBlock!");
P.p.errorLog("Brewery was tested with version 1.80 of LogBlock!");
P.p.errorLog("Brewery was tested with version 1.94 of LogBlock!");
e.printStackTrace();
}
}
@@ -461,7 +461,7 @@ public class Barrel implements InventoryHolder {
LogBlockBarrel.breakBarrel(breaker.getName(), items, spigot.getLocation());
} catch (Throwable e) {
P.p.errorLog("Failed to Log Barrel-break to LogBlock!");
P.p.errorLog("Brewery was tested with version 1.80 of LogBlock!");
P.p.errorLog("Brewery was tested with version 1.94 of LogBlock!");
e.printStackTrace();
}
}
+13 -2
View File
@@ -83,8 +83,7 @@ public class Brew {
public static Brew get(ItemStack item) {
if (item.getType() == Material.POTION) {
if (item.hasItemMeta()) {
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
return get(potionMeta);
return get((PotionMeta) item.getItemMeta());
}
}
return null;
@@ -274,6 +273,18 @@ public class Brew {
unlabeled = true;
}
public int getDistillRuns() {
return distillRuns;
}
public float getAgeTime() {
return ageTime;
}
public BRecipe getCurrentRecipe() {
return currentRecipe;
}
public boolean isPersistent() {
return persistent;
}
+1 -1
View File
@@ -262,7 +262,7 @@ public class P extends JavaPlugin {
} catch (Throwable e) {
wg = null;
P.p.errorLog("Failed loading WorldGuard Integration! Opening Barrels will NOT work!");
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");
e.printStackTrace();
}
@@ -26,7 +26,7 @@ public class WGBarrelOld implements WGBarrel {
canBuild = ApplicableRegionSet.class.getMethod("canBuild", LocalPlayer.class);
} catch (NoSuchMethodException e) {
P.p.errorLog("Failed to Hook WorldGuard for Barrel Open Permissions! Opening Barrels will NOT work!");
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");
e.printStackTrace();
}
@@ -17,13 +17,12 @@ public class DrinkListener1_9 implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerDrink(PlayerItemConsumeEvent event) {
ItemStack item = event.getItem();
Brew brew = Brew.get(item);
if (brew == null) {
return;
}
if (item.getType() == Material.POTION) {
PotionMeta meta = (PotionMeta) item.getItemMeta();
Brew brew = Brew.get(meta);
if (brew == null) {
return;
}
// Throw away former "base" effect and replace with MUNDANE.
meta.setBasePotionData(new PotionData(PotionType.MUNDANE, false, false));
item.setItemMeta(meta);
@@ -1,9 +1,12 @@
package com.dre.brewery.listeners;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
import com.dre.brewery.BRecipe;
import com.dre.brewery.Barrel;
import com.dre.brewery.Brew;
import com.dre.brewery.P;
import com.dre.brewery.integration.LogBlockBarrel;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.BrewingStand;
@@ -11,25 +14,17 @@ import org.bukkit.entity.HumanEntity;
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;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.*;
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import com.dre.brewery.Barrel;
import com.dre.brewery.Brew;
import com.dre.brewery.P;
import com.dre.brewery.integration.LogBlockBarrel;
import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
/**
* Updated for 1.9 to replicate the "Brewing" process for distilling.
@@ -152,16 +147,14 @@ public class InventoryListener implements Listener {
P.p.debugLog("The block was replaced; not a brewing stand.");
}
}
}.runTaskTimer(P.p, 2l, 1l).getTaskId());
}.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.
Boolean[] contents = new Boolean[3];
for (int slot = 0; slot < 3; slot++) {
item = brewer.getItem(slot);
contents[slot] = false;
if (item != null) {
if (item.getType() == Material.POTION) {
if (item.hasItemMeta()) {
@@ -216,6 +209,29 @@ public class InventoryListener implements Listener {
return false;
}
// convert potions from 1.8 for color and to remove effect descriptions in 1.9
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = false)
public void onInventoryClickLow(InventoryClickEvent event) {
if (!P.use1_9) return;
if (event.getCurrentItem() != null && event.getCurrentItem().getType().equals(Material.POTION)) {
ItemStack item = event.getCurrentItem();
if (item.hasItemMeta()) {
PotionMeta potion = ((PotionMeta) item.getItemMeta());
if (!potion.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
Brew brew = Brew.get(potion);
if (brew != null) {
BRecipe recipe = brew.getCurrentRecipe();
if (recipe != null) {
Brew.PotionColor.valueOf(recipe.getColor()).colorBrew(potion, item, brew.canDistill());
item.setItemMeta(potion);
}
}
}
}
}
}
// convert to non colored Lore when taking out of Barrel/Brewer
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
@@ -260,7 +276,7 @@ public class InventoryListener implements Listener {
LogBlockBarrel.closeBarrel(event.getPlayer(), event.getInventory());
} catch (Exception e) {
P.p.errorLog("Failed to Log Barrel to LogBlock!");
P.p.errorLog("Brewery was tested with version 1.80 of LogBlock!");
P.p.errorLog("Brewery was tested with version 1.94 of LogBlock!");
e.printStackTrace();
}
}