Merge pull request #263 from jman13378/jman13378-patch-1

Added some new features
This commit is contained in:
RockyHawk 2023-07-13 07:38:24 +10:00 committed by GitHub
commit 228ccec717
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 400 additions and 155 deletions

View File

@ -40,6 +40,18 @@ body:
attributes:
label: What CommandPanels version are you using?
options:
- latest
- 3.19.0.3
- 3.19.0.2
- 3.19.0.1
- 3.19.0.0
- 3.18.6.2
- 3.18.6.1
- 3.18.6.0
- 3.18.5.1
- 3.18.5.0
- 3.18.4.1
- 3.18.4.0
- 3.18.3.0
- 3.18.2.0
- 3.18.1.4

View File

@ -1,6 +1,6 @@
name: Need help
description: Create an issue for a problem you are having.
labels: ["help wanted"]
labels: [ "help wanted" ]
body:
- type: checkboxes
id: searched
@ -32,12 +32,24 @@ body:
- 1.18
- 1.19
validations:
required: true
required: true
- type: dropdown
id: commandpanels_version
attributes:
label: What CommandPanels version are you using?
options:
- latest
- 3.19.0.3
- 3.19.0.2
- 3.19.0.1
- 3.19.0.0
- 3.18.6.2
- 3.18.6.1
- 3.18.6.0
- 3.18.5.1
- 3.18.5.0
- 3.18.4.1
- 3.18.4.0
- 3.18.3.0
- 3.18.2.0
- 3.18.1.4
@ -64,7 +76,7 @@ body:
- 3.17.1.0
- Any other version
validations:
required: true
required: true
- type: dropdown
id: server_software
attributes:
@ -82,7 +94,7 @@ body:
- Velocity
- Travertine
validations:
required: true
required: true
- type: textarea
id: what-happened
attributes:

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
# Project exclude paths
/out/
/out/
/target/

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
</list>
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>

View File

@ -1,5 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>ADVENTURE</platformType>
<platformType>SPIGOT</platformType>
<platformType>BUKKIT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />

View File

@ -75,3 +75,7 @@ purchase:
enable: true
success: '&aSuccessfully Bought For %cp-args% Experience.'
failure: '&cInsufficient Experience!'
permission:
enable: true
success: '&aYou have successfully passed the permission check for "%cp-args%".'
failure: '&cInefficient Permissions'

View File

@ -1,4 +1,4 @@
version: 3.19.0.3
version: 3.19.0.3-DEV
main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels
author: RockyHawk

View File

