forked from RepoMirrors/seppuku
module value commands now have text component usage for hover display of descriptions
This commit is contained in:
parent
34ba087107
commit
6a21b87ebc
|
@ -7,6 +7,7 @@ import me.rigamortis.seppuku.api.logging.SeppukuFormatter;
|
|||
import me.rigamortis.seppuku.impl.gui.menu.GuiSeppukuMainMenu;
|
||||
import me.rigamortis.seppuku.impl.management.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
|
@ -117,8 +118,8 @@ public final class Seppuku {
|
|||
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString("\2477[Seppuku]\247f " + message));
|
||||
}
|
||||
|
||||
public void logcChat(TextComponentString textComponentString) {
|
||||
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString("\2477[Seppuku]\247f ").appendSibling(textComponentString));
|
||||
public void logcChat(ITextComponent textComponent) {
|
||||
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString("\2477[Seppuku]\247f ").appendSibling(textComponent));
|
||||
}
|
||||
|
||||
public void logfChat(String format, Object... objects) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package me.rigamortis.seppuku.api.command;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import me.rigamortis.seppuku.Seppuku;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
/**
|
||||
* Author Seth
|
||||
|
@ -13,6 +15,8 @@ public abstract class Command {
|
|||
private String desc;
|
||||
private String usage;
|
||||
|
||||
private TextComponentString textComponentUsage;
|
||||
|
||||
public Command() {
|
||||
|
||||
}
|
||||
|
@ -24,15 +28,20 @@ public abstract class Command {
|
|||
this.usage = usage;
|
||||
}
|
||||
|
||||
public Command(String displayName, String[] alias, String desc, TextComponentString textComponentUsage) {
|
||||
this(displayName, alias, desc, textComponentUsage.getText());
|
||||
this.textComponentUsage = textComponentUsage;
|
||||
}
|
||||
|
||||
public abstract void exec(String input);
|
||||
|
||||
public boolean clamp(String input, int min, int max) {
|
||||
String[] split = input.split(" ");
|
||||
if(split.length > max) {
|
||||
if (split.length > max) {
|
||||
Seppuku.INSTANCE.errorChat("Too much input");
|
||||
return false;
|
||||
}
|
||||
if(split.length < min) {
|
||||
if (split.length < min) {
|
||||
Seppuku.INSTANCE.errorChat("Not enough input");
|
||||
return false;
|
||||
}
|
||||
|
@ -41,7 +50,7 @@ public abstract class Command {
|
|||
|
||||
public boolean clamp(String input, int min) {
|
||||
String[] split = input.split(" ");
|
||||
if(split.length < min) {
|
||||
if (split.length < min) {
|
||||
Seppuku.INSTANCE.errorChat("Not enough input");
|
||||
return false;
|
||||
}
|
||||
|
@ -59,12 +68,16 @@ public abstract class Command {
|
|||
|
||||
public void printUsage() {
|
||||
final String[] usage = this.getUsage().split("\n");
|
||||
Seppuku.INSTANCE.logChat("Usage: ");
|
||||
Seppuku.INSTANCE.logChat(ChatFormatting.GRAY + this.getDisplayName() + " usage: ");
|
||||
|
||||
for(String u : usage) {
|
||||
if (this.textComponentUsage != null) {
|
||||
this.getTextComponentUsage().getSiblings().forEach(Seppuku.INSTANCE::logcChat);
|
||||
} else {
|
||||
for (String u : usage) {
|
||||
Seppuku.INSTANCE.logChat(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
|
@ -97,4 +110,12 @@ public abstract class Command {
|
|||
public void setUsage(String usage) {
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
public TextComponentString getTextComponentUsage() {
|
||||
return textComponentUsage;
|
||||
}
|
||||
|
||||
public void setTextComponentUsage(TextComponentString textComponentUsage) {
|
||||
this.textComponentUsage = textComponentUsage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package me.rigamortis.seppuku.api.module;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import me.rigamortis.seppuku.Seppuku;
|
||||
import me.rigamortis.seppuku.api.value.Value;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.event.HoverEvent;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -69,9 +74,9 @@ public class Module {
|
|||
|
||||
public void toggle() {
|
||||
this.setEnabled(!this.isEnabled());
|
||||
if(this.isEnabled()) {
|
||||
if (this.isEnabled()) {
|
||||
this.onEnable();
|
||||
}else{
|
||||
} else {
|
||||
this.onDisable();
|
||||
}
|
||||
this.onToggle();
|
||||
|
@ -81,24 +86,27 @@ public class Module {
|
|||
return null;
|
||||
}
|
||||
|
||||
public String toUsageString() {
|
||||
if(this.valueList.size() <= 0) {
|
||||
public TextComponentString toUsageTextComponent() {
|
||||
if (this.valueList.size() <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final TextComponentString msg = new TextComponentString("");
|
||||
final DecimalFormat df = new DecimalFormat("#.##");
|
||||
|
||||
for (Value v : this.getValueList()) {
|
||||
final Style style = new Style().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(ChatFormatting.GOLD + ((v.getDesc() == null || v.getDesc().equals("")) ? "There is no description for this module" : v.getDesc()) + ChatFormatting.RESET)));
|
||||
|
||||
for(Value v : this.getValueList()) {
|
||||
if (v.getValue() instanceof Boolean) {
|
||||
sb.append(v.getName() + "\n");
|
||||
msg.appendSibling(new TextComponentString(v.getName() + ChatFormatting.DARK_GRAY + " | " + ((Boolean) v.getValue() ? ChatFormatting.GREEN : ChatFormatting.RED) + v.getValue()).setStyle(style));
|
||||
}
|
||||
|
||||
if (v.getValue() instanceof Number && !(v.getValue() instanceof Enum)) {
|
||||
sb.append(v.getName() + " <Amount>\n");
|
||||
msg.appendSibling(new TextComponentString(v.getName() + ChatFormatting.GRAY + " <Amount>" + ChatFormatting.DARK_GRAY + " | " + ChatFormatting.AQUA + (df.format(v.getValue()))).setStyle(style));
|
||||
}
|
||||
|
||||
if (v.getValue() instanceof String) {
|
||||
sb.append(v.getName() + " <String>\n");
|
||||
msg.appendSibling(new TextComponentString(v.getName() + ChatFormatting.GRAY + " <String>" + ChatFormatting.DARK_GRAY + " | " + ChatFormatting.WHITE + v.getValue()).setStyle(style));
|
||||
}
|
||||
|
||||
if (v.getValue() instanceof Enum) {
|
||||
|
@ -111,20 +119,18 @@ public class Module {
|
|||
for (int i = 0; i < size; i++) {
|
||||
final Enum option = val.getClass().getEnumConstants()[i];
|
||||
|
||||
options.append(option.name() + ((i == size - 1) ? "" : " | "));
|
||||
options.append(option.name() + ((i == size - 1) ? "" : ", "));
|
||||
}
|
||||
|
||||
sb.append(v.getName() + " <" + options.toString() + ">\n");
|
||||
msg.appendSibling(new TextComponentString(v.getName() + ChatFormatting.GRAY + " <" + options.toString() + ">" + ChatFormatting.DARK_GRAY + " | " + ChatFormatting.YELLOW + v.getValue()).setStyle(style));
|
||||
}
|
||||
}
|
||||
|
||||
final String s = sb.toString();
|
||||
|
||||
return s.substring(0, s.length() - 1);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public Value find(String alias) {
|
||||
for(Value v : this.getValueList()) {
|
||||
for (Value v : this.getValueList()) {
|
||||
for (String s : v.getAlias()) {
|
||||
if (alias.equalsIgnoreCase(s)) {
|
||||
return v;
|
||||
|
|
|
@ -38,7 +38,7 @@ public final class ModuleCommand extends Command {
|
|||
if (mod != null) {
|
||||
msg.appendSibling(new TextComponentString((mod.isEnabled() ? "\247a" : "\247c") + mod.getDisplayName() + "\2477" + ((i == size - 1) ? "" : ", "))
|
||||
.setStyle(new Style()
|
||||
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("\2476" + (mod.getDesc() == null ? "There is no description for this module" : mod.getDesc()) + "\247f").appendSibling(new TextComponentString((mod.toUsageString() == null ? "" : "\n" + mod.toUsageString()) + "\247f"))))
|
||||
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("\2476" + (mod.getDesc() == null ? "There is no description for this module" : mod.getDesc()) + "\247f").appendSibling(new TextComponentString((mod.toUsageTextComponent() == null ? "" : "\n" + mod.toUsageTextComponent().getText()) + "\247f"))))
|
||||
.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, commandsModule.getPrefix().getValue() + "toggle" + " " + mod.getDisplayName()))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public final class CommandManager {
|
|||
public void loadValueCommands() {
|
||||
for (final Module module : Seppuku.INSTANCE.getModuleManager().getModuleList()) {
|
||||
if (module.getValueList().size() > 0) {
|
||||
this.commandList.add(new Command(module.getDisplayName(), module.getAlias(), module.getDesc() != null ? module.getDesc() : "There is no description for this command", module.toUsageString()) {
|
||||
this.commandList.add(new Command(module.getDisplayName(), module.getAlias(), module.getDesc() != null ? module.getDesc() : "There is no description for this command", module.toUsageTextComponent()) {
|
||||
|
||||
@Override
|
||||
public void exec(String input) {
|
||||
|
|
Loading…
Reference in New Issue