-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.2 - Big update with some bugfixes
Added expression to get image from locale file Added effect to draw line Added effect to draw rounded rectangle with custom arcs Added DrawString effect to make the text center Added image rounded expression Fixed version configuration in the build.gradle
- Loading branch information
BuildTools
committed
Jan 7, 2021
1 parent
c979681
commit 521857d
Showing
9 changed files
with
322 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/info/itsthesky/SkImage/skript/effects/EffDrawLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package info.itsthesky.SkImage.skript.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
|
||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
|
||
@Name("Draw Line on Image") | ||
@Description("Draw a line on a specific image (with color, location and size)") | ||
@Examples("draw line with size 5 from 50, 30 to 60, 40 with color from rgb 150, 30, 233 on {_image}") | ||
@Since("1.0") | ||
public class EffDrawLine extends Effect { | ||
|
||
static { | ||
Skript.registerEffect(EffDrawLine.class, | ||
"[skimage] draw line with [the] (size|width) %integer% from %integer%[ ][,][ ]%integer% to %integer%[ ][,][ ]%integer% with [(color|colored)] %imagecolor% on [the] [image] %image%"); | ||
} | ||
|
||
private Expression<Integer> exprSize; | ||
private Expression<Integer> exprFromX, exprFromY; | ||
private Expression<Integer> 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]; | ||
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); | ||
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.dispose(); | ||
} | ||
|
||
@Override | ||
public String toString(Event e, boolean debug) { | ||
return ""; | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/info/itsthesky/SkImage/skript/effects/EffDrawRoundRect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package info.itsthesky.SkImage.skript.effects; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
|
||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
|
||
@Name("Draw Rounded Rectangle on Image") | ||
@Description("Draw a rectangle with rounded arc on a specific image (with color, location and size)") | ||
@Examples("draw rounded rect at 0, 0 with size 50, 50 with color from rgb 50, 30, 60 with arc size 50, 50 on {_image}") | ||
@Since("1.0") | ||
public class EffDrawRoundRect extends Effect { | ||
|
||
static { | ||
Skript.registerEffect(EffDrawRoundRect.class, | ||
"[skimage] draw round[ed] rect[angle] at [the [pixel] location] %integer%[ ][,][ ]%integer% with [the] size %integer%[ ][,][ ]%integer% with [(color|colored)] %imagecolor% with arc (size|pixel) %integer%[ ][,][ ]%integer% on [the] [image] %image%"); | ||
} | ||
|
||
private Expression<Integer> exprX, exprY; | ||
private Expression<Integer> exprSizeX, exprSizeY; | ||
private Expression<Integer> exprArcX, exprArcY; | ||
private Expression<Color> exprColor; | ||
private Expression<BufferedImage> exprImage; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
exprX = (Expression<Integer>) exprs[0]; | ||
exprY = (Expression<Integer>) exprs[1]; | ||
exprSizeX = (Expression<Integer>) exprs[2]; | ||
exprSizeY = (Expression<Integer>) exprs[3]; | ||
exprColor = (Expression<Color>) exprs[4]; | ||
exprArcX = (Expression<Integer>) exprs[5]; | ||
exprArcY = (Expression<Integer>) exprs[6]; | ||
exprImage = (Expression<BufferedImage>) exprs[7]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event e) { | ||
Integer x = exprX.getSingle(e); | ||
Integer y = exprY.getSingle(e); | ||
Integer sizeX = exprSizeX.getSingle(e); | ||
Integer sizeY = exprSizeY.getSingle(e); | ||
Integer arcX = exprArcX.getSingle(e); | ||
Integer arcY = exprArcY.getSingle(e); | ||
Color color = exprColor.getSingle(e); | ||
BufferedImage image = exprImage.getSingle(e); | ||
if (x == null || y == null || sizeX == null || sizeY == null || color == null || image == null || arcX == null || arcY == null) return; | ||
Graphics2D g2d = image.createGraphics(); | ||
g2d.setColor(color); | ||
g2d.fillRoundRect(x, y, sizeX, sizeY, arcX, arcY); | ||
g2d.dispose(); | ||
} | ||
|
||
@Override | ||
public String toString(Event e, boolean debug) { | ||
return "draw rounded rectangle on " + exprImage.toString(e, debug) + " at " + exprX.toString(e, debug) + ", " + exprY.toString(e, debug) + " with size " + exprSizeX.toString(e, debug) + ", " + exprSizeY.toString(e, debug); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/info/itsthesky/SkImage/skript/expressions/ExprImageFromFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package info.itsthesky.SkImage.skript.expressions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
@Name("Image from File") | ||
@Description("Get and return an image from locale File") | ||
@Examples("set {_image2} to image from file \"plugins/temp/image.png\"") | ||
@Since("1.0") | ||
public class ExprImageFromFile extends SimpleExpression<BufferedImage> { | ||
|
||
static { | ||
Skript.registerExpression(ExprImageFromFile.class, BufferedImage.class, ExpressionType.SIMPLE, | ||
"[skimage] [the] image from [the] [file] %string%"); | ||
} | ||
|
||
private Expression<String> exprFile; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
exprFile = (Expression<String>) exprs[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected BufferedImage[] get(Event e) { | ||
String file = exprFile.getSingle(e); | ||
if (file == null) return new BufferedImage[0]; | ||
|
||
File image = new File(file); | ||
if (!image.exists()) { | ||
return new BufferedImage[0]; | ||
} | ||
Path path = Paths.get(file); | ||
try { | ||
return new BufferedImage[] {ImageIO.read(path.toFile())}; | ||
} catch (IOException ioException) { | ||
ioException.printStackTrace(); | ||
} | ||
return new BufferedImage[0]; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<? extends BufferedImage> getReturnType() { | ||
return BufferedImage.class; | ||
} | ||
|
||
@Override | ||
public String toString(Event e, boolean debug) { | ||
return "image from the file " + exprFile.toString(e, debug); | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/info/itsthesky/SkImage/skript/expressions/ExprImageRounded.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package info.itsthesky.SkImage.skript.expressions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Examples; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
|
||
import java.awt.*; | ||
import java.awt.geom.RoundRectangle2D; | ||
import java.awt.image.BufferedImage; | ||
|
||
@Name("Rounded Image") | ||
@Description("Make an return the rounded version of the input Image") | ||
@Examples("set {_image} to image rounded {_image}") | ||
@Since("1.2") | ||
public class ExprImageRounded extends SimpleExpression<BufferedImage> { | ||
|
||
static { | ||
Skript.registerExpression(ExprImageRounded.class, BufferedImage.class, ExpressionType.SIMPLE, | ||
"[skimage] image (oval|roud[ed]) [of] %image%", | ||
"[skimage] rounded image %image%"); | ||
} | ||
|
||
private Expression<BufferedImage> exprImage; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
exprImage = (Expression<BufferedImage>) exprs[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected BufferedImage[] get(Event e) { | ||
BufferedImage image = exprImage.getSingle(e); | ||
if (image == null) return new BufferedImage[0]; | ||
int w = image.getWidth(); | ||
int h = image.getHeight(); | ||
BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); | ||
|
||
Graphics2D g2 = output.createGraphics(); | ||
|
||
g2.setComposite(AlphaComposite.Src); | ||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | ||
g2.setColor(Color.WHITE); | ||
g2.fill(new RoundRectangle2D.Float(0, 0, w, h, Math.round(image.getWidth()), Math.round(image.getHeight()))); | ||
g2.setComposite(AlphaComposite.SrcAtop); | ||
g2.drawImage(image, 0, 0, null); | ||
g2.dispose(); | ||
|
||
return new BufferedImage[] {output}; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<? extends BufferedImage> getReturnType() { | ||
return BufferedImage.class; | ||
} | ||
|
||
@Override | ||
public String toString(Event e, boolean debug) { | ||
return "rounded version of image " + exprImage.toString(e, debug); | ||
} | ||
|
||
} |
Oops, something went wrong.