Skip to content

Commit

Permalink
Improves BlobLib assets debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Aug 2, 2024
1 parent 0e90e16 commit edb2679
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 50 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.698.30</version>
<version>1.698.31</version>
<packaging>pom</packaging>

<properties>
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/us/mytheria/bloblib/action/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import us.mytheria.bloblib.exception.ConfigurationFieldException;

import java.util.Objects;
import java.util.function.Function;

/**
Expand All @@ -19,20 +19,26 @@ public abstract class Action<T extends Entity> {
* @return The action
*/
public static Action<Entity> fromConfigurationSection(ConfigurationSection section) {
String type = Objects.requireNonNull(section.getString("Type"), "Action.Type is null");
String type = section.getString("Type");
if (type == null)
throw new ConfigurationFieldException("'Action.Type' is not set or valid");
ActionType actionType;
try {
actionType = ActionType.valueOf(type);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Unknown Action Type: " + type);
throw new ConfigurationFieldException("Invalid 'Action.Type': " + type);
}
switch (actionType) {
case ACTOR_COMMAND -> {
String command = Objects.requireNonNull(section.getString("Command"), "Action.Command is null");
String command = section.getString("Command");
if (command == null)
throw new ConfigurationFieldException("'Action.Command' is not valid");
return CommandAction.build(command);
}
case CONSOLE_COMMAND -> {
String command = Objects.requireNonNull(section.getString("Command"), "Action.Command is null");
String command = section.getString("Command");
if (command == null)
throw new ConfigurationFieldException("'Action.Command' is not valid");
return ConsoleCommandAction.build(command);
}
default -> throw new IllegalArgumentException("Unknown Action Type: " + type);
Expand Down
33 changes: 17 additions & 16 deletions src/main/java/us/mytheria/bloblib/entities/BlobMessageReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.api.BlobLibMessageAPI;
import us.mytheria.bloblib.entities.message.*;
import us.mytheria.bloblib.exception.ConfigurationFieldException;
import us.mytheria.bloblib.utilities.TextColor;

import java.util.Objects;
Expand Down Expand Up @@ -37,16 +38,16 @@ public static BlobMessage read(@NotNull ConfigurationSection section,
switch (type) {
case "ACTIONBAR" -> {
if (!section.contains("Message"))
throw new IllegalArgumentException("'Message' is required for ACTIONBAR messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Message' is required for ACTIONBAR messages at " + section.getCurrentPath());
return new BlobActionbarMessage(key, TextColor.PARSE(section.getString("Message")),
sound.orElse(null),
locale);
}
case "TITLE" -> {
if (!section.contains("Title"))
throw new IllegalArgumentException("'Title' is required for TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Title' is required for TITLE messages at " + section.getCurrentPath());
if (!section.contains("Subtitle"))
throw new IllegalArgumentException("'Subtitle' is required for TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Subtitle' is required for TITLE messages at " + section.getCurrentPath());
int fadeIn = section.getInt("FadeIn", 10);
int stay = section.getInt("Stay", 40);
int fadeOut = section.getInt("FadeOut", 10);
Expand All @@ -57,7 +58,7 @@ public static BlobMessage read(@NotNull ConfigurationSection section,
}
case "CHAT" -> {
if (!section.contains("Message"))
throw new IllegalArgumentException("'Message' is required for CHAT messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Message' is required for CHAT messages at " + section.getCurrentPath());
String hover = section.isString("Hover") ? TextColor.PARSE(section.getString("Hover")) : null;
return new BlobChatMessage(key, TextColor.PARSE(section.getString("Message")),
hover,
Expand All @@ -66,11 +67,11 @@ public static BlobMessage read(@NotNull ConfigurationSection section,
}
case "ACTIONBAR_TITLE" -> {
if (!section.contains("Title"))
throw new IllegalArgumentException("'Title' is required for ACTIONBAR_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Title' is required for ACTIONBAR_TITLE messages at " + section.getCurrentPath());
if (!section.contains("Subtitle"))
throw new IllegalArgumentException("'Subtitle' is required for ACTIONBAR_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Subtitle' is required for ACTIONBAR_TITLE messages at " + section.getCurrentPath());
if (!section.contains("Actionbar"))
throw new IllegalArgumentException("'Actionbar' is required for ACTIONBAR_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Actionbar' is required for ACTIONBAR_TITLE messages at " + section.getCurrentPath());
int fadeIn = section.getInt("FadeIn", 10);
int stay = section.getInt("Stay", 40);
int fadeOut = section.getInt("FadeOut", 10);
Expand All @@ -82,9 +83,9 @@ public static BlobMessage read(@NotNull ConfigurationSection section,
}
case "CHAT_ACTIONBAR" -> {
if (!section.contains("Chat"))
throw new IllegalArgumentException("'Chat' is required for CHAT_ACTIONBAR messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Chat' is required for CHAT_ACTIONBAR messages at " + section.getCurrentPath());
if (!section.contains("Actionbar"))
throw new IllegalArgumentException("'Actionbar' is required for CHAT_ACTIONBAR messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Actionbar' is required for CHAT_ACTIONBAR messages at " + section.getCurrentPath());
String hover = section.isString("Hover") ? TextColor.PARSE(section.getString("Hover")) : null;
return new BlobChatActionbarMessage(key, TextColor.PARSE(section.getString("Chat")),
hover,
Expand All @@ -94,11 +95,11 @@ public static BlobMessage read(@NotNull ConfigurationSection section,
}
case "CHAT_TITLE" -> {
if (!section.contains("Chat"))
throw new IllegalArgumentException("'Chat' is required for CHAT_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Chat' is required for CHAT_TITLE messages at " + section.getCurrentPath());
if (!section.contains("Title"))
throw new IllegalArgumentException("'Title' is required for CHAT_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Title' is required for CHAT_TITLE messages at " + section.getCurrentPath());
if (!section.contains("Subtitle"))
throw new IllegalArgumentException("'Subtitle' is required for CHAT_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Subtitle' is required for CHAT_TITLE messages at " + section.getCurrentPath());
String hover = section.isString("Hover") ? TextColor.PARSE(section.getString("Hover")) : null;
int fadeIn = section.getInt("FadeIn", 10);
int stay = section.getInt("Stay", 40);
Expand All @@ -112,13 +113,13 @@ public static BlobMessage read(@NotNull ConfigurationSection section,
}
case "CHAT_ACTIONBAR_TITLE" -> {
if (!section.contains("Chat"))
throw new IllegalArgumentException("'Chat' is required for CHAT_ACTIONBAR_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Chat' is required for CHAT_ACTIONBAR_TITLE messages at " + section.getCurrentPath());
if (!section.contains("Actionbar"))
throw new IllegalArgumentException("'Actionbar' is required for CHAT_ACTIONBAR_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Actionbar' is required for CHAT_ACTIONBAR_TITLE messages at " + section.getCurrentPath());
if (!section.contains("Title"))
throw new IllegalArgumentException("'Title' is required for CHAT_ACTIONBAR_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Title' is required for CHAT_ACTIONBAR_TITLE messages at " + section.getCurrentPath());
if (!section.contains("Subtitle"))
throw new IllegalArgumentException("'Subtitle' is required for CHAT_ACTIONBAR_TITLE messages at " + section.getCurrentPath());
throw new ConfigurationFieldException("'Subtitle' is required for CHAT_ACTIONBAR_TITLE messages at " + section.getCurrentPath());
String hover = section.isString("Hover") ? TextColor.PARSE(section.getString("Hover")) : null;
int fadeIn = section.getInt("FadeIn", 10);
int stay = section.getInt("Stay", 40);
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/us/mytheria/bloblib/entities/BlobSoundReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import us.mytheria.bloblib.api.BlobLibSoundAPI;
import us.mytheria.bloblib.entities.message.BlobSound;
import us.mytheria.bloblib.entities.message.MessageAudience;
import us.mytheria.bloblib.exception.ConfigurationFieldException;

import java.util.Objects;
import java.util.Optional;
Expand All @@ -17,24 +18,24 @@ public class BlobSoundReader {
public static BlobSound read(@NotNull ConfigurationSection section,
@NotNull String key) {
if (!section.contains("Sound"))
throw new IllegalArgumentException("'Sound' is not defined");
throw new ConfigurationFieldException("'Sound' is not defined");
if (!section.contains("Volume"))
throw new IllegalArgumentException("'Volume' is not defined");
throw new ConfigurationFieldException("'Volume' is not defined");
if (!section.contains("Pitch"))
throw new IllegalArgumentException("'Pitch' is not defined");
throw new ConfigurationFieldException("'Pitch' is not defined");
Optional<SoundCategory> category = Optional.empty();
if (section.contains("Category"))
try {
category = Optional.of(SoundCategory.valueOf(section.getString("Category")));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid Sound's Category: " + section.getString("Category"));
throw new ConfigurationFieldException("Invalid Sound's Category: " + section.getString("Category"));
}
MessageAudience audience = MessageAudience.PLAYER;
if (section.contains("Audience"))
try {
audience = MessageAudience.valueOf(section.getString("Audience"));
} catch (IllegalArgumentException e) {
BlobLib.getAnjoLogger().singleError("Invalid Sound's Audience: " + section.getString("Audience"));
throw new ConfigurationFieldException("Invalid Sound's Audience: " + section.getString("Audience"));
}
return new BlobSound(
Sound.valueOf(section.getString("Sound")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.BlobLib;
import us.mytheria.bloblib.action.ActionMemo;
import us.mytheria.bloblib.action.ActionType;
import us.mytheria.bloblib.api.BlobLibTranslatableAPI;
import us.mytheria.bloblib.entities.translatable.TranslatableItem;
import us.mytheria.bloblib.exception.ConfigurationFieldException;
import us.mytheria.bloblib.itemstack.ItemStackReader;
import us.mytheria.bloblib.utilities.IntegerRange;

Expand Down Expand Up @@ -51,14 +51,12 @@ public static BlobMultiSlotable read(ConfigurationSection section, String key,
.getTranslatableItem(reference,
locale);
if (translatableItem == null)
throw new NullPointerException("TranslatableItem not found: " + reference);
throw new ConfigurationFieldException("TranslatableItem not found: " + reference);
itemStack = translatableItem.getClone();
} else {
ConfigurationSection itemStackSection = section.getConfigurationSection("ItemStack");
if (itemStackSection == null) {
Bukkit.getLogger().severe("ItemStack section is null for " + key);
return null;
}
if (itemStackSection == null)
throw new ConfigurationFieldException("'ItemStack' ConfigurationSection is null");
itemStack = ItemStackReader.getInstance().readOrFailFast(itemStackSection);
}
if (section.isInt("Amount")) {
Expand Down Expand Up @@ -110,7 +108,7 @@ public static BlobMultiSlotable read(ConfigurationSection section, String key,
try {
actionType = ActionType.valueOf(singleActionSection.getString("Action-Type"));
} catch (IllegalArgumentException e) {
BlobLib.getAnjoLogger().singleError("Invalid 'ActionType' for " + key + ".Action.Action-Type");
throw new ConfigurationFieldException("Invalid 'ActionType' for " + key + ".Action.Action-Type");
}
}
List<ActionMemo> actions = new ArrayList<>();
Expand All @@ -130,7 +128,7 @@ public static BlobMultiSlotable read(ConfigurationSection section, String key,
try {
type = ActionType.valueOf(actionSection.getString("Action-Type"));
} catch (IllegalArgumentException e) {
BlobLib.getAnjoLogger().singleError("Invalid 'ActionType' for " + key + ".Action.Action-Type");
throw new ConfigurationFieldException("Invalid 'ActionType' for " + key + ".Action.Action-Type");
}
actions.add(new ActionMemo(reference, type));
} else if (actionsSection.isString(key1)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public static InventoryBuilderCarrier<InventoryButton> BLOB_FROM_FILE(@NotNull F
return BLOB_FROM_CONFIGURATION_SECTION(configuration, fileName);
}

@NotNull
public static InventoryBuilderCarrier<InventoryButton> BLOB_FROM_CONFIGURATION_SECTION(
@NotNull ConfigurationSection configurationSection, @NotNull String reference) {
String title = TextColor.PARSE(Objects.requireNonNull(configurationSection,
"'configurationSection' cannot be null!").getString("Title", configurationSection.getName() + ">NOT-SET"));
Objects.requireNonNull(configurationSection, "'configurationSection' cannot be null!");
String title = TextColor.PARSE(configurationSection.getString("Title", configurationSection.getName() + ">NOT-SET"));
int size = configurationSection.getInt("Size", -1);
if (size < 0 || size % 9 != 0) {
if (size < 0) {
Expand Down Expand Up @@ -67,8 +68,8 @@ public static InventoryBuilderCarrier<MetaInventoryButton> META_FROM_FILE(@NotNu

public static InventoryBuilderCarrier<MetaInventoryButton> META_FROM_CONFIGURATION_SECTION(
@NotNull ConfigurationSection configurationSection, @NotNull String reference) {
String title = TextColor.PARSE(Objects.requireNonNull(configurationSection,
"'configurationSection' cannot be null!").getString("Title", configurationSection.getName() + ">NOT-SET"));
Objects.requireNonNull(configurationSection, "'configurationSection' cannot be null!");
String title = TextColor.PARSE(configurationSection.getString("Title", configurationSection.getName() + ">NOT-SET"));
int size = configurationSection.getInt("Size", -1);
if (size < 0 || size % 9 != 0) {
if (size < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.BlobLib;
import us.mytheria.bloblib.action.ActionMemo;
import us.mytheria.bloblib.action.ActionType;
import us.mytheria.bloblib.api.BlobLibTranslatableAPI;
import us.mytheria.bloblib.entities.translatable.TranslatableItem;
import us.mytheria.bloblib.exception.ConfigurationFieldException;
import us.mytheria.bloblib.itemstack.ItemStackReader;
import us.mytheria.bloblib.utilities.IntegerRange;

Expand Down Expand Up @@ -55,13 +55,12 @@ public static MetaBlobMultiSlotable read(ConfigurationSection section, String ke
.getTranslatableItem(reference,
locale);
if (translatableItem == null)
throw new NullPointerException("TranslatableItem not found: " + reference);
throw new ConfigurationFieldException("TranslatableItem not found: " + reference);
itemStack = translatableItem.getClone();
} else {
ConfigurationSection itemStackSection = section.getConfigurationSection("ItemStack");
if (itemStackSection == null) {
Bukkit.getLogger().severe("ItemStack section is null for " + key);
return null;
throw new ConfigurationFieldException("'ItemStack' ConfigurationSection is null");
}
itemStack = ItemStackReader.getInstance().readOrFailFast(itemStackSection);
}
Expand Down Expand Up @@ -119,7 +118,7 @@ public static MetaBlobMultiSlotable read(ConfigurationSection section, String ke
try {
actionType = ActionType.valueOf(singleActionSection.getString("Action-Type"));
} catch (IllegalArgumentException e) {
BlobLib.getAnjoLogger().singleError("Invalid 'ActionType' for " + key + ".Action.Action-Type");
throw new ConfigurationFieldException("Invalid 'ActionType' for " + key + ".Action.Action-Type");
}
}
List<ActionMemo> actions = new ArrayList<>();
Expand All @@ -139,7 +138,7 @@ public static MetaBlobMultiSlotable read(ConfigurationSection section, String ke
try {
type = ActionType.valueOf(actionSection.getString("Action-Type"));
} catch (IllegalArgumentException e) {
BlobLib.getAnjoLogger().singleError("Invalid 'ActionType' for " + key + ".Action.Action-Type");
throw new ConfigurationFieldException("Invalid 'ActionType' for " + key + ".Action.Action-Type");
}
actions.add(new ActionMemo(reference, type));
} else if (actionsSection.isString(key1)) {
Expand Down
Loading

0 comments on commit edb2679

Please sign in to comment.