- Fixed potion stacking and adding items to stacks with a different durability

- Modified /iteminfo a bit
- Added a message to the DBpage generator
- Added more functions to word datavalue
- Modified the SignChange fourth line formatting
This commit is contained in:
Acrobot 2011-12-20 21:39:45 +01:00
parent 2e489774d8
commit 505dfb3449
7 changed files with 66 additions and 12 deletions

View File

@ -36,8 +36,9 @@ public class ItemInfo implements CommandExecutor {
String enchantment = (ench != null ? ChatColor.DARK_AQUA + "-" + ench : "");
sender.sendMessage(Config.getLocal(Language.iteminfo));
sender.sendMessage(ChatColor.GRAY + uSign.capitalizeFirst(item.getType().name())
+ ChatColor.WHITE + " " + item.getTypeId() + durability + enchantment + ChatColor.WHITE);
String itemname = Items.getName(item);
sender.sendMessage(ChatColor.GRAY + itemname + ChatColor.WHITE + " "
+ item.getTypeId() + durability + enchantment + ChatColor.WHITE);
Map<Enchantment, Integer> map = item.getEnchantments();
for (Map.Entry<Enchantment, Integer> e : map.entrySet())

View File

@ -112,6 +112,9 @@ public class Generator implements Runnable {
private static void generateStats() {
try {
File f = new File(filePath).getParentFile();
if (!f.exists()) f.mkdir();
fileStart();
buf = new BufferedWriter(new FileWriter(filePath, true));
@ -124,6 +127,7 @@ public class Generator implements Runnable {
fileEnd();
} catch (Exception e) {
Logging.log("Couldn't generate statistics page!");
e.printStackTrace();
}
}
}

View File

@ -4,6 +4,7 @@ import org.bukkit.CoalType;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.TreeSpecies;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.*;
/**
@ -27,9 +28,11 @@ public class DataValue {
materialData = new Step(Items.getMaterial(type));
break;
case WOOL:
case INK_SACK:
materialData = new Wool(DyeColor.valueOf(type));
break;
case INK_SACK:
materialData = new Wool(15 - DyeColor.valueOf(type).getData());
break;
case COAL:
materialData = new Coal(CoalType.valueOf(type));
break;
@ -38,4 +41,37 @@ public class DataValue {
return (materialData == null ? 0 : materialData.getData());
}
public static String getName(ItemStack is){
short dur = is.getDurability();
if (dur == 0) return null;
Material material = is.getType();
String name = null;
try {
switch (material) {
case SAPLING:
case LOG:
name = TreeSpecies.getByData((byte) dur).name();
break;
case STEP:
case DOUBLE_STEP:
name = new Step(Material.getMaterial(dur)).getMaterial().name();
break;
case WOOL:
name = DyeColor.getByData((byte) dur).name();
break;
case INK_SACK:
name = DyeColor.getByData((byte) (15 - dur)).name();
break;
case COAL:
name = CoalType.getByData((byte) dur).name();
break;
}
} catch (Exception e) { return null; }
return name;
}
}

View File

@ -2,6 +2,7 @@ package com.Acrobot.ChestShop.Items;
import com.Acrobot.ChestShop.Utils.uEnchantment;
import com.Acrobot.ChestShop.Utils.uNumber;
import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
@ -32,6 +33,15 @@ public class Items {
return finalMaterial;
}
public static String getName(ItemStack is){
return getName(is, true);
}
public static String getName(ItemStack is, boolean showData){
String name = DataValue.getName(is);
return uSign.capitalizeFirst((name != null && showData ? name + '_' : "") + is.getType());
}
public static ItemStack getItemStack(String itemName) {
ItemStack toReturn = getFromOddItem(itemName);
if (toReturn != null) return toReturn;

View File

@ -70,7 +70,7 @@ public class signChange extends BlockListener {
return;
}
event.setLine(2, thirdLine);
event.setLine(3, formatFourthLine(line[3], mat));
event.setLine(3, formatFourthLine(line[3], stock));
Chest chest = uBlock.findChest(signBlock);
@ -148,15 +148,18 @@ public class signChange extends BlockListener {
return (thirdLine.length() > 15 ? null : thirdLine);
}
private static String formatFourthLine(String fourthLine, Material material) {
private static String formatFourthLine(String fourthLine, ItemStack is) {
int index = (fourthLine.indexOf(':') != -1 ? fourthLine.indexOf(':') : 9999);
if (fourthLine.indexOf('-') < index && fourthLine.indexOf('-') != -1) index = fourthLine.indexOf('-');
StringBuilder toReturn = new StringBuilder(3);
String matName = uSign.capitalizeFirst(material.name());
if (index != 9999 && matName.length() > (15 - (fourthLine.length() - index))) matName = matName.substring(0, 15 - (fourthLine.length() - index));
if (Items.getMaterial(matName) == material) toReturn.append(matName);
else toReturn.append(material.getId());
String matName = fourthLine.split(":|-")[0];
matName = matName.trim();
if (uNumber.isInteger(matName)) matName = Items.getName(is, false);
int iPos = 15 - (fourthLine.length() - index);
if (index != 9999 && matName.length() > iPos) matName = matName.substring(0, iPos);
if (Items.getItemStack(matName).getType() == is.getType()) toReturn.append(matName);
else toReturn.append(is.getTypeId());
if (index != -1 && index != 9999) toReturn.append(fourthLine.substring(index));
return toReturn.toString();

View File

@ -57,7 +57,7 @@ public class uInventory {
}
private static int addManually(Inventory inv, ItemStack item, int amount) {
return addManually(inv, item, amount, item.getType().getMaxStackSize());
return addManually(inv, item, amount, (item.getType() != Material.POTION ? item.getType().getMaxStackSize() : 1)); //TODO Change it when it's repaired in Bukkit
}
public static int addAndStackTo64(Inventory inv, ItemStack item, int amount) {
@ -76,7 +76,7 @@ public class uInventory {
dupe.addEnchantments(item.getEnchantments());
amount -= dupe.getAmount();
inv.setItem(slot, dupe);
} else if (equals(item, curItem, item.getDurability()) && curItem.getAmount() != max) {
} else if (equals(item, curItem, curItem.getDurability()) && curItem.getAmount() != max) {
int cA = curItem.getAmount();
int amountAdded = amount > max - cA ? max - cA : amount;
dupe.setAmount(cA + amountAdded);

View File

@ -2,7 +2,7 @@ name: ChestShop
main: com.Acrobot.ChestShop.ChestShop
version: 3.30
version: 3.31
author: Acrobot