Update v3.11.0

This commit is contained in:
rockyhawk64 2020-09-10 21:01:51 +10:00
parent 44dc044fe5
commit 401ea967ea
12 changed files with 261 additions and 185 deletions

View File

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

View File

@ -28,6 +28,9 @@ import me.rockyhawk.commandpanels.ingameeditor.EditorUtils;
import me.rockyhawk.commandpanels.ioclasses.Sequence_1_13;
import me.rockyhawk.commandpanels.ioclasses.Sequence_1_14;
import me.rockyhawk.commandpanels.legacy.LegacyVersion;
import me.rockyhawk.commandpanels.legacy.PlayerHeads;
import me.rockyhawk.commandpanels.openwithitem.SwapItemEvent;
import me.rockyhawk.commandpanels.openwithitem.UtilsOpenWithItem;
import me.rockyhawk.commandpanels.panelblocks.BlocksTabComplete;
import me.rockyhawk.commandpanels.panelblocks.Commandpanelblocks;
@ -69,6 +72,8 @@ public class CommandPanels extends JavaPlugin {
public ItemCreation itemCreate = new ItemCreation(this);
public GetCustomHeads customHeads = new GetCustomHeads(this);
public Updater updater = new Updater(this);
public PlayerHeads getHeads = new PlayerHeads(this);
public LegacyVersion legacy = new LegacyVersion(this);
public File panelsf;
public YamlConfiguration blockConfig; //where panel block locations are stored
@ -107,6 +112,9 @@ public class CommandPanels extends JavaPlugin {
this.getServer().getPluginManager().registerEvents(new EditorUserInput(this), this);
this.getServer().getPluginManager().registerEvents(new Commandpanelrefresher(this), this);
this.getServer().getPluginManager().registerEvents(new PanelBlockOnClick(this), this);
if (!Bukkit.getVersion().contains("1.8")) {
this.getServer().getPluginManager().registerEvents(new SwapItemEvent(this), this);
}
//save the config.yml file
File configFile = new File(this.getDataFolder() + File.separator + "config.yml");
@ -155,6 +163,7 @@ public class CommandPanels extends JavaPlugin {
Bukkit.getLogger().info("RockyHawk's CommandPanels Plugin Disabled, aww man.");
}
@SuppressWarnings("deprecation")
public Inventory openGui(String panels, Player p, YamlConfiguration pconfig, int onOpen, int animateValue) {
String tag = this.config.getString("config.format.tag") + " ";
if (Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) < 7 && Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) > 0) {
@ -164,7 +173,7 @@ public class CommandPanels extends JavaPlugin {
i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) * 9, papi(p, Objects.requireNonNull(pconfig.getString("panels." + panels + ".title"))));
} else {
//this means it is the Editor window
i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) * 9, papi(p, ChatColor.GRAY + "Editing Panel: " + pconfig.getString("panels." + panels + ".title")));
i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) * 9, "Editing Panel: " + panels);
}
String item = "";
@ -217,7 +226,11 @@ public class CommandPanels extends JavaPlugin {
if (!found) {
ItemStack empty;
try {
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(pconfig.getString("panels." + panels + ".empty")).toUpperCase())), 1);
short id = 0;
if(pconfig.contains("panels." + panels + ".emptyID")){
id = Short.parseShort(pconfig.getString("panels." + panels + ".emptyID"));
}
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(pconfig.getString("panels." + panels + ".empty")).toUpperCase())), 1,id);
if (empty.getType() == Material.AIR) {
continue;
}
@ -330,26 +343,6 @@ public class CommandPanels extends JavaPlugin {
}
}
public String getHeadBase64(ItemStack var0) {
if (var0.getType().equals(Material.PLAYER_HEAD) && var0.hasItemMeta()) {
try {
SkullMeta var1 = (SkullMeta) var0.getItemMeta();
assert var1 != null;
if (!var1.hasOwner()) {
Field var2 = var1.getClass().getDeclaredField("profile");
var2.setAccessible(true);
GameProfile var3 = (GameProfile) var2.get(var1);
Iterator var4 = var3.getProperties().get("textures").iterator();
if (var4.hasNext()) {
Property var5 = (Property) var4.next();
return var5.getValue();
}
}
}catch(Exception exc){/*If there is a problem with the head skip and return null*/}
}
return null;
}
//regular string papi
public String papi(Player p, String setpapi) {
try {
@ -607,7 +600,7 @@ public class CommandPanels extends JavaPlugin {
public Reader getReaderFromStream(InputStream initialStream) throws IOException {
//this reads the encrypted resource files in the jar file
if(Bukkit.getVersion().contains("1.13")){
if(Bukkit.getVersion().contains("1.13") || legacy.isLegacy()){
return new Sequence_1_13().getReaderFromStream(initialStream);
}else{
return new Sequence_1_14().getReaderFromStream(initialStream);

View File

@ -10,6 +10,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.UUID;
public class GetCustomHeads {
@ -18,16 +19,41 @@ public class GetCustomHeads {
this.plugin = pl;
}
public String getHeadBase64(ItemStack head) {
if (plugin.getHeads.ifSkullOrHead(head.getType().toString()) && head.hasItemMeta()) {
try {
SkullMeta meta = (SkullMeta) head.getItemMeta();
assert meta != null;
if (!meta.hasOwner()) {
Field fld = meta.getClass().getDeclaredField("profile");
fld.setAccessible(true);
GameProfile prof = (GameProfile) fld.get(meta);
Iterator itr = prof.getProperties().get("textures").iterator();
if (itr.hasNext()) {
Property var5 = (Property) itr.next();
return var5.getValue();
}
}
}catch(Exception exc){/*skip return null*/}
}
return null;
}
//getting the head from a Player
@SuppressWarnings("deprecation")
public ItemStack getPlayerHead(String name) {
ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD, 1);
byte id = 0;
if(plugin.legacy.isLegacy()){
id = 3;
}
ItemStack itemStack = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id);
SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
meta.setOwner(name);
itemStack.setItemMeta(meta);
return itemStack;
}
@SuppressWarnings("deprecation")
public ItemStack getCustomHead(String b64stringtexture) {
//get head from base64
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
@ -36,7 +62,11 @@ public class GetCustomHeads {
throw new IllegalStateException("Profile doesn't contain a property map");
} else {
propertyMap.put("textures", new Property("textures", b64stringtexture));
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
byte id = 0;
if(plugin.legacy.isLegacy()){
id = 3;
}
ItemStack head = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id);
ItemMeta headMeta = head.getItemMeta();
assert headMeta != null;
Class headMetaClass = headMeta.getClass();

View File

@ -26,6 +26,7 @@ public class ItemCreation {
plugin = pl;
}
@SuppressWarnings("deprecation")
public ItemStack makeItemFromConfig(ConfigurationSection itemSection, Player p, boolean placeholders, boolean colours){
String tag = plugin.config.getString("config.format.tag") + " ";
String material = itemSection.getString("material");
@ -60,17 +61,27 @@ public class ItemCreation {
mat = material.toUpperCase();
matskull = material;
skullname = "no skull";
short id = 0;
if(itemSection.contains("ID")){
id = Short.parseShort(itemSection.getString("ID"));
}
if (matskull.split("\\s")[0].toLowerCase().equals("cps=") || matskull.split("\\s")[0].toLowerCase().equals("cpo=")) {
skullname = p.getUniqueId().toString();
mat = "PLAYER_HEAD";
mat = plugin.getHeads.playerHeadString();
if(plugin.legacy.isLegacy()){
id = 3;
}
}
if (matskull.split("\\s")[0].toLowerCase().equals("hdb=")) {
skullname = "hdb";
mat = "PLAYER_HEAD";
mat = plugin.getHeads.playerHeadString();
if(plugin.legacy.isLegacy()){
id = 3;
}
}
s = new ItemStack(Objects.requireNonNull(Material.matchMaterial(mat)), 1);
s = new ItemStack(Objects.requireNonNull(Material.matchMaterial(mat)), 1,id);
if (!skullname.equals("no skull") && !skullname.equals("hdb") && !matskull.split("\\s")[0].equalsIgnoreCase("cpo=")) {
try {
@ -78,12 +89,16 @@ public class ItemCreation {
if (matskull.split("\\s")[1].equalsIgnoreCase("self")) {
//if cps= self
meta = (SkullMeta) s.getItemMeta();
try {
assert meta != null;
meta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(skullname)));
} catch (Exception var23) {
p.sendMessage(plugin.papi( tag + plugin.config.getString("config.format.error") + " material: cps= self"));
plugin.debug(var23);
if(!plugin.legacy.isLegacy()) {
try {
assert meta != null;
meta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(skullname)));
} catch (Exception var23) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " material: cps= self"));
plugin.debug(var23);
}
}else{
meta.setOwner(p.getName());
}
s.setItemMeta(meta);
}else if (plugin.papiNoColour(p,matskull.split("\\s")[1]).length() <= 16) {

View File

@ -5,6 +5,7 @@ import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -27,9 +28,9 @@ public class OpenEditorGuis {
public void openEditorGui(Player p, int pageChange) {
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<ItemStack> panelItems = new ArrayList<ItemStack>(); //all panels from ALL files (panel materials)
ArrayList<String> panelNames = new ArrayList<>(); //all panels from ALL files (panel names)
ArrayList<String> panelTitles = new ArrayList<>(); //all panels from ALL files (panel titles)
ArrayList<ItemStack> panelItems = new ArrayList<>(); //all panels from ALL files (panel materials)
try {
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
@ -44,7 +45,7 @@ public class OpenEditorGuis {
if (temp.contains("panels." + key + ".open-with-item.material")) {
panelItems.add(plugin.itemCreate.makeItemFromConfig(temp.getConfigurationSection("panels." + key + ".open-with-item"), p, false, true));
} else {
panelItems.add(new ItemStack(Material.FILLED_MAP));
panelItems.add(new ItemStack(Material.PAPER));
}
}
}
@ -68,7 +69,7 @@ public class OpenEditorGuis {
int pagesAmount = (int) Math.ceil(panelNames.size() / 45.0);
//make all the bottom bar items
ItemStack temp;
temp = new ItemStack(Material.SUNFLOWER, 1);
temp = new ItemStack(Material.SLIME_BALL, 1);
plugin.setName(temp, ChatColor.WHITE + "Page " + pageNumber, null, p, true, true);
i.setItem(49, temp);
temp = new ItemStack(Material.BARRIER, 1);
@ -114,8 +115,9 @@ public class OpenEditorGuis {
p.openInventory(i);
}
@SuppressWarnings("deprecation")
public void openPanelSettings(Player p, String panelName, YamlConfiguration cf) {
Inventory i = Bukkit.createInventory(null, 45, "Panel Settings: " + panelName);
Inventory i = Bukkit.createInventory(null, 45, ChatColor.stripColor("Panel Settings: " + panelName));
List<String> lore = new ArrayList();
ItemStack temp;
//remove if the player already had a string from previously
@ -126,7 +128,7 @@ public class OpenEditorGuis {
}
}
//make all the items
temp = new ItemStack(Material.WRITABLE_BOOK, 1);
temp = new ItemStack(Material.IRON_INGOT, 1);
lore.add(ChatColor.GRAY + "Permission required to open panel");
lore.add(ChatColor.GRAY + "commandpanel.panel.[insert]");
if (cf.contains("panels." + panelName + ".perm")) {
@ -172,14 +174,14 @@ public class OpenEditorGuis {
plugin.setName(temp, ChatColor.RED + "Delete Panel", lore, p,true, true);
i.setItem(21, temp);
temp = new ItemStack(Material.PISTON, 1);
temp = new ItemStack(Material.LADDER, 1);
lore.clear();
lore.add(ChatColor.GRAY + "How many rows the panel will be");
lore.add(ChatColor.GRAY + "choose an integer from 1 to 6");
plugin.setName(temp, ChatColor.WHITE + "Panel Rows", lore, p,true, true);
i.setItem(23, temp);
temp = new ItemStack(Material.BLACK_STAINED_GLASS, 1);
temp = new ItemStack(Material.GLASS, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Fill empty slots with an item");
if (cf.contains("panels." + panelName + ".empty")) {
@ -189,7 +191,7 @@ public class OpenEditorGuis {
plugin.setName(temp, ChatColor.WHITE + "Panel Empty Item", lore, p,true, true);
i.setItem(13, temp);
temp = new ItemStack(Material.COMMAND_BLOCK, 1);
temp = new ItemStack(Material.ANVIL, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Execute commands when opening");
lore.add(ChatColor.GRAY + "- Left click to add command");
@ -219,7 +221,11 @@ public class OpenEditorGuis {
i.setItem(18, temp);
//This will create a wall of glass panes, separating panel settings with hotbar settings
temp = new ItemStack(Material.BLACK_STAINED_GLASS_PANE, 1);
if(plugin.legacy.isLegacy()) {
temp = new ItemStack(Material.matchMaterial("STAINED_GLASS_PANE"), 1,(short)15);
}else{
temp = new ItemStack(Material.matchMaterial("BLACK_STAINED_GLASS_PANE"), 1);
}
plugin.setName(temp, ChatColor.WHITE + "", null, p,false, true);
for(int d = 27; d < 36; d++){
i.setItem(d, temp);
@ -256,7 +262,7 @@ public class OpenEditorGuis {
plugin.setName(temp, ChatColor.WHITE + "Hotbar Item Name", lore, p, true, true);
i.setItem(38, temp);
temp = new ItemStack(Material.SPRUCE_SIGN, 1);
temp = new ItemStack(Material.FEATHER, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Display a lore under the Hotbar item");
lore.add(ChatColor.GRAY + "- Left click to add lore");
@ -299,7 +305,7 @@ public class OpenEditorGuis {
}
public void openItemSettings(Player p, String panelName, YamlConfiguration cf, int itemNumber) {
Inventory i = Bukkit.createInventory(null, 36, "Item Settings: " + panelName);
Inventory i = Bukkit.createInventory(null, 36, ChatColor.stripColor("Item Settings: " + panelName));
List<String> lore = new ArrayList();
ItemStack temp;
//remove if the player already had a string from previously
@ -321,7 +327,7 @@ public class OpenEditorGuis {
plugin.setName(temp, ChatColor.WHITE + "Item Name", lore, p,true, true);
i.setItem(1, temp);
temp = new ItemStack(Material.COMMAND_BLOCK, 1);
temp = new ItemStack(Material.ANVIL, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Execute commands when item is clicked");
lore.add(ChatColor.GRAY + "- Left click to add command");
@ -337,7 +343,7 @@ public class OpenEditorGuis {
plugin.setName(temp, ChatColor.WHITE + "Item Commands", lore, p,true, true);
i.setItem(3, temp);
temp = new ItemStack(Material.EXPERIENCE_BOTTLE, 1);
temp = new ItemStack(Material.ENCHANTED_BOOK, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Display enchantment of the item in the Panel");
if (cf.contains("panels." + panelName + ".item." + itemNumber + ".enchanted")) {
@ -364,7 +370,7 @@ public class OpenEditorGuis {
plugin.setName(temp, ChatColor.WHITE + "Item Potion Effect", lore, p,true, true);
i.setItem(7, temp);
temp = new ItemStack(Material.SPRUCE_SIGN, 1);
temp = new ItemStack(Material.FEATHER, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Display a lore under the item name");
lore.add(ChatColor.GRAY + "- Left click to add lore line");
@ -396,17 +402,19 @@ public class OpenEditorGuis {
plugin.setName(temp, ChatColor.WHITE + "Item Stack Size", lore, p, true, true);
i.setItem(21, temp);
temp = new ItemStack(Material.ANVIL, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Add Custom Model Data here");
if (cf.contains("panels." + panelName + ".item." + itemNumber + ".customdata")) {
if (!Objects.equals(cf.getString("panels." + panelName + ".item." + itemNumber + ".customdata"), "")) {
lore.add(ChatColor.WHITE + "--------------------------------");
lore.add(ChatColor.WHITE + cf.getString("panels." + panelName + ".item." + itemNumber + ".customdata"));
if(!plugin.legacy.isLegacy()) {
temp = new ItemStack(Material.PAINTING, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Add Custom Model Data here");
if (cf.contains("panels." + panelName + ".item." + itemNumber + ".customdata")) {
if (!Objects.equals(cf.getString("panels." + panelName + ".item." + itemNumber + ".customdata"), "")) {
lore.add(ChatColor.WHITE + "--------------------------------");
lore.add(ChatColor.WHITE + cf.getString("panels." + panelName + ".item." + itemNumber + ".customdata"));
}
}
plugin.setName(temp, ChatColor.WHITE + "Custom Model Data", lore, p, true, true);
i.setItem(23, temp);
}
plugin.setName(temp, ChatColor.WHITE + "Custom Model Data", lore, p, true, true);
i.setItem(23, temp);
temp = new ItemStack(Material.LEATHER_HELMET, 1);
lore.clear();
@ -425,55 +433,7 @@ public class OpenEditorGuis {
plugin.setName(temp, ChatColor.RED + "Back", null, p, true, true);
i.setItem(27, temp);
if(Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + itemNumber + ".material")).startsWith("cps=")){
temp = new ItemStack(Material.PLAYER_HEAD, 1);
if(Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + itemNumber + ".material")).equalsIgnoreCase("cps= self")){
//if self
SkullMeta meta = (SkullMeta) temp.getItemMeta();
try {
assert meta != null;
meta.setOwningPlayer(Bukkit.getOfflinePlayer(p.getUniqueId()));
} catch (Exception var23) {
plugin.debug(var23);
}
temp.setItemMeta(meta);
}else{
//custom head
temp = plugin.customHeads.getCustomHead(Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + itemNumber + ".material")).replace("cps=", "").trim());
}
}else if (Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + itemNumber + ".material")).startsWith("%cp-player-online-")){
//leave default for the find material tag
temp = new ItemStack(Material.PLAYER_HEAD, 1);
}else if (Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + itemNumber + ".material")).startsWith("hdb=")){
//head database head
temp = new ItemStack(Material.PLAYER_HEAD, 1);
if (plugin.getServer().getPluginManager().isPluginEnabled("HeadDatabase")) {
HeadDatabaseAPI api;
api = new HeadDatabaseAPI();
try {
temp = api.getItemHead(Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + itemNumber + ".material")).replace("hdb=", "").trim());
} catch (Exception var22) {
plugin.debug(var22);
}
}
}else{
temp = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + itemNumber + ".material")))), 1);
}
try {
temp.setAmount(Integer.parseInt(Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + itemNumber + ".stack"))));
} catch (Exception ex) {
//skip
}
if (cf.contains("panels." + panelName + ".item." + itemNumber + ".enchanted")) {
if (!Objects.equals(cf.getString("panels." + panelName + ".item." + itemNumber + ".enchanted"), "false")) {
ItemMeta EnchantMeta;
EnchantMeta = temp.getItemMeta();
assert EnchantMeta != null;
EnchantMeta.addEnchant(Enchantment.KNOCKBACK, 1, true);
EnchantMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
temp.setItemMeta(EnchantMeta);
}
}
temp = plugin.itemCreate.makeItemFromConfig(cf.getConfigurationSection("panels." + panelName + ".item." + itemNumber),p,false,false);
lore.clear();
lore.add(ChatColor.GRAY + "Click to set custom material");
lore.add(ChatColor.GRAY + "typically for custom heads");

View File

@ -99,16 +99,21 @@ public class NewGenUtils implements Listener {
file.addDefault("panels." + date + ".rows", inv.getSize()/9);
file.addDefault("panels." + date + ".title", "&8Generated " + date);
file.addDefault("panels." + date + ".command", date);
file.addDefault("panels." + date + ".empty", "BLACK_STAINED_GLASS_PANE");
if(plugin.legacy.isLegacy()) {
file.addDefault("panels." + date + ".empty", "STAINED_GLASS_PANE");
file.addDefault("panels." + date + ".emptyID", "15");
}else{
file.addDefault("panels." + date + ".empty", "BLACK_STAINED_GLASS_PANE");
}
for(int i = 0; cont.length > i; i++){
//repeat through all the items in the chest
try{
//make the item here
if(cont[i].getType() == Material.PLAYER_HEAD){
if(plugin.getHeads.ifSkullOrHead(cont[i].getType().toString())){
SkullMeta meta = (SkullMeta) cont[i].getItemMeta();
if(plugin.getHeadBase64(cont[i]) != null){
if(plugin.customHeads.getHeadBase64(cont[i]) != null){
//check for base64
file.addDefault("panels." + date + ".item." + i + ".material", "cps= " + plugin.getHeadBase64(cont[i]));
file.addDefault("panels." + date + ".item." + i + ".material", "cps= " + plugin.customHeads.getHeadBase64(cont[i]));
}else if(meta.hasOwner()){
//check for skull owner
file.addDefault("panels." + date + ".item." + i + ".material", "cps= " + meta.getOwner());

View File

@ -338,7 +338,7 @@ public class EditorUserInput implements Listener {
break;
case "head":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".item." + itemSlot + ".material", "PLAYER_HEAD");
cf.set("panels." + panelName + ".item." + itemSlot + ".material", plugin.getHeads.playerHeadString());
savePanelFile(cf, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Material is now default."));
break;

View File

@ -76,7 +76,7 @@ public class EditorUtils implements Listener {
}
if(e.getSlot() == 49){
//sunflower page index
if(Objects.requireNonNull(e.getCurrentItem()).getType() == Material.SUNFLOWER){
if(Objects.requireNonNull(e.getCurrentItem()).getType() == Material.SLIME_BALL){
p.updateInventory();
return;
}
@ -134,7 +134,7 @@ public class EditorUtils implements Listener {
if(e.getInventory().getType() != InventoryType.CHEST){
return;
}
if(!p.getOpenInventory().getTitle().contains(ChatColor.GRAY + "Editing Panel:")){
if(!p.getOpenInventory().getTitle().contains("Editing Panel:")){
return;
}
String panelName = ""; //all panels from ALL files (panel names)
@ -151,7 +151,7 @@ public class EditorUtils implements Listener {
}
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) {
key = s;
if (e.getView().getTitle().equals(ChatColor.GRAY + "Editing Panel: " + plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".title"))))) {
if (e.getView().getTitle().equals("Editing Panel: " + key)) {
panelName = key;
fileName = fileTempName;
file = temp;
@ -201,7 +201,7 @@ public class EditorUtils implements Listener {
if(e.getInventory().getType() != InventoryType.CHEST){
return;
}
if(!p.getOpenInventory().getTitle().contains(ChatColor.GRAY + "Editing Panel:")){
if(!p.getOpenInventory().getTitle().contains("Editing Panel:")){
return;
}
String panelName = "";
@ -212,14 +212,12 @@ public class EditorUtils implements Listener {
//neew to loop through files to get file names
for(String tempName : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + tempName));
String key;
if(!plugin.checkPanels(temp)){
continue;
}
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) {
key = s;
if (e.getView().getTitle().equals(ChatColor.GRAY + "Editing Panel: " + plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".title"))))) {
panelName = key;
if (e.getView().getTitle().equals("Editing Panel: " + s)) {
panelName = s;
fileName = tempName;
file = temp;
found = true;
@ -256,7 +254,7 @@ public class EditorUtils implements Listener {
return;
}
if(tempEdit.contains("panels." + panelName + ".temp." + p.getName() + ".material")) {
if(Objects.requireNonNull(e.getCursor()).getType() != Material.PLAYER_HEAD) {
if(!plugin.getHeads.ifSkullOrHead(Objects.requireNonNull(e.getCursor()).getType().toString())) {
//if the material doesn't match and also isn't a PLAYER_HEAD
if (e.getCursor().getType() != Material.matchMaterial(Objects.requireNonNull(tempEdit.getString("panels." + panelName + ".temp." + p.getName() + ".material")))) {
clearTemp(p, panelName);
@ -584,7 +582,7 @@ public class EditorUtils implements Listener {
if(inv.getType() != InventoryType.CHEST){
return;
}
if(!p.getOpenInventory().getTitle().contains(ChatColor.GRAY + "Editing Panel:")){
if(!p.getOpenInventory().getTitle().contains("Editing Panel:")){
return;
}
String panelName = ""; //all panels from ALL files (panel names)
@ -601,7 +599,7 @@ public class EditorUtils implements Listener {
}
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) {
key = s;
if (invView.getTitle().equals(ChatColor.GRAY + "Editing Panel: " + plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".title"))))) {
if (invView.getTitle().equals("Editing Panel: " + key)) {
panelName = key;
fileName = tempFile;
file = temp;
@ -634,7 +632,7 @@ public class EditorUtils implements Listener {
}
if(file.contains("panels." + panelName + ".item." + i + ".material")){
if(Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("%") || Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("=")){
if(cont.getType() != Material.PLAYER_HEAD){
if(!plugin.getHeads.ifSkullOrHead(cont.getType().toString())){
file.set("panels." + panelName + ".item." + i + ".material", cont.getType().toString());
}
}else{
@ -643,15 +641,17 @@ public class EditorUtils implements Listener {
}else{
file.set("panels." + panelName + ".item." + i + ".material", cont.getType().toString());
}
if(cont.getType() == Material.PLAYER_HEAD){
//inject base64 here
if(plugin.getHeadBase64(cont) != null){
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + plugin.getHeadBase64(cont));
}
//check for skull owner
if(plugin.getHeads.ifSkullOrHead(cont.getType().toString())){
SkullMeta meta = (SkullMeta) cont.getItemMeta();
if(meta.hasOwner()){
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + meta.getOwner());
//disable for legacy as is broken
if(!plugin.legacy.isLegacy()) {
if (plugin.customHeads.getHeadBase64(cont) != null) {
//inject base64 here
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + plugin.customHeads.getHeadBase64(cont));
} else if (meta.hasOwner()) {
//check for skull owner
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + meta.getOwner());
}
}
}
if(cont.getAmount() != 1){

View File

@ -0,0 +1,31 @@
package me.rockyhawk.commandpanels.legacy;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.Bukkit;
import java.util.ArrayList;
public class LegacyVersion {
CommandPanels plugin;
public LegacyVersion(CommandPanels pl) {
this.plugin = pl;
}
//true if 1.12 or below
public boolean isLegacy() {
boolean output = false;
ArrayList<String> legacyVersions = new ArrayList();
legacyVersions.add("1.8");
legacyVersions.add("1.9");
legacyVersions.add("1.10");
legacyVersions.add("1.11");
legacyVersions.add("1.12");
for(String key : legacyVersions){
if (Bukkit.getVersion().contains(key)) {
output = true;
break;
}
}
return output;
}
}

View File

@ -0,0 +1,22 @@
package me.rockyhawk.commandpanels.legacy;
import me.rockyhawk.commandpanels.CommandPanels;
public class PlayerHeads {
CommandPanels plugin;
public PlayerHeads(CommandPanels pl) {
this.plugin = pl;
}
public boolean ifSkullOrHead(String material) {
return material.equalsIgnoreCase("PLAYER_HEAD") || material.equalsIgnoreCase("SKULL_ITEM");
}
public String playerHeadString() {
if(plugin.legacy.isLegacy()){
return "SKULL_ITEM";
}else{
return "PLAYER_HEAD";
}
}
}

View File

@ -0,0 +1,71 @@
package me.rockyhawk.commandpanels.openwithitem;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.Iterator;
import java.util.Objects;
public class SwapItemEvent implements Listener {
CommandPanels plugin;
public SwapItemEvent(CommandPanels pl) {
this.plugin = pl;
}
@EventHandler
public void onPlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent e){
if(!plugin.openWithItem){
//if none of the panels have open-with-item
return;
}
Player p = e.getPlayer();
try {
if (plugin.panelFiles == null) {
return;
}
}catch(Exception b){
return;
}
String tpanels; //tpanels is the temp to check through the files
ItemStack clicked = e.getOffHandItem();
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();
if(temp.contains("panels." + key + ".open-with-item")){
assert clicked != null;
if(clicked.getType() != Material.AIR) {
//if loop has material first to stop 1.12.2 from spitting errors
//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." + key + ".open-with-item.material")))), 1).getType()) {
if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".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(NullPointerException | IllegalArgumentException n){
plugin.debug(n);
}
}
}
}
}
}
}

View File

@ -332,57 +332,6 @@ public class UtilsOpenWithItem implements Listener {
}
}
@EventHandler
public void onPlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent e){
if(!plugin.openWithItem){
//if none of the panels have open-with-item
return;
}
Player p = e.getPlayer();
try {
if (plugin.panelFiles == null) {
return;
}
}catch(Exception b){
return;
}
YamlConfiguration cf; //this is the file to use for any panel.* requests
String tpanels; //tpanels is the temp to check through the files
ItemStack clicked = e.getOffHandItem();
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();
if(temp.contains("panels." + key + ".open-with-item")){
assert clicked != null;
if(clicked.getType() != Material.AIR) {
//if loop has material first to stop 1.12.2 from spitting errors
//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." + key + ".open-with-item.material")))), 1).getType()) {
if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".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(NullPointerException | IllegalArgumentException n){
plugin.debug(n);
}
}
}
}
}
}
@EventHandler
public void onInteractEntity(PlayerInteractEntityEvent e){
if(!plugin.openWithItem){
//if none of the panels have open-with-item