From 15c873392a94b1319fd0d2af96ac90a801683e39 Mon Sep 17 00:00:00 2001 From: Mini-Chiss Date: Thu, 20 Aug 2015 20:38:07 +0200 Subject: [PATCH] updated give to allow naming of items. --- .../mineplex/core/common/util/UtilItem.java | 35 ++++++++++++------- .../src/mineplex/core/give/Give.java | 19 ++++++---- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java index cdd967e05..1c874c58b 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java @@ -4,22 +4,24 @@ import java.util.AbstractMap; import java.util.LinkedList; import java.util.Map.Entry; +import mineplex.core.common.structs.ItemContainer; + import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class UtilItem { - public static LinkedList> matchItem(Player caller, String items, boolean inform) + public static LinkedList matchItem(Player caller, String items, boolean inform) { - LinkedList> matchList = new LinkedList>(); + LinkedList matchList = new LinkedList(); String failList = ""; //Mass Search for (String cur : items.split(",")) { - Entry match = searchItem(caller, cur, inform); + ItemContainer match = searchItem(caller, cur, inform); if (match != null) matchList.add(match); @@ -40,21 +42,27 @@ public class UtilItem return matchList; } - public static Entry searchItem(Player caller, String args, boolean inform) + public static ItemContainer searchItem(Player caller, String args, boolean inform) { - LinkedList> matchList = new LinkedList>(); + LinkedList matchList = new LinkedList(); 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 if (cur.toString().equalsIgnoreCase(args)) - return new AbstractMap.SimpleEntry(cur, (byte)0); + return new ItemContainer(cur, (byte)0, name); if (cur.toString().toLowerCase().contains(args.toLowerCase())) - matchList.add(new AbstractMap.SimpleEntry(cur, (byte)0)); + matchList.add(new ItemContainer(cur, (byte)0, name)); - //By ID:Data - String[] arg = args.split(":"); + //By ID:Data:Name //ID int id = 0; @@ -82,8 +90,8 @@ public class UtilItem { continue; } - - return new AbstractMap.SimpleEntry(cur, data); + + return new ItemContainer(cur, data, name); } //No / Non-Unique @@ -102,8 +110,9 @@ public class UtilItem if (matchList.size() > 0) { String matchString = ""; - for (Entry cur : matchList) - matchString += F.elem(cur.getKey().toString()) + ", "; + for (ItemContainer cur : matchList) + matchString += F.elem(cur.Type.toString()) + ", "; + if (matchString.length() > 1) matchString = matchString.substring(0 , matchString.length() - 2); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/give/Give.java b/Plugins/Mineplex.Core/src/mineplex/core/give/Give.java index 458ad6400..21234daa6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/give/Give.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/give/Give.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.common.structs.ItemContainer; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilInv; 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) { //Item - LinkedList> itemList = new LinkedList>(); + LinkedList itemList = new LinkedList(); itemList = UtilItem.matchItem(player, itemNames, true); if (itemList.isEmpty()) return; @@ -128,11 +129,15 @@ public class Give extends MiniPlugin if (givenList.length() > 0) givenList = givenList.substring(0, givenList.length()-1); - for (Entry curItem : itemList) + for (ItemContainer curItem : itemList) { 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 stack.addUnsafeEnchantments(enchs); @@ -142,18 +147,18 @@ public class Give extends MiniPlugin { //Inform 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")) - 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) - 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 - 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()) + ".")); } } }