use of pl.asie.charset.module.tablet.format.api.TruthError in project Charset by CharsetMC.
the class AbstractTypesetter method write.
@Override
public void write(String text) throws TruthError {
if (Strings.isNullOrEmpty(text))
return;
final Tokenizer tokenizer = new Tokenizer(text);
while (tokenizer.nextToken()) {
final String token = tokenizer.getToken();
if (token.isEmpty())
continue;
switch(tokenizer.getType()) {
default:
throw new TruthError("Unknown tokentype: " + tokenizer.getToken());
case WORD:
write(new WordText(token));
break;
case PARAMETER:
write(token);
break;
case COMMAND:
final String cmdName = token.toLowerCase(Locale.ROOT);
ICommand cmd = TabletAPI.INSTANCE.getCommand(cmdName);
if (cmd == null) {
throw new TruthError("Unknown command: " + cmdName);
}
runCommand(cmd, tokenizer);
break;
}
}
}
use of pl.asie.charset.module.tablet.format.api.TruthError in project Charset by CharsetMC.
the class CommandImg method call.
@Override
public void call(ITypesetter out, ITokenizer tokenizer) throws TruthError {
String imgName = tokenizer.getParameter("domain:path/to/image.png");
String scaleOrWidth = tokenizer.getOptionalParameter();
String heightS = tokenizer.getOptionalParameter();
ResourceLocation rl = new ResourceLocation(imgName);
try {
Minecraft mc = Minecraft.getMinecraft();
IResource r = mc.getResourceManager().getResource(rl);
if (r == null) {
throw new TruthError("Not found: " + imgName);
}
} catch (Throwable e) {
e.printStackTrace();
throw new TruthError(e.getMessage());
}
WordImage img;
if (heightS != null) {
int width = Integer.parseInt(scaleOrWidth);
int height = Integer.parseInt(heightS);
img = new WordImage(rl, width, height);
} else {
img = new WordImage(rl);
if (scaleOrWidth != null) {
img.scale(Double.parseDouble(scaleOrWidth));
}
}
if (out.hasFixedWidth()) {
img.fitToPage(out.getWidth(), Integer.MAX_VALUE);
}
out.write(img);
}
use of pl.asie.charset.module.tablet.format.api.TruthError in project Charset by CharsetMC.
the class CommandURL method call.
@Override
public void call(ITypesetter typesetter, ITokenizer tokenizer) throws TruthError {
String uriLink = tokenizer.getParameter("\\url missing parameter: uriLink");
String content = tokenizer.getParameter("\\url missing parameter: content");
try {
typesetter.write(new WordURL(content, new URI(uriLink)));
} catch (Exception e) {
e.printStackTrace();
throw new TruthError(e.getMessage());
}
}
use of pl.asie.charset.module.tablet.format.api.TruthError in project Charset by CharsetMC.
the class CommandURLMissing method call.
@Override
public void call(ITypesetter typesetter, ITokenizer tokenizer) throws TruthError {
String content = tokenizer.getParameter("\\urlmissing missing parameter: content");
try {
typesetter.pushStyle(new StyleColor(0xFFCC3333), StyleFormat.ITALIC, StyleFormat.UNDERLINE);
typesetter.write(new WordText(content));
typesetter.popStyle(3);
} catch (Exception e) {
e.printStackTrace();
throw new TruthError(e.getMessage());
}
}
Aggregations