mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
Add damage value support to FlatItemDb
...in case you wanted to give players broken swords, or something?
This commit is contained in:
parent
b49d3cc21c
commit
2d703fbc80
1 changed files with 20 additions and 5 deletions
|
@ -8,7 +8,10 @@ import com.google.gson.JsonParser;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.Damageable;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
|
import org.bukkit.inventory.meta.Repairable;
|
||||||
import org.bukkit.potion.PotionData;
|
import org.bukkit.potion.PotionData;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -95,7 +98,9 @@ public class FlatItemDb extends AbstractItemDb {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack get(final String id) throws Exception {
|
public ItemStack get(final String id) throws Exception {
|
||||||
ItemData data = getByName(id);
|
final String[] split = id.split(":");
|
||||||
|
|
||||||
|
ItemData data = getByName(split[0]);
|
||||||
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
throw new Exception(tl("unknownItemName", id));
|
throw new Exception(tl("unknownItemName", id));
|
||||||
|
@ -107,12 +112,22 @@ public class FlatItemDb extends AbstractItemDb {
|
||||||
ItemStack stack = new ItemStack(material);
|
ItemStack stack = new ItemStack(material);
|
||||||
stack.setAmount(material.getMaxStackSize());
|
stack.setAmount(material.getMaxStackSize());
|
||||||
|
|
||||||
if (potionData != null) {
|
ItemMeta meta = stack.getItemMeta();
|
||||||
PotionMeta meta = (PotionMeta) stack.getItemMeta();
|
|
||||||
meta.setBasePotionData(potionData);
|
if (potionData != null && meta instanceof PotionMeta) {
|
||||||
stack.setItemMeta(meta);
|
PotionMeta potionMeta = (PotionMeta) meta;
|
||||||
|
potionMeta.setBasePotionData(potionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For some reason, Damageable doesn't extend ItemMeta but CB implements them in the same
|
||||||
|
// class. As to why, your guess is as good as mine.
|
||||||
|
if (split.length > 1 && meta instanceof Damageable) {
|
||||||
|
Damageable damageMeta = (Damageable) meta;
|
||||||
|
damageMeta.setDamage(Integer.parseInt(split[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue