#help-development
1 messages Β· Page 1892 of 1
Yea but there might be a list of those items
i guess you have to itertate Material.values()
Make it so the file is on the same directory as the icecube.iml and .gitattributes
Yea but that gives almost every item
Material#isBlock should
has anyone ever run into and fixed this issue before?
but still some blocks will bypass that (like TNT which is in the redstone tab)
hm , thanks u all for help , someone calling me now, gtg
You might want to filter it yourself.
you could make an enumset with the values
How much is it allowed to obfuscate a premium plugin on Spigotmc.org?
with the materials i mean
Aight thanks
thx
https://paste.md-5.net/qidikacawo.xml POM.XML
Dependency 'com.github.libraryaddict:LibsDisguises:10.0.27' not found --> Error. Someone told me to use the libraryaddict one. Libsdisguises as it is shown on spigot doesn't work either
Hi. I was making a server with custom textures for guns. Creating the textures/ Custom Model Data wasn't the problem. I don't know how to apply it to the gun. Basically I have iron horse armor that is textured to look like a gun with the custom model data of 1. Does anyone know how to apply this to the crack shot gun version of it? Is there a way to do it in the crack shot config?
what is a crack shot gun?
a plugin
oh
Isnβt that plugin popular in 2018 or something?
It is outdated now i guess, iirc the author abandoned it already
event.getPlayer().getItemInHand().setAmount(event.getPlayer().getItemInHand().getAmount() - 1);
why doesn't this remove my item when it reaches only 1 item.... 1-1 = 0 which should remove the item, but it doesn't..
player.updateInventoty()?
why would that work?
idk
it's NOT a visual bug.
and with another amount it works?
wdym inefficient
and I want to ask if this is actually spigot behavior
the code internally would have to do the exact same
thats not inefficient thats just a getter and setter
What version are you on?
I remember on the newer version you can just set the amount to 0
if it becomes 0, remove it makes sense no?
when i did something like that the item showed like a red 0 next to it
I doubt that
idk what i did
What version are you on?
it seems like 1.8
not wrong.
it looks like
https://paste.md-5.net/qidikacawo.xml POM.XML
Dependency 'com.github.libraryaddict:LibsDisguises:10.0.27' not found --> Error. Someone told me to use the libraryaddict one. Libsdisguises as it is shown on spigot doesn't work either
That's probably because of that, the API is not updated yet maybe.
You might want to check the amount and set the item in hand to null or something
.
How would I go about giving a Custom Model Data value to plugin items? (items given by plugin commands)
well that is probably worthless.
my point is simple, if there was a bug, there's a potential chance it should be fixed.
i think theres ItemMeta#setCustomModelData(int)
yea
in the config of the plugin? or where would I find that. (Im not really good with plugins)
You add that in the code
or trying to configure one
configure, Im trying to basically take an item a plugin gives me and add custom model data to it
https://paste.md-5.net/qidikacawo.xml POM.XML
Dependency 'com.github.libraryaddict:LibsDisguises:10.0.27' not found --> Error. Someone told me to use the libraryaddict one. Libsdisguises as it is shown on spigot doesn't work either
Well, can't blame spigot too, 1.8 is old
is 1.8 even supported?
well I can, because if 1.8 was updated, it SHOULD be fixed.
as I said.
at least that's my mindset.
,./version says you're capping
I have data for example "a", "b", "c" in python to iterate through this I'd do
for i in ["a", "b", "c"]:
how would i go about doing this in java
You are just not using the latest version on 1.8
sure I'll build 1.8.8 again no problem
I think for(String i : arr)
ty
Couldn't really find something for this exact issue:
https://paste.md-5.net/qidikacawo.xml POM.XML
Dependency 'com.github.libraryaddict:LibsDisguises:10.0.27' not found --> Error. Someone told me to use the libraryaddict one. Libsdisguises as it is shown on spigot doesn't work either
still doesn't work π
amazing.
1.8.8 sheeesh did i fall back in time
you kinda did... f
some people are living in the past
not that I'm living in the past, I know what I am going to get for maining my plugins 1.8, but I have to prepare for people who refuse to update versions π
Unless your plugin becomes a staple like luckperms you really don't lol
tell me why I shouldn't.
help
Because unless you're working for someone making a plugin in an older version is less useful as a majority of server owners looking for plugins to use are running newer version s. And because people here are much less inclined to help you.
I have a question. How can i make something like the plots-Plugin like every user can only build on their own plot. How can i make something like that
If I wanted to make a jagged / 2d array I would do this right? ik this is more java not spigot but
coordinates = new double[11 + 20 * 2][];
int arrayLocation = 0;
for (double i = 0; i <= Math.PI; i += Math.PI / 20) {
double radius = Math.sin(i);
double y = Math.cos(i);
for (double a = 0; a < Math.PI * 2; a+= Math.PI / 20) {
double x = Math.cos(a) * radius;
double z = Math.sin(a) * radius;
coordinates[arrayLocation++] = new double[] { x, y, z };
}
}
Use a database to store the quadrants? I don't understand the question really setup claim commands and permission levels within each for the amount they can claim
it's not like I'm asking for forge support on spigot server, spigot 1.8.8 is like spigot 1.18 but "worse",
and how can i set the radius where they can build?
Yes so when you want to do anything and we give you the PDC you'll say "can't use it" and we'll roll our eyes because if we actually want to help we'll have to spend even more time figuring it out
You either write your own system or use worldguard
okay thx
Mike yk or anyone?
I'm not too familiar with it if you know what you're looking for then just test it and see i suppose
I tested what supposedly causing the error but java wanna be dumb so I have no idea Xd, Iβll just wait for someone to respond I suppose Xd
cute doggo
i love that this works:
π΅βπ«
Brain hurt
cant see any problem
Is #damage() in terms of hearts or some obscure value?
damage(2) would be 1 heart would it not?
1 heart = 2.0d
1/2 heart = 1.0d
1/4 heart = 0.5d
π
you can have players with 0.1 health and they still alive
yea
hey, is there some sort of Command execution event in bungeecord?
?jd
maybe chatevent
hey how would I get getNearbyEntities with radius
World.getnearbyentites iirc
nahh i dont wanne live in ancient versions
actually when did java allow <> instead of the full type
was it 7 or 8
it mightve been 7 bc then 8 were lambdas
write it in java 6 
Actually you could just do: HashMap<ListType, Object> xD
Hello! I was just developing a bit for fun, with my second plugin and I found a bunch of errors that weren't there last time. I was looking for a root for the problem and found this
ok I cant even send images
cool
you have to verify for images
oh hold on
I have @NotNull in front of everything in my CommandExecutor.java file
and this is how I need to set commands apparently
and when I build the project and add it to the plugins folder in my server directory
it says "are you sure your plugin is up to date
Is your command in the plugin.yml
yes
you have not imported the annotations