@ -1,5 +1,6 @@
package me.rockyhawk.commandpanels;
import com.bencodez.votingplugin.VotingPluginHooks;
import io.lumine.mythic.lib.api.item.NBTItem;
import me.rockyhawk.commandpanels.api.CommandPanelsAPI;
import me.rockyhawk.commandpanels.api.Panel;
@ -66,6 +67,7 @@ import java.util.*;
import java.util.concurrent.Callable;
public class CommandPanels extends JavaPlugin{
public VotingPluginHooks votingPlugin;
public YamlConfiguration config;
public Economy econ = null;
public boolean openWithItem = false; //this will be true if there is a panel with open-with-item
@ -213,7 +215,10 @@ public class CommandPanels extends JavaPlugin{
if (!Bukkit.getVersion().contains("1.8")) {
this.getServer().getPluginManager().registerEvents(new SwapItemEvent(this), this);
}
//if VotingPlugin is enabled
if (getServer().getPluginManager().isPluginEnabled("VotingPlugin")) {
votingPlugin= VotingPluginHooks.getInstance();
}
//if plugin ChestSort is enabled
if(getServer().getPluginManager().isPluginEnabled("ChestSort")){
this.getServer().getPluginManager().registerEvents(new UtilsChestSortEvent(this), this);

View File

@ -142,8 +142,12 @@ public class Utils implements Listener {
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", "AIR"));
}
}
plugin.commandTags.runCommands(panel,position,p,commands,e.getClick());
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

@ -16,7 +16,6 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.*;
import java.util.stream.Collectors;
public class Placeholders {
CommandPanels plugin;

View File

@ -10,9 +10,12 @@ import org.bukkit.scheduler.BukkitRunnable;
public class CommandPanelImport implements CommandExecutor {
CommandPanels plugin;
public CommandPanelImport(CommandPanels pl) { this.plugin = pl; }
@EventHandler
public CommandPanelImport(CommandPanels pl) {
this.plugin = pl;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("commandpanel.import")) {
if (args.length == 2) {
@ -20,14 +23,14 @@ public class CommandPanelImport implements CommandExecutor {
new BukkitRunnable() {
@Override
public void run() {
plugin.downloader.downloadPanel(sender,args[1],args[0]);
plugin.downloader.downloadPanel(sender, args[1], args[0]);
plugin.reloadPanelFiles();
plugin.hotbar.reloadHotbarSlots();
}
}.run();
return true;
}
}else{
} else {
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
}
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpi <file name> <url>"));

View File

@ -3,6 +3,7 @@ package me.rockyhawk.commandpanels.commands;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -17,77 +18,97 @@ public class Commandpanel implements CommandExecutor {
this.plugin = pl;
}
@EventHandler
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
//below is going to go through the files and find the right one
Panel panel = null;
if (args.length != 0) { //check to make sure the person hasn't just left it empty
for(Panel tempPanel : plugin.panelList){
if(tempPanel.getName().equals(args[0])) {
for (Panel tempPanel : plugin.panelList) {
if (tempPanel.getName().equals(args[0])) {
panel = tempPanel;
break;
}
}
}else{
} else {
plugin.helpMessage(sender);
return true;
}
if(panel == null){
if (panel == null) {
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.nopanel")));
return true;
}
boolean disableCommand = false;
if(panel.getConfig().contains("panelType")) {
if (panel.getConfig().contains("panelType")) {
if (panel.getConfig().getStringList("panelType").contains("nocommand")) {
//do not allow command with noCommand, console is an exception
disableCommand = true;
disableCommand = true;
}
}
//below will start the command, once it got the right file and panel
if(!(sender instanceof Player)) {
if (!(sender instanceof Player)) {
//do console command
if(args.length == 2){
if(!args[1].equals("item")){
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(), PanelPosition.Top, true);
}else{
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [item] [player]"));
if (args.length == 2) {
if (!args[1].equals("item")) {
if (args[1].equalsIgnoreCase("all")) {
for (Player player : Bukkit.getOnlinePlayers())
plugin.openVoids.openCommandPanel(sender, player, panel.copy(), PanelPosition.Top, true);
} else
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(), PanelPosition.Top, true);
} else {
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [item] [player|all]"));
}
return true;
}else if(args.length == 3){
} else if (args.length == 3) {
if (args[1].equals("item")) {
plugin.openVoids.giveHotbarItem(sender,plugin.getServer().getPlayer(args[2]),panel.copy(),true);
}else{
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> item [player]"));
if (args[2].equalsIgnoreCase("all")) {
// if the argument is all open the panel for all of the players
for (Player player : Bukkit.getOnlinePlayers())
plugin.openVoids.openCommandPanel(sender, player, panel.copy(), PanelPosition.Top, true);
} else
plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), panel.copy(), true);
} else {
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> item [player|all]"));
}
return true;
} else {
sender.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Please execute command directed to a Player!"));
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Please execute command directed to a Player!"));
return true;
}
}else{
} else {
//get player
Player p = (Player) sender;
//do player command
if (args.length == 1) {
if(!disableCommand) {
plugin.openVoids.openCommandPanel(sender, p, panel.copy(),PanelPosition.Top, false);
if (!disableCommand) {
plugin.openVoids.openCommandPanel(sender, p, panel.copy(), PanelPosition.Top, false);
}
return true;
}else if(args.length == 2){
} else if (args.length == 2) {
if (args[1].equals("item")) {
plugin.openVoids.giveHotbarItem(sender, p, panel.copy(), false);
}else{
if(!disableCommand) {
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(),PanelPosition.Top, true);
} else {
if (!disableCommand) {
if (args[1].equalsIgnoreCase("all")) {
// if the argument is all open the panel for all of the players
for (Player player : Bukkit.getOnlinePlayers())
plugin.openVoids.openCommandPanel(sender, player, panel.copy(), PanelPosition.Top, true);
} else
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(), PanelPosition.Top, true);
}
}
return true;
}else if(args.length == 3){
plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), panel.copy(),true);
} else if (args.length == 3) {
if (args[2].equalsIgnoreCase("all")) {
// if the argument is all open the panel for all of the players
for (Player player : Bukkit.getOnlinePlayers())
plugin.openVoids.giveHotbarItem(sender, player, panel.copy(), true);
} else
plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), panel.copy(), true);
return true;
}
}
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [player:item] [player]"));
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [player|all:item] [player|all]"));
return true;
}
}

View File

@ -1,84 +1,123 @@
package me.rockyhawk.commandpanels.commands;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import java.util.Arrays;
public class Commandpanelsdata implements CommandExecutor {
CommandPanels plugin;
public Commandpanelsdata(CommandPanels pl) { this.plugin = pl; }
@EventHandler
public Commandpanelsdata(CommandPanels pl) {
this.plugin = pl;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("commandpanel.data")) {
boolean sendPlayerMessage = true;
//if the first argument is -s it will not send a message to the sender
if(args[0].equalsIgnoreCase("-s")){
if (args[0].equalsIgnoreCase("-s")) {
args = Arrays.copyOfRange(args, 1, args.length);
sendPlayerMessage = false;
}
if(args.length == 2){
int count = 0;
if (args.length == 2) {
//for the clear command
if(args[0].equals("clear")){
plugin.panelData.clearData(plugin.panelData.getOffline(args[1]));
if(sendPlayerMessage) {
if (args[0].equals("clear")) {
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
plugin.panelData.clearData(plugin.panelData.getOffline(player.getName()));
count++;
}
} else
plugin.panelData.clearData(plugin.panelData.getOffline(args[1]));
if (sendPlayerMessage) {
sender.sendMessage(plugin.tex.colour(plugin.tag
+ ChatColor.GREEN + "Cleared all data for "
+ ChatColor.WHITE + args[1]));
+ ChatColor.WHITE + (count == 0 ? args[1] : count + "" + ChatColor.GREEN + " players")));
}
return true;
return true;
}
}else if (args.length == 3){
} else if (args.length == 3) {
//for the remove command
if(args[0].equals("remove")) {
plugin.panelData.delUserData(plugin.panelData.getOffline(args[1]), args[2]);
if(sendPlayerMessage) {
if (args[0].equals("remove")) {
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
plugin.panelData.delUserData(plugin.panelData.getOffline(player.getName()), args[2]);
count++;
}
} else
plugin.panelData.delUserData(plugin.panelData.getOffline(args[1]), args[2]);
if (sendPlayerMessage) {
sender.sendMessage(plugin.tex.colour(plugin.tag
+ ChatColor.GREEN + "Removed "
+ ChatColor.WHITE + args[2]
+ ChatColor.GREEN + " from "
+ ChatColor.WHITE + args[1]));
+ ChatColor.WHITE + (count == 0 ? args[1] : count + "" + ChatColor.GREEN + " players")));
}
return true;
}else if(args[0].equals("get")){
return true;
} else if (args[0].equals("get")) {
//for the get command
sender.sendMessage(plugin.tex.colour(plugin.tag
+ ChatColor.GREEN + "Value of data is "
+ ChatColor.WHITE + plugin.panelData.getUserData(plugin.panelData.getOffline(args[1]), args[2])));
return true;
return true;
}
}else if (args.length == 4){
if(args[0].equals("set")){
} else if (args.length == 4) {
if (args[0].equals("set")) {
//for set command
plugin.panelData.setUserData(plugin.panelData.getOffline(args[1]), args[2],args[3],true);
if(sendPlayerMessage) {
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
plugin.panelData.setUserData(plugin.panelData.getOffline(player.getName()), args[2], args[3], true);
count++;
}
} else {
plugin.panelData.setUserData(plugin.panelData.getOffline(args[1]), args[2], args[3], true);
}
if (sendPlayerMessage) {
sender.sendMessage(plugin.tex.colour(plugin.tag
+ ChatColor.GREEN + "Set "
+ ChatColor.WHITE + args[2]
+ ChatColor.GREEN + " to "
+ ChatColor.WHITE + args[3]));
+ ChatColor.WHITE + args[3]
+ ChatColor.GREEN + " for "
+ ChatColor.WHITE + (count == 0 ? args[1] : count + "" + ChatColor.GREEN + " players")));
}
}else{
} else {
//for add command
plugin.panelData.setUserData(plugin.panelData.getOffline(args[1]), args[2],args[3],false);
if(sendPlayerMessage) {
if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("online")) {
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (args[1].equalsIgnoreCase("online") && !player.isOnline()) continue;
plugin.panelData.setUserData(plugin.panelData.getOffline(player.getName()), args[2], args[3], false);
count++;
}
} else
plugin.panelData.setUserData(plugin.panelData.getOffline(args[1]), args[2], args[3], false);
if (sendPlayerMessage) {
sender.sendMessage(plugin.tex.colour(plugin.tag
+ ChatColor.GREEN + "Set "
+ ChatColor.WHITE + args[2]
+ ChatColor.GREEN + " to "
+ ChatColor.WHITE + args[3])
+ ChatColor.GREEN + " if it did not exist already");
+ ChatColor.GREEN + " for "
+ ChatColor.WHITE + (count == 0 ? args[1] : count + "" + ChatColor.GREEN + " players")
+ " if it did not exist already");
}
}
return true;
return true;
}
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpdata <set:add:get:remove:clear> <player> <data> [value]"));
}else{
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")));
}
return true;

