#help-development

1 messages Β· Page 1892 of 1

vestal dome
#

map the materials if you want such behaviour...

quaint mantle
#

Yea but there might be a list of those items

tardy delta
#

i guess you have to itertate Material.values()

summer scroll
#

Make it so the file is on the same directory as the icecube.iml and .gitattributes

quaint mantle
tardy delta
#

Material#isBlock should

torn shuttle
#

has anyone ever run into and fixed this issue before?

quaint mantle
#

but still some blocks will bypass that (like TNT which is in the redstone tab)

mint quiver
#

hm , thanks u all for help , someone calling me now, gtg

summer scroll
#

You might want to filter it yourself.

tardy delta
neat maple
#

How much is it allowed to obfuscate a premium plugin on Spigotmc.org?

tardy delta
#

with the materials i mean

quaint mantle
#

Aight thanks

vestal dome
worldly ingot
#

TL;DR: Whatever Minecraft does

#

Simple name obfuscation

fervent gate
#

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

wet sigil
#

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?

tardy delta
#

what is a crack shot gun?

eternal oxide
#

a plugin

tardy delta
#

oh

quaint mantle
#

Isn’t that plugin popular in 2018 or something?

#

It is outdated now i guess, iirc the author abandoned it already

vestal dome
#
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..

tardy delta
#

player.updateInventoty()?

vestal dome
#

why would that work?

tardy delta
#

idk

vestal dome
#

it's NOT a visual bug.

tardy delta
#

and with another amount it works?

vestal dome
#

yes-.

#

from 64 it goes to 63

tardy delta
#

check if it becomes 0 then

#

and remove it

vestal dome
#

Inefficient....

#

and if amount is 0

#

it should auto default to AIR..

glossy venture
#

wdym inefficient

vestal dome
#

and I want to ask if this is actually spigot behavior

glossy venture
#

the code internally would have to do the exact same

tardy delta
#

thats not inefficient thats just a getter and setter

glossy venture
#

if its from you or from the bukkit devs

#

also does it show like a red 0

vestal dome
#

it still makes no sense..

#

no

summer scroll
#

What version are you on?

vestal dome
#

the amount is 1

#

it doesn't go 0

summer scroll
#

I remember on the newer version you can just set the amount to 0

tardy delta
#

if it becomes 0, remove it makes sense no?

vestal dome
#

it doesn't disappear..

#

it just doesn't change.,

tardy delta
#

i think its spigot behaviour

#

i had things like that before

glossy venture
#

when i did something like that the item showed like a red 0 next to it

summer scroll
#

I doubt that

glossy venture
#

idk what i did

vestal dome
#

simple?

#

it doesn't disappear..

summer scroll
#

What version are you on?

glossy venture
#

it seems like 1.8

vestal dome
#

not wrong.

glossy venture
#

it looks like

fervent gate
#

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

summer scroll
#

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

vestal dome
wet sigil
#

How would I go about giving a Custom Model Data value to plugin items? (items given by plugin commands)

vestal dome
#

well that is probably worthless.

#

my point is simple, if there was a bug, there's a potential chance it should be fixed.

glossy venture
tardy delta
#

yea

wet sigil
glossy venture
#

what

#

wait are you making a plugin

glossy venture
#

or trying to configure one

wet sigil
#

configure, Im trying to basically take an item a plugin gives me and add custom model data to it

glossy venture
fervent gate
#

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

summer scroll
glossy venture
#

is 1.8 even supported?

vestal dome
#

as I said.

#

at least that's my mindset.

summer scroll
#

Sadly it's not updated anymore

#

I mean fortunately

vestal dome
obtuse ferry
#

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

summer scroll
vestal dome
#

sure I'll build 1.8.8 again no problem

obtuse ferry
fervent gate
#

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

vestal dome
#

amazing.

vocal cloud
#

1.8.8 sheeesh did i fall back in time

vestal dome
#

you kinda did... f

tardy delta
#

some people are living in the past

vestal dome
#

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 πŸ™‚

vocal cloud
#

Unless your plugin becomes a staple like luckperms you really don't lol

vestal dome
#

tell me why I shouldn't.

golden turret
#

help

vocal cloud
# vestal dome tell me why I shouldn't.

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.

copper scaffold
#

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

