forked from Upstream/CommandPanels
Added custom-data: to the sellall= and sell=
This commit is contained in:
parent
5b15f59e53
commit
5f30c6edcb
@ -200,7 +200,7 @@ public class CommandTags {
|
||||
}
|
||||
}
|
||||
case "item-paywall=": {
|
||||
//if player uses item-paywall= [Material] [Amount] [Id] [CustomModelData]
|
||||
//if player uses item-paywall= [Material] [Amount] <id:#> <custom-data:#>
|
||||
//player can use item-paywall= [custom-item]
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
List<ItemStack> remCont = new ArrayList<>();
|
||||
@ -284,6 +284,7 @@ public class CommandTags {
|
||||
} else {
|
||||
//if the item is a standard material
|
||||
if (cont.get(f).getType() == sellItem.getType()) {
|
||||
//Checking for custom model data. If it does not have or not the correct number go to next in loop.
|
||||
if(customData != 0){
|
||||
if(!cont.get(f).hasItemMeta()){
|
||||
continue;
|
||||
@ -293,6 +294,7 @@ public class CommandTags {
|
||||
}
|
||||
}
|
||||
|
||||
//Adding item to the remove list then checking if we have reached the required amount.
|
||||
ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f);
|
||||
remainingAmount -= add.getAmount();
|
||||
remCont.add(add);
|
||||
@ -308,6 +310,7 @@ public class CommandTags {
|
||||
for (int f = 0; f <= remCont.size() - 1; f++) {
|
||||
ItemStack remItem = remCont.get(f);
|
||||
|
||||
//Check if its the last item in the loop and only subtract the remaining amount.
|
||||
if(f == remCont.size() - 1){
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
p.getInventory().getItem((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
@ -316,7 +319,7 @@ public class CommandTags {
|
||||
cont.get((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
} else {
|
||||
} else { //If its anywhere but the last in loop just get rid of the items.
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
p.getInventory().getItem(remItem.getDurability()).setAmount(0);
|
||||
p.updateInventory();
|
||||
|
@ -29,7 +29,7 @@ public class SellItemTags implements Listener {
|
||||
public void commandTag(CommandTagEvent e){
|
||||
if(e.name.equalsIgnoreCase("sell=")){
|
||||
e.commandTagUsed();
|
||||
//if player uses sell= it will be eg. sell= <total cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
||||
//if player uses sell= it will be eg. sell= <total cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP] [custom-data:#]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
int sold = removeItem(e.p, e.args, false);
|
||||
@ -98,6 +98,20 @@ public class SellItemTags implements Listener {
|
||||
//get inventory slots and then an empty list to store slots that have the item to sell
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
List<ItemStack> remCont = new ArrayList<>();
|
||||
byte id = -1;
|
||||
String potion = "false";
|
||||
int customData = 0;
|
||||
for(String argsTemp : args){
|
||||
if(argsTemp.startsWith("potion:")){
|
||||
potion = argsTemp.replace("potion:","");
|
||||
}
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
}
|
||||
if (argsTemp.startsWith("custom-data:")) {
|
||||
customData = Integer.parseInt(argsTemp.replace("custom-data:", ""));
|
||||
}
|
||||
}
|
||||
|
||||
//create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount)
|
||||
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), removeAll ? 0 : Integer.parseInt(args[2]));
|
||||
@ -107,23 +121,6 @@ public class SellItemTags implements Listener {
|
||||
ItemStack remItm;
|
||||
if (itm != null && itm.getType().equals(sellItem.getType())) {
|
||||
remItm = new ItemStack(itm.getType(), itm.getAmount(), (short)f);
|
||||
//determine if the command contains parameters for extensions
|
||||
String potion = "false";
|
||||
for(String argsTemp : args){
|
||||
if(argsTemp.startsWith("potion:")){
|
||||
potion = argsTemp.replace("potion:","");
|
||||
}
|
||||
}
|
||||
//legacy ID
|
||||
byte id = -1;
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
|
||||
for (String argsTemp : args) {
|
||||
if (argsTemp.startsWith("id:")) {
|
||||
id = Byte.parseByte(argsTemp.replace("id:", ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//check to ensure any extensions are checked
|
||||
try {
|
||||
if (!potion.equals("false")) {
|
||||
@ -139,6 +136,15 @@ public class SellItemTags implements Listener {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (customData != 0) {
|
||||
if (!itm.hasItemMeta()) {
|
||||
continue;
|
||||
} else {
|
||||
if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(Exception exc){
|
||||
//skip if it cannot do unless plugin.debug is enabled
|
||||
plugin.debug(exc,p);
|
||||
|
Loading…
Reference in New Issue
Block a user