View File

@ -6,13 +6,12 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
public class Commandpanelsdebug implements CommandExecutor {
CommandPanels plugin;
public Commandpanelsdebug(CommandPanels pl) { this.plugin = pl; }
@EventHandler
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("commandpanel.debug")) {
if (args.length == 0) {

View File

@ -11,7 +11,7 @@ public class Commandpanelversion implements CommandExecutor {
CommandPanels plugin;
public Commandpanelversion(CommandPanels pl) { this.plugin = pl; }
@EventHandler
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (label.equalsIgnoreCase("cpv") || label.equalsIgnoreCase("commandpanelversion") || label.equalsIgnoreCase("cpanelv")) {

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;
@ -167,6 +184,22 @@ public class CommandTags {
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: " + command);
return PaywallOutput.Blocked;
}
}
case "hasperm=": {
//if player uses hasperm= [perm]
if (p.hasPermission(String.valueOf(command.split("\\s")[1]))) {
if (plugin.config.getBoolean("purchase.permission.enable") && removal) {
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.permission.success")).replaceAll("%cp-args%", command.split("\\s")[1]));
}
return PaywallOutput.Passed;
} else {
if (plugin.config.getBoolean("purchase.currency.enable")) {
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.permission.failure")));
}
return PaywallOutput.Blocked;
}
}
case "tokenpaywall=": {
//if player uses tokenpaywall= [price]
@ -176,9 +209,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]));
}
@ -209,15 +242,15 @@ public class CommandTags {
byte id = -1;
int customData = 0;
boolean noCustom = false;
for(String val : args) {
if(val.startsWith("id:")) {
for (String val : args) {
if (val.startsWith("id:")) {
id = Byte.parseByte(val.substring(3));
continue;
}
if(val.startsWith("custom-data:")) {
if (val.startsWith("custom-data:")) {
customData = Integer.parseInt(val.substring(12));
}
if(val.contains("NOCUSTOMDATA")) {
if (val.contains("NOCUSTOMDATA")) {
noCustom = true;
}
}
@ -249,7 +282,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 +298,11 @@ public class CommandTags {
if (plugin.isMMOItem(itm, mmoType, mmoID) && sellItem.getAmount() <= itm.getAmount()) {
if (plugin.inventorySaver.hasNormalInventory(p)) {
p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount());
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 +311,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;
@ -292,23 +326,23 @@ public class CommandTags {
//if the item is a standard material
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(customData != 0){
if(!itm.hasItemMeta()){
if (customData != 0) {
if (!itm.hasItemMeta()) {
continue;
}
if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){
if (Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData) {
continue;
}
}
//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;
}
//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()){
if (noCustom && itm.hasItemMeta()) {
if (Objects.requireNonNull(itm.getItemMeta()).hasCustomModelData()) {
continue;
}
}
@ -316,7 +350,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;
@ -330,25 +364,27 @@ public class CommandTags {
ItemStack remItem = remCont.get(f);
//Check if its the last item in the loop and only subtract the remaining amount.
if(f == remCont.size() - 1){
if (f == remCont.size() - 1) {
if (plugin.inventorySaver.hasNormalInventory(p)) {
p.getInventory().getItem((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
if (removal)
p.getInventory().getItem((int) remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
p.updateInventory();
} else {
cont.get((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
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 +397,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 +420,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,7 +445,8 @@ 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])) {
plugin.panelData.doDataMath(p.getUniqueId(), command.split("\\s")[1], "-" + plugin.tex.placeholdersNoColour(panel, PanelPosition.Top, p, 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")) {
plugin.tex.sendString(panel, PanelPosition.Top, p, Objects.requireNonNull(plugin.config.getString("purchase.data.success")).replaceAll("%cp-args%", command.split("\\s")[1]));

View File

@ -2,6 +2,7 @@ package me.rockyhawk.commandpanels.completetabs;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
@ -13,37 +14,63 @@ import java.util.List;
public class CpTabComplete implements TabCompleter {
CommandPanels plugin;
public CpTabComplete(CommandPanels pl) { this.plugin = pl; }
public CpTabComplete(CommandPanels pl) {
this.plugin = pl;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
if(sender instanceof Player && args.length == 1){
Player p = ((Player) sender).getPlayer();
if(label.equalsIgnoreCase("cp") || label.equalsIgnoreCase("cpanel") || label.equalsIgnoreCase("commandpanel")){
ArrayList<String> apanels = new ArrayList<String>(); //all panels
for(Panel panel : plugin.panelList) { //will loop through all the files in folder
try {
if (!panel.getName().startsWith(args[0])) {
//this will narrow down the panels to what the user types
continue;
}
if (sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) {
if(panel.getConfig().contains("panelType")) {
if (panel.getConfig().getStringList("panelType").contains("nocommand")) {
//do not allow command with nocommand
continue;
if (sender instanceof Player && args.length >= 1)
if (label.equalsIgnoreCase("cp") || label.equalsIgnoreCase("cpanel") || label.equalsIgnoreCase("commandpanel")) {
Player p = ((Player) sender).getPlayer();
if (args.length == 1) {
ArrayList<String> apanels = new ArrayList<String>(); //all panels
for (Panel panel : plugin.panelList) { //will loop through all the files in folder
try {
if (!panel.getName().startsWith(args[0])) {
//this will narrow down the panels to what the user types
continue;
}
if (sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) {
if (panel.getConfig().contains("panelType")) {
if (panel.getConfig().getStringList("panelType").contains("nocommand")) {
//do not allow command with nocommand
continue;
}
}
if (plugin.panelPerms.isPanelWorldEnabled(p, panel.getConfig())) {
apanels.add(panel.getName());
}
}
if(plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
apanels.add(panel.getName());
}
} catch (Exception skip) {
//ignore panel
}
}catch(Exception skip){
//ignore panel
}
return apanels;
}
return apanels;
if (args.length == 2 || args.length == 3) {
List<String> aplayers = new ArrayList<>();
if ("all".startsWith(args[(args.length == 2 ? 1 : 2)].toLowerCase())) aplayers.add("all");
if (args.length == 2 && "item".startsWith(args[1].toLowerCase())) aplayers.add("item");
for (Player player : Bukkit.getOnlinePlayers()) {
String name = player.getName();
if (name.toLowerCase().startsWith(args[(args.length == 2 ? 1 : 2)])) {
//this will narrow down the panels to what the user types
aplayers.add(name);
}
}
return aplayers;
}
}
}
return null;
}
}

View File

@ -2,13 +2,13 @@ package me.rockyhawk.commandpanels.completetabs;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
public class DataTabComplete implements TabCompleter {
@ -18,25 +18,50 @@ 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 && args[0].equalsIgnoreCase("-s")) {
args = Arrays.copyOfRange(args, 1, args.length);
}
if(args.length == 1){
output.add("set");
output.add("add");
output.add("get");
output.add("remove");
output.add("clear");
String arg1 = args[0].toLowerCase();
if ("set".startsWith(arg1))output.add("set");
if ("add".startsWith(arg1))output.add("add");
if ("get".startsWith(arg1))output.add("get");
if ("remove".startsWith(arg1))output.add("remove");
if ("clear".startsWith(arg1))output.add("clear");
}else if(args.length == 2){
for (Player p : Bukkit.getOnlinePlayers()) {
if (!p.getName().startsWith(args[1])) {
continue;
if ("all".startsWith(args[1].toLowerCase()) && !args[0].equalsIgnoreCase("get")) output.add("all");
if ("online".startsWith(args[1].toLowerCase()) && !args[0].equalsIgnoreCase("get")) output.add("online");
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
String name = player.getName();
// don't worry about it saying it may throw a NPE
if (name.toLowerCase().startsWith(args[1].toLowerCase())) {
//this will narrow down the panels to what the user types
output.add(name);
}
output.add(p.getName());
}
}else if(args.length == 3){
if (!args[0].equalsIgnoreCase("remove")) return new ArrayList<>();
//the clear function is here as it is the only subcommand with 3 args
try {
return new ArrayList<>(plugin.panelData.dataConfig.getConfigurationSection("playerData." + plugin.panelData.getOffline(args[1])).getKeys(false));
if (!args[1].equalsIgnoreCase("all") && !args[1].equalsIgnoreCase("online"))
return new ArrayList<>(plugin.panelData.dataConfig.getConfigurationSection("playerData." + plugin.panelData.getOffline(args[1])).getKeys(false));
else {
Set<String> set = new HashSet<>();
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
if (!player.isOnline()&&args[1].equalsIgnoreCase("online")) continue;
set.addAll(plugin.panelData.dataConfig.getConfigurationSection("playerData." + plugin.panelData.getOffline(player.getName())).getKeys(false));
}
String[] finalArgs = args;
set.removeIf(s -> !s.toLowerCase().startsWith(finalArgs[2]));
return new ArrayList<>(set);
}
} catch (Exception ex) {
return null;
return new ArrayList<>();
}
}
return output;

View File

@ -24,7 +24,7 @@ public class CommandPanelsEditor implements CommandExecutor {
this.plugin = pl;
}
@EventHandler
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("commandpanel.edit")) {
if (!(sender instanceof Player)) {

View File

@ -1,8 +1,13 @@
package me.rockyhawk.commandpanels.editor;
import me.rockyhawk.commandpanels.CommandPanels;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.*;
import java.net.URL;
@ -13,19 +18,23 @@ import java.util.logging.Level;
public class PanelDownloader {
CommandPanels plugin;
public PanelDownloader(CommandPanels pl) { this.plugin = pl; }
public PanelDownloader(CommandPanels pl) {
this.plugin = pl;
}
public void downloadPanel(CommandSender sender, String url, String fileName) {
BufferedInputStream in = null;
FileOutputStream fout = null;
//add extension if not already added
if(!fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) {
if (!fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) {
fileName = fileName + ".yml";
}
//Check if fileName contains file://
try {
if(URLDecoder.decode(url, StandardCharsets.UTF_8.toString()).contains("file://")) {
if (URLDecoder.decode(url, StandardCharsets.UTF_8.toString()).contains("file://")) {
sender.sendMessage(plugin.tag + ChatColor.RED + "Invalid URL. Using file:// is not supported.");
return;
}
@ -55,10 +64,32 @@ public class PanelDownloader {
byte[] data = new byte[1024];
int count;
while((count = in.read(data, 0, 1024)) != -1) {
while ((count = in.read(data, 0, 1024)) != -1) {
fout.write(data, 0, count);
}
sender.sendMessage(plugin.tag + ChatColor.GREEN + "Finished downloading.");
if (sender instanceof Player) {
YamlConfiguration panels = YamlConfiguration.loadConfiguration(file);
if (panels.getConfigurationSection("panels").getKeys(false).size()>1) {
sender.sendMessage(plugin.tag + ChatColor.GREEN + "Finished downloading," +
ChatColor.UNDERLINE +ChatColor.YELLOW+ " Panel '" + fileName + "'");
} else {
BaseComponent[] components = new ComponentBuilder(plugin.tag +
net.md_5.bungee.api.ChatColor.GREEN + "Finished downloading, " +
ChatColor.UNDERLINE + "Panel '" + fileName + "'.\n" +
ChatColor.YELLOW + ChatColor.UNDERLINE + " Click Here to open the panel.")
.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/cp " +
panels.getConfigurationSection("panels").getKeys(false).toArray()[0]))
.create();
Player player =(Player) sender;
player.spigot().sendMessage(components);
}
} else {
sender.sendMessage(plugin.tag + ChatColor.GREEN + "Finished downloading, " +
ChatColor.UNDERLINE +ChatColor.YELLOW+ "Panel '" + fileName + "'");
}
} catch (Exception var22) {
sender.sendMessage(plugin.tag + ChatColor.RED + "Could not download panel.");
} finally {

View File

@ -15,19 +15,29 @@ public class OpenOnJoin implements Listener {
}
@EventHandler
public void onWorldLogin(PlayerJoinEvent e){
//only opens when the player first logins
openOnJoin(e.getPlayer(),"open-on-login.");
if (!e.getPlayer().hasPlayedBefore()) {
openOnJoin(e.getPlayer(),"open-on-first-login");
return;
}
//only opens when the player logs into the server
openOnJoin(e.getPlayer(),"open-on-login");
}
@EventHandler
public void onWorldJoin(PlayerChangedWorldEvent e){
//only opens when the player changes the world internally
openOnJoin(e.getPlayer(),"open-on-join.");
openOnJoin(e.getPlayer(),"open-on-join");
}
private void openOnJoin(Player p, String joinType){
if(plugin.config.contains(joinType + p.getWorld().getName())){
String command = "open= " + plugin.config.getString(joinType + p.getWorld().getName());
String world = p.getWorld().getName();
// Limited to '1' panel as you can only have '1' inventory open
// pass the world as "" to tell the code to not use world
if (joinType.equalsIgnoreCase("open-on-first-login")) world="";
String joinString = joinType + (world.equals("") ? "" : "."+ world);
if(plugin.config.contains(joinString)){
String command = "open= " + plugin.config.getString(joinString);
plugin.commandTags.runCommand(null, PanelPosition.Top,p, command);
}
}