Skip to content

Commit

Permalink
🚀 let me cook pls
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed May 6, 2024
1 parent f235dc8 commit 15f8adc
Show file tree
Hide file tree
Showing 11 changed files with 1,159 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/info/itsthesky/disky/DiSky.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import info.itsthesky.disky.core.DiSkyCommand;
import info.itsthesky.disky.core.Utils;
import info.itsthesky.disky.elements.properties.ConstLogs;
import info.itsthesky.disky.elements.structures.slash.SlashManager;
import info.itsthesky.disky.managers.BotManager;
import info.itsthesky.disky.managers.Configuration;
import info.itsthesky.disky.managers.WebhooksManager;
import net.dv8tion.jda.api.requests.RestAction;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down Expand Up @@ -195,11 +197,12 @@ public static void debug(String s) {

private void debugMessage(String s) {
if (getConfiguration().getOrSetDefault("debug", false))
getLogger().info(ChatColor.DARK_PURPLE + "DEBUG: " + ChatColor.LIGHT_PURPLE + s);
Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_PURPLE + "DEBUG: " + ChatColor.LIGHT_PURPLE + s);
}

@Override
public void onDisable() {
SlashManager.shutdownAll();
botManager.shutdown();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package info.itsthesky.disky.api.skript.entries;

import ch.njol.skript.ScriptLoader;
import ch.njol.skript.config.Node;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.config.SimpleNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.entry.EntryContainer;
import org.skriptlang.skript.lang.entry.EntryData;
import org.skriptlang.skript.lang.entry.EntryValidator;
import org.skriptlang.skript.lang.entry.KeyValueEntryData;

import java.util.function.Function;

public class MutexEntryData<T> extends EntryData<MutexEntryData.MutexEntry<T>> {

private EntryValidator entryValidator;
private KeyValueEntryData<T> valueEntryData;

public MutexEntryData(String key, @Nullable T defaultValue, boolean optional,
EntryValidator entryValidator, Function<String, T> parser) {
super(key, MutexEntryData.MutexEntry.ofValue(defaultValue), optional);
this.entryValidator = entryValidator;
this.valueEntryData = new KeyValueEntryData<T>(key,
defaultValue, false) {

@Override
protected T getValue(@NotNull String value) {
return parser.apply(value);
}

@Override
public @NotNull String getSeparator() {
return ":";
}

};
}

@Override
public MutexEntryData.MutexEntry<T> getValue(@NotNull Node node) {
if (node instanceof SimpleNode) {
final T value = valueEntryData.getValue(node);
return MutexEntryData.MutexEntry.ofValue(value);
} else if (node instanceof SectionNode) {
final @Nullable EntryContainer entry = entryValidator.validate((SectionNode) node);
if (entry == null)
return MutexEntryData.MutexEntry.empty();

return MutexEntryData.MutexEntry.ofEntry(entry);
}

return MutexEntryData.MutexEntry.empty();
}

@Override
public boolean canCreateWith(@NotNull Node node) {
if (node instanceof SectionNode) {
String key = node.getKey();
if (key == null)
return false;
key = ScriptLoader.replaceOptions(key);
return getKey().equalsIgnoreCase(key);
}

return valueEntryData.canCreateWith(node);
}

public static class MutexEntry<T> {

public static <T> MutexEntry<T> ofEntry(@NotNull EntryContainer entry) {
return new MutexEntry<>(null, entry);
}

public static <T> MutexEntry<T> ofValue(@NotNull T value) {
return new MutexEntry<>(value, null);
}

public static <T> MutexEntry<T> empty() {
return new MutexEntry<>(null, null);
}

private final @Nullable T value;
private final @Nullable EntryContainer entry;

private MutexEntry(@Nullable T value,
@Nullable EntryContainer entry) {
this.value = value;
this.entry = entry;
}

public @Nullable T getValue() {
return value;
}

public @Nullable EntryContainer getEntryContainer() {
return entry;
}

public boolean isComplex() {
return entry != null;
}

public boolean isValid() {
return value != null || entry != null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package info.itsthesky.disky.api.skript.entries;

import ch.njol.skript.Skript;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.entry.KeyValueEntryData;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.regex.Pattern;

public final class SimpleKeyValueEntries {
private static final Pattern LIST = Pattern.compile("\\s*,\\s*/?");

public static KeyValueEntryData<Boolean> createBooleanEntry(String key, boolean def, boolean optional) {
return new KeyValueEntryData<Boolean>(key, def, optional) {
@Override
protected @Nullable Boolean getValue(@NotNull String value) {
try {
return Boolean.parseBoolean(value);
} catch (Exception e) {
Skript.error("Cannot parse the value as a boolean! (got " + value + ")");
return null;
}
}
};
}

public static <T> KeyValueEntryData<List<T>> createList(String key, List<T> def, boolean optional,
Function<String, T> singleParser) {
return new KeyValueEntryData<List<T>>(key, def, optional) {
@Override
protected @Nullable List<T> getValue(@NotNull String value) {
final String[] values = LIST.split(value);
final List<T> result = new ArrayList<>();
for (String val : values) {
try {
final T parsed = singleParser.apply(val);
if (parsed == null) {
return null;
}
result.add(parsed);
} catch (Exception e) {
Skript.error("Cannot parse the value as a list! (got " + value + ")");
return null;
}
}

return result;
}
};
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package info.itsthesky.disky.api.skript.entries;

import ch.njol.skript.ScriptLoader;
import ch.njol.skript.config.Node;
import ch.njol.skript.config.SectionNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.entry.EntryContainer;
import org.skriptlang.skript.lang.entry.EntryData;
import org.skriptlang.skript.lang.entry.EntryValidator;

public class SubEntryData extends EntryData<EntryContainer> {

private final EntryValidator validator;

public SubEntryData(String key, boolean optional, EntryValidator validator) {
super(key, null, optional);
this.validator = validator;
}

@Override
public @Nullable EntryContainer getValue(@NotNull Node node) {
assert node instanceof SectionNode;
return validator.validate((SectionNode) node);
}

@Override
public boolean canCreateWith(@NotNull Node node) {
if (!(node instanceof SectionNode))
return false;
String key = node.getKey();
if (key == null)
return false;
key = ScriptLoader.replaceOptions(key);
return getKey().equalsIgnoreCase(key);
}

}
7 changes: 7 additions & 0 deletions src/main/java/info/itsthesky/disky/core/SkriptUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.entry.EntryValidator;

import java.lang.reflect.Array;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -273,4 +274,10 @@ public static Date convertDateTime(@Nullable OffsetDateTime dateTime) {
public static void dispatchEvent(Event e) {
SkriptUtils.sync(() -> Bukkit.getPluginManager().callEvent(e));
}

public static EntryValidator custom() {
return EntryValidator.builder()
.unexpectedNodeTester(node -> false)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

public class StructBot extends Structure {

private static final Priority PRIORITY = new Priority(500);

public static final GatewayIntent[] DefaultIntents = new GatewayIntent[] {
GatewayIntent.GUILD_MODERATION,
GatewayIntent.GUILD_EMOJIS_AND_STICKERS,
Expand Down Expand Up @@ -260,4 +262,9 @@ protected MemberCachePolicy parse(String input) {
public @NotNull String toString(@Nullable Event e, boolean debug) {
return "define bot named " + name;
}

@Override
public @NotNull Priority getPriority() {
return PRIORITY;
}
}
Loading

1 comment on commit 15f8adc

@Mushkrem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CryCryingGIF (2)

Please sign in to comment.