Merge pull request #6 from DieReicheErethons/master

Syncing with upstream
This commit is contained in:
Daniel Boston 2016-05-20 11:07:54 -04:00
commit 3504a7451e
10 changed files with 129 additions and 66 deletions

46
pom.xml
View File

@ -4,7 +4,7 @@
<groupId>com.dre</groupId>
<artifactId>brewery</artifactId>
<version>1.4.1</version>
<version>1.4.2</version>
<name>Brewery</name>
<properties>
@ -33,7 +33,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
@ -44,6 +44,10 @@
</build>
<repositories>
<repository>
<id>md_5-releases</id>
<url>http://repo.md-5.net/content/repositories/releases/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
@ -52,25 +56,17 @@
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
</repository>
<!--<repository>
<id>dre2n-repo</id>
<url>http://feuerstern.bplaced.net/repo/</url>
</repository>-->
<repository>
<id>mcstats-repo</id>
<url>http://repo.mcstats.org/content/repositories/public/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<repository>
<id>addstar-repo</id>
<url>http://maven.addstar.com.au/artifactory/ext-release-local/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>md_5-releases</id>
<url>http://repo.md-5.net/content/repositories/releases/</url>
<id>dre2n-rpo</id>
<url>http://feuerstern.bplaced.net/repo/</url>
</repository>
</repositories>
@ -78,7 +74,8 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.9-R0.1-SNAPSHOT</version>
<version>1.9.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
@ -90,22 +87,31 @@
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.griefcraft.lwc</groupId>
<artifactId>LWCPlugin</artifactId>
<version>1.7.2</version>
<version>4.5.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.ryanhamshire</groupId>
<artifactId>GriefPrevention</artifactId>
<version>14.5.1</version>
<scope>compile</scope>
<version>14.5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.diddiz</groupId>
<artifactId>logblock</artifactId>
<version>1.94</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.diddiz</groupId>
<artifactId>questioner</artifactId>
<version>1.94</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -203,7 +203,7 @@ public class BRecipe {
BIngredients bIngredients = new BIngredients(list, cookingTime);
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, 0);
Brew.PotionColor.valueOf(getColor()).colorBrew(potionMeta, potion, false);
potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
@ -212,6 +212,7 @@ public class BRecipe {
brew.convertLore(potionMeta, false);
Brew.addOrReplaceEffects(potionMeta, effects, quality);
brew.touch();
potion.setItemMeta(potionMeta);
return potion;

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();
}
}

View File

@ -21,6 +21,7 @@ public class Brew {
// represents the liquid in the brewed Potions
public static Map<Integer, Brew> potions = new HashMap<Integer, Brew>();
public static long installTime = System.currentTimeMillis(); // plugin install time in millis after epoch
public static Boolean colorInBarrels; // color the Lore while in Barrels
public static Boolean colorInBrewer; // color the Lore while in Brewer
@ -33,9 +34,11 @@ public class Brew {
private boolean unlabeled;
private boolean persistent;
private boolean stat; // static potions should not be changed
private int lastUpdate; // last update in hours after install time
public Brew(int uid, BIngredients ingredients) {
this.ingredients = ingredients;
touch();
potions.put(uid, this);
}
@ -44,11 +47,12 @@ public class Brew {
this.ingredients = ingredients;
this.quality = quality;
this.currentRecipe = recipe;
touch();
potions.put(uid, this);
}
// loading from file
public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat) {
public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat, int lastUpdate) {
potions.put(uid, this);
this.ingredients = ingredients;
this.quality = quality;
@ -58,6 +62,7 @@ public class Brew {
this.unlabeled = unlabeled;
this.persistent = persistent;
this.stat = stat;
this.lastUpdate = lastUpdate;
setRecipeFromString(recipe);
}
@ -83,8 +88,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 +278,23 @@ public class Brew {
unlabeled = true;
}
// Do some regular updates
public void touch() {
lastUpdate = (int) ((float) (System.currentTimeMillis() - installTime) / 3600000F);
}
public int getDistillRuns() {
return distillRuns;
}
public float getAgeTime() {
return ageTime;
}
public BRecipe getCurrentRecipe() {
return currentRecipe;
}
public boolean isPersistent() {
return persistent;
}
@ -304,6 +325,10 @@ public class Brew {
}
}
public int getLastUpdate() {
return lastUpdate;
}
// Distilling section ---------------
// distill all custom potions in the brewer
@ -355,6 +380,7 @@ public class Brew {
prefix = getQualityColor(ingredients.getDistillQuality(recipe, distillRuns));
}
updateDistillLore(prefix, potionMeta);
touch();
slotItem.setItemMeta(potionMeta);
}
@ -410,6 +436,7 @@ public class Brew {
updateWoodLore(potionMeta);
}
}
touch();
item.setItemMeta(potionMeta);
}
@ -639,6 +666,9 @@ public class Brew {
if (brew.stat) {
idConfig.set("stat", true);
}
if (brew.lastUpdate > 0) {
idConfig.set("lastUpdate", brew.lastUpdate);
}
// save the ingredients
idConfig.set("ingId", brew.ingredients.save(config.getParent()));
}

