Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/main/java/com/cleanroommc/groovyscript/GroovyScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.cleanroommc.groovyscript.documentation.linkgenerator.LinkGeneratorHooks;
import com.cleanroommc.groovyscript.event.EventHandler;
import com.cleanroommc.groovyscript.helper.JsonHelper;
import com.cleanroommc.groovyscript.helper.StyleConstant;
import com.cleanroommc.groovyscript.mapper.ObjectMapper;
import com.cleanroommc.groovyscript.mapper.ObjectMapperManager;
import com.cleanroommc.groovyscript.network.CReload;
Expand Down Expand Up @@ -181,10 +182,10 @@ public static long runGroovyScriptsInLoader(LoadStage loadStage) {
public void onPostInit(FMLPostInitializationEvent event) {
CustomClickAction.registerAction("copy", value -> {
GuiScreen.setClipboardString(value);
Minecraft.getMinecraft().player.sendMessage(
new TextComponentTranslation("groovyscript.command.copy.copied_start")
.appendSibling(new TextComponentString(value).setStyle(new Style().setColor(TextFormatting.GOLD)))
.appendSibling(new TextComponentTranslation("groovyscript.command.copy.copied_end")));
var message = new TextComponentTranslation("groovyscript.command.copy.copied_start").setStyle(StyleConstant.getEmphasisStyle())
.appendSibling(new TextComponentString(value).setStyle(new Style().setColor(TextFormatting.RESET)))
.appendSibling(new TextComponentTranslation("groovyscript.command.copy.copied_end").setStyle(StyleConstant.getEmphasisStyle()));
Minecraft.getMinecraft().player.sendMessage(message);
});
}

Expand Down Expand Up @@ -279,21 +280,21 @@ public static void postScriptRunResult(ICommandSender sender, boolean onlyLogFai
if (!onlyLogFails) {
if (running) {
String s = packmode ? "changes packmode" : "reloaded scripts";
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Successfully " + s + TextFormatting.WHITE + " in " + time + "ms"));
sender.sendMessage(new TextComponentString("Successfully " + s).setStyle(StyleConstant.getSuccessStyle()).appendSibling(new TextComponentString(" in " + time + "ms")));
} else {
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "No syntax errors found :)"));
sender.sendMessage(new TextComponentString("No syntax errors found :)").setStyle(StyleConstant.getSuccessStyle()));
}
}
} else {
String executing = running ? "running" : "checking";
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Found " + errors.size() + " errors while " + executing + " scripts"));
sender.sendMessage(new TextComponentString("Found " + errors.size() + " errors while " + executing + " scripts").setStyle(StyleConstant.getErrorStyle()));
int n = errors.size();
if (errors.size() >= 10) {
sender.sendMessage(new TextComponentString("Displaying the first 7 errors:"));
sender.sendMessage(new TextComponentString("Displaying the first 7 errors:").setStyle(StyleConstant.getTitleStyle()));
n = 7;
}
for (int i = 0; i < n; i++) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + errors.get(i)));
sender.sendMessage(new TextComponentString(errors.get(i)).setStyle(StyleConstant.getErrorStyle()));
}
GSCommand.postLogFiles(sender);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.cleanroommc.groovyscript.api.infocommand;

import com.cleanroommc.groovyscript.helper.StyleConstant;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextFormatting;

