forked from Upstream/CommandPanels
Merge pull request #293 from TinyTank800/master
Additions, QOL changes, Fixes...
This commit is contained in:
commit
614a9c77d5
@ -18,6 +18,10 @@ commands:
|
||||
description: Change data values for players
|
||||
usage: /commandpaneldata
|
||||
aliases: [cpdata]
|
||||
commandpanelupdate:
|
||||
description: Refresh/update panel/s for player
|
||||
usage: /commandpanelupdate
|
||||
aliases: [ cpu, cpanelu ]
|
||||
commandpaneldebug:
|
||||
description: Enable and Disable debug mode globally
|
||||
usage: /commandpaneldebug
|
||||
@ -73,6 +77,8 @@ permissions:
|
||||
default: op
|
||||
commandpanel.data:
|
||||
default: op
|
||||
commandpanel.refresh:
|
||||
default: op
|
||||
commandpanel.edit:
|
||||
default: op
|
||||
commandpanel.list:
|
||||
|
@ -18,6 +18,7 @@ import me.rockyhawk.commandpanels.classresources.placeholders.Placeholders;
|
||||
import me.rockyhawk.commandpanels.commands.*;
|
||||
import me.rockyhawk.commandpanels.commandtags.CommandTags;
|
||||
import me.rockyhawk.commandpanels.completetabs.CpTabComplete;
|
||||
import me.rockyhawk.commandpanels.completetabs.UpdateTabComplete;
|
||||
import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom;
|
||||
import me.rockyhawk.commandpanels.datamanager.DebugManager;
|
||||
import me.rockyhawk.commandpanels.datamanager.PanelDataLoader;
|
||||
@ -160,6 +161,9 @@ public class CommandPanels extends JavaPlugin{
|
||||
Objects.requireNonNull(this.getCommand("commandpaneldata")).setTabCompleter(new DataTabComplete(this));
|
||||
Objects.requireNonNull(this.getCommand("commandpaneldata")).setExecutor(new Commandpanelsdata(this));
|
||||
|
||||
Objects.requireNonNull(this.getCommand("commandpanelupdate")).setTabCompleter(new UpdateTabComplete(this));
|
||||
Objects.requireNonNull(this.getCommand("commandpanelupdate")).setExecutor(new Commandpanelsupdate(this));
|
||||
|
||||
Objects.requireNonNull(this.getCommand("commandpanelimport")).setExecutor(new CommandPanelImport(this));
|
||||
Objects.requireNonNull(this.getCommand("commandpanelimport")).setTabCompleter(new ImportTabComplete(this));
|
||||
Objects.requireNonNull(this.getCommand("commandpaneledit")).setExecutor(new CommandPanelsEditor(this));
|
||||
|
@ -1,5 +1,8 @@
|
||||
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.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
@ -194,8 +197,13 @@ public class ItemCreation {
|
||||
}
|
||||
}
|
||||
|
||||
if(addNBT){
|
||||
s = plugin.nbt.setNBT(s);
|
||||
if(addNBT && itemSection.contains("nbt")){
|
||||
for(String key : Objects.requireNonNull(itemSection.getConfigurationSection("nbt")).getKeys(true)){
|
||||
if(itemSection.isConfigurationSection("nbt." + key)){
|
||||
continue;
|
||||
}
|
||||
s = plugin.nbt.setNBT(s,key,plugin.tex.attachPlaceholders(panel, position, p, Objects.requireNonNull(itemSection.getString("nbt." + key)))); //itemSection.getString("nbt." + key));
|
||||
}
|
||||
}
|
||||
if (itemSection.contains("enchanted")) {
|
||||
try {
|
||||
@ -333,8 +341,11 @@ public class ItemCreation {
|
||||
}
|
||||
}
|
||||
if (itemSection.contains("nbt")) {
|
||||
for(String key : itemSection.getConfigurationSection("nbt").getKeys(false)){
|
||||
s = plugin.nbt.setNBT(s,key,itemSection.getString("nbt." + key));
|
||||
for(String key : Objects.requireNonNull(itemSection.getConfigurationSection("nbt")).getKeys(true)){
|
||||
if(itemSection.isConfigurationSection("nbt." + key)){
|
||||
continue;
|
||||
}
|
||||
s = plugin.nbt.setNBT(s,key,plugin.tex.attachPlaceholders(panel, position, p, Objects.requireNonNull(itemSection.getString("nbt." + key)))); //itemSection.getString("nbt." + key));
|
||||
}
|
||||
}
|
||||
// 1.20 Trim Feature for Player Armor
|
||||
@ -474,6 +485,13 @@ public class ItemCreation {
|
||||
if(plugin.legacy.LOCAL_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_14)){
|
||||
file.set("panels." + panelName + ".item." + i + ".customdata", Objects.requireNonNull(cont.getItemMeta()).getCustomModelData());
|
||||
}
|
||||
try {
|
||||
ReadWriteNBT nbt = NBT.itemStackToNBT(cont);
|
||||
file.set("panels." + panelName + ".item." + i + ".nbt", nbt.toString());
|
||||
}catch(Exception ignore){
|
||||
//no nbt or error
|
||||
file.set("panels." + panelName + ".item." + i + ".nbt", null);
|
||||
}
|
||||
}catch(Exception n){
|
||||
//skip over an item that spits an error
|
||||
}
|
||||
@ -487,11 +505,14 @@ public class ItemCreation {
|
||||
Material, Name, Lore, Enchanted, Potion
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isIdentical(ItemStack one, ItemStack two){
|
||||
public boolean isIdentical(ItemStack one, ItemStack two, Boolean nbtCheck){
|
||||
//check material
|
||||
if (one.getType() != two.getType()) {
|
||||
return false;
|
||||
}
|
||||
if(one.hasItemMeta() != two.hasItemMeta()){
|
||||
return false;
|
||||
}
|
||||
//check for name
|
||||
try {
|
||||
if (!one.getItemMeta().getDisplayName().equals(two.getItemMeta().getDisplayName())) {
|
||||
@ -508,6 +529,17 @@ public class ItemCreation {
|
||||
}
|
||||
}
|
||||
}catch(Exception ignore){}
|
||||
//check for nbt
|
||||
if(nbtCheck) {
|
||||
try {
|
||||
NBTItem nbtitem1 = new NBTItem(one);
|
||||
NBTItem nbtitem2 = new NBTItem(two);
|
||||
|
||||
if (!nbtitem1.equals(nbtitem2)) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
//check for damage
|
||||
try {
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
|
||||
|
@ -11,6 +11,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -145,7 +147,7 @@ public class Placeholders {
|
||||
String slot_key = identifier.replace("nbt-", "");
|
||||
String value;
|
||||
value = plugin.nbt.getNBT(p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(slot_key.split(":")[0])),slot_key.split(":")[1]);
|
||||
if(value == null){
|
||||
if(value.isEmpty()){
|
||||
value = "empty";
|
||||
}
|
||||
return value;
|
||||
@ -155,6 +157,30 @@ public class Placeholders {
|
||||
}
|
||||
}
|
||||
|
||||
// Placeholder to check if an item has POTION data %cp-potion-slot%
|
||||
if (identifier.startsWith("potion-")) {
|
||||
try {
|
||||
String slot_key = identifier.replace("potion-", "");
|
||||
int slotIndex = (int) Double.parseDouble(slot_key);
|
||||
|
||||
// Get the item in the specified slot
|
||||
ItemStack item = p.getOpenInventory().getTopInventory().getItem(slotIndex);
|
||||
|
||||
// Check if the item is not null and has potion meta
|
||||
if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof PotionMeta) {
|
||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||
|
||||
//Returns the value like this <Type>:<Extended>:<Upgraded> Example SLOWNESS:true:false
|
||||
return potionMeta.getBasePotionData().getType() + ":" + potionMeta.getBasePotionData().isExtended() + ":" + potionMeta.getBasePotionData().isUpgraded();
|
||||
} else {
|
||||
return "empty"; // Item is either null or doesn't have potion meta
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
plugin.debug(ex, p);
|
||||
return ""; // Handle exceptions as needed
|
||||
}
|
||||
}
|
||||
|
||||
//DO placeholders for detection of other items in a panel
|
||||
//get material value from slot in current open inventory (panel)
|
||||
if(identifier.startsWith("material-")) {
|
||||
@ -249,7 +275,7 @@ public class Placeholders {
|
||||
try {
|
||||
//if it is a regular custom item
|
||||
ItemStack confItm = plugin.itemCreate.makeItemFromConfig(panel,position,panel.getConfig().getConfigurationSection("custom-item." + matLoc),p,true,true, false);
|
||||
if(plugin.itemCreate.isIdentical(confItm,itm)){
|
||||
if(plugin.itemCreate.isIdentical(confItm,itm, Objects.requireNonNull(panel.getConfig().getConfigurationSection("custom-item." + matLoc)).contains("nbt"))){
|
||||
isIdentical = true;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,72 @@
|
||||
package me.rockyhawk.commandpanels.commands;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
|
||||
public class Commandpanelsupdate implements CommandExecutor {
|
||||
CommandPanels plugin;
|
||||
public Commandpanelsupdate(CommandPanels pl) { this.plugin = pl; }
|
||||
|
||||
@EventHandler
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (label.equalsIgnoreCase("cpu") || label.equalsIgnoreCase("commandpanelupdate") || label.equalsIgnoreCase("cpanelu")) {
|
||||
if (sender.hasPermission("commandpanel.refresh")) {
|
||||
//command /cpu
|
||||
// /cpu <Playername> <Position/ALL>
|
||||
|
||||
String name;
|
||||
Player targetPlayer;
|
||||
try {
|
||||
name = args[0];
|
||||
targetPlayer = Bukkit.getPlayer(name);
|
||||
}catch (Exception e){
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Player was not found."));
|
||||
return true;
|
||||
}
|
||||
assert targetPlayer != null;
|
||||
|
||||
PanelPosition pp;
|
||||
if(args[1].equalsIgnoreCase("all")){
|
||||
for(PanelPosition papo : PanelPosition.values()){
|
||||
if(plugin.openPanels.hasPanelOpen(name, papo)) {
|
||||
plugin.createGUI.openGui(plugin.openPanels.getOpenPanel(name, papo), targetPlayer, papo, PanelOpenType.Refresh, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
pp = PanelPosition.valueOf(args[1]);
|
||||
}catch (Exception e){
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Panel position not found."));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(plugin.openPanels.hasPanelOpen(name, pp)) {
|
||||
plugin.createGUI.openGui(plugin.openPanels.getOpenPanel(name, pp), targetPlayer, pp, PanelOpenType.Refresh, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(plugin.inventorySaver.hasNormalInventory(targetPlayer)){
|
||||
plugin.hotbar.updateHotbarItems(targetPlayer);
|
||||
}
|
||||
|
||||
//Successfully refreshed panel for targetPlayer.getName()
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.GREEN + "Successfully refreshed panel for " + targetPlayer.getName() + "."));
|
||||
}else{
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms")));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpu <Playername> <Position/ALL>"));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -20,10 +20,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
public class CommandTags {
|
||||
CommandPanels plugin;
|
||||
@ -150,9 +147,12 @@ public class CommandTags {
|
||||
public PaywallOutput commandPayWall(Panel panel, Player p, String rawCommand, boolean removal) { //return 0 means no funds, 1 is they passed and 2 means paywall is not this command
|
||||
|
||||
//create new instance of command but with placeholders parsed
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
switch (command.split("\\s")[0]) {
|
||||
switch (rawCommand.split("\\s")[0]) {
|
||||
default: {
|
||||
return PaywallOutput.NotApplicable;
|
||||
}
|
||||
case "paywall=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses paywall= [price]
|
||||
try {
|
||||
if (plugin.econ != null) {
|
||||
@ -179,6 +179,7 @@ public class CommandTags {
|
||||
}
|
||||
}
|
||||
case "hasperm=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses hasperm= [perm]
|
||||
if (p.hasPermission(String.valueOf(command.split("\\s")[1]))) {
|
||||
if (plugin.config.getBoolean("purchase.permission.enable") && removal) {
|
||||
@ -195,6 +196,7 @@ public class CommandTags {
|
||||
|
||||
}
|
||||
case "tokenpaywall=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses tokenpaywall= [price]
|
||||
try {
|
||||
if (plugin.getServer().getPluginManager().isPluginEnabled("TokenManager")) {
|
||||
@ -228,25 +230,17 @@ public class CommandTags {
|
||||
}
|
||||
}
|
||||
case "item-paywall=": {
|
||||
//if player uses item-paywall= [Material] [Amount] <id:#> <custom-data:#>
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses item-paywall= [Material] [Amount] <id:#> WILL NOT TAKE CUSTOM ITEMS
|
||||
//player can use item-paywall= [custom-item] [Amount]
|
||||
List<ItemStack> cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p)));
|
||||
List<ItemStack> remCont = new ArrayList<>();
|
||||
HashMap<Integer, ItemStack> remCont = new HashMap<>();
|
||||
String[] args = command.split("\\s");
|
||||
try {
|
||||
byte id = -1;
|
||||
int customData = 0;
|
||||
boolean noCustom = false;
|
||||
int id = -1;
|
||||
for (String val : args) {
|
||||
if (val.startsWith("id:")) {
|
||||
id = Byte.parseByte(val.substring(3));
|
||||
continue;
|
||||
}
|
||||
if (val.startsWith("custom-data:")) {
|
||||
customData = Integer.parseInt(val.substring(12));
|
||||
}
|
||||
if (val.contains("NOCUSTOMDATA")) {
|
||||
noCustom = true;
|
||||
id = Integer.parseInt(val.substring(3));
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,10 +268,10 @@ public class CommandTags {
|
||||
|
||||
if (Material.matchMaterial(args[1]) == null) {
|
||||
//item-paywall is a custom item as it is not a material
|
||||
if (plugin.itemCreate.isIdentical(sellItem, itm)) {
|
||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
|
||||
if (plugin.itemCreate.isIdentical(sellItem, itm, Objects.requireNonNull(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();
|
||||
if (removal) remCont.add(add);
|
||||
if (removal) remCont.put(f,add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
@ -291,23 +285,10 @@ public class CommandTags {
|
||||
String mmoType = customItemMaterial.split("\\s")[1];
|
||||
String mmoID = customItemMaterial.split("\\s")[2];
|
||||
|
||||
if (plugin.isMMOItem(itm, mmoType, mmoID) && sellItem.getAmount() <= itm.getAmount()) {
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
if (removal) {
|
||||
p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount());
|
||||
}
|
||||
p.updateInventory();
|
||||
} else {
|
||||
if (removal) itm.setAmount(itm.getAmount() - sellItem.getAmount());
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
}
|
||||
if (plugin.isMMOItem(itm, mmoType, mmoID)) {
|
||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f);
|
||||
ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount());
|
||||
remainingAmount -= add.getAmount();
|
||||
if (removal) remCont.add(add);
|
||||
if (removal) remCont.put(f,add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
@ -321,14 +302,9 @@ public class CommandTags {
|
||||
} else {
|
||||
//if the item is a standard material
|
||||
if (itm.getType() == sellItem.getType()) {
|
||||
//Checking for custom model data. If it does not have or not the correct number go to next in loop.
|
||||
if (customData != 0) {
|
||||
if (!itm.hasItemMeta()) {
|
||||
continue;
|
||||
}
|
||||
if (Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData) {
|
||||
continue;
|
||||
}
|
||||
if(itm.hasItemMeta()){
|
||||
//If item has custom meta continue to next item.
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check if the item matches the id set. If not continue to next in loop.
|
||||
@ -336,17 +312,10 @@ public class CommandTags {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check if noCustom is set and if the item has custom data. If so continue to next in loop.
|
||||
if (noCustom && itm.hasItemMeta()) {
|
||||
if (Objects.requireNonNull(itm.getItemMeta()).hasCustomModelData()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//Adding item to the remove list then checking if we have reached the required amount.
|
||||
ItemStack add = new ItemStack(itm.getType(), itm.getAmount(), (short) f);
|
||||
ItemStack add = new ItemStack(itm.getType(), itm.getAmount());
|
||||
remainingAmount -= add.getAmount();
|
||||
if (removal) remCont.add(add);
|
||||
if (removal) remCont.put(f,add);
|
||||
if (remainingAmount <= 0) {
|
||||
removedItem = PaywallOutput.Passed;
|
||||
break;
|
||||
@ -356,26 +325,29 @@ public class CommandTags {
|
||||
}
|
||||
|
||||
if (remainingAmount <= 0) {
|
||||
for (int f = 0; f <= remCont.size() - 1; f++) {
|
||||
ItemStack remItem = remCont.get(f);
|
||||
for(Map.Entry<Integer, ItemStack> entry : remCont.entrySet()) {
|
||||
ItemStack remItem = entry.getValue();
|
||||
|
||||
//Check if its the last item in the loop and only subtract the remaining amount.
|
||||
if (f == remCont.size() - 1) {
|
||||
if (sellItem.getAmount() < remItem.getAmount()) {
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
if (removal)
|
||||
p.getInventory().getItem(remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
p.getInventory().getItem(entry.getKey()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
p.updateInventory();
|
||||
} else {
|
||||
if (removal)
|
||||
cont.get((int) remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount());
|
||||
cont.get(entry.getKey()).setAmount(remItem.getAmount() - sellItem.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)) {
|
||||
if (removal) p.getInventory().getItem(remItem.getDurability()).setAmount(0);
|
||||
if (removal) p.getInventory().setItem(entry.getKey(), null);
|
||||
//p.getInventory().remove(entry.getValue());
|
||||
//p.getInventory().getItem(entry.getKey()).setAmount(0);
|
||||
p.updateInventory();
|
||||
} else {
|
||||
if (removal) cont.get(remItem.getDurability()).setAmount(0);
|
||||
if (removal) cont.remove(entry.getValue());
|
||||
//cont.get(entry.getKey()).setAmount(0);
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0])));
|
||||
}
|
||||
}
|
||||
@ -406,6 +378,7 @@ public class CommandTags {
|
||||
}
|
||||
}
|
||||
case "xp-paywall=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses xp-paywall= <price> <levels:points>
|
||||
try {
|
||||
int balance;
|
||||
@ -438,6 +411,7 @@ public class CommandTags {
|
||||
}
|
||||
}
|
||||
case "data-paywall=": {
|
||||
String command = plugin.tex.placeholders(panel, PanelPosition.Top, p, rawCommand);
|
||||
//if player uses data-paywall= <data> <amount>
|
||||
try {
|
||||
if (Double.parseDouble(plugin.panelData.getUserData(p.getUniqueId(), command.split("\\s")[1])) >= Double.parseDouble(command.split("\\s")[2])) {
|
||||
@ -461,7 +435,6 @@ public class CommandTags {
|
||||
}
|
||||
}
|
||||
}
|
||||
return PaywallOutput.NotApplicable;
|
||||
}
|
||||
|
||||
//Experience math is a bit doggy doo doo so these will help to calculate values
|
||||
|
@ -23,6 +23,13 @@ public class ItemTags implements Listener {
|
||||
if(e.name.equalsIgnoreCase("give-item=")){
|
||||
e.commandTagUsed();
|
||||
ItemStack itm = plugin.itemCreate.makeCustomItemFromConfig(null,e.pos,e.panel.getConfig().getConfigurationSection("custom-item." + e.args[0]), e.p, true, true, false);
|
||||
if(e.args.length == 2){
|
||||
try{
|
||||
itm.setAmount(Integer.parseInt(e.args[1]));
|
||||
} catch (Exception err){
|
||||
plugin.debug(err,e.p);
|
||||
}
|
||||
}
|
||||
plugin.inventorySaver.addItem(e.p,itm);
|
||||
return;
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package me.rockyhawk.commandpanels.completetabs;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class UpdateTabComplete implements TabCompleter {
|
||||
CommandPanels plugin;
|
||||
public UpdateTabComplete(CommandPanels pl) { this.plugin = pl; }
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if(sender.hasPermission("commandpanel.refresh")) {
|
||||
ArrayList<String> output = new ArrayList<>();
|
||||
if(args.length == 1){
|
||||
for(Player player : Bukkit.getOnlinePlayers()){
|
||||
output.add(player.getName());
|
||||
}
|
||||
}else if(args.length == 2){
|
||||
output.add("ALL");
|
||||
for(PanelPosition pp : PanelPosition.values()){
|
||||
output.add(pp.toString());
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package me.rockyhawk.commandpanels.ioclasses.nbt;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBT;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -12,39 +14,57 @@ public class NBTManager {
|
||||
|
||||
//commandpanel item NBT
|
||||
public boolean hasNBT(ItemStack item){
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
|
||||
return new NBT_1_13().contains(item, "CommandPanelsItem");
|
||||
}else{
|
||||
return new NBT_1_14(plugin).hasNBT(item,"CommandPanelsItem");
|
||||
}
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
return nbti.hasTag("CommandPanelsItem");
|
||||
|
||||
// if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
|
||||
// return new NBT_1_13().contains(item, "CommandPanelsItem");
|
||||
// }else{
|
||||
// return new NBT_1_14(plugin).hasNBT(item,"CommandPanelsItem");
|
||||
// }
|
||||
}
|
||||
|
||||
public ItemStack setNBT(ItemStack item){
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
|
||||
return new NBT_1_13().set(item,1,"CommandPanelsItem");
|
||||
}else{
|
||||
return new NBT_1_14(plugin).addNBT(item,"CommandPanelsItem","1");
|
||||
}
|
||||
NBT.modify(item, nbt -> {
|
||||
nbt.setString("CommandPanelsItem", "1");
|
||||
});
|
||||
|
||||
return item;
|
||||
|
||||
// if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
|
||||
// return new NBT_1_13().set(item,1,"CommandPanelsItem");
|
||||
// }else{
|
||||
// return new NBT_1_14(plugin).addNBT(item,"CommandPanelsItem","1");
|
||||
// }
|
||||
}
|
||||
|
||||
//custom key NBT
|
||||
public String getNBT(ItemStack item, String key){
|
||||
String output = "";
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
|
||||
try{
|
||||
output = new NBT_1_13().getString(item, key);
|
||||
}catch(NullPointerException ignore){}
|
||||
}else{
|
||||
output = new NBT_1_14(plugin).getNBT(item, key);
|
||||
}
|
||||
return output;
|
||||
NBTItem nbti = new NBTItem(item);
|
||||
if(!nbti.hasNBTData()) return "";
|
||||
return nbti.getString(key);
|
||||
|
||||
// String output = "";
|
||||
// if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
|
||||
// try{
|
||||
// output = new NBT_1_13().getString(item, key);
|
||||
// }catch(NullPointerException ignore){}
|
||||
// }else{
|
||||
// output = new NBT_1_14(plugin).getNBT(item, key);
|
||||
// }
|
||||
// return output;
|
||||
}
|
||||
|
||||
public ItemStack setNBT(ItemStack item, String key, String value){
|
||||
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
|
||||
return new NBT_1_13().set(item,value,key);
|
||||
}else{
|
||||
return new NBT_1_14(plugin).addNBT(item,key,value);
|
||||
}
|
||||
NBT.modify(item, nbt -> {
|
||||
nbt.setString(key, value);
|
||||
});
|
||||
|
||||
return item;
|
||||
//if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
|
||||
// return new NBT_1_13().set(item,value,key);
|
||||
//}else{
|
||||
// return new NBT_1_14(plugin).addNBT(item,key,value);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,9 @@ public class UtilsPanelsLoader implements Listener {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
//end the old panel session and copy a new one
|
||||
if(plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top) == null){
|
||||
return;
|
||||
}
|
||||
plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).isOpen = false;
|
||||
Panel reopenedPanel = plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).copy();
|
||||
//re-add placeholders as they are not transferred in the Panel object
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HotbarItemLoader {
|
||||
@ -63,7 +64,7 @@ public class HotbarItemLoader {
|
||||
//return true if found
|
||||
public boolean itemCheckExecute(ItemStack invItem, Player p, boolean openPanel, boolean stationaryOnly){
|
||||
try {
|
||||
if (plugin.nbt.getNBT(invItem, "CommandPanelsHotbar") == null) {
|
||||
if (Objects.equals(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar"), "")) {
|
||||
return false;
|
||||
}
|
||||
}catch(IllegalArgumentException | NullPointerException nu){
|
||||
@ -119,7 +120,7 @@ public class HotbarItemLoader {
|
||||
stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager());
|
||||
for(int i = 0; i <= 35; i++){
|
||||
try {
|
||||
if (plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar") != null) {
|
||||
if (!Objects.equals(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar"), "")) {
|
||||
//do not remove items that are not stationary
|
||||
if(!plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar").endsWith("-1")) {
|
||||
p.getInventory().setItem(i, new ItemStack(Material.AIR));
|
||||
|
Loading…
Reference in New Issue
Block a user