#help-development

1 messages · Page 2008 of 1

quaint mantle
#

whats your host?

tender shard
#

doesn't every hoster have at least one mysql DB free?

young knoll
#

Most hosts do

quaint mantle
#

wait..

dawn hazel
quaint mantle
#

how does mysql work?

dawn hazel
#

if u buy minecraft hosting u get free databases most of the time

young knoll
#

What do you mean how does it work

tender shard
dawn hazel
#

oh great mongo shat itself again

quaint mantle
#

i own a server lol

unreal quartz
#

Problem: using mongo
Solution: don’t use mongo

dawn hazel
#

i use it for luckperms

tender shard
dawn hazel
#

nah its just that clevercloud sucks for mongo

#

but i dont have a node for databases yet

unreal quartz
#

Clever cloud

#

Worlds worst name award goes to

lavish hemlock
#

Clever cloud, dumb ground

dawn hazel
#

i dont rlly have another option lol

lavish hemlock
#

ironic that "Skygamez" is using "Clever cloud"

dawn hazel
#

its that or i buy a server for mongo

young knoll
#

Doesn’t lp support

#

Like

#

Not mongo

quaint mantle
#

@lavish hemlock just realized ur pfp is puro

#

lmao

#

cute

unreal quartz
#

It supports literally everything

quaint mantle
young knoll
#

Yours is Gordon Ramsey

#

Did I win

quaint mantle
#

yes

#

is your uhhhh

dawn hazel
quaint mantle
#

idk

lavish hemlock
#

Gordon Ramsey in basically every Kitchen Nightmares:
IT'S FOCKIN' RAAAW

quaint mantle
#

i only have the pfp

#

cause ive worn it

#

for 2 years

#

on discord

dawn hazel
#

i need to keep costs low for the development phase of the server

young knoll
#

Mine is me

#

(I’m the orange one)

lavish hemlock
#

they're both orange

young knoll
#

