Skip to content

Commit

Permalink
🚀 SkImage v1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Mar 5, 2022
1 parent aa29223 commit 255b85c
Show file tree
Hide file tree
Showing 25 changed files with 461 additions and 201 deletions.
8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

12 changes: 12 additions & 0 deletions .idea/modules/Skimage.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'info.itsthesky'
version '1.3'
version '1.8'

repositories {
mavenCentral()
Expand Down
56 changes: 9 additions & 47 deletions src/main/java/info/itsthesky/SkImage/SkImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import info.itsthesky.SkImage.skript.Test;
import info.itsthesky.SkImage.skript.Types;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
Expand All @@ -27,65 +26,28 @@ public static SkImage getInstance() {
public void onEnable() {

INSTANCE = this;
Bukkit.getConsoleSender().sendMessage("§3==========================================");
Bukkit.getConsoleSender().sendMessage("§6SkImage version §e" + getDescription().getVersion() + "§6 is loading ...");
getLogger().info("SkImage v" + getDescription().getVersion() + " is loading ...");

saveResourceAs("config.yml", "config.yml");

new Test();
getLogger().info("Saving default configuration ...");
saveResource("config.yml", true);

getLogger().info("Checking for Skript ...");
pluginManager = Bukkit.getPluginManager();
if ((pluginManager.getPlugin("Skript") != null) && Skript.isAcceptRegistrations()) {
getLogger().info("Skript found! registering syntaxes ...");
SkriptAddon addon = Skript.registerAddon(this);
new Types().skImageRegisterTypes();
try {
addon.loadClasses("info.itsthesky.SkImage.skript");
} catch (IOException e) {
Skript.error("Wait, this is anormal. Please report this error on GitHub.");
getLogger().severe("Wait, this is anormal. Please report this error on GitHub.");
e.printStackTrace();
}
} else {
Skript.error("Skript isn't installed or doesn't accept registrations.");
getLogger().severe("Skript is not found (or not enabled), cannot load SkImage.");
pluginManager.disablePlugin(this);
return;
}
Bukkit.getConsoleSender().sendMessage("§aSkImage doesn't seems to get error while loading!");
Bukkit.getConsoleSender().sendMessage("§3==========================================");
}

public void saveResourceAs(String inPath, String outPath) {
if (inPath == null || inPath.isEmpty()) {
throw new IllegalArgumentException("The input path cannot be null or empty");
}
InputStream in = getResource(inPath);
if (in == null) {
throw new IllegalArgumentException("The file "+inPath+" cannot be found in plugin's resources");
}
if (!getDataFolder().exists() && !getDataFolder().mkdir()) {
getLogger().severe("Failed to make the main directory !");
}
File outFile = new File(getDataFolder(), outPath);
try {
if (!outFile.exists()) {
getLogger().info("The file "+outFile.getName()+" cannot be found, create one for you ...");
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int n;

while ((n = in.read(buf)) >= 0) {
out.write(buf, 0, n);
}

out.close();
in.close();

if (!outFile.exists()) {
getLogger().severe("Unable to copy file !");
} else {
getLogger().info("The file "+outFile.getName()+" has been created!");
}
}
} catch (IOException e) {
e.printStackTrace();
}
getLogger().info("SkImage has been enabled correctly!");
}
}
34 changes: 6 additions & 28 deletions src/main/java/info/itsthesky/SkImage/skript/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ch.njol.skript.classes.Parser;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.registrations.Classes;
import info.itsthesky.SkImage.skript.tools.TextInfo;

import java.awt.*;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -38,34 +39,11 @@ public BufferedImage parse(String s, ParseContext context) {
}
})
);
Classes.registerClass(new ClassInfo<>(Color.class, "imagecolor")
.user("imagecolor")
.name("imagecolor")
.description("Represents an Image Color")
.since("1.0")
.parser(new Parser<Color>() {

@Override
public String toString(Color o, int flags) {
return "color with red " + o.getRed() + ", green " + o.getGreen() + " and blue " + o.getBlue() + " ("+o.getRGB()+")";
}

@Override
public String toVariableNameString(Color o) {
return "color with red " + o.getRed() + ", green " + o.getGreen() + " and blue " + o.getBlue() + " ("+o.getRGB()+")";
}

@Override
public String getVariableNamePattern() {
return ".+";
}

@Override
public Color parse(String s, ParseContext context) {
return null;
}
})
);
Classes.registerClass(new ClassInfo<>(TextInfo.class, "textinfo")
.user("textinfo")
.name("Text Information")
.description("Represents a text that contains further information about its style, such as color, font and center values.")
.since("1.5"));
Classes.registerClass(new ClassInfo<>(Font.class, "font")
.user("font")
.name("font")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package info.itsthesky.SkImage.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
Expand All @@ -11,6 +12,7 @@
import ch.njol.skript.lang.Variable;
import ch.njol.util.Kleenean;
import info.itsthesky.SkImage.skript.tools.Utils;
import info.itsthesky.SkImage.skript.tools.skript.EasyEffect;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;

Expand All @@ -21,7 +23,7 @@
@Description("Draw an Image on another Image")
@Examples("draw image {_image1} on {_image} at 0, 50")
@Since("1.0")
public class EffDrawImage extends Effect {
public class EffDrawImage extends EasyEffect {

static {
Skript.registerEffect(EffDrawImage.class,
Expand All @@ -39,7 +41,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
exprImage2 = (Expression<BufferedImage>) exprs[1];
exprX = (Expression<Number>) exprs[2];
exprY = (Expression<Number>) exprs[3];
return true;
return validate(exprImage2);
}

@Override
Expand All @@ -52,7 +54,7 @@ protected void execute(@NotNull Event e) {
Graphics2D g2d = image2.createGraphics();
g2d.drawImage(image1, x.intValue(), y.intValue(), null);
g2d.dispose();
Utils.setSkriptVariable((Variable) exprImage2, image2, e);
exprImage2.change(e, new BufferedImage[] {image2}, Changer.ChangeMode.SET);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import info.itsthesky.SkImage.skript.tools.Utils;
import org.bukkit.event.Event;

import java.awt.*;
Expand All @@ -22,13 +23,13 @@ public class EffDrawLine extends Effect {

static {
Skript.registerEffect(EffDrawLine.class,
"[skimage] draw line with [the] (size|width) %number% from %number%[ ][,][ ]%number% to %number%[ ][,][ ]%number% with [(color|colored)] %imagecolor% on [the] [image] %image%");
"[skimage] draw line with [the] (size|width) %number% from %number%[ ][,][ ]%number% to %number%[ ][,][ ]%number% with [(color|colored)] %color% on [the] [image] %image%");
}

private Expression<Number> exprSize;
private Expression<Number> exprFromX, exprFromY;
private Expression<Number> exprToX, exprToY;
private Expression<Color> exprColor;
private Expression<ch.njol.skript.util.Color> exprColor;
private Expression<BufferedImage> exprImage;

@SuppressWarnings("unchecked")
Expand All @@ -39,7 +40,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
exprFromY = (Expression<Number>) exprs[2];
exprToX = (Expression<Number>) exprs[3];
exprToY = (Expression<Number>) exprs[4];
exprColor = (Expression<Color>) exprs[5];
exprColor = (Expression<ch.njol.skript.util.Color>) exprs[5];
exprImage = (Expression<BufferedImage>) exprs[6];
return true;
}
Expand All @@ -51,11 +52,11 @@ protected void execute(Event e) {
Number toX = exprToX.getSingle(e);
Number toY = exprToY.getSingle(e);
Number size = exprSize.getSingle(e);
Color color = exprColor.getSingle(e);
ch.njol.skript.util.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.setColor(Utils.convert(color));
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 @@ -9,6 +9,7 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import info.itsthesky.SkImage.skript.tools.Utils;
import org.bukkit.event.Event;

import java.awt.*;
Expand All @@ -22,14 +23,14 @@ public class EffDrawRect extends Effect {

static {
Skript.registerEffect(EffDrawRect.class,
"[skimage] draw rect[angle] [with anti[-]aliases] at [the [pixel] location] %number%[ ][,][ ]%number% with [the] size %number%[ ][,][ ]%number% with [(color|colored)] %imagecolor% [[with] [rotation] %-number% degree[s] [angle] [using origin location %-number%,[ ]%-number%]] on [the] [image] %image%");
"[skimage] draw rect[angle] [with anti[-]aliases] at [the [pixel] location] %number%[ ][,][ ]%number% with [the] size %number%[ ][,][ ]%number% with [(color|colored)] %color% [[with] [rotation] %-number% degree[s] [angle] [using origin location %-number%,[ ]%-number%]] on [the] [image] %image%");
}

private Expression<Number> exprX, exprY;
private Expression<Number> exprSizeX, exprSizeY;
private Expression<Number> exprRotation;
private Expression<Number> exprRotOriginX, exprRotOriginY;
private Expression<Color> exprColor;
private Expression<ch.njol.skript.util.Color> exprColor;
private Expression<BufferedImage> exprImage;
private boolean hasAliases = false;

Expand All @@ -40,7 +41,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
exprY = (Expression<Number>) exprs[1];
exprSizeX = (Expression<Number>) exprs[2];
exprSizeY = (Expression<Number>) exprs[3];
exprColor = (Expression<Color>) exprs[4];
exprColor = (Expression<ch.njol.skript.util.Color>) exprs[4];
exprRotation = (Expression<Number>) exprs[5];
exprRotOriginX = (Expression<Number>) exprs[6];
exprRotOriginY = (Expression<Number>) exprs[7];
Expand All @@ -58,7 +59,7 @@ protected void execute(Event e) {
Number rot = exprRotation == null ? null : (exprRotation.getSingle(e) == null ? null : exprRotation.getSingle(e));
Number rotPosX = exprRotOriginX == null ? null : (exprRotOriginX.getSingle(e) == null ? null : exprRotOriginX.getSingle(e));
Number rotPosY = exprRotOriginY == null ? null : (exprRotOriginY.getSingle(e) == null ? null : exprRotOriginY.getSingle(e));
Color color = exprColor.getSingle(e);
ch.njol.skript.util.Color color = exprColor.getSingle(e);
BufferedImage image = exprImage.getSingle(e);
if (x == null || y == null || sizeX == null || sizeY == null || color == null || image == null) return;
Graphics2D g2d = image.createGraphics();
Expand All @@ -74,7 +75,7 @@ protected void execute(Event e) {
g2d.rotate(Math.toRadians(rot.intValue()), rotPosX.intValue() - x.intValue(), rotPosX.intValue() - y.intValue());
}
}
g2d.setColor(color);
g2d.setColor(Utils.convert(color));
g2d.fillRect(x.intValue(), y.intValue(), sizeX.intValue(), sizeY.intValue());
g2d.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import info.itsthesky.SkImage.skript.tools.Utils;
import org.bukkit.event.Event;

import java.awt.*;
Expand All @@ -22,7 +23,7 @@ public class EffDrawRoundRect extends Effect {

static {
Skript.registerEffect(EffDrawRoundRect.class,
"[skimage] draw round[ed] rect[angle] [with anti[-]aliases] at [the [pixel] location] %number%[ ][,][ ]%number% with [the] size %number%[ ][,][ ]%number% with [(color|colored)] %imagecolor% with arc (size|pixel) %number%[ ][,][ ]%number% on [the] [image] %image%");
"[skimage] draw round[ed] rect[angle] [with anti[-]aliases] at [the [pixel] location] %number%[ ][,][ ]%number% with [the] size %number%[ ][,][ ]%number% with [(color|colored)] %color% with arc (size|pixel) %number%[ ][,][ ]%number% on [the] [image] %image%");
}

private Expression<Number> exprX;
Expand All @@ -31,7 +32,7 @@ public class EffDrawRoundRect extends Effect {
private Expression<Number> exprSizeY;
private Expression<Number> exprArcY;
private Expression<Number> exprArcX;
private Expression<Color> exprColor;
private Expression<ch.njol.skript.util.Color> exprColor;
private boolean hasAliases = false;
private Expression<BufferedImage> exprImage;

Expand All @@ -42,7 +43,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
exprY = (Expression<Number>) exprs[1];
exprSizeX = (Expression<Number>) exprs[2];
exprSizeY = (Expression<Number>) exprs[3];
exprColor = (Expression<Color>) exprs[4];
exprColor = (Expression<ch.njol.skript.util.Color>) exprs[4];
exprArcX = (Expression<Number>) exprs[5];
exprArcY = (Expression<Number>) exprs[6];
exprImage = (Expression<BufferedImage>) exprs[7];
Expand All @@ -58,7 +59,7 @@ protected void execute(Event e) {
Number sizeY = exprSizeY.getSingle(e);
Number arcX = exprArcX.getSingle(e);
Number arcY = exprArcY.getSingle(e);
Color color = exprColor.getSingle(e);
ch.njol.skript.util.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();
Expand All @@ -67,7 +68,7 @@ protected void execute(Event e) {
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setRenderingHints(rh);
}
g2d.setColor(color);
g2d.setColor(Utils.convert(color));
g2d.fillRoundRect(x.intValue(), y.intValue(), sizeX.intValue(), sizeY.intValue(), arcX.intValue(), arcY.intValue());
g2d.dispose();
}
Expand Down
Loading

0 comments on commit 255b85c

Please sign in to comment.