Modify the about command

This commit is contained in:
2023-12-29 12:43:58 +01:00
parent f37a196dd9
commit f657816533
5 changed files with 76 additions and 6 deletions

View File

@@ -460,7 +460,7 @@ public class Stargate extends JavaPlugin {
private void registerCommands() {
PluginCommand stargateCommand = this.getCommand("stargate");
if (stargateCommand != null) {
stargateCommand.setExecutor(new CommandStarGate());
stargateCommand.setExecutor(new CommandStarGate(this));
stargateCommand.setTabCompleter(new StarGateTabCompleter());
}
}

View File

@@ -1,12 +1,18 @@
package net.knarcraft.stargate.command;
import de.themoep.minedown.MineDown;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.utility.FileHelper;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.InputStream;
/**
* This command represents the plugin's about command
*/
@@ -18,10 +24,14 @@ public class CommandAbout implements CommandExecutor {
ChatColor textColor = ChatColor.GOLD;
ChatColor highlightColor = ChatColor.GREEN;
commandSender.sendMessage(textColor + "Stargate Plugin originally created by " + highlightColor +
"Drakia" + textColor + ", and revived by " + highlightColor + "EpicKnarvik97");
commandSender.sendMessage(textColor + "Go to " + highlightColor +
"https://git.knarcraft.net/EpicKnarvik97/Stargate " + textColor + "for the official repository");
try(InputStream inputStream = Stargate.class.getResourceAsStream("/messages/about.md")){
String aboutMessageString = FileHelper.readStreamToString(inputStream);
BaseComponent[] component = MineDown.parse(aboutMessageString);
commandSender.spigot().sendMessage(component);
} catch (IOException ioException){
commandSender.sendMessage("Internal error");
}
String author = Stargate.getStargateConfig().getLanguageLoader().getString("author");
if (!author.isEmpty()) {
commandSender.sendMessage(textColor + "Language created by " + highlightColor + author);

View File

@@ -0,0 +1,30 @@
package net.knarcraft.stargate.utility;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
public class FileHelper {
/**
* Converts the stream directly into a string, includes the newline character
*
* @param stream <p> The stream to read from </p>
* @return <p> A String of the file read </p>
* @throws IOException <p>If unable to read the stream</p>
*/
public static String readStreamToString(InputStream stream) throws IOException {
InputStreamReader inputStreamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
BufferedReader reader = new BufferedReader(inputStreamReader);
String line = reader.readLine();
StringBuilder lines = new StringBuilder();
while (line != null) {
lines.append(line).append("\n");
line = reader.readLine();
}
return lines.toString();
}
}