#help-development

1 messages · Page 938 of 1

eternal oxide
#

not BukkitTask

wintry lynx
#

I have to use Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() instead of Bukkit.getScheduler().runTaskTimer(plugin, new BukkitRunnable()

eternal oxide
#

no

#

you are trying to use BukkitTask

wintry lynx
#

Yea... I need to create a task

eternal oxide
#

No, you need to create a BukkitRunnable

wintry lynx
#

And how would I do that?

#

Psudo code me

eternal oxide
#

it retuirns a Task

#

new BukkitRunnable

wintry lynx
#

Thats what im doing and it says "Depreciated"

#

So I need this, but i need to access the new BukkitRunnable() from within the run()

eternal oxide
#

this.cancel()

wintry lynx
#

I tried that

ivory sleet
#

BukkitRunnable can schedule itself

#

no need to use BukkitScheduler

wintry lynx
#

it loops?

eternal oxide
#

you append .runTaskTimer or runTask as you need

ivory sleet
#

new BukkitRunnable() {
@Override public void run() {

}
}.runTaskTimer(plugin,initialDelay,interval);

#

and BukkitRunnable#runTaskTimer returns a BukkitTask

#

so outside the runnable you can call bukkitTask.cancel();

#

and inside, this.cancel();

wintry lynx
ivory sleet
#

lol nopee

#

?scheduling does cover it iirc

undone axleBOT
ivory sleet
#

well I did write it there

#

as long as someone didnt remove it x)

dusky wigeon
#

yml looks like pain to look at, would you guys recommend using JSON instead ?

ivory sleet
#

yml is supposed to be more friendly

#

well if u use its "common" style

#

but yeah json is fine?

young knoll
#

Imo it is

young knoll
#

If you show a user {} they’ll think it’s programming and get scared

wintry lynx
#

lol

ivory sleet
#

ofc u can use the flow style and make it look more jsony

#
#crazy its valid yml
{
  key: [1,2,3,{nestedKey: "sheesh"}]
  epic: *anchorFromSomewheereree

}
dusky wigeon
#

well that looks better.

but if i need a config file i will see if can make it so people use commands to do stuff and don't need to interact with the JSON file.

#

if not, yml it is.

ivory sleet
#

well

#

I think for sending and receiving data between programs and servers etc json is nice due to its stricter format, that also allows for it to be compactified

#

but well, all the brackets and curly brackets can make it somewhat harder to read and fiddle around with arguably

gleaming token
ivory sleet
#

i recall there being api for this

#

I think Bukkit.getTPS() should be fine?

gleaming token
#

i dont see such thing

ivory sleet
#

a frick, its a paper thing

ivory sleet
#

in case u dont wna measure it urself ^^

gleaming token
#

hmm okey

#

thanks

river oracle
young knoll
#

(MD has rejected it a few times)

worldly ingot
#

In fairness, it is kind of a shit metric and not really anything developers should need access to

#

Some have argued they can disable features if TPS is too poor, but that's a really poor justification imo

eternal oxide
#

they could just monitor CPU usage

young knoll
#

We don’t get api access to the current tick either

#

Sadge

river oracle
#

you can try to stop people but you never really will

vernal basalt
#

is it possible to defen a player? So they can't hear certain sounds?

rough ibex
#

Hm.

#

Maybe.

#

You can either /stopsound (find a way to use this in spigot; im busy)

#

or intercept the sound packet if applicable (I think sounds happening are client-side though.)

vernal basalt
#

yeah i was going to say for example breaking blocks wouldn't that be client side

echo basalt
#

What you can do is just have a resourcepack

rough ibex
#

Very true

#

Just blank out each sound definition, replace: true

vernal basalt
#

yeah but dynamically for different players

valid burrow
#

i need help with placeholder api

#

ive never really used it before

#

im trying to save 5 values globably that dont apply to a certain player but to the whole server

#

how would i do that

lost matrix
#

Create a class which manages those global values, make it a singleton, pass it to your PlaceholderExpansion via the constructor.
The placeholder gets the global values from this singleton.
You can pass the singleton to other listeners or commands and change the values there.

echo basalt
#

womp womp what about a map of functions

valid burrow
#

i cant find any proper doku

#

except these 10 lines

young knoll
#

Placeholders always have a player when resolved afaik

#

But you can just ignore it

valid burrow
#

oh okay

#

so what if people wanna use it eg in a scoreboard

#

oh wait

#

yh nvm

#

alr

#

yh i get it

#

then ill just do what i had before

small valve
#

For BungeeCord, I noticed the ServerConnectedEvent sometimes produces null when doing;

event.getPlayer().getServer(), is this intended? I wanna be able to get the server the player joins the proxy

#

It seems like a hit or miss if it returns null or not

#
[23:12:51 WARN]: Error dispatching event ServerConnectedEvent(player=DeadMan712, server=net.md_5.bungee.ServerConnection@e6a2fb8) to listener com.beanbeanjuice.simpleproxychat.utility.listeners.bungee.BungeeServerListener@ed37f28
java.lang.NullPointerException: Cannot invoke "net.md_5.bungee.api.connection.Server.getInfo()" because the return value of "net.md_5.bungee.api.connection.ProxiedPlayer.getServer()" is null
drowsy helm
#

even though it shouldn't be returning null, might be worth a try

lost matrix
cursive kite
#

How can I remove health from my NPCs

lost matrix
#

*Given they are physical and not virtual

cursive kite
#

Sorry - I meant to hide the health bar from them lol

lost matrix
#

Depends on how this health bar is achieved...