View File

@ -69,9 +69,6 @@ public class P extends JavaPlugin {
String v = Bukkit.getBukkitVersion();
useUUID = !v.matches(".*1\\.[0-6].*") && !v.matches(".*1\\.7\\.[0-5].*");
use1_9 = !v.matches(".*1\\.[0-8].*");
if (use1_9) {
log("&eExperimental support for Bukkit 1.9 enabled.");
}
// load the Config
try {
@ -262,7 +259,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();
}
@ -369,6 +366,8 @@ public class P extends JavaPlugin {
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
Brew.installTime = data.getLong("installTime", System.currentTimeMillis());
// Check if data is the newest version
String version = data.getString("Version", null);
if (version != null) {
@ -410,8 +409,9 @@ public class P extends JavaPlugin {
boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
boolean persistent = section.getBoolean(uid + ".persist", false);
boolean stat = section.getBoolean(uid + ".stat", false);
int lastUpdate = section.getInt("lastUpdate", 0);
new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat);
new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat, lastUpdate);
}
}

View File

@ -59,6 +59,8 @@ public class DataSave extends BukkitRunnable {
FileConfiguration configFile = new YamlConfiguration();
configFile.set("installTime", Brew.installTime);
if (!Brew.potions.isEmpty()) {
Brew.save(configFile.createSection("Brew"));
}

View File

@ -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();
}

View File

@ -430,6 +430,7 @@ public class CommandListener implements CommandExecutor {
brew.setStatic(true, hand);
p.msg(sender, p.languageReader.get("CMD_Persistent"));
}
brew.touch();
return;
}
}
@ -459,6 +460,7 @@ public class CommandListener implements CommandExecutor {
brew.setStatic(true, hand);
p.msg(sender, p.languageReader.get("CMD_Static"));
}
brew.touch();
return;
}
}
@ -478,6 +480,7 @@ public class CommandListener implements CommandExecutor {
Brew brew = Brew.get(hand);
if (brew != null) {
brew.unLabel(hand);
brew.touch();
p.msg(sender, p.languageReader.get("CMD_UnLabel"));
return;
}

View File

@ -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);

View File

@ -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.
@ -120,7 +115,7 @@ public class InventoryListener implements Listener {
if (now instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) now;
if (brewTime == DISTILLTIME) { // only check at the beginning (and end) for distillables
if (!isCustomAndDistill(stand.getInventory())) {
if (!isCustom(stand.getInventory(), true)) {
this.cancel();
trackedBrewers.remove(brewery);
P.p.debugLog("nothing to distill");
@ -152,22 +147,20 @@ 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) {
private boolean isCustom(BrewerInventory brewer, boolean distill) {
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()) {
int uid = Brew.getUID(item);
Brew pot = Brew.potions.get(uid);
if (pot != null && pot.canDistill()) { // need at least one distillable potion.
if (pot != null && (!distill || pot.canDistill())) { // need at least one distillable potion.
return true;
}
}
@ -179,6 +172,12 @@ public class InventoryListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBrew(BrewEvent event) {
if (P.use1_9) {
if (isCustom(event.getContents(), false)) {
event.setCancelled(true);
}
return;
}
if (runDistill(event.getContents())) {
event.setCancelled(true);
}
@ -216,6 +215,29 @@ public class InventoryListener implements Listener {
return false;
}
// Clicked a Brew somewhere, do some updating
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = false)
public void onInventoryClickLow(InventoryClickEvent event) {
if (event.getCurrentItem() != null && event.getCurrentItem().getType().equals(Material.POTION)) {
ItemStack item = event.getCurrentItem();
if (item.hasItemMeta()) {
PotionMeta potion = ((PotionMeta) item.getItemMeta());
Brew brew = Brew.get(potion);
if (brew != null) {
// convert potions from 1.8 to 1.9 for color and to remove effect descriptions
if (P.use1_9 && !potion.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
BRecipe recipe = brew.getCurrentRecipe();
if (recipe != null) {
Brew.PotionColor.valueOf(recipe.getColor()).colorBrew(potion, item, brew.canDistill());
item.setItemMeta(potion);
}
}
brew.touch();
}
}
}
}
// convert to non colored Lore when taking out of Barrel/Brewer
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
@ -260,7 +282,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();
}
}