3.9.0 Updates

This commit is contained in:
rockyhawk64 2020-08-14 21:16:08 +10:00
parent 4dfef8cb7b
commit 9cf3c060fa
6 changed files with 71 additions and 30 deletions

View File

@ -1,6 +1,6 @@
# |------------------------------------------------------------------------
# | CommandPanels Config File
# | By RockyHawk v3.0
# | By RockyHawk v4.0
# | https://www.spigotmc.org/resources/command-panels-custom-guis.67788/
# |------------------------------------------------------------------------
config:
@ -29,6 +29,6 @@ config:
needmoney: '&cInsufficient Funds!'
needitems: '&cInsufficient Items!'
bought: '&aSuccessfully Bought For $%cp-args%'
sold: '&aSuccessfully Sold For $%cp-args%'
sold: '&aSuccessfully Sold Item!'
offline: 'Offline'
offlineHeadValue: 'eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNmU1Mjg2YzQ3MGY2NmZmYTFhMTgzMzFjYmZmYjlhM2MyYTQ0MjRhOGM3MjU5YzQ0MzZmZDJlMzU1ODJhNTIyIn19fQ=='

View File

@ -1,4 +1,4 @@
version: 3.8.3
version: 3.9.0
main: me.rockyhawk.commandPanels.commandpanels
name: CommandPanels
author: RockyHawk

View File

