use of net.anweisen.utilities.common.collection.WrappedException in project Utility by anweisen.
the class MessageReplyMessageAction method addActionRows.
@Nonnull
@Override
@SuppressWarnings("unchecked")
public ReplyMessageAction addActionRows(@Nonnull ActionRow... rows) {
try {
Class<?> actionClass = action.getClass();
Field componentsField = actionClass.getDeclaredField("components");
componentsField.setAccessible(true);
final Collection<ActionRow> components;
Object componentsObject = componentsField.get(action);
if (componentsObject instanceof Collection)
components = (Collection<ActionRow>) componentsObject;
else
components = new ArrayList<>(rows.length);
Collections.addAll(components, rows);
action.setActionRows(components);
return this;
} catch (Throwable ex) {
throw new WrappedException("Reflections for injecting components failed, JDA v" + JDAInfo.VERSION + " | ActionClass " + action.getClass().getName(), ex);
}
}
use of net.anweisen.utilities.common.collection.WrappedException in project Utility by anweisen.
the class BukkitModule method onLoad.
@Override
public final void onLoad() {
isLoaded = true;
if (!requirementsMet || !(requirementsMet = new RequirementsChecker(this).checkBoolean(getPluginDocument().getDocument("require"))))
return;
if (setFirstInstance || firstInstance == null) {
setFirstInstance(this);
}
ILogger.setConstantFactory(this.getLogger());
trySaveDefaultConfig();
if (wasShutdown)
isReloaded = true;
if (firstInstall = !getDataFolder().exists()) {
getLogger().info("Detected first install!");
}
if (devMode = getConfigDocument().getBoolean("dev-mode") || getConfigDocument().getBoolean("dev-mode.enabled")) {
getLogger().setLevel(Level.ALL);
getLogger().debug("Devmode is enabled: Showing debug messages. This can be disabled in the plugin.yml ('dev-mode')");
} else {
getLogger().setLevel(Level.INFO);
}
injectInstance();
try {
handleLoad();
} catch (Exception ex) {
throw new WrappedException(ex);
}
}
use of net.anweisen.utilities.common.collection.WrappedException in project Utility by anweisen.
the class BukkitModule method onEnable.
@Override
public final void onEnable() {
if (!requirementsMet)
return;
commands.forEach((name, executor) -> registerCommand0(executor, name));
listeners.forEach(this::registerListener);
try {
handleEnable();
} catch (Exception ex) {
throw new WrappedException(ex);
}
}
use of net.anweisen.utilities.common.collection.WrappedException in project Utility by anweisen.
the class StringUtils method format.
@Nonnull
public static String format(@Nonnull String sequence, @Nonnull Object... args) {
char start = '{', end = '}';
boolean inArgument = false;
StringBuilder argument = new StringBuilder();
StringBuilder builder = new StringBuilder();
for (char c : sequence.toCharArray()) {
if (c == end && inArgument) {
inArgument = false;
try {
int arg = Integer.parseInt(argument.toString());
Object current = args[arg];
Object replacement = current instanceof Supplier ? ((Supplier<?>) current).get() : current instanceof Callable ? ((Callable<?>) current).call() : current;
builder.append(replacement);
} catch (NumberFormatException | IndexOutOfBoundsException ex) {
logger.warn("Invalid argument index '{}'", argument);
builder.append(start).append(argument).append(end);
} catch (Exception ex) {
throw new WrappedException(ex);
}
argument = new StringBuilder();
continue;
}
if (c == start && !inArgument) {
inArgument = true;
continue;
}
if (inArgument) {
argument.append(c);
continue;
}
builder.append(c);
}
if (argument.length() > 0)
builder.append(start).append(argument);
return builder.toString();
}
use of net.anweisen.utilities.common.collection.WrappedException in project Utility by anweisen.
the class Document method readJsonArrayFile.
@Nonnull
@CheckReturnValue
static List<Document> readJsonArrayFile(@Nonnull Path file) {
try {
JsonArray array = GsonDocument.GSON.fromJson(FileUtils.newBufferedReader(file), JsonArray.class);
if (array == null)
return new ArrayList<>();
List<Document> documents = new ArrayList<>(array.size());
array.forEach(element -> documents.add(new GsonDocument(element.getAsJsonObject())));
return documents;
} catch (IOException ex) {
throw new WrappedException(ex);
}
}
Aggregations