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

Can't find difference between Date and Timespan #575

Closed
MacMcMillan opened this issue May 18, 2017 · 11 comments
Closed

Can't find difference between Date and Timespan #575

MacMcMillan opened this issue May 18, 2017 · 11 comments
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation).

Comments

@MacMcMillan
Copy link

So I am trying to make some scripts but I keep running into errors and it fails to load anything.

[01:19:46] [Server thread/ERROR]: #!#!
[01:19:46] [Server thread/ERROR]: #!#! [Skript] Severe Error:
[01:19:46] [Server thread/ERROR]: #!#! Could not load Smash.sk
[01:19:46] [Server thread/ERROR]: #!#!
[01:19:46] [Server thread/ERROR]: #!#! If you're developing an add-on for Skript this likely means that you have done something wrong.
[01:19:46] [Server thread/ERROR]: #!#! If you're a server admin however please go to https://github.com/bensku/Skript/issues/
[01:19:46] [Server thread/ERROR]: #!#! and check whether this error has already been reported.
[01:19:46] [Server thread/ERROR]: #!#! If not please create a new ticket with a meaningful title, copy & paste this whole error into it (or use paste service),
[01:19:46] [Server thread/ERROR]: #!#! and describe what you did before it happened and/or what you think caused the error.
[01:19:46] [Server thread/ERROR]: #!#! If you think that it's a trigger that's causing the error please post the trigger as well.
[01:19:46] [Server thread/ERROR]: #!#! By following this guide fixing the error should be easy and done fast.
[01:19:46] [Server thread/ERROR]: #!#!
[01:19:46] [Server thread/ERROR]: #!#! Stack trace:
[01:19:46] [Server thread/ERROR]: #!#! java.lang.NullPointerException
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.expressions.ExprDifference.init(ExprDifference.java:104)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.SkriptParser.parse(SkriptParser.java:247)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.SkriptParser.parse(SkriptParser.java:174)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.SkriptParser.parseSingleExpr(SkriptParser.java:319)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.SkriptParser.parseExpression(SkriptParser.java:445)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.SkriptParser.parse_i(SkriptParser.java:1159)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.SkriptParser.parse_i(SkriptParser.java:1150)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.SkriptParser.parse(SkriptParser.java:219)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.SkriptParser.parse(SkriptParser.java:174)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.Statement.parse(Statement.java:59)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.ScriptLoader.loadItems(ScriptLoader.java:753)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.TriggerSection.(TriggerSection.java:54)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.lang.Conditional.(Conditional.java:44)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.ScriptLoader.loadItems(ScriptLoader.java:839)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.ScriptLoader.loadScript(ScriptLoader.java:510)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.ScriptLoader.loadScripts(ScriptLoader.java:245)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.ScriptLoader.loadScripts(ScriptLoader.java:199)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.Skript.reload(Skript.java:722)
[01:19:46] [Server thread/ERROR]: #!#! at ch.njol.skript.SkriptCommand.onCommand(SkriptCommand.java:159)
[01:19:46] [Server thread/ERROR]: #!#! at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
[01:19:46] [Server thread/ERROR]: #!#! at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
[01:19:46] [Server thread/ERROR]: #!#! at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:650)
[01:19:46] [Server thread/ERROR]: #!#! at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchServerCommand(CraftServer.java:636)
[01:19:46] [Server thread/ERROR]: #!#! at net.minecraft.server.v1_11_R1.DedicatedServer.aM(DedicatedServer.java:437)
[01:19:46] [Server thread/ERROR]: #!#! at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:400)
[01:19:46] [Server thread/ERROR]: #!#! at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678)
[01:19:46] [Server thread/ERROR]: #!#! at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576)
[01:19:46] [Server thread/ERROR]: #!#! at java.lang.Thread.run(Thread.java:745)
[01:19:46] [Server thread/ERROR]: #!#!
[01:19:46] [Server thread/ERROR]: #!#! Version Information:
[01:19:46] [Server thread/ERROR]: #!#! Skript: 2.2-dev27
[01:19:46] [Server thread/ERROR]: #!#! Bukkit: 1.11.2-R0.1-SNAPSHOT
[01:19:46] [Server thread/ERROR]: #!#! Minecraft: 1.11.2
[01:19:46] [Server thread/ERROR]: #!#! Java: 1.8.0_74 (Java HotSpot(TM) 64-Bit Server VM 25.74-b02)
[01:19:46] [Server thread/ERROR]: #!#! OS: Linux amd64 3.10.23-xxxx-std-ipv6-64
[01:19:46] [Server thread/ERROR]: #!#!
[01:19:46] [Server thread/ERROR]: #!#! Running CraftBukkit: false
[01:19:46] [Server thread/ERROR]: #!#!
[01:19:46] [Server thread/ERROR]: #!#! Current node: set {_dash} to difference between {dash.%player%} and now (Smash.sk, line 3)
[01:19:46] [Server thread/ERROR]: #!#! Current item: null
[01:19:46] [Server thread/ERROR]: #!#!
[01:19:46] [Server thread/ERROR]: #!#! Thread: Server thread
[01:19:46] [Server thread/ERROR]: #!#!
[01:19:46] [Server thread/ERROR]: #!#! End of Error.
[01:19:46] [Server thread/ERROR]: #!#!

Is there anything that I am doing wrong that I just don't know of?

@TheLimeGlass
Copy link
Collaborator

TheLimeGlass commented May 22, 2017

{dash.%player%} is not a Timeperiod/Timespan type or it's not set, so it throws a null pointer. It's your problem, but a small cosmetic that could be fixed.

2018 Edit: It's not a small fix lol

@bensku bensku added the bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. label May 24, 2017
@Snow-Pyon Snow-Pyon added the priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation). label Jan 31, 2018
@TheLimeGlass
Copy link
Collaborator

This class has been modified since the date this was posted. Someone should test to see if this still occurs.

@Snow-Pyon
Copy link

I'll test it later, thanks for the heads up @TheLimeGlass.

@Nicofisi
Copy link
Member

Seems fine

>!message "%difference between {notset} and now%"
[08:30:01 INFO]: executing 'message "%difference between {null} and now%"'
[08:30:01 INFO]: <none>
>

@Snow-Pyon
Copy link

@TheLimeGlass did you try comparing a date with a timespan/timeperiod too?

@Nicofisi
Copy link
Member

Like that?

>!message "%difference between 30 seconds and now%"
[08:37:23 ERROR]: Error in: message "%difference between 30 seconds and now%"
[08:37:23 ERROR]: Can't understand this expression: difference between 30 seconds and now
>

I'm not LimeGlass :c

@Nicofisi
Copy link
Member

Nicofisi commented Feb 28, 2018

Wellll

>!set {x} to now
[10:34:01 INFO]: executing 'set {x} to now'                                        >!set {y} to 30 seconds
[10:34:14 INFO]: executing 'set {y} to 30 seconds'                                 >message "%diference between {x} and {y}%"
[10:34:44 INFO]: Unknown command. Type "/help" for help.                           >!message "%diference between {x} and {y}%"
[10:34:52 ERROR]: Error in: message "%diference between {x} and {y}%"              [10:34:52 ERROR]: Can't understand this expression: diference between {x} and {y}
>!message "%difference between {x} and {y}%"                                       [10:35:06 INFO]: executing 'message "%difference between {x} and {y}%"'
[10:35:06 ERROR]: #!#!                                                             [10:35:06 ERROR]: #!#! [Skript] Severe Error:
[10:35:06 ERROR]: #!#! Unexpected error while executing effect command 'message "%difference between {x} and {y}%"' by 'CONSOLE'
[10:35:06 ERROR]: #!#!                                                             [10:35:06 ERROR]: #!#! Something went horribly wrong with Skript.                  [10:35:06 ERROR]: #!#! This issue is NOT your fault! You probably can't fix it yourself, either.                                                                      [10:35:06 ERROR]: #!#! You should report it at https://github.com/bensku/Skript/issues. Please copy paste this report there (or use paste service).                   [10:35:06 ERROR]: #!#! This ensures that your issue is noticed and will be fixed as soon as possible.                                                                 [10:35:06 ERROR]: #!#!
[10:35:06 ERROR]: #!#! Stack trace:                                                [10:35:06 ERROR]: #!#! java.lang.ClassCastException: ch.njol.skript.util.Timespan cannot be cast to ch.njol.skript.util.Date
[10:35:06 ERROR]: #!#!     at ch.njol.skript.classes.data.SkriptClasses$14.difference(SkriptClasses.java:1)                                                           [10:35:06 ERROR]: #!#!     at ch.njol.skript.expressions.ExprDifference.get(ExprDifference.java:136)
[10:35:06 ERROR]: #!#!     at ch.njol.skript.lang.util.SimpleExpression.getArray(SimpleExpression.java:100)
[10:35:06 ERROR]: #!#!     at ch.njol.skript.lang.VariableString.toUnformattedString(VariableString.java:472)
[10:35:06 ERROR]: #!#!     at ch.njol.skript.lang.VariableString.getMessageComponents(VariableString.java:487)
[10:35:06 ERROR]: #!#!     at ch.njol.skript.effects.EffMessage.execute(EffMessage.java:86)
[10:35:06 ERROR]: #!#!     at ch.njol.skript.lang.Effect.run(Effect.java:49)
[10:35:06 ERROR]: #!#!     at ch.njol.skript.command.Commands.handleEffectCommand(Commands.java:267)
[10:35:06 ERROR]: #!#!     at ch.njol.skript.command.Commands.access$0(Commands.java:248)
[10:35:06 ERROR]: #!#!     at ch.njol.skript.command.Commands$1.onServerCommand(Commands.java:171)
[10:35:06 ERROR]: #!#!     at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
[10:35:06 ERROR]: #!#!     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[10:35:06 ERROR]: #!#!     at java.lang.reflect.Method.invoke(Method.java:498)

