updated give to allow naming of items.
This commit is contained in:
parent
f97da1bdba
commit
15c873392a
@ -4,22 +4,24 @@ import java.util.AbstractMap;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import mineplex.core.common.structs.ItemContainer;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class UtilItem
|
public class UtilItem
|
||||||
{
|
{
|
||||||
public static LinkedList<Entry<Material, Byte>> matchItem(Player caller, String items, boolean inform)
|
public static LinkedList<ItemContainer> matchItem(Player caller, String items, boolean inform)
|
||||||
{
|
{
|
||||||
LinkedList<Entry<Material, Byte>> matchList = new LinkedList<Entry<Material, Byte>>();
|
LinkedList<ItemContainer> matchList = new LinkedList<ItemContainer>();
|
||||||
|
|
||||||
String failList = "";
|
String failList = "";
|
||||||
|
|
||||||
//Mass Search
|
//Mass Search
|
||||||
for (String cur : items.split(","))
|
for (String cur : items.split(","))
|
||||||
{
|
{
|
||||||
Entry<Material, Byte> match = searchItem(caller, cur, inform);
|
ItemContainer match = searchItem(caller, cur, inform);
|
||||||
|
|
||||||
if (match != null)
|
if (match != null)
|
||||||
matchList.add(match);
|
matchList.add(match);
|
||||||
@ -40,21 +42,27 @@ public class UtilItem
|
|||||||
return matchList;
|
return matchList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entry<Material, Byte> searchItem(Player caller, String args, boolean inform)
|
public static ItemContainer searchItem(Player caller, String args, boolean inform)
|
||||||
{
|
{
|
||||||
LinkedList<Entry<Material, Byte>> matchList = new LinkedList<Entry<Material, Byte>>();
|
LinkedList<ItemContainer> matchList = new LinkedList<ItemContainer>();
|
||||||
|
|
||||||
for (Material cur : Material.values())
|
for (Material cur : Material.values())
|
||||||
{
|
{
|
||||||
|
String[] arg = args.split(":");
|
||||||
|
|
||||||
|
//Get Selected Name
|
||||||
|
String name = null;
|
||||||
|
if (arg.length > 2)
|
||||||
|
name = arg[2].replaceAll("_", " ");
|
||||||
|
|
||||||
//By Name
|
//By Name
|
||||||
if (cur.toString().equalsIgnoreCase(args))
|
if (cur.toString().equalsIgnoreCase(args))
|
||||||
return new AbstractMap.SimpleEntry<Material, Byte>(cur, (byte)0);
|
return new ItemContainer(cur, (byte)0, name);
|
||||||
|
|
||||||
if (cur.toString().toLowerCase().contains(args.toLowerCase()))
|
if (cur.toString().toLowerCase().contains(args.toLowerCase()))
|
||||||
matchList.add(new AbstractMap.SimpleEntry<Material, Byte>(cur, (byte)0));
|
matchList.add(new ItemContainer(cur, (byte)0, name));
|
||||||
|
|
||||||
//By ID:Data
|
//By ID:Data:Name
|
||||||
String[] arg = args.split(":");
|
|
||||||
|
|
||||||
//ID
|
//ID
|
||||||
int id = 0;
|
int id = 0;
|
||||||
@ -83,7 +91,7 @@ public class UtilItem
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AbstractMap.SimpleEntry<Material, Byte>(cur, data);
|
return new ItemContainer(cur, data, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//No / Non-Unique
|
//No / Non-Unique
|
||||||
@ -102,8 +110,9 @@ public class UtilItem
|
|||||||
if (matchList.size() > 0)
|
if (matchList.size() > 0)
|
||||||
{
|
{
|
||||||
String matchString = "";
|
String matchString = "";
|
||||||
for (Entry<Material, Byte> cur : matchList)
|
for (ItemContainer cur : matchList)
|
||||||
matchString += F.elem(cur.getKey().toString()) + ", ";
|
matchString += F.elem(cur.Type.toString()) + ", ";
|
||||||
|
|
||||||
if (matchString.length() > 1)
|
if (matchString.length() > 1)
|
||||||
matchString = matchString.substring(0 , matchString.length() - 2);
|
matchString = matchString.substring(0 , matchString.length() - 2);
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.MiniPlugin;
|
import mineplex.core.MiniPlugin;
|
||||||
|
import mineplex.core.common.structs.ItemContainer;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.F;
|
||||||
import mineplex.core.common.util.UtilInv;
|
import mineplex.core.common.util.UtilInv;
|
||||||
import mineplex.core.common.util.UtilItem;
|
import mineplex.core.common.util.UtilItem;
|
||||||
@ -65,7 +66,7 @@ public class Give extends MiniPlugin
|
|||||||
public void give(Player player, String target, String itemNames, String amount, String enchants)
|
public void give(Player player, String target, String itemNames, String amount, String enchants)
|
||||||
{
|
{
|
||||||
//Item
|
//Item
|
||||||
LinkedList<Entry<Material, Byte>> itemList = new LinkedList<Entry<Material, Byte>>();
|
LinkedList<ItemContainer> itemList = new LinkedList<ItemContainer>();
|
||||||
itemList = UtilItem.matchItem(player, itemNames, true);
|
itemList = UtilItem.matchItem(player, itemNames, true);
|
||||||
if (itemList.isEmpty())
|
if (itemList.isEmpty())
|
||||||
return;
|
return;
|
||||||
@ -128,11 +129,15 @@ public class Give extends MiniPlugin
|
|||||||
if (givenList.length() > 0)
|
if (givenList.length() > 0)
|
||||||
givenList = givenList.substring(0, givenList.length()-1);
|
givenList = givenList.substring(0, givenList.length()-1);
|
||||||
|
|
||||||
for (Entry<Material, Byte> curItem : itemList)
|
for (ItemContainer curItem : itemList)
|
||||||
{
|
{
|
||||||
for (Player cur : giveList)
|
for (Player cur : giveList)
|
||||||
{
|
{
|
||||||
ItemStack stack = ItemStackFactory.Instance.CreateStack(curItem.getKey(), curItem.getValue(), count);
|
ItemStack stack;
|
||||||
|
if (curItem.Name == null)
|
||||||
|
stack = ItemStackFactory.Instance.CreateStack(curItem.Type, curItem.Data, count);
|
||||||
|
else
|
||||||
|
stack = ItemStackFactory.Instance.CreateStack(curItem.Type, curItem.Data, count, curItem.Name);
|
||||||
|
|
||||||
//Enchants
|
//Enchants
|
||||||
stack.addUnsafeEnchantments(enchs);
|
stack.addUnsafeEnchantments(enchs);
|
||||||
@ -142,18 +147,18 @@ public class Give extends MiniPlugin
|
|||||||
{
|
{
|
||||||
//Inform
|
//Inform
|
||||||
if (!cur.equals(player))
|
if (!cur.equals(player))
|
||||||
UtilPlayer.message(cur, F.main("Give", "You received " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.getKey(), curItem.getValue(), false)) + " from " + F.elem(player.getName()) + "."));
|
UtilPlayer.message(cur, F.main("Give", "You received " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.Type, curItem.Data, false)) + " from " + F.elem(player.getName()) + "."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.equalsIgnoreCase("all"))
|
if (target.equalsIgnoreCase("all"))
|
||||||
UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.getKey(), curItem.getValue(), false)) + " to " + F.elem("ALL")) + ".");
|
UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.Type, curItem.Data, false)) + " to " + F.elem("ALL")) + ".");
|
||||||
|
|
||||||
else if (giveList.size() > 1)
|
else if (giveList.size() > 1)
|
||||||
UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.getKey(), curItem.getValue(), false)) + " to " + F.elem(givenList) + "."));
|
UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.Type, curItem.Data, false)) + " to " + F.elem(givenList) + "."));
|
||||||
|
|
||||||
else
|
else
|
||||||
UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.getKey(), curItem.getValue(), false)) + " to " + F.elem(giveList.getFirst().getName()) + "."));
|
UtilPlayer.message(player, F.main("Give", "You gave " + F.item(count + " " + ItemStackFactory.Instance.GetName(curItem.Type, curItem.Data, false)) + " to " + F.elem(giveList.getFirst().getName()) + "."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user