Solved Skull Owner

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Uzumaki

Well-Known Member
Feb 20, 2017
310
10
18
33
This is the skellet skull owner expression, I will really appreciate if anybody could fix it


Code:

Java:
package com.gmail.thelimeglass.Expressions;

import javax.annotation.Nullable;

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 com.gmail.thelimeglass.Utils.Annotations.Config;
import com.gmail.thelimeglass.Utils.Annotations.PropertyType;
import com.gmail.thelimeglass.Utils.Annotations.Syntax;

import ch.njol.skript.classes.Changer;
import ch.njol.skript.classes.Changer.ChangeMode;
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 ch.njol.util.coll.CollectionUtils;

@Syntax({"[the] [skellett] skull[ ]owner of [skull] %block%", "[skellett] [skull] %block%'s skull[ ]owner"})
@Config("SkullOwner")
@PropertyType(ExpressionType.COMBINED)
public class ExprSkullBlockOwner extends SimpleExpression<OfflinePlayer>{
   
    private Expression<Block> skull;
    @Override
    public Class<? extends OfflinePlayer> getReturnType() {
        return OfflinePlayer.class;
    }
    @Override
    public boolean isSingle() {
        return true;
    }
    @SuppressWarnings("unchecked")
    @Override
    public boolean init(Expression<?>[] e, int matchedPattern, Kleenean isDelayed, ParseResult parser) {
        skull = (Expression<Block>) e[0];
        return true;
    }
    @Override
    public String toString(@Nullable Event e, boolean arg1) {
        return "[the] skull[ ]owner of [skull] %block%";
    }
    @Override
    @Nullable
    protected OfflinePlayer[] get(Event e) {
        BlockState state = skull.getSingle(e).getState();
        if (state instanceof Skull) {
            Skull skull = (Skull) state;
            return new OfflinePlayer[]{skull.getOwningPlayer()};
        }
        return null;
    }
    @Override
    public void change(Event e, Object[] delta, Changer.ChangeMode mode){
        if (mode == ChangeMode.SET) {
            BlockState state = skull.getSingle(e).getState();
            if (state instanceof Skull) {
                Skull skull = (Skull) state;
                skull.setOwningPlayer((OfflinePlayer)delta[0]);
                skull.update();
            }
        }
    }
    @Override
    public Class<?>[] acceptChange(final Changer.ChangeMode mode) {
        if (mode == ChangeMode.SET) {
            return CollectionUtils.array(OfflinePlayer.class);
        }
        return null;
    }
}

Error:

code_language.skript:
[18:34:41 ERROR]: Could not pass event PlayerCommandPreprocessEvent to Skript v2.2-dev27
org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1154) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_171]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_171]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
Caused by: java.lang.NoSuchMethodError: org.bukkit.block.Skull.setOwningPlayer(Lorg/bukkit/OfflinePlayer;)V
        at com.gmail.thelimeglass.Expressions.ExprSkullBlockOwner.change(ExprSkullBlockOwner.java:59) ~[?:?]
        at ch.njol.skript.effects.EffChange.execute(EffChange.java:271) ~[?:?]
        at ch.njol.skript.lang.Effect.run(Effect.java:52) ~[?:?]
        at ch.njol.skript.lang.TriggerItem.walk(TriggerItem.java:61) ~[?:?]
        at ch.njol.skript.lang.TriggerItem.walk(TriggerItem.java:89) ~[?:?]
        at ch.njol.skript.lang.Trigger.execute(Trigger.java:55) ~[?:?]
        at ch.njol.skript.command.ScriptCommand.execute2(ScriptCommand.java:220) ~[?:?]
        at ch.njol.skript.command.ScriptCommand.execute(ScriptCommand.java:182) ~[?:?]
        at ch.njol.skript.command.Commands.handleCommand(Commands.java:268) ~[?:?]
        at ch.njol.skript.command.Commands$1.onPlayerCommand(Commands.java:163) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_171]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
        ... 16 more
[18:34:41 ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'test' in plugin Skript v2.2-dev27
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_171]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_171]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-21fe707-e1ebe52]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
Caused by: java.lang.NoSuchMethodError: org.bukkit.block.Skull.setOwningPlayer(Lorg/bukkit/OfflinePlayer;)V
        at com.gmail.thelimeglass.Expressions.ExprSkullBlockOwner.change(ExprSkullBlockOwner.java:59) ~[?:?]
        at ch.njol.skript.effects.EffChange.execute(EffChange.java:271) ~[?:?]
        at ch.njol.skript.lang.Effect.run(Effect.java:52) ~[?:?]
        at ch.njol.skript.lang.TriggerItem.walk(TriggerItem.java:61) ~[?:?]
        at ch.njol.skript.lang.TriggerItem.walk(TriggerItem.java:89) ~[?:?]
        at ch.njol.skript.lang.Trigger.execute(Trigger.java:55) ~[?:?]
        at ch.njol.skript.command.ScriptCommand.execute2(ScriptCommand.java:220) ~[?:?]
        at ch.njol.skript.command.ScriptCommand.execute(ScriptCommand.java:182) ~[?:?]
        at ch.njol.skript.command.ScriptCommand.onCommand(ScriptCommand.java:159) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-21fe707-e1ebe52]
        ... 15 more
>
[doublepost=1531774337,1531755348][/doublepost]nvm, found that you can update skull using nbt.