quaint mantle
#

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 };
            }
        }
vocal cloud
vestal dome
copper scaffold
vocal cloud
vocal cloud
copper scaffold
#

okay thx

vocal cloud
#

I'm not too familiar with it if you know what you're looking for then just test it and see i suppose

quaint mantle
#

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

tardy delta
#

cute doggo

spiral light
#

i love that this works:

tardy delta
#

πŸ˜΅β€πŸ’«

quaint mantle
#

Brain hurt

spiral light
#

cant see any problem

obtuse ferry
#

Is #damage() in terms of hearts or some obscure value?

#

damage(2) would be 1 heart would it not?

spiral light
#

1 heart = 2.0d
1/2 heart = 1.0d
1/4 heart = 0.5d

obtuse ferry
#

πŸ‘

spiral light
#

you can have players with 0.1 health and they still alive

tardy delta
#

yea

quaint mantle
#

hey, is there some sort of Command execution event in bungeecord?

spiral light
#

?jd

spiral light
#

maybe chatevent

wary harness
#

hey how would I get getNearbyEntities with radius

spiral light
#

World.getnearbyentites iirc

buoyant viper
spiral light
#

nahh i dont wanne live in ancient versions

buoyant viper
#

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 Chad

spiral light
tardy delta
#

i learned in school
private ArrayList<String> list = new ArrayList<String>();

#

blehh

mint mesa
#

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

opal juniper
#

you have to verify for images

mint mesa
#

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

chrome beacon
#

Is your command in the plugin.yml

mint mesa
#

yes

chrome beacon
#

Okay then send the entire error

#

?paste

undone axleBOT
tardy delta
#

which annotation is it?

#

the org.jetbrains one?

opal juniper
#

you have not imported the annotations

mint mesa
#

well I cant

#

because its a read-only file

opal juniper
vale ember
#

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?

mint mesa
#

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

opal juniper
#

like wtf

#

goes from latest to 1.8

tardy delta
#

wtf

#

1.8

mint mesa
#

Im not a big fan of survival

#

im more into PvP

worldly quest
#

is it possible to spawn mobs with double hp?

#

or triple, etc

tardy delta
#

probably

worldly quest
#

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)
tardy delta
#

is it for a player?

worldly quest
#

a mob

tardy delta
#

isnt there a .setMaxHealth method?

worldly quest
#

[10:49:53 ERROR]: Could not pass event CreatureSpawnEvent to mypluginv

#

oo lemme try that

#

thanks

tardy delta
#

why dont people use google tho

worldly quest
#

its not a thing nvm

#

no i looked at the docs

signal locust
#

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)

worldly quest
#

well it was but its deprecated

latent zephyr
#

Hello, I want to create custom achievements in my plugin, can I do it without special APIs and such?

tardy delta
#

or an setAttribute?

#

custom achievements is json stuff iirc

quaint mantle
#

oop

#

s

#

but yes it is

tardy delta
#

heh what did i see

latent zephyr
tardy delta
#

is 1.8 pvp with the fishing rod spam?

quaint mantle
#

it is extremely primitive and bound to the mouse capability of clicking

tardy delta
#

LMAO I HATE THAT

#

πŸ™„

worldly quest
#

thanks

latent zephyr
tardy delta
#

the only reason i had a chance in 1.8 pvp was because of my triple click mouse

quaint mantle
latent zephyr
#

I'm not going to continue discussing this, have a good evening.

quaint mantle
#

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?

tardy delta
#

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

quaint mantle
#

isnt it stored by bukkit itself

tardy delta
#

uhm maybe but that wasnt my question

#

each player stores a weakly referenced set with hidden players for them iirc

glossy venture
#

like Player.Spigot#getHiddenPlayers()

spiral light
glossy venture
quaint mantle
glossy venture
#

actually thats a sphere

#

remove the y component if you want a 2d circle from 0-255

#

or a cilinder in that case

tardy delta
quaint mantle
glossy venture
#

np

quaint mantle
delicate lynx
#

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?"

tardy delta
#

dont create the random each time pls

trail bough
#

hey - making sure that doing an if (sender.teleport(location)) would still teleport a player, correct?

glossy venture
#

yeah

trail bough
#

ok good lol

#