cursive kite
#
            Scoreboard board = manager.getNewScoreboard();
            Objective health = board.registerNewObjective("showhealth", "health");
            health.setDisplaySlot(DisplaySlot.BELOW_NAME);
            health.setDisplayName(ChatColor.DARK_RED + "❤");

            for(User online : Server.getOnlineUsers()) {
                health.getScore(online.getName()).setScore((int) online.getHealth());
            }```
lost matrix
#

But i would assume that this is the health display from Scoreboards.

valid burrow
#

they must have some kind of identifier

lost matrix
#

Why are your NPCs in the online server list?

valid burrow
#

yh confuses me too

#

how did u spawn these xd

cursive kite
#

They aren't lol

#

my users are just a custom player class

valid burrow
valid burrow
#

if so why dont they have an identifier

#

like

cursive kite
#

Nope custom NPC class with hella packets

valid burrow
#

then this code should not effect them

cursive kite
#

shouldnt but it gives them the health scoreboard lol

#

i only want it on players

valid burrow
#

well then they are in thew onlineuser list my guy

#

spigot wont just decide to put them there to bully you

cursive kite
#

i list the online users and its only 1 (me)

valid burrow
#

maybe it was set previously and never got removed?

echo basalt
#

usually the TAB plugin causes this with citizens

cursive kite
#

no plugins beside mine

valid burrow
#

thats really the only 2 options i can imagine

#

either it was already there

#

or your code sets it which requires them to be in the online users list

#

or there is some other code snipped u didnt show us that causes this

cursive kite
#

Removing the scoreboard entirely does remove the health so it has to be within there

#

NPC doesnt have it now but neither do i

valid burrow
#

well

#

i could analyse your whole code base now

#

but fact is

#

npcs seem to be inside Server.getOnlineUsers

#

thats the only possibility explanation

wicked sinew
#

If I'm wanting to make a crop field that players share, but the wheat blocks are unique to each player, in a sense that players can only see and break their own wheat fields, would I use ProtocolLib 🤨 I'm so outdated it hurts

wicked sinew
#

Ok that makes sense, I saw that function mentioned in a 2018 post but I remember the SpigotAPI tend to go--- DEPRICATED every time you'd find something

lost matrix
#

The hard part will be listening to breaking those blocks, since the server has no idea that a player sees a block at this position, which means it will simply disregard packets by clients
which suggest they broke a block at that position.

Workaround: Actually spawn wheat there and make sure it doesnt get broken by players.

This will ensure the Spigot event being fired if they break a fake block.

wicked sinew
#

Can you actually... interact with those fake blocks? 🤔

#

Ah ok

#

ooooo smart dayum

restive mango
#

I'm in the process of updating an old plugin that used some old imports like net.minecraft.server.v1_16_R3.EntityCow, net.minecraft.server.v1_16_R3.EntityTypes, etc. to 1.18.2. Would anyone know where I could go to find what those classes became in the Mojang mappings?

#

Thank you 🙂

restive mango
#

thanks bro

#

wait

#

uh

#

...how do i use this tool

crude drift
#

Is there a bungee economy plugin thats open source?

lost matrix
crude drift
restive mango
#

this doesn't hm

#

okay

#

i will try

#

thanks smile

#

🙂

crude drift
lost matrix
crude drift
#

no

#

not really

lost matrix
#

I would just write one then. What do you need this for?

crude drift
#

basically what I'm trying to do is make a currency managed on the proxy that servers can use plugin messaging with the bungee and ask for players balance and to give them confirmation

lost matrix
#

Sounds good, what do you need the other plugin for?

crude drift
#

my network works on a model where users can have their servers connected to it, hence why I need to give the players confirmation

crude drift
#

I haven't seen any currency plugin directly managed on the proxy before

lost matrix
#

Maybe the proxy is not the proper place for that.
If its for your own network then you might consider using Redis and store the data in a Database.

crude drift
#

The thing is, I can't trust the backend server's word when it comes to currency transfer

#

I was gonna make the proxy send a GUI or a book ui that makes the player confirm their transaction

lost matrix
#

Ah i see what you mean

#

So players can dynamically attach their servers to your network?

crude drift
#

with staff confirmation yes

#

currently we have joins closed so users can't attach their servers (we're rewriting our plugin for the backend servers)

#

the new system lets us dynamically attach servers with a tokenized system

#

the backend server connects to bungee first then negotiates attachment with a secret token issued to the server

lost matrix
#

You might want to consider a standalone application as well.
But that would require a decent project setup.

What part of the currency management is troubling you?

crude drift
#

if that goes fine then it gets connected as a bungee server

crude drift
lost matrix
#

The core is just a mapping from UUIDs to a Number.

crude drift
#

Alright.

lost matrix
#

The main hurdle will be the asynchronous nature of it

lost matrix
crude drift
#

so its compatible with plugins like EconomyShopGui immediately?

restive mango
#

Hi 7smile7, I'm just having some trouble doing the conversion. I will give an example:

I have the import net.minecraft.server.v1_16_R3.EntityZombie. I can use this in my code as follows:

private EntityZombie camera = new EntityZombie(((CraftWorld) player.getWorld()).getHandle());
camera.setInvisible(true);
camera.setLocation(centerLoc.getX(), centerLoc.getY(), centerLoc.getZ(), 0, 0);

Eventually, this was used to have the player spectate the zombie.

When I change this import to the class listed here, https://mappings.cephx.dev/1.18.2/net/minecraft/world/entity/monster/Zombie.html
'net.minecraft.world.entity.monster.Zombie', I no longer can either create a new EntityZombie using a CraftWorld, and I also lose access to the setInvisible and setLocation methods. Do you have any advice?

lost matrix
crude drift
lost matrix
#

Sure

crude drift
#

Do you think its safe to have the backend server ask for the player's balance when they join?

#

Since a player can only be on one bungee server at a time

#

Wait... I'd still need to have a way to delay whatever action is done until the player confirms

#

so I do need to stay async

#

I was eyeing playerpoints to see if it would be plausible to clone its API

agile hollow
#

how can i Apply the edits done in the config without Reloading the whole server

rough ibex
#

You can create a reload command specific for your plugin.

#

which reloads the config and makes any necessary updates

#

so you can do /myreallyverycoolplugin reload without using /reload.

small valve
torn shuttle
#

I am starting to get rather tired of writing for loops, I wish there was a faster keyword for them

lost matrix
torn shuttle
#

like

until(x == 10){
//blah
}

would start an x integer at 0 and make it go up till it is equal to 10

shadow night
torn shuttle
#

for loops are cool because they are flexbile but realistically just how many times do we just need to go from 0 to a certain number

lost matrix
shadow night
torn shuttle
#

is it breakable?

torn shuttle
#

initialize map sizes, initialize objects, initialize pools so on so forth

onyx fjord
#

with something like spark framework, how do you organize stuff so it isnt in one huge method?

ivory sleet
#

i bet u could split up each lambda for each route

pallid oxide
#

but probably gonna just stick with
(1..10).forEach { println(it) }
:D

tardy delta
pallid oxide
lost matrix
#

I hate this...

slender elbow
#

same

#

kotlin

tardy delta
#

i love it

icy beacon
#

i love it

ocean hollow
#

who knows how to use WorldGuard? I registered a flag on their wiki, but how can I check if the player is in a region where there is such a flag?

But what next? How can I find out if it is there? what to do with State?

ocean hollow
#

yeah, i used this

lost matrix
ocean hollow
lost matrix
ocean hollow
#

but what kind of class is this?

lost matrix
#

JavaPlugin

ocean hollow
#

😯

lost matrix
#

Press ctrl + O and look what methods you can override

ocean hollow
#

never heard about "onLoad"

lost matrix
#

You learn every day when programming

slender elbow
#

yeah

quaint mantle
#

who can be a dev on my smp

#

its bliss and we have too many bugs

young knoll
#

?services

undone axleBOT
icy beacon
#

My code is doing something very weird where the invincibility frame reduces from 10 ticks to 0 after shooting a player a couple times lol

#

Like I found out that something removed the i-frame and have been trying all day to find the cause lol

#

Apparently I'm doing something with bows and gotta go figure it out now

twin venture
#

hi , uhh i found a glitch ..
so when i click on the item to fast , it may or may not get the items to my inventory

twin venture
#

how i can disable it?

#

this is only preview items menu so player should not be able to take any item

wet breach
#

don't rely on events soley

twin venture
#

?_?

wet breach
#

use a task that constantly checks the inventory

twin venture
#

HUH?

wet breach
#

not sure why that is hard to grasp

twin venture
#

check what exactly?

wet breach
#

that they didn't take an item

twin venture
#

alr thanks

wet breach
#

when the custom inventory is opened

#

start your task

#

check that the inventory they had, is still the same and no extra items

#

if it has changed, change it back

jagged bobcat
#

Not sure if spigot has drag event, but if it does, check on it too (It's a drag event when it clicks quickly and moves most likely)

wet breach
#

don't really need it with a 1 tick repeating task

#

all you need to do is capture the state of the players inventory when the gui is opened

#

check the state captured with the current state

#

if they don't match, change it back to the state captured initially

#

cancel the task once the gui is closed 😉

orchid trout
#

how do i get a player's name with a uuid when he has never played on the server before?

wet breach
#

believe offlineplayer should do the trick

orchid trout
#

it returns null

chrome beacon
#

You need to fetch the player profile

orchid trout
#

ok

wet breach
#

?javadoc

hybrid spoke
#

shouldnt be possible in survival

twin venture
hybrid spoke
sand spire
#

Hey, so I just started working with ProtocolLib and I send OPEN_SIGN_EDITOR packets to the player when the player sends CHAT packets containing "Sign", but the problem is that after this has happened once during the time the player is online, if the player sends any message that doesn't contain "Sign" they get kicked for "Chat message validation failure". Does anyone know why this is happening?

@Override
            public void onPacketReceiving(PacketEvent event) {
                PacketContainer packet = event.getPacket();
                String message = packet.getStrings().read(0);

                Player player = event.getPlayer();
                Location location = player.getLocation();
                System.out.println(message);

                if (message.contains("Sign")) {
                    event.setCancelled(true);
                    player.sendMessage("Opened Sign");

                    PacketContainer sign = new PacketContainer(PacketType.Play.Server.OPEN_SIGN_EDITOR);
                    sign.getBooleans().write(0, true);
                    sign.getBlockPositionModifier().write(0, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
                    manager.sendServerPacket(player, sign);
                }
            }```
