forked from Upstream/CommandPanels
Merge pull request #251 from TinyTank800/master
Changes to sell= and item-paywall=
This commit is contained in:
commit
aa8722513f
@ -27,6 +27,7 @@ import java.util.Objects;
|
||||
|
||||
public class CommandTags {
|
||||
CommandPanels plugin;
|
||||
|
||||
public CommandTags(CommandPanels pl) {
|
||||
this.plugin = pl;
|
||||
}
|
||||
@ -202,6 +203,7 @@ public class CommandTags {
|
||||
//if player uses item-paywall= [Material] [Amount] [Id]
|
||||
//player can use item-paywall= [custom-item]
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
List<ItemStack> remCont = new ArrayList<>();
|
||||
try {
|
||||
short id = 0;
|
||||
if (command.split("\\s").length == 4) {
|
||||
@ -218,6 +220,7 @@ public class CommandTags {
|
||||
//this is not a boolean because it needs to return an int
|
||||
PaywallOutput removedItem = PaywallOutput.Blocked;
|
||||
|
||||
int remainingAmount = sellItem.getAmount();
|
||||
//loop through items in the inventory
|
||||
for (int f = 0; f < 36; f++) {
|
||||
|
||||
@ -229,18 +232,10 @@ public class CommandTags {
|
||||
if (Material.matchMaterial(command.split("\\s")[1]) == null) {
|
||||
//item-paywall is a custom item as it is not a material
|
||||
if (plugin.itemCreate.isIdentical(sellItem, cont.get(f))) {
|
||||
int sellItemAmount = sellItem.getAmount();
|
||||
if(command.split("\\s").length == 3){
|
||||
sellItemAmount = Integer.parseInt(command.split("\\s")[2]);
|
||||
}
|
||||
if (sellItemAmount <= cont.get(f).getAmount()) {
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
p.getInventory().getItem(f).setAmount(cont.get(f).getAmount() - sellItemAmount);
|
||||
p.updateInventory();
|
||||
} else {
|
||||
cont.get(f).setAmount(cont.get(f).getAmount() - sellItemAmount);
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
|
||||
remainingAmount -= add.getAmount();
|
||||
remCont.add(add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
@ -264,6 +259,15 @@ public class CommandTags {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
if (plugin.isMMOItem(cont.get(f), mmoType, mmoID)) {
|
||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
|
||||
remainingAmount -= add.getAmount();
|
||||
remCont.add(add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
plugin.debug(ex, p);
|
||||
@ -272,14 +276,10 @@ public class CommandTags {
|
||||
} else {
|
||||
//if the item is a standard material
|
||||
if (cont.get(f).getType() == sellItem.getType()) {
|
||||
if (sellItem.getAmount() <= cont.get(f).getAmount()) {
|
||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
||||
p.getInventory().getItem(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
}else{
|
||||
cont.get(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount());
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f);
|
||||
remainingAmount -= add.getAmount();
|
||||
remCont.add(add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
@ -287,6 +287,34 @@ public class CommandTags {
|
||||
}
|
||||
}
|
||||
|
||||
if (remainingAmount <= 0) {
|
||||
for (int f = 0; f <= remCont.size() - 1; f++) {
|
||||
ItemStack remItem = remCont.get(f);
|
||||
|
||||
if(f == remCont.size() - 1){
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
p.getInventory().getItem((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
} else {
|
||||
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 {
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
p.getInventory().getItem(remItem.getDurability()).setAmount(0);
|
||||
p.updateInventory();
|
||||
} else {
|
||||
cont.get((int)remItem.getDurability()).setAmount(0);
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
}
|
||||
|
||||
sellItem.setAmount(sellItem.getAmount() - remItem.getAmount());
|
||||
}
|
||||
|
||||
removedItem = PaywallOutput.Passed;
|
||||
}
|
||||
|
||||
//send message and return
|
||||
if (removedItem == PaywallOutput.Blocked) {
|
||||
if (plugin.config.getBoolean("purchase.item.enable")) {
|
||||
|
@ -75,10 +75,16 @@ public class SellItemTags implements Listener {
|
||||
//returns false if player does not have item
|
||||
private boolean removeItem(Player p, String[] args){
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
List<ItemStack> remCont = new ArrayList<>();
|
||||
|
||||
|
||||
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]));
|
||||
int RemainingAmount = sellItem.getAmount();
|
||||
for (int f = 0; f < 36; f++) {
|
||||
ItemStack itm = cont.get(f);
|
||||
if (itm != null && itm.getType().equals(Material.matchMaterial(args[1]))) {
|
||||
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){
|
||||
@ -115,20 +121,37 @@ public class SellItemTags implements Listener {
|
||||
//skip if it cannot do unless plugin.debug is enabled
|
||||
plugin.debug(exc,p);
|
||||
}
|
||||
if (itm.getAmount() >= new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2])).getAmount()) {
|
||||
int amt = itm.getAmount() - new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2])).getAmount();
|
||||
itm.setAmount(amt);
|
||||
|
||||
remCont.add(remItm);
|
||||
RemainingAmount -= remItm.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
if(RemainingAmount <= 0){
|
||||
for (int f = 0; f <= remCont.size() - 1; f++) {
|
||||
ItemStack remItm = remCont.get(f);
|
||||
if(f == remCont.size() - 1){
|
||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
||||
p.getInventory().setItem(f, amt > 0 ? itm : null);
|
||||
p.getInventory().getItem((int)remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
}else{
|
||||
cont.set(f,amt > 0 ? itm : null);
|
||||
cont.get((int)remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
} else {
|
||||
if(plugin.inventorySaver.hasNormalInventory(p)){
|
||||
p.getInventory().getItem(remItm.getDurability()).setAmount(0);
|
||||
p.updateInventory();
|
||||
}else{
|
||||
cont.get((int)remItm.getDurability()).setAmount(0);
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
}
|
||||
sellItem.setAmount(sellItem.getAmount() - remItm.getAmount());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user