Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.ClassCastException: ch.njol.skript.util.Timespan cannot be cast to ch.njol.skript.util.Date #1001

Closed
supertassu opened this issue Dec 6, 2017 · 7 comments
Labels
completed The issue has been fully resolved and the change will be in the next Skript update. enhancement Feature request, an issue about something that could be improved, or a PR improving something. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation).

Comments

@supertassu
Copy link
Contributor

java.lang.ClassCastException: ch.njol.skript.util.Timespan cannot be cast to ch.njol.skript.util.Date

My skript is most likely broken, but a nice error message would be nicer that errors in console. :P

The Script

command /restart <timespan=10 minutes>:
    description: Restart the server!
    permission: restart.now
    executable by: players and console
    trigger:
        if {restart.timer} is set:
            send "&cServer already restarting at %difference between {restart.started} and {restart.difference}%... "
            stop

        set {restart.started} to now
        set {restart.difference} to arg 1 
    
        broadcast "&c*** SERVER RESTARTING AT %difference between {restart.started} and {restart.difference}%!"
        stop

every second:
    if {restart.timer} is set:
        loop all players:
            #show an action bar from "&cServer restarting at %difference between {restart.started} and {restart.difference}%... " to loop-player ## Skelett
        if difference between {restart.started} and now is more than {restart.difference}:
            broadcast "&c*** SERVER RESTARTING NOW!"
            execute console command "/stop"

Stack Trace

[10:45:15 ERROR]: #!#!
[10:45:15 ERROR]: #!#! [Skript] Severe Error:
[10:45:15 ERROR]: #!#!
[10:45:15 ERROR]: #!#! Something went horribly wrong with Skript.
[10:45:15 ERROR]: #!#! This issue is NOT your fault! You probably can't fix it yourself, either.
[10:45:15 ERROR]: #!#! You should report it at https://github.com/bensku/Skript/issues. Please copy paste this report there (or use paste service).
[10:45:15 ERROR]: #!#! This ensures that your issue is noticed and will be fixed as soon as possible.
[10:45:15 ERROR]: #!#!
[10:45:15 ERROR]: #!#! Stack trace:
[10:45:15 ERROR]: #!#! java.lang.ClassCastException: ch.njol.skript.util.Timespan cannot be cast to ch.njol.skript.util.Date
[10:45:15 ERROR]: #!#!     at ch.njol.skript.classes.data.SkriptClasses$14.difference(SkriptClasses.java:1)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.expressions.ExprDifference.get(ExprDifference.java:139)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.lang.util.SimpleExpression.getArray(SimpleExpression.java:104)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.lang.VariableString.toString(VariableString.java:430)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.lang.VariableString.getArray(VariableString.java:594)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.lang.VariableString.getArray(VariableString.java:1)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.effects.EffBroadcast.execute(EffBroadcast.java:67)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.lang.Effect.run(Effect.java:52)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.lang.TriggerItem.walk(TriggerItem.java:61)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.lang.TriggerItem.walk(TriggerItem.java:89)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.lang.Trigger.execute(Trigger.java:55)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.command.ScriptCommand.execute2(ScriptCommand.java:220)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.command.ScriptCommand.execute(ScriptCommand.java:182)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.command.Commands.handleCommand(Commands.java:269)
[10:45:15 ERROR]: #!#!     at ch.njol.skript.command.Commands$1.onPlayerCommand(Commands.java:164)
[10:45:15 ERROR]: #!#!     at com.destroystokyo.paper.event.executor.MethodHandleEventExecutor.execute(MethodHandleEventExecutor.java:35)
[10:45:15 ERROR]: #!#!     at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:78)
[10:45:15 ERROR]: #!#!     at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
[10:45:15 ERROR]: #!#!     at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:515)
[10:45:15 ERROR]: #!#!     at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:500)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1463)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1276)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:5)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:14)
[10:45:15 ERROR]: #!#!     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[10:45:15 ERROR]: #!#!     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:843)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:426)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:767)
[10:45:15 ERROR]: #!#!     at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:665)
[10:45:15 ERROR]: #!#!     at java.lang.Thread.run(Thread.java:748)
[10:45:15 ERROR]: #!#!
[10:45:15 ERROR]: #!#! Version Information:
[10:45:15 ERROR]: #!#!   Skript: 2.2-dev32c (latest)
[10:45:15 ERROR]: #!#!   Bukkit: 1.12.2-R0.1-SNAPSHOT
[10:45:15 ERROR]: #!#!   Minecraft: 1.12.2
[10:45:15 ERROR]: #!#!   Java: 1.8.0_151 (OpenJDK 64-Bit Server VM 25.151-b12)
[10:45:15 ERROR]: #!#!   OS: Linux amd64 4.4.0-98-generic
[10:45:15 ERROR]: #!#!
[10:45:15 ERROR]: #!#! Running CraftBukkit: false
[10:45:15 ERROR]: #!#! Running Spigot (or compatible): true
[10:45:15 ERROR]: #!#! Running Paper (or compatible): true
[10:45:15 ERROR]: #!#!
[10:45:15 ERROR]: #!#! Current node: null
[10:45:15 ERROR]: #!#! Current item: broadcast "*** SERVER RESTARTING AT %difference between {restart.started}(as java.lang.Object) and {restart.difference}(as java.lang.Object)%!"
[10:45:15 ERROR]: #!#! Thread: Server thread
[10:45:15 ERROR]: #!#!
[10:45:15 ERROR]: #!#! Language: english
[10:45:15 ERROR]: #!#! Link parse mode: DISABLED
[10:45:15 ERROR]: #!#!
[10:45:15 ERROR]: #!#! End of Error.
[10:45:15 ERROR]: #!#!