hybrid spoke
#
  • bug prone, f.e. when you get an item dropped it will get removed
wet breach
hybrid spoke
#

canceling the event entirely should do the trick

#

otherwise get on protocol level and check it there

wet breach
#

no, relying on the events only is how you get the bugs

hybrid spoke
#

but that shouldnt be needed

hybrid spoke
sand spire
#

?gui

hybrid spoke
#

and if you give your players creative access you have other problems then duplicating items from a menu

sand spire
#

for inventories

wet breach
#

they don't only occur in creative

#

not sure what your source of info is

wet breach
#

Lol

hybrid spoke
# twin venture

anyways what i forgot to say, make sure to cancel the inventorydragevent as well since sometimes the click event isnt called but drag is

ocean hollow
#

guys, please help me with algorythm that converts playerHp to String

lost matrix
#

lul

ocean hollow
#

I've already spent an hour and it doesn't work.

#
    private Component getHearts(Player owner){
        StringBuilder string = new StringBuilder();
        Component result = Component.text("");

        FontImageWrapper heart = new FontImageWrapper("green_tavern:heart");
        FontImageWrapper halfHeart = new FontImageWrapper("green_tavern:half_heart");
        FontImageWrapper noneHeart = new FontImageWrapper("green_tavern:none_heart");

        int hp = (int) Math.round(owner.getHealth());

        int maxLines = (hp / 20) + ((hp % 20 == 0) ? 0 : 1);
        int fullLines = hp - maxLines-1;
        int remainHp = hp - (fullLines * 20);

        int fullHP = remainHp / 2;
        boolean hasHalf = (remainHp % 2) == 1;
        int empty = 10 - (fullHP + (hasHalf ? 1 : 0));


        Component fullLine = Component.text(heart.getString().repeat(10));

        for (int i = 0; i < fullHP; i++) {
            string.append(heart.getString());
        }
        if (hasHalf) {
            string.append(halfHeart.getString());
        }
        for (int i = 0; i < empty; i++) {
            string.append(noneHeart.getString());
        }
        result = result.append(Component.text(string.toString())).appendNewline();

        for(int i = 0; i < fullLines; i++){
            result = result.append(fullLine);
            if((i + 1) != fullLines){
                result = result.appendNewline();
            }
        }
        return result;
    }
