#help-development

1 messages · Page 1702 of 1

young knoll
#

Does exactchoice care about stack size

torn oyster
#

i dont think so

#

ok trying

#

nope

young knoll
#

Didn't think so

torn oyster
#

requiring 64 of an item

#

in 1.16

young knoll
#

¯_(ツ)_/¯

#

Use the event

torn oyster
#

aaaa

#

ok fine

torn oyster
young knoll
#

PrepareItemCraftEvent

torn oyster
#
    @EventHandler
    public void onCraft(PrepareItemCraftEvent e) {
        if (e.getInventory().getMatrix().length == 1) {
            ItemStack wheat = e.getInventory().getMatrix()[0];
            if (wheat.getType() == Material.WHEAT && wheat.getAmount() == 64) {
                e.getInventory().setResult(new CustomItem(Material.WHEAT)
                        .addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
                        .setName("&aCompacted Wheat")
                        .addItemFlags(ItemFlag.HIDE_ENCHANTS).getItemStack());
            }
        }
    }```
#

will that work

#

prob not

#

lmao

young knoll
#

I generally go about setting the result to null when the condition is not met

torn oyster
#

idk

young knoll
#

That is why you check if the result is the item you want

torn oyster
#

i'm a bit confused

young knoll
#

If result = yourItem and matrix != what you want {
set result to null
}

torn oyster
# young knoll If result = yourItem and matrix != what you want { set result to null }
    @EventHandler
    public void onCraft(PrepareItemCraftEvent e) {
        if (e.getInventory().getMatrix().length == 1) {
            ItemStack itemStack = e.getInventory().getMatrix()[0];
            ItemStack wheat = new CustomItem(Material.WHEAT)
                    .addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
                    .setName("&aCompacted Wheat")
                    .addItemFlags(ItemFlag.HIDE_ENCHANTS).getItemStack();
            if (itemStack.getType() == Material.WHEAT && itemStack.getAmount() == 64) {
                e.getInventory().setResult(wheat);
            } else if (e.getInventory().getResult() == wheat) {
                e.getInventory().setResult(new ItemStack(Material.AIR));
            }
        }
    }```
#

would this work

#

prob not

#

lmao

torn oyster
#

@young knoll help

#

it works

#

but when i take it out

young knoll
#

You will need to use the craftitemevent to handle that

torn oyster
#

uh

#

ok

paper viper
#

listen to another event

torn oyster
#

ok

torn oyster
#
    @EventHandler
    public void onCraft(CraftItemEvent e) {
        ItemStack compactedWheat = CustomItemManager.compactedWheat.getItemStack();
        
        if (e.getInventory().getResult() != null) {
            if (e.getInventory().getResult().equals(compactedWheat)) {
                
            }
        }
    }```
young knoll
#

Loop the matrix and remove extra items

torn oyster
# young knoll Loop the matrix and remove extra items
    @EventHandler
    public void onCraft(CraftItemEvent e) {
        ItemStack compactedWheat = CustomItemManager.compactedWheat.getItemStack();
        ItemStack air = new ItemStack(Material.AIR);
        
        if (e.getInventory().getResult() != null) {
            if (e.getInventory().getResult().equals(compactedWheat)) {
                ItemStack recipeItem = new ItemStack(Material.WHEAT, 64);
    
                for (int i = 0; i < 9; i++) {
                    ItemStack stack = e.getInventory().getMatrix()[i];
                    
                    if (stack.equals(recipeItem)) {
                        e.getInventory().getMatrix()[i] = air;
                    }
                }
            }
        }
    }```
#

this?

#

doesnt work lol

#

idk what to do

paper viper
#

Learn to debug code

#

Set breakpoints, use System.out statements

#

print out if it got past the second conditional

torn oyster
paper viper
#

good then

torn oyster
#
@EventHandler
    public void onCraft(CraftItemEvent e) {
        ItemStack compactedWheat = CustomItemManager.compactedWheat.getItemStack();
        ItemStack air = new ItemStack(Material.AIR);
    
        System.out.println("item crafted");```
#

i dont see "item crafted" in console

paper viper
#

then solve the problem. What are the reasons why the method might not be called?

torn oyster
#

i have no idea

#

maybe PrepareItemCraftEvent doesnt call CraftItemEvent?

paper viper
#

is this in the same class?

torn oyster
#

ya

#

should it not be?

paper viper
#

One second

young knoll
#

I mean no the one event does not call the other

paper viper
#

^

torn oyster
#

so i have to manually call the event?..

paper viper
#

No

torn oyster
#

no idea what im doing at this point lol

young knoll
#

It's called when the player crafts the item

torn oyster
young knoll
#

About what

torn oyster
young knoll
#

It does get called

#

When the player takes the result out

torn oyster
#

ye i did that

#

doesnt get called

#

when i take the item out

young knoll
#

Did you register it properly

torn oyster
#

yes lol

quaint mantle
#

when this screen appears it doesn't trigger any resource pack event for some reason

torn oyster
#

and the prepare works

young knoll
quaint mantle
young knoll
#

Tell that to mojang

#

You can check incoming packets to make sure

torn oyster
#

any idea why the event isnt being called

#

i know for a fact it isnt

#

cuz it doesnt system.out "item craft"

#

oh

#

if i craft a normal item

#

the event is called

#

if i craft the special item

#

it doesnt

#

work

young knoll
#

Is the special item added as a recipe

torn oyster
young knoll
#

Yes?

torn oyster
#

...

#

im literally done lol

#

i was told "just listen to the event" when trying to ask about the recipe

#

i took that as "use event instead of recipe"

young knoll
#

Add the recipe with 1 item

#

Use the event to ensure it's 64

torn oyster
#

still has 126

#

but when i place it in inventory

#

it becomes 63

#

nvm

paper viper
#

the client doesnt even send the proper resourcepack packet

#

it only sends SUCCESFUL or DECLINED

#

but nothing else

young knoll
#

What else did it used to send

paper viper
#

It used to also send succesful download

#

and failed download

young knoll
#

Ah

#

Still I don't see why it would send a packet if the user just presses okay

paper viper
#

sorry i meant "ACCEPTED"

#

not "SUCCESFUL"

#

Basically it only sends whether the user accepted or declined the pack

young knoll
#

Yes

paper viper
#

but never anything about whether the resourcepack was failed to be applied or not

young knoll
#

But this is a different screen

paper viper
#

Yes, that occurs after you try to accept the pack

#

it signfies that the client failed to download or apply the pack

young knoll
#

Ah so before it would tell you it failed

paper viper
#

Yes

#

that screen wasnt even there before either

carmine nacelle
#

Hey, sooo... I'm trying to despawn my hologram (armorstand)

    public void despawnHologram(Player player, Hologram hologram) {

        int entityID = hologram.getEntityID();
        int [] integerArray = {entityID};

        PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_DESTROY);
        packet.getIntegers().write(0, integerArray.length);
        packet.getIntegerArrays().write(0, integerArray);

        protocolManager.broadcastServerPacket(packet);
    }

I'm getting an error that No field with type int exists in PacketPlayOutEntityDestroy. The wiki.vg says that it's supposed to be an int, please help
https://i.gyazo.com/5ac260006ee98a8b9d417b1cb325b7ad.png

young knoll
#

Are you checking the right version or wiki.vg for your server version

carmine nacelle
#

im on 1.17.1

worldly ingot
#

Note that the protocol documentation != what ProtocolLib expects

#

PL acts based on the fields in the actual packet class, the protocol documents how they're transmitted across the network

carmine nacelle
#

I can't find the packets

young knoll
#

Because protocollib isn’t part of the spigot API

carmine nacelle
#

im searching for the normal packets

young knoll
#

They aren’t part of the API either

carmine nacelle
#

so then...how am I supposed to know what they are and how to use them

young knoll
#

Decompile the server code

carmine nacelle
#

bruhhh...

#

so there's zero documentation.

young knoll
#

Correct

carmine nacelle
#

nice.

young knoll
#

Modding is third party, Mojang isn’t going to document it for you

carmine nacelle
#

id expect spigot to have docs on it

#

decompile which jar?

worldly ingot
#

Packets change each version and they're implementation details. We have no reason to document them

carmine nacelle
worldly ingot
#

Yes. Or browse the BuildTools directory as it's already decompiled there

carmine nacelle
#

Which folder/directory tree do I follow?

vernal pier
carmine nacelle
#

That's just a reader though isnt it..? I need to know what fields to write to

young knoll
#

Looks like it’s just an integer array

#

And the size is handled by the game

vernal pier
#

setEntityIds( is the one

carmine nacelle
#

Yeah, I'm supplying an int[] as the second argument

#

its giving me an issue with my first

vernal pier
#

i believe the in[] is the only argument

sharp kelp
#
ShapedRecipe r = new ShapedRecipe(NamespacedKey.minecraft("flint_shovel"), item);
        r.shape(" F ",
                " S ",
                " S ");
        r.setIngredient('F', Material.FLINT);
        r.setIngredient('S', Material.STICK);
        Bukkit.getServer().addRecipe(r);
``` That's the shaped recipe in which instead of the F ingredient as Flint how do I change it to another custom Item I made?
```java
public static ItemStack FlintShard() {
        ItemStack item = new ItemStack(Material.FLINT, 1);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName("§7Flint Shard");
        // List<String> lore = new ArrayList<>();
        // lore.add("§fExample Lore");
        // meta.setLore(lore);
        meta.setCustomModelData(1);
        item.setItemMeta(meta);
        flintshard = item;
        return item;
    }
``` Also this is my custom item atm and I already Initialized it
young knoll
#

RecipeChoice.ExactChoice

sharp kelp
#

What do you mean by it?

#

Is it a type of recipe making like Shapless/Shaped recipe?

carmine nacelle
sharp kelp
#

Omg

#

use paste bin for such big errors..

carmine nacelle
#

That's after getting rid of the int I was supplying, now im only supplying int[].

sharp kelp
#

That scared me for a sec

carmine nacelle
#

...do i need to attach trigger warnings to errors now

#

apply pastebin links to your long code then homie, was longer than my error

young knoll
sharp kelp
#

Oh ookay

#

can you come to dms for a second?

young knoll
#

Why

#

This is the support chat

sharp kelp
#

Hmm well kay i just like dms better but nvm

#

So I found this

young knoll
#

Correct

sharp kelp
#

can you tell where to put it in the ingridient?

#

r.setIngredient('F', Material.FLINT);

#

Like in it

young knoll
#

Where the material is?

sharp kelp
#

I give code above but its id is flintshard

#

I made it as public static ItemStack flintshard; and Initialized it in one of the methods in the same class

#

Oh wait I understood wrong

#

Oh okay a seconddd

#

..

#

r.setIngredient('F', RecipeChoice.ExactChoice);?

young knoll
#

You’ll need a new

#

But yes

carmine nacelle
#

So..where are the packet classes located in the spigot jar? I see nothing about packets

sharp kelp
#

r.setIngredient('F', new RecipeChoice.ExactChoice(flintshard));

young knoll
#

No

#

They are located in the server jar

young knoll
#

You’ll have access to them if you are depending on the spigot jar or on spigot with a build tool

carmine nacelle
#

so the spigot is the server jar..

#

unless you mean the vanilla one?

young knoll
#

Either

carmine nacelle
#

any idea what folder?

#

jd-gui isnt coming up with anything

vernal pier
#

which jar u opening

young knoll
#

No idea

#

probably net.minecraft.server.networking or something

unkempt peak
#

does anyone know what symbol is used for colored vertical rectangles in minecraft? I've seen them on servers but this symbol 🟩(U+1F7E9) is the only thing close to what I'm looking for that i have found and the color doesn't show up.

young knoll
#

#

With chat Color

unkempt peak
#

Thanks

golden turret
#

\🟩

#

?

quaint mantle
#

oh boi java [ERROR] .... Could not pass event PlayerRespawnEvent to RisingCore v1.0 java.util.NoSuchElementException: null at java.util.TreeMap.key(Unknown Source) ~[?:?] at java.util.TreeMap.firstKey(Unknown Source) ~[?:?] at com.risingcore.events.onDeathRespawn.onRespawn(onDeathRespawn.java:71) ~[?:?]

#


    public Map<Double, String> unsorteddistance = new HashMap<>();
    public TreeMap<Double, String> sorteddistance = new TreeMap<>(unsorteddistance);

    @EventHandler
    public void onRespawn(PlayerRespawnEvent e) {
        for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
            for (int i = 0; i < locationsData.getCustomConfig().getKeys(false).size(); i++) {
                if (p.getWorld().getName().equals(locationsData.getCustomConfig().get(locationName + ".world"))){
                    unsorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
                }
            }
        }
        sorteddistance.putAll(unsorteddistance);
        String locationName = sorteddistance.remove(sorteddistance.firstKey());
        e.setRespawnLocation(locationsData.getCustomConfig().getLocation(locationName));
    }
}```
#

why... :<

young knoll
#

What is line 71

stone sinew
#

String locationName = sorteddistance.remove(sorteddistance.firstKey()); // error here
Why do you remove?

quaint mantle
#

}

#

sorry lol this

quaint mantle
#

*value

young knoll
#

You don’t need to remove for that

stone sinew
young knoll
#

Also you shouldn’t be loading this on every respawn

sharp kelp
#

coll

quaint mantle
sharp kelp
#

How to add single type of custom item to a player inventory?

#

p.getInventory().removeItem(new ItemStack[] {new ItemStack(Material.FLINT, 1) }); 
#

This is the code for removing

#

The add would use p.getInventory().addItem(); ?

#

What is the format to put items in the additem one

quaint mantle
young knoll
#

Load it on startup

sharp kelp
#

I want it to add one custom item

quaint mantle
sharp kelp
#

Hmm

#

Go to plugin yml

quaint mantle
#

oh right

sharp kelp
#

and add load: STARTUP

#

I use it as well

young knoll
sharp kelp
#

Yes I know that

#

I want to know the format

young knoll
#

?jd

sharp kelp
#

for inside the bracked

young knoll
#

Just an itemstack iirc

sharp kelp
#

bracket*

#

a se

#
p.getInventory().addItem(new ItemStack[] {new ItemStack(flintitems.flintshard)});
quaint mantle
sharp kelp
#

Will that work for removing only one item of that type?

#

@young knoll

young knoll
#

I thought you wanted to add 1

sharp kelp
#

Oh yes*

#

I got little confuse

quaint mantle
#

?help

undone axleBOT
#
CafeBabe Help Menu
*Red V3*
**__Admin:__**

selfrole Add or remove a selfrole from yourself.

**__Cleanup:__**

cleanup Base command for deleting messages.

**__Core:__**

embedset Commands for toggling embeds on or off.
info Shows info about CafeBabe.
licenseinfo Get info about Red's licenses.
mydata Commands which interact with the data CafeBabe has about...
set Commands for changing CafeBabe's settings.
uptime Shows CafeBabe's uptime.

**__Downloader:__**

findcog Find which cog a command comes from.

**__Mod:__**

names Show previous names and nicknames of a member.
userinfo Show information about a member.

**__ModLog:__**

listcases List cases for the specified member.
reason Specify a reason for a modlog case.

**__Permissions:__**

permissions Command permission management tools.

young knoll
#
  1. you don’t need the array
sharp kelp
#

will that work for adding one item?

young knoll
#
  1. flintShard is already an itemstack
stone sinew
#

@sharp kelp
Remove:
p.getInventory().removeItem(new ItemStack(Material.FLINT, 1));
Add:
p.getInventory().addItem(new ItemStack(Material.FLINT, 1));

young knoll
#

Just add that

young knoll
#

If you need to change the amount, .clone() it and setAmount 1

sharp kelp
#
@SuppressWarnings("deprecation")
    @EventHandler
    public void onPlayerAction(PlayerInteractEvent e) {
        Player p = e.getPlayer();
        Material i = p.getItemInHand().getType();
        Material b = e.getClickedBlock().getType();
        if(i == Material.FLINT) {
            if(b == Material.STONE || b == Material.COBBLESTONE || b == Material.DEEPSLATE || b == Material.END_STONE || b == Material.COBBLED_DEEPSLATE) {
                if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
                    p.getInventory().removeItem(new ItemStack(new ItemStack(Material.FLINT, 1)));
                    p.getInventory().addItem(new ItemStack(new ItemStack(flintitems.flintshard)));
                }
            }
        }
    }
#

@young knoll Correct code?

#

Its meant to give player a flint shard and remove flint from his inventory if he left clicks a stone block with flint in hand

stone sinew
young knoll
#

Also don’t supress depreciation warnings

#

They exist for a reason

sharp kelp
#
Player p = e.getPlayer();
        Material i = p.getItemInHand().getType();
        Material b = e.getClickedBlock().getType();
        if(i == Material.FLINT) {
            if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
                if(b == Material.STONE || b == Material.COBBLESTONE || b == Material.DEEPSLATE || b == Material.END_STONE || b == Material.COBBLED_DEEPSLATE) {
                    p.getInventory().removeItem(new ItemStack(new ItemStack(Material.FLINT, 1)));
                    p.getInventory().addItem(new ItemStack(new ItemStack(flintitems.flintshard)));
                }
            }
        }
#

is that correct?

young knoll
#

Also what on earth is going on here ```
p.getInventory().addItem(new ItemStack(new ItemStack(flintitems.flintshard)));

stone sinew
#

Looks right

sharp kelp
#

I made it check if a block is clicked first and then check which block

quaint mantle
young knoll
#

You are making an itemstack of an itemstack of an itemstack

young knoll
sharp kelp
#

...

young knoll
#

Please read the javadocs for a map

young knoll
#

In the code I just sent

stone sinew
young knoll
#

Surely your ide will yell at your about this

quaint mantle
#

man this work so why didnt this work too?

        ItemStack[] items = playerMap.remove(p.getUniqueId().toString());```
sharp kelp
#
Player p = e.getPlayer();
        Material i = p.getItemInHand().getType();
        Material b = e.getClickedBlock().getType();
        if(i == Material.FLINT) {
            if(e.getAction() == Action.LEFT_CLICK_BLOCK) {
                if(b == Material.STONE || b == Material.COBBLESTONE || b == Material.DEEPSLATE || b == Material.END_STONE || b == Material.COBBLED_DEEPSLATE) {
                    p.getInventory().removeItem(new ItemStack(Material.FLINT, 1));
                    p.getInventory().addItem(new ItemStack(flintitems.flintshard));
                }
            }
        }
quaint mantle
#

*this work

sharp kelp
#

or yapperyapps

#

is that correct?/

stone sinew
#

Yeah TreeMap has a .get(Key) method.

young knoll
#

All maps do

sharp kelp
#

Soo it will work how i wanted to...

#

Kay imma test it out!

young knoll
#

I’m going to wager a guess flintItems.flintShard is an itemstack

sharp kelp
#

Yep.

young knoll
#

You can’t make an itemstack using an itemstack

#

Your ide will tell you this is wrong

#

Listen to it

sharp kelp
#

If I dont add new itemstack() then it gives error

#

I use eclipse ide

young knoll
#

It shouldn’t if it’s already an itemstack

sharp kelp
#

and if I use new ItemStack(Material.FLINT, 1) it doesnt give error

young knoll
#

Correct

#

But your custom item is an itemstack

sharp kelp
#

Okay so thanks

young knoll
#

Not a material

sharp kelp
#

I understood what you mean

#

The custom item is

#

and the one i removing the flint

#

Is not

#

so i need just p.getInventory().removeItem(new ItemStack(Material.FLINT, 1));

young knoll
#

Mhm

sharp kelp
#

I need to add itemstack only for remove item flint?

#

Thats what you mean right?

young knoll
#

No?

sharp kelp
#

anyway exam time please halt the talk

quaint mantle
young knoll
#

Give it the key

quaint mantle
#

how to give the key

young knoll
#

Well you should have the key

#

Since you can’t add to a map without a key

quaint mantle
#

welp this is my key .-.

young knoll
#

So assign it to a variable so you can use it later

#

You don’t even need a map for this honestly, just loop through all locations and keep track of the closest one

young knoll
#

Have a variable for the location and one for distance

#

Every time you find a closer one, update the two variables

#

At the end of the loop you will have the closest one stored in the variable

quaint mantle
#

oh man i still cant process it

#

hmmmmmmmmmmm

#

let me try find something on the internet

#

welp

quaint mantle
# young knoll Have a variable for the location and one for distance

i think this is what you are talking about


        for (String locationName : getCustomConfig.getKeys(false)) {
            if (p.getWorld().getName().equals(getCustomConfig.get(locationName + ".world"))) {
                double distance = p.getLocation().distanceSquared(getCustomConfig.getLocation(locationName));
            }
        }```
somber hull
#

Wait, if i want to make things like a vehicle builder, and a thing that interacts with those vehicles. Wouldnt that be more of a framework rather than an API?

manic furnace
#

I have a question. When i made a installer with inno setup, can i publish it? Because auf yhe license.

eternal oxide
#

Yes, it may be used completely free of charge, even when deploying commercial applications. However if you wish to show your appreciation and support its development you can make a donation.

(Note: "Completely free of charge" must not be confused with "completely free". Inno Setup is copyrighted software, not public domain software. There are some restrictions on distribution and use; see the LICENSE.TXT file for details.)```
quaint mantle
# young knoll You don’t even need a map for this honestly, just loop through all locations and...

nah man i still think hashmap is the best

        for (String locationName : getCustomConfig.getKeys(false)) {
            if (getCustomConfig.getString(locationName + ".world").equals(p.getWorld().getName())) {
                unsorteddistance.put(p.getLocation().distanceSquared(getCustomConfig.getLocation(locationName)), locationName);
            }
        }
        TreeMap<Double, String> sorteddistance = new TreeMap<>(unsorteddistance);
        e.setRespawnLocation(getCustomConfig.getLocation((String) sorteddistance.values().toArray()[0]));```
torn oyster
#

hi im back

#

question

#