i was 90% sure but i just wanted to make sure it didnt break something somehow

glossy venture
#

it calls the method so it will do everything it normally does

trail bough
#

huh

#

didnt think about that

#

thanks

tardy delta
quaint mantle
tardy delta
#

i thought it was good to implement all the logic directly in my command clsass

maiden thicket
#

is it normal for creaturespawnevent to trigger when the player only is on the server?

glossy venture
#

what

quaint mantle
maiden thicket
tardy delta
#

i had the idea that were was too little code in my executor

#

if i handled all the logic somewhere else

glossy venture
#

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

quaint mantle
glossy venture
#

wait an ender dragon is actually handled as multiple entities?

#

i can give permissions to an ender dragon part?

visual tide
#

can plugin classes be access from inside craftbukkit/spigot?

tardy delta
#

my code looks weird

glossy venture
#

because if so yes

visual tide
#

hm odd

hollow arch
#

Been a while since I've done anything with Spigot plugins, is the bukkit scheduler the recommended tool for scheduling simple actions & delays?

quaint mantle
glossy venture
visual tide
glossy venture
#

yeah you need to get them from the classloader i think

#

the plugins classloader

visual tide
#

hm

#

where is that stored?

glossy venture
#

in the plugin instance i think

#

and somewhere else probably

#

but i dont know

tardy delta
glossy venture
#

where is the PluginLoader implementation wtf

#

oh nvm found it for javaplugins

fervent gate
tender shard
glossy venture
#

its JavaPluginLoader

#

in org.bukkit.plugin.java

fervent gate
tardy delta
glossy venture
#

bruh

glossy venture
#

because that doesnt seem right

fervent gate
#

It is

glossy venture
#

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

manic crater
#

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????

quaint mantle
#

how can i send a user an action bar title? i see sendTitle but i dont see an option for actionbar

manic crater
quaint mantle
#

sendmessage chatmes- yep kk

manic crater
#

sorry... >_<

quaint mantle
#

nah ty xd

manic crater
manic crater
tardy delta
#

you have to use a runnable for an actionbar to keep it sending iirc

manic crater
#

^

tardy delta
#

i tried without and it never showed up

quaint mantle
manic crater
quaint mantle
manic crater
#

your server will become laggy and most likely crash.

#

and i learned that from scoreboards.....

tardy delta
quaint mantle
#

i have if statements so it wont run 24/7

quaint mantle
tardy delta
manic crater
quaint mantle
#

kk

manic crater
#

use a runnable for the on join method.

#

And you're gonna be fine

quaint mantle
#

good to know

tardy delta
#

and if the player stops moving its gone

north trench
#

How to make a cooldown when it right click

tardy delta
#

map<UUID, Long> would be a good start

#

and use timestamps instead of runnable

manic crater
#

okay or that ig,

manic crater
proud basin
#

why use uuid when you can hash it then use that

manic crater
#

rip..

manic crater
proud basin
#

yea

tardy delta
#

πŸ˜“

proud basin
#

I believe its Player#openInventory

#

that you call your gui in there

manic crater
#

yeah ik but how do u get it from another class is what im trying to do,

tardy delta
#

share the inventory instance

proud basin
#

make an instance of the class

manic crater
#

can i have a quick example???

manic crater
#

Like i said i rarely work with guis, so this is kind of something ive just started doing.

proud basin
#

ClassA classA = new ClassA();

tardy delta
#

so i open them by making a new instance of it

fervent gate
manic crater
quaint mantle
proud basin
#

I believe you can also do new ClassA().mymethod in the openInventory method

glossy venture
#

sorry then i have no clue

manic crater
tardy delta
#

is how to work with girls also help-development?

proud basin
#

yes

tardy delta
#

oh 😳

proud basin
#

it states above "Ask other questions here"

manic crater
proud basin
#

show me your code

manic crater
#

kk 1 sec let me open up pastebin,

tardy delta
#

static ._.

manic crater
#

??

tardy delta
#

nvm

manic crater
#

private final Inventory inv1; <- Ig i have to change this to private static?? or something?

wintry badger
#

Hi, how to set the result of PrepareItemCraftEvent ?

#

i want the result to be null

#

or just cancel the event if possible

manic crater
wintry badger
#

yes without losing the items

manic crater
#

so u dont want ppl to craft in general??

wintry badger
#

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

fervent gate
#

Does anyone have any experience with working with the LibsDisguises API?

manic crater
wintry badger
#

in case anyone will have the same issue

quaint mantle
#

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

visual tide
#

does the main thread have to be working (not blocked) for events to work?

ivory sleet
#

Depends if events are invoked on the main thread

visual tide
#

nope

#

async

#

on watchdog thread 😳

left swift
#

is it possible for the server to think that, for example, 3 pigs is really one entity?

spiral light
#

\n

quaint mantle
#

\n

quaint mantle
#

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"));

stoic brook
river hearth
#

Database question

worldly quest
#

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

little elm
#

Hi. What is the suggested way for persistent data storage? In particular, I would like to store coordinates.

sterile token
#

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?

trail bough
#

For coordinates you csna just store it in a YML file

sterile token
trail bough
#

^

sterile token
vocal cloud
#

You have a map yet you're streaming it? Kinda defeats the purpose of having a map

sterile token
#

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

worldly quest
#

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?

worldly quest
#

ooh ty

vocal cloud
#

Or you can always do .contains("SHULKER_BOX") on the material

worldly quest
#

im pretty sure its an itemstack tho

#

what the player is holding

vocal cloud
#

So wait, you have a slot and a map?

#

What are you comparing

sterile token
#

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

worldly quest
#

is there a way to check if a shulker has a certain item like an enchanted book

vocal cloud
sterile token
#

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

worldly quest
sterile token
vocal cloud
sterile token
ivory sleet
#

Performance roocry

sterile token
#

No i have read that lambda perfomance was solved

ivory sleet
#

That’s not it

vocal cloud
ivory sleet
#

The time complexity is still O(n)

vocal cloud
#

Okay so do you understand what a map is for

sterile token
ivory sleet
#

just because lambda uses invoke dynamic doesn’t mean everything that uses lambdas are inherently performant

#

The bytecode instruction is fast sure

vocal cloud
ivory sleet
#

But if used incorrectly, like everything else, your performance still drops

vocal cloud
#

So you can query a value instantly

ivory sleet
#

In fact stream creates a lot of objects under the hood

vocal cloud
#

Yet for some reason you're streaming it

sterile token
ivory sleet
#

And object instantiation is expensive

#

just use map::get

vocal cloud
ivory sleet
#

it’s faster, it’s more readable in this scenario and it’s more flexible

vocal cloud
#

Store an int for the slot id then get it with map::get like the good doggo is saying

#

liziscute good doggo

sterile token
ivory sleet
#

getOrDefault

sterile token
#

It will explote instead of returning null

ivory sleet
#

get and null check

#

computeIfAbsent

#

computeIfPresent and return identity

#

there are options

vocal cloud
#

getOrDefault is what you really want for null prevention

#

For the love of God don't stream a map YanSigh

ivory sleet
#

If it’s a Map<Integer,V> you could also go with an Int2ObjectMap<V>

paper viper
#

bruh

#

use an array in this case

sterile token
#

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

ivory sleet
#

Thonk

worldly quest
ivory sleet
#

I believe Inventory::contains should do

sterile token
worldly quest
sterile token
#

Im checking with custom class

ivory sleet
#

That wasn’t to you

sterile token
#

Map<Integer, MenuButton> buttons = new HashMap<>()

#

That my map

ivory sleet
#

Yeah

sterile token
#

I want to loop trought it, returning object and checking slot given its not null

ivory sleet
#

I’m still extremely puzzled why you would use a stream

worldly quest
sterile token
paper viper
#

use an array

#

(:

ivory sleet
#

1 it’s not a keyword
2 if (boolean) literally exists

sterile token
paper viper
#

im assuming you are dealing with inventory slots, so its fixed size anyways

ivory sleet
#

3 more lines of code != less readable code

sterile token
#

So how would you do it

#

Giveme an example

#

I will use map#get

ivory sleet
#

Look at sth like triumph gui

sterile token
#

The one i find uses stream#filter

ivory sleet
#

They make perfect sense on how to use a Map for inventories

ivory sleet
sterile token
#

` 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;
}
`
gleaming grove
#

@sterile token why dont you use just array for store buttons

#

like this?

paper viper
#

why do people use maps for inventories tho, its fixed size inventory, index based

#

perfect use of an array

gleaming grove
#

the slot numbers are fixed

ivory sleet
#

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

#

Β―_(ツ)_/Β―

sterile token
#

But why using an array?

ivory sleet
#

Idk

#

Depends what you’re trying to do

vocal cloud
ivory sleet
#

I mean I personally believe LinkedHashMap is the way to go

sterile token
#

How i will check that the slot you clicked on menu its the one i setted?

gleaming grove
#
   public GuiButton getButton(int slot) {
//validate slot posiotion
        GuiButton button= buttons[slot]
        
        if(button== null)
{
//do sth
        }
        return button;
    }
    ```
#

because its easier and faster

sterile token
#

buttons[] its an array

#

Hum

#

Im not using array

vocal cloud
#

Don't use arrays too much wasted space. Use a map assign buttons to positions. Much easier and less of a hassle

paper viper
#

well either way, you really need to rethink your algorithm here (verano)

ivory sleet
#

myEpicMap.computeIfPresent(event.getSlot(), (key,value) -> {
//for instance verano

return value;
});

ivory sleet
#

(With the assumption you do not use null values

sterile token
#

I will send full code

#

Im confused

#

?paste

undone axleBOT
gleaming grove
#

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

paper viper
#

GuiButton can be a lot of memory tho it depends

gleaming grove
#

but the array its just list of pointers, so i does not matter how heavy are the object inside

ivory sleet
buoyant viper
#

:)

sterile token
young knoll
#

Yeah I don’t think using an array is gonna cripple your server

paper viper
#

i mean i personally prefer arrays cause speed lol

sterile token
young knoll
#

But hashmaps are hot

vocal cloud
#

But with a map you don't need to worry about doing if(value == null) or other crap you can just return a default

sterile token
#

So what do you think?

vocal cloud
#
public MenuButton getButton(int slot) {
        return this.buttons.get(slot);
    }
``` isn't this nicer than some crazy foreach
gleaming grove
#

it will throw exception if slot is not inside Hashmap

vocal cloud
sterile token
#

Sometimes i think i get ignored. HAhaha cuz im really unbearable

#

Hahaha

paper viper
#

plan your logic first then implement

sterile token
#

And thanks

sterile token
manic crater
#

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.....

paper viper
#

show code

gleaming grove
#

but i mean better to validate slot like if(slot > MaxSize || slot < 0) then...

#

it will be faster the stream

manic crater
#
@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;
      }
young knoll
#

I normally just null check the value gotten from the map

young knoll
#

computeIfPresent seems fun though

sterile token
#

I cannot use other things because for putting it if it null, because the way how i create a menu

paper viper
#

you can do that too

sterile token
gleaming grove
#
    {
        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
sterile token
#

But im not using array

paper viper
#

if the index isnt valid

sterile token
gleaming grove
#

now better? @sterile token

#

look at code

sterile token
#

Yeah

paper viper
#

you just use the utility method

sterile token
#

What the name?

#

Its java 9

#

btww

young knoll
#

Maps already have getOrDefault

paper viper
#

Oh yeah i forgot about that LMFAO

#

yeah you might as well use that

sterile token
#

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

gleaming grove
#

lol how

sterile token
#
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

manic crater
sterile token
#

Jack

gleaming grove
#

so do like this, if the slot of method is out of index, cancel the operation

sterile token
#

So up to now the code with your change should be working

gleaming grove
#
    {
        if(index > MAX_SIZE)
        {
            return;
        }
        this.buttons.put(index,button);
    }```
#

like this

sterile token
#

What a lovely thing i didnt know

sterile token
gleaming grove
#

why you have the 8 version of JAVA?

#

you are doing pluing for older version of MC?

sterile token
gleaming grove
#

ok

sterile token
#

Please dont ban me

young knoll
#

Outdated! Get them!

sterile token
#

Hahaha in other server i got banend cuz i was not asking for help for newer versions

gleaming grove
#

you are doing your Core API as a Plugin??? @sterile token

sterile token
#

That i will use for Core

#

Do you understand like its multi module proejct

#

Hahaha

gleaming grove
#

ghb ?

quaint bough
#

setting nms nbt data

sterile token
manic crater
#

ghb i am pretty sure means github

sterile token
#

Yeah

#

Jack

#

Any recommendation for my menu api?

manic crater
#

Yeah make it simplified and easier for people to use,

#

BUT speaking of MENUS/GUIS i need help.

sterile token
sterile token
#

I tried and i can take the items

#

Out from my inventory

manic crater
sterile token
#

(The buttons in my case)

sterile token
manic crater
manic crater
#

wait before i help u just wondering,

#

do u know how to fix my problem?

sterile token
# manic crater oh?

I think its because im calling it on the MenuListener and not in the consumer

gleaming grove
manic crater
#

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...

sterile token
#

The problems is that i will an exception when the clicked slot its not on the map

gleaming grove
#

if(buttons.contains(index) == false) {return} can you just do that in the OnInventoryClick?

sterile token
# manic crater no i have not yet to see the example :)
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);
quaint bough
sterile token
manic crater
young knoll
#

Check if the value returned from the map is null

sterile token
#

I already checking that on InvclickEvent i think

manic crater
#
@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 ;-;

sterile token
#

That what do you refer?

gleaming grove
#

but the getButton has not this if if(buttons.contains(index)) { return null; }

manic crater
gleaming grove
#

this is why you get erros

young knoll
#

No it isn’t

sterile token
#

Now i udnerstand

#

Im getting error because the slot its not on the map

#

Yo urefer to that?

young knoll
#

Calling get on a map with an invalid key is fine

#

It just returns null

sterile token
young knoll
#

No

sterile token
#

Im confused between you and Jack

gleaming grove
sterile token
#

jack

manic crater
gleaming grove
#

if the key is not inside the Map and you use map.get(key) the exception will be thrown

sterile token
#

Another question i need to cancel the button movement from my MenuListener or from the button Consumer?

young knoll
#

No it won’t

sterile token
young knoll
#

Correct

manic crater
gleaming grove
sterile token
#

Jack

#

So what do you recommend?

candid plover
#

how to load world?

sterile token
#

Or search at least on google: "Spigotmc how to load a world?"

sterile token
young knoll
#

Using WorldCreator

sterile token
manic crater
#

?paste

undone axleBOT
candid plover
sterile token
#

Because it format the code

manic crater
candid plover
#

But if I put two, it only initializes one.

sterile token
manic crater
# sterile token 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

gleaming grove
#

so the inv1 is never initialized

manic crater
#

well how do i go about initializing inv1?

gleaming grove
#
        this.inv1 = null;
        plugin = instance;
this();
    }```
manic crater
#

ok ok,

sterile token
manic crater
#

ill update u

gleaming grove
#

do this code so the two constructors will be triggered

lost matrix
gleaming grove
#

XD

#

its not my code

manic crater
#

error 101,

gleaming grove
#

public EXPGui(VoteRewards instance) {
this.inv1 = null;
plugin = instance;

}
manic crater
manic crater
gleaming grove
#
        this();
        this.inv1 = null;
        plugin = instance;

    }```
#

like this

sterile token
# gleaming grove XD

Jack so do i have to cancel item movement on my MenuListener or in the Consumer (InventoryClickEvent )

gleaming grove
#

sry the this(); should be the first thing

manic crater
#

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

young knoll
#

Real programming languages don’t need loops

manic crater
#
  • i get this error now apparently.
#

o wait hold up

#

nope still not working,

lost matrix
manic crater
#

i tried without one of them, but it doesnt wanna work.

quaint bough
#

can you add nms nbt data to an extended class of itemstack?

sterile token
gleaming grove
#

and use the loop plz

#

for(int i=0;i<44;i++){ inv.1.setItem(i,......):}

manic crater
lost matrix
sterile token
manic crater
#

Anyway i can still move items around in the gui..

#

idk how to fix this... :/

sterile token
#

@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

lost matrix
#

e.getInventory() == inv1
Dont check Objects with == unless you want to check for identity

manic crater
#

Okay so what should i replace it with?

gleaming grove
#

e.getInvenotry().equals(inv1)

lost matrix
#

.equals

sterile token
#

SO dont fuck

#

Equals internally do an ==

ivory sleet
#

Not really

manic crater
#

Should i do the same with this?

gleaming grove
ivory sleet
#

derivatives may actually end up implementing it themselves

sterile token
young knoll
#

I’m pretty sure inventories are referentially comparable

sterile token
manic crater
lost matrix
ivory sleet
#

Yeah coll for most part? Altho iirc Bukkit sometimes create delegates

manic crater
#

i wanna give veranO123's idea a go, and see wtf happens,

lost matrix
#

Yes getInventory is always the top inventory unless there is only the players inventory present

manic crater
#

ah ok

quaint bough
manic crater
#

so then ig not then.

sterile token
analog prairie
#

Hiw can I add or remove thinks to Inventory

manic crater
#

here ill send an updated version of the gui thing and u tell me what i need to fix.

sterile token
lost matrix
gleaming grove
#
      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

sterile token
lost matrix
sterile token
#

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)??

manic crater
quaint bough
lost matrix
manic crater
lost matrix
young knoll
gleaming grove
#

but do you removed the first constructor? @manic crater

quaint bough
#

im 1.12.2 tho

manic crater
#

The thing is,

young knoll
#

I mean you can use NBT for the same thing

#

But like, update

lost matrix
lost matrix
ivory sleet
#

Yikes

sterile token
manic crater
#

I dont know how to fix this issue,

analog prairie
#

I don't understand the meaning of these functions

manic crater
analog prairie
#

What's InOffHand

lost matrix
manic crater
#

its the item in ur off hand.

ivory sleet
#

That’s like the shield hand whes

manic crater
sterile token
ivory sleet
#

Do you play minecraft? It’s quite hard to understand some of the methods if you don’t even know the content.

quaint bough
# lost matrix 🀷

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?

manic crater
#

yeah same with that,

lost matrix
manic crater
#

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..

ivory sleet
#

Jelles usually when you have a custom item you use pdc to identify it, then a factory method to create it

analog prairie
#

It is difficult for people to understand it's actual use in these English

sterile token
ivory sleet
#

the Bukkit ItemStack class is simply a middleman and a context provider

manic crater
lost matrix
ivory sleet
lost matrix
#

To also prevent bottom inv clicks

gleaming grove
analog prairie
lost matrix
#

?jd

ivory sleet
#

Scarcely

#

It’s actually really bare

#

I was considering rewriting major parts

sterile token
analog prairie
#

🀩

manic crater
#

e.setCancelled(true);

#

^ Thats to cancel events.

sterile token
#

Allrgiht thanks

manic crater
#

np

#

Now i still need help with my issue...

#

or i will cry about it

sterile token
#

What happens?

manic crater
#

I can still drag items out of the gui..

sterile token
manic crater
#

even after i cancelled it..

sterile token
lost matrix
sterile token
manic crater
light parcel
#

Can EntityDamageEvent and EntityDamageByEntity event get thrown at the same time? e.g. player hits a player

manic crater
#
@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.

gleaming grove
#
           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
lost matrix
sterile token
manic crater
#

As this doesn't work....

lost matrix
manic crater
#

Ill just make it send a msg.

sterile token
gleaming grove
#

Bukkit.getConsoleSender().sendMessage("AAA");

#

try this

sterile token
manic crater
#

it doesnt send a msg to console.

lost matrix
# sterile token

Debug it again to see if the menu is really not null.
Then check if your button reverses the cancellation of your event

gleaming grove
# manic crater ``` @EventHandler public void onInventoryClick(final InventoryClickEvent e...
@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
lost matrix
sterile token
#

I think thats why i can move the items

#

I think you havent seen the code i sent on paste

manic crater
#

It just sends "1"

#

and not "2"

lost matrix
#
          if (e.getInventory() != inv1) {
              return;
          }

I thought we established not to use identity equality with Objects...

manic crater
#

cuz i dont think the word "Doesn't" will work

brave sparrow
#

.equals

manic crater
#

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

lost matrix
ivory sleet
brave sparrow
#

For objects == just checks the memory location, not the actual object data

#

Which isn’t what you want

manic crater
#

i changed it, and i can still drag the items out

analog prairie
#

I don't know how to add item to player

#

What is Index mean

#

Slot?

manic crater
young knoll
#

Use addsItem rather than setItem

young knoll
manic crater
gleaming grove
manic crater
young knoll
#

They aren’t descriptive

manic crater
#

well in events they are.

young knoll
#

Any ide will let you autocomplete it

manic crater
#

and it is kind of really obvious on what an event is.

sterile token
#

That why

ivory sleet
#

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. 12434b1bf8604b228598a41d3936d2cd

sterile token
#

I alread recommend him learning how to use Intellij Idea Community

lost matrix
# manic crater i changed it, and i can still drag the items out

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
  }

}
manic crater
young knoll
#

