Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/me/rockyhawk/commandpanels/commandtags/tags/economy/BuyItemTags.java
#	src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java
This commit is contained in:
TinyTank800 2024-05-04 10:57:45 -07:00
commit 1f7db8a1d7
32 changed files with 256 additions and 675 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

@ -48,7 +48,6 @@ placeholders:
start: '{' start: '{'
end: '}' end: '}'
updater: updater:
auto-update: false
update-checks: true update-checks: true
purchase: purchase:
currency: currency:

View File

@ -1,10 +1,10 @@
version: 3.20.1.0 version: 3.21.0.0
main: me.rockyhawk.commandpanels.CommandPanels main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels name: CommandPanels
author: RockyHawk author: RockyHawk
api-version: '1.13' api-version: '1.13'
description: Fully Custom GUIs. Make your Server Professional. description: Fully Custom GUIs. Make your Server Professional.
softdepend: [Essentials, PlaceholderAPI, Vault, HeadDatabase, TokenManager, VotingPlugin, MMOItems, ChestSort] softdepend: [Essentials, PlaceholderAPI, Vault, HeadDatabase, TokenManager, VotingPlugin, MMOItems, ChestSort, floodgate]
commands: commands:
commandpanel: commandpanel:
description: Open a command panel. description: Open a command panel.

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,7 +179,11 @@ 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 OpenFloodgateGUI(this), this); this.getServer().getPluginManager().registerEvents(new SwapItemEvent(this), this);
if (this.getServer().getPluginManager().isPluginEnabled("floodgate")) {
this.getServer().getPluginManager().registerEvents(new OpenFloodgateGUI(this), this);
}
//load in the updater if requested //load in the updater if requested
if (Objects.requireNonNull(config.getString("updater.update-checks")).equalsIgnoreCase("true")) { if (Objects.requireNonNull(config.getString("updater.update-checks")).equalsIgnoreCase("true")) {
@ -221,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();
@ -237,23 +232,19 @@ 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)){ //top
FileConfiguration exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("exampleLegacy.yml"))); FileConfiguration exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_top.yml")));
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example.yml")); exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_top.yml"));
}else { //middle one
//top exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_middle_one.yml")));
FileConfiguration exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_top.yml"))); exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_middle_one.yml"));
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_top.yml")); //middle two
//middle one exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_middle_two.yml")));
exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_middle_one.yml"))); exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_middle_two.yml"));
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_middle_one.yml")); //bottom
//middle two exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_bottom.yml")));
exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example_middle_two.yml"))); exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_bottom.yml"));
exampleFileConfiguration.save(new File(this.panelsf + File.separator + "example_middle_two.yml"));
//bottom
exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("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) {
@ -292,7 +283,7 @@ public class CommandPanels extends JavaPlugin{
//save files //save files
panelData.saveDataFile(); panelData.saveDataFile();
inventorySaver.saveInventoryFile(); inventorySaver.saveInventoryFile();
updater.autoUpdatePlugin(this.getFile().getName()); updater.updatePlugin(this.getFile().getName());
Bukkit.getLogger().info("RockyHawk's CommandPanels Plugin Disabled, aww man."); Bukkit.getLogger().info("RockyHawk's CommandPanels Plugin Disabled, aww man.");
} }
@ -315,16 +306,9 @@ 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 renamedMeta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
if(legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20)){ renamedMeta.addItemFlags(ItemFlag.HIDE_DYE);
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);
}
} }
if (customName != null) { if (customName != null) {
renamedMeta.setDisplayName(customName); renamedMeta.setDisplayName(customName);
@ -457,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.");
@ -467,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,16 +122,12 @@ 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))); } catch (Exception var23) {
} catch (Exception var23) { 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) {
@ -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,29 +283,20 @@ 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)) { if(itemSection.getString("damage").equalsIgnoreCase("-1")){
try { //if the player wants the item to be unbreakable. Only works in non legacy versions
s.setDurability(Short.parseShort(Objects.requireNonNull(plugin.tex.placeholders(panel,position,p, itemSection.getString("damage"))))); ItemMeta unbreak = s.getItemMeta();
} catch (Exception e) { unbreak.setUnbreakable(true);
plugin.debug(e, p); s.setItemMeta(unbreak);
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 the player wants the item to be unbreakable. Only works in non legacy versions
ItemMeta unbreak = s.getItemMeta();
unbreak.setUnbreakable(true);
s.setItemMeta(unbreak);
}
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")) {
@ -346,11 +304,11 @@ 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))));
} }
} }
// 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)){ Damageable tempOne = (Damageable) one.getItemMeta();
if(one.getDurability() != two.getDurability()) { Damageable tempTwo = (Damageable) two.getItemMeta();
return false; if(tempOne.getDamage() != tempTwo.getDamage()){
} return false;
}else {
Damageable tempOne = (Damageable) one.getItemMeta();
Damageable tempTwo = (Damageable) two.getItemMeta();
if(tempOne.getDamage() != tempTwo.getDamage()){
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)){ Damageable itemDamage = (Damageable) itm.getItemMeta();
if(itm.getType().getMaxDurability() != 0) { damaged = itemDamage.hasDamage();
damaged = (itm.getType().getMaxDurability() - itm.getDurability()) < itm.getType().getMaxDurability();
}
}else {
Damageable itemDamage = (Damageable) itm.getItemMeta();
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;
@ -13,7 +12,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.*; import java.util.Objects;
public class BuyItemTags implements Listener { public class BuyItemTags implements Listener {
CommandPanels plugin; CommandPanels plugin;
@ -25,13 +24,13 @@ public class BuyItemTags implements Listener {
public void commandTag(CommandTagEvent e){ public void commandTag(CommandTagEvent e){
if(e.name.equalsIgnoreCase("buy=")){ if(e.name.equalsIgnoreCase("buy=")){
e.commandTagUsed(); e.commandTagUsed();
//if player uses buy= it will be eg. buy= <price> <item> <amount of item> [id:#] //if player uses buy= it will be eg. buy= <price> <item> <amount of item> <ID>
try { try {
if (plugin.econ != null) { if (plugin.econ != null) {
if (plugin.econ.getBalance(e.p) >= Double.parseDouble(e.args[0])) { if (plugin.econ.getBalance(e.p) >= Double.parseDouble(e.args[0])) {
plugin.econ.withdrawPlayer(e.p, Double.parseDouble(e.args[0])); plugin.econ.withdrawPlayer(e.p, Double.parseDouble(e.args[0]));
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", e.args[0])); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.success")).replaceAll("%cp-args%", e.args[0]));
giveItem(e.p, e); giveItem(e.p, e.args);
} else { } else {
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure"))); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.currency.failure")));
@ -47,7 +46,7 @@ public class BuyItemTags implements Listener {
} }
if(e.name.equalsIgnoreCase("tokenbuy=")) { if(e.name.equalsIgnoreCase("tokenbuy=")) {
e.commandTagUsed(); e.commandTagUsed();
//if player uses tokenbuy= it will be eg. tokenbuy= <price> <item> <amount of item> [id:#] //if player uses tokenbuy= it will be eg. tokenbuy= <price> <item> <amount of item> <ID>
try { try {
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
final TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); final TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
@ -58,7 +57,7 @@ public class BuyItemTags implements Listener {
plugin.tex.sendMessage(e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", e.args[0])); plugin.tex.sendMessage(e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", e.args[0]));
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", e.args[0])); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.success")).replaceAll("%cp-args%", e.args[0]));
giveItem(e.p, e); giveItem(e.p,e.args);
} else { } else {
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure"))); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.tokens.failure")));
@ -73,28 +72,7 @@ public class BuyItemTags implements Listener {
} }
} }
@SuppressWarnings("deprecation") private void giveItem(Player p, String[] args){
private void giveItem(Player p, CommandTagEvent e){ plugin.inventorySaver.addItem(p,new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2])));
String[] args = e.args;
//legacy ID
byte id = 0;
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
for (String arg : args) {
if (arg.startsWith("id:")) {
id = Byte.parseByte(arg.replace("id:", ""));
break;
}
}
}
ItemStack buyItem;
if (Material.matchMaterial(args[1]) == null) {
buyItem = plugin.itemCreate.makeCustomItemFromConfig(e.panel, PanelPosition.Top, e.panel.getConfig().getConfigurationSection("custom-item." + args[1]), e.p, true, true, false);
buyItem.setAmount(Integer.parseInt(args[2]));
} else {
buyItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]), id);
}
plugin.inventorySaver.addItem(p,buyItem);
} }
} }

