#help-development
1 messages · Page 2012 of 1
i do kinda like math
You will not like this math 
why
Get the difference of the starting yaw and ending yaw, and the same for the pitch
Yeah I tried that, and then limited it to a maximum of 5 (for the difference) and I just started spinning around 💀
I also wrapped it so it couldn't go into negatives.
I’d be willing to explore this further at another time but currently I’m “””writing an essay”””
fair, gl man
I’m looking for a gui lib that can open guis asynchronously. I need to populate it with stuff I pull from sql. Does anyone know of one that can do that? None of the ones on spigots list of gui libraries could do that (at least without modification as far as I saw). It would also be nice if after clicking a button it would prevent it from being pressed again for a couple seconds (I could probably modify the lib to add this behavior but I would really like the asynchronous part
ugh I need help. why is the memory usage of my bot constantly rising, and also the number of tasks? both tasks and memory increase by about 1 every second and I don't know why. full source code: https://github.com/JEFF-Media-GbR/DiscordSpigotUpdateBot
I am confused and need heeeeelp D:
Problem With Build Path?
I believe it has something to do with OkHttpClient because normally I always just used the native ways (InputStreams etc) and never had that problem
I got it using
Dispenser dispenser = (Dispenser) block.getState();
bsBlock.setType(itemType);
dispenser.getInventory().removeItem(item);
event.setCancelled(true);
dispenser.getInventory().removeItem(item);
But I have an issue
If there are only 2 blocks in the dispenser it wont remove any.
How do I fix this?
and the 2ed removeItem doesnt seam to do anything
hm it seems like my garbage collector is just veeeeeeeeeery lazy, it now stoped to use more RAM at about 200M and also tasks stopped to raise at 299... maybe I just have too much free RAM lol?
xd
I realized
bro did he just
I found the problem. I created a new OkHttpClient everytime I needed to do a new request
instead of just reusing the existing object
well normally no problem
no idea why it keeps in memory
it should normally be garbage collected
I'll go back to regular inputstreams
OkHttpClient sucks
I'm on java 8
Ah that why
how would i get the current item held by the player?
?jd
public class CompassHub implements Listener {
@EventHandler
public void CompassClick(PlayerItemHeldEvent e){
Player p = e.getPlayer();
p.get
if (p.getInventory().getItemInMainHand().getType() == Material.COMPASS && p.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase("hubtp")){
p.sendMessage(":hi");
}
}
}
i have this, it works, but it only says hi after i move slots
That's PlayerItemHeldEvent
The event is sent when a player changes hand items
what are you trying to do?
well, when a player clicks with a compass in there hand i want it to say hi
then why are you listening to PlayerItemHeldEvent
then use PlayerInteractEvent
Isnt deprecated or abstract ?
So we should not use it?
no?
I rember someone told me
no
I don't mean to be condescending, but you should really make use of the javadocs
When i was doing my menu api
no
learning to read the documentation will clear up a lot of confusion for you
and help you understand what events to use and the methods made available by them
I rember that i was doing my menu api and someone told me that InteractEvent was abstract and that i shouldnt be using it
Sorry if im an idiot, but its still not working.
Is there a reason why my chance is 0.00, instead of its actual chance?
Number percent = ((conf.getInt(rewardData+s+".Weight")/chance) * 100);
String form = new DecimalFormat("###.##").format(percent);
itemLore.add("Chance: " + form + "%");
chance = 85
weight = 15
there is no InteractEvent
Cant figure out why
I didn't think so, I just assumed it could've been a thing
lol
Ah
Cast either chance or weight to a double
Ah yeah that was
i did player interact event and nothing is happaning
Did u debug?
Kk
@young knoll Your amazing. Why do it like that however?
no
Is there a reason why they make it formatted like that
Seperating doubles to numbers to integers
they seem the EXACT same
Because when dividing two integers
You get an integer back
So anything from 0 to 0.999999 will just be 0
Integers do not have decimals
Doubles do
Code.
float too
Huh
public class CompassHub implements Listener {
@EventHandler
public void CompassClick(PlayerInteractEvent e){
Player p = e.getPlayer();
if (p.getItemInUse().getType() == Material.COMPASS && p.getItemInUse().getItemMeta().getDisplayName().equalsIgnoreCase("hubtp")){
ItemMeta m = p.getItemInUse().getItemMeta();
m.addEnchant(Enchantment.VANISHING_CURSE,1,true);
p.getItemInUse().setItemMeta(m);
}
}
}
That seems weird though, for example: Is there a difference between float and double
Yes
double has a larger number limit
It’s complicated to explain, floats will be more precise closer to 0
get main hand?
Hmm, so basically, 4 number types for different purposes an applications
That, and there's a method from the event itself that should provide the ItemStack that was clicked
I really urge you to familiarize yourself with reading the documentation because you're just going to have a bad time throwing stuff at the wall and hoping it sticks
also, @young knoll, here is why ive been asking so many questions:
Just so you know xd
I don't like OkHttpClient
I got it working, I just find it weird that creating a new client stays in memory forever and is not GCed
I thought that if I create one and then derefence it, it'll be gone
but that's not true
Did you check that you fully de-referenced it
yes, but it schedules its own tasks
Ah
I never had it in any fields, only in local vars
So I imagine it has a close method or soemthing
Yep
even closing it manually didnt do anything
Auto closeable is nice
everytime you create a new OkHttpClient, it stays in memory forever
I just didn't know that and it still feels weird that it does
imho it should be disposed of as soon as it's no longer references but yeah of course that won't happen if it decides to create its own tasks
You know what isn’t nice, the fact that the minecraft server is closable
Which means you get yelled at for not closing it when you use it
I recently get people on my discord claiming one of my plugins is at fault when their world breaks
then in 99% of cases it's them force closing the server every time
"I dont want to wait for it to shutdown everytime"
then somehow they think it's related to some of my plugins
lol
all I can say is Unsafe.getUnsafe().putAddress(0,0);
Unsafe: because java neutered reflection :(
im trying to send a pluginmessage to bungeecord and use completablefuture to wait for its response, but the thread never continues, even after a response was received:
I was doing my own lib for http request on Java 1.8 but never finished because i didnt understand how to catch the reponse
?paste - For long codes
sorry, didnt know that
No problems
Just join there, paste your code, press CTRL + S, copy the url and send it here
am I stupid?
This must-have library lets you reliantly and instantly crash the JVM.
is there a typo in "reliantly"?
IntelliJ says there's typo but doesn't suggest any better spelling
i didnt understand mfalex
i forgot which ones the name of the project, artifcatID or groupID
artifactId
thanks
group = "username"
artifact = "plugin"
e.g. one group can have many artifacts / one developer can have many plugins
so a "group" groups different artifacts
idk, maybe this helps you remember
maybe it doesnt
that's what I wrote
anyway, here's my new awesome lib - must have for every spigot dev https://github.com/JEFF-Media-GbR/CrashLib
Is it async
this is my favorite part
Where that from=
Please every picture burns and fries my eyes
from my CrashLib, I sent the link 5 messages above
^
.
Lamo i dont know how you can develop on white : thinking:
Alex will get made fun of for light mode for all eternity
Back in my day we didn’t have dark mode!
no
It has a light mode
in porn mode (+ not logged in) it defaults to white
Yeah
Its amazing, to be all dark with rbgs and mfalex with all light things
it's because I am a happy mind
My bedroomhas the light off my mouse, keyword, headphones, and table have rgbs on
I wish i had rgbs on bathroom to dont turn on the light and get literally shocked
I don't even have a bedroom
Isnt a way to setting a global runnable on Intellij for running things? Because everytime i change the project i have to configure again the Spigot path, ram, etc
😮💨
I dont even know how to make intellij start spigot at all lol
I have a few classes for storing player data. Mainly two, NetworkPlayer, which holds things like rank and gold for players that are offline, and OnlinePlayer, which holds a ton of other data for only players that are online, OnlinePlayer extends NetworkPlayer. I have a system, so that when a player joins, it checks if there is a currently cached NetworkPlayer for their uuid, and if so, turn it into a OnlinePlayer, if not, make a new OnlinePlayer. for some reason, when a player joins for the second time none of the stuff in OnlinePlayer effects the player, like sending text to their title. I did some debugging and the caching works, idk what is the issue. HEre is the code: https://paste.helpch.at/nokibapixo.cs
Thanks in advance!
try running it in the main thread instead of async
wdym
that'd be nice
the issue isnt with async tasks
I have a method, getCachedPlayer, java public static OnlinePlayer getCachedPlayer(OfflinePlayer p) { for (OnlinePlayer sp : cachedPlayers) { if (sp.getPlayer().getUniqueId() == p.getUniqueId()) return sp; } return null; }and this is returning null
.equaks'
even though the arraylist has stuff in it
Your onlinePlayer holds a Bukkit player object right?
yeah
a bukkit player is only valid as long as the player is online
once they reconnect, they get a new player object
yeah
so you have to get the new player object everytime they rejoin
the online player object gets yeeted when they leave
and gets recreated when they join
hm
hence the removeplayer method in the code provided
its been so fustrating
cause I cant find the issue
well hard to say without seeing more code or without you telling us what EXACTLY doesn't work, like - what line of the code you sent, etc
in the loop print both
uuids
try that and if 2 are the same
sp.getPlayer().getUniqueId().equals(p.getUniqueId())
as opposed to
sp.getPlayer().getUniqueId() == p.getUniqueId()
Allright (On intellij):
- Click on the button called "Add Configuration"
- Add new and select "Jar Application"
- Configure your spigot jar path and vm options
yeah but how would that use maven to compile my plugin and also copy it there?
never use the == version for UUIDs
Using maven you use the label: <outputFile>Your server plugin path</outputFile>
And if its a shaded jar you put the path + jar name.jar
yeah sure but then this would also affect my normal maven building
No
The jar will still bein inside the target folder
The outputfile just copy and the paste the jar
Or at least in my case does that
The vm options its: -Xmx or just Xmx?
I dont rember if it contains the "-" first
Allright thanks
So, im trying to create a class where I store all my data, instead of all in config.
Is this a good or bad idea?
good idea
as long as u save it to config
when the server stops
or do it periodically
I meant more or less like, for example, what crates have in them but yea
Also, how would I do this?
how would i make it so i run a command, and that activates an event listener?
It doesnt let me update a HashMap right inside a class
do I have to do it inside a function
you cant run an event
only bukkit can
yea
like private static void setupData()
yes
you can run an event, if you are careful
?
ur not supposed to do that
depends on the event
what kind of event u wanna run
I have a plugin that spawns a creeper everytime you break a block. How would I make that toggleable through commands?
store a hashmap somewhere
of a <Player, boolean>
and then when the command is ran
you don't need to run an event. just set a boolean toggle to early exit from the listener
ok
set the player's value in the hashmap to true/false
and then in the blockbreakevent
check what the player's value in the hashmap is
if its true, spawn creeper
if its false, don't
ohhhh
How do I allow a HashMap to contain multiple key types
like:
"A" = 1
"B" = "C"
"C" = 1.0
and so forth
HashMap<String, ?> basicCrate = new HashMap<>();
This doesnt seem to work, and research got me nothing
Yes I did search this issue up first
Ill send the code rq hold on
cratesMain = new HashMap<>();
HashMap<String, Object> basicCrate = new HashMap<>();
ArrayList<String> basicCrateList = new ArrayList<String>();
basicCrate.put("Items",basicCrateList);
basicCrate.put("Amount",5);
basicCrate.put("Name", ChatColor.GREEN + "Basic Crate");
cratesMain.put("basicCrate", basicCrate);
Am I creating this wrong?
Like is this inefficent
This
u would have to cast
back to the String or integer object or whatever
really bad practice to use object
public static HashMap<String, HashMap> cratesMain = null;
public void setupData(){
cratesMain = new HashMap<>();
HashMap<String, Object> basicCrate = new HashMap<>();
ArrayList<String> basicCrateList = new ArrayList<String>();
basicCrate.put("Items",basicCrateList);
basicCrate.put("Amount",5);
basicCrate.put("Name", ChatColor.GREEN + "Basic Crate");
cratesMain.put("basicCrate", basicCrate);
}
I mean I kinda already did
CrateData.cratesMain
or should I do CrateData.Data
idk lol
its weird cause some it works, but other stuff doesnt, and it works on the first join, but not second
good lord
No
just make a Crate class
And then store that in the map
Can somebody send me a site to learn that?
See
Confused on what you mean
?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.
ty
Class is a very basic concept
java is a very classy language
Heh
The hashmap enthusiast is disgusted by your use of a hashmap
That’s not a good sign
lol
Hey, can somebody point me in the right direction for setting up publishing for this: https://github.com/WeaponMechanics/MechanicsMain
I've set up my settings.xml in my .m2 folder, but I am unsure what I need to put into my repo.
stop trying to make your thing work
can someone walk me through adding nms to maven?
im not i just deleted all the code
im trying to figure out how to do what you said
..how to make a class?
run buildtools with whatever revision you want then delete the -api from the spigot-api dependency 
I know how to make a class
public class CrateData {
}
Thats already done, im confused on what I need to add to the class
Exactly
Heres the config.yml file
Crates:
basicCrate:
Items:
0: DiamondRewardBasic
1: EmeraldRewardBasic
2: GoldRewardBasic
3: IronRewardBasic
4: TNTRewardBasic
Amount: 5
Name: Basic Crate
Color: GREEN
rareCrate:
Items:
0: DiamondRewardBasic
1: EmeraldRewardBasic
2: GoldRewardBasic
Amount: 3
Name: Rare Crate
Color: BLUE
crateRewardData:
DiamondRewardBasic:
Material: DIAMOND
Weight: 3
Amount: 2
EmeraldRewardBasic:
Material: EMERALD
Weight: 5
Amount: 5
GoldRewardBasic:
Material: GOLD_INGOT
Weight: 20
Amount: 16
IronRewardBasic:
Material: IRON_INGOT
Weight: 45
Amount: 32
TNTRewardBasic:
Material: TNT
Weight: 10
Amount: 16
The items it can roll
Man that's not a good way to structure that
if a crate is fixed once created use a record not a class
Yeah records are great
never heard of that before
it is
so how do i make it actually work however?
this entire time i thought classes were just to hold functions
so now im extremely lost
basically it handles all the field setting and gives you a read only object back
I don't think you should be messing around with the spigot api if you don't understand the fundamentals of java
So make a playground workspace that is just plain java, not a spigot plugin
I know how java works, I just dont understand this lol
Find a tutorial you can follow and learn the basics of OOP and mess around with it in your playground
No you clearly don't understand how java works
read up on records, they are handy
If you understood how java works then you wouldn't be running into this issue
Send me a video>?
Ill watch it, and learn that
At this point id rather watch a 2 hour tutorial on all of that
Then have to be confused
This video on Java OOP Basic Concepts. This Object-Oriented Programming Java video will help you understand the fundamentals of Object-Oriented Programming in Java with practical examples for a better learning experience. 🔥Enroll for Free Java Course & Get Your Completion Certificate: https://www.simplilearn.com/learn-java-basics-skillup?utm_cam...
found one
lol
I'll do you one better https://www.youtube.com/watch?v=xk4_1vDrzzo
public class data {
String name = "";
List<ItemStack> items = new ArrayList<>();
int amount = 0;
}
12 hours lol
@quaint mantle
12 HOURS
almost half of it is over java swing

ew
ehhh its just an example
so would I have to make a class for every crate then?
At least capitalize it
mike
No
You need to understand what a class is
do i need all this
A class is a template
in my pom
A blueprint
Im watching the video rn
You can create multiple instances of a class
Each one has its own values in the fields
so new Class()
in a sense
class as in the classes name
That's how you create an instance of a class, yes
.. Okay but how would I know if its a Basic, rare, etc crate?
How would it return the correct info?
Stop worrying about that right now
Yknow nvm ill watch the video
Yeah please do
It will be much easier to approach once you understand OOP
But don't expect it to click immediately
For some people it takes weeks or months to really click
The best way to get a handle on it is to follow some tutorial(s) and then mess around with it in a playground just to get a feel for it
Same thing happened to me in LuaU
learning how modules work (which is VERY SIMILAR to java classes and OOP)
took a while before it clicked
LuaU uses oop actually as a lil fun fact
You can model oop behavior with metatables but it's not an oop language
In very small parts of it
Well yea
@waxen plinth wait so
public class CrateInfo {
String name;
int version;
public CrateInfo(String name, int version){
this.name = name;
this.version = version;
}
public static CrateInfo newCrate(){
CrateInfo newCrate = new CrateInfo("basicCrate",1);
return newCrate;
}
}
This would be considered oop correct?
If im learning this correctly
no
remove newCrate, you can overload methods
if you want yoru static method to be useful it shoudl return a new CrateInfo
and constructors
return new CrateInfo("basicCrate",1);
so you can make another constructor with no params that sets the name and version to basicCrate and 1
so like that correct?
polymorphism goes hard
how do i make a boolean public?
public boolean
I mean acssesible from another class
public boolean
You could do this using record java public record CrateInfo(String name, int version) {}
HOLY CRAP I UNDERSTAND THIS NOW
alright
yea i may make stuff to update it in the future
so ill leave it as it is
wait so.. this also supports lists and such
correct?
it's the same thing as a regular class but with a private final var and no setters
and it handles setting all vars for you, also creating hash. toString and equals method
What do you think? :D
Message senderMsg = Message.builder().text("&3Active players &f" + Bukkit.getOnlinePlayers().size()).build();
Message playerMsg = Message.builder().open("&3Follow us :D", "Hover message", "url link here").build();
senderMsg.send(sender);
playerMsg.send(player);
stop posting screenshots of my blog
otherwise you'll have to pay me
9 billion $
what currency
why isnt there a delete button in intellij
zimbabwe dollars
German dollars
Don't we all. Probably in the wrong place to make that tho
what's your problem?
nothing i got it working
What your issue ....?
I have a problem and i want to ask that how to stop silent joining in my server?
okay nice 🙂
ok
Wrong channel
well if you don't need NMS, you don't need it
if you need NMS, you definitely want to do the stuff from that post
what does it actually do?
i added the dependency only, and I had all of the classes imported
1sec
If you say you need NMS for something dumb enough you can summon MD_5.
NMS is for using base MC stuff outside the scope of the API.
tbh NMS is still needed for so much stuff that should be API
e.g. creating a simple hologram
they dont call it no mans sky for nothing
*client side hologram
exactly, so doing holograms is a valid reason for NMS
huh? really?
opening books is not possible? are you sure?
declaration: package: org.bukkit.entity, interface: Player
Player#openBook
smh, everyone here still thinking in 1.8 API lol
Start start = new Start();
would this line acsses the class named Start? Im using "if(start.boolName)", but its not working
Is the boolName public
or static
are you trolling or drunk?
Hey
im 13
It doesn’t have to be an “or”
so trolling
yes it is
No 1.16.5 but I can't remember what the issue was I had that required it
can u send the start class
If you have an instance of Start, and start has a public bool named boolName that should work
huh
yeah it was also just a joke lol
I know that openBook and openSign are quite new 😄
I stopped doing 1.8 cause it gave me the 1.8 brain tho
openBook isn’t super new
how does that have 2.9m views
openSign is 1.18
I wish the API docs would have a @since tag
Bro code coming in clutch 🥶
Fun fact, open book very briefly changes your held item to the book
And forces you to right click
Essentially
my start class:
my other class:
that should be fine
it's not working
im very happy rn
public class CrateInfo {
String name;
int version;
public CrateInfo(String name, int version){
this.name = name;
this.version = version;
}
public String getName(){
return this.name;
}
public int getVersion(){
return this.version;
}
public static CrateInfo newCrate(String name, int version){
return new CrateInfo(name,version);
}
}
i learnt OOP
lol
you created one start object for your listener
and obviously you made another instance of it for your command
so whenever someone does the command, your listener's start class object will never change
I am pretty sure they want it toggleable per player
not the static constructor 😭
erm yeah
sorry
the static constructor is 100% useless lol
also one question
how would I return a list of every available Crate?
in the class?
getters and setters
make a list of crateinfo
in what class
can someone help me with this, thanks :)
do you want it toggleable per player
i want it so one player runs the command and it effects the hole server
so public static creeperSpawns
public static boolean creeperSpawns = false
yeah that'd do it
yes
thanks
but
@night torrent
do you know what static does?
because it's important to tell people what it actually does
before telling them to use it
okay, well if you know it, I wonder why you didn't then make it static right away 😛
+1
im not very smart
also
And what about google?
nvm
i looked for abt 15 mins
Dont tag
do you actually know what static means? If not I'll happily try to explain it within 3 sentences
sorry, they helped me earlier so i pinged
ngl i do struggle with it
Okay I'll try to explain
i looked it up once but i didnt retain it
wdym
you wanna remove a crate from the list of crates?>
if I wanted to i mean
remove a crate from a list
list.remove(crate object)
Isnt that a java staff?
some people like registry classes for stuff like that but personally I just have a private static var
@night torrent Imagine you have a Human class that has three fields: Name, Age, and Planet. Of course, we have 8 billion different humans. They can all have different names and different ages. But all humans that we know have the same planet, which is earth. So. in this case, "Planet" is the same for every human. No Human (as we know of) will ever have a different Planet. That's why Planet does not refer to any individual human, but to all humans. so Planet can be static, meaning it belongs to the class itself. Age and name differ between humans so it must be changable PER individual human, so those are not static
I still think he didnt learn Java and just started using the api
Hey, can somebody point me in the right direction for setting up publishing for this: https://github.com/WeaponMechanics/MechanicsMain
I've set up my settings.xml in my .m2 folder, but I am unsure what I need to put into my repo.
ohhh
static = belongs to the class
not static = belongs to the invidiual instance of this class
You want to deploy your dependency or your code?
that was actually a really good explanation thanks
np 🙂
OOP, where have you been all my life
half my coding wouldnt have been so hard if i was using oop
im disappointed
code. I want people to be able to access my api without manually downloading the jar
go OOP as much as you can
i mean im trying as much as i can xd
yeah I try my best
Allrigh so its the first option, you want to deploy your dependency package
the idea of oop is so cool to me
So people can import it using your github repo
if someone cannot explain something in 2-3 easy sentences, the person trying to explain hasn't understood it themselves
@night torrent that would look like this https://paste.md-5.net/vazisowuli.java
oop is godly is the basis of it lol
By the way, related to oop, so by a list of crates this right?
public CrateInfo(String lowName, String detailName){
this.lowName = lowName;
this.detailName = detailName;
crateList.put(lowName, true);
}
public HashMap<String, Boolean> getAllCrates(){
return crateList;
}
public Boolean getCrate(String lowName){
return crateList.get(lowName);
}
public boolean removeCrate(String lowName){
if(crateList.get(lowName)){
crateList.remove(lowName);
}
return true;
}
I’ve never seen static described like that
Why would any of these things be booleans
cause its a HashMap, value is true
because I dont need a value for it
..what
Well a list, to grab it requires an int
so to make it easier to find
im using a string, by using a hasmap
Ok what you're describing is a HashSet
Which doesn't map keys to values, only holds them and you can check contains
?
But that also doesn't make sense in this context
I don't get why you're doing it that way
So that if it exists, I can grab it later
without creating a new crate
and access the data
Right and how does a Map<String, Boolean> help with that
HashMaps are like two lists side by side but insane and on steroids if you know what I mean, you should look at Bro Code's list chapter https://youtu.be/xk4_1vDrzzo?t=7590
That is a really bad comparison
A hashmap is not like two lists side by side
when in doubt, watch Bro Code
say that one more time I dare you
@waxen plinth
HashMap<String, CrateInfo> crateList = new HashMap<String, CrateInfo>();
public CrateInfo(String lowName, String detailName){
this.lowName = lowName;
this.detailName = detailName;
crateList.put(lowName, this);
}
public HashMap<String, CrateInfo> getAllCrates(){
return crateList;
}
public CrateInfo getCrate(String lowName){
return crateList.get(lowName);
}
public boolean removeCrate(String lowName){
if(crateList.get(lowName) != null){
crateList.remove(lowName);
}
return true;
}
there it returns this
so the value itself returns it
yesss
also
for remove crate
just do
That makes more sense, yes
if (crateList.contains(lowName)
A map links two things together, a key to an object
containsKey*
But you really need to make that map static
sure
Idk how to go more laymen than that
And all the methods too
containsKey*
there
Basically everything there should be static since it doesn't belong to any one specific crate
You also don't need to check contains in order to call remove
Just call remove, and it will return the old value if there is one
oh alright
why does remove return a bool?
Classes in and of themselves are not oop though
god @waxen plinth tysm for telling me about OOPing in java
you have NO IDEA
how happy I am
Keep looking
I had to make so many workarounds for code
You're far from done
ah
You are only scratching the surface
they should be static
unless u have a singleton
Oh- alright
You can get a hell of a lot deeper with it
oh its not letting me chance the ones that contain "this" into static
This is literally just one class
also it works fine without static lol
just replace this with the class name
What no
That's not how anything works
Are you trying to make the constructor static
.-.
i mean the hashmap, getter and remover
ah
not the constructor
Yeah you can't make the constructor static
there
Make all the other methods you showed and the map static
Do you understand what static means
theres only 1 instance of that variable and it belongs to the class
https://blog.jeff-media.com/a-basic-explanation-on-what-static-means tbh this is probably the most concise analogy I've ever written lol
oh so everything has the same value
basically
every person has the same “Planet” attribute in common, so “Planet” actually has the same value for ALL humans.
based on how you stated it means lol
its just so you dont have 2 different versions of the hashmap
there is only ever 1
OHHH
so it doesnt allow duplicates
no
What
if it's not static it's individual to each object
That's not a good analogy
oh i read that ENTIRELY wrong
"planet" is still a property of a person
The fact that it's the same for every instance doesn't make it static
that was a great analogy what are you talkin about
No it's really not
no, there is not a single human we know that was not born on earth
So?
It still would not be static unless there is literally no possibility of a human ever being born elsewhere
Man it's frustrating helping people here sometimes
lol
so we could easily say stuff like
Human has a static field Planet = EARTH
and non-static fields Age and name
it gets the point across, even including name and age that aren't static in comparions
No you wouldn't make that static
It gets the wrong point across
That's not what static means
Static means it is a property of the type itself, not each instance
do you now want to tell me that some humans ever went into space 2000 years ago or what
Being born on earth is not a fundamental property of being a human
property of the class, not instance
If someone was born on mars they would still be human
If someone was born in the ISS they would still be human
yes true but it's an analogy
And you're really just making it seem like a static field is a constant
Which is not the case
okay, call the variable "homePlanet"
Yes it's not a good analogy
now what
honestly we should all just go watch Bro Code's explanation on static
okay please tell me a better way to explain "static" to someone who didnt understand it yet
Call it homePlanet and make it an instance field
im more confused on static now cause of this lol
🙃
but i do know the difference between private and public
public means it can be viewed by other code
private means not
from what ive seen
yesd
AND it uses spongebob
I think my Human.Planet explanation is preeeeetty good to explain it
It's not
?paste
oh fun fact, never ever was any human on another planet
It falls apart if you think about it past the surface level
it IS about the surface level though
Dude I am really not in the mood for going in circles about this right now
it is to explain it to beginners
Yeah and giving them an analogy like that will make them think about static in the wrong way
Static =/= constant
as said, I'm waiting here for a better real life example
Sure
I didnt say constant, I just said "planet" is what all "humans" share
which is true, no human was ever born outside of earth
All of its instance fields are what you would expect
Name, age, place of birth, whatever else
and no human ever visited ANY other planet at all too lol
A static field you might use in this case could be population
Which would keep track of how many humans there are
let's hear out what Bro Code had to say about this:
You have a class, Friend. In this class there is public static int numberOfFriends. Everytime there is a new friend, this number increments. Everytime someone does, it decrements
It would be incremented when the constructor of Human is called, and decremented when you call Human#die or whatever
in the planet class a static field could be "solar system"
well I guess my explanation made them understand static while yours doesn't really
no?
Name, age, place of birth are all properties of an individual
no
The population is a property of the class
It's more abstract and describes the type itself
planets belong to all kinds of solar systems
And the information does not belong to any one individual
there wasn't a single human who ever visited another planet so I guess it's kinda safe to say that planet right now can be a static field
Alex
Can you please stop
You're just saying the same thing over and over and it doesn't make your analogy correct
It's misleading
human has age, name, dob, but a static field is like their kingdom
And it's getting very frustrating
yeah
Population is such an easy analogy
it is not misleading, it may not be 100% correct but it explains it to someone who cannot differentiate between classes and instances yet
because every human belongs to the kingdom, as they do earth
...
and someone who can differentiate between classes and instances doesnt need an explanation anymore anyway
And population is 100% a valid usage of static
why would population be a property related to human, it should more like belong to the planet
Planet is not because it breaks as soon as a human is born anywhere but earth, and it also conflates the idea of a constant with a property of the type
CrateInfo crate = CrateInfo.newCrate("basicCrate", "Basic Crate");
crate.addItemToList(new ItemStack(Material.TNT,16));
@waxen plinth cant thank you enough seriously
public class Human {
public static String kingdom = "Animalia";
public String name;
public Date dob;
public int age;
}
all humans belong to animal kingdom
this is so helpful its not even funny
Sure, that works too, but it's also a constant
If you want people to understand static you shouldn't use a constant as your analogy
Because they might conflate the idea of static with constants
public class Human {
public static String kingdom = "Animalia";
public static String type = "Mammal";
public String name;
public Date dob;
public int age;
}
public static float gayPercentage
Which is why population is a much better analogy
All humans are mammals, and belong to animalia
not all humans have the same name, dob, age
Yes, but again, those are constants
I agree with that, but I disagree that population is better in any way
So you agree that it's better to not use a constant
I'd use the private keyword over public for the individual fields
yes, sure
But you also disagree that my analogy which doesn't use a constant is better
yeah
exactly because imho "population" doesn't belong to the human class, but to the planet they are living on
You could make that argument, sure
you also wouldn't store the amount of produced cars in a car but more in the car factory
You can almost always make the argument that some static property could instead belong to a manager class
But for the purpose of analogy, population works perfectly fine
It could be universal population rather than population on a single planet
yeah
It's not conflating it with constants, and it's not breaking the design of the class
you wouldn't do someVwCar.amountOfProducedVwCars but more like VwFactory.amountOfProducedVwCars
this is based
lexus?
what about beamers
Seriously though please don't use the planet analogy, you're only going to confuse beginners
okay Redempt
You don't have to use the population analogy either
lets think of an example we both think is perfect
Bro Code has the example you want https://youtu.be/xk4_1vDrzzo?t=13227
I don't think you're really going to get something simpler and more analogous than population
Like you can make something that is more technically correct
But it's going to be more complicated and potentially go over their heads
that's only going to confuse beginners on where to store their statics then
And you can almost always make the argument that some static property could belong to a manager class instead of being a static member of a pojo class
population count isnt a property of human, it's a property of planet
Not necessarily
depends
It could be the universal count of all humans
population of all humans ever?
^
yea exactly
"how many humans currently exist?"
It's perfectly valid to make that a static field
Making it a property of a planet would complicate things a lot
it wouldnt
the definition of population would not complicate that at all
to properly portray your analogy
...
Human.numberOfHumans would make total sense to me
You're just being pedantic
but not population
Okay then call it numberOfHumans
that'd make definitely make more sense to me
Great I'm sick of this argument
Call it numberOfHumans and let's move on, this has been so pointless
but I doubt that people would understand it as well
I am literally just trying to find a valid analogy so people can easily understand what static actually means
It's not a property of any one human
somehow the planet thingy helped someone undertsand it immediately
They said they understood it, you mean
But that doesn't mean they understood it correctly
lets say you are making a multiplayer video game. you have a "server" class, which you need to store a list of players. this would be non static, as the game could have multiple servers. but if you wanted to store all the players across all servers it would be a static list
what they understood is that static belongs to the class and is the same for all instances
and that's everything I tried to explain
This is a more confusing analogy
honestly all beginners need is that static vars are shared
yeah that's much mre confusing
I feel like there would be 2 lists, one of local players and a static list of all players, or a hashmap of Player, Server
yeah but we want to have a real life analogy
because
beginners do not understand the difference between class and instance
that's exactly the hardest part for many people
yes the server class has a non static list of players, and then a staticlist of players which is global
I remember my teacher used students at a school, where the school is the static var
public class CrateItems {
String findName;
ItemStack item;
Integer weight;
static HashMap<String, CrateItems> crateItemList = new HashMap<String, CrateItems>();
public CrateItems(String findName, ItemStack item, Integer weight){
this.findName = findName;
this.item = item;
this.weight = weight;
crateItemList.put(findName, this);
}
public HashMap<String, CrateItems> getAllItems(){
return crateItemList;
}
public CrateItems getItem(String findName){
return crateItemList.get(findName);
}
public static CrateItems newCrateItem(String findName, ItemStack item, Integer weight){
return new CrateItems(findName,item,weight);
}
}
did it work
im vibin rn
yep, that's exactly what I did
in my case I just used planet earth and not your school
get all item should be static
public void broadcast(Boolean component, Message message) {
component ? Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(message.getComponent())) : Bukkit.broadcastMessage(message.getText());
}```
its telling me that its not a statement
and getItem
ty
But not every student is in the same school
do you know what a getter is?
He was just referring to our school
redempt is right that I only explained what a static CONSTANT is, but that doesn't make the argument invalid that I explained
not 100%
I think ternary requires assignment
like i said im still kinda learning
because a static constant is still a static property
Hmn i didnt understand explain in diff words please
say you have a private string name variable. you create a getter so that classes outside of that instance can access it
public class Items {
private String name = "item";
public String getName(){
return name;
}
}
OHHH
i see
public class OtherClass {
public Items items = new Items();
String name = items.getName();
}
@earnest forum So if its ouside the class, its still accessible to use
THATS AMAZING
now create getters for the 3 variables
yes.
theres also setters,
ternary requires assignment somewhere, like for(int i = 0; i < (n < 0) ? 0 : n; i++) or int n = x < 0 ? 0 : x
Repeating this question from earlier:
Hey, can somebody point me in the right direction for setting up publishing for this: https://github.com/WeaponMechanics/MechanicsMain
I've set up my settings.xml in my .m2 folder, but I am unsure what I need to put into my repo.
Oh so i cannot do what i was doing?
public class Items {
private String name = "item";
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
}
no, those are for if you wanna change it outside the class
only make these if you want the variables to change
no
you can refactor it into an if else quickly though
No please
I dont like if else
Loks really ugly the code
I changed to using if + return, for dont use if else
hahaha
yay my memory leak is fixed
NICE
In my case Intellij its leaking my memory
here I wrote it for you ❤️ java if(component) { Bukkit.getOnlinePlayers().forEach(player -> player.spigot().sendMessage(message.getComponent())); } else { Bukkit.broadcastMessage(message.getText()); }
Idk what the fuck intellij is doing but with 64 gb of ram looks like an old car
Its really slowly idk what happening
Java its so amazing that it doesnt allow you to have 2 method with same name and same Argument, but using diff method from the argument
How would you have 2 methods with the same name and arguments
you dont
If java allow that i wouldnt being having 4 methods for doing exactly the same but just cuz java its so annoying i have to have the 4 methods
Repeating this question from earlier. I want to publish my code so people can access my api without manually downloading the jar file (Allow people to use maven). So I have this gradle project https://github.com/WeaponMechanics/MechanicsMain that I want to publish.
It's difficult because it is multiple modules, and it builds 2 separate jar files. I have already set up my local .md > settings.xml file, but I don't know what to do for my next step. I've tried looking at other spigot plugins on github but I haven't had any success in finding help.
I made my own maven repo. You can always do the same if you have a webserver
personally since I don't have my own web server setup I use repsy.io though I'm sure you could find plenty of tools out there
Jitpack works as well for anything at java version 17 or 8
Maven and Gradle deploy plugins do PUT or POST request?
🤷♂️
Jitpack is notoriously shitty
Because i set a express POST listener, and didnt receive anything from the maven or gradle plugin
Did you configure your repo properly?
Im using an Express webserver, that has a POST request listener (I done it to debug). And them on the maven config i tell to do the request to the post listener
And i didnt receive anything
Understand?
Oh lmao i will use translator again
Yes. I don't use express so idk