``` now it has code smth like this
lost matrix
#
  public String createHealthBar(int currentHp, int maxHp, String fullHeart, String halfHeart, String emptyHeart) {
    int fullHearts = Math.max(0, currentHp / 2);
    int halfHearts = Math.max(0, currentHp % 2);
    int emptyHearts = Math.max(0, (maxHp - currentHp) / 2);
    return fullHeart.repeat(fullHearts) + halfHeart.repeat(halfHearts) + emptyHeart.repeat(emptyHearts);
  }

There you go

ocean hollow
#

wow

#

so fast

ocean hollow
fallen fjord
#

why does Bukkit.getPluginManager().loadPlugin(newPluginFile) throw a huge error

#

it doesnt load the plugin

#

its a plugin that reloads other plugins except itself btw

icy beacon
#

?nocode + show the error

undone axleBOT
#

It’s hard to answer a programming question without code
Oh no! You ran into a problem. But no worries, people are willing to help, but first they need to see your code. This is because otherwise, they would be providing help based on guesses instead of concrete knowledge. Whether it be a compile error, runtime error, or an unexpected output, I'm sure that if you were to provide code, you'd receive a quick solution.

icy beacon
#

?paste for large text

undone axleBOT
fallen fjord
icy beacon
#

attempted to add duplicate plugin

#

Quite clear imho

#

Also this is spigot discord, not paper

#

?whereami

lost matrix
# ocean hollow I forgot to write here about the transition to a new line, they say it looked th...

See if this works

  public String createHealthBar(int currentHp, int maxHp, String fullHeart, String halfHeart, String emptyHeart) {
    int fullHearts = Math.max(0, currentHp / 2);
    int halfHearts = Math.max(0, currentHp % 2);
    int emptyHearts = Math.max(0, (maxHp - currentHp) / 2);
    return fullHeart.repeat(fullHearts) + halfHeart.repeat(halfHearts) + emptyHeart.repeat(emptyHearts);
  }
  
  public Component createMultiLineHealthBar(int currentHp, int maxHp, int heartsPerLine, String fullHeart, String halfHeart, String emptyHeart) {
    int numberOfLines = (int) Math.ceil((double) maxHp / heartsPerLine);

    String healthBar = createHealthBar(currentHp, maxHp, fullHeart, halfHeart, emptyHeart);
    String[] splitLines = new String[numberOfLines];
    
    for (int i = 0; i < numberOfLines; i++) {
      int start = i * heartsPerLine;
      int end = Math.min(maxHp, start + heartsPerLine);
      splitLines[i] = healthBar.substring(start, end);
    }

    Component multiLineComponent = Component.empty();
    for (String line : splitLines) {
      multiLineComponent = multiLineComponent.append(Component.text(line)).appendNewline();
    }

    return multiLineComponent;
  }
ocean hollow
#

createMultiLineHealthBar((int)owner.getHealth(), (int)owner.getMaxHealth(), 20, heart.getString(), halfHeart.getString(), noneHeart.getString())

lost matrix
#

Hm

#

First validate that the createHealthBar method works.

ocean hollow
#

I tried instead of 20 - 10, then it splits into 4 lines

lost matrix
#

Does the single line produce a long enough String?

#

lmk

ocean hollow
lost matrix
#

Ok looks good. Let me check if the multiline method is scuffed

lost matrix
# ocean hollow .
  public Component createMultiLineHealthBar(int currentHp, int maxHp, int heartsPerLine, String fullHeart, String halfHeart, String emptyHeart) {
    int numberOfLines = (int) Math.ceil((double) maxHp / heartsPerLine);

    String healthBar = createHealthBar(currentHp, maxHp, fullHeart, halfHeart, emptyHeart);
    String[] splitLines = new String[numberOfLines];

    for (int i = 0; i < numberOfLines; i++) {
      int start = i * heartsPerLine;
      int end = Math.min(maxHp, start + heartsPerLine);
      splitLines[i] = healthBar.substring(start, end);
    }

    Component multiLineComponent = Component.text("");
    for (String line : splitLines) {
      Component lineComponent = Component.text(line);
      multiLineComponent = multiLineComponent.append(lineComponent);
    }

    return multiLineComponent;
  }

This should yield the same result as just the single line.
Could you check that?

ocean hollow
lost matrix
#

Ah, missed that one heart is actually 2hp -.-

ocean hollow
#

so what should I change

lost matrix
# ocean hollow

Next try

  public Component createMultiLineHealthBar(int currentHp, int maxHp, int heartsPerLine, String fullHeart, String halfHeart, String emptyHeart) {
    int numberOfLines = (int) Math.ceil((double) maxHp / (heartsPerLine * 2));

    String healthBar = createHealthBar(currentHp, maxHp, fullHeart, halfHeart, emptyHeart);
    String[] splitLines = new String[numberOfLines];

    for (int i = 0; i < numberOfLines; i++) {
      int start = i * heartsPerLine;
      int end = Math.min(healthBar.length(), start + heartsPerLine);
      splitLines[i] = healthBar.substring(start, end);
    }

    Component multiLineComponent = Component.text("");
    for (String line : splitLines) {
      Component lineComponent = Component.text(line);
      multiLineComponent = multiLineComponent.append(lineComponent).appendNewline();
    }

    return multiLineComponent;
  }
ocean hollow
hybrid spoke
#

"pair programming"

lost matrix
# ocean hollow

Could you try this and use "F" "H" "E" for the hearts?
Tell me what the console prints

  public Component createMultiLineHealthBar(int currentHp, int maxHp, int heartsPerLine, String fullHeart, String halfHeart, String emptyHeart) {
    int numberOfLines = (int) Math.ceil((double) maxHp / (heartsPerLine * 2D));

    String healthBar = createHealthBar(currentHp, maxHp, fullHeart, halfHeart, emptyHeart);
    String[] splitLines = new String[numberOfLines];

    for (int i = 0; i < numberOfLines; i++) {
      int start = i * heartsPerLine;
      int end = Math.min(healthBar.length(), start + heartsPerLine);
      splitLines[i] = healthBar.substring(start, end);
      System.out.println(splitLines[i]);
    }

    Component multiLineComponent = Component.text("");
    for (String line : splitLines) {
      Component lineComponent = Component.text(line);
      multiLineComponent = multiLineComponent.append(lineComponent).appendNewline();
    }

    return multiLineComponent;
  }
ocean hollow
ocean hollow
lost matrix
#

Are you just casting your health to ints??

#

-.-

lost matrix
#

Ok let me rewrite this so you can pass double values so you dont round hearts away (like you currently do)

ocean hollow
#

thanks :)))

lost matrix
#
  public String createHealthBar(double currentHp, double maxHp, String fullHeart, String halfHeart, String emptyHeart) {
    int fullHearts = Math.max(0, ((int) (currentHp + 0.5)) / 2);
    int halfHearts = Math.max(0, ((int) (currentHp + 0.5)) % 2);
    int emptyHearts = Math.max(0, ((int) ((maxHp + 0.5) - (int) (currentHp + 0.5))) / 2);
    return fullHeart.repeat(fullHearts) + halfHeart.repeat(halfHearts) + emptyHeart.repeat(emptyHearts);
  }

  public Component createMultiLineHealthBar(double currentHp, double maxHp, int heartsPerLine, String fullHeart, String halfHeart, String emptyHeart) {
    int numberOfLines = (int) Math.ceil(maxHp / (heartsPerLine * 2D));

    String healthBar = createHealthBar(currentHp, maxHp, fullHeart, halfHeart, emptyHeart);
    String[] splitLines = new String[numberOfLines];

    for (int i = 0; i < numberOfLines; i++) {
      int start = i * heartsPerLine;
      int end = Math.min(healthBar.length(), start + heartsPerLine);
      splitLines[i] = healthBar.substring(start, end);
      System.out.println(splitLines[i]);
    }

    Component multiLineComponent = Component.text("");
    for (String line : splitLines) {
      Component lineComponent = Component.text(line);
      multiLineComponent = multiLineComponent.append(lineComponent).appendNewline();
    }

    return multiLineComponent;
  }

Here. But what i've seen from console is that it works perfectly fine.
Looks like your heart Strings are messing up the formatting.

earnest forum
#

Is there a more efficient way to make crops grow back fully after 5 seconds?

#

i was thinking of creating a runnable that sets the growth stage to max after 5 seconds for each crop but that could be wasteful in terms of resources

#

if players are farmings crops quickly

inner mulch
#

.runtasklater?

#

unless its cactus

earnest forum
#

yeah thats my idea

#

but i was just wondering if there was a more efficient alternative

#

or if this way is actually optimized and wont slow down the servere

inner mulch
#

the tasks will be gone after 5 seconds

#

unless you repeat them

spare hazel
inner mulch
icy beacon
lost matrix
# earnest forum yeah thats my idea

There is not much you can do, other than respawning the Blocks with a runnable.
The most performance gain is achieved with an efficient implementation.
One question you need to answer first: How do you handle Blocks which should respawn, but are currently in unloaded chunks.

inner mulch
#

@earnest forum if you are worried you can loadbalance this

earnest forum
#
@Override
    public void handleBlockBreak(Player player, ItemStack tool, BlockBreakEvent e) {
        Block block = e.getBlock();
        //TODO check if player is in farming zone
        if (block.getState().getBlockData() instanceof Ageable ageable){
            e.setDropItems(false);
            ageable.setAge(0);
            block.setBlockData(ageable);
            getBrokenBlockDrops(player, tool, block).forEach(drop ->{
                player.getInventory().addItem(drop);
            });
            e.setCancelled(true);
        }
    }
#

well heres my current code

echo basalt
#

Yeah I just have a runnable for each block

earnest forum
#

i was just going to add a runnable after the event cancel that sets it back to max age

lost matrix
#

I hope /s

echo basalt
earnest forum
#

yeah this is the functionality im hoping to achieve ^

spare hazel
echo basalt
#

Sounds like a list isn't the right data structure for you

sand spire
earnest forum
#

actually wait no

lost matrix
#

Guys pls no... Dont decrement a timer and dont start a task for every block

inner mulch
#

:)

#

i did it myself too 😔

lost matrix
#

Here is my proposal:

public record RespawnableBlock(Location location, BlockData blockData, long respawnTick) implements Comparable<RespawnableBlock> {

  public boolean isValid() {
    return location.isChunkLoaded();
  }

  public void respawn() {
    location.getBlock().setBlockData(blockData);
  }

  @Override
  public int compareTo(@NotNull RespawnableBlock other) {
    return Long.compare(respawnTick, other.respawnTick);
  }
}
public class BlockRespawnTask implements Runnable {

  private final PriorityQueue<RespawnableBlock> respawnQueue = new PriorityQueue<>();

  public void addBlock(RespawnableBlock block) {
    respawnQueue.add(block);
  }

  @Override
  public void run() {
    int currentTick = Bukkit.getCurrentTick();
    while (!respawnQueue.isEmpty() && respawnQueue.peek().respawnTick() <= currentTick) {
      RespawnableBlock block = respawnQueue.poll();
      if (block.isValid()) {
        block.respawn();
      }
    }
  }
}

Just start this task when the server starts and add respawnable blocks to it.

earnest forum
#

what does .peek() do?

inner mulch
#

where is .peek

#

oh

icy beacon
inner mulch
icy beacon
#

Oh were you not takling about streams

earnest forum
#

talking about priority queue

lost matrix
#

The PriorityQueue is ordered by the time the blocks are supposed to respawn.
Each tick you poll from the top of the Queue until the first block doesnt have to respawn.
-> This automatically invalidates all other blocks which are in the queue because every entry behind that is even further in the future.

icy beacon
#

Mb

lost matrix
#

peek() looks at the top of the queue but does not retrieve the element.
Its like poll() but without removing

earnest forum
#

ah righ\t

#

is .respawnTick() supposed to be part of the record you sent?

inner mulch
#

yes

lost matrix
icy beacon
#

Does this look right to you guys? I'm trying to figure out why the spawned wolf does not attack players, but only mobs, when its owner attacks somebody (e.g. if its owner hits a player, the dog will aggro but won't deal damage; if the owner hits a pig, the dog will start damaging the pig)

      // no consumers in 1.8 which i'm unfortunately forced to use for this plugin
      (player.world.spawnEntity(player.location, EntityType.WOLF) as Wolf).apply {
        setAdult()
        maxHealth = 35.0
        health = maxHealth
        isTamed = true
        owner = player
      }

I've removed all my damage-related listeners and the result is the same Nvm, spawning a vanilla wolf and taming it does the same. It's something with my listeners or maybe an external plugin This happens even with no plugins at all, wtf? The problem was that wolves do not attack players in peaceful. Crisis averted.

earnest forum
#

oh do records automatically create methods like that?

#

thats interesting

#

doesn't look like compareTo is being used, can i just leave that out?

lost matrix
#
    BlockRespawnTask respawnTask = ...; // Should be a singleton from somewhere. Only create 1 instance ever.
    
    Location loc = ...;
    Ageable blockData = (Ageable) Material.WHEAT.createBlockData();
    blockData.setAge(blockData.getMaximumAge());
    int respawnTick = Bukkit.getCurrentTick() + 100;
    RespawnableBlock respawnableBlock = new RespawnableBlock(loc, blockData, respawnTick);
    
    respawnTask.addBlock(respawnableBlock);

This would be a usage example

earnest forum
#

Bukkit.getCurrentTick() doesn't exist...

lost matrix
#

Oh no... its a forked method

earnest forum
#

World#getFullTime?

inner mulch
earnest forum
#

not sure if its in ticks though

dawn flower
#

i got this code

        ItemStack item = new ItemStack(Material.PLAYER_HEAD);
        if (texture.isEmpty())
            return item;
        SkullMeta itemMeta = (SkullMeta) item.getItemMeta();
        GameProfile profile = new GameProfile(UUID.randomUUID(), "Player");
        profile.getProperties().put("textures", new Property("textures", texture));
        try {
            Field profileField = itemMeta.getClass().getDeclaredField("profile");
            profileField.setAccessible(true);
            profileField.set(itemMeta, profile);
        } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) {
            return new ItemStack(Material.PLAYER_HEAD);
        }
        item.setItemMeta(itemMeta);
        return item;
    }```