Edit: sorry I sent this from my phone lol

@TheLimeGlass
Copy link
Collaborator

TheLimeGlass commented May 3, 2018

The stacktraces are due to variables (The Difference expression handles Variables differently) and when they're not variables it states that Skript can't get the difference between the two, which leads to the stacktraces within the variables due to no Arithmetic setup for Date to Timespan and vice versa.

I attempted to fix this issue but the main problem is being the Arithmetic of the Date/Timespans. They only accept the first generic of the Arithmetic to be converted with itself (Meaning compare Date with Date but returns the secondary generic) and the main problem is that the system would have to be heavily modified to be able to support multiple Arithmetics. Due to this I didn't want to finalize a fix for this. You can make a cheesy fix in this section https://github.com/bensku/Skript/blob/master/src/main/java/ch/njol/skript/expressions/ExprDifference.java#L123-L142

But the main point of difference is to be able to use the Arithmetic of types to compare differences.

Alternatives could include making a dual Arithmetic, making an Arithmetic that checks the difference between the first and second generic and returns the type that the Arithmetic is associated with, or utilizing a Comparator to convert a Timespan to Date and vice versa while finding the difference.

This expression has since been released https://github.com/bensku/Skript/blob/master/src/main/java/ch/njol/skript/expressions/ExprDateAgoLater.java

Which will help you achieve what you're attempting to do in this issue.

For reference:
https://github.com/bensku/Skript/blob/016bd2b4aadfd2bf3c3ea12be3c0f86d179d8222/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java#L559-L561

https://github.com/bensku/Skript/blob/016bd2b4aadfd2bf3c3ea12be3c0f86d179d8222/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java#L437-L439

@bensku I'm interested in your thoughts about this fix, because there should definitely be a system to be able to check multiple Arithmetics. Some types can contain more than one difference between two objects (just like in this case), especially for addon developers.

And to anyone reading this with permissions, can the title be changed to something like "Can't find difference between Date and Timespan"

@bensku
Copy link
Member

bensku commented May 3, 2018

We should probably attempt to convert Dates to Timespans or the other way around. I'm not exactly sure how that would be best implemented, though...

@TheLimeGlass
Copy link
Collaborator

TheLimeGlass commented May 3, 2018

I don't know the best way either but I know of several ways, and the conversion already exists in the date class.

public Timespan difference(final Date other) {
	return new Timespan(Math.abs(timestamp - other.timestamp));
}

@TheLimeGlass
Copy link
Collaborator

TheLimeGlass commented Aug 26, 2018

There are like 3-4 issues about this now, some duplicates.

@ShaneBeee ShaneBeee changed the title Failure to load Skripts. an't find difference between Date and Timespan Jun 29, 2020
@ShaneBeee ShaneBeee changed the title an't find difference between Date and Timespan Can't find difference between Date and Timespan Jun 29, 2020
@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
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. 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

7 participants