mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-28 15:36:07 +00:00
feat: Basic gui
This commit is contained in:
1 parent
5283b0641f
commit
42bf760bcb
57 files changed
+2705
-600
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package me.towdium.jecalculation.command;
|
||||
|
||||
import me.towdium.jecalculation.command.commands.CommandHelp;
|
||||
import me.towdium.jecalculation.command.commands.CommandState;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/10/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class Commands {
|
||||
public static final HashMap<String, SubCommand> commands;
|
||||
|
||||
public static final CommandHelp commandHelp = new CommandHelp();
|
||||
public static final CommandState commandState = new CommandState();
|
||||
|
||||
static {
|
||||
commands = new HashMap<>();
|
||||
|
||||
add(commandHelp);
|
||||
add(commandState);
|
||||
}
|
||||
|
||||
static void add(SubCommand c) {
|
||||
commands.put(c.getName(), c);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package me.towdium.jecalculation.command;
|
||||
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/10/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class JecaCommand extends CommandBase {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "jec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender sender) {
|
||||
return "/jec [help]";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length == 0 || args[0].toLowerCase().equals("help")) {
|
||||
Commands.commandHelp.execute(sender, cut(args));
|
||||
} else {
|
||||
SubCommand cmd = Commands.commands.get(args[0].toLowerCase());
|
||||
if (cmd != null) {
|
||||
cmd.execute(sender, args);
|
||||
} else {
|
||||
sender.addChatMessage(new ChatComponentTranslation("command.not_found", args[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String[] cut(String[] args) {
|
||||
if (args.length == 0)
|
||||
return new String[0];
|
||||
String[] ret = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, ret, 0, args.length - 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String cmd = args[0].toLowerCase();
|
||||
if (args.length == 1) {
|
||||
return getListOfStringsFromIterableMatchingLastWord(args, Commands.commands.keySet());
|
||||
} else {
|
||||
Single<SubCommand> sub = new Single<>(null);
|
||||
Commands.commands.values().stream().filter(c -> c.getName().equals(cmd))
|
||||
.findFirst().ifPresent(sub::push);
|
||||
return sub.value == null ? sub.value.getTabCompletions(sender, cut(args))
|
||||
: Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package me.towdium.jecalculation.command;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/10/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface SubCommand {
|
||||
String getName();
|
||||
|
||||
String getUsage(ICommandSender sender);
|
||||
|
||||
void execute(ICommandSender sender, String[] args) throws CommandException;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
default List<String> getTabCompletions(ICommandSender sender, String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package me.towdium.jecalculation.command.commands;
|
||||
|
||||
import me.towdium.jecalculation.command.Commands;
|
||||
import me.towdium.jecalculation.command.SubCommand;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/10/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class CommandHelp implements SubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender) {
|
||||
return "/jec [help]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length != 0) {
|
||||
sender.addChatMessage(new ChatComponentTranslation("command.unexpected_arg", String.join(" ", args)));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.addChatMessage(new ChatComponentTranslation("command.help.list"));
|
||||
Commands.commands.values().stream().sorted(Comparator.comparing(SubCommand::getName))
|
||||
.forEachOrdered(c -> sender.addChatMessage(new ChatComponentText(c.getUsage(sender))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package me.towdium.jecalculation.command.commands;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.command.SubCommand;
|
||||
import me.towdium.jecalculation.utils.helpers.LocalizationHelper;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/10/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class CommandState implements SubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "state";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender) {
|
||||
return "/jec state";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) throws CommandException {
|
||||
sender.addChatMessage(new ChatComponentTranslation("command.state.desc",
|
||||
LocalizationHelper.format(JustEnoughCalculation.side.toString())));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user