forked from Upstream/CommandPanels
Item-paywall fix for 1.8
This commit is contained in:
parent
4da33349a5
commit
056c547605
@ -492,6 +492,9 @@ public class ItemCreation {
|
|||||||
if (one.getType() != two.getType()) {
|
if (one.getType() != two.getType()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(one.hasItemMeta() != two.hasItemMeta()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
//check for name
|
//check for name
|
||||||
try {
|
try {
|
||||||
if (!one.getItemMeta().getDisplayName().equals(two.getItemMeta().getDisplayName())) {
|
if (!one.getItemMeta().getDisplayName().equals(two.getItemMeta().getDisplayName())) {
|
||||||
|
@ -20,10 +20,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class CommandTags {
|
public class CommandTags {
|
||||||
CommandPanels plugin;
|
CommandPanels plugin;
|
||||||
@ -228,25 +225,16 @@ public class CommandTags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "item-paywall=": {
|
case "item-paywall=": {
|
||||||
//if player uses item-paywall= [Material] [Amount] <id:#> <custom-data:#>
|
//if player uses item-paywall= [Material] [Amount] <id:#> WILL NOT TAKE CUSTOM ITEMS
|
||||||
//player can use item-paywall= [custom-item] [Amount]
|
//player can use item-paywall= [custom-item] [Amount]
|
||||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||||
List<ItemStack> remCont = new ArrayList<>();
|
HashMap<Integer, ItemStack> remCont = new HashMap<>();
|
||||||
String[] args = command.split("\\s");
|
String[] args = command.split("\\s");
|
||||||
try {
|
try {
|
||||||
byte id = -1;
|
int id = -1;
|
||||||
int customData = 0;
|
|
||||||
boolean noCustom = false;
|
|
||||||
for (String val : args) {
|
for (String val : args) {
|
||||||
if (val.startsWith("id:")) {
|
if (val.startsWith("id:")) {
|
||||||
id = Byte.parseByte(val.substring(3));
|
id = Integer.parseInt(val.substring(3));
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (val.startsWith("custom-data:")) {
|
|
||||||
customData = Integer.parseInt(val.substring(12));
|
|
||||||
}
|
|
||||||
if (val.contains("NOCUSTOMDATA")) {
|
|
||||||
noCustom = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,9 +263,9 @@ public class CommandTags {
|
|||||||
if (Material.matchMaterial(args[1]) == null) {
|
if (Material.matchMaterial(args[1]) == null) {
|
||||||
//item-paywall is a custom item as it is not a material
|
//item-paywall is a custom item as it is not a material
|
||||||
if (plugin.itemCreate.isIdentical(sellItem, itm)) {
|
if (plugin.itemCreate.isIdentical(sellItem, itm)) {
|
||||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
|
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount());
|
||||||
remainingAmount -= add.getAmount();
|
remainingAmount -= add.getAmount();
|
||||||
if (removal) remCont.add(add);
|
if (removal) remCont.put(f,add);
|
||||||
if (remainingAmount <= 0) {
|
if (remainingAmount <= 0) {
|
||||||
removedItem = PaywallOutput.Passed;
|
removedItem = PaywallOutput.Passed;
|
||||||
break;
|
break;
|
||||||
@ -291,23 +279,10 @@ public class CommandTags {
|
|||||||
String mmoType = customItemMaterial.split("\\s")[1];
|
String mmoType = customItemMaterial.split("\\s")[1];
|
||||||
String mmoID = customItemMaterial.split("\\s")[2];
|
String mmoID = customItemMaterial.split("\\s")[2];
|
||||||
|
|
||||||
if (plugin.isMMOItem(itm, mmoType, mmoID) && sellItem.getAmount() <= itm.getAmount()) {
|
|
||||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
|
||||||
if (removal) {
|
|
||||||
p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount());
|
|
||||||
}
|
|
||||||
p.updateInventory();
|
|
||||||
} else {
|
|
||||||
if (removal) itm.setAmount(itm.getAmount() - sellItem.getAmount());
|
|
||||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
|
||||||
}
|
|
||||||
removedItem = PaywallOutput.Passed;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (plugin.isMMOItem(itm, mmoType, mmoID)) {
|
if (plugin.isMMOItem(itm, mmoType, mmoID)) {
|
||||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
|
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount());
|
||||||
remainingAmount -= add.getAmount();
|
remainingAmount -= add.getAmount();
|
||||||
if (removal) remCont.add(add);
|
if (removal) remCont.put(f,add);
|
||||||
if (remainingAmount <= 0) {
|
if (remainingAmount <= 0) {
|
||||||
removedItem = PaywallOutput.Passed;
|
removedItem = PaywallOutput.Passed;
|
||||||
break;
|
break;
|
||||||
@ -321,32 +296,20 @@ public class CommandTags {
|
|||||||
} else {
|
} else {
|
||||||
//if the item is a standard material
|
//if the item is a standard material
|
||||||
if (itm.getType() == sellItem.getType()) {
|
if (itm.getType() == sellItem.getType()) {
|
||||||
//Checking for custom model data. If it does not have or not the correct number go to next in loop.
|
if(itm.hasItemMeta()){
|
||||||
if (customData != 0) {
|
//If item has custom meta continue to next item.
|
||||||
if (!itm.hasItemMeta()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Check if the item matches the id set. If not continue to next in loop.
|
//Check if the item matches the id set. If not continue to next in loop.
|
||||||
if (id != -1 && itm.getDurability() != id) {
|
if (id != -1 && itm.getDurability() != id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if noCustom is set and if the item has custom data. If so continue to next in loop.
|
|
||||||
if (noCustom && itm.hasItemMeta()) {
|
|
||||||
if (Objects.requireNonNull(itm.getItemMeta()).hasCustomModelData()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Adding item to the remove list then checking if we have reached the required amount.
|
//Adding item to the remove list then checking if we have reached the required amount.
|
||||||
ItemStack add = new ItemStack(itm.getType(), itm.getAmount(), (short) f);
|
ItemStack add = new ItemStack(itm.getType(), itm.getAmount());
|
||||||
remainingAmount -= add.getAmount();
|
remainingAmount -= add.getAmount();
|
||||||
if (removal) remCont.add(add);
|
if (removal) remCont.put(f,add);
|
||||||
if (remainingAmount <= 0) {
|
if (remainingAmount <= 0) {
|
||||||
removedItem = PaywallOutput.Passed;
|
removedItem = PaywallOutput.Passed;
|
||||||
break;
|
break;
|
||||||
@ -356,26 +319,29 @@ public class CommandTags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (remainingAmount <= 0) {
|
if (remainingAmount <= 0) {
|
||||||
for (int f = 0; f <= remCont.size() - 1; f++) {
|
for(Map.Entry<Integer, ItemStack> entry : remCont.entrySet()) {
|
||||||
ItemStack remItem = remCont.get(f);
|
ItemStack remItem = entry.getValue();
|
||||||
|
|
||||||
//Check if its the last item in the loop and only subtract the remaining amount.
|
//Check if its the last item in the loop and only subtract the remaining amount.
|
||||||
if (f == remCont.size() - 1) {
|
if (sellItem.getAmount() < remItem.getAmount()) {
|
||||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||||
if (removal)
|
if (removal)
|
||||||
p.getInventory().getItem(remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
p.getInventory().getItem(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
} else {
|
} else {
|
||||||
if (removal)
|
if (removal)
|
||||||
cont.get((int) remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
cont.get(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||||
}
|
}
|
||||||
} else { //If its anywhere but the last in loop just get rid of the items.
|
} else { //If its anywhere but the last in loop just get rid of the items.
|
||||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||||
if (removal) p.getInventory().getItem(remItem.getDurability()).setAmount(0);
|
if (removal) p.getInventory().setItem(entry.getKey(), null);
|
||||||
|
//p.getInventory().remove(entry.getValue());
|
||||||
|
//p.getInventory().getItem(entry.getKey()).setAmount(0);
|
||||||
p.updateInventory();
|
p.updateInventory();
|
||||||
} else {
|
} else {
|
||||||
if (removal) cont.get(remItem.getDurability()).setAmount(0);
|
if (removal) cont.remove(entry.getValue());
|
||||||
|
//cont.get(entry.getKey()).setAmount(0);
|
||||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user