#help-development

1 messages ยท Page 2152 of 1

tardy delta
#

iirc it works with command too

tall dragon
#

pretty sure console even has higher permission than op

ancient plank
#

console is god

#

you can't deop god, only prevent god from seeing and acting ๐Ÿ˜‰

tender shard
#

well

tardy delta
#

you can do System.exit(0) and god is gone

tender shard
#

CraftConsoleCommandSender extends ServerCommandSender

#

and that still has a "permissions map"

tall dragon
tender shard
#

so I wouldn't trust the ConsoleSender to ALWAYS have all perms

tardy delta
#

ah i just stopped checking for console permissions cuz i assumed it had all permissions

tender shard
#

it's definitely possible to remove permissions from the console sender

tardy delta
#

why would you ๐Ÿคท

tender shard
#

idk, I just wanted to say that ConsoleCommandSender does NOT override hasPermission to always return true

#

I assume that it still uses the default permissions as defined in plugin.yml

#

so I guess if you set a permission to default to "false" in plugin.yml, I guess that the console sender does not have this permission

tardy delta
#

hmm

tender shard
#

I'll just try it out quickly

fossil lily
#

Why can't I cast this to a Bed?

tardy delta
#

anyways using the var keyword looks so ugly

tardy delta
tall dragon
tardy delta
#

or how its called

tender shard
#

yeah, use getBlock().getBlockData()

tender shard
#

commands:
  test:
    description: Some command
    permission: some.permission.name

permissions:
  some.permission.name:
    default: false
#

the console by default only has permissions that are either "default: true" or "default: op"

#

if a permission is "default: false", then console won't have it either

tender shard
#

so yeah, the console also needs explicit permissions

tardy delta
#

oh

fossil lily
fossil lily
#

Using 1.8.8 api if it matters

tender shard
#

ugh...

tardy delta
#

anyone who uses acf?

tender shard
#

you have to mention that you use a 8 year old version

tender shard
tender shard
fossil lily
#

Not my server, not my decisions

ancient plank
#

I believe in my god

tender shard
fossil lily
#

I would upgrade if it were me

stray flare
fossil lily
#

but yea

tender shard
#

1.8 uses a totally different way for "blockdata"

ancient plank
#

having an omnipotent god is cringe

tardy delta
#

im trying to make a method

@Default
public void onSetHome(KingdomsPlayer player, String[] args) {}```
instead of (Player player, String[] args) and im wondering how it could get a kingdomsplayer object
tender shard
tardy delta
#

i guess i need commandcontext

tender shard
#

let me check, I am using something similar in one of my plugins

ivory flume
#

How do I change the server resource pack via code.

tender shard
tardy delta
#

set it in the server.properties file? or where its located

tender shard
#

Player#sendResourcePack or sth like that

tardy delta
#

:o

ivory flume
#

Should i just handle sending the reosurce pack stuff myself and have no server resource pack specified in the server.properties file

#

okay i think thats what I plan to do...

stray flare
tender shard
tender shard
#

?paste

undone axleBOT
tender shard
ancient plank
#

๐Ÿ’

tender shard
#

then see what the output is

tender shard
ancient plank
ancient plank
#

in main

stray flare
#

oh i see

#

my bad

tender shard
#

haven't checked the main but that shouldn't do anything bad except that it's totally useless

ancient plank
#

useless is bad >:(((

tender shard
#

oh wait

#

in what line did the error occur

#

only now do I see that you also cast random blockdata to endportalframe in lines 57 to 60

#

you get an error in line 60

tardy delta
#

im wondering what BukkitCommandExecutionContext#popFirstArgs is doin

tender shard
#

that means that frame4 is not an EndPortalFrame

#

@stray flare

stray flare
#

Whys that

tender shard
#

because the block at loc4 is something else then END_PORTAL_FRAME

latent pelican
#

In my plugin I want to create a plain, flat start world: On the internet, I figured that you need to edit the server.properties file and set "level-type" to flat. However, if I do so, it isnt working... Any tipps?๐Ÿ˜…

tender shard
#

or do you want to change the "default" world?

#

setting "level-type" to flat will work

stray flare
tender shard
#

unless there already is an existing world

stray flare
#

idk what is going on

tender shard
#

easy: the block at 5, 65, 13 is not an end portal frame

#

go there and take a look

latent pelican
tender shard
#

@latent pelican changing the "level-type" in server.properties will only change anything if there isn't already any generated world

tardy delta
#

@tender shard i think its something like this, i might test it out tomorrow

tender shard
#

stop server, delete the world folder, start it again. now you should get a flat world

tender shard
tardy delta
#

its supposed to be that ye, didnt create it yet

tender shard
#

okay then yes, that should work fine

#

oh wait

#

no

#

you are trying to make KingdomPlayer be the commandsender right?

#

that won't work. the context is only for the given parameters

tardy delta
#

ye

tender shard
#

your ACF method should still take a normal CommandSender

tardy delta
#

:o

tender shard
#

and inside that, get your KingdomPlayer

#

the first parameter in ACF will ALWAYS be either ConsoleCommandSender or Player (or just CommandSender to allow both)

buoyant viper
#

be a gigachad, use bukkit commands

tardy delta
#

is it possible to do something liek onBlablabla(Player player, KingdomsPlayer kp, String[] args)?

tender shard
tardy delta
#

void onSetHome(Player player, KingdomsPlayer kp, String[] args)

tender shard
#
public void onBlabla(Player player, String[] args) {
  KingdomsPlayer kp = userMap.get(player.getUniqueId());
}
tender shard
tardy delta
#

wdym

#

ah

tender shard
#

like /message <receivingPlayer> <message...>

tardy delta
#

/sethome <name>

#

๐Ÿ’€

tender shard
#

yeah just do what I sent

#

the first parameter will be Player

#

a bukkit player

#

now just turn it into a KingdomsPlayer on your own

tardy delta
#

manual stuff aaa

#

lol

tender shard
#

manual? it's one line

#

ACF works with the builtin command senders

#

it won't mess with those

#

it can transform the arguments into your custom classes, but not the commandsender itself

#

e.g. if you do something like this:

#

/home myFirstHome

#

it can turn the String "myFirstHome" into a "KingdomsHome" object

#

but it will never do that for the sender itself

#

just create a method ```public KingdomgsPlayer fromPlayer(Player player) { userMap.get(player.getUniqueId()); \

#

btw I suggest to use compueIfAbsent instead of get()

tardy delta
#

mye doesnt matter too much

buoyant viper
#

does acf support parsing custom types

tender shard
#

you mean to turn a "string parameter" into a custom object?

buoyant viper
#

like u use custom object as a param

tender shard
#

yes

#

you can do that easily

#

I can write a short example if you like

tardy delta
#

is that what the registerContext is doin?

tender shard
#

yes

latent pelican
tardy delta
#

the world folder

#

folders with world in the name

latent pelican
#

So 3 folder right?

tardy delta
#

depends on which world you want to remove

tender shard
#

@tardy delta @buoyant viper here's an example that works like this:

Players can enter /test someString

The commandExecutor receives a MyCustomObject instance, which is generated from the "someString" thing.

In your main class:

        PaperCommandManager acf = new PaperCommandManager(this);
        acf.getCommandContexts().registerContext(MyCustomObject.class, context -> {
            return new MyCustomObject(context.getFirstArg());
        });

The command executor:

public class MyCommand extends BaseCommand {

    @Default
    public void onCommand(CommandSender sender, MyCustomObject parameter) {
        // Do something
    }
}

The MyCustomObject class:

public class MyCustomObject {

    final String myValue;

    public MyCustomObject(final String myValue) {
        this.myValue = myValue;
    }
}

stray flare
tardy delta
#

:o

tender shard
#

important: in this case, the MyCustomObject thing is always created from the first argument

#

if you want to change that, you can ofc also get the full args[] in the "context" lambda

#

basically, a "context" in ACF returns an object that consists of

  1. the commandsender
  2. the full arguments that were entered
  3. and more information
tardy delta
#

ah i get it

tender shard
#

you can use the context flags to also get the correct parameter if your commands have different parameters and the desired object isn't e.g. always the first parameter

#

it's a bit complicated at first but once you get it, it makes everything so much easier. so yeah just let me know if you have a specific example and I'll try to explain it again in detail

#

btw for ACF questions I recommend joining their discord. for some reason, most people here have no idea about ACF

#

everytime I ask a question here, noone answers ๐Ÿ˜„

#

ACF is awesome but unfortunately the documentation is shit. it's so powerful but so badly documented >.<

humble tulip
#

I use lamp

#

Also powerful but undocumented

buoyant viper
#

i simply use bukkit commands

humble tulip
#

Ew

tender shard
ivory sleet
tender shard
#

my biggest plugin uses a mixture lol

humble tulip
#

No

tender shard
#

bukkit commands for commands that already existed 3 years ago, and ACF for all commands that came after that

#

and I would never go back to bukkit commands

#

I am just too lazy to "translate" the old logic to ACF

buoyant viper
#

ill have @ancient plank write a command api for me then

#

๐Ÿ˜Ž

tender shard
#

adele is busy preparing her birthday

ivory sleet
#

acf is nice but Im not a fan of annots which it bases itself of so ye

humble tulip
#

Lamp also uses annotations

ivory sleet
#

ye I havent touched lamp

humble tulip
#

Why do you not like annotations tho

tender shard
#

even spigot uses annotations. although not for commands

ivory sleet
#

it becomes awkward to use

#

especially since Java is so oo

tender shard
#

but the "provide custom objects as parameters" we were talking about does not require ANY annotation

ivory sleet
#

yeye

#

like annotations are pretty bad when it comes to proper abstraction, ofc a cli implementation is a lower level module type, so one could argue for that proper abstraction might not be that integral

tardy delta
tender shard
#

ACF is really nice. onCommand2 is using ACF, onCommand is the bukkit way:

    @Default
    public void onCommand2(Player player, AngelChest angelChest) {
        // Do stuff
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if(!(sender instanceof Player)) {
            // send error
        }
        int angelChestId = Integer.parseInt(args[0]);
        AngelChest angelChest = angelChests.get(angelChestId);
        if(angelChest == null) {
            // send error
        }
        // Do stuff
        return true;
    }
buoyant viper
tardy delta
#

i used to do it manually too

tender shard
#

obviously in ACF you have to tell it once how to turn a string into an "AngelChest" object but you only have to do it once and do not worry about all the error messages everytime etc

ivory sleet
#

I mean I still write argument parsers for my arguments but yeah get watchu mean alex

tender shard
#

actually angelchest is my only plugin that doesn't heavily rely on ACF lol

#

so it was a bad example

#

but anyway

tardy delta
#

there was a time, instead of sending messages and blablabla to a player, i just returned a CommandResult in my onCommand method

ivory sleet
#

scary

tender shard
#

I do the same thing in my discord bot

tender shard
#
    public void handleCommand(@NotNull CommandSender sender, @Nullable Message message, @NotNull String... args) {
        if(args.length==0) return;

        String commandName = args[0].toLowerCase(Locale.ROOT);
        Command command = commandMap.get(commandName);

        if(command == null) {
            CommandSender.CONSOLE.message("Unknown command: \"" + Command.withPrefix(CommandSender.CONSOLE, commandName) + "\". Enter \"" + Command.withPrefix(CommandSender.CONSOLE, "help") + "\" for a list of available commands.");
            return;
        }

        if(!sender.hasPermission(command.getPermission())) {
            sender.message("You do not have the required permission (" + command.getPermission() + ") to run this command.");
            return;
        }

        CommandResult result = command.execute(sender, message, Utils.shiftArray(args));

        if(result == CommandResult.WRONG_USAGE) {
            sender.message("Usage: " + commandName + " " + command.getUsage());
            return;
        } else if(result == CommandResult.NOT_FROM_CONSOLE) {
            sender.message("You cannot run this command from console.");
            return;
        }

        Logger.info(sender + " executed command: " + String.join(" ",args));

    }
public enum CommandResult {
    OK, NOT_FOUND, WRONG_USAGE, NO_PERMISSION, NOT_FROM_CONSOLE;
#

whoops

#

that's longer than I thought

tardy delta
dusk flicker
#

I just made a command system where I dont need to do checks for arguments cause fuck arguments

buoyant viper
#

just have no arguments

#

ezpz

tender shard
#

we should create a library called "TerribleCommands" that works like this:

  1. Player enters /sethome
  2. A conversation starts where the plugin says "Please now enter the first parameter"
  3. Player enters a name in chat
  4. Plugin asks "Do you want to enter an additional parameter?"
  5. Player enters "no"
  6. Plugin replies "Error: Your home was set successfully."
dusk flicker
#

yes

#

its also case sensitive of course

#

if you type No rather than no you must restart

tender shard
#

I updated #6

tardy delta
#

it should ask "enter your second parameter" if you enter no

#

hehehe

tender shard
#

it should only be over complicated

fossil lily
#

So setting the type to "BED_BLOCK" allows me to cast it to a Bed, but it removes the actual block...

tardy delta
#

"please enter the base64 encoded name of your home"

tender shard
#

in 1.13+ it's simply "BED"

fossil lily
tender shard
#

IIRC in 1.8 there's two blocks for the head of the bed and the tail of the bed

fossil lily
#

Oh

#

Is BED_BLOCK the head?

tender shard
fossil lily
#

It probably is

tender shard
#

while BED_BLOCK needs to be set twice for both the head and the end, with different data

#

idk anything about 1.8, I started in 1.13 when all this bullshit was changed to proper API ๐Ÿ˜„

#

1.8 is so tedious to work with

#

but for beds it's similar in 1.13+ too: you have to set the head block and the tail block. if you only set one, you only have half a bed and it will break once there's a blockupdate or similar

tardy delta
ivory flume
#

How do I get a pack hash?

#

do i have to have it saved

#

i can't just generate it

#

ugh

#

how do I get the hash

tender shard
#

of a resource pack?

#

sha1sum <resourcepackfilename>

ivory flume
#

whats that, CLI?

tender shard
#

yeah

ivory flume
#

ok

tender shard
#

I am sure there's also websites where you can upload your file and it will tell you the hash

ivory flume
#

ty, I guess

#

nice using that!!!

#

not that I hate CLI but that I have to get server owner to use it

tender shard
ivory flume
#

thank you!

tender shard
#

np

#

but as said, in linux you can also always just do "sha1sum <filename>"

tardy delta
#

๐Ÿ’€

buoyant viper
dusk flicker
#

not really

torn shuttle
#

not at all

#

doing most basic things in minecraft is pretty snappy

subtle folio
lost matrix
subtle folio
#

wait oops forgot the implements Serializable nvm

lost matrix
#

Show your SerializePlayerWrapper.java file

ivory flume
#

How does Hypixel get to avoid authentication server issues

#

its currently working with the auth servers down

next stratus
#

Man, why are the 1.12 kids the most toxic kids?

hasty prawn
#

Probably because they're using 1.12

eternal night
#

because they aren't using 1.8, the best version kappa

vocal cloud
#

1.12 most toxic? Then 1.8 is most entitled dogekek

buoyant viper
#

idk after like 5 years working with the client, its tedious @dusk flicker @torn shuttle

dusk flicker
#

oh well client

#

sure

buoyant viper
#

yee

dusk flicker
#

I could be 110% wrong, but thats my understanding

ivory flume
#

so new accounts can't log on?

#

like, first time log in-ers

buoyant viper
#

most likely not

torn shuttle
buoyant viper
#

client or server

#

bc they are (kinda) different workloads

torn shuttle
#

I'm doing Unity and even some web dev right now and it's the good old meme of if you wish to make a pie from nothing you must first create the universe

#

server-side

buoyant viper
#

hmm

#

webdev is still fun for me for now, not as monotonous as mcdev yet

#

even when i have to do it from scratch

torn shuttle
#

if you want to make a hunger games plugin in minecraft you can rig up some code in under a week to get something pretty decent going, if you want to make a hunger games game in Unity, or any engine (or god forbid with - no engine) you better start making the models, rigging animations, checking your topology, create the map assets, script the movement, record your various soundtracks, create the UI and also at some point you have to create or implement netcode, lobby systems, dedicated servers or p2p solutions (so basically use steam as the middleman)...

#

and then you can start worrying about the gameplay lol

vocal cloud
#

Yeah then the bugs start rolling in kek

buoyant viper
#

the bugs start comin n they dont stop comin n they dont stop comin n

torn shuttle
#

if you want to talk tedious I'm doing webdev right now and this is the most bored I've felt all year

#

making a single page webapp with just html css and js makes you wish for nuclear winter

buoyant viper
#

are u a framewoker or vanilla kinda guy

torn shuttle
#

and I would rather go become a goat farmer than actually finish learning angular

lost matrix
torn shuttle
#

I'm just using the vanilla tools

#

I am not going to learn these fancy frameworks for this project

#

I hate webdev, the less I do it the happier I am

buoyant viper
#

tru

lost matrix
#

Same. Ive tried force learning it each other month now and i could never get past
the basic building blocks. Its just so boring...

torn shuttle
#

I did the classic mistake of trying to fix how shit of an experience web dev is by trying fancier tools of web dev

buoyant viper
torn shuttle
#

it lead nowhere and it's one of the few times in my life I gave up on something

buoyant viper
#

ill get the url just wait

waxen plinth
#

Webdev sucks

#

Avoid at all costs

torn shuttle
#

which tbf I am doing the thing I gave up on a couple of years right now so I guess ultimately I didn't really give up on the project, just on using angular for it

lost matrix
#

The most complicated web application ive written was actually done in Java with vaadin XD

torn shuttle
#

now I'm not even using jquery, either it gets done with js or it gets done with js but it takes me a bit longer

buoyant viper
torn shuttle
#

besides webdev frameworks are basically just fashion statements with the speed at which they seem to come into and out of popularity

buoyant viper
# torn shuttle besides webdev frameworks are basically just fashion statements with the speed a...

I built a simple app with 10 different JavaScript frameworks... Learn the pros and cons of each JS framework before building your next app https://github.com/fireship-io/10-javascript-frameworks

#javascript #webdev #top10

๐Ÿ”— Resources

Full Courses https://fireship.io/courses/
Performance Benchmarks https://github.com/krausest/js-framework-benc...

โ–ถ Play video
#

talk abt frameworks coming n going

lost matrix
#

Ill just wait until web assembly is more adapted and then write websites in Kotlin or something

torn shuttle
#

hope you're not waiting standing up then

buoyant viper
torn shuttle
#

the only thing I used for it was bootstrap because I'm not a masochist either

buoyant viper
#

is it supposed to be .yml.txt

torn shuttle
#

nah, part of why it's a prototype rn

lost matrix
torn shuttle
#

yeah I think it might be a platform thing

#

were you on chrome?

eternal night
buoyant viper
#

FF

torn shuttle
#

@lost matrix chrome?

lost matrix
buoyant viper
#

ill try it on pc later

torn shuttle
#

k then I don't know, it seemed to be generating as yml as well but tbf I wrote the code for generating the file extension after 23 hours of straight work

buoyant viper
torn shuttle
#

it doesn't even matter that much because ultimately it would be better if it gave you a zipped file with everything in the appropriate directories, it's a tool for mass creation

#

the main things I still have to do are the zip distribution and the nested editing

#

well, and adding all of the fields for the other file types but that's just me mindlessly filling in the already created templates

fossil lily
#

Why wont this work? Am I setting it wrong? Once again, 1.8.8 API.

spare marsh
#

Question... If I have a YamlFile in class 1 and another yamlfile in class 2 but they both are refrenced to the same place, and come from the same place... If i write something to the file from class 1, and another thing from class 2 and then saved the both, will class 2 overwrite what class one wrote or they both get written down since it is the same object refrence?

humble tulip
spare marsh
#

Yes

humble tulip
#

Are you setting and saving different things

spare marsh
#

So YamlFile file1 and YamlFile file2 come from the same location

#

point to the same refrence

humble tulip
spare marsh
#

if I set "Name" to John in file 1 and "Age" to 22 in file 2. Will both of those values be saved or only age since it was saved second>?

#

It is just a way to explain it brother.

#

Each class i am working with has a different YamlFile but some can repeat that's why I'm asking if they both come from the same place, what I make to file 1 happens to file 2?

humble tulip
#

If it's the same instance of yamlconfiguration it'll save both

#

If you create 2 different instances I'm not sure what ll happen

spare marsh
#

No no

#

Let me give you an example

humble tulip
#

Can you show your code?

sharp flare
spare marsh
#

Lets say there is a list with a bunch of files saved. in class 1 I need a file that is the same file that class 2 needs. I get it from that list. So YamlFile file1 comes from that list and YamlFile file2 also comes from that list it is the same exact instance of the file. What I'm asking is that if I modify the file from class 1 class 2 also has those modifications on its file instance

spare marsh
#

Two different objects but same refrence

humble tulip
#

Huh?

spare marsh
#

that keeps track of the changes right?:

humble tulip
#

Thought it's the same object

#

If you load 2 configs of tje same file, changes to one do not show in the other

#

However if you load one config and share it between multiple classes

#

Changes are shared

spare marsh
#
YamlFile file1 = Tools.getFileLoaded("java4life");
YamlFile file2 = Tools.getFileLoaded("java4life");
``` Modificatios to file1 also happen to file2 since the value Tools.getFileLoaded returns the same exact object it returned to file1
#

?

humble tulip
#

If getFileLoaded returns it from a map that caches loaded files then yeah

#

2 referemces to the same object

spare marsh
#

Yessss that was my question

#

I have a hard time explaining my self xd

humble tulip
#

It's alright

#

You got the answer

spare marsh
#

its like its in there but I can turn it into words

#

thanks brother

humble tulip
#

No problem

torn shuttle
#

that way I don't have to do any of the work and I also don't have to scrape the api page which would not really be cool of me to do

sharp flare
#

Aight, I think your web app is suitable in node

#

Since it mostly deals with io and files

torn shuttle
#

I would rather not make the app at all than make it in node

sharp flare
#

Kindw tedious but node does the job too

torn shuttle
#

yeah I have no intention of using node unless I really have no option

#

ultimately this works just fine with vanilla js

#

it's barely 300 lines of code

sharp flare
#

Fair, my plugin wiki is just vanilla js too as of now with fetching data from a cloudflare worker that returns a json of the items, lore, recipe

torn shuttle
#

I like how we're using the exact same bootstrap button

#

btn btn-primary

#

is this even the same blue?

sharp flare
#

Yeah its using bootstrap

torn shuttle
#

jesus you'd think one of us was looking at the other's webpage while making it

sharp flare
#

Xd I thought same when i visited urs

#

But its common with bootstrap users

torn shuttle
#

yeah I mean it's the default primary action button

sharp flare
#

U get same shit

#

Since its a html css framework

torn shuttle
#

this is basically a card layout with a basic bootstrap hooked up to it

#

oh well

sharp flare
#

Mine uses modals

#

Button then pops up modals

#

I made it 2 days ago since I exported all of the items in a json file

torn shuttle
#

I was using cards but then I stripped the card code out at some point and ended up remaking it in my own implementation

modest shard
#

anyone know why this error happens

#

i havent boot up my server to test my plugin in a while now so it may be outdated

sharp flare
torn shuttle
#

bootstrap is great for quick formatting, especially if you're more of a developer and less of an artist

#

alright I need to get back to writing this

sharp flare
#

Goodluck ๐Ÿ‘Œ

modest shard
#

no help? sadge

earnest forum
#

google the error

modest shard
#

i hvae

#

have

#

or i wouldnt be asking here

quaint mantle
modest shard
#

it worked before

#

nothing shouldve changed

#

could u tell me how i can check i installed the server months agop

quaint mantle
#

Just open the start file with nodepad and check if the names are the same as the jar file in server folder.

modest shard
#

start file?

#

sorry i dont know much about servers lol

quaint mantle
modest shard
#

i did nobody there ๐Ÿ˜ญ

quaint mantle
#

All needed info is on that spigot page I've send ๐Ÿ™‚

modest shard
#

ok ty

warm light
#

Trying to open a inv with 9 slot and got
java.lang.IllegalArgumentException: Invalid inventory size; expected 9 or less

Trying to open with 18 slot and got
java.lang.IllegalArgumentException: Invalid inventory size; expected 18 or less

Trying to open with 27 slot and got
java.lang.IllegalArgumentException: Invalid inventory size; expected 27 or less

dusk flicker
#

Can you show the code?

warm light
#

@dusk flicker

dusk flicker
#

can you show your inv method please?

#

oh nevermind I am stupid

warm light
#

Its just openinv(inv)

dusk flicker
#

Interesting

#

What line is the error coming from?

warm light
#

Its a custom ec plugin. so when I try to open ec. I got error

#

but same code was working 2 weeks ago

#

users started reporting me then I found this

humble tulip
#

Which line though

warm light
#
[08:50:24 ERROR]: Could not pass event PlayerInteractEvent to EnderPlus v1.6
java.lang.IllegalArgumentException: Invalid inventory size; expected 9 or less
        at org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory.setContents(CraftInventory.java:85) ~[patched_1.17.1.jar:git-Airplane-"74774a0"]
        at me.rrs.Util.Util.inv(Util.java:21) ~[EnderPlus.jar:?]
        at me.rrs.Listener.OpenEnderchest.onPlayerInteract(OpenEnderchest.java:27) ~[EnderPlus.jar:?]
warm light
humble tulip
#

Invalid inventory size

#

Why would it excped 9 or less though

#

Isn't max like 54

dusk flicker
#

Im wondering if the size being passed in by RRS is too small for the contents being added

humble tulip
#

The inv methoud should ideall take the number of rows

dusk flicker
#

yeah

humble tulip
#

And then multiply by 9

warm light
#

from all other I got error

#

only size 54 is working

dusk flicker
#

so from what I am betting RRS

#

is the contents of that players enderchest, however you are storing it (where you showed earlier) is larger than what they have permission for

humble tulip
#

Rrs

#

Check from lvl 6 to 1

#

Not 1 to 6

dusk flicker
#

oh yeah thatd do it

#

lol

warm light
#

so I can remove the if player is op things?

fading lake
#

Slot IDs start at 0

#

so 54 is not a slot

#

no

#

im an idiot

humble tulip
#

Lol

humble tulip
dusk flicker
#

start at 6, then 5, then 4, etc

humble tulip
#

Btw you can create a for loop for that

warm light
#

loop?

warm light
humble tulip
#

for (i=6, i>0,i--)

warm light
warm light
#

alright That will be grate ig. but I will still get error .-.

humble tulip
#

Yeah let's solve the issue first

warm light
#

java.lang.IllegalArgumentException: Invalid inventory size; expected 18 or less

#

with enderplus.lvl.2 perm

humble tulip
#

Can you print the size

#

Of the inventory

warm light
#

okay

humble tulip
#

And the size of the contents

#

So the size of echest. Get

warm light
#

wait @humble tulip I can't print inv size as there is no inv

#

I mean inv didn't created

#

java.lang.IllegalArgumentException: Invalid inventory size; expected 18 or less

#

so it just cancel

humble tulip
#

Print it as soon as the method is called

warm light
#

its all

#

I mean int size and echest size

#

before it open

humble tulip
#

Did it throw an error there?

warm light
#

yes

#

same error as before

humble tulip
#

Nooo

#

You did it wrong

#

Print

warm light
#

??

humble tulip
#

Echest.get(player).size

warm light
#

oh

humble tulip
#

Me?

warm light
#

nvm

humble tulip
#

The Echest.get

#

The size of whatever that returns

warm light
#

umm, its return 1

humble tulip
#

Noooo

#

That's the map size

#

Echest.get(Player.getName).size

#

Or .length if it's an array

#

Before you even test it send the code so I'll make sure it's the correct thing you're printing

warm light
#

idk whats wrong/write, now inv is opening after adding this line .-.

#

but

#

problem is

#

java.lang.NullPointerException: Cannot read the array length because the return value of "java.util.HashMap.get(Object)" is null

humble tulip
#

Bruh

#

Hold on

warm light
#

now its working

#

but with that error

humble tulip
#

That line didn't fix it

#

I can confirm

warm light
#

do you think its java problem?? before I tested it with java 8. and now using 17

humble tulip
#

Nope

#

Not java

#

The size of the echest inventory contents was larger than the inventory you created

#

That was the problem

#

Is your code on github?

warm light
warm light
humble tulip
#

That line couldn't have possible fixed it

#

Okay what happens if a player had an inv of 4 rows and then got downgraded to 1 row

#

When you load the data tjere are 36 items

#

But then when you set contents to 1 row you're trying to set the other 27 items that can't fit in an inventory with 9 spaces

#

If you add an extra - null to your config file it'll break it once more

warm light
#

umm. but all empty slot is null. so it shouldn't fill

#

I mean null == no item

#

so that shouldn't search for an item

#

but

#

I tested that before

#

it just remove items from data.yml(where it save hashmap) on inv close

#

if slot downgraded

humble tulip
#
if (Echest.containsKey(player.getName())){
            int echestSize = Echest.get(player.getName()).length;
            EnderPlus.getInstance().getLogger().info("Number of enderchest contents: " + echestSize);
            EnderPlus.getInstance().getLogger().info("Trying to open enderchest of size: " + size);
            EnderPlus.getInstance().getLogger().info("Will fail? " + (echestSize > size));
            inventory.setContents(Echest.get(player.getName()));
        }
#

try putting that

warm light
humble tulip
#

did you get the error?

#

?

warm light
#

yap. but how to fix it .-.

humble tulip
#

this plugin is too far gone

warm light
#

wait

humble tulip
#

lots of issues

warm light
humble tulip
#

you can recode it or just use a for loop and set the contents

#

did it fail there?

warm light
#

oh nah. that was inventory.setContents(Echest.get(player.getName())); problem

humble tulip
#

its not a problem with setContents

#

its a problem with how you handle data

#
if (Echest.containsKey(player.getName())){
            ItemStack[] echestContents = Echest.get(player.getName());
            for (int i = 0; i < size || i < echestContents.length; i++) {
                inventory.setItem(i, echestContents[i]);
            }
        }
#

that should solve your problem

#

but i do recommend you recode your plugin

sterile token
humble tulip
#

yeah that too

#

player names can change

sterile token
#

Because name can chamge and data go to the trash

#

๐Ÿ˜‚

#

A simply explanation

wet breach
#

however, in general yes use UUID where possible

humble tulip
#

I always have a database table mapping uuid to player name and update it every time the player logs in on asycplayerpreloginevent

glossy venture
#

nvm

golden kelp
#

I am using a NPCClickEvent to get which player clicked and which npc got clicked (using the CitizensAPI) but the event isnt firing

#

I have registered it as well

#

can it be because I am implementing the Bukkit Listener and not something else

#

nvm fixed, I was using the wrong event, I shouldve used NPCRightClickEvent

rugged topaz
#
        NbtCompound signNbt = NbtFactory.ofCompound("ExtraAttributes");
        signNbt.put("id", "minecraft:sign");
        signNbt.put("x", pos.getX());
        signNbt.put("y", pos.getY());
        signNbt.put("z", pos.getZ());
        signNbt.put("Text1", "{\"text\":\"" + line1 + "\"}");
        signNbt.put("Text2", "{\"text\":\"" + line2 + "\"}");
        signNbt.put("Text3", "{\"text\":\"" + line3 + "\"}");
        signNbt.put("Text4", "{\"text\":\"" + line4 + "\"}");

shouldn't the Text1, Text2 .. work ?

#

id, x, y, z, do.

golden kelp
#

what duration should i pass if I want the effect to be permanent (in a PotionEffect)

rugged topaz
#

Integer.MAX_VALUE

golden kelp
#

I get the duration through the config, so what should I put in the config?

#

2147483647

eternal oxide
#

9999 will do it, if I remember correctly

quaint mantle
#

Depends on how you give it to the player and what the effect is for

quaint mantle
golden kelp
quaint mantle
golden kelp
#

when he clicks an NPC

quaint mantle
#

Hmmm, I'd say maybe use Integer.MAX_VALUE

golden kelp
#

But how can I know that value from the config

#

I am importing what the user wants to do on click from the config

quaint mantle
#

You grab the config ?

#

Grab it from the user config file.

golden kelp
#

okay so i think some progress

quaint mantle
#
getConfig().getInt(duration); //The duration should be the path where you store the potion duration in the configs of the player, and also instead of getConfig, maybe use FileConfiguration to get the player config file and go off of there.```
golden kelp
#

yea i do that

quaint mantle
#

Does this make any sense to you?

crude loom
#

Is it possible to check if an item is an armor, and if it is, where it?

golden kelp
#

rn when the player click, the plugin gives them haste but it dissapears after 1 millisecond

quaint mantle
#

Or just use instanceof

crude loom
#

instandof what?

quaint mantle
#

ItemArmor

crude loom
quaint mantle
#

#ItemArmor

crude loom
#

Oh I didn't know this was a thing, thank you!

quaint mantle
#

No worries, hope it helps.

bold copper
#

Hello all Spigot experts, please tell me how to do it right

f.add("title", (c /*yaml-similar config*/, path) -> {
    TitlePart part = switch (c.getString(path+".type", /*comment*/"TITLE or SUBTITLE or TIMES")) {
        case "SUBTITLE" -> TitlePart.SUBTITLE;
        case "TIMES" -> TitlePart.TIMES;
        default -> TitlePart.TITLE;
    };

    return new Script() {
        final String msg = c.getString(path+".title");//not null

        @Override
        public void run(Player p, /*and other*/) {
            p.sendTitlePart(part, msg);// <- there's a mistake here
        }
    };
});
#

the error itself

java.lang.ClassCastException: 
class java.lang.String cannot be cast to class net.kyori.adventure.text.Component 
(java.lang.String is in module java.base of loader 'bootstrap'; 
net.kyori.adventure.text.Component is in unnamed module of loader 'app')
at org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer.sendTitlePart(CraftPlayer.java:2333)

chrome beacon
#

Give it a component instead of a string

bold copper
#

Please tell me the exact name of the class.

chrome beacon
#

Component

bold copper
chrome beacon
bold copper
#

Thank you, I think that's enough for me to figure it out

quaint mantle
golden kelp
crude loom
# quaint mantle Did it work for you ?

I ended up manually checking it since I'm making a Bedwars minigame and it doesn't have a lot of armor types
The class you spoke of wasn't recognized and I didn't find it in the SpigotAPI

bold copper
chrome beacon
#

Yes

#

That wiki has everything you need

#

Take a look around :)

bold copper
#

Looks like I 'm really blind .. Okay, I'll look for more.

chrome beacon
#

Text Serializers
Or MiniMessage

tardy delta
#

i'm currently having a KingdomsPlayer class which stores a AtomicReference<PlayerData>, should i just throw all data in there or should i make it more structured?

quaint mantle
#

Also, i think its craftbukkit not spigot

tardy delta
#

'im for example saving a list of homes, cooldowns, the kingdom

chrome beacon
crude loom
bold copper
chrome beacon
#

You're already using Paper api

#

It includes all of that

bold copper
#

however, the development environment does not see MiniMessage

#

despite the fact that the paper fork with all its classes is in dependencies

chrome beacon
#

Are you on 1.18.2?

#

@bold copper ^^

bold copper
tardy delta
#

any good tutorial how to work with h2 databases

crimson terrace
#

whats the best way to deal with CraftBukkit versions? Do I just have to make an if else statement for each version I want to support?

bold copper
# chrome beacon <@735856983231561740> ^^

I found a suspicious similarity of work

player.sendTitlePart(Component);
player.spigot().sendMessage(Component);

I know for sure that sendMessage(BaseComponent[])
allows you to send a message in multiple colors

if I put in Title ,,BaseComponent[],, (Component will be empty), it will work?

hasty wasp
#

Is there a possibility to change the spigot-api code? I want to route the Bukkit#getOfflinePlayer method to my own service or something like that

bold copper
tender shard
#

and if you change the spigot code itself, your plugin will not run on other people's servers

bold copper
bold copper
tender shard
#

now you have the complete source code for spigot

sterile token
#

If you want to a modification you modify spigot-jar right?

tender shard
#

since yesterday there were a shit ton of people who suddenly want to modify the server software

#

which imho is a very bad idea

sterile token
#

Because i have seen many time spigot jar and i didnt find any impl flrmthe te api

tender shard
#

spigot.jar IS the implementation

chrome beacon
chrome beacon
#

Paper 1.18.2

tender shard
#

in paper or in spigot?

#

I thought minimessage was part of paper since like... a long time ago

bold copper
chrome beacon
#

Alright

sterile token
#

Wait why bungee component text are not full colored?

#

๐Ÿค”

tender shard
#

minimessage is very flawed imho but still 100 times better than spigot's weird "components"

sterile token
#

Yes

#

I seen the json of spigot components and its really strange

bold copper
hushed spindle
#

is there any way to tell if a called event had an actual impact in the game? like if i call an entity damage event is there a way to distinguish between an actual damaging event or just a called event

#

without comparing hp before and after a tick

sterile token
#

Also which the impl of player?

bold copper
sterile token
#

But that its from vanilla server-jar

#

Its isnt done by spigot

bold copper
#

org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer to be precise

#

implements Player

sterile token
#

Ohh ok

compact cape
#

How can I update/change the inventory name? (Preferably without NMS)

hushed spindle
#

setTitle()?

compact cape
#

There is no method ๐Ÿคท

hushed spindle
#

i guess the title can only be defined when the inventory is made

#

is it a custom inventory

bold copper
eternal night
#

pretty certain the name is part of the open menu packet

#

e.g. you cannot mutate it without reopening the inventory

compact cape
#

And the update happens every 4 tick ๐Ÿคท

#

So the cursor will be stuck ๐Ÿ˜‚

compact cape
hushed spindle
#

i mean

#

just add the title i guess

bold copper
#

He wants to change the name so that he doesn't have to create a new inventory

hushed spindle
#

without opening a new inventory i doubt that will be possible

compact cape
#

Let me clear it, Title is like this Confirm (10s) and it will count down and after that it will enable the confirm slot

#

I know there must be a way as I saw it in several servers ๐Ÿคท

hushed spindle
#

is it impractical for you to open new inventories with the same contents

compact cape
#

Update is frequent ๐Ÿคท and as I said opening new ones cause the cursor reset...

hushed spindle
#

are you closing the inventory before opening? i feel like that might cause the cursor reset

bold copper
#

I am so masochistic that I keep all non-changeable menus in RAM as a finite set of packages..

hushed spindle
#

but i dont know for sure

compact cape
hushed spindle
#

dont see why not

compact cape
#

I made the API last year... But I think not closing the last one was causing issues

hushed spindle
#

doesnt hurt to try i think lol

compact cape
#

I think so...

#

But I think I might just use NMS and reflections ๐Ÿ˜‚

tender shard
#

AFAIK it's a "standalone" system

#

but I don't really know

bold copper
#

please tell me where are the vanilla commands? (in which package)

summer scroll
compact cape
#

Packets always confuse me...

humble tulip
#

If you see the value is negative set it to max

golden kelp
#

Aight

eternal needle
#

hi when i type somthing i get a white line over it like ------

compact cape
eternal needle
restive tangle
#

Is it an alright idea to have a class such as ItemRegistry be used to store static ItemStack objects?

worldly ingot
#

Sure, so long as you understand that ItemStacks are mutable so things like ItemRegistry.MY_ITEM.setAmount(5) would change it

river oracle
#

You could make a series of static getters to make sure they aren't mutable

worldly ingot
#

^, .clone() them

#

Was about to recommend the same

river oracle
#

Probably the best option in that case

echo basalt
#

it would be so cursed

#

imagine a

public static ItemStack MY_ITEM() {
  return MyClass.MY_ITEM.clone();
}
worldly ingot
#
private static final ItemStack ITEM = // whatever

public static ItemStack getItem() {
    return ITEM.clone();
}

public static boolean isItem(ItemStack itemStack) {
    return ITEM.isSimilar(itemStack);
}```
#

That's generally what I would do

midnight shore
#

is it safe to add an event listener to a class constructor? or would this cause a lot of problems when you have a lot of class instances?

worldly ingot
#

I'd avoid registration of listeners in constructors

#

I know some people prefer doing that but it's just... not great...

#

(1) Loose object construction
(2) Not clear that it's being registered
(3) Prone to mistakes if multiple instances are created

midnight shore
#

oh ok

worldly ingot
#

Though to answer your question about whether or not it's safe: yes it's safe

#

Just unclear

midnight shore
#

how would i listen for a left-click at an entity?

river oracle
#

Use a listener

midnight shore
#

Really? I thought i should use a recipe

#

: /

river oracle
#

Np

midnight shore
#

i know that i need to use listeners but what event should i use its my question

quaint mantle
#

I need help storing custom enchants on a pickaxe, and I don't want to do that in a .yml file, what would be a smarter option to do to have something like this?

midnight shore
#

use the PersistentDataContainer

midnight shore
#

this only triggers on right-click

river oracle
#

You want on punch?

midnight shore
#

yes

river oracle
#

EntityDamageEvent

midnight shore
#

what if the entity is invulnerable armor stand?

#

would that trigger?

earnest forum
#

probably

#

still shows hit particles right?

quaint mantle
earnest forum
#

yes

#

u can make custom persistent data types

#

make like a class that stores all the info u need

midnight shore
karmic hull
#

Hey, how can I cancel the throwing of a snowball and give it back in the Inventory with the onPlayerInteract event? Is it even possible?

midnight shore
crimson terrace
#

PlayerInteractEvent @karmic hull

quaint mantle
#

Okay, another question, would it cause lag if I got the persistent data every time someone broke a block ?

crimson terrace
#

you can cancel the throwing

karmic hull
crimson terrace
#

if you cancel the event it should just not do anything

karmic hull
#

no difference

midnight shore
#

as my experience

crimson terrace
#

try it with the projectileLaunchEvent

quaint mantle
midnight shore
#

np

karmic hull
crimson terrace
#

you can get the entity which launched the projectile, right?

karmic hull
#

yea, but not the itemStack i guess

#

its an EntityType

crimson terrace
#

EntityType.SNOWBALL

crimson terrace
quaint mantle
#

@midnight shore would you store the economy in PDC ?

#

Such as /balance /tokens etc..

crimson terrace
quaint mantle
#

Oh so it only loads a data when a player's online ?

crimson terrace
#

you cant get the PDC of an offline player as far as I know unless you store it in a file

karmic hull
# crimson terrace did you figure this out yet?

oh sorry, needed to go away for a short period. My problem is that if I cancel the ProjectileLaunchEvent nothing happens, I would need to manually give the player the item back and remove the entity. Same with the PlayerInteractEvent. Should this be the case?

earnest forum
worldly ingot
#

database

#

YAML is not storage

earnest forum
#

depends what u have access to

worldly ingot
#

If you don't have access to MySQL, you always have access to SQLite

crimson terrace
#

if the cancelling does not work as you want it to you have to give back the item to the player and remove the launched projectile... not sure about what cancelling the ProjectileLaunchEvent actually does

quaint mantle
#

I'm using MySQL

earnest forum
#

use that for your economy then

crimson terrace
#

YAML can be abused as storage tho :3

karmic hull
crimson terrace
#

hold on, checking the event real quick

#

well for one you can get the launched projectile with the getEntity() method. From there you can get the ProjectileSource with getShooter(), check whether thats a player and do whatever in the inventory there.

compact cape
#

For some reason, I have items in my GUI inventory but I can not see them on my client ๐Ÿค”

quaint mantle
#

How do I update a minecraft plugin that is 1.16.5 to 1.18.2?

karmic hull
crimson terrace
earnest forum
#

as long as you dont have nms it should be fine

crimson terrace
quaint mantle
crimson terrace
#

do you have nms?

rotund pond
wet breach
crimson terrace
#

it was meant as a half joke but yeah

sterile token
#

Any ideas for designing protocols?

wet breach
#

protocol for what exactly?

sterile token
#

Communication one

wet breach
#

yes lets just keep it broad

#

you designing a protocol level like TCP or something? Or you talking about software protocols

sterile token
#

Im thinking to design a protocol using a backend as base

#

I think looks more similar to "SMS" or "SMTP"

echo basalt
#

All protocols need a backend

#

but are you looking for something like Minecraft's protocol where it's basically TCP on crack or something a little more specific?

#

minecraft's protocol operates on a very simple ideal, where you just have a packetid and you let both sides decypher info based on that id

#

there are some slightly more complex byte structures that indicate the type of data the following byte segment has, like nbt

#

where you have a byte saying wheter it is a long, an nbt tag etc and then you just parse it based on that byte

red sedge
#

How memory intensive would a trie be?

#

In java

red sedge
# red sedge In java

Like I think using hashmaps is the only way so like how mcuh overhead is there

sterile token
red sedge
#

Ya obviously but like

#

is there any overhead specific to java

sterile token
# echo basalt All protocols need a backend

Yeah i was a protocol similar, which allow sending/receiving data (my server working as a router), which allow multiple people doing their communication. Defining custom packets

red sedge
#

or smth else i should use instead of a hashmap

wet breach
#

those are easy to create for the most part

midnight shore
wet breach
#

the hard part is keeping the packets/data to small sizes for what you are creating as well as avoiding duplication

sterile token
#

So i dont know from where to start, so i was looking if i can find any ideas for doing the protocol layer design

wet breach
#

that something is returning null either because it is or you made it null

#

but you asserted it isn't suppose to be

midnight shore
wet breach
#

partial or image shots of code isn't helpful

#

and what I said also applies to api methods too

#

where it was asserted to not be null, but you made it null anyways

ivory sleet
#

if you wanna reduce memory usage, then operations may scale worse

red sedge
#

Soo a hashmap it is?

wet breach
ivory sleet
#

lol. sure

red sedge
#

Im just not quite sure about the overhead that comes with java has maps so its kinda scary

ivory sleet
#

it has a good time complexity so it scales quite well

#

do some benchmarking Ig

wet breach
ivory sleet
#

or read already benchmarked results

red sedge
wet breach
#

then you really have no concerns over overhead of any kind of object you decide to use

humble tulip
#

I'm wondering how a server implementation works in java. If inwere to create my own would i have a thread for each socket connection and have a main thread with a concurrentcollection where i store "packets" to be processed?

red sedge
#

Ya but when the amount reaches 10s of thousands I'm just not quite sure

ivory sleet
#

The most convenient optimization would be for you to define the scale factor for your hashmap lol.

wet breach
red sedge
#

Alr

wet breach
#

very fast

ivory sleet
#

yeah youd usually opt in for a thread pool

humble tulip
#

Doesn't wating for data from a socket block the thread?

wet breach
#

it could, depends how you have it setup

#

Network cards have buffers

#

as long as you don't make it wait too long you could have a non-blocking thread

ivory sleet
#

I mean both netty and java nio can help you with the entire concurrency design

humble tulip
#

Never looked into any of those

#

It's just something i think about sometimes

#

I'll have a look into it

wet breach
#

well you should also research what network hardware is capable of too ๐Ÿ˜›

#

netty is the library that MC uses for its network implementation

#

nio is the java package in java that is for concurrency

humble tulip
#

Btw for runnables that need to run sync from an async task, does it just add the runnable to a concurrentset and call runnable.run on the next tick?

ivory sleet
#

define sync?

#

are we talking about the server thread?

humble tulip
#

Main bukkit thread

#

Ye

ivory sleet
#

ah

#

yeah well use the BukkitScheduler then

humble tulip
#

No i mean how does it work internally

ivory sleet
#

oh

#

it is basically a queue

#

(thread safe)

#

that picks off runnables every round

wet breach
#

an asynchronous task that executes a synchronous task will cause the asynchronous task to wait on that sync one every time it is called

quaint mantle
humble tulip
#

Been working with other threads alot recently and concurrency is mind boggling

#

Haven't run into issues yet but i feel like I'll cause a deadlock eventually

wet breach
#

synchronous and asynchronous tasks do not directly relate to threads

ivory sleet
#

always smart to read up on stuff like optimistic concurrency design

humble tulip
#

Can i read 1 variable from 2 threads at the same time safely?

wet breach
#

well I guess it is if you really know how

#

but for the most part, Java won't let you easily do that ๐Ÿ˜›

humble tulip
wet breach
#

it doesn't just happen randomly lol

ivory sleet
#

the value of the variable might not be 100% up to date

#

but sure

#

works anytime

humble tulip
#

Ohhh

#

I thought that was gonna cause problems

ivory sleet
#

well

#

doing multiple operations can cause concurrency update problems

wet breach
#

if you need the variable to be the same between two threads or a method to be thread safe use the synchronized keyword in java

ivory sleet
#

if you're setting the value of a variable based on an old value

#

for instance

humble tulip
#

So even setting and reading on multiple tjreads is thread safe

sterile token
#

Java objects are sync right?

tardy delta
#

yes

quaint mantle
#

What does the * mean after a plugin name in /pl?

tardy delta
#

wouldnt make sense otherwise, they would have to use futures

wet breach
humble tulip
#

Ok thought so

wet breach
#

if you try to do things say on an array that adds and removes in one operation

humble tulip
#

Which is why i get data async and set it sync

ivory sleet
#

no

#

objects have no notion of sync/async

humble tulip
crimson terrace
#

they said collections at first

ivory sleet
#

methods do tho

crimson terrace
#

they edited it

wet breach
tardy delta
#

there was 'collections' before

crimson terrace
sterile token
wet breach
#

I mean adding or removing and then reading

#

what happens in that scenario is that what was read in the list, may not be in the list anymore

ivory sleet
#

the methods a collection offers may support it

tardy delta
#

dunno how objects would be async

humble tulip
#

How will i be reading and writing in one operation from different threads though? I can understand if the read and write occurs at the same time but it'll be different operations

stray flare
#

noobie question..

How do I add radius using e.getPlayer().playSound

wet breach
#

if you have 2 threads that are doing it, its not 2 operations per-say one after the other. Its 2 operations at the exact same time or nearly

#

thus the reading could happen before the write

#

which is not the ideal scenario in most cases

#

or you could get 2 write operations that add and remove a variable in the same position

humble tulip
wet breach
#

if the remove was suppose to happen first before the add

#

you could get the add happening before the removing ๐Ÿ˜›

ivory sleet
wet breach
#

now if you use the synchronized keyword though on methods, any threads accessing that method will need to wait for that method to complete before getting their turn. This a cheap way in making something non-thread safe into something thread safe. But have to be careful in doing it this way as you could potentially take performance hit doing so.

ivory sleet
#

Yeah for starters using synchronized will suffice, but as you develop you must learn how to operate atomically and learn about Javaโ€™s framework concerning multithreading

humble tulip
#

Let's say i have a dataholderobject that is only modified sync, can i load the data into it on asyncprelogin since it's on a different thread but when I'm ready to read and modify, it'll be done on one thread only

humble tulip
ivory sleet
#

minion in principle

wet breach
ivory sleet
#

^

wet breach
#

it doesn't necessarily get its own thread to execute in

crimson terrace
ivory sleet
#

async means code does not run linearly to its expressive declaration

stray flare
#

my bad wrong line

#

Thats the line:

e.getPlayer().playSound(loc5, Sound.EVENT_RAID_HORN, 25.0F, 1F);

ivory sleet
#

btw

wet breach
#

think of asynchronous as meaning the work is spread out over multiple ticks instead of trying to do it in a single one

humble tulip
#

Get all the players in thenradius and play thebsound for them

stray flare
humble tulip
wet breach
#

yes

ivory sleet
#

Sync - code runs linearly (by reading the order you put your statements in, you can predict the order the code will execute)
Async - code does not run linearly thus you cannot predict in what order the code is going to run despite knowing the order of how the code was declared

Concurrent - two operations run seemingly at the same time, but not really
Parallel - two operations can run exactly at the same time, usually when you have multiple processors

sterile token
ivory sleet
#

depends

humble tulip
#

So why is it reccommend to save data async if it's possible tjat it runs on the main thread?

#

Wouldn't that be blocking

red sedge
ivory sleet
#

not really

sterile token
#

When saving data into database or using rest api, if you dont use async can block the main thread or atleast you lost resources

sterile token
ivory sleet
#

more like, when the backing array is full, how big it should be resized to

wet breach
red sedge
#

since its not going to be mutated any further

wet breach
#

so it will slice up your task, and add other tasks in there too in the loop

ivory sleet
#

uh sure lol.

wet breach
#

and then keep processing those small slices until its done

humble tulip
wet breach
#

yes, except it won't try fitting your task in that full 50ms

red sedge
wet breach
#

you might have a fraction get done in one tick

#

then it might skip doing your task for 1-2 ticks

#

then come back and do 2 of your tasks etc

humble tulip
#

How would it run half my runnable though?

wet breach
#

but the point being, your task is just broken up over time to fit in with everything else going on

humble tulip
#

Or does it?

ivory sleet
#

in Java its by convention not possible unless you throw some error inside the runnable or use Thread.interrupt()

humble tulip
#

So if my async runnable takes 3 seconds and it haooens to be run on the main thread, it will lag?

ivory sleet
#

pretty much

humble tulip
#

Wtf

sterile token
humble tulip
#

That i did not know

ivory sleet
#

or well

#

there is no real concept of the main thread

humble tulip
#

So should i use my own threads then if i have really heavy reading/writing to do?