:(

#

I’m not that orange am I

lavish hemlock
#

Is your last name Trump or smthn?

dawn hazel
young knoll
#

Was I Donald Trump all along

lavish hemlock
#

same joke

#

@dawn hazel Have you considered just running an SQL server locally...?

young knoll
#

Step 1. Use the database your server probably provided

#

Step 2: don’t buy premium plugins

#

They suck

#

<3

lavish hemlock
#

This is true

dawn hazel
#

i need builds, graphic design, web design, all that

#

all that costs

#

wait for it

#

money

young knoll
#

You making the next hypixel

dawn hazel
#

...

#

this is just basic stuff

#

if i just put a dirt build on the server and released it

#

actually that could be cool

#

but not rn bad impression

unreal quartz
#

Have you considered armed robbery as a source of income

lavish hemlock
#

^

dawn hazel
#

LMFAO

lavish hemlock
#

Hasn't failed me yet

young knoll
#

I mean you can run a server without a website

#

Or fancy graphic design stuff

dawn hazel
#

this is my logo rn

lavish hemlock
#

wow

#

that is fucking

#

amazing

dawn hazel
#

i made it in 10 seconds using mspaint

tender shard
lavish hemlock
#

like legitimately some of the best graphic design I've ever seen

#

gg

#

I think you win at life

dawn hazel
#

this server is currently being hosted 24/7

#

my computer is not up 24/7

young knoll
#

Okay

dawn hazel
#

more like 15/7

young knoll
#

So host it on the server

dawn hazel
#

i do that

#

for the sql databases

young knoll
#

Then

dawn hazel
#

mongo tho

young knoll
#

Setup luckperms to use sql

dawn hazel
#

i probably should do that

#

but i dont rlly feel like transferring perms at the moment considering i was doing over an hours worth of debugging on a plugin all for it to be a little invisible typo on plugin.yml

young knoll
#

I bet lp has something to handle the transfer for you

dawn hazel
#

it does

#

but i have to reopen minecraft and export the perms then setup a new database on all the subservers and proxy then reload the perms

#

tedious

kind hatch
#

You don't need to open minecraft for it. Just use the console command. 😛 (lp export <fileName>)

quaint mantle
#

its 10 grand to use MySQL publically?

#

oh im sorry thats the expensive pack

#

2 grand

#

jesus fuck

wet breach
#

maybe if you want to use the enterprise version

#

which includes support and other tools

#

the community edition is free

quaint mantle
#

easy

#

or

wet breach
#

the only difference between the enterprise and community edition is the tools and support for enterprise. Otherwise functionality wise with the DB software is the exact same

quaint mantle
#

okay so basically spent 2K for dumb tools and support

#

im fine lol

#

ill use free

wet breach
#

probably should have better researched their site

#

because their site actually states this

quaint mantle
#

i saw 10 thousand dollars

#

and got scared

#

who wouldnt get scared at the site of that

#

thats INSANE

wet breach
#

If you didn't bother looking at any other pages sure I guess

#

they don't make it hidden for the community edition

quaint mantle
#

How do I get a blocks amterial?

#

*material

young knoll
#

getType

#

?jd-a

#

?jd-s

undone axleBOT
quaint mantle
#
block.getType() == Material.CHEST
#

This wouldnt work normally...

#

would it?

young knoll
#

It will

#

It returns a material enum value

quaint mantle
#

huh

#

alr

#

How would I make a chest thats locked

#

But it doesnt show that it is

young knoll
#

Cancel the interact event

quaint mantle
#
if(blockCont.get(new NamespacedKey(EmeraldsPlugin.jp,"crateMain"), PersistentDataType.STRING) == null){
                            blockCont.set(new NamespacedKey(EmeraldsPlugin.jp,"crateMain"), PersistentDataType.STRING, "basicCrate");
                            p.sendMessage(ChatColor.GREEN + "Crate is now a basic crate!");
#

Any reason why this, when clicking twice, runs successfully still?

#

It should be detecting it as not null anymre

young knoll
#

What is blockCont

quaint mantle
#

yes btw its a chest

young knoll
#

Do you update it

quaint mantle
#

wdym update it

young knoll
#

state.update

quaint mantle
#

ty

#

@young knoll Last question: How would I prevent somebody from closing a gui for X amount of time?

young knoll
#

Use a runnable

#

And reopen it if it’s close

#

Or use the close event to reopen it

quaint mantle
young knoll
#

InventoryCloseEvent

quaint mantle
young knoll
#

Player.getOpenInventory

quaint mantle
#

does it return null if its closed

#

or

young knoll
#

It returns the players inventory if its closed

quaint mantle
#

how would i check if its actually closed

#

p.getOpenInventory().equals(gui)?

#

this is gui btw: Inventory gui = Bukkit.createInventory(p, 9*5, crateType);

quaint mantle
young knoll
#

Should work

#

Idk if it returns a inventory or a view

ornate patio
#

how can i get rid of this "When in Main Hand" stuff

#

and "Unbreakable"

earnest forum
#

item flags

ornate patio
#

which flag?

earnest forum
#
ItemStack item = new ItemStack(Material.DIAMOND_SWORD, 1);
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
item.setItemMeta(meta);
young knoll
#

Hide attributes

#

I think hide unbreakable is another one

young knoll
#

What version is this

ornate patio
young knoll
#

Why a hoe

ornate patio
#

so i can have custom textures

young knoll
#

Use something edible, it will make life much easier

ornate patio
#

for each damage value

young knoll
#

You can add custom textures to anything

#

Custom model data

quaint mantle
#

@young knoll Small question: How do i constantly update and open a gui

#

like an animation

ornate patio
#

with a hoe you can have like 3000 custom textures on one item though

quaint mantle
#

ig you could say

young knoll
#

Yeah

#

And with custom model data you can have 999,999

ornate patio
#

wait what

young knoll
young knoll
#

In spigot you simply use ItemMeta#setCustomModelData

quaint mantle
ornate patio
#

oh damn

#

but using a netherite hoe still wouldn't hurt right?

young knoll
#

You can set a single item

ornate patio
#

no one uses those

young knoll
#

Or use setcontents

#

Yes but you can’t drink a hoe

ornate patio
#

oh

young knoll
#

Using something already edible will give you the nice animation

ornate patio
#

i guess so

young knoll
#

And then you can just intercept the PlayerConsumeItemEvent

ornate patio
#

i can use like a water bottle then right

young knoll
#

Sure

ornate patio
#

i'm trying to make the alcohol have a certain ml of liquid in it

#

so you'll be able to drink it like 20 times before it disappears

#

thing is that means i'm gonna have to have a custom model for empty bottles and water bottles

#

for that split second when the bottle is empty before the server replaces with a water bottle

young knoll
#

?

ornate patio
#

like

#

i can have an event

#

when the player consumes the water bottle

#

it'll replace the item in their hand with a new one

young knoll
#

Why replace it

ornate patio
#

what else can i do

young knoll
#

Just edit the current one

#

And cancel the event so it doesn’t disappear

ornate patio
#

because when the water bottle is consumed it turns into a glass bottle

ornate patio
quaint mantle
#

@young knoll How would I select a random object in a list like so?

#
Crates:
  basicCrate:
    fullName: Basic Crate
    itemList:
      DIAMOND:
        Type: Regular
        Amount: 5
      EMERALD:
        Type: Regular
        Amount: 5
      NETHERITE_INGOT:
        Type: Regular
        Amount: 1
#

Each have equal chances btw

young knoll
#

You can read the keys of itemList into a collection

#

And then get a random element from the collection

quaint mantle
#

Cant find anything online.

#
private static Object getRandom(String crateType){
        Object conf = EmeraldsPlugin.jp.getConfig().get("Crates." + crateType + ".itemList");
        Object item = null;

        return item;
    }
ornate patio
young knoll
#

getConfigurationSection(Crates.basicCrate.itemList).getKeys(false)

#

“Plugins should check that hasCustomModelData() returns true before calling this method.”

#

So who knows, might throw an error

quaint mantle
ornate patio
#

thanks

young knoll
quaint mantle
young knoll
#

Also I noticed a javadoc error

#

Yay free PR

#

Heh

quaint mantle
#

@young knoll Last question, is there a way I can get an enum based on a string?

#

Example: Material[item]

#

or smth like that

young knoll
#

Material.matchMaterial

quaint mantle
#

@young knoll returns null

#
private static ItemStack getRandom(String crateType){
        FileConfiguration conf = EmeraldsPlugin.jp.getConfig();
        ItemStack item = new ItemStack(Objects.requireNonNull(Material.matchMaterial(conf.getConfigurationSection("Crates.basicCrate.itemList").getName())), 1);;

        return item;
    }
#

printed in console as a test first btw

young knoll
#

And?

quaint mantle
#

it returns null lol

#

like i said

#

and errors

young knoll
#

You are getting the name of the section

quaint mantle
#

Yes?

#

DIAMOND:
Type: Regular
Amount: 5
EMERALD:
Type: Regular
Amount: 5
NETHERITE_INGOT:
Type: Regular
Amount: 1

young knoll
#

The name of the itemList section

quaint mantle
#

As in its returning DIAMOND

young knoll
#

Is itemList

quaint mantle
#

... oh

#

wait so

#

then how would I get

#

DIAMOND

#

or EMERALD

#

or etc

young knoll
#

Crates.basicCrate.itemList.DIAMOND

quaint mantle
#

yea but

young knoll
#

That’s why I told you to read all the keys into a collection

quaint mantle
#

OH

young knoll
#

So you’ll have a list of DIAMOND, EMERALD, etc

quaint mantle
#

But that gets ALL keys correct?

#

So how would I select a random one

young knoll
#

Put them in a list

#

Get random item from list

quaint mantle
young knoll
#

Google it

#

That’s a basic java question

ancient jackal
#

is this basically a hashmap computeIfPresent but with a put after it? I tried computeIfPresent but couldn't return

            HashMap<Integer, Integer> hm = ...
            if(hm.containsKey(target-n)) {
                return new int[]{hm.get(target-n), i};
            } else {
                hm.put(n, i);
            }```
young knoll
#

What

#

ComputeIfAbsent

ancient jackal
#

but if hm.containsKey

#

then return

young knoll
#

Or just get the value once and check if it’s null

quaint mantle
#

@young knoll it errors, now at randomSelection

FileConfiguration conf = EmeraldsPlugin.jp.getConfig();
        Set<String> list = conf.getConfigurationSection("Crates.basicCrate.itemList").getKeys(true);

        int size = list.size();
        int randomSelection = new Random().nextInt(size);
        int i = 0;
        for(String obj : list){
            if (i == randomSelection) {
                return new ItemStack(Material.getMaterial(obj), 1);
            }
            i++;
        }

Caused by: java.lang.IllegalArgumentException: bound must be positive
11.03 04:33:59 [Server] INFO at hidingthis.Crate.getRandom(Crate.java:21) ~[?:?]

ancient jackal
#

the code works, it was an O(n) solution to something I'm working on but I was wondering something that doesn't really matter ig

young knoll
#

You know you can just do

#

List.get(random number)

#

Well, if you use a list instead of a set

quaint mantle
#

it doesnt let me

#

it errors

ornate patio
#

so i've tried to use a resource pack to edit the potion's texture and decided to use a gold ingot as a test...

I've just created pink bar.

young knoll
#

Pig ingot

young knoll
ornate patio
quaint mantle
#

Unfixable

ancient jackal
#

bound is size in nextInt(size)

young knoll
#

Oh weird it returns a set and not a collection

#

You can just do list blah = new ArrayList(get the stuff here)

ornate patio
#

is there a way to make a potion "colorless"? Because I think thats what is making my textures pink

young knoll
#

I don’t think you can get rid of the glow

#

Not sure

quaint mantle
#

also @young knoll still no workie

#
FileConfiguration conf = EmeraldsPlugin.jp.getConfig();
        ArrayList<String> list = new ArrayList<String>();
        list.addAll(conf.getConfigurationSection("Crates.basicCrate.itemList").getKeys(false));

        System.out.println(list);

        return new ItemStack(Material.getMaterial(list.get(new Random().nextInt(list.size()))), 1);
#

I did what you said

#

Its at return it doesnt work

iron tundra
#

I can't seem to find the correct api to make a wolf that I spawned via a item become tamed by the item owner if someone can help guide me to the correct api I would appreciate it!

young knoll
#

Tamable#setOwner

young knoll
quaint mantle
# young knoll Doesn’t work isn’t helpful

11.03 04:47:15 [Server] INFO Caused by: java.lang.IllegalArgumentException: bound must be positive
11.03 04:47:15 [Server] INFO at java.util.Random.nextInt(Random.java:322) ~[?:?]
11.03 04:47:15 [Server] INFO at me.emerald.emeraldsplugin.ui.Crate.getRandom(Crate.java:25) ~[?:?]

#

Error

#

also, list prints out []

young knoll
#

That means the list is empty

quaint mantle
#

Well, why?

young knoll
#

Looks right to me

#

Assuming the file you sent earlier is accurate

quaint mantle
#
Crates:
  basicCrate:
    fullName: Basic Crate
    itemList:
      DIAMOND:
        Type: Regular
        Amount: 5
      EMERALD:
        Type: Regular
        Amount: 5
      NETHERITE_INGOT:
        Type: Regular
        Amount: 1
#

Did I do something wron here maybe?

young knoll
#

Looks fine

quaint mantle
#

Here is an updated thingy @young knoll

private static ItemStack getRandom(String crateType){
        FileConfiguration conf = EmeraldsPlugin.jp.getConfig();
        ArrayList<String> list = new ArrayList<String>();
        list.addAll(conf.getConfigurationSection("Crates." + crateType + ".itemList").getKeys(false));

        System.out.println(conf.getConfigurationSection("Crates." + crateType + ".itemList").getKeys(false));

        return new ItemStack(Material.getMaterial(list.get(new Random().nextInt(list.size()))), 1);
    }
#

It errors at new Random().nextInt(list.size())

#

for some reason

young knoll
#

Yeah then list is empty

quaint mantle
#

tested list.size

#

why?

young knoll
#

Not sure

#

Make sure crateType is right

quaint mantle
#

cause it be unable to find the correctpath

waxen plinth
#

That's kind of a bad way to do it

#

It'll refetch every time

#

Doing an O(n) operation just to fetch one element which should be O(1)

#

Just load it once and then get a random element when the method is called

quaint mantle
young knoll
#

Do it on startup

quaint mantle
#
public class Crate {
    private static ItemStack getRandom(String crateType){
        ArrayList<String> list = new ArrayList<String>();
        list.addAll(EmeraldsPlugin.jp.getConfig().getConfigurationSection("Crates." + crateType + ".itemList").getKeys(true));

        System.out.println(list);
        System.out.println(EmeraldsPlugin.jp.getConfig().getConfigurationSection("Crates." + crateType + ".itemList"));
        System.out.println(EmeraldsPlugin.jp.getConfig().getConfigurationSection("Crates." + crateType + ".itemList").getKeys(true));

        return new ItemStack(Material.getMaterial(list.get(new Random().nextInt(list.size()))), 1);
    }
waxen plinth
#

Just load it and store it somewhere rather than refetching every time

quaint mantle
#

Oh.

waxen plinth
#

That system also doesn't allow for any kind of weighting other than by adding duplicates

young knoll
#

I mean that’s just the start of issues

#

But hey, learning is learning

quaint mantle
#

What if i need to add some sort of wait or smth for it to addAll?

#

But im not sure, my brain hurts e.e

young knoll
#

You do not

quaint mantle
#

Any way to do my script better then?

young knoll
#

Several but it would probably just be confusing to spew them all at you

quaint mantle
young knoll
#

Everyone starts somewhere

#

I would learn more java before tackling spigot, but I can’t really tell you what to do

quaint mantle
#

i tackle hard stuff so that i challenge myself, but ask for help

#

i learn more in a shorter time, and recall it better

#
  • you cant "learn" java without a reason to
#

so trying to make a minecraft plugins a good way to actually learn java

#

per say

young knoll
#

Disagree

#

Spigot is a third party API, you don’t need to be introducing it until you understand enough of the first party APIs

quaint mantle
#

Personal preference

#

Challenge will both let me learn more in a shorter time, recall it better, and its fun to me

#

I like a challenge

young knoll
#

The problem is you are asking dozens of questions in here

#

A lot of which you should already know, or can find on the javadocs

quaint mantle
#

Which many of the questions I ask are so I dont have to do trial and error, if you noticed

hasty prawn
#

That is part of learning how to do it though

quaint mantle
#

Cause it takes me 5 minutes to:
Saving the plugin build
Insert the plugin again
Reloading the server

#

Its WHY ive been asking like 80 questions

#

There have only been like 3 where its not related to trial and error

#

And was an actual situation

#

Otherwise I have been learning lol

hasty prawn
#

And that's why you have your IDE build directly to the plugin folder so all you have to do is build and /reload 😄

quaint mantle
#

thats the issue

hasty prawn
#

You can still have it auto-upload I believe.

quaint mantle
#

Sadly only if you pay 15 extra dollars.

#

Which is kinda BS in my opinion.

hasty prawn
#

And honestly, for testing plugins, it's a good idea to use a localhost server for quick testing.

quaint mantle
#

I tried

hasty prawn
#

Yikes lol

quaint mantle
#

It only doesnt do that in 1.12.2 or lower

#

And my plugin is 1.18.1

hasty prawn
#

My laptop is only using 18% of CPU right now and I have Minecraft, Server, IDE, Firefox, Discord all open

iron tundra
#

I am trying to make when I spawn this wolf entity in, it automatically becomes the owner of the item holder. If you can explain what I did wrong I would appreciate it!

            event.getPlayer().getWorld().spawnEntity(event.getPlayer().getLocation(), EntityType.WOLF).setCustomName(ChatColor.GOLD + "Queen's Guard");
            Wolf w = (Wolf) event.getPlayer().getNearbyEntities(1,1,1);
            if (Objects.equals(w.getCustomName(), ChatColor.GOLD + "Queen's Guard")) {
                w.setOwner(event.getPlayer());
            }
hasty prawn
#

What are your computer specs

quaint mantle
#

so i mean its a good pc

#

*using 20%

hasty prawn
#

A server shouldn't be killing you then, should be fine.

#

Definitely not 80%...

quaint mantle
#

I have 0 reason why it does.

#

It takes up 80% during its loading.

hasty prawn
#

Oh, yeah. That happens.

quaint mantle
#

Thats normal?

hasty prawn
#

Yes.

quaint mantle
#

Well damn xD

hasty prawn
#

Chunk loading is extremely CPU intensive, once it starts, should be fine.

#

Although I've noticed it's faster in 1.18.2 for some reason, or it seems to be.

young knoll
#

You already have the wolf returned from the spawn method

quaint mantle
#

:P

hasty prawn
#

1.18.1 I assume you mean?

ornate patio
hasty prawn
#

I mean 1.18.1 should still be fine, startup is just longer.

ornate patio
#

i don't even know where else to ask

hasty prawn
#

I guess potion ItemStack takes in a color and just applies it to whatever model it's given

#

On the client ^

ornate patio
#

it's just slapping the potion color on top of the texture

hasty prawn
#

You wouldn't be able to stop that probably, maybe there's some color that wouldn't do that, not sure.

quaint mantle
ornate patio
#

what have i done

#

wait hold up a minute tho

#

those actual gold ingots are slow falling potions

#

interesting

smoky oak
#

aint there a better option to do that

#

CustomModelData iirc?

ornate patio
#

right now im just trying to get rid of the color

hasty prawn
#

Could you use a water bottle instead of a potion

smoky oak
#

ah you're doing the textures rn then

ornate patio
hasty prawn
#

Or wait hang on

ornate patio
#

how can i extract the color of the slow falling potion..??

#

if i can somehow make the potion color to that

#

it might fix it

smoky oak
#

color picker?

ornate patio
#

i mean

smoky oak
#

screenshot it and put in a image editer

young knoll
#

The wiki should have it

hasty prawn
#

PotionMeta#getColor

young knoll
#

That too

ornate patio
young knoll
#

#F7F8E0

ornate patio
#

potions are just one item

young knoll
#

Yes

ornate patio
#

you set the effect/color using the meta

hasty prawn
#

If you want the color to go away, I'd assume PotionMeta#setColor(null)

ornate patio
young knoll
#

Don’t think that’s valid

ornate patio
hasty prawn
#

Yeah it's Nullable

young knoll
#

Hmm

#

Well it still has to be some color

hasty prawn
#

It's probably inheriting the color from the CustomPotionEffects if the color is null

#

Which have un-modifiable colors I think

#

?

#

Maybe

ornate patio
#

for org.bukkit.Color

young knoll
#

Convert it to rgb

smoky oak
#

they're rgb values

ornate patio
#

you can't use hex?

#

damn

young knoll
#

I mean maybe you can

#

But why

smoky oak
#

#RRGGBB i think

young knoll
#

Yep

ornate patio
#

well

smoky oak
#

being hex two numbers can be any value from 0 to 255

ornate patio
young knoll
#

Just throw it on a website to convert it

#

Yep

ornate patio
#

it looks very close to white..

#

maybe just making the potion white will do it

#

LETS GOOO

#

white potions don't affect the color

#

¯_(ツ)_/¯

young knoll
#

Yum

#

Solid gold bars

hasty prawn
#

LOL

young knoll
#

Maybe I should make custom textures for my drinks

#

Currently I just used coloured potions

quaint mantle
#

So uhh cool

#

*coll

#

I did research on randomization

ornate patio
quaint mantle
#
private static ItemStack getRandom(String crateType){
        ItemStack item = null;
        ArrayList<String> list = new ArrayList<String>(EmeraldsPlugin.jp.getConfig().getStringList("Crates." + crateType + ".itemList"));
        
        for (int i = 0; i < list.size(); i++) {
            int index = (int)(Math.random() * list.size());

            System.out.println("Selected");

            item = new ItemStack(Objects.requireNonNull(Material.getMaterial(list.get(index))), 1);
        }

        System.out.println(item);

        return item;
    }
#

Idk it still doesnt work lol

#

Doesnt error

#

But it doesnt actually, select something

young knoll
#

Well if the list is empty

#

Nothing will work

ancient jackal
young knoll
#

You don’t need any fancy loops, .get with a random index is fine

#

You get an error because the list is empty

#

And you can’t get a random number between 0 and 0

quaint mantle
#

its nothing

smoky oak
#

random but constricted to 0-(bound-1)

#

random numbers for a computer are doubles between 0 and 1 inclusive

#

so calling nextInt(int bound) translates to return (integer) Math.random() * bound

quaint mantle
#

well i have a bigger issue to fix

#

"Why the list is empty"

smoky oak
#

cant help you rn

somber hull
#

26

#

👍

somber hull
#

opr

#

liek

#

wachu mean by that?

quaint mantle
smoky oak
#

?notworking

undone axleBOT
#

"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.

quaint mantle
smoky oak
#

just paste your question

#

dont just ask if someone can help you

quaint mantle
#

im trying to fix it first

#

and was waiting for a reply

smoky oak
#

print out list.size

#

is it 0?

quaint mantle
#

sec, i found a small workaround

#

seeing if it works

#

@smoky oak Any reason why this isnt working?

Function:

private static ItemStack getRandomItem(String crateType){
        Integer totalWeight = 0;
        Random rand = new Random();

        for(Map<?, ?> item: EmeraldsPlugin.jp.getConfig().getMapList("Crates" + crateType)){
            totalWeight += (Integer) item.get("Weight");
        }

        double r = rand.nextDouble() * totalWeight;

        for(Map<?, ?> item: EmeraldsPlugin.jp.getConfig().getMapList("Crates" + crateType)){
            if ((Integer) item.get("Weight") >= r) {
                return new ItemStack(Material.getMaterial((String) item.get("Item")), Integer.parseInt((String) item.get("Count")));
            }
        }

        return null;
    }

Config:

Crates:
  basicCrate:
      0:
        Item: DIAMOND
        Weight: 25
        Count: 5
      1:
        Item: EMERALD
        Weight: 5
        Count: 25
smoky oak
#

you're missing the period at the end of the string you call the config with

quaint mantle
#

i love my life

smoky oak
#

it needs to be "Crates."

quaint mantle
#

Fixed, still not working however

#

Did I type something wrong or

#

It seems to be returning 0.0 for total weight

smoky oak
#

FileConfiguration has specific methods to get ints

#

mayb you have to use those

quaint mantle
#

so the only valid functionality

#

is get

#

not getInteger

smoky oak
#

refractor that code then

#

get the collection of keys of the file config

#

iterate over it

#

call the getInt method

#

*configurationSection i mean

quaint mantle
smoky oak
#
ConfigurationSection cfs = EmeraldsPlugin.jp.getConfig.getConfigurationSection("Crates."+crateType);
for(String s : cfs.getKeys()){
  totalWeight += cfs.get(s+".Weight");
}```
no guarantee
quaint mantle
# smoky oak ```java ConfigurationSection cfs = EmeraldsPlugin.jp.getConfig.getConfigurationS...

I did this:

Integer totalWeight = 0;
        Random rand = new Random();

        ConfigurationSection cfs = EmeraldsPlugin.jp.getConfig().getConfigurationSection("Crates."+crateType);

        for(String s: cfs.getKeys(false)){
            totalWeight += (Integer) cfs.get(s + ".Weight");
        }

        double r = rand.nextDouble() * totalWeight;

        for(String s: cfs.getKeys(false)){
            if ((Integer) cfs.get(s + ".Weight") >= r) {
                return new ItemStack(Material.getMaterial((String) cfs.get(s + ".Name")), Integer.parseInt((String) cfs.get(s + ".Amount")));
            }
        }
#

nope

smoky oak
#

did totalWeight change?

quaint mantle
smoky oak
#

you're trying to convert object to int

#

that does not necessarily work

#

totalWeight += cfs.getInt(s+".Weight");

#

call getInt

quaint mantle
#

kk

#

@smoky oak hold on gotta reload my shockbyte server

#

it crashed after 24 hours lol

smoky oak
#

my server reloads itself automatically at 2AM

quaint mantle
#

oh nice

#

@smoky oak guess what

#

its still null

#
private static ItemStack getRandomItem(String crateType){
        int totalWeight = 0;
        Random rand = new Random();

        ConfigurationSection cfs = EmeraldsPlugin.jp.getConfig().getConfigurationSection("Crates."+crateType);

        assert cfs != null;
        for(String s: cfs.getKeys(false)){
            totalWeight += cfs.getInt(s + ".Weight");
        }

        double r = rand.nextDouble() * totalWeight;

        for(String s: cfs.getKeys(false)){
            if (cfs.getInt(s + ".Weight") >= r) {
                return new ItemStack(Material.getMaterial(cfs.getString(s + ".Name")), cfs.getInt(s + ".Amount"));
            }
        }

        return null;
    }
smoky oak
#

try printing out cfs.getKeys()

#

maybe that's null and as such doesnt call the loop

quaint mantle
#

@smoky oak

11.03 07:20:24 [Server] Server thread/INFO 0.0 - 0
11.03 07:20:24 [Server] Server thread/INFO []
11.03 07:20:24 [Server] Server thread/INFO []

System.out.println(r + " - " + totalWeight);
        System.out.println(cfs.getKeys(false));
        System.out.println(cfs.getKeys(true));
#

why

#

it should be showing them perfectly fine

#

hi guys

#
java.lang.NoClassDefFoundError: net/minecraft/world/entity/npc/WanderingTrader
        at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?]

has this changed in 1.18.2?

smoky oak
#

maybe how you calll the method is an issue

quaint mantle
smoky oak
#

what i mean is that crateType should be equals to "basicCrate" exactly

#

if its not

#
null
quaint mantle
#

it is

quaint mantle
#

if this means it exists then yea its not null

smoky oak
#

sounds about right

quaint mantle
#
System.out.println(EmeraldsPlugin.jp.getConfig().get("Crates."+crateType));
smoky oak
quaint mantle
#

just wait

#

it can take a bit

#

well just wait for now

#

for a reply

smoky oak
#

wait a sec, how the fuck is cfs existing but getKeys returns nothing

quaint mantle
#

i dont know

#

just saying, ive NEVER been this angry while coding

#

i want to scream in agony, its pissing me off

#

bro

#

you're returning null 😭

#
        int totalWeight = 0;
        Random rand = new Random();

        ConfigurationSection cfs = EmeraldsPlugin.jp.getConfig().getConfigurationSection("Crates."+crateType);

        assert cfs != null;
        for(String s: cfs.getKeys(false)){
            totalWeight += cfs.getInt(s + ".Weight");
        }

        double r = rand.nextDouble() * totalWeight;

        for(String s: cfs.getKeys(false)){
            if (cfs.getInt(s + ".Weight") >= r) {
                return new ItemStack(Material.getMaterial(cfs.getString(s + ".Name")), cfs.getInt(s + ".Amount"));
            }
        }

        return null;
    }
#

read your code haha

#

?

#

so?

#

WAIT

#

💀

#

HOLD ON

#

💀 💀 💀 💀 💀 💀 💀 💀

#

THERE IS NO WAY I OVERLOOKED THAT

#

💀 💀 💀 💀 💀 💀 💀 💀💀 💀 💀 💀 💀 💀 💀 💀💀 💀 💀 💀 💀 💀 💀 💀💀 💀 💀 💀 💀 💀 💀 💀💀 💀 💀 💀 💀 💀 💀 💀💀 💀 💀 💀 💀 💀 💀 💀💀 💀 💀 💀 💀 💀 💀 💀💀 💀 💀 💀 💀 💀 💀 💀💀 💀 💀 💀 💀 💀 💀 💀

#

all good brother

#

we've been there done that

raw ibex
#

why would you return null in the first place lmao

quaint mantle
#

autofill

#

just happenjs

#

also can someone help me

#

i updated to 1.18.2

#

but

raw ibex
#

yea with what

quaint mantle
#

java.lang.NoClassDefFoundError: net/minecraft/world/entity/npc/WanderingTrader at java.lang.ClassLoader.defineClass1(Native Method) ~[?:?]

smoky oak
#

if that doesnt fix it see if EmeraldsPlugin.jp.getConfig.getConfigurationSection("Crates.basicCrate.0.Weight") returns the actual number

