#help-development
1 messages Β· Page 127 of 1
That's what the docs make it sound like.
I dont fiddle with documents. I can literally just create a TypedMongoStorage<UUID, CustomPlayerData> and call save and load on it.
Everything is handled by the codec in the background.
Jedis... so primitive
I really don't care
Its like a sharpened rock when it comes to libraries
I write about 100 lines of it and abstract the rest away
π€·
I kinda hate messing with databases directly
public void runnable() {
new BukkitRunnable() {
@Override
public void run() {
World world = getServer().getWorld("world");
if (world == null) return;
System.out.println(world.getNearbyEntities(new Location(world, -32.0, 23.0, -194.0), -24.0, 23.0, -201));
}
}.runTaskTimerAsynchronously(this, 0L, 20L);
}
why doesn't this work?
Thread Craft Scheduler Thread - 6 - Dune failed main thread check: getNearbyEntities java.lang.Throwable: null
You cant use any spigot api from an async task or another thread. None.
I don't get the point of them then if you can barley use them
I use them a lot. You'll find a lot of use cases. Just keep on tackling projects with increasing size/complexity.
I guess this is slightly better
Well... i actually use my own task system. But sometimes i still use them.
I have my own scheduler system
how does this guy do it then? https://youtu.be/T1_ikvAQHkM
just because bukkit's is very ugly
lol i also learned my first plugins from this guy
5:12
new ScheduleBuilder(plugin)
.every(15).ticks()
.run(() -> {
...
})
.async()
.during(5).minutes()
.start()
.onCancel(() -> {
... something else
});
hes doing async but is using getserver
He is only calling getters. Those are mostly fine being called async.
TSC's tutorials were nice back in the day
I used to get most of my help from his server
Bootleg TaskChain?
https://github.com/aikar/TaskChain
but I'm just calling get nearby entites no?
yes, made like 3 years ago
I always like knowing what I'm doing which is why I'm writing netty next
Which has a metric ton of non-getter operations underneath
Reminds me of a recent quest system i wrote
yeah thats kt
my expectations have lowered
is there any real difference from running a task async or not?
Those are placeholder messages because we had a translatable component system on the way
it runs on a different thread
there's no going back
is it fine running on the same thread tho?
Is it fine running what on the same thread?
think of it like this:
Instead of having 1 decent person at doing their job, you hire an assistant
except what if the assistant is faster than the "master"?
you can have desync issues
It still has benefits though
The "assistant" can chip away at bigger tasks while the master processes smaller, crucial tasks
For example, instead of lagging your server with processing chunks, you can make chunk snapshots and let parallel threads process the blocks
then have the main thread operate based on the outcome of those parallel threads
Or instead of letting your main thread stall for IO, you can make a dedicated thread for it and let your main server actually process stuff
But just like training an assistant or explaining the job to them, creating new threads also has overhead
hey so I've got world.getNearbyEntities(new Location(world, -32.0, 23.0, -194.0), -40.0, 23.0, -201) right, but it's picking up on stuff at -44 -190
I thought -40 was the boundry
no, that's the range
I think for this it's kinda just more of a thing to learn for java as a whole right?
it's useful for unrestricting "traffic"
so anything that takes time, like http requests or messing with files can benefit
but also just huge amounts of data
mostly yeah
there are some things that are fine to do async
very little, mostly just methods that send packets directly
Chat messages, guis, particles
whats the best way to prevent NPE with a offline player
okay letme explain
im creating a punishment gui for my server
but when the player if offline the command throws NPE
and i need it to be punished either if the player if offline or online
declaration: package: org.bukkit, interface: OfflinePlayer
I take it you cannot do a dependency for a private repository in your pom.xml file?
iirc you can add username and password stuff
Eh I'll just do a local jar... It's never getting updated
I know its bad practice, but π€·
true

<dependency>
<groupId>com.CorpseReborn.EaglePrideMC</groupId>
<artifactId>CorpseReborn</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/CorpseReborn-Acorn.jar</systemPath>
</dependency>
I smell heretic convos
aren't drive letters A and B used for floppies
Yeah, this bad boy is on a floppy
As much as i and j can only hold integer variables
Gotta keep it safe
yeah its an outdated thing. nevermind. first time I've seen it!
Oh
bad google
so whats the thing for workspace?
${project.workspace}?
Or I guess I can google that
id create a folder "dependencies" and then add ${project.basedir}/dependencies/yourdependency.jar
Yeah, that's what I did. Wasn't sure if ${project.workspace} was a thing or not
Oh should be project.basedir
basedir only does the root for the project
Oh, well I guess I can do ${project.basedir}/../
PlayerBucketFillEvent, to get what exactly the bucket was filled with which method do I use?
getBlockClicked, getBucket, or getItemStack
Same error as here...
Maybe it just absolutely doesn't want me to use ${project.basedir}
looks like the correct is ${project.baseUri}
thanks
If only there was a documentation for such questions...
there sure is
but discord is faster
yep
Nevermind, it doesn't recognize ${project.baseUri}
this will end in recursion
I just hardcoded the path
because its ${project.basedir}. otherwise just set your own property with the path
Best practice would be to define a local maven repository in your project and mvn install:file your dependency in it
I'm a bad boy and am going to just leave it hardcoded π
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file:///${project.parent.basedir}/project-maven-repo</url>
</repository>
</repositories>
Then
mvn install:install-file \
-Dfile=/some/path/on/my/local/filesystem/felix/target/dependency-0.9.0-SNAPSHOT.jar \
-DgroupId=org.apache.felix -DartifactId=org.apache.felix.dependency \
-Dversion=0.9.0-SNAPSHOT -Dpackaging=jar \
-DlocalRepositoryPath=${master_project}/project-maven-repo
Ok my goodness it looks like I've finally resolved all my dependencies....
But meh
Yeah, I'm gonna be a bad boi
I'll sleep now, and try and work with shading tomorrow....
All of this wouldnt happen if you wouldnt use some bootleg dependency written by someone that doesnt know how
to support any build tools.
What? Then you dont need to do any of this
Just run install on your other project and then you can depend on it because its installed in your local maven repo
I was just exporting through native eclipse, but my server blew up when my code used FileUtils
And I was using the .jar for commons.io as a java Build Path for my project
I have some code that displays a scoreboard under the players name. The score board contains each player's "level" if you will. The issue I'm having is; when the player levels up in the menu I made, it will set their level but not update it below their name.
so update the scoreboard
let me rephrase; that's my issue. its not updating.
so give us something we can look at, otherwise my next question would be "have you tried to update it yet?"
thanks for the advice. should have done this sooner
if you are not using teams, then you need to update it manually
im using teams. i think i got it now
I really dislike the whole scoreboard api.
I just abstracted away all that nonsense with packets so that
i can use it by simply appending lines and accessing them by index.
this is more reasonable lmao
How can I make a snowball invisible
Why do you want to do that?
I want an invisible projectile
I could do It fine with nms in 1.15/1.16
Doesnt seem to work now
Why do you need an invisible projectile? Because snowballs can be changed to display any item.
You should be able to do this with nms
what is the purpose of having the projectile invisible ?
Im creating a sort of magic wand, and i Need the snowball to be invisible cause It has a Trail of particles
if it was me, I wouldn't make projectiles invisible. I would just do the math to make it look like there is one invisible
not like anyone can see it anyways so why have an entire entity consuming resources for this
you can have a trail of particles without an entity
I think its too hard for me
but does your magic have a curve?
Like you mean the snowball curve?
f.e. yes
Yes It has
It follows the snowball, but I can have the snowball going in a straight line with nms
then just do the maths yourself
why waste the resources if you could just do it native
and print a line
all the information you need is available with some research, gravity/weight velocity
everything you need to calculate the math yourself
without having an entire entity for it
he doesnt even want gravity or whatever
going in a straight line
well yeah if you want it to just fly straight gravity isn't needed
Do you have any link that could help me
for the relevant numbers to do the math?
Yeah i Guess so
give me a bit, in a game and I will grab some links
You would probably use the values that are for a fireball since that is what would be similar in regards to a snowball
you get the trajectory
this is where some trig or calculus comes in π
you know where the players are at any given time
you just have to look at the trajectory of both, do some math and you will know if it should hit or not
the reason this is more optimal then spawning an invisible entity, is because all of this math stuff can be done in its own thread that doesn't affect the server
where as that spawned entity even invisible, the server has to keep track of it now and everything else
Speaking of ballistics
I'm trying to figure out the velocity and direction to launch a player in to reach a given target
But all of the algorithms I've found ignore drag and hence undershooting at greater distances
how would I remove an NMS NPC from the tablist without removing their skin
packets
i know that
hide the name
what
sendPacket(sp, new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, npc));```
i'm using that
but it removes their skin
too
oh i thought you want to keep the head texture in the tablist
no like
remove it from tablist
but it still shows in person
so how would i do this?
you could take a look at this: https://www.spigotmc.org/threads/remove-player-from-tablist.55175/page-2#post-3082008
is this for NMS fake players?
doesn't look like it to me
i said take a look, not copy&paste it
wasn't planning on doing that
Is there a method to check if the gui was updated?
I have this one input slot at 19, and whenever you click next/previous page, the gui updates and the input item gets lost
I want to have the input item stay if the gui updates
InventoryClickEvent and then cancel the event
I don't know what is wrong with my code, but my updateperline method is not updating scores in socreboard. I have test if this method is event triggering and this test is positive. I have teams in my scoreboard and I wont to show number of players in team. I also have join command, so I can join to team and I can see myself in team, but in scoreboard still 0. And this method is working because every time it is triggered it print int LOL (idk why LOL) to console. And sorry for my English.
Here is my code: https://pastebin.com/RuHmE0n6
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i dont think you understand what i want to do bc this won't help
Does FileConfiguration#get actually reads the file or?
no
It has its instance fetched?
Well
When you open the inventory save the item and place it in the new inventory?
YamlConfiguration is the only implementation of it rn
and it parses the entire file into memory
The thing I am wondering is if I use it within move event, will it cause lag
i already tried saving it as tempitem somehow, didn't work. Guess I'll try again
Not sure how you implemented it so I can't help
this is how I get the tempitem
And I tried putting it somehow into this pagination stuff
I use an inventory framework btw
view line 5, thats what I'm gonna try now
you might need to just make a custom tablist
like look at this i put it everywhere and it won't work
a custom tablist would probably be the easiest method
I'm not sure how this system work
how could I do what I want to do with basic spigot api then?
What
I donβt wanna do that
Is there a different way?
I donβt particularly mind if it is more challenging
public void onInventoryClickEvent(InventoryClickEvent event) {
ItemStack placedItem = ...;
nextInventory.addItem(placedItem);
player.openInventory(nextInventory);
}
I'll try this
yea but how to get the nextinventory lol
there's no onGuiUpdate() or similar
not sure if its more challenging, but it would allow you to put whatever it is you are wanting even if it looks the same as the normal tablist
in other words accomplish what you seek
That's up for you to create
There are multiple ways
Don't do me dirty I started coding plugins a week ago
Do you have basic java knowledge?
yea
I'm not going to spoonfeed you code
π rip me
Creating a new inventory shouldn't be hard for you
You already created one
Why can't you create another
i use this framework i don't wanna break stuff lol
ik and I already asked on his discord but no answer
i don't even know if its possible to code within that framwork
wtf have i done
copilot kinda helpful tho
atleast someone who understands what im doin π₯Ί
Damn your still working on that?
Ahh are you parsing just simple stuff or going to do calc level stuff
im going to let the user define its own functions
next thing to do is properly implementing operator priority cuz sucks so hard now and parentheses too
kekw
Fourteen
Why dont you use regex
You can use regex to identify groups and operations
then ofc iirc regex doesnt support recursion
cuz regex slow and would only become worser when the expressions are longer
not if you only compile the pattern once
would be less flexible to use regex instead of my switch rn ig
ill see
creating operands char by char now lol
Are u trying to parse an equation ?
they might be as well, but primarily just a fundamental math expression
Mind change the object to long type or double
its double
Or string
might use a bigdecimal to hold the precision but im wondering if using a bigdecimal has overhead
Use string*
cant just do "1" + "1" lmfao
It has
need to make it a number anyways
For instance its on heap partly π¦
brr
You mind need to remind how you do math when you started learning math
You can convert it into single number and add up step by step
gimme valhalla for big decimal on stack
ππ
bruh if i have "1.4573937282" * "2.93836282" and convert those to a number, would still have rounding issues
For example 111+ 12 -> 1+2 , 1+1 -> 123
String never round π
tell me how to do "1.4573937282" * "2.93836282"
Put the . Away and then add it later ?
Big decimal cant be as long as string :> for sure
Not sure what ya mean
1.12* 1.12 = 112x112/(100x100)
Im still bewildered
why would you even do that
just multiply 2 doubles
and if its a big double, make it a big decimal and take the precision loss like a man
Double cant hold 10^6 length
decimal in c# doesnt have precision loss right?
Isnt big decimal is only 32bits ?
No

You can set its scale and stuff
smh it holds a bigint internally
Well yea it just stores the int and decimal part seperatly
Right. Every C# app just allocates a couple thousand bits per double so that the precision is practically infinite.
Hmm i see big decimal doesnt have a limit the only thing is the memory :d
here is something to help you in regards to bitshifting since it was discussed some time ago, for every bitshift to the left, its 2 to power n(being the amount being shifted over). so lets say its 5 for the start number. its 5*(2^N) and if its a right shift, we divide instead. In case you want to try optimizing at some point π
also
in regards to bitshifts
if you are shifting between 0-31 places, an int works, if its higher you need a long up until place 63
after that you need a BigInteger
hmm BigDecimal(char[] in, int offset, int len, MathContext mc) has some nice parsing
Hi someone used XParticle how i can do the image to particle by this lib
Alright, so I am trying to find a way to shorten my config files a little bit. Right now, if I want to give each list a unique state in the lore, I need to have a list of sections proportional to the length of the list. I really don't like this as it just adds unnecessary length to the config file. Especially when the list contents are identical except for the additional styling.
So what do I have in mind? A placeholder of sorts. However, this isn't without issue. The two problems I have with this are:
- Finding a way to replace the placeholder with a list of strings.
- Applying the styling to each unique case.
I have no clue how to approach the second one since the styling is variable. As it stands, they do share a common format. (<Indicator> <Text>) So maybe I could take advantage of this somehow?
The config problem can get bad quickly. Here's two example configs to show the difference that I am trying to achieve.
Example 1 (18 Lines Reduced)
Before: https://paste.md-5.net/ecuwojigep.sql (67 Lines)
After: https://paste.md-5.net/loyenafuwo.sql (49 Lines)
Example 2 (79 Lines Reduced)
Before: https://paste.md-5.net/ovonopinux.sql (160 Lines)
After: https://paste.md-5.net/qiyutaduca.pl (81 Lines)
particle_quality:
indicator:
selected_format: "%colour_prefix%->%display_name%"
deseleced_format: "%colour_prefix%%display_name%"
states:
- off:
display_name: "Off"
colour_prefix: "&c"
description: "&7No particles will be displayed"
- low:
display_name: "Low"
colour_prefix: "&e"
description: "&7Very few particles will be displayed"
why not format it something like this?
right now you have heaps of boilerplate which can just be put into one variable
then that same format could also be carried over for all the other ones
I'm not familiar with that structure. Is that a list? How would I get those values?
hey guys, i want to add it to my discord server, can anyone help how to?
what is "it"
the voice chat bot
?
oh ok
hi, i wanted to make the dragon egg invulnerable to everything but the void, but it gives me an error if i drop it..
@EventHandler
public void damageCancellation(EntityDamageEvent event) {
Item item = (Item) event.getEntity();
Location eggLocation = item.getLocation();
if (event.getEntity() instanceof Item) {
if (item.getItemStack().getType().equals(Material.DRAGON_EGG)) {
if (event.getCause() == EntityDamageEvent.DamageCause.VOID) {
System.out.println("RIP!");
event.setCancelled(false);
} else {
event.setCancelled(true);
}
}
}
}```
what error
check instanceof first, then cast
oh ok
if you're using later versions of java you can also do
if(event.getEntity() instanceof Item item)
alr
Based versions of java*
not giving us much information lol
hello can someone help me why iron golems doesnt spawn on air
EventListeners is quite vague, maybe make a bettre name for that
show your code
what code
Sendyljr clse
ive no code
Use #help-server so
I mean programming questions this channels and for related question use #help-server
ok sorry
Na dont worry
i want to detect if a player has the dragon egg in their inventory, i have 2 ways to do that, the first is to listen to all events relating to inventories and items, the other way would be to make a custom event which i actually wanted to do, but im not that good in it
whats the usecase?
detect whenever they pick one up?
if its on demand just scan the inventory
the event should just scan the inventories of all players and see if they have the egg
wait do you want to detect whether they have it
or call an event when they get it
two different scenarios
oh
this
yeah just iterate over their items and check
and how do i do that?
wanna check every player on the server?
loop thro Bukkit.getOnlinePlayers() and call player.getInventory().contains(Material.DRAGON_EGG)
alight
ill try
like this?
public static void scan() {
for (Player player : Bukkit.getOnlinePlayers()) {
player.getInventory().contains(Material.DRAGON_EGG);
player.sendMessage("u have egg!!!!");
}
}
u forgot if statement
what if statement?
if(player have the egg) say it
I want to run code when someone says myWord in chat. How would I go about doing that?
I haven't made plugins in like 2 years but if I remember correctly, there's an event system. If there is, then is there an event that triggers when a chat message gets sent?
AsyncPlayerChatEvent
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerChatEvent.html &
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/AsyncPlayerChatEvent.html
Check if message contains myWord
declaration: package: org.bukkit.event.player, class: PlayerChatEvent
declaration: package: org.bukkit.event.player, class: AsyncPlayerChatEvent
And this is how I would use events, correct? https://www.spigotmc.org/wiki/using-the-event-api/
yup
should I be using the normal one or the async one? What's the difference?
something related to threads?
Normal one makes chat wait for stuff iirc
so if you just wanna do stuff if a message contains something I'd use async
99% devs use AsyncPlayerChatEvent
alright
pretty sure it's since 1.8 lol
what's the naming convention with listeners? do I just name the class AsyncPlayerChatEventListener?
no convention
<purpose>Listener
ChatListener
hey can anybody help me with a plugin?
?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!
checkmydesc
where does this get saved and how do I access it in another class (The YamlConfiguration)
Wtf is this
what is your question
You want to save your stack to config?
well I want to save an item stack
to where
let's say for this example test.yml
how do u cast BuildItemStack to ItemStack then
create a new file
File f = new File(plugin.getDataFolder(), "test.yml");
f.createNewFile();
alr thanks
Then to get it's wrapper you do var contents = YamlConfiguraion.loadConfiguration(f);
contents.set("item-on-cursor", yourItem);
and contents.save()
so what's the difference between YamlConfiguration and just a normal file
why var?
YamlConfiguration is a wrapper for FileReader and FileWriter. With YamlConfiguration you can store some predefined Bukkit things to yml file(like itemstack)
cuz it takes less letters to write
^^
JITC will carry it out anyways
use .build() method
inv.setItem(slot, item.build());
basically you read file with YamlConfiguraion.loadConfiguration(File), save it to variable, then use a lot of .set(), and .save() in the end.
So you don't have to write 9999 lines of code to work with YML yourself
So basically I'm using EconomyShopGUi to sell vehicles right but,
for some reason it messes it up so the vehicle doesn't work after I buy it, unfortunately I can't attach a screenshot.
can I send you a screenshot?
why can't you send it here
I don't have permission
verify
wait
!verify <YourSpigotMCName>
Could not find your SpigotMC.org account!
thanks cafebabe
How can i shoot a fireball to the player?
#launchProjectile
and?
it's not supposed to look like that, it's supposed to look like this and they don't work when I buy them
Is there a way I can use the file for other stuff too or must I make an individual file for each item
you should probably ask in their discord @rancid elm
this seems like a very plugin specific issue
I want it TO the player
what is wrong
create a new File each time
read it with YamlConfig... and save
pain alr
i mean
You can store everything in one file
list of items
and boolean true/false values
and ints and strings
like in essentials config
play around with velocity then
You just need to use .set() multiple times
and don't save 2 values on one path @reef lagoon
new value gonna replace old one
technically you could tho
I'm just storing other stuff on the same file, such as uuids
I made some methods to set stuff myself, I never touched YamlConfiguration
Well if you plan to use yml
resourcepack based on custom modeldata?
It's better if you use included YamlConfiguration class
yes
well do you have the resourcepack applied?
Well you need to store ItemStacks with customModelData in your GUI
And have resourcepack on
yes
and the itemmeta has thhe custom modeldata?
the path is item: in this case right
so just item?
hmm looks a bit hotter already
If you want this kind of storage
you need "previous-item.material"
and so on
separated by .
If you store a list of strings, it would look like this
Can you show
config of your shop gui plugin(where actual items are stored as values)
I bet it doesn't store itemmeta(custommodeldata, nbt tags)
sure wait
is that the same menu as when you open it the first time?
slightly unrelated, you know you can hit the tab key to complete the current completion suggestion, right? You don't have to use your mouse?
then no custommodeldata is applied to those items
I've never seen anybody use their mouse for that lol
lmao
same here
yeah
that sucks
if you have an hour we can go to discord and i will make a small plugin for your vehicles shop
dutch lol
sure
add me
FREE JAVA LESSONS hehe
Why use Β§ in config?
can you use a regex match in a switch?
if so please do
i can but that would just work the same way as i'm doing and would be slow
then take a look at how a BigDecimal parses a string
yeah ik
I guess a parser is kinda low level so you're allowed to do that verbose shit
kinda ye
also wondering how to make it as efficient as possible
but thats for a later time
frostalf talking bout bitwise calculations which i dont even understand lmfao
yes
Not so well :l
π€
If i create a backpack with store data with persistentdataholder it mind create a big trouble when server load that
eventually you are going to need to
Bit wise is very useful
have never used it
most people haven't
but in regards to doing calculations without taking up processing time though is where it comes in handy
is the whole bitwise code to perform a multiplication actually faster than doing a * b?
not just that
bitmasks, using some funky properties like OR
basically if you're messing with bytes and doing fancy trickery, you want to do bitwise stuff
mmh
bitmasking is also handy too
mc protocol uses bitmasking if I recall
entity metadata
so make them correct
i dont know to mistake
did you add the repository?
to the pom that is
if you didn't it isn't going to find that dependency unless its on maven central
@EventHandle cannt access previous value ?
i have this
private HashMap<Integer,AbilityData> data=new HashMap<>();
except that you can't, adventure can be used in other places the api provides, inventories aren't one of them and will never be because it's provided by paper
so in spigot there is no way to do it because of outdated inventories
I thought maybe there was another maybe funky way to set the font but I guess not
after that
@EventHandler
public void InventoryEvent(InventoryClickEvent event){
System.out.println(this.data);
}
Technically you could probably set Unicode Characters to your font in the resource pack and then use those
this.data return empty although i already put data to it
You didn't put anything in it though
π€
did something weird again
1+1 = 0 yes
ehhhh
just redefine 1 -> 0 and it's about right
how can i unregister an event listener ?
java.lang.NoSuchMethodError: 'org.bukkit.configuration.file.FileConfiguration nl.stefanokeizers.vehicles.utils.data.VehiclesConfig.getConfig()'
at nl.stefanokeizers.vehicles.Main.onEnable(Unknown Source) ~[?:?]```
Someone knows why after obfuscation my custom config with getconfig method doesnt work anymore?
Yeah thats probably why xD
But yes i need to obfuscate this one because skids are on the hunt for this lol
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/HandlerList.html
check the unregister methods
declaration: package: org.bukkit.event, class: HandlerList
magic
2+2 gives 1+1 wtf
probably my parsing method
ah yes new Operand(value: 1).getValue() gives 0 :/
aah did setValue(currentChar - '1') instead of '0'
those are lowercase
how can i detect if a player sits on a armorstand (which event and which methods)
players cannot normally sit on armor stands π€
smh
k thx
when button falls
or redstone
or sand
and breaks?
i want to change the itemstack that drops
yes
artifactid should be lowercase
when blocks collapse
hi, i wanted to make it so if u have the dragon egg in ur inventory u get 100+ levels and if u remove it will remove you those 100, but in my program i never stop gaining levels when i have the egg.
Bukkit.getScheduler().runTaskTimer(this, runnable -> {
for (Player player : Bukkit.getOnlinePlayers()) {
player.getInventory().contains(Material.DRAGON_EGG);
if (player.getInventory().contains(Material.DRAGON_EGG)) {
player.giveExpLevels(100);
} else {
player.giveExpLevels(-100);
}
}
}, 1, 1);```
this is in onEnable()
no need for runnable, just put ()
wdym?
(BlockPhysicsEvent?
this, () -> {}
alr
can you post the error
for example if i add like a boolean it gives me an error
this is a task timer, this gives you like 2000 levels per second if you have that egg in your inventory
gains
what is that character after the st
ik
but how do i fix it?
What is your goal?
.
are there any nms tutorials (reflection)?
run it once
gradle btw
yes but this is the onenable method
what does reflection have to do with the build system π€
You don't even need a scheduler for this
Just loop through only players in your onEnable and check if they have that item, yes -> add levels, no -> remove levels
i gotta add dependency somehow
for reflection ?
so remove the scheduler?
the entire point of a reflective access to NMS is to not depend on the server impl isn't it ?
yea
like that?
for (Player player : Bukkit.getOnlinePlayers()) {
player.getInventory().contains(Material.DRAGON_EGG);
if (player.getInventory().contains(Material.DRAGON_EGG)) {
player.giveExpLevels(100);
asdasdasdasdasdasdasd=false;
} else {
player.giveExpLevels(-100);
}
}
@iron glade
you'd have to move that logic into a listener
and listen for the player inventory changing
there is no such event tho
you're missing an if
player.getInventory().contains(Material.DRAGON_EGG);
literally the line below that dude xD
why ignoring return value of first method call?
/ remove it
remove the if?
remove this
this does nothing
alr
you're checking in the next line
btw that ignore that boolean
If a player has 50 levels removing 100 just sets them to 0 I suppose?
ye ig
alternatively you could remove those levels when he drops the item
or moves it to another inventory
yes, but those are a lot of events to listen to, its i think better if i just scan the entire inventory
Then maybe a task timer that checks that every minute or so?
and some boolean hadItemOnLastCheck or smth like that
so that you don't keep adding 100 xp levels
nvm
u dont understand
the egg is like visual levels, so if u have it u get 100levels and if not, u dont have those 100 levels
its kinda first time me actually using reflection, could someone help me figure out how to get rid of "Not Secure" thingy in that method?
private void broadcastChatMessage(PlayerChatMessage playerchatmessage, Predicate<ServerPlayer> predicate, @Nullable ServerPlayer entityplayer, ChatSender chatsender, ChatType.Bound chatmessagetype_a) {
boolean flag = this.verifyChatTrusted(playerchatmessage, chatsender);
this.server.logChatMessage(playerchatmessage.serverContent(), chatmessagetype_a, flag ? null : "Not Secure");
...
cant i set flag just to true
Honestly I think it would be cleaner to just listen to events in that case, aren't that many
reflection does not get inside methods
reflection can do fields
I mean, a log4j2 config to filter that out ?
you are not running your server with the poper java version
hmm i'm wondering how to properly clear a linkedlist? would setting the head and the tail to null be enough?
singly linked nodes
nah made my own linkedlist like class
lets hope i dont create too many memleaks
figured out why my expressionparser wasnt working, it was working with the previous expression lol
yes but you compiled your plugin to java 9
yea π it should be defined in your pom.xml
your mom's gonna work now
oh you finally switched it to floats? that's nice
doubles lol
might want to use bigdecimals eventually to not loose precision
or some way in between
yet to implement op priority
and my exception are the best thing
so I have figured out the event and config stuff and whatever but I want the code to run when the first word of the chat message is a string contained in a string array form the config. I think I should use config.getStringList(...).contains(firstWord) but I'm not sure how I would get the first word of it. I guess split at or smt
Big decimal only makes sense if you need to do accurate maths - so almost never
and I need to get the rest of the message into another string
mans literally writing a calculator xD
Good joke, but those all use really outdated programming language
More like: Java nonexistent
then join the rest of that
AsyncPlayerChatEvent.getMessage().replaceFirst(firstWord + " ", "");
or
AsyncPlayerChatEvent.getMessage().substring(firstWord.length + 1 /*, maybe AsyncPlayerChatEvent.getMessage().length*/);
alright, thanks! I'lll use substring
i don't remember substring parameters
JavaDocs bless you
I'll figure it out
start (inclusive), end (exclusive)
I only need the start tho, right?
yup
and firstword.length() + 1 because there's a
maybe i shouldnt delegate Validate.isTrue to isfalse(!condition) lol
how do I send a message to the chat? So that everyone can see it
hi a question how i can run a command without the player having the permission like /craft from essentials
Thanks a lot!
Is there a way to make a spawned mob have no ai, and have it be affected by gravity, knockback, etc?
I tried messing with LivingEntity.setAI(false) but that disables gravity
^^
Without diving into NMS
oof
rip
more debugging
ah, AsyncPlayerChatEvent runs before the message is sent
yeah
can I somehow have code run after it
run task 1 tick later
alright
yez
I wanna send a chat message
Could they not listen to it with event priority monitor?
I thought that was the whole point of the monitor priority, just there to observe the events effects
oh, does monitor run after?
so what do I do
point is that if you don't override anything and just want to know what plugins changed
ah
you should use MONITOR
all I want to do is send a message after a player sends a message, using the contents of what the player sent
Use the scheduler
I will
old method vs new lol https://paste.md-5.net/egufiwazir.cs
do I have to run ```java
Runnable sendMessage = () -> Bukkit.broadcastMessage(String.format("...", restOfMessage));
Yeah
alright then
do I use runTaskLater() or runTaskLaterAsynchronously()?
depends on what you need
first runs later and second later and async
just use sync
the normal one?
yes
yes
ah my famous parser.parse("1+ - 1") returns 2
so the final product is ```java
Bukkit.getScheduler().runTaskLater(this, () -> Bukkit.broadcastMessage(String.format("...", restOfMessage)), 1);
just test it
I will
nobody cares about the process)
your mom does
ha
didn't work :D
deprecated
loop for all players and send the message
huh?
nah
since when ?
event registered?
Spreading false info are we
@EventHandler
yes, it's working, just sending it before the player message
for me appears as deprecated lol
Cause ur probably a paper user
You're depending on Paper. They want you to use components
nah
runTaskLater using BukkitRunnable is depricated
new BukkitRunnable() {blah}.runTaskLater(plugin, 1L);
feels bad
instead of the whole ```java
@Override
public void run() {
}
people still instantiating damn bukkitrunnables instead of using scheduler smh
You can use the scheduler
Yeah delay it a bit more I guess
I'm not saying it's what you should use lel
Chat isn't sync so using ticks isn't perfect
how do I do it then
.
How do I calculate the default damage? Iβm recreating damage for my plugin and want to learn how the default damage works for attacking players. For example, set a playerβs health based on the armor they have, the item the attacker has in their hand, then send the damage animation.
so do i just use like 10?
Yeah I guess
alright
Try looking at how vanilla calculates it
The Minecraft wiki probably has something useful too
event.getFinalDamage()
Well that's not calculating it yourself
but yes it would probably be smarter to just use the damage events
YOOOO! it works
Is there a way to check if the command executor is a CommandBlock?
no
hi, im making a plugin where if you have the dragon egg in your inventory you get +100 levels, but if you drop or remove it, those 100 levels will disappear. my question is what are all the events that i need to listen to?
Okay thanks
declaration: package: org.bukkit.command, interface: BlockCommandSender
EntityPickupItemEvent
And EntityDropItemEvent
probably
and what if u like put it in a chest?
or drag it out of ur inventory
You'd better have a task timer
which checks if there is or there is no egg in player's inv
Otherwise 999 events related to inventory
how do i do that?
true lol
wait
actually i tried that already, but the issue was that i kept gaining more and more levels
whenever I run a custom command, in chat it says the command I just ran. Is there a way to not show that?
create a timer which loops through players and checks if they are in a list of players who had dragon eggs
If they now don't, remove 100 levels and remove from the list
If they have and not on the list, add 100 levels and put them
add to the list on join
idk if im able to do that :/
alright, ima try 1 sec
(checkmybio)
π¬
in the hashmap do i have to put <Player, Boolean>?
just a list
ohhhhh
or a map who cares
or a Set
or a Stack
A stack wouldnt be ideal
or a Collection<?>
List?
i think LinkedList would be alright
Set<UUID>
^
HashSet should be a good implementation for this
f state doesnt want to reset to prepare for new expression
sth like this to detect?
public class DragonEggFunction {
public void fun() {
List<Player> hadDragonEgg = new ArrayList<>();
for (Player i : Bukkit.getOnlinePlayers()) {
if (i.getInventory().contains(Material.DRAGON_EGG)) {
hadDragonEgg.add(i);
} else {
hadDragonEgg.remove(i);
}
}
}
}```
hmm if user decides to catch syntax exception, the tokens are corrupted
your list should be a field
should probably reinstantiate tokenlist on every expression
outside of the method
List<Player> hadDragonEgg = new ArrayList<>();
public void fun() {
for (Player i : Bukkit.getOnlinePlayers()) {
if (i.getInventory().contains(Material.DRAGON_EGG)) {
hadDragonEgg.add(i);
} else {
hadDragonEgg.remove(i);
}
}
}```
`?
@fluid river
and add the player.getUniqueId()
like this yea
and how would i do the exp gain/remove part?
well bukkit methods lol
...
Get ready for memory leaks
yez
k
?jd-s
final thing ig https://paste.md-5.net/eqebefonev.cs
check if player is on the list already, and if player was not on the list before
Why?
Why store the player multiple times
Also don't forget to remove the player when they leave
Also just use a Set rather than an array list
thats why you should store uuids, im 100% sure youll forget
how :/
wouldn't it add players two times
Exactly
and remove even if not in collection