Eclipse lets you autocomplete variables just fine lmao

sterile token
#

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

ivory sleet
#

The player inventory is always open (iirc)

manic crater
lost matrix
brave sparrow
#

The player’s inventory cannot be hidden if another inventory is open

#

That’s just Minecraft

ivory sleet
#

πŸ₯²

lost matrix
#

Oh thats what he meant...

manic crater
#

anyway

#

So

#

how would i go about fixing my inv issue?

sterile token
lost matrix
#

?paste

undone axleBOT
manic crater
#

yep

#

its just the dragging that causes issues,

#

like u can drag items out and i dont want that to happen...

lost matrix
manic crater
#

???

analog prairie
manic crater
#

wdym duckduck go?

lost matrix
#

google it.. -.-

manic crater
#

ik duckduckgo is a web browser.

#

just like

#

still okay whatever who cares about duckduck go for rn

late sonnet
# analog prairie

You can check the docs.. need pass a Material in the construction of itemstack

lost matrix
#

Queue a search request with the search engine that you fancy.

manic crater
#

literally when i first started out in java not ONCE did i need to ask for help regarding giving an item...

manic crater
#

yeah,

#

y

#

Even when i used intellij still didnt need help

#

thats the thing

lost matrix
#

ctrl + shift + F

#

Then paste again

