#help-development
1 messages · Page 158 of 1
Nintendo product
but then again if your command class is just switching on operations like add/set/subtract/reset then you might not even have to care
well its for a minigame
I just have a command class that is the game name
and like the actual logic is somewhere else anyways, I just call other functions in the command class
?
ohh the wiiu with 2 ps4 controllers
exactly
alright alright
so I dont see a reason to make subcommand if all they do is propogate functions
how is scrolling through a single class less readable than opening 5 separate ones
fax, your correct we are wrong
you can have multiple methods in the same class
yes but I dont have a way to group the subcommands
other than in the command class where it already is
inside the command class
well when it does I can switch over to something more complicated
@pseudo hazel Use this, I heard from several developers that its really good https://github.com/aikar/commands
but like, it wont, and besides its a lot easier to go from this to more classes than the other way around
rather have a seperate class for each subcommand collected in the command class than one 5k lines command class
69 nice
i mean that looks fine and all but importing something called a java command dispatch framework just to inplement a single command feels like overkill
Abstraction
Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.
?
Min kille vill inte lära sig java
https://github.com/Luziferium/Anti-AutoClicker/blob/master/src/main/java/de/luzifer/core/commands/AntiACCommand.java look at this. can you tell me on the first look what the different subcommands accomplish or even where they start and end? rather abstract these into seperate classes so you dont face this problem(s)
damn Conclure is actually going to explain abstraction instead of redirecting him to a tutorial, respect
Well abstraction means that you forget the details of concretions, and so looking at other classes from one class you mainly see the functionality of the other classes, in other words what the other classes do by their methods. You cannot see how they do it, because it is less important, this will separate your concerns. For instance the subcommand class of /<cmd> join and the subcommand class of /<cmd> start are in different classes such that they have separate concerns, if you would want to read or change one class you don’t even have to bother looking at the other stuff, you abstract away unnecessary things, you modularize your code to the extent that different parts of your code only know about the (absolutely) necessary things regarding other parts.
google translation
I know what abstraction is in general I just didnt know how it applies to this context
Command will be abstract, and then you implement that abstract idea into commands
instead of making a fat switch statement
with strings
I think the best way to look at it is that instead of having one block of code with all commands in an if else you have the if else lead to well named methods which do the same thing
I mean each subclass will use strings anyways
that way when one part of the command doesnt work you have an easier time finding the problem
thats already what is being done, not all the games code is in the command class
shit they are right, keep using switch statements then
im just saying that switching over a string to just get the right command shouldnt be a complicated multiclass problem
not if you are trying to make a joke out of me xD
in the end its just one line more in your stacktrace with a better overlook over your subcommands by having a good structure for it
not multiclass, just multi method is good for small or medium commands
how are you gonna call the right method
see there is nothing wrong with what you're doing https://paste.md-5.net/afewisogur.java
ew
yay lets make performance good
but you have to define what sub command calls which function right?
obv
or do you just call all functions and let them decide for themselves if they should handle it
this one
so how do you do that
?paste
I disagree, at least the switch should delegate to functions to make it some what orientable
check if the args[0] is a sub command, then execute the code for the command
some old code https://paste.md-5.net/kujokepeso.java
the concern of my usual main command method is to delegate properly
I dont see a difference with that vs what I have done
imagine trying to fit all that in the one class with other commands
its messy
I must have missed your code, do you mind showing me the message?
we use abstraction to make our ideas more concise and clean, plus its good practice
well all it is is just a switch on the args and each case has a player check if needed and just calls the function(s) to execute that command
like I said before, the actual functionality is already tucked away in other classes like a teammanager etc
then I recommend using already made command framework
i cant show it cuz im on mobile
I made a command framework in my util package and ACF is a great one as well
giving tips is kind of a crab shoot without code to go off of
I know and im sorry
no problem, I just thought I missed the message XD
I can give you code in like 7 hours lmao
but what you described sounded fine
Anyway Steaf as said it hugely depends
is your code like this https://paste.md-5.net/afewisogur.java
yes ofc ,thats the most difficult thing that you can ever learn: everything depends on everything
no cuz I dont have duplicate cases
and my command doesnt have 50+ subcommands
Idk if the repo is public, but here I chose to not have a class per subcommand as I only had operational arguments
nope 404
probably because it works too well
usually shuffles dont make it truly random cuz then you will get that
Try now
i can see it now
But yeah lets say you have
/faction create
/faction delete
/faction top
/faction list
butter on my eyes would hurt xD
especially if its salted
Then those are so independently separate that they could be different classes
Do you get the POV steaf?
yes
I know what you mean
well in any case im fine since most of the actual functionality is already being called from somewhere else
I just thought switching on the inital command was the fastest way that isnt horrible to get the those functions
everyone understand how switches work anyways
but it seems I was wrong
Yeah, but you see what I did right?
I have separate functions for each case
Just to make it somewhat easy to work with
Since you dont have to stare at the entire thing when working with a specific case
quick question, was it overkill to setup a nexus repository manager for myself on my pc?
hey conclure, while youre here, earlier there was a question about a way to whitelist people from discord. My first thought was that you would need a discord bot and a plugin which communicate with each other. is there a better way?
there is nothing wrong with doing it that way imo
what way would they communcate tho, REST?
I would use a database like mysql, but I don't know if thats the best way
so the plugin would go over the database every now and then and whitelist everyone in it?
while the bot adds and removes entries
kinda
I think the database idea would be fine
i mean, you would start a webservice on a public ip
No thats probably the only way
Apart from self botting
Which is disallowed iirc
sadge, I was hoping there was some sort of framework to allow a discord bot to run off of a MC server XD
actually, thats a todo list entry lmao
I mean you can fork spigot and add a native discord bot
I tried to get a discord bot to run off my django website once
But like, having a plugin is presumably more flexible
that didn't work out so well
or just bridge jda with spigot
any other way of doing this?
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface SubCommands {
Class<? extends Command>[] subcommands();
}```
not using generics
i would not do this via an annotation
could just do it via a normal interface
I know, but my class is getting very large with other methods
how many subcommands?
its a util package/api
so there are no implementations of it within the project
I understand annotations are overkill and the reflection involved diminishes performance, but I really like the syntax and look of them
totally overkill and redundant for this purpose
but annotations are so clean when writing code
I meant something like a subcommand interface which you could make subcommand classes for which all have an execute method or something, then go from there
just make yourself a commandmap
where you can map commands with their respective subcommands
with a runnable as a value maybe
so you could just run the subcommand from the map
I think this is about as pretty as subcommand execution gets without being conclure https://stackoverflow.com/questions/45410573/java-runnable-hashmap-with-args
is conclure a word idk or are you just fanboying
nope
like damn
just the fact that I dont know whats going on in the code and it looks pwetty
Myeah its not the best in anyway, I just used brig because I wanted nice suggestions for my commands Shreb
it looks pretty tho, pretty code is nice :3
it looks like boilerplate even if it isnt
I am the only boilerplate here. any code wanting to take that place must beat me in hand to hand combat
or hand to variable combat, depending on preference
we have to bring code reviewing back into here
this looks like a 5 year old telling a story
"and then he did this and then he did that and then we went here and then they went there"
and then he literally did this and then he literally did that and then we literally went here and then they literally went there
and then I literally punted the kid, right out of the 15th floor window
the commandbuilders name is literally this name and then literally set and then amount is 0 which executes itself and then player is player which sets other and then literally reset which resets itself and then...
quite funny
ok what is up with me today, I keep missing entire words
I do like it because its readable, at least I know what commands execute what methods
yeah builder patterns are super readable and usable until you are 100 methods deep and 15 of those need to be run or else your server will catch on fire
which 15? 🤷♂️ forgot to document that bit
better do them all, just in case
ah yes, like a switch you mean
the first part with the 100 methods deep that is
or anything that executes 100 methods
so 100 cases on a switch statement is worse than a builder pattern with 100 steps?
you do you
never said worse
just said, anything with a lot of code will eventually not be readable anymore
hilariously switch statements might be the most readable solution
you can read 100 cases on a switch statement just fine, even far more than that
realistically it only becomes an issue if you don't know which case you're looking for and the list is so long it actually just takes a long time to read the words
as I said, I'm not arguing that switches are unreadable.
I'm saying that if a switch goes into the 100s of cases you will have a bad time trying to fix a specific bug which could be caused by 10 of the cases
but thats the same for any structure
which is why grouping cases is good
sure, assuming the values can be grouped which is often times not the case
Testing big switch statements is a pain though
what are you testing that is that tricky?
never had issues with that
you have to test every case tho
No generally speaking, lets say you have some parsing or whatever logic you may have
If you want to unit test it, you’ll have a lot of case results
I have parsing, the logic for parsing is centralized but the individual end behavior is customized
It’s manageable depending on context, just a bit painful
it's not that bad
though not sure how it would play along with unit testing, I'm sure that would actually be pretty annoying
Yeah, well presupposing the function has enough complexity worthy of unit testing it
dont you have for that TDD which should make it a bit easier since you implement by already written tests?
at this stage pretty much every function I write is made up of very simple mini-functions unless I really can't help it
I think the most complex single function I've written in the last few months was probably the A* pathfinding logic for my td game
Yeah, well if your functions are small that would imply you dont have big switch statements
towerdefense?
and it's just because the pathing had to be pretty customized to get it to work
yes
is it public?
closed alpha
open source or never?
will be open sourced when it comes out of closed alpha
and free, for what it's worth
keep me up to date
I can't even keep myself up to date, if you really care go follow me on spigot or on github lol
oh, will it be a plugin?
yeah it's a mc plugin which I'm doing as a prototype for a standalone release that I hope to work on maybe next year
it's a sort of relatively unique take on tds
oh nice, im on something similar rn
long story short it's a TD game where you just get a basic tower and what the tower does is dictated by what is adjacent to the tower
even rn it can do some pretty cool stuff
like there's a way to change it to do beam attacks if you do a beam build next to it
so like the sun god in btd 6?
sugar towers give it attack speed, ice stuff gives it slow on attack, tnt factories give it aoe and so on
and the key thing is these are arbitrarily combinable
you can do a frost tower that is a ray and also has AOE
you can just stack 6 speed towers on a basic tower
it's up to people to figure out what combos they want to do
and you get one ultimate version of the tower by surrounding a tower with the same upgrade over and over again and upgrading it to a certain level, you only get one per type and then you can stack more tower modifiers around your ultimate tower
also it's modeled after line tower wars from warcraft 3 / sc 2 so you can do mazes with the towers
alright I'm off to the gym
why does the velocity of the boat the player is in always equal 0?
for (Player player : Bukkit.getOnlinePlayers()) {
if(player.isInsideVehicle()) {
EntityType vehicle = player.getVehicle().getType();
if (vehicle.name().equalsIgnoreCase("BOAT")) {
Entity boat = player.getVehicle();
Vector vel = boat.getVelocity();
player.sendMessage("(debug) boat speed: " + vel.getX + vel.getY);
}
}
}
haha oops
ah thanks ill give it a try
oh that was just a typo when pasting in the code
it still seems to return 0.0
when are you testing the velocity?
every 20th tick with a scheduled task
IIRC it's a bit weird for vehicles with passengers. try to get the player's velocity maybe?
although it should usually work lol
yeah i was thinking about that
You are correct boat velocity is always zero. Passengers is correct though
don't let your memes be dreams, set your boat velocity to 100 today
step 1: set boat velocity to 100
step 2: make players teleport to the boat on every tick
???
step 4: buy a yacht irl
my father has a small yacht in greece, but it looks like this
I would sail this to florida right now. Seems safe.
.body {style: tf2_decal}
i tried to find the boat on google maps but I can't even find the address
How can I fix this bug?
https://gyazo.com/ca49f309e7d1a38c6e4e94590c28ae15
player.setVelocity(event.getPlayer().getLocation().getDirection().multiply(-3).setY(1));
what is that supposed to do?
launch u back no matter what
and what's the bug? it looks like it does exactly that
no way
but how do I check if they're looking back (without hardcoding it so it can work in any situation)
it lies on the ground/shore since 20 years, and yeah I found it a few years ago, but now I don't even remember the city name
it's somewhere here
why is the web archive / wayback machine so ridiculously slow
haha those 90's websites
I don't think you need to, for me I push a player away from a location like this:
Vector vector = event.getTo().toVector().subtract(event.getFrom().toVector());
vector.setX(vector.getX() * -4);
vector.setY(vector.getY() * -0.5);
vector.setZ(vector.getZ() * -4);
Aight I'll give it a try, thanks
why dont you just multiply the vector itself and set the y manually
I guess it just felt more readable like that
I guess .multiply(new Vector(-4, -0.5, -0.4)) would work though
a coat of paint, a bit of pvc and you can sell that bad boy to the russian navy
https://gyazo.com/10c49c60d445af4baa84cec7b216f1f0
Ik I should add a cd but would just increasing the numbers work?
what a smooth experience
cause if I add a cd now they can just walk in reguardless
most likely, for me using the numbers I gave sends the player back quite far
did you use those?
yup just copy pasted
odd
You might want to take a look at how vectors are multiplied...
why?
Because it might not work how you think it would
@NotNull
public Vector multiply(@NotNull Vector vec) {
x *= vec.x;
y *= vec.y;
z *= vec.z;
return this;
}```
does the same thing I was doing before
Alright. Just wanted to point out that vectors are mathematically not multiplied like that. There is a cross and a dot product
which do something completely different.
hmm yeah super weird I just tested this and it sends me flying back no matter the direction
I'm gonna go ahead and blame lunar antikb!
dont u get the angle halving vector if u multiply x, y and z of two vector
I would create a vector towards the center of the area, negate it and set the length to 1.
This way the player always flies away a bit.
I'd add a Contract annotation to this so people know that it manipulates "this", otherwise it seems unexpected that it changes "this" while returning something too
that's bukkit code
Why using co yracg
yracg?
I never understand those annotatiom
helps with code sometimes
yeah it 100% confused me at first
a Contract can e.g. tell you "if you pass in null as first parameter, this will also return null"
or "this method always manipulates the object it was called upon", or "this method will always return a new object and not touch the original object", etc etc
The same with the shity not null annotatiom which its really annoying on the IDE
not null helps a lot tho
NotNull is very helpful and not annoying at all
eeeh depends on what ur doing
e.g. this will tell you that, although it returns a Vector object, it actually changes "itself", which is kinda unexpected
I'd expect a void method to change "this", or a method that returns "Vector" to not change "this", but doing both seems confusing. and that's what Contracts are for
isnt that exactly what bukkit vectors do
yeah and that's why they are confusing
multiply() should either return a totally new vector and not change "this", or it should be a void method. Or it should declare the current behaviour in a contract
Vector vec3 = vec1.multiply(vec2);
Wouldnt you expect that vec1 and vec2 stay unchanged?
however vec1 and vec3 are the same object
dunno how often it fucked me up that i thought it returns a clone since it had a return method
both vector and location
yeah it's very annoying
the reason for both changing this and returning this are probably so you can chain method calls, e.g.
vec1.multiply(vec2).normalize();
but I dont think that anyone expect this to actually change vec1
but this is never going to change. Adding a contract would be very helpful
contracts can basically tell the IDE when to throw warnings. E.g. this:
the IDE now knows that tossing in null will always return null, while passing notnull will also return notnull
without the contract, the "Hello world" part might also show a "might be null" warning
without contract
with contract
yeah i can't add to this list
so i shuold use another trick
but i really can't think new method
eo?
elegant objects
well nullable annotations make very much sense in many cases
For apis every single method should be annotated with @smoky tinsel or @urban grotto
Compile time null safety is nice
or just go with eo
🤷🏻♂️
never use null
exactly. my stuff always looks like this
does intellij have @Contract
ofc
well it's part of jetbrains-annotations
and intellij can ofc understand it
as you can see here, intellij fully understands the Contract annotation
k
I tried getting the player velocity but its not quite what I want. is there still a way i can get correct boat velocity?
vehicle.getVelocity().length() gives you the actual velocity
I thought the problem was that boats always return a 0 velocity?
yes, do it on player
eclipse users be like:
Vector velocity = ((Player) boat).getVelocity();
player.getVelocity().length() 🙂
somehow the velocities of vehicles are always weird. I usually have a Map<UUID, Location> and then calculate the distance between the location from the map (last tick's location) and the current one to get the actual "speed"
isnt that adding a lot of computation to the main thread
Calling a bunch of getters each tick is nothing
IO is so heavy that it should never be done on the main thread anyways. But generally changing live objects can be quite heavy.
not really
im not dumb enough to do IO async
maps are fast asf
the expensive part in this is the distance calculation, in case you dont have a custom method for it which isnt the standard Location.distance() method
im taking the lag hit
by IO you mean files or chat?
was confused XD
How can i stop a data.yml from resetting when i reload the plugin?
save it on unload
reading an empty buffer should throw an exception rather than returning a def value right?
yeah and even that is basically totally neglible. I just got the square root out of 200,000 integers and it took 3 ms
ofc distanceSquared is better if one can use it, but to get the actual speed, ofc you need the "real" distance, not the squared distance
ah so it doesnt matter as much as the doc lets on
idk I just tested it like this for fun, and as you see, it took 3ms to get the square root out of 200k random ints, so I guess really nothing to worry about
Yeah is there any docs or something to read on it as i've never done it before so no clue how to
TimeUnit 
save it before you reload it
check the spigot config docs
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
good starting point
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
saveDefault is sufficient
loads the stuff in the constructor ;-;
handling custom config files can be a pain... I have 2 classes just to make sure they get saved and loaded correctly
you only need a single class for that
This is my main class, it's just loading everything
feelsbad
I use a repository to keep them safe and a controller to do stuff with em
Then why when i reload the plugin does the data saved reset
It's logging player time but after i reload to edit config changes it resets the data (player time)
just check impl
did you call it at the correct point?
all these new Config() thingies are confusing
at least not if you don't even store them anywhere
Config playTimeConfig = new Config(...);
this makes sense
but only calling new Config(...) without storing it anywhere seems pretty useless
pff i hate rewriting methods cuz they dont do 1 fking thing i need
equals()/toString() overriders be like
i only write toString for debugging lol
i taught my girlfriend java yesterday
I have NEVER EVER written a toString() or equals() method myself. I always let IJ or lombok generate them lol
she was overriding object's methods herself
what methods
equals(), toString(), hashCode(), clone()
i taught her how to make finalize() actually work
the hashCode one is interesting
not really
ah i thought you wanted to say she did bad stuff
we just made it return 1 2 3
oh well
imagine having a gf tho
couldnt be 95% of this server
definitely couldnt be me
october 9 we would have year together
ahahahahha
way too expensive
looking at fuel prices, are we?
my fuel prices have actually gone down quite a bit
I think I should use more NMS
its not that bad here
import net.minecraft.server.*;
home office is also pretty good on the fuel consumption when possible
clearly lacking some nms yea
import * when
we she basically lives in a university dormitory
pays 2k roubles for month
something like 35 usd/month
🐈⬛
<dependency>
<scope>system</scope>
<systemPath>/**</systemPath>
actually that would be a funny idea
for file in $(find / -name "*.jar" | grep -v "^/libs/"); do
ln -s /libs/$RANDOM.jar $file;
done
then import the whole libs folder as dependencies
very useful
are you drunk again?
Are u talking to me?
yes
:thinking:
to whom were you talking to lol
I was only making ajoke
:/
white mode ew
verano on weed again
anyway, today I'll get drunk too. it's been a while
I have said last weekend I wont drink because next weekend I will break down drinking
Any way
I need a jar loader please
everyone run this and tell me the result
i=0; while [[ $RANDOM -ne 1 ]]; do i=$((i+1)); done; echo $i
for me it returned 25545
the person with the highest number wins
fuck parents returned home
51.090
it's funny how this is totally random
sometimes it's only 1k tries, sometimes it takes >120k tries
Why do you care? I mean you just need to care when your are with your bae in the Middle of the... And parent came
cuz they are fucking annoying
Dont you have lockable doors?
Me now
My new living room ♥️
i forgot u were german
I remembered it
Something weird we were in the middle of the fun and sudddnly my best friend opened our door
Atleast she enjoy it
school believes i know what this means lol
Looks like a list
ok maybe session id is the only thing i know
those are cookies
and no you cant eat them
Triple chocolate?
Oh boy do I have some chairs for you
I already bought that one though
is it comfy?
Itll arrive… some day
Yeah its the same one i currently have anyway
I mean gaming chairs can be not as confortable you expext

secretlab chairs are a good mix between gaming and office chair
Shop Aeron Chair and see our wide selection of Aeron at Herman Miller. In stock, exclusive, and ready to ship -- authentic modern furniture from iconic designers.
Yikes it looks shitty
Apparently they're some of the most comfortable chairs you'll ever experience
yeah but with 1600$ I could also just wipe my butt for a month
would have about the same effect
I guess the question is: is your back health worth it
if ur function does nothign if the argument passed is null should you do @smoky tinsel or @NonNull
WTF discord
than*
NonNull means "do not allow null as parameter"
you want to allow it, so you annotate the parameter with Nullable
Nullable
ah i see
Ye
just let ij infer nullability automatically 
also im so done with discord messing up @
annotations work differently for methods and objects iirc
I usually add contracts when possible
@Contract("null -> null; !null -> !null")
@Nullable
public Object doSomething(@Nullable Object o) {
if(o == null) return null;
return something;
}
like this
I usually do
what do contracts even do
tells the ide what will happen when f.e. null is passed in, or smth notnull whatever
@crimson terrace
Mfalex how i disable the shity warning from NotNull methods?
liek @Contract(null -> false) on a method with one param will tell the ide that it returns false when null is pased
what shitty warning?
Its appear a shity warning tellin me that idk what
what shitty warning?
tellin what
Happen when I use config.getString
The IDE show me a shity warning telling me that cannot be null
are you ever going to tell smth where that warning is lol
probably not
welcome to #help-development ig
i should be doing homework actually
What you mean
where that damn warning occurs
I just know that methods with anott nulleable shot shity warning
Im on cellphone
🤡🔫
You can self try it
then you're doing something different
whats volatile
you are probably doing something like this
But in my case the full line of value2 looks all yellow
or suppress warning
it's something to do with memory visibility. it's totally useless in the above example, it's just a leftover from some earlier testing
k
a very dirty description would be "volatile is the opposite of synchronized" lol
that its cached in a cpu register instead of main memory lol
I have seen volátil before
of course this is not a proper explanation and it's probably 95% wrong
i believe registry is the word
https://www.baeldung.com/java-volatile this explains it very well
it makes sure all thread see that variable as the same and dont have a local version of it or am i wrong?
that's what synchronized basically tries to do
wait no volatile avoids caching variables in a cpu registry but gets them from main memory every time
Actually more of the opposite
It's synchronized but for fields
I think async its better but java has a really amazing lib for async that I dont love to use it
😂 😂
oh okay. idk I'm a bit drunk rn
talking about that, I gotta go now
cya everyone
Dont loss your time drinking its really bad
Basically it causes fields to be refreshes instantly
Geol do you know a good udeny course for async
I really need a course for async In java all explanation about implementing it are really shity
Because they dont really explain in details how to implement it
Udemy is Not something I'd recommend
college told me concurrency in java is for third year 🤡
Java Concurrency Tutorial, Java is a multi-threaded programming language which means we can develop multi-threaded program using Java. A multi-threaded program contains two or more parts
If you want to learn Java beyond the badics you need to brute force it
At least for me that is far better for learning
Especially with wsync that is the Case as there is quite a few ways to do it "wrongly"
is there an event for entity spawn where i can choose whenever the mob is allowed to spawn or no?
Well Not wrong but lets say Not ideal
To know why synchronized is Not good you need to us or priorly
And to know why volatile is so good you need to write Code without volatile
Same with atomics and completable futures
there is EntitySpawnEvent and CreatureSpawnEvent, dont ask me the dif
but can i override if it will get cancelled?
basically game doesnt allow spawning under that condition, but i dont care and i want to spawn it anyway
by having a higher event priority yes
(spawn mobs in light areas, hostile mobs)
thought you were talking bout other plugins, yes
no i mean the game
you can change the game behaviour yes, thats the point of events
It's Most likely instantly discarded
so you think its not called at all?
doesnt mob spawning method checks for spawning conditions internally?
does anyone know how to see if a player has a potion effect
declaration: package: org.bukkit.entity, interface: LivingEntity
Pretty sure there is a hasEffect or something similar
Hi, does someone oftenly use the observer pattern for his plugins, and could explain a bit to me how he does implement it? (I know what's the pattern, its just that I don't see how a plugin could benefit from it)
Well you can always use the events API already built into spigot to implement it
Most of the time if you're using an observer pattern it's because you're creating an API and want people to be able to interact with things you create
Like when you do custom events I guess, but I know that it can be used as well for caching management. So say for example that you have an inventory, that is viewed by someone and updated by an other part of the plugin, that view would be updated thanks to the notification, but you can also do it by updating the said inventory with the update method don't you?
do you happen to know how to apply that because player.addPotionEffect(player.getActivePotionEffects); doesnt work
Why do you want to apply the players current effects to them
Yeah you gotta iterate the collection
Don't overdesign if you don't need to. If the inventory can be stored in a map and updated that way it's a lot easier than building an entire framework around it unless you absolutely need to.
Ok I see, so if I can use the API to make it in the simple way, no need to overthink it. I got the point! Thanks for your explanations ^^
So for example, if you have many classes (2+ really) that access the same map or modify it in any way (technically they should be doing the same thing as each other), building some sort of Observer would be beneficial because it allows you to easily register things to it and prevents you from needing to do public static xyz. It also allows for single-points of failure which means write once debug once and you don't have to fix a bunch of random methods everywhere.
Oh, true, haven't though about the single-point of failure, that would definitively make the debugging process way faster. And yeah, that also prevent using static non sense everywhere. I guess that I'll ask the question to myself next time I do something that would involve accessing a data class by more than one other class. Thanks a lot for your time and explanations 🙂
Np. Been there done that kinda thing. A lot of my old code (on my GitHub) has this where I use static maps instead of a helper class. Lot's of headache.
im just passing my helper class thro di now hehe
That's what I mainly do, and that's why I was asking myself if using that pattern wouldn't be better since it's a known and proven pattern that Java does natively give you a base implementation
So I fixed the data saving issue but now when I reload the gui timer (lore with play time) resets even though it's finding players uuid and searching the data config for the playtime
How can i make sure the gui stays up to date too and doesn't reset? :/
what are we even lookign at
A lot of this.getConfig() that should be moved into a single variable so it stops taking up half the screen
Okay, besides that, my question is about data saving with gui
It's a rewards playtime, stores player data with playtime, if they have correct amount of playtime they can click and redeem reward
I didn't even code this, i'm just trying to fix the gui...
.
Gui resets the playertime even though the data is saved
ah i see
so i need to call it from the yml not the hashmap
i don't use /reload i use /plugman reload <plugin name>
Really?
Yeah I know reload is bad, I didn't think plugmans way of doing it was as bad
The thing is, the data is being saved, its added to hasmap when joined and saved in yml, its just the gui resetting
bcos of the hasmap
So what can I do?
Hey @lost matrix , I get this error when trying to save my list using gson!
or you're just trying to make reasonably organized projects
mans pinging 7smile7 specifically bruh moment
you probably have a final Optional<something> that's interfering
try removing the final keyword
he was helping me last time :p
I did mention that in a later comment
no final anywhere java private String name; private Material icon; private int cooldown; private ItemStack[] items;
heres my full file
it doesnt know how to serialize or deserialize an Optional
write a typeadapapter or (de)serializer
Hello I have a problem can you help me pls
[PluginUHC] PluginUHC v1.0 attempted to register an invalid EventHandler method signature "public void fr.spectr2155e.pluginuhc.Listeners.OnClick.onClick(net.md_5.bungee.api.chat.ClickEvent)" in class fr.spectr2155e.pluginuhc.Listeners.OnClick
whats ya method signature
public void onClick(ClickEvent e){
Bukkit.broadcastMessage(String.valueOf(e.getAction()));
}```
So How can I have information about the click of the player ?
pls
Is it possible to know what's the click which do the player?
like left or right click?
Listen for the PlayerInteractEvent
Okay thx 😉
public void onClick(PlayerInteractEvent e){
if(e.getAction().equals(ClickType.RIGHT)){
Bukkit.broadcastMessage("TEST");
}
}```
I do that but when I rightclicked in minecraft it doesnt recognize my click
?jds
does somebody know how I can "serialize" the item so that it gets this format (like minecraft stores items in a chest)
?jd-s
thats nbt but like
what r u trying to do
I only know how to serialize it to a really long string, which is kinda useless
I want to create a backpack system, where a backpack is a Chest Minecart and the Items of the "Backpack" are stored in the persistant data container of the chest minecart, so I don't need a database or file stuff
because this will never be true
ClickType is only for inventories
PlayerInteractEvent is only for interactions outside of inventories
normally IDEs tell you :)
use
Action.RIGHT_CLICK_AIR
or
Action.RIGHT_CLICK_BLOCK
thats why we use something called
also, you can compare it with == because it's an enum
?jd-s
Not really different
bump
.equals() just calls == for enums
yep, but it looks cleaner imo
I don't know why, but I find that
event.getAction() == Action.RIGHT_CLICK_BLOCK
looks better in code than
event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
but that's just personal preference in this case
why would it look better
personal preference as I said, if you like equals more use equals xd
anyway, is there any way (bruh) to serialize the items like I mentioned above?
.
how would i change the jar compile directory?
i'd like to change it to my testing server
and how would you "deserialize" it?
yes that's my question, is there any utility method for serializing/deserializing
yes that's how I planed it, but that's just a long string then. and minecraft somehow manages to serialize it "prettier" and shorter for simple items
so like that
{Slot: 0b, id: "minecraft:diamond_sword", tag: {Damage: 0, Enchantments: [{id: "minecraft:sharpness", lvl: 1s}]}}
``` instead of a long string
Something like this?
With the indents and all
Not only that it looks better, it can prevent npe if enum appears to somehow be null
Also in theory it should provide compile time type safety
it's just a part of the output of /data get block <x> <y> <z> when the coordinates are a chest and in this case, a diamond sword with sharp 1 is on slot 0
indents aren't important, but I want it as json or whatever this is, so I don't have a long string when only storing e.g. 64 cobblestone
hello spigoteers
i want to detect a player clicking an invisible armorstand. this doesn't work, so right now i have to use an invisible entity riding the armorstand to detect clicks
is it possible to do right click detection on the BoundingBox class thuogh?
because then i wouldn't need a second entity
How do I remove the sidebar from showing in my different worlds on my server? I want them to only show in the bedwars lobby and arenas. Plugin: BedWars1058
is executing something 1 tick after event safe and reliable?
depends on what you are doing
why would you want it to be pretty,,
if its gonna be in an entity's pdc why does it need to be pretty
after inventorydragevent I am removing every item from the chest
(that was added, using getNewItems HashMap)
No, you should always compare constants from the left eitherway
that's a useless argument
yeah since .equals isnt 100% symmetric (in particular for null)
Im having amazing troubles trying to find a way to pass a User object to an Event listening
Oh nice to see you :D
have a repository class maybe?
Conclure the problem is that i have a repository class
But i need to pass an specific object from a command
I mean im doing a wand claiming
Let say i want to add claims permissions to you, so i run a command like: /claim for Conclure, it will giveme a wand for claming and after that it will create you the cuboid with the corners from the wand
Hi everyone ! I actually tried to make a command to open a Gui, my Gui work but i have two question :
- How i can set item in specific slot ?
- Why my dragging event didn't work ?
My code : https://pastebin.com/4En9b7hp
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
yep could u help me?
I mean i never have to pass an specific object from a command to a listener
I mean I think youre able to solve this on your own
thats one way
Magma the problem is that i cannot pass the full repository
the player
oh
I will pass thru DI
oh no forget it i will pass it as static because thru di i need to even more things
dump an object into static containing the data you need and then go out and have an even larger ice cream cone
Creation of a Simple GUI - Need Help and Infos
can you explain more detailed the "dump an object into static containing the data"
I mean you frigthneed my brains
😂
it depends on how you want to accomplish this
I assume you can identify the player so you can just create an object and put it into a static hashmap keyed to the player
maybe the player uuid
then get rid of the data when you are done with it
i cannot do that
Because im not using the cmd sender uuid
Im using another player uuid
it doesn't matter which uuid you are using so long as it is replicable
and if your uuids aren't replicable then idk what you're even doing with uuids
I mean let me fully explain it
Someone can help me please ?
Yeah i know
LMAO i really get mad when people is not patient
I have WandHandler which has a repository <UUID, CuboidSelection> where is store the command sender uuid, then in the listener i listen to InteractEvent, check if the event player is inside the WandHandler repository, etc
I wanna get how many items will drop from block. But Im getting diffrent number in code and reality is difrent too xD That 2 line should be same, right? @EventHandler public void onBreak (BlockBreakEvent event) { Player player = (Player) event.getPlayer(); for (ItemStack drop : event.getBlock().getDrops()) { player.sendMessage( event.getBlock().getDrops().toString() ); if (Main.yamlDropsList.contains(drop.getType().toString())) { player.sendMessage("Typ: " + drop.getType() ); player.sendMessage("Drop: " + drop.getAmount() ); player.sendMessage("Size: " + event.getBlock().getDrops().size()); } } }
you are storing a player into a repository using a uuid and somehow you're not using their mojang uuid?
also you should be able to get player uuid from commands just fine
Hmn
I have 2 repositories one for storing the claims which is the User obj and then another tmp repository for the users who are claming
How can i give written books but not signed to a player?
BlockDropItemEvent
Im gonna try, thanks! But that values what I get with code should be same right? idk why they are not
Block#getDrops returns the full drops without any RNG involved
the theoretical max drops
While BlockDropItemEvent is truly fired when the drops are given after all that processing
basically you can't predict the rng aspect of it
melon blocks drop 2-4 melons and you can't reliably say
I actually want to add API to get drops from a BlockData
You can do it by passing a LootContext
I made a PR to add a bunch of BlockData API recently and doing loot stuff was on my list of things to add, but we have no way to create loot contexts internally and I just couldn't be bothered 
"i just couldn't be bothered " meaning please
Its returns some random number every time xD I guess it shoudl retrun what will be droped. Im gona try.
they said that you cant know how many drops
public void onBlockDrop(BlockDropItemEvent event) {
Player player = event.getPlayer();
player.sendMessage( event.getBlock().getDrops().toString() );
}``` Hmm, I get emptz result. Did I do somehting wrong?
try using a for and then sendin
Some times the toString() is not done and you only get the hash
I want to multiply drop if a certain condition is met
public void onBlockDrop(BlockDropItemEvent event) {
Player player = (Player) event.getPlayer();
player.sendMessage( event.getBlock().getDrops().toString() );
for (ItemStack drop : event.getBlock().getDrops()) {
player.sendMessage( String.valueOf(drop) );
player.sendMessage( String.valueOf(drop.getAmount()) );
}
}``` hmmm nothing changed. I get only empty ``[]``
why does that sound like a 1.7 issue
older versions tend to be buggy like that
english 100
How have I never known that "bool ^ bool" (XOR) exists?!
Hi ! I would like from this code to ensure that it is a certain item with a certain name that cannot be dropped, can you help me please?
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
if (event.isCancelled())
return;
event.getItemDrop().remove();
event.setCancelled(true);
}
Even if the name contains a particular color? (§9§lGame)
To do that first get allthe dropped items and then loop over it, checking if ItemStack#isSimilar(yourCustomItem)
Okay, thx
ur welcome
If need more help feel free to ask
Amazing mvn command is not working anymore no matter if i set the env path again and over again
For those type of questions you have the javadocs
?jd-s
i said nevermind
I know but just letting u know
there a proper resource for forking spigot? not really sure where to start
I dont know why but most people prefer forking paper
i haven't really looked at paper much
it seems like it might have better documentation on doing exactly that tbh
...or not.
(If you voted on the poll please tell us why you chose what you did!)
Yo. After like 5 minutes of looking I've discovered that there are way more spigot forks than I thought. Is there any rule of thumb regarding them? Are there any things to watch out for? What's the reason to get a smaller...
Agree
oh sorry
what an amazing way for looking better
google built different
tbh if an existing fork already has optimizations, then great, i don't have to do it
any
What are you needing to fork spigot?
There are alredy multiple forks for diff things
hard to keep track of all the forks as a developer
it'd be nice to know which forks do what, specifically
oh ok
tl;dr java is implementing SIMD support (finally) and MC only runs on two threads by default - sync thread for the game world and async for chat
you can add async tasks but
some stuff i'm working on could definitely benefit from optimal thread usage + SIMD support
SIMD?
single instruction, multiple data
it's an ASM thing
but C/C++ have supported it for a while
basically allows you to optimize basic instructions on vectors of data
it's not simple so if you're interested i'd suggest doing some research, also depends on CPU architecture
if i use this will it return the block east 1 block away
Block under = block.getRelative(BlockFace.EAST,1);
jman?
what?
why dont you try it on the sever
I think its the best way for seeing if something is correct or not
bc i dont want to do that bc the plugin isnt set up i still need a config and a plugin.yml and a bunch of there stuff
Na i was shocking i mean i dont really have patient and i get mad for whatever
lol
by the way dont use § thats really disgust
just make a format method
public static String format(String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}
DevelopperWilliam can i ask u a question please ?
if you are using intellij and maven you can choose the Spigot option when creating a project under Minecraft and it will setup plugin.yml automatically
Sure
Hey,
Is it possible to access a file in the plugins "internal" resources folder?
I just want to have a second config to declare some stuff, but without creating it in the plugin's folder
.
Do you know the Gui system ?
the gui system?
pufferfish uses SIMD for map rendering
Creatiion of GUI in spigot
Loving spigot coding im getting NPE when using PlayerInteractEvent#getClickedBlock()#getLocation()
Just create a gui
y have to check if the clicked block is null
you can use something like this https://github.com/TriumphTeam/triumph-gui
<dependency>
<groupId>dev.triumphteam</groupId>
<artifactId>triumph-gui</artifactId>
<version>3.1.3</version>
</dependency>
And when im checking if location is null its warning me that location is always false
public void openGUI(Player player) {
Inventory inventory = Bukkit.createInventory(null, slots, title);
player.openInventory(inventory);
}
this easy
check my discussion thread x)
Williams but if i check if location is null and return; its giveme a shity warning
I dont understand java its bipolar some times
could u send the stacktrace or warning
yes the 2 things
I think i fix it
I wasnt checking if the clicked block was null or not
But then its trolling me again hahaa
Because when i run the command its not giving me the wand item
hahaha what a shity day
are they using experimental java features?
I'm on a server that uses pufferfish, probably for that exact reason
i'm using a lot of armor stands and custom AI on a fairly large scale (way larger than a pet plugin or a mythicmobs boss) so i just want to make sure what i'm doing doesn't eat the cpu lmao
What are the reason of an item not being added to a player inventory?
Because fucked java is making me rage because its not setting up the item into my inventory and i have debugged
?
Can I see the code that is adding the items
like the whole bit that involves the inventory
Hm it always works for me without even using updateInventory()
I mean none of the debug messages are getting sent to everything is okay
Yes i know just add that to see if was something else
but its really weird haha
I have no clue
maybe the item is null
I will check that
@sterile token check if the wand is null or not