forked from Upstream/CommandPanels
3.21.2.4
This commit is contained in:
parent
724d5039c0
commit
44e4c5831e
@ -1,4 +1,4 @@
|
||||
version: 3.21.2.3
|
||||
version: 3.21.2.4
|
||||
main: me.rockyhawk.commandpanels.CommandPanels
|
||||
name: CommandPanels
|
||||
author: RockyHawk
|
||||
|
@ -119,7 +119,7 @@ public class ItemCreation {
|
||||
|
||||
//creates item from custom-items section of panel
|
||||
if(matraw.split("\\s")[0].equalsIgnoreCase("cpi=")){
|
||||
s = makeCustomItemFromConfig(panel,position,panel.getConfig().getConfigurationSection("custom-item." + matraw.split("\\s")[1]), p, true, true, true);
|
||||
s = makeCustomItemFromConfig(panel,position,panel.getConfig().getConfigurationSection("custom-item." + matraw.split("\\s")[1]), p, true, true, false);
|
||||
normalCreation = false;
|
||||
}
|
||||
|
||||
@ -185,18 +185,18 @@ public class ItemCreation {
|
||||
if(itemSection.getStringList("itemType").contains("noAttributes")){
|
||||
hideAttributes = true;
|
||||
}
|
||||
if(itemSection.getStringList("itemType").contains("noNBT")){
|
||||
addNBT = false;
|
||||
}
|
||||
if(itemSection.getStringList("itemType").contains("placeable")){
|
||||
addNBT = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(addNBT && itemSection.contains("nbt")){
|
||||
|
||||
if(itemSection.contains("nbt")){
|
||||
plugin.nbt.applyNBTRecursively("", itemSection, s, p, panel, position);
|
||||
}
|
||||
if(addNBT){
|
||||
plugin.nbt.setNBT(s, "CommandPanelsItem", "true");
|
||||
}
|
||||
|
||||
if (itemSection.contains("enchanted")) {
|
||||
try {
|
||||
ItemMeta EnchantMeta;
|
||||
@ -325,14 +325,6 @@ public class ItemCreation {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (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));
|
||||
}
|
||||
}
|
||||
// 1.20 Trim Feature for Player Armor
|
||||
if(plugin.legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && itemSection.contains("trim")){
|
||||
// trim: <Material> <Pattern>
|
||||
|
@ -3,6 +3,7 @@ package me.rockyhawk.commandpanels.commandtags;
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.api.Panel;
|
||||
import me.rockyhawk.commandpanels.commandtags.paywalls.*;
|
||||
import me.rockyhawk.commandpanels.commandtags.paywalls.itempaywall.ItemPaywall;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.other.DataTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.other.PlaceholderTags;
|
||||
import me.rockyhawk.commandpanels.commandtags.tags.other.SpecialTags;
|
||||
|
@ -0,0 +1,21 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.paywalls.itempaywall;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InventoryOperationResult {
|
||||
private final boolean success;
|
||||
private final ItemStack[] inventory;
|
||||
|
||||
public InventoryOperationResult(boolean success, ItemStack[] inventory) {
|
||||
this.success = success;
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public ItemStack[] getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package me.rockyhawk.commandpanels.commandtags.paywalls;
|
||||
package me.rockyhawk.commandpanels.commandtags.paywalls.itempaywall;
|
||||
|
||||
import me.rockyhawk.commandpanels.CommandPanels;
|
||||
import me.rockyhawk.commandpanels.commandtags.PaywallEvent;
|
||||
@ -74,37 +74,34 @@ public class ItemPaywall implements Listener {
|
||||
}
|
||||
|
||||
public boolean removeItem(Player p, ItemStack itemToRemove, boolean ignoreNBT) {
|
||||
boolean result;
|
||||
InventoryOperationResult result;
|
||||
|
||||
if (plugin.inventorySaver.hasNormalInventory(p)) {
|
||||
result = removeItemFromInventory(p.getInventory().getContents(), itemToRemove, ignoreNBT);
|
||||
p.getInventory().setContents(result.getInventory());
|
||||
} else {
|
||||
// Load the saved inventory from config, manipulate it, and save it back
|
||||
ItemStack[] savedInventory = plugin.inventorySaver.getNormalInventory(p);
|
||||
result = removeItemFromInventory(savedInventory, itemToRemove, ignoreNBT);
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(savedInventory));
|
||||
plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(result.getInventory()));
|
||||
}
|
||||
|
||||
return result; // Return true if the items were successfully removed, otherwise false
|
||||
return result.isSuccess(); // Return the success status of the inventory operation
|
||||
}
|
||||
|
||||
private boolean removeItemFromInventory(ItemStack[] inventory, ItemStack itemToRemove, boolean ignoreNBT) {
|
||||
private InventoryOperationResult removeItemFromInventory(ItemStack[] inventory, ItemStack itemToRemove, boolean ignoreNBT) {
|
||||
int amountToRemove = itemToRemove.getAmount();
|
||||
int count = 0; // To count how many of the required items are present
|
||||
int count = 0;
|
||||
|
||||
// First pass: count the items to ensure there are enough
|
||||
for (ItemStack item : inventory) {
|
||||
if (item != null && plugin.itemCreate.isIdentical(item, itemToRemove, !ignoreNBT)) {
|
||||
count += item.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
// If not enough items, return false and do not modify the inventory
|
||||
if (count < amountToRemove) {
|
||||
return false;
|
||||
return new InventoryOperationResult(false, inventory); // Not enough items, return with original inventory unchanged
|
||||
}
|
||||
|
||||
// Second pass: remove the items if there are enough
|
||||
for (int i = 0; i < inventory.length; i++) {
|
||||
ItemStack currentItem = inventory[i];
|
||||
if (currentItem != null && plugin.itemCreate.isIdentical(currentItem, itemToRemove, !ignoreNBT)) {
|
||||
@ -112,18 +109,16 @@ public class ItemPaywall implements Listener {
|
||||
currentItem.setAmount(currentItem.getAmount() - removeAmount);
|
||||
amountToRemove -= removeAmount;
|
||||
|
||||
// Remove the item stack if it becomes empty
|
||||
if (currentItem.getAmount() == 0) {
|
||||
inventory[i] = null;
|
||||
}
|
||||
|
||||
// If removed all needed, break out of the loop
|
||||
if (amountToRemove == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true; // Return true as items were successfully removed
|
||||
return new InventoryOperationResult(true, inventory); // Return true and the modified inventory
|
||||
}
|
||||
}
|
@ -16,47 +16,60 @@ public class DataTags implements Listener {
|
||||
if(e.name.equalsIgnoreCase("set-data=")){
|
||||
e.commandTagUsed();
|
||||
if(e.args.length == 3){
|
||||
plugin.panelData.setUserData(plugin.panelData.getOffline(e.args[2]),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),true);
|
||||
plugin.panelData.setUserData(plugin.panelData.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[2])),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),true);
|
||||
return;
|
||||
}
|
||||
//this will overwrite data. set-data= [data point] [data value] [optional player]
|
||||
plugin.panelData.setUserData(e.p.getUniqueId(),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),true);
|
||||
plugin.panelData.setUserData(e.p.getUniqueId(),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),true);
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("add-data=")){
|
||||
e.commandTagUsed();
|
||||
if(e.args.length == 3){
|
||||
plugin.panelData.setUserData(plugin.panelData.getOffline(e.args[2]),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),false);
|
||||
plugin.panelData.setUserData(plugin.panelData.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[2])),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),false);
|
||||
return;
|
||||
}
|
||||
//this will not overwrite existing data. add-data= [data point] [data value] [optional player]
|
||||
plugin.panelData.setUserData(e.p.getUniqueId(),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),false);
|
||||
plugin.panelData.setUserData(e.p.getUniqueId(),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]),false);
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("math-data=")){
|
||||
e.commandTagUsed();
|
||||
if(e.args.length == 3){
|
||||
plugin.panelData.doDataMath(plugin.panelData.getOffline(e.args[2]),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]));
|
||||
plugin.panelData.doDataMath(plugin.panelData.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[2])),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]));
|
||||
return;
|
||||
}
|
||||
//only works if data is number, goes math-data= [data point] [operator:number] [optional player] eg, math-data= -1 OR /3
|
||||
plugin.panelData.doDataMath(e.p.getUniqueId(),e.args[0],plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]));
|
||||
plugin.panelData.doDataMath(e.p.getUniqueId(),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1]));
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("clear-data=")){
|
||||
e.commandTagUsed();
|
||||
//will clear all data for player clear-data= [playerName]
|
||||
plugin.panelData.clearData(e.p.getUniqueId());
|
||||
plugin.panelData.clearData(plugin.panelData.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0])));
|
||||
return;
|
||||
}
|
||||
if(e.name.equalsIgnoreCase("del-data=")){
|
||||
e.commandTagUsed();
|
||||
if(e.args.length == 3){
|
||||
plugin.panelData.delUserData(plugin.panelData.getOffline(e.args[1]),e.args[0]);
|
||||
if(e.args.length == 2){
|
||||
plugin.panelData.delUserData(plugin.panelData.getOffline(plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[1])),
|
||||
plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]));
|
||||
return;
|
||||
}
|
||||
//this will remove data. del-data= [data point] [optional player]
|
||||
plugin.panelData.delUserData(e.p.getUniqueId(),e.args[0]);
|
||||
plugin.panelData.delUserData(e.p.getUniqueId(),plugin.tex.placeholdersNoColour(e.panel,e.pos,e.p,e.args[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class ItemTags implements Listener {
|
||||
e.commandTagUsed();
|
||||
//if player uses setitem= [custom item] [slot] [position] it will change the item slot to something, used for placeable items
|
||||
//make a section in the panel called "custom-item" then whatever the title of the item is, put that here
|
||||
ItemStack s = plugin.itemCreate.makeItemFromConfig(null, e.pos,e.panel.getConfig().getConfigurationSection("custom-item." + e.args[0]), e.p, true, true, true);
|
||||
ItemStack s = plugin.itemCreate.makeItemFromConfig(null, e.pos,e.panel.getConfig().getConfigurationSection("custom-item." + e.args[0]), e.p, true, true, false);
|
||||
PanelPosition position = PanelPosition.valueOf(e.args[2]);
|
||||
if(position == PanelPosition.Top) {
|
||||
e.p.getOpenInventory().getTopInventory().setItem(Integer.parseInt(e.args[1]), s);
|
||||
|
@ -25,10 +25,12 @@ public class NBTManager {
|
||||
return nbtitem1.equals(nbtitem2);
|
||||
}
|
||||
|
||||
public ItemStack setNBT(ItemStack item, String key, String value){
|
||||
NBT.modify(item, nbt -> {
|
||||
nbt.setString(key, value);
|
||||
});
|
||||
public ItemStack setNBT(ItemStack item, String key, String value) {
|
||||
if (item != null) {
|
||||
NBT.modify(item, nbt -> {
|
||||
nbt.setString(key, value);
|
||||
});
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,6 @@ public class OpenGUI {
|
||||
}
|
||||
}
|
||||
|
||||
//will only add NBT if not an editor GUI
|
||||
ItemStack s = plugin.itemCreate.makeItemFromConfig(panel,position,Objects.requireNonNull(pconfig.getConfigurationSection("item." + item + section)), p, true, true, true);
|
||||
|
||||
//This is for CUSTOM ITEMS
|
||||
@ -135,7 +134,6 @@ public class OpenGUI {
|
||||
empty = plugin.itemCreate.makeItemFromConfig(panel,position,pconfig.getConfigurationSection("custom-item." + pconfig.getString("empty")),p,true,true,true);
|
||||
}else{
|
||||
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(pconfig.getString("empty").toUpperCase())), 1,id);
|
||||
empty = plugin.nbt.setNBT(empty, "CommandPanelsItem", "true");
|
||||
ItemMeta renamedMeta = empty.getItemMeta();
|
||||
assert renamedMeta != null;
|
||||
renamedMeta.setDisplayName(" ");
|
||||
|
Loading…
Reference in New Issue
Block a user