This commit is contained in:
rockyhawk64 2021-09-06 12:48:25 +10:00
parent bbb7f0bf55
commit 64211d80be
10 changed files with 230 additions and 113 deletions

View File

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

View File

@ -5,6 +5,7 @@ import me.rockyhawk.commandpanels.api.CommandPanelsAPI;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.classresources.ExecuteOpenVoids;
import me.rockyhawk.commandpanels.classresources.GetCustomHeads;
import me.rockyhawk.commandpanels.classresources.HasSections;
import me.rockyhawk.commandpanels.classresources.ItemCreation;
import me.rockyhawk.commandpanels.classresources.placeholders.expansion.CpPlaceholderExpansion;
import me.rockyhawk.commandpanels.completetabs.DataTabComplete;
@ -91,6 +92,7 @@ public class CommandPanels extends JavaPlugin{
public OpenEditorGuis editorGuis = new OpenEditorGuis(this);
public ExecuteOpenVoids openVoids = new ExecuteOpenVoids(this);
public ItemCreation itemCreate = new ItemCreation(this);
public HasSections has = new HasSections(this);
public GetCustomHeads customHeads = new GetCustomHeads(this);
public Updater updater = new Updater(this);
public PlayerHeads getHeads = new PlayerHeads(this);

View File

@ -100,7 +100,7 @@ public class Utils implements Listener {
}
//get the section of the slot that was clicked
String section = plugin.itemCreate.hasSection(panel,position,panel.getConfig().getConfigurationSection("item." + clickedSlot), p);
String section = plugin.has.hasSection(panel,position,panel.getConfig().getConfigurationSection("item." + clickedSlot), p);
if(panel.getConfig().contains("item." + clickedSlot + section + ".itemType")){
if(panel.getConfig().getStringList("item." + clickedSlot + section + ".itemType").contains("placeable")){
@ -116,7 +116,7 @@ public class Utils implements Listener {
//if an item has an area for input instead of commands
if(panel.getConfig().contains("item." + clickedSlot + section + ".player-input")) {
plugin.inputUtils.playerInput.put(p,new PlayerInput(panel,panel.getConfig().getStringList("item." + clickedSlot + section + ".player-input")));
plugin.inputUtils.playerInput.put(p,new PlayerInput(panel,panel.getConfig().getStringList("item." + clickedSlot + section + ".player-input"),e.getClick()));
plugin.inputUtils.sendMessage(panel,position,p);
}

View File

@ -71,13 +71,13 @@ public class Panel{
}
public ItemStack getItem(Player p, int slot){
String section = plugin.itemCreate.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("item." + slot), p);
String section = plugin.has.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("item." + slot), p);
ConfigurationSection itemSection = panelConfig.getConfigurationSection("item." + slot + section);
return plugin.itemCreate.makeItemFromConfig(this,PanelPosition.Top,itemSection, p, true, true, false);
}
public ItemStack getCustomItem(Player p, String itemName){
String section = plugin.itemCreate.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("custom-item." + itemName), p);
String section = plugin.has.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("custom-item." + itemName), p);
ConfigurationSection itemSection = panelConfig.getConfigurationSection("custom-item." + itemName + section);
return plugin.itemCreate.makeCustomItemFromConfig(this,PanelPosition.Top,itemSection, p, true, true, false);
}
@ -91,7 +91,7 @@ public class Panel{
return plugin.nbt.setNBT(s,"CommandPanelsHotbar",panelName + ":" + slot);
}
public ConfigurationSection getHotbarSection(Player p){
String section = plugin.itemCreate.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("open-with-item"), p);
String section = plugin.has.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("open-with-item"), p);
return panelConfig.getConfigurationSection("open-with-item" + section);
}

View File

