#help-development
1 messages · Page 540 of 1
“Can this be reopened? This as the current fix still can cause a memory leak. Entity metadata doesn't automatically delete on entity delete, so you need to either do it yourself or use a custom system for storing this data.”
Yeah, in that regards it's leaky. Though that's sort of tough to fix tbh
Java doesn't have destructors
Can’t you remove it on death
It should persist across deaths
On entities?
Yes
I see
I use a similar concept on VeinMiner by the way https://github.com/2008Choco/VeinMiner/blob/155327e1aa487859485abe9a7122d73e45261917/veinminer-bukkit/src/main/java/wtf/choco/veinminer/listener/PlayerDataListener.java#L40C68-L41
Can it be fixed with weak references
Dunno. Haven't looked at the impl super in-depth enough to know how to resolve leaky API like that. I don't even really think you can resolve it without destructors
Hmm
if (item1.getType() == Material.IRON_HORSE_ARMOR && itemd1.getCustomModelData() == 1) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_AIR) {
List<Block> los = e.getPlayer().getLineOfSight(null, 5);
for (Block b : los) {
if (b.getType() == Material.WATER) {
itemd1.setCustomModelData(2);
world.playSound(block.getLocation(), Sound.ITEM_BUCKET_FILL_LAVA, 5,2);
item1.setItemMeta(itemd1);
Bukkit.broadcastMessage("test");
break;
}
}
}
}``` @eternal oxide
this code not working btw
Might be something to look at if I get bored
i mean works but if click block in water not working
Point being, super super useful API, people just don't know how to use it correctly. Deprecating it isn't an option
Fair enough
Might be good to add a warning that you should explicitly remove any metadata you add
If it's not in the Javadocs currently then yeah, could probably be set on Metadatable
Although imho I think metadata should extend beyond a player disconnecting
For the same reason a Player instance still exists so long as a reference is held
Yeah I guess as long as the instance is still valid it can be useful
what version spigot?
do you have an api version in your plugin.yml?
you are on paper then
spigot
I forget what the default is for ignoreCancelled on events
I believe it’s false
won;t be that then
what i need cancel event ?
It’s false
since when can you smoke water
I had an idea for using lombok/manifold extension methods but i want to know if its an appropriate use
we have a lot of "manager" classes, like party manager, level manager, etc.
its a pain to pass all these around, and it'd be nice to use object methods like player.getLevel instead of levelManager.getLevel(player)
so I was planning to use have some special player wrapper class
like PluginPlayer or whatever
that has all those methods
and then has .asPlayer()
this is all fine
the only problem is that it's a pain to go from player to plugin player
is it unreasonable to add like a .asPluginPlayer method to the bukkit player interface
PluginPlayerManager#asPluginPlayer(player)
not literally but using an extension method
you really dont want to do that
all the managers
wrapping the playerdata is good
then you only need to pass one "manager" around
lets name it repository
the PluginPlayerRepository f.e.
which caches your wrapper instances
I have a lot of managers in my recent plugin
Sadly they don’t all connect to a player tho
manager classes are the pure evil
you usually dont want to have them
and there is most likely a better way to approach what you do
despite that "Manager" is an awful suffix
they really aren't
it's more the name than anything
good for you
I'm avoiding using static, and using dependency injection to get them into my classes
I have to manage state thats built upon builtin classes somehow
why are you avoiding static
singletons are not always wrong
private SpellPartRegistry spellPartRegistry;
private CustomInventoryManager inventoryManager;
private ConfigurationManager configurationManager;
private PlayerManager playerManager;
private AltarManager altarManager;
private StorageAdapter storageAdapter;
tragic
what's a "manager class" in your opinion
once done ugly your code's shit
perfect example
what principles
I think they do a much better job of OOP principles than singletons do
di all the way
mostly SRP, encapsulation could be, DM, and the lack of abstraction
how else shall you unit test
Tbf I like singletons
my managers are all interfaces
But many people disagree
a class to manage your object
turn them into services
and voila
if I were to
All of these are basically singletons
whats wrong about that
rename them to BlahBlahBlahService
and change nothing about them
would that be preferable
ASM is pretty okay done, wouldv'e understood if you would've complained about antiac lmao
depends how they are build up
what do they do
the architecture is important
for example LevelManager
actually that one's called LevelController
because I made it more recently
the managers are all old
but anyways
public interface LevelController {
/**
* Gives back the level of the player
* @param player player to check the level of
* @return the level of player
*/
int getPlayerLevel(OfflinePlayer player);
/**
* Levels up the player by 1
* @param player the player to level up
*/
default void levelUp(OfflinePlayer player) {
addLevels(player, 1);
}
void addLevels(OfflinePlayer player, int amount);
/**
* Sets the players level - should be used for like
* an admin command or something
* @param player the player to set the level of
* @param level the level to set the player to
*/
void setLevel(OfflinePlayer player, int level);
}
for that I would do what you initially said
make your own player class which wraps around the UUID of a player storing extra attributes
f.e. the level
And then have a manager to keep track of them
not a manager, please
I already mentioned that I plan to make a wrapper class
yeah but dont extend or reimplement the bukkit api
im not doing that
i mentioned using lombok extension methods
where you add a fake new method to a class
which is really just a static method
a fake new method what
inventory.getViewers().forEach(HumanEntity::closeInventory); inside a sync bukkit tasktimer throws java.util.ConcurrentModificationException: null what am I doing wrong
yeah because you remove them while looping over them
that wont work
sorry lemme rephrase
new fake method
not fake new method
basicallyh
that doesnt change the fact that im confused
how am I supposed to close their inventories then
delay it by a tick
Aren’t Lombok extension methods just fancy ways to have a static method
public static void doACoolThing(Player thizz) {
// Do something
}
Player player;
player.doACoolThing() // valid
// which is compiled to
doACoolThing(player);
its just a way to make static methods look a little nicer
thats so inconvenient
welcome to spigot
or better, java.
you cant operate on a list while looping over it
you could just copy the collection too, I think that's better than delaying stuff
You are supposed to delay certain things by a tick in the inventory click event
That’s just how the event is
what event, there was no event given in the context
🧠 🙏
yeah well no i dont see why you would need something like that
So what do I change these all to :p
cant advice without context
so simple yet I didn't think of it, it's time to go to sleep
thanks though
i meant to reply to this
bruh
Fair
And yes a lot of code is just thrown together atm, don’t question the random try catch in the onEnable for example :p
yeah was about to say, this is all so entangled
Exceptions in constructors 
there are many things to criticise
nah fuck that
More async makes everything better
start in the first layer
Exactly
Surprised so few of Bukkit's events are async. They should all be!
Bukkit would perform so much better!
time to build out the async catcher
SuperDuperAsyncSpigot
Gotta go for that deluxe async multithreaded data driven object oriented uhh
<Insert a bunch more buzzwords> code
stay
Functional
Because Functional is more catchy nowadays
and it functions better
Annotate it with a new annotation, @FunctionalClass. It's like @FunctionalInterface only it's not
Actually just annotate it with a new @Functional annotation instead. That way API users know that the class is working as intended
Is there also a @NonFunctional
FSpigot
No that’s spigot in F#
That's just any class that isn't annotated with @Functional
here is a good OOP example: https://github.com/GodCipher/the-cipher-project
How do I stop the eye bleeding
not sure
A tampon
Eye period
Good for nose bleeds, must be good for eyes
go to the doctor you probably shouldn't be bleeding from your eyes
no no
tried to catch the blood with your eyelids?
I feel like a pad would be more effective
It’s too late the Amazon drone is already here
Yeah idk I notice all my recent projects have a lot of managers to pass around
That’s probably the biggest issue
Managers 😭
the most annoying thing
jesus I just make a ManagerManagerBuilder and call it a day
Yeah but like what else do I useeeee
its not that big of an issue
Ah yes a ManagerManager
just a tiny big issue
Why didn’t I think of that
tut tut, you also need a ManagerManagerBuilder for teh cool pattern
like sometimes compromising design for usability (like with managers) may be justifiable
I mean technically they are all accessible from the main class so I could just pass that to everything
chunk them together to a ManagerBundle
frrr ^
Exactly
before i knew what i was doing, and i still dont, i made infinite sub classes in my class to have a this.class.doesthat.cando.with.cool.shit effect.takethispath.andyes.store
?paste
first of all work at the names
just be glad you didn't write this https://paste.md-5.net/xatehosuru.java
I had to come in and fix this code when the dev before me got fired
then SRP, then untie the knots
and after all that refactorating you can think of how do i get that in this class
Pair sadly got removed
This is why you keep all your code closed source, then nobody can judge it
whatever you will tell chatgpt, it wont be able to reproduce that
thats for sure
good business dont need good code
it just have to work
f.e. twitter algo
never change only add
It may not be good, but it needs to be maintainable
if I can't add to it its shit code
non functional
How are you supposed to add when you have 30 singletons overlapping the same responsability? its nearly impossible
Just try harder
code debt go brrrr
Takes less time to add more garbage than it does to clean up garbage
?paste
i spent 1 week redoing the entire game engine versus spending 3 weeks learning how tf it works 🤷♂️ in my situation redoing it was definitely easier
only thing
why does it need a gameprofile
and not just directly a player or whatever
thats not a mojang thing
its a internal impl of something
ohhhhh so they just named it stupid
😭 rude asf man, but yeah makes sense lol
yep I did, but we don't use mojang code in the game engine so its fine 😎
Clearly it should be PlayerProfile
PlayersGamesProfiles
Just a convention to avoid pluralization
choco, respectfully, no.
Only reasonable case to use a plural class name would be for a class containing constants or utility methods
Enums contain constants but are data types
well yeah no, same for collections or grouping
Collections is a utility class
org.bukkit.Materials
Or something made to hold multiples
So is Arrays, or Utils (I hate this naming convention, but technically valid)
for example I have a class ILoadoutItems because it's the wrapper of a Map
(it's not actually wrapping a Map but the result is similar)
Managers to group manager classes
Quick someone judge him for using the I prefix
I would even avoid it here. LoadoutEquipment, LoadoutSet, or even just Loadout would be better
IAbstractAsyncLoadout
the good old Listeners class

I mean, I don't see the problem with plurals
Why does 19 ur old coll feel attacked
if it feels right then I do it
the reason I have prefixed my interfaces with I here is because I wanted it to be clear that it isnt the implementation, because I'm providing both
(albeit under different class names)
ILoadoutItems is only provided anonymously, though my others have default implementations
Something tells me people will disagree on design choices throughout all of time and space
definitely
i disagree
L
Alright well
bro wait a minute
wtf is this bullshit
why there an automatic new line after my end class brackets
i know its convention but like in C or some bs
I can't think of any classes where I've named them with plural words
I have an IKitsConfig and YamlKitsConfig in the same project
but that isnt really "plural"
its plural but only in the adjective
not the noun
Credentials
I have some, but it's "Utils"
oh wtf
there's 2 immediately I can think of in the Java stdlib
stop making trouble
Collectors and Collections
i avoid using them because they are plurals
though recently I've been typing out "Utility" instead of Utils
oh i also have a class called TaskForce1
nope I've got nothin, no (recent) projects where a class name is plural
It's because first is class which contains multiple static collectors and other is also utility method for collections
Those are not really any kind of instance classes
oh so i can start using them?
It's fine ig
how do i instantiate them
Kek
I’ll just get ChatGPT to write all my code
If it writes it then it can’t be bad
automate it and force chatgpt to check itself 10 times
See because a computer can’t write bad code that will be run on another computer
That’s like, poisoning someone
And that’s illegal
is it possible to listen when a fence updates visually? for example a player places a block next to a fence and this updates connecting to this block, or a player places a fence and this updates connecting to nearby blocks?
i have tried using BlockPhysicsEvent but it didnt work as expected
i have also checked out NMS to try and capture the package that updates the fence, but didnt get it to work
using 1.19+ java
public void onBlockPhysics(BlockPhysicsEvent event) {
Block block = event.getBlock();
if (block.getType() == Material.COBBLESTONE_WALL || block.getType() == Material.MOSSY_COBBLESTONE_WALL) {
event.setCancelled(true);
}
}
``` this kinda works but its quite buggy
Yeah I think physics is the only one that would be fired in this instance
but that means theres a deaper level with packages, something is changing that fence
something somewhere is udpating that fence because a new block was placed
I think the internal method is called updateStateForNeighbours
When a block is placed it notifies all neighbouring blocks which can then react however they see fit
Blocks and chunks
Is this static abuse?
Anyone know how to properly rotate a display entity to set degrees on XYZ using the setTranslation method?
Is the only way to change the required spawning light level for mob spawners through nms?
is it possible to get an offline player by name if they've been on the server before
using their previously known name
I don't want the server asking mojang or anything in the middle of a tick
Bukkit.getOfflinePlayer(string) is deprecated and idk if there's anything better for this
this is for commands
I don't want it to run a blocking io call
if its to the hard drive that's fine if its to the network it isn't
<plugin>#getServer#getOfflinePlayer isnt deprecated
yes it is
getOfflinePlayer with string is
with uuid isn't
but I am trying to get it with their name
It isnt deprecated for me
I want those using the command to be able to type the name of the player
declaration: package: org.bukkit, interface: Server
In intellaJ it isnt saying deprecated, also it being deprecated doesnt matter
The reasoning is because "Persistent storage of users should be by UUID as names are no longer unique past a single session."
If you are not planning on accessing users too far into the future after they logged off then its fine
also they are correct, you should use UUID and not username since usernames are not unique after a session is ended
did you read my usecase though?
I'm writing a command
my users are not going to check people's uuid's then they want to refer to them
^
yes I did
Obviously not
Not at all
you said that its okay for me to not use uuid
and then you said that I should use uuid
not a contridiction
a contridiction would be me saying its okay to use uuid then to say its not okay to use uuid
what I wanted to know is if there's a method that won't potentially make a blocking web request
I said you should use uuid, I never stated its not okay to use uuid thus I never contridicted myself
dawg that's just how I interpreted at first
because I was reading quickly
Double check your reading before you blame people then :/
MiniMessage miniMessage = MiniMessage.miniMessage();
Player target = player;
if (args.length > 0) {
target = Bukkit.getPlayer(args[0]);
if (target == null) {
player.sendMessage(miniMessage.deserialize("<red>The referenced player was not found."));
return;
}
}
I have this code in like 8 classes for commands to get an optional player argument. I've considered making this a method but even then I feel like it won't really reduce the amount of code in the method? any ideas?
im just sleepy maaannnn
like your username lol
if you're writing it again and again
in exactly the same way
then it'd probably be nice to have
as a method
Id say its better if he just simplifies it into 1 line then make a method but its his choice
like what if you want to change that and then you have to change all 8 (and likely soon to be more) versions of it
how would you simplify that to one line??
well you could get rid of the first if
right
oh wait nvm
no because it's optional
oh okay well you cant do statement && return like in js so its 3 lines
just gotta slightly modify my idea
Player target = args.length > 0 ? Bukkit.getPlayer(args[0]) : player;
there's your one liner
and then just check if target is null
if (args.length > 0 && Bukkit.getPlayer(args[0]) == null) {
player.sendMessage();
return true;};
that never sets the target variable
edited
oh mb I thought you use just checking if it was a player
(wrong reply)
lol
yeah then I have to reset it to the player
this looks good but it doesnt check if its a player or not so you will have to check the target value to be null after
edit: im dumb you said that
no?
yea
cause that's not what I want here
or returning or something
yeah
my statement is exactly the same as the code you already have
without the second if statement
not exactly
but similar enough
I'm still gonna have repeated code though
move it to a function
I'll make it work and come back
🫡
omg hapily
hi jake
ok here's the problem
I have the method to get the player argument right
then I check if it's null in the execute method and then send them a response and stop the execute method right then and there
but that's what
4 lines
of repeated code
which is equal to what I already have
or actually like 1 line less
just make a method which takes in the args and the executing player then do all the checks and messages in the method, return either true of false and then do if (!method(args, executor)) return true;;
Just use offline player
I think he needs it to be an online player (im assuming)
yes
Why?
does it matter?
Yes
no not really
cause the operations I'm performing on the player are them being there
if he needs it to be an online player then he needs it to be an online player, doesnt matter to us what for
Well that is your opinion. But if i provide help i try to steer to best practices and usages
I assume he knows enough to know whether he needs a player to be online or offline to perform the desired action on them :/
I get where your coming from but it just doesnt apply here
If you understand then everything you said was pointless as it will not change how i provide help
I dont make assumptions and therefore why i ask questions of their code
I do not need to change how you provide help to get my point across
I have literally zero clue what you mean
What are you making and what issues are you having?
commands and the issue I'm having is repeated code
So i can understand better and provide appropriate input if able lol
Alright so, make a method that takes in 2 arguments, one being the args from the command and one being the sender (or player), then inside the method check for the args length, check for the player and whatever other checks you need, if all checks pass return true in the method, if any check fails use the sender arg to send them a message about it then in the method return false, Back in your command code check whether the method returned true of false by if (!methodName(args, sender)) return true;
(i dont know your level in java so incase you dont know the !method() in the if statement is a replacement for doing method() == false)
Mind elaborating on the commands part?
Depending on what you are doing i may have some example code for you
I'm gonna have to call Bukkit#getPlayer(String) twice
Why?
Well i guess i can show you how i do commands
?paste
Is it allowed to feed code in this server or no?
https://paste.md-5.net/ikapeserox.java base command
https://paste.md-5.net/xesuyazoka.java example subcommand
that's what I have rn
This is how i setup my commands
Hes not having issues with creating commands
I know how to make commands I'm using my own command system
I typically make use of sub commands unless it doesnt make sense to
Please leave us be for now frost
^ yes/no?
Maybe not, but it sounds like your system isnt very well designed if your issue is repeated code though
*note to myself look at this later then got time
So it may help to see how others do it
it doesn't handle argument parsing or whatever like brigadier
Oh you want tab completions
Hes issue is repeated code when checking if the arg input is a player in commands
it's just made to be a little bit better than BukkitCommand (commandmap way of registering commands, not plugin.yml) and does like half of the things for you
Tab completions dont force the given argument (from what ive seen)
Well this isnt difficult, if it must only be online players to match then you can do this by grabbing a map from the collection with the player names as keys.
Tab completions do not force the argument to match them (from what ive seen)
It doesnt matter if you give the end user all the options if they can input something else to break it
Passing completions does not fix his issue unless there is a way to force the completions as the only accepted arguments which I do not know about if there is
Well you can provide possible completions as they type but you cant force the completion as that is client side
Exactly my point
so please
leave us be since you are not helping
I appreciate the efforts but it will only cause more confusion
Then go to dms if you dont like public forums
I am more then welcome to have him privatly message me if he so prefers
Then it seems it isnt solely your decision
I politely asked you to please refrain from trying to help since what you are saying could only cause more confusion
I am not making any choices for anyone I am simple suggesting something
You are not forced to listen but it would be more helpful if you did
Sure everyone here is free to do so. But you suggesting someone to not talk is not constructive either
@lethal coral im sorry about this, we can continue this here or in dms whichever you would prefer
idrc but in-case anybody else runs into the problem maybe here
Alrighty!
Here ill write some example code to show you what I mean with explanations
You both failed to explain the situation adequately. But in either case it seems their problem isnt all that trivial if they are looking to not repeat code
I understand his problem perfectly
Please refrain from speaking if you wish to help
moving on
Always want to hush people lol
I only hush people whose input is not needed
And you are in a public space
I still have the right to express my opinion as much as you do
Do you need reminding again?
I have the right to express my opinion as much as you do
Never said otherwise
I do not have to listen to you and you do not have to listen to me
Speaking of which I am now going to ignore you since this conversation has no positive effect on anything relating to spigot, spigot developers or any developers in general
Sure doesnt bother me in the least
Anyways time to look at the pastes
To see what they are saying in regards to repeated code
I think personally in this situation the repeated code for checking if the player input is valid is not an issue since the repeated code is necessary and even if you made it into a method it would still require a few lines to set the target variable
Player Target = Bukkit.getPlayer(<username>);
if (args.length == 0 && Target == null) {
<executing_player>.sendMessage(<message>)
return true;
}
Would be your best bet, <username> being the provided username, <executing_player> being a reference to the player running the command and <message> being the message you want to send to them for inputing an invalid player
I am no means an expert but I personally dont think repeated code in this sort of context is bad for the reasons above
That piece of code seems fine and is similar to what others suggested. I dont see how this is repeated code unless they are referring in that they dont want to repeat that code in all their sub commands. If that is the case then move it either to the main class or to its own class. If its something expected to run all the time probably wise to make such methods static regardless where its at.
This would be the only way to avoid repeating such code and keeping it optimal
Yes they meant they didnt want that code in other commands/subcommands but even if you made it a method in a main class it would still use 2-3 lines just to check the method and assign the target variable
I would say use recursion but i probably wouldnt recommend it in case simply for the fact it seems it may get used too much and recursion can be bad for that somtimes lol
Yes this true, but this shouldnt be a concern in regards to creating a function
Purpose of a function is repeated use, not how many lines the function needs
He already implied before that he didnt think it was worth it if it already used the same amount of lines
I hope their concern wasnt how large the method function would be?
It is if it has repeated use. It would also help the jit optimize better
here
Hope that answers their concern in regards to that
Also the other advantage is that if something is wrong with it or it needs tweaking
Instead of changing that repeated code in however many command classes you only have a central point for it
I dont feel like a check for user input being a player would change that much
In fact this code would fit perfectly in a utility class where you could override it if necessary
I doubt it, but its how the end result is obtained. It would be beneficial if that piece of code you gave was in its own method and then that method used where its needed
Sometimes 3 lines of code may seem insignificant but if you actually trace all those objects and methods back to where they come from as well as understand how the jvm and jit try to optimize. Then those 3 lines becomes clear that they are not as insignificant as you assumed them to be
One of the main objectives in objective programming is object reuse and code reuse
args.length can't be 0 otherwise there is no player arg
sorry yes
and I gotta check the length is greater than 0 before trying to do Bukkit#getPlayer(String)
but I would still have to extract that if before
So if you are able to reuse code that means put it in its own method and many things can use it, then this is generally the best choice
otherwise I would get a potential indexoutofbounds exception
yes I would do that if I could
but I can't because I have to set the variable and in certain circumstances also stop the code
so I thought of throwing an exception
but even then I would have to have a try catch and then it doesn't reduce anything really
Which variable?
The player?
I do that
Default should be the same as the player doing the command in this manner its never null and easier to check
yes I have that already
Alright i think that covers setting the variable
no
Then i think you misunderstand a default
I don't
If there is a default variable is always set
what I'm saying is I have to set the variable to the argument
Alright, and why is it that a function couldnt do that part for you?
There is more pieces. You can feed a function any number of objects you want and with recent java versions you can even use optionals
Is the issue at hand in trying to make the function return what you are wanting?
ok frostalf
I think you should give this a go yourself
and explain to me what you did to improve it
so I can learn
Well i think we need to work out the part where you say a function wouldnt work, because i am failing to see how it wouldnt. At least given my knowledge in how objects and methods work.
The piece of code to check for a player for example can be returned in 3 different ways for example
The code above that is
yes frostalf we are not understanding each other
Since this seems to go for a while already - where's the code?
so if you give it a try maybe you will understand what I'm trying to say
You could return a boolean, return a string, return a player object and the 4th is returning nothing but instead setting something aka void method
https://paste.md-5.net/ikapeserox.java base command
https://paste.md-5.net/xesuyazoka.java example sub command
I have the optional player argument getting part repeated in like 8 classes
and we cannot seem to figure out how to effectively reduce the code repetition
Usually you can trust on frostalf's advice. I just wanted to take a look because you two seem to not be on the same track
We are not, but as i said i think this is mostly due to our differing experience and knowledge in where they are trying to convey a problem that i cant see as a problem
if (args.length > 0) {
target = Bukkit.getPlayer(args[0]);
if (target == null) {
player.sendMessage(miniMessage.deserialize("<red>The referenced player was not found."));
return;
}
}
That part?
yes perfect and the Player target = player;'
Well it was suggested to be moved to main class or its own class and you feed the method what it needs. So in this case i would recommend the constructor taking in a command, and spitting out a command.
And it would be the first thing your commands go through
Then you can interact with it however you want
If further interaction is needed
see that sounds great in theory but I just tried to connect the bridges in my head and they didn't connect
Fantastic, we have identified the problem then
no we did not
This right here is the problem and we can work with this
idk I think we're going to run into problems pretty quickly
For me to properly help with this particular problem i need to be at my computer. Currently at work on a phone and its not adequate. Unless maybe fabsi here understands and can demonstrate
proof im tired
What frostalf is suggesting would work but I can understand how that's hard to understand for devs without years of experience.
And simpler approach would be to have a function with the args array and the commandsender and then sending the message & returning null or returning the target player.
Would reduce the repeated code to
Player target = getTarget(player, args)
if(target == null) return;
if ((Player target = getTarget(player, args)) == null) return;
What I don't fully understand at this point is what you want to return. An instance of SimuXCommand?
Do you want to call your method before actually going into the execution?
it would still be only 1 line less
that idea was proposed earlier
As I don't know the command framework that is used here I'm not aware if that's actually possible.
but it's still repeated code
Well a function call is one "repeated" line aswell
sure
Your idea might be better or just as good too
Unless that command framework has some function where you put code to run before every command - then there's actually 0 repeated code
whats a good yaml editor?
this would actually be
Player target = getTarget(player, args);
if (target == null) {
player.sendMessage("error");
return;
}
which I suppose is a bit better but nonetheless 💀
Repeated code doesnt include function calls. Because otherwise how are you suppose to call the function, the only way to have this not be the case is if the initial entry was the function to begin with
you can send the error inside your function aswell
if ((Player target = getTarget(player, args)) == null) return;
ig
that's why I put the player in there in the first place
Condensing it like that isnt exactly the overall point lol but very nice regardless
well no the player has to be in there to be able to set it to the player possibly anyways
My idea earlier was on the basis of initial entry point, but fabsi did bring up a good point that it does depend on your framework
Oh. I overlooked that part.
In that case you would have to return the player itself if the args length is 0 instead of null
maybe you did that already
I suggested this already as well
Optionals are cool
Maybe i am just too advanced to help
Am i really that knowledgeable that i cant help right now with something like this? Lol
public boolean isNull(String[] args) {
return Bukkit.getPlayer(args[0]) == null;
}
if (isNull) return true;
No don't feel like that - you are just abstracting a lot of steps at once. Beginner or Intermediate dev will have a hard time understanding that
you could do that too
you're just too old
im just giving an example
you are not funky enough anymore
I am inclined to believe this but fabsi's response is better
Maybe you are to something here

