Skip to content

Commit

Permalink
Merge pull request #3 from SkJsonTeam/master
Browse files Browse the repository at this point in the history
Bunch fixes (Typos, Expressions, Examples)
  • Loading branch information
aabssmc authored Oct 31, 2023
2 parents 9a541bb + 4481398 commit 0045a78
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@Since("1.2")
public class CondMainHand extends Condition {
enum MainHandSide {
LEFT, RIGHT, UNKNOWN;
LEFT, RIGHT
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
@Description("Thrown when a player executes a command that is not defined.")
@Examples({
"on unknown command:",
"\tset unknown command message to \"that doesnt exist\""
"\tset unknown command message to \"that doesn't exist\""
})
@Since("1.3")
@RequiredPlugins("Paper 1.13+")
public class EvtUnknownCmd extends SkriptEvent {
static {
Skript.registerEvent("unknown command", SimpleEvent.class, UnknownCommandEvent.class, "[on] unknown command");
EventValues.registerEventValue(UnknownCommandEvent.class, CommandSender.class, new Getter<CommandSender, UnknownCommandEvent>() {
EventValues.registerEventValue(UnknownCommandEvent.class, CommandSender.class, new Getter<>() {
@Override
public CommandSender get(UnknownCommandEvent e) {
return e.getSender();
}
}, 0);

EventValues.registerEventValue(UnknownCommandEvent.class, String.class, new Getter<String, UnknownCommandEvent>() {
EventValues.registerEventValue(UnknownCommandEvent.class, String.class, new Getter<>() {
@Override
public String get(UnknownCommandEvent e) {
return e.getCommandLine();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package lol.aabss.skuishy.elements.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.expressions.base.PropertyExpression;
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.entity.Player;
import org.bukkit.event.Event;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lol.aabss.skuishy.elements.skins.expressions;
package lol.aabss.skuishy.elements.expressions.skins;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
Expand All @@ -10,7 +10,7 @@
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.util.LiteralUtils;
import ch.njol.util.Kleenean;
import lol.aabss.skuishy.other.skins.PlayerFace;
import lol.aabss.skuishy.other.skins.SkinWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
Expand All @@ -20,8 +20,10 @@
@Name("Skins - Face of Player")
@Description("Gets the player's face.")
@Examples({
"set {_texture} to face of player with an outer layer",
"set {_texture} to player's face with size 10 with a layer"
"command face-texture <player>:",
"\ttrigger:",
"\t\tset {_texture} to arg-1 face at size 10 with an outer layer",
"\t\tset {_texture} to face with a layer of player"
})
@Since("1.0")

Expand All @@ -46,7 +48,7 @@ public class ExprPlayerFace extends PropertyExpression<Player, BufferedImage> {
if (this.size != null) size = this.size.getSingle(event);
if (player == null) return new BufferedImage[0];
try {
var buffer = PlayerFace.get(player, size == null ? 16 : size, !without);
var buffer = SkinWrapper.get(player, size == null ? 16 : size, !without);
return new BufferedImage[]{buffer};
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lol.aabss.skuishy.elements.skins.expressions;
package lol.aabss.skuishy.elements.expressions.skins;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
Expand All @@ -9,7 +9,7 @@
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.registrations.Classes;
import ch.njol.util.Kleenean;
import lol.aabss.skuishy.other.skins.Property;
import lol.aabss.skuishy.other.skins.SkinWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
Expand All @@ -26,15 +26,15 @@
public class ExprPlayerSig extends PropertyExpression<Player, String> {

static {
register(ExprPlayerSig.class, String.class, "[the] [texture|skin] signature", "players");
register(ExprPlayerSig.class, String.class, "[the] (texture|skin) signature", "players");
}


@Override
protected String @NotNull [] get(@NotNull Event event, Player @NotNull [] source) {
Player p = source[0] != null ? source[0] : null;
assert p != null;
return new String[]{Property.getProfileProperties(p).getSignature()};
return new String[]{SkinWrapper.getProfileProperties(p).getSignature()};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package lol.aabss.skuishy.elements.skins.expressions;
package lol.aabss.skuishy.elements.expressions.skins;

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.expressions.base.PropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import lol.aabss.skuishy.other.skins.PlayerTexture;
import lol.aabss.skuishy.other.skins.SkinWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
Expand All @@ -21,7 +18,9 @@
@Name("Skins - Player Skin Texture (Image)")
@Description("Gets the player's skin as a image.")
@Examples({
"set {_texture} to skin texture of player as image"
"command set-texture <player>:",
"\ttrigger:",
"\t\tset {_texture} to skin texture image of player"
})
@Since("1.0")

Expand Down Expand Up @@ -60,7 +59,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, @NotNull Kleenean
try {
if (source.length < 1) return new BufferedImage[0];
var player = source[0];
return new BufferedImage[] {PlayerTexture.imgTexture(player)};
return new BufferedImage[] {SkinWrapper.imgTexture(player)};
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
package lol.aabss.skuishy.elements.skins.expressions;
package lol.aabss.skuishy.elements.expressions.skins;

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.expressions.base.PropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import lol.aabss.skuishy.other.skins.PlayerTexture;
import lol.aabss.skuishy.other.skins.SkinWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

@Name("Skins - Player Skin Texture (URL)")
@Description("sticking out your gyat for the rizzler, your so skibidi, your so fanum tax, i jus wana be ur sigma ):")
@Examples({
"send texture of player as url"
"command send-texture <player>:",
"\ttrigger:",
"\t\tsend texture url of arg-1"
})
@Since("1.0")

Expand Down Expand Up @@ -61,7 +58,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, @NotNull Kleenean
try {
if (source.length < 1) return new String[0];
var player = source[0];
return new String[] {PlayerTexture.urlTexture(player)};
return new String[] {SkinWrapper.urlTexture(player)};
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
package lol.aabss.skuishy.elements.skins.expressions;
package lol.aabss.skuishy.elements.expressions.skins;

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.expressions.base.PropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import lol.aabss.skuishy.other.skins.Property;
import lol.aabss.skuishy.other.skins.SkinWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;

@Name("Skins - Player Skin Value")
@Description("Sends the value of the player's skin .")
@Examples({
"command sendvalue <player>:",
"\tsend arg-1's skin value"
"command send-value <player>:",
"\ttrigger:",
"\t\tsend arg-1's skin value"
})
@Since("1.0")

public class ExprPlayerVal extends PropertyExpression<Player, String> {

static {
register(ExprPlayerVal.class, String.class,
"[the] texture|skin value",
"[the] (texture|skin) value",
"players"
);
}
Expand Down Expand Up @@ -60,7 +58,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, @NotNull Kleenean
if (source.length < 1) return new String[0];
Player p = source[0];
assert p != null;
return new String[]{Property.getProfileProperties(p).getValue()};
return new String[]{SkinWrapper.getProfileProperties(p).getValue()};
}

}
79 changes: 79 additions & 0 deletions src/main/java/lol/aabss/skuishy/other/skins/SkinWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package lol.aabss.skuishy.other.skins;

import com.destroystokyo.paper.profile.PlayerProfile;
import com.destroystokyo.paper.profile.ProfileProperty;
import org.bukkit.entity.Player;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.StringReader;
import java.net.URL;
import java.util.Base64;

public abstract class SkinWrapper {
public static BufferedImage get(Player player, @Nullable Number size, boolean lay) throws Exception {
BufferedImage textureImage = imgTexture(player);
BufferedImage subImage = textureImage.getSubimage(8,8,8,8);
assert size != null;
BufferedImage face = new BufferedImage(size.intValue(), size.intValue(), subImage.getType());
Graphics2D faceTmp = face.createGraphics();
faceTmp.drawImage(textureImage, 0, 0, size.intValue(), size.intValue(), null);
faceTmp.dispose();
if (lay) {
try {
BufferedImage outerLayer = textureImage.getSubimage(40, 8, 8, 8);
faceTmp.drawImage(outerLayer, 0, 0, size.intValue(), size.intValue(), null);
faceTmp.dispose();
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
return face;
}

public static ProfileProperty getProfileProperties(Player p) {
PlayerProfile playerProfile = p.getPlayerProfile();
ProfileProperty prop = null;
for (ProfileProperty property : playerProfile.getProperties()) {
if (property.getName().equals("textures")) {
prop = property;
break;
// add break statement for that for loop, cause when for loop matches the condition it's should stop looping
}
}
return prop;
}

static final JSONParser JSON_PARSER = new JSONParser();

public static String urlTexture(Player player) throws Exception {
// Gets the player's value
Player p = player.getPlayer();
assert p != null;
String value = getProfileProperties(p).getValue();
byte[] playerBytes = Base64.getDecoder().decode(value);
String playerString = new String(playerBytes);
Object parsedPlayerString = JSON_PARSER.parse(new StringReader(playerString));
if (parsedPlayerString instanceof JSONObject object) {
JSONObject textures = (JSONObject) object.get("textures");
JSONObject skin = (JSONObject) textures.get("SKIN");
return skin.get("url").toString();
}
return null;
}
public static BufferedImage imgTexture(Player player) {
String url;
try {
url = urlTexture(player);
assert url != null;
URL skinurl = new URL(url);
return ImageIO.read(skinurl);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 0045a78

Please sign in to comment.