Adds multi-paywall

This commit is contained in:
jman13378 2023-07-11 12:37:23 -04:00
parent 840bd53d66
commit f93e126260
5 changed files with 65 additions and 40 deletions

View File

@ -142,7 +142,11 @@ public class Utils implements Listener {
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", "AIR"));
}
}
if (panel.getConfig().contains("item." + clickedSlot + section + ".multi-paywall")) {
plugin.commandTags.runMultiPaywall(panel,position,p,
panel.getConfig().getStringList("item." + clickedSlot + section + ".multi-paywall"),
commands,e.getClick());
} else
plugin.commandTags.runCommands(panel,position,p,commands,e.getClick());
}
}

View File

@ -1,7 +1,6 @@
package me.rockyhawk.commandpanels.classresources.placeholders;
import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.user.UserManager;
import com.earth2me.essentials.Essentials;
import me.realized.tokenmanager.api.TokenManager;
import me.rockyhawk.commandpanels.CommandPanels;

View File

@ -116,7 +116,7 @@ public class Commandpanelsdata implements CommandExecutor {
}
return true;
}
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpdata <set:add:get:remove:clear> <player|all> <data> [value]"));
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpdata <set:add:get:remove:clear> <player|all|online> <data> [value]"));
} else {
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
}

View File

@ -41,7 +41,7 @@ public class CommandTags {
continue;
}
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command);
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command, true);
if (val == PaywallOutput.Blocked) {
break;
}
@ -53,7 +53,7 @@ public class CommandTags {
public void runCommands(Panel panel, PanelPosition position, Player p, List<String> commands) {
for (String command : commands) {
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command);
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command, true);
if (val == PaywallOutput.Blocked) {
break;
}
@ -63,6 +63,23 @@ public class CommandTags {
}
}
public void runMultiPaywall(Panel panel, PanelPosition position, Player p, List<String> paywalls, List<String> commands, ClickType click) {
List<String> cmds = new ArrayList<String>();
for (String command : paywalls) {
PaywallOutput val = plugin.commandTags.commandPayWall(panel, p, command, false);
// Stop the for loop if 1 of the outputs is blocked
if (val == PaywallOutput.Blocked) {
break;
}
// add the paywall so it will be executed in runCommands
cmds.add(command);
}
// Add the commands last so paywalls run first
cmds.addAll(commands);
plugin.commandTags.runCommands(panel, position, p, cmds, click);
}
public void runCommand(Panel panel, PanelPosition position, Player p, String commandRAW) {
CommandTagEvent tags = new CommandTagEvent(plugin, panel, position, p, commandRAW);
Bukkit.getPluginManager().callEvent(tags);
@ -137,7 +154,7 @@ public class CommandTags {
}
@SuppressWarnings("deprecation")
public PaywallOutput commandPayWall(Panel panel, Player p, String rawCommand) { //return 0 means no funds, 1 is they passed and 2 means paywall is not this command
public PaywallOutput commandPayWall(Panel panel, Player p, String rawCommand, boolean removal) { //return 0 means no funds, 1 is they passed and 2 means paywall is not this command
//create new instance of command but with placeholders parsed
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
@ -147,8 +164,8 @@ public class CommandTags {
try {
if (plugin.econ != null) {
if (plugin.econ.getBalance(p) >= Double.parseDouble(command.split("\\s")[1])) {
plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1]));
if (plugin.config.getBoolean("purchase.currency.enable")) {
if (removal) plugin.econ.withdrawPlayer(p, Double.parseDouble(command.split("\\s")[1]));
if (plugin.config.getBoolean("purchase.currency.enable") && removal) {
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
}
return PaywallOutput.Passed;
@ -176,9 +193,9 @@ public class CommandTags {
assert api != null;
int balance = Integer.parseInt(Long.toString(api.getTokens(p).orElse(0)));
if (balance >= Double.parseDouble(command.split("\\s")[1])) {
api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
if (removal) api.removeTokens(p, Long.parseLong(command.split("\\s")[1]));
//if the message is empty don't send
if (plugin.config.getBoolean("purchase.tokens.enable")) {
if (plugin.config.getBoolean("purchase.tokens.enable") && removal) {
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
}
@ -249,7 +266,7 @@ public class CommandTags {
if (plugin.itemCreate.isIdentical(sellItem, itm)) {
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
remainingAmount -= add.getAmount();
remCont.add(add);
if (removal) remCont.add(add);
if (remainingAmount <= 0) {
removedItem = PaywallOutput.Passed;
break;
@ -265,10 +282,11 @@ public class CommandTags {
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 {
itm.setAmount(itm.getAmount() - sellItem.getAmount());
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;
@ -277,7 +295,7 @@ public class CommandTags {
if (plugin.isMMOItem(itm, 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 (removal) remCont.add(add);
if (remainingAmount <= 0) {
removedItem = PaywallOutput.Passed;
break;
@ -316,7 +334,7 @@ public class CommandTags {
//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);
remainingAmount -= add.getAmount();
remCont.add(add);
if (removal) remCont.add(add);
if (remainingAmount <= 0) {
removedItem = PaywallOutput.Passed;
break;
@ -332,23 +350,25 @@ public class CommandTags {
//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)) {
if (removal)
p.getInventory().getItem((int) remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
p.updateInventory();
} else {
if (removal)
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 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);
if (removal) p.getInventory().getItem(remItem.getDurability()).setAmount(0);
p.updateInventory();
} else {
cont.get((int)remItem.getDurability()).setAmount(0);
if (removal) 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());
if (removal) sellItem.setAmount(sellItem.getAmount() - remItem.getAmount());
}
removedItem = PaywallOutput.Passed;
@ -361,7 +381,7 @@ public class CommandTags {
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
}
} else {
if (plugin.config.getBoolean("purchase.item.enable")) {
if (plugin.config.getBoolean("purchase.item.enable") && removal) {
//item was removed
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
}
@ -384,12 +404,12 @@ public class CommandTags {
}
if (balance >= Integer.parseInt(command.split("\\s")[1])) {
if (command.split("\\s")[2].startsWith("level")) {
p.setLevel(p.getLevel() - Integer.parseInt(command.split("\\s")[1]));
if (removal) p.setLevel(p.getLevel() - Integer.parseInt(command.split("\\s")[1]));
} else {
removePlayerExp(p, Integer.parseInt(command.split("\\s")[1]));
if (removal) removePlayerExp(p, Integer.parseInt(command.split("\\s")[1]));
}
//if the message is empty don't send
if (plugin.config.getBoolean("purchase.xp.enable")) {
if (plugin.config.getBoolean("purchase.xp.enable") && removal) {
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.xp.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
}
return PaywallOutput.Passed;
@ -409,6 +429,7 @@ public class CommandTags {
//if player uses data-paywall= <data> <amount>
try {
if (Double.parseDouble(plugin.panelData.getUserData(p.getUniqueId(), command.split("\\s")[1])) >= Double.parseDouble(command.split("\\s")[2])) {
if (removal)
plugin.panelData.doDataMath(p.getUniqueId(), command.split("\\s")[1], "-" + plugin.tex.placeholdersNoColour(panel, PanelPosition.Top, p, command.split("\\s")[2]));
//if the message is empty don't send
if (plugin.config.getBoolean("purchase.data.enable")) {

View File

@ -18,8 +18,9 @@ public class DataTabComplete implements TabCompleter {
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
if(sender.hasPermission("commandpanel.data")) {
ArrayList<String> output = new ArrayList<>();
if (args.length>=1) {
if (args[0].equalsIgnoreCase("-s"))
if (args.length>=1
&& args[0].equalsIgnoreCase("-s")) {
args = Arrays.copyOfRange(args, 1, args.length);
}
if(args.length == 1){