public interface InfoParser {

/**
* The style for any parser header - bold and light purple.
*
* @deprecated use {@link com.cleanroommc.groovyscript.helper.StyleConstant#getTitleStyle()}
*/
Style headerStyle = new Style().setColor(TextFormatting.WHITE).setBold(true);
@Deprecated
Style headerStyle = StyleConstant.getTitleStyle();

/**
* Priority of the parser for determining the order they are logged in chat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage;
import com.cleanroommc.groovyscript.api.infocommand.InfoParserRegistry;
import com.cleanroommc.groovyscript.event.GsHandEvent;
import com.cleanroommc.groovyscript.helper.StyleConstant;
import com.google.common.base.Predicates;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
Expand All @@ -15,9 +16,7 @@
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.common.MinecraftForge;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -112,14 +111,14 @@ public int getRequiredPermissionLevel() {
protected void print(EntityPlayer player, List<ITextComponent> messages, List<String> argList) {
if (messages.isEmpty()) {
if (argList.isEmpty()) {
player.sendMessage(new TextComponentString(String.format("Couldn't find %s!", targetDescription())).setStyle(new Style().setColor(TextFormatting.RED)));
player.sendMessage(new TextComponentString(String.format("Couldn't find %s!", targetDescription())).setStyle(StyleConstant.getErrorStyle()));
} else {
player.sendMessage(new TextComponentString(String.format("Couldn't find %s matching the given arguments!", targetDescription())).setStyle(new Style().setColor(TextFormatting.RED)));
player.sendMessage(new TextComponentString(String.format("Couldn't find %s matching the given arguments!", targetDescription())).setStyle(StyleConstant.getErrorStyle()));
player.sendMessage(new TextComponentString("The following arguments were provided: " + String.join(", ", argList)));
}
} else {
// have a horizontal bar to improve readability when running multiple consecutive info commands
player.sendMessage(new TextComponentString("================================").setStyle(new Style().setColor(TextFormatting.GOLD)));
player.sendMessage(new TextComponentString("================================").setStyle(StyleConstant.getEmphasisStyle()));
messages.forEach(player::sendMessage);
}
}
Expand Down
37 changes: 19 additions & 18 deletions src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.compat.mods.jei.JeiPlugin;
import com.cleanroommc.groovyscript.documentation.Documentation;
import com.cleanroommc.groovyscript.helper.StyleConstant;
import com.cleanroommc.groovyscript.network.NetworkHandler;
import com.cleanroommc.groovyscript.network.SReloadScripts;
import com.cleanroommc.groovyscript.network.StartLanguageServerPacket;
Expand All @@ -15,9 +16,7 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent;
import net.minecraftforge.server.command.CommandTreeBase;
Expand Down Expand Up @@ -59,17 +58,8 @@ public GSCommand() {
addSubcommand(new InfoLookingCommand());
addSubcommand(new InfoSelfCommand());

addSubcommand(
new SimpleCommand(
"wiki",
(server, sender, args) -> sender.sendMessage(
new TextComponentString("GroovyScript wiki").setStyle(
new Style().setColor(TextFormatting.GOLD)
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to open wiki in browser")))
.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://cleanroommc.com/groovy-script/")))),
"doc",
"docs",
"documentation"));

addSubcommand(new SimpleCommand("wiki", (server, sender, args) -> sender.sendMessage(getTextForUrl("GroovyScript wiki", "Click to open wiki in browser", new TextComponentString("https://cleanroommc.com/groovy-script/"))), "doc", "docs", "documentation"));

addSubcommand(new SimpleCommand("generateWiki", (server, sender, args) -> {
Documentation.generateWiki();
Expand Down Expand Up @@ -106,9 +96,9 @@ public GSCommand() {

addSubcommand(new SimpleCommand("deleteScriptCache", (server, sender, args) -> {
if (GroovyScript.getSandbox().deleteScriptCache()) {
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Deleted groovy script cache"));
sender.sendMessage(new TextComponentString("Deleted groovy script cache").setStyle(StyleConstant.getSuccessStyle()));
} else {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "An error occurred while deleting groovy script cache"));
sender.sendMessage(new TextComponentString("An error occurred while deleting groovy script cache").setStyle(StyleConstant.getErrorStyle()));
}
}));

Expand All @@ -120,7 +110,7 @@ public GSCommand() {

addSubcommand(new SimpleCommand("cleanLog", (server, sender, args) -> {
GroovyLogImpl.LOG.cleanLog();
sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Cleaned Groovy log"));
sender.sendMessage(new TextComponentString("Cleaned Groovy log").setStyle(StyleConstant.getSuccessStyle()));
}));

if (ModSupport.MEKANISM.isLoaded()) {
Expand Down Expand Up @@ -148,8 +138,19 @@ public static void postLogFiles(ICommandSender sender) {
}

public static ITextComponent getTextForFile(String name, String path, ITextComponent hoverText) {
return new TextComponentString(TextFormatting.UNDERLINE + (TextFormatting.GOLD + name))
.setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, path)).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)));
return getTextForClickEvent(name, new ClickEvent(ClickEvent.Action.OPEN_FILE, path), hoverText);
}

public static ITextComponent getTextForUrl(String name, String url, ITextComponent hoverText) {
return getTextForClickEvent(name, new ClickEvent(ClickEvent.Action.OPEN_URL, url), hoverText);
}

public static ITextComponent getTextForClickEvent(String name, ClickEvent clickEvent, ITextComponent hoverText) {
return new TextComponentString(name).setStyle(
StyleConstant.getEmphasisStyle()
.setUnderlined(true)
.setClickEvent(clickEvent)
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)));
}

public static boolean hasArgument(String[] args, String arg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.compat.mods.mekanism.Mekanism;
import com.cleanroommc.groovyscript.helper.StyleConstant;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.infuse.InfuseRegistry;
Expand All @@ -10,7 +11,6 @@
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.server.command.CommandTreeBase;
import org.jetbrains.annotations.NotNull;

Expand All @@ -24,22 +24,22 @@ public GSMekanismCommand() {
sender.sendMessage(new TextComponentString("Mekanism gases:"));
for (Gas gas : GasRegistry.getRegisteredGasses()) {
String copyText = Mekanism.asGroovyCode(gas, true);
sender.sendMessage(TextCopyable.string(copyText, " - " + gas.getName()).build());
sender.sendMessage(TextCopyable.string(copyText, " - " + copyText).build());
}
}, "gases"));
addSubcommand(new SimpleCommand("infusionTypes", (server, sender, args) -> {
sender.sendMessage(new TextComponentString("Mekanism infusion types:"));
for (InfuseType infuseType : InfuseRegistry.getInfuseMap().values()) {
String copyText = "'" + infuseType.name + "'";
sender.sendMessage(TextCopyable.string(copyText, " - " + infuseType.name).build());
String copyText = Mekanism.asGroovyCode(infuseType, true);
sender.sendMessage(TextCopyable.string(copyText, " - " + copyText).build());
}
}));
}

@Override
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, String @NotNull [] args) throws CommandException {
if (!ModSupport.MEKANISM.isLoaded()) {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "Mekanism is not loaded!"));
sender.sendMessage(new TextComponentString("Mekanism is not loaded!").setStyle(StyleConstant.getErrorStyle()));
return;
}
super.execute(server, sender, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package com.cleanroommc.groovyscript.command;

import com.cleanroommc.groovyscript.helper.StyleConstant;
import net.minecraft.util.text.*;
import net.minecraft.util.text.event.HoverEvent;

public class TextCopyable {

public static Builder string(java.lang.String copyText, java.lang.String msg) {
public static Builder string(String copyText, String msg) {
return new Builder(copyText, msg);
}

public static Builder translation(java.lang.String copyText, java.lang.String msg, Object... args) {
public static Builder translation(String copyText, String msg, Object... args) {
return new Builder(copyText, msg).translate(args);
}

public static class Builder {

private final java.lang.String copyText;
private final java.lang.String msg;
private final String copyText;
private final String msg;
private Object[] args;
private ITextComponent hoverMsg;

public Builder(java.lang.String copyText, java.lang.String msg) {
this.copyText = TextFormatting.getTextWithoutFormattingCodes(copyText);
public Builder(String copyText, String msg) {
this.copyText = copyText;
this.msg = msg;
}

Expand All @@ -33,16 +34,12 @@ public Builder translate(Object... args) {
public ITextComponent build() {
Style style = new Style();
if (hoverMsg == null) {
hoverMsg = new TextComponentTranslation("groovyscript.command.copy.hover")
.appendSibling(new TextComponentString(" " + copyText).setStyle(new Style().setColor(TextFormatting.GOLD)));
hoverMsg = new TextComponentTranslation("groovyscript.command.copy.hover").setStyle(StyleConstant.getEmphasisStyle())
.appendSibling(new TextComponentString(" " + copyText));
}
style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverMsg));
style.setClickEvent(CustomClickAction.makeCopyEvent(copyText));
ITextComponent textComponent;
if (args == null)
textComponent = new TextComponentString(msg);
else
textComponent = new TextComponentTranslation(msg, args);
style.setClickEvent(CustomClickAction.makeCopyEvent(TextFormatting.getTextWithoutFormattingCodes(copyText)));
ITextComponent textComponent = args == null ? new TextComponentString(msg) : new TextComponentTranslation(msg, args);
textComponent.setStyle(style);
return textComponent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage;
import com.cleanroommc.groovyscript.compat.vanilla.command.infoparser.GenericInfoParser;
import com.cleanroommc.groovyscript.core.mixin.jei.ModRegistryAccessor;
import com.cleanroommc.groovyscript.helper.StyleConstant;
import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.oredict.OreDictionary;
import org.jetbrains.annotations.NotNull;

import java.util.List;
Expand All @@ -29,7 +30,7 @@ public String name() {

@Override
public String text(@NotNull IRecipeCategory entry, boolean colored, boolean prettyNbt) {
return colored ? TextFormatting.YELLOW + entry.getUid() : entry.getUid();
return colored ? StyleConstant.STRING + entry.getUid() : entry.getUid();
}

@Override
Expand All @@ -41,7 +42,7 @@ public void parse(InfoParserPackage info) {
List<String> allowed = ((ModRegistryAccessor) JeiPlugin.modRegistry).getRecipeCatalysts()
.entrySet()
.stream()
.filter(entry -> entry.getValue().stream().anyMatch(x -> x instanceof ItemStack stack && ItemStack.areItemStacksEqual(stack, info.getStack())))
.filter(entry -> entry.getValue().stream().anyMatch(x -> x instanceof ItemStack stack && OreDictionary.itemMatches(stack, info.getStack(), false)))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
List<IRecipeCategory> list = JeiPlugin.recipeRegistry.getRecipeCategories(allowed);
Expand Down
Loading