Changes to item-paywall= and sell=

Added the ability to sell= and item-paywall= items at an amount over 64.
This commit is contained in:
TinyTank800 2023-03-27 22:49:00 -07:00 committed by GitHub
parent 1738be4950
commit a68176e83c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 157 additions and 106 deletions

View File

@ -27,6 +27,7 @@ import java.util.Objects;
public class CommandTags { public class CommandTags {
CommandPanels plugin; CommandPanels plugin;
public CommandTags(CommandPanels pl) { public CommandTags(CommandPanels pl) {
this.plugin = pl; this.plugin = pl;
} }
@ -202,6 +203,7 @@ public class CommandTags {
//if player uses item-paywall= [Material] [Amount] [Id] //if player uses item-paywall= [Material] [Amount] [Id]
//player can use item-paywall= [custom-item] //player can use item-paywall= [custom-item]
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<>();
try { try {
short id = 0; short id = 0;
if (command.split("\\s").length == 4) { 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 //this is not a boolean because it needs to return an int
PaywallOutput removedItem = PaywallOutput.Blocked; PaywallOutput removedItem = PaywallOutput.Blocked;
int remainingAmount = sellItem.getAmount();
//loop through items in the inventory //loop through items in the inventory
for (int f = 0; f < 36; f++) { for (int f = 0; f < 36; f++) {
@ -229,18 +232,10 @@ public class CommandTags {
if (Material.matchMaterial(command.split("\\s")[1]) == null) { if (Material.matchMaterial(command.split("\\s")[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, cont.get(f))) { if (plugin.itemCreate.isIdentical(sellItem, cont.get(f))) {
int sellItemAmount = sellItem.getAmount(); ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
if(command.split("\\s").length == 3){ remainingAmount -= add.getAmount();
sellItemAmount = Integer.parseInt(command.split("\\s")[2]); remCont.add(add);
} if (remainingAmount <= 0) {
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])));
}
removedItem = PaywallOutput.Passed; removedItem = PaywallOutput.Passed;
break; break;
} }
@ -264,6 +259,15 @@ public class CommandTags {
removedItem = PaywallOutput.Passed; removedItem = PaywallOutput.Passed;
break; 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) { } catch (Exception ex) {
plugin.debug(ex, p); plugin.debug(ex, p);
@ -272,14 +276,10 @@ public class CommandTags {
} else { } else {
//if the item is a standard material //if the item is a standard material
if (cont.get(f).getType() == sellItem.getType()) { if (cont.get(f).getType() == sellItem.getType()) {
if (sellItem.getAmount() <= cont.get(f).getAmount()) { ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f);
if(plugin.inventorySaver.hasNormalInventory(p)){ remainingAmount -= add.getAmount();
p.getInventory().getItem(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount()); remCont.add(add);
p.updateInventory(); if (remainingAmount <= 0) {
}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])));
}
removedItem = PaywallOutput.Passed; removedItem = PaywallOutput.Passed;
break; 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 //send message and return
if (removedItem == PaywallOutput.Blocked) { if (removedItem == PaywallOutput.Blocked) {
if (plugin.config.getBoolean("purchase.item.enable")) { if (plugin.config.getBoolean("purchase.item.enable")) {

View File

@ -75,10 +75,16 @@ public class SellItemTags implements Listener {
//returns false if player does not have item //returns false if player does not have item
private boolean removeItem(Player p, String[] args){ private boolean removeItem(Player p, String[] args){
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<>();
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++) { for (int f = 0; f < 36; f++) {
ItemStack itm = cont.get(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 //determine if the command contains parameters for extensions
String potion = "false"; String potion = "false";
for(String argsTemp : args){ for(String argsTemp : args){
@ -115,20 +121,37 @@ public class SellItemTags implements Listener {
//skip if it cannot do unless plugin.debug is enabled //skip if it cannot do unless plugin.debug is enabled
plugin.debug(exc,p); 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(); remCont.add(remItm);
itm.setAmount(amt); 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)){ 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(); p.updateInventory();
}else{ }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]))); 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 true;
} }
}
}
return false; return false;
} }
} }