From a581668a8568f30bf67cdfc8ef9a1c3c6ba2f6a3 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Mon, 15 May 2023 15:41:46 +0800 Subject: [PATCH 1/2] Initial --- .../skript/expressions/ExprSkullOwner.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/main/java/ch/njol/skript/expressions/ExprSkullOwner.java diff --git a/src/main/java/ch/njol/skript/expressions/ExprSkullOwner.java b/src/main/java/ch/njol/skript/expressions/ExprSkullOwner.java new file mode 100644 index 00000000000..d80f34a032e --- /dev/null +++ b/src/main/java/ch/njol/skript/expressions/ExprSkullOwner.java @@ -0,0 +1,84 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.expressions; + +import ch.njol.skript.classes.Changer.ChangeMode; +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.SimplePropertyExpression; +import ch.njol.util.coll.CollectionUtils; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.block.Block; +import org.bukkit.block.Skull; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Skull Owner") +@Description("The skull owner of a player skull.") +@Examples({ + "set {_owner} to the skull owner of event-block", + "set skull owner of {_block} to player" +}) +@Since("INSERT VERSION") +public class ExprSkullOwner extends SimplePropertyExpression { + + static { + register(ExprSkullOwner.class, OfflinePlayer.class, "(head|skull) owner", "blocks"); + } + + @Override + public @Nullable OfflinePlayer convert(Block block) { + if (block.getType().equals(Material.PLAYER_HEAD) || block.getType().equals(Material.PLAYER_WALL_HEAD)) { + return ((Skull) block.getState()).getOwningPlayer(); + } + return null; + } + + @Override + public @Nullable Class[] acceptChange(ChangeMode mode) { + if (mode == ChangeMode.SET) + return CollectionUtils.array(OfflinePlayer.class); + return null; + } + + @Override + public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { + for (Block block : getExpr().getArray(event)) { + if (block.getType().equals(Material.PLAYER_HEAD) || block.getType().equals(Material.PLAYER_WALL_HEAD)) { + Skull skull = (Skull) block.getState(); + skull.setOwningPlayer((OfflinePlayer) delta[0]); + skull.update(); + } + } + } + + @Override + public Class getReturnType() { + return OfflinePlayer.class; + } + + @Override + protected String getPropertyName() { + return "skull owner"; + } + +} From adf4f7836a525cc8bef3c00d875e5549a7f96ad1 Mon Sep 17 00:00:00 2001 From: DelayedGaming Date: Fri, 11 Aug 2023 21:08:07 +0800 Subject: [PATCH 2/2] Requested changes from LimeGlass till June 2, 2023 --- .../skript/expressions/ExprSkullOwner.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/njol/skript/expressions/ExprSkullOwner.java b/src/main/java/ch/njol/skript/expressions/ExprSkullOwner.java index d80f34a032e..403d7b360c9 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprSkullOwner.java +++ b/src/main/java/ch/njol/skript/expressions/ExprSkullOwner.java @@ -25,9 +25,9 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.expressions.base.SimplePropertyExpression; import ch.njol.util.coll.CollectionUtils; -import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.Skull; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; @@ -36,7 +36,7 @@ @Description("The skull owner of a player skull.") @Examples({ "set {_owner} to the skull owner of event-block", - "set skull owner of {_block} to player" + "set skull owner of {_block} to \"Njol\" parsed as offlineplayer" }) @Since("INSERT VERSION") public class ExprSkullOwner extends SimplePropertyExpression { @@ -47,14 +47,15 @@ public class ExprSkullOwner extends SimplePropertyExpression[] acceptChange(ChangeMode mode) { + @Nullable + public Class[] acceptChange(ChangeMode mode) { if (mode == ChangeMode.SET) return CollectionUtils.array(OfflinePlayer.class); return null; @@ -62,11 +63,13 @@ public class ExprSkullOwner extends SimplePropertyExpression