what will java do if i try to us evalueOf on enum and the constant with specified name don't exist? will it throw exception or return null?
lemme check if I accidentally downloaded the wrong spigot version
oh right
I was using 1.18 instead of 1.8
my bad my bad
probably
i was getting this error when doubling hp:
java.lang.IllegalArgumentException: Health must be between 0 and 20.0, but was 40.0. (attribute base value: 20.0)
is it for a player?
a mob
isnt there a .setMaxHealth method?
[10:49:53 ERROR]: Could not pass event CreatureSpawnEvent to mypluginv
oo lemme try that
thanks
why dont people use google tho
Anyone willing to help me with Optimizations? I have a massive plugin and am having TPS drop on a specific Class. I have tried to make it as effecient as possible yet still having issues with TPS drop (Server resources are in the single digits during TPS drop)
well it was but its deprecated
Hello, I want to create custom achievements in my plugin, can I do it without special APIs and such?
heh what did i see
No.
is 1.8 pvp with the fishing rod spam?
it is extremely primitive and bound to the mouse capability of clicking
didnt realize u were talking to me but im 99% sure that works
thanks
Okay, It explains everything.
I think this chat is not intended to discuss the mechanics of minecraft.
Oh, yes, the status, it definetly makes sense and is good argument in the discussion
We did not have a discussion, there was only your not smart statement that did not correspond to the topic of the chat.
I'm not going to continue discussing this, have a good evening.
how could i create a sphere radius and check if a user walks in it, basically how can i make an array/list of coords in a sphere shape?
should i store like a collection of vanished players in the vanish command class or should i store all my command related collections in one class?
im remaking my whole plugin
isnt it stored by bukkit itself
uhm maybe but that wasnt my question
each player stores a weakly referenced set with hidden players for them iirc
its stored by spigot per player i think
like Player.Spigot#getHiddenPlayers()
why a list of coords ..... ?
all you need is a location and check the radius you want for players
if you want to check if they are in the circle, use something like this:
circleLocation.distance(player.getLocation()) < radius;
like, depends. Do you need that collection outside of the command class?
actually thats a sphere
remove the y component if you want a 2d circle from 0-255
or a cilinder in that case
i'm planning on handling all interactions with that collection from within the class
im stupid i didnt know distance was a thing lmfaooo
i was going to create a sphere of cords store it in db and check each individual cords. thats much easier ty
np
Welp, you can do some sort of manager for vanished players
I am trying to drop items. I have a list of materials that is generated. once generated, I then create the items and actually drop them. however, it keep getting "cannot drop air" when anything drops.
for (Material dropMaterial : materials) {
int quantity = new Random().nextInt(maxDrops - minDrops) + minDrops;
ItemStack itemToDrop = new ItemStack(dropMaterial);
if (itemToDrop.getType() != Material.AIR) {
itemToDrop.setAmount(1);
for (int i = 0; i < quantity; i++) {
location.getWorld().dropItemNaturally(location, itemToDrop);
}
}
}
here is the code I am using. I check if the item is air, so not sure what's up. are there other reasons for why and item can be "air?"
dont create the random each time pls
hey - making sure that doing an if (sender.teleport(location)) would still teleport a player, correct?
yeah
ok good lol
i was 90% sure but i just wanted to make sure it didnt break something somehow
it calls the method so it will do everything it normally does
i seemed me needless to make a manager for just like 5 small methods or something
Even 5 methods makes sense if it shares the common logic. It is better than having repeating code in different places
i thought it was good to implement all the logic directly in my command clsass
is it normal for creaturespawnevent to trigger when the player only is on the server?
what
With commands, you just handle user interfaction with your program
CreatureSpawnEvent only triggers if someone is on the server
i had the idea that were was too little code in my executor
if i handled all the logic somewhere else
i honestly dont know
spawn chunks should be loaded
but i dont know if some optimization causes them to not spawn stuff or something
CreatureSpawnEvent is called whenever a living entity (mob or player) spawns
no problem! Less code == easier to navigate and debug
wait an ender dragon is actually handled as multiple entities?
i can give permissions to an ender dragon part?
can plugin classes be access from inside craftbukkit/spigot?
my code looks weird
you mean like from the server implementation?
because if so yes
hm odd
Been a while since I've done anything with Spigot plugins, is the bukkit scheduler the recommended tool for scheduling simple actions & delays?
Aaaaqwa big font small resolution
although you need to use the correct class loader to access them
because im modifying WatchdogThread to call my method when the server crashes and its just getting a classnotfound
better?
How would I implement libsdisguises? This is my build.gradle: https://paste.md-5.net/qadivahebi.rb
SimplePluginLoader, isn't it?
nah thats the plugin manager
its JavaPluginLoader
in org.bukkit.plugin.java
No error, doesn't work either
:kek:
bruh
are you 100% sure that the group name is LibsDisguises?
because that doesnt seem right
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
It is
oh ye
alright
and it doesnt give an error
10.0.21 is the latest version
try that
also it says here that the id=md_5-public but i dont know if that matters
I know this is gonna be a noob question and you all will yell at me, but i don't work with guis much but i was wondering how do i open a gui from another class????
how can i send a user an action bar title? i see sendTitle but i dont see an option for actionbar
player.sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(msg in here color codes work as well));
sendmessage chatmes- yep kk
sorry... >_<
nah ty xd
btw really random, but do you know how to do this?
np np
you have to use a runnable for an actionbar to keep it sending iirc
^
i tried without and it never showed up
no idea havent worked with guis yet sorry maybe var dunno
ok, >_< well thank you for trying anyway,
its going to be in the player move event so
Terrible idea,
your server will become laggy and most likely crash.
and i learned that from scoreboards.....
i read "how to work with girls" and i want to know that too π
i have if statements so it wont run 24/7
f
brr that expensive
Still, it is better to use a runnable.
kk
good to know
and if the player stops moving its gone
How to make a cooldown when it right click
okay or that ig,
Nah but in all seriousness do u know how to do that though?
why use uuid when you can hash it then use that
nah :(
rip..
#help-development message <- Do u know how to do this?
yea
π
yeah ik but how do u get it from another class is what im trying to do,
share the inventory instance
make an instance of the class
can i have a quick example???
i made this
https://github.com/FourteenBrush/MagmaBuildNetwork/blob/main/src/main/java/io/github/FourteenBrush/MagmaBuildNetwork/gui/ShopGui.java
see it all extends GuiCreator
Like i said i rarely work with guis, so this is kind of something ive just started doing.
ClassA classA = new ClassA();
so i open them by making a new instance of it
Still refuses to work. Do you have a build.gradle file where it does work?
oh ok, then i can just use classA.<whatever method here> yeah?
no.. Move event is not that bad, if you dont do setup stupid things, for sure
I believe you can also do new ClassA().mymethod in the openInventory method
no
sorry then i have no clue
ohh ok let me give this a try and ill let u know,
is how to work with girls also help-development?
yes
oh π³
it states above "Ask other questions here"
doesnt work for some reason..
show me your code
kk 1 sec let me open up pastebin,
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Then this is my main class, https://pastebin.com/wAWkkJyz
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
static ._.
??
nvm
private final Inventory inv1; <- Ig i have to change this to private static?? or something?
Hi, how to set the result of PrepareItemCraftEvent ?
i want the result to be null
or just cancel the event if possible
R u trying to remove crafting?
yes without losing the items
so u dont want ppl to craft in general??
no no, i just want to disable combining two elytras
so they wont be able to repair
so im checking if PrepareItemCraftEvent inventory contains any elytra
and i will not let it to be crafted
Does anyone have any experience with working with the LibsDisguises API?
Any luck?
okay, setResult is a member of event.getInventory
in case anyone will have the same issue
Hey, Guys!
Do you know what event should I cancel to prevent players from taken an Item out of an ItemFrame?
Neither PlayerInteractAtEntity, PlayerInteractEntity nor HangingBreakByEntity seem to work
does the main thread have to be working (not blocked) for events to work?
Depends if events are invoked on the main thread
is it possible for the server to think that, for example, 3 pigs is really one entity?
you can just not add them to the world .... but then you have to calculate all movements and stuff by yourself (and also all items/names stuff via packets)
\n
\n
when using this i get the err
sendMessage(net.md_5.bungee.api.ChatMessageType, net.md_5.bungee.api.chat.BaseComponent[])
oops forgot to turn off ping
it seems that uses bungee api?
ye i have to do ```java
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("text"));
Hehe i have developed action var the whole day. So that code looks like something i have seen to many times today π
Database question
how would i check if a certain enchanted book has a certain level of enchant? i want to have players drag and drop books onto weapons in their inventory and add the enchants
but only unsafe enchantments
Hi. What is the suggested way for persistent data storage? In particular, I would like to store coordinates.
How would I loop a Map<Slot, ItemStack> using lambda for returning the ItemStack if the slot given equals to the one in the map?
For coordinates you csna just store it in a YML file
YAML and using ConfigurationSection
^
I have tried with: ```java
map.entrySet().stream().filter(a -> a.equals(slot)).findFirst().orElse(null)
You have a map yet you're streaming it? Kinda defeats the purpose of having a map
Yeah
I need a map for saving the Buttons of my custom Menu. And then i have to loop throught it for getting the button via slot and checking if slot equals
how would i check if a player is holding a shulker box? would i have to hard code all the colors of each type of box?
instanceof I imagine
ooh ty
Or you can always do .contains("SHULKER_BOX") on the material
So?
I have this Map<Slot, ItemStack>
Im looping it and i want to get the object via slot and check if slot given in method equals to one in the map
is there a way to check if a shulker has a certain item like an enchanted book
?jd
So wait, you have a method that takes in a slot and yet you're looping through a map? You know what a map is used for right?
Yeah
public MenuButton getButton(int slot) {
return this.buttons.entrySet().stream().filter(i -> i.equals(slot)).findFirst().orElse(null);
}
That my method
It wont work because im comparing the objects not the slot
i alr looked at docs
aa ok
Why are you streaming a map? Do you understand how a map works?
Because i like using lambda
Performance 
No i have read that lambda perfomance was solved
Thatβs not it
Trust me I'm already suffering
The time complexity is still O(n)
Okay so do you understand what a map is for
Yeah for mapping 2 values
Still need help on this
just because lambda uses invoke dynamic doesnβt mean everything that uses lambdas are inherently performant
The bytecode instruction is fast sure
Maps are a method of mapping 1 value as a key to another value as a value
But if used incorrectly, like everything else, your performance still drops
Yes i know
So you can query a value instantly
In fact stream creates a lot of objects under the hood
Yet for some reason you're streaming it
Yes i know but i need to stream it because i cannot return the object if slot given its not in the map
if it's not in the map then why stream it what
itβs faster, itβs more readable in this scenario and itβs more flexible
Store an int for the slot id then get it with map::get like the good doggo is saying
good doggo
I know but what about if slot given its not in map?
getOrDefault
It will explote instead of returning null
get and null check
computeIfAbsent
computeIfPresent and return identity
there are options
getOrDefault is what you really want for null prevention
For the love of God don't stream a map 
If itβs a Map<Integer,V> you could also go with an Int2ObjectMap<V>
dont even use a map
bruh
use an array in this case
I cannot because my menu works like this:
1- Create a button
2- Then you add it to map
3- Menu add buttons from map
4- On click event i check if click item slot its on the map
Thonk
does anyone know how to do this? i saw one forum post and when i tried it createInventory was deprecated
I believe Inventory::contains should do
That why i cannot use map#get or others methods
ok ill try that thanks
But im not checking directly the slot
Im checking with custom class
That wasnβt to you
Yeah
I want to loop trought it, returning object and checking slot given its not null
Iβm still extremely puzzled why you would use a stream
how would u get the inventory to check if it contains a item i couldnt figure that out
Because i can use filter keyword
1 itβs not a keyword
2 if (boolean) literally exists
- Add more lines of code
im assuming you are dealing with inventory slots, so its fixed size anyways
3 more lines of code != less readable code
Look at sth like triumph gui
The one i find uses stream#filter
They make perfect sense on how to use a Map for inventories
Link me
` public GuiButton getButton(int slot) {
int exists = buttons.keySet().stream().filter(i -> i == slot).findFirst().orElse(-1);
if(exists != -1)
return buttons.get(exists);
return null;
}
`
why do people use maps for inventories tho, its fixed size inventory, index based
perfect use of an array
the slot numbers are fixed
I mean you basically claim a lot of memory with an array where the majority of its positions arenβt pointing at any objects
Claim is the wrong word
But yeah
Space
Β―_(γ)_/Β―
But why using an array?
All that memory taken up for empty slots is a waste however. Maps only use what is assigned
I mean I personally believe LinkedHashMap is the way to go
How i will check that the slot you clicked on menu its the one i setted?
public GuiButton getButton(int slot) {
//validate slot posiotion
GuiButton button= buttons[slot]
if(button== null)
{
//do sth
}
return button;
}
```
because its easier and faster
Allright
buttons[] its an array
Hum
Im not using array
Don't use arrays too much wasted space. Use a map assign buttons to positions. Much easier and less of a hassle
well either way, you really need to rethink your algorithm here (verano)
myEpicMap.computeIfPresent(event.getSlot(), (key,value) -> {
//for instance verano
return value;
});
Its what im doing xdd
(With the assumption you do not use null values
wait
I will send full code
Im confused
?paste
the slot number for 6 height gui is 54, so Buttons[] = new Buttons[54] takes 54*4 bytes of ram i guess, so it is not much
and every player has only one instance of GUI
GuiButton can be a lot of memory tho it depends
but the array its just list of pointers, so i does not matter how heavy are the object inside
DownloadMoreRAM.com - CloudRAM 2.0
:)
Yeah I donβt think using an array is gonna cripple your server
i mean i personally prefer arrays cause speed lol
That my complete code
But hashmaps are hot
But with a map you don't need to worry about doing if(value == null) or other crap you can just return a default
So with this, it would work right?
So what do you think?
public MenuButton getButton(int slot) {
return this.buttons.get(slot);
}
``` isn't this nicer than some crazy foreach
it will throw exception if slot is not inside Hashmap

plan your logic first then implement
And thanks
That why i was trying to use stram#filter
need help, i figured out the inventory cross thing issue, Now a new issue occurred which makes no sense to me. For some reason you can steal items out of the gui, is there a way to fix this??? i tried e.setCancelled(true); but for some reason it wont cancel taking items out.....
show code
but i mean better to validate slot like if(slot > MaxSize || slot < 0) then...
it will be faster the stream
@EventHandler
public void onInventoryClick(final InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
if (e.getInventory() != inv1) {
return;
}
if (e.getInventory() == inv1) {
e.setCancelled(true);
VoteRewards voterewards = new VoteRewards();
if (e.getRawSlot() == 36) {
p.openInventory(new VoteRewards().SimpleConfig(p));
}
}
return;
}
Example please
I normally just null check the value gotten from the map
How?
computeIfPresent seems fun though
I cannot use other things because for putting it if it null, because the way how i create a menu
you can do that too
me?
{
var position = index >= buttons.length ? buttons.length - 1 : index;
return buttons.get(position);
}``` for example this code returns the last button if slot is invalid
But im not using array
Yeah you can supply the second argument the fallback result
if the index isnt valid
I apply that keyword to the method right?
Yeah
its not a keyword
you just use the utility method
Maps already have getOrDefault
Yes but i cannot add if it null, cuz how i create the menu
I will send an example
if not you wont understand me
Omg with intellij my pc its eating 20gb of ram
What a nice IDE
lol how
MenuButton button = new MenuButton(new ItemStack(Material.DIRT), event -> System.out.println("[Menus] Player " + event.getWhoClicked().getName() + " clicked on " + event.getSlot()));
Menu menu = new MenuBuilder().setButton(3, button).build("&6&lTime", 9);
menu.open(player);
Hums
Discord get bug
Nice
So any idea on how i could fix this inventory issue from another class: #help-development message
That its how i create the menu so if the Button its null i cannot add it
Jack
so do like this, if the slot of method is out of index, cancel the operation
So up to now the code with your change should be working
{
if(index > MAX_SIZE)
{
return;
}
this.buttons.put(index,button);
}```
like this
I already check that i think
why you have the 8 version of JAVA?
you are doing pluing for older version of MC?
Cuz i dont programe up to 1.12.2
ok
Please dont ban me
Outdated! Get them!
Hahaha in other server i got banend cuz i was not asking for help for newer versions
you are doing your Core API as a Plugin??? @sterile token
This is for a library i will open source on ghb
That i will use for Core
Do you understand like its multi module proejct
Hahaha
ghb ?
setting nms nbt data
github
ghb i am pretty sure means github
Yeah make it simplified and easier for people to use,
BUT speaking of MENUS/GUIS i need help.
have you seen the example? Do you think its easy?
Me too
I tried and i can take the items
Out from my inventory
e.setCancelled(true);
(The buttons in my case)
It doesnt work
no i have not yet to see the example :)
oh?
wait before i help u just wondering,
do u know how to fix my problem?
I think its because im calling it on the MenuListener and not in the consumer
it that code the answer for your problem? @sterile token
My problem i got going on is i can still drag items out of the inventory BUT the inventory is in a diff class aside from my main class,
and i dont know how to cancel it out...
Cuz i tried e.setCancelled(true); and it wont work for some reason...
The methods its the same as mine
The problems is that i will an exception when the clicked slot its not on the map
if(buttons.contains(index) == false) {return} can you just do that in the OnInventoryClick?
MenuButton button = new MenuButton(new ItemStack(Material.DIRT), event -> System.out.println("[Menus] Player " + event.getWhoClicked().getName() + " clicked on " + event.getSlot()));
Menu menu = new MenuBuilder().setButton(3, button).build("&6&lTime", 9);
menu.open(player);
could anyone help me out π₯Ί #932424700389367828
== false
Wat
I dont have a getter for the map
That kind of seems easy... just gonna take a little to get used to,
Check if the value returned from the map is null
I already checking that on InvclickEvent i think
@EventHandler
public void onInventoryClick(final InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
if (e.getInventory() != inv1) {
return;
}
if (e.getInventory() == inv1) {
e.setCancelled(true);
VoteRewards voterewards = new VoteRewards();
if (e.getRawSlot() == 36) {
p.openInventory(new VoteRewards().SimpleConfig(p));
}
}
}
It wont cancel it...... pls help someone i beg ;-;
but the getButton has not this if if(buttons.contains(index)) { return null; }
Do u know how to fix my issue..
this is why you get erros
No it isnβt
Aaa
Now i udnerstand
Im getting error because the slot its not on the map
Yo urefer to that?
But so i wont get an exception or yes?
No
Im confused between you and Jack
if this is not working that means e.getInventory() is not inv1
jack
Well that makes no sense, how can i make it "inv1" do i have to close the other gui??
if the key is not inside the Map and you use map.get(key) the exception will be thrown
Another question i need to cancel the button movement from my MenuListener or from the button Consumer?
No it wonβt
I tihin its return nulls
Correct
Do you agree?
here im gonna send a pastebin of my code, and maybe you can help me find what i did wrong...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
sorry, the exception will be thrown in C#
for this
how to load world?
have you read the javadocs?
Or search at least on google: "Spigotmc how to load a world?"
This sometimes always have a solution
Using WorldCreator
I recommend you using pastebin from md5 (?paste)
Yes, i using Bukkit.getServer().createWorld(new WorldCreator("serverBuilds"));
Because it format the code
But if I put two, it only initializes one.
i will check it
Alright thank you,
Im having a e.setCancelled(true); issue, where it wont cancel out item clicking in the gui, so just trying to get help on wtf i did wrong
i think the problem is you use first constructor instead of secound
so the inv1 is never initialized
well how do i go about initializing inv1?
this.inv1 = null;
plugin = instance;
this();
}```
ok ok,
And second error he is not checking about the top inventory and no the player one
ill update u
do this code so the two constructors will be triggered
Good thing loops arent available in java
error 101,
public EXPGui(VoteRewards instance) {
this.inv1 = null;
plugin = instance;
}
Dude we would be here for ages if that was the case.
Thats how it was before hand..
Jack so do i have to cancel item movement on my MenuListener or in the Consumer (InventoryClickEvent )
sry the this(); should be the first thing
ok ok, no worries, just give me a second to see if this is gonna work,
if it does i will gladly let u know :)
it doesn't wanna work.... skldjhf
Real programming languages donβt need loops
Why do you need 2 constructors? Makes absolutely no sense here.
well i dont,
i tried without one of them, but it doesnt wanna work.
can you add nms nbt data to an extended class of itemstack?
In command handler i have multiple constructors. Hahaha. So it wrong??
Will later, just wanna fix this set cancelled issue first,
You cant extend ItemStack. ItemStacks are handled quite differently.
If you want to store data in an ItemStack just use its PDC
HATE LOOP
@gleaming grove listen
He forgot something
And you ignore me
PEOPLE he is not checking if the inventory he is clicking its the TOP one
e.getInventory() == inv1
Dont check Objects with == unless you want to check for identity
Okay so what should i replace it with?
e.getInvenotry().equals(inv1)
.equals
If you use Equals do internally that
SO dont fuck
Equals internally do an ==
Not really
Should i do the same with this?
sry what is your issue?
Thatβs just the Object::equals implementation
derivatives may actually end up implementing it themselves
I was telling YOU that he forgot to checking if the invetory its the TOP one if not the event wont be cancelled
Iβm pretty sure inventories are referentially comparable
Ah allright
oh ok, so what should i do then?
No he doesnt. The inventory is the primary inventory involved in the event. This part is fine.
Really?
Yeah coll for most part? Altho iirc Bukkit sometimes create delegates
i wanna give veranO123's idea a go, and see wtf happens,
Yes getInventory is always the top inventory unless there is only the players inventory present
ah ok
I am using 1.12.2 tho, but youre saying you cant extend itemstack, but you can? I am doing that right now I know that you dont get the object after its been added to the players inventory. But extending still works in order to create multiple items and some sort of abstraction if you know what I mean
so then ig not then.
So i can remove this from my code??
Hiw can I add or remove thinks to Inventory
here ill send an updated version of the gui thing and u tell me what i need to fix.
Inventory#setItem(slot, ItemStack) and Inventory#Remove()
Extending the Interface ItemStack does exactly nothing as you will always get a new instance of ItemStack every so often.
private final Inventory inv1;
public EXPGui(VoteRewards instance) {
plugin = instance;
inv1 = Bukkit.createInventory(null, 45, "Experimental Options");
inv1.setItem(36, createGuiItem(Material.ARROW, ChatColor.GREEN + "Back A Page", ChatColor.YELLOW + "Click to flip"));
inv1.setItem(0, createGuiItem(Material.BLACK_STAINED_GLASS_PANE, ChatColor.GREEN + ""));
inv1.setItem(1, createGuiItem(Material.BLACK_STAINED_GLASS_PANE, ChatColor.GREEN + ""));
inv1.setItem(2, createGuiItem(Material.BLACK_STAINED_GLASS_PANE, ChatColor.GREEN + ""));
inv1.setItem(3, createGuiItem(Material.BLACK_STAINED_GLASS_PANE, ChatColor.GREEN + ""));
}```
use just one constructor
Now can u help me?
should be event.getInventory().equals(menu.getInventory()) instead
I can remove this check here?
and second thing: For calling item moving from gui i have to cancell it on MenuListener or in the Consumer (InventoyClickEvent)??
oki uh ill see 1 sec,
Ah allright
So how do you create custom items then within their own class?
But you are tracking the inv opened by a player so you can also just remove that check all together actually...
Still letting me pick up items.
By using a supported spigot version and accessing its PDC
And the second one?
I use pdc to save a unique name to the item and then map said unique name to a custom item class
but do you removed the first constructor? @manic crater
im 1.12.2 tho
The thing is,
You just need to check if the menu is null and if the button is null. Everything else should be obsolete.
π€·
Yikes
I have done all that. But i still can move the items
I dont know how to fix this issue,
Learn JAVA
What's InOffHand
Then cancel the event
its the item in ur off hand.
Thatβs like the shield hand whes
https://www.spigotmc.org/wiki/how-to-learn-java-programming/
Honestly learn this before u jump into such "big" projects for no reason.
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
I actually NOW that i have to cancell it BUT WHERE?? On the MenuListener or Consumer?
Do you play minecraft? Itβs quite hard to understand some of the methods if you donβt even know the content.
but I am not really extending itemstack just making a structure around the constructor. After its initialized i dont touch it does that make more sense?
yeah same with that,
Wherever you think it makes sense. Depends on your menu implementation. Just cancel it somewhere.
anyway i can still drag items out of the inv... and i fr have no clue how to fix this.. ive tried google, doing it on my own etc. and nothing seems to wanna work..
Jelles usually when you have a custom item you use pdc to identify it, then a factory method to create it
It is difficult for people to understand it's actual use in these English
Cancelling it on MenuListener doesnt affect i have tried
the Bukkit ItemStack class is simply a middleman and a context provider
https://www.spigotmc.org/wiki/how-to-learn-java-programming/ BTW! you make 0 sense.
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
CraftBukkit will always produce instances of CraftItemStack as their implementation of ItemStack.
You can extend that all you want but it will never get called.
Yeah, learning is just that hard, donβt give up tho, but maybe you wanna take a look at the javadocs for instance and if you lack experience in navigating those, then maybe thatβs your first stepping stone.
Always cancel if menu is not null.
To also prevent bottom inv clicks
offhand means the left hand
Is there a wiki page for Inventory?
?jd
Scarcely
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Itβs actually really bare
I was considering rewriting major parts
setCancel(true) right and should be before Button checking?
π€©
Allrgiht thanks
What happens?
I can still drag items out of the gui..
I have been crying with my menu since a week HAHAHA
even after i cancelled it..
AHHHHH
I havin the same yeat
cancel the event
Not works
I did...
Can EntityDamageEvent and EntityDamageByEntity event get thrown at the same time? e.g. player hits a player
@EventHandler
public void onInventoryClick(final InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked();
if (e.getInventory() != inv1) {
return;
}
if (e.getInventory().equals(inv1)) {
e.setCancelled(true);
VoteRewards voterewards = new VoteRewards();
if (e.getRawSlot() == 36) {
p.openInventory(new VoteRewards().SimpleConfig(p));
}
}
}
See
it was cancelled to begin with.
Bukkit.getConsoleSender.sendMessage("IT WORKS");
e.setCancelled(true);
VoteRewards voterewards = new VoteRewards();
if (e.getRawSlot() == 36) {
p.openInventory(new VoteRewards().SimpleConfig(p));
}
}``` @manic crater replace your code with that and see if message will be send
It does. If not then either:
The event is not called
or
Menu is null
Check for both
Menu its not null because i debug that
As this doesn't work....
Show some code
Ill just make it send a msg.
Yeah that how you should debug
it doesnt send a msg to console.
Debug it again to see if the menu is really not null.
Then check if your button reverses the cancellation of your event
I already do it before
@EventHandler
public void onInventoryClick(final InventoryClickEvent e) {
Bukkit.getConsoleSender().sendMessage("1");
Player p = (Player) e.getWhoClicked();
if (e.getInventory() != inv1) {
return;
}
Bukkit.getConsoleSender().sendMessage("2");
e.setCancelled(true);
VoteRewards voterewards = new VoteRewards();
if (e.getRawSlot() == 36) {
p.openInventory(new VoteRewards().SimpleConfig(p));
}
}``` try this and check the messages
Do it again. If menu is not null then you cant move items
Remember that in MenuButton i have a consumer of InventoryClickEven t
I think thats why i can move the items
I think you havent seen the code i sent on paste
only if the consumer reverses the cancellation. Otherwise it doesnt matter.
if (e.getInventory() != inv1) {
return;
}
I thought we established not to use identity equality with Objects...
well i dont know what to replace "!=" with.
cuz i dont think the word "Doesn't" will work
.equals
yeah but im checking though if the inventory doesn't equal that,.
The whole point of that is so other's inventories doesn't act like the gui
then negate the statement
Yeah, unfortunately the spigot wiki uses it so probably why other devs also decide to stick to it.
For objects == just checks the memory location, not the actual object data
Which isnβt what you want
i changed it, and i can still drag the items out
First off using "e" instead of "event" is faster,
2nd, Please learn the literal BASIC MOVEMENT OF JAVA!
Use addsItem rather than setItem
Donβt use one letter variables
y
why e is faster then event?
because then you don't have to type out "vent" every time.
They arenβt descriptive
well in events they are.
Any ide will let you autocomplete it
and it is kind of really obvious on what an event is.
Yeah I mean theyβre both fine. The name of a variable should be proportional to the size of its scope; so e and event is fine, whilst event does in fact make it more explicit, a short event method would still make it clear that e is for event. 
I alread recommend him learning how to use Intellij Idea Community
This is your general setup:
public class CustomInvListener implements Listener {
private final Inventory customInv;
public CustomInvListener() {
this.customInv = Bukkit.createInventory(null, 3 * 9, "Cool Inv");
setupInv();
}
private void setupInv() {
// Fill your inv with garbage
}
@EventHandler
public void onClick(InventoryClickEvent event) {
Inventory primary = event.getInventory();
if (!customInv.equals(primary)) {
return;
}
event.setCancelled(true);
// Custom inventory was clicked here
}
}
Okay but why wont what i have work???
Eclipse lets you autocomplete variables just fine lmao
Please i need a logical explanation of how player inventory works and custom one. Because when you open a custom inventory his invetory its still open
That will helpme to understand more
The player inventory is always open (iirc)
Just close the inventory when they close that inventory.....
You probably have a Map<UUID, Menu> right?
The playerβs inventory cannot be hidden if another inventory is open
Thatβs just Minecraft
π₯²
Oh thats what he meant...
Yes
Paste your current class again pls
?paste
yep
its just the dragging that causes issues,
like u can drag items out and i dont want that to happen...
First of all: DuckDuckGo the shortcut for auto formatting for your IDE, press it and then paste again.
???
wdym duckduck go?
google it.. -.-
ik duckduckgo is a web browser.
just like
still okay whatever who cares about duckduck go for rn
You can check the docs.. need pass a Material in the construction of itemstack
Queue a search request with the search engine that you fancy.
literally when i first started out in java not ONCE did i need to ask for help regarding giving an item...
You use eclipse, right?
yeah ctrl s is really helpful
- make VoteRewards plugin private
- Group your fields:
private final VoteRewards plugin;
private final Inventory inv1;
public EXPGui(VoteRewards instance) {
this();
plugin = instance;
}
- rename your method
EXPConfigto something likeopenGUIand make it return void - remove the second constructor and merge them
Is this error?
Test it out then find out, honestly no one is gonna spoon feed you basic things.
I got api error
public void openGUI(HumanEntity entity) {
entity.openInventory(inv1);
}
id assume combind this(); and plugin = instance in EXPGui?
remove the call to your other constructor and merge them
instance = this
[08:56:00] [Server thread/ERROR]: Fatal error trying to convert ExpTech_Economy v22w04-pre1:eventlistener/eventlistener.class
org.bukkit.plugin.AuthorNagException: No legacy enum constant for GRASS_BLOCK. Did you forget to define a modern (1.13+) api-version in your plugin.yml? ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3398-Spigot-f4ff00f-f3828bb]
at org.bukkit.craftbukkit.v1_18_R1.CraftServer.reload(CraftServer.java:941) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3398-Spigot-f4ff00f-f3828bb]
at org.bukkit.Bukkit.reload(Bukkit.java:749) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_18_R1.CraftServer.dispatchCommand(CraftServer.java:821) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3398-Spigot-f4ff00f-f3828bb]
at org.bukkit.craftbukkit.v1_18_R1.CraftServer.dispatchServerCommand(CraftServer.java:806) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3398-Spigot-f4ff00f-f3828bb]
at net.minecraft.server.dedicated.DedicatedServer.bf(DedicatedServer.java:453) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3398-Spigot-f4ff00f-f3828bb]
at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:429) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3398-Spigot-f4ff00f-f3828bb]
at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1206) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3398-Spigot-f4ff00f-f3828bb]
at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1034) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3398-Spigot-f4ff00f-f3828bb]
at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~[spigot-1.18.1-R0.1-SNAPSHOT.jar:3398-Spigot-f4ff00f-f3828bb]
at java.lang.Thread.run(Thread.java:833) [?:?]
Add api-version: 1.13 to your plugin.yml
The stack trace literally asks you:
Did you forget to define a modern (1.13+) api-version in your plugin.yml?
is this necessary
add api-version: 1.13 in your plugin.yml
Or is this only necessary to use the new version of the block
.....
Yes it's necessary if you are creating a plugin post 1.13
You dont even know basic java and you're getting people who are x1000 better to help u
when yet they normally redirect you to learn java,.
then do api-version: 1.17
then insert 1.18
Then your api version would be 1.18
oh wait 1.18 api is out now?
hm thats weird, bc for me it wont let me use 1.18 as a spigot jar file... and only 1.17.1 and under...
now im getting an intilization error,
The point of that flag is to prevent the legacy code from running. Which it will do if no flag is provided.
The flag should really be set to the lowest version your plugin supports. (At least down to 1.13)
A recommendation about APIS, would you call a project an API when the project works over an API?
Maybe
I think its a really opened question
I mean you can have several apis inside your project
yeah that was my bad, but fr though in this scenario,
Yeah but i dont know if correct calling something an API when its over/using another API
Even if itβs not an interface
No dont. The openGUI method is fine as it is. No need to change it to anything else than void.
I can now see the problem emerging. You are creating several new instances of your GUI inventory. None of which are known by the registered listener.
Well what you got?
ok so then wat do i do about the error then?
Like for example an easy way of commands for spigot/bukkit will be called a CommandHandler or a CommandAPI?
Treat your listener as a singleton
Okay but ive been doing that for a while now...
Yeah so its really strange the usage of word API on miencraft plugins
Your code tells me otherwise
Because for my buiness owner if told him an API he dont understand why i called API
I mean the whole api thing is kinda softy defined
When you really think about it, every single project is an API. It's just that we don't refer to it as one until another project depends on it.
well.... can u help me make it then a singleton??
Object orientation is about making apis for yourself that hide the complexity and details of things (which has proven to be both good and bad)
Sure. Only construct a single instance of your listener and then never again.
erm ok.......
I ask because i talk with my work owner that works on .NET If i tell him about an api. He didnt understand because the menaning on spigot development its different
In a sense itβs probably very different from the general api term
Which usually is an inferred reference to a web api
That answer i was waiting
