Skip to content

Commit

Permalink
what did i do here
Browse files Browse the repository at this point in the history
  • Loading branch information
yusshu committed Mar 16, 2024
1 parent 929049f commit fe4825d
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 300 deletions.
1 change: 1 addition & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
api("org.ahocorasick:ahocorasick:0.6.3")

compileOnlyApi(libs.annotations)
compileOnlyApi(libs.gson)

// Adventure!
compileOnlyApi(libs.adventure.api)
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ adventure = "4.12.0"
creative = "1.3.0" # keep in sync with creative-central's creative version
creative-central = "0.10.0-SNAPSHOT"
annotations = "22.0.0"
gson = "2.10.1"

[libraries]
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
adventure-api = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" }
adventure-text-minimessage = { group = "net.kyori", name = "adventure-text-minimessage", version.ref = "adventure" }
creative-api = { group = "team.unnamed", name = "creative-api", version.ref = "creative" }
Expand Down
7 changes: 6 additions & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
maven("https://repo.essentialsx.net/releases/") // EssentialsDiscord
maven("https://nexus.scarsz.me/content/groups/public/") // DiscordSRV
maven("https://m2.dv8tion.net/releases") // JDA - Required by DiscordSRV
maven("https://repo.unnamed.team/repository/unnamed-public/") // creative
maven("https://repo.unnamed.team/repository/unnamed-public/") // creative, command-flow
mavenCentral()
}

