This commit is contained in:
rockyhawk64 2024-04-30 19:54:19 +10:00
parent fe32486b0b
commit 42dd8ee698
29 changed files with 118 additions and 460 deletions

View File

@ -126,7 +126,7 @@
<dependency> <dependency>
<groupId>de.tr7zw</groupId> <groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId> <artifactId>item-nbt-api</artifactId>
<version>2.12.2</version> <version>2.12.4-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -150,7 +150,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.20-R0.1-SNAPSHOT</version> <version>1.20.5-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -221,7 +221,7 @@
<dependency> <dependency>
<groupId>io.papermc</groupId> <groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId> <artifactId>paperlib</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.essentialsx</groupId> <groupId>net.essentialsx</groupId>

View File

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

View File

@ -75,7 +75,7 @@ panels:
'21': '21':
material: POTION material: POTION
name: '&fClick to heal the player' name: '&fClick to heal the player'
potion: INSTANT_HEAL potion: HEALING
lore: lore:
- '&7Uses the /heal command so that' - '&7Uses the /heal command so that'
- '&7the player needs permission' - '&7the player needs permission'

View File

@ -31,10 +31,6 @@ import me.rockyhawk.commandpanels.interactives.OutsideClickEvent;
import me.rockyhawk.commandpanels.interactives.input.UserInputUtils; import me.rockyhawk.commandpanels.interactives.input.UserInputUtils;
import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher; import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher;
import me.rockyhawk.commandpanels.interactives.OpenOnJoin; import me.rockyhawk.commandpanels.interactives.OpenOnJoin;
import me.rockyhawk.commandpanels.ioclasses.nbt.NBTManager;
import me.rockyhawk.commandpanels.ioclasses.legacy.LegacyVersion;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import me.rockyhawk.commandpanels.ioclasses.legacy.PlayerHeads;
import me.rockyhawk.commandpanels.openpanelsmanager.*; import me.rockyhawk.commandpanels.openpanelsmanager.*;
import me.rockyhawk.commandpanels.openwithitem.HotbarItemLoader; import me.rockyhawk.commandpanels.openwithitem.HotbarItemLoader;
import me.rockyhawk.commandpanels.openwithitem.SwapItemEvent; import me.rockyhawk.commandpanels.openwithitem.SwapItemEvent;
@ -43,6 +39,7 @@ import me.rockyhawk.commandpanels.openwithitem.UtilsOpenWithItem;
import me.rockyhawk.commandpanels.panelblocks.BlocksTabComplete; import me.rockyhawk.commandpanels.panelblocks.BlocksTabComplete;
import me.rockyhawk.commandpanels.panelblocks.Commandpanelblocks; import me.rockyhawk.commandpanels.panelblocks.Commandpanelblocks;
import me.rockyhawk.commandpanels.panelblocks.PanelBlockOnClick; import me.rockyhawk.commandpanels.panelblocks.PanelBlockOnClick;
import me.rockyhawk.commandpanels.nbt.NBTManager;
import me.rockyhawk.commandpanels.playerinventoryhandler.InventorySaver; import me.rockyhawk.commandpanels.playerinventoryhandler.InventorySaver;
import me.rockyhawk.commandpanels.playerinventoryhandler.ItemStackSerializer; import me.rockyhawk.commandpanels.playerinventoryhandler.ItemStackSerializer;
import me.rockyhawk.commandpanels.updater.Updater; import me.rockyhawk.commandpanels.updater.Updater;
@ -97,19 +94,17 @@ public class CommandPanels extends JavaPlugin{
public HasSections has = new HasSections(this); public HasSections has = new HasSections(this);
public GetCustomHeads customHeads = new GetCustomHeads(this); public GetCustomHeads customHeads = new GetCustomHeads(this);
public Updater updater = new Updater(this); public Updater updater = new Updater(this);
public PlayerHeads getHeads = new PlayerHeads(this);
public LegacyVersion legacy = new LegacyVersion(this);
public OpenPanelsLoader openPanels = new OpenPanelsLoader(this); public OpenPanelsLoader openPanels = new OpenPanelsLoader(this);
public OpenGUI createGUI = new OpenGUI(this); public OpenGUI createGUI = new OpenGUI(this);
public PanelPermissions panelPerms = new PanelPermissions(this); public PanelPermissions panelPerms = new PanelPermissions(this);
public HotbarItemLoader hotbar = new HotbarItemLoader(this); public HotbarItemLoader hotbar = new HotbarItemLoader(this);
public NBTManager nbt = new NBTManager(this);
public InventorySaver inventorySaver = new InventorySaver(this); public InventorySaver inventorySaver = new InventorySaver(this);
public ItemStackSerializer itemSerializer = new ItemStackSerializer(this); public ItemStackSerializer itemSerializer = new ItemStackSerializer(this);
public UserInputUtils inputUtils = new UserInputUtils(this); public UserInputUtils inputUtils = new UserInputUtils(this);
public OpenFloodgateGUI floodgateOpenGUI = new OpenFloodgateGUI(this); public OpenFloodgateGUI floodgateOpenGUI = new OpenFloodgateGUI(this);
public NBTManager nbt = new NBTManager(this);
public File panelsf = new File(this.getDataFolder() + File.separator + "panels"); public File panelsf = new File(this.getDataFolder() + File.separator + "panels");
public YamlConfiguration blockConfig; //where panel block locations are stored public YamlConfiguration blockConfig; //where panel block locations are stored
@ -184,6 +179,7 @@ public class CommandPanels extends JavaPlugin{
this.getServer().getPluginManager().registerEvents(new ItemFallManager(this), this); this.getServer().getPluginManager().registerEvents(new ItemFallManager(this), this);
this.getServer().getPluginManager().registerEvents(new OpenOnJoin(this), this); this.getServer().getPluginManager().registerEvents(new OpenOnJoin(this), this);
this.getServer().getPluginManager().registerEvents(new OutsideClickEvent(this), this); this.getServer().getPluginManager().registerEvents(new OutsideClickEvent(this), this);
this.getServer().getPluginManager().registerEvents(new SwapItemEvent(this), this);
if (this.getServer().getPluginManager().isPluginEnabled("floodgate")) { if (this.getServer().getPluginManager().isPluginEnabled("floodgate")) {
this.getServer().getPluginManager().registerEvents(new OpenFloodgateGUI(this), this); this.getServer().getPluginManager().registerEvents(new OpenFloodgateGUI(this), this);
@ -224,10 +220,6 @@ public class CommandPanels extends JavaPlugin{
this.getServer().getPluginManager().registerEvents(new PanelBlockOnClick(this), this); this.getServer().getPluginManager().registerEvents(new PanelBlockOnClick(this), this);
} }
//if 1.8 don't use this
if (!Bukkit.getVersion().contains("1.8")) {
this.getServer().getPluginManager().registerEvents(new SwapItemEvent(this), this);
}
//if VotingPlugin is enabled //if VotingPlugin is enabled
if (getServer().getPluginManager().isPluginEnabled("VotingPlugin")) { if (getServer().getPluginManager().isPluginEnabled("VotingPlugin")) {
votingPlugin= VotingPluginHooks.getInstance(); votingPlugin= VotingPluginHooks.getInstance();
@ -240,10 +232,6 @@ public class CommandPanels extends JavaPlugin{
//save the example_top.yml file and the template.yml file //save the example_top.yml file and the template.yml file
if (!this.panelsf.exists()) { if (!this.panelsf.exists()) {
try { try {
if(legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
FileConfiguration exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("exampleLegacy.yml")));
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example.yml"));
}else {
//top //top
FileConfiguration exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_top.yml"))); FileConfiguration exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_top.yml")));
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_top.yml")); exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_top.yml"));
@ -256,7 +244,7 @@ public class CommandPanels extends JavaPlugin{
//bottom //bottom
exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_bottom.yml"))); exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_bottom.yml")));
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_bottom.yml")); exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_bottom.yml"));
}
FileConfiguration templateFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("template.yml"))); FileConfiguration templateFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("template.yml")));
templateFileConfiguration.save(new File(this.panelsf + File.separator + "template.yml")); templateFileConfiguration.save(new File(this.panelsf + File.separator + "template.yml"));
} catch (IOException var11) { } catch (IOException var11) {
@ -318,17 +306,10 @@ public class CommandPanels extends JavaPlugin{
//hiding attributes will add an NBT tag //hiding attributes will add an NBT tag
if(hideAttributes) { if(hideAttributes) {
renamedMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); renamedMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
renamedMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
renamedMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); renamedMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
//HIDE_ARMOR_TRIM was added into 1.20 api
if(legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20)){
renamedMeta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM); renamedMeta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
}
//HIDE_DYE was added into 1.17 api
if(legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_17)){
renamedMeta.addItemFlags(ItemFlag.HIDE_DYE); renamedMeta.addItemFlags(ItemFlag.HIDE_DYE);
} }
}
if (customName != null) { if (customName != null) {
renamedMeta.setDisplayName(customName); renamedMeta.setDisplayName(customName);
} }
@ -460,7 +441,7 @@ public class CommandPanels extends JavaPlugin{
p.sendMessage(ChatColor.GOLD + "/cpv " + ChatColor.WHITE + "Display the current version."); p.sendMessage(ChatColor.GOLD + "/cpv " + ChatColor.WHITE + "Display the current version.");
} }
if (p.hasPermission("commandpanel.refresh")) { if (p.hasPermission("commandpanel.refresh")) {
p.sendMessage(ChatColor.GOLD + "/cpu [player] [position:all] " + ChatColor.WHITE + "Update a panel for a player while it is still open."); p.sendMessage(ChatColor.GOLD + "/cpu <player> [position:all] " + ChatColor.WHITE + "Update a panel for a player while it is still open.");
} }
if (p.hasPermission("commandpanel.update")) { if (p.hasPermission("commandpanel.update")) {
p.sendMessage(ChatColor.GOLD + "/cpv latest " + ChatColor.WHITE + "Download the latest update upon server reload/restart."); p.sendMessage(ChatColor.GOLD + "/cpv latest " + ChatColor.WHITE + "Download the latest update upon server reload/restart.");
@ -470,7 +451,7 @@ public class CommandPanels extends JavaPlugin{
p.sendMessage(ChatColor.GOLD + "/cpe <panel file> " + ChatColor.WHITE + "Export panel to the Online Editor."); p.sendMessage(ChatColor.GOLD + "/cpe <panel file> " + ChatColor.WHITE + "Export panel to the Online Editor.");
} }
if (p.hasPermission("commandpanel.import")) { if (p.hasPermission("commandpanel.import")) {
p.sendMessage(ChatColor.GOLD + "/cpi [file name] [URL] " + ChatColor.WHITE + "Downloads a panel from a raw link online."); p.sendMessage(ChatColor.GOLD + "/cpi <file name> <URL> " + ChatColor.WHITE + "Downloads a panel from a raw link online.");
} }
if (p.hasPermission("commandpanel.list")) { if (p.hasPermission("commandpanel.list")) {
p.sendMessage(ChatColor.GOLD + "/cpl " + ChatColor.WHITE + "Lists the currently loaded panels."); p.sendMessage(ChatColor.GOLD + "/cpl " + ChatColor.WHITE + "Lists the currently loaded panels.");

View File

@ -99,7 +99,7 @@ public class Panel{
} }
try { try {
//add NBT to item and return the ItemStack //add NBT to item and return the ItemStack
return plugin.nbt.setNBT(s, "CommandPanelsHotbar", panelName + ":" + slot); return plugin.nbt.setData(s, "CommandPanelsHotbar", panelName + ":" + slot);
}catch(Exception e) { }catch(Exception e) {
//return air if null //return air if null
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);

View File

@ -4,7 +4,6 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap; import com.mojang.authlib.properties.PropertyMap;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -32,7 +31,7 @@ public class GetCustomHeads {
public HashMap<String, String> playerHeadTextures = new HashMap<>(); public HashMap<String, String> playerHeadTextures = new HashMap<>();
public String getHeadBase64(ItemStack head) { public String getHeadBase64(ItemStack head) {
if (plugin.getHeads.ifSkullOrHead(head.getType().toString()) && head.hasItemMeta()) { if ((head.getType() == Material.PLAYER_HEAD) && head.hasItemMeta()) {
try { try {
SkullMeta meta = (SkullMeta) head.getItemMeta(); SkullMeta meta = (SkullMeta) head.getItemMeta();
assert meta != null; assert meta != null;
@ -71,18 +70,13 @@ public class GetCustomHeads {
//getting the head from a Player Name //getting the head from a Player Name
public ItemStack getPlayerHead(String name) { public ItemStack getPlayerHead(String name) {
byte id = 0;
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
id = 3;
}
//get texture if already cached //get texture if already cached
if(playerHeadTextures.containsKey(name)) { if(playerHeadTextures.containsKey(name)) {
return getCustomHead(playerHeadTextures.get(name)); return getCustomHead(playerHeadTextures.get(name));
} }
//create ItemStack //create ItemStack
ItemStack itemStack = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1, id); ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD, 1);
//Run fallback code, if API call fails, use legacy setOwner //Run fallback code, if API call fails, use legacy setOwner
SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
@ -144,11 +138,7 @@ public class GetCustomHeads {
throw new IllegalStateException("Profile doesn't contain a property map"); throw new IllegalStateException("Profile doesn't contain a property map");
} else { } else {
propertyMap.put("textures", new Property("textures", b64stringtexture)); propertyMap.put("textures", new Property("textures", b64stringtexture));
byte id = 0; ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
id = 3;
}
ItemStack head = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id);
ItemMeta headMeta = head.getItemMeta(); ItemMeta headMeta = head.getItemMeta();
assert headMeta != null; assert headMeta != null;

View File

@ -106,16 +106,6 @@ public class HasSections {
outputValue = false; outputValue = false;
} }
//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 the functions implemented inside it //the current has section with all the functions implemented inside it
if(setName.startsWith("has")) { if(setName.startsWith("has")) {
if(value.endsWith(" HASPERM")) { if(value.endsWith(" HASPERM")) {

View File

@ -1,15 +1,10 @@
package me.rockyhawk.commandpanels.classresources; package me.rockyhawk.commandpanels.classresources;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTItem;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import me.arcaniax.hdb.api.HeadDatabaseAPI; import me.arcaniax.hdb.api.HeadDatabaseAPI;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel; import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.MMOItemsAPI;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.manager.ItemManager; import net.Indyuce.mmoitems.manager.ItemManager;
import org.bukkit.*; import org.bukkit.*;
@ -28,7 +23,6 @@ import org.bukkit.inventory.meta.*;
import org.bukkit.inventory.meta.trim.ArmorTrim; import org.bukkit.inventory.meta.trim.ArmorTrim;
import org.bukkit.inventory.meta.trim.TrimMaterial; import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern; import org.bukkit.inventory.meta.trim.TrimPattern;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import java.util.*; import java.util.*;
@ -79,24 +73,14 @@ public class ItemCreation {
boolean normalCreation = true; boolean normalCreation = true;
//name of head/skull if used //name of head/skull if used
skullname = "no skull"; skullname = "no skull";
short id = 0;
if(itemSection.contains("ID")){
id = Short.parseShort(itemSection.getString("ID"));
}
if (matraw.split("\\s")[0].equalsIgnoreCase("cps=") || matraw.split("\\s")[0].toLowerCase().equals("cpo=")) { if (matraw.split("\\s")[0].equalsIgnoreCase("cps=") || matraw.split("\\s")[0].toLowerCase().equals("cpo=")) {
skullname = p.getUniqueId().toString(); skullname = p.getUniqueId().toString();
mat = plugin.getHeads.playerHeadString(); mat = Material.PLAYER_HEAD.toString();
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
id = 3;
}
} }
if (matraw.split("\\s")[0].equalsIgnoreCase("hdb=")) { if (matraw.split("\\s")[0].equalsIgnoreCase("hdb=")) {
skullname = "hdb"; skullname = "hdb";
mat = plugin.getHeads.playerHeadString(); mat = Material.PLAYER_HEAD.toString();
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
id = 3;
}
} }
//creates custom MMOItems items //creates custom MMOItems items
@ -129,7 +113,7 @@ public class ItemCreation {
} }
if(normalCreation) { if(normalCreation) {
s = new ItemStack(Objects.requireNonNull(Material.matchMaterial(mat)), 1, id); s = new ItemStack(Objects.requireNonNull(Material.matchMaterial(mat)), 1);
} }
if (!skullname.equals("no skull") && !skullname.equals("hdb") && !matraw.split("\\s")[0].equalsIgnoreCase("cpo=")) { if (!skullname.equals("no skull") && !skullname.equals("hdb") && !matraw.split("\\s")[0].equalsIgnoreCase("cpo=")) {
@ -138,7 +122,6 @@ public class ItemCreation {
if (matraw.split("\\s")[1].equalsIgnoreCase("self")) { if (matraw.split("\\s")[1].equalsIgnoreCase("self")) {
//if cps= self //if cps= self
meta = (SkullMeta) s.getItemMeta(); meta = (SkullMeta) s.getItemMeta();
if(!plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
try { try {
assert meta != null; assert meta != null;
meta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(skullname))); meta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(skullname)));
@ -146,9 +129,6 @@ public class ItemCreation {
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " material: cps= self")); p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " material: cps= self"));
plugin.debug(var23,p); plugin.debug(var23,p);
} }
}else{
meta.setOwner(p.getName());
}
s.setItemMeta(meta); s.setItemMeta(meta);
}else if (plugin.tex.placeholdersNoColour(panel,position,p,matraw.split("\\s")[1]).length() <= 16) { }else if (plugin.tex.placeholdersNoColour(panel,position,p,matraw.split("\\s")[1]).length() <= 16) {
//if cps= username //if cps= username
@ -203,7 +183,7 @@ public class ItemCreation {
if(itemSection.isConfigurationSection("nbt." + key)){ if(itemSection.isConfigurationSection("nbt." + key)){
continue; continue;
} }
s = plugin.nbt.setNBT(s,key,plugin.tex.attachPlaceholders(panel, position, p, Objects.requireNonNull(itemSection.getString("nbt." + key)))); //itemSection.getString("nbt." + key)); s = plugin.nbt.setData(s,key,plugin.tex.attachPlaceholders(panel, position, p, Objects.requireNonNull(itemSection.getString("nbt." + key))));
} }
} }
if (itemSection.contains("enchanted")) { if (itemSection.contains("enchanted")) {
@ -290,22 +270,9 @@ public class ItemCreation {
PotionMeta potionMeta = (PotionMeta)s.getItemMeta(); PotionMeta potionMeta = (PotionMeta)s.getItemMeta();
String[] effectType = plugin.tex.placeholdersNoColour(panel,position,p,itemSection.getString("potion")).split("\\s"); String[] effectType = plugin.tex.placeholdersNoColour(panel,position,p,itemSection.getString("potion")).split("\\s");
assert potionMeta != null; assert potionMeta != null;
boolean extended = false; PotionType newData = PotionType.valueOf(effectType[0].toUpperCase());
boolean upgraded = false;
//create data
if(effectType.length >= 2){
if(effectType[1].equalsIgnoreCase("true")){
extended = true;
}
if(effectType.length == 3){
if(effectType[2].equalsIgnoreCase("true")){
upgraded = true;
}
}
}
PotionData newData = new PotionData(PotionType.valueOf(effectType[0].toUpperCase()),extended,upgraded);
//set meta //set meta
potionMeta.setBasePotionData(newData); potionMeta.setBasePotionType(newData);
s.setItemMeta(potionMeta); s.setItemMeta(potionMeta);
} catch (Exception er) { } catch (Exception er) {
//don't add the effect //don't add the effect
@ -316,14 +283,6 @@ public class ItemCreation {
if (itemSection.contains("damage")) { if (itemSection.contains("damage")) {
//change the damage amount (placeholders accepted) //change the damage amount (placeholders accepted)
//if the damage is not unbreakable and should be a value //if the damage is not unbreakable and should be a value
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
try {
s.setDurability(Short.parseShort(Objects.requireNonNull(plugin.tex.placeholders(panel,position,p, itemSection.getString("damage")))));
} catch (Exception e) {
plugin.debug(e, p);
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " damage: " + itemSection.getString("damage")));
}
} else {
if(itemSection.getString("damage").equalsIgnoreCase("-1")){ if(itemSection.getString("damage").equalsIgnoreCase("-1")){
//if the player wants the item to be unbreakable. Only works in non legacy versions //if the player wants the item to be unbreakable. Only works in non legacy versions
ItemMeta unbreak = s.getItemMeta(); ItemMeta unbreak = s.getItemMeta();
@ -334,23 +293,22 @@ public class ItemCreation {
try { try {
Damageable itemDamage = (Damageable) s.getItemMeta(); Damageable itemDamage = (Damageable) s.getItemMeta();
itemDamage.setDamage(Integer.parseInt(Objects.requireNonNull(plugin.tex.placeholders(panel,position,p, itemSection.getString("damage"))))); itemDamage.setDamage(Integer.parseInt(Objects.requireNonNull(plugin.tex.placeholders(panel,position,p, itemSection.getString("damage")))));
s.setItemMeta((ItemMeta) itemDamage); s.setItemMeta(itemDamage);
} catch (Exception e) { } catch (Exception e) {
plugin.debug(e, p); plugin.debug(e, p);
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " damage: " + itemSection.getString("damage"))); p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " damage: " + itemSection.getString("damage")));
} }
} }
}
if (itemSection.contains("nbt")) { if (itemSection.contains("nbt")) {
for(String key : Objects.requireNonNull(itemSection.getConfigurationSection("nbt")).getKeys(true)){ for(String key : Objects.requireNonNull(itemSection.getConfigurationSection("nbt")).getKeys(true)){
if(itemSection.isConfigurationSection("nbt." + key)){ if(itemSection.isConfigurationSection("nbt." + key)){
continue; continue;
} }
s = plugin.nbt.setNBT(s,key,plugin.tex.attachPlaceholders(panel, position, p, Objects.requireNonNull(itemSection.getString("nbt." + key)))); //itemSection.getString("nbt." + key)); s = plugin.nbt.setData(s, key, plugin.tex.attachPlaceholders(panel, position, p, Objects.requireNonNull(itemSection.getString("nbt." + key))));
} }
} }
// 1.20 Trim Feature for Player Armor // 1.20 Trim Feature for Player Armor
if(plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && itemSection.contains("trim")){ if(itemSection.contains("trim")){
// trim: <Material> <Pattern> // trim: <Material> <Pattern>
String trim = itemSection.getString("trim"); String trim = itemSection.getString("trim");
String[] trimList = trim.split("\\s"); String[] trimList = trim.split("\\s");
@ -421,14 +379,9 @@ public class ItemCreation {
} }
} }
} }
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
if (cont.getDurability() != 0 && !cont.getType().toString().equals("SKULL_ITEM")) {
file.set("panels." + panelName + ".item." + i + ".ID", cont.getDurability());
}
}
if(file.contains("panels." + panelName + ".item." + i + ".material")){ 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(Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("%") || Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("=")){
if(!plugin.getHeads.ifSkullOrHead(cont.getType().toString())){ if(!(Material.PLAYER_HEAD == cont.getType())){
file.set("panels." + panelName + ".item." + i + ".material", cont.getType().toString()); file.set("panels." + panelName + ".item." + i + ".material", cont.getType().toString());
} }
}else{ }else{
@ -437,15 +390,11 @@ public class ItemCreation {
}else{ }else{
file.set("panels." + panelName + ".item." + i + ".material", cont.getType().toString()); file.set("panels." + panelName + ".item." + i + ".material", cont.getType().toString());
} }
if(plugin.getHeads.ifSkullOrHead(cont.getType().toString())){ if(Material.PLAYER_HEAD == cont.getType()){
if(!Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("%") && !Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("=")) { if(!Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("%") && !Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("=")) {
SkullMeta meta = (SkullMeta) cont.getItemMeta(); if (plugin.customHeads.getHeadBase64(cont) != null) {
if (plugin.customHeads.getHeadBase64(cont) != null && !plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) { //inject base64 here
//inject base64 here, disable for legacy as is not working
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + plugin.customHeads.getHeadBase64(cont)); 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());
} }
} }
} }
@ -463,11 +412,8 @@ public class ItemCreation {
try { try {
PotionMeta potionMeta = (PotionMeta) cont.getItemMeta(); PotionMeta potionMeta = (PotionMeta) cont.getItemMeta();
assert potionMeta != null; assert potionMeta != null;
PotionData potionData = potionMeta.getBasePotionData(); String potionType = potionMeta.getBasePotionType().toString(); // Gets the potion type as a string rather than bukkit type
PotionType potionType = potionData.getType(); // Gets the potion type as a string rather than bukkit type file.set("panels." + panelName + ".item." + i + ".potion", potionType);
boolean level = potionData.isUpgraded(); // Check if the potion is level II
boolean extended = potionData.isExtended(); // Check if the potion is extended
file.set("panels." + panelName + ".item." + i + ".potion", potionType + " " + extended + " " + level);
}catch(Exception ignore){ }catch(Exception ignore){
//not a banner //not a banner
file.set("panels." + panelName + ".item." + i + ".potion", null); file.set("panels." + panelName + ".item." + i + ".potion", null);
@ -483,9 +429,7 @@ public class ItemCreation {
} }
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()); file.set("panels." + panelName + ".item." + i + ".lore", Objects.requireNonNull(cont.getItemMeta()).getLore());
if(plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_14)){
file.set("panels." + panelName + ".item." + i + ".customdata", Objects.requireNonNull(cont.getItemMeta()).getCustomModelData()); file.set("panels." + panelName + ".item." + i + ".customdata", Objects.requireNonNull(cont.getItemMeta()).getCustomModelData());
}
}catch(Exception n){ }catch(Exception n){
//skip over an item that spits an error //skip over an item that spits an error
} }
@ -534,42 +478,25 @@ public class ItemCreation {
//check for nbt //check for nbt
if(nbtCheck) { if(nbtCheck) {
try { try {
NBTItem nbtitem1 = new NBTItem(one); if(!plugin.nbt.hasSameNBT(one, two)){
NBTItem nbtitem2 = new NBTItem(two);
if (!nbtitem1.equals(nbtitem2)) {
return false; return false;
} }
} catch (Exception ignore) {} } catch (Exception ignore) {}
} }
//check for damage //check for damage
try { try {
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
if(one.getDurability() != two.getDurability()) {
return false;
}
}else {
Damageable tempOne = (Damageable) one.getItemMeta(); Damageable tempOne = (Damageable) one.getItemMeta();
Damageable tempTwo = (Damageable) two.getItemMeta(); Damageable tempTwo = (Damageable) two.getItemMeta();
if(tempOne.getDamage() != tempTwo.getDamage()){ if(tempOne.getDamage() != tempTwo.getDamage()){
return false; return false;
} }
}
} catch (Exception ignore) {} } catch (Exception ignore) {}
//check for potions //check for potions
try { try {
PotionMeta meta1 = (PotionMeta) one.getItemMeta(); PotionMeta meta1 = (PotionMeta) one.getItemMeta();
PotionMeta meta2 = (PotionMeta) two.getItemMeta(); PotionMeta meta2 = (PotionMeta) two.getItemMeta();
//different duration
if(meta1.getBasePotionData().isExtended() != meta2.getBasePotionData().isExtended()){
return false;
}
//different upgrade
if(meta1.getBasePotionData().isUpgraded() != meta2.getBasePotionData().isUpgraded()){
return false;
}
//different potion type //different potion type
if (meta1.getBasePotionData().getType().compareTo(meta2.getBasePotionData().getType()) != 0){ if (meta1.getBasePotionType().toString().compareTo(meta2.getBasePotionType().toString()) != 0){
return false; return false;
} }
}catch(Exception ignore){} }catch(Exception ignore){}

View File

@ -5,14 +5,12 @@ import com.earth2me.essentials.Essentials;
import me.realized.tokenmanager.api.TokenManager; import me.realized.tokenmanager.api.TokenManager;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel; import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -141,18 +139,18 @@ public class Placeholders {
} }
} }
//placeholder to check if an item has NBT %cp-nbt-slot:key% //placeholder to check if an item has a container %cp-container-slot:key%
if(identifier.startsWith("nbt-")) { if(identifier.startsWith("nbt-")) {
try { try {
String slot_key = identifier.replace("nbt-", ""); String slot_key = identifier.replace("nbt-", "");
String value; String value;
value = plugin.nbt.getNBT(p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(slot_key.split(":")[0])),slot_key.split(":")[1]); value = plugin.nbt.getData(p.getOpenInventory().getTopInventory().getItem((int) Double.parseDouble(slot_key.split(":")[0])), slot_key.split(":")[1]);
if(value.isEmpty()){ if(value.isEmpty()){
value = "empty"; value = "";
} }
return value; return value;
}catch (Exception ex){ }catch (Exception ex){
plugin.debug(ex,p); //nbt does not exist or slot does not exist
return ""; return "";
} }
} }
@ -170,8 +168,8 @@ public class Placeholders {
if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) { if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) {
PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
//Returns the value like this <Type>:<Extended>:<Upgraded> Example SLOWNESS:true:false //Returns the value like this <Type> Example SLOWNESS
return potionMeta.getBasePotionData().getType() + ":" + potionMeta.getBasePotionData().isExtended() + ":" + potionMeta.getBasePotionData().isUpgraded(); return potionMeta.getBasePotionType().toString();
} else { } else {
return "empty"; // Item is either null or doesn't have potion meta return "empty"; // Item is either null or doesn't have potion meta
} }
@ -189,10 +187,6 @@ public class Placeholders {
String material; String material;
try { try {
material = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)).getType().toString(); material = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)).getType().toString();
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
//add the ID to the end if it is legacy (eg, material:id)
material = material + ":" + p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)).getData().getData();
}
} catch (NullPointerException er) { } catch (NullPointerException er) {
material = "AIR"; material = "AIR";
} }
@ -238,17 +232,11 @@ public class Placeholders {
if(identifier.startsWith("damaged-")) { if(identifier.startsWith("damaged-")) {
try { try {
String matNumber = identifier.replace("damaged-", ""); String matNumber = identifier.replace("damaged-", "");
boolean damaged = false; boolean damaged;
ItemStack itm = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber)); ItemStack itm = p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(matNumber));
try { try {
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
if(itm.getType().getMaxDurability() != 0) {
damaged = (itm.getType().getMaxDurability() - itm.getDurability()) < itm.getType().getMaxDurability();
}
}else {
Damageable itemDamage = (Damageable) itm.getItemMeta(); Damageable itemDamage = (Damageable) itm.getItemMeta();
damaged = itemDamage.hasDamage(); damaged = itemDamage.hasDamage();
}
} catch (NullPointerException er) { } catch (NullPointerException er) {
damaged = false; damaged = false;
} }

View File

@ -20,9 +20,6 @@ public class Commandpanelsupdate implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (label.equalsIgnoreCase("cpu") || label.equalsIgnoreCase("commandpanelupdate") || label.equalsIgnoreCase("cpanelu")) { if (label.equalsIgnoreCase("cpu") || label.equalsIgnoreCase("commandpanelupdate") || label.equalsIgnoreCase("cpanelu")) {
if (sender.hasPermission("commandpanel.refresh")) { if (sender.hasPermission("commandpanel.refresh")) {
//command /cpu (uses .refresh permission node)
// /cpu <Playername> <Position/ALL>
String name; String name;
Player targetPlayer; Player targetPlayer;
try { try {

View File

@ -5,7 +5,6 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
public class Commandpanelversion implements CommandExecutor { public class Commandpanelversion implements CommandExecutor {
CommandPanels plugin; CommandPanels plugin;

View File

@ -3,7 +3,6 @@ package me.rockyhawk.commandpanels.commandtags.tags.economy;
import me.realized.tokenmanager.api.TokenManager; import me.realized.tokenmanager.api.TokenManager;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent; import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -73,18 +72,7 @@ public class BuyItemTags implements Listener {
} }
} }
@SuppressWarnings("deprecation")
private void giveItem(Player p, String[] args){ private void giveItem(Player p, String[] args){
//legacy ID plugin.inventorySaver.addItem(p,new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2])));
byte id = 0;
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
for (String argsTemp : args) {
if (argsTemp.startsWith("id:")) {
id = Byte.parseByte(argsTemp.replace("id:", ""));
break;
}
}
}
plugin.inventorySaver.addItem(p,new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]),id));
} }
} }

