#help-development
1 messages · Page 798 of 1
why is there separate file type for interfaces?
public interface
Regardless of implementation, I get the interface
public class
whats .class
There isn’t
and call the method defined on that interface
Hell nah bros using notepad++ for usre
Which the implementation.. implements
which is blank
empty
you still need to make the code in that method
The interface defines that the method exists
And it is up to each implementation of the interface to define its functionality
The mongo implementation grabs the data and sticks it in a mongodb database
but inteface is literally made out of empty shit
The mysql implementation grabs the data and sticks it in a mysql database
how is it supposed to tell how empty shit is supposed to work
The interface is a common contract that they all follow, so that regardless of implementation I'm calling the same method
And if you don't get these explicit technical words then just ask chatgpt and fuck off
how nice of you
He doesn’t trust it and want us to tutor him though
of course I dont get them lol
why would I trust an AI that cant even properly use 2nd law of thermodynamics? 😭
I can’t recall the 2nd law of thermodynamics either so don’t trust me too
why not just make class for database
Roast opportunity
you will make a class
what advantage is in using interfaces
that implements the interface
you can do it later
You can rely on interfaces while you design your program's architecture
We will just repeat what we have already said lol
Gl emily
its mainly so that other parts of the code dont have to be a pain in the ass when interacting with the classes that implement interfaces
then why not just not implement them at all?
interface Storage {
void saveItem(ItemStack)
}
class SqlStorage implements Storage {
// implement saveItem for sql
}
class YamlStorage implements Storage {
// implement saveItem for yml
}
then in your plugin you use Storage but it can be either SQL or yaml
this is called abstraction
if you dont see the benefit you either dont understand, or have not made big enough code to see why its useful
why not make two methods in storage for db and yaml and use the one im interested in interchangably
because you want to use one kind of storage that is determined at startup
and then you aren't doing if (storage == sql) savesql else saveyml
every single time
I wouldnt
id just do storage.saveItemSQL or storage.saveItemYaml
id just do two methods for it
and use whichever one Id need
yeah, I can just make one instance of Storage, pass it to whatever class needs it and just cast whichever method I need
I wouldnt care about the other one
yes
and wherever you need to save the item just call saveItem on the Storage instance, where you use it you don't need to care what kind of storage it is
You opening class for modifications
aand?
Like if you want to remove the "yaml" saving most of parts of app just give compile error.
And you have to refactor it.
isnt programming about rewriting
no
not if you do it right
good code is that that has the least friction to changes elsewhere
it's good to maintain because you don't have to go all over the place adjusting one small thing
whats the point of abstraction
why would I not give access to data
to someone
well to something
You mean encapsulation?
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
idk what it is
why is it so important to not let other classes or other shit know about stuff
what if that class happens to need to know about something
Example?
stop spamming learnjava, it has no meaning at this point
Bukkit gives you access to a Player but it doesn;t expose the whole Map of Players
idk
While he refuses to read any of it it has meaning
im just saying
not if it gets ignored
you ever been to school?
then that end up being the only answer
at some point he will stop askign basic questions or actually READ
Have I been to school? odd question
let me explain
Elgar getting banned i guess
the more teacher pushes you to study stuff the less you are inclined to do it
Oh, sooo
no I just didnt want him to actually say "yeah I am" cuz that could actually get him banned
😭
If we tell you to write plugins you will eventually stop and leave?
only an idiot takes that approach
damn 80% of students must be such idiots
yes
out of 13 years of education so far Ive rarely, rarely ever saw people who get motivated when teachers tell them to study this or that, instead of getting demotivated or starting asking questions what is it even for
ah so you want me to leave, then no
If a teacher keeps telling you something and you refuse to listen, at some point the teacher gives up as you refuse to learn
Bros stubborn
okay so what is this discussion even about
then they dont get paid no more that's overstretching
Interfaces and polymorphism
the more you are pushed towards doing something most of the times you show innertia unless you got a good reason to do it and are motivated enough
teachers don;t get paid for you learning, they get paid to teach
like spamming ?learnjava for n'th time wont do stuff, at this point I consider it as a way for someone to deliver their bad blood towards me and simply ignore it
Its the only answer you will get from me from now, for basic java questions
why do you act as if somebody is forcing you to answer tho
You've been here a few weeks now and adamantly refused to learn or read anything
We've been dumb idiots before, after years and years of experience it is our moral obligation to pass the content down to the new generation of dumb idiots in hopes they get smart
We”re all here because we for some reason or another enjoy helping others. It gets annoying when some dumb idiots don’t listen
Think I'm about to get the crustiest pizza
I remember when I was a dumb idiot
We give you answers over and over but all you say is "I don;t understand".
We explain it every way possible but you refuse to read the simplest of documents
im asking a question not asking for reference duh
Throwback to when I tried learning chunk packets and block pallettes in 1.8 without knowing what a bitshift did
maybe tis cuz we bad at explaining
and we have answered over and over. This question you are asking you asked the near identical question a month ago
and who obliges you to try and answer it, get mad about me not getting it and just saying how you are not gonna help from now on and still decide to do it
its like, willingly hurting yourself at this rate
Go away troll.
Weren't you arguing that us developers shouldn't be paid at all?
Something tells me you have no respect at all for the people attempting to help you
Shoo away
He's argued with every person in here
Begone troll
Block and move on
block only spams you every time they post
Which is kinda annoying tbh
if it was a true mute I'd use it
Block is like a fake block

It functions as my don't help list lol
no I was saying that Id rather buy food than entertainment
What about we send him to helpchat instead
which is true because being a student doesnt help with budget lol
Bet you see this argument as free entertainment
Yeah. I've never blocked anyone but he's come the closest
What about me elgar
bro I literally gave you the perfect solution for your problem - just not interact if you dont feel like it
I'm worthy
Nah you cute 🙂
why do people treat blocking someone on discord like it's some kind of divine punishment but still resort to interacting with them
Elgar pleae let me be your first
Lmfao
lol
for a sunday?
Yes
I was going to cook a roast but it looks like it will be burgers
Was about 2,25$
well how i undestand i not can change block hardness blast-resistance ?
You can't sadly
2.25? how so cheap?
You could reflect the blast resistance
Hax
Since imillusion is here he may have some packet hacks
Has it been on teh floor for it to be cheap?
then how this do itemAdder lol
You can
Ask in item adder discord they probably have one ye
Every 6 orders you get a free pizza of any size
They do but you can still reflect
Sure
or rewrite core server in runtime?
I will share ur black history
Can someone decompile this and let me know what it is.
lol
but hacking is possible in any case if you really think about it
woudl still work 🙂
Great permission
public interface AnimalStuff {
void breathe();
}
public class Animal implements AnimalStuff {
public void breathe() {
//breathes w/e
}
}
class Main {
public static void main(String[] args) {
Animal cow = new Animal();
cow.breathe();
}
}
and now
how do I make another animal
that would breathe differently
with interfaces
blame w3schools
interfaces with 1 implementation are literally useless
it would be Animal implements Breathing
and then your cow would extend Animal
and if you want you can make another animar that breathes differently
but you can also make a Human implements Breathing
thats not even the point w/e the semantics
assuming humans arent animals
I feel like animal should either be abstract or the interface considering animals doesn’t breathe the same
@storm crystal do you know what an antonym is?
yes and relevance?
I mean the example is just kinda bad
I havent asked for critique
idc how bad it is
whats the point of interface if I supposedly cant even make those methods work differently
You can ur just being dumb about it
you can
I am literally asking a question how to do it
you can implement breathing in all subclasses f you want to
Make animal an abstract class or interface too
are you still not understanding what an interface is for
He is not
Woah the spanish thing
¿Tu hables español?
not at all
Ah
public interface Animal {
void breathe();
void shit();
}
public class Cow implements Animal {
public void breathe() {
//breathes w/e
}
public void shit() {
//comically large amounts of methane
}
}
public class Pig implements Animal {
public void breathe() {
//breathes the other way w/e
}
public void shit() {
//doesnt spit methane violently i guess
}
}
class Main {
public static void main(String[] args) {
Animal cow = new Cow();
Animal pig = new Pig();
cow.breathe();
pig.breathe();
}
}
Same
better?
Now name animalstuff animal
And Cow cow and Pig pig just needs to be Animal instead of their respective classes
Why?
Most basic definition
Watch me get home and record a 10 minute video
Animal cow = new Cow()
And toss it in the index
Hey, how can i create an empty world in spigot 1.20 ? I try use ChunkGenerator but methods that i found on Internet are now deprecated.
you cant create an instance of an interface
They usually name a different method to use if they’re deprecated
why Animal
helpful
you would assign it teh most basic iomplementation that you wnat to use
why not just make it their respective class
but in most cases it doesnt really matter I find
Well the idea would be that regardless of what animal it is you can just have one method and be able to call Animal#breathe
Instead of 50 methods that does each animal
thats not the issue
he was just asking why it would be Animal cow = new Cow() instead of Cow cow = new Cow()
there is no reason for it imo
in here they would just do Pig pig = new Pig();
Make sure to get a Turtle too
so im asking what the difference is
I am trying to reply to it considering the whole hour or two long convo we had
Oh a Stone too
teh diff is if your pig has another method and you create it with Animal pig, you cnat use that method
Though, that doesn’t breathe
unless you cast it back to a pig
okay so casting Animal t ype
Sigh
Yes
if I casted Pig and pig had haveFunInMud() method
I could use that method
but if I casted Animal
I wouldnt
Yes
so it just tells me what methods I can cast?
No
If you need a pig specifically and really down bad just instantiate Pig pig = new Pig(), but if you need any animal with no quirks, instantiate Animal pig = new Pig()
It's a good practice to instantiate the lowest level iirc
Look up how to use Java modules and then how to use them with maven and just cry its not fun it doesn't make much sense and worst of all its insanely hard to get to compile
It probably does dusk
You can survive without that. That's why
It is just a better practice
I'm never using JavaFX again
and make a class for lets say kills
Fuck that module shit
It fucks with your other depenendecies too
Why would there be a class for omly kills
Uhh I don't exactly see why you would make a class for kills
class for each data type
kills isnt a data type
^
PlayerStats can be
player data is a data type
what illusion said about data types isnt that
class for kills that implements database management or behaviour or whatever you call it
you get it
and class for deaths
no
and for other shit like money
player stats class has the data behaviour
sounds like overkill
You do not need a class for every statistic
Illusion essentially told me that I do
Link the message plz
Here's the proper explanation because in his eyes the interface can be omitted:
An interface is a sort of empty contract class that defines the methods its implementations (classes that implement the interface) can have.
An interface can extend multiple interfaces, a class can implement multiple interfaces.
public interface Animal {
void idle(); // A method of the return type "void" named "idle" with no parameters
}
public interface Breathable {
void breathe();
}
public interface BreathableAnimal extends Animal, Breathable {
}
With these contracts, we can then create a few implementations
public class Snake implements Animal {
@Override
public void idle() { // We must override this method or make this class abstract, as the Animal interface states this method exists in all implementations
System.out.println("I'm a snek");
}
}
public class Cow implements BreathableAnimal { // This is the same as implementing Animal and Breathable
@Override
public void idle() {
System.out.println("moo");
}
@Override
public void breathe() {
System.out.println("*cow farts*");
}
}
We can then instance the classes we created as objects of the interface type, for example
List<Animal> animals = List.of(
new Cow(),
new Snake()
);
for(Animal animal : animals) {
animal.idle();
if(animal instanceof Breathable) {
System.out.println("We found a breathable animal!");
animal.breathe();
}
}
scroll up
We can pass as many different animal types on our list
I scrolled up and I did not see anything that mentioned your idea. Please link the message
I told you that my solid design structure employs an interface and usually an abstract class for each implementation
Illusion bad programmer? Banned
That's because I'm writing platform-agnostic code and linking with the bukkit api
It also means I'm applying dependency inversion everywhere
Any other questions?
I dont get any of it

?tryandsee
Tbh
why do you link your code that does something that I dont even understand
it has pointers and malloc no thanks
And memory management
Haskell
Use rust then
Eta is a simple, compact and powerful programming language to build scalable systems on the JVM. It is a dialect of Haskell on the JVM.
my friend is obsesseed with C++
so I automatically have no respect to any C language
Are you that friend that downplays your friends' interests
Seems so
too bad like everything else is built on top of c languages
I mean if someone tells me that I should end myself because I am not learning the almighty and useful C++ and instead resort to useless Java for virgins
then I wont get good impression of C++ at all
Ah in that case
thenits not a friend
Still though that's more about the C++ community, and even so you've only been exposed to one member of it
^
I am not a virgin, but i use more kotlin than java
^^^^^
your virginity just came back
maybe ill switch to Kotlin
congratulations
@rotund ravine wanna help me?
Ahahah
pls say no
kotlin is not much diffeernt from java with what you cna do with it
Yep, the biggest difference is probably syntax
And well new builtins
But I find it much more convenient
Kotlin still requires basic programming knowledge
Oh and very strict null control
Gotta love the String! Times
Haha
wait untill dusk finds out about generics
every language does
On compiler level?
Well compared to Java, in Kotlin it's much harder to get an NPE
I'm sop confused on why this is happening. everything is setup right in my pom.xml, I do get code sense help when typing and no errors when actually writting the code, this only happens when I am trying to compile it to a jar file to test it. toastrpg is my custom library, and is imported from the system, lamp revxrsal is shaded from toastrpg so it comes from that.
Because you almost always know when you're working with a nullable object and the compiler will bitch about it if you're not careful
Did you add the jar through intellij but are building through maven
yes... that bad?
yes
ahhh okay..
you should add it through maven
Would anyone be able to advise on a way to stress test my server with players? Bots of course but I want to best simulate players? Any tools out there ?
I can do that.
Why?
Oh u crossposted
Blocked
Most of my plugins are custom, I’d like to test the durability
Bye papa
so I make separate class for each stat set?
like player stats, enemy stats, lootbox drops etc.
yeah prolly
wdym probably
we are not illusion
we cannot say exactly what illusion means
we can interpret what he means
@echo basalt what did you mean
probably as in I would make tehm separate classes
and if they share a lot of logic have a superclass or interface above it
Alright so I did do it through maven and that works, what's the problem with doing it through intellij?
they dont talk, maven doesnt know about ij deps, ij knows about maven though
When why did you give yours
also you cant share ij deps, ij doesnt know where they are but you can share maven poms and it will download of repos
Mine will 99% suck either way
We share our ideas and implementation
It’s like school you reflect on things and write your own shit
Java fx with a theme = stonks
java modules are fun :3
oh don't forget! if you have any dependencies that aren't java modules your build will fail!!!
so you have to use a very "easy" to use maven plugin to fix that yourself!
then use jlink! and more!
maven is ez
you know what makes me wanna kms
I just reverted to java 8 when i made javafx stuff
life
that'd make me wanna die too
I need my java 17 features
Kotlin 🤪
dumblin
Ill write my shit ask how it looks and turns out I need to rewrite it entirely
Motivating
I refactored my plugin like 3 times by now
refactoring stuff is fun
val L = db.randomData() ?: throw NullPonterExeption()
:troll:
yeah exactly
and entirely motivating you see yourself getting better
if you can't deal with having to refactor because you're getting better development isn't for you tbh
if you dont like rewriting stuff, then dont do programming for fun
or only make small projects thats fine too
Ig
I hope programming isnt mandatory for my profession
i can change block break sound?
I've had nothing but issues with those weird modules they expect you to use
I have trouble compiling anything because I depend on things that don't use java modules
its a headache and quite frankly makes me want to never use jfx again
then you don't use them either
jfx doesn't work properly without java modules
just put javafx in the module path at runtime and your stuff in the classpath
that's what I do
ig I haven't found a nice way to do this with maven I saw one plugin but it pretty much required me to write the module file in xml vs java's syntax
and when I did use it, it didn't work nicely either so Jlink still failed to build
I can show how I have it set up, it's nothing special, but, yeah, it isn't maven however
I pretty much just have a separate task to invoke jpackage correctly, that's all the "special setup"
Hey I am learning the basics of spigot events and I struggle with world teleportation
public void onBlockBreak(BlockBreakEvent e){
e.setCancelled(true);
World world = e.getPlayer().getWorld();
Location location = new Location(world,0,64,0);
e.getPlayer().sendMessage("Monde courant : " + world.getName());
if(world.getName()== "world"){
world = Bukkit.getWorld("world_nether");
Bukkit.getLogger().info("World set : " + world.getName());
}else{
world = Bukkit.getWorld("world");
Bukkit.getLogger().info("World set : " + world.getName());
}
location.setWorld(world);
e.getPlayer().teleport(location);
}
here is my function for it, I just switch worlds whenever a block is broken
it seems like my program never goes through the first if statement for some reason
okay
now it works, thank you
I am still learning the basics of Java Objects in class rn
the 0.000000001% chance where they're at the same memory location 
this is why you always use String#intern(), so your string equality checks are always correct
v:kappa:
Can someone happen to me how is this visual bug can happen? The fireball always curve when I try to increase the speed of the fireball, but if it has default velocity, it will not curve, it will go straight.
You hit it?
nocode
No I spawned it with left click air interact.
Right, one sec.
@EventHandler(priority = EventPriority.HIGHEST)
private void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (event.getHand() != EquipmentSlot.HAND) return;
if (event.getAction() == Action.LEFT_CLICK_AIR) {
// get two blocks in front of player
Location eye = player.getEyeLocation();
Location location = eye.add(eye.getDirection().multiply(1.2));
Fireball fireball = location.getWorld().spawn(location, Fireball.class);
fireball.setVelocity(location.getDirection().normalize().multiply(5));
fireball.setShooter(player);
}
}
Interact probably runs before the actual hit
I heard that it was actually because of 1.20.2 spigot.
you are multiplying by 6 so that will also increase the Y axis by 5
I tested it myself and it was fine in 1.19.4
Okay, so I need to set the Y to 0 right?
Is the problem is in my code?
it looks like it arcs to the right
It curves randomly, it can curves below, right or left.
Left at the start
What happens if you delay it by a few ticks?
yeah nothing wrong with your code
Depends on where I'm looking at, if I look at the left, it will curve to the left.
@summer scroll
oh use setDirection not Velocity
Delay the spawning
I've tried using setDirection but it will not change the speed.
Same thing happened.
Alright, I'll try to use setDirection.
else use the spwn method which accepts a Consumer
so you setDirection in the Consumer
Oh yeah you're right, I can use consumer okay.
It shoots straight but it has default speed, here's my code.
@EventHandler(priority = EventPriority.HIGHEST)
private void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (event.getHand() != EquipmentSlot.HAND) return;
if (event.getAction() == Action.LEFT_CLICK_AIR) {
Location eye = player.getEyeLocation();
Location location = eye.add(eye.getDirection().multiply(1.2));
location.getWorld().spawn(location, Fireball.class, fireball -> {
fireball.setShooter(player);
fireball.setDirection(location.getDirection().normalize().multiply(5));
});
}
}
You can compare the speed to the video I've shown above.
what if you increase the 5?
Do 1000 and see that’d be fun
Nothing happened.
a normalized vector would be 1 block per second
so multiplied by 5 should be 5 blocks per second
does the value not affect the speed at all?
I'll try to debug the fireball's velocity.
else try....
setDirection(...
setVelocity(fireball.getDirection.multiply(5))```
err
Same thing happened, the fireball will curve.
If you get the direction of the ball?
I guess it does not like setVelocity, as teh javadoc says
I assume he used the fireball for getDirection
Here, I'll show you the code and the debug https://paste.md-5.net/acufizajoh.md
Fireball Power is 15, that means I multiply the Vector by 15.
getDirection of the fireball not the location when you setVelocity
oh nm, ignore me
What happens if you mutiply the velocity of the fireball after a tick
sysout the getVelocity.length
a vector is annoying
you just want to see its actual speed
as is for now
I've tried to delayed the set velocity, but the result is the same, the fireball will curve
What you have now, but.
fireball.setVelocity(fireball.getVelocity().multiply(5))
A few ticks after?
should check stash/nms and see if setDirection is normalizing your imput
.
um
I can’t click that for some reason
Probably fireball mechanics
yeah i guess
Same, no matter how many ticks after.
Would want to see this run after a few ticks and what happens
Dang
Oh well blame legacy versions
The length right?
Well the getDirection().length() is identical till death, always 0.1
Same with sysout getDirection(), it's the same all the time.
um 0.1?
Yes, the getDirection().length() is always 0.1
There is update() method, what is that?
. Totally
Here's when I tried to set the velocity after 3 ticks.
Rip
@eternal oxide I got this from EntityFireball.class. I'm not sure what it means tho
public void setDirection(double d3, double d4, double d5) {
double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
if (d6 != 0.0) {
this.xPower = d3 / d6 * 0.1;
this.yPower = d4 / d6 * 0.1;
this.zPower = d5 / d6 * 0.1;
}
}
@echo basalt what are CompletableFuture<UUID>
Oh my
do I need anything else?
bim bim bam bam
do I need it for database or not really
and how to do it?
do I just make main class for connecting to databases and class for each db management or include connection within those classes for each database
thats a shit ton of work
well I cant even download sqlite
There is a client side limitation for displaying velocity
It's bundled iwth the spigot jar
is it proper way of making connection method?
Depends on what you mean by "making connection method"
method that would connect to desired database with given prompt
or should I remove the prompt and just hardcode it for each database class
Usually you would pass all components of your jdbc url to a class and then internally concat it
so just how I made it?
can I just make it like that?
You should get a completely new connection for every time you access the Database.
Unless its SQLite specifically.
Well not completely new 😅
It's weird that this doesn't happen in version below 1.20.2 (at least in 1.19.4)
Well... yeah. Usually you have a bunch of connections and check which ones are valid.
preferabl you don't do any of this and shade a proper connection pool like hikaricp
It does even down to 1.8
so just use method for it?
What's the limitation anyway? I have tried to multiply the velocity to 10 and 15 in the previous version and fireball shoots straight.
how do I make a method that would just return this particular connection?
@storm crystal You would cache them
Hikari is a tool to do this for you
Wait no, smile told u to do smth else so why are you trying to get the same one?
great idc at this moment because I have those two fuckers
It’s just IJ trying to be helpful
"Oh no I have a warning about not using connections correctly"
"Use a proper connection pool"
"Great idc"

Anyone know a way to in the chat tab completion use essentials x nicknames or simalar?
you always have to close the statements
yeah because SQLite tutorial literally has no mentioning about it
and it works for them just fine
so
try (final PreparedStatement statement = connection.prepareStatment("...")) {
}
Well SQLite is a different beast
prepareStatement*
Close enjf
Helpful!
koriLaugh
yeah now try not copy pasting
I didnt
x
d
x
so much copied
me irl
I thought its correct way of writing Statement
.
what about this one
?
IJ is trying to be useful @storm crystal as i said
Ah fuck yea sorry I misspelled the method you were to lazy to google on my phone 😭
mb mb
You can’t add enchantments like that
The client only shows what it knows
So you gotta add ur own lore
how i can add lore down the olther enchant?
Add lore like you normally would with itemmeta on proper events
Can I create a system that removes the enchants with the ItemFlag and then finally adds the enchants to the lore?
how do i use the mojang mappings while using nms?
add visible all enchant
? You want to hide them?
?nms
hide and then create a new lore with it
Why would you hide normal enchants
because if i put normal lore, it go up.
What goes up?
450+ Custom Enchants - Create Your Own Enchants In-Game - Enchantment Table & Anvil Support - 20+ Items | AdvancedPlugins.net
i want create enchant like this
Uses lore
but the lore is up the enchant
do you guys have a custom site to upload large files to?
For?
No
could you send an ingame screenshot?
thats what i meant, thanks
Yes
exuse me
if you want to remove the enchantment displays
He doesn’t want to
how do I insert any wanted data into database with a method
Google your question before asking it:
https://www.google.com/
no, i want do it visible
use ItemFlag to remove
?
do I make getter and setter for each datatype that I want to edit/set/get?
like UUID, deaths etc.
You would get everything you would need in the immediate future from one connection
great I have empty table and I need to fill it first
:]
I cant make one method to be able to set both UUID and deaths
follow a tutorial
of how to use databases
(depends on which database you are using?)
its not even about databases
You can make one method to do it
Thanks, solved it
do I make separate method for each datatype
That’s good i didn’t do anything tho haha
@storm crystal no
so what
- I told you that I am not asking in field of databases
- Im using SQLite, duh
You would have PlayerStats or smth that has each of the stats and then just have a method that saves and gets that
but I am supposed to fill it first
with shit
Sorry for not knowing the database you are using, if you do not specify it
its empty
I didnt ask you for database guide at all
It seemed like you do not know what you want
so i suggested to first learn the basics
Return an empty PlayerStats object
relevance?
Are you broken?
what do I need empty object for
you dont just add random data to the database
He’s so broken
@storm crystal explain your problem from top to bottom
you can either actually explain yourself or just keep saying it
Like he comes off as either absolutely clueless or a troll
What?
Yes, because there's nothing there
is there a problem with an empty row?
technically it shouldn't return any row
the browser just shows an empty row, probably
It should just return nothing when u try and get it
and I want to make a method that would fill that empty row with provided information
Yes?
No
how do I handle it
So you want a method to insert data to a database?
to make one yeah
You have a data object called PlayerStats that stores your rowdata
You have a method called savePlayerStats
That insers the data
Form the playerstats object
because I cant just make setData(UUID playerId, String data)
what if I want to update deaths
its not a string
it would be setDeaths(UUID palyerId, int deaths)
the whole setData thing was pseudo
so it comes to a conclusion that for each datatype I'd have to make separate method
they idea is setDeaths or setObject(UUID, PlayerStats obj)
Not necessarily, no.
No…
I personally have done it that way, yes
then why do you even propose it
He explained it cause ur saving one single thing
just make a check when you request the information if it is currently defined or not, if it isnt just return a default value, like 0 would probably be good in your case
omw to return uuid 0
class PlayerStats {
private final UUID playerId;
@Getter @Setter
private int deaths;
}
class PlayerRepository {
public Optional<PlayerStats> get(UUID playerId) {
...
}
public PlayerStats getOrCreate(UUID playerId) { ... }
public void store(PlayerStats data) { ... }
}
class MyPlugin extends JavaPlugin {
public void onEnable() {
PlayerRepository repository = new PlayerRepository();
getServer().getPluginManager().registerListeners(new Listener() {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
UUID playerId = event.getPlayer().getUniqueId();
PlayerStats data = repository.getOrCreate(playerId);
Bukkit.broadcastMessage("Player just joined with " + data.getDeaths() + " deaths.");
}
}, this);
}
There you go. I've jsut typed up exactly what you want through Discord
but you dont request uuid by death count??
like what he's saying makes no sense at all
yea
what does Repository mean
it's just an "interface" between your database and your code
that's what it is called in Spring, but you can call it anything you want
for you its just a fancy name
for me sounds derogatory, whats the actual purpose of such name then
oh fuck
now you went ahead and did it, he just kept trolling so he would be spoonfed the code
this is gonna start the whats an interface for again
the code doesnt solve my issue at all
its more or less what I've written so far
it literally explains everything bro
getOrCreate means
if they don't have a row in the database with their id
then create it
and return that new row containing the defaults
i.e., the default death count, etc., all tied by their UUID which was provided in getOrCreate
"PlayerStats data = repository.getOrCreate(playerId);
data.getDeaths()"
which is what I wrote, yes
why is there getDeaths out of nowhere
bro
okay that's a fine question
that's called lombok and I used it because I wasnt going to write boilerplate through Discord
class PlayerStats {
private final UUID playerId;
@Getter @Setter
private int deaths;
}
@Getter just means that getDeaths() and setDeaths(int) exists inside of PlayerStats
import java.util.UUID;
public class PlayerStats {
private UUID uuid;
private int deaths;
private int exp;
public PlayerStats(UUID uuid, int deaths, int exp) {
this.uuid = uuid;
this.deaths = deaths;
this.exp = exp;
}
public UUID getUuid() {
return uuid;
}
public int getDeaths() {
return deaths;
}
public int getExp() {
return exp;
}
public void setDeaths(int deaths) {
this.deaths = deaths;
}
public void setExp(int exp) {
this.exp = exp;
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
public class SqlManager {
public void insertPlayerStats(PlayerStats playerStats) {
try {
PreparedStatement statement = connection.prepareStatement("INSERT INTO player_stats (uuid, deaths, exp) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE deaths = ?, exp = ?");
statement.setString(1, playerStats.getUuid().toString());
statement.setInt(2, playerStats.getDeaths());
statement.setInt(3, playerStats.getExp());
statement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public PlayerStats retrievePlayerStats(UUID uuid) {
try {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM player_stats WHERE uuid = ?");
statement.setString(1, uuid.toString());
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
int deaths = resultSet.getInt("deaths");
int exp = resultSet.getInt("exp");
return new PlayerStats(uuid, deaths, exp);
} else {
return new PlayerStats(uuid, 0, 0);
}
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
}
oh lovely
so turns out that I do have to make separate methods for each datatype
..
No?
...
oh my fucking god
public UUID getUuid() {
return uuid;
}
public int getDeaths() {
return deaths;
}
public int getExp() {
return exp;
}
you did it there
that is called a getter
yes that's literally called a getter pattern in Java
are you so clueless
That is not what you asked
how clueless are you
Like at all
that is literally a method
do I make each of them for each database
The point is that it's standard convention to create getters and setters for properties of an object. The reason we didn't say "yes" to your question was because it was about the database
?
Are you attempting to support multiple types of SQL databases?
i.e. SQLite, MySQL, PostgreSQL?
Use one db file
you have 1 db with mutliple tables
you have several tables per database, one database file
And multiple tables
so do I make separate table manager
yes
like here?
https://www.youtube.com/watch?v=MbsI0bNxDEc he may be using mysql, but he is trying todo about the same thing as you
In this episode of the Spigot series, I show you how to make your first plugin that connects to and uses a MySQL Database to store player statistics. It uses JDBC to connect and execute SQL statements upon the database. #Spigot #Minecraft #SQL
(Adding video timestamps soon)
Code: https://github.com/Spigot-Plugin-Development-Tutorial/plugin-with...
and explains it pretty well
oh no not this guy please
just look at veinminer storage stuff
or that
He doesn’t learn by looking at code @remote swallow
that is true
ah great
I dont learn with his videos at all
if that was a case I wouldnt be asking anything here
Watching a video, or looking at code
@terse raven no need to delete ur messages idrc
He asks a ton in here
watch the video and follow along
most of the stuff i learn is based of getting some code examples
^ I've given epic pseudo code about writing a Factory system for his library and he learnt it very quickly
I did read w3school inferface code example and it didnt explain anything that I asked about earlier
very similar to how I tried to teach you by giving you pseudo
That’s surprising
epic is great
i mean it took a while but i got there and now it would take minutes to get that
Oh u gave epic it
yes
I didn’t say epic didn’t learn
so you look at multiple sites
nah I know
so where do I use interface here
I haven’t had any issues with epic not being willing to learn
it was an example to how I tried to teach Dusk they same way I taught Epic
but ig dusk is just trolling or smth
if you supported multiple different sql types
@storm crystal You don’t really since ur not ready for it yet tbh
yea
I can't really tell because I've tried to help dusk twice now, and they just don't absorb
Ikr?
I am not going to write a code that'll be rewritten anyway
i pretty much gave up trying to help
Then stop writing immediately
thats how you learn
Don’g write anything
better ways to spend my time
development is a hell of a lot of rewriting
you literally said "use this simple thing and you will rewrite it entirely either way"
very motivating
sure its annoying to rewrite but you will have a much better time interacting with it later in development
yea later on
ligma
balls
make it simple to start, you can then learn how to do it and use it then once you understand moer you can make it better
its not like you won't start writing a simple english essay rn, because someday you are going to rewrite a better one anyway lol
it's all about trial & error and the progression that results from it
so I make
yes
connection manager class for one database
i hated rewriting stuff to start with, i still dislike it now but its the life of developing stuff
and we will give you tips on what todo next
and for each row or whatever it was called I make separate class with getters and setters?
table, yes
for each table
I posted my code several times here and got no tips at all
because you dont learn anything
we give you help and info to learn about it but just complain instead
it's a shocker how many people come into this channel and learn using the exact methods we're using to teach you
and succeed
how do you learn without testing the limits of your existing knowledge?
you want me to say thank you and come back with same question 5 mins later cuz I didnt get it at all?
It’s because they reflect
yes
go and test with the code, once you understand how to use it make something
Method
its a shocker that you want to cast statistical majority onto everyone
try and find some new things to use it
best method around
Ikr
i might not understand something new, i get an example and dont understand so i try and find some code usages or ask how to use it and then i can test it out
You want to come here and write perfect code (because you have this aversion to realizing your initial code will be terrible and you'll improve it as you learn more concepts) without putting in the effort to learn it yourself. You want us to put more effort each (and there's like 4 people here trying to teach you) than you want to yourself... at least this is how it's coming off
@chrome beacon how'd you learn GLSL Shaders?
Dying
olivio i orded my pc upgrade stuff, arrives thursday
happy times
woah so you didn't go to a discord for 24 hours but instead used posted resources (and asked anything that confused you after)?
sorry, I'm using you as an example bro
Why didn’t u ask us ? @chrome beacon
Well do you know anything about them?
LOL


