Try to find Items with Vault

Makes adding Ingredients a lot easier, as Vault has a great database of item names.
Will match things like "green dye", or even "stained glass pane green"
This commit is contained in:
Sn0wStorm
2015-03-16 15:59:44 +01:00
parent 834804e44f
commit b8e0f1f38b
4 changed files with 56 additions and 5 deletions
+12
View File
@@ -53,6 +53,11 @@
</snapshots> </snapshots>
</repository> </repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
</repository>
<repository> <repository>
<id>sk89q-repo</id> <id>sk89q-repo</id>
<url>http://maven.sk89q.com/artifactory/repo/</url> <url>http://maven.sk89q.com/artifactory/repo/</url>
@@ -90,6 +95,13 @@
<version>1.8-R0.1-SNAPSHOT</version> <version>1.8-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.5</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>com.sk89q</groupId> <groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId> <artifactId>worldguard</artifactId>
+1 -1
View File
@@ -2,7 +2,7 @@ name: Brewery
version: 1.3.2 version: 1.3.2
main: com.dre.brewery.P main: com.dre.brewery.P
authors: [Milan Albrecht, Frank Baumann] authors: [Milan Albrecht, Frank Baumann]
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention] softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault]
commands: commands:
brewery: brewery:
description: Command for Administration description: Command for Administration
+18 -3
View File
@@ -51,11 +51,26 @@ public class BRecipe {
matParts = ingredParts[0].split("\\."); matParts = ingredParts[0].split("\\.");
} }
Material mat = Material.matchMaterial(matParts[0]); Material mat = Material.matchMaterial(matParts[0]);
if (mat != null) { short durability = -1;
ItemStack stack = new ItemStack(mat, P.p.parseInt(ingredParts[1]), (short) -1);
if (matParts.length == 2) { if (matParts.length == 2) {
stack.setDurability((short) P.p.parseInt(matParts[1])); durability = (short) P.p.parseInt(matParts[1]);
} }
if (mat == null && P.p.hasVault) {
try {
net.milkbowl.vault.item.ItemInfo vaultItem = net.milkbowl.vault.item.Items.itemByString(matParts[0]);
if (vaultItem != null) {
mat = vaultItem.getType();
if (durability == -1 && vaultItem.getSubTypeId() != 0) {
durability = vaultItem.getSubTypeId();
}
}
} catch (Exception e) {
P.p.errorLog("Could not check vault for Item Name");
e.printStackTrace();
}
}
if (mat != null) {
ItemStack stack = new ItemStack(mat, P.p.parseInt(ingredParts[1]), durability);
this.ingredients.add(stack); this.ingredients.add(stack);
} else { } else {
P.p.errorLog("Unknown Material: " + ingredParts[0]); P.p.errorLog("Unknown Material: " + ingredParts[0]);
+24
View File
@@ -49,6 +49,7 @@ public class P extends JavaPlugin {
public boolean useLWC; //LWC public boolean useLWC; //LWC
public boolean useLB; //LogBlock public boolean useLB; //LogBlock
public boolean useGP; //GriefPrevention public boolean useGP; //GriefPrevention
public boolean hasVault;
// Listeners // Listeners
public BlockListener blockListener; public BlockListener blockListener;
@@ -243,6 +244,7 @@ public class P extends JavaPlugin {
useLWC = config.getBoolean("useLWC", true) && getServer().getPluginManager().isPluginEnabled("LWC"); useLWC = config.getBoolean("useLWC", true) && getServer().getPluginManager().isPluginEnabled("LWC");
useGP = config.getBoolean("useGriefPrevention", true) && getServer().getPluginManager().isPluginEnabled("GriefPrevention"); useGP = config.getBoolean("useGriefPrevention", true) && getServer().getPluginManager().isPluginEnabled("GriefPrevention");
useLB = config.getBoolean("useLogBlock", false) && getServer().getPluginManager().isPluginEnabled("LogBlock"); useLB = config.getBoolean("useLogBlock", false) && getServer().getPluginManager().isPluginEnabled("LogBlock");
hasVault = getServer().getPluginManager().isPluginEnabled("Vault");
// various Settings // various Settings
DataSave.autosave = config.getInt("autosave", 3); DataSave.autosave = config.getInt("autosave", 3);
@@ -282,6 +284,17 @@ public class P extends JavaPlugin {
if (configSection != null) { if (configSection != null) {
for (String ingredient : configSection.getKeys(false)) { for (String ingredient : configSection.getKeys(false)) {
Material mat = Material.matchMaterial(ingredient); Material mat = Material.matchMaterial(ingredient);
if (mat == null && hasVault) {
try {
net.milkbowl.vault.item.ItemInfo vaultItem = net.milkbowl.vault.item.Items.itemByString(ingredient);
if (vaultItem != null) {
mat = vaultItem.getType();
}
} catch (Exception e) {
P.p.errorLog("Could not check vault for Item Name");
e.printStackTrace();
}
}
if (mat != null) { if (mat != null) {
BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null))); BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null)));
BIngredients.possibleIngredients.add(mat); BIngredients.possibleIngredients.add(mat);
@@ -299,6 +312,17 @@ public class P extends JavaPlugin {
if (drainSplit.length > 1) { if (drainSplit.length > 1) {
Material mat = Material.matchMaterial(drainSplit[0]); Material mat = Material.matchMaterial(drainSplit[0]);
int strength = p.parseInt(drainSplit[1]); int strength = p.parseInt(drainSplit[1]);
if (mat == null && hasVault && strength > 0) {
try {
net.milkbowl.vault.item.ItemInfo vaultItem = net.milkbowl.vault.item.Items.itemByString(drainSplit[0]);
if (vaultItem != null) {
mat = vaultItem.getType();
}
} catch (Exception e) {
P.p.errorLog("Could not check vault for Item Name");
e.printStackTrace();
}
}
if (mat != null && strength > 0) { if (mat != null && strength > 0) {
BPlayer.drainItems.put(mat, strength); BPlayer.drainItems.put(mat, strength);
} }