View File

@ -3,7 +3,6 @@ package me.rockyhawk.commandpanels.commandtags.tags.economy;
import me.realized.tokenmanager.api.TokenManager; import me.realized.tokenmanager.api.TokenManager;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent; import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -130,7 +129,7 @@ public class SellItemTags implements Listener {
if (!potion.equals("false")) { if (!potion.equals("false")) {
PotionMeta potionMeta = (PotionMeta) itm.getItemMeta(); PotionMeta potionMeta = (PotionMeta) itm.getItemMeta();
assert potionMeta != null; assert potionMeta != null;
if (!potionMeta.getBasePotionData().getType().name().equalsIgnoreCase(potion)) { if (!potionMeta.getBasePotionType().name().equalsIgnoreCase(potion)) {
p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Your item has the wrong potion effect")); p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Your item has the wrong potion effect"));
return 0; return 0;
} }

View File

@ -4,7 +4,6 @@ import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.PanelCommandEvent; import me.rockyhawk.commandpanels.api.PanelCommandEvent;
import me.rockyhawk.commandpanels.classresources.SerializerUtils; import me.rockyhawk.commandpanels.classresources.SerializerUtils;
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent; import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType; import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
@ -138,11 +137,10 @@ public class BasicTags implements Listener {
if(e.name.equalsIgnoreCase("minimessage=")){ if(e.name.equalsIgnoreCase("minimessage=")){
e.commandTagUsed(); e.commandTagUsed();
//get checks //get checks
boolean isVersionCompatible = plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_18);
boolean isPaper = Bukkit.getServer().getVersion().contains("Paper"); boolean isPaper = Bukkit.getServer().getVersion().contains("Paper");
boolean allowUnsafeMiniMessage = plugin.config.getBoolean("config.allow-unsafe-mini-message"); boolean allowUnsafeMiniMessage = plugin.config.getBoolean("config.allow-unsafe-mini-message");
//do mini message if conditions are met //do mini message if conditions are met
if (isVersionCompatible && (isPaper || allowUnsafeMiniMessage)) { if (isPaper || allowUnsafeMiniMessage) {
Audience player = (Audience) e.p; // Needed because the basic Player from the Event can't send Paper's Components Audience player = (Audience) e.p; // Needed because the basic Player from the Event can't send Paper's Components
Component parsedText = SerializerUtils.serializeText(String.join(" ", e.args)); Component parsedText = SerializerUtils.serializeText(String.join(" ", e.args));
player.sendMessage(parsedText); player.sendMessage(parsedText);

View File

@ -2,7 +2,6 @@ package me.rockyhawk.commandpanels.generatepanels;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel; import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -93,12 +92,7 @@ public class GenUtils implements Listener {
file.set("panels." + date + ".title", "&8Generated " + date); file.set("panels." + date + ".title", "&8Generated " + date);
file.addDefault("panels." + date + ".command", date); file.addDefault("panels." + date + ".command", date);
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
file.set("panels." + date + ".empty", "STAINED_GLASS_PANE");
file.set("panels." + date + ".emptyID", "15");
}else{
file.set("panels." + date + ".empty", "BLACK_STAINED_GLASS_PANE"); file.set("panels." + date + ".empty", "BLACK_STAINED_GLASS_PANE");
}
//add items //add items
file = plugin.itemCreate.generatePanelFile(date,inv,file); file = plugin.itemCreate.generatePanelFile(date,inv,file);

View File

@ -115,7 +115,7 @@ public class Commandpanelrefresher implements Listener {
if(plugin.inventorySaver.hasNormalInventory(p)) { if(plugin.inventorySaver.hasNormalInventory(p)) {
for (ItemStack itm : p.getInventory().getContents()) { for (ItemStack itm : p.getInventory().getContents()) {
if (itm != null) { if (itm != null) {
if (plugin.nbt.hasNBT(itm)) { if (plugin.nbt.hasData(itm,"CommandPanelsItem")) {
p.getInventory().remove(itm); p.getInventory().remove(itm);
} }
} }

View File

@ -1,16 +0,0 @@
package me.rockyhawk.commandpanels.ioclasses;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class GetItemInHand {
CommandPanels plugin;
public GetItemInHand(CommandPanels pl) {
this.plugin = pl;
}
public ItemStack itemInHand(Player p){
return p.getInventory().getItemInMainHand();
}
}

View File

@ -1,17 +0,0 @@
package me.rockyhawk.commandpanels.ioclasses;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class GetItemInHand_Legacy {
CommandPanels plugin;
public GetItemInHand_Legacy(CommandPanels pl) {
this.plugin = pl;
}
@SuppressWarnings("deprecation")
public ItemStack itemInHand(Player p){
return p.getInventory().getItemInHand();
}
}

View File

@ -1,22 +0,0 @@
package me.rockyhawk.commandpanels.ioclasses;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
//get contents
public class GetStorageContents {
CommandPanels plugin;
public GetStorageContents(CommandPanels pl) {
this.plugin = pl;
}
public ItemStack[] getStorageContents(Inventory i){
return i.getContents();
}
public void setStorageContents(Player p, ItemStack[] i){
p.getOpenInventory().getTopInventory().setContents(i);
}
}

View File

@ -1,22 +0,0 @@
package me.rockyhawk.commandpanels.ioclasses;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
//get contents legacy
public class GetStorageContents_Legacy {
CommandPanels plugin;
public GetStorageContents_Legacy(CommandPanels pl) {
this.plugin = pl;
}
public ItemStack[] getStorageContents(Inventory i){
return i.getContents();
}
public void setStorageContents(Player p, ItemStack[] i){
p.getOpenInventory().getTopInventory().setContents(i);
}
}

View File

@ -1,35 +0,0 @@
package me.rockyhawk.commandpanels.ioclasses.legacy;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents;
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents_Legacy;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class LegacyVersion {
CommandPanels plugin;
public MinecraftVersions LOCAL_VERSION;
public LegacyVersion(CommandPanels pl) {
this.plugin = pl;
String VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
LOCAL_VERSION = MinecraftVersions.get(VERSION);
}
public ItemStack[] getStorageContents(Inventory i){
if(LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
return new GetStorageContents_Legacy(plugin).getStorageContents(i);
}else{
return new GetStorageContents(plugin).getStorageContents(i);
}
}
public void setStorageContents(Player p, ItemStack[] i){
if(LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
new GetStorageContents_Legacy(plugin).setStorageContents(p,i);
}else{
new GetStorageContents(plugin).setStorageContents(p,i);
}
}
}

View File

@ -1,49 +0,0 @@
package me.rockyhawk.commandpanels.ioclasses.legacy;
public enum MinecraftVersions {
v1_8( "1_8", 0 ),
v1_9( "1_9", 1 ),
v1_10( "1_10", 2 ),
v1_11( "1_11", 3 ),
v1_12( "1_12", 4 ),
v1_13( "1_13", 5 ),
v1_14( "1_14", 6 ),
v1_15( "1_15", 7 ),
v1_16( "1_16", 8 ),
v1_17( "1_17", 9 ),
v1_18( "1_18", 10 ),
v1_19( "1_19", 11 ),
v1_20( "1_20", 12 ),
v1_21( "1_21", 13 ),
v1_22( "1_22", 14 ),
v1_23( "1_23", 15 ),
v1_24( "1_24", 16 ),
v1_25( "1_25", 17 ),
v1_26( "1_26", 18 );
private int order;
private String key;
MinecraftVersions( String key, int v ) {
this.key = key;
order = v;
}
public boolean greaterThanOrEqualTo( MinecraftVersions other ) {
return order >= other.order;
}
public boolean lessThanOrEqualTo( MinecraftVersions other ) {
return order <= other.order;
}
public static MinecraftVersions get(String v ) {
for ( MinecraftVersions k : MinecraftVersions.values() ) {
if ( v.contains( k.key ) ) {
return k;
}
}
return null;
}
}

View File

@ -1,22 +0,0 @@
package me.rockyhawk.commandpanels.ioclasses.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.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
return "SKULL_ITEM";
}else{
return "PLAYER_HEAD";
}
}
}

View File

@ -1,4 +1,4 @@
package me.rockyhawk.commandpanels.ioclasses.nbt; package me.rockyhawk.commandpanels.nbt;
import de.tr7zw.changeme.nbtapi.NBT; import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTItem; import de.tr7zw.changeme.nbtapi.NBTItem;
@ -11,30 +11,28 @@ public class NBTManager {
this.plugin = pl; this.plugin = pl;
} }
//commandpanel item NBT public boolean hasSameNBT(ItemStack one, ItemStack two){
public boolean hasNBT(ItemStack item){ NBTItem nbtitem1 = new NBTItem(one);
NBTItem nbti = new NBTItem(item); NBTItem nbtitem2 = new NBTItem(two);
return nbti.hasTag("CommandPanelsItem");
return nbtitem1.equals(nbtitem2);
} }
public ItemStack setNBT(ItemStack item){ public ItemStack setData(ItemStack item, String key, String value){
NBT.modify(item, nbt -> {
nbt.setString("CommandPanelsItem", "1");
});
return item;
}
//custom key NBT
public String getNBT(ItemStack item, String key){
NBTItem nbti = new NBTItem(item);
if(!nbti.hasNBTData()) return "";
return nbti.getString(key);
}
public ItemStack setNBT(ItemStack item, String key, String value){
NBT.modify(item, nbt -> { NBT.modify(item, nbt -> {
nbt.setString(key, value); nbt.setString(key, value);
}); });
return item; return item;
} }
public boolean hasData(ItemStack item, String key){
NBTItem nbti = new NBTItem(item);
return nbti.hasTag(key);
}
public String getData(ItemStack item, String key){
NBTItem nbti = new NBTItem(item);
if(!nbti.hasNBTData()) return "";
return nbti.getString(key);
}
} }

View File

@ -141,7 +141,7 @@ public class OpenGUI {
empty = plugin.itemCreate.makeItemFromConfig(panel,position,pconfig.getConfigurationSection("custom-item." + pconfig.getString("empty")),p,true,true,true); empty = plugin.itemCreate.makeItemFromConfig(panel,position,pconfig.getConfigurationSection("custom-item." + pconfig.getString("empty")),p,true,true,true);
}else{ }else{
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(pconfig.getString("empty").toUpperCase())), 1,id); empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(pconfig.getString("empty").toUpperCase())), 1,id);
empty = plugin.nbt.setNBT(empty); empty = plugin.nbt.setData(empty, "CommandPanelsItem", "true");
ItemMeta renamedMeta = empty.getItemMeta(); ItemMeta renamedMeta = empty.getItemMeta();
assert renamedMeta != null; assert renamedMeta != null;
renamedMeta.setDisplayName(" "); renamedMeta.setDisplayName(" ");
@ -175,7 +175,7 @@ public class OpenGUI {
} else if (openType == PanelOpenType.Refresh) { } else if (openType == PanelOpenType.Refresh) {
//openType 0 will just refresh the panel //openType 0 will just refresh the panel
if(position == PanelPosition.Top) { if(position == PanelPosition.Top) {
plugin.legacy.setStorageContents(p, plugin.legacy.getStorageContents(i)); p.getOpenInventory().getTopInventory().setContents(i.getContents());
} }
} else if (openType == PanelOpenType.Return) { } else if (openType == PanelOpenType.Return) {
//will return the inventory, not opening it at all //will return the inventory, not opening it at all

View File

@ -130,9 +130,9 @@ public class OpenPanelsLoader {
} }
} }
public boolean isNBTInjected(ItemStack itm){ public boolean isContainerInjected(ItemStack itm){
if(itm != null){ if(itm != null){
return plugin.nbt.hasNBT(itm); return plugin.nbt.hasData(itm,"CommandPanelsItem");
} }
return false; return false;
} }

View File

@ -32,7 +32,7 @@ public class UtilsPanelsLoader implements Listener {
p.updateInventory(); p.updateInventory();
for(ItemStack itm : p.getInventory().getContents()){ for(ItemStack itm : p.getInventory().getContents()){
if(itm != null){ if(itm != null){
if (plugin.nbt.hasNBT(itm)) { if (plugin.nbt.hasData(itm, "CommandPanelsItem")) {
p.getInventory().remove(itm); p.getInventory().remove(itm);
} }
} }
@ -93,7 +93,7 @@ public class UtilsPanelsLoader implements Listener {
Player p = (Player)e.getWhoClicked(); Player p = (Player)e.getWhoClicked();
if(!plugin.openPanels.hasPanelOpen(p.getName(),PanelPosition.Top)){ if(!plugin.openPanels.hasPanelOpen(p.getName(),PanelPosition.Top)){
for(ItemStack itm : p.getInventory().getContents()){ for(ItemStack itm : p.getInventory().getContents()){
if(plugin.openPanels.isNBTInjected(itm)){ if(plugin.openPanels.isContainerInjected(itm)){
p.getInventory().remove(itm); p.getInventory().remove(itm);
} }
} }

View File

@ -36,7 +36,7 @@ public class HotbarItemLoader {
if(stationaryItems.get(p.getUniqueId()).list.containsKey(String.valueOf(slot))){ if(stationaryItems.get(p.getUniqueId()).list.containsKey(String.valueOf(slot))){
if(openPanel) { if(openPanel) {
try { try {
if (!plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar").split(":")[1].equals(String.valueOf(slot))) { if (!plugin.nbt.getData(p.getInventory().getItem(slot), "CommandPanelsHotbar").split(":")[1].equals(String.valueOf(slot))) {
return false; return false;
} }
}catch(Exception ex){ }catch(Exception ex){
@ -64,7 +64,7 @@ public class HotbarItemLoader {
//return true if found //return true if found
public boolean itemCheckExecute(ItemStack invItem, Player p, boolean openPanel, boolean stationaryOnly){ public boolean itemCheckExecute(ItemStack invItem, Player p, boolean openPanel, boolean stationaryOnly){
try { try {
if (Objects.equals(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar"), "")) { if (Objects.equals(plugin.nbt.getData(invItem, "CommandPanelsHotbar"), "")) {
return false; return false;
} }
}catch(IllegalArgumentException | NullPointerException nu){ }catch(IllegalArgumentException | NullPointerException nu){
@ -73,13 +73,13 @@ public class HotbarItemLoader {
for(Panel panel : plugin.panelList) { for(Panel panel : plugin.panelList) {
if(stationaryOnly){ if(stationaryOnly){
try { try {
if (plugin.nbt.getNBT(invItem, "CommandPanelsHotbar").split(":")[1].equals("-1")) { if (plugin.nbt.getData(invItem, "CommandPanelsHotbar").split(":")[1].equals("-1")) {
continue; continue;
} }
}catch(NullPointerException | IllegalArgumentException ignore){} }catch(NullPointerException | IllegalArgumentException ignore){}
} }
if(panel.hasHotbarItem()){ if(panel.hasHotbarItem()){
if(plugin.nbt.getNBT(invItem,"CommandPanelsHotbar").split(":")[0].equals(panel.getName())){ if(plugin.nbt.getData(invItem,"CommandPanelsHotbar").split(":")[0].equals(panel.getName())){
if(openPanel) { if(openPanel) {
//only open panel automatically if there are no commands and if world is not disabled //only open panel automatically if there are no commands and if world is not disabled
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){ if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
@ -120,9 +120,9 @@ public class HotbarItemLoader {
stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager()); stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager());
for(int i = 0; i <= 35; i++){ for(int i = 0; i <= 35; i++){
try { try {
if (!Objects.equals(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar"), "")) { if (!Objects.equals(plugin.nbt.getData(p.getInventory().getItem(i), "CommandPanelsHotbar"), "")) {
//do not remove items that are not stationary //do not remove items that are not stationary
if(!plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar").endsWith("-1")) { if(!plugin.nbt.getData(p.getInventory().getItem(i), "CommandPanelsHotbar").endsWith("-1")) {
p.getInventory().setItem(i, new ItemStack(Material.AIR)); p.getInventory().setItem(i, new ItemStack(Material.AIR));
} }
} }

View File

@ -1,8 +1,6 @@
package me.rockyhawk.commandpanels.openwithitem; package me.rockyhawk.commandpanels.openwithitem;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.ioclasses.GetItemInHand;
import me.rockyhawk.commandpanels.ioclasses.GetItemInHand_Legacy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -110,17 +108,15 @@ public class UtilsOpenWithItem implements Listener {
try { try {
for (ItemStack s : new ArrayList<>(e.getDrops())) { for (ItemStack s : new ArrayList<>(e.getDrops())) {
try { try {
if (!plugin.nbt.getNBT(s, "CommandPanelsHotbar").isEmpty()) { if (!plugin.nbt.getData(s, "CommandPanelsHotbar").isEmpty()) {
//do not remove items that are not stationary //do not remove items that are not stationary
if (!plugin.nbt.getNBT(s, "CommandPanelsHotbar").endsWith("-1")) { if (!plugin.nbt.getData(s, "CommandPanelsHotbar").endsWith("-1")) {
e.getDrops().remove(s); e.getDrops().remove(s);
} }
} }
} catch (NullPointerException | IllegalArgumentException ignore) {} } catch (NullPointerException | IllegalArgumentException ignore) {}
} }
}catch (NullPointerException ignore){ }catch (NullPointerException ignore){}
System.out.println("crapped out");
}
} }
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent e){ public void onPlayerJoin(PlayerJoinEvent e){
@ -152,11 +148,7 @@ public class UtilsOpenWithItem implements Listener {
//cancel everything if holding item (item frames eg) //cancel everything if holding item (item frames eg)
Player p = e.getPlayer(); Player p = e.getPlayer();
ItemStack clicked; ItemStack clicked;
if(Bukkit.getVersion().contains("1.8")){ clicked = p.getInventory().getItemInMainHand();
clicked = new GetItemInHand_Legacy(plugin).itemInHand(p);
}else{
clicked = new GetItemInHand(plugin).itemInHand(p);
}
if(plugin.hotbar.itemCheckExecute(clicked,p,true,false)){ if(plugin.hotbar.itemCheckExecute(clicked,p,true,false)){
e.setCancelled(true); e.setCancelled(true);
p.updateInventory(); p.updateInventory();