but whenever i try to use it, it throws this warning in the console
```[14:38:11 WARN]: Found inconsistent skull meta, this should normally not happen and is not a Bukkit / Spigot issue, but one from a plugin you are using.
Bukkit will attempt to fix it this time for you, but may not be able to do this every time.
If you see this message after typing a command from a plugin, please report this to the plugin developer, they should use the api instead of relying on reflection (and doing it the wrong way).```
#

how do i not use reflection?

lost matrix
earnest forum
#

Doesn't that not account for lag?

dawn flower
lost matrix
dawn flower
dawn flower
#

👍

#

can i use the texture not url?

lost matrix
#

What is a "texture" for you?

dawn flower
#

URL: d42789267f63a57156cfb81255f63bbd60ecbf486bab0c5042aca663714e2a56

Texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDQyNzg5MjY3ZjYzYTU3MTU2Y2ZiODEyNTVmNjNiYmQ2MGVjYmY0ODZiYWIwYzUwNDJhY2E2NjM3MTRlMmE1NiJ9fX0=

lost matrix
dawn flower
#

...

icy beacon
#

xD

dawn flower
#

so i just get the 'url' in the decoded 'texture'?

lost matrix
#

Yeah, or just use the url directly.

dawn flower
#

wait do i get the full url or the url text thingi

earnest forum
lost matrix
#
public class HeadCache {

  private static final String BASE_URL = "http://textures.minecraft.net/texture/";
  private static final Map<String, ItemStack> headCache = new HashMap<>();

  public static ItemStack get(String key) {
    return headCache.computeIfAbsent(key, HeadCache::create);
  }

  private static ItemStack create(String key) {
    ItemStack headItem = new ItemStack(Material.PLAYER_HEAD);
    SkullMeta meta = (SkullMeta) headItem.getItemMeta();
    PlayerProfile profile = Bukkit.createPlayerProfile(key);
    PlayerTextures textures = profile.getTextures();
    URL url = fromKey(key);
    textures.setSkin(url);
    profile.setTextures(textures);
    assert meta != null;
    meta.setOwnerProfile(profile);
    headItem.setItemMeta(meta);
    return headItem;
  }