i did player.sendBlockChange(player.getLocation(), Bukkit.createBlockData(Material.COBBLESTONE);

#

works

#

but whenever someone right clicks it

#

it disappears

#

how do i prevent

young knoll
#

Listen for the interact event and send the change again

#

Or use a packet listener to stop the change going out in the first place

torn oyster
young knoll
#

Actually I don’t know if a packet would be fired for that

#

Is it replacing air or replacing another block

young knoll
#

Not sure of the interact event will be fired for that

#

You’d have to test

torn oyster
sharp kelp
#

BACK

young knoll
#

There you go then

sharp kelp
#

@young knoll This correct?

p.getInventory().removeItem(new ItemStack(Material.FLINT, 1));
p.getInventory().addItem(flintitems.flintshard);
torn oyster
#

do i add meta

#

no i cant

young knoll
#

Keep track of the location

eternal oxide
#

You can't easily. As soon as they interact the block will vanish. So yoru location may be of air already

torn oyster
#

also is checking if a block has metadata preformance costing

#

or checking if its data is instanceof ageable

young knoll
#

Hence you have to track the location

sharp kelp
#

Error

#

It seems like its occuring from the RecipeChoice.ExactRecipe

#

@young knoll

young knoll
#

Your item is null at that point

sharp kelp
#

Thats the file

#

The custom items one

#

Please wait I will check

young knoll
#

You try to use flintShard before you call the method that initializes flintShard

sharp kelp
#

Fixed

#

Instead of messing some variables I copied the flint shard item meta info code to the other methods and made small variables

#

Which was more easier

#

wooo

#

finally its doneee

#

It works just Like I want it too

#

Now i gotta work on resourcepack soon

carmine nacelle
#

Code: ```java
protocolManager.addPacketListener(new PacketAdapter(cadiaCore, ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
@Override
public void onPacketReceiving(PacketEvent event) {
PacketContainer packet = event.getPacket();
Player player = event.getPlayer();

            int interactEntityID = packet.getIntegers().read(0);

            if(packet.getEntityUseActions().read(0) != EnumWrappers.EntityUseAction.ATTACK) {
                Bukkit.broadcastMessage("test");
            }
        }
    });
Error: https://pastebin.com/raw/mzxtgAza
quasi flint
#

com.comphenix.protocol.reflect.FieldAccessException: No field with type

carmine nacelle
#

hmm, had to change "read(0)" to "readSafely(0)". Apparently it doesnt like being unsafe.

quasi flint
#

there is ur problem

#

falty reflection

#

faulty

carmine nacelle
#

nah

#

was even more dumb

#

works now tho

quasi flint
#

well what is it?

quasi flint
#

bruh

carmine nacelle
#
if(packet.getEntityUseActions().read(0) != EnumWrappers.EntityUseAction.ATTACK) {

V

if(packet.getEntityUseActions().readSafely(0) != EnumWrappers.EntityUseAction.ATTACK) {
sharp kelp
#

How to open a book when players joins and also use json in that book to run certain events/commands when clicked on text in the book

sharp kelp
quasi flint
#

dont fucking ping random people

sharp kelp
#

you were helping him ...

#

and I didnt ping you

#

Ping is like @sharp kelp

quasi flint
#

when replying smth it pings em

marble granite
#

is using an itemstacks localized name for identifying an itemstack bad practise?

#

or should i stick to using PDCs

quasi flint
#

1.16 Persistent Data Holder

#

i would use that

#

both ways are fine

marble granite
#

okay, thank you

#

i think i'll use the localized name, since its for buttons in a GUI

rotund pond
quasi flint
#

?

rotund pond
quasi flint
#

what exactly is wrong there?

#

using localized names

carmine nacelle
young knoll
#

Are you depending on it

#

In your plugin.yml

carmine nacelle
#

yes

rotund pond
quasi flint
#

stooop pinging me

#

reeeeeeeeeeeeeeeeeeeeeee

#

i hate humans

rotund pond
#

You asking a question, I answer it then you cry

#

You the only one to blame

#

Stop asking questions

quasi flint
#

please just turn off ping

young knoll
#

You should not depend on item names

quasi flint
#

when repöying

young knoll
#

Or GUI names

carmine nacelle
rotund pond
#

Mute discord server, so you will have no problem anymore

carmine nacelle
#

lmao

#

anyone have other ideas for my message?

#

For some reason it only does it with this in the code

Bukkit.broadcastMessage(packet.getEntityUseActions().read(0).toString());

(which isn't working anyway...)

young knoll
#

Would be nice if it actually had the placeholders replaced

carmine nacelle
#

Huh?

young knoll
#

It should be telling you what class and what plugin

#

Not {0} and {1}

carmine nacelle
#

ahh

#

well, it's because of me trying to get the EntityUseActions

#
        protocolManager.addPacketListener(new PacketAdapter(cadiaCore, ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
            @Override
            public void onPacketReceiving(PacketEvent event) {
                PacketContainer packet = event.getPacket();
                Player player = event.getPlayer();

                int interactEntityID = packet.getIntegers().read(0);

                if(packet.getEntityUseActions().readSafely(0) == EnumWrappers.EntityUseAction.INTERACT_AT) {
                    Bukkit.broadcastMessage("Test");
                }
            }
        });
#

I'm trying to make it ONLY trigger when right clicking an entity, and only trigger once (only mainhand)

#

this is exactly what they use in a lot of Spigot threads and it works for them..

young knoll
#

Doesn’t matter what you use as long as it’s from the plugin you depend or softdepend on

carmine nacelle
#

huh

vernal pier
#

if you have a stream and do .filter().findFirst() does it filter the whole thing and give out the first element or does it one by one and stop when find

carmine nacelle
#

Well, I got it working

                if(packet.getEntityUseActions().readSafely(0) != EnumWrappers.EntityUseAction.ATTACK) {
                    Bukkit.broadcastMessage("Test");
                }

This only triggers "Test" once, and only when right clicking my holograms so it'll do

rotund pond
vernal pier
#

i tested myself and it seems to just stop when it finds which is good

quaint mantle
#

what is the event name when player kills a mob?

tribal holly
#

hi someone know how to execute code after a click inventory event ?

#

i need to execute my code after the player has clicked

#

but the event is trigger "before" the click event

quasi flint
#

?

tribal holly
#

Like:
Player1 his looking inventory of Player2
Player2 move an item in his inventory
So my code trigger and fire a refresh inventory of Player1
But the inventory of player2 have one action late whith the player1

#

Because the code is fire before the server do the clickEvent and not after

formal prawn
#

java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class org.bukkit.entity.Entity (java.util.ArrayList is in module java.base of loader 'bootstrap'; org.bukkit.entity.Entity is in unnamed module of loader 'app')

tribal holly
#

open your eyes and read the error

#

hint : the error tell you what's wrong

formal prawn
tribal holly
#

you know what's wrong so you can fix it

#

you make a wrong cast

#

so check your cast

formal prawn
#

Entity nearbyEnt = (Entity) e.getEntity().getNearbyEntities(5, 5, 5);
if(nearbyEnt instanceof LivingEntity)
{
double distance = e.getEntity().getLocation().distanceSquared(nearbyEnt.getLocation());
if(distance<0.5)
{
nearbyEnt.setVelocity(new Location(nearbyEnt.getWorld(), 0, 100, 0).toVector());
}
else
{
nearbyEnt.setVelocity(nearbyEnt.getLocation().subtract(e.getEntity().getLocation()).toVector().multiply(1 / distance));
}
}

This should be working but doesn't work

#

Entity nearbyEnt = (Entity) e.getEntity().getNearbyEntities(5, 5, 5);

#

This line is the problem

tribal holly
#

Look your first line

#

what's returning getNearbyEntities() ?

formal prawn
tribal holly
#

respond to my question what's returning the method getNearbyEntites() ?

formal prawn
tribal holly
#

here you make a wrong cast

#

the method is returning you this type of variable java.util.List<Entity>

#

and you try to cast it with (Entity)

#

see the problem ?

formal prawn
#

List<Entity> nearbyEnt = e.getEntity().getNearbyEntities(5, 5, 5);

I am thinking this can work but I want to return only Players from those nearby Entities

tribal holly
#

better, but you will need to adapte your code

carmine nacelle
#

instanceof

formal prawn
carmine nacelle
#

Not that

tribal holly
#

do you know what is a List in java ?

formal prawn
carmine nacelle
#

Don't cast things to certain datatypes when they could return multiple different things

#

an entity will not always be a player

tribal holly
carmine nacelle
#

but a player will always be an entity.

tribal holly
#

you can cast each object of the list but not the list it self

carmine nacelle
#

if you cast a Zombie to (Player), you'll get errors.

#

but if you cast (Entity) to Player it should work, but wont get all methods for players

tribal holly
carmine nacelle
#

im tryna give hints not all the beans lol

tribal holly
#

yeah but he have some lesson to learn...

ivory sleet
#

You can cast the list, just not to a specific type of its type parameter due to type erasure

cerulean jasper
#

What would be a way to debug where my own plugin makes server lag? I haven't touched any related code to the function timings paste points at for past week... and I have no idea which line of code causes the lag, I guess I do know which file (class) it is since timings paste told me ;_;

#

It gets a bit complex because I call lots of database and rest API calls around that class.. :/

#

I checked and rest API output is fine, lol

#

Can a MySQL query be getting stuck? if so I probably need to set a timeout or something?

ivory sleet
#

Use a profiler like spark maybe

#

Anyways when it comes to database questions it should be done async

cerulean jasper
#

Does spark give more detail? not like it can see my source

ivory sleet
#

Because it’s slow

#

It’s a profiler

cerulean jasper
#

Yeah but I thought timings paste was about same

ivory sleet
#

Idk I found spark more helpful personally

cerulean jasper
#

Well anyways I am lagging up the onplayerjoin event, and some specific players get stuck and keepalive kicks them, lol

ivory sleet
#

What are you doing in the join event?

cerulean jasper
#

A bit of everything... 😦 database calls, other plugin API calls

#

even rest API call

ivory sleet
#

That’s bad

cerulean jasper
#

but it has problem today all of a sudden

#

it was working well

ivory sleet
#

Sounds reasonable why your server hangs

cerulean jasper
#

yea

lavish hemlock
ivory sleet
#

Do it in AsyncPlayerPreLoginEvent (file loading, database calls or anything with IO)

cerulean jasper
#

Yeah. but clearly something is clogged either way :c, I'll try spark now

ivory sleet
#

Bruh

#

PlayerJoinEvent callbacks are invoked on the server thread

cerulean jasper
#

Yeah, I'll check it out too, the async method

sharp kelp
#

So I have completed the base of the gui class but I want to make it that the Black glass panes appear one by one every half second in the 9 slots of the gui and after the 9th slot has a black staiend pane it will send the resourcepack to the player

#

How can I make it? Is it possible using while () and for () ? with variables? anyone got a example code or tips?

#

@ivory sleet hI! you awake right?

#

someone??? I guess least people on this tim?

quaint mantle
#

Hello I am trying to create database with SQLite but, I am getting the following error java.sql.SQLException: No suitable driver found for jdbc:sqlite:plugins/BedEffect/data/data.db

carmine nacelle
#

I'm probably just an idiot, but I'm trying to get the "Test" portion of my config

holos:
  Test:
    location: world, -337.9180889181425, 72.0, -446.26819453769014
    owner: e42b60b0-c35a-462f-a2b4-b1a9980f399e
    lines:
    - '&cTest 1'
    - '&cTest 2'
    - '&cTest 3'
    - '&cTest 4'

with ```java
for(String holoNames : getHoloConfig().getConfigurationSection("holos").getKeys(true)) {
String holoName = getHoloConfig().getString("holos" + "." + holoNames);

but I keep getting a long string for holoName instead of just "Test"
rotund pond
sharp kelp
carmine nacelle
onyx shale
#

is not hard.. you just need to be creative how you do it

sharp kelp
#

Okay so I use scheduler for timer?

rotund pond
onyx shale
#

dont stop thread

#

ever..

#

use the built in timer aka bukkit runnable

sharp kelp
#

Also I found this in a tutorial for scheduler but i dont get what this mans

#
BukkitTask task = new ExampleTask(this.plugin).runTaskLater(this.plugin, 20);
#

What does this do? smaller version of scheduler?

#

How do I use it then ??

onyx shale
#

its same as a scheduler

rotund pond
sharp kelp
#

wait oh I get ittt

#

Okiii goodd

#

soo if I use multiple schedulers in my gui it should be fine right?

rotund pond
carmine nacelle
onyx shale
#
new BukkitRunnable() {
            int startingValue = 0;
            @Override
            public void run() {
                if (startingValue==8){
                    //texture pack
                    this.cancel();
                    return;
                }
                inventory.setItem(startingValue,new ItemStack(Material.GLASS_PANE));
                startingValue++;
            }
        }.runTaskTimer(this,0,10);
gusty bough
#

Hey, is there an event for players added to scoreboard ?

onyx shale
#

dont think,theyr usually added by a code

#

not a minecraft feature

sharp kelp
#

Ooo so this basically ends the program when its 8 Hmm

#

When the variable is 8 the program ends right?

onyx shale
#

end that loop

rotund pond
sharp kelp
#

How can I forward that ending to another event which gives the player the resourcepack

rotund pond
sharp kelp
#

@onyx shale

onyx shale
#

you call your method there

sharp kelp
#

Hmm okay good enough Hmm

sharp kelp
#

the 10 means?

#

ticks?

#

or seconds?

carmine nacelle
#

first number is delay, 2nd in period. always ticks.

sharp kelp
#

period hmm

carmine nacelle
#

how often it runs.

sharp kelp
#

delay is the delay between 2 schedules ?

#

Like once run and again run after the delay

onyx shale
#

how long to wait till it starts

sharp kelp
#

and the delay is 0

#

Oh okay

#

And by period what does how often it runs means?

#

Uhm error here

#

It doesnt show any imports for it

#

Nvm fixed

sharp kelp
tardy delta
#

so (new BukkitRunnable() {...}).runTask...

onyx shale
#

you are not passing the plugin instnace

tardy delta
#

this

onyx shale
#

the "this" needs the main

sharp kelp
#

I added the (Plugin)

onyx shale
#

dont cast you need to pass the class extending JavaPlugin

sharp kelp
#

how do I do that?

tardy delta
#

get the instance of your main class

carmine nacelle
#

AyUniz, I got it. I was way overthinking it.

#

typical

#

it's 6am and ive been up all night 😄 😭

sharp kelp
#

@tardy delta I added it

#

private setup mainClass = setup.getPlugin(setup.class);

#

Its like this right?

carmine nacelle
#

nope

tardy delta
#

like that

#

with capital S

#

and its an object not a class

carmine nacelle
#

wait what

sharp kelp
#

but my class name is In lower case

#

runTaskTimer(mainClass,0,10);

#

^^ thats how right?

carmine nacelle
#
    private FirstClass firstClass;
    public MySecondClass(FirstClass firstClass) {
        this.firstClass = firstClass;
    }
tardy delta
#

that wont work

carmine nacelle
#

this is the proper way.

tardy delta
#

dependency injection...

sharp kelp
#

Hmm please wait a second

tardy delta
#

thats just the same

sharp kelp
carmine nacelle
#

that would go in the 2nd class, then in the main you'd do...

SecondClass secondClass = new SecondClass(this);
carmine nacelle
#

there's a right way, and 40 hacky ways.

carmine nacelle
onyx shale
#

last thing someone needs is to give it a value after

carmine nacelle
#

explain?

tardy delta
#

just use private final Main plugin = Main.getInstance(Main.class);

carmine nacelle
#

what I posted is the right way..

tardy delta
#

ok

onyx shale
#

mark the field as final so its always initialised once

carmine nacelle
#

making it final doesn't matter..but...thats interesting i guess

onyx shale
#

otherwise in your case you can later do firstClass = null;

#

or w/e bs

sharp kelp
#

wrong quotee

carmine nacelle
#

sigh

#

i got my ass reamed for YEARS for doing that on the forums.

#

but you do you boo

onyx shale
carmine nacelle
#

I guess I dont make mine final cause I'm not dumb enough to try assigning it twice lol

sharp kelp
#
private static setup instance;
    
    @Override
    public void onEnable() {
        PluginManager event = getServer().getPluginManager();
        event.registerEvents(new woodbreak(), (Plugin) this);
        event.registerEvents(new makeshard(), (Plugin) this);
        getCommand("customgive").setExecutor(new customgive());
        flintitems.load();
        instance = this;
    }    
    
    @Override
    public void onDisable() {
    }
    
    public static setup getInstance() {
        return instance;
    }
onyx shale
#

well you know what it does,others like this case might.. get ideeas

sharp kelp
#

Thats good?

#

Now I can get the instance in the gui class

carmine nacelle
#

patience...

sharp kelp
#

oKI

#
    public static setup getInstance(Class<setup> class1) {
        return instance;
    }
#

If I dont add that Class<Setup> CLASS1 in that brackets it gives error

carmine nacelle
#

ptsd flashbacks to when I used to static abuse

#

just use what i told you.

sharp kelp
#

wut did u told mee ??

onyx shale
carmine nacelle
#

That passes an instance of the main into the second class so you can reference it in the second class.

sharp kelp
#
private final Inventory inv;
    private setup main;

    public ResourcepackSelection() {
        inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
        init();
        this.main = main;
    }
    
    @SuppressWarnings("unused")
    private void init() {
        
        ItemStack item;        
        List<String> lore = new ArrayList<>();
        // lore.add("§7Example Lore");
        new BukkitRunnable() {
            int startingValue = 0;
            @Override
            public void run() {
                if (startingValue==8){
                    //texture pack
                    this.cancel();
                    return;
                }
                inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
                startingValue++;
            }
        }.runTaskTimer(main,0,10);
    }
#

@carmine nacelle

carmine nacelle
#

is ResourcepackSelection the name of your secondary class? looks good in there.

onyx shale
#

wut this.main = main;

carmine nacelle
#

change

private setup main;

to

private final setup main;
#

to make Stellrow happy lol

#

actually yeah you're missing something.

onyx shale
#

the IDE will force her

#

to have it in the cosntructor

#

if its final,making it dumb proof

sharp kelp
#

Yep resourcepack selection Is the name

carmine nacelle
#
    public ResourcepackSelection(Main main) {
        inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
        init();
        this.main = main;
    }
sharp kelp
#

also wut to do in main

carmine nacelle
#

"main" would be whatever the name of your main class is.

onyx shale
#

also gonna drop this here dont mind me

#

?learnjava

undone axleBOT
carmine nacelle
#

I remember being told to hang myself by people on the forums when I was still new. 😄

sharp kelp
#

I was being cursed like some people here are still doing in their minds

shadow tide
sharp kelp
#

Now @carmine nacelle What to put in main class

carmine nacelle
onyx shale
carmine nacelle
#
SecondClass secondClass = new SecondClass(this);

this would go in your onEnable() in the main.

shadow tide
#

youtube way up to you

carmine nacelle
#

edited ofc.

sharp kelp
#

In the main class?

#

Oki

shadow tide
#

No

#

No

#

No

carmine nacelle
#

Yes yes yes?

shadow tide
#

I mean this

onyx shale
#

surprised he didnt got booted by bot for spam

shadow tide
#

youtube way up to you

carmine nacelle
#

true

sharp kelp
#

@carmine nacelle

#

ResourcepackSelection rs = new ResourcepackSelection(this); this?

shadow tide
#

youtube bad for programming, I've had that stuck in my head since I started

carmine nacelle
#

yup

sharp kelp
#

@carmine nacelle

carmine nacelle
#

YouTube is great for programming tutorials, especially Spigot.

#

u dont have to keep mentioning me i have the chat open.

sharp kelp
#

ka

carmine nacelle
#

@shadow tide Check out Kody Simpson

#

Whats the error?

sharp kelp
#

says remove this in the brackets

#

the "this"

#

in the brackets

carmine nacelle
#

Send your constructor in the second class

sharp kelp
#
private final Inventory inv;
    private setup main;

    public ResourcepackSelection() {
        inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
        init();
        this.main = main;
    }
    
    @SuppressWarnings("unused")
    private void init() {
        
        ItemStack item;        
        List<String> lore = new ArrayList<>();
        // lore.add("§7Example Lore");
        new BukkitRunnable() {
            int startingValue = 0;
            @Override
            public void run() {
                if (startingValue==8){
                    //texture pack
                    this.cancel();
                    return;
                }
                inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
                startingValue++;
            }
        }.runTaskTimer(main,0,10);
    }
carmine nacelle
#

Stellrow, any easy way to convert & back to § (proper spigot way, not just String#replace)? from my configs?

sharp kelp
#

??

#

ChatColor.translatealternatecolorcodes

carmine nacelle
#

That translates the other way around, § to &, I need the opposite.

sharp kelp
#

ChatColor.translatealternatecolorcodes('&', "§7Hmmm")

carmine nacelle
#

ok so...

    public ResourcepackSelection() {
        inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
        init();
        this.main = main;
    }

This is called whenever a new instance of the class is created.

sharp kelp
#

Thats for the symbol to &

carmine nacelle
#
ResourcepackSelection rs = new ResourcepackSelection(this);

This is passing in "this" (the main class) into the second class

sharp kelp
#

soo

onyx shale
onyx shale
#

i only use &

carmine nacelle
sharp kelp
#

sooo wut do I do...

naive jolt
#

can someone give me a quick think out of making a morph plugin cause i think its easier with spigot cause. Its a lot of work with datapacks

carmine nacelle
onyx shale
#

are you passing them with ChatColor.translateAlternateColorCodes('&', toTranslate);

carmine nacelle
carmine nacelle
sharp kelp
#
private setup main;

    public ResourcepackSelection() {
        inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
        init();
        setup main;
        this.main = main;
    }
#

..

carmine nacelle
#

you still didn't do it

sharp kelp
#

I added setup main; ...

onyx shale
#

wait you are saving translated color text to config?

carmine nacelle
#
public ResourcepackSelection() {

needs to be

public ResourcepackSelection(Main main) {
sharp kelp
#

Kay good enough no more error highlights

#

Vivian

#
runTaskTimer(main,0,10);
onyx shale
sharp kelp
#

That o?

onyx shale
#

have like Utils.translateS(string) and return the translated string

sharp kelp
#

@carmine nacelle

#

oh sry for ping**

carmine nacelle
# onyx shale Worst case just make a utility method
                List<String> holoLinesBefore = holograms.getHoloLines();
                List<String> holoLinesAfter = new ArrayList<>();

                for(String holoLinesFormatted : holoLinesBefore) {
                    holoLinesAfter.add(ChatColor.translateAlternateColorCodes('&', holoLinesFormatted));
                }
``` doing that to save, then in my config..
```java
holos:
  Test:
    location: world, -337.9180889181425, 72.0, -446.26819453769014
    owner: e42b60b0-c35a-462f-a2b4-b1a9980f399e
    lines:
    - '&cTest 1'
    - '&cTest 2'
    - '&cTest 3'
    - '&cTest 4'

#

It's saving to config properly, just not loading it back with colors :p

carmine nacelle
sharp kelp
#

the scheduler

carmine nacelle
#

That will run every half second

#

send the full code again of what you're trying to do

onyx shale
#

so the lines list is getHoloLines? if yes its rather strange that it doesnt do it

sharp kelp
#

good enough it does what I wanted enough

sharp kelp
#

@carmine nacelle I want to ask one thing

#

After the scheduler

#

the value goes to 8

#

How can we detect when it goes to 8 and then trigger a event?

carmine nacelle
#

send the scheduler

sharp kelp
#
new BukkitRunnable() {
            int startingValue = 0;
            @Override
            public void run() {
                if (startingValue==8){
                    //texture pack
                    this.cancel();
                    return;
                }
                inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
                startingValue++;
            }
        }.runTaskTimer(main,0,10);
carmine nacelle
#

you don't need a return AND cancel, cancel will automatically return

#

surprised it isnt telling you that

#

just do

sharp kelp
#

good enough

carmine nacelle
#

change ==8 to <8, then setitem and increment, else cancel

#

looks cleaner

#
                new BukkitRunnable() {
                    int startingValue = 0;
                    @Override
                    public void run() {
                        if (startingValue < 8){
                            inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
                            startingValue++;
                        } else {
                            //texture pack
                            // Do other task
                            this.cancel();
                        }
                    }
                }.runTaskTimer(main,0,10);
#

that looks cleaner 🤷‍♂️

sharp kelp
#

Okay

#

so else means that when its not < that 8 ?

carmine nacelle
#

yes

#

so anything above 8 would trigger the else

sharp kelp
#

and so

#

Its basically 20 ticks is one second

carmine nacelle
#

yes

sharp kelp
#

and here are 90 ticks beind used ?

#

basically 4.5 seconds ?

carmine nacelle
#

correct

sharp kelp
#

after this if I first make a player join event

#

and then make it run this inventory event in a scheduler and also add a delay in scheduler of 4.5

#

and the scheduler runs it will send the resourcepack to player?

#

and it will run after the gui closes

carmine nacelle
#

you'd set the delay to 90 to run after 4.5s

sharp kelp
#

right?

#

Oki

#

Ye

carmine nacelle
#

try it

sharp kelp
#

and I need to add same instance in the event class as well right?

#

I gtg rn tuition will come after this kay?

#

bye

drowsy helm
#

Anyone know any simple UPnP libs? I've found WaifUPnP but it doesn't seem to work

#

just need to open/close ports on UPnP

onyx shale
#

Hmm afaik there is 1 plugin doing that

#

You might be able to look at tge source

carmine nacelle
#

Got it working, Stell.

                List<String> holoLines = getHoloConfig().getStringList("holos" + "." + holoName + ".lines");
                List<String> holoLinesFormatted = new ArrayList<>();

                for(String holoLine : holoLines) {
                    holoLinesFormatted.add(ChatColor.translateAlternateColorCodes('&', holoLine));
                }

Super weird having to do that.

sharp kelp
# carmine nacelle try it

Hey If in this gui class after the else statement if I add that when the starting value is finally 8 it will make a boolean variable true then I can pass that variable to the event class to run the event?

#

will that work? does the event check variables again and again as well? Like checking for the event action iteself

carmine nacelle
#

So, each time that your runnable runs, it runs EVERYTHING inside public void run()

#
                    public void run() {
                        if (startingValue < 8){
                            inv.setItem(startingValue,new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
                            startingValue++;
                        } else {
                            //texture pack
                            // Do other task
                            this.cancel();
                        }
                    }

This is run every half second.

sharp kelp
#

oKAY OKAY

#

But in that code

#

if after the else statement

#

I first create a public static variable which I in the else statement I give it the value true

carmine nacelle
#

dont make it static

sharp kelp
#

so that the event class it can detect wether its true or false

#

Hm?

carmine nacelle
#

static means it cannot change

sharp kelp
#

why?

#

No no

carmine nacelle
#

you can't update static variables

sharp kelp
#

But static variables can be changed in the class itself

#

I using it in one area

#

wait

#

do you mean static variable can only be givenvalue once?

carmine nacelle
#

Statics are set once then can never be changed again

#

yes

sharp kelp
#

Oh okay

sharp kelp
#

Okay then instead of static what else to use?

carmine nacelle
#

Bruh, yes?

quartz pike
#

FINAL variables are set once then can never be changed again

sharp kelp
#

vivian focus please

#

ignore others for a moment and after that continue

quartz pike
#

STATIC can be changed by every static member

carmine nacelle
#

😐

sharp kelp
#

What else to use instead of static then

carmine nacelle
#

just try it I guess.

#

if it works it works.

quartz pike
#

?learnjava

undone axleBOT
carmine nacelle
#

I sure hope that isnt directed at me bud lmao

sharp kelp
#

vivian pro and good helper

#

dont doubt him

carmine nacelle
#

Idk about pro lol

sharp kelp
#

bruh

carmine nacelle
#

he's technically right but still being a dick about it

sharp kelp
#

who am I helping?

#

Nvm but okay

quaint mantle
#
[ERROR] .... Could not pass event PlayerRespawnEvent to RisingCore v1.0
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at com.risingcore.events.onDeathRespawn.onRespawn(onDeathRespawn.java:68) ~[?:?]

this is so suck

    public Map<Double, String> sorteddistance = new TreeMap<>();```
carmine nacelle
#

mans is lurking just to call ppl out

quartz pike
#

yeah because most people here are dumb dumb

#

XD

carmine nacelle
#

Finals can only be set once yes.

#

just try to avoid static unless necessary.

sharp kelp
sharp kelp
#

@carmine nacelle Then instead of static what else to use?

carmine nacelle
#

Pretty much, yeah. You dont have to set finals right away but once you do thats the only time they can be set

#

Send the code in question

carmine nacelle
sharp kelp
#

Btw a clas which does have any data storage file with all variabls being saved
wont the variable data be gone anyway after the static variable gets a value and then the event is triggered which resets this gui class data anyway

#

static is fine in this case

#

wont be if the variables are saved somewhere however

quaint mantle
carmine nacelle
#

ok.

#

@sharp kelp working?

quaint mantle
#

        for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
            if (Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())) {
                sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);``` this code dont even work man this is so suck
carmine nacelle
#

you need to change getKeys to true

quaint mantle
#

OH WAIT

carmine nacelle
#

send the whole code man

quaint mantle
#

yes

#

man lol

carmine nacelle
#

its hard to piece this together.

quaint mantle
#

i just realized

quaint mantle
carmine nacelle
#

Well that part

#

more than 2-3 lines at a time

#

need context

quaint mantle
#
public class onDeathRespawn implements Listener {

    public Map<String, ItemStack[]> playerMap = new HashMap<>();
    public Map<Double, String> sorteddistance = new TreeMap<>();

    RisingCore plugin;
    LocationsData locationsData;
    SoulData soulData;

    public onDeathRespawn(RisingCore plugin, LocationsData locationsData, SoulData soulData) {
        this.plugin = plugin;
        this.locationsData = locationsData;
        this.soulData = soulData;
    }

    @EventHandler
    public void onRespawn(PlayerRespawnEvent e) {
        // Spawn at nearest location
        for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
            if (Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())) {
                sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
            }
        }
        System.out.print(sorteddistance.values().toArray()[0].toString());
        sorteddistance.clear();
        // Small Details
        p.sendTitle(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("title.player.respawnevent")), ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("subtitle.player.respawnevent")), 20, 60, 20);
    }
}
``` nothing really matters to this
carmine nacelle
#

send your config

quaint mantle
carmine nacelle
#

you arent saving anything to config?

quaint mantle
#
Firminus:
  ==: org.bukkit.Location
  world: world
  x: -6.5
  y: 70.0
  z: -250.5
  pitch: 0.0
  yaw: 0.0
carmine nacelle
#

What is "LocationsData"?

quaint mantle
#

it names say all lol

#

that is the custom config file i use to store locations data

carmine nacelle
#

still getting the same error of the empty map?

quasi flint
#

could someone tell me, why this throws an class not initialized error, even though i have configured my pom.xml correctly?

quaint mantle
quasi flint
#

pom.xml here

carmine nacelle
quaint mantle
carmine nacelle
#

Wherever you save the locations

quaint mantle
#

locationsdata.yml and i already show u

carmine nacelle
#

so that way the dependency loads before your plugin

quasi flint
#

ah shit here we go again

#

;V

carmine nacelle
quaint mantle
carmine nacelle
#

Well, change getKeys to true for starters

sharp kelp
#

@carmine nacelle

#
package srv.yassev.customitem.gui;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;

import srv.yassev.customitem.setup.setup;

public class ResourcepackSelection implements InventoryHolder {

    private final Inventory inv;
    private setup main;
    public static Boolean trigger;

    public ResourcepackSelection(setup main) {
        inv = Bukkit.createInventory(this, 9, "Downloading Resourcepack...");
        load();
        this.main = main;
    }
    
    @SuppressWarnings("unused")
    private void load() {
        
        ItemStack item;        
        List<String> lore = new ArrayList<>();
        // lore.add("§7Example Lore");
        new BukkitRunnable() {
            int slot = 0;
            @Override
            public void run() {                
                if (slot<8){
                    ItemStack item = createItem("", Material.BLACK_STAINED_GLASS_PANE);
                    inv.setItem(slot, item);
                    slot++;
                } else {
                    trigger = true;
                    this.cancel();
                }
                
            }
        }.runTaskTimer(main,0,10);
    }
    
    private ItemStack createItem(String name, Material m) {
        ItemStack item = new ItemStack(m, 1);
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(name);
        item.setItemMeta(meta);
        return item;
    }

    @Override
    public Inventory getInventory() {
        return inv;
    }
}
quaint mantle
sharp kelp
#

This is the final code for the gui class

#

vivian

carmine nacelle
#

yes, dear

#

im here

sharp kelp
#

When I try to get the ResourcepackSelection.getInventory()

#

It says error

carmine nacelle
#

what's the error

sharp kelp
#

and tells to change the public Inventory getInventory() to public static Inventory getInventory()

quaint mantle
carmine nacelle
#
        for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
            if (Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())) {
                sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
            }
        }
#

What is this supposed to be doing?

quaint mantle
#

so:
i loop through all the locations in locationsData

carmine nacelle
#

right

quaint mantle
#

then check if the locations world = p world

#

*player

sharp kelp
carmine nacelle
#

So, what I would recommend is structuring your config like..

locations:
    Firminus:
      ==: org.bukkit.Location
      world: world
      x: -6.5
      y: 70.0
      z: -250.5
      pitch: 0.0
      yaw: 0.0
    Firminus2:
      ==: org.bukkit.Location
      world: world
      x: -6.5
      y: 70.0
      z: -250.5
      pitch: 0.0
      yaw: 0.0
sharp kelp
#

Answer me too

quaint mantle
#

i just save it without the locations:

sharp kelp
#

VIAAAAAAAAAAVIAAAAAN

#

:< u ignore me

#

😦

#

😭

#

u should know my level of patience after helping me here and there atleast

quaint mantle
sharp kelp
#

My brain broken

chrome beacon
sharp kelp
#

wut?

carmine nacelle
# quaint mantle no locations:

You could structure it like above, or something like

locations:
    - Firminus:
      ==: org.bukkit.Location
      world: world
      x: -6.5
      y: 70.0
      z: -250.5
      pitch: 0.0
      yaw: 0.0
    - Firminus2:
      ==: org.bukkit.Location
      world: world
      x: -6.5
      y: 70.0
      z: -250.5
      pitch: 0.0
      yaw: 0.0
chrome beacon
#

Or you know make it static

carmine nacelle
#

So that would be saving a list of your locations

sharp kelp
#

My school classes got no instance and I think only teacher can add

sharp kelp
carmine nacelle
#

which is better for referencing and such.

chrome beacon
quaint mantle
sharp kelp
#

says surround with try and catch

carmine nacelle
#

That way you could do..

        for (String locationName : locationsData.getCustomConfig().getConfigurationSection("locations").getKeys(true)) { // This line here
            if (Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())) {
                sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
            }
        }
sharp kelp
#

if I do that then there is a chain of ERRORS

carmine nacelle
#
Objects.equals(locationsData.getCustomConfig().getString(locationName + ".world"), p.getWorld().getName())

As far as I can tell, this isn't doing anything at all

carmine nacelle
#

hold on

#

What is LocationsData @quaint mantle

#

I know its a class but

chrome beacon
quaint mantle
# carmine nacelle What is `LocationsData` <@456226577798135808>
public class LocationsData {

    RisingCore plugin;
    private File customConfigFile;
    private FileConfiguration customConfig;

    public LocationsData(RisingCore plugin) {
        this.plugin = plugin;
    }

    public FileConfiguration getCustomConfig() {
        return this.customConfig;
    }

    public void createCustomConfig() {
        customConfigFile = new File(plugin.getDataFolder(), "locations.yml");
        if (!customConfigFile.exists()) {
            plugin.saveResource("locations.yml", false);
        }

        customConfig = new YamlConfiguration();
        try {
            customConfig.load(customConfigFile);
        } catch (IOException | InvalidConfigurationException e) {
            e.printStackTrace();
        }
    }

    public void saveCustomConfig() {
        try {
            customConfig.save(customConfigFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

nothing such

chrome beacon
#

?paste

undone axleBOT
quaint mantle
#

just some copy from the original wiki of spigot :madman:

carmine nacelle
#

here,

        for (String locationName : locationsData.getCustomConfig().getConfigurationSection("locations").getKeys(true)) { // Would loop through "locations"
            if (locationsData.getCustomConfig().getString(locationName + ".world").equals(p.getWorld().getName())) {
                sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
            }
        }
#

this could work

sharp kelp
#

Vivi

#

an

#

mu

#

sic

carmine nacelle
#

So if you format your config like this:

locations:
    Firminus:
      ==: org.bukkit.Location
      world: world
      x: -6.5
      y: 70.0
      z: -250.5
      pitch: 0.0
      yaw: 0.0
    Firminus2:
      ==: org.bukkit.Location
      world: world
      x: -6.5
      y: 70.0
      z: -250.5
      pitch: 0.0
      yaw: 0.0

I know you arent CURRENTLY, but you COULD

quaint mantle
#

nothing actually change man, i mean i dont think adding another line of locations will work better than not having it lol

carmine nacelle
#

that's not the point here

#

the point is structuring it better

quaint mantle
#

yes, structuring it, but i dont think it really matters

carmine nacelle
#
locations: // This is the configurationsection
    Firminus: // Key
      ==: org.bukkit.Location
      world: world
      x: -6.5
      y: 70.0
      z: -250.5
      pitch: 0.0
      yaw: 0.0
    Firminus2: Key
      ==: org.bukkit.Location
      world: world
      x: -6.5
      y: 70.0
      z: -250.5
      pitch: 0.0
      yaw: 0.0
quaint mantle
#

like it will be better at look

#

but this is my custom pl (which everyone can make)

carmine nacelle
#
for (String locationName : locationsData.getCustomConfig().getConfigurationSection("locations").getKeys(true)) { 

This would loop through all of the keys of the "locations"

quaint mantle
#

that deep things actually is for loop through not only the key but the things in it too.

#

these things

carmine nacelle
#

Yeah, well dont you need that?

quaint mantle
#

i only need the name

carmine nacelle
#

so you can try it with false then I guess, but

#

I changed your entire second line in that loop

if (locationsData.getCustomConfig().getString(locationName + ".world").equals(p.getWorld().getName())) {
#

way better than trying to compare with the Object class.

quaint mantle
#

so actually nothing really change since the start? just add another configurationsection and nothing else? i dont think it will work. the second line i forgot to change back after testing

carmine nacelle
#

my brain hurts

sharp kelp
#

vivi now can u help?

#

lemme make it bleed please

carmine nacelle
#
        for (String locationName : locationsData.getCustomConfig().getKeys(false)) {
            if (locationsData.getCustomConfig().getString(locationName + ".world").equals(p.getWorld().getName())) {
                sorteddistance.put(p.getLocation().distanceSquared(locationsData.getCustomConfig().getLocation(locationName)), locationName);
            }
        }

since you're so dead set on the keeping the config how it is, here

#

I changed your comparison line and kept the top

#

try it like that

carmine nacelle
sharp kelp
#

is it bleeding?

carmine nacelle
#

whats the current issue @sharp kelp

#

yeah

quaint mantle
#

ok, but just for some notice

sharp kelp
#

can I then make it explode

quaint mantle
#

that's why i replace it with the Objects.replace

carmine nacelle
quaint mantle
#

*equasl

carmine nacelle
#

if your config isnt null you're fine, but you could do a check before that

#

or just change it to == instead of equals

sharp kelp
#

Okay so Now to get the inventory in another class Like my player join event class
I need to use the getInventory method in my code but as I was using a tutorial to make the gui it says that the get Inventory class needs to be static

carmine nacelle
#

idk if that would avoid the alert

sharp kelp
#

But making it static will break whole code

#

should I send the code?

quaint mantle
#

oooooo