@ -0,0 +1,119 @@
package me.rockyhawk.commandpanels.classresources;
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.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
public class HasSections {
CommandPanels plugin;
public HasSections(CommandPanels pl) {
plugin = pl;
}
public String hasSection(Panel panel, PanelPosition position, ConfigurationSection cf, Player p){
for (int count = 0; cf.getKeys(false).size() > count; count++) {
boolean outputValue = true;
String setName;
if(cf.isSet("has" + count)) {
setName = "has" + count;
}else if(cf.isSet("hasperm" + count)) {
setName = "hasperm" + count;
}else if(cf.isSet("hasvalue" + count)) {
setName = "hasvalue" + count;
}else if(cf.isSet("hasgreater" + count)) {
setName = "hasgreater" + count;
}else{
continue;
}
if(cf.contains(setName + ".output")) {
//if output is true, and values match it will be this item, vice versa
outputValue = cf.getBoolean(setName + ".output");
}
//loop through possible values and compares for hypothetical and operators
for (int a = 0; cf.getConfigurationSection(setName).getKeys(false).size() > a; a++) {
if(cf.isSet(setName + ".value" + a) && cf.isSet(setName + ".compare" + a)){
//get the values of this statement
String value = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, cf.getString(setName + ".value" + a)));
String compare = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, cf.getString(setName + ".compare" + a)));
String operator = "AND";
if(compare.endsWith(" OR")){
compare = compare.substring(0, compare.length()-3);
operator = "OR";
}else if(compare.endsWith(" AND")){
compare = compare.substring(0, compare.length()-4);
}
//list of values with the or operator
HashSet<String> values = doOperators(new HashSet<>(Collections.singletonList(value)));
//go through all values with the or operator
boolean endProcess = true;
for(String val : values){
if (hasProcess(setName, val, compare, p, outputValue)) {
endProcess = false;
//if it is true and it is OR, there is no need to check the next value in the line
if(operator.equals("OR")){
a++;
}
}
}
if(endProcess){
//check if the operator link between the next value/compare is OR
if(operator.equals("OR")){
//I can just continue because the algorithm already assumes the last sequence was true
continue;
}
return "";
}
}
}
//proceed if none of the values were false
return "." + setName + hasSection(panel, position, cf.getConfigurationSection(setName), p);
}
return "";
}
private HashSet<String> doOperators(HashSet<String> value){
for(String val : value){
if(val.contains(" OR ")){
value.remove(val);
value.addAll(Arrays.asList(val.split(" OR ")));
return doOperators(value);
}
}
return value;
}
private boolean hasProcess(String setName, String value, String compare,Player p, boolean outputValue){
//the original has sections as TinyTank800 wanted to keep them
if(setName.startsWith("hasvalue")) {
return compare.equals(value) == outputValue;
}
if(setName.startsWith("hasperm")) {
return p.hasPermission(value) == outputValue;
}
if(setName.startsWith("hasgreater")) {
return (Long.parseLong(compare) >= Long.parseLong(value)) == outputValue;
}
//the current has section with all of the functions implemented inside it
if(setName.startsWith("has")) {
if(value.endsWith(" HASPERM")) {
return Bukkit.getPlayer(value.substring(0, value.length()-8)).hasPermission(compare) == outputValue;
}else if(value.endsWith(" ISGREATER")) {
return (Long.parseLong(compare) <= Long.parseLong(value.substring(0, value.length()-10))) == outputValue;
}else{
return compare.equals(value) == outputValue;
}
}
return false;
}
}

View File

