Skip to content

Commit

Permalink
🐛 Fixed Number conversion in some effect / expression
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Aug 12, 2021
1 parent e7e4e5d commit aa29223
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 66 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ plugins {
group 'info.itsthesky'
version '1.3'

def version = '1.7'

repositories {
mavenCentral()
maven {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,39 @@ public class EffDrawLine extends Effect {
"[skimage] draw line with [the] (size|width) %number% from %number%[ ][,][ ]%number% to %number%[ ][,][ ]%number% with [(color|colored)] %imagecolor% on [the] [image] %image%");
}

private Expression<Integer> exprSize;
private Expression<Integer> exprFromX, exprFromY;
private Expression<Integer> exprToX, exprToY;
private Expression<Number> exprSize;
private Expression<Number> exprFromX, exprFromY;
private Expression<Number> exprToX, exprToY;
private Expression<Color> exprColor;
private Expression<BufferedImage> exprImage;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
exprSize = (Expression<Integer>) exprs[0];
exprFromX = (Expression<Integer>) exprs[1];
exprFromY = (Expression<Integer>) exprs[2];
exprToX = (Expression<Integer>) exprs[3];
exprToY = (Expression<Integer>) exprs[4];
exprSize = (Expression<Number>) exprs[0];
exprFromX = (Expression<Number>) exprs[1];
exprFromY = (Expression<Number>) exprs[2];
exprToX = (Expression<Number>) exprs[3];
exprToY = (Expression<Number>) exprs[4];
exprColor = (Expression<Color>) exprs[5];
exprImage = (Expression<BufferedImage>) exprs[6];
return true;
}

@Override
protected void execute(Event e) {
Integer fromX = exprFromX.getSingle(e);
Integer fromY = exprFromY.getSingle(e);
Integer toX = exprToX.getSingle(e);
Integer toY = exprToY.getSingle(e);
Integer size = exprSize.getSingle(e);
Number fromX = exprFromX.getSingle(e);
Number fromY = exprFromY.getSingle(e);
Number toX = exprToX.getSingle(e);
Number toY = exprToY.getSingle(e);
Number size = exprSize.getSingle(e);
Color color = exprColor.getSingle(e);
BufferedImage image = exprImage.getSingle(e);
if (color == null || image == null || size == null || fromX == null || fromY == null || toX == null || toY == null) return;
Graphics2D g2d = image.createGraphics();
g2d.setColor(color);
g2d.setStroke(new BasicStroke(size));
g2d.drawLine(fromX, fromY, toX, toY);
g2d.setStroke(new BasicStroke(size.intValue()));
g2d.drawLine(fromX.intValue(), fromY.intValue(), toX.intValue(), toY.intValue());
g2d.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class EffDrawText extends Effect {

private Expression<String> exprText;
private Expression<Font> exprFont;
private Expression<Integer> exprX, exprY;
private Expression<Number> exprX, exprY;
private Expression<Color> exprColor;
private Expression<BufferedImage> exprImage;
private boolean hasAliases = false;
Expand All @@ -41,8 +41,8 @@ public class EffDrawText extends Effect {
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
exprText = (Expression<String>) exprs[0];
exprFont = (Expression<Font>) exprs[1];
exprX = (Expression<Integer>) exprs[2];
exprY = (Expression<Integer>) exprs[3];
exprX = (Expression<Number>) exprs[2];
exprY = (Expression<Number>) exprs[3];
exprColor = (Expression<Color>) exprs[4];
exprImage = (Expression<BufferedImage>) exprs[5];
isCenter = matchedPattern;
Expand All @@ -54,8 +54,8 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
protected void execute(Event e) {
String text = exprText.getSingle(e);
Font font = exprFont.getSingle(e);
Integer x = exprX.getSingle(e);
Integer y = exprY.getSingle(e);
Number x = exprX.getSingle(e);
Number y = exprY.getSingle(e);
Color color = exprColor.getSingle(e);
BufferedImage image = exprImage.getSingle(e);
if (text == null || x == null || y == null || image == null) return;
Expand All @@ -69,14 +69,14 @@ protected void execute(Event e) {
g2d.setColor(color);
try {
if (isCenter == 0) {
g2d.drawString(text, x, y);
g2d.drawString(text, x.intValue(), y.intValue());
} else {
TextLayout textLayout = new TextLayout(text, g2d.getFont(),
g2d.getFontRenderContext());
double textHeight = textLayout.getBounds().getHeight();
double textWidth = textLayout.getBounds().getWidth();
g2d.drawString(text, (x / 2 - (int) textWidth / 2),
(y / 2 + (int) textHeight / 2));
g2d.drawString(text, (x.intValue() / 2 - (int) textWidth / 2),
(y.intValue() / 2 + (int) textHeight / 2));
}
} catch (Exception exception) {
SkImage.getInstance().getLogger().warning("Cannot draw text on the image because of an internal exception:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ public class ExprColorFromRGB extends SimpleExpression<Color> {
"[skimage] color from (rgb|redgreenblue) %number%[ ][,][ ]%number%[ ][,][ ]%number%");
}

private Expression<Integer> exprRed, exprGreen, exprBlue;
private Expression<Number> exprRed, exprGreen, exprBlue;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
exprRed = (Expression<Integer>) exprs[0];
exprGreen = (Expression<Integer>) exprs[1];
exprBlue = (Expression<Integer>) exprs[2];
exprRed = (Expression<Number>) exprs[0];
exprGreen = (Expression<Number>) exprs[1];
exprBlue = (Expression<Number>) exprs[2];
return true;
}

@Override
protected Color[] get(Event e) {
Integer r = exprRed.getSingle(e);
Integer g = exprGreen.getSingle(e);
Integer b = exprBlue.getSingle(e);
Number r = exprRed.getSingle(e);
Number g = exprGreen.getSingle(e);
Number b = exprBlue.getSingle(e);
if (b == null || g == null || r == null) return new Color[0];
return new Color[] {new Color(r, g, b)};
return new Color[] {new Color(r.intValue(), g.intValue(), b.intValue())};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ public class ExprDarkerImage extends SimpleExpression<BufferedImage> {
}

private Expression<BufferedImage> exprImage;
private Expression<Integer> exprForce;
private Expression<Number> exprForce;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
exprImage = (Expression<BufferedImage>) exprs[0];
exprForce = (Expression<Integer>) exprs[1];
exprForce = (Expression<Number>) exprs[1];
return true;
}

@Override
protected BufferedImage[] get(Event e) {
BufferedImage image = exprImage.getSingle(e);
Integer force = exprForce.getSingle(e);
Number force = exprForce.getSingle(e);
if (image == null || force == null) return new BufferedImage[0];
return new BufferedImage[] {Utils.darkerImage(Utils.copiedImage(image), force)};
return new BufferedImage[] {Utils.darkerImage(Utils.copiedImage(image), force.intValue())};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ public class ExprImageBlurred extends SimpleExpression<BufferedImage> {
}

private Expression<BufferedImage> exprImage;
private Expression<Integer> exprForce;
private Expression<Number> exprForce;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
exprImage = (Expression<BufferedImage>) exprs[0];
exprForce = (Expression<Integer>) exprs[1];
exprForce = (Expression<Number>) exprs[1];
return true;
}

@Override
protected BufferedImage[] get(Event e) {
BufferedImage image = exprImage.getSingle(e);
Integer force = exprForce.getSingle(e);
Number force = exprForce.getSingle(e);
if (image == null || force == null) return new BufferedImage[0];
int w = image.getWidth();
int h = image.getHeight();
return new BufferedImage[] {Utils.blur(Utils.copiedImage(image), force)};
return new BufferedImage[] {Utils.blur(Utils.copiedImage(image), force.intValue())};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
@Description("Return the height size of an image")
@Examples("set {_width} to height of {_image}")
@Since("1.0")
public class ExprImageHeight extends SimpleExpression<Integer> {
public class ExprImageHeight extends SimpleExpression<Number> {

static {
Skript.registerExpression(ExprImageHeight.class, Integer.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprImageHeight.class, Number.class, ExpressionType.SIMPLE,
"[skimage] [the] [pixel] height of [the] [image] %image%");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
@Description("Return the width size of an image")
@Examples("set {_width} to width of {_image}")
@Since("1.0")
public class ExprImageWidth extends SimpleExpression<Integer> {
public class ExprImageWidth extends SimpleExpression<Number> {

static {
Skript.registerExpression(ExprImageWidth.class, Integer.class, ExpressionType.SIMPLE,
Skript.registerExpression(ExprImageWidth.class, Number.class, ExpressionType.SIMPLE,
"[skimage] [the] [pixel] width of [the] [image] %image%");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ public class ExprLighterImage extends SimpleExpression<BufferedImage> {
}

private Expression<BufferedImage> exprImage;
private Expression<Integer> exprForce;
private Expression<Number> exprForce;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
exprImage = (Expression<BufferedImage>) exprs[0];
exprForce = (Expression<Integer>) exprs[1];
exprForce = (Expression<Number>) exprs[1];
return true;
}

@Override
protected BufferedImage[] get(Event e) {
BufferedImage image = exprImage.getSingle(e);
Integer force = exprForce.getSingle(e);
Number force = exprForce.getSingle(e);
if (image == null || force == null) return new BufferedImage[0];
return new BufferedImage[] {Utils.lighterImage(Utils.copiedImage(image), force)};
return new BufferedImage[] {Utils.lighterImage(Utils.copiedImage(image), force.intValue())};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ public class ExprNewImage extends SimpleExpression<BufferedImage> {
"[skimage] new image with size %number%[ ][,][ ]%number%");
}

private Expression<Integer> exprWidth;
private Expression<Integer> exprHeight;
private Expression<Number> exprWidth;
private Expression<Number> exprHeight;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
exprWidth = (Expression<Integer>) exprs[0];
exprHeight = (Expression<Integer>) exprs[1];
exprWidth = (Expression<Number>) exprs[0];
exprHeight = (Expression<Number>) exprs[1];
return true;
}

@Override
protected BufferedImage[] get(Event e) {
Integer width = exprWidth.getSingle(e);
Integer height = exprHeight.getSingle(e);
Number width = exprWidth.getSingle(e);
Number height = exprHeight.getSingle(e);
if (width != null && height != null) {
BufferedImage image = new BufferedImage(width, height, Utils.getDefaultType());
BufferedImage image = new BufferedImage(width.intValue(), height.intValue(), Utils.getDefaultType());
return new BufferedImage[] {image};
}
return new BufferedImage[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ public class ExprResizedImage extends SimpleExpression<BufferedImage> {
}

private Expression<BufferedImage> exprImage1;
private Expression<Integer> exprSizeX, exprSizeY, exprAlgo;
private Expression<Number> exprSizeX, exprSizeY, exprAlgo;

@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
exprImage1 = (Expression<BufferedImage>) exprs[0];
exprSizeX = (Expression<Integer>) exprs[1];
exprSizeY = (Expression<Integer>) exprs[2];
exprAlgo = (Expression<Integer>) exprs[3];
exprSizeX = (Expression<Number>) exprs[1];
exprSizeY = (Expression<Number>) exprs[2];
exprAlgo = (Expression<Number>) exprs[3];
return true;
}

@Override
protected BufferedImage[] get(Event e) {
BufferedImage image = exprImage1.getSingle(e);
Integer sizeX = exprSizeX.getSingle(e);
Integer sizeY = exprSizeY.getSingle(e);
Integer algo = exprAlgo.getSingle(e);
Number sizeX = exprSizeX.getSingle(e);
Number sizeY = exprSizeY.getSingle(e);
Number algo = exprAlgo.getSingle(e);
if (algo == null) algo = 1;
if (sizeX == null || sizeY == null || image == null) return new BufferedImage[0];
if (algo == 1 || algo == 2 || algo == 4 || algo == 8 || algo == 16) {
if (algo.intValue() == 1 || algo.intValue() == 2 || algo.intValue() == 4 || algo.intValue() == 8 || algo.intValue() == 16) {
return new BufferedImage[] {
Utils.resizedImage(Utils.copiedImage(image), sizeX, sizeY, algo)
Utils.resizedImage(Utils.copiedImage(image), sizeX.intValue(), sizeY.intValue(), algo.intValue())
};
} else {
Skript.error("The algorithm ID is not valid. Valid ones are 1, 2, 4, 8 and 16 !");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SkImage
author: ItsTheSky
version: 1.7
version: 1.7.1
description: Simple addon which let you create, manage and customize image.
main: info.itsthesky.SkImage.SkImage
depend:
Expand Down

0 comments on commit aa29223

Please sign in to comment.