Skip to content

Commit

Permalink
Init and update Langfiles
Browse files Browse the repository at this point in the history
Found this Gem on my Shelf. Feel like I already committed it, but I cant find it.
  • Loading branch information
FireInstall committed Jan 24, 2024
1 parent 6090747 commit 3314e72
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 141 deletions.
6 changes: 6 additions & 0 deletions Minigames/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
</dependency>
<!-- part of org.apache.commons -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.15.1</version>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import au.com.mineauz.minigames.Minigames;
import au.com.mineauz.minigames.backend.BackendManager;
import au.com.mineauz.minigames.backend.ExportNotifier;
import au.com.mineauz.minigames.managers.MinigameMessageManager;
import au.com.mineauz.minigames.managers.language.langkeys.MgCommandLangKey;
import au.com.mineauz.minigames.minigame.Minigame;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
Expand Down Expand Up @@ -31,12 +33,15 @@ public boolean canBeConsole() {

@Override
public @NotNull Component getDescription() {
return "Allows access to export and change the backend used by minigames.";
return MinigameMessageManager.getMgMessage(MgCommandLangKey.COMMAND_BACKEND_DESCRIPTION);
}

@Override
public Component getUsage() {
return new String[]{"/minigame backend export <type>", "/minigame backend switch <type>"};
return new String[]{
"/minigame backend export <type>",
"/minigame backend switch <type>"
};
}

@Override
Expand All @@ -61,7 +66,7 @@ public boolean onCommand(final @NotNull CommandSender sender, @NotNull Minigame
Futures.addCallback(future, new FutureCallback<>() {
@Override
public void onFailure(@NotNull Throwable t) {
sender.sendMessage(ChatColor.RED + "An internal error occurred while exporting.");
sender.sendMessage(ChatColor.RED + "An internal error occurred while exporting." + t.getMessage());
}

@Override
Expand Down Expand Up @@ -91,8 +96,6 @@ public void onSuccess(Void result) {
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + e.getMessage());
}
} else {
sender.sendMessage(ChatColor.RED + "Unknown option " + args[0]);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,13 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

public class CommandDispatcher implements CommandExecutor, TabCompleter {
private static final Map<String, ICommand> commands = new HashMap<>();
private static final Minigames plugin = Minigames.getPlugin();
private static BufferedWriter cmdFile;

static {
if (plugin.getConfig().getBoolean("outputCMDToFile")) {
try {
cmdFile = new BufferedWriter(new FileWriter(plugin.getDataFolder() + "/cmds.txt"));
cmdFile.write("{| class=\"wikitable\"");
cmdFile.newLine();
cmdFile.write("! Command");
cmdFile.newLine();
cmdFile.write("! Syntax");
cmdFile.newLine();
cmdFile.write("! Description");
cmdFile.newLine();
cmdFile.write("! Permission");
cmdFile.newLine();
cmdFile.write("! Alias");
cmdFile.newLine();
} catch (IOException e) {
Minigames.getCmpnntLogger().warn("Couldn't output cmds to file!", e);
}
}
registerCommand(new CreateCommand());
registerCommand(new SetCommand());
registerCommand(new JoinCommand());
Expand Down Expand Up @@ -75,57 +52,10 @@ public class CommandDispatcher implements CommandExecutor, TabCompleter {
registerCommand(new BackendCommand());
registerCommand(new InfoCommand());
registerCommand(new ResourcePackCommand());

if (plugin.getConfig().getBoolean("outputCMDToFile")) {
try {
cmdFile.write("|}");
cmdFile.close();
} catch (IOException e) {
Minigames.getCmpnntLogger().warn("Couldn't save cmds file!", e);
}
}
}

public static void registerCommand(ICommand command) {
commands.put(command.getName(), command);

if (plugin.getConfig().getBoolean("outputCMDToFile")) {
try {
cmdFile.write("|-");
cmdFile.newLine();
cmdFile.write("| '''" + command.getName() + "'''");
cmdFile.newLine();
if (command.getUsage() != null) {
cmdFile.write("| " + command.getUsage());
} else {
cmdFile.write("| N/A");
}
cmdFile.newLine();
command.getDescription();
cmdFile.write("| " + command.getDescription());
cmdFile.newLine();
if (command.getPermission() != null)
cmdFile.write("| " + command.getPermission());
else
cmdFile.write("| N/A");
cmdFile.newLine();
if (command.getAliases() != null) {
int count = 0;
cmdFile.write("| ");
for (String alias : command.getAliases()) {
cmdFile.write(alias);
count++;
if (count != command.getAliases().length) {
cmdFile.write("\n\n");
}
}
} else
cmdFile.write("| N/A");
cmdFile.newLine();
} catch (IOException e) {
//Failed to write
}
}
}

public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
Expand Down Expand Up @@ -182,7 +112,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
} else {
sender.sendMessage(ChatColor.GREEN + "Minigames");
sender.sendMessage(ChatColor.GRAY + "By: " + plugin.getDescription().getAuthors().get(0));
sender.sendMessage(ChatColor.GRAY + "By: " + plugin.getDescription().getAuthors());
sender.sendMessage(ChatColor.GRAY + "Version: " + plugin.getDescription().getVersion());
sender.sendMessage(ChatColor.GRAY + "Type /minigame help for help");
return true;
Expand All @@ -205,11 +135,9 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
}

if (comd != null) {
if (sender instanceof Player) { // todo ok, but why? let the commands test if a player was needed.
if (args.length > 1) {
List<String> l = comd.onTabComplete(sender, null, shortArgs);
return Objects.requireNonNullElseGet(l, () -> List.of(""));
}
if (args.length > 1) {
List<String> l = comd.onTabComplete(sender, null, shortArgs);
return Objects.requireNonNullElseGet(l, () -> List.of(""));
}
} else {
List<String> ls = new ArrayList<>(commands.keySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import au.com.mineauz.minigames.gametypes.MinigameType;
import au.com.mineauz.minigames.managers.MinigameMessageManager;
import au.com.mineauz.minigames.managers.language.MinigameMessageType;
import au.com.mineauz.minigames.managers.language.MinigamePlaceHolderKey;
import au.com.mineauz.minigames.managers.language.langkeys.MgCommandLangKey;
import au.com.mineauz.minigames.minigame.Minigame;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -29,13 +32,12 @@ public boolean canBeConsole() {

@Override
public @NotNull Component getDescription() {
return "Creates a Minigame using the specified name. Optionally, adding the type at the end will " +
"set the type of minigame straight up. (Type defaults to SINGLEPLAYER)";
return MinigameMessageManager.getMgMessage(MgCommandLangKey.COMMAND_CREATE_DESCRIPTION);
}

@Override
public String[] getUsage() {
return new String[]{"/minigame create <Minigame> [type]"};
public Component getUsage() {
return MinigameMessageManager.getMgMessage(MgCommandLangKey.COMMAND_CREATE_USAGE);
}

@Override
Expand All @@ -44,24 +46,29 @@ public String[] getUsage() {
}

@Override
public boolean onCommand(@NotNull CommandSender sender, Minigame minigame, @NotNull String @Nullable [] args) {
public boolean onCommand(@NotNull CommandSender sender, @Nullable Minigame minigame, @NotNull String @Nullable [] args) {
if (args != null) {
Player player = (Player) sender;
String mgmName = args[0];
if (MinigameUtils.sanitizeYamlString(mgmName) == null) {
throw new CommandException("Name is not valid for use in a Config.");
}
if (!plugin.getMinigameManager().hasMinigame(mgmName)) {
MinigameType type = MinigameType.SINGLEPLAYER;
MinigameType type;
if (args.length >= 2) {
if (MinigameType.hasValue(args[1].toUpperCase())) {
type = MinigameType.valueOf(args[1].toUpperCase());
} else {
MinigameMessageManager.sendMessage(player, MinigameMessageType.ERROR, null, "command.create.noName", args[1]);
MinigameMessageManager.sendMgMessage(player, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_NOTTYPE,
Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), args[1]));
return false;
}
} else {
type = MinigameType.SINGLEPLAYER;
}
Minigame mgm = new Minigame(mgmName, type, player.getLocation());
MinigameMessageManager.sendMessage(player, MinigameMessageType.INFO, null, "command.create.success", args[0]);
MinigameMessageManager.sendMgMessage(player, MinigameMessageType.INFO, MgCommandLangKey.COMMAND_CREATE_SUCCESS,
Placeholder.unparsed(MinigamePlaceHolderKey.MINIGAME.getKey(), args[0]));
List<String> mgs;
if (plugin.getConfig().contains("minigames")) {
mgs = plugin.getConfig().getStringList("minigames");
Expand All @@ -75,15 +82,15 @@ public boolean onCommand(@NotNull CommandSender sender, Minigame minigame, @NotN
mgm.saveMinigame();
plugin.getMinigameManager().addMinigame(mgm);
} else {
MinigameMessageManager.sendMessage(sender, MinigameMessageType.ERROR, null, "command.create.nameexists");
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_CREATE_ERROR_EXISTS);
}
return true;
}
return false;
}

@Override
public @Nullable List<@NotNull String> onTabComplete(@NotNull CommandSender sender, Minigame minigame,
public @Nullable List<@NotNull String> onTabComplete(@NotNull CommandSender sender, @Nullable Minigame minigame,
@NotNull String @NotNull [] args) {
if (args.length == 2) {
List<String> types = new ArrayList<>(MinigameType.values().length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DeniedCommandCommand implements ICommand {
Expand Down Expand Up @@ -69,9 +67,7 @@ public boolean onCommand(@NotNull CommandSender sender, Minigame minigame,
public @Nullable List<@NotNull String> onTabComplete(@NotNull CommandSender sender, Minigame minigame,
@NotNull String @NotNull [] args) {
if (args.length == 1) {
List<String> ls = new ArrayList<>();
Collections.addAll(ls, {"add", "remove", "list"});
return MinigameUtils.tabCompleteMatch(ls, args[0]);
return MinigameUtils.tabCompleteMatch(List.of("add", "remove", "list"), args[0]);
} else if (args.length == 2 && args[0].equalsIgnoreCase("remove")) {
return MinigameUtils.tabCompleteMatch(plugin.getPlayerManager().getDeniedCommands(), args[1]);
}
Expand Down
Loading

0 comments on commit 3314e72

Please sign in to comment.