#dev-general
1 messages ยท Page 84 of 1
why is it caps
lol frosty
I've legit got 0 braincells to cope with this rn
Been doing school shit for like 5 hours already
i think i've got it
@topaz bay hey you can't call me weird anymore because I started writing in Kotlin now lol
no idea what the fuck I was on about before but Kotlin >>>>>>>>>>>>>>> Java any day
nah KM
๐
kotlin good @hot hull
@jovial warren I dont know who you are
@hot hull did u know kotlin good
But good job
It's simple, just didn't click in my head at first
Very proud of you
@topaz bay you can't remember the guy who said Java + Lombok is better than Kotlin? lol
Absolutely not.
fair enough xD
well once I found out that Kotlin compiles in to JS as well that definitely steered me toward it
how come lol
because I want to write a plugin with a built-in web interface
and knowing I don't even have to touch JS lol
you know how litebans has the php bans page?
my friend told me I could put is it ktor? embedded in to the plugin
so you don't even need to install a web server with php
yeah Ktor is pretty nice
I'm not sure yet though if I should also provide some sort of php-based web interface as well
or I should just add the stylesheet as an optional dependency in like the plugin's data folder or something
spring
spring?
big rip, my next year course at school focusses on php
heard of it before, got no idea what it is or how it works
yeah php is a weird language
I don't really think JS is that much better though
as a language
js is probably a better option than php though, since it's more responsive
@lunar cypress i just realised after I submitted that I could've removed all my imports ๐ญ
possibly
my actual functionality is 2 lines
val N = readLine()?.toIntOrNull() ?: return
for(i in 1..N step 2) println(i)```
skript always wins
I don't know whether I could agree with that @lunar cypress
Kotlin wins since it compiles to Java and JS
..what?
oh yeah python still wins
so you only need one codebase
@jovial warren we are talking about something else lol
trying to get the smallest code possible to print odd numbers
yeah lol
yeah python usually wins things like that
poor guy using Java
This is my code ```clj
(run! println (filter odd? (range (inc (read)))))
But I need to specify an entry point and a namespace unfortunately
Java usually comes last in tests like that
๐ญ
Kotlin comes somewhere in the middle I think
that is correct
it's usually the language with the most boilerplate comes last and the language with the least boilerplate comes first
nice
rip
thing is though Java wasn't built for compactness, it was built on it's WORA policy
probably why it's got so much boilerplate
that.... isnt true
but Java was heavily built around that policy
yeah not an excuse for so much verbosity
Probaby has more to do so with that Java is built for readability
sounds about right
possibly
hey guys
yo
who wants to do a code review
sure
go on then
}
catch (e: KotlinNullPointerException) {
Don't catch NullPointerException
๐
don't catch any RuntimeExceptions
aw
most of the time using !! is a bad idea
yeah don't catch null pointers
You need to add a lie checker
it was recommended by IJ
IJ is dumb
unless you have VERY good reason you should never use !!
it doesn't solve any problems, it just defers them
IntelliJ sometimes tells you to do smart things and sometimes tells you to do stupid things
I would null check number, if it's null, send a message and return
clash of code don't kick me challenge 2020
lol
Just do return null!! easy
@onyx loom you could also do something like kotlin var number = calc() while(number == null) { println("Invalid Input") number = calc() }
ew
what does !! do again? sorry I'm still kinda new to Kotlin lol
Asserts not null
ah okay
hmm i was thinking of looping it at first
basically throws an NPE if it's null
We should call it the Java operator
They're unavoidable
ever since I started using Kotlin though I haven't seen a NPE in ages
share code @prisma wave
You can't null check everything
Certainly you could
Java is very discrete with NPE's sometimes though
I remember the days of sitting there on debug mode just looking for them
is there a way to save a default folder (stored in the plugin) ?
cant relate
yeah when your command just runs but doesn't do anything
then you gotta run it in debug mode to find out it's a NPE
happened to me all the time
is there a way to save a default folder (stored in the plugin) ?
saveDefaultConfig()?
you can't save folders from what I remember
you can only save files
then other than saveDefaultConfig() ?
You can save folders, but not through the spigot api
and for things other than the config use saveResource()
thx ๐
I did it in voteparty
these are pretty fun @lunar cypress
yeah they are
if I can't do a full folder it's not a problem it's like a config file and a custom file
Use it to save the language files
is it glaze? something like that, his one is premium
and it doesn't have any DB support
It will
they working on it?
they?
can I use saveRessource() in an expansion ?
this one was a joke @prisma wave
it was really easy
@topaz bay is that vote party plugin you sent a link to gonna have database support?
ah okay
so it's yours and darbyjack's
wait that's open-source?
All of Glare's plugins are
they're premium and open-source?
Freemium yes
yes
Yeah
You're paying for support
ah okay
which is very good imo
Agree
Everyone should do that
^
hulp me pls :c
does he have his own spigot page?
@hot hull ๐ 
because clip's page for it doesn't mention anything about source code
that's the one I'm on
actually yeah it's not on clip's page
sorry the art being the same confused me
same guy who makes clip's art
no mention of source code on that page though
is there a way to use saveRessource() in an expansion as long as it's not extended from JavaPlugin ? :c
you can't use saveResource() outside of JavaPlugin or an extension of it
you'd have to use a built-in method
Files.copy
actually you could either have the main as a singleton or pass an instance of the main to the subclass using the constructor
It'd save in the extension's plugin's folder if you did it with it's instance
can you show me an example pls ? I don't really understand ^^'
@lunar cypress anymore?
yeah, our mate is still lost lmfao
oh yeah lmao
poor guy
@brave minnow you'll probably need to read from ClassLoader#getResource and copy to your file. Have a look how saveResource does it
i am pretty sure there's a method somewhere in Files for this
It gets resource as inputstream i think
@topaz bay why are some parts of VoteParty still in Java?
even though most of it's in Kotlin
we ended his suffering
Imma join that on my phone
also for DB support I'd recommend just removing raw text file support completely and setting h2 as the default flat file driver, then maybe for people with the old versions you could have it migrate to h2 on startup if the old raw text file still exists or something @topaz bay
Then take like 30 minutes to type it xD
isn't getRessource good for it ?
getResource won't work in an extension misunderstood, use getResourceAsStream
WHAT
HOW
i was pretty proud of my 1 line factorial function
by 2 seconds lol
how do I ask glare?
?
what's his username?
hes literally in this server?
using java is just shooting yourself in the foot here lol
what was your solution bm?
yeah pretty much lol
@topaz bay couldn't recognise his username lol
wat
he's got dm's from server members turned off, don't really blame him to be fair lol
The waffle king
yep
I mean I could always fork the plugin, make my changes, then submit a merge request
probably best to talk to him about my proposed changes though
@frail glade I heard you were planning on adding database support for VoteParty, thought I'd propose a plan. I think you should just use relational databases and scrap raw text files completely, preferably using H2 as the default driver, then possibly adding in a migration system for the old raw text file system to H2, since there isn't really a reason to support raw text files once you support H2 anyway.
lol
how do i fix this ๐
needed a notnull int and got a nullable int
hmm k
https://paste.helpch.at/urajiqusek.cs i took ur advice with the code review but idk if im doing it right haha
im in the dark here so ignore me
number is of type Int
it's inferred
toIntOrNull() returns a nullable integer, or Int?
when u said number = calc(), it was throwing a different error, so i put it to number = 0
try val number: Int? = 0
that will tell kotlin explicitly that you want a nullable integer
also I'd suggest just parsing number as a parameter to calc()
either that or change it to var
then it can be ig
Realistically number shouldn't be a global variable
1 method should parse the user input and return it, another method should check the input
ill get there eventually haha
eg kotlin fun main() { val age = readIntFromInput() validateAge(age) } something like that
also, repeated code
just put the println("You are $number years old.") outside of the if statement
I probabaly won't add database anytime soon. It's not a priority.@jovial warren
Glare should probably answer the guy in #general-plugins if you haven't already
thats how i had it at first, idk why i repeated it actually
@frail glade alright, I could just fork it and implement it myself then submit a merge request I guess
If you want to
you've got a bit of spaghetti logic going on here @onyx loom . you go from main() to calc() and then back to main() over and over. You should have 1 function that loops until they put in a valid int, and then return that int
I don't plan to rid flatifle support tho
H2 is flatfile
Idc, I like json
alright
You're welcome to offer a MySQL implmentation.
this is why OSS good
OSS?
Ikr. I can go back to bed now.
https://img.bristermitten.me/14.07.18-2020.png @lunar cypress ๐ณ
get that out of here right now
What the fuck lmao
ye i will do that when i get parameter passing, but for now spaghetti good.
@prisma wave ^
spaghetti bad
๐
๐ฆ
strange
@prisma wave what should be the input stream to get the file in the plugin ?
ClassLoader#getResourceAsStream
kay :p
or just Class#getResourceAsStream
so eg getClass().getResourceAsStream("config.yml")
that one might not work tho
why ? ๐ค
because papi & spigot both do some weird classloader stuff that can cause problems
Class#getResourceAsStream has never worked in my experience but you can try
@lunar cypress any more?
missed the last one, currently waiting
ok, most of the others left
so that's it for now
if enough people from this server participate, we can also do that some time
Lmao
repositories {
jcenter()
}
dependencies {
compile("org.jetbrains.exposed", "exposed-core", "0.24.1")
compile("org.jetbrains.exposed", "exposed-dao", "0.24.1")
compile("org.jetbrains.exposed", "exposed-jdbc", "0.24.1")
}
anyone know why Gradle says that's invalid?
never used gradle before, just got that from exposed
What does it say is wrong?
Although that might be for the kotlin DSL, try this https://github.com/JetBrains/Exposed/wiki/LibDocumentation
The groovy syntax is slightly different
The snippet up there only works with kotlin
With groovy you can't separate artifact, group and version like that
@prisma wave sry a bit late but what should go in copyOption ? ^^'
so null ?
Umm shortness of breath is not a initial symptom of covid right?
Paths.get("plugins/PlaceholderAPI/mli/") how can I make a relative path ?
Relative to?
its a symptom ye
Yugi, rip you

thats the same with my mum
Someone put a 2min cooldown here
lol
gotta have the social distancing
u got covid buddy
Uh but I didnt go out till day before yesterday
3 days is too less to show any symptoms
is it tho
You drink much?
I havent drunk since like jan
๐
Well I have had breathing issues jn thw past so Im gonna wait till I get any other symptom
Just gonna take some asthalin for now
gl
โ ๏ธ
InputStream config = this.getClass().getClassLoader().getResourceAsStream("Language.yml");is it correct at least ?
@prisma wave help my deadass brain pls '-'
Looks good
why is null then ? :c
That's a good question
The answer might be Papi and spigot being weird
Is the file present in the jar?
What is you even trynna do btw
Is that....
is that ?
yes don't try to understand I also have ij '-'
https://img.bristermitten.me/15.12.31-2020.png that's a nice cry for help
yes it is x)
white theme as well tho
I got in on every load lol
@brave minnow 2 things:
make sure the file is inside the jar
try Class#getResourceAsStream
if both of those fail then you might need to try something cleverer
I like the pain
i love pain too
don't we all
reeeeeeeeee
is the file in the exported jar?
yus
@prisma wave is it possible to grab from jar file with those ? ```private FileConfiguration customConfig = null;
private File customConfigFile = null;
Not really, you need to get the file from inside the jar somehow. does getClass().getResourceAsStream work?
wdym?
it is possible to get files from those configurations
as long as you initialise them
I think File has a load() method
FileConfiguration does, the difficulty is getting a File
this is why you're supposed to load configurations using the main class
since that one has the data folder
getDataFolder() in Java
this isn't a plugin
what is it?
an expansion i believe
an expansion of a plugin?
for papi
ah okay
the only time you make PAPI expansions though is with a plugin
unless you're trying to make an expansion to bridge PAPI and another plugin that doesn't use PAPI
which seems like a bad idea
you can have standalone papi expansions
purpose.exe not found
yep but I would say generate the file and the config from api methods
what are you actually trying to make?
the expansion or the file ?
the whole project
translatable placeholders
placeholders that can be translated in to other languages?
yes
what files are you trying to write? locale files?
yes
yes
yep but can't put one in the java archive and extract it :/
you using maven?
nope
gradle?
neither
any form of build automation tool?
nah
if you're using build path that's the first thing I would change
but that's not important
for the moment
why ? ๐ค
makes dependency management like a million times easier
I guess ^^
easier, platform agnostic, more extendable, handles things like shading, etc
^^^^
but I think the problem is that papi's (and spigot)'s loading of classes suck
I would've thought PAPI's API would have some way to get the data folder
ah okay
so there's not a problem saving the file to the right place or what?
or is it just not bundling properly
there's a problem to grab the file not save it
https://github.com/PlaceholderAPI/PlaceholderAPI/blob/82fa8d7393442e18619b9c99192bf6f030be2874/src/main/java/me/clip/placeholderapi/util/FileUtil.java#L79 possibly because of this
file in jar jar in papi folder
yeah that's definitely questionable @prisma wave
i tried to make a kotlin script expansion for papi
the amount of class not found errors I experienced was horrific
making an efficient, user-friendly, working, actually looks like programmer gives a shit about end user API is harder than you think
although when the entirety of your project is an API you'd expect it to be written well
also why is it loading classes?
For the expansion to run
to load the classes from the jar?
but loading all the .class files is a questionable decision when URLClassLoader can load full jars in 1 line
sorry I don't know much about loading classes
I've never ever had to load classes
I had to make a module system a few years ago so I picked up a lot then
so that should be used to just load entire JAR files rather than separate classes?
indeed
there's no reason to iterate over the JarEntries when URLClassLoader can just load the entire jar
also yeah I've never made an API before so probably why I haven't ran in to things like this
which will include resources as well
if I want to optionally hook in to PAPI though I'll need to use this API won't I
though that method won't apply for me since I'll <scope>provided</scope> the PAPI API maven module
yeah PAPI won't need to load any classes in that case
the classloading is done for standalone expansions that aren't plugins
if you're wondering what I'm working on it's a free and open-source punishments plugin with built-in web server, bukkit and bungee support, possibly placeholder support, and as if not more customisable than paid alternatives such as LiteBans
also with a better API than LiteBans
currently a WIP
but anyway
is there a way to grab all file name in a dir ?
File#listFiles
yeah i remember you mentioning the Litebans rewrite a while back
sounds nice
it's written from scratch in Kotlin
the bukkit and bungee plugins will be separate JARs, unlike pretty much every other punishments plugin I seem to be able to find, mainly because I personally think having separate JARs is easier to distinguish between the versions
oh I forgot to mention that it has full database support as well
H2, MySQL, MariaDB, hopefully PostgreSQL, and SQL server I think
can't add MongoDB because it's not relational
anything else you think I should add?
yeah probably
nice
something I can embed in to the plugin
so that it doesn't even depend on an external web server like LiteBans does
not sure how I'm going to make it configurable
I think you should release the webserver as a standalone jar
so people can run it on a vps or something if they want
Kotlin/JS ?
even so
in case I'm making a placeholder expansion stored in papi folder the path to it (from the jar of expansion) will be plugins/placeholderapi/expansions isn't it ?
should it be a JAR if it's got no Java in it though?
well gud ๐
yeah
so File("plugins/placeholderapi/expansions") will show me the dir of it no ? ๐ค
I want to make it be able to run standalone though
I mean the plugin
without actually requiring that the web server be added to be able to use it
if you know what I mean
yeah
@brave minnow I don't think so. new File("") will be `plugins/placeholderapi/expansions I believe
I could bundle it in to the JAR and then make it configurable
and yeah should be
also where's the PAPI maven dependency?
please don't tell me it doesn't have one
sec
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.6</version>
<scope>provided</scope>
</dependency>
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repositories>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>{VERSION}</version>
<scope>provided</scope>
</dependency>
</dependencies>
got it? I'm guessing that's it
cheers
found it on the wiki
was just confused because it wasn't on the front page lol
also if I implement it in my plugin you don't need to make an expansion for it right?
Nope
these expansions are just for the plugins that don't have it implemented in them right?
that answer is memory
I mean where are you storing it as in: if the server goes down, what happens?
End goal for warp storage is gonna be mysql/flatfile
Is that per player warps too frosty? c:
if you want DB support I'd suggest just scrapping raw text file support
Good man
what I mean by that is just use H2 or SQLITE as the default driver
and scrap things like JSON, YAML or Plain Text
We'll see what's easiest to use I guess
just, I wouldn't implement MongoDB support
since MongoDB isn't a relational database
also I'd suggest using some sort of object-relational mapping software
for Java I recommend ORMLite and for Kotlin I recommend Exposed
if you don't know what ORM is basically it just takes executing raw queries out of your hand by using objects that represent columns in a database
Spring
Spring?
Don't listen to him, he suffers from SDD
Spring everything
tf even is spring lol
Spring?
wdym "everything"
spring literally does everything
websockets, persistence, http
security, oauth, dependency injection
reactive streams
I've got a use for exactly one of those
Then you need it
^
- 45mb jar
I don't need Spring for dependency injection
you dont need
Until you do
but you could
you do
Do you?
you always need spring
I wanna try out the reactive stuff at somepoint
koin does just fine
no matter how simple your app is
Hello world
Besides the point
What's the cleanest way of validating that an input string exists as an enum?
Spring
spring
Cause valueOf throws ew errors if it doesn't
Enums.getIfPresent or something iirc
A DTO
Enums.valueOf maybe
Then @Valid annotations
Km boi
Build a validation
yes
Enum's value of throwing error is so annoying, just return null
final class final MyStringInput {
final @NotNull
final @MyEnumExists
final private final String final input;
final public final void final setInput(final String final input) {
final this.final input = final input;
}
final public final String final getInput() {
final return finalinput;
}
}```
class MyStringInput {
private val input: String;
}
isn't that literally enough for Kotlin or is it just me lol
Matt, exactly
Make your own static method
^
there ya go
equals, hashcode, toString and all the other stuff done for you
Niall, effort
you're right
"not enough boilerplate"
"not enough boilerplate"
I should put that one on a T-Shirt
enum MyCoolEnum {
COOL,
COOLER,
COOLEST;
public static MyCoolEnum whichCoolIsIt(String coolEnumName) {
for (MyCoolEnum coolEnum : values()) {
if (coolEnum.name().equalsIgnoreCase(coolEnumName)) {
return coolEnum;
}
//there is no cool enum
return null;
}```
class? CLASS????????
Lol
smh
Dammit spring boi
I haven't quite got to that point yet lol
I only really started using Kotlin a few days ago
How would I have a param for any type of enum, so I can just loop through those enums values
wdym
enums can't have type parameters i don't think
Any doesn't exist in Java
How would I have a param for any type of enum, so I can just loop through those enums values
@heady birch ^^^^^
Enum<Object> then @ocean quartz
Enum and interface
I mean so I can just input that enum, and loop through the values, instead of having a method in each enum
Enum and interface
^^^^ yeah that's probably a better idea
enum DefaultCoolEnum implements CoolEnumNamable {
COOL {
@Override
public String getName() {
return "Cool";
}
}
}
Niall, ew.
public static MyCoolEnum valueOf(String name) {
MyCoolEnum[] values = values();
List<MyCoolEnum> notMatching = new ArrayList<>();
while(notMatching.size() <= 1) {
for(MyCoolEnum value : values) {
if(!value.name().equalsIgnoreCase(name.toLowerCase())) {
notMatching = new ArrayList<>(notMatching);
notMatching.add(value);
}
}
}
return notMatching.get(0);
}``` I've not tested this but behold - valueOf in `O(n!)`
put that in a code block @heady birch
public static MyCoolEnum valueOf(String name) {
MyCoolEnum[] values = values();
List<MyCoolEnum> notMatching = new ArrayList<>();
while(notMatching.size() <= 1) {
for(MyCoolEnum value : values) {
if(!value.name().equalsIgnoreCase(name.toLowerCase())) {
notMatching = new ArrayList<>(notMatching);
notMatching.add(value);
}
}
}
return notMatching.get(0);
}``` I've not tested this but behold - valueOf in `O(n!)`
@prisma wave No
nvm that won't work
Not enough OO
this needs improvement
Not enough boiler plate
lol
Not enough enterprise
I hope you're not actually being serious @heady birch xD
public static boolean isValid(final Warp.Category inputEnum, final String input) {
Warp.Category being any enum I desire
I think I misunderstood what he wanted anyway
You get what I mean now?
not enough boilerplate you say?
Why do this
bear with
Because that's not the only enum I'm gonna be using it for
Well then it wont work
also @hot hull you should learn Kotlin
Bardy, be gone.
use type
type?
public <T extends Enum<T>> boolean isValid(Enum<T> theEnum, String theEnumValue) {
for (T val : theEnum.values()) {
if (val.name().equalsIgnoreCase(theEnumValue)) {
return true;
}
}
return false;
}
Frosty is a hater ๐ข
someone should change this to say Java and Kotlin instead of Eclipse and IntelliJ lol
why is that a void and a boolean Niall :p
smh
Lol lmao
public <T extends Enum<T>> boolean isValid(Enum<T> theEnum, String theEnumValue) {
for (T val : theEnum.values()) {
if (val.name().equalsIgnoreCase(theEnumValue)) {
return true;
}
}
return false;
}
Havnt tested it should work
I cant even remember where the T definition goes
Do you like my apihttps://github.com/Niall7459/KiteBoard-Documentation/wiki/Developer-API
you want me to pick it apart?
Criteria.Factory<MyCriteria> factory = MyCriteria::new;```
Uses nice genreics
pick it apart?
if you mean criticize yes
would like to know how/if it can be improved
by pick it apart I basically mean go through it and find pretty much every fault there is lol
also if it's an API it always be improved
Oh I like that
I made it as slow as possible
lol
Including useless concat() and toLowerCase() calls
Oof
oh and it's written like that
Should probably add some Thread.sleep calls so we can make a nice progress bar
Yes!
yeah
I'm lost Niall
BM do you like my api
I've not seen it much
what's it an API for @heady birch ?
Kiteboard
=pl kiteboard
This bad boi
"enterprise" ๐
Also I documented one part wrong
Does that mean what I hope it does
Do what
RegisteredServiceProvider<KiteBoard>serviceProvider = getServer().getServicesManager().getRegistration(KiteBoard.class);
not sure about that one
I've legit no clue what I'm doing at this point
Over .load(
I'd suggest just having some sort of API singleton main class and then just getting the instance
๐
pretty sure LuckPerms does it the way I'm thinking of hold on
@hot hull I will try in ide
https://github.com/lucko/LuckPerms/blob/master/api/src/main/java/net/luckperms/api/LuckPerms.java there it is
https://github.com/lucko/LuckPerms/blob/master/api/src/main/java/net/luckperms/api/LuckPermsProvider.java and it's used from here
then lucko registers the API in the plugin I think
might be wrong there
yeah common depends on the API
wait that's wrong
That's hella quick KM
@hot hull
public <T extends Enum<T>> boolean isValid(Class<T> theEnum, String enumName) {
for (T val : theEnum.getEnumConstants()) {
if (val.name().equalsIgnoreCase(enumName)) {
return true;
}
}
return false;
}
Reflection to get the constants
you've passed that a Class object though
I wouldn't've thought that object would have the getEnumConstants() method
or am I just talking out of my arse
Warps.Category.class
ah okay
never had to do what he's doing before
also someone put that in to kotlin
I'm just curious what it'd look like
fun <T : Enum<T>?> isValid(theEnum: Class<T>, enumName: String?): Boolean {
for (value in theEnum.enumConstants) {
if (value!!.name.equals(enumName, ignoreCase = true)) {
return true
}
}
return false
}
ayy, works
that's what I got from IntelliJ
probably
inline fun <reified T : Enum<T>> isValid(name: String) : Boolean {
return enumConstantsOf(T::class.java).any {
it.name.equals(name, true)
}
}```
I believe it would be that
but I typed it on mobile so
Then you could do like isValid<Material>("stone_bricks")
fun <T: Enum<T>?> isValid(theEnum: Class<T>, enumName: String?): Boolean = theEnum.enumConstants.forEach { it?.name == enumName } @prisma wave ?
You can access the class of a type parameter
actually no that returns Unit
reified means you can do T::class
We're*
when
frosty, u owe me 50$ for advertising FJ
U already got your clout
What's that?
mooney
@jovial warren enumConstantsOf is a thing that does the reflection for you, and I would avoid the nullability, and use any instead of forEach
Happened two times within 2 days already, anyone got any idea why?
Cannot create resource output directory: C:\Users\Frosty\Desktop\Projects\IntelliJ\Warps\target\classes -> [Help 1]
Bad pc
Thanks
bad pc
Usually that's windows being dumb
fun <T: Enum<T>?> isValid(theEnum: Class<T>, enumName: String?): Boolean = theEnum.enumConstants.any { it?.name == enumName } so this @prisma wave ?
I've noticed it seems to happen a lot on win 7
Whats your fav template engine for spring BM?
It hasn't happened in the last 6 months i've been using IJ, and now it started, sus af
@jovial warren that would work but for QoL I would not allow nullable things
I've only ever used thymeleaf
that return type can also be inferred
freemarker and mustache, never used them though
I think the rule with inferences is if it's nullable it must be defined explicitly, otherwise it can usually be inferred
But you should be careful with inferred return types, unless the body is clear then it can be somewhat difficult to read
Nullable types can be inferred too
lemme correct that
And goovy templates
Which can actually work against you
yieldUnescaped '<!DOCTYPE html>'
html {
head {
title('Spring Boot - Groovy templates example')
link(rel: 'stylesheet', href: '/css/bootstrap.min.css')
}
body {
div(class: 'container') {
div(class: 'navbar') {
div(class: 'navbar-inner') {
a(class: 'brand',
href: 'http://beta.groovy-lang.org/docs/groovy-2.3.2/html/documentation/markup-template-engine.html',
'Groovy - Template Engine docs')
a(class: 'brand',
href: 'hhttp://projects.spring.io/spring-boot/') {
yield 'Spring Boot docs'
}
}
}
div("This is an application using Boot $bootVersion and Groovy templates $groovyVersion")
}
}
}
That's intersting
yikes
the rule with inferences is: if the type you want to return is being returned by the method you're using, it can be inferred
I really love Kotlin
Also KM, I wouldn't be surprised if it's IJ since I'm using version 2018.3 :kek:
could be
why are you still on a 2018 build?
Reasons
@jovial warren this shows when inference can be a bad idea sometimes https://twitter.com/kotlin/status/1255882186559029248?s=19
If youโre using the expression body syntax, try to add explicit return types for any non-trivial functions. This way, the type of the function will not change unexpectedly, which can help prevent surprises. #KotlinTips https://t.co/h19bPYSljE
339
that must've bugged you every time you opened it up that it needs an update
Still does
I'd highly suggest updating that
Can't
why not?
Pc bad
latest not compatible with your machine?
reasons
but why
OS?
@ocean quartz destructuring is hands down of Kotlin's best features
some things can be destructured if they override the component operators
one of my favourite features is the ability to add methods to existing classes
So for example ```kotlin
playerXP.entries.forEach { (player, xp) ->
}
ah okay
Which is a lot more useful than it sounds
You can destructure lists like in Matt's example
yeah right now I'm like "usage.exe not found"
val (first, second, third) = listOf(1, 2, 3)
It's mostly for QoL
Makes working with regexes a lot nicer for example
Basically any data class can be destructured into their independent variables
what are your thoughts on being able to add methods to existing classes though?
sounds useful
fun LocalDateTime.add(duration: String): LocalDateTime? {
if (!duration.matches("((\\d+)\\w*)+".toRegex())) return null
val matcher = "(\\d+)([a-z]*)".toPattern(Pattern.CASE_INSENSITIVE).matcher(duration)
var result = this
while (matcher.find()) {
val amount = matcher.group(1).toLong()
val unit = when {
matcher.group(2).matches("s(ec(onds?)?)?".toRegex()) -> SECONDS
matcher.group(2).matches("m(in(utes?)?)?".toRegex()) -> MINUTES
matcher.group(2).matches("h(ours?)?".toRegex()) -> HOURS
matcher.group(2).matches("d(ays?)?".toRegex()) -> DAYS
matcher.group(2).matches("w(eeks?)?".toRegex()) -> WEEKS
matcher.group(2).matches("mo(nths?)?".toRegex()) -> MONTHS
matcher.group(2).matches("y(ears?)?".toRegex()) -> YEARS
else -> SECONDS
}
result += Duration.of(amount, unit)
}
return result
}
that is so useful to have
Pretty much the first thing I write in any project is String.color to process color codes
you wanna know what that was in Java?
Some hideous helper method probably
public static long convertDuration(final String duration) {
Matcher regex = Pattern.compile("(\\d+)([a-z]*)").matcher(duration);
long milliseconds = 0L;
while (regex.find()) {
int amount = Integer.parseInt(regex.group(1));
switch (regex.group(2)) {
case "s": case "sec": case "second": case "seconds":
milliseconds += amount * 1000L;
continue;
case "m": case "min": case "minutes":
milliseconds += (amount * 1000L) * 60L;
continue;
case "h": case "hour": case "hours":
milliseconds += ((amount * 1000L) * 60L) * 60L;
continue;
case "d": case "day": case "days":
milliseconds += (((amount * 1000L) * 60L) * 60L) * 24L;
continue;
case "w": case "week": case "weeks":
milliseconds += ((((amount * 1000L) * 60L) * 60L) * 24L) * 7L;
continue;
case "M": case "mo": case "month": case "months":
milliseconds += ((((amount * 1000L) * 60L) * 60L) * 24L) * 30L;
continue;
case "y": case "year": case "years":
milliseconds += ((((amount * 1000L) * 60L) * 60L) * 24L) * 365L;
}
}
return milliseconds;
}
that mess
Oh dear god
YUCK
yep
I'm pretty sure there are ways to clean that up even more
Iirc you can destructure a Matcher for example
But you should definitely be caching those regexes
toRegex() is the same as Pattern.compile so it should be cached
the left one was stolen straight out of MaxBans lol
Kotlin really clears up your code a lot though
it really does
ngl, the second one is spicy af
https://github.com/Prevarinite/Punishments/blob/master/src/main/java/com/prevarinite/punishments/commands/BanCommand.java that's my old ban command lol
mostly because I was using an inefficient method
Declarative programming in kotlin feels dirty imo, it should almost always be imperative
@jovial warren that is hideous
yeah I know
As simple as it gets, lovely
my friend literally used the anydesk drawing tool to draw the line on the left of the code and said it looked like the himalayas lol
fun lazyString(body: () -> String) = object {
override fun toString() = body()
}``` this entire thing is useless
kotlin can do lazy loading for you
that is only there because lazy {} wasn't working properly
@ocean quartz cute
kept saying "Lazy field not initialised"