@ -379,115 +379,13 @@ public class ItemCreation {
//do custom-item items, they have an additional hasSection requirement
public ItemStack makeCustomItemFromConfig(Panel panel,PanelPosition position, ConfigurationSection itemSection, Player p, boolean placeholders, boolean colours, boolean addNBT){
String section = plugin.itemCreate.hasSection(panel,position,itemSection,p);
String section = plugin.has.hasSection(panel,position,itemSection,p);
if(!section.equals("")){
itemSection = itemSection.getConfigurationSection(section.substring(1));
}
return plugin.itemCreate.makeItemFromConfig(panel,position,itemSection, p, placeholders, colours, addNBT);
}
//hasperm hasvalue, etc sections will be done here
public String hasSection(Panel panel,PanelPosition position, ConfigurationSection cf, Player p){
if (cf.isSet("hasvalue")) {
//this will do the hasvalue without any numbers
boolean outputValue = true;
//outputValue will default to true
if (cf.contains("hasvalue.output")) {
//if output is true, and values match it will be this item, vice versa
outputValue = cf.getBoolean("hasvalue.output");
}
String value = ChatColor.stripColor(plugin.tex.placeholders(panel,position,p,cf.getString("hasvalue.value")));
String compare = ChatColor.stripColor(plugin.tex.placeholders(panel,position,p,cf.getString("hasvalue.compare")));
if (compare.equals(value) == outputValue) {
//onOpen being 3 means it is the editor panel.. hasvalue items cannot be included to avoid item breaking
String section = hasSection(panel,position,Objects.requireNonNull(cf.getConfigurationSection("hasvalue")), p);
//string section, it executes itself to check for subsections
return ".hasvalue" + section;
}
//loop through possible hasvalue 1,2,3,etc
for (int count = 0; cf.getKeys(false).size() > count; count++) {
if (cf.contains("hasvalue" + count)) {
outputValue = true;
//outputValue will default to true
if (cf.contains("hasvalue" + count + ".output")) {
//if output is true, and values match it will be this item, vice versa
outputValue = cf.getBoolean("hasvalue" + count + ".output");
}
value = ChatColor.stripColor(plugin.tex.placeholders(panel,position,p,cf.getString("hasvalue" + count + ".value")));
compare = ChatColor.stripColor(plugin.tex.placeholders(panel,position,p,cf.getString("hasvalue" + count + ".compare")));
if (compare.equals(value) == outputValue) {
//onOpen being 3 means it is the editor panel.. hasvalue items cannot be included to avoid item breaking
String section = hasSection(panel,position,Objects.requireNonNull(cf.getConfigurationSection("hasvalue" + count)), p);
//string section, it executes itself to check for subsections
return ".hasvalue" + count + section;
}
}
}
}
if (cf.isSet("hasgreater")) {
//this will do the hasgreater without any numbers
boolean outputValue = true;
//outputValue will default to true
if (cf.contains("hasgreater.output")) {
//if output is true, and values match it will be this item, vice versa
outputValue = cf.getBoolean("hasgreater.output");
}
double value = Double.parseDouble(ChatColor.stripColor(plugin.tex.placeholdersNoColour(panel,position,p,cf.getString("hasgreater.value"))));
double compare = Double.parseDouble(ChatColor.stripColor(plugin.tex.placeholdersNoColour(panel,position,p,cf.getString("hasgreater.compare"))));
if ((compare >= value) == outputValue) {
//onOpen being 3 means it is the editor panel.. hasgreater items cannot be included to avoid item breaking
String section = hasSection(panel,position,Objects.requireNonNull(cf.getConfigurationSection("hasgreater")), p);
return ".hasgreater" + section;
}
//loop through possible hasgreater 1,2,3,etc
for (int count = 0; cf.getKeys(false).size() > count; count++) {
if (cf.contains("hasgreater" + count)) {
outputValue = true;
//outputValue will default to true
if (cf.contains("hasgreater" + count + ".output")) {
//if output is true, and values match it will be this item, vice versa
outputValue = cf.getBoolean("hasgreater" + count + ".output");
}
value = Double.parseDouble(ChatColor.stripColor(plugin.tex.placeholdersNoColour(panel,position,p,cf.getString("hasgreater" + count + ".value"))));
compare = Double.parseDouble(ChatColor.stripColor(plugin.tex.placeholdersNoColour(panel,position,p,cf.getString("hasgreater" + count + ".compare"))));
if ((compare >= value) == outputValue) {
//onOpen being 3 means it is the editor panel.. hasgreater items cannot be included to avoid item breaking
String section = hasSection(panel,position,Objects.requireNonNull(cf.getConfigurationSection("hasgreater" + count)), p);
return ".hasgreater" + count + section;
}
}
}
}
if (cf.isSet("hasperm")) {
//this will do hasperm with no numbers
boolean outputValue = true;
//outputValue will default to true
if (cf.contains("hasperm.output")) {
//if output is true, and values match it will be this item, vice versa
outputValue = cf.getBoolean("hasperm.output");
}
if (p.hasPermission(Objects.requireNonNull(cf.getString("hasperm.perm"))) == outputValue) {
String section = hasSection(panel,position,Objects.requireNonNull(cf.getConfigurationSection("hasperm")), p);
return ".hasperm" + section;
}
for(int count = 0; cf.getKeys(false).size() > count; count++){
if (cf.contains("hasperm" + count) && cf.contains("hasperm" + count + ".perm")) {
outputValue = true;
//outputValue will default to true
if (cf.contains("hasperm" + count + ".output")) {
//if output is true, and values match it will be this item, vice versa
outputValue = cf.getBoolean("hasperm" + count + ".output");
}
if (p.hasPermission(Objects.requireNonNull(cf.getString("hasperm" + count + ".perm"))) == outputValue) {
String section = hasSection(panel,position,Objects.requireNonNull(cf.getConfigurationSection("hasperm" + count)), p);
return ".hasperm" + count + section;
}
}
}
}
return "";
}
@SuppressWarnings("deprecation")
public YamlConfiguration generatePanelFile(String panelName, Inventory inv, YamlConfiguration file){
ItemStack cont;
@ -538,7 +436,7 @@ public class ItemCreation {
BannerMeta bannerMeta = (BannerMeta) cont.getItemMeta();
List<String> dyePattern = new ArrayList<>();
for(Pattern pattern : bannerMeta.getPatterns()) { //sublist to skip first value
dyePattern.add(pattern.getColor().toString() + "," + pattern.getPattern().toString());
dyePattern.add(pattern.getColor() + "," + pattern.getPattern());
}
file.set("panels." + panelName + ".item." + i + ".banner", dyePattern);
}catch(Exception ignore){

View File

@ -1,13 +1,20 @@
package me.rockyhawk.commandpanels.commands;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class Commandpanelsdebug implements CommandExecutor {
CommandPanels plugin;
public Commandpanelsdebug(CommandPanels pl) { this.plugin = pl; }
@ -32,6 +39,21 @@ public class Commandpanelsdebug implements CommandExecutor {
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.GREEN + "Personal Debug Mode Enabled!"));
}
}else{
//START
if(args.length == 1) {
if(args[0].equals("converteverything")){
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.GREEN + "Converting Everything"));
for(Panel panel : plugin.panelList){
convertPanel(panel.getName(), sender);
}
return true;
}
//temporary panel converter from 3.16.x.x to 3.17.x.x
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.GREEN + "Converting panel " + args[0]));
convertPanel(args[0], sender);
return true;
}
//END
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpd"));
}
}else{
@ -39,4 +61,77 @@ public class Commandpanelsdebug implements CommandExecutor {
}
return true;
}
//temporary converter
public void convertPanel(String name, CommandSender sender){
Panel panel = null;
for(Panel pan : plugin.panelList){
if(pan.getName().equals(name)){
panel = pan;
}
}
if(panel == null){
return;
}
Map<String,Object> oldKeys = panel.getConfig().getValues(true);
Map<String,Object> newKeys = new HashMap<>();
for(Map.Entry<String,Object> key : oldKeys.entrySet()){
ArrayList<String> newKey = new ArrayList<>();
String[] subKeys = key.getKey().split("\\.");
for(String subKey : subKeys){
if(subKey.startsWith("hasvalue")){
newKey.add(addNumber("hasvalue",subKey));
continue;
}
if(subKey.startsWith("hasperm")){
newKey.add(addNumber("hasperm",subKey));
continue;
}
if(subKey.equals("perm")){
if(subKeys.length != 1) {
newKey.add("value0");
continue;
}
}
if(subKey.startsWith("hasgreater")){
newKey.add(addNumber("hasgreater",subKey));
continue;
}
if(subKey.equals("value")){
newKey.add("value0");
continue;
}
if(subKey.equals("compare")){
newKey.add("compare0");
continue;
}
newKey.add(subKey);
}
newKeys.put(String.join(".", newKey),key.getValue());
}
YamlConfiguration newConfig = new YamlConfiguration();
if(new File(panel.getFile().getPath().replaceFirst("panels","CONVERTED_PANELS")).exists()){
newConfig = YamlConfiguration.loadConfiguration(new File(panel.getFile().getPath().replaceFirst("panels","CONVERTED_PANELS")));
}
for(Map.Entry<String,Object> key : newKeys.entrySet()){
if(key.getValue() instanceof ConfigurationSection){
continue;
}
newConfig.set("panels." + panel.getName() + "." + key.getKey(),key.getValue());
}
try {
newConfig.save(new File(panel.getFile().getPath().replaceFirst("panels","CONVERTED_PANELS")));
sender.sendMessage(ChatColor.WHITE + panel.getFile().getName() + ChatColor.GREEN + " File saved to the CommandPanels plugin folder, please check it is correct before overwriting it.");
} catch (IOException s) {
plugin.debug(s,null);
}
}
public String addNumber(String word,String str){
if(str.equals(word)){
return (str + "0");
}
int number = Integer.parseInt(str.replace(word,""));
number += 1;
return (word + number);
}
}

