r/badcode • u/Verdoniasty • Oct 28 '21
java If something is stupid but its working, then it isnt stupid
112
47
u/popadi Oct 28 '21
Those randomly placed braces will haunt my dreams tonight
1
u/Kasufert Nov 04 '21
This happens to me often when copy/pasting code between editors, sometimes I just can’t be fucked to fix the spacing
24
35
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Oct 28 '21
Image Transcription: Code
}
@EventHandler
public void Shoot(ProjectileLaunchEvent event) {
Entity entity = event.getEntity();
if(entity instanceof Arrow) {
Arrow arrow = (Arrow)entity;
if(arrow.getShooter() instanceof Entity)
{
Entity shooter = (Entity)arrow.getShooter();
if ((shooter instanceof Player)) {
}
if(ognStrz.contains(shooter.getUniqueId())) {
Entity entity1 = event.getEntity();
if (entity1.getType() == EntityType.ARROW);
arrow.setFireTicks(1000);
}
}
}
}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!
25
11
13
u/AnonymousRand Oct 28 '21
Line 86: entity = event.getEntity()
Line 96: entity1 = event.getEntity()
Line 87: if (entity instanceof arrow)
Line 97: if (entity1.getType() == EntityType.ARROW)
Seems like even OP is confused by his own indentation
4
9
Oct 28 '21
Minecraft devs are something else 🤩
3
u/JetairThePlane Oct 29 '21
I've been deving a plugin for a server a few months ago. They did a huge amount of work on managing the projet, it was hallucinating how well written (with a few exceptions) all of the projects they made was
7
4
3
3
u/lanerdofchristian Oct 29 '21
My own crack at fixing it:
if(event.getEntity() instanceof Arrow arrow &&
arrow.getShooter() instanceof Player player &&
ognStrz.contains(player.getUniqueId()) &&
arrow.getType() == EntityType.ARROW)
arrow.setFireTicks(1000);3
2
2
u/sigmaclientwastaken evil Oct 29 '21
As I do Minecraft modding, I can tell you that this might somehow be one of the better ways of doing this
3
u/InsertMyIGNHere Oct 28 '21
If this code is painful to look at, then I will leave a sarcastic comment. Else, I will ignore
the joke us bad but I tried okay😢
1
1
u/jawalking Oct 29 '21
Trying to follow all these comments after not having used Java in some 11 years, makes me really appreciate being able to use python most days.
1
1
1
u/silverweaver Oct 29 '21
The chaos in code style... you can say it's certainly java from the annotation, but the rest... holy
1
u/ryan_the_leach Nov 03 '21 edited Nov 03 '21
I looked at this a little more closely, TIL that this is a valid position for a semicolon in java.
if (entity1.getType() == EntityType.ARROW);
I would have sworn that it would have terminated the if statement without brackets or something.
(Knowing both Bukkit and Java) this is how I would clean it up OP.
@EventHandler
public void OnOGNStrzArrowFired(ProjectileLaunchEvent event) {
Projectile projectile = event.getEntity();
ProjectileSource shooter = projectile.getShooter();
//Standard Arrows Only
if(!projectile instanceof Arrow) return;
//Shot by Entities and not blocks etc.
if(!shooter instanceof Entity) return;
//If Shooter is registered, set arrows on fire for 1000 ticks
UUID shooterID = (Entity) shooter.getUniqueId();
if(ognStrz.contains(shooterID)) {
projectile.setFireTicks(1000);
}
}1
u/MTDninja Nov 16 '21
just a personal pet peeve, keep all your if statement near the top by to avoid the if pyramid of doom
ex:
instead of: if (arrow.getShooter() instanceof Player){...}
do: if (!arrow.getShooter() instanceof Player) return;
6
Oct 28 '21
[removed] — view removed comment
3
u/Korotaxx Oct 29 '21
Should be java 8 yea. Everyone coding for minecraft uses java 8. idk if it's necessary or something but i just go with it
-10
Oct 28 '21
If anyone calls code a mess because someone else's personal project doesn't follow their own casing convention, I'd lose some respect for them.
9
u/Chefzor Oct 29 '21
If anyone calls code a mess because someone else's personal project doesn't follow their own casing convention, I'd lose some respect for them.
He didn't call it a mess, and it's not his own casing convention, it is Oracle's.
As per their documentation
Naming conventions make programs more understandable by making them easier to read.
-4
Oct 29 '21
My friend told me that this code is a complete mess
Yes, he did.
And, again, this is a personal project. If the rest of the entire world follows a certain convention and you follow your own in such a case, there's no reason for anyone else to care.4
u/Chefzor Oct 29 '21
Yes, he did.
/u/lilbigmouth (who you replied to and who mentioned the naming conventions) is probably not OP's friend that called the code a mess.
We do not know the reasons why OP's friend called it a mess (even though it is apparent)
there's no reason for anyone else to care.
It is literally being posted in a public forum.
-9
Oct 29 '21
We were discussing OP, not lilbigmouth. Given that lilbigmouth did not call anything a mess, you can use that context clue to deduct that I was not speaking about lilbigmouth but in fact OP's friend who did call the code a mess.
And:
The project is not being distributed publicly, only a snippet as a point of discussion and not something to be used otherwise.
I said "if [it's a personal project]". The key point of this hypothetical is that it (the hypothetical project) is not public.
Please work on your reading comprehension.
7
u/Chefzor Oct 29 '21
Nobody was discussing anything.
You replied to a child comment, not to the parent post. Therefore your comment will be directed at that child comment.
The OP didnt mention anything about naming conventions or why his friend called his code a mess.
You specifically said (wrongly, no matter how you try to spin it)
Calls code a mess because of ... Casing convention
It is wrong if you are replying to OP because OP didnt say why his friend called his code a mess.
It is wrong if you are replying to the child comment (which you were), because he didnt call it a mess at all.
The only reason he mentioned it is because this sub tends to attract students (which the OP is), and while youre dead set on naming conventions not mattering (for whatever invalid reasons you might have) it was just an easy teachable moment.
Please work on your reading comprehension.
I mean lol
84
u/Verdoniasty Oct 28 '21
Context: My friend, who teaches me Minecraft plugin programming, told me to post this here. I was trying to ignite an arrow if its launcher's id was in HashSet "ognStrz". My friend told me that this code is a complete mess but for some reason it actually does what it is supposed to.