quaint mantle
#

very confused

raw ibex
#

have you tried to google the error

quaint mantle
#

yeah...

#

its pretty self explanatory

#

ive tried a few things but im just stumped

raw ibex
#

no i mean google it to see if someone else had the same problem

raw ibex
quaint mantle
#

Like this correct?

#

maybe my mapping?

#
private static ItemStack getRandomItem(String crateType){
        int totalWeight = 0;
        ItemStack item = null;
        Boolean found = false;
        Random rand = new Random();

        ConfigurationSection cfs = EmeraldsPlugin.jp.getConfig().getConfigurationSection("Crates."+crateType);

        assert cfs != null;
        for(String s: cfs.getKeys(false)){
            totalWeight += cfs.getInt(s + ".Weight");
        }

        double r = rand.nextDouble() * totalWeight;

        System.out.println(EmeraldsPlugin.jp.getConfig().getConfigurationSection("Crates."+crateType));

        for(String s: cfs.getKeys(false)){
            if (cfs.getInt(s + ".Weight") >= r && !found) {
                item = new ItemStack(Material.getMaterial(cfs.getString(s + ".Name")), cfs.getInt(s + ".Amount"));
            }
        }

        return item;
    }
raw ibex
#

?paste

undone axleBOT
raw ibex
#

whoops

quaint mantle
#

nice

#

wait do you know where to find the mapping for each jar release

#

or whatever

raw ibex
#

don't you go into um

#

the

#

external libs

quaint mantle
#

i meanthe url

#

to find the tag

raw ibex
#

oh

#

idk tbh

quaint mantle
#

like i just manually changed it from 1.18.1 to 1.18.2

raw ibex
#

OH

quaint mantle
#

have a feeling maybe something chjanged

raw ibex
#

yea probably

quaint mantle
#

Nope, still not working lol

#

Code:

private static ItemStack getRandomItem(String crateType){
        int totalWeight = 0;
        ItemStack item = new ItemStack(Material.TNT, 1);
        Boolean found = false;
        Random rand = new Random();

        ConfigurationSection cfs = EmeraldsPlugin.jp.getConfig().getConfigurationSection("Crates."+crateType);

        assert cfs != null;
        for(String s: cfs.getKeys(false)){
            totalWeight += cfs.getInt(s + ".Weight");
        }

        double r = rand.nextDouble() * totalWeight;
        
        for(String s: cfs.getKeys(false)){
            if (cfs.getInt(s + ".Weight") >= r && !found) {
                item = new ItemStack(Material.getMaterial(cfs.getString(s + ".Name")), cfs.getInt(s + ".Amount"));
            }
        }

        return item;
    }

Config:

Challenges:
  BlockDamage: false
  Hunger: false

BlockBreakList:
  OBSIDIAN: 10.0
  DIAMOND_ORE: 10.0
  EMERALD_ORE: 10.0
  LAPIS_ORE: 7.0
  GOLD_ORE: 7.0
  REDSTONE_ORE: 7.0
  IRON_ORE: 5.0
  COAL_ORE: 3.0

Crates:
  basicCrate:
      DiamondReward:
        Name: DIAMOND
        Weight: 25
        Amount: 5
      EmeraldReward:
        Name: EMERALD
        Weight: 5
        Amount: 25
#

Maybe I typed my YML file wrong

#

or smth idk

#

No errors, its returning TNT, not the actual item I want btw

#

(I set TNT as a base so that errors dont occur)

raw ibex
#

?paste @quaint mantle

undone axleBOT
raw ibex
#

What's so hard

#

well bruv

smoky oak
#

short question, buildtools says 1.18.2 is out but latest generates 1.18.1
is 1.18.2 finalized already?

raw ibex
#

you can't access something defined in a method

#

you're defining item twice

quaint mantle
raw ibex
#

remove the first item

#

the TNT

quaint mantle
#

alright

raw ibex
#

is the ide giving you an errorr?

quaint mantle
#

Yes

#

It is

raw ibex
#

where?

quaint mantle
#

At return item

#

'Variable 'item' might not have been initialized'

raw ibex
#

exactly

#

wait

#

is it red or yellow

quaint mantle
#

Red

raw ibex
#

Ok

#

It's because you can't access variables outside a method

quaint mantle
#

has anyone got the mapping guide

#

i cant find it

#

so should I public it?

raw ibex
#

so what you do @quaint mantle

#

is this

#

JK JK?learnjava

quaint mantle
#

h

raw ibex
#

you need to define it before the for

#

so do ItemStack item;

#

before the for()

#

then it should work

quaint mantle
#

isnt it already defined before the for?

raw ibex
#

no

quaint mantle
#

OH WAIT

raw ibex
#

?

quaint mantle
#
ItemStack item;
item = new ItemStack(Material.TNT, 1);
#

like that?

#

or\

raw ibex
#

no

#

remove tnt

quaint mantle
#

k

raw ibex
#

there

quaint mantle
#

isnt it going to error however?

raw ibex
#

no

#

does it?

quaint mantle
#

Yep

#

error: variable item might not have been initialized
return item;
^

raw ibex
#

then the for isn't happening

quaint mantle
#

did you mean place ItemStack item ouside of getRandomItem?

#

so inside of public class Crate?

raw ibex
#

no

quaint mantle
#
public class Crate {
    private static ItemStack getRandomItem(String crateType){
        int totalWeight = 0;
        ItemStack item;
#

then idk what you mean lol

#

cause its deff above both for statements

#

so i dont have to do new Crate.getRandomItem()

#

or whatever

raw ibex
#

hm ok fien

quaint mantle
#

does static cause issies?

#

*issues

#

ah

raw ibex
#

well the only answer

#

is that your for() is not working

earnest forum
#

why not use static?

quaint mantle
#

okay wait, so how do I overwrite a statement?

raw ibex
#

you already done it

quaint mantle
#

you sure?

raw ibex
#

because your tnt was showing

quaint mantle
#

So thats correct..?

earnest forum
#

static is perfectly fine

#

for that

raw ibex
#

meaning that there must be no false keys

#

i think

#

@quaint mantle that should theoredically work

#

but that can't be the problem

quaint mantle
#

cause there is an error

#

anyone god the mapping guide

raw ibex
#

idk

#

why s+ ".Name"

#

is that a material?

#

idk

earnest forum
#

config file

#

path

quaint mantle
#

yes

#

it is

#

ill rename it tho

#

org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-obf

#

is this correct?

#

Failure to find org.spigotmc:spigot:jar:remapped-mojang:1.18.2-R0.1-SNAPSHOT in https://hub.spigotmc.org/nexus/content/repositories/snapshots/

#

i dont see why not

#

@raw ibex That wasnt the issue

#

Hmm

#

Why is .getKeys returning none?

#

what

terse panther
#

Hi, I was using a 1.18 local host, but now I must to use one in 1.16.5
However when I run BuildTools to install 1.16.5 server I get this error:
´´***The version you have requested to build requires Java versions between [Java 8, Java16], but you are usin Java 17
** Please rerun BuildTools using appropiate Java version. ´´
I understand the error, but is there a way to change it without uninstalling Java 17? Just switching the default version or something

tender shard
tender shard
#

e.g.

C:\Program Files\Java\Java8\bin\java.exe -jar BuildTools.jar
terse panther
#

Ohh thanks!

tender shard
tender shard
terse panther
tender shard
#

if you're using bash, you can just create a .bash_aliases file

#

so you can do java8 to run java8, java17 for java 17, etc

terse panther
#

oh nice, thanks!

#

I going to use it

smoky oak
#

is spigot 1.18.2 stable by now? building latest spits out 1.18.1 but buildtools says 1.18.2 is the latest version

tender shard
#
    public static Plugin fromSpiget(Plugin plugin) {
        final int id = plugin.id;
        final String name = plugin.name;
        final String thumbnail = plugin.thumbnail;
        final String version = spigetApi.getVersion(id);
        final int downloadId = spigetApi.getDownloadId(id);
        final PluginUpdate lastUpdate = spigetApi.getUpdate(id);
        final int updateId = lastUpdate.updateId();
        final long timestamp = lastUpdate.timestamp();
        return new Plugin(name, version, id, updateId, downloadId, thumbnail, timestamp);
    }

Anyone here like final local vars? lol

#

does anyone know if I can get rid of this warning? From what I know, I cannot check for the generic types at runtime anyway soooo isn't the whole warning pointless?

brave sparrow
#

I’d just suppress the warning

tender shard
#

yeah I just thought maybe checking at least if it's instanceof Map would avoid the warning but still, no

brave sparrow
#

Nah

tender shard
#

I just wonder why it throws a warning if it HAS to be suppressed anyway :/

#

there must be SOME other way I guess

brave sparrow
#

Generics are kinda fucky with that

#

If it wasn’t a generic you could check

smoky oak
#

cant you throw an instanceof arond that

brave sparrow
#

Not with generics

tender shard
brave sparrow
#

You can check instanceof Map but not instanceof Map<K, V>

tender shard
#

it gets erased on compile time

brave sparrow
#

That’s why the warning is there lol

#

There’s just not a special case for generics

tender shard
#

anyone have a good idea for a name for my spigot update checker discord bot? I'll release it on SpigotMC so I need a more friendly name than "DiscordSpigotUpdateBot" lol

kindred valley
#

guys how can i get event.getplayer from non event method

kindred valley
tender shard
#

I don't get it

kindred valley
tender shard
#

yeah that makes no sense

#

can you please just explain what you are trying to achieve

kindred valley
#

I'm trying to make the "p" be accesable from all events.

brave sparrow
#

You really need to learn Java man

tender shard
#

what "p"?

#

it's null

#

just directly use "null" whereever you need your "p"?

tender shard
quaint mantle
#

do you have the name for the mapping jar(s)

tender shard
brave sparrow
#

@tender shard they’re trying to add players who died to a set and reference that set later but they don’t know enough Java to accomplish it or understand what they’re even trying to do

quaint mantle
#

oh

#

spigot-1.18.2-R0.1-SNAPSHOT-bootstrap

#

got it ty

brave sparrow
#

You can’t use the bootstrap as a dependency lol

tender shard
quaint mantle
#

uh

#

i ran buildtools

tender shard
#

?paste your BuildTools.log file

undone axleBOT
quaint mantle
brave sparrow
quaint mantle
#

idk why its not there

quaint mantle
#

vm

#

found it

quaint mantle
#

@tender shard should the name be in the buildtools log

tender shard
#

you don't need any .jars name

#

you are using maven to handle your dependencies

#

I asked you to send the log file

sharp flare
#

does package rename reflect on github after merging it directly on the main branch, I renamed my old shitty package name to all lowercase

ivory sleet
#

Yes should do, just push upstream

sharp flare
#

thanks, Was conscious on what github desktop is showing with the changes. Though it wasn't reflecting it

sharp flare
#

tried it, the package names on github are still in uppercase

brave sparrow
#

yeah just changing capitalization doesn't really work

sharp flare
#

rip

brave sparrow
#

change the name to something else and then change it back

sharp flare
#

how do I change it

tender shard
#

like you did it the last time?

sharp flare
#

I did it on github desktop, and pushed it from there

brave sparrow
#

so do it again

tender shard
#

git config core.ignorecase false

sharp flare
#

thanks the git command recognized the changes

west oxide
#

why does this not work ...

tender shard
#

because there is no constructor called TextComponent(String)

#

you wat to use TextComponent.fromLegacyText(String)

west oxide
#

hoiw do i make a clickable text then ? this was what i found on the internet

lavish hemlock
#

Actually it depends

#

Are you converting from color codes

#

or are you creating a new component with some plain text?

west oxide
west oxide
lavish hemlock
#

Oh you're importing the wrong class

west oxide
#

yeah its the only class that intellij prompt me

tender shard
#

did you add spigot-api to your dependencies?

lavish hemlock
tender shard
west oxide
#

theres no spigot one

lavish hemlock
#

In the fucking documentation, therefore probably in the class

undone axleBOT
tender shard
#

this is the full TextComponent class

lavish hemlock
tender shard
#

yes that's outdated

west oxide
#

oh 1 sec

#

was this a thing on 1.8.8 ?

tender shard
west oxide
#

1.8.8

lavish hemlock
tender shard
lavish hemlock
#

Also no this API does not exist for 1.8 iirc

tender shard
west oxide
#

ty for the help tho

lavish hemlock
#

Also I know that constructor exists because I've seen it in 1.18 :p

dire marsh
#

meh, I prefer adventure

tender shard
#

it seems to exist in 1.8

lavish hemlock
#

Either way you'd want a ComponentBuilder

#

Oh

#

Do you use Gradle or Maven? @west oxide

west oxide
west oxide
#

i think am using the default thing from intellij idea

tender shard
#

do you have a build.gradle file?

lavish hemlock
#

Use one, that API is not built by BuildTools

tender shard
#

do you have a pom.xml file?

smoky oak
tender shard
#

yeah best screenshot ever

west oxide
#

ITS BEST I COULD DO

tender shard
#

looks like JPG with quality set to -17

west oxide
tender shard
tender shard
west oxide
#

no

lavish hemlock
#

The Chat Component API is available from the Sonatype Maven repos

west oxide
#

neither

tender shard
#

wow lol

#

you should use either maven or gradle

#

it'll make everything so much easier

#

your problem is:

lavish hemlock
#

Yeah

earnest forum
#

is there a way to access nms with maven

tender shard
#

you imported spigot-api.jar

earnest forum
#

without files

#

i couldnt find a repo for nms

tender shard
tender shard
west oxide
#

wait what

tender shard
tender shard
#

or let maven handle your dependencies

west oxide
#

build tools ?

lavish hemlock
#

Use Maven ffs

#

It's not hard to learn at all

earnest forum
#

yes buildtools

lavish hemlock
#

Still, use Maven :p

west oxide
#

lol

lavish hemlock
#

If it "wouldn't work," then you fix it

quaint mantle
#

Hello, I'm making plugin where when you walk it spawns glowstone below you (except air). So I was wondering how do I create function for every time event gets triggered (im trying to replace glowstone with old block after 1 second)


import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.concurrent.TimeUnit;


public class PlayerMoveListener implements Listener {




    @EventHandler
    public void onMovement(PlayerMoveEvent e) {

        Player player = e.getPlayer();
        World world = player.getWorld();
        Block block = player.getLocation().subtract(0, 1, 0).getBlock();
        Material type = block.getType();
        if(type != Material.GLOWSTONE && type != Material.AIR) {
            block.setType(Material.GLOWSTONE);
            player.sendMessage("asd");
            block.setType(type);
        }
        }
        
}```
west oxide
earnest forum
earnest forum
#

in maven

west oxide
earnest forum
#

google it

lavish hemlock
#

Yeah you can use file dependencies

earnest forum
#

ive done it before

west oxide
#

i didnt know that

tender shard
#

<scope>system</scope> but

west oxide
#

yeah i ll just do that

tender shard
#

that's not really supported

#

you should rather install local files to your repo

earnest forum
#

does work tho]

tender shard
#

using mvn install:install-file

tender shard
lavish hemlock
#

you should probably give him the full rundown

tender shard
#

I'll write a blog post on how to manually install .jars to maven repo

west oxide
#

thank you guys

tender shard
lavish hemlock
#

Also this is why you don't use your own repos ;)

#

Maven Central go brrrr

west oxide
#

btw

#

@lavish hemlock are you the on on the forums ?

#

i ve seen a similar pfp to yours many times

lavish hemlock
#

yeah I'm the on on the forums

west oxide
#

ooh thats nice

tacit drift
lavish hemlock
#

but no my forum profile is

#

a lil different

west oxide
#

yeah nvm

lavish hemlock
#

lmao

west oxide
#

mb i thought this was you lol

lavish hemlock
#

I'm still not quite sure what "the on on the forums" means

#

it's not quite English

quaint mantle
west oxide
lavish hemlock
#

What does that have to do with what I said

tacit drift
#

I would suggest using fake blocks

tacit drift
#

so no permanent things are made

quaint mantle
#

I want it to make block under player glowstone, wait 1 second and set it back to original block

west oxide
quaint mantle
earnest forum
#

run task later

lavish hemlock
digital haven
lavish hemlock
#

I have a forum account but "the one" is not descriptive

tacit drift
#

Player#sendBlockChange

#

@quaint mantle

lavish hemlock
#

This is me

west oxide
#

F

lavish hemlock
#

I mean

#

I'm also verified

#

That means my forum name matches my Discord name

earnest forum
#

for all players to see

west oxide
tacit drift
tender shard
west oxide
#

yes

tacit drift
#

But that's the safest way to do it anyway

earnest forum
#

why not just do a scheduler task?

tacit drift
#

a scheduler that does what?

earnest forum
#

sets block

#

then 20 ticks later set it back

digital haven
#

Oops

#

Replied to wrong person

tacit drift
#

And if the server crashes or something happens, the changes are permanent