View File

@ -1,15 +1,18 @@
package me.rockyhawk.commandpanels.interactives.input;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.event.inventory.ClickType;
import java.util.List;
public class PlayerInput {
public Panel panel;
public ClickType click;
public List<String> commands;
public PlayerInput(Panel panel1, List<String> commands1){
public PlayerInput(Panel panel1, List<String> commands1, ClickType click1){
panel = panel1;
click = click1;
commands = commands1;
}
}

View File

@ -42,7 +42,7 @@ public class UserInputUtils implements Listener {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
plugin.commandTags.runCommands(playerInput.get(e.getPlayer()).panel, PanelPosition.Top,e.getPlayer(), playerInput.get(e.getPlayer()).commands); //I have to do this to run regular Bukkit voids in an ASYNC Event
plugin.commandTags.runCommands(playerInput.get(e.getPlayer()).panel, PanelPosition.Top,e.getPlayer(), playerInput.get(e.getPlayer()).commands,playerInput.get(e.getPlayer()).click); //I have to do this to run regular Bukkit voids in an ASYNC Event
playerInput.remove(e.getPlayer());
}
});

View File

@ -58,7 +58,7 @@ public class OpenGUI {
String section = "";
//openType needs to not be 3 so the editor won't include hasperm and hasvalue, etc items
if (openType != PanelOpenType.Editor) {
section = plugin.itemCreate.hasSection(panel,position,pconfig.getConfigurationSection("item." + Integer.parseInt(item)), p);
section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + Integer.parseInt(item)), p);
//This section is for animations below here: VISUAL ONLY
//check for if there is animations inside the items section