#help-development

1 messages ¡ Page 2186 of 1

quaint mantle
#

imagine

#

anti cheat

carmine valley
#

hm?

quaint mantle
#

wait

tender shard
quaint mantle
#

so you whipped a guy

lethal python
#

if create a shapedrecipe which uses a bucket of powdered snow in it, will the empty bucket be left behind? or will i have to manually put an empty bucket in the crafting grid?

quaint mantle
#

18 blocks

#

and then to stop kb?

carmine valley
#

the code I sent knocks the player back more each time I hit him

carmine valley
#

once I reach a knockback of 18, it stops increasing

lethal python
#

u know how when u craft a block of honey it leaves the bottles behind quackiee

eternal oxide
tender shard
#

where's the problem? you're applying a vector 10|2|-10

#

that's pretty much

#

just use a shorter vector

carmine valley
lethal python
#

mfnalex do u know if this happens

eternal oxide
#

you want it to go further and it won't?

carmine valley
carmine valley
eternal oxide
#

does your multiplier still increase?

carmine valley
#

the vector is increasing as you see in the console, but the actual kb doesn't

quaint mantle
#

omg I have been waiting to use this command for a long time

tender shard
quaint mantle
undone axleBOT
quaint mantle
#

(its a joke dw)

carmine valley
#

as I programmed it to do

eternal oxide
#

you increase your multiplier

carmine valley
#

mhm

eternal oxide
#

if you find it is hitting the floor increase your Y

#

if its only reaching 18 blocks and hitting the floor, you don;t have enough elevation

carmine valley
tender shard
#

set Y to 100 and see what happens

eternal oxide
#

^

carmine valley
#

aight

tender shard
#

if you get further than 18 blocks now, it's simply because you hit the ground too soon

quaint mantle
#
private static final double MILLION = 1_000_000;
private static final double THOUSAND = 1_000;```
#

can I use this isntead of the thing I sent?

tender shard
#

?

#

that's simply two variables

eternal oxide
#

_ delimiter?

tender shard
#

one holds a million and one holds a thousand

quaint mantle
#

and this

if (health >= MILLION) {
  // The `/=` is short for `health = health / MILLION`.
  health /= MILLION;
else if (health >= THOUSAND) {
  health /= THOUSAND;
}
return format.format(health);```
tender shard
#

the _ doesn't do ANYTHING

quaint mantle
#

I was finding the code tho D:

eternal oxide
#

ah k

quaint mantle
#

so how about know?

#

@tender shard

carmine valley
#

as if it's still .setY(2)

#

no vertical velocity

#

and still 18 blocks

eternal oxide
#

makes no sense

carmine valley
#

yeah very weird

eternal oxide
#

show your code again

carmine valley
#
package me.r3dx.mcbrawl;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;

public class Knockback implements Listener {
    int heatValue = 0;
    @EventHandler
    public void onPlayerHitPlayer(EntityDamageByEntityEvent event){
        if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
            heatValue++;
            Vector v = event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(100);
            System.out.println(v);
            event.getEntity().setVelocity(v);
//            event.getEntity().setVelocity(event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(2));
        }
    }

}```
eternal oxide
#

math is fine

carmine valley
eternal oxide
#

hard code your heatValue and don;t increase it. set it to 100

#

see if that gets you beyond 18 blocks

carmine valley
#

or just do multiply(100)

eternal oxide
#

yep

quaint mantle
#

a

#
public static Map<Integer, String> prefixes = ImmutableMap.of(
            7, "k",
            10, "M",
            13, "B");
    public static String formatNumber(double num){

        int length = Double.toString(num).length();

        String numAfter = String.format("%,d", num);

        for (int i : prefixes.keySet()){
            if (length > i) continue;

            if (length < i && length > 3){
                String prefix = numAfter.split(",")[0];
                if (prefix.length() == 1){
                    prefix += "."+numAfter.split(",")[1].charAt(0);
                }
                numAfter = prefix + prefixes.get(i);
                break;
            }
        }
        return numAfter;
    }```
#

changing the d to a f

#

will change the number display format?

#

@eternal oxide can u help please?

#

yk what

#

nvm I asked

carmine valley
eternal oxide
#

test it on a mob as I know they can get thrown miles

#

see if there is somethign odd going on with the player velocity

carmine valley
#

so I should comment out the if

eternal oxide
#

just the entity part

#

still keep damager so other things are not confusing the console

carmine valley
#
public void onPlayerHitPlayer(EntityDamageByEntityEvent event){
        //if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
            heatValue++;
            Vector v = event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(100).setY(100);
            System.out.println(v);
            event.getEntity().setVelocity(v);```
#

oh

#

right

#

nah don't worry about it I disabled mobs and animals

#

I will try it on the wandering villiger

ornate patio
#

if I've spawned a custom NMS entity

#

and the server restarts

#

would it be possible to convert that entity back into my custom entity so that it has custom pathfinding?

#

for example, kind of like "Hijack" all living zombies in the world to make their pathfinding not attack players

uneven fiber
#

i think i just found an insane side hustle that no one is talking about

vocal cloud
#

Writing apps for cryptocurrencies?

uneven fiber
#

yes 🖖

chrome beacon
#

If not load and unload your entity with the ChunkLoad and ChunkUnload events

carmine valley
#

so it has to do with the player

unreal sandal
#

How can I equip player with Elytra in spigot 1.18.2 ?

ornate patio
ornate patio
#

i'm not actually using pathfinding on zombies

echo basalt
#

surprisingly easy

ornate patio
#

i have a very complex horse entity

#

that i need to convert a living horse to that entity

echo basalt
#

I even have a 50 line PathfinderInjector class for that

echo basalt
ornate patio
#

so i just kill the horse

#

and spawn in my custom entity?

#

in place

echo basalt
#

pretty much

#

Entity#remove

#

on both CreatureSpawnEvent and EntitiesLoadEvent

ornate patio
#

if thats fine

#

it might work

echo basalt
#

I decided to do a lil static abuse on it because it was for a rush job but

chrome beacon
#

Forgot about that

green prism
#

https://pastebin.com/5BevYpN6
Guys, I have a problem, there are two values inside the hash and at exactly row 49, they both become equal... I did some tests and (You can see also from the code) this comes out in the console, (where there are the two 'rara' is the problem!) Can you help me?

[18:36:51 INFO]: BAWGAE - scoteca
[18:36:51 INFO]: rrrrrrr rara
[18:36:51 INFO]: BAWGAE - rara
[18:36:51 INFO]: CUSTOMCHAT VALUES: scoteca
[18:36:51 INFO]: rara
[18:36:51 INFO]: CUSTOMCHAT VALUES: rara
[18:36:51 INFO]: rara```
#

Olivo i bliv in u

carmine valley
echo basalt
#

forgot to mention but I believe it also does a little exception throwing whenever a player joins lmao

#

but that can be easily fixed

uneven fiber
#

im tryna create flappy bird with chest inventory but sadly i am failing

ornate patio
eternal oxide
echo basalt
#

michè doesn't believe in me 😭

echo basalt
#

try cloning at line 71

green prism
green prism
echo basalt
#

also you have some weird debugging names let me tell you

green prism
#

wdym with cloning?

echo basalt
#

ItemStack#clone

echo basalt
#

you're modifying the walkie itemstack

echo basalt
green prism
#

haha

green prism
echo basalt
#

it's tired of suffering with suspicious quality code

ornate patio
#

how can i add persistent data container info to an nms entity

tender shard
#

PDC is bukkit only

#

you can only use NBT

ornate patio
#

damn

#

is there a workaround?

green prism
tender shard
#

not really

eternal oxide
#

if your NMS entity is also a CraftEntity you can

ornate patio
#

whats a craftentity

tender shard
eternal oxide
#

looks like

tender shard
green prism
#

@echo basalt wORKSSSSSSSSS

#

works

#

THANKS BRO

ornate patio
#

can i still do pathfinding operations on it?

tender shard
#

on what?

ornate patio
#

craftentity

tender shard
#

CraftEntity is basically a wrapper for the NMS entity

eternal oxide
#

how did you spawn your nms entity?

ornate patio
#

well i have a wrapper for the entity

#

hold up lemme send a mystbin

eternal oxide
#

I only need to know how you spawned it

carmine valley
echo basalt
#

craftentity is the implementation of the interface

eternal oxide
#

api or packets?

eternal oxide
#

yes it has a Bukkit entity

#

um

ornate patio
#

sry what

eternal oxide
#

nm

ornate patio
#

so like

#

how would i use persistent data container

#

or do you think i should just use NBT tags

eternal oxide
#

nbt

tender shard
#

NBT for custom entities

#

PDC for bukkit stuff

ornate patio
#

alright

#

is there documentation for NMS somewhere

tender shard
#

no

#

NMS is not part of the API

ornate patio
#

damn

#

well

#

how do i set NBT data then lol

tender shard
#

you could look into the source code of CraftPersistentDataContainer or so

#

PDC also uses NBT internally

humble tulip
#

Just get the bukkit entity

#

And use pdc

ornate patio
ornate patio
humble tulip
#

I'm pretty sure they still use bukkit entities tho

#

Do CraftHorse.getEntity

tardy delta
#

ur mom is a bukkit entity

humble tulip
ornate patio
humble tulip
#

just pass bukkit.getserver

#

and cast

ornate patio
#

oh k

#

lemme try this

humble tulip
#

kinda stupid that it requires the server tho given that there is only one server

carmine valley
#

@humble tulip hey dude

humble tulip
#

yeha

carmine valley
#

we figured it has to do with the player

#

because it worked fine on all other entities

humble tulip
#

oh wow

carmine valley
#

still trying to figure out how to bypass that

ornate patio
#

i'm assuming like this though right

#

CraftEntity craftEntity = CraftEntity.getEntity((CraftServer) Bukkit.getServer(), entity)

humble tulip
#

yep

ornate patio
#

alright

echo basalt
#

only thing I hate is how Spigot internally casts to CraftServer

noble spire
#

If you get an ItemStack from Inventory#getContents, and then use ItemStack#setAmount (or ItemStack#setType etc...), is the ItemStack in the Inventory updated, or do you need to overwrite the ItemStack somehow?

echo basalt
#

breaks the concept of abstraction but whatever

carmine valley
#

do you think I can for loop the thing?

humble tulip
#

u can try

carmine valley
#

nah that would make it happen every time the player walks

#

velocity is not only kb right?

ivory sleet
humble tulip
ivory sleet
#

But sure, most stuff will end up having leaky abstractions somehow

echo basalt
#

I once tried injecting something that wasn't CraftServer

ivory sleet
#

When?

#

oh

humble tulip
#

wait why

ivory sleet
#

yeah

echo basalt
#

funky command map that didn't fire events on certain conditions

ivory sleet
#

I mean the api doesn't really support custom implementations unless mentioned otherwise

humble tulip
#

there's supposed to be one server

ivory sleet
#

believe its even documented that way

echo basalt
#

I wrapped CraftServer

#

but gotta love having everything final

#

can't even extend it

#

CraftServer is a final class, with a final command map with final implementations

tardy delta
#

sounds like fun

ivory sleet
#

but I mean apis like these are not very friendly towards the open closed principle for instance, they only care about providing the api as is and thats it, no custom implementations or low level detail exposure

pastel juniper
#

Is there a way to disable nether and end portals

#

Or end and nether navigation through the portals

echo basalt
#

on top of that, java12+ locked down the final modifier

#

we can only bypass it with bytecode manipulation iirc

ivory sleet
#

yes or sth like unsafe

echo basalt
#

but if we're going this far, it's easier to just fork the server

humble tulip
echo basalt
#

there's conversion when calling setItem

noble spire
#

hmm okay, so you need to overwrite them?

carmine valley
#

nah for loop didn't do shit @humble tulip

echo basalt
noble spire
#

okay, thanks!

carmine valley
#

is there a method to hit the player? maybe we can do that @humble tulip

echo basalt
#

do you need the knockback vector or something?

noble spire
#

you might want to craete a thread for whatever you're working on

brave sparrow
#

@carmine valley can you explain what you’re attempting to do and what your current solution is to that problem

carmine valley
echo basalt
#

there's a max velocity stated on spigot.yml iirc

#

might be paper specific

#

not sure

carmine valley
#

can I edit it?

brave sparrow
#

Are you running an anticheat

echo basalt
#

but it usually throws a console warning if you go above it

carmine valley
echo basalt
#

just run it on a scheduler and call it a day

brave sparrow
#

You could theoretically lerp between two points and perform a sequence of small delayed teleports

#

Lol

carmine valley
#

the player also didn't experience any vertical velocity even though I tried to do .add(new Vector(0,5,0)) and setY(100) and neither worked

#

no vertical velocity at all

brave sparrow
#

That’s way too big

#

Lol

carmine valley
#

I tried 2 and 100, same results

humble tulip
#

He set it at 2 and still notbing

echo basalt
#

this does the job

brave sparrow
#

2 is decently high

carmine valley
#

what's frustrating is that it works fine on all entities but not players

brave sparrow
#

Entities are moved by the server

#

Players are moved by the client

humble tulip
#

Oh yeah that's why antikb works

brave sparrow
#

You can tell the player their new velocity is whatever you want, if the client doesn’t like it it isn’t gonna happen

carmine valley
#

then how did I even get to 18 blocks in the first place if it's solely depends on the client

#

oh ok

brave sparrow
#

The client decided that was ok

carmine valley
#

so are you saying I need a custom client?

humble tulip
#

Or a mod maybe

brave sparrow
#

No I’m saying you need to stop trying to do massive vectors at once

eternal oxide
#

You need to calculate the locations in small steps

brave sparrow
#

^

carmine valley
#

what about if we hit the player again? is there a method to do that?

brave sparrow
#

Lerp between two points

echo basalt
#

you just add the vector or something

#

but yeah

#

smaller steps

#

that's why my custom shield works :)

carmine valley
#

wouldn't that look crude with the tp?

eternal oxide
#

the client will smooth between near locations

brave sparrow
#

Minecraft treats small teleports as movement

carmine valley
#

oh you mean very small teleports

brave sparrow
#

Yes

eternal oxide
#

every tick

brave sparrow
#

^

carmine valley
#

I've never done anything like that, what would that look like?

echo basalt
#

uhh

brave sparrow
#

It would look like them moving

#

You need a scheduler here

carmine valley
#

I meant in code

brave sparrow
#

You need a bukkitrunnable

echo basalt
carmine valley
#

does the video explain implementation?

echo basalt
#

no but my code is pretty simple to understnad

carmine valley
#

alright I will see what I can make of that

#

thx

tardy delta
#

its just a custom recipe and a resourcepack x)

carmine valley
#

but just to make sure, there is no method to hit the player right?

echo basalt
#

and a scheduler

echo basalt
#

perhaps

carmine valley
#

hmmm

echo basalt
#

you can do a lot with custom recipes and resourcepacks

tardy delta
#

ye

carmine valley
#

how about I just damage the player again so he goes further distance?

echo basalt
carmine valley
#

in the game I'm trying to make the player's will be always healed to 100%

echo basalt
#

you can just set a manual knockback

carmine valley
#

with setVelocity?

echo basalt
#

yes

#

wrong link

#

ther

tardy delta
#

i hate my teacher.. exposing collections...

#

when you can just write methods that interact with it

echo basalt
#

what's the problem with public static List<Object> ACollection = new Hashmap<>();

tardy delta
#

me do not like that

humble tulip
#

what could possibly be wrong

carmine valley
echo basalt
tardy delta
#

and he not having a cache for the database

#

aaaaa

echo basalt
#

if the db is too big, a cache might end up killing stuff

humble tulip
#

dont cache the whole db

#

just whats needed

tardy delta
#

you can clearly see the applications slowing down cuz of the unneccesary db stuff

carmine valley
#

@echo basalt I can't find LivingEntity#damage(double, LivingEntity)

echo basalt
#

LivingEntity extends Damageable

#

so there's that

carmine valley
#

but can you set velocity to that?

humble tulip
#

u can do it after

echo basalt
#

I literally gave you a util that calculates accurate kb vectors

#

what else do you need

carmine valley
echo basalt
#

they might not be loaded by that stage

tender shard
#

should work if you set "load" to "STARTUP" in plugin.yml

ornate patio
#

is there a built in method to get the target entity a player is looking at

tender shard
#

returns a RayTraceResult

#

and that has a method getHitEntity

carmine valley
#

I imported org.bukkit.entity.Damageable, why can't I use the method damage()?

tender shard
#

you can

carmine valley
#

gives me an error

echo basalt
tender shard
carmine valley
#

no the error suggests to create a method damage() in my class

#

why isn't the compiler recognizing the import?

tender shard
#

obviously you can only use instance methods on an instance of the class that declared that method

tender shard
carmine valley
#

shouldn't it work on a player entity?

river oracle
#

Ěóğ

tender shard
#

?paste your code

undone axleBOT
tender shard
#

or show a screenshot or whatever

ornate patio
#

i cant find the method in the docs

tender shard
ornate patio
#

oh wait nvm

#

i was looking at nms docs lmao

carmine valley
tender shard
#

cast the entity to Damageable or LivingEntity

carmine valley
#

oooh ok

ornate patio
#

is distance the measurement in blocks?

#

or is it something else

lament swallow
#

Managed to get scores working but does anyone know why the tablist is not sorting itself?

#

by score, I mean

carmine valley
#

I made that ```cpp
package me.r3dx.mcbrawl;

import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;

public class Knockback implements Listener {
int heatValue = 0;

@EventHandler
public void onPlayerHitPlayer(EntityDamageByEntityEvent event) {
    if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
        heatValue++;
        Vector v = event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(2);
        event.getEntity().setVelocity(v);
        LivingEntity en = (LivingEntity) event.getEntity();
        if(heatValue >= 8){
            int extraKnock = ((heatValue - 8)/3);
            for (;extraKnock >= 1;){
                 en.damage(1, event.getDamager()) ;
                }
            }
        }
    }
}
#

@tender shard

river oracle
#

Nice

carmine valley
#

oh wait I forgot to add the setVelocity to the artificial damage

ornate patio
#
RayTraceResult raytraceResult = player.rayTraceBlocks(50);
if (raytraceResult == null) {
    player.sendMessage(Utils.colorize("&cYou are not looking at a horse!"));
    return true;
}

Entity entity = raytraceResult.getHitEntity();
#

entity is always null

carmine valley
#

wait I can't just add it afterwards

#

goddamn it

echo basalt
#

because you're raytracing blocks not entities

ornate patio
#

how do i ray trace entities

echo basalt
#

idk you tell me

ornate patio
#

oh mb

carmine valley
#

wait, LivingEntities don't have a .getLocation?

ivory sleet
#

Hi! Do you know how I can add color to the name of my item on my plugin? Thank for your help

echo basalt
#

you are reading the docs for LivingEntity and completely ignoring all hierarchy

tardy delta
#

i mean why saying thank for your help if noone has answered yet

tardy delta
echo basalt
tardy delta
#

i cant believe people arent checking the forum for simple questions 🥺

river oracle
#

People are dum

echo basalt
#

not even trying to google

river oracle
#

Very dum dum

tardy delta
#

?bing

undone axleBOT
echo basalt
#

come to us if you have serious questions and you've done previous research of attempts

tardy delta
#

oh god why is it still there

#

imagine usin bing

river oracle
#

Gross bing

vocal cloud
#

?askjeeves

#

😔

tardy delta
#

?tryandsee

undone axleBOT
tardy delta
#

ayy

vocal cloud
#

?tas

undone axleBOT
frail sluice
#

is there any way to store data in non-tile-entity blocks? (without an external file)

waxen plinth
#

It's backed by either pdc or sqlite

frail sluice
#

whats pdc?

waxen plinth
#

?pdc

humble tulip
#

Pdc is 1.14+

ornate patio
#

can i not use lambdas?

waxen plinth
#

What are you trying to do

frail sluice
ornate patio
#

trying to pass in a predicate to World.rayTraceEntities

waxen plinth
#

You can't specify the type of a lambda parameter in the lambda

ornate patio
#

wait

#

you sure?

waxen plinth
#

It must be inferred

#

Yes

#

But also are you using Java 7

tardy delta
#

set your project version to java 8 smh

ornate patio
#

well im still getting the same issue

ornate patio
waxen plinth
#

Use 8 or above

tardy delta
#

java 17 😍

waxen plinth
#

Yeah newer is better of course

ornate patio
#

ye ill do that

carmine valley
#

I'm using this code and server crashes after the heat value exceeds 7 ```cpp
package me.r3dx.mcbrawl;

import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;

public class Knockback implements Listener {
int heatValue = 0;

@EventHandler
public void onPlayerHitPlayer(EntityDamageByEntityEvent event) {
    if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
        heatValue++;
        Vector v = event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(2);
        event.getEntity().setVelocity(v);
        LivingEntity en = (LivingEntity) event.getEntity();
        if(heatValue >= 8){
                 en.damage(1, event.getDamager());
                 en.getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(2);
                }
            }
        }
    }
tardy delta
#

you are firing a damage event in the damage event i guess?

#

en.damage(1, event.getDamager());

odd sentinel
#

how do I determine which block was the cause of a BlockExplodeEvent? event.getBlock() is AIR

frail sluice
tardy delta
#

BlockExplodeEvent#getBlock i guess

waxen plinth
frail sluice
#

thx

tender shard
tardy delta
#

hurrah

waxen plinth
#

Man I should really advertise my libraries via the spigot forums more

tender shard
#

and write better javadocs 😛

waxen plinth
#

??

#

I have extensive javadocs and wikis for everything

#

What more do you want

tender shard
#

idk I only looked at the overview and there's nothing

waxen plinth
#

Bruh

#

Click on a package

tender shard
#

my overview always looks like this lol

quaint mantle
#

package_info.java

tardy delta
#

i was writing javadocs and i stopped it when i wrote what a getter did 💀

tender shard
#

yeah not everything needs javadocs

waxen plinth
#

I do tend to document everything

#

I guess it's not truly necessary

quaint mantle
waxen plinth
#

What's that do

#

I use eclipse bindings

quaint mantle
#

its for the javadoc plugin

#

it generates javadocs for everything

tender shard
#

it doesnt do anything for me

quaint mantle
tender shard
#

oh it's another plugin

waxen plinth
tardy delta
#

whats in fact the use of a package_info.java?

quaint mantle
tardy delta
#

lol

carmine valley
#

Why isn't the player getting knocked back more when the heatValue exceeds 8?```cpp
package me.r3dx.mcbrawl;

import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;

public class Knockback implements Listener {
int heatValue = 0;

@EventHandler
public void onPlayerHitPlayer(EntityDamageByEntityEvent event) {
    if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
        heatValue++;
        Vector v = event.getEntity().getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(2);
        event.getEntity().setVelocity(v);
        LivingEntity en = (LivingEntity) event.getEntity();
        if(heatValue >= 8){
                 en.damage(1);
                 en.getLocation().toVector().subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue).setY(2);
                }
            }
        }
    }
tardy delta
#

i mean clean up that code lol

tender shard
tardy delta
#

kinda sucks to make a separate file for it

tender shard
#

why?

#

it's just a tiny file

/**
 * <b>Main Library methods.</b> Some methods require initialization first, see {@link de.jeff_media.jefflib.JeffLib#init(org.bukkit.plugin.Plugin)}
 */

package de.jeff_media.jefflib;
quaint mantle
#

theres a shortcut in intellij to generate them

tardy delta
#

conclure is very sus today

quaint mantle
tardy delta
#

werent you doin it in rust?

quaint mantle
#

what

humble tulip
#

lex

#

Luthor

quaint mantle
#

thats the guy with the book right

frosty tinsel
#

Hi, anyone know how to publish Kotlin lib to maven repository using Gradle Kotlin DSL?

ornate patio
#

uhh

#

im java.lang.ClassFormatError: Class file version does not support constant tag 16 in class file ... when i try to load my plugin now

wary cape
#

Hi
Given a config like below how can iterate through all groups and all the stuff inside them?

groups:
  admin:
    - "somestuff"
    - "someotherstuff"
  mod:
    - "something"
    - "someotherthing"
  player:
    - "idk"
ornate patio
sterile token
tardy delta
ornate patio
#

because 17.0.3.1 wasnt working

tardy delta
#

then iterate over the stringlist

sterile token
ornate patio
#

if i set the source to 17.0.3.1 then i get this underline

wary cape
ornate patio
#

it throws an error too when running

chrome beacon
#

Are you using maven?

humble tulip
#

Can't u set it to 17

ornate patio
chrome beacon
#

Just set target and source to 17

tardy delta
#

intellij?

wary cape
chrome beacon
tardy delta
#

smh

ornate patio
tardy delta
#

you have the string

chrome beacon
wary cape
ornate patio
chrome beacon
#

Don't use Plugman

waxen plinth
waxen plinth
ornate patio
#

well besides plugman theres still these red underlines everywhere

tardy delta
waxen plinth
#

Don't catch ClassCastException wtf

tardy delta
#

i guess

wary cape
waxen plinth
#

That code appears to be written outside a method

tardy delta
wary cape
waxen plinth
#

Ok

ornate patio
#

im just writing some debug code

crisp steeple
#

sender instanceof Player

ornate patio
#

i was testing something earlier dw

wary cape
tardy delta
#

actually i believe its config.getConfigurationSection("groups").getKeys(false)

mellow cedar
#

Compass pointer not updating on join event?

ornate patio
#

anyways

#

how do i fix this java issue thing

waxen plinth
#

Seriously

#

Now you catch the exception but if it happens you're just gonna get an NPE anyways lol

tardy delta
#

that will iterate over all keys under groups

ornate patio
#

it seems like everything built into java is just gone

#

says that Object is missing, no String, no @Override, etc

chrome beacon
#

?paste The entire file

undone axleBOT
ornate patio
#

my pom.xml?

chrome beacon
#

target and source should both be 17

ornate patio
#

mb i posted my temporary fix-ish kinda

chrome beacon
#

One issue at a time

ornate patio
#

yeah here's what I actually have right now

chrome beacon
#

Just 17

#

not 1.17

ornate patio
#

wait lmfao

#

nah still didnt work

chrome beacon
#

What does it say

ornate patio
#

still just a bunch of red underlines

chrome beacon
#

and when you hover over it

ornate patio
#

stuff like this

crisp steeple
#

now would be a good time to switch to intellij

ornate patio
#

also wtf mvn now says its not recognized as a command

#

i have the location saved in path..

#

ima restart my pc

chrome beacon
ornate patio
eternal oxide
#

What IDE?

chrome beacon
#

VScode

eternal oxide
#

eww

ornate patio
eternal oxide
#

sorry

tardy delta
#

not even an ide

ornate patio
#

i prefer vscode

chrome beacon
tardy delta
#

but i like the color scheme uwu

ornate patio
#

yes

chrome beacon
#

Path

ornate patio
chrome beacon
#

Not JAVA_HOME

ornate patio
#

yeah its there

chrome beacon
#

vscode gives useless error messages

carmine valley
#

Hey guys, I'm trying to make a spigot plugin that increases the player's KB the more they are hit, I've so far constructed the following code. One issue with it is that it stops knocking the player further once the knockback sends you 18 blocks away due to some Player class restriction(All other entities can be hit further than 18 blocks and don't have such a threshold) I've tried fixing it by damaging the player artificially and sending him further away once after 3 hits of reaching the threshold, but it didn't quite work, any ideas why it didn't? and any alternative solutions? code:```cpp

package me.r3dx.mcbrawl;

import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.util.Vector;

public class Knockback implements Listener {
int heatValue = 0;

@EventHandler
public void onPlayerHitPlayer(EntityDamageByEntityEvent event) {
    if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
        heatValue++;
        Vector v = event.getEntity().getLocation().toVector();
        event.getEntity().setVelocity(v.subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue));
        LivingEntity en = (LivingEntity) event.getEntity();
        Vector v2 = en.getLocation().toVector();
        if(heatValue >= 8){
                 en.damage(1);
                 en.setVelocity(v2.subtract(event.getDamager().getLocation().toVector()).normalize().multiply(heatValue));
                }
            }
        }
    }```
chrome beacon
#

Run maven and see what it says

ornate patio
#

well just like 2 minutes ago my pc apparently forgot what maven is

#

im gonna restart my pc

humble tulip
#

lmao just use intellij

ornate patio
#

well even if I did

#

spigot server still fails to load the plugin

humble tulip
#

and why is that?

#

because of java file versions?

ornate patio
#

I’ll check the error in just a sec

ornate patio
humble tulip
#

which would easily be fixed in intellij

chrome beacon
#

1.18 requires Java 17?

humble tulip
#

think so

chrome beacon
#

Are you actually running 1.18

ornate patio
#

1.18.1 yes

chrome beacon
#

Then Java file versions shouldn't be an issue

ornate patio
#

yeah it shouldn’t

chrome beacon
#

Unless you used Java 18 for some reason

ornate patio
#

nah im on java 17

wary cape
humble tulip
#

config.get("groups." + group);

#

in a for loop

tardy delta
#

List<String> list = config.getStringList("groups." + groupname)

humble tulip
#

^^

ornate patio
#

why am i just getting random errors now

ornate patio
#

now its telling me i dont have a plugin.yml 🤦‍♂️

#

i clearly do

humble tulip
#

my guy

#

just use intellij

ornate patio
#

i need vscode

#

for

#

other purposes

humble tulip
#

such as?

ornate patio
#

dw about it lmao

#

i doubt its a vscode issue though

humble tulip
#

well use intellij for plugins?

ornate patio
#

maven is failing

crisp steeple
#

vscode + java has always sounded pretty unstable

quaint mantle
#

just use intellij 😭

valid totem
#
java.lang.NullPointerException: Cannot invoke "net.minecraft.core.BlockPosition.v()" because "pos" is null
        at net.minecraft.world.level.LevelHeightAccessor.isOutsideBuildHeight(LevelHeightAccessor.java:41) ~[paper-1.18.2.jar:git-Paper-268]
        at net.minecraft.world.level.Level.getBlockState(Level.java:824) ~[?:?]
        at net.minecraft.world.entity.Entity.lambda$findDimensionEntryPoint$4(Entity.java:3359) ~[paper-1.18.2.jar:git-Paper-268]
        at java.util.Optional.map(Optional.java:260) ~[?:?]
        at net.minecraft.world.entity.Entity.findDimensionEntryPoint(Entity.java:3357) ~[paper-1.18.2.jar:git-Paper-268]
        at net.minecraft.server.level.ServerPlayer.findDimensionEntryPoint(ServerPlayer.java:1050) ~[?:?]
        at net.minecraft.server.level.ServerPlayer.changeDimension(ServerPlayer.java:1103) ~[?:?]
        at net.minecraft.server.level.ServerPlayer.changeDimension(ServerPlayer.java:1066) ~[?:?]

how do i fix this

crisp steeple
#

not sure since you havent sent any code

tardy delta
#

doing what?

chrome beacon
#

The full error would also be good to have

valid totem
#
try {
            Field field2 = net.minecraft.world.entity.Entity.class.getDeclaredField("ah");
            field2.setAccessible(true);
            field2.set(player, player.getPortalWaitTime());
            player.setPortalCooldown();

            player.changeDimension(getMinecraftServer().getLevel(level));
            Field field1 = net.minecraft.world.entity.Entity.class.getDeclaredField("ag");
            field1.setAccessible(true);
            field1.set(player, false);

            Method method1 = net.minecraft.world.entity.Entity.class.getDeclaredMethod("H");
            method1.setAccessible(true);
            method1.invoke(player);
        } catch (NoSuchFieldException | SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
#

it worked with the end and the overworld

#

but for the nether it doesnt work

crisp steeple
#

that just looks like a disaster waiting to happen

chrome beacon
#

^^

valid totem
#

but it worked

#

unless the nether

crisp steeple
#

what are you even trying to do here?

eternal night
#

you are calling a dimension change without a portal location

crisp steeple
#

this seems like an xy problem

eternal night
#

which will explode

valid totem
#

no it works if i load the nether chunks

#

which... i dont know which chunks to load

sacred mountain
eternal night
#

I mean yea obviously this fails

#

you are calling a method that should not be called

tender shard
eternal night
#

without prior preporation

sacred mountain
#

oh

valid totem
#

i put in the name of the field and method

crisp steeple
#

?xy

undone axleBOT
sacred mountain
#

why is it named like that

valid totem
#

obfuscation

eternal night
#

but yea, please xy

valid totem
#

alright so i want to warp the player into the nether

sacred mountain
valid totem
#

using NMS

eternal night
#

why NMS

crisp steeple
#

why do you need nms to do that?

eternal night
#

there is proper API for cross world teleportation

valid totem
#

because nms knows exactly where to teleport the player to

eternal night
#

wat

#

you want to find the exit location ?

valid totem
#

if the nether chunks are loaded then NMS teleports me straight to the portal

tender shard
valid totem
#

but with bukkit api i need the location

tender shard
#

just wanted to mention it 🙂

valid totem
#
    protected void handleNetherPortal() {
        if (this.level instanceof ServerLevel) {
            int i = this.getPortalWaitTime();
            ServerLevel serverlevel = (ServerLevel) this.level;

            if (this.isInsidePortal) {
                MinecraftServer minecraftserver = serverlevel.getServer();
                ResourceKey<Level> resourcekey = this.level.dimension() == Level.NETHER ? Level.OVERWORLD : Level.NETHER;
                ServerLevel serverlevel1 = minecraftserver.getLevel(resourcekey);

                if (serverlevel1 != null && minecraftserver.isNetherEnabled() && !this.isPassenger() && this.portalTime++ >= i) {
                    this.level.getProfiler().push("portal");
                    this.portalTime = i;
                    this.setPortalCooldown();
                    this.changeDimension(serverlevel1);
                    this.level.getProfiler().pop();
                }

                this.isInsidePortal = false;
            } else {
                if (this.portalTime > 0) {
                    this.portalTime -= 4;
                }

                if (this.portalTime < 0) {
                    this.portalTime = 0;
                }
            }

            this.processPortalCooldown();
        }
    }

this is nms code for the portal

#

i dont know what im missing though

eternal night
#

ehh you might want to look at the actual method contents in a craftbukkit/spigot/paper server

ornate patio
#

ok i managed to fix everything else, im just running into an issue where maven isn't compiling the plugin.yml

eternal night
#

as that has a special case for players

tender shard
#

well it's only supposed to compile .java files lol

valid totem
#

and make sure your pom doesnt specify a different location

#

also it doesnt compile a yml file

#

it copies it as a resource

ornate patio
#

this is in my pom.xml btw, is it necessary

<resources>
    <resource>
        <directory>${basedir}/src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
            <include>*</include>
        </includes>
    </resource>
</resources>
<sourceDirectory>src/main/java</sourceDirectory>
tender shard
#

the ${basedir} part is useless

tardy delta
#

why do people put that in their pom

valid totem
#

yeah

tender shard
#

the source directory part too

ornate patio
#

i found it online i was desperate for answers

valid totem
#

thats the default

tender shard
#

the <includes> part is useless too

valid totem
#

remove it

ornate patio
#

what do i not need

#

or actually

#

what do i need

chrome beacon
#

All of that

ornate patio
#

to keep

tender shard
#
    <resources>
      <resource>
        <filtering>true</filtering>
        <directory>src/main/resources</directory>
      </resource>
    </resources>
#

just keep this

#

the rest is useless

valid totem
#

yeah

ornate patio
#

alright thanks

valid totem
#

i fixed the code

#

\

subtle folio
#
        for (Player onlinePlayers : Bukkit.getOnlinePlayers()) {
            setNametag(onlinePlayers, player);
        }

    }

    public void setNametag(Player player1, Player player2) {
        Scoreboard scoreboard = player1.getScoreboard();
        if (scoreboard.getTeam(player2.getUniqueId().toString()) != null) {
            scoreboard.getTeam(player2.getUniqueId().toString()).unregister();
        }
        Team team = scoreboard.registerNewTeam(player2.getUniqueId().toString());
        team.setPrefix(ChatColor.translateAlternateColorCodes('&', "eee"));
        scoreboard.getTeam(player2.getUniqueId().toString()).addPlayer(player2);
    }``` Hello friends, i have this code for setting a player's prefix to their overhead name with scoreboards, whenever the join. But it only works for the latest player who joined and removes it from all the other players. Any Ideas?
twilit pulsar
chrome beacon
twilit pulsar
#

oh

humble tulip
twilit pulsar
#

so do i need to change it to 45?

humble tulip
#

This is a player join event right?

#

45 or 54

valid totem
#

how come end portals in the end keep teleporting me to the end again

subtle folio
#

i set the nametag of the new player

#

for every player

#

on join

#

right?

humble tulip
#

So why do you use a for loop?

subtle folio
#

to get all the online players?

humble tulip
#

If there are 20 players

#

You're setting the players scoreboard 20 times

#

Ohhh

#

Wait

#

Now i understand

subtle folio
#

😄

humble tulip
#

Each player has their own scoreboard right?

subtle folio
#

still confused on why it removes it for others tho

#

yeah

humble tulip
subtle folio
#

3 players joined

#

the last player to join kept the prefix

#

the others did not

humble tulip
#

So player 1 and player 2 joins they both have nametags

subtle folio
#

no,

#

player 1 joins gets the name tag

#

when player 2 joins

#

player 1 looses the tag

#

and player 2 gets it instead

humble tulip
#

Are you adding all online players to the scoreboard of the newly joined play btw?

valid totem
#

Bukkit.getServer().reload();

humble tulip
valid totem
#

nothing

#

ignore it

#

dont run it

#

unless you want memory leaks

#

:P

river oracle
#

I love memory leaks

#

I'm going to make a plugin for this

#

I call it Reload unlimited

valid totem
#
while(1) {
    malloc(1);
}
humble tulip
#

I try my best for my plugins to not leak memory

tardy delta
#

cat

river oracle
humble tulip
#

Aha

#

Also try to make my plugins reload safe

valid totem
#

im gonna run that code and see what happens

river oracle
#

I wonder if it does the same thing as /reload

humble tulip
river oracle
#

I hate having no idea wtf to name my packages

#

I just sit in this stasis until I figure it out

humble tulip
#

name it a.b.c

river oracle
#

no I need something that is discriptive yet also not long

humble tulip
#

What are you putting in there?

river oracle
#

I'll screens hot

humble tulip
#

pixels?

#

pixel

river oracle
humble tulip
subtle folio
#

their scoreboard display's their stats

humble tulip
#

Right.. So you need to add all online players to that players scoreboard so that the newly joined player can see their nametag prefix?

subtle folio
#

should i make a seperate scoreboard to do this?

valid totem
#

my computer froze when i ran that code

humble tulip
subtle folio
#