Expand All @@ -26,6 +26,10 @@ dependencies {
// Optional libraries
compileOnly(libs.adventure.text.minimessage)

// Internal libraries
implementation("me.fixeddev:commandflow-universal:0.6.0") // command-flow
implementation("me.fixeddev:commandflow-bukkit:0.6.0") // command-flow

// Optional plugin hooks
compileOnly("me.clip:placeholderapi:2.10.10")
compileOnly(files("../lib/TownyChat-0.91.jar", "../lib/EzChat-3.0.3.jar"))
Expand All @@ -43,5 +47,6 @@ tasks {
shadowJar {
val pkg = "team.unnamed.creativeglyphs.lib"
relocate("org.ahocorasick", "$pkg.ahocorasick")
relocate("me.fixeddev.commandflow", "$pkg.commandflow")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.bukkit.plugin.java.JavaPlugin;
import team.unnamed.creative.central.CreativeCentralProvider;
import team.unnamed.creative.central.event.pack.ResourcePackGenerateEvent;
import team.unnamed.creativeglyphs.plugin.command.RootCommand;
import team.unnamed.creativeglyphs.plugin.command.CommandService;
import team.unnamed.creativeglyphs.plugin.integration.carbon.CarbonChatIntegration;
import team.unnamed.creativeglyphs.plugin.integration.essentialsdiscord.EssentialsDiscordIntegration;
import team.unnamed.creativeglyphs.plugin.listener.misc.AnvilEditListener;
Expand Down Expand Up @@ -87,8 +87,8 @@ public void onEnable() {

EventBus eventBus = EventBus.create(this);

Objects.requireNonNull(getCommand("emojis"), "'emojis' command not registered")
.setExecutor(new RootCommand(this).asExecutor());
// todo:!
new CommandService(this).start();

Set<PluginIntegration> hooks = IntegrationManager.integrationManager(this)
.register(new CarbonChatIntegration(this))
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package team.unnamed.creativeglyphs.plugin.command;

import me.fixeddev.commandflow.annotated.AnnotatedCommandTreeBuilder;
import me.fixeddev.commandflow.annotated.part.PartInjector;
import me.fixeddev.commandflow.annotated.part.defaults.DefaultsModule;
import me.fixeddev.commandflow.bukkit.BukkitCommandManager;
import me.fixeddev.commandflow.bukkit.factory.BukkitModule;
import org.jetbrains.annotations.NotNull;
import team.unnamed.creativeglyphs.plugin.CreativeGlyphsPlugin;

import static java.util.Objects.requireNonNull;

public final class CommandService {
private final CreativeGlyphsPlugin plugin;

public CommandService(final @NotNull CreativeGlyphsPlugin plugin) {
this.plugin = requireNonNull(plugin, "plugin");
}

public void start() {
final var manager = new BukkitCommandManager(plugin.getName());
final var partInjector = PartInjector.create();

partInjector.install(new DefaultsModule());
partInjector.install(new BukkitModule());

final var builder = AnnotatedCommandTreeBuilder.create(partInjector);

manager.registerCommands(builder.fromClass(new GlyphsCommand(plugin)));
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,97 @@
package team.unnamed.creativeglyphs.plugin.command;

import me.fixeddev.commandflow.annotated.CommandClass;
import me.fixeddev.commandflow.annotated.annotation.Command;
import me.fixeddev.commandflow.annotated.annotation.Named;
import me.fixeddev.commandflow.annotated.annotation.OptArg;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import team.unnamed.creative.central.CreativeCentralProvider;
import team.unnamed.creativeglyphs.Glyph;
import team.unnamed.creativeglyphs.plugin.CreativeGlyphsPlugin;
import team.unnamed.creativeglyphs.plugin.util.Permissions;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class ListSubCommand implements CommandRunnable {
import static java.util.Objects.requireNonNull;

@Command(names = { "glyphs", "glyph", "emojis", "emoji" })
public final class GlyphsCommand implements CommandClass {
private static final String API_URL = "https://artemis.unnamed.team/tempfiles/get/%id%";

private final CreativeGlyphsPlugin plugin;

public ListSubCommand(CreativeGlyphsPlugin plugin) {
this.plugin = plugin;
public GlyphsCommand(final @NotNull CreativeGlyphsPlugin plugin) {
this.plugin = requireNonNull(plugin, "plugin");
}

@Override
@SuppressWarnings("deprecation") // Spigot
public void run(CommandSender sender, ArgumentStack args) {
@Command(names = {"help", "?"}, permission = "emojis.admin")
public void help(final @NotNull CommandSender sender) {
sender.sendMessage(ChatColor.translateAlternateColorCodes(
'&',
plugin.getConfig().getString("messages.help", "Message not found")
));
}

@Command(names = "reload", permission = "emojis.admin")
public void reload() {
plugin.reloadConfig();
plugin.registry().load();
}

@Command(names = "update", permission = "emojis.admin")
public void update(final @NotNull CommandSender sender, final @NotNull @Named("id") String id) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> execute(sender, id));
}

@Command(names = "edit", permission = "emojis.admin")
public void edit(final @NotNull CommandSender sender) {
}

private void execute(CommandSender sender, String id) {
try {
URL url = new URL(API_URL.replace("%id%", id));
Collection<Glyph> glyphs = plugin.importer().importHttp(url);

// synchronous update and save
Bukkit.getScheduler().runTask(plugin, () -> {
plugin.registry().setGlyphs(glyphs);
plugin.registry().save();

// asynchronous export
CreativeCentralProvider.get().generate();
});
} catch (IOException e) {
sender.sendMessage(ChatColor.RED + "Something went wrong, please" +
" contact an administrator to read the console.");
e.printStackTrace();
} catch (IllegalStateException e) {
// stack trace in this case isn't so relevant
sender.sendMessage(ChatColor.RED + e.getMessage());
}
}

@Command(names = "list")
@SuppressWarnings("deprecation") // Spigot
public void list(final @NotNull CommandSender sender, final @OptArg("0") @Named("page") int page) {
// load the configuration for listing emojis
ConfigurationSection listConfig = plugin.getConfig().getConfigurationSection("messages.list");
if (listConfig == null) {
throw new IllegalStateException("No configuration for list subcommand");
}

int page = -1;
if (args.hasNext()) {
try {
page = Integer.parseInt(args.next()) - 1;
} catch (NumberFormatException ignored) {
// lets 'page' be -1, detected later
}
} else {
page = 0;
}

// load the separation config
ConfigurationSection separationConfig = listConfig.getConfigurationSection("separation");
Map<Integer, String> separators = new TreeMap<>((a, b) -> b - a);
Expand Down Expand Up @@ -113,9 +161,9 @@ public void run(CommandSender sender, ArgumentStack args) {

TextComponent component = new TextComponent(
ChatColor.translateAlternateColorCodes(
'&',
'&',
listConfig.getString(basePath + ".content", "Not found")
)
)
.replace("<emoji>", glyph.replacement())
.replace("<emojiname>", glyph.name())
);
Expand Down Expand Up @@ -154,5 +202,4 @@ public void run(CommandSender sender, ArgumentStack args) {
.replace("<maxpages>", String.valueOf(maxPages))
);
}

}

This file was deleted.

Loading

0 comments on commit fe4825d

Please sign in to comment.