#help-development
1 messages · Page 242 of 1
What's the best way to make an Inventory Builder that assign to the chosen element a predefined click-event (action)?
Always used a line action: {ACTION_ENUM} inside my invbuilder config, I'm looking for new and maybe faster ways
[20:20:59 ERROR]: Could not load 'plugins/LyuDuels-1.8.8.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: Cannot find main class `me.lyu.lyuduels.LyuDuels'
does this have to do abt me deleting the on plugin enable and on plugin disable?
the path is wrong
how I fix
by putting the right path, take care of uppercase and lowercaase characters
i dont know your project structure
is it bc I deleted the code in the LyuDuels.java
well does the class still exist?
which is i think what loads it up
ye
whats the onenable and ondisable code
that you get in every plugin
extend JavaPlugin and
@Override
public void onEnable() {
code
}
@Override
public void onDisable() {
code
}
``` iirc
feel like epicebic knows the answer
my soul can feel it
ive got no clue if this is exactly what you want, but heres my custom inventory thing that makes inventories https://github.com/The-Epic/EpicSpigotLib/blob/master/src/main/java/me/epic/spigotlib/inventory/CustomInventory.java
I created an Inventory Builder, which is a class that, translates a YAML config into elements and actions. In order to be able to assign an element an action, I use ENUMs so when an element within the config has the line action: EXAMPLE_ENUM it means that, when a click occurs, a default action takes place
I'm looking for new ways to do that instead of using ENUMs
Example of what I just said above:
13:
material: "PLAYER_HEAD"
texture: ""
displayName: "<gold><bold>Set Owner %company_owner%"
lore:
- "<gold>Click to set the owner of the company."
click-event: SET_COMPANY_OWNER```
What do you need for automatically update server version
What scripts or something
For most rev lastest
Why when I try to do this: player.getLocation().setYaw(player.getLocation().getYaw()*-1); nothing happens?
I want the player to be rotated and it does nothing
mutating it wont do anything to the player
dont you have to teleport them to their located with a switched yaw?
oh
well, that's the only way to create a CustomInventory starting from a YAML
Not the only way lol
Im not suer, if this is best chanel to ask. But, I have problem with importing PAPI in my plugin. I added PAPI jar to project. Someone have some ideas?
ye, IntelijjIdea is destroing my shit ntb 😄
Just plain Java
I have added here. So that cloud work
public class SomeExpansion extends PlaceholderExpansion {
@Override
public String getIdentifier() {
return null;
}
@Override
public String getAuthor() {
return null;
}
@Override
public String getVersion() {
return null;
}
}```
Is just wierd.. Im getting blueshit errors.
I know Im returning null, I will change that later
What is the PlaceholderExpansion class contents?
Or better said what methods does it declare?
yeah, I could surely create a new file type and maybe a custom file reader like SnakeYAML
Also, I advise you to not use Eclipse JDT for dependency management unless you know what you are doing.
anyway, it's the easiest way for other people who wants to use the plugin
huh
That should be Papi class, right?
Yeah, do F3 on the "PlayerholderExpansion" part of "me.clip.placeholderapi.expansion.PlaceholderExpansion"
Then show the contents of the outline view (should be to the right by default), though depending on your settings it might be easier to just screenshot the main window - should the view change
I tried IntelliJ Idea and there is no error. Weird. I´m not using that, because my ntb is to low 😄
Eeem, There is probably problem..
Gona try import that file again
Still same
That is to be excepted. Do you have that outline view?
here
not really what I meant but okay
Im not sure than, Im sorry. I just not having here some outline view
this is what the example is on papi wiki
my screen looks like this
I just followed this: https://github.com/PlaceholderAPI/PlaceholderAPI/wiki/PlaceholderExpansion
This indicates that something went down the drain. Thus do Project > Clean..., tick Clean All Projects, hit Clean
ah, the typical beginner eclipse configuration.
done
Ye, Im just new in Java 😄 I would like to use Intellij, but if I run MC to test and IntelliJ my ntb is too slow
Does it now work?
if not you might need to right click your project (on the left-hand window) and click refresh
If it still does not work, you are in a cursed position
It's honestly not bad. Could be worse. Could be the very very basic, untouched Eclipse configuration.
Still same, I just tried open procjet in IntelliJ and looks corect.
I use Eclipse and that default viewport still haunts me to this day
Yeah, the package view must at least occupy half the screen
Oh no 4j
But everythink look correct, right? 🤔 Maybe there should be someone else with same problem on spigot forum, or just google. Gona try. Thanks
Could you DM me that PAPI jar?
The only thing I could think of is that jar not containing the placeholder api
Mby, problem could be Im using 1.17 spigot?
nah, this is either an eclipse (compiler) issue or an issue with your papi jar
I tried download new one. No problem with that.
I insist on that.
@vocal cloud seems like you have a lot of experience behind so... Could you help me?
What do you think is the most optimized and best way to make custom inventories with items that can have (different for each inventory) predefined (Consumer) actions through config?
(I'm sure whatever the answer is, I will have to learn about CompletableFuture or BiFunctions haha)
If it were an eclipse compiler issue, which is extremely unlikely given that I use PAPI myself, the issue would be easily visible when I have the jar on hand
please
What kind of actions are you referring to? You shouldn't need a consumer as those are usually for APIs.
@trim lake Move PAPI from the module path to the classpath
Wait... I just tried to move jar from Modulepath to ClassPath and errors are gone... Shoudl that file be in ClassPath?
The placeholder API devs are absolute idiots
You are faster 😄
I just tried that 😄
Im using NBTApi and that is in Modulepath soo 😄
This file is the cause of your trouble for reference
@tender shard is PDC for blocks in your lib removed when blocks are broken?
Or destroyed
thanks, now I will know PAPI should be in Classpaht not module one
I am doing a plug-in regarding companies.
Example
To create a company I use an inventory that a person can customize from the config.
Obviously, to create a company you need 3 factors (name, owner and description) so, I need 3 (+1, the save action) consumers for this functionality.
hover event of itemstack possibly?
I'm confused as to why or what would be configurable. I'm having a hard time understanding the use case of allowing such insane levels of customization
text component i think it was
according to https://www.spigotmc.org/wiki/the-chat-component-api/ there is
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
np lol
Good question, I don't know.
My logic would say that since I have to do 5/6 inventories like that, I would make my life easier by finding and extracting the common parts.
My masochistic side also tells me that it's cool to make everything more and MORE and MORE and MOrE customizable
mORE
Start with everything as simple as possible and grow features where you need to
Created an issue, hopefully it'll get resolved soon: https://github.com/PlaceholderAPI/PlaceholderAPI/issues/894
I assume this will be a public plugin. If that's the case remember that more customization isn't useful if no one will use it. Write features people will want from it then go from there.
Plus you can get feedback from them as to what would be/is actually useful in the real world
It's a challenge to myself, I will only use this plug-in in the port-folio maybe in the future
I believe there is a better way than shading Kotlin libraries into plugin. I kinda remember sth like I can use libraries: in plugin.yml but not sure how can I do that. Any docs or IDK anything
developing with Java 17, 1.19
And that same myself, is not understanding if there is some better way to do that thing
So, anyway, back to the problem...
What's the best way to associate a Consumer to a desired element?
Is the action: {ENUM} the faster way?
Why a consumer?
Consumer<InventoryClickEvent> // Action
why
So multiple configs or whatever will interact with the same InventoryClickEvent?
Why a consumer for this?
nah
GODDDDDDDDDDDDDDD
You tried to help me with this like 3 months agoooo hiii
Now I am here to tell you, I didn't understand a word of what you said before
thank you
if you want to let people configurate your plugin or whatever, make a config opt for every thing you think "hey, this could be changable" at
did you gave up or what
whats the issue
Yeah, after you write the plugin itself. Don't spend all day writing configs for systems that don't even exist yet
YAML -> InventoryBuilder -> CustomInventory
Best way to associate a def action to an element
while coding it
"def action"? - defense action?
default haha
defined
ah
default
so you basically want to make a plugin players can make interactable guis with?
If you want to see a bit of a complicated way that I did it you can look at this
https://github.com/Fisher2911/FisherLib/blob/master/src/main/java/io/github/fisher2911/fisherlib/config/serializer/ClickActionSerializer.java
And if you want I can dm you a link to an example plugin configuration so it isn't seen as advertising
Imo write the core first. Otherwise you'll end up spending all day writing fluff that isn't necessary.
nah, as soon as there'd be a configurable part just do that right next to it
I am making a plug-in for companies.
There are 5 commands
- Promote
- Create
- I don't remember
- I don't remember
- don't remember
Each command, works through an inventory (Look at the image)
I want to have 5 config files for each inventory and each player change the location of any Item and maybe even create new static ones.
I was looking for the best way to do this and also associate with the items such as "set description" a Consumer<InventoryClickEvent>
otherwise you either forget about it or you squeeze it between somewhere
this's the better explanation of my entire life
If it's required but if it's fluff then don't waste time on it
if you plan it into your config its not "fluff"
I'd argue what they're trying to do is very much fluff
and if you code by hours then add anything you can into the config
Code by hours? You mean paid by the hour?
yeah if you're getting paid, á work, á code by hours
lol okay with that mentality
5 config files for each inventory sounds a bit overkill
You want to get a project done write the core first then focus on all the configuration
never, but we are circeling
less text for each file is much cleaner
I have
libraries:
- "org.jetbrains.kotlin:kotlin-stdlib-common:1.7.20"
- "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20"
- "org.jetbrains.kotlin:kotlin-bom:1.7.20"
``` in my plugin.yml
but I get org.bukkit.plugin.InvalidPluginException: java.lang.RuntimeException: Error resolving libraries error
as a user i would personally just remove the plugin from my server after opening the third
then dont do it
okay...
Now, before I have to go...
What's the best way to associate an action to an element?
this is my actual solution: https://paste.md-5.net/tusenofega.java
https://paste.md-5.net/qahamizipa.java
That's my lib
since you are just using keys to determine what happens on the click, i would just store the key with a runnable or, yeah consumer, in a map and recall it everytime
.
You can associate a click action with a StaticElement which I’m assuming is the item
The element with the action could be in slot 1 as well as slot 31
that Builder class is "general"
SmartInventories need SmartHolders haha
does anyone know how to resolve?
doesnt matter
It’s the easiest way to do it
not really
Anything else ends up being a lot more work and more likely to have mistakes
it doesnt break anything
its just not intended to represent an inventory instance for identification
wouldnt call it a misuse but a feature
https://paste.md-5.net/igatikehat.java
So, creating and using consumers like this, what would you change?
god
Hi, how can i get a direction in order to make a point face another point? Let me explain better, we have point A and point B, how can i get a vector in order to make A face B? Also note that it needs to work in 3 dimensions
I still don't understand
I have to go, thank you all for the help 🙂
I will reply later
You explain better than I do, congratulations
ping me later than, a bit much to just scroll over and shittalk at
I have two locations, loc A and loc B how can i make a vector (a direction) to make loc A face loc B?
seriously?
what is to resolve?
that gives you the offsets yes
Seriously
thank you so much 🙂
One thing is you can make the consumers constants, you don't need to create new ones each time
so this should work right?
what
b.subtract(a).toVector();
oh
That's if you're okay with b being modified
If you dont want b being modified, do b.toVector first
and to get the distance between the two points?
Location.distance(location)
oh right that shit wasnt immutable
oh right
What is Content
dafuq is a content
remove this message
check the config
Is this with adventure?
How tall is a small armor stand? Like 0.3 blocks?
@last temple
Yeah ItemTag seems to be the NBT data😂😂
Why is this so convoluted
This has the solution
check out InteractiveChat and how they do it
well that is #help-server stuff. Alternatively we could ping choco, who will promptly say that this is configurable
Is there a way to tell how long a player has been drinking a potion? So far all I can do is find out when the player drinks a potion, and when they right click with the potion. But I can't get anything else.
I tried to use logic to determine how long the player was right clicking in the interact event, however, it seems that the event only fires once while drinking a potion
Ik how u can use logic to determine
^^
Busy rn I'll explain in a bit
depends on whether you call "CustomBlockData.registerListeners()" or not
declaration: package: com.jeff_media.customblockdata, class: CustomBlockData
Ty
okay, the way I tried was saving each time the player right clicked into a map and checking the next time they clicked if enough time had passed, but that doesn't work since theres only one right click.
Check each tick if they're right clicking
If they are they're drinking
If they're not they stopped
If the playeritemconsuleevent is called, they actually drank it
me: gets out of bed and opens intellij
With player.getItemInUse
I did the same lol
I was struggling to read the documentation for it tbh, so I didn't catch that. gotta hotfix the plugin I just updated today 💀 I hate pushing updates in quick succession
it's mentioned in the "main" class, I hope I didnt describe it too poorly lol
psh I don't read javadocs
I've never done this in my plugin and it still works should I be worried
then you have leftover data when a block gets broken
or pushed by a piston, etc
oh I just deal with that myself
oh then everything's good
also whats the whole thing with relocating it
I like never relocate my packages lol
it's actually not required. it used to be required to avoid stuff when two plugins shade the same classes
but now, iirc, they all have their own classloader so it's basically irrelevant now
how can I stop the scoreboard from flickering when it refreshes?
better logic I've never seen flicker when refreshing my scoreboard
;-;
it happens all of the time
ill record it and see if it works
you can see it at the start of this vid at abt 2 secs in
just flickers for like a split second
how are you updating it
lowkey looks like your clearing the entire scoreboard
bruh it wont work
than readding everything
I probably am
xD
ok ima restart my pc lmao
Main function public static FileConfiguration getInstanceConfig(){ return instance.getConfig(); }
Reload command ```
private FileConfiguration config = bpLobby.getInstanceConfig();
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
instance.reloadConfig();
sender.sendMessage(reloadMessage);
return true;
}```
How to properly reload config? This does not work
Can i see where you get values frm the config?
is the config custom? or is it just config.yml
config = YamlConfiguration.loadConfiguration(new File("myConfig.yml"))
?paste
regular bukkit api config 😥
😠 how dare you reply to me
I'm blocking you
lmfao
ok i'm going to be honest with you. I don't know how to use the spigot scoreboard api
🤔
but don't update every line every time you refresh is my reccomendation
I just use FastBoard
packet only scoreboard api
do you use maven?
deps, repos
oh yes
usually you just add the repository and the dependency
okay
then you set the scope to "compile" and you also need the maven-shade-plugin, if you don't already have it in your <build><plugins> section
check out the second headline in this: https://blog.jeff-media.com/common-maven-questions/
then you basically only need to add the <dependency> and maybe <repository> stuff
that I don't know lol, but Y2K probably knows it
they have docs on their github i would guess
okay
yeah looks like it's well explained
but how is this better?
you don't have to worry about objectives and stuff yourself, instead you can just throw some strings at it
if I update and it is the same as it is rn will it not update?
okay that just seems easier to code but doesnt seem to make it better for players
like I want to remove the flickering scoreboard
so annoying lol
it would remove the flicker
but yes, this does seem faster
I am pretty sure that this API will take care of this for you
as well as making it easier to write
okay
nice
so, do I not need to use the line player.setscoreboard(something) with this?
if I use update lines it just does it
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player player = e.getPlayer();
FastBoard board = new FastBoard(player);
board.updateTitle(ChatColor.RED + "FastBoard");
this.boards.put(player.getUniqueId(), board);
}
https://paste.md-5.net/asigumolim.java full example found on their github
FastboardAPI is just simply the best nothing comes close
from what I see, you only have to create a new FastBoard (e.g. new FastBoard(somePlayer)) and then it automatically works
hm ok
in the example, they use a Map<UUID, FastBoard> so you can update it later
the scoreboard is for everyone
no
all players
oh
me about to totally not yoink some of this code (i mean most of it):
hm?
you still have to create one for every player
just make a ScoreboardFormat object
how does the hashmap update it for each player im so confused
the hashmap doesn't do anything but cache the scoreboard
okay
you update it yourself. Basically you do this:
create a FastBoard for every online player
loop over the hashmap every second and update them all
ohh I didnt see that u put a player in the new fastboard
👀 if your updating them that often wouldn't another collection be better
so thats who updates for
if it's the same for every player, they could ofc just use a List
but tbh who cares 😄
they will never have more than like 200 players on one server
the code formatting and naming police
I'd still use a map because that way you always know which player has which scoreboard
even if you don't need it now
maybe you'll need it tomorrow
true you'll always have Map#values()
chickity china, the chinese chicken
idk I forget I'd assume its the same
k
I hate scoreboard impl by mojang
so this would give the player a new scoreboard with the title "hi" and on the 2nd line it would say "t"
it's basically the same as get(...) in a list
Fastboard is my best friend
hewwwwo :3
oop forgot code
idk try and see
hmm
go for it
ok
omg I thought that gizmo dude on this other discord was the same gizmo who's here
I believe in you
but he's someone totally else lol
me 2
i found a person in another discord I'm in that talks here
💀
is it maybe me?
damn, he's a jerk
I once found mfs I had an NDA with, in a server that I was open about age
no clue whom you're talking about tbh lol
he only talks in help dev
Just crazy I saw him in a smaller server I played on is all
💀 terminated
just left instantly
there are people from the server I used to work for on here
but they never talk
their last message was 2 years ago xD
is oliver finally asleep now?
How would I use a for loop that starts at 1 and ends at the value in the indexed element of the array?
you want to loop over an array?
it didnt work
yes
String[] myArray = { ... };
for(String element : myArray) {
System.out.println(element);
}
or if you need the indexes:
for(int i = 0; i < myArray.length(); i++) {
System.out.println(myArray[i]);
}
note that array indexes start at 0, not 1
so if I wanted what I wanted above I would do ```
for(int i = 1; i < myArray.length(); i++) {
System.out.println(myArray[i]);
}
If you want to iterate everything except the first element, this is correct
yeah that will loop over all elements except the first
How can I override other plugin's commands?
for example: (this uses boostedyaml, but ignore that)
if (!config.getBoolean("should-override-other-plugins")) {
return false;
}
// This is what I want to figure out, to override every plugin with the same command name as the command I'm trying to create.
...
Thanks a lot :)
register your command later in command map or something it will take priority
dynamically
searxh "register command without plugin.yml" or something
basically you can get the CommandMap from the SimplePluginManager (just cast Bukkit.getPluginManager()) using reflection
and then change it to whatever you like
it sounds like a horrible idea though, you shouldnt mess with other plugin's commands
or use my shit command engine with fucked completion and half working arguments
Sometimes plugins use an alias that you wanna use as ur main command
I just unregister it💀
well the cleaner solution would be to ask the other author to make their commands configurable
but yeah sometimes you just have to use dirty hacks lol
😂😂
also the slower solution
IIRC I haven't used plugin.yml for commands for 2 years or so now
same
Why is it even needed still?
Or in the first place
I don't know
I nowadays use ACF for all commands
huh ofc you can
I tried for like 2 days everyone that answered me said its impossible
couldnt find it at all
what kind of args? just a bunch of strings?
yea
public static void myCommand(CommandSender sender, String[] args) { ...
works 100% fine
I always do it like this
thats weird
lemme double check
there was no String[] args when I did it
and literally like 10 ppl told me it was impossible
i find including shit like ACF too hard so i make my own big mistake
failed twice now
well usually you define every arg separately, like this
but it also works 100% fine when just using String[]
I just checked it
the execution always works but the completion always fucking sucks god damn it
welp ive been using normal spigot way for like a while now ;-;
you can always register custom completers but usually the builtin works extremely well
if that works for you, then there's no reason to switch
I only switched to ACF because parsing is a hell if you have different commands with exchangeable args
goos
e.g.
good
yea tru
/giveitem <item> <amount>
and
/giveitem <amount> <item>
in spigot you'd have to manually parse this shit
in ACF you just do
public void onGive(Player sender, Material material, int amount)
lol I parse all of the time with this
just surround it in try/catch incase of error xd
I recently restarted using spigot commands
yea...
i use https://github.com/The-Epic/EpicSpigotLib/blob/master/src/main/java/me/epic/spigotlib/commands/ArgumentCommandHandler.java for the main sub command stuff but then just default back to arg checks
Thank you :)
Thank you too :)
np! feel free to ping if you got any question about that
Time to document my plugin
why not jump off bridges
because they weren't made for that
^
how do you know
god will save u if you land on concrete yes i swear if u think you gonna die just phone up god asap and ask yo can i not splash on the floor
it says ot right there
well maybe you'll also just get a miscarriage
obviously scam website
bonus
yeah fuck wikipedia
wikipedia != real
tbh I love wikipedia, I have over 400 edits there lol
so wikipedia = (f)x = {x | y = 1}
"Bridges are structurally designed to be the primary location of suicide" it says it righ there
you can add it if you like
but what I sent is the article about the card game "bridge"
yeah sorry the quality was so shit combined with the fact that its 2 am
oh ysah 1:30
or is my windows clock weird again
my xloxk is set incoreect i guess
maybe lol
1:32
now that i look back at it the word xloxk looks more like xbox than clock lol
can I use Bukkit#getPluginCommand(...)?
yep, sure
but you can only do that if the other plugin was already loaded / enabled
usually, if you want to override other plugin's commands, you would delay your whole command registration stuff by one tick or so
I cant get this to work, im getting errors with this
you didn't shade it
hm?
🥳 maven shade plugin
oh I thought I had
NoClassDefFoundError
I have this in my pom.xml what else do I need?
ok xd
I just reload
but how did you even compile the jar?
but what did you do to get a .jar?
oh lmao
it works fine if you dont need to shade anything
well its worked fine till now lol
you probably now also want to make maven automatically put it into the correct folder right? If so: https://blog.jeff-media.com/common-maven-questions/ (first headline)
so will this also make the jar?
but you can check the blog post above to change it to somewhere else
no, my server is on a different machine than the one I develop on and I only make plugins for my server'
oh ok, then you don't have to worry about it
just double click on "package" and your .jar will be inside <yourProjectFolder>/target
WildGamesSkyMining-1.0-SNAPSHOT.jar
there are 2 of that
one has "-shaded" at the end
although they should be the same anyway
it actually doesnt matter
also you can just drag that GUI so you can see the full name
but in your case, both files should be the same anyway
I would always use the file that does NOT have "-shaded" in it's name
in your case, they are the same. but I remember that the -shaded one can be different and then it won't be what you're looking for
ah ok
just go for the one that does not start with "original-" and does not end in "-shaded" 😄
public Voucher getByItem(ItemStack itemStack) {
int amount = itemStack.getAmount();
itemStack.setAmount(1);
Voucher voucher = this.itemVoucherMap.get(itemStack);
itemStack.setAmount(amount);
return voucher
}
thoughts?
since the map only stores items that have an amount of 1
what is this supposed to do
i have a Map<ItemStack, Voucher> that maps an item to a voucher
i wanted to use PDC but this is < 1.14
so i'm using a map
I want to get a voucher given an itemstack
oh so the item is turned into a voucher that can... get the item again?
no
vouchers are redeemables
but they are physical ingame items
so i need to map the voucher to the item
item to the voucher*
ah
@tender shard I think earlier u were talking abt chunks having to be loaded to get the entities from them... do they need to be loaded to spawn mobs in them or to check if they die?
feels like you should have a Map<String,Voucher>
Where you first get a String from the ItemStack pdc.
so basically a stringed registry
yes
so I cannot spawn them if they are not loaded?
correct
ahhhhhhh
thats why
Ive been trying to fix this for forever xd
sooooo
uh
should I just load all of em before I spawn them
you can simply call getChunk() on your location to force load it for a few ticks
depends - when are you spawning them? midgame, or on startup?
ima make a method to load like 20 chunks xd
20 chunks isn't that much
HOWEVER
the best idea would be to load until that chunk got loaded, and only spawn the entities then
every 20 secs if there are less than 15 mobs, it spawns it to where there are 15 mobs
then I would do it like I described above
how can I do that
basically you would have a Map<Location, EntityType> or similar. You can add to that everytime you wanna spawn something
then listen to ChunkLoadEvent and loop over the map
huh
and if the location happens to be inside this chunk, you would spawn your entity
so I would check if the chunk is loaded before I do it?
oh yeah, sure
if the chunk is already loaded, then you spawn the entity directly ofc
but... getting the chunk loads it
I forgot to mention that
you can use World#
sooo checking if its loaded loads it
isChunkLoaded
okay
declaration: package: org.bukkit, interface: World
BUT you have to note that it requires chunk coordinates
e.g. do not just do location.getX() but location.getX() / 16
oh
(same for Z ofc)
noo noo. well
if you have a location, you can just / 16 both X and Z, and then those are the chunk coordinates
so just all of the x y and z /16
you can then just toss them into World#isChunkLoaded
yea
@fresh timber Something like this should do
public class Test extends JavaPlugin implements Listener {
private static final Map<Location, EntityType> ENTITIES_TO_BE_SPAWNED = new HashMap<>();
public static void spawnEntity(Location location, EntityType entityType) {
if(location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4)) {
location.getWorld().spawnEntity(location, entityType);
} else {
ENTITIES_TO_BE_SPAWNED.put(location, entityType);
}
}
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
Iterator<Map.Entry<Location, EntityType> iterator = ENTITIES_TO_BE_SPAWNED.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry<Location, EntityType> entry = iterator.next();
if(entry.getKey().getWorld() != event.getWorld()) continue;
if(entry.getKey().getChunk() != event.getChunk()) continue;
entry.getKey().getWorld().spawnEntity(entry.getKey(), entry.getValue());
iterator.remove();
}
im tryin this
public void run() {
Bukkit.getScheduler().runTaskLater(WildGamesSkyMining.getInstance(), () -> {
int i = 15 - piglinbrutes.size();
while (i > 0) {
int randomX = ThreadLocalRandom.current().nextInt(-44, 1 + 1);
int randomZ = ThreadLocalRandom.current().nextInt(-90, -47 + 1);
if (Bukkit.getWorld("nether").isChunkLoaded(((int) (((double) randomX)/16.0d)), ((int) (((double) randomZ)/16.0d)))) {
PiglinBrute entity = (PiglinBrute) Bukkit.getWorld("nether").spawnEntity(new Location(Bukkit.getWorld("nether"), randomX, Bukkit.getWorld("nether").getHighestBlockYAt(randomX, randomZ) + 1, randomZ), EntityType.PIGLIN_BRUTE);
piglinbrutes.add(entity.getUniqueId());
}
i--;
}
for (Entity entity : Bukkit.getWorld("nether").getEntities()) {
if (entity instanceof PiglinBrute) {
PiglinBrute piglinBrute = (PiglinBrute) entity;
if (piglinbrutes.contains(piglinBrute.getUniqueId())) {
if (!Damage.pbhp.containsKey(piglinBrute.getUniqueId())) {
Damage.pbhp.put(piglinBrute.getUniqueId(), 1000);
}
piglinBrute.setCustomNameVisible(true);
piglinBrute.setCustomName("§c§lPiglin Brute §c" + Damage.pbhp.get(piglinBrute.getUniqueId()) + "§7/§c1000❤");
}
}
}
}, 10);
}
so "spawnEntity()" checks if the chunk is already loaded, if yes, it spawns it directly, otherwise it cachces this entity type for later
I would rather move this into its own method
y
e.g. my example above, so you can just do "spawnEntity()" and then the method itself checks whether the chunk is loaded or not
eh yea
im lazy ;-; dont wanna type stuff for a method... but it will be helpful if I want to spawn again later xd
being lazy means that you should have as many methods as possible lol
yea but rn its easier to not make a method
it will be easier later xd
once I need to make another mob slaughter location
is "piglinbrutes" a map?
yes
it looks like you never remove anything from that map
ondeath
oh ok
piglinbrutes.remove(piglinbrute)
ok good
although... it does not work for the void for some reason
if tp them to the void and they all die there, they dont respawn xd
still workin on that
it should call the EntityDeathEvent even when they die from void damage
I'd just listen for EntityDeathEvent and print it out (entity type + location)
and then see if it actually gets called
yea ill do that
oh haha I only read this rn
great
orby, me and a few others today joined a christian discord to discuss stuff haha
my passport says yes, but in reality I don't believe
but I still love discussing stuff
well we'll prob get banned for talking abt this here
nope
but we could discuss somewhere else if ud like xd
ah ok
you really have to fuck up big time here to get banned 😄
most discord servers do that
this discord basically works like this:
Don't be a jerk, then you're fine
I am not sure. I like the idea, but I don't actually believe that there's anything that science cannot explain
its so obviously laid out in existence though
well idk, I've aksed on this other discord whether it's okay to be gay and they were just spamming bible quotes telling me "it's not okay because you cannot have children" and stuff, and I just think that this is all plain bullshit
like, how can you describe how everything is perfectly made so that we can survive and not only survive, we are in the perfect spot in the universe to discover so much more about God's world
but maybe we should move to #general 😄
yea xD
if I spawn an entity will it despawn? I think my entities may be despawning cus they just disappear out of nothing
yes
they despawn like usual
can I stop this?
Entity#setPersistent(true) should prevent it
okay
also, I am using a hashmap of uuids to contain the alive entites and I use a death even to check, I want to just remove it every 20 seconds from the hashmap if the entity is invalid/dead but what happens is i use Bukkit.getEntity(entityuuid) and it gives errors because the mob is dead... can I still check if it is dead with this?
hm well you could simply check whether Bukkit.getEntity(UUID) returns null or not
oh yes
if it returns null, then this entity is either dead or not loaded anymore (chunks & stuff)
oh well thats a problem
id remove them from list if its not loaded xd
should I load chunks where they should be?
or only do if they are loaded
or what
well if you really only have 20 chunks, you can just keep them force loaded
yea ig
but that's a bad idea if you ever have any more chunks later on
yeah if you only have 20 chunks or so, that's totally fine
but if it becomes 200 chunks, then it's not a good idea lol
does ticket keep it loaded until plugin closes?
yes
yeah but ofc you wanna do it for every chunk yuo wanna keep loaded, not just a single one
yes ik
oki
for(int z = (int) e.getBlockPlaced().getZ() - 11; z <= (int) e.getBlockPlaced().getZ() + 11; z++) {
if (x == e.getBlockPlaced().getX() - 11 || x == e.getBlockPlaced().getZ() - 11 || x == e.getBlockPlaced().getX() + 11 || x == e.getBlockPlaced().getZ() + 11) {
e.getBlock().getWorld().getBlockAt(x, e.getBlock().getY() - 1, z).setType(Material.RED_WOOL);
}
}
}```
i want to make a border of red wool but this only makes 2 lines
show a screenshot pls of how it currently looks, and how it should look
cant upload files..
orange = center block
red = blocks that are placed
green = where they should also be
you can get verified to send files
hm yeah your math is off then
usually, you wanna do it something like this:
erm
one sec, gotta start intellij
public static void createBorder(Location start, Location end) {
BoundingBox box = BoundingBox.of(start, end);
int minX = (int) box.getMinX();
int minY = (int) box.getMinY();
int minZ = (int) box.getMinZ();
int maxX = (int) box.getMaxX();
int maxY = (int) box.getMaxY();
int maxZ = (int) box.getMaxZ();
Material mat = Material.RED_WOOL;
for(int x = minX; x <= maxX; x++) {
start.getWorld().getBlockAt(x, minY, minZ).setType(mat);
}
for(int z = minZ; z <= maxZ; z++) {
start.getWorld().getBlockAt(maxX, minY, z).setType(mat);
}
}
might be totally wrong though haha
ill try it thanks for the help
but yeah basically you need two for loops, one for minX > x > maxX, and one for z
you don't even need the BoundingBox part but I guess it's easier to use it
new Location(e.getBlock().getWorld(), e.getBlockPlaced().getX() - 11, e.getBlock().getY() - 1, e.getBlockPlaced().getZ() - 11),
new Location(e.getBlock().getWorld(), e.getBlockPlaced().getX() + 11, e.getBlock().getY() - 1, e.getBlockPlaced().getZ() + 11)
);``` not sure if im doing something wrong but this is the result i get https://cdn.discordapp.com/attachments/829796363188830218/1047356560235560970/image.png
you gotta loop from startX to endX, from startY to endY, from startX to endY, and from startY to endX
and with Y, I actually meant Z, lol
tip: make a drawing on actual paper with the coordinates
then you'll see how the loop should work
sounds stupid, but it helps
what I sent earlier was probably wrong
you definitely need 4 for loops
BoundingBox box = BoundingBox.of(start, end);
int minX = (int) box.getMinX();
int minY = (int) box.getMinY();
int minZ = (int) box.getMinZ();
int maxX = (int) box.getMaxX();
int maxY = (int) box.getMaxY();
int maxZ = (int) box.getMaxZ();
Material mat = Material.RED_WOOL;
for(int x = start.getBlockX(); x <= end.getBlockX(); x++) {
start.getWorld().getBlockAt(x, minY, minZ).setType(mat);
}
for(int z = start.getBlockZ(); z <= end.getBlockZ(); z++) {
start.getWorld().getBlockAt(maxX, minY, z).setType(mat);
}
}``` yeah getting the same result
sth like this maybe
for(int x = minX; x <= maxX; x++) {
start.getWorld().getBlockAt(x, minY, minZ).setType(mat);
}
for(int z = minZ; z <= maxZ; z++) {
start.getWorld().getBlockAt(maxX, minY, z).setType(mat);
}
for(int x = minX; x <= maxX; x++) {
start.getWorld().getBlockAt(x, minY, maxZ).setType(mat);
}
for(int z = minZ; z <= maxZ; z++) {
start.getWorld().getBlockAt(minX, minY, z).setType(mat);
}
idk, you have to try it yourself. you definitely need 4 for loops
I really suggest you to make a drawing, it'll help you to understand what's wrong / missing
I am too drunk to make a drawing myself rn
I can help once I get off work if by then you haven't resolved problem lol
ok tysm for the help 😀 ill try some stuff and see if it works
I get home usually around 7am CST
real chads use GMT 😛
this works ty 😄 been trying to get this to work for 2 days
great!
Alright -6 GMT I think
you could condense that code into 2 for loops, but tbh, if it works now, I wouldnt touch it again haha
as long as its not more laggy its fine
Well like I said can help with that when at home lol
It won't cause lag, just takes small bit longer is all. However you won't really notice difference except under extreme loads
is there any "prematureoptimization" command?
?premature
?prematureoptimization
we should def have a command like that
sometimes people are like "WHY DO YOU USE A LIST INSTEAD OF A SET" and I always think "damn tbh you are right, but who cares"
Lol
anyway, I'm going to bed now lol. have a nice day everyone
Cya
I'm so confused
public static void calculatePlayerStats(Player player) {
PlayerStats playerStats = new PlayerStats();
PlayerInventory inventory = player.getInventory();
List<ItemStack> items = new ArrayList<>();
items.add(inventory.getItemInMainHand());
items.add(inventory.getItemInOffHand());
items.add(inventory.getBoots());
items.add(inventory.getLeggings());
items.add(inventory.getChestplate());
items.add(inventory.getHelmet());
player.sendMessage("new PlayerStats() = " + playerStats);
for (ItemStack item : items) {
if (item == null || !item.hasItemMeta()) continue;
Collection<CustomAttributeModifier> attributeModifiers = ItemUtil.getAttributes(item);
if (attributeModifiers.size() < 1) continue;
for (CustomAttributeModifier m : attributeModifiers){
playerStats.applyAttributeModifier(m);
}
}
player.sendMessage("Calculated playerStats = " + playerStats);
playerData.put(player.getUniqueId(), playerStats);
}
I don't understand why new PlayerStats(); would have any values
Here's PlayerStats
public class PlayerStats {
private static final Map<CustomAttribute, Double> stats = new HashMap<>();
public double getStat(CustomAttribute a) { return stats.get(a); }
public void setStat(CustomAttribute a, double v) { stats.put(a, v); }
public void applyAttributeModifier(CustomAttributeModifier m) {
double value = m.getValue();
CustomAttribute a = m.getAttribute();
double currentValue = stats.getOrDefault(a, 0D);
switch (m.getOperation()) {
case ADD_NUMBER:
stats.put(a, currentValue+value);
break;
case MULTIPLY:
stats.put(a, currentValue*value);
break;
case MULTIPLY_SCALAR_1:
stats.put(a, currentValue*(value+1));
break;
}
}
}
Ok looks like adding a constructor and in it setting stats to a new hashmap fixes the problem
public class PlayerStats {
private static Map<CustomAttribute, Double> stats;
public PlayerStats() {
stats = new HashMap<>();
}
}
is there a better way to do this?
I'd also appreciate it if somebody would explain to me why not doing this was causing weird problems
Um
Why is that static
I have a dumb question. If i store a byte[] in a sql db does it take up at most byteArray.length bytes of storage?
That definitely shouldn't be static reccomend learning when to use static instead of abusing it
Fixed thanks. I think that was an accident
though I have been using statics for stuff like my ItemUtil class, but I'm not sure how to get around that
For example I have this to check if a namespaced key is for one of my custom attributes
public class ItemUtil {
private static final String attributePrefix = "attribute.";
public static boolean isAttributeKey(NamespacedKey key) {
return key.getKey().startsWith(attributePrefix);
}
}
Is this static abuse? Could someone point me to some resources on the topic?
@fervent panther That’s fine
Don’t actually think there is a resource on static abuse. But if you could easily handle it with oop and use static instead cause ur lazy that is it.
^^
just config.yml
Now it looks like this ``` private File pluginConfigFile;
private static YamlConfiguration pluginConfig;
public static FileConfiguration getInstanceConfig(){
return pluginConfig;
}
public void loadInstanceConfig(){
pluginConfigFile = new File(getDataFolder(), "config.yml");
pluginConfig = new YamlConfiguration();
try {
pluginConfig.load(pluginConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}```
do i need to call loading config everytime in event? i want to just load in when executing reload command
you just answered yourself
idk if it was wrong or not, i thought its overloading like for example loading it everytime player joins
if it never changes you dont have to
if you expect it to change within, you would have to load it everytime to have the latest config applied
so how to handle it? unregister and register events?
but since you only want to reload on reload, you dont have to load it back every time
what?
private FileConfiguration config = bpLobby.getInstanceConfig();
@EventHandler
public void OnJoinEvent(PlayerJoinEvent event) {
config.getString(...)
...
}```
Eyo I think it shouldn't be capitalized
hold the instance somewhere centralized and update it on reload
Pure style problem
method?
OnJoinEvent
so like onJoinEvent
Ye but that's just style
okay i understand leave capitalized for classes
You need to register a listener?
In main class getServer().getPluginManager()
It'll be there iirc I'm on mobile tho
something like? i want to reload config inside events, idk how to do it
Oh
config.reload() in the library I'm using
In spigots idk
Why do you need to do it?
private bpLobby instance;
@Override
public void onEnable() {
instance = this;
}
public bpLobby getInstance() {
return instance;
}```
I just want to reload config, like /reload command to reload strings from yaml
this is wrong?
return pluginConfig;
}
public void loadInstanceConfig(){
pluginConfigFile = new File(getDataFolder(), "config.yml");
pluginConfig = new YamlConfiguration();
try {
pluginConfig.load(pluginConfigFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}``` And then ``` @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
instance.loadInstanceConfig();```
hmm okay

you dont need to get the config.yml yourself, your main class already keeps track of it for you https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/java/JavaPlugin.html#getConfig()
as well as you can quickly reload the config
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/java/JavaPlugin.html#reloadConfig()
i did this it did not work
so just make your instance and the getter static and refer to #getConfig
then you did it wrong
isnt the public static bpLobby getInstance() { return instance; } getter?
yes it is
and then how to use it properly in reload command and class with event?
either you use that singleton or inject your main via DI and call #reloadConfig inside your command class
same as for the event just that you then use #getConfig to get your stuff out of it
inside event or outside
in your eventhandler
but you dont want to read from the file everytime something happens so i would cache your config values somewhere, even tho i believe that #getConfig is a cached instance of the config file
okay, i was 1 step behind it lol
i made it outside the eventhandler
so it only loaded on register
no idea what you're talking about but that sounds wrong
public JoinEvent(bpLobby instance) {
Bukkit.getPluginManager().registerEvents(this, instance);
}
private FileConfiguration config = bpLobby.getInstanceConfig();
@EventHandler
public void onJoinEvent(PlayerJoinEvent event) {
String prefix = config.getString("prefix");
...
}
}
It loads on registerEvents only right
but if i move config to eventhandler it will load every time its called
no, rn your listener registers itself what it shouldnt do.
thats what i found on the internet lol 😂
this only loads the config when the listener object is instantiated
so dislike the post you read
give it a thumb down because thats garbage
bpLobby should btw. be uppercase
so i need to make some other class like RegisterEvents and in it do Bukkit.getPluginManager.registerEvents
yee ik its class
store the passed instance of your main class inside your listener and use it in the eventhandler to load the config. thats all. but as it seems you didnt wanted to load it in the eventhandler so screw the loading
no, just inside your main class
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
tysm for help
idk ;D
yeah well anyways, here you have everything regarding configs:
https://www.spigotmc.org/wiki/creating-a-config-file/
https://www.spigotmc.org/wiki/config-files/
how can I make ranks look like this?
thats not really helpful, but thank you anways
you maybe could give me an example of these type of "models" for ranks
specific unicode characters changed in a texture pack
so its not possible to have the "normal looking" ranks and these both?
what
your customname would look like something like this: \u01234 > GodCipher where \u01234 is changed to an icon in your TP or whatever you like
f.e.
One config file for each inventory.
5 configs in total
5 inventories in total
Are you trying to use SQLite?
there is no default database. usually every plugin has their own, inside the plugin folder
whut
Sounds like a pretty vague question
yeah
usually you just add some sqlite thingy to your pom.xml lol
and then you use that
for example this https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
tbh It sounds like you're a bit lost on what you're trying to do
So try to explain it better
and eat some schnitzel, it always helps
I think they are looking for some library perhaps to start working in sqlite
What's schnitzel
wtf
Sounds like schabowy wannabe
polish is funny
the original version is calf, but usually it's pork, yes
it can also be chicken
but then it's called chicken schnitzel
That's our national food 😠
no it's ours!
Ok let's verify that
Also we eat it with mashed potatoes
this is a proper schnitzel
with salami, cheese, ketchup, egg, bacon and röstzwiebeln
kingshit
Ketchup oh no
damn you must be from berlin or sth
i actually am lmao
haha
Ketchup on schabowy 😭
I prefer some mushroom sauce but to each their own lol
tbh in serbia we call this Viennese schnitzel 😂
yeah because it's from Vienna, austria haha
@tender shard L it's from Austria
ik
And it doesn't originally use pig
Which is what mfnalex said
@AllArgsConstructor
@Data
public class Element {
private Component displayName;
private List<Component> lore;
private Material material;
private @Nullable Enum<?> action;
private @Nullable Consumer<InventoryClickEvent> event;
private int slot, customModelData, amount;
}```
Associate a Consumer to an Element or an Element to an Action?
hmh
now im hungry, well done guys
did you do Class.forName("some.random.sqlite.driver") ?
map an action with a consumer
I'm trying to create a setup inventory, consumer will be generated later in the code
why would it
the action should stay the same
just applied on different slots
i usually just use the itemstack's PDC to define the actions lol
Inventory Builder from YAML config
and then just let the players download it at the first join?
Yeah but, it's a setup inventory
Actions should start a convo to change values
Example:
private Consumer<InventoryClickEvent> generateNameSetupConsumer() {
return consumer -> {
player.closeInventory();
Component[] messages = new Component[]{
Lang.CREATE_COMPANY__CONVO__SET_NAME__CHAT_MESSAGE,
Lang.CREATE_COMPANY__CONVO__SET_NAME__TITLE__TITLE,
Lang.CREATE_COMPANY__CONVO__SET_NAME__TITLE__SUBTITLE
};
Convo convo = new Convo(plugin, player, ConvoType.STRING, messages, Lang.CONVO_EXIT_WORD);
convo.setOnComplete(event -> {
String input = event.getMessage();
if (input.length() > 32) {
player.sendMessage(Lang.CREATE_COMPANY__CONVO__SET_NAME__FAIL.replaceText(TextReplacementConfig.builder()
.matchLiteral("%s")
.replacement(input)
.build()));
create();
return;
}
player.sendMessage(Lang.CREATE_COMPANY__CONVO__SET_NAME__SUCCESS.replaceText(TextReplacementConfig.builder()
.matchLiteral("%s")
.replacement(input)
.build()));
name = input;
create();
});
convo.setOnFail(event -> this.create());
convo.setOnExit(event -> this.create());
};
}
why do you create a new consumer everytime? just save it in a field
ew pork
What's better than pork then
name = input;
Well, a consumer changes values in the setup
After the convo is completed, a new inventory gets generated with new values to complete/continue the setup
any other meat
giraffe
Chicken for schabowy makes it literally just a big nugget
pork is super high in saturated fat
no, you have to declare the class name, not the dependency name
I meant chicken, fish
Yea well idc i wanna eat good
usually it's simply ```java
Class.forName("org.sqlite.JDBC");
Could you recommand any good library for Map GUI?
Is there anyway to get entities in radius around Location?
saturated fat means big boy diseases like cancer
you can either get all entities from that world and check their distance, or get them from the chunk manually
square radius or circle radius?
My dad lives for ~50 year's eating schabowy two times a week and he is fine (he is also a long time smoker)
circle radius can be okay
is that supposed to be a good thing or bad thing
public static Set<Entity> getEntitiesInRadius(Location center, double radius) {
Set<Entity> entities = new HashSet<>();
for (Entity entity : center.getWorld().getEntities()) {
if (entity.getLocation().distanceSquared(center) <= radius * radius) { // distanceSquared is faster than the normal distance() method
entities.add(entity);
}
}
return entities;
}
Fish only on Fridays
besides, if he lives a lot when eating pork and smoking, he can live a lot more not eating pork and not smoking
but is looping all entity in the world good for optimizing..?
there is no better alternative. and keep in mind that the server loops over all entities every tick anyway. it's usually not a problem
unless you care more about size than health (which i really don't recommend) you should try to minimize high saturated foods
ahha... do many other targeting system work like this way?
Mfnalex, sorry for the bump but...
Would you have any ideas for doing the setup inventory in a better way?
https://paste.md-5.net/sumesifava.java
please, I'm going crazy
not sure what you mean with "targeting system", but - if you are afraid of looping over all entities, you should better not look into minecraft's NMS code haha
it's a huge mess
nms... haha...