#help-development
1 messages · Page 1514 of 1
How to check what armor a player is wearing?? I want to do an action when the player equips a certain type of armor
If I create the inventory instance as a public variable within one class, the ClickListener class I have would have access to it, right?
yes, but you are better keeping it private and add a getter
smart, thank you so much!
I typed in player.getInventory(). and found this player.getInventory().getArmorContents()
there are a few libraries that implement armor change/equip events
asssuming you have a player variable ready to go
and paper has one built in
there are also specific methods for each individual armor slot, like getChestplate and so on
Would it be the InventoryHolder?
most likely yes
you'll want to check instanceof and cast the returned HumanEntity to Player if that's the route you're taking
however it's pretty strange for you to have a PlayerInventory but not a Player in the scope
If you are referring to the PlayerInventory class it sounds like you may be doing something wrong.
yeah, that question has worms somewhere
Are you trying to create a Player inventory and then trying to figure out how to attach it to a player?
his end goal afaik is to get the armor item worn by a player
yep
Im trying to check to see if a player is wearing certain armor and if true then give the player an effect
ok, is this in some event or just any code?
which?
PlayerInventory
that's not an event
Ah
all of the events have Event in the name
there is no armor equip event on spigot
you'll have to check every player's every armor slot every tick
or import and shade in a library that does that for you
Ok
There are three you need to watch, InventoryClick, Drag, Move.
for inventory actions, yes
There are others too, but start with those
but armor is more complex than that
and with the way how bukkit is, it won't be reliable even if you listened to every event there is
as other plugins can still modify the slots without emitting any events
https://hastebin.com/pekilifuyu.java
I created a public static variable in the Item.java class, and created a getter.
I then checked if the getClickedInventory() obejct was equal to the Items.getGui() getter, but it's not cancelling the event when I click an item in the inventory. Any help?
if you have a getter, the variable should be private
the point of the getter is that you don't need to expose the underlying state (the variable) directly
Right, changed. Thank you
Yeah sorry I'm just new to the experience of writing my own code 😅
assuming the code works and is set up correctly and whatnot, that would imply that the Items.getGui() inventory is not == as getClickedInventory()
that is, they are not the same inventory object
in my Items class the variable is now private static Inventory gui; which is initialized during the onCommand event. Inside the ClickListener class I made, I'm trying to compare whether a player clicked an item in said opened inventory. I tried if (e.getClickedInventory().equals(Items.getGui())){, but it doesn't cancel it. Not sure what I did wrong
print out the Items.getGui object and the e.getClickedInventory object to system.out and see what they are
okay will do
Oh it's because I never added clicklistener to the main method, pretty sure
Looks like both references are equal and it is in-fact canceling the event thanks for the help!
Does anyone happen to know what the class BuiltinRegistries is equal to for spigot
Ah thanks
Fuck internet lol
BuiltinRegistries is the fabric name, forge uses WorldGenRegistries
Looking for whatever name I need to use on spigot
I don't know why I can't seem to find this one
if you know the mojang name you can check the mojang->spigot translation on mini's mappings viewer
Is there a method to check whether or not the player has at least 1 empty slot in their inventory? Or rather, the total filled slots in their inventory?
player.getInventory().getSize() wasn't correct
compare size to getContents() ?
player.getInventory().getContents().length?
however the empty slot may be an armor slot (not sure)
Ah, maybe I should write my on method?
try getStorageContents() instead. It should exclude armor
you will have to check the returned array for null as those will be empty slots.
Ooo, I'll give it a shot
ItemStack[] items = player.getInventory().getStorageContents();
for (ItemStack theItem : items){
player.sendMessage(theItem.toString());
}```
that sent all the items in the inventory
it shoudl be excluding armor slots?
Correct, I can just write a method public int itemsInInventory(Inventory inventory) if it returns the result I want, that'll do the trick
I made sure to check for armor slots too, doesn't display them
cool, just be sure to check for any slots that contain null.
empty slots shoudl contain null or AIR
for (ItemStack theItem : items){
player.sendMessage(theItem.toString());
}```this only displays items that exist in the inventory
It doesn't seem to be displaaying an empty slot
yes, its just not sending a message for null. It should actually be throwing an error
oh cool! thanaks
public boolean hasFreeSlot(Player player){
ItemStack[] items = player.getInventory().getStorageContents();
for (ItemStack theItem : items){
if (theItem.equals(null)){
return true;
}
}
return false;
}```seems to give an error in console, https://hastebin.com/unizenedan.apache
Blah, everything is working with hooking into the Mojang structure system, other than the structures actually placing blocks
I assume it's because I am missing those registry entries, but I'm not sure
Going to head off for tonight, but seriously thanks for the help today.
if (theItem == null)
MiniMappingsView doesn't seem to have anything for WorldGenRegistries
anyone knows why this does not work?
if (hasFreeSlot(player)){
player.sendMessage("You've receive an item!");
player.getInventory().addItem(item);
}else{
player.sendMessage("Inventory full!");```worked perfectly, thaanks. night ❤️
If anyone does happen to know, @ me
if (!player.getInventory().addItem(item).isEmpty()) player.sendMessage("Inventory full")
idr if it was addItem, but one of the methods that adds item(s) to an inventory returns a Map of the items that didn't fit
yep it is
more efficient and usually more accurate to check that after attempting to insert the given items
Hey! I’m new to coding plugins. Anyone know a good place to start?
new to java or new to plugins?
Has anyone had issues with SQLite taking forever to close the connection?
I've had some issues where it takes as much as 5-10 minutes to close the connection
Stack trace says it's doing a commit
Which makes sense, but it shouldn't be taking that long
Even without the io sync it doesn't make a difference
Validate#notNull checks if the first object is null, if it is null it will output an error with the message in the second parameter.
I've turned off auto-commit but I also commit every 5 minutes automatically and none of those take an unreasonable amount of time
I'm really baffled as to why SQLite is acting this way
I'm going to assume you are not using some connection pool thats keeping it active
then I can;t help I'm afraid
My first google gave this. It is a year old though https://stackoverflow.com/questions/8511901/system-data-sqlite-close-not-releasing-database-file
That's not it
The close() call is freezing the server up
It doesn't have to do with gc, otherwise it wouldn't appear in the stack trace
further down that thread they talk about objects not being released
its still applicable, probably.
If that's the problem then it's freezing within the call
Here they're talking about cleanup after calling close
Not saying it is related to yoru issue, but its somethign to consider if you are holding objects
Ideally, applications should finalize all prepared statements, close all BLOB handles, and finish all sqlite3_backup objects associated with the sqlite3 object prior to attempting to close the object. If the database connection is associated with unfinalized prepared statements, BLOB handlers, and/or unfinished sqlite3_backup objects then sqlite3_close() will leave the database connection open and return SQLITE_BUSY. If sqlite3_close_v2() is called with unfinalized prepared statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups, it returns SQLITE_OK regardless, but instead of deallocating the database connection immediately, it marks the database connection as an unusable "zombie" and makes arrangements to automatically deallocate the database connection after all prepared statements are finalized, all BLOB handles are closed, and all backups have finished. The sqlite3_close_v2() interface is intended for use with host languages that are garbage collected, and where the order in which destructors are called is arbitrary.
This seems like it might be related
It's possible there are prepared statements or other objects I'm not closing
In that thread they mentioned a call to essentially clear/close all of the related objects
I wonder if something similar exists for java
is there a way to check if an argument is a player?
@EventHandler
public static void onHackerManClick(PlayerInteractEvent event) {
Player player = event.getPlayer();
Action action = event.getAction();
if (player.getInventory().getItemInMainHand().isSimilar(CustomItems.hackerMan)) {
if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
CustomItems.hackerMan.getItemMeta().addEnchant(Enchantment.LUCK, 1, true);
CustomItems.hackerMan.addEnchantment(Enchantment.LUCK, 1);
Location location = player.getLocation().subtract(0,1,0);
}
}
}
}```
I have a custom item that i want to add the shiny effect (Enchantment.Luck) outside of the class where it was initialized. Is there a way to do this.
CustomItems.hackerMan.addEnchantment(Enchantment.LUCK, 1);``` These were two ways i tried, but did not work
The custom item is a Totem of undying
check if it's an instanceof Player
are you sure it's being called ?
yes
you have a static variable there. its not the item in the hand of the player.
lmao didnt even notice that
its not supposed to be a static method..?
no
this is a bad practice you did there
you're supposed to reference the player's item in hand
ur modifying a static variable that you created not a player's item
Hello! I'm trying to kill armorstand in every world. However, if the player is not in the same world or near it, the armorstand will not disappear. Here's my code.
for (World world : Bukkit.getWorlds()) {
for (Entity entity : world.getEntities()) {
if (!entity.getMetadata("hologram").isEmpty() && entity.getMetadata("hologram").get(0).asString().equals(name)) {
Bukkit.broadcastMessage(entity.getLocation().toString());
entity.remove();
}
}
}
}```
I should do static cuz my constructor registers event
world#getEntities just returns the loaded entities
ahh!
ok i'll search google with "how to kill unloaded entites"
hmm
how to kill unloaded entites?
you could cache the entities which are being unloaded in the ChunkUnloadEvent and remove them too if they are the entity you want to remove
ahh thanks you
or if you don't want to remove them in an interval, you can just remove them directly
is there a way to turn a string into a player?
Do you mean a command argument?
Yes
Bukkit.getPlayer(String)
omg tyvm
And if that returns null
You can tell it's not a player
At least, not an online one
Does anyone know a way to set an ItemStack's name property as a BaseComponent?
I mean the name is stored as a string
Not in Vanilla
In Vanilla Minecraft, you can use commands to generate items with component names
Data like this: {"text":"Ornate Diamond Sword","font":"blah","color":"#BBFF45","italic":false}
yeah
in SpigotAPI you would use strings tho
or create a component and turn it into a string
but at the end its just a string
That'll work?
Idk haven't done that but 99% sure it should work
So create the component, store it as a string, then set it as the display name?
Sick, I'll try that
yeah basically
altho if u rly want to use components I believe PaperAPI offers it
or like yeah just PaperMC
If that doesn't work I'll probably go with that yeah
But if this works it really isn't much of a hassle
Yeah
ok so i've started with some simple javascript stuff for modding, but does anyone know how i build a .jar file for a mod? and are there any nice libraries i can import do my project?
im trying to use vscode as my IDE... intelij and eclipse are rather confusnig xD
gotcha
i just need some guidance to some good api and documentation so i can compile a simple .jar file... any "hello world" examples?
tbh
i'd watch a tutorial video
just like 2-3 eps
to get the basics
package index
this is the api
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
maybe this too^
Do i need to watch tutorials in order to learn spigot fully or can i rely on the stuff ive learned studying java for the past 4 months?
sweet thanks, i need help mostly with syntax and a few language specific things. I've done some practicing with c++
will def check out some youtube vids to get me started
uh, I mean that's really up to you, and how confident you are.
hey
quick thing
youtube is a terrible way to learn spigot
wiki guide has lots of good resources
youll be fine if you know the basics of java/oop
That's not true youtube can be a good way to learn spigot
There is different ways people learn
YouTube taught me horrible practices that took me a while to unlearn lol
naw
watching someone code, pausing every 3 seconds to see what they wrote
Most spigot/bukkit tutorials dont explain what is happening either
maybe for the absolute basics
but it's not a good way to learn, just a good way to do
it depends on the person tbh, i usually like using documentation
and following examples
That's correct craftinc
youtube is eh just stay close to wikis and tutorialpoints docs
It does depend on the person
is there a way to download the spigot api file instead of using a dependency in maven or gradle? internet issues :/
buildtools
knowing the very fundamental basics of Java as well as OOP will be enough to get you started with Spigot API without problems. As a matter of fact if you are already knowledgeable in Java you are probably already better than the average Spigot developer. Anyways in my experience YouTube tutorials are a hard field as some of them are good while others are less good leaving big confusion in which one to pick. The best way to find how to do something is to use the Javadocs but the Spigot Wiki page has some decent tutorials and both Bukkit and Spigot forums can offer great help in how you would tackle stuff but keep in mind both wikis and threads can be outdated. sry for the bible lol
if you are already knowledgeable in Java you are probably already better than the average Spigot developer
haha true
lmfao
Thank you for the reply! I will take this into account
does it do the api file as well?
This my first time working with an API so its a bit overwhelming
I was an unfortunate soul who learned Java through Spigot at the beginning. Fortunately I had people to bully me into actually learning the language instead of monkeying my way through it
it gives you a .jar file yes
isn't an api jsut a new library to learn? u import it and u use the functions as if it was a standard java library
I literally made my first plugin by doing copy-paste-tweak until it worked lol.
U guys know a discord just for Plugins of Spigot?
here
yeah craftinc that is correct
im in that state rn, help
how does the shape method work for shapedRecipes
i think it's left to right
cant recall
Trying to find a animated scoreboard plugin working for 1.17 but Spigot search bar sucks 😦
i just type roughly what im trying to do and have the ide autofill do the work
See i would do that
but i want to learn every single little things and thats what catches me
shape(java.lang.String... shape)
So like for example shapedRecipe.shape("xxx","xxx","yxy");
i believe i will waste alot of my time trying to learn everything on my own
i got plenty of time just want to be efficient
so heres the question for me, if im using vscode where do i need to put the api files
anyone familiar with vscode?
nope dont use a text editor lol
oh btw, doesnt work. as I said internet issues. I need to download directly from the source
I would use Eclipse or IntelliJ
I agree
okay, i have it, just felt more used to vscode
i mean you can get it from
Insane plugin dudee! Thx for helping me! But 17.99 EUR feels bad man 😭
ok thanks
Okay the shape method is pretty simple lol
you just specify a letter at the index basically
"T "
ye so like "xxx","xxx","yyy"
this represents the ingredient on the top left corner
dopppeeeeee
this is so fucking cool
yea
what are you actually trying to do? you get spigot either by using the maven-dependency, or decompiling it with BuildTools if you need nms and stuff
yes, the API is kept in the spigot repo
i just want the api so i can set it up in a directory and reference it when using my IDE
nvm i was on the whole wrong way lol
thx
im having a problem where it doesn't look at my for loop anyone see a reason for it ?>???
https://paste.helpch.at/elahexevih.java
probably your hashmap is empty? :o
How can I prevent passengers from being ejected if the vehicle is in water or teleporting?
there's the VehicleExitEvent, which you could cancel if the entity/player is in water.
not sure about teleports tho, and if that's possible. you could probably teleport both the player and the entity to the location, and set him back onto the entity manually
That event isn't even being called for some reason.
The vehicle is a player.
so... a player riding a player? :o
armor stand riding player
i want to prevent the armor stand to get ejected
yea i know
Google showed me this
https://hub.spigotmc.org/javadocs/spigot/org/spigotmc/event/entity/EntityDismountEvent.html
declaration: package: org.spigotmc.event.entity, class: EntityDismountEvent
Don't think Player extends Vehicle
yea thats it
alright imma try that
well, try it out i guess. player extends Entity/Livingentity tho
last time i used that event, we can't really cancel the event.
we need to mount the entity back
What happens when you attempt to cancel it?
yea, thats what i said.
but that would be weird in water tho
and laggy probably
it's just visual bug
oh it works now
still weird when player is swimming lmao
Wow, I'm surprised it looks as good as it does
is that a backpack plugin or smthn
yeah, for cosmetics
u prolly jus have to rotate the armor stands body
by like
90 degrees? i think
so pi/2 since i think eular is in radians
Yeah on EntityToggleSwimEvent right?
if thats a thing then probably
pitch could be based on sight and not body angle
what method should i use?
i did a quick search online and it seems like body direction is client side
i dont think there's one. the body yaw/pitch is based on client-mode
for the head rotation i use nms
then it would be visual only to you, unless you try and send these to every player in vacanity
i'm gonna test with the second player
this is not nms
just craftbukkit's api
That'll be a fun one to fix lol
what condition are cancelling the dismount event?
Yeah that's what you're going to have to do for sure
Can I see the class that controls the dismount event, if it isn't too much trouble?
I think by cancelling the dismount event he also cancelled the tp event
Yeah
Does it still call a teleport event?
You could check if teleporting players are wearing a backpack, remove it, go through with the teleportation, then remount it
in the PlayerTeleportEvent right?
I've never touched the teleportation events but that sounds about right yeah lol
Make a lil debug class and see if it spits
oh god, it's harder than i thought
wish there is something like DismountCause
the PlayerTeleportEvent isn't being called
Yikes
I’d offer to help you work through that but I’m not at my PC right now. Good luck
Lmk if you get it working, I’d like to hear how you did it
alright, thanks!
Sick backpack design i must say
thanks, now i'm stuck
so excited, ima try to develop a mod for water that allows it to be pushed. i was trying to make a wave pool 👀
Anyone know why cancelling EntityDismountEvent cancel teleportation too? and the PlayerTeleportEvent isn't being called.
Teleporting with entities stacked is always a challenge
When is the dismount event being called?
Like, what circumstances cause the armor stand to dismount from the player?
Teleporting.
Just teleporting?
Because when the "vehicle" or player teleports, the entity got dismounted.
Then why cancel the event at all?
Perhaps only cancel it when the player is swimming and remount the entity after teleportation?
Is there like a player.isSwimming() method or something?
Hey guys, I'm having some troubles adding some values to my string list in my config.yml. I have a list of cosmetics to add to a players profile, but whenever I add something, it replaces what's already there.
Ah, I could try that yes.
I've looked it up on the spigot forums and I've tried everything, but none work
Can I see your code?
You need to get the list, add value to the list and then set them back.
^
I did this, and it still didn't work
Code pls
I also tried making a new arraylist and copying everything over by looping through the values in getStringList, adding them to the new arraylist, and setting that--still didn't work
it replaces it every time
wait
Print the contents of both the unmodified list and after it’s modified
lol
It’s always the little things
@hexed hatch okay so, right now I can teleport with backpack, but I can't do it in the water, there's no way to do that I think. https://paste.md-5.net/opamehocal.cs
Let me think
when half of the player's body is in water
Is it when the player goes in to the swimming animation or is it when they go a certain amount of blocks underwater
the entity got dismounted
yeah very helpful
Is the isInWater method working properly?
yes
there could be any others cause other than passengers dismounted because in water and teleportation
I’m trying to think of a hacky solution for this
very true, it's always "i forgot the semicolon" or something at the end of the day lol
so glad it finally works now 👀
are there something like Player#isHalfBodyIsInWater lol
I can’t see why this wouldn’t work if it worked before. Are you sure Player#isInWater works?
yeah it works perfectly
anyone know why persistentdatacontainer for an item might not be persistent?
No but you can ✨ make it ✨
isHalfInWater(player) moment
Here's the issue.
When you stand right there, it's count as the player is in water
Ah
and you can't teleport, because the entity tries to dismount
Maybe just make a boolean method that gets the block at the player’s head and if it’s water, they’re underwater
when you teleport
Ah
that could work
Though I’m not too sure how efficient that method is, especially if it spams it whenever the user is underwater
that's the only way ig
I’m struggling to think of alternative solutions lol
it may affect the performance too
Yeah that’s what I meant
Perhaps you can just package this nifty little issue as a ✨feature✨
Exactly
okay it is working right now
Bonus feature: water disables your ✨teleportation aura✨ or some bullshit
anyone familiar with vscode here at all?
For.. Java development?
I looove the new rest api of spigot <3
how would i detect whether a player fills a glass bottle with water?
PlayerInteractEvent has lots of tools for that
use getclickedblock() and hasitem()
getClickedBlock returns null if you right click water
well then i guess just get the item in their hand to see if is a bottled water
What if they have like multiple glass bottles. If I check their hand, it’ll still be a glass bottle.
if you click water with a bottle full of water, it empties. So it is safe to assume that a person holding a bottle of water that just clicked a water block, got the water from the block.
@tired ferry don't bottles stack?
think their problem is when there is a stack of bottles
hmm good point. Because if you click with a stack of empty bottles, then it will just dump the full bottle in your inventory or on the floor.
interesting we have bukkitfillevent
but no event for bottles unless it relates to the cauldron
odd
are you sure the block returns null? maybe getclickedblock().isliquid()
can i cast an offlineplayer to player without it saying there was an internal error
nope
no workaround?
what are you trying to do?
change scoreboard data of all players who joined
mayb
you can cast offlinePlayer to player only if said player is online
It may be better to just use Bukkit.getPlayerExact("name"); instead
or just use the method in OfflinePlayer to see if they are online first before making the cast 😉
I believe Bukkit.getOfflinePlayer is more resource intensive
it queries the mojang api on the main thread, if you get a player by their name.
Ah right, well I didn't suggest getting a player by their name 😛
Just as a habit, I stay away from that method ¯_(ツ)_/¯
oh wait does .getplayer() work only if they are online
Yes, because its only when the player is online is there a Player object for them
otherwise you have to do .getOfflinePlayer();
there is a method from OfflinePlayer to check if they are online
for what
a server?
if you want to use the latest spigot for your server you have to compile buildtools yourself
oh i think im confusing myself, i want to use the api to call org.bukkit libraries. is that all containted in the spigot.jar file?
bukkit-1.11.2-R0.1-20170514.012224-124.jar Sun May 14 01:22:24 UTC 2017 930834
this one @formal dome if you are using maven, maven will pick the appropriate version automatically
OH BRUH
My man got the red string of death
There is PersistenseDataContainer for blocks?
i wont use metadata
because it resets with /reload/restart
If the library is separated in a lot of files, just add to your project the classes you need
Is the library open-source ?
add in pom.xml
Then just go on the git repository and download the files you need
and paste them in your project
Which library it is ?
why no work what should i do to get player name
Hi im having an issue with my GUI and I cant seem to find a solution to it. Is there an inventory event that i can cancel when the player moves an item to the inventory from their hotbar by pressing 1
uhh
gib me a munite
10s google search
declaration: package: org.bukkit.event.inventory, class: InventoryMoveItemEvent
disable_inventory_movement: true
can i get awnsered
?
scroll up
Oh this
this
I have no idea sorry
ok
Is this a yml file ?
yes
ok thanks
How are you using it to make the thing appear in the inventory ?
This doesn't answer to my question
deluxehub menus
ok
why would you do that???
That's dumb.
and piracy
@tame coral, somehow the event isnt being triggered?
Another possible issue that I can't seem to solve for some time now is, if the player has an item in their slot (0 for example, first slot) and they were to move their mouse on the inventory above and click the number 1 on their keyboard to move the item, no event would be fired (not sure if I remember correctly, perhaps InventoryClickEvent is fired but no information is given or no valid information so as to what click it was and what items were moved etc). So I solved this issue by checking the event#getInventory() and then canceling the event.
this is the event im trying to capture
i want to make a community for cracked players so they dont be sad for being in bad servers like herobrine
you forgot = true
%100
Cracked mode = Piracy
Piracy = Illegal
cracked = free trial
Still is illegal

And hypixel can sue you for this i guess
no it isn't free trial
im sorry could you elaborate a bit?
for people who have potato pcs and who donthave money for premuim minecraft
do you mean set cancelled true?
no
So the event you're using is InventoryMoveItemEvent ? @lone sandal
no, cancel event where players move item from their inv to the chest inv
(just making sure)
yes, logging debug msg when event is triggered
but still no
yeah i see
when balalla = false when ballala = true
@EventHandler
public void move(InventoryMoveItemEvent event) {
System.out.println("asdf");
InventoryHolder holder = event.getDestination().getHolder();
if (holder instanceof HelpGUI || holder instanceof LotteryGUI || holder instanceof ConfirmGUI) {
event.setCancelled(true);
}
}
@EventHandler
public void test(InventoryCloseEvent event) {
System.out.println("close");
}
}```
inventory close is triggering properly (was used as test)
im out
I see
Wait
Are you in creative mode ?
The fired event might be InventoryCreativeEvent in this case
yes, ill try in survival
nope still not triggering
Hmmm
Try with a more global event such as InventoryInteractEvent
Or even InventoryEvent and you print the event type in the console
anyone help-server is inactive
Dude just be patient
Ok to my surprise both InventoryInteract or InventoryEvent are not triggered at all
This would be the InventoryClickEvent and InventoryDragEvent. Are these the events you tried?
info on what im trying to achieve
inventory click doesnt work properly, only triggers player inventory
havent tried inventory drag
found this thread : https://www.spigotmc.org/threads/inventory-events-not-firing.412300/
InventoryClickEvent does work just fine
Yeah it should work
declaration: package: org.bukkit.event.inventory, class: InventoryClickEvent
InventoryAction
getAction()
Gets the InventoryAction that triggered this event.
The inventory click event works just fine with number presses not sure what you're talking about
declaration: package: org.bukkit.event.inventory, enum: InventoryAction
Can you elaborate on how you check if its the correct inv?
currently im getting the invview, check topinventory if it has a custom holder
What do you mean by correct inventory ?
i only want the event to be cancelled if the player is opening a gui from the plugin
Hmmm
From your plugin ?
Like did you do the GUI yourself or are you using a plug-in such as deluxehub ?
my plugin
Just getView and then getTopInventory should work just fine
does loadbefore still work in plugin.yml?
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/inventory/InventoryOpenEvent.html should work i guess
declaration: package: org.bukkit.event.inventory, class: InventoryOpenEvent
Yes
thx
then do like this i guess
I can't use ProtocolLib's javadoc
yeah it's buggy
the javascript doesn't work properly
You generally don't need their Javadoc
despite other javadocs' working
What are you trying to do
Im trying to Modify Players' data before it get to the player
Yeah it's always been like that
It's just to learn how to work with ProtocolLib
I see
since I will need it in the future
Can you be more precise please ?
If you're unsure how to edit packets or what data is on them these exist: https://github.com/dmulloy2/PacketWrapper
like a clear example on what you want to do
Currently what Im trying to do is:
Make every player's name random
For each player ?
Do you want every player to have the same name or nah ?
I dont think minecraft likes players with the same name?
It can
but if it can, I would prefer that
Yeah you can
There are rare cases of multiple vanilla accounts with the same name
protocolManager = ProtocolLibrary.getProtocolManager();
protocolManager.addPacketListener(new PacketAdapter(this,
ListenerPriority.NORMAL,
PacketType.Play.Server.PLAYER_INFO) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) {
PacketContainer packet = event.getPacket();
}
}
});
here's what I have so far
The if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO) is useless
rip
have to drag and drop it
Anyway once you get that open copy WrapperPlayServerPlayerInfo in to your plugin
wat
Any now you can use that to easily modify data
Gradle
Do you have the Gradle shade plugin
If it's not there by default, no
This file in particular
It contains a few other files that needs to be added hence why I'm helping with shading instead.
do i like add it in the same way I add ProtocolLib and Spigot?
But still, wouldn't maven add every wrapper ?
what is local opened = true in javascript the first one is lua
Yes
whats its maven link
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.dmulloy2:PacketWrapper:master-SNAPSHOT'
}
Here's the shade plugin alternative for Gradle https://github.com/johnrengelman/shadow
for if I like want to include it in my plugin?
Yes
So after this you can just do
WrapperPlayServerPlayerInfo wrapper = WrapperPlayServerPlayerInfo(event.getPacket());
List<PlayerInfoData> data = wrapper.getData();
// do thing with data here
wrapper.setData(data);
event.setPacket(wrapper);
wait so do I just drop the plugin line in?
Yeah sorry
thanks
so if im understanding correctly
I replace compileOnly or whatever with shadow
Yes
do I need to run shadowJar then
You also want to use the relocation guide and minimize guide
Since you don't need a bunch of useless classes
7
7.0.1?
7.1.0?
Just 7.1 if you look at their release page ;/
lmao the file name is 7.1
Yeah
Could not find com.github.dmulloy2:PacketWrapper:master-SNAPSHOT.
why is snapshot included in the first place
shouldn't it juse be :master?
well at least it works now
now how does one modify packets
Alright now open your packet listener
Just copy this
k
(and do what you cant to do with the data)
did you forget new?
Yeah
WrapperPlayServerPlayerInfo wrapper = new WrapperPlayServerPlayerInfo(event.getPacket());
Yes it's supposed to be new there
also do I like cast it in the end?
cause setpacket expects a PacketContainer
and you gave it that long thing
I did indeed, sorry
Required type:
PacketContainer
Provided:
WrapperPlayServerPlayerInfo
(Mostly coded in python recently)
the auto thing suggests me to use PacketContainer.fromPacket
No
so what do
but we dont have a variable named player?
wait a sec please
ok
Call getHandle on wrapper
To get PacketContainer
yeah
sendPacket just send a new packet, my bad
so event.setPacket(wrapper.getHandle())
?
The task is shadowJar
oh ok
hmm
Entry plugin.yml is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.1/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.
looks like some more fucky wacky
ok thx
so what do I do here, I get the premise of it but what do I actually do
and where in build.gradle do I put shadowJar or does it not matter
It needs to be in the shadowJar
You want to move PacketWrapper somewhere else and then minimize that
This will stop conflicts with other plugins shading it and it will lower file size
so from what I am understanding
the plugin.yml inside PacketWrapper is conflicting with mine?
Yeah
ok so this is my build.gradle rn
I need to move the shadow ' ' thing away
and minimize it?
?paste
So what you want to do first is create a shadowJar section
like does the order matter
No
So inside that add use exlude to remove file that you don't want
Like the plugin.yml
exclude 'plugin.yml'
I really hope this doesn't remove your plugin.yml too
so now whenever a jar is shadowed, no plugin.yml is included
is what Im getting from this
and what about the minimize thing
do I just throw that in
Anyway use exlude to remove the other plugin.yml not your own
shadowJar {
exclude('plugin.yml')
minimize()
}
Yes
If you have any API or unsed classes inside of you own plugin that you need to keep
same error
What error?
Entry plugin.yml is a duplicate but no duplicate handling strategy has been set. Please refer to https://docs.gradle.org/7.1/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy for details.
Yeah wait until we add the relocation
oh ok
relocate 'com.comphenix.packetwrapper', '<Your cool package>.packetwrapper'
Add that
And replace it with your package
Well just copy your package shouldn't be hard
Don't forget .packetwrapper
shadowJar {
relocate('com.comphenix.packetwrapper', 'hk.eric.hidename')
exclude('plugin.yml')
minimize()
}
oh right
Yeah that looks good but we might have to do something about that exclude
Do you have a github page with the project that I can test with because this is the first time I'm doing this too
;/
You're having trouble with adding dependencies in gradle ?
Shading, it contains another plugin.yml. and I'm not sure how to exclude it in gradle
Could you just send the project so I can test it real quick? Feel free to do so in DMs
?
how does one zip something on linux XD
wait nvm got it
dmed
wait a minute
discord finally fixed it
poggers
Cool
I see
I was just asking to see if i could help in any way 😅
I was responding to Olivo asking if I had a github repo
Oh ok my bad
I've got a pretty basic question, for some reason my package dev.stan.mc in my main class shows up underlined and the fix is to configure the build path, does anyone know what specifically should I configure to fix this? Some imports aren't working as well which is happening to me for the first time
Code-centric IDE, focused on your productivity. Full Java EE support, deep code understanding, best debugger, refactorings, everything right out of the box...
?
You should rather use Intellij than eclipse
^
it has plug-ins for minecraft plugin devs
It will be way better
It'll configure you the project without errors
I've been using eclipse since the beginning, I might switch, though for now I really need to fix this eclipse problem :/
Almost no-one uses eclipse, so almost no-one knows
have you tried cleaning your project?
or invalidating your caches
but yeah if you're using java for plugin development, especially if maven/gradle is making an appearance, you should use IntelliJ
maybe try naming your package: com.whateveryouwant.yourprojectname
I never heard anything about maven or gradle, i installed intellij and Minecraft dev plugin, and here i am coding a plug-in
i just click the build button and it works perfectly
yeah, Maven and gradle are just confusing to me
netbeans integrates with maven just nicely 🙂
i prefer just using a regular java project
It prob does, I just haven't used it before and if he still needs help, that'll take me out
maven and gradle are just build managers that stop you manually installing dependent jars into the plugin, if you go to big servers etc they'll probably force one of them, its a good skill to learn @quaint mantle @tame coral
I have an issue that I cant fix no matter what
?
I see
it includes onPlayerJoinEvent and .setGameMode
it can be really confusing to new people though
why whats up
Yeah i have time to learn anyway
You need to be more precise
like
- what do you want to do
- what have you tired
@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (started == true) {
event.getPlayer().setGameMode(GameMode.SPECTATOR);
}
else if (started == false) {
}
he's one if the 'ask to ask' coders, he'll get there lol
dont do started == true/false
you don't need a elif
the problem is that when a player joins, there not set to spectator
started == false will always be false if started == true is true
@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (started) {
event.getPlayer().setGameMode(GameMode.SPECTATOR);
}
else {
}
even if started == true
if (started) {
} else [
}
can you print the value of started to see if its actually started
or the event is actually running
cause it may not have registered
Did you register the event ?
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
ok
Bukkit.getPluginManager(listener, plugin)
no it isnt
Bukkit.getPluginManager().registerEvents(listener, plugin)
listen i haven't slept yet please
yeah, UI stuff is too tedious and addictive
It seems like teleportation got cancelled if the EntityDismountEvent got cancelled, how can I make the player got teleported even tho there's a passenger.
I'm in college until 17:00 so that's gonna be a difficult task
you can't teleport entities with passengers
private Map<String, String> sendAllTranslations(Map<String, Set<UUID>> languageCodes, String message) {
Map<String, String> messagesPerLocale = new HashMap<>();
for (String language : languageCodes.keySet()) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
String translation = this.getTranslationForText(message, language);
messagesPerLocale.put(language, translation);
});
}
return messagesPerLocale;
}
I have a method that looks a little bit like this. how can i wait until all the async tasks are completed before returning the map?
(Im probs being stupid 🙃 )
eject the passengers, teleport the passengers too and remount them?
i've tried that, but it will not work if the player is in water.
because passenger will keep trying to dismount on water
iirc you need to wait 1 tick in between teleporting and remounting
and i cancel the event
or otherwise the client gets pissed
Look up CompletableFuture in java concurrency
Yeah but that is gonna get a bit messy afaik
Its the best way afaik :( Future#get forces the thread to lock until the other bit is done
don't use the bukkit scheduler for that
asynchronous tasks too are only started at the beginning of a tick
Aww but it was such an easy solution that mostly worked 😦
if the player is in water, the EntityDismountEvent fired quite a lot and I don't want the passengers to got ejected.
which means that your execution could be delayed by up to 50ms
which is undesirable
use CompletableFuture.supplyAsync or something
i mean - before i used async the whole thing was 12 seconds so 50ms wasn't an issue
ill have a look at java async
It really depends on if you're happy to wait the possible 50ms
there is no need to wait the possible 50ms
there is no advantage to using the bukkit scheduler
and if you're waiting for the futures in like the async chat event, that will deadlock the server when a plugin compels a player to chat
as the next tick will not be reached until the future is complete
and the future will not be complete until the scheduler fires the task
and the scheduler won't fire the task until the next tick starts
as when a plugin compels a player to chat, the async chat event is actually fired on the main thread
which means your .get is going to block the main thread, and consequently halt the scheduler
oh woops didn't spot the event, @opal juniper ignore me
idk if he's using the event but based on what he's doing, he probably is
prob, either that or its a plugin response message translator
ah, ignore me then
yeah, you don't want to block that while waiting for the bukkit scheduler
I'm trying to teleport player, but I can't because the EntityDismountEvent is being cancelled.
make the entity dismount event not get cancelled
Do I have to keep track of all the potentially 24 completable futures?
If the passengers enter the water, they will got dismounted and I don't want that.
then make it only get not cancelled when you're teleporting
So I cancel the event, and because of that I cannot teleport the player that is in water.
dont use futures @opal juniper ignore what I said
How can I check that?
futures should be fine
right so I'm going to shut up
I wish there is dismount cause.
you can apply futures from the scheduler?
well i mean he basically was
ah
not like directly, but scheduling an async task that explicitly completes a future
oh I see
How can I check if the entity dismount because the vehicle teleported?
check which event fires first
The PlayerTeleportEvent doesn't even got called.
do you need to support other, unknown teleport causes
or only teleports fired from your plugin
The teleport event doesn't got called at all.
you'd have to like grab the stack trace and figure out whether it's caused by teleporting by looking at the stack
on newer java versions you'd want to use like a stack walker or something as getting the entire stack trace is kind of expensive
oh god
alternatively you could use a custom entity type and implement it so that it doesn't try to dismount in water
i don't remember whether the dismount logic is in the passenger or the vehicle, so I'm not sure if that's doable
you could, uh, not cancel the dismount event, then drop the packets that are sent when the entity is dismounted, and remount it later
i've been stuck for 6 hours trying to solved this problem
or, if the player got teleported, not remount it, and send those packets
alternatively alternatively, just spoof the whole entity via protocol and don't have it exist on the server to begin with
that way it won't try to dismount
you might need to manually unmount and remount it in the teleport event though as iirc the client gets pissed if you try to teleport it while mounted
i've done that
but i can't do that if the player/vehicle is in water
sure you can
on teleport, i dismount and then remount the entity