I have code that gives them a new scoreboard with their data yes?

humble tulip
#

The same way u need to add the newly joined player to currently online player scoreboard

#

U also need to add currently online players to the newly joined plauers scoreboard

subtle folio
#

so 2 scoreboards it is

humble tulip
#

I'm not too well versed on scoreboards

#

Well doesn't each player have tjeir own scoreboard?

subtle folio
#

yeah?

#

should I just add all online player's to the new player's scoreboard?

humble tulip
#

Yep

subtle folio
#

but wouldn't that display the wrong stats on the online player's scoreboard then?

humble tulip
#

No add them as teams

#

So the new plauer can see their prefixes as well

subtle folio
#

okay,

humble tulip
#

@subtle folio is this consistent with what you see ingame?

#

Cuz this is wjat i think your code does

subtle folio
#

I believe so

humble tulip
#

Yeah so when p2 joins u need to add p1 to p2 scoreboard

#

Basically add new player to everyones scoreboard

#

And eveeryone to new players scoreboard

subtle folio
#

got it

hybrid spoke
#

without paint

#

on a piece of paper

humble tulip
#

That's a pic

#

I wrote it

hybrid spoke
#

no shit sherlock

#

thanks

#

didnt saw it was a pic

humble tulip
#

Lmao

#

You saod paint

#

I wrote it

hybrid spoke
#

thought its a gif

humble tulip
#

Huh?????

iron glade
#

nice handwriting

lyric grove
#

Is this a clever way of listening for potion effects being added?

humble tulip
#

by the server?

lyric grove
#

Im basically setting a new map with custom implementation on add and remove

humble tulip
#

that's one way

visual tide
#

smort

humble tulip
#

might as well call a potionapplyevent

#

so u can listen to i

lyric grove
#

i dont have that on this version

humble tulip
#

no i mean, create a custom event

lyric grove
#

oh yeah

humble tulip
#

not sure if you'd be able to cancel it though

#

server might still send the packet

#

so things may get weird

#

you'll have to test to find out

lyric grove
#

yeah i guess i might just have to listen for both packet level and using this map

humble tulip
dense geyser
#

I want to do conversations between a user and an npc user using basecomponents, if I want to make a yes/no choice in the dialogue, should I just create a temporary command using the reprocess event like /doFJ3DFGGTJRE2FFDDJVJFD92KDVFD3F9K or is there a better way

sinful rapids
#
            ItemStack a = new ItemStack(Material.LEATHER_BOOTS, 1);
            LeatherArmorMeta b = (LeatherArmorMeta)a.getItemMeta();
            ItemMeta c = a.getItemMeta();
            b.setColor(Color.RED);
            c.setDisplayName("§cStivali §cVDF");
            a.setItemMeta(c);
            a.addEnchantment(Enchantment.DURABILITY, 1);
            player.getInventory().addItem(a);
            player.sendMessage("§7[§cVDF CORE§7] §7Stivali givvati con successo!");

Not working LeatherArmorMeta, why?

humble tulip
#

Leatherarmormeta is an itemmeta

#

Remove c

#

And everything u do with c do with b

sinful rapids
#

ok

humble tulip
#

@subtle folio did you solve the scoreboard issue?

clever musk
#
test_tags_profile:
  type: tags_profile
  debug: false
  block:
    climbable:
      ladder: false
      vine: false
      iron_bars: true
      chain: true
      oak_wall_sign: true
      oak_sign: true
      oak_door: true
    mineable/shovel:
      stone: true
      obsidian: true
      gravel: false
    mineable/axe:
      oak_sign: false
  item:
    non_flammable_wood:
      CRIMSON_DOOR: true
      CRIMSON_HYPHAE: false
      CRIMSON_PLANKS: true
  worldgen/biome:
    is_beach:
      SNOWY_BEACH: false
      jungle: true

config.getBoolean("block.climbable.iron_bars") will always return false, but Boolean.valueOf(config.getString("block.climbable.iron_bars")) will return true
Is this happening for anyone else?
edit: config is of test_tags_profile

#

Am I forgetting to do something?

humble tulip
#

Shouldn't it be "test_tags_profile.block.climbable.iron_bars"

#

Ah ok

sinful rapids
humble tulip
#

?paste your code pls

undone axleBOT
humble tulip
#

It should work but you say it doesn't so maybe it's something wrong above

sinful rapids
#

Last thing, how do I do that when the player wears a it gives it a certain effect?

humble tulip
#

Or u can google armor equip event

#

And copy the class

sinful rapids
#

okk

#

thanks

tender shard
tender shard
sinful rapids
#

ok

crisp steeple
tender shard
#

well actually a sessionid isn't even required

#

it doesn't really add anything useful imho

#

just something like /npcreply yes|no

#

and if you currently don't have any conversation, then this command simply does nothing

shadow gazelle
#

Is there any way I could compact this or make it more efficient?

    @EventHandler
    public void getSoulboundItems(PlayerRespawnEvent event) {
        if (soulboundItemMap.containsKey(event.getPlayer().getUniqueId())) {
            for (UUID uuid : soulboundItemMap.keySet()) {
                if (uuid.equals(event.getPlayer().getUniqueId())) {
                    PlayerInventory inventory = event.getPlayer().getInventory();
                    SoulboundItemData soulboundItemData = soulboundItemMap.get(uuid);
                    int slot = soulboundItemMap.get(uuid).getSlot();

                    if (inventory.getItem(slot).getType() == Material.AIR) {
                        inventory.setItem(slot, soulboundItemData.getItemStack());
                    } else {
                        inventory.setItem(inventory.firstEmpty(), soulboundItemData.getItemStack());
                    }

                    soulboundItemMap.remove(uuid, soulboundItemData);
                }
            }
        }
    }
#

It's for adding any items back into someone's inventory when they respawn. The item comes from the player's inventory when they died, assuming it had the enchantment that is actually supposed to do that.

sterile token
#

You can use if + return, instead of nested if-else

crisp steeple
shadow gazelle
sterile token
#

mfalex

#

What do you use for catching "Cafeine cache"?

tender shard
#

whut

sterile token
#

What do you use for java catching

tender shard
#

catching?

sterile token
#

Like catching custom objects

tender shard
#

have you smoked too much devil's lettuce again lol

sterile token
#

catching = cache

tender shard
#

no idea what you mean with caching custom objects

crisp steeple
sterile token
#

But i have seen there are libs that make that easier and with a timer to expire the object every x time

#

Something like:

Cache<UUD, BlaBla> cache = new CacheBuilder().expireAt(10, TimeUnit.Minutes).build();

shadow gazelle
sterile token
shadow gazelle
#

