3.10.2 Fixes

This commit is contained in:
rockyhawk64 2020-08-29 18:03:42 +10:00
parent b1b5248249
commit d35e45ea3e
6 changed files with 32 additions and 49 deletions

View File

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

View File

@ -1067,7 +1067,7 @@ public class commandpanels extends JavaPlugin {
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)
ArrayList<ItemStack> panelItems = new ArrayList<ItemStack>(); //all panels from ALL files (panel materials)
try {
for(String fileName : panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(panelsf + File.separator + fileName));
@ -1080,9 +1080,9 @@ public class commandpanels extends JavaPlugin {
panelNames.add(papi( key));
panelTitles.add(papi( Objects.requireNonNull(temp.getString("panels." + key + ".title"))));
if (temp.contains("panels." + key + ".open-with-item.material")) {
panelItems.add(Material.matchMaterial(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.material"))));
panelItems.add(makeItemFromConfig(temp.getConfigurationSection("panels." + key + ".open-with-item"), p, false, true));
} else {
panelItems.add(Material.FILLED_MAP);
panelItems.add(new ItemStack(Material.FILLED_MAP));
}
}
}
@ -1141,8 +1141,8 @@ public class commandpanels extends JavaPlugin {
for (String panelName : panelNames) {
//count is +1 because count starts at 0 not 1
if ((pageNumber * 45 - 45) < (count + 1) && (pageNumber * 45) > (count)) {
temp = new ItemStack(panelItems.get(count), 1);
setName(temp, ChatColor.WHITE + panelName, null, p, true, true);
temp = panelItems.get(count);
setName(temp, ChatColor.WHITE + panelName, null, p, false, true);
i.setItem(slot, temp);
slot += 1;
}
@ -1266,7 +1266,7 @@ public class commandpanels extends JavaPlugin {
if(cf.contains("panels." + panelName + ".open-with-item.material")){
hotbarItems = true;
temp = new ItemStack((Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(cf.getString("panels." + panelName + ".open-with-item.material"))))), 1);
temp = makeItemFromConfig(cf.getConfigurationSection("panels." + panelName + ".open-with-item"), p, false, true);
}else{
temp = new ItemStack(Material.REDSTONE_BLOCK, 1);
}

View File

@ -9,6 +9,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import java.io.File;
import java.io.IOException;
public class commandpanelsreload implements CommandExecutor {
commandpanels plugin;
@ -20,6 +21,11 @@ public class commandpanelsreload implements CommandExecutor {
if (label.equalsIgnoreCase("cpr") || label.equalsIgnoreCase("commandpanelreload") || label.equalsIgnoreCase("cpanelr")) {
if (sender.hasPermission("commandpanel.reload")) {
plugin.reloadPanelFiles();
try {
YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "temp.yml")).save(new File(plugin.getDataFolder() + File.separator + "temp.yml"));
} catch (IOException e) {
//skip clearing temp
}
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")));

View File

@ -249,13 +249,12 @@ public class editorUserInput implements Listener {
plugin.reloadPanelFiles();
break;
}
Material temp = Material.matchMaterial(e.getMessage());
cf.set("panels." + panelName + ".open-with-item.material", temp.toString());
cf.set("panels." + panelName + ".open-with-item.material", e.getMessage());
if(!cf.contains("panels." + panelName + ".open-with-item.name")){
cf.set("panels." + panelName + ".open-with-item.name", panelName + " Item");
}
savePanelFile(cf, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Material to " + ChatColor.WHITE + temp.toString()));
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Material to " + ChatColor.WHITE + e.getMessage()));
//after an open-with-item has been altered, reload after changes
plugin.reloadPanelFiles();
break;

View File

@ -652,16 +652,7 @@ public class editorUtils implements Listener {
if(!cont.getEnchantments().isEmpty()){
file.set("panels." + panelName + ".item." + i + ".enchanted", "true");
}
if(file.contains("panels." + panelName + ".item." + i + ".name")){
//these will ensure &f items (blank items) will be set to &f to stay blank
if(Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".name")).equalsIgnoreCase("&f") || file.getString("panels." + panelName + ".item." + i + ".name").equalsIgnoreCase("§f")){
file.set("panels." + panelName + ".item." + i + ".name", "&f");
}else{
file.set("panels." + panelName + ".item." + i + ".name", Objects.requireNonNull(cont.getItemMeta()).getDisplayName());
}
}else {
file.set("panels." + panelName + ".item." + i + ".name", Objects.requireNonNull(cont.getItemMeta()).getDisplayName());
}
file.set("panels." + panelName + ".item." + i + ".name", Objects.requireNonNull(cont.getItemMeta()).getDisplayName());
file.set("panels." + panelName + ".item." + i + ".lore", Objects.requireNonNull(cont.getItemMeta()).getLore());
}catch(Exception n){
//skip over an item that spits an error
@ -669,7 +660,6 @@ public class editorUtils implements Listener {
}
try {
file.save(new File(plugin.panelsf + File.separator + fileName));
tempEdit.save(new File(plugin.getDataFolder() + File.separator + "temp.yml"));
p.sendMessage(plugin.papi(tag + ChatColor.GREEN + "Saved Changes!"));
} catch (IOException s) {
p.sendMessage(plugin.papi(tag + ChatColor.RED + "Could Not Save Changes!"));

View File

@ -307,38 +307,26 @@ public class utilsOpenWithItem implements Listener {
}catch(Exception b){
return;
}
String tpanels; //tpanels is the temp to check through the files
ItemStack clicked = e.getItemDrop().getItemStack();
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
String key;
tpanels = "";
if(!plugin.checkPanels(temp)){
continue;
}
for (Iterator var10 = Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") {
key = (String) var10.next();
for(String ekey : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)){
if(temp.contains("panels." + key + ".open-with-item")){
if(clicked.getType() != Material.AIR) {
//try and catch loop to stop errors with the same material type but different name
try {
if (clicked.getType() == new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(temp.getString("panels." + ekey + ".open-with-item.material")))), 1).getType()) {
if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi( Objects.requireNonNull(temp.getString("panels." + ekey + ".open-with-item.name")))))) {
//cancel the click item event
if(temp.contains("panels." + key + ".open-with-item.stationary")){
if(p.getInventory().getHeldItemSlot() == Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary")))){
e.setCancelled(true);
return;
}
}
}
}
}catch(Exception n){
//do nothing
for(String[] panelName : plugin.panelNames){
YamlConfiguration tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1]))));
String tempName = panelName[0];
if(tempFile.contains("panels." + tempName + ".open-with-item")) {
try{
assert clicked != null;
if (clicked.getType() == new ItemStack(Objects.requireNonNull(plugin.makeItemFromConfig(Objects.requireNonNull(tempFile.getConfigurationSection("panels." + tempName + ".open-with-item")), p, false, true).getType()), 1).getType()) {
if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi( Objects.requireNonNull(tempFile.getString("panels." + tempName + ".open-with-item.name")))))) {
//cancel the click item event
if (tempFile.contains("panels." + tempName + ".open-with-item.stationary")) {
e.setCancelled(true);
p.updateInventory();
return;
}
return;
}
}
}catch(NullPointerException cancel){
//do nothing skip item
}
}
}