Versions

> pl
[10:49:45 INFO]: Plugins (22): AdvancedAchievements, BungeeTabListPlus, CoreProtect, DynamicSigns, dynmap, Essentials, EssentialsChat, FastAsyncVoxelSniper, FastAsyncWorldEdit, FeatherBoard, LuckPerms, mcMMO, MVdWPlaceholderAPI, PacketListenerApi, PlaceholderAPI, Skript, StaffPlus, Vault, VoxelSniper, WorldBorder, WorldEdit, WorldGuard
> ver
[10:50:11 INFO]: This server is running Paper version git-Paper-1268 (MC: 1.12.2) (Implementing API version 1.12.2-R0.1-SNAPSHOT)
[10:50:11 INFO]: Checking version, please wait...
[10:50:11 INFO]: You are 1 version(s) behind
> ver Skript
[10:50:27 INFO]: Skript version 2.2-dev32c
[10:50:27 INFO]: Customize Minecraft's mechanics with simple scripts written in plain English sentences.
[10:50:27 INFO]: Website: https://bensku.github.io/Skript
[10:50:27 INFO]: Authors: Njol, Mirreski, bensku, TheBentoBox, tim740, Tuke-Nuke, TheLimeGlass, xXAndrew28Xx, Sashie, RoyCurtis, nfell2009, Syst3ms and Snow-Pyon

Let me know if you need any more information.

@Pikachu920
Copy link
Member

Pikachu920 commented Dec 7, 2017

This is a recent issue, it used to be a silent failure. The issue with your script, though, is that you can't compare a date and a timespan (think about it, it wouldn't make sense.. How do you compare 12/06/2017 9:00 PM and 10 minutes?).

@bensku
Copy link
Member

bensku commented Dec 7, 2017

Well, silent failures are bad but this is worse.

@TheBentoBox TheBentoBox added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label Dec 7, 2017
@TheBentoBox
Copy link
Member

Marking as an enhancement since this isn't a bug (it's user error, the things you're comparing can't be compared) but there should be an on-parse error which says you can't get the difference between a date and timespan.

@Pikachu920
Copy link
Member

That isnt really possible

@TheBentoBox
Copy link
Member

Why not? Couldn't it just check if the things you're checking a difference between are a timespan and a date?

@Pikachu920
Copy link
Member

It isn't possible because sometimes the thing being returned isn't known until runtime. Take variables for example, unless you meant if it could be determined in which case it already does error although not descriptively.

@Snow-Pyon Snow-Pyon added the priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation). label Feb 20, 2018
@TheLimeGlass
Copy link
Collaborator

TheLimeGlass commented Aug 26, 2018

Similar #575

Also use %date% (was|were)( more|(n't| not) less) than %timespan% [ago]

@Whimsyturtle Whimsyturtle added the completed The issue has been fully resolved and the change will be in the next Skript update. label Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completed The issue has been fully resolved and the change will be in the next Skript update. enhancement Feature request, an issue about something that could be improved, or a PR improving something. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation).
Projects
None yet
Development

No branches or pull requests

8 participants