what

crisp steeple
tender shard
shadow gazelle
#

If the player isn't in the map then it just "exists" and making it for one usage is just a waste

sterile token
crisp steeple
#

i’m not sure what you’re saying

crisp steeple
#

i’m asking why you iterate through all keys of the map and check if it’s the players instead of using .get on it

sterile token
#

Map#get(path) will return the value if exists, if not will return null

vocal cloud
#

You can always null check it.

sterile token
crisp steeple
shadow gazelle
crisp steeple
#

what?

#

a map can only have one unique key

shadow gazelle
#

I should just add the UUID to that class and use an ArrayList

sterile token
crisp steeple
vocal cloud
#

You check if they have an entry then loop over all the entries to find the players?

sterile token
shadow gazelle
crisp steeple
#

.get(event.getPlayer().getUniqueId()) does the same thing as iterating through all of them and checking if its the players

vocal cloud
#

But why loop through everything when you can just .get?

sterile token
shadow gazelle
#

I was trying to use duplicate keys for whatever reason🤦‍♂️

sterile token
ivory sleet
#

Caffeine is definitively favored to Guava

#

it might look like the same deal superficially, but the implementation is much more sophisticated and optimized

vocal cloud
#

Idk man Guava tastes pretty good

sterile token
#

Allright so i'll definetly use Caffeine cache

#

Thanks to the too for answering

ivory sleet
#

myes, but anyway when I say cleanup pattern I mean that you can have some runnable that clears invalid map entries every minute or so

#

iirc thats how they do it in luckperms

crisp steeple
#

nvm

#

just intellij being weird lying

ornate patio
#

does PersistentDataContainer work for CraftEntitys?

#
CraftEntity craftEntity = CraftEntity.getEntity((CraftServer) Bukkit.getServer(), entity);
PersistentDataContainer persistentDataContainer = craftEntity.getPersistentDataContainer();
persistentDataContainer.set(new NamespacedKey(plugin, "hunger"), PersistentDataType.DOUBLE, 0.5);

I'm using this code but it doesn't save any data

#

i've worked with persistent data containers before and they work fine, but I suspect this may have sometihng to do with CraftEntity..

opal juniper
#

what are you using craft bukkit entities rather than normal bukkit

ornate patio
#

custom NMS entities

opal juniper
#

i imagine that might have something to do with it

#

but you can cast that to a normal bukkit entity anyways

ornate patio
#

wait rlly

opal juniper
#

yes lol, craft bukkit implements bukkit

#

so CraftEntity implements Entity

ornate patio
#

oh lmao

#

lemme try

opal juniper
#

but the fact that it is a “custom nms entity” is probably the reason your pdc doesn’t work

#

i’m not sure how much registering normally happens that you haven’t done

humble tulip
#

I dont think it matters if you cast it to entity or not

ornate patio
shadow gazelle
#

Okay, fixed whatever the hell that was 🤦‍♂️

    @EventHandler
    public void getSoulboundItems(PlayerRespawnEvent event) {
        Player player = event.getPlayer();

        for (SoulboundItemData itemData : soulboundItems) {
            if (itemData.getPlayerUUID().equals(player.getUniqueId())) {
                PlayerInventory inventory = player.getInventory();
                final int slot = itemData.getSlot();

                if (inventory.getItem(slot).getType() == Material.AIR) {
                    inventory.setItem(slot, itemData.getItemStack());
                } else {
                    inventory.setItem(inventory.firstEmpty(), itemData.getItemStack());
                }

                soulboundItems.remove(itemData);
            }
        }
    }
shadow gazelle
#

Anything here that could be improved?

ornate patio
#

wdym

humble tulip
#

U casting ur nms horse to bukkit entity

ornate patio
#

what should i use then

opal juniper
ornate patio
#
package me.screescree.SuperiorSteed.SuperiorHorse;

import org.bukkit.World;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;

import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.horse.Horse;

public class SuperiorHorseEntity extends Horse {
    public SuperiorHorseEntity(World world) {
        super(EntityType.HORSE, ((CraftWorld) world).getHandle());
    }
}
#

thats my custom entity for now

#

this is what I'm casting it to:

import org.bukkit.entity.Entity;
...
// in some function:
Entity newEntity = (Entity) entity;
opal juniper
#

oh no that’s not gonna work

humble tulip
#

Can't cast nms stuff to bukkit stuff

ornate patio
humble tulip
#

It doesn't matter if u cast it to entity because craftentity is the implementation

#

I'm gonna test it

#

You say it doesn't save

ornate patio
humble tulip
#

Check if it exists right after u set it

ornate patio
#

yeah i did

#

checked nbt data

humble tulip
#

Does it?

ornate patio
#

nope

#

i made a command to read the data too and it returns null

opal juniper
#

how are you spawning it

humble tulip
#

Probably have to go the route of nms nbt then

opal juniper
#

or just manage the data yourself 👀

#

avoid nbt

humble tulip
#

Nbt is easier tbh

#

If mc handles the data

#

@ornate patio I'm gonna look at some stuff to see if i can help

ornate patio
# opal juniper how are you spawning it

In a command:

new SuperiorHorse(player.getLocation());

SuperiorHorse class acts as a wrapper:

public class SuperiorHorse {
    private static SuperiorSteed plugin;

    ...

    private SuperiorHorseEntity entity;
    
    public static void setPlugin(SuperiorSteed javaPlugin) {
        plugin = javaPlugin;
    }

    public SuperiorHorse(Location spawnLocation) {
        entity = new SuperiorHorseEntity(spawnLocation.getWorld());

        ServerLevel serverLevel = ((CraftWorld) spawnLocation.getWorld()).getHandle();
        serverLevel.addFreshEntity(entity);
        entity.setPos(spawnLocation.getX(), spawnLocation.getY(), spawnLocation.getZ());
        ...
        System.out.println("TEST YES");
        CraftEntity craftEntity = CraftEntity.getEntity((CraftServer) Bukkit.getServer(), entity);
        PersistentDataContainer persistentDataContainer = craftEntity.getPersistentDataContainer();
        persistentDataContainer.set(new NamespacedKey(plugin, "hunger"), PersistentDataType.DOUBLE, 0.5);
    }

SuperiorHorseEntity is the entity itself:

public class SuperiorHorseEntity extends Horse {
    public SuperiorHorseEntity(World world) {
        super(EntityType.HORSE, ((CraftWorld) world).getHandle());
    }
}
opal juniper
#

oh yeah you definitely need some sort of registering for the pdc

ornate patio
#

wdym registering

ornate patio
humble tulip
#

@ornate patio

#

this works