#help-development

1 messages · Page 1727 of 1

golden turret
#

NullPointerException

ivory sleet
#

getRecursiveAbstractFactoryFactorySodaBaseImpl()

tender shard
#

why does this remind me so much of the internship I once did

#

FactoryFactories and stuff

#

ergh

mystic sky
#
    return new cocacola(Double.parseDouble(Cocacola[0]), Sprite.parseLong(sprite[1]));
tender shard
#

I don't have any coke

#

so vodka sprite it is

lavish hemlock
ivory sleet
lavish hemlock
#

cocacola, Cocacola

ivory sleet
#

😮

lavish hemlock
#

also

#

Sprite.parseLong lol

mystic sky
#

Yeah, well i won't add that to my code

lavish hemlock
#

(meanwhile, Kotlin: return CocaCola(cocaCola[0].toDouble(), sprite[1].toLong()))

alpine urchin
#

public class player {

}

tender shard
#

drinking Sprite reminds me of my BlitzBasic time

ivory sleet
#

protected final synchronized sealed record A<T>(T t) {}

lavish hemlock
#

I don't think you can synchronize a record

#

I also don't think you can make a protected class

#

I also don't think you can make a sealed record when it's also final and also records can't be inherited (also final is redundant since records are final by default)

#

so there are many things wrong with this

tender shard
#

seems like it's perfectly fine to me

ivory sleet
#

hehe

crimson terrace
#

sheesh

ivory sleet
#

yeah maow

tender shard
#

only 80% invalid keywoards, that's quite good

alpine urchin
#

stop sippin sprite

ivory sleet
#

mfnalex is
record A<T extends A<T>>(){} possible btw?

alpine urchin
#

stop askin for more

ancient plank
#
IT'S SHOWTIME
TALK TO THE HAND "hello world"
YOU HAVE BEEN TERMINATED
alpine urchin
#

cause that sprite ain't clean

ivory sleet
#

oh lol

alpine urchin
#

lets make a programming language that compiles english

tender shard
#

at least it doesnt complain and compiles fine

lavish hemlock
#

it's possible

alpine urchin
#

And sue people for distributing our code

lavish hemlock
#

but you probably can't use the record

#

unless you A<?> or A it

alpine urchin
#

whenever they mention our words

lavish hemlock
#

bc nothing can extend so A so nothing besides a raw type or wildcard can be placed there

#

so your IDE would probably warn you about doing that

ivory sleet
#

yeah indeed

alpine urchin
#

i just witnessed bugs bunny scoring a hoop

lavish hemlock
#

but yeah, nothing semantically wrong about it ig

tender shard
#

anyone know how I can add javadocs to the lombok constructors, builder methods and getters setters?

I know I can just write javadocs for the fields but that would require to always add the param and return things manually because IntelliJ doesnt generate them automatically for lombok annotated fields 😦

ivory sleet
#

just dont use lombok

tender shard
#

but I like it

#

the class would be about three times as long without it

lavish hemlock
#

anyone know how I can add javadocs to the lombok constructors, builder methods and getters setters?

you can't, you have to write them manually

eternal night
#

records are crying

tender shard
#

I have to support MC 1.16 too 😦

lavish hemlock
#

record classes probably have internal JVM optimizations as they are immutable

eternal night
#

1.16.5 latest supports java 16

lavish hemlock
#

so Lombok would be the one crying

tender shard
#

and they won't upgrade just for one or three plugins

#

at least some of them won't

#

at least not today

#

so does anyone have a real idea instead of not using lombok? 😄

ivory sleet
#

afaik records hashCode and equals method is generated using lambda meta factory and method handles, unsure about toString

ivory sleet
#

ya

lavish hemlock
#

there is no other way, Alex

ivory sleet
#

lombok is purely useless, soz alex

#

imo

tender shard
#

I just thought that IntelliJ would somehow support it using a plugin or sth but I didnt find anything

valid solstice
#

anybody here working with intellij idea? i cant add spigot 1.17.1 to the dependencies for some reason...

#

*spigot 1.17.1 api

#

im in macos

tender shard
#

actually lombok is pretty awesome at times, e.g. sneakythrows, UtilityClass, Getter/Setter/Data, NonNull, etc bla bla

ivory sleet
lavish hemlock
#

sneakythrows are concerning

#

just use Kotlin if you don't wanna deal with exceptions :p

tender shard
valid solstice
ivory sleet
#

wat

#

literally isnt

#

if you know the keybinds it takes less time than writing it out through an annot even

valid solstice
#

usually i can make plugins in window os and can put the spigot api into the dependencies, but for macos idk why its not working

tender shard
ivory sleet
#

I mean records and you can minimize it if you use a reasonable ide

tender shard
#

but of course both have their advantages and disadvantages - I am used to lombok and will continue to use it, but of course it also has some downsides

ivory sleet
#

also the code will be about same once compiled

tender shard
#

as said I can't use records until almost everyone is on java 16/17 :/

ivory sleet
#

¯_(ツ)_/¯

tender shard
#

I'll just manually write the javadocs

#

for the fields

#

I don't have anything better to do right now anyway

ivory sleet
#

javadocing fields lmao

tender shard
# valid solstice thanks!

np! If you have any further questions about that guide, just write a comment on the blog so I can add it to the guide

ancient plank
#

my server gets angy if I use java 16 on 1.16.5 :(

tender shard
#

what JDK are you using?

ancient plank
#

lemme boot the server

tender shard
#

on windows I'm using oracles JDK and on debian 11 just the default openjdk-17-jdk from the official repos

ancient plank
#

nvm it works apparently

#

it didn't a few months ago

tender shard
#

hm strange

ancient plank
#

well fuck man

#

time to go change my plugin to java 16

tender shard
#

I'm still scared to switch my plugins java version to 16

#

too many java 8 users still around

#

they'll write one star reviews because "Unsupported major minor version" and then never reply again when I tell them what's wrong

ancient plank
#

f

#

I don't like java 8 because it doesn't have try-with-resource statements

tender shard
#

lol

#

yes

#

it does

#

I use them all the time

ancient plank
#

like the multilined ones

#

where you can declare multiple variables at once or w/e

lavish hemlock
tender shard
#
    /**
     * Turns an ItemStack into a byte array
     *
     * @param itemStack ItemStack
     * @return ItemStack as byte array
     * @throws IOException exception
     */
    public static byte[] toBytes(final ItemStack itemStack) throws IOException {
        try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
             final ObjectOutput objectOutputStream = new BukkitObjectOutputStream(outputStream)
        ) {
            objectOutputStream.writeObject(itemStack);
            return outputStream.toByteArray();
        }
    }
#

like this?

#

that's perfectly fine in java 8

lavish hemlock
#

that right there is valid in Java 8 ^

ancient plank
#

wtf man

#

it wouldn't work for me

#

im so scuffed

#

i hate coding im gonna go become a janitor

tender shard
#

my lib is full of that stuff and I always compile against java 8 😮

ancient plank
#

it was tellin me to upgrade to at least java 9 for that

tender shard
#

it throws errors when you define non-autoclosables inside the ( ) though

#

but after all something that's not autocloseable doesn't have to be inside the brackets

ancient plank
#

wanted to use it for my database controller but it wasn't working

tender shard
#

hm maybe you had some other mistake and the error was just misleading

lavish hemlock
ancient plank
#

idk

#

all I know was intellij was telling me "ayo bro you gotta use at least java 9 to use this feature, wanna upgrade?"

ancient plank
#

I'd go check but intellij takes 50 years to open on my computer since I think it's on my hdd and not my ssd

valid solstice
#

can a paper server run spigot plugins?

eternal night
#

yes

mystic sky
valid solstice
#

ty

acoustic pendant
#

Hello, i have imported the API and this problem happens,
Could be the error caused by the version?
It's outdated

acoustic pendant
tender shard
lavish hemlock
acoustic pendant
#

mfnalex

#

look

tender shard
#

also why would you need it? action bar is accessible by spigot

alpine urchin
#

oh i just saw it

tender shard
alpine urchin
#

yea java 8 does have it

acoustic pendant
lavish hemlock
#

try (ByteArrayOutputStream baos = new ByteArrayOutputStream()), y'know

alpine urchin
#

im like some new java feature?

#

that i missed out

tender shard
alpine urchin
#

yea yea

#

true

tender shard
#

one sec I'll send an example

lavish hemlock
#

ARM has existed since Java 7

lavish hemlock
#

yes

alpine urchin
#

exactly

tender shard
acoustic pendant
lavish hemlock
#

Automatic Resource Management

tender shard
#

you add your dependency to intellij although you're using maven

lavish hemlock
#

it closes baos at the end of the try block within a finally I believe, very useful

tender shard
#

that's like paying your rent to your neighbour instead to your landlord @acoustic pendant

#

maven needs the dependency, not intellij

acoustic pendant
#

ok, i will check a thread ty

lavish hemlock
alpine urchin
#

thanks for the explanation

quaint mantle
#

Do we have any others jar than bukkit (no counts its forks)

tender shard
#

I have a hundred jars on my hard disk

#

I don't really get your question

lavish hemlock
#
OutputStream os = null;
try {
    os = getStream(); // for example purposes
    useStream(os);
} catch (IOException ex) {
    ex.printStackTrace();
} finally {
    try {
        if (os != null)
            os.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
lavish hemlock
lavish hemlock
#

(os is assigned in try as getStream theoretically throws IOException)

alpine urchin
#

you are actually giving me a whole tutorial

#

thanks

quaint mantle
#

Any other server jar that is different than bukkit and its forks, vanilla is an example

lavish hemlock
#

I mean

#

Every popular modloader?

lavish hemlock
#

They have their own server patching methods.

#

Forge, Rift, and Fabric have server patching (I think Rift does).

quaint mantle
#

No counts mod either tho i forgot 🙂

alpine urchin
#

minestom?

tender shard
quaint mantle
#

They required players to uses mod

lavish hemlock
tender shard
#

depends

lavish hemlock
#

server-side mods exist

#

which don't require the user to install the mod either

alpine urchin
#

minestom and sponge, i just mentioned them

eternal oxide
#

try (OutputStream os = getStream()) { then you don't need the finally

quaint mantle
#

Minestom? Sponge? Heard it before but never tried it

lavish hemlock
#

I was explaining the non-ARM version

lavish hemlock
#

Mixins :)

tender shard
#

I uses sponges all the time when showering

tardy delta
#

smh

quaint mantle
#

Uhmmm… nothing really interesting, do you guys aphave any other server jars?

lavish hemlock
#

Sponge isn't interesting to you?

tender shard
#

although I'd use one of the works for a real server

#

but none of the forge / etc things

lavish hemlock
#

Pretty sure Sponge allows you to run Spigot and Forge.

tender shard
quaint mantle
lavish hemlock
#

Sponge just released a preview build for SpongeVanilla 1.17

#

which means that SpongeForge'll eventually get a 1.17 build too

tender shard
#

all I remember is that I used to get a ton of bug reports from people using sponge and it was always caused by sponge only implementing bukkit/spigot very poorly

#

IIRC there was a timespan of a few months where they didnt even call PlayerDeathEvent when a player died

lavish hemlock
#

perhaps if Spigot was easier to implement lol

tender shard
#

maybe I'm confusing the PlayerDeathEvent bug with another hybrid thing though

quaint mantle
#

Uhh, just a minor question that I should know before even starting java, but do you guys think 2 years is the needed time to learn all of the basic of java? Maybe less if you already know how coding work

tender shard
#

soooo

#

that can't be answered generally

quaint mantle
#

Yep

#

Oh btw

#

Coding like what you love the most is better than just follow some tutorials about how you should code (clean code) right?

eternal night
#

no

quaint mantle
#

Depends i think

eternal night
#

there is a line yea. Obviously on some high level you can argue about how to code and should just use your own style.

#

but "I like how my public static mutable global state variable is available everywhere" isn't too much help

quaint mantle
#

I don’t even use static

#

😂

lavish hemlock
#

I use static for utilities and stuff

quaint mantle
#

Lel

#

That is a joke tho, but i really don’t use static

lavish hemlock
#

if Java had top-level functions and namespaces

quaint mantle
#

I used constructor for everything

lavish hemlock
#

then I wouldn't need to use static at all, really

severe marsh
#

How can I get information about potion such as type, durability, level and splash?

eternal night
#

or are you talking about the itemstack representation

severe marsh
#

So let's say I have ItemStack and I want to check if it's potion and if it is then I want to get its type, durability...

severe marsh
#

Thanks

amber vale
#

?paste

undone axleBOT
amber vale
#

Please tell me what's wrong 😂

severe marsh
#

@eternal night I can't use PotionData tho

eternal night
#

huh ?

#

why not

severe marsh
#

It doesn't exist, I can't import it at all

#

Is it because of spigot version?

hasty prawn
#

Are you using 1.8.9

severe marsh
#

yeah

#

seems like it's for 1.9+

#

What could be solution for 1.8 tho?

hasty prawn
#

🤷‍♂️ you're kinda on your own if you want to support 7 year old server software

#

My best guess would be setMainEffect

severe marsh
#

aight

amber vale
alpine urchin
#

Yes

ivory sleet
#

How do u instantiate TestClass?

#

ItemRegistry field won’t be null unless you pass null to it ofc

#

But based on that little snippet you sent it’s impossible to tell

final fog
#
((LivingEntity) entity).damage(25);
entity.setVelocity(vector1.multiply(2));
``` Does anyone know how I could make it so that this code doesn't crash my server?
wide coyote
#

maybe vector1.clone().multiply(2)

#

and what is the error log?

#

@final fog

final fog
#

I fixed it

#

nvm

#

apparently it wont let me multiply it by 2 but it will let me multiply it by 1

tender shard
stiff ember
#

How can I get a direction from two locations so one faces the other?

#

Lets say I have one object at 0, 0, 0 and another at 10, 10, 10. What direction does 0, 0, 0 need to face to be looking at 10, 10, 10?

#

Idk how else to explain it

tender shard
#

and then use Vector#angle(Vector) which returns the angle between both vectors in radians

#

is that what you need?

stiff ember
#

Uh

#

yes

#

Sounds like it

#

tthanks

tender shard
#

np

stiff ember
#

Wait what uh

#

it says Vector.angle returns a float?

tender shard
#

yes

stiff ember
#

uh

tender shard
#

I have no idea about vectors and stuff, it's just what I found by looking through the javadocs, no idea if that's anyhow related to what you need lol

stiff ember
#

oh

#

i mean

#

it seems like it work work but I need a vector

tender shard
#

ah I think I know what you need

stiff ember
#

Probably something with normalize?

#

idk

tender shard
#

subtract one vector from the other and normalize the result

stiff ember
#

Oh

tender shard
#

then you should have a vector pointing in the right direction

stiff ember
#

uh wait so lets say its 10, 10, 10 and 5, 5, 5

#

would give 5, 5, 5

#

then normalize gets

#

uh

#

how does one normalize

tender shard
#

normalize()

stiff ember
#

oh i mean

#

outside of code

#

lol

hasty prawn
#

What are you trying to do exactly?

stiff ember
#

in math

tender shard
#

he has two locations and wants to get the direction that you have to look from loc1 to look to loc2

stiff ember
#

yes

hasty prawn
#

I think you can just subtract one vector from the other and it'll give you a vector that starts at one and points to the other

tender shard
#

yep

#

and then normalize it

hasty prawn
#

^

#

Well depending on what you wanna do with it I guess

tender shard
#

yeah true

hasty prawn
#

If you're setting Velocity, yeah, normalize it KEKW

stiff ember
#

ok ill try it

tender shard
#

to get pitch / yaw you probably have to do this ugly sin/cos things on the nomalized vector I assume? 😄

stiff ember
#

yeah im trying to make a turret

#

uh

#

oh

#

wait you cant cast location to vector?

tender shard
#

Location.toVector

#

this is probably what you're looking for?

stiff ember
#

Oh

#

I need all of that?

tender shard
#

the first code

#

you provide two locations

#
  1. your current location
#
  1. the location you want to look at
#

then it returns location number 1 with adjusted pitch/yaw

#

so that you are still standing at loc1 but you are looking at exactly loc2

#

isn't that what you need?

stiff ember
#

uhhhh

#

I think I need a vector

tender shard
#

what exactly are you trying to achieve?

stiff ember
#

trying to make a turret that shoots at nearby players with arrows

#

I already got nearby players

#

just need to shoot them

tender shard
#

is your turrent an entity?

#

or what exactly is it?

stiff ember
#

block

#

its end rod

tender shard
#

so you only need a vector where it should at

#

shoot at*

stiff ember
#

uh

#

Im using the

#

World.spawnArrow(Location, Vector (rotation), speed, somethingelse)

tender shard
#
Location turretLocation = ...;
Location whereToShootAt = ...;

Vector direction = turretLocation.toVector().substract(whereToShootAt.toVector()).normalize();
stiff ember
#

Its that short?

tender shard
#

you can then then use turretLocation as Location in the spawnArrorMethod, and direction as your Vector (rotation) thing

#

(I THINK)

#

just try it

#

if it shoots in the opposite direction, you have to switch the turretLocation and whereToShootAt location of course in the vector calculations

stiff ember
#

subtract or substract?

#

Apparently both exist

#

in the context

tender shard
#

hugh? both exist?

#

only subtract exist, I just made a typo

stiff ember
#

on an object

#

oh

tender shard
#

I just typed it into discord

stiff ember
#

Object.substract works

tender shard
stiff ember
#

Well

#

it was happy with .substract once I casted the vector to an object

tender shard
#

stop blindly casting everything

#

also

#

everything in java is an object

stiff ember
#

yeah ik

tender shard
#

and Object also doesnt have any "substract" method

stiff ember
#

it was a suggested thing

#

nvm

#

i was wrong

#

it was something else

young knoll
#

Technically primitives aren’t objects

tender shard
#

I meant

#

every object in java is instanceof Object

stiff ember
#

lol its shooting backwards

#

and from the corner of the block

#

just multiply by -1 i guess and subtract 0.5 from x and y

#

or is it add 0.5?

tender shard
stiff ember
#

oh

#

didnt see that

tender shard
#

multiplying by -1 should work fine

stiff ember
#

I just switched them

#

looks cleaner I think

tender shard
#

is it working?

stiff ember
#

Its getting stuck in the block

#

just gonna add 1 to the height

#

great

#

my ftp just stopped working

formal dome
#

i cannot figure out this jdbc url for the life of me

#

why is it null?

#

specifically jdbc:mysql://address=(host=myhost1)(port=1111)(key1=value1),address=(host=myhost2)(port=2222)(key2=value2)/db

#

Connection con = DriverManager.getConnection("jdbc:mysql://address=(host=localhost)(port=3306) (user=paul) (password=password)/logReader")

hasty jackal
#

I'd use the simple url unless you have a specific reason not to and passing username and password as arguments: getConnection("jdbc:mysql://localhost:3306/logReader", "paul", "password")

indigo iron
#
    public void onBreak(BlockDamageEvent e) {

        Location location;
        Player player = e.getPlayer();
        Block block = e.getBlock();
        String broken = block.getType().name();
        ItemStack item = player.getInventory().getItemInMainHand();

        if (item != null) {
            return;
        }
        if (item.hasItemMeta()) {
            if (item.getItemMeta().getLore().contains(ChatColor.GREEN + "- Wood Cutter")) {
                if (broken.endsWith("_LOG") || broken.endsWith("_PLANKS") || broken.endsWith("_STEM") || broken.endsWith("_WOOD")) {
                    e.setInstaBreak(true);
                }
            }
        }

    }``` anyone know why it won't insta break the block please
young knoll
#

Does all the code run

#

Add debug prints

indigo iron
#

sends no errors

stiff ember
#

right?

#

you basically are making sure that item is null

young knoll
#

You return if the item is not null, yes

indigo iron
indigo iron
stiff ember
#

Wont that error?

#

Is there an easy way to get the location of the top of an end rod?

tender shard
#

does anyone have an idea on how I could check whether a player is allowed to open a chest, without having other plugins think that I actually opened the chest? (other plugins might open a GUI or something)

ivory sleet
#

The interact event maybe?

tender shard
#

Currently I'm simply calling PlayerInteractEvent and check if it gets cancelled, buuut that leads to WorldGuard messages when they are not allowed, and sometimes opens GUIs for some plugins

tender shard
ivory sleet
#

What priority?

#

Might wanna try and lower/higher one

tender shard
#

well I'm just calling the event and then check if it was cancelled

#

I'm not listening to it

ivory sleet
#

Wait wat

#

Oh

tender shard
#

yeah imagine I have to know whether a player is allowed to open a chest at x100 y64 z100

#

so I call a PlayerInteractEvent with "player XY right clicked the block at x100 y64 z100"

#

and if that get's cancelled, i know a player isn't allowed to open that chest

ivory sleet
#

Ah

tender shard
#

I haven't found a better way so far

ivory sleet
#

Feels like a terrible work around

#

Most plugins should have some sort of api for you to hook into

tender shard
#

well I cannot hook into 100 APIs 😄

ivory sleet
#

True

tender shard
#

and actually the workaround isn't thaaaat terrible because

#

let me explain why I need it

#

for my ChestSort plugin, players can sort a chest by leftclicking it

stiff ember
#

What about nms?

tender shard
#

the alternative would be the player to open the chest (so they would actually do a playerinteractevent anyway) and then sort it with the inventory open

stiff ember
#

packets

tender shard
# stiff ember packets

how would sending packets or NMS tell me whether other plugins allow a player to open a chest?

stiff ember
#

Is there a way to block packets from getting to the server?

raw coral
#
override fun getServer(player: ProxiedPlayer): ServerInfo? {
        if(onlinePlayers.containsKey(player.uniqueId)) return onlinePlayers[player.uniqueId]!!
        if(!player.isStaff()){
            player.disconnect(ComponentBuilder(ChatHelper.format("&cServer is in maintanence mode!")).currentComponent)
            return null
        }
        if(main.serverHandler.hubs.isEmpty()){
            player.disconnect(ComponentBuilder(ChatHelper.format("&cNo hubs online!")).currentComponent)
            return null
        }
        val server = main.serverHandler.getHub()!!
        onlinePlayers[player.uniqueId] = server
        println("Player ${player.displayName} is being sent to hub: ${server.name}")
        return server
    }

Does anyone know the right way to do this? Because I'm getting a NullPointerException and the player isnt getting kicked.

tender shard
raw coral
#

the return nulls

tender shard
#

well returning null cannot cause an exception

stiff ember
#

Is having too many repeating tasks a bad thing?

tender shard
#

define "too many"

stiff ember
#

oops

tender shard
#

not at all lol

#

unless they are doing very very expensive stuff

stiff ember
#

ok

#

ty

#

also

tender shard
#

when those tasks compile spigot, then even one task is too many lol

stiff ember
#

How can I get the location of the tip of the end rod?

tender shard
#

you mean regardless of whether it was placed left/right/up/down of a block?

stiff ember
#

yeah

#

Is there an easy way to do it?

#

Without a bunch of ifs

tender shard
#

Block has a method getBoundingBox

#

but you'd still have to do some calculations based on the rotation of the rod etc

stiff ember
#

Well if I know the rotation I can just add or subtract one to the right axis

#

e

#

Ill have to do that i guess

tender shard
#

End rod's blockdata implements Directional

#

so cast the Block#getBlockData to Directional and you can get the BlockFace / "rotation"

#
import org.bukkit.block.data.Directional;
Block block = e.getBlockPlaced();
Directional blockData = (Directional) block.getBlockData();
blockData.getFacing()
olive valve
#

i need help with this code i have been trying to get it working for a week @EventHandler public void onAnvil(PrepareAnvilEvent event){ AnvilInventory anvilInventory = event.getInventory(); ItemStack[] itemsInAnvil = anvilInventory.getContents(); ItemStack slot1 = itemsInAnvil[0]; ItemStack slot2 = itemsInAnvil[1]; ItemStack result = new ItemStack(slot1.getType()); if(slot2.getEnchantments().containsKey(Enchantment.getByKey(Enchantment.DURABILITY.getKey()))){ result.addEnchantment(Enchantment.DAMAGE_ALL, 4); event.setResult(result); }else{} } it has this NullPointerException java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.ItemStack.getType()" because "slot1" is null

#

can someone tell me why it says slot1 is null when its not

#

ok

#

it output this Lorg.bukkit.inventory.ItemStack;@1349ff99

#

ok

clear blade
#

yo, newbie to spigot so please forgive me lol
is there a way to always get a player by username (assuming the player exists)? i see on the docs org.bukkit.Bukkit.getPlayer(string) may not return a Player if the player is offline

unkempt peak
#

Bukkit.getOfflinePlayer?

clear blade
#

seriously lmao is that it

olive valve
#

it output 2

hasty jackal
#

neither length nor printing out the array will help

#

you need to print out the actual object at the index

#

which will be null

#

otherwise it wouldn't error

unkempt peak
clear blade
#

see that's the thing- i need to use usernames here because it's a hassle for players to grab their uuid

#

is there some API i can poll?

unkempt peak
#

Why can't you get the uuid?

clear blade
#

because this is a command that's being run from discord 😛

unkempt peak
#

What are you trying to do?

eternal night
#

just make sure to throw those calls onto another thread

unkempt peak
clear blade
#

si

eternal night
#

lookups obviously require network

unkempt peak
#

What does the bot command do in discord?

clear blade
#

whitelists a user if they have a given role

#

then links their discord ID to their minecraft UUID

olive valve
unkempt peak
#

Ah ok

hasty jackal
#

which makes complete sense

#

because if there's no item in the first slot it will be null

#

and you're calling a method on it

unkempt peak
#

Just do a null check @olive valve

olive valve
unkempt peak
#

If thing null return

olive valve
#

oh ive tried that

#

it doesnt work

unkempt peak
#

Show code

olive valve
#

if(slot1 == null) return;, if (slot2 == null) return;

unkempt peak
#

It's throwing an npe because slot1 is null. You need to check if slot1 is null before doing anything with it

#

What line is the npe being thrown at?

noble knot
#

Hi how do i add content to a book? When I try i get this

olive valve
unkempt peak
#

show me the line

#

23 isn't helpfull

olive valve
#

wait one sec

unkempt peak
#

ok

olive valve
olive valve
#

i dont know sorry

unkempt peak
#

ok then check if slot2 is null first

#

if you don't want do anything when slot 2 is empty return if it's null

clear blade
olive valve
unkempt peak
#

then do the same for slot1

#

you always need to null check stuff like that before using it

hasty prawn
#

Books require some specific type of data, else they do that

#

Author is one of them, I think there's another but not 100% sure.

olive valve
#

thank you!

#

i put the Null Checks in the wrong spots

#

when i was doing it

stiff ember
#

How do you get the name of an inventory?

young knoll
#

Are you in an event

stiff ember
#

yes

#

I have the inventory

young knoll
#

event.getView.getTitle iirc

stiff ember
#

object

#

ohhh

#

i was doing e.getInventory().getView()

#

that explains it

#

thanks

#

I'm making a thing where you right click a block and it opens a gui, and then you click different items to change that block. How can I get the block they right clicked in the inventory click event?

eternal night
#

store it in some form of map ?

#

you could also use a custom InventoryHolder

stiff ember
#

oh yeah hashmap

#

forogot

#

ty

opal sluice
#

Hi, I have an issues with a ResultSet from a query... I don't know why but it seems that when I do rs.next() to get the first row, it seems that the resultset is empty.

#

I tried to make the command directly on the sql db and it does return a table with the values I want

#

So, I don't understand why 🥲

#

nvm... I found the issue 🥲

quaint mantle
#

If anyone can make if u eat a specific item it give u effects dm me 🙂

young knoll
#

Are you hiring

#

Or looking for advice

quaint mantle
young knoll
#

Add a pdc tag to the item and use the PlayerItemConsomeEvent

quaint mantle
#

ik but it hard

#
        
                ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
                BookMeta meta = (BookMeta) book.getItemMeta();
                meta.setTitle(ChatColor.RED + "My Book");
                meta.setAuthor(ChatColor.GREEN + "Gamer Girl");
                meta.addPage(ChatColor.RED + "Hi,\n Welcome To Our Server "
                        + "\n Enjoy Our Server. "
                        + "\n Our Store is https://HarvsCraft.tebex.io");
                
                book.setItemMeta(meta);                
                
                e.getPlayer().openBook(book);```
#

it give error that its not a book

young knoll
#

Do you have api-version set

quaint mantle
#

oh ye I always forgets i am on 1.16

blissful folio
#

#setPlayerListName doesn't work on Join
I'm on 1.17.1 spigot, any ideas?

young knoll
#

Have you tried a 1 tick delay

blissful folio
#

I've tried 2 ticks

#

@young knoll

young knoll
#

Weird

#

Share your code

blissful folio
#
            Bukkit.getScheduler().runTaskTimer(Plugin.getInstance(), () -> {
                player.setPlayerListName(finalId + "- " + player.getName() + "      ");
                playerIDs.put(player, finalId);
            }, 0L, 5L);
formal dome
#

well that was my whole idea xD

#

i was gonna try to make this disord minecraft bridigng plugin

#

but it already exists 🥲

ivory sleet
#

make it better

formal dome
#

what're the chances the dudes who made that are on this server

opal juniper
#

meh

#

Looks like there is some1 called "Scarsz" but idk if it is them

young knoll
#

Let us check

#

It is

formal dome
#

there he is

#

vankka is in this server too

#

those two have the most commits

#

dang

tiny wolf
#

Hold up, and how is my gui var ever being changed! its final

#

im so confused rn

marsh burrow
#

Would anyone know if there is an attribute or some kind of way to change the delay of being able to put up your shield?

young knoll
#

Don't think so

tiny wolf
#

so what is intended is for it to get the items from a config once

#

but for some reason every time I open the gui it decides to add another item to it

young knoll
#

The inventory may be final

#

But the contents aren't

#

Similar to how you can add to a final ArrayList

tiny wolf
#

isnt that the whole point of final..

#

that it cant be changed

hasty jackal
#

no, the point is that you cannot re-assign a variable

young knoll
#

^

tiny wolf
#

anyways, it anyways is never setting that main variable as far as im aware to add items

ivory sleet
#

final is mostly a compile time feature to write code defensively

#

yeah but that shit does it on runtime

#

and it actually overrides final, yes ikr hacky

young knoll
#

But not static final

tiny wolf
#

I only set the local variable to the inv, never set the items in the main gui

ivory sleet
#

I believe only true constants cannot be changed with reflection due to inlining

young knoll
#

Well you can't change static final fields anymore with just reflection

ivory sleet
#

pretty sure you can?

young knoll
#

Nah you need Unsafe

ivory sleet
#

if its just static final MyCustomObject o = new MyCustomObject(); or smtng

young knoll
#

Private static final to be exact

#

Try it

tiny wolf
#

ok

young knoll
#

In java 16

ivory sleet
#

you'd ofc need to set the field accessible but else than that afaik only constants are what dont work

#

(true constants)

young knoll
#

The problem is you can't do this anymore

 Field modifiersField = Field.class.getDeclaredField("modifiers");
      modifiersField.setAccessible(true);
      modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
hushed spindle
#

hey guys, i was wondering if there's any particular reason why you can't edit the drops of a blockbreakevent directly. the only way that you can currently edit item drops is if you set the event to not drop items and to then drop them manually, but i feel this to be kind of hacky and makes it harder to make your plugins compatible with others in certain situations. i dont need to know how to do it, i just wonder about the reason why there isn't a BlockBreakEvent#setDrops(collection of item) method to make it more straightforward

young knoll
#

No idea why it's immutable

#

Spigot moment I guess

ivory sleet
young knoll
#

Not if it's static

young knoll
#

Newer java blocks it afaik

eternal night
#

because you are reflecting into jdk internals

#

which are now locked in their module

young knoll
#

Because Field is a protected class

eternal night
#

and no longer exposed

#

same reason you can no longer call URLClassLoader#addUrl anymore

stone sinew
young knoll
#

It's fine, we have unsafe

eternal night
#

tbf, this reflection shit is garbage anyway

#

PR it to the server software and properly expose it

#

life is better that way

young knoll
#

Takes much longer

ivory sleet
#

unsafe is planned to be removed in the future I think

#

and be replaced with safer api

young knoll
#

Fair enough

#

As long as it still works

ivory sleet
#

yee

eternal night
#

I mean, at some point it just becomes an issue with how much JIT could technically do as well

ivory sleet
#

if it works then skip all tests hahayes

young knoll
#

Someone tell Mojang to stop using best practices with their private static final ImmutableLists

#

smh

eternal night
#

which like, it already does xD

#

JIT actually can screw you already

#
public class JavaTest {

    private final String FOO = "a";

    @Test
    public void testMuhJIT() {
        try {
            final Field foo = JavaTest.class.getDeclaredField("FOO");
            foo.setAccessible(true);
            foo.set(this, "b");

            System.out.println(FOO);
        } catch (ReflectiveOperationException e) {
            e.printStackTrace();
        }
    }

}
ivory sleet
#

I believe Mojang even uses a singleton for a sneaky thrower

eternal night
#

yields very interesting results xD

ivory sleet
#

which could just be a static utility method

ivory sleet
quaint mantle
tender shard
#

I just wanted to say: using „static“ often has very good use cases

#

But of course not always

stiff ember
#

How can I use a custom ItemStack in a shaped crafting recipe?

young knoll
#

new RecipeChoice.ExactChoice(itemstack)

stiff ember
naive jolt
#

is it possible to force a player into a animation?

quaint mantle
#

packets

young knoll
#

Depends

#

You can do some with playEffect

naive jolt
#

oh

#

so thats not for particles?

young knoll
#

That would be spawnParticle

#

playEffect lets you do stuff like item breaking or the totem animation

naive jolt
#

Oh

#

I want to make the player play a certain animation

#

or even better

#

like bedrock

#

make a player play a animation from another entity

naive jolt
quaint mantle
#

me neither

#

I used constructor, but someone said that a constructor only need 3 classes, if it more than only 3 class then use something else, what it call, uhhh builder pattern or something

ivory sleet
#

no no no thats definitely not what you want to follow

#

Sure it might be convenient

#

but if you have an intermediate component which just requires other intermediate components it'd be perfectly fine just doing smtng like

Configuration config = new JsonConfiguration(
  new JsonLoader(),
  new ConfigurationSerializer(serializerContext),
  this.plugin,
  path -> Files.newBufferedReader(path),
  path -> Files.newBufferedWriter(path)
);
#

here all the components passed are significantly distinctive

#

so we dont need a builder really

#

even tho it surpasses 3 arguments

#

okay maybe not the last two

#

but yeah you get the point

stiff ember
#

How can I save a list of custom objects to a file?

quaint mantle
#

do it as you would normally

#

set(path, object)

stiff ember
#

I normally use gson

#

but

#

does it work with custom objects? Like Player?

quaint mantle
#

dont save player to a file

stiff ember
#

That was an example

opal juniper
#

as long as they are serializable it is possible

stiff ember
#

I need to save my own class

#

to file

quaint mantle
#

?google "Bukkit serialization API"

undone axleBOT
stiff ember
#

I did

quaint mantle
stiff ember
#

The...

opal juniper
#

what are you serialising

stiff ember
#

Is serialising just turning it to string?

#

and back

opal juniper
#

anything that can be stored in a file

#

so yeah

#

technically a string

stiff ember
#

    public List<Player> safe = new ArrayList<Player>();
    
    public Block block;
    
    public Player owner;
    
    public int tier;
    
    public Turret(Block block, Player owner) {
        this.block = block;
        this.owner = owner;
        safe.add(owner);
        tier = 0;
    }
    
}```
#

Im serialising this list

quaint mantle
#

no

stiff ember
quaint mantle
#

do not store a list of players

young knoll
#

Use UUIDs

stiff ember
young knoll
#

You could probably give UUIDs to the turrets too

stiff ember
#

is it just UUID instead of Player?

young knoll
#

If they don't have one

opal juniper
#

yes

stiff ember
#

They don't but how would I store the list of safe uuids

#

in a uuid

opal juniper
#

and probably use location instead of block

opal juniper
stiff ember
#

would that save to file?

opal juniper
#

uuids can go to string easily

stiff ember
#

yea

#

wel

#

well

opal juniper
#

and then i imagine there is a static from string

stiff ember
#

wdym

young knoll
#

Does spigot already handle serilization for UUIDs?

#

I've never tried

opal juniper
#

mmm idk

young knoll
#

Either way you have toString and UUID.fromString

opal juniper
#

uuid is just a java thing tho right?

young knoll
#

Yes

#

So are a lot of things you can serialize

quaint mantle
#

they serialize perfectly

young knoll
#

There ya go

stiff ember
#

im confused

#

oh

#

So what do I do after I switch to using uuids?

#

Annnnd you're gone...

raw coral
quaint mantle
#

shitlin 🤮

raw coral
#

well do you have any ideas .w.

formal dome
#

any tutorials on config.yml... location... ways to read... what to put in

#

found it sorry for askin like a dope

stiff ember
#

How do I serialize a Block?

real spear
#

Ik it's a dumb question, but what is the best way to innit a list? I am doing it like this rn:

    List<String> bannedWords = new ArrayList<>(){{
        add("word 1");
        add("word 2");
        add("word 3");
        add("word 4");
        add("word 5");
    }};
sullen marlin
#

Arrays.asList("word 1", "word 2" ....)

#

if you're looking for banned words consider using a set though

real spear
#

what would be the benefit?

sullen marlin
#

faster

real spear
#

mk. I will look up the usage. it's been a while since i've used java. ty

quaint mantle
#
Set<String> blockedWords = Set.of("word 1", "word 2");

//
blockedWords.contains(word);
formal dome
#

does the config file go in resources?

#

along with plugin.yml

quaint mantle
#

yes

vagrant heron
#

@quaint mantlehey it is possible get some help with NuVotifier and GAListener....this is killing me

stiff ember
#

How can I save a list of custom objects?

quaint mantle
slow topaz
quaint mantle
#

?

slow topaz
#

oh... my bad.. did not read correct 😄

stiff ember
#

Ok I got my custom object serialized but now how can I serialize the list of serialized objects?

quaint mantle
stiff ember
#

wdym

quaint mantle
#
List<MyObject> list = ...;

config.set("path", list);
stiff ember
#

That saves to file?

quaint mantle
#

yes

#

you're overthinking it

stiff ember
#

with one of my own classes?

#

as the object?

quaint mantle
#

🙂

stiff ember
#

no one else

#

told me this

#

I think

#

config cannot be resolved?

wide flicker
#

if you're in your main plugin class, getConfig() will get it

stiff ember
#

Wont this just add it to the config.yml file?

clear blade
#

heyo, what's the difference between Bukkit.getOfflinePlayer() and Server.getOfflinePlayer()?

young knoll
#

Nothing

clear blade
#

awesome

wide flicker
stiff ember
#

wdym

wide flicker
#
File file = new File(getDataFolder() + File.separator + "your_config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
config.set("path", "value");
try {
  config.save(file);
} catch (IOException e) {
  e.printStackTrace();
}```
stiff ember
#

where does the path start?

#

in the plugins dir?

wide flicker
#

for config.set("path", "value");, the path is inside the config file. Like if you wanted to set name to whatever value, you'd put name for the path.

If you're talking about new File(getDataFolder() + File.separator + "your_config.yml");, that's gonna be in your plugin's folder

stiff ember
#

oh

#

so config is like a hashmap?

wide flicker
#

yes and no

#

in the sense that you use a key to access a value, yes

#

but otherwise no

stiff ember
#

ok

#

ty

#

so does this work with lists?

wide flicker
#

For lists of strings/ints/etc... it should

#

not sure for custom objects

stiff ember
#

oh

#

wellll

#

i have custom objects

#

ill try it though

clear blade
#

Getting UUIDs

formal dome
#

how do you set up the config file to login to your database?

stiff ember
#

org.bukkit.configuration.InvalidConfigurationException: could not determine a constructor for the tag tag:yaml.org,2002:SMPly.utils.Turret

#

What happened here?

quaint mantle
#

?google "Bukkit serialization api"

undone axleBOT
stiff ember
#

?

zealous hill
sullen marlin
#

what are you doing?

#

just construct recipe and call addRecipe

golden turret
#

hello

#

i want to use the tab in the console

#

im using windows

#

when i type the tab

#

a huge space appears

#

instead of to do the tab completion

stiff ember
#

Do I need to serialize the Block object too?

#

when saving to config

zealous hill
#

md_5 I am trying too create a new recipie to allow Iron items to be used and crafted with Diamond to create Diamond gear and also keep the enchantments on the item.

Iron helmet with Unbreaking 4 + x5 Diamond = Diamond helmet + Unbreaking 4.

stiff ember
#

my custom object contains a block

#

nvm got it

barren nacelle
#

Hey can I use a custom material what I mean is like (material.fireball.enchanted.fireprot.4)

young knoll
#

No

#

You need to make and modify an item stack

quaint mantle
#

is there a better way to have floating text above a fired arrow than using an armor stand that tracks the arrow in a runnable?

#

My hashmap has player

#

but i try remove return null.

#

cache.remove(uuid)

barren nacelle
vague oracle
#

You are removing from hash map whilst looping through it

paper viper
#

Yes

#

he is talking to you

#

that issue is pretty common and caused by that usually

formal dome
barren nacelle
#

But I am not talking about code

#

well

paper viper
#

?

barren nacelle
#

I am just I was asking if I could include NBT data on items Material.fireball.enchant.fireprot.4 something like that

paper viper
#

Oh nvm

#

sorry

#

wrong person

#

I meant Diimensions

paper viper
barren nacelle
paper viper
#

Btw, you can't add a "Material"

#

you have to create your own enum class

#

and add your own custom nbt items there

#

(or at least you should)

#

?pdc

quaint mantle
#

How do I solve this?

#

I'm doing a foreach on the hashmap to save the data in the database, and I want to remove the data from players who are offline (checking)

#

😶

barren nacelle
quaint mantle
paper viper
#

What is saveData(uuid)?

#

can you show the method

#

And also, you shouldn't use that symbol for color codes. ChatColor is better

quaint mantle
quaint mantle
#

(This is a question)

paper viper
#

compatability issues

#

and also

#

you get a weird A symbol sometimes

#

due to compatability issues

#

ChatColor fixes that

quaint mantle
#

ohhhh

stiff ember
#

Help with saving

paper viper
#

you dont have to search the color code up

#

and keep copying and pasting

#

ChatColor already has names

stiff ember
#

Anyone know how to save stuff?

#

to config

quaint mantle
barren nacelle
#

?learnjava

undone axleBOT
formal dome
#

fyi i think this tutorial has a typo

#

unless i'm doing it wrong

#
Database database = config.getDatabase();
// we set out credentials
dataSource.setServerName(database.getHost());
dataSource.setPortNumber(database.getPort());
dataSource.setDatabaseName(database.getDatabase());
dataSource.setUser(database.getUser());
dataSource.setPassword(database.getPassword());```

Database should be Datasource
#

i can't resolve the object as Database

#

i might be wrong

#

i'm def wrong

#

ya'll are using hikari cp and i;'m not

crude charm
#

...?

#

it makes dbs 100x faster

#

especially for something as slow as sql

formal dome
#

well it still uses java.sql.*

#

that's all the primitive version of my plugin is doing

young knoll
#

It handles connections for you

#

Which is nice

formal dome
quaint mantle
#

HashMap return after try remove java.util.ConcurrentModificationException:

#

help?

lavish hemlock
#

you cannot remove while iterating via for-loop/forEach

young knoll
#

Use an iterator

quaint mantle
lavish hemlock
#

you have to use iterator()

#

e.g.

Iterator<String> it = stringList.iterator();
while (it.hasNext()) {
    String s = it.next();
    System.out.println(s);
    it.remove();
}
#

('tis an example)

quaint mantle
#

try

#

i solved

golden turret
#

also works for maps

valid solstice
#

what classifies as a player animation event

young knoll
#

Looks like only arm swinging

carmine nacelle
#

Is there a better way to get entities in an EntityBlockStorage other than removeAllEntities()?? seems kinda dumb you gotta release them.

young knoll
#

Doesn't look like there is anything in the API for it

#

I assume because an Entity has to be in the world

raw coral
#

Is there any place I can get a list of functions that are thread safe, my plugin requires a lot of api requests and I don't want to freeze the main server thread

young knoll
#

No

#

Spigot will generally yell at you if they aren't

valid solstice
young knoll
#

The animation of the arm swinging

#

So whatever swings the arm

valid solstice
#

alright ty

quaint mantle
#

Is bad use contains name from check unique menu?

#
    public void onInventoryClick(InventoryClickEvent e) {
        if (!e.getView().getTitle().contains("Perfil de ")) return;
        e.setCancelled(true);
        final ItemStack clickedItem = e.getCurrentItem();
        if (clickedItem == null || clickedItem.getType().isAir()) return;
        final Player p = (Player) e.getWhoClicked();
        p.sendMessage("You clicked at slot " + e.getRawSlot());
    }```
tacit drift
#

check for instance of the inventory

quaint mantle
#

I've tried, but I can't.

#

I create a menu for each player.

#

to show player information.

#

this is my code (it's a test draft)

tacit drift
#

if you check for inventory name

#

other inventories can false flag that check

quaint mantle
#

Do you have any alternatives?

#

For what I want to do.

young knoll
#

The best way is to save the View returned from openInventory into a set

#

And then make use of set.contains with the event.getView

worldly ingot
#

👏 Thank 👏 you 👏

#

Everything you said in that response was perfect KEKW

young knoll
#

I actually use a map to connect it with a custom inventory class, but a set is fine for most uses

worldly ingot
#

Depends on whether or not you want to abstract it away

young knoll
#

Yeah

quaint mantle
#

Does anyone have any tutorials I can base myself on to open an inventory with player information?

young knoll
#

What do you mean by information

quaint mantle
#

Kills ,deaths

#

level

real spear
#

Is there a reason why this doesn't work:

    @EventHandler
    public void onPlayerLogin(PlayerLoginEvent e) {
        if (!main.started && !e.getPlayer().hasPermission("admin.minecraft"))
            e.getPlayer().kickPlayer(ChatColor.YELLOW + "Server is closed right now. If you think this is an error, please contact an admin or owner.");
    }
young knoll
#

Use the AsyncPlayerPreLoginEvent

#

It has a disallow method

young knoll
quaint mantle
young knoll
#

I mean that is up to you

#

Lay out the items and info however you want

quaint mantle
#

Ah, I want to know if using " if (e.getView().getTitle().contains("Perfil de ")) return;" is the best way

young knoll
#

No

quaint mantle
#

set.contains?

#

What's that?

young knoll
#

Method in the set interface

quaint mantle
worldly ingot
#

JDK 7

young knoll
#

Why did that turn up first

#

I blame google

alpine urchin
#

personalized results

#

they know what you like and use

alpine urchin
young knoll
#

I don’t event remember the last time I used java 7

#

Probably back before java 8 released

alpine urchin
#

Go to project structure

#

Oh… what happened? you don’t wanna use JDK 7 anymore?…

#

you know your default jdk is 7

quaint mantle
#

Just a minor question, how would this (default reloadConfig by spigot (or paper idk if they changed those))

    @Override
    public void reloadConfig() {
        newConfig = YamlConfiguration.loadConfiguration(configFile);

        final InputStream defConfigStream = getResource("config.yml");
        if (defConfigStream == null) {
            return;
        }

        newConfig.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
    }```
different than this
```java
    public void reloadConfig() {
        customConfig = new YamlConfiguration();
        try {
            customConfig.load(customConfigFile);
        } catch (IOException | InvalidConfigurationException e) {
            e.printStackTrace();
        }
    }```
I read through the first one, but still havent found out the different between 2 of them
tender shard
#

Using the Annotation Command Framework, is it possible to add command aliases loaded from the config file? Or do the aliases HAVE to be defined using an annotation?

tender shard
tender shard
#

got another ACF question:

    @Default
    public static void onDefault(CommandSender sender, @Optional Player player) {

How can I make ACF print something like "Player asdasd not found" when an argument is given but the player isn't online? I want to the command to only work when people enter no player name, or a valid one, but not when they enter an invalid player name