They are having trouble understanding how to abstract a piece of code in their command that will have repeated use and turn it into a function
@lethal coral
private Player getTarget(Player player, String[] args) {
if(args.length == 0) return player;
Player target = Bukkit.getPlayer(args[0]);
if(target == null) {
player.sendMessage(miniMessage.deserialize("<red>The referenced player was not found."));
}
return target;
}
Something along those lines should do the job. Just don't forget the null check when you call it.
Their other issue is when doing so how to handle errors or other problems with said abstracted code
I didn't need that but thank you
https://paste.ethannetwork.net/ayiloserej.cpp https://paste.ethannetwork.net/utokurenag.typescript
The file is not getting its contents saved
I do not know why
minimessage coming in from the void
🚎
public void saveConfig(FileConfiguration config, String configName) { try { config.save(new File(plugin.getDataFolder(), configName)); } catch (IOException e) { logError("Error while saving config,", e); } } If you want to know
ah i see
Am I too old to understand that joke?
🚋
the trolley?
Or did I not sleep enough? lol
🛒
🚲
woah, outstanding move??
🐗 hihiha
fixed
YOU ACTIVATED MY TRAP CARD 🚙
I'm confused
GG
Just return player from the constructor if target is null
I can't use external emojis so that's my replacement for the troll emoji
and it makes no sense so ha funny
02:26:02] [Server thread/WARN]: java.io.FileNotFoundException: plugins\BetterServer\playerdata\homes (Access is denied)
but the file is there
bad troll emoji
Now I'm speechless
access is denied
Did you know GitHub has a real trollface
Check perms and also check spellings and caps
might be spelling
Well then you would get an error that the player was not found and then set your own gamemode. That's rather confusing
Tf is that path
you name it. Did you create that file with another user? Might have to use chmod to enable access
public void saveConfig(FileConfiguration config, String configName) { try { config.save(new File(plugin.getDataFolder(), configName)); } catch (IOException e) { e.printStackTrace(); } }
this is the file saver
Well you would check the return to ensure what is returned isnt the same. If it is dont do anything
plugin.getFileApi().saveConfig(getConfig(player, plugin), "/playerdata/homes");
this is how I called it
https://paste.ethannetwork.net/ulefubagab.java
is the getConfig
i would rather use an optional and fail if its not present in the end
That path looks absolute
Yeah you could do that too. I dont use optionals much but forget they are there lol
I only ever use optionals because streams provide them on findFirst() to which I just go with orElse(null) to create fancy one-liners that probably everyone will hate when seeing them.
Lol
optionals are cool and all but also very annoying if overused
but once you design your shit optional based its over
.map(value -> /* ... */)
.orElse(default);
``` is pretty nice tho
Optional.None when
Optional.empty()?
Cant afford An if check at Runtime 💀
Optional != null
I hope this was a good learning experience in that sometimes the issue is your understanding and not necessarily the code. Which i hope helps you to better convey problems in the future and to not assume when others are asking questions its not due to lack of experience but rather trying to grasp what is really the problem. As you seen for someone like me, it can be hard to convey the solution if i dont know your level of understanding and knowledge and inadvertently tell you things that seem impossible or make no sense
Those icons back?
Thought i should put that out there
currentField = actionFields.stream()
.filter(field -> {
String configKey = field.getAnnotation(ConfigurableValue.class).configKey();
if (configKey.isBlank()) {
configKey = field.getName();
}
return configKey.equals(fieldName);
})
.findFirst()
.orElse(null);
if (currentField == null) {
continue;
}
The more I code the more I use streams and the less readable the code gets :(
I never said it was a problem with the code
if it was the compiler's fault I wouldn't have come here
frostalf playing god rn
thats my role
and I also didn't say you lacked experience which is why I told you to give me an example so we could bridge the gap between what you were saying
Well regardless i hope you learned something nonetheless
Oh my bad. Seemed like something that should be said

While true you did end up saying this, the other issue is i couldnt provide you with an example in more ways then one. The major one was me failing to grasp the level of understanding you had or your experience level. And also could be that i typically dont spoonfeed code more so if i dont know if you would understand it. But yeah seems like you are getting the proper help now. And with that i have some work to do
So sorry i couldnt do that
And i need to learn to not be so abstract as well it seems
signal writing a novel rn
looks like an ego problem to me.
Is it?
Seeing you reflecting yourself like that hurts my feelings frostalf. What you did or suggested wasn't bad at all. Sure he wasn't quite understanding what you said but that's neither yours nor his fault. You suggested what came to your mind based on your knowledge. He could have asked for a simpler solution - he chose to try to understand what you suggested. You both did a great job and none of you should feel bad at this point ♥️
y'all both having a mental breakdown over misjudging someone
looks like it
Optimization question. I have a large set of data used for a wide variety of items, mechanics, and dialogue ingame (stat blocks, requirement lists, that sort of thing.) Sadly, the data can't be hard-coded, I can explain more if needed, but I retrieve it from an SQL server using a String object, but I'm puzzling over what to do next.
My question is, which is better: to deserialize into one giant JsonObject that we can pull from? Or separate into multiple smaller, different JsonObjects?
Assume the data is going to be accessed at random by different players and game elements (we might need to reference a stat-block when spawning a mob, for example.) Which is better? Or should I be approaching this in a different way?
ahh there it is
Lmfao sorry
I dont have mental break downs
not yet
You only want to fetch the data you need
for that you have microservices
Fetching one giant json object is just going to spike your RAM usage
Perfect
Thank you
So it'd be better to create multiple smaller ones for what we need
I dont think i ever will but i will be poking your brain later on the looks of it being ego cause i dont see it
Same reason we use multiple individual player files when dealing with file-based storage instead of making a giant one
Perfect. Thank you!
Guys what plugin do you use for custom GUIs?
long story short: you think too much of yourself, at least it looks like it. thats why you behave in a rather abstract way. you do not trust the person looking for help enough to understand your help because of your experience. so you only have one solution for them. not sure how to say it in english, but you arent staying at the same eye level with the OP
or do you mean like a lib
if you mean a lib, I just make my own stuff for everything
I tried CommandPanels but i don t know how to configure it
^^
That's pretty harsh. I'd say the problem is just being used to people that join this discord, basically learned nothing but System.out.println("Hello world"); and ask how to code Facebook as a spigot plugin (this is an exaggeration but you get the point).
I also have to evaluate each developers on whether helping them would be reasonable or would lead to spoonfeeding
coding facebook would just be easy :)
no, thats victim blaming. well, kinda. its pretty much possible to help people and help them, or try to understand them, without taking the position way above their head. you don't have to put people down or tell them how bad they are compared to you. thats all im saying
if(!facebook.isPresent()) {
createFacebook();
}
facebook.orElseGet smh
But that's not what he did
indirectly, yes.
also the reason for my comment here
im a fan of satire if you didnt noticed yet
He provided a solution that was hard to understand but I doubt he did that to "play god". More like because he's used to solve his own problems like that.
i dont want to boo anyone. he asked what i see, and i told him. what he does with it is not my beer
which could be the case, but we dont know, since he didnt delivered it like that. the tone plays the music, or whatever
therefore we have ?learnjava
so, ive shown enough humanity. y'all suck noobs
exactly that is the reason I'm not always motivated to help.
As long as I notice the person on the other side is trying their best and is listening to feedback instead of saying "but chatgpt said that's better" I'm willing to help.
If "you don't have enough knowledge to achieve X yet and should start with Y" makes them mad then I'm out
String coordkey = loreLine.substring(19);
int length = pigsection.getInt(coordkey + ".length");
long expiration = pigsection.getLong(coordkey + ".expiration") - System.currentTimeMillis();
int amount = pigsection.getInt(coordkey + ".amount");
long experience = pigsection.getLong(coordkey + ".experiance") - System.currentTimeMillis();
if(e.getCurrentItem().getType() == PLAYER_HEAD) {
double moneytogivepercent = (((100.0 - (((double)expiration / length) * 100.0)) / 100.0));
if (moneytogivepercent <= 100 && moneytogivepercent > 0.005) {
double moneytogive = ((moneytogivepercent) * amount) * pigmake;
String playerName = p.getName();
String moneycmd = "economy give " + playerName + " " + moneytogive;
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), moneycmd);
pigsection.set(coordkey + ".expiration", System.currentTimeMillis() + 14400000);
}else if(moneytogivepercent < 0.005){
p.sendMessage(ChatColor.RED + "You need to have the GENERATOR at least 0.5% full before claiming");
} else {
double moneytogive = pigmake * amount;
String playerName = p.getName();
String moneycmd = "economy give " + playerName + " " + moneytogive;
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), moneycmd);
pigsection.set(coordkey + ".expiration", System.currentTimeMillis() + 14400000);
}``` When the 'amount' is less tham 1,000,000 this works fine, but as soon as it goes abouve 1M it stops working, any ideas?
?paste please
Some people just join this discord and pretend that we are forced to help them. Nobody here has a contract or gets paid to do so. And if you are unfriendly and unable to deal with feedback then it's quite obvious that people don't like to help
How do I define and get maps/dictionaries in config.yml
So I'm the only one forced
i have no idea what that does. elaborate it a bit
If you force yourself, sure
map:
key1: value1
key2: value2
```The standard yaml way basically
Imteresting. Thanks
So it's the same. But how do I get the list of keys so I can turn it into map?
gladly again
It's a configurationSection. You can iterate it and turn it into a map. You might be able to cast it directly aswell.
I think the issue was that they believed they understood and really didnt and therefore insisting it being some other problem
oh thanks
Social interactions are not always my forte so i really do appreciate that feedback
I only followed the last ~10-20% of that conversation. And there they said that you are probably not understanding each other which was right in this case.
Both of you probably thought the other side does not understand the problem/solution. It was a misunderstanding and that's a common thing. I really feel like both of you did nothing wrong. Besides that your solution required quite deep knowledge - which isn't always a problem.
Yeah once i realized that was the case it was just trying to figure out that misunderstanding lol
One of these days i will make educational videos
do spigot tutorials
Not if you also have a private constructor and therefore make it a "real" utility class that does not hold a state
.
😡
he's trying to be funny
when in doubt
It's basically a glorified map
I wasn't sure about that anymore which is why I said might
reflections 🙏
shouldn't the utility class throw an exception in the private constructor
and in the singleton as well if it's not null
no I'm saying for A singleton
in their example code
And then we end up with the same problems as the SimpleDateFormat
I do throw it in the constructor
for the singleton
for utility class it's whatever
Therefore if avoidable at any cost don't make a static (especially utility) class have a state :/
Why would a static utility class have a usable constructor?
You said it doesn't have to be private
Yeah sure but what's the point?
You could also name your classes MY_CLASS_FOR_COMMANDS because you SHOULD go with conventions
And why would I not teach conventions in #help-development ?
Oh that's not how my sentence was meant. I just wanted to be clear that there should be no state and a private constructor. Not that the private constructor makes it stateless
Yeah I see why
Also birds eat them, too
I still hate ticks more than mosquitos
No open air concerts in the evening for you ig
🤷♂️ nobody asking for help atm
And I can't work either because I have to wait for 800 integration tests to run
help
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
jk
thanks
antm#7677 definitely regrets to for the most part inform you that unfortunately, they essentially are unable to definitely assist with definitely your enquiry, which essentially is fairly significant. Please simply really ask again later or possibly kind of ask someone else about this enquiry, demonstrating that the person that ran this command generally regrets to kind of inform you that unfortunately, they for the most part are unable to generally assist with actually your enquiry in a subtle way. Thank you very sort of much for kind of your time and the person that ran this command specifically wishes you a really good day, so the person that ran this command really regrets to actually inform you that unfortunately, they literally are unable to definitely assist with very your enquiry, or so they particularly thought.
To get this back to something programming related:
Do you guys actually write unit/integration tests for your plugins? I can't be the only lazy one
nah
i just fix it if smth doesnt seem to work 💀
Not even my biggest plugins have a single test
no tests needed
wouldnt test spigot logic anyways
imagine finding spigot bugs while testing
wtf is this
sounds like what I would get when I asked chatgpt to write the most unreadable explanation of a simple term
Imagine spending hours to write tests when I could have developed 10 new features in the same time
Tests make sense when multiple people work on a single project and there's no "single-point-of-truth" as in someone who's fully aware of all code reviewing everything
?cba
Luzifer#0666 definitely regrets to for the most part inform you that unfortunately, they essentially are unable to definitely assist with definitely your enquiry, which essentially is fairly significant. Please simply really ask again later or possibly kind of ask someone else about this enquiry, demonstrating that the person that ran this command generally regrets to kind of inform you that unfortunately, they for the most part are unable to generally assist with actually your enquiry in a subtle way. Thank you very sort of much for kind of your time and the person that ran this command specifically wishes you a really good day, so the person that ran this command really regrets to actually inform you that unfortunately, they literally are unable to definitely assist with very your enquiry, or so they particularly thought.
thats mythology
god luzifer
im the better ending of the series lucifer
no
When the 'amount' is less tham 1,000,000 this works fine, but as soon as it goes abouve 1M it stops working, any ideas? https://paste.md-5.net/logupiviku.cpp
already told you to elaborate more since we dont know what you are trying to do
You aren't my god 😠
more like devil
sin
I didnt know abt that when i started making the plugin
My only sin is using way to long stream.filter expressions to push things into one line
well I still split the line. But one expression
Streams are so sexy we have to admit
I do like them but everyone seeing this code will hate me
Yeah, there is a limit 🤣
I told you that's my sin 😅
join rust where streams compile to the same machinecode as normal loops
i am using an example i found online to change the metadata of a player (using protcollib )
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
PacketContainer packet = pm.createPacket(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, player.getEntityId());
WrappedDataWatcher watcher = new WrappedDataWatcher();
WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(Byte.class);
watcher.setEntity(player);
watcher.setObject(0, serializer, (byte) (0x40));
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
pm.broadcastServerPacket(packet);
when executing i am getting kicked from the server and get this errormessage in the console
class net.minecraft.network.syncher.DataWatcher$Item cannot be cast to class net.minecraft.network.syncher.DataWatcher$b
i assume this has something to do with the serializer, but don't know
wdym?
how do i use a datacontainer here
i think this example makes the player glow
but i won't be using it for storage
By entity metadata I'm not talking about bukkit's shitty metadata api
entity metadata in nms is like
All the data that the server needs to communicate to the client such as like
maybe i should have made that clearer mb
how much health, if it is on fire, what items it has equiped
No you're good
I would like to do this
I'd recommend uhh
updating protocollib
Just to be sure
using 5.0.0 is there a new one already?
5.1.0 is in snapshot
can i just change the verison in pom and reload it?
No, it's what's on the server that matters
ok server got it
😅
I don't want to sound like a moron but there's still some learning for you to do
And don't worry we're all going through this at one stage
You cant shade protocollib as it wont work properly even if you relocate. Its one of few plugins/libs that simply cant be and will run into a lot of problems if you do
he never said he is shading it though. He might just have scope provided
There was like a time period back in 2020 where I stopped everything I was doing to fuck around with packets
where can i find the snapshot versions? i can only find the 5.0.0
Dont be rude now
Just go with the latest dev build
I honestly don't remember where I saw 5.1.0
Not always the case, ProtocolLib doesn't change much across versions
It's way too popular to afford splitting its community
True, the protocol does however which sometimes matters
That's protocollib's job to handle, updating the pom won't change how you're writing data into the container
If you were using the packet wrappers, sure
But plib just wraps stuff and updating the pom on your plugin won't change how it serializes stuff
this is a stupid argument
I agree but point is. Sometimes alteration to the underlying implementation can still affect the higher level code even if the api didnt change
That's why I suggested updating the plugin on the server. The API didn't change
And it won't for a good time
If it does lots of people would be coming here to complain too 😂
Because the only way that changing the pom would actually change how the underlying code would work is if you were shading it
how can i specify the 645 build in the pom?
You don't need to
They do when it id necessary because the protocol somehwhere changed that forced it
But most of the time this isnt the case
then changing the versions didn't help, even deleted the protocollib server folder
They change versions when the protocol changes, meaning they need to add new wrappers and more reflection
jfc it's disappointing we still arguing over something this minor
I'm gonna look for a solution, y'all 2 can bicker
fml
so anyone an idea on how the error occurs and maybe knows a solution?
Server version?
19.4
I dont really see the issue other then potentially building against a version that isnt for whatever mc version
only thing I can think of
which I did on my packet wrapper
was like
boxing primitives
but I'm pretty sure that's just with getting the serializer rather than actually writing the data
okay yeah I can replicate
hmm i got no idea how to continue this so i am willing to try everything at this point
the code is a few years old so i assume something has changed over time
yeah they changed something
I think protocollib genuinely broke this packet
think this packet uses WrappedDataWatcherObject now
@native ruin Found a solution!
fr?
isnt Player#setGlowing a thing?
Since Player is an Entity, yes
Though the issue most likely is that it does not work on a per-player basis