// Check if the transcript of a post contains the German word "<Yet another German word>" Else If post..transcript.contains ( "<Yet another German word>")
Someone commented, that the § constructs are color codes for the Minecraft chat and it contains hard-coded non-English messages, so this is probably code from a mod.
Mods being what they are might be written by people with no prior experience in the language and quite possibly no software engineering education. As such, the code isn't that surprising.
== compares if they are the same object(if they point to the same place ),equals, compares if the content is the same. strings however have a pool, so two strings will point to the same place if the content is the same.
I don't know about Java > 8, but afaik only string literals as well as strings on which you explicitly called intern() go into the pool. Either way you shouldn't rely on that and always use equals() in Java.
Memory saving and performance. But it’s an internal implementation thingy of the JVM. So if you use == it will fail at some point and will leave you wondering why your code just broke. Using == on strings is wrong here. Don’t do it.
Ah yeah, didn't look too close, no unicode problems there.
On a more serious note in case you actually expect this code to work: The string compare is broken, you can't compare strings using == in Java (well - you can, but it doesn't do what you want and will always return false in your case). Use .equals(). This is one of the side effects of Java being one of the few languages boycotting operator overloading.
You could use a switch/case though, which works with strings. Also an improvement would be to use translatable text, but that requires a resource pack to contain the language files I believe. This would have the advantage that each client would see the text in the configured language (as long a you provide one) though.
...but you didn't even mention the main issue - the Date should never have been converted to a string in the first place!! Just use Date arithmetic to find out the number of minutes, then display it. No need for switch-case, etc.
I didn't actually make this code, just to clarify. I did learn the == lesson the hard way though. I was comparing two UUIDs and it didn't warn me, so I was super confused until a kind spigot user informed me that UUIDs also need to be compared with .equals.
That seems fine if it is a DateTimeFormatter or something.
The concerning thing is the use of == for string comparison; the use of Date when it is mostly deprecated in favour of the time API; the use of strings to compare time, and the fact this code is likely making assumptions that the OS doesn't pause the thread during the moments that are being compared, which is entirely possible under load, especially outside a real time kernel.
I dunno why this is downvoted. Java has a proper time API that is far easier to use and far more accurate. Most of the old Date API is deprecated now too, and has issues that can cause confusion between timezones.
194
u/Jayson_json Oct 13 '21
I love how 60% of posts are german
6
u/RedditAcc-92975 Oct 14 '21
Where the hell did you dig out this one? I mean, nobody can be that stupid. I need to know.
51
u/MarquisDan Oct 14 '21
All these hardcoded strings could be avoided if only computers were good at math.
49
u/inventord Oct 13 '21
Spigot plugin?
21
u/[deleted] Oct 14 '21
Minecraft spigot devs be like
72
u/Rainbow-Dev Oct 13 '21
== instead of .equals :(
30
u/Kilobyte22 Oct 13 '21
Also unicode problems and even improper string compare. A true masterpiece
1
u/LanimationsD Dec 19 '21
amogus
7
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Oct 13 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
4
u/[deleted] Oct 14 '21
also broadCast... its one word
1
u/Auxilor Oct 14 '21
Spigot plugins bring out the best of developers
1
u/TheAwesome98_Real evil Oct 14 '21
Minecraft?
EDIT: if this is a modern plugin for spigot this is actually wronger than you’d think
1
u/zerolfer Oct 14 '21
Well if the format do not format then who's gonna format
1
u/alexhmc Oct 14 '21
you know its gonna be bad if its a minecraft server plugin on this sub lol
1
u/nekokattt Oct 14 '21
That seems fine if it is a DateTimeFormatter or something.
The concerning thing is the use of == for string comparison; the use of Date when it is mostly deprecated in favour of the time API; the use of strings to compare time, and the fact this code is likely making assumptions that the OS doesn't pause the thread during the moments that are being compared, which is entirely possible under load, especially outside a real time kernel.
1
u/itsTyrion Oct 14 '21
Ah yes, "Minecraft plug-in developer"
Can confirm that people love to jump into it with (next to) no prior experience.
(It may be possible that I did parts of this myself when I first jumped into the rabbit hole...)
1
u/Tvde1 Oct 14 '21
imagine thinking times are valid in programming
0
u/dfmaaa1 Oct 14 '21
bruh .equals
-5
u/BroBroMate Oct 13 '21
What monster is still using
Date?Nevermind the other atrocities...
-1
u/kappcity Oct 14 '21
Wow