mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-17 16:15:21 +01: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
@ -8,7 +8,10 @@ import com.google.gson.JsonParser;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Material;
|
||||
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.Repairable;
|
||||
import org.bukkit.potion.PotionData;
|
||||
|
||||
import java.util.*;
|
||||
@ -95,7 +98,9 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
throw new Exception(tl("unknownItemName", id));
|
||||
@ -107,12 +112,22 @@ public class FlatItemDb extends AbstractItemDb {
|
||||
ItemStack stack = new ItemStack(material);
|
||||
stack.setAmount(material.getMaxStackSize());
|
||||
|
||||
if (potionData != null) {
|
||||
PotionMeta meta = (PotionMeta) stack.getItemMeta();
|
||||
meta.setBasePotionData(potionData);
|
||||
stack.setItemMeta(meta);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
|
||||
if (potionData != null && meta instanceof PotionMeta) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user