#help-development
1 messages ยท Page 138 of 1
I always get the configsection instead of using the "."
if you want to get the whole thing, you just do it like this
ConfigurationSection materials = getConfig().getConfigurationSection("materials");
Explain better.
then you can do materials.getDouble("STONE");
So, I'm making it so players can set the blocks in their mine so this list will update whenever they change their blocks.
so?
ConfigurationSection materials = config.getConfigurationSection("materials");
for(String key : materials.getKeys(false)) {
Material type = Material.matchMaterial(key);
double cost = materials.get(key);
}
So basically when you mine a block, the config changes the material you've mined?
No, I made a private mines plugin and the players can change the blocks within their mine by running a command.
why do you ignore what Im and I sent? we both explained to you how to "read" a key>value configurationsection
getDeclaredField
why do you need reflection for this? o0
.get(object)
you can just do ClassName.fieldName
probably privaet
I'm updating my code accordingly.
then you have to do setAccessible(true) on that field
calling me "Im" is really cursed
haha sorry but I dont know your actual name lol
Im and big brain ๐
Will 1 cookie make you feel considered?
๐ช
thanks for the cookie
at least you're not the guys at work
no
ah okay
you usually do not have to check this in the first place
why do you need to check this?
if you access fields via reflection and only want to "retrieve" the value, you can safely ignore whether it's final or not
thanks for helping, I feel stupidly dumb now I fixed it.
I don't really feel like saving via reflection is the most ideal
haha np, happens all the time
then make an API to create those objects
o nvm I actually used reflections for my skyblock core
I was thinking: who in the world still uses bukkit in 2022
Just convert your object into a Map<String, Object>
everyone here?
how else are you going to create spigot plugin s
I use @waxen plinth's wrapper RedLib https://github.com/Redempt/RedLib what handles all this config stuff for me so I've legit not used the default spigot config since forever, lol.
I mean, spigot is based from bukkit, but I still found someone that uses bukkit version
spigot is in theory, a fork of bukkit
Not the spigot or paper
pretty sure spigot is a 1.8 thing so hypixel is definitely not using it
Not in theory, it is.
Yeah but Spigot is better, can't say so for Bukkit
almost correct ๐ https://blog.jeff-media.com/bukkit-vs-spigot-api-vs-craftbukkit-vs-spigot/
it's like a version determiner, if i ever change the serialization i'll identify the old runes with this
Is the Pattern Bukkit -> Spigot -> Paper?
yep
Paper > *
why not
or did craft bukkit come first
the most recent is paper
did you mean that
then spigot
I mean what came first
then Bukkit
like bukkit came first, then spigot forked bukkit then paper forked spigot?
purpur is modified paper which is modified spigot which modified / runs on top of craftbukkit that is the implementation of bukkit which is a wrapper for mojang's server
Craftbukkit, Spigot and Paper all implement Bukkit API
simple enough
oh yeah
PaperSpigot is rare to hear lol
paper is so successful though
It's the most efficient version for a server I think
https://blog.jeff-media.com/bukkit-vs-spigot-api-vs-craftbukkit-vs-spigot/ I can only remember that this blog post exists, and it explains everything about paper, spigot, craftbukkit, bukkit, etc
tho I still code plugin in spigot and not in paper
For the public, yeah. But then if you got the money you spend the money and get a custom fork lol
That is probably what HyPixel did
I'm fairly sure my friend has a custom fork with the size of his server lol.
pro tip: it's actually free to fork stuff
even small servers can be running forks
There are lack of developers in the world
I always wished that spigot had ways of disabling parts of NMS that simply weren't used
so servers could disable stuff like advancements at a classloader level
My friend has over 3k people on so likely using a fork don't you think?
oh wow you have friends
In these, it's rare to find forks developer
i'll go to bed now, have a nice day everyone โค๏ธ
the guys on my friends list are all hypixel developers so I guess they're also running a fork
You destroyed me. ๐ช
I mean, I got the owners of mchub on my friends list. Helping make the server helps a bit ig.
Italy has GMT +2
๐
afternoon
yeah we have the same time zone. but I'm tired lol
whos this nerd
Dunno! barely responds so I guess we'll never know.
What's your time zone?
have to get out of bed at 7am tomorrow
was used to 6pm in the holidays
I helped my friend get his server going finding bugs etc and now he has the players he forgot me ๐
oh we have the same time zone
this dude literally called devbukkit
hol'up
lol
๐
loooooooooooong story.
smh i have parents that tell me to go to bed at 10pm
mfs called "McDevelopment" asking for coding help
my parents neglect me actively so can't relate
Why don't you change it I mean this is a spigot server xd
help I have a romanian military song stuck on my head
I'd be admitting defeat, lol.
Hm?
It was.
It's got good content, but they moved to a shitty coin system making stuff much more expensive.
I helped design it at the start, so I'd hope it was.
What about the 4 digits it brings in each day?
yeah
I was joking in a call with the owner once and he shown me buycraft
People sell their skins for like 20k coins, 10k is about $120 so that's $239.98 per skin
7 figures when I saw likely higher.
But they got so many dedis to pay off every month.
They have 350 dedicated servers as of July 2017.
He bought another 150 at once in 2020
I should get them to hire me and give me all their money
Oh hi redempt!
Hi
It's the RedLib guy!
RedLib is a Spigot plugin development library, designed to make your life easier and soothe the pain points of plugin development. Below, find instructions for the various components of RedLib.
It has an incredible config system
It really is, look at this for a config manager https://github.com/Redempt/RedLib/wiki/Config-Manager โค๏ธโ๐ฅ
I should get around to replacing RC with Ordinate
It does, yeah!
Honestly, it's worth a shot. You might work out how damn incredible it is and start using it daily. Redempt gives amazing support too!
Ah yes! the 3 classes
It has one but I've since made a better one
And I'm looking to replace the one in RedLib with it eventually
I'm fine with my own command framework
I like this one because it's really lightweight but it works real well.
no annotations, auto-registers commands without plugin.yml
im fine with acf
supports wildcards and wildcard tab completion
arguably it might be a bit annoying given each subcommand has its own class
but that's how I like to handle it
ehh this is just an example
as of right now it's somewhat private
code's a bit garbage but it's present on my skyblock core ig
like?
you can put as many *'s as you want
and aliases are a thing iirc
uhhhhh
don't think so
Mine does
report player:target string...:something {
}```
With mine you write a description of each command like this, then annotate methods with @CommandHook and they'll be run when the command is run
add int[]:nums {
hook = add
}```
@CommandHook("add")
public void add(CommandSender sender, int[] nums) {
sender.sendMessage(Stream.of(nums).sum() + "");
}```
Simple example
You could run it like /add 1 2 3 and it would show you the sum of the inputs
yeah but annotations
One annotation
still more than 0
And one method per command instead of a class
It's a tradeoff I'm willing to make
You cut back on so much boilerplate with it
I don't like the annotation spam of other frameworks which is why this only uses one and has a separate file to describe the metadata
Yeah
Feel free to DM me or join my support server if you want to use it and need help with it
.-.
looks like rust
vanish || EnumSet.of(GameMode.CREATIVE, GameMode.SPECTATOR).contains(player.getGameMode())
smh
I do like rust though
i stopped using it because of the weird syntax and lifetimes lol
didnt really get far anyways
into c++ rn
Rust is much less painful if you avoid lifetimes
For anything except one-off uses they often make things more effort than they're worth
So. Many. Kinds.
&, Box, Cow, RefCell, Rc, Arc
this is also a bit cursed, ig you can cache the enumset as a constant
It's definitely worth learning
Depends on how often it's called
hopefully jit will optimize that call
unecessary to create a new enumset just for a contains check
It's so fast that unless it's being called thousands of times per second it's not an issue
still not good practice
I would take the code cleanliness for a slight performance hit
Making it a constant is good but not always needed
probably your IDE
i didnt clone it
I love optimizing too
heh my parser
But I know that sometimes it's pointless
:(.
Nah it's often very necessary
I can't sleep at night without having top-tier performance measured in tens of microseconds
You just need to know when to pursue performance
running async ofc
Illusion I'm still kind of miffed at you
Why is this check not working if (player.getInventory().getItemInMainHand().getItemMeta().getDisplayName().equals("&e&lTaser ยง6[4]")) { ?
Yes
so am I, we have different goals
probably want to identify items by pdc, not by name
Dont check for custom items like that. Use the pdc of your itemstacks.
You find that consistently abstracting features is clean, I find that simple, basic code is clean
it's for a plugin in 1.12.2
And don't mind going the extra mile
I do both in different scenarios
I am consistent regardless of scenario
Was never my issue though
You insulted me as a developer and never apologized or took it back and it's hard not to be reminded of it when seeing you
ยฏ_(ใ)_/ยฏ
Alright, if you don't want to do anything about it then we'll just go on being adversarial
That's perfectly fine
I'd rather not have things that way
Like when I see you in chat it just puts me on guard because I know you're judgemental about my code and have a superiority complex or something
Yes, we can
Which dev isnt cycling between imposter syndrome and god complex?
And that's what we're here to do
only you afaik
god complex when dealing with people that don't know how to code, feeling like a brick when dealing with people who are better than you
and impostor syndrome when applying for new jobs
I just feel bored when helping beginners
Well, people doing crazy funky NMS can help themselves
Just pick up a very complex project, like let's say..
synchronize 2 servers
idk
I got a bit of impostor syndrome at intern presentations because some of the people had really good presentations
I'm in a programming course, interned at school replacing computers ๐
But I stalked their contributions and we all had pretty comparable levels of productivity
I smell dunning kruger in here. Whoever claims to be sublime like this doesnt know how little he actually knows.
I know about spigot and nothing else
and that's what makes me extremely doubtful of my future
You know java
You know design principles
It's not hard to branch out but it's not like you're behind
hopefully databases
(and presumably a decent skill in googling)
so yea, already probably better than the 90% out there 
I know how the entire internet works but I also locked myself out of the new work server like 3x before outsourcing my job to an "underpaid chinese worker" according to my source
and had to ask the guy what dns flags to set ๐
This is actually quite underestimated sometimes. Finding the right keywords and filtering the garbage is an art.
keywords in google are so nice
"spigot <1-3 words that describe your problem>"
fake death ๐
Im creating a plugin for 1.12.2 is there something else to check the custom item?
nbt api if you're willing to have dependencies
but also ItemStack#isSimilar
or equals
What in the hell?
we can use google on or programming tests in college
cuz thats how real world works ๐
We can use google for projects not our tests though our tests are usually random BS like what is printing after this code is run lmao
Entity#getPessenger == null < failed Entity#getPessenger#isEmpty < failed
it doesnt return correct value
always false
well learn like basic concepts of programming lol
but in fact i put pessenger
i dont even have to go to lesson if i want lol
my attendance is graded
I'm in "Intermediate Java" and we learned how to print with sysout through 3 lectures
smh
๐คฎ
lol
225 minutes of learning sysout
well learn like basic java and javafx this year lol
Y2K_ you can get job in htech company now adays
most of employes there are 2 digit iq
u know all of those who think begin a dev is good money
and easy
alot of idiots
just go to google
they will give u some tasks
true good developers are in need lol
not something difficult
i cloud go
and probably pass the tasks
it will be like reverse a string
and some simple shit
The thing is i suck at interview questions lol
idk how to do all hte obscure bs they ask in interviews
if only one instance is permitted
f.e MinecraftServer
when there will only be ever one instance and should only ever be one instance of an object example Database Connections
i used to use singletons its really bad
same
Main.getPlugin(Main.class) aa
when i started learning i always used to create static main class
like instance
not static class yeah
not good
DI
is good
clear code easy to understand
no need to make 10thousand constracturs
or abusing static
like guys you only saw mojang code
so u can say who works there 2 digit iq monkeys
the community is way better
basically if your questioning whether you should DI or Singleton just think if there would ever be a scenario where there would be a second object of that type if yes DI otherwise singleton generally singleton makes your code less portable though
either the reason why the code is obsf probably because they are ashamed of it
you create more contstructors with DI...
C_V
C+V
not really headache
either i have premade temple for it
depends what does the message handler do
so like if its listener...
many things cloud
its just not better
u dont know if u will need to accses it somewhere else later
so
Singleton Could be fine, but honestly just sounds like you'd need a better design pattern for this
MessageHandler seems pretty useless to me
just fetch the data from the configs and send the message
at the most make 1 static method to handle it
The singleton pattern is an easy to understand design pattern.
how ever
When I first started dabbling with Cocoa development, I almost immediately came into contact with the singleton pattern. Many Cocoa frameworks, including UIKit and Foundation, use the singleton pattern.
idk if your project is few classes
then use it
just overload a static util method I don't really see a reason for a whole class here ๐คทโโ๏ธ util methods should cover your use cases
With configs generally best to stick to DI imho mostly because there is a reason to create / manage more than one instance of a config
just stick to DI and pass MessageHandler around it'll be cleaner than the singleton regardless and easier to manage / more portable which would be useful for something like MessageHandler class
well he can abuse static
there are plenty of reasons to use static/singleton it isn't bad
pvbble simply asked which would be preferable
Hi Im new to making plugin, why do i get error Could not pass event BlockPlaceEvent to MCPluginDev when I place a block
Scalability, Readability, and better design patterns. It also makes your classes purposes clear and concise, You also benefit from being easier to integrate people into your codebase.
send stacktrace
?stacktrace
aw
DI is easier to manage at scale than singletons
therefore increasing your scalability
you can technically scale with singletons but it becomes unmanagable after a certain time
learn java please.
i can
i know java
u didnt do an instance
oh...
so what oh
you dont know java
man i'm here to help those who are in trouble
not to those who have no idea what they are doing
because you know what ever class does and what classes are used inside of it. This makes it easier to bug fix issues as its easier to trace back. Again also makes it easier to look back and know what old code does. Very useful at a large scale. Easier maintain due to if you need to compeltely overhaul a class DI will lend better to telling you where everything is used and what you need to upgrade vs singleton which will be all over the place
i learned java
for half year
before even coding something
even for a year
not sure
how long it was
Minescule amounts more if you want to sacrifice a good design pattern for slightly lower memory usage go ahead but it'd be equivalent to shooting yourself in the foot
i mean it would be a tiny amount cause it is literally that, a reference
itโs just saying โgo here in memoryโ
you probs wouldnโt even notice it
false
true it technically does
but it is true
well my brain did 7 > 10
if it was 6 > 5
that what my brain did
he doesnt have to worry about such a thing
what he gonna do next use an to queries each time instead of storing things in cache
(sql)
then why you ask
in first place
singletons aren't bad if used properly but very rarely do people actually use them properly
i send u an whole article
imho MessageHandler is not an example of a good singleton
?paste
how bad this is
yeah because you asked a wierd question
if it use memory
like how much it would use
i'm not into singleton topic
generally my final input to you is that I wouldn't reccomend making MessageHandler a singleton class hell it doesn't seem like a worth while class at all to me, however you are free to do as you please.
you ask same questions in loop
Y2K_ i was tripping that he asked pretty much same questions in different ways?
Asking about your attempted solution rather than your actual problem
since this is what i felt we went thru rn
0 -> 0
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 3
6 -> 2
7 -> 1
8 -> 0
9 -> 1
10 -> 2
11 -> 3
12 -> 4
13 -> 3
14 -> 2
15 -> 1
16 -> 0
How can i achieve this, using arithmetic operations (modulo, subtraction ...) only, given a counter-variable i going from 0 to 16 and a "limit" of n = 5, where the numbers "turn around" ?
nope, that will give
0 -> 0
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 0
6 -> 1
7 -> 2
8 -> 3
9 -> 4
10 -> 0
...
if you mean i should do i%n
see how at 5 it restarts at 0 instead of turning around
cuz it gives this
instead of this
get it?
for example when the number is 5, it should output 4 and not 0
a VERY basic implementation
public static void main(String[] args) {
int allRotations = 0;
int currentNum = 0;
do{
if(currentNum < 4){
System.out.println(allRotations + "->" + currentNum);
currentNum ++;
}else{
System.out.println(allRotations + "->" + currentNum);
currentNum --;
}
allRotations ++;
}while(allRotations < 16);
}
well that way its easy
i wanna use just arithmetic operations
no if
just modulo, division, etc
not like that would work anyway 
the purple line is kinda wrong
at least that code
how did u make that, pvbble?
ah
well if i knew the formula i could show u on there haha
i dont know the formula, thats the problem.. xD
green is using modulo
Why the fuck the itemstacks takes the customModelData number of the last item i clicked
purple is what i want
How to check if config is empty in bungeecord?
that gives the green line
what formula
notably tho the c here is wrong
How to check if config is empty in bungeecord?
Well, their n (or c) was 5
but that should be an easy fix
to yield the desired output they'd c = (n-1)*2
for c=8
oh
yea
hence, if they are going to feed 5 as their turning point
make sure to smack it through a - 1 and *2 first
das all I am saying ๐
okie, you got me ๐
lol
sorry, horrible joke

@boreal seal I learned java
https://youtu.be/giyVlMZVkm0
i already knew tbhj i just like how kotlin looks
well it only went up to 2.5/2.5 instead of to 4/4
but yeah Lynx already said the fix
cuz (5-1 )* 2 right
all depends on where you come from ๐
nah but given the limit c
if they think of a number t being the turning point that the series should never reach
then c = (t-1)*2
yea
you are thinking of the limit that the series reaches, which means c = 2L
just a question of โจ perspective and expectations โจ
true xD
is it possible to modify minecraft enchantments - spigot? (without needing to make them from scratch). I've already looked it up on google but nothing shows up.
ok yeah. that's what i thought
I have a problem, I just have create a ArrayList for a command vanish but when the player join my list dont take the right arguments
@Override
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] strings) {
if(cmd.getName().equalsIgnoreCase("vanish")){
if (!(sender instanceof Player)){
sender.sendMessage(errorMessage + "Vous ne pouvez pas utiliser cette commande.");
}
Player p = (Player) sender;
if (sender instanceof Player) {
if(!vanished.contains(p)){
for(Player pl : Bukkit.getOnlinePlayers()){
pl.hidePlayer(p);
}
vanished.add(p);
p.sendMessage(label + "Vous รชtes maintenant en vanish.");
Bukkit.broadcastMessage(String.valueOf(vanished));
}
else{
for(Player pl : Bukkit.getOnlinePlayers()){
pl.showPlayer(p);
}
vanished.remove(p);
p.sendMessage(label + "Vous n'รชtes plus en vanish.");
return false;
}
}
}
return true;
}
@EventHandler
public void onJoin(PlayerJoinEvent e){
for(Player player : vanished){
e.getPlayer().hidePlayer(player);
}
Bukkit.broadcastMessage(String.valueOf(vanished));
}```
i just wanted to make sure before i spent time doing it
if I had to guess you are creating two instances of the class
or is that your main class ?
No it's not my main class
yes so presumably you create two instances of it
Yes
which, vanished is a non-static field
e.g. each instance of the class has its own array list
they don't share one
Okay I understand but How can I do so for store information when I execute command /vanish and retake it on my Event?
Well
either you just slap a static on the field or you properly do object oriented coding
and create some type that holds onto the vanished players
how can i get the itemstacks that drop from a block in BlockBreakEvent
(or in this case, you create th e instance once and use the same instance when registering commands and listener)
Okay thank you very much that's work
What's the difference between static and non-static?
static means its on the level of the class
while not static means its on the level of the object instance created from the class
Okay ! Thx a lot !
also how difficult would it be to modify world generation to make the amount of ores in veins smaller?
--- Subscribe if you like to relax on video games songs ---
The first pic is the mount Denali in Alaska.
The second pic was taken in Norway.
Caution & Crisis remix 1hour:
http://www.youtube.com/watch?v=jbBKfseNuwM&feature=youtu.be
Thank you :)
how hard would it be to learn how to do it
I'm only now getting round to trying what I was suggested earlier, but I've came across an issue. I was recommended to use Maven build profiles (settings.xml) to set the directory (my testing server's plugins directory) for Maven to package my plugin's JAR to. However, to set this directory you need to use Maven build plugins, but you can't set build plugins (or anything under 'build') from settings profiles. Is there a way to do something similar to the below settings.xml but that is allowed in Maven?xml <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> <profiles> <profile> <id>spigotTestingServer</id> <build> <finalName>${project.name}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.1</version> <configuration> <outputDirectory>D:/hoppe/Documents/Testing server/plugins/</outputDirectory> </configuration> </plugin> </plugins> </build> </profile> </profiles> </settings>
MyEvent cannot be triggered asynchronously from another thread.
Maven package to testing server
hey does anyone know why spigot plugins won't load at all on pufferfish?
-whereami
?whereami
it is related to development i promise!
i also dont know if they have their own support server
they do ๐
Does it work on spigot?
it does
Have you tried other plugins?
yeah other plugins seem to work fine
literally just kills players below a certain y level
moveevent
@EventHandler
public void onPlayerY(PlayerMoveEvent event) {
if (event.getPlayer().getLocation().getY() <= -10) {
event.getPlayer().setHealth(0.0);
}
}
Try runnables
Idk if the pufferfish limits the moveevent or whatever
Error?
/pl just brings up "plugins(0)"
Console
nothing in console either
And what is the pufferfish?
1.18.2
Try changing the api version to 1.18 in plugin.yml
Yep
And dont do this, it does not look good on the performance side at all
alright
A player changes 0.1 yaw or pitch, this gets called
Moves 0.01 block it gets called
imma be honest, i started plugin development literally today so im not sure what the more optimised way to do it would be
PlayerMoveEvent is just not okay
that doesnt seem like it would change much?
I mean, generally it should be fine to just run something every like half second or so instead
But you're suggesting to still use PlayerMoveEvent but just put more code in the function
Alright
yeah im not 100% sure why you'd do that
as i said i have no idea what the alternatives are
no
would it not make more sense to check if the player health is 0 and return if true
just stick with the move event
and kill them if false
yes
I'm doing something like this:
String code;
while (line!=null) {
code = "something"
}
and when I'm using code variable here, it says it's not initialized
thought so
why?
Actually, why is there not just separate more specific forms of the PlayerMoveEvent? Like PlayerRotateEvent, PlayerShiftEvent (idk a better way to say 'move but not just rotate') or PlayerShiftBlockEvent
what would be the point of that
To reduce function calls?
okay, will it have a big impact on server performance?
should still be fine, you are doing two checks
I listened for the fly packet and called an event
It worked fine and not like move event
Idk what bukkit did
But what would the alternative be for plugins that 100% need to know every time a player changes position, but doesn't care about rotation?
to listen to the move event and check that ?
Or packet listening booo
you'd be horribly breaking API contracts if you changed when move event is triggered
not to mention, then the server has to do all those checks
all the time
for any player move packet
But wouldn't it be better for performance if your function was only called for changes in position?
not really
But it's better to have just the server do them than for multiple plugins to do them, surely?
the server would still have to compute that
yea sure this will be benefitial if more plugins use move event
but like
such a negligible difference
Which I feel like quite a few plugins do lol
definitely not worth breaking half the plugins on the earth for
packet listening
dude i just need to know if im gonna get fired if i use PlayerMoveEvent
How would it break plugins? You wouldn't have to change PlayerMoveEvent, you'd just add a few more events
doubt it xD
No
alright
alright
I am a 1.18 plugin
i listen to the move event for rotation
now you come along and change it
can someone help me pls
move event is only called for movement now
my plugin completely breaks
until I release an update that replaces that with your new event for rotation
which, that event does not exist in 1.18
Your plugin was a mistake from the start
so 
No plugin listens for rotation
I'm not saying to make move event only get called for changes in position- I'm saying have a separate event for changes in position. PlayerMoveEvent would still be for position AND rotation
Realy who does that
@quaint mantle ^
String code = null
Try that
so then how would that improve performance ?
if you are still calling the move event for everything
ok but will it be initialized later from while loop?
and on top of that actually have to also call all other events
Listen for packets instead of moveevent
By your logic, wouldn't the optimal solution be that all plugins just listen to all events and determine whether it's the event they're looking for? We have loads of events so that plugins only need to listen to what they need to
not really ? the issue with the move event is that there is only a single point where it originates from
like, server receives player move packet and there ya go
Ohhh I see what you mean now, fair enough
it does not longer because i added = null; on code variable
I guess it gets called in both rotation and fly (move) packet
ok but
Will the while loop change that variable first, or will the other method call it first outside the while loop?
Guys did you ever questioned life and what was going on in that mojang dev's head while doing nms specially supporting all versions?
what
mhm
ok ill test it
thats what im trying to
but i cant change that variable without while loop
wdym
the thing i want it to set to is in while loop
Hello, I'm trying to get the hex color (in chat for ex) for #5865f2 (blurple) so I did this: ยงxยง5ยง8ยง6ยง5ยงfยง2
But it only looks at ยง2 (dark green): https://cdn.discordapp.com/attachments/695431668944732270/1021149767667040277/unknown.png
I'm using 1.18.2
I'd generally just recommend ChatColor#of
bungee's chatcolor
i dont get it
iirc that still goes to that format but in case I mistyped it or smth I'll try that
same result ๐
https://www.spigotmc.org/threads/hex-colours-not-working-the-same-in-1-18.542850/
Seems like this person also had the issue but they didn't post the solution unfortunately
I didn't test it on 1.16 though
How can I improve this code in your opinion?
https://paste.md-5.net/cofadiwuri.java
uhh lots of ways
๐ค
actually
For example, calling less repeated code (common clause)
reusing variables instead of calling getters
making your static values as constants
and constants are formatted LIKE_THIS
not like_somethingWeird
ehhh somewhat debatable, striving to enforce the best standards ever since the start is extremely nice
Will variable.replace() method edit the original string variable??
Well, that's perfect, but a way to keep my mind off uninstalling intellij as long as I don't see this code?
no, strings are immutable
Anyone got any idea?
OKAY HEY GUYS im teleporting players, not even to another world and it only. tps. them. if. they. are OPERATOR
So why is this loop spamming "2" on every tick?
while(line!=null) {
System.out.println("2");
if (!line.replace("'", "").substring(6).equalsIgnoreCase(sender.getName())) {
contains = true;
code = line.replace(line.substring(4), "");
if (plugin.verifiedconfig.contains(line.replace(line.replace("'", "").substring(4), ""))) {
verified = true;
}
}
}
there isnt
its just player.teleport(Main.getCourseLocation("trade"))
and ik the getcourselocation is a thing bc it works for me
maybe a check before that
Show all the code
ok
Nothing much, I was looking for someone to recommend a style to improve my code....
I know the style has to be my own, but you learn by imitation, and so, I was asking
@chrome beaconjava @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (args.length == 0) return true; switch (args[0]) { case "start": if (a.getData().contains("courses." + args[1])) { Location loc = a.getData().getLocation("courses." + args[1]); player.teleport(loc); player.getInventory().setChestplate(a.elytra); player.getInventory().setItemInOffHand(a.rockets); player.sendMessage(Artifact.construct("&aStarted course &f" + a.getData().get("courses." + args[1]))); a.inCourse.put(player, args[1]); } player.sendMessage(Artifact.construct("&cThat's not a course")); break; case "create": if (player.hasPermission("course.create")) { a.getData().set("courses." + args[1], player.getLocation()); player.sendMessage(ChatColor.GREEN + "Created new course " + args[1]); } } } return false; }
?paste
yeah the hasPermission whatever
There is a config called Inventories.yml.
It takes data for each item that needs to be inside the inventory by turning it into an ActionElement containing an Enum of the function they perform and the Item processed.
Thanks to the inventoryGui API, it adds the item and assigns an X click event to it if the Item enum is Y
In this case, the items, provide and set 3 possible genders based on what you click and open the next inventory of the Setup.
Setup consists of three parts: name, gender, age.
Did you set a command permission in the plugin.yml
no
okay
so it does what the rest of the code does
but doesnt teleport player unless they have operator
How does setCarriedMaterial method works correctly? I want to remove or replace the block that an enderman is holding
setCarriedBlock(BlockData)
setCarriedMaterial is if you're <1.13
You can pass anything you want
if the carried material is @NotNull, pass AIR
Olivo, in your opinion, how is it possible that if I click too many times repeatedly an item updating another one by setting a value of +1 to the age and putting it in displayname, it skips several numbers.
I'm using an AtomicInteger as it requires me to.
Thanks!
regardless, you'd only need that big block if the code you're doing was vastly different
if (plugin.verifiedconfig.contains(line.replace(line.replace("'", "").substring(4), ""))) {
Since it's just a message difference, I'd recommend some sort of registry
this gives me nullpointer
either:
- plugin is null
- verifiedconfig is null
- line is null
line isnt null
also that just looks horrible
verifiedconfig cant be null because im checking it in onenable
why plugin has to be null?
order of operations matters sometimes
most cases*
I really hate these checks that go through all enum values
I completely understand,
That repeated code I'm afraid I can't do anything about it....
I think no matter how bad this code looks, to do these exact things, it has to stay that way.
Thank you for your answer anyway
it's so non-optimal
it really just needs to be organized in a different way
usually maps and lists are your best friend for this kind of stuff
I don't think so since it assigns an event to the click, it's not an action that can be extracted and repeated only once
ehh it can
I'm trying to figure out with all my heart how to do this, I'm never getting it right, I'm going around in "circles"
let me make something in paint
Would you agree if:
.setClickListener(click ->
switch (element.getActionType()) {
case case1:
runA();
break;
case case2:
runB();
break;
case case3:
runC();
break;
}```
Right now you have something like this
This is exactly what I'm understanding of the entire class lmao
I must admit, I have outdone myself in intelligence xD
I understand now
The code was in mess...
which turns out to this
Well, I can fix that smallness but then, I would stop like a rock
add an extra column with the message value to the right btw
wdym
hmhmmhm
you either end up with:
- a table
- a Map<Role, Map<MessageType, String>>
- an enhanced version of the method above, a MultiMap<Role, MessageType, String>
Google made a very simple class for this called HashBasedTable
Here's a basic example on how you can use it
WOW! I UNDERSTOOD!! I'm deadly serious
HashBasedTable<Role, String, String> table = HashBasedTable.create();
table.put(Role.SOMETHING, "no-permission", "The role SOMETHING doesn't have permission");
table.put(Role.SOMETHING_ELSE, "no-permission", "You suck");
And then fetch it in a very simple way
Do I need to install some dependency?
String message = table.get(role, "no-permission");
Should be bundled with spigot afaik
You can use it for more than just messages
For example, cooldowns and all
This is a neat collection
So cool! I have always used SimpleEntry inside a hashmap.
does anyone know how i would go about making throwables
sort of like the xp bottle and splash potions
yo Illusion
yes?
cellSEt
Thank yuo!
HashBasedTable<Action, String, String> table = HashBasedTable.create();
table.put(Action.FEMALE, ConfigLoader.message_female, ConfigLoader.message_femaleClicked);
table.put(Action.NONBINARY, ConfigLoader.message_non_binary, ConfigLoader.message_nonBinaryClicked);
table.put(Action.MALE, ConfigLoader.message_male, ConfigLoader.message_maleClicked);
for(ActionElement actionElement : inventoryBuilder.getElements()) {
inventoryGui.addElement(actionElement.getCharPos(), actionElement.getStack(), click -> {
for (Table.Cell<Action, String, String> genderCell : table.cellSet()) {
if (actionElement.getAction() == genderCell.getRowKey()) {
personUtil.getPerson(click.getWhoClicked().getUniqueId()).setGender(genderCell.getColumnKey());
click.getWhoClicked().sendMessage(genderCell.getValue());
}
}
if (!setup) {
customConfigsInit.saveInConfig(click.getWhoClicked().getUniqueId(), personUtil);
click.getWhoClicked().closeInventory();
return true;
}
return true;
});
}```
That's it now
ehh I'd just create that table elsewhere and cache all messages on it
the table is structured like this
so it's a little weird
but also you don't need to loop through the entire table just to compare rowkey and all
it's a bit backwards
just add 2 separate entries under 2 keys
wat
you can also just get all the rows or all the columns for a given id
huh
like this:
java for(ActionElement actionElement : inventoryBuilder.getElements()) { inventoryGui.addElement(actionElement.getCharPos(), actionElement.getStack(), click -> { if(table.containsRow(actionElement.getAction())) { Table.Cell<Action, String, String> genderCell = table.cellSet().stream().filter(cell -> cell.getRowKey() == actionElement.getAction()).findFirst().get(); personUtil.getPerson(click.getWhoClicked().getUniqueId()).setGender(genderCell.getColumnKey()); click.getWhoClicked().sendMessage(genderCell.getValue()); }
Maybe it could be better with the for-cycle at this point
Idk
no I meant like
HashBasedTable<Gender, MessageType, String> messages = ...
messages.put(Gender.SOMETHING, MessageType.SOME_MESSAGE, "test message 123");
for all messages on your project
inside your for loop, you'd do something like
Map<Character, Gender> genderMap = Map.of("1", MALE, "2", FEMALE, "3", OTHER);
so
Gender chosenGender = genderMap.get(...);
setGender(chosenGender);
sendMessage(messages.get(chosenGender, MessageType.GENDER_CHANGE))
I think it's a little too late for that, I went a little too far in the project...
Everything was working now, but the code was pretty lame...
I was trying to fix the fixable so that I wouldnt burn out everything
Anyway, thank you!
Had I discovered HashBasedTable earlier, I would have done something awesome ahahah now, in at least every proj
Why is src null?
what am i doing wrong?
console
i try to use src later on
but its null
but why
yes
all u need to see
why is it null
src
why? that wont help
Cannot invoke "java.net.URL.toURI()" because "src" is null
https://paste.md-5.net/omeximipiz.cs
For what absurd reason does it jump numbers when spam-clicked?
you cant copy whole folder like that
plus a few differences lol
its not how it works
you must write input stream of every file
or using hacky jar entries
y
super IS the instance of your class
why not?
no way to copy a map easier?
because a File object represents "itself" and not all it's contents
you can use FileUtils or similar
i am
FileUtils.copyDirectory(srcDir, destDir);
oh yeah that should work
Tried all 4 combinations, nothing worked :/
https://paste.md-5.net/acibawecij.cs
here
And it has a true the confirm object indicating dynamic.
In my util class, it modifies and updates the %actualage% placeholder with the age:
https://paste.md-5.net/oxitofikin.java
(Look at the events)
what folder is getClass().getClassLoader().getResource() starting in?
the src or the resources folder?
anyone knows?
why don't you just use getResource(...)
getting the classloader for a resource seems weird to me
look at the msg
wym
are you trying to read a "file" included in your .jar?
what why
because it's inside your .jar and not an actual file
so i cant copy stuff from the resources folder in my jar?
of course you can
how
but you won't have it as File object
ah
so i cant use FileUtils.copyDirectory cuz that takes a file and i dont have a file?
It is called within a process.
There is a setup that calls 3 different inventories in order, including that one. It simply takes the getAgeAnvilGUI method and does .show
It's so much code because there's also Type for each inventory, if you want I'll gladly pass it on to you :3
yeah, that's true
whats the workaround? is there a copyDirectory that takes a stream?
tbh, I have no idea ๐ A quick fix would be to include your whole folder as zip file or sth, then save it and extract it, but that seems like a horrible solution ๐
yea .. :/
saw a solution like that on stackoverflow
every solution i find is like 50 lines
No, there is an OnJoinEvent that starts a setup method that takes 3 different inventories (including getAgeAnvilGUI().show()) in order and opens them one by one to complete the setup.
If you mean the age value that adds up, yes, in the onClick.
instead of a simple oneliner like FileUtils.copyDirectory
yeah but that's no problem if you only need to copy it once
with "copy" I mean "copy/paste the stackoverflow solution"
yea xD
ye
you won't get it any shorter, a folder in resources is simply not a File :/
I think it's the AtomicInteger, I've never used it and it's pretty scary from the name
I can't use an int in a lambda
sadly
Just use a final one size int array
wat?
Use an atomic int 
bro
Brooooooooo
look at my first message, wait
And this is the problem: Yeah I meant the age thing, ok so the problem is if you click it super fast it will go up a ton of values?
then add some sort of cooldown
hm
maybe a cooldown could do the job but...
Why does it do that? @vocal cloud
Is it incrementing by 20?
A cooldown on a maximum X numbers around 100. Too high a cooldown would become bad as usability
I'm going to try
You can either do a ratelimit (max x per x seconds) or you can do a general cd (max every 50ms)
Something like this?
won't it become a server killer?
hm
hm
Uh CD's should be lightening fast?
wdym
It should be a currentTimeMillis - lastClickMillis > cdTime
currentTimeMillis?
oh damn yeah don't use a boolean for that
actually check if enough time passed as Mike suggested
yea
huh
also looks like its global right now
so one person clicking gives everyone a cooldown
I had never thought of something like this before
cool
unless u make an object for each thing idk
It is much worse, it creates an inventory on the spot for each player with its utility classes
It's the best way to do it. Make a HashMap with UUID,Long and you can store the last successful click time then compare to that for your cd
+1
If it's inventory specific and only 1 person will view it you don't need a map obviously
I just figured out the problem, thank you!
What was it?
Uhhh you want to subtract currentTimeMillis with the time of the last successful trigger

wait nvm
currentTimeMillis - lastClickMillis > cdTime
as you said
:thonkForPoorPeople: