PlaceholderAPI / Javascript-Expansion

Adds javascript placeholders
GNU General Public License v3.0
22 stars 24 forks source link

I couldn't use the javascript to make console send command. (Could you help me?) #80

Closed BaiMoYi closed 2 months ago

BaiMoYi commented 2 months ago

var haha = BukkitConsoleCommandSender;

function getMotd() { var niubi = haha.getServer(); // 获取控制台命令发送者 var kongzhitai = niubi.getConsoleSender(); // 定义要执行的命令 var zhiling = "time set day"; // 让控制台执行命令 return bukkit.dispatchCommand(kongzhitai, zhiling);

}

getMotd();

This is my

BaiMoYi commented 2 months ago

This is my javascipt and the Console back me

BaiMoYi commented 2 months ago

[22:01:22 ERROR]: [PAPI] [Javascript-Expansion] An error occurred while executing the script 'ceshi javax.script.ScriptException: ReferenceError: "BukkitConsoleCommandSender" is not defined in at line number 1 at org.openjdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:463) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:447) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:395) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:151) ~[PlaceholderAPI-2.11.6.jar:?] at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:262) ~[java.scripting:?] at com.extendedclip.papi.expansion.javascript.evaluator.NashornScriptEvaluator.execute(NashornScriptEvaluator.java:27) ~[?:?] at com.extendedclip.papi.expansion.javascript.JavascriptPlaceholder.evaluate(JavascriptPlaceholder.java:120) ~[?:?] at com.extendedclip.papi.expansion.javascript.JavascriptExpansion.onRequest(JavascriptExpansion.java:157) ~[?:?] at me.clip.placeholderapi.replacer.CharsReplacer.apply(CharsReplacer.java:119) ~[PlaceholderAPI-2.11.6.jar:?] at me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(PlaceholderAPI.java:71) ~[PlaceholderAPI-2.11.6.jar:?] at me.clip.placeholderapi.commands.impl.local.CommandParse.evaluateParseSingular(CommandParse.java:118) ~[PlaceholderAPI-2.11.6.jar:?] at me.clip.placeholderapi.commands.impl.local.CommandParse.evaluate(CommandParse.java:57) ~[PlaceholderAPI-2.11.6.jar:?] at me.clip.placeholderapi.commands.PlaceholderCommandRouter.onCommand(PlaceholderCommandRouter.java:114) ~[PlaceholderAPI-2.11.6.jar:?] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.20.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.craftbukkit.v1_20_R3.CraftServer.dispatchCommand(CraftServer.java:999) ~[paper-1.20.4.jar:git-Paper-497] at org.bukkit.craftbukkit.v1_20R3.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:64) ~[paper-1.20.4.jar:git-Paper-497] at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.2.9.jar:?] at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:31) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:19) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.commands.execution.UnboundEntryAction.lambda$bind$0(UnboundEntryAction.java:8) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.commands.execution.CommandQueueEntry.a(CommandQueueEntry.java:5) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.commands.execution.ExecutionContext.runCommandQueue(ExecutionContext.java:103) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.commands.Commands.executeCommandInContext(Commands.java:434) ~[?:?] at net.minecraft.commands.Commands.performCommand(Commands.java:336) ~[?:?] at net.minecraft.commands.Commands.performCommand(Commands.java:323) ~[?:?] at net.minecraft.server.network.ServerGamePacketListenerImpl.performChatCommand(ServerGamePacketListenerImpl.java:2230) ~[?:?] at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$14(ServerGamePacketListenerImpl.java:2190) ~[?:?] at net.minecraft.util.thread.BlockableEventLoop.lambda$submitAsync$0(BlockableEventLoop.java:59) ~[?:?] at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?] at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:149) ~[?:?] at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?] at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1465) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:194) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:123) ~[?:?] at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1442) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1365) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:133) ~[?:?] at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1343) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1232) ~[paper-1.20.4.jar:git-Paper-497] at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:319) ~[paper-1.20.4.jar:git-Paper-497] at java.lang.Thread.run(Thread.java:1583) ~[?:?] Caused by: org.openjdk.nashorn.internal.runtime.ECMAException: ReferenceError: "BukkitConsoleCommandSender" is not defined at org.openjdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:318) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:290) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.internal.objects.Global.noSuchProperty(Global.java:1614) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.internal.scripts.Script$187$\^eval\.:program(:1) ~[?:?] at org.openjdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:646) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:520) ~[PlaceholderAPI-2.11.6.jar:?] at org.openjdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:442) ~[PlaceholderAPI-2.11.6.jar:?] ... 42 more