manic crater
#

yooo thats cool didnt know u could do that

#

ok hold up

young knoll
#

I use the shortcut constantly

#

Along with CTRL S

manic crater
#

yeah ctrl s is really helpful

lost matrix
# manic crater https://paste.md-5.net/litixiyope.java
  1. make VoteRewards plugin private
  2. Group your fields:
    private final VoteRewards plugin;
    private final Inventory inv1;

    public EXPGui(VoteRewards instance) {
        this();
        plugin = instance;
    }
  1. rename your method EXPConfig to something like openGUI and make it return void
  2. remove the second constructor and merge them
analog prairie
manic crater
analog prairie
manic crater
analog prairie
#

I got api error

lost matrix
# manic crater
public void openGUI(HumanEntity entity) {
  entity.openInventory(inv1);
}
manic crater
#

id assume combind this(); and plugin = instance in EXPGui?

lost matrix
kind hatch
#

instance = this

analog prairie
#
[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) [?:?]
kind hatch
lost matrix
analog prairie
#

is this necessary

manic crater
analog prairie
#

Or is this only necessary to use the new version of the block

manic crater
#

.....

kind hatch
manic crater
#

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,.

analog prairie
#

In gradle

manic crater
#

then do api-version: 1.17

lost matrix
kind hatch
#

Then your api version would be 1.18

manic crater
#

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...

manic crater
kind hatch
#

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)

sterile token
#

A recommendation about APIS, would you call a project an API when the project works over an API?

manic crater
#

do i click it?

sterile token
ivory sleet
#

I mean you can have several apis inside your project

manic crater
ivory sleet
#

Which are just internal

#

To some extent, every class can be an "api"

sterile token
ivory sleet
#

Even if it’s not an interface

lost matrix
# manic crater

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.

manic crater
sterile token
lost matrix
ivory sleet
#

More a framework

#

But yes that thing would have an api

manic crater
sterile token
#

Yeah so its really strange the usage of word API on miencraft plugins

lost matrix
sterile token
#

Because for my buiness owner if told him an API he dont understand why i called API

ivory sleet
#

I mean the whole api thing is kinda softy defined

kind hatch
#

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.

ivory sleet
#

Like people know what it means

#

But as said verano

#

Every class is an api

#

Almost

manic crater
ivory sleet
#

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)

lost matrix
sterile token
ivory sleet
#

In a sense it’s probably very different from the general api term

#

Which usually is an inferred reference to a web api

sterile token