-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change meta embedding method, add version command
- Loading branch information
1 parent
06175ce
commit 58d6a3e
Showing
9 changed files
with
119 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/pink/zak/minestom/operadora/command/VersionCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package pink.zak.minestom.operadora.command; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.JoinConfiguration; | ||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import net.minestom.server.MinecraftServer; | ||
import net.minestom.server.command.CommandSender; | ||
import net.minestom.server.command.builder.Command; | ||
import net.minestom.server.command.builder.CommandContext; | ||
import net.minestom.server.command.builder.arguments.ArgumentType; | ||
import net.minestom.server.command.builder.arguments.ArgumentWord; | ||
import net.minestom.server.extensions.DiscoveredExtension; | ||
import net.minestom.server.extensions.Extension; | ||
import net.minestom.server.extensions.ExtensionManager; | ||
import pink.zak.minestom.operadora.Operadora; | ||
import pink.zak.minestom.operadora.config.OperadoraMeta; | ||
|
||
import java.util.Arrays; | ||
|
||
public class VersionCommand extends Command { | ||
private final OperadoraMeta meta = Operadora.getMeta(); | ||
private final ExtensionManager extensionManager = MinecraftServer.getExtensionManager(); | ||
|
||
public VersionCommand() { | ||
super("version", "ver", "v"); | ||
|
||
ArgumentWord extensionArgument = ArgumentType.Word("extension").from( | ||
this.extensionManager.getExtensions().stream() | ||
.map(extension -> extension.getOrigin().getName()) | ||
.toArray(String[]::new) | ||
); | ||
|
||
this.setDefaultExecutor(this::versionCommand); | ||
this.addSyntax(this::extensionVersionCommand, extensionArgument); | ||
} | ||
|
||
private void versionCommand(CommandSender sender, CommandContext context) { | ||
Component content = Component.text("Running Operadora version " + this.meta.version() + " (#" + this.meta.buildNumber() + " git-" + this.meta.shortCommitHash() + ")"); | ||
sender.sendMessage(content); | ||
} | ||
|
||
private void extensionVersionCommand(CommandSender sender, CommandContext context) { | ||
String extensionName = context.get("extension"); | ||
Extension extension = this.extensionManager.getExtension(extensionName); | ||
DiscoveredExtension origin = extension.getOrigin(); | ||
|
||
JoinConfiguration joinConfiguration = JoinConfiguration.builder() | ||
.separator(Component.text(", ", NamedTextColor.GREEN)) | ||
.build(); | ||
|
||
Component content = Component.text(extensionName + " v" + origin.getVersion() + " ", NamedTextColor.GREEN); | ||
|
||
if (origin.getAuthors().length > 0) | ||
content = content | ||
.append(Component.text("\nAuthors: ", NamedTextColor.WHITE)) | ||
.append(Component.join(joinConfiguration, Arrays.stream(origin.getAuthors()).map(Component::text).toArray(Component[]::new))); | ||
|
||
sender.sendMessage(content); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/pink/zak/minestom/operadora/config/OperadoraMeta.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package pink.zak.minestom.operadora.config; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import pink.zak.minestom.operadora.utils.data.FileUtils; | ||
|
||
public record OperadoraMeta(String version, String buildNumber, String commitHash) { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(OperadoraMeta.class); | ||
|
||
public static OperadoraMeta load() { | ||
try { | ||
String jsonString = new String(FileUtils.class.getClassLoader().getResourceAsStream("operadora.json").readAllBytes()); | ||
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject(); | ||
System.out.println(jsonString); | ||
System.out.println(jsonObject); | ||
return new OperadoraMeta( | ||
jsonObject.get("version").getAsString(), | ||
jsonObject.get("buildNumber").getAsString(), | ||
jsonObject.get("commitHash").getAsString() | ||
); | ||
} catch (Exception ex) { | ||
LOGGER.error("Error loading OperadoraMeta (MANIFEST.MF)", ex); | ||
return null; | ||
} | ||
} | ||
|
||
public String shortCommitHash() { | ||
return this.commitHash.substring(0, 7); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,7 @@ operadora: { | |
} | ||
stop: { | ||
enabled = true | ||
} | ||
version: { | ||
enabled = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": "${version}", | ||
"buildNumber": "${build_number}", | ||
"commitHash": "${commit_hash}" | ||
} |