forked from Upstream/CommandPanels
Addition of sell-all= tag Format: sell-all= <Per Item Cashback> <Item> [enchanted:KNOCKBACK:1] [potion:JUMP]
This commit is contained in:
parent
cd0db76df3
commit
49e1ae849f
@ -37,7 +37,28 @@ public class SellItemTags implements Listener {
|
|||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")).replaceAll("%cp-args%", e.args[1]));
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")).replaceAll("%cp-args%", e.args[1]));
|
||||||
} else {
|
} else {
|
||||||
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]));
|
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]));
|
||||||
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]));
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]).replaceAll("%cp-args2%", "$" + e.args[0]));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!");
|
||||||
|
}
|
||||||
|
} catch (Exception sell) {
|
||||||
|
plugin.debug(sell,e.p);
|
||||||
|
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(e.name.equalsIgnoreCase("sell-all=")){
|
||||||
|
e.commandTagUsed();
|
||||||
|
//if player uses sell-all= it will be eg. sell-all= <Per Item Cashback> <item> [enchanted:KNOCKBACK:1] [potion:JUMP]
|
||||||
|
try {
|
||||||
|
if (plugin.econ != null) {
|
||||||
|
int sold = removeAllItem(e.p, e.args);
|
||||||
|
if (sold <= 0) {
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")).replaceAll("%cp-args%", e.args[1]));
|
||||||
|
} else {
|
||||||
|
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]) * sold);
|
||||||
|
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]).replaceAll("%cp-args2%", "$" + String.valueOf(Double.parseDouble(e.args[0]) * sold)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!");
|
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!");
|
||||||
@ -157,4 +178,76 @@ public class SellItemTags implements Listener {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//returns 0 if player does not have items. Returns number of sold items.
|
||||||
|
private int removeAllItem(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])), 0);
|
||||||
|
//int RemainingAmount = sellItem.getAmount();
|
||||||
|
for (int f = 0; f < 36; f++) {
|
||||||
|
ItemStack itm = cont.get(f);
|
||||||
|
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")) {
|
||||||
|
PotionMeta potionMeta = (PotionMeta) itm.getItemMeta();
|
||||||
|
assert potionMeta != null;
|
||||||
|
if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) {
|
||||||
|
p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Your item has the wrong potion effect"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (id != -1) {
|
||||||
|
if (itm.getDurability() != id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(Exception exc){
|
||||||
|
//skip if it cannot do unless plugin.debug is enabled
|
||||||
|
plugin.debug(exc,p);
|
||||||
|
}
|
||||||
|
|
||||||
|
remCont.add(remItm);
|
||||||
|
sellItem.setAmount(sellItem.getAmount() + remItm.getAmount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sellItem.getAmount() >= 1){
|
||||||
|
for (int f = 0; f <= remCont.size() - 1; f++) {
|
||||||
|
ItemStack remItm = remCont.get(f);
|
||||||
|
|
||||||
|
if(plugin.inventorySaver.hasNormalInventory(p)){
|
||||||
|
p.getInventory().getItem((int)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])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sellItem.getAmount();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user