@ -47,7 +47,6 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
@ -930,7 +929,46 @@ public class commandpanels extends JavaPlugin {
p.sendMessage(papi(p, tag + config.getString("config.format.error") + " " + "commands: " + command));
return 0;
}
} else if (command.split("\\s")[0].equalsIgnoreCase("xp-paywall=")) {
}else if (command.split("\\s")[0].equalsIgnoreCase("item-paywall=")) {
//if player uses item-paywall= [Material] [Amount]
try {
ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])),Integer.parseInt(command.split("\\s")[2]));
int sellItemAmount = sellItem.getAmount();
sellItem.setAmount(1);
int removedItem = 0;
for(ItemStack content : p.getInventory().getContents()){
int contentAmount;
try {
contentAmount = content.getAmount();
}catch(NullPointerException skip){
//item is air
continue;
}
content.setAmount(1);
if(content.isSimilar(sellItem)){
if(sellItemAmount <= contentAmount){
content.setAmount(contentAmount-sellItemAmount);
p.updateInventory();
removedItem = 1;
break;
}
}
content.setAmount(contentAmount);
}
if(removedItem == 0){
p.sendMessage(papi( tag + config.getString("config.format.needmoney")));
}else{
if(!Objects.requireNonNull(config.getString("config.format.sold")).isEmpty()) {
p.sendMessage(papi( tag + config.getString("config.format.sold")));
}
}
return removedItem;
} catch (Exception buyc) {
debug(buyc);
p.sendMessage(papi(p, tag + config.getString("config.format.error") + " " + "commands: " + command));
return 0;
}
}else if (command.split("\\s")[0].equalsIgnoreCase("xp-paywall=")) {
//if player uses xp-paywall= [price]
try {
int balance = p.getLevel();
@ -955,22 +993,32 @@ public class commandpanels extends JavaPlugin {
}
}
//look through all files in all folders
public void fileNamesFromDirectory(File directory) {
int count = 0;
for (String fileName : Objects.requireNonNull(directory.list())) {
if(new File(directory + File.separator + fileName).isDirectory()){
fileNamesFromDirectory(new File(directory + File.separator + fileName));
continue;
}
int ind = fileName.lastIndexOf(".");
if(!fileName.substring(ind).equalsIgnoreCase(".yml") && !fileName.substring(ind).equalsIgnoreCase(".yaml")){
continue;
}
panelFiles.add((directory + File.separator + fileName).replace(panelsf.toString() + File.separator,""));
for (String tempName : Objects.requireNonNull(YamlConfiguration.loadConfiguration(new File(directory + File.separator + fileName)).getConfigurationSection("panels")).getKeys(false)) {
panelNames.add(new String[]{tempName, Integer.toString(count)});
}
count += 1;
}
}
public void reloadPanelFiles() {
try {
panelFiles.clear();
panelNames.clear();
int count = 0;
for (String fileName : Objects.requireNonNull(panelsf.list())) {
int ind = fileName.lastIndexOf(".");
if(!fileName.substring(ind).equalsIgnoreCase(".yml") && !fileName.substring(ind).equalsIgnoreCase(".yaml")){
continue;
}
panelFiles.add(fileName);
for (String tempName : Objects.requireNonNull(YamlConfiguration.loadConfiguration(new File(panelsf + File.separator + fileName)).getConfigurationSection("panels")).getKeys(false)) {
panelNames.add(new String[]{tempName, Integer.toString(count)});
}
count += 1;
}
//load panel files
fileNamesFromDirectory(panelsf);
//this bit will set openWithItem to false/true upson reload
YamlConfiguration tempFile;
String tempName;
@ -1049,7 +1097,7 @@ public class commandpanels extends JavaPlugin {
public void openEditorGui(Player p, int pageChange) {
reloadPanelFiles();
Inventory i = Bukkit.createInventory((InventoryHolder) null, 54, "Command Panels Editor");
Inventory i = Bukkit.createInventory(null, 54, "Command Panels Editor");
ArrayList<String> panelNames = new ArrayList<String>(); //all panels from ALL files (panel names)
ArrayList<String> panelTitles = new ArrayList<String>(); //all panels from ALL files (panel titles)
ArrayList<Material> panelItems = new ArrayList<Material>(); //all panels from ALL files (panel materials)
@ -1138,7 +1186,7 @@ public class commandpanels extends JavaPlugin {
public void openPanelSettings(Player p, String panelName, YamlConfiguration cf) {
reloadPanelFiles();
Inventory i = Bukkit.createInventory((InventoryHolder) null, 45, "Panel Settings: " + panelName);
Inventory i = Bukkit.createInventory(null, 45, "Panel Settings: " + panelName);
List<String> lore = new ArrayList();
ItemStack temp;
//remove if the player already had a string from previously
@ -1323,7 +1371,7 @@ public class commandpanels extends JavaPlugin {
public void openItemSettings(Player p, String panelName, YamlConfiguration cf, int itemNumber) {
reloadPanelFiles();
Inventory i = Bukkit.createInventory((InventoryHolder) null, 36, "Item Settings: " + panelName);
Inventory i = Bukkit.createInventory(null, 36, "Item Settings: " + panelName);
List<String> lore = new ArrayList();
ItemStack temp;
//remove if the player already had a string from previously
@ -1960,7 +2008,7 @@ public class commandpanels extends JavaPlugin {
sender.sendMessage(papi(tag + config.getString("config.format.error") + " open-with-item: material"));
return;
}
setName(s, cf.getString("panels." + panels + ".open-with-item.name"), cf.getStringList("panels." + panels + ".open-with-item.lore"),p,true, false);
setName(s, cf.getString("panels." + panels + ".open-with-item.name"), cf.getStringList("panels." + panels + ".open-with-item.lore"),p,false, true);
//if the sender has OTHER perms, or if sendGiveMessage is false, implying it is not for another person
if(sender.hasPermission("commandpanel.other") || !sendGiveMessage) {
try {

View File

@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.*;

View File

@ -19,8 +19,8 @@ public class commandpanelsreload implements CommandExecutor {
String tag = plugin.config.getString("config.format.tag") + " ";
if (label.equalsIgnoreCase("cpr") || label.equalsIgnoreCase("commandpanelreload") || label.equalsIgnoreCase("cpanelr")) {
if (sender.hasPermission("commandpanel.reload")) {
plugin.config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "config.yml"));
plugin.reloadPanelFiles();
plugin.config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "config.yml"));
tag = plugin.config.getString("config.format.tag") + " ";
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.reload")));
return true;

View File

@ -267,19 +267,11 @@ public class utilsOpenWithItem implements Listener {
if (p.hasPermission("commandpanel.panel." + temp.getString("panels." + key + ".perm")) && temp.contains("panels." + key + ".open-with-item")) {
if(temp.contains("panels." + key + ".disabled-worlds")){
List<String> disabledWorlds = temp.getStringList("panels." + key + ".disabled-worlds");
assert disabledWorlds != null;
if(disabledWorlds.contains(p.getWorld().getName())){
continue;
}
}
ItemStack s = plugin.makeItemFromConfig(Objects.requireNonNull(temp.getConfigurationSection("panels." + key + ".open-with-item")), p, false, true);
/*ItemStack s;
try {
s = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.material")))), 1);
}catch(Exception n){
continue;
}
plugin.setName(s, temp.getString("panels." + key + ".open-with-item.name"), temp.getList("panels." + key + ".open-with-item.lore"),p,true);*/
if(temp.contains("panels." + key + ".open-with-item.stationary") && 0 <= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))) && 8 >= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary")))){
p.getInventory().setItem(Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))), s);
}