#dev-general

1 messages ยท Page 535 of 1

winter iron
#

but it doesnt pick it up

ocean quartz
#
cooldowns[key]?.let { System.currentTimeMillis() - it <= cooldown } == true
half harness
#

^

winter iron
#

thats rank

onyx loom
#

fun isOnCooldown(key: K) {
val value = cooldowns[key] ?: return false
return TIME - value <= cooldown

winter iron
#

๐Ÿคฎ

winter iron
onyx loom
#

the whole reason why the !! is there is because it can lol

winter iron
#

keep it coming more suggestions ๐Ÿ˜‹

half harness
#

ok then

#

lol

#

๐Ÿ™„

forest pecan
#

You canโ€™t hide your embarrassment

onyx loom
#

editing ur messages kek

cinder flare
#

happened to me too

onyx loom
#

i can easily expose u rn ๐Ÿ˜Œ

winter iron
#
return System.currentTimeMillis() - (cooldowns[key] ?: return false) <= cooldown
#

๐Ÿ™‚

ocean quartz
#

๐Ÿ˜ฉ

onyx loom
#

decent

half harness
#

lol

#

rip let

onyx loom
#

im guessing u removed the containsKey too

winter iron
#

ye

#

thats it now

#

lmao

cinder flare
#

let is so cute tho

onyx loom
#

ez 1 liner

half harness
#
fun blah(): Boolean = System.currentTimeMillis() - (cooldowns[key] ?: return false) <= cooldown
``` ๐Ÿ˜Œ
#

rice?

forest pecan
#

Very healthy

half harness
#

O

ocean quartz
#
fun blah() = cooldowns[key]?.let { System.currentTimeMillis() - it <= cooldown } == true
half harness
#

lol

#

matt

#

persistent

onyx loom
#

explicit Type ๐ŸŒš

#

ew no

#

if u using expression functions then remove the return type

half harness
#

ok

#

i sometimes keep it to make sure its correct

#

or to know the return value without looking too much into it

winter iron
#

๐Ÿ˜ฆ

#

it was confusion

half harness
#

use matt's fingerguns

winter iron
#

no

#

no let

half harness
#

y

onyx loom
winter iron
#

when i first saw let i was instantly put off

half harness
winter iron
#

idk why

half harness
#

too long ๐Ÿ˜ฉ

winter iron
#

i didnt like it

cinder flare
#

are you a math hater too

forest pecan
half harness
rotund egret
winter iron
#

maybe i will grow fond of let one day

half harness
#

jitpack

ocean quartz
#

Dkim, you forgot also, with ๐Ÿ˜Œ

half harness
#

oh

#

i didn't know those existed

onyx loom
#

with is so great

rotund egret
#

what is with?

onyx loom
#

it takes a receiver then u can use it so it like shortens the code with the implicit this kinda

#

idk how else to explain it

winter iron
#

with is nice

ocean quartz
#
with (something) {
  doThis()
  doThat()
  doHello()
}
// instead of
something.doThis()
something.doThat()
something.doHello()
winter iron
#
fun getLocation(path: String): Location? {
        return with (config.getString(path)) {
            if (this == null) {
                null
            } else {
                locationFromString(this)
            }
        }
    }
#

smth like that

rotund egret
#

Oh, I thought you were talking about gradle tasks

#

I know about with, super nice

half harness
rotund egret
#

err I'm thinking of when in kotlin

onyx loom
#

run uses it instead of this i think

rotund egret
#

I'm all over the place

half harness
onyx loom
#

i could also say its apply, also etc etc

ocean quartz
#

They are similar but used for different things

onyx loom
#

^

winter iron
#

the question I have for with is should it be

with(someshit) {}
with (someshit) {}
#

first one right?

ocean quartz
#

Bottom

winter iron
#

i use the bottom currently

#

but it looks weird

ocean quartz
#

Oh wait i guess first lmao

onyx loom
#

i use first

#

because its technically a function still

winter iron
#

ye

ocean quartz
#

Auto format

winter iron
#

thats probs why I have the space

#

ahh fuck

#

these are the real decisons

cinder flare
#

yeah defo have a space

#

it's like an if statement

#

hey im not a dog

winter iron
#

ok

ocean quartz
winter iron
#

fucking let man

#

hmm

#

I shall adopt the let method

ocean quartz
#

it's good

cinder flare
#

hell yea

half harness
winter iron
#

Ok

cinder flare
#

so let just lets you (heh) do stuff based on if something is null or not?

winter iron
#

i like it now

half harness
cinder flare
#

oh dang someone's gotta do like a streams in java -> kotlin tutorial

#

where's the BM youtube series

winter iron
#

in the void

onyx loom
#

check the kotlin yt channel

cinder flare
#

is that a terraria npc Zodd lmao

rotund egret
#

Yes

onyx loom
#

matt linked an obscure, yet cool yt vid from them like last week or smth

cinder flare
#

she kinda cute tho

#

well send it again!

ocean quartz
cinder flare
ocean quartz
#

a hack

cinder flare
#

i mean true

rotund egret
#

Yo did BM ever get back to that guy that was pinging him for like 3 hours? I need to know

cinder flare
#

if it were open source it'd probably not be a hack tho

#

no I don't think so

rotund egret
#

๐Ÿ˜ฆ

#

Rest in peace

cinder flare
#

Matt send me your kotlin knowledge

#

i need to be prepared for Ktor

onyx loom
ocean quartz
#

This blog post accompanies this episode: https://dev.to/kotlin/advanced-kotlin-collection-functionality-5e90

In todayโ€™s episode of Kotlin Standard Library Safari, weโ€™re learning all about advanced collection functionality!

Weโ€™ll see how the โ€˜anyโ€™, โ€˜noneโ€™, and โ€˜allโ€™ functions can be used to check conditions for elements in our collections, and ...

โ–ถ Play video
#

๐Ÿ˜Œ

cinder flare
#

nice

ocean quartz
winter iron
#
fun isOnCooldown(key: K) = cooldowns[key]?.let { System.currentTimeMillis() - it <= cooldown } ?: false
#

ok

#

let is now in my vocab

ocean quartz
winter iron
#

๐Ÿ˜ฆ

#

but even so

#

?: will be fine here

#

if it returns null then i wanna default to false

#

if not will it not just return whatever is returned by let?

ocean quartz
#

Yeah, i just think == true is more readable, though that's preference

winter iron
#

thats true

#

alrdy gets weird with let

#

lets not make it aids

#
cooldowns[key] ?: 0

cooldowns.getOrDefault(key, 0)
#

๐Ÿค”

#

i think default makes sense here

#

since i dont wanna deal with a null

ocean quartz
#

Get or default does exactly that

winter iron
#

ik but like if theres a method that alrdy deals with it

#

i just use it

ocean quartz
#

Not really, it's one less call

#

Similar to Enum#equals it just returns enum == other

#

So instead is better to just do enum == other instead of calling equals

winter iron
#

idek why im rly bothering with stupid shit like this

#

XD

#

i gotta sleep

#

but sleep is for the weak

winter iron
#

Alpha

cinder flare
winter iron
#

Struggles man

#

rly living life on the edge with CI

cinder flare
#

almost 13 hours ๐Ÿ™ƒ

prisma wave
#

Why use CI when you could use discord pinned messages

cinder flare
#

cause I don't have a discord

#

i'm not that cool

prisma wave
#

We've got the discord database, and now the discord CI service

#

Full stack discord

cinder flare
#

people barely want to talk to me here, I doubt they'd join a specific discord just for me ๐Ÿฅฒ

prisma wave
#

oof

ocean quartz
#

Me too โ˜บ๏ธ

cinder flare
#

awee

forest pecan
#

If you think about it

#

Dkim den tho

#

Lol

#

People joined dkimโ€™s server ๐Ÿ˜Œ

obtuse gale
#

@cinder flare โค๏ธ

cinder flare
#

๐Ÿ˜Š

ocean quartz
#

Star you're the only one not in my server sadge

cinder flare
#

you have a server?

#

since when

ocean quartz
#

Since like 2019 or 18 don't remember lmao

cinder flare
#

well send me an inv bro

half harness
winter iron
#

If anyone has any ideas for things I can add to my library lmk pls

#

๐Ÿ™‚

obtuse gale
#

Now Matt is not in my server

#

pensive

ocean quartz
#

You have one? ๐Ÿ˜ฎ

#

Sned sned sned

obtuse gale
#

Not like there's any activity anyway ๐Ÿคฃ

ocean quartz
#

We can make it active ๐Ÿ‘€

obtuse gale
#

Ah yes

#

Abandon HelpChat

#

actually leaves HelpChat

frail glade
#

๐Ÿ˜

obtuse gale
#

Hi glare

#

Anyway, cooking time owo

forest pecan
#

Mr

#

Glare

#

how is your day

half harness
#

ah yes, you love when you press the stop button on a server that I'm developing for and the server console doesn't work either (not using vps), so it decides to kill itself ๐Ÿฅฒ

#

no idea why the stop command kills the server instead

#

might be hooked up to some other command causing the unknown command error

#

lol

quaint isle
#

@all plugin devs: Are there any epic methods to promote Spigot plugins? I recently published my first. So far I've only shared it on spigotmc and polymart. How do I get the ball rolling?

old wyvern
#

wait.

obtuse gale
#

idk tbh

#

yeah waiting and publishing updates is the best you can do lol

ocean quartz
#

Small updates pushes your plugin up the recent list

obtuse gale
#

yeah updating is pretty important because of that

#

i made a plugin, published it on spigotmc, kept it up to date for some time very frequently and it got like uh idk how many few thousand downloads lmao

#

i don't regret it

#

but

#

๐Ÿฅฒ

old wyvern
#

lol

quaint isle
#

I suppose keeping an eye on r/admincraft and spigot forums won't hurt either, maybe I can suggest the plugin every now and then

#

I already published two updates (~3 days apart), guess I keep doing that for a while until I got a smol userbase.

#

Is it worth putting some SEO effort in the spigot description in order to get some organic traffic in from Google?

old wyvern
#

Um, is it me or does IntelliJ's embedded scene builder not render css updates?

obtuse gale
#

wow the one single time I'm using kotlin

#

it lets me down

#

this is extremely disappointing

cinder flare
#

wdym

obtuse gale
#

if you ever worked with regex patterns and match results etc, you'll know that you can make "groups", kinda like "sections" you can get out of the match result

#

so for instance \\d(\\w) will match any single digit + any single alphanumeric character, the () is grouping the match inside of it so I can "extract" it, result.group(1) (0 is the entire match, 1 first group, 2 second group, etc)

cinder flare
#

so kotlin and java don't have a way to get the groups?

obtuse gale
#

yeah yeah they do

#

but

#

I was expecting something like match[1] to get the first group

#

kinda like how you access a map or a list

#

but nooooo

#

i need to add that myself

cinder flare
#

huh

#

make a youtrack suggestion to kotlin

#

sure that'd be easy to implement

old wyvern
#

Doesnt that already work?

old wyvern
obtuse gale
#

kt

old wyvern
#
val res = "\\d(\\w)".toRegex().find("1w")?.groupValues ?: return
println(res[1])

This seems to work

obtuse gale
#

eeee not exactly what I want

old wyvern
#

oh rip

obtuse gale
#

because that's a list if i'm not mistaken

old wyvern
#

yea

cinder flare
#

i mean what else would it be

obtuse gale
#

!!!

ocean quartz
#

operator fun Matcher.get(index: Int): String = group(index)

obtuse gale
#

I love you

cinder flare
#

wait were you not doing that already emilyy?

obtuse gale
#

?

cinder flare
#

i thought you wrote your own impl thingy

obtuse gale
#

yes but it was erm not tidy

#

kt is not my main after all

cinder flare
#

lol

#

i want kt to be my main

#

i'm heavily considering migrating portions of plugins to it

old wyvern
#

I think you mean hs ๐Ÿ˜Œ

cinder flare
#

do you need to shade the kotlin runtime or something? i swear Glare does that with Guilds

old wyvern
#

you need to shade the kotlin std-lib

#

yes

cinder flare
#

how big that be

old wyvern
#

1mb-ish

cinder flare
#

hmmmmmmmmmmmmmm

#

is that in maven central

old wyvern
#

Yup

cinder flare
#

oh snap so I can use bungee library functionality!!!!

old wyvern
#

mhm

#

its not just bungee

cinder flare
#

man this kotlin thing is getting better and better

old wyvern
#

its on spigot as well

cinder flare
#

paper too?

onyx loom
#

๐Ÿ˜ญ

old wyvern
#

yes, paper has everything spigot does

cinder flare
#

until the hard fork >:)

old wyvern
#

Probably wont change things instantly

#

They would end up with too many broken plugins

#

What would be the best way to setup a layout like this?

cinder flare
#

they should definitely like get a bunch of people to sign on and like prepare their plugin for paper only compatability

#

uh definitely a grid setup with like bootstrap

#

css also has its own but it's a lot less good

old wyvern
#

Its javafx star

cinder flare
#

oh

#

i thought that was a poorly-designed web app lol

old wyvern
#

I tried with stackpanes and ended up with this shit

cinder flare
#

javafx has a grid system

old wyvern
#

Yes, but I probably shouldnt have have multiple inner ones

old wyvern
cinder flare
#

well surely that could all be in one grid, just have the top row be like 7 - 5, second row be 4 - 4 - 4, bottom be like 4 - 8

old wyvern
old wyvern
cinder flare
#

oh god

#

javafx why

old wyvern
cinder flare
#

they really don't go next to eachother? that is so weird

#

well you just extend the height of the row

old wyvern
#

wdym?

cinder flare
#

like they should always be that width, but if there's like a whole paragraph in there just wrap it and make it taller

old wyvern
#

But then you lose responsiveness

#

the applet is resizeable

cinder flare
#

i dunno man, websites do it all the time

#

and it's very responsive or somethin

old wyvern
#

You meant a fixed width right?

cinder flare
#

well like, it changes based on percent right

old wyvern
#

Thats how its set rn

cinder flare
#

so you have the overall grid that takes like 80% of the screen

#

then the boxes inside all have a number or percent, bootstrap does 12

#

so then if you make it smaller it makes the middle bits smaller and eventually stacks them

old wyvern
#

Im doing 6x6

#

Thats what I already have star

cinder flare
#

well it's weird that it doesn't work how I'd think it should

old wyvern
#

The problem is the table-cell like area

ocean quartz
# obtuse gale I love you

A fun thing, wouldn't apply to this case but pretty useful

val regex = "(?<example>\\d+).(?<second>\\d+)".toRegex()
val (example, second) = regex.matchEntire("5.5")?.destructured ?: return
example.toInt() // now 5 as int
second.toInt() // now 5 as int as well
obtuse gale
#

gasm

#

lovely

cinder flare
obtuse gale
#

๐Ÿ…ฑ๏ธerhaps

cinder flare
#

hmmm

cinder flare
#

wow that's a lot of links

ocean quartz
#

Ahh the wonders of supporting

obtuse gale
#

lmao

#

not failure, i omitted them

cinder flare
#

remember that one time I needed that in CoC

old wyvern
old wyvern
cinder flare
#

what's wrong with it?

old wyvern
#

It wasnt working for like 2 weeks atleast last time I played

cinder flare
#

oh dang what

old wyvern
#

It works in the editor, but all testcases fail fast on submission

#

There were a few reports on the discord, but not sure if its fixed yet

half harness
obtuse gale
#

no, the super long screenshots are on the phone

#

because i have a really long phone

ocean quartz
#

Emily's phone

obtuse gale
#

mhm

half harness
#

do you have some program that lets you screenshot like that

#

how in the world do you do it

cinder flare
#

sharex?

half harness
#

no i mean the phone

obtuse gale
#

??

#

i'm telling you i have a really long phone

cinder flare
#

take a screenshot with the power and volume button, then crop it?

half harness
#

by zooming out on discord mobile?

obtuse gale
#

wat

half harness
#

wat

#

jiukmndwas

#

idk

#

๐Ÿ˜ฉ

cinder flare
#

did you guys know IJ did that

#

that is so nice

forest pecan
#

Tbh I never really pay too close attention to those boxes things lmao

#

Only used it for argument checking

cinder flare
#

yea they are also on the wrong bracket

#

but cool nonetheless!

obtuse gale
#

i have them disabled lmao

ocean quartz
#

I find them quite useful

obtuse gale
#

i find them cluttering tbh

#

not necessarily useless but i'm like "yeah okay but i know what i'm writing and what is what, can you stop filling up precious space for my code?"

cinder flare
#

hey @frail glade do you perchance have the source code for InventoryFull

frail glade
#

I listed what I had yesterday ๐Ÿ‘€

cinder flare
#

sheeee

#

i didn't know if you didn't mention it because literally nobody has ever heard of it

frail glade
#

No I read from GitHub what I had ๐Ÿ˜”

cinder flare
#

dang dang

#

well it's MIT apparently

#

so I might be reverse engineering this bad boy lmao

quiet depot
#

what is inventoryfull

cinder flare
#

i also wondered that lol

quiet depot
#

cube has it

cinder flare
#

๐Ÿ˜ฎ

#

can I have it?

quiet depot
#

idk

cinder flare
#

it's MIT ๐Ÿ™‚

quiet depot
#

@pallid gale can u look in clip's eclipse archives for inventoryfull source

cinder flare
#

oh god is that what the .project file is

frail glade
#

Damn even I don't have access that that.

cinder flare
#

don't worry guys I got it

frail glade
#

He does keep a usb with all his projects on it on his keychain

cinder flare
#

ah so all I need to do is mug him?

#

nice

frail glade
#

๐Ÿ˜‚

quiet depot
cinder flare
#

yooooo

#

time to fix this plugin bois

quiet depot
#

definitely not just decompiled

#

definitely the original

cinder flare
#

๐Ÿ‘€

frail glade
#

Procyon to the rescue

quiet depot
#

fuck no

#

cfr is the best decompiler for general purpose change my mind

cinder flare
#

uh the only one I've heard of is FernFlower so

#

that's my choice

old wyvern
#

ghc is the best compiler for general purpose change my mind

#

๐Ÿ˜Œ

cinder flare
#

i dunno dude LLVM kinda slaps

#

someone should make a haskell -> llvm boi

cinder flare
#

ew what you can generate C

frail glade
#

Paste the decompile command you won't

#

That's what I thought

old wyvern
#

๐Ÿฅฒ

quiet depot
#

java -jar cfr.jar if.jar --outputdir if

frail glade
#

Good work

cinder flare
#

wow look at this guy

old wyvern
#

2 mins command generation time, slow pig

frail glade
#

I can unfortunately do the same for ASM code

quiet depot
#

i like to use procyon where cfr miserably fails

#

but last time I checked, you really can't use procyon on an entire project

frail glade
#

FishSlapper says otherwise

old wyvern
quiet depot
#

I tried to use procyon for a commission once and the code it generated from the bytecode was just plain wrong

#

semantics were different

#

it's fine for quickly looking at shit

#

but I wouldn't use it to decompile a project to work on

old wyvern
#

I got GangsPlus working with that

frail glade
#

If all of your plugin's code isn't from Google, you're doing it wrong.

old wyvern
#

๐Ÿ˜Œ

quiet depot
#

for some reason

old wyvern
#

ah

obtuse gale
#

FernFlower apparently derps when you have ternary inside constructors lol

quiet depot
#

they all have flaws

obtuse gale
#

does this thing which is correct by spec but i mean lmao

quiet depot
#

from my experience I've found cfr & procyon to be the best mix

old wyvern
#

how do you mean mix?

quiet depot
#

you use cfr for the base project

#

then anything cfr fails on, or doesn't look quite right

#

you use procyon on

old wyvern
#

hmm

frail glade
#

Alrighty. I'll see y'all on the flip side. ๐Ÿ˜ด

old wyvern
#

gn

quiet depot
#

cya

cinder flare
#

keep up the great work Glare my boy

old wyvern
#

Ohhh Mee6 bot is a rick and morty reference

rotund egret
#

Whew

obtuse gale
#

this is amazing, the vanilla game actually does load chunks in another thread other than main

#

and .join()s the future immediately after

cinder flare
#

surely it would be trivial, then, for spigot to utilize that and not lock it to the main thread?

quiet depot
#

pls supply star with src

cinder flare
#

yeyeye

#

bro what the actual fuck

obtuse gale
#

hahaha

cinder flare
#

yo uh, what do I want

#

i've literally never seen this before lmao

obtuse gale
#

? what's that lol

cinder flare
#

gradle init

obtuse gale
#

ah?

cinder flare
#

apparently these are the types

obtuse gale
#

i have only used it for migrating from maven lmao

cinder flare
#

but I'm not sure what the connotation actually means

#

me too

old wyvern
#

go for basic

cinder flare
#

okay sick ty

cinder flare
#

kill me

old wyvern
#

Jesus

cinder flare
#

finna make this a config file real soon

rotund egret
#

Sometimes a static import is okay

cinder flare
#

hahaha

#

i just keep repeating "Minimum Viable Product" to myself

rotund egret
#

MVP!

cinder flare
#

Material.LEAVES, Material.LEAVES_2, ah the good old days, when there was only 2 leaves

obtuse gale
#

lmao

#

what's the criteria

old wyvern
#

What was leaves_2?

cinder flare
#

Material.RED_ROSE, Material.YELLOW_FLOWER,

old wyvern
#

acasia?

obtuse gale
#

ROSES

cinder flare
#

and two flowers!

rotund egret
obtuse gale
#

!!!!

old wyvern
#

oh

#

lol

cinder flare
rotund egret
old wyvern
#

uhh

#

Did the vcs menu change to directly git for anyone else?

obtuse gale
#

yeah long ago

old wyvern
#

weird

cinder flare
#

I think it changes if your project is a git project

#

cause I'm working in a non-initialized project rn and it's still VCS

obtuse gale
#

oh probably

cinder flare
#

but in my other project it says Git

old wyvern
#

It was still vcs for me like yesterday

#

weird

cinder flare
#

yo wtf, my boy clip swapped to allman for a single file in this project

#

how peculiar

rotund egret
#

We're gonna need to you un remember that

cinder flare
#

well it's been erased so

rotund egret
#

All is well

obtuse gale
#

i hate type erasure

cinder flare
#

what's the ETA on project valhalla huh

obtuse gale
#

soontm

cinder flare
#

well soonโ„ข๏ธ your sadness will be alleviated

rotund egret
#

Just make assumptions about what the type is at runtime

#
    fun function(response: List<*>): List<String> {
        @Suppress("UNCHECKED_CAST")
        response as List<String>
        
        return response
    }```
cinder flare
#

mm the ol' void pointer strat

cinder flare
#
for (entry in gson.fromJson<Any>(content.toString(), object : TypeToken<Set<Map<String, Any>>>() {}.type) as Set<Map<String, Any>>) {```
#

okay um

#

there must be a better way to do this in Kotlin

#

I also only kind of understand what's happening

#

is that basically converting the json into a Set of Maps of String and Any?

quiet depot
#

u using guice in that project?

cinder flare
#

not yet

quiet depot
#

well

#

when you do

#

Types.setOf(Types.mapOf(String.class, Any.class))

#

alternative to typetoken

cinder flare
#

That's a guice function?

quiet depot
#

if ur not a fan

#

yes

cinder flare
#

well yeah but like earlier I just bound it to a cute little data class

#

is there no way to like, do the same thing with Sets and Maps?

old wyvern
cinder flare
#

val profile = gson.fromJson(content.toString(), MojangUUIDProfile::class.java) look at that!

cinder flare
old wyvern
#

Or wait no

#

Actually

cinder flare
#

it converts it to a set of maps

old wyvern
#

I think you were right

cinder flare
#

and iterates over that set

old wyvern
#

Yes

cinder flare
#

but is there no cute :: way of writing that?

old wyvern
#

I can barely read that on a phone

#

๐Ÿ˜‚

cinder flare
#

i can barely read that on pc

old wyvern
#

lol

#

Can you put that in a paste or something?

cinder flare
quiet depot
#

no star because class instances don't hold runtime type parameters

cinder flare
#

ah stupid java

#

can I make a data class that can do that or something lol

quiet depot
#

yes

cinder flare
#

๐Ÿ˜ฎ

old wyvern
#

The type token is a nice hack to overcome type erasure

cinder flare
#

it's really ugly though

quiet depot
#

yes but you have to explicitly cast it anyway

#

kotlin is ugly*

cinder flare
#

maybe I'll just get guice and do that piggy thing

#

wtf do you mean

#

this looked 10x worse in java

quiet depot
#

doubt

cinder flare
#

what

#

do you even mean

#

are you saying you're a fan of this

#
} finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }```
#

instead of java } finally { reader?.close() }

quiet depot
#

no, that's not how you close a reader

#

have you never heard of try with resources

cinder flare
#

can't

#

have more resources

quiet depot
#

what

cinder flare
#
        var reader: BufferedReader? = null
        return try {
            val mojangURL = URL("https://api.mojang.com/user/profiles/${Core.getUUID(pName)}/names")
            val conn = mojangURL.openConnection()
            reader = BufferedReader(InputStreamReader(conn.getInputStream()))```
quiet depot
#

you can put multiple autocloseables in a try with resources

cinder flare
#

I'll auto close you

old wyvern
#

Umm star

#

I dont think you need that cast

quiet depot
#

the cast is necessary

old wyvern
#

Cant the type in the parameter be that?

quiet depot
#

no, because he calls .type which returns a java Type

cinder flare
#

you have to realize I did not write this code

#

is there a kotlin json library or somethin that will pretty this up for me

old wyvern
#

Wait, let me get on pc, 10 mins

quiet depot
#

probably

#

is this for a plugin?

#

if not look at moshi instead of gson

old wyvern
#

Gson and kotlin dont go particularly well anyway

quiet depot
#

apparently we're meant to use moshi

#

not gson

#

Lists.newArrayList()

#

aren't you meant to use mutableListOf()

cinder flare
cinder flare
obtuse gale
cinder flare
#

shush

#

I literally just converted this code seconds ago

obtuse gale
#

You converted horrible java to horrible kt

cinder flare
#

yes and I am repairing it

rotund egret
#

Homie just tryna make progress and everyone jumping down they throat about "it bad"

#

smh

obtuse gale
#

Well yeah

rotund egret
obtuse gale
#

Because it ia

#

Is*

rotund egret
#

Pats for you star

cinder flare
#

๐Ÿ˜Š

#

I freaking updated one of clip

#

's random plugins just for fun for one guy

obtuse gale
#

sounds boring

cinder flare
#

it was kinda fun actually

#

gives me purpose, writing code that I know someone actually wants

obtuse gale
#

idk its just imo, for me working with or off other peoples stuff is annoying

#

id rather just make it

rotund egret
#

git gud

obtuse gale
#

and this is really only for spigot shit lol

#

other things im fine with

rotund egret
#

How to say I don't know what I'm doing without saying it

obtuse gale
#

?

cinder flare
#

hmmm I'd rather work on something that already exists and mold it than make something fresh

#

probably because I don't have enough experience yet with plugins

old wyvern
cinder flare
#

man that's... not much better

obtuse gale
#

i just have a somewhat odd style and dont like a lot of stuff

cinder flare
#

I mean yeah I love the functional ๐Ÿ™‚

old wyvern
#

What else did you want?

obtuse gale
#

use kryo codecs gg

old wyvern
#

You had an unnecessary cast in there like I said

quiet depot
#

use guice type util

old wyvern
#

this is what I meant btw pig fromJson<Set<Map<String, Any>>>

#

instead of using Any and casting

old wyvern
cinder flare
#

I mean is there really no way to get around that horribleness

quiet depot
#

bruh

old wyvern
cinder flare
#

oh yea I forgot about Guice

#

lemme get that

#

content = reader.lines().reduce { acc, line -> "$acc\n$line" }.orElse(null) this line will slap em all together separated by newlines or if there's nothing there it'll be null right

jovial warren
#

there's a library called Kotlin Guice that adds these sorts of things to Guice

#

and I made my own extensions library for Gson that has these sorts of reified thingies

cinder flare
#

Kotlin Guice!

jovial warren
old wyvern
#

Wow, im impressed. They didnt name it Kuice!

jovial warren
#

lol

old wyvern
#

xD

cinder flare
#

damn that would've been a good name

obtuse gale
cinder flare
#

baby steps okay

#

I'm working on Scala

obtuse gale
#

Oo

cinder flare
#
        val conn = URL("https://api.mojang.com/user/profiles/${Core.getUUID(pName)}/names").openConnection()
        val reader = BufferedReader(InputStreamReader(conn.getInputStream()))
        val content: Optional<String>
        reader.use {
            content = reader.lines().reduce { acc, line -> "$acc\n$line" }
        }
        return gson.fromJson<Set<Map<String, Any>>>(
            content.get(),
            object : TypeToken<Set<Map<String, Any>>>() {}.type
        ).map { it["name"].toString() }```
#

how's that

#

a lot cleaner, eh?

obtuse gale
#

why arent you just memory caching this?

cinder flare
#

baby stpes

#

also how would that change anything

#

this function would still need to exist to get the stuff to cache in the first place

rotund egret
#

oh wait

obtuse gale
#

not true its just a uuid and a string lol

rotund egret
#

I have a lib for this you may find useful

cinder flare
#

what

rotund egret
cinder flare
#

I'd have to query mojang's servers for a namehistory still?

obtuse gale
#

sure if thats what you want

cinder flare
#

how else could it be done

obtuse gale
#

i thought this was only to get a uuid from a name

cinder flare
#

no

#

fun getPlayerNameHistory(pName: String): List<String> {

obtuse gale
#

yea i guess tahts the move then

cinder flare
#

wait URLConnection doesn't have a use function?

#

does it not implement AutoCloseable?

#

I really need me a Kotlin http library

rotund egret
#

๐Ÿ‘€

#

Star please.

cinder flare
#

?

#

your retrofit thing is for Java

#

I need a Kotlin-centric one

rotund egret
#

Dude I am gonna flip you

#

holy heck

cinder flare
#

?

obtuse gale
#

For the love of god

rotund egret
#

You can use java libs in kotlin, lib works fine in kotlin

cinder flare
#

I thought that was a thing

#

well yeah I know Zodd

#

but then I end up doing some stupid syntax shit like this

rotund egret
obtuse gale
#

btw kotlin has nullable types

distant sun
cinder flare
#

well yea

obtuse gale
#

val content: String?

cinder flare
#

but isn't Optionals the functional way

obtuse gale
#

youre in kotlin

#

no need

cinder flare
#

hmmm okay

distant sun
#

Elvis everywhere

cinder flare
#
    fun getPlayerNameHistory(pName: String): List<String> {
        if (!ProxyServer.getInstance().config.isOnlineMode) {
            throw RuntimeException("Can't get player name history from an offline server!")
        }

        // Fetch player's name history from Mojang servers
        val url = URL("https://api.mojang.com/user/profiles/${Core.getUUID(pName)}/names")
        with (url.openConnection() as HttpURLConnection) {
            val content: String
            inputStream.bufferedReader().use {
                content = it.lines().reduce { acc, line -> "$acc\n$line" }.get()
            }
            return gson.fromJson<Set<Map<String, Any>>>(
                content,
                object : TypeToken<Set<Map<String, Any>>>() {}.type
            ).map { it["name"].toString() }
        }
    }```
#

okay how's that

potent nest
#

well that'll throw an exception if lines() returns an empty stream

cinder flare
#

well how do I not do that

potent nest
#

also there's .collect(Collectors.joining("\n"))

distant sun
#

Thats not java

#

Cant use joinToString("\n") @cinder flare ?

cinder flare
#

uh, doesn't seem so

potent nest
#

that's java api

cinder flare
#

please keep in mind I am doing all this functional stuff for the first time in Kotlin ๐Ÿ™‚

distant sun
#

Doesnt lines() return a collection?

cinder flare
#

returns a Stream

distant sun
#

Ah

cinder flare
#
    fun getPlayerNameHistory(pName: String): List<String> {
        if (!ProxyServer.getInstance().config.isOnlineMode) {
            throw RuntimeException("Can't get player name history from an offline server!")
        }

        // Fetch player's name history from Mojang servers
        val url = URL("https://api.mojang.com/user/profiles/${Core.getUUID(pName)}/names")
        with (url.openConnection() as HttpURLConnection) {
            inputStream.bufferedReader().use { response ->
                return gson.fromJson<Set<Map<String, Any>>>(
                    response.lines().reduce { acc, line -> "$acc\n$line" }.get(),
                    object : TypeToken<Set<Map<String, Any>>>() {}.type
                ).map { it["name"].toString() }
            }
        }
    }```
#

okay how bout that

quiet depot
#

still not using types util

cinder flare
#

also will that return an empty list if it doesn't succeed in any of those

#

yeah gettin there

quiet depot
#

gson has a type util too

#

itโ€™s just internal lmao

cinder flare
#

it do?

#

bruh

distant sun
#

The one with $$?

quiet depot
#

ye

distant sun
#

bs

cinder flare
#

hey will that return an empty list or whatever it succeeds with?

#

cause I don't have another return...

distant sun
#

Most likely no

cinder flare
#

so why is it okay with me not having another return lol

distant sun
#

Kotlin doesnt force you to use try / catch

obtuse gale
#

for your type

cinder flare
#

wait why the fuck does this function throw a runtime exception

#

shouldn't it just like... return an empty list or something

old wyvern
#

Star, use reduce with the 2 args

#

Use an empty string as first arg

#

No need to use the optional version here

cinder flare
#

isn't that already reduce with the 2 args?

old wyvern
#

You're using the single argument one

#

Try

.reduce("") { ...}
cinder flare
#

uh

#

I still don't understand

old wyvern
#

What are you confused about?

cinder flare
#

how to change my function to the one you said

#

I have literally the slimmest idea of how these work

#

i just copied from the kotlin examples page

old wyvern
#

Just add that emoty string argument like I showed above

cinder flare
#

k and then

old wyvern
#

And then remove the get()

cinder flare
#

ahhh I see

old wyvern
#

Because this one returns T instead of Optional<T>

cinder flare
#

Oh that's nice!

#

ah cause it'll just return an empty string if it doesn't have anything in it

#

now that's smart

old wyvern
#

Not an equivalent for a default btw

#

Its just what the initial value of acc will be

#

The identity value for your operation

cinder flare
#

well yea but if there's no elements in it, it'll just return whatever I pass in first right?

old wyvern
#

Mhm

cinder flare
#

yeah okay so sounds like a default

#

can I test this in any way lol

old wyvern
#

This might still add an extra line to your output tbh

cinder flare
#

hmmm

#

how can I not do that

old wyvern
#

You could move the \n to the end of the string and trim at last

cinder flare
#

response.lines().reduce("") { acc, line -> "$acc$line\n" }.trim(),

#

like that?

old wyvern
#

Yea I guess so

#

That should produce the same output

#

Give it a try

cinder flare
#

well hmm

#

to try it I have to do a lot more lol

#

can I just execute this script by itself

#

how do those kotlin scripts work lo

old wyvern
#

I just test on kotlin playground normally

cinder flare
#

kotlin playground don't have the type shit

old wyvern
#

Oh right gson

cinder flare
#

well I guess let's trial by fire it

prisma wave
#

How come you're not using Collectors.joining

cinder flare
#

because it's a Stream

old wyvern
#

Collectors.joining is used in a stream

cinder flare
#

it is?

#

well how come I'm not using that then Yugi

old wyvern
#

Wait did you just want to join by newline?

cinder flare
#

lol

#

ya

potent nest
#

that's why I mentioned it before

prisma wave
#

๐Ÿ˜ตโ€๐Ÿ’ซ ๐Ÿ˜ตโ€๐Ÿ’ซ

old wyvern
#
Reader#lineSequence().join("\n")
prisma wave
#

joinToString*

old wyvern
#

^

cinder flare
#

response.lineSequence().joinToString("\n"),

#

that?

quiet depot
#

what r u tryna do

cinder flare
#

I'm not entirely sure tbh

quiet depot
#

pls no make me scroll up

cinder flare
#

get list of names from ol' mojang

#

name history

old wyvern
#

Is response a BufferedReader?

cinder flare
#

yes

prisma wave
#

doesn't kotlin also have reader.readAllText or something

old wyvern
#

Then ok

cinder flare
#

man see this is why I got the Genius Bar here

#

imagine what I'd be doing without you guys

quiet depot
#

writing bad code

cinder flare
#

i am fixing this code sir

#

none of this has been originally mine

obtuse gale
#

why did you switch it to kotlin?

cinder flare
#

cause I think its pretty and nicer than Java

obtuse gale
#

jw idc if youre doing it to learn, i do not recommend pasting java code in then converting tho cuz it makes it aids

cinder flare
#

well this entire plugin is in Java

#

and is moderately poorly written

#

so I figure converting it to Kotlin then fixing it up real nice file-by-file is a pretty good solution for all the small parts

#

then when it becomes more manageable, I plan on implementing Guice and other niceties project-wide

#

plus look at how much I'm learning about streams and stuff!

#

okay well guys it worked perfectly

#

thank you all for your support โค๏ธ

obtuse gale
#

gg, kotlin you dont have to use streams so often prolly unless you prefer them over kt sequeneces

cinder flare
#

are sequences the collection operations

#

cause I would like to use those a lot more, it's just that this is a Java stream boi

prisma wave
#

Nah sequences are a distinct thing

#

They're lazy rather than eager

#

Similar to streams

cinder flare
#

how would I go about using those

prisma wave
#

.asSequence()

obtuse gale
#

streams are pretty lazy as well tho yea

prisma wave
#

or sequenceOf()

cinder flare
#

so what about doing like .map and stuff on a Collection

#

bad?

prisma wave
#

Not particularly

#

Depends

#

If you have a big collection and / or lots of operations it might be worth converting to a sequence

cinder flare
#

okay I see

obtuse gale
#

love you bristy

prisma wave
#

Ily too

cinder flare
#

hey is RedisBungee like not a thing anymore

obtuse gale
#

ah just bridge it yourself

cinder flare
#

well this plugin had support for it like 5 years ago

#

so I'm just not touching it for a while lol

obtuse gale
#

lol jesus as long as it works

cinder flare
#

I am not sure if it works

#

I just am not touching it lol and the one person who wanted it does not use it so

#

we gucci

obtuse gale
cinder flare
#

woah what

obtuse gale
#

were just intimate like that

cinder flare
#

dang yeah apparently

#

so this is a weird request but... is there an easy way to take that gson that's been mapped to a Map<String, Any> and use its values in a pretty string?

#

okay that's a weird one nevermind

#

but what about

 val city = if (!(attributes["city"] as String?)!!.isEmpty()) attributes["city"] as String? else "unknown"```
#

terser?

old wyvern
#

What exactly do you want to do?

#

I didnt understand

#

safe cast?

cinder flare
#

if attributes["city"] is empty, put "Unknown"

#

otherwise put its value

old wyvern
#
(attributes["city"] as? String) ?: "Unknown"
cinder flare
#

hey wait

old wyvern
#

oh empty

cinder flare
#

this JSON will only be strings won't it

old wyvern
#

one moment

cinder flare
#

why do I have a map of String and Any

old wyvern
#

idk lol

obtuse gale
#

thats probably what the conversion did

cinder flare
#

it's trying its hardest

obtuse gale
#

yea sometimes its handy

cinder flare
#

val city = if (attributes["city"].isEmpty()) attributes["city"] else "unknown"

#

that but condensed

#

how do

obtuse gale
#

make val attribute = attributes["city"]

cinder flare
#

what

#

I mean is there not a terser way of saying "if this condition, return this, otherwise return myself"

obtuse gale
#

not really thats kotlins way

cinder flare
#

hmmm

old wyvern
cinder flare
#

YES

#

see Yugi you're the best

old wyvern
#

lol

cinder flare
#

There's a lot more querying of REST apis in this plugin than I thought there would be

#

this is the third time I've used that little Http script

old wyvern
#

retrofit?

cinder flare
#

what

old wyvern
#

for http requests

cinder flare
#

oh no the little thing we made earlier

#
        val url = URL("http://ip-api.com/json/$ip?fields=country,countryCode,city")
        with (url.openConnection() as HttpURLConnection) {
            inputStream.bufferedReader().use { response ->
                val attributes: Map<String, String> = gson.fromJson(
                    response.lineSequence().joinToString("\n"),
                    object : TypeToken<Map<String, String>>() {}.type
                )
                return """&7City: &f${attributes["city"]?.ifEmpty { "Unknown" }}&7
                    | Country: &f${attributes["country"]?.ifEmpty { "Unknown" }}&e
                    | (&f${attributes["countryCode"]?.ifEmpty { "Unknown" }}&e)""".trimMargin()
            }
        }```
old wyvern
cinder flare
#

I mean is it really worth it for the 3 times I used it?

old wyvern
#

๐Ÿคท

quiet depot
#

use java 11 http api

cinder flare
#

which would look like?

quiet depot
#

oof

cinder flare
#

pfft

quiet depot
#

u can check messages log

#

or docdex

#

class: DocumentationCommand

cinder flare
#

lmao even you're not exempt from the pron

quiet depot
#

guess not

old wyvern
#

pron?

quiet depot
#

hub

old wyvern
#

Did he actually mean porn?

cinder flare
#

yes but I did not want to be censored

quiet depot
#

wait

#

if thatโ€™s illegal

#

can i

old wyvern
#

lol

quiet depot
#

lame

cinder flare
#

rules are rules

#

until you go add an exception to Barry, that is

#

well hang on now

#

mr BodyHandlers, that doesn't map it to a cute data class for me

quiet depot
#

well

#

make ur own body handler

cinder flare
#

I'll body handle you

obtuse gale
#

woah woah

#

keep it pg13

cinder flare
#

okay so there actually is a cute little BodyHandler maker

#

but my brain is much too small to understand the type declaration or how I could map it myself

#

so that's a function that takes a ResponseInfo! and returns a BodySubscriber of some type?

quiet depot
#

@cinder flare donโ€™t even bother

#

just map the string

cinder flare
#
    fun getUUID(pName: String): String {
        val request = HttpRequest.newBuilder()
            .uri(URI("https://api.mojang.com/users/profiles/minecraft/$pName")).build()
        val response = httpClient.send(request, BodyHandlers.ofString()).body()
        return gson.fromJson(response, MojangUUIDProfile::class.java).id
    }```
#

this is the final formm

quiet depot
#

ohh that is just cuz i use an optional

#

idk

#

๐Ÿ‘

cinder flare
#

good shout tho

quiet depot
#

looks like shit but iโ€™m on phone

cinder flare
#

a lot clearer than the old one

#

damn it's 5 am how did this happen

sly sonnet
#

Didn't you have to use {$pName}?

cinder flare
#

no?

#

you would only use ${pName.id} or something

old wyvern
#

${} format is only when using accessors

#

yea

#

anything more than just variables

sly sonnet
#

Ah, now I see

cinder flare
#
                val isEnabled = when (module) {
                    is BanConfig -> module.config.get(BanConfig.ENABLED)
                    is MuteConfig -> module.config.get(MuteConfig.ENABLED)
                    is CommentConfig -> module.config.get(CommentConfig.ENABLED)
                    is KickConfig -> module.config.get(KickConfig.ENABLED)
                    else -> false
                }```
#

damn is that beautiful or what

#

this could be Java some day

#

like, around september actually

old wyvern
#

Any reason module itself doesnt just expose a isEnabled method?

cinder flare
#

uhhh

#

cause I'm silly and just stapled on MF-CFG

#

the old cfg framework used inheritance, so it was just a single method to get any of the enabled states

#

but that is an excellent suggestion sir

prisma wave
#

Irrespective of language

cinder flare
#

you... don't like pattern matching switches?

prisma wave
#

That definitely breaks some principle / guideline

#

No you should be doing what yugi said

cinder flare
#

well yea

#

this is quick fix time okay

#

it's literally 6 am almost

old wyvern
#

Kotlin bad?

cinder flare
#

sleep time

#

good night and thank you all for your help โค๏ธ

old wyvern
#

gn

prisma wave
#

bonne nuit

#

Yugi

old wyvern
#

yea?

prisma wave
#

Do you know of a nice way of handling errors in haskell

#

MonadFail isn't really what I want

old wyvern
#

Either

prisma wave
#

Maybe just an Either

#

Hmm

old wyvern
#

I think thats what libraries commonly use atleast

prisma wave
#

what if there could be multiple errors?

steel heart
#

I think I started to understand what a monad is

prisma wave
#

nice

#

basically i am writing a math parser but obviously there will be certain things that don't work (dividing by 0, referencing variables that aren't bound, etc)

old wyvern
#

Hmm

prisma wave
#
class Evaluate t where
  evaluate :: Context -> t -> Either Double String
``` have done something like this so far
#

not sure if that's the best option though

#

and then we can implement it with something like this: ```hs
instance Evaluate Expression where
evaluate context (VariableExpression name) = variables context M.!? name

steel heart
#

Is Stream#flatMap a monad or no?

prisma wave
#

Stream is

old wyvern
#

try something like this maybe

data ParseException = DivisionByZero | UnboundVariableAccess | ...

class Evaluate t where
  evaluate :: Context -> t -> Either Double ParseException 
steel heart
#

Oh pog

prisma wave
#

ooh that is a good idea

old wyvern
prisma wave
#

you need a function a -> m a for it to be a monad though

#

which is Stream.of

steel heart
old wyvern
#

mhm

prisma wave
#

hmm

steel heart
#

mmh

prisma wave
#

now how to get nice error messages that show where the error occurred

#

i guess just have ParseException take a String too

#

and worry about that later

#

ooh i wonder if i can just store the Expression that caused the error

steel heart
#

What language do u write it in?

#

Oh nvm I think I already know now

prisma wave
#

lol