View File

@ -11,8 +11,12 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class SellItemTags implements Listener { public class SellItemTags implements Listener {
CommandPanels plugin; CommandPanels plugin;
@ -24,15 +28,15 @@ public class SellItemTags implements Listener {
public void commandTag(CommandTagEvent e){ public void commandTag(CommandTagEvent e){
if(e.name.equalsIgnoreCase("sell=")){ if(e.name.equalsIgnoreCase("sell=")){
e.commandTagUsed(); e.commandTagUsed();
//if player uses sell= it will be eg. sell= <total cashback> <item> <amount of item> [IGNORENBT] //if player uses sell= it will be eg. sell= <total cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP] [custom-data:#]
try { try {
if (plugin.econ != null) { if (plugin.econ != null) {
int sold = removeItem(e.p, e, false); int sold = removeItem(e.p, e.args, false);
if (sold <= 0) { if (sold <= 0) {
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure"))); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
} else { } else {
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0])); plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]));
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", sold + " " + e.args[1]).replaceAll("%cp-args2%", "$" + e.args[0])); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]).replaceAll("%cp-args2%", "$" + e.args[0]));
} }
} else { } else {
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!"); plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!");
@ -45,15 +49,15 @@ public class SellItemTags implements Listener {
} }
if(e.name.equalsIgnoreCase("sellall=")){ if(e.name.equalsIgnoreCase("sellall=")){
e.commandTagUsed(); e.commandTagUsed();
//if player uses sell-all= it will be eg. sell-all= <Per Item Cashback> <item> [IGNORENBT] //if player uses sell-all= it will be eg. sell-all= <Per Item Cashback> <item> [enchanted:KNOCKBACK:1] [potion:JUMP]
try { try {
if (plugin.econ != null) { if (plugin.econ != null) {
int sold = removeItem(e.p, e, true); int sold = removeItem(e.p, e.args, true);
if (sold <= 0) { if (sold <= 0) {
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure"))); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
} else { } else {
plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]) * sold); plugin.econ.depositPlayer(e.p, Double.parseDouble(e.args[0]) * sold);
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", sold + " " + e.args[1]).replaceAll("%cp-args2%", String.valueOf(Double.parseDouble(e.args[0]) * sold))); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]).replaceAll("%cp-args2%", "$" + Double.parseDouble(e.args[0]) * sold));
} }
} else { } else {
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!"); plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires Vault and an Economy to work!");
@ -66,17 +70,17 @@ public class SellItemTags implements Listener {
} }
if(e.name.equalsIgnoreCase("tokensell=")) { if(e.name.equalsIgnoreCase("tokensell=")) {
e.commandTagUsed(); e.commandTagUsed();
//if player uses tokensell= it will be eg. tokensell= <cashback> <item> <amount of item> [IGNORENBT] //if player uses tokensell= it will be eg. tokensell= <cashback> <item> <amount of item> [enchanted:KNOCKBACK:1] [potion:JUMP]
try { try {
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) { if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
final TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager"); final TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
int sold = removeItem(e.p, e, false); int sold = removeItem(e.p, e.args, false);
if (sold <= 0) { if (sold <= 0) {
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure"))); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
} else { } else {
assert api != null; assert api != null;
api.addTokens(e.p, Long.parseLong(e.args[0])); api.addTokens(e.p, Long.parseLong(e.args[0]));
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", sold + " " + e.args[1])); plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", e.args[1]));
} }
} else { } else {
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires TokenManager to work!"); plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires TokenManager to work!");
@ -86,194 +90,115 @@ public class SellItemTags implements Listener {
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name); plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
} }
} }
if(e.name.equalsIgnoreCase("tokensellall=")){
e.commandTagUsed();
//if player uses tokensellall= it will be eg. tokensellall= <cashback> <item> [IGNORENBT]
try {
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
final TokenManager api = (TokenManager) Bukkit.getServer().getPluginManager().getPlugin("TokenManager");
int sold = removeItem(e.p, e, true);
if (sold <= 0) {
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.failure")));
} else {
assert api != null;
api.addTokens(e.p, Long.parseLong(e.args[0]));
plugin.tex.sendString(e.panel, PanelPosition.Top, e.p, Objects.requireNonNull(plugin.config.getString("purchase.item.success")).replaceAll("%cp-args%", sold + " " + e.args[1]));
}
} else {
plugin.tex.sendMessage(e.p, ChatColor.RED + "Selling Requires TokenManager to work!");
}
} catch (Exception sell) {
plugin.debug(sell,e.p);
plugin.tex.sendMessage(e.p, plugin.config.getString("config.format.error") + " " + "commands: " + e.name);
}
return;
}
} }
//returns false if player does not have item //returns false if player does not have item
private int removeItem(Player p, CommandTagEvent e, boolean removeAll){ private int removeItem(Player p, String[] args, boolean removeAll){
String[] args = e.args;
//get inventory slots and then an empty list to store slots that have the item to sell //get inventory slots and then an empty list to store slots that have the item to sell
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
HashMap<Integer, ItemStack> remCont = new HashMap<>(); List<ItemStack> remCont = new ArrayList<>();
int count = 0; byte id = -1;
String potion = "false";
try { int customData = 0;
int id = -1; boolean noCustom = false;
for (String val : args) { for(String argsTemp : args){
if (val.startsWith("id:")) { if(argsTemp.startsWith("potion:")){
id = Integer.parseInt(val.substring(3)); potion = argsTemp.replace("potion:","");
}
} }
if (argsTemp.startsWith("id:")) {
ItemStack sellItem; id = Byte.parseByte(argsTemp.replace("id:", ""));
if (Material.matchMaterial(args[1]) == null) {
sellItem = plugin.itemCreate.makeCustomItemFromConfig(e.panel, PanelPosition.Top, e.panel.getConfig().getConfigurationSection("custom-item." + args[1]), e.p, true, true, false);
if(!removeAll){
sellItem.setAmount(Integer.parseInt(args[2]));
} else {
sellItem.setAmount(1);
}
} else {
if(!removeAll){
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]));
} else {
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])));
}
} }
if (argsTemp.startsWith("custom-data:")) {
//This is here for when people want to take nbt items like spawners with types in a check for spawners. customData = Integer.parseInt(argsTemp.replace("custom-data:", ""));
boolean ignoreNBT = false;
for(String arg : args){
if (arg.equalsIgnoreCase("IGNORENBT")) {
ignoreNBT = true;
break;
}
} }
if (argsTemp.contains("NOCUSTOMDATA")) {
noCustom = true;
}
}
int remainingAmount = removeAll ? 0 : sellItem.getAmount(); //create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount)
//loop through items in the inventory ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), removeAll ? 0 : Integer.parseInt(args[2]));
for (int f = 0; f < 36; f++) { int remainingAmount = removeAll ? 0 : sellItem.getAmount();
for (int f = 0; f < 36; f++) {
if (cont.get(f) == null) { ItemStack itm = cont.get(f);
//skip slot if empty ItemStack remItm;
continue; if (itm != null && itm.getType().equals(sellItem.getType())) {
} remItm = new ItemStack(itm.getType(), itm.getAmount(), (short)f);
//check to ensure any extensions are checked
ItemStack itm = cont.get(f); try {
if (!potion.equals("false")) {
if (Material.matchMaterial(args[1]) == null) { PotionMeta potionMeta = (PotionMeta) itm.getItemMeta();
//if custom item is a mmo item (1.14+ for the API) assert potionMeta != null;
try { if (!potionMeta.getBasePotionType().name().equalsIgnoreCase(potion)) {
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && e.panel.getConfig().getString("custom-item." + args[1] + ".material").startsWith("mmo=")) { p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Your item has the wrong potion effect"));
String customItemMaterial = e.panel.getConfig().getString("custom-item." + args[1] + ".material"); return 0;
String mmoType = customItemMaterial.split("\\s")[1]; }
String mmoID = customItemMaterial.split("\\s")[2]; }
//Check if the item matches the id set. If not continue to next in loop.
if (plugin.isMMOItem(itm, mmoType, mmoID)) { if(id != -1 && itm.getDurability() != id){
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount()); continue;
remainingAmount -= add.getAmount(); }
remCont.put(f,add); //Check if noCustom is set and if the item has custom data. If so continue to next in loop.
if (remainingAmount <= 0 && !removeAll) { if(noCustom && cont.get(f).hasItemMeta()){
break; if(Objects.requireNonNull(cont.get(f).getItemMeta()).hasCustomModelData()){
} continue;
}
}
//Check if custom model data is set and if the item has that data. If not continue to next in loop.
if (customData != 0) {
if (!itm.hasItemMeta()) {
continue;
} else {
if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){
continue;
} }
continue; //This stops the other custom item section from reading and adding false numbers.
}
} catch (Exception ex) {
plugin.debug(ex, p);
}
//item-paywall is a custom item as it is not a material
if (plugin.itemCreate.isIdentical(sellItem, itm, Objects.requireNonNull(e.panel.getConfig().getConfigurationSection("custom-item." + args[1])).contains("nbt"))) {
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount());
remainingAmount -= add.getAmount();
remCont.put(f,add);
if (remainingAmount <= 0 && !removeAll) {
break;
} }
} }
}catch(Exception exc){
//skip if it cannot do unless plugin.debug is enabled
plugin.debug(exc,p);
}
remCont.add(remItm);
//if the remaining amount has been reached, break otherwise sell all
if (!removeAll) {
remainingAmount -= remItm.getAmount();
if (remainingAmount <= 0) {
break;
}
} else { } else {
//if the item is a standard material sellItem.setAmount(sellItem.getAmount() + remItm.getAmount());
if (itm.getType() == sellItem.getType()) {
//If item has custom meta continue to next item.
if(itm.hasItemMeta() && !ignoreNBT){
continue;
}
//Check if the item matches the id set. If not continue to next in loop.
if (id != -1 && itm.getDurability() != id) {
continue;
}
//Adding item to the remove list then checking if we have reached the required amount.
ItemStack add = new ItemStack(itm.getType(), itm.getAmount());
remainingAmount -= add.getAmount();
remCont.put(f,add);
if (remainingAmount <= 0 && !removeAll) {
break;
}
}
} }
} }
}
if (remainingAmount <= 0 && !removeAll) { if(remainingAmount <= 0){
//Only remove if passed requirement int removedItems = 0;
for(Map.Entry<Integer, ItemStack> entry : remCont.entrySet()) { for (int f = 0; f <= remCont.size() - 1; f++) {
ItemStack remItem = entry.getValue(); ItemStack remItm = remCont.get(f);
if(f == remCont.size() - 1){
//Check if its the last item in the loop and only subtract the remaining amount. if(plugin.inventorySaver.hasNormalInventory(p)){
if (sellItem.getAmount() < remItem.getAmount()) { p.getInventory().getItem(remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
if (plugin.inventorySaver.hasNormalInventory(p)) {
p.getInventory().getItem(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
count += remItem.getAmount();
p.updateInventory();
} else {
cont.get(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
count += remItem.getAmount();
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
}
} else { //If its anywhere but the last in loop just get rid of the items.
if (plugin.inventorySaver.hasNormalInventory(p)) {
p.getInventory().setItem(entry.getKey(), null);
count += remItem.getAmount();
p.updateInventory();
} else {
cont.remove(entry.getValue());
count += remItem.getAmount();
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
}
}
sellItem.setAmount(sellItem.getAmount() - remItem.getAmount());
}
} else if(remainingAmount <= 0){
//Remove all. Used for sellall=
for(Map.Entry<Integer, ItemStack> entry : remCont.entrySet()) {
ItemStack remItem = entry.getValue();
if (plugin.inventorySaver.hasNormalInventory(p)) {
p.getInventory().setItem(entry.getKey(), null);
count += remItem.getAmount();
p.updateInventory(); p.updateInventory();
} else { }else{
cont.remove(entry.getValue()); cont.get(remItm.getDurability()).setAmount(remItm.getAmount() - sellItem.getAmount());
count += remItem.getAmount(); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
}
} else {
if(plugin.inventorySaver.hasNormalInventory(p)){
p.getInventory().getItem(remItm.getDurability()).setAmount(0);
p.updateInventory();
}else{
cont.get(remItm.getDurability()).setAmount(0);
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0]))); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
} }
} }
removedItems += remItm.getAmount();
sellItem.setAmount(sellItem.getAmount() - remItm.getAmount());
} }
return removedItems;
//Return how many were sold.
return count;
} catch (Exception buyc) {
//Error somewhere in sell= process.
plugin.debug(buyc, p);
plugin.tex.sendString(p, plugin.tag + plugin.config.getString("config.format.error") + " " + "commands: sell=/sellall=");
return 0; //Return 0 showing failure.
} }
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

@ -52,18 +52,26 @@ public class CommandPanelsEditor implements CommandExecutor {
// Prepend "fileName: {name}" and "filePath: {relativePath}" to the YAML content // Prepend "fileName: {name}" and "filePath: {relativePath}" to the YAML content
String yamlWithFileNameAndPath = "fileName: " + (relativePath.replaceFirst("[.][^.]+$", "")) + "\n" + fileContents; String yamlWithFileNameAndPath = "fileName: " + (relativePath.replaceFirst("[.][^.]+$", "")) + "\n" + fileContents;
byte[] contentBytes = yamlWithFileNameAndPath.getBytes(StandardCharsets.UTF_8);
// Create a clickable text component with the modified YAML content //65535 is maximum value that can be represented by an unsigned 16-bit binary number
BaseComponent[] components = new ComponentBuilder(plugin.tag + if (contentBytes.length > 65535) {
net.md_5.bungee.api.ChatColor.GREEN + "Click here to copy " + // If the content is too large, notify the player to use a different method
net.md_5.bungee.api.ChatColor.WHITE + panel.getFile().getName() + sender.sendMessage(plugin.tag + ChatColor.RED +
net.md_5.bungee.api.ChatColor.GREEN + " to the clipboard!") "Content too long to paste in chat. Please copy and paste the panel file into the editor manually.");
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yamlWithFileNameAndPath)) } else {
.create(); // Safe to send
BaseComponent[] components = new ComponentBuilder(plugin.tag +
net.md_5.bungee.api.ChatColor.GREEN + "Click here to copy " +
net.md_5.bungee.api.ChatColor.WHITE + panel.getFile().getName() +
net.md_5.bungee.api.ChatColor.GREEN + " to the clipboard!")
.event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yamlWithFileNameAndPath))
.create();
Player player = (Player) sender;
player.spigot().sendMessage(components);
}
// Send the clickable text to the player
Player player = (Player) sender;
player.spigot().sendMessage(components);
return true; return true;
} }
} }

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", "BLACK_STAINED_GLASS_PANE");
file.set("panels." + date + ".empty", "STAINED_GLASS_PANE");
file.set("panels." + date + ".emptyID", "15");
}else{
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();

View File

@ -104,7 +104,7 @@ public class Updater implements Listener {
} }
//the pluginFileName can only be obtained from the main class //the pluginFileName can only be obtained from the main class
public void autoUpdatePlugin(String pluginFileName){ public void updatePlugin(String pluginFileName){
if (Objects.requireNonNull(plugin.config.getString("updater.update-checks")).equalsIgnoreCase("false")) { if (Objects.requireNonNull(plugin.config.getString("updater.update-checks")).equalsIgnoreCase("false")) {
return; return;
} }
@ -113,23 +113,20 @@ public class Updater implements Listener {
String thisVersion = plugin.getDescription().getVersion(); String thisVersion = plugin.getDescription().getVersion();
//manual download, only if it was requested //manual download, only if it was requested
if(downloadVersionManually != null) { if(downloadVersionManually == null) {
if (downloadVersionManually.equals("latest")) {
downloadFile(latestVersion, pluginFileName);
}else{
downloadFile(downloadVersionManually, pluginFileName);
}
return; return;
} }
if (downloadVersionManually.equals("latest")) {
downloadFile(latestVersion, pluginFileName);
}else{
downloadFile(downloadVersionManually, pluginFileName);
}
if(latestVersion.equals(thisVersion) || thisVersion.contains("-")){ if(latestVersion.equals(thisVersion) || thisVersion.contains("-")){
//no need to update or running custom version //no need to update or running custom version
return; return;
} }
if (Objects.requireNonNull(plugin.config.getString("updater.auto-update")).equalsIgnoreCase("false")) {
//return if auto-update is false
return;
}
if(thisVersion.split("\\.")[1].equals(latestVersion.split("\\.")[1]) && thisVersion.split("\\.")[0].equals(latestVersion.split("\\.")[0])){ if(thisVersion.split("\\.")[1].equals(latestVersion.split("\\.")[1]) && thisVersion.split("\\.")[0].equals(latestVersion.split("\\.")[0])){
//only update if the latest version is a minor update //only update if the latest version is a minor update
//the first and second number of the version is the same, updates: [major.major.minor.minor] //the first and second number of the version is the same, updates: [major.major.minor.minor]