  private static URL fromKey(String key) {
    String url = BASE_URL + key;
    try {
      return new URL(url);
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }

}
ItemStack head = HeadCache.get("4ba55671f97ff3bfc5be335ae92cd9749abd619e7afc2a6673597b80b755c741");
dawn flower
#

alr

lost matrix
# dawn flower alr

But dont tell anyone that i showed you a stateful utility class.
Usually not recommended.

dawn flower
#

alr

echo basalt
#

read that as headache

lost matrix
#

naturally

gilded lily
#

can i use this menu?

gilded lily
lost matrix
#

Sure, why not

icy beacon
#

Which kill-death message pair looks the tastiest?

tall dragon
#

Top one imo

sand spire
#

^

shadow night
#

Agreed

twin venture
#

Hello , amm i get this problem :
Initializing Legacy Material Support. Unless you have legacy plugins and/or data this is a bug!

and the server lag for few seconds and after that the lag is gone ..

icy beacon
#

Any reason why you think so?

twin venture
#

how i can fix it?

shadow night
icy beacon
# icy beacon Any reason why you think so?

I personally like the second one more because the color coding of just the first characters helps distinguish between good and bad messages. But I see that you guys prefer the first one. I want to know why you think so, maybe I'm missing something

sand spire
wet breach
#

because I don't like those extra stuff in between what I want to see

icy beacon
#

Alright, thanks for your input, I'll go with the first one 🙂

sand spire
#

Also I would prefer the last one over the first one if the weird emoji's weren't there and the prefix was changd

lost ledge
#

Any tips on how to put bukkit/spigot and bungeecord support into one jar file? Because they both use the same plugin.yml file.
I'm pretty new to multi-platform support

fallen lily
#

If the kits contain special items ofc

#

You were killed by Player with their Necromancer Sword (Necromancer Kit)

#

For example

icy beacon
#

I want my message to look kinda extra (but not too extra), which is why I use the blocks. Maybe some other character would look better as the prefix?

tall dragon
restive mango
#

this is a basic ide question

#

but uh

fallen lily
restive mango
#

is there a way to just automatically // out all broken classes

icy beacon
#

Unfortunately I'm coding this plugin against 1.8

fallen lily
#

I would personally just prefix it with an icon

#

Skull / Sword

icy beacon
lost ledge
icy beacon
#

Do you like that?

#

I personally really do

#

Hope minecraft can render these lol

tall dragon
#

U cant rlly cleanly use the same jar

lost ledge
chrome beacon
#

paper has their own plugin yml too

#

even if it didn't you can just check the platform you're on in the onEnable

wet breach
icy beacon
#

Commission purpose i'm torturing myself but i don't have the balls to say that i am voluntarily coding this particular plugin for 1.8 so i make excuses like "commissions"

#

Getting paid well though

wet breach
#

I refuse commissions for outdated stuff

icy beacon
#

I don't mind 1.8 as long as it's not something crazy

#

I mostly draw the line at whether I have to use pdc or not lol

lost ledge
chrome beacon
#

yeah not talking about that

#

bungee uses it's own yml

sand spire
#

packets giving me headaches 💀

orchid trout
#

should i make like a config file for this

orchid trout
#

thats uh

tall dragon
#

u can combine paper/spigot tho

chrome beacon
orchid trout
#

yeah

#

i mean its readable

lost ledge
cinder abyss
#

Hello, I've got spigot update checker and universal scheduler in my plugin, universal scheduler is shading correctly but not update checker, how can I fix it?
https://paste.md-5.net/axoyesatem.xml

orchid trout
cinder abyss
lost matrix
eternal oxide
# orchid trout

if this is yaml you can;t use numbers as keys without quotes

orchid trout
#

my brain is clogged

lost ledge
orchid trout
#

yeah thats probably it

blazing ocean
orchid trout
#

thats not very fun

lost ledge
blazing ocean
#

real

lost matrix
# orchid trout

The first slot is 4 and every other slot is 2 * (x - 2) + 10

cinder abyss
lost matrix
cinder abyss
lost matrix
#

How did you determine if the lib was shaded correctly or not?

cinder abyss
#

and in com...

#

and where it should be shaded:

lost matrix
blazing ocean
cinder abyss
#

that hell has taken control of my project and my computer will explose in the night

#

no, seriously I have no idea

lost matrix
#

Remove the artifactSet includes and add the scope provided to the spigot-api dependency.

cinder abyss
#

humm okay

#

okay I see

#

it changed nothing

#

I inverted the order of update and universalScheduler in relocation, and only the last one is shaded

lost matrix
#

Each is its own relocation ofc

cinder abyss
lost matrix
#
                        <relocation>
                            <pattern>com.github.Anon8281.universalScheduler</pattern>
                            <shadedPattern>io.github.paulem.btm.libs.universalScheduler</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>com.jeff_media.updatechecker</pattern>
                            <shadedPattern>io.github.paulem.btm.libs.updatechecker</shadedPattern>
                        </relocation>
cinder abyss
#

oh okay thanks!

fallen lily
lost matrix
# cinder abyss

What you essentially did was:

String pattern = "com.github.Anon8281.universalScheduler"
pattern = "com.jeff_media.updatechecker"

Which obvsly overwrites the first assignment completely

cinder abyss
#

seems logical, responsible, practical

eternal oxide
# orchid trout thats stupid

kinda. Its just a rule that all keys must be strings. If you use an unquoted number it gets treated as a number and isn't valid.

cinder abyss
#

I'll try not to make the same error next time x)

lilac dagger
warm pine
#

'org.bukkit.event.player.AsyncPlayerChatEvent' is deprecated ?

blazing ocean
#

use AsyncChatEvent IIRC

warm pine
#

Ah, thank you

cinder abyss
#

Oh an also, how can I update configuration file from a string (writing config.yml content)

eternal oxide
blazing ocean
cinder abyss
cinder abyss
blazing ocean
#

seems about right

lost matrix
#

config.getCurrentPath() ?

peak jetty
#

how do i do something if the player enters a boundingBox (only on enter)

lost matrix
chrome beacon
#

Didn't we tell you that yesterday?

peak jetty
cinder abyss
lost matrix
cinder abyss
#

an empty string

#

so I'm trying using getName

lost matrix
chrome beacon
#

^^

blazing ocean
cinder abyss
#

and... returns an empty string 👍

blazing ocean
#

get your datafolder and then config.yml

cinder abyss
#

okay thanks

blazing ocean
#

so like File(plugin.getDataFolder(), "config.yml") (in java file representation)

lost matrix
# cinder abyss not working :/

A FileConfiguration is not a File.
It exists purely in memory and has no idea in which File it is going to be saved in.

peak jetty
cinder abyss
#

plugin.getDataFolder() + "/config.yml" ?

blazing ocean
#

idt you can use the + operator on a file and string 🤓

#

get the full path of the datafolder + config.yml

cinder abyss
#

oh my bad

cinder abyss
blazing ocean
#

that should work

cinder abyss
#

okay thanks

blazing ocean
#

plugin.getDataFolder().getFullPath() + "/config.yml" ig

#

no actualy

#

its the relative path

cinder abyss
#

oh okay

#

okay thanks I'll try

blazing ocean
#

im stupid mb

cinder abyss
#

x)

#

no it's absolute

blazing ocean
#

absolute = /home/user/server/plugins/myplugin/config.yml, relative = plugins/myplugin/config.yml

cinder abyss
#

🤔

blazing ocean
#

i just use java file objects xd

eternal oxide
#

why are you using paths to get a config.yml?

cinder abyss
#

💀

#

so, how should I use it?

blazing ocean
lost matrix
#
    File configFile = new File(getDataFolder(), "config.yml");
    YamlConfiguration configuration = ...;
    configuration.save(configFile);

getDataFolder() is from JavaPlugin.class

cinder abyss
eternal oxide
#

Plugin#getConfig()

#

you never need to touch Files

blazing ocean
#

.-.

cinder abyss
#

just that

eternal oxide
#

you still don;t need files

eternal oxide
#

you can getResource from teh jar for the new config

#

getConfig() will get teh one in the plugins data folder

bleak moth
#

Hi, i make a plugin which should fix that the teams suffix isnt shown in chat, so i need to edit the Chatmessage with the onChat Event. I heard that there is a way to do that and dont get in the way of other plugins which add Ranks and Set the rank name before the name. I dont want to interfer with these, is there a guide or a specific tutorial which shows that?

blazing ocean
#

why would team suffixes not show

#

i thought they did?

eternal oxide
#

set the resource as default to teh getConfig() merge and save

cinder abyss
eternal oxide
#

no]

cinder abyss
#

hmm

cinder abyss
eternal oxide
#

yes

#

one sec

cinder abyss
#

okay

eternal oxide
#

?stash for me

undone axleBOT
bleak moth
# blazing ocean i thought they did?

they dont i dont really know why it doesnt show. It seems like it worked some time ago but now its not working. I wanted to add The teams suffix in chat but i dont need a complicated Rank plugin. I want to write a Plugin which is so simple only fixing this.

blazing ocean
eternal oxide
#
saveDefaultConfig();
getConfig().options().copyDefaults(true);
getConfig().setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("config.yml"), Charsets.UTF_8)));
saveConfig();```
eternal oxide
#

not tested but that "should" add any new entries to an already existing config

cinder abyss
#

okay thanks

#

I'm testing for you 😄

eternal oxide
#

you could even prefix it with a saveDefaultConfig()

#

so you know there is always a config

cinder abyss
#

yeah I'm already doing that

eternal oxide
#

um, not sure comments will pass as defaults

cinder abyss
#

humm

eternal oxide
#

comment parsing is default true, but they will not be used from a defaults

cinder abyss
eternal oxide
#

not that I know of

blazing ocean
dapper flower
#

any idea how to check if item got renamed in an anvil? like has bold name, i cannot use hasDisplayName as it creates conficts so i need to check if it is bold or not

blazing ocean
#

check with the renaming event

cinder abyss
#

maybe something interesting

blazing ocean
#

couldnt find one

eternal oxide
cinder abyss
#

yeah

muted dirge
#

yaml is cool

fleet imp
#

how to get an entity a player is looking at

muted dirge
icy beacon
inner mulch
icy beacon
#

This is kitpvp so kinda yeah

#

Currently refining the messages to look cool

inner mulch
#

are your messages following ocp

#

?

icy beacon
#

Nothing does. It is impossible

inner mulch
#

no NO

bleak moth
dapper flower
inner mulch
muted dirge
#

?

inner mulch
blazing ocean
#

yea

dapper flower
inner mulch
lost matrix
dapper flower
muted dirge
blazing ocean
#

what event

#

there is none

muted dirge
#

PrepareAnvilEvent

#

this event

blazing ocean
#

doesnt include an itemstack

inner mulch
blazing ocean
#

but not check the actual name

inner mulch
#

t

#

he asked how to see if it got renamed

muted dirge
#

we save the item on inventory change

#

then compare

#

?

inner mulch
#

mehran

lost matrix
inner mulch
muted dirge
#

oh

#

ok

inner mulch
#

and he is tryna get that info

blazing ocean
#

in that case check if it contains the italic token

#

ChatColor.ITALIC iirc

lost matrix
#

He cant use the displayName apparently. So this is going to be hard.
Pretty sure there is simply a better solution to whatever he is trying to do.
He just has to spill the beans to us.

dapper flower
lost matrix
#

Pretty sure slimefun has NBT tags on their items. Nobody should ever use the displayName of an ItemStack to check if it is a custom item or not.

dapper flower
#

no idea how NBT tags work tho

fleet imp
#

how to get an entity a player is looking at

lost matrix
buoyant viper
#

raytrace? idk

icy beacon
#

Or is it Player#rayTraceEntities() idr

lost matrix
#

Yeah, rayTraceEntities. Just make sure to filter out the ray caster.

fleet imp
#

ok...

#

i will probably be back

#

player does not implement raytraceentities

fleet imp
#

so pass the player's location and facing vector?

dapper flower
fleet imp
#

will it return a list, or just the first entity it runs into

icy beacon
#

RayTraceResult

#

Read em docs

fleet imp
#

k

lost matrix
#

They... extend org.bukkit.inventory.ItemStack

dapper flower
lost matrix
#

There we go. They use PDC tags.

#

Dont they have an API directly?

dapper flower
#

i am working on a custom build i made myself because i had to adapt some features

#

not sure if api would help

lost matrix
#

Alright i found their pdc tag

solemn meteor
#

how do I stop my plugin from loading (if something goes wrong during initialization)

lost matrix
dapper flower
icy beacon
#

Or you can just call PluginManager#disablePlugin

solemn meteor
#

which one is safer

#

I assume its disable plugin

icy beacon
#

None is "safer". Your plugin stops in both cases

lost matrix
# dapper flower where is this defined?
  private static final NamespacedKey SLIMEFUN_ITEM_KEY = NamespacedKey.fromString("Slimefun:slimefun_item");

  public static boolean isSlimefunItem(ItemStack itemStack) {
    if (itemStack == null) {
      return false;
    }
    ItemMeta meta = itemStack.getItemMeta();
    if (meta == null) {
      return false;
    }
    PersistentDataContainer dataContainer = meta.getPersistentDataContainer();
    return dataContainer.has(SLIMEFUN_ITEM_KEY);
  }

See if this works

dapper flower
#

how to post images

#

i just verified yet i cant

icy beacon
#

?img

undone axleBOT
#

Can't send images? That's because you're not verified! Use !verify to complete verification.
Alternatively, you can upload screenshots to any image hosting site and share the link.

Here's some screenshot utilities that you can use to upload images.
Lightshot: https://prnt.sc
Imgur: https://imgur.com/upload
Flameshot: https://flameshot.org

icy beacon
#

Now you can

eternal oxide
#

relog for the verify to fix

dapper flower
#

alr

#

doesn't work but maybe i can make a fix

#

ok neither the workaround neither that code works

topaz cape
#

how do i play the potion drinking sound correctly

#

playing it plays only first like 0.5s of the sound or smth

eternal oxide
#

play it 6 times

icy beacon
#

I'm also curious now

icy beacon
eternal oxide
#

yes

icy beacon
#

Holy shit

eternal oxide
#

with a slight delay between each

lost matrix
topaz cape
eternal oxide
#

the sound is 0.5 seconds but you need to overlap a little

#

it takes 3.5 seconds to drink a potion

#

so 70 ticks total

topaz cape
#

70 ticks to drink a potion? 👀

#

dyam

dapper flower
eternal oxide
#

first start playing one after another 0.5 seconds apart

icy beacon
topaz cape
twin venture
#

Hello there , iam trying to make a database.settings , but its empty everytime the server create it :

eternal oxide
#

then shorten it slightly to be in time with yoru animation

lost matrix
twin venture
#

this is my database class

topaz cape
#

does that sound right?

sick hinge
#

does a task ran with runTaskTimer and an event handler run on the same thread?

dapper flower
eternal oxide
#

just do a repeating task at 10 ticks. cancel when you played 6 times

topaz cape
#

aight sure

twin venture
#

the file is being created but null values :

lilac dagger
blazing ocean
#

reminds me of golang

lilac dagger
#

i don't see you saving it

twin venture
#

like this?

lost matrix
twin venture
#

trying to make easy json file manager :

lilac dagger
#

i think the saveconfig method is wrong

#

i think you need something like toJson Writer

twin venture
#

yeah

#

i do

muted dirge
#

how do i register a custom entity in net.minecraft.world.entity.EntityType?

lost matrix
# twin venture
  public void loadConfig() {
    File configFile = new File(plugin.getDataFolder(), "database.json");
    if(configFile.exists()) {
      this.settings = gson.fromJson(new FileReader(configFile), DatabaseSettings.class);
    } else {
      this.settings = new DatabaseSettings();
    }
    // Always save the config to merge default values
    this.saveConfig();
  }
twin venture
#

now it should work

lilac dagger
#

i also don't think flush is correct

#

you might wanna look into how writer works exactly

#

wasn't it something like print?

#

unless tojson does that which i bet it does

twin venture
#

it works on my other plugins

#

this way..

lilac dagger
#

it's just very weird that's all

twin venture
#

testing :p

#

still null uhu

lilac dagger
#

if it doesn't work then you have some weird condition that enables it to work there

lost matrix
# twin venture now it should work

I would probably use nio for this. I find it simpler:

  public void loadConfig() {
    File configFile = new File(plugin.getDataFolder(), "database.json");
    if(configFile.exists()) {
      String json = Files.readString(configFile.toPath());
      this.settings = gson.fromJson(json, DatabaseSettings.class);
    } else {
      this.settings = new DatabaseSettings();
    }
    // Always save the config to merge default values
    this.saveConfig();
  }
  
  public void saveConfig() {
    File configFile = new File(plugin.getDataFolder(), "database.json");
    if(!configFile.exists()) {
      configFile.createNewFile();
    }
    String json = gson.toJson(this.settings);
    Files.writeString(configFile.toPath(), json);
  }
twin venture
#

i was thinking about using yaml files but ehh

#

i think json is nicer and easier

sick hinge
#

everything runs in a single thread as long as you don't use anything that's "async" right? or do I misunderstand how spigot works

lilac dagger
#

i think yaml is more beautiful for end users

twin venture
lilac dagger
#

plus there's no random {} to delete by mistake

lost matrix
twin venture
sick hinge
#

yml is easier to use for end-users probably

#

json is better for serialization

lilac dagger
#

i agree

#

yml for files is probably the best choice

lost matrix
# twin venture nice , would love to try it out
    String json = ...;
    try {
      JsonNode tree = this.objectMapper.readTree(json);
      String yml = this.yamlMapper.writeValueAsString(tree);
    } catch (JsonProcessingException e) {
      throw new RuntimeException(e);
    }

Other way around:

    String yml = ...;
    try {
      JsonNode tree = this.yamlMapper.readTree(yml);
      String json = this.objectMapper.writeValueAsString(tree);
    } catch (JsonProcessingException e) {
      throw new RuntimeException(e);
    }

The mappers needed:

    this.objectMapper = new ObjectMapper();
    this.yamlMapper = new YAMLMapper();
twin venture
lilac dagger
#

yeah

lilac dagger
#

serialization is great because you can contract text

#

yaml is mostly formatted for end users

#

json beatifying is an after taught

lost matrix
# muted dirge ?

nms is generally not supported. Its a anarchistic wasteland.
Try to check what others did and hope that it works for your version.
Prying open frozen registries is always a hustle. Pretty sure you will have to do that.

muted dirge
lost matrix
#

You will need both nms and reflections. If you use only reflections then you will have a much harder time.

lost matrix
#
  private static <T extends Entity> EntityType<T> register(String id, Builder type) {
    return (EntityType)Registry.register(BuiltInRegistries.ENTITY_TYPE, id, type.build(id));
  }

So all you need to do is call

Registry.register(BuiltInRegistries.ENTITY_TYPE, id, type.build(id));

With your custom id and an instance of EntityType.Builder
Which has a static of() method.

#

The factory is just an functional interface

worldly ingot
#

Fairly confident that registry is frozen

twin venture
#

Thanks , i got it working now .

lost matrix
worldly ingot
#

And even if you unfreeze it, there's a non-zero chance the client will crash because that registry is synched, as far as I know

lost matrix
rough drift
#

I know how to fix it but it requires severe reflections

#

and severe hacks

worldly ingot
#

And as a bonus, you have no access to Bukkit entities because CraftBukkit doesn't understand that custom type

rough drift
#

which break every minor update, if you want

worldly ingot
#

Is it not? I thought it was

#

Probably misremembering

twin venture
#

what do you think is better spawning bukkit entity [like 50 , or 100 or more depend on the server owner want .] or spawn entities using packets?
and it will send the packets to the user?

rough drift
#

choco is right

#

the client will crash

slender elbow
#

crap like trim materials and some other random stuff is

rough drift
#

you need to translate the entity

#

goes for items, blocks and some other props too

slender elbow
#

it's like, 5 or 6 registries are synced

worldly ingot
#

CB still won't be happy with you though :p So if you ever want to invoke getBukkitEntity() then you're SOL

twin venture
rough drift
#

That still works :P

#

if I'm not completely fried

worldly ingot
#

Not anymore

rough drift
#

a h.

worldly ingot
#

It used to default to a non-specific CraftEntity but now it throws an exception

echo basalt
#

If we reworked CraftEntity.getEntity into an NMSEntity#createCraftMirror life would be good

twin venture
worldly ingot
echo basalt
#

But last time I pitched this I was turned down for having to modify every nms entity class

#

even though it allows for some very funny behavior

#

unless someone makes those methods final :(

hybrid spoke
rough drift
#

I love how using a map is just not something that's done in that huge method

lost matrix
#

throw new AssertionError("Unknown entity " + entityType); PES2_Uhm

echo basalt
#

what if you just trycatch it

twin venture
rough drift
echo basalt
#

and do some hacky stuff

twin venture
rough drift
#

You can @echo basalt, with Unsafe, technically edit the field ig?

echo basalt
#

ofc

hybrid spoke
rough drift
#

and return a generic entity that wraps your entity

echo basalt
#

throwback to when I hacked in an universal craftscheduler on folia servers

worldly ingot
#

All this conversation is making clear is that you're going through significant effort for something that's probably going to break and is not worth doing lol

echo basalt
#

lmao yeah

worldly ingot
#

If you want a new entity, use Fabric or Forge :p

#

That's what they're for

rough drift
#

but but but I need to run my CratesUltimateEpikProPlusDeluxeEdition++ that's 69420Petabytes (without dependencies) and has a 4.78Quadrilion line config to setup an overcomplicated version of a loot table!!!!

lost matrix
#

In the old days when i had no idea about how any of this worked, i just slapped a Scoreboard String on the entity (PDC wasnt a thing yet) and simply
checked the tags in the ChunkLoadEvent, then replaced the vanilla entity with my custom one.

echo basalt
#

just sent a 200mb .zip bomb to one of my customers

echo basalt
#

And associate data to that unique id

lost matrix
#

I remember a plugin doing that.

public static final String SECRET_NAME_PREFIX = "§a§c§a§9§r";

And then checked if the name contained this prefix (which ended with §r to reset the formatting)

echo basalt
#

Well yeah but in my case it was more sophisticated

lost matrix
#

From codisimo i think

#

What was it...

echo basalt
#

Think of generating a uuid, grabbing both longs and rendering them as §hex

rough drift
#

I just checked references tbh 💀

echo basalt
#

Well yeah but database support

#

it was dank

rough drift
#

put the InventoryView in a map

rough drift
echo basalt
#

blud i'm talking about itemstacks that players can mess with

#

It was bootleg pdc

rough drift
#

😭

echo basalt
#

I've done all kinds of hacky stuff tbf

#

Extending nms entities and rewriting all movement logic to collide with client-sided blocks

#

uH

rough drift
echo basalt
#

I think I had a client-sided world manager at some point

#

hm I once tried making fl studio in minecraft

#

had a system to order domino's within minecraft

#

that was fun

shadow night
#

actually

#

you should use the java chromium embedded framework or whatever it was called and write an utility that would let you access the internet from a minecraft server

lilac dagger
#

that sounds like such a huge undertake

wicked sinew
#

Ok question, since this is something I always struggled with-- is there a hot-reload or better way to compile a plugin and restart a server yet? 💀 Such as JRebel for Minecraft

scenic sigil
#

hello, when i start the minecraft's server my plugin don't start who help me to resolve?

scenic sigil
shadow night
valid burrow
lilac dagger
#

should be fine for testing

echo basalt
#

It used selenium and a lot of wrapping to send requests

valid burrow
#

why does it not start? is there an error

echo basalt
#

it could process your entire pizza order in like 15 seconds it was wacky

echo basalt
#

so I just made it all client-sided

shadow night
scenic sigil
valid burrow
#

is there an error in the servers console

lilac dagger
echo basalt
echo basalt
#

Not really

#

Just time consuming

#

specially given I hadn't set up mappings yet

scenic sigil
shadow night
lilac dagger
#

what if you had to handle block breaking?

#

or to interact with the world more

echo basalt
#

I've done client-sided blocks like 20x already

#

That isn't a problem

valid burrow
#

woah

#

impressive

wicked sinew
echo basalt
#

It's quite simple you're only dealing with like 3 packets

lilac dagger
#

but like at a big scale?

valid burrow
echo basalt
#

yeah

#

I've done big scale

#

intercepting and processing chunk packets all of that

wicked sinew
valid burrow
lilac dagger
#

that's nice

shadow night
valid burrow
wicked sinew
#

I know my hardware is good 🤣

valid burrow
#

than your server shouldnt take long to boot

#

spigot and paper are both rather fast

#

shouldnt take more than 30 seconds i have a 1.8 server that boots in 5 seconds

shadow night
#

comparing to 1.19.4 for example

icy beacon
scenic sigil
icy beacon
valid burrow
scenic sigil
ornate heart
#

love dealing with that issue

remote swallow
#

compiled with java 22 but trying to run on 16 iirc

shadow night
#

ah, that man be compiling against newer java and wondering why his plugin ain't working

#

I would recommend to compile against java 8 if you are planning to support most versions

nova bolt
#

hi , does anybody have any idea why my worldguard plugin doesnt work?

chrome beacon
#

?notworking

undone axleBOT
#

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

scenic sigil
#

i resolve installing Paper because paper is Bukkit+Spigot

chrome beacon
#

WorldGuard is compatible with Spigot

peak jetty
#

how do i make a chest with items inside?

chrome beacon
#

Place a chest

#

Get it's inventory

#

set item

#

Or are you talking about a chest item with items in?

peak jetty
#

like how do i get a chest which is at a specific location?

chrome beacon
#

get it's blockdata

lost matrix
#

Hm

solemn meteor
#

is there documentation or material for making config.yml s

peak jetty
lost matrix
#

*BlockState is what you want

chrome beacon
#

oh right mb

#

wrong name

solemn meteor
chrome beacon
dawn flower
#

wait im 1000% sure it's getBlockState?

#

oh damn

chrome beacon
#

It does exist

#

sort of