diff --git a/ci-pom.xml b/ci-pom.xml
index aac2c1b..1c0dcb9 100644
--- a/ci-pom.xml
+++ b/ci-pom.xml
@@ -7,7 +7,7 @@
us.mytheria
BlobLib
- 1.698.09
+ 1.698.10
pom.xml
bloblib
diff --git a/local-pom.xml b/local-pom.xml
index 0dfe4b1..69d25dd 100644
--- a/local-pom.xml
+++ b/local-pom.xml
@@ -5,7 +5,7 @@
us.mytheria
BlobLib
- 1.698.09
+ 1.698.10
pom.xml
bloblib
diff --git a/pom.xml b/pom.xml
index b36ccf0..4561c62 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
us.mytheria
BlobLib
- 1.698.09
+ 1.698.10
pom
diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/BlobMultiSlotable.java b/src/main/java/us/mytheria/bloblib/entities/inventory/BlobMultiSlotable.java
index 6043ab8..051ae18 100644
--- a/src/main/java/us/mytheria/bloblib/entities/inventory/BlobMultiSlotable.java
+++ b/src/main/java/us/mytheria/bloblib/entities/inventory/BlobMultiSlotable.java
@@ -5,6 +5,8 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
+import us.mytheria.bloblib.BlobLib;
+import us.mytheria.bloblib.action.ActionType;
import us.mytheria.bloblib.api.BlobLibTranslatableAPI;
import us.mytheria.bloblib.entities.translatable.TranslatableItem;
import us.mytheria.bloblib.itemstack.ItemStackReader;
@@ -59,11 +61,25 @@ public static BlobMultiSlotable read(ConfigurationSection section, String key,
String action = null;
if (section.isString("Action"))
action = section.getString("Action");
+ ActionType actionType = null;
+ ConfigurationSection actionSection = section.getConfigurationSection("Action");
+ if (actionSection != null) {
+ if (!actionSection.isString("Action"))
+ Bukkit.getLogger().info("'Action' field is missing in 'Action' ConfigurationSection (" + key + ".Action.Action)");
+ if (!actionSection.isString("Action-Type"))
+ Bukkit.getLogger().info("'Action-Type' field is missing in 'Action' ConfigurationSection (" + key + ".Action.Action-Type)");
+ action = actionSection.getString("Action");
+ try {
+ actionType = ActionType.valueOf(actionSection.getString("Action-Type"));
+ } catch (IllegalArgumentException e) {
+ BlobLib.getAnjoLogger().singleError("Invalid 'ActionType' for " + key + ".Action.Action-Type");
+ }
+ }
ItemStack clone = translatableItem.getClone();
int amount = section.getInt("Amount", 1);
clone.setAmount(amount);
return new BlobMultiSlotable(list, clone, key, permission, price,
- priceCurrency, action);
+ priceCurrency, action, actionType);
}
ConfigurationSection itemStackSection = section.getConfigurationSection("ItemStack");
if (itemStackSection == null) {
@@ -86,8 +102,22 @@ public static BlobMultiSlotable read(ConfigurationSection section, String key,
String action = null;
if (section.isString("Action"))
action = section.getString("Action");
+ ActionType actionType = null;
+ ConfigurationSection actionSection = section.getConfigurationSection("Action");
+ if (actionSection != null) {
+ if (!actionSection.isString("Action"))
+ Bukkit.getLogger().info("'Action' field is missing in 'Action' ConfigurationSection (" + key + ".Action.Action)");
+ if (!actionSection.isString("Action-Type"))
+ Bukkit.getLogger().info("'Action-Type' field is missing in 'Action' ConfigurationSection (" + key + ".Action.Action-Type)");
+ action = actionSection.getString("Action");
+ try {
+ actionType = ActionType.valueOf(actionSection.getString("Action-Type"));
+ } catch (IllegalArgumentException e) {
+ BlobLib.getAnjoLogger().singleError("Invalid 'ActionType' for " + key + ".Action.Action-Type");
+ }
+ }
return new BlobMultiSlotable(list, itemStack, key, permission, price,
- priceCurrency, action);
+ priceCurrency, action, actionType);
}
/**
@@ -106,8 +136,9 @@ public BlobMultiSlotable(Set slots, ItemStack itemStack,
@Nullable String permission,
double price,
@Nullable String priceCurrency,
- @Nullable String action) {
- super(slots, itemStack, permission, price, priceCurrency, action);
+ @Nullable String action,
+ @Nullable ActionType actionType) {
+ super(slots, itemStack, permission, price, priceCurrency, action, actionType);
this.key = key;
}
@@ -126,7 +157,7 @@ public void setInInventory(Inventory inventory) {
public InventoryButton toInventoryButton() {
return new InventoryButton(key, getSlots(), getPermission(), getPrice(),
- getPriceCurrency(), getAction());
+ getPriceCurrency(), getAction(), getActionType());
}
/**
diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryButton.java b/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryButton.java
index a78ec18..3428e6f 100644
--- a/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryButton.java
+++ b/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryButton.java
@@ -5,8 +5,12 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.Permissible;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.action.Action;
+import us.mytheria.bloblib.action.ActionType;
+import us.mytheria.bloblib.action.CommandAction;
+import us.mytheria.bloblib.action.ConsoleCommandAction;
import us.mytheria.bloblib.api.BlobLibActionAPI;
import us.mytheria.bloblib.api.BlobLibEconomyAPI;
import us.mytheria.bloblib.vault.multieconomy.ElasticEconomy;
@@ -21,18 +25,25 @@ public class InventoryButton {
private final String permission;
private final double price;
private final String priceCurrency;
+ @Nullable
private final String action;
+ @Nullable
+ private final ActionType actionType;
- public InventoryButton(String key, Set slots,
+ public InventoryButton(String key,
+ @NotNull Set slots,
@Nullable String permission,
- double price, @Nullable String priceCurrency,
- @Nullable String action) {
+ double price,
+ @Nullable String priceCurrency,
+ @Nullable String action,
+ @Nullable ActionType actionType) {
this.key = key;
this.slots = slots;
this.permission = permission;
this.price = price;
this.priceCurrency = priceCurrency;
this.action = action;
+ this.actionType = actionType;
}
public String getKey() {
@@ -142,6 +153,13 @@ public String getAction() {
return action;
}
+ /**
+ * @return The action type of the button. Null if there is no action type.
+ */
+ @Nullable ActionType getActionType() {
+ return actionType;
+ }
+
/**
* Will handle the action of the button.
*
@@ -150,6 +168,20 @@ public String getAction() {
public void handleAction(Entity entity) {
if (action == null)
return;
+ if (actionType != null) {
+ Action build;
+ switch (actionType) {
+ case ACTOR_COMMAND -> {
+ build = CommandAction.build(action);
+ }
+ case CONSOLE_COMMAND -> {
+ build = ConsoleCommandAction.build(action);
+ }
+ default -> throw new IllegalStateException("Unexpected value: " + actionType);
+ }
+ build.perform(entity);
+ return;
+ }
Action fetch = BlobLibActionAPI.getInstance().getAction(action);
fetch.perform(entity);
}
@@ -165,6 +197,6 @@ public void accept(ButtonVisitor visitor) {
*/
public InventoryButton copy() {
return new InventoryButton(key, new HashSet<>(slots),
- permission, price, priceCurrency, action);
+ permission, price, priceCurrency, action, actionType);
}
}
diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryDataRegistry.java b/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryDataRegistry.java
index a23f582..defb083 100644
--- a/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryDataRegistry.java
+++ b/src/main/java/us/mytheria/bloblib/entities/inventory/InventoryDataRegistry.java
@@ -1,5 +1,6 @@
package us.mytheria.bloblib.entities.inventory;
+import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.jetbrains.annotations.NotNull;
@@ -138,6 +139,8 @@ public void processClickEvent(InventoryClickEvent event, T button) {
clickEvents.values().forEach(clickEvent -> {
if (clickEvent == null)
return;
+ if (!button.handleAll((Player) event.getWhoClicked()))
+ return;
clickEvent.accept(event, button);
});
}
diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/MetaBlobMultiSlotable.java b/src/main/java/us/mytheria/bloblib/entities/inventory/MetaBlobMultiSlotable.java
index cf5c094..2731b92 100644
--- a/src/main/java/us/mytheria/bloblib/entities/inventory/MetaBlobMultiSlotable.java
+++ b/src/main/java/us/mytheria/bloblib/entities/inventory/MetaBlobMultiSlotable.java
@@ -5,6 +5,8 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
+import us.mytheria.bloblib.BlobLib;
+import us.mytheria.bloblib.action.ActionType;
import us.mytheria.bloblib.api.BlobLibTranslatableAPI;
import us.mytheria.bloblib.entities.translatable.TranslatableItem;
import us.mytheria.bloblib.itemstack.ItemStackReader;
@@ -68,11 +70,25 @@ public static MetaBlobMultiSlotable read(ConfigurationSection section, String ke
String action = null;
if (section.isString("Action"))
action = section.getString("Action");
+ ActionType actionType = null;
+ ConfigurationSection actionSection = section.getConfigurationSection("Action");
+ if (actionSection != null) {
+ if (!actionSection.isString("Action"))
+ Bukkit.getLogger().info("'Action' field is missing in 'Action' ConfigurationSection (" + key + ".Action.Action)");
+ if (!actionSection.isString("Action-Type"))
+ Bukkit.getLogger().info("'Action-Type' field is missing in 'Action' ConfigurationSection (" + key + ".Action.Action-Type)");
+ action = actionSection.getString("Action");
+ try {
+ actionType = ActionType.valueOf(actionSection.getString("Action-Type"));
+ } catch (IllegalArgumentException e) {
+ BlobLib.getAnjoLogger().singleError("Invalid 'ActionType' for " + key + ".Action.Action-Type");
+ }
+ }
ItemStack clone = translatableItem.getClone();
int amount = section.getInt("Amount", 1);
clone.setAmount(amount);
return new MetaBlobMultiSlotable(set, clone, key, meta, subMeta,
- permission, price, priceCurrency, action);
+ permission, price, priceCurrency, action, actionType);
}
ConfigurationSection itemStackSection = section.getConfigurationSection("ItemStack");
if (itemStackSection == null) {
@@ -102,8 +118,22 @@ public static MetaBlobMultiSlotable read(ConfigurationSection section, String ke
String action = null;
if (section.isString("Action"))
action = section.getString("Action");
+ ActionType actionType = null;
+ ConfigurationSection actionSection = section.getConfigurationSection("Action");
+ if (actionSection != null) {
+ if (!actionSection.isString("Action"))
+ Bukkit.getLogger().info("'Action' field is missing in 'Action' ConfigurationSection (" + key + ".Action.Action)");
+ if (!actionSection.isString("Action-Type"))
+ Bukkit.getLogger().info("'Action-Type' field is missing in 'Action' ConfigurationSection (" + key + ".Action.Action-Type)");
+ action = actionSection.getString("Action");
+ try {
+ actionType = ActionType.valueOf(actionSection.getString("Action-Type"));
+ } catch (IllegalArgumentException e) {
+ BlobLib.getAnjoLogger().singleError("Invalid 'ActionType' for " + key + ".Action.Action-Type");
+ }
+ }
return new MetaBlobMultiSlotable(set, itemStack, key, meta, subMeta,
- permission, price, priceCurrency, action);
+ permission, price, priceCurrency, action, actionType);
}
/**
@@ -118,8 +148,9 @@ public MetaBlobMultiSlotable(Set slots, ItemStack itemStack, String key
@Nullable String permission,
double price,
@Nullable String priceCurrency,
- @Nullable String action) {
- super(slots, itemStack, permission, price, priceCurrency, action);
+ @Nullable String action,
+ @Nullable ActionType actionType) {
+ super(slots, itemStack, permission, price, priceCurrency, action, actionType);
this.key = key;
this.meta = meta;
this.subMeta = subMeta;
@@ -140,7 +171,8 @@ public void setInInventory(Inventory inventory) {
public MetaInventoryButton toMetaInventoryButton() {
return new MetaInventoryButton(key, getSlots(), meta, subMeta,
- getPermission(), getPrice(), getPriceCurrency(), getAction());
+ getPermission(), getPrice(), getPriceCurrency(),
+ getAction(), getActionType());
}
/**
diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/MetaInventoryButton.java b/src/main/java/us/mytheria/bloblib/entities/inventory/MetaInventoryButton.java
index df2a948..0c85efe 100644
--- a/src/main/java/us/mytheria/bloblib/entities/inventory/MetaInventoryButton.java
+++ b/src/main/java/us/mytheria/bloblib/entities/inventory/MetaInventoryButton.java
@@ -2,6 +2,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import us.mytheria.bloblib.action.ActionType;
import java.util.HashSet;
import java.util.Set;
@@ -14,14 +15,14 @@ public static MetaInventoryButton fromInventoryButton(InventoryButton button, St
String subMeta) {
return new MetaInventoryButton(button.getKey(), button.getSlots(), meta,
subMeta, button.getPermission(), button.getPrice(),
- button.getPriceCurrency(), button.getAction());
+ button.getPriceCurrency(), button.getAction(), button.getActionType());
}
public MetaInventoryButton(String key, Set slots, String meta,
@Nullable String subMeta, @Nullable String permission,
double price, @Nullable String priceCurrency,
- @Nullable String action) {
- super(key, slots, permission, price, priceCurrency, action);
+ @Nullable String action, @Nullable ActionType actionType) {
+ super(key, slots, permission, price, priceCurrency, action, actionType);
this.meta = meta;
this.subMeta = subMeta;
}
@@ -62,6 +63,6 @@ public void accept(ButtonVisitor visitor) {
@Override
public MetaInventoryButton copy() {
return new MetaInventoryButton(getKey(), new HashSet<>(getSlots()), getMeta(), getSubMeta(),
- getPermission(), getPrice(), getPriceCurrency(), getAction());
+ getPermission(), getPrice(), getPriceCurrency(), getAction(), getActionType());
}
}
diff --git a/src/main/java/us/mytheria/bloblib/entities/inventory/MultiSlotable.java b/src/main/java/us/mytheria/bloblib/entities/inventory/MultiSlotable.java
index 14576c9..499c515 100644
--- a/src/main/java/us/mytheria/bloblib/entities/inventory/MultiSlotable.java
+++ b/src/main/java/us/mytheria/bloblib/entities/inventory/MultiSlotable.java
@@ -2,6 +2,7 @@
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
+import us.mytheria.bloblib.action.ActionType;
import java.util.Collection;
@@ -18,7 +19,10 @@ public abstract class MultiSlotable {
private final String permission;
private final double price;
private final String priceCurrency;
+ @Nullable
private final String action;
+ @Nullable
+ private final ActionType actionType;
/**
* @param slots The slots to be used.
@@ -27,18 +31,21 @@ public abstract class MultiSlotable {
* @param price The price to be used.
* @param priceCurrency The price currency to be used.
* @param action The action to be used.
+ * @param actionType The action type to be used.
*/
public MultiSlotable(Collection slots, ItemStack itemStack,
@Nullable String permission,
double price,
@Nullable String priceCurrency,
- @Nullable String action) {
+ @Nullable String action,
+ @Nullable ActionType actionType) {
this.slots = slots;
this.itemStack = itemStack;
this.permission = permission;
this.price = price;
this.priceCurrency = priceCurrency;
this.action = action;
+ this.actionType = actionType;
}
/**
@@ -75,4 +82,9 @@ public String getPriceCurrency() {
public String getAction() {
return action;
}
+
+ @Nullable
+ public ActionType getActionType() {
+ return actionType;
+ }
}