#help-development
1 messages · Page 2088 of 1
its funny those questions may seem simple and dumb at first but in the end the detail is in their exact implementation
and can thus change its ultimate usage
xD
ye lol, disadvantage of abstraction
ppl always ask me
why i write so much low level in java
simply cause u have more control xD
and im too used to it anyway
in for example my ini parser, which is written using primitives
cant see a disadventage here
mye I mean its a dilemma, writing too coupled code and it becomes deplorably suffering to work with
and iterating strings with low level methods
well
spigot abstracts over the storage implementation
the problem is that an api is supposed to help you
Good
yes but its a disadvantage as well
but if its not doing what you need and ur bound to it
I dont see any disadventage though
does anyone know why PlayerInteractEvent runs twice?
for each hand
oversights my man
like hasPlayedBefore works for anyone EXCEPT first time joiners
and when do you actually figure that
only very rarely
I mean just look at timinators case, we do not know for sure how hasPlayedBefore works from a high level abstraction point of view
?
if it was well documented, it would be ok
nah
its documentation says
checks if a player has played before
yay
the docs must not talk about the low level implementation
the documentation of an interface should only define the abstract contract of said methods
it should talk about functionality
in this case, this is functionality
I mean to some degree
it should mention unexpected results in certain cases
the low level doc would be like "checks if a player profile has been serialized, returns null if no file was found"
and thats what id need
it cannot talk about how IdentityHashMap disobeys the general Map contract
it cannot talk about the concurrency impl of ConcurrentHashMap or ConcurrentSkipListMap
the problem is that i misinterpreted it as its also a check for online players and thus coded in an oversight which i only found by chance by testing the plugin with a friend who didnt connect to the server ever before
Mhm
Well IdentityHashMap should talk about it
and quickly realized where the error is coming from
yes
it should define unexpected results in a certain case
it defines contract such as transitivity, symmetry etc
depends
sometimes they're too coupled with the concretion
In this case it isnt though
thats why i work with offline player
yes it is
because it'd have to define whether the check of hasPlayedBefore is using a cached value of if it uses a direct IO check as those would be the main error sources
which is definitively too coupled with the implementation
how do i make it so it only runs for the main hand?
check what hand it is
funfact did u know that by setting an offlineplayer op who is actually offline u can jank the vanilla command system
xD
jank?
are we talking about CraftOfflinePlayer or CraftPlayer merely?
cause its then missing the name value, and that causes the system to always throw nullptr errors when that players name is being retrieved for say auto completing the deop list
OfflinePlayer.setOp(true);
and it breaks vanilla commands
My guess is you got an invalid OfflinePlayer which would hav no name
nope
ive compared it
the uuid was correct
used my own to test it
but the name field wasnt existing
and that causes the other vanilla commands to break
Whats missing the name value
OfflinePlayer? it has the name value though
the ops.json file
as well as its version in memory
if you get an OfflinePlayer (by name) which does not exist, an OfflinePlayer object will still be returned but it will have a null name
i used my own name
its valid
i used the name of my friend
its valid
it is because OfflinePlayer seems to be missing methods
tf
to actually set a player
thats kinda weird
op
like ive said
if i use it on the player
and hes actually online
the server has no problem to set op for an OfflinePlayer instance
but if that player logs off
and is then set op
it breaks
How wtf
test it for urself if u cant believe it 😛
working with valid player objects after they logged out?
and then check the ops.json
its offlineplayer
thats a bug then @granite owl
that explenation isnt makign sense then
are you getting the same error using the console op command?
no issue
nope
only using the .setOp member from the bukkit api
So what are you discussing if no issue
one sec and I'll test it
the fact that you can not .setOp someone using an OfflinePlayer instance when that player is actually offline
I barely can believe this
me too
until it broke
xD
then ive written a system that checks if that player is actually online
and if hes not
his op will be updated
the next time he logs in
Why
is your usercache.json corrupted or something?
because i needed different behavior
which is
are there vectors with x, y, z, yaw & pitch in spigot?
which is what i receive alot of hate for. binding permissions to scoreboard teams
jst xyz
yaw and pitch would be with a location, but then you get the world as well
why not use PermissionAttachment
I just tested Bukkit.getOfflinePlayer("ElgarL").setOp(true); and it works just fine
probably a reason that you are lol
how do i set the yaw and pitch tho
You mean a Location? 
were u offline
yes, just started server. Never logged in
Location technically could be a vector
also had an empty usercache
and now
@granite owl lol?
why?
and see if autocomplete still works
Location#setYaw iirc
because thats where i got the nullptr error from
ofc it works since ops.json is correct
Same with pitch
You said your issue was with OfflinePlayer setting op had no name in teh ops.json
Ide should show all methods they'll be named relative to what they are
it worked perfectly with .setOp
knew it
"uuid": "2643e076-2434-4994-bd91-cb076d57f941",
"name": "ElgarL",
"level": 4,
"bypassesPlayerLimit": false```
v.toLocation(world).setYaw(10)?
well i mean i can try to delete the usercache but it did happen to me on 2 different server installations
Well, no, you would use a Location instead of a Vector ;p
u did it incorrectly then
What chocolate said ^
Choco****
Stupid autocirrecy
lol

OH BUT DONT CORRECT THAT OKAY
i got the player by his uuid
i don't understand
works perfectly fine here. Doesn't matter if I'm in the cache or not
"Autocirrecy"
idk then ur incorrect
Use Locations as your vector if you want yah and pitch
Or create your own vector class with these values

I can test using UUID
lets say i want to make a ray of particles with vectors, so i set the yaw and the pitch for the direction, then i set the location of where i want to shoot it from, and then i play a particle at the tip of the vector, add 1 to the length, and repeat
that's how we do it in skript lol

This is why I dont help from my phone lmfao
ahahah
does it score the colorcode of the particle?

xD
@granite owl Getting the Offline Player by UUID fails with no name Bukkit.getOfflinePlayer(UUID.fromString("2643e076-2434-4994-bd91-cb076d57f941")).setOp(true);
as they have never been on the server
and it retrieved the username?
No, they have never been on the server and getting by UUID does not perform a Mojang lookup
then use it on urself
so if you get by UUID, you MUST check the name is not null to ensure its a valid object
You seem to be confused
get an OfflinePlayer by UUID ONLY checks the local server cache of players
it will not get a name if the player has never logged into your server
did u try to op urself with a known user profile on ur local server installation
targeting by uuid
op from a valid OfflinePlayer object always works
think it’s pretty clear that it’s a bug with your code and not the entire api
I feel more ppl would of brought this issue up if it was the api
I will check it pulls correctly from usercache
will take me a minute. I have to update my MC as I've not logged in for over a year 🙂
sure xD
OK, odd. I can confirm fetching by UUID from Usercache does fail to set the name field in ops.json
afk 10, then I'll check soime more
?paste
so im not insane?
what does your shrink say?
I am
I'm having this weird bug, I'm trying to set it so every time the player click a green dye then it will vanish him and convert the green to a gray dye and the other way around
But when its on the green dye i have to click twice and when I had the if statements in order to try and debug it doesnt work at all
here is my code: https://paste.md-5.net/orizinipuf.cs
mmmm, this is a great place to use a switch case jyk
I will try and do that
Also when you change a material in a gui try calling p.updateInventory()
(If the item you edited in the gui doesn't update that is)
Ah, didn't know this was a thing
so you set it to grey dye and then you run the code for the grey dye 😛 - yeah a switch would avoid that
and speed up the time you are in that code a bit
the other alternative is to reduce your code and make the dye swap a generic function and call it by itself and swap colors - rather than separate tests
however that is a logic call and style thing on your part
What do you mean?
Also, what am I doing wrong here?
Material m = p.getInventory().getItemInMainHand().getType();
switch(m){
case XMaterial.GREEN_DYE.parseMaterial():
break;
}
Error : Constant expression required
A constant variable?
Oh
String m = p.getInventory().getItemInMainHand().getType().toString();
switch(m){
case XMaterial.GREEN_DYE.parseMaterial().toString():
p.sendMessage();
break;
}
Shouldnt this work then?
No because you need a string constant not just a string
ok finished testing. If the player data (from their last login) is too old/expired it will fail to fetch their data as an OfflinePlayer. As such the name will be null.
it doesnt need to be a string, your sort of complicating your test
just use XMaterial and GREEN_DYE
But I need to give it a value from XMaterial because of the version compatabillity, is it not possible like that?
Yeah? You can't have variable case checks
specifiv to this, somethink like dyeSwap(colorIn, colorOut)
the compiler needs to know the values at compile time
is XMaterial an enum
Well couldn't you make m the XMaterial? Idk if it has a method to get a Material to an XMaterial, but if it does, you can do that and then use XMaterial.GREEN_DYE in the case check.
because then you can convert the type to an XMaterial and switch that
thinks its a good thing I didnt suggest Swtch Case-L
I can convert a Material to an Xmaterial, is that what you mean?
like
switch (XMaterial.of(m)) {
case XMaterial.GRAY_DYE:
// ...
break;
// ...
}
yeah
Ah, then why will this work and doing this with normal Material won't?
it will but its harder if you keep trying to cast it to other types
switch is like if, while, etc. it does not care what the types are, but they need to match to be valid
because parseMaterial() is a method that cant be evaluated at compile time
which is required for switch cases
I'm confused😅
this is possibly true for java, I've not tried to use a parse in one myself
switch is a fairly new method to java
Oh, so it works the other way around because I convert it before the switch
And in the switch I need variables the are not a result of methods?
they need to be constant, yes
I see, thanks for the help!
a switch is (normally) a hard coded state machine
hence sometimes desugared to something completely else
Uhh
yeah... it was painful not having it when I first tried to learn java
I wouldn't exactly call switch new to Java.
Switch Case-L is actually only available java 16+
true. the general switch was added in java 5 or 7 - says the internet
Wtf
anyway, its moot and just shows when i first tried to learn java
switch has likely been around since JDK 1.0
nope
it was one of the things java intially refused to adopt from C
that could be, I abandoned trying to learn java for quite a while
I found the very first language specification for Java
JLS, First Edition
There's a section for the switch statement :p
but then its an unsafe method to op from an offline player
if I were to change my server hardware, would I use bungeecord or iptables to route the traffic while the dns changes propagate?
Could not find spigot-api-1.18.2-R0.1-SNAPSHOT.jar (org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT:20220318.230433-21).
Searched in the following locations:
https://hub.spigotmc.org/nexus/content/groups/public/org/spigotmc/spigot-api/1.18.2-R0.1-SNAPSHOT/spigot-api-1.18.2-R0.1-20220318.230433-21.jar```
anyone know how to fix this?
tried clearing .m2, invalidating caches, etc
Did you press the offline mode button in intellij for maven
are you changing the ip?
WHICH CORRESPONDS TO JAVA 1.1 BTW
How would I check if the inv click event is in the actual player inv?
yes.
read the docs on it. It does tell you https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Bukkit.html#getOfflinePlayer(java.util.UUID)
I'm using gradle and no it's not in offline mode
I would also like to mention how
it just randomly started doing this yesterday
just use cloudflare
has been working fine for months
in what way?
same happens across multiple projects as well :/
it will probably only take an hour anyway, unless your DNS is in a very slow part of the world
as the dns server temporarily
i suppose. but if i were to do that, which would be the best option?
||cloudflare now lol?||
it will propigate in teh cloudflare network the fastest and spread out
then you can keep your iptables /UFW locked down
ah okay, thanks!
Well, what's the issue?
I haven't changed anything in those projects build.gradles for ages
and i've tried clearing all kinds of caches
that is just my reccomendation, the last time I did this most propigation was in a few minutes
alrighty!
would i change my dns server on my machine or where?
I mean it clearly doesn't exist when I go to it, so where would it get that from
if I just leave it for a month it will probably fix itself lol
you just set cloudflare as authortive DNS for your old IP, verify its behaving, switch the ip to the new one, then change your authortive DNS back to your normal one after its done (or not, thats up to you) . you would not enable cloudeflare caching jsyk
he has the newest one?
oh, thank you so much!
unless the repo url has changed
yes
year/month/day?
oh yeah
well sam you could declare which snapshot version to use specifically
or well, just clear the caches and everything
.gradle specifically
Is there a way of checking if a ChatColor exists before trying to use it?
Like i have a config file that you put a colour in. But if that is say something like DARK_CYAN which doesn't exist then the plugin just kind of crashes, so i wish to check if a colour exists before trying to use it
do you know what the JLS is and what the 6 grammars in it are?
wdm
it's still searching for 20220318 after I specified 20220408, why must I always get problems like this
guess I'll just wait for it to fix itself
You mean translate the dark_cyan to be dark_aqua and do that for every colour? No that really isn't an option cause what if someone put something stupid in like banana and expected it to work? That would just crash again
pretty sure they mean id
id?
did u delete .gradle and (possible .idea)?
you could check against valid ID for the version rather that whatever the color is called
I tried .gradle, will try .idea now
mye
chatcolor#?
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.
same thing
hmm
dum computers not doing what i tell them to
this is gradle not pulling the correct snapshot?
It works from gradlew cmd line, intellij is on drugs
yes, yes it is
This doesn't help me
i generally only use gradlew in teh terminal
Where?
Well your wrong cause i've tried finding what # means and i cannot find anything expect basic operators which i already know
don't think that's doing anything
intellij may just be dumb and set it in your tasks
alright time to try repair ide lol
lol
I abandoned using intellij's tasks a long time ago
yes
i am not energetic enough to implement vi in windows for programming java
alright repair ide didn't work with all 7 steps, good job intellij
build.gradle? or the .gradle folder
Then could you explain it? Cause all i know is python comments and google isn't finding anything
i hate plugin.yml!!!!!
Got it
there's an annotation processor which perhaps would make it a bit more appealing
clash of code ?
or clash of clans
thats very random
I think its dead compared with class royale
can spigot unblock tor
like damn
i cant access the forums
and stackoverflow is no help here
dont ask him
Is there any good developer able to contact me? (Able to create games)
It's agains't rules ask for that?
technically
?services
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
which no?
Thank you!
since we don't have a dedicated channel for services and collabs
but ye
Ig its fine to ask in general every once in a while
how can i have a command parameter tab completion for all online players
how do i do that
Im really secure because im not doing correct the Listener
you reinventing the wheel @sterile token ?
Console has tab complete
or return null
i cant access the docs for it though cause im at school
No
Who execute the tab complete class
PluginCommand
since TabCompleter, CommandExecutor and the combiner interfaces are just strategies
So to register command throw Command Map I should use plugin command or command executor?
But in using reflections 2 times
🤔
Imsome minutes I will send my code again because the claims are not being created
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
intellij has to be caching it somewhere, I just can't figure out where
But when I said not working really I dont find the reason
ME NO
I hate kotlin, its like really oddy to understand
Anyone who has experience with integrating with the new mythic mobs?
are you using the minecraft plugin?
yes
For development 🙂
what does it tell you?
wdym
when you look in your libraries what did the plugin set?
Maven is giving me the following error when I try to compile:
I'm not a maven expert and don't understand what I'm missing
its F4 to open module settings btw - intellij has stupid names for settings and preferences
anyone?
is intellij available on linux?
can you browse to it?
the latest
HAH IT WORKS, F YOU INTELLIJ
Why the heck the operator "||" cannot be applied to a boolean?
i downloaded it for windows and and i have access to that disk but i probably have to reinstall it for linux then

I didn't even know it used that
yeah ...
i thought that was just where it downloaded gradle and those jdk's to
well .gradle is used to determine the underlying snapshot version
since else it'd have to make a request to the repo every time
shouldnt return stop the code from executing further? or is my previous python experience fooling me?
yes it should
context?
Can u assert if what i code its correct because im still having the issue that the claim its not being created
yes, but its scoped to a method merely
what type is claims?
set claim var
wait nvm im stupid
Claims is the repository manager
you can easily mitigate that by doing this.claims.create(claim = new Claim(...)
r e a d
what is event.setBuild(true) btw
I will remake the listener for 900 times
Already exists, that why im calling getClaim()
wonders why you dont use an api from an existing claim library
claims.getOrCreate(id, SUpplier<Claim>)
Because my issue is the next im not using normal cuboid
Im using radius cuboid
oh ok
oh ok
oh ok
ahah get ninja'd
Doesnt exists that method on set
i mean the id, the thing like in the claims.getClaim(id) method
ah its based on a location
Yeah
then do smth like
Claim getOrCreate(Location loc, Supplier<Claim>)
So will be:
getOrCreate(Location, Supplier<Claim>)
yesj
😌
😌
i stole your cat
aa
does that mean yes?
du då? 😮
whats no?
nej
Whythe supplier?
njetz
whats that supposed to mean?
does anyone really know?
is this.create saving it in a map or smth?
yeah
only that?
yes
add amazon
mye then it doesnt really matter
I need a life
cache i'd say
Instead of a map im using a set for cache
🤷
And im saving into mongo
ahaha
you can load databases to cache just fine
depends on what you have in the db in the first place
depends on size
why not, if your db isn't meant to be large you can load that bad boy all day long
not particularly scalable but sure works
if you dont need it dont load it 🤷
Im only loading into cache the claims objects, and when a player join his profile object
if you need it super fast and it's small cache it
So dotn worry now i need to fix the claims creation haha
like I said depends on the db but it's fine for some stuff
Fourteen in conclusion do i have to add tgat mehotd?
like if I had a db that gets changed every tick and is super tiny I probably wouldn't want to keep writing to the db on every damned tick
get method?
i guess ye
you mean if it was naturally generated with the world gen?
So what do i have to do...
put em all on the same package
each class should be a standalone plugin that depends on your core plugin which just loads every class
man I could be the first spigot author with over 1000 plugins within the week
and also banned
I have way too many classes, I should make it all in 1
god damned amateurs all around me thinking they're big
I know
but that will only work
project is maybe 10% done tho
but player placed cannot
man's writing java itself
if you don't catch players placing it down and register it yourself you're going to have to pull some dark magic to actually guess if a spawner is "natural"
damn
half of it is probably gradle
I have no clue of what you're trying to do but if you are the one modifying these spawners you should be registering them to either a file or a database when they are placed
yeah it's a statistics plugin
PlayerData.get().addDefault("Players. ", 0);
PlayerData.get().options().copyDefaults(true);
PlayerData.save();``` i want to make the default config look like ```Players:
*uuid*:
kills:
otherstuff:``` how do i do that?
static meh
how do i put uuid in default
"players." + uuid.toString()
no
yes
ok I guess it depends on whether you want they key to be the player uuid
package me.snazzeh.main;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin implements Listener {
public HashMap<Player, Integer> mined = new HashMap<>();
@Override
public void onEnable() {
getLogger().info("Successfully enabled.");
Bukkit.getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
event.setJoinMessage("Welcome to the server" + p.getDisplayName() + "!");
}
public void onBlockBreak(BlockBreakEvent event, Player player) {
Player p = player.getPlayer();
p.sendMessage("You broke a block!");
}
@Override
public void onDisable() {
getLogger().info("Succesfully disabled.");
}
}
Anyone know why when I break a block nothing happens?
nope
that's not right
block break event is an event
oh lmao what is it
u what 😭
might want to save that map on disable too
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
event.getPlayer();
player.sendMessage("You broke a block!");
like this?
im learning hashmaps rn lol no clue how to disable them
why is my plugin 8mb, but other people make plugins that are like 800kb with more code
the data will just vanish
where does that player comes from do you think?
magic player objects hanging around?
im not sure thats why i put it in the event
you included binaries you are not using again?
you do event.getPlayer().your stuff
ohh
inst that what getOffline is for? 😛
that makes sense okay thanks
how un the do of the binaries
check your includes and dependancies
cheers bro
if you can't make magic player objects appear out of thin air then you have not truly mastered java jank
cheers everyone aswell. legends <3
also why is there original-plugin.jar and plugin.jar
what do that mean
are you shadin?
Ignore the original :p
dutch kek
shaded means you have dependencies packaged with your plugin
usually through maven
or gradle if you are a man of culture
based on some of the errors I've seen related to detecting fake players as real players I am going to assume some people can produce player entities just by going to the bathroom
sorry you used up your limited time trial of having people on here make your plugin line by line, may I recommend looking up how to use hashmaps on google or copying your solution from stackoverflow without ever really reading it
generics for primitives when
nah i am tryna search it up bro i just cant find how to put it in a string 😭
ive been using skript for years pls save me smh
hash_map.get(key)
give a man a line of code and feed him for 5 seconds, set a man on fire and feed him for a lifetime
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
int value = mined.get(event.getPlayer());
mined.replace(event.getPlayer(), value + 1);
event.getPlayer().sendMessage("You broke a block! (" + mined.hashCode() + ")");
Thats what ive got
bro some people learn way better from seeing it work than reading
we told you the same thing as you would find it on the internet
guys I learn better from seeing it work than reading who wants to develop my dream game for me so I can see it working
nah its better here tho idk how to explain it but yeah lmao
nah thats just unneeded bro thats not what i mean
snippets and shit help because it works and then I know what to do for next time and eventually it builds up in memory and i know how to do it lol
can u link them pls
?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.
if you would take a look at how it works, you would know that mined.hashcode() doesnt return te mined blocks for that player
I told you the code 😅 and still :p
wait im so dumb its .size() isnt it 😭
wait is it i thought that was just to get the name lol my bad
stop trying to guess it based on what your IDE is saying and actually look for it or learn java in general
learn java
if anything your question shows you're not ready to start making mc plugins quite yet
you broke 157283653 blocks kekw
im not interested in learning java for long term im just trying to make minecraft plugins lol
snake case aint it sis
thats what im tryna do bro
but youre not
then you have to learn java :)
i would suggest starting small and then working your way up, not starting big and working your way down
i am asking for help so that i can learn how to java
u cant without learning java
this is not a java education channel
i am starting small im making a plugin that displays how many blocks ive mined, thats quite small imo
you will just annoy people
this is a support room for getting help with specific implementations of the spigot api
is also for java
nah magma
i ask for web dev questions here
and java questions as well
if your question is with java itself, unless it's a somewhat reasonable question or if you don't keep showing up with them you will be given the resources to learn java
Well it's an example :p
this isnt only for spigot
plugins are relatively big compared to a simple starter java project
kotlin 🤣
just because you don't use the room for its stated purpose doesn't mean it's not what the room is for
1% is actual spigot api
i mean its called help-dev
and conclure said its fine
yeah help-dev kind of assumes that its for plugin development
well thanks for defending my point and making your questions worse lol
since what youre asking for isnt spigot
thats so funny
man defended a point against him
if i went to a java discord with spigot stuff they most likely wouldnt know what to do lol
nah what
it says help-dev right?
just goes to show you how right I was
they would
Lol
or am i just not able to english anymore
oh alr
a surprising amount of java devs have actually done a lot of minecraft modding/plugin
people will help you do something, but do not appreciate doing it for you
i wonder how many java devs there are that started learning it just for minecraft
all the non-comp sci ones
is it possible to add nbt data (like {example=1b}) that dont exist in vanilla minecraft to entities
and
how do i add nbt data
also just for instance
that will send
You mined 999123 blocks
are you talking to me
depending on what you want to do you could just use the persistent data container
whats that
check the api or forum posts about it, spigot has a bunch of good resources for it
why?
like what you would add to an entity with
/summon zombie ~ ~ ~ {gravity:1b}
in command blocks but in spigot
because you’re using .hashCode()
Nope
theres a difference?
yes…
tell me
how the fuck will the hashmap
know what player ur referencing to
with hashCode()
ok don’t need to be toxic
but yeah that’s not how a hash map works
mined.get(event.getPlayer()) thats what ive got
but for custom values? what are you actually trying to do here because it's starting to sound like jank
that works yeah?
entity nbt isn’t always the best option for these things
im looking at persistant data like magmaguy said
okay so like im really confused because theres no errors but the message just wont send.. :/
code?
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
int value = mined.get(event.getPlayer());
mined.put(event.getPlayer(), value + 1);
event.getPlayer().sendMessage("You broke a block! (" + mined.get(event.getPlayer()) + ")");
}
👁️
i honestly have no clue why you’re using a hashmap
hashmap.replace() should work fine iirc.
Nope u dont get it
👁️
use event.getBlock().getType().name() if you just want the name of the block
so if its the first time a player is breaking a block it aint workin
Bukkit.getPluginManager().registerEvents(this, this);
👁️👄👁️
do i need to do this every time i make an event or just once?
like in the main class
once
okay yeah so its been registered
key means value right?
that should work
once per class
no
still wondering what you’re trying to use a hashmap for
hashmap is a key and a value
to get the amt of blocks the player broke
ah
2Hex is value
oh okay
you’re never giving it a value
fyi that code won't work because it will almost certainly NPE on the getter
Ah yea thought he already made a put before replacing it. Will give null then ur right.
what getter
you should be using getOrDefault(player, 0) when you assign that int
getOrDefault(player, 1)
not 0 ig
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event, Player player) {
mined.put(player, 0);
event.setJoinMessage("Welcome to the server" + player.getDisplayName() + "!");
is this what you mean
0, he's counting blocks broken
why do u have 2 params
and immediately incrementing
well he’s adding another a line later
the blind leading the blind
this doesnt make sense
yes and he adds that in the next line
they changed it to playerjoinevent
then thats not how it should be ordered
¯_(ツ)_/¯
you just can't make this shit up
the get should be after the put if im not bsing
what
jesus
how would i use getOrDefault?
yeah
on the hashmap
use the getordefault method like a normal get method, but add another parameter you want it to return if the value it finds is null
Magma guy ive never seen you help until now, youve only been either making fun of him or arguing
you know 2hex somehow I feel like your strong suite isn't seeing things anyhow
in this case, the first time a player breaks a block it would say “player has broken 2 blocks”
persistent data seems to be what i need thanks
np
where would i put getOrDefault in the hashmap tho im lowkey tripping rn 😭
what?
well then
he should put before get
that makes less than no sense
if you put a value you're going to get the value you just put
and you're going to be putting the wrong value
yes
no
after he breaks a block
you guys need to agree which logic you want to work with
- get how many blocks have been broken
- increment that number and store it in the map
- tell the player what the number is
it's really simple
I don't see how this is confusing you
both methods are valid but handled differently
thats what i just said
obviously you don't need to get the value from the map if you stored it in a field but hey
but he was doing
now it'snot
before get was meant
the get to send to the player
you get it to send to the player
u wanna increase the amount of blocks placed before sending it
so u dont send the value before operating on it
pre-increment vs post-increment rumble
actually this is based on something much dumber because he was saying the default should be 1
the default should be 1 since it will never fire except if he breaks a block
but then he adds it again
you realize that then you would need extra code to prevent it from adding to the counter
Oh thats before the add
this is like 4 lines of code how can you be this confused
mb i confused things
sis ive only been eating in the last 4 hours of my day for 11 days
yeah
you didnt push the button
I fasted for a year and I don't remember getting this confused
huh
that would be the normal reason something doesnt happen
Where do you live
I live in a desert country
You did register the event right? :p
summers are 42 celsius here, stop trying to find excuses
did you implement the getOrDefault?
it should send even if he didnt
connecting strings with null can do some weird things
except if he got an exception
no idk where im putting it
he's probably getting a npe
lets start at the beginning: did the plugin unload itself?
are you reloading your server without rejoining?
👁️👄👁️
theres an error in console but its too big to send
?paste
does it say null pointer exception
Yeah it does
insert shocked pikachu
that would be the thing we've been mentioning for the past 15 min
what is the line that it refers to
Line31
you implement the getOrDefault hashmap method or you otherwise assign a default value / handle the null value
public void onBlockBreak(BlockBreakEvent event) {
i don’t think it is
but im not sure whats wrong wit hthat
that is not where it is happening
thats the line of the method bukkit is executing
yeah but where do i put getOrDefualt thats what im confused about loll
shouldn’t be a problem since he already sets it when the player logs in
unless he’s not rejoining when he reloads the server
check the documentation for hashmaps
but yeah you should use getordefault anyways
do i need to manually write constructors for every @smoky tinsel combination or is there a simpler way of doing it?
int minedAlready = mined.getOrDefault(event.getPlayer(), 0);
int mined = mined.put(event.getPlayer, minedAlready + 1);
event.getPlayer().sendMessage(mined);
lol poor nullable
oh ffs
minedAlready is the amount of blocks the player has already mined
why does anyone have that username bruh
why do you need to account for every nullable combination anyhow
gives you a known return you can work with ^
because some constructors can get massive, but have Nullable arguments. I want to know if i can do something to the effect of using T or ?
aka
return map.get(object) == null : defaultValue : map.get(object);
but it doesnt get twice
hold on what
ok so I recommend using a builder pattern here tbh