#development

1 messages · Page 12 of 1

lyric gyro
#

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.checkerframework.checker.nullness.qual.NonNull;

import static org.bukkit.Material.*;

public class Listeners implements Listener {

    @EventHandler
    public void usedGoatHorn (PlayerInteractEvent e){
        Player p = e.getPlayer();
        Material goatHorn = e.getMaterial();
        if (goatHorn == GOAT_HORN){
            if (p.hasCooldown(goatHorn)){
              return;
            } else {
                World world = p.getWorld();
                world.spawnEntity(p.getLocation(), EntityType.GOAT);
            }


        }

        }


    }

#

what about now

hoary scarab
#
public void onInteract(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    Material goatHorn = Material.GOAT_HORN;
    ItemStack interactionItem = event.getInteractionItem();
    if(interactionItem == null)
        return; // No item.

    if(interactionItem.getType() != goatHorn)
        return; // No goat horn.

    if(p.hasCooldown(goatHorn))
        return; // Cool down

    World w = p.getWorld();
    w.spawnEntity(p.getLocation(), EntityType.GOAT);
}
lyric gyro
#

what is the item stack thing for

hoary scarab
lyric gyro
#

Uhh it's not needed I think

tepid hawk
#

is it possible to return a net.kyori.Component on placeholder request?

hoary scarab
dusky harness
hoary scarab
#

I'll pretend I didn't see that @dusky harness 😉

dusky harness
#

as it wasn't relevant

#

idk I don't feel like scrolling up and checking

dense drift
dense galleon
#

How bad is it for performance to create a runnable for each mob present in a minigame I am making?

#

There can be up to 150-200 mobs in the minigame

dense drift
#

x y problem?

dense galleon
#

Hold on

#

I was about to get into specifics

#

The runnable would run every 10 ticks, will compare doubles and possibly change the value of a field present in its outer class

merry knoll
#

and loop over the mobs / entities

dense galleon
#

I already have a data class for each mob, would have been neat to have a runnable within that class which handles that logic

#

Instead of having a common runnable do that

merry knoll
#

it wont be a big deal performance wise

#

runnable is just a version of a callback

dense galleon
#

It's code which affects mobs AI, would feel weird to have each mob AI change in some MobManager class

merry knoll
#

state machine?

#

again the runnable itself is not a big deal

#

it depends on what you do inside it

dense galleon
#

okay that's kinda what I wanted to hear

merry knoll
#

make sure to cancel the tasks as they die though

dense galleon
#

Yeah of course

lyric gyro
#

guys

#

I just figured out something really weird

dense galleon
#

I'd literally just be comparing a few doubles together, and then setting a field from time to time

lyric gyro
#

with goat horns

#

seriously

#

the first goat horn

#

"ponder" isnt considered a goat horn?

merry knoll
#

i dont think it fits in the class though

#

architecture wise

lyric gyro
#

me

#

how do I pull a nbt tag from an item?

#

using nms

#

of course

clever relic
#

Yeah. basically making a site for it and just want the basics:

All below will be vice versa

MP4 -> GIF
AVI -> MP4
FLV -> MP4
PNG -> JPEG etc
PDF -> DOC, DOCX```
lyric gyro
#

uh I don't know of any one single godlike solution that does all of them but you'll be able to find plenty of solutions that can do specific types, e.g. ffmpg for video, another one for images, another for documents etc

dusky harness
#

unless you want to pay for a conversion api just google like "convert png to jpg java"

icy shadow
#

Ffmpeg can do all of those video and audio conversions yeah

lyric gyro
#

just cant figure out the method or how to do it

lyric gyro
#

like

#

I want to make goat horns do different things

#

but I don't want to create a new item for them

winged pebble
#

You have to have an instance of an item to set its nbt tags, yes

#

But not to read from them

lyric gyro
#

i dont want to set nbt tags

#

just read them

#

like

#

if nbt tag = 5 (idk)
do something

winged pebble
#

No, you don't need to create a separate item to read from it, you just use the item you already have

lyric gyro
#

so

#

how do i do it

lyric gyro
winged pebble
#

Then you haven't read it

#

It shows how to read an nbt tag

lyric gyro
#

where exactly

#

this thing is huge

merry knoll
#

the whole thing

winged pebble
#

Ctrl + f is your friend

lyric gyro
#

yeah i tried that

winged pebble
#

What did you search

lyric gyro
#

read

winged pebble
#

Do "get"

lyric gyro
#

what is it about

#

goddamn so much text

#

its making me confused

winged pebble
#

No it's not lol

#

The first screen of text tells you how to get the NBT object, set a value in it, and how to retrieve a value from the nbt object

#

Essentially the basics of interacting with nbt

lyric gyro
#

what is nbt compound though

#

and nms copy

winged pebble
#

You have to get the NMS version of the item to get the NBT data

#

And NBTTagCompound is just the class that stores/interacts with nbt

lyric gyro
#

If a specific goat horn is played

#

Add potion effect absorption

winged pebble
#

interacts with nbt

#

That answers your question I believe

lyric gyro
#

understood

#

So what I have to do is

#

Get the nmscopy

#

Then do something with the compound idk

#

then write the code of what I want it to do?

#

And how nbt tags look like?

#

are they numbers

#

?

#

or something like that

winged pebble
#

You'll have to explore that yourself

#

Idk how the data is stored in goathorns

lyric gyro
#

@winged pebble It also mentions creating a NBTTCompound

#

But the person who wrote this is using apple as an example

#

Which doesn't have NBT tags I believe

#

But a goat horn does

#

so

winged pebble
#

Basically iirc, getTag() can return null

#

So they are just giving it an instance if it is null

lyric gyro
#

Christ

#

This is going to be difficult

#

But I'll try

#

that's the last thing I've got to do

#

till my plugin is finished

lyric gyro
#

where do I put this

#

this net.minecraft.server thing

winged pebble
#

That's just the package of nms you're using

#

It's the fully qualified name of the class you're accessing

lyric gyro
#

I don't have to write this anywhere in my code then?

winged pebble
#

You'll most likely have to adapt it for your version

lyric gyro
#

yes

winged pebble
#

As you can't just say ItemStack because you also have the bukkit ItemStack class so it needs to differentiate them somehow

winged pebble
#

Use the fully qualified name of the class

lyric gyro
#

goddamn why am I so slow today

lyric gyro
#

thats what I want to know

winged pebble
#

All that line is doing is taking a bukkit item and giving you the nms version of it

#

So you need to do that first in order to access the nbt tags

lyric gyro
#

i know

#

but where do i put it

#

i know what its doing

winged pebble
#

What do you mean where do you put it?

lyric gyro
#

where do i write it

winged pebble
#

You put it wherever you're checking to see if the item in question is that item

lyric gyro
#

ok

lyric gyro
#
            if (p.hasCooldown(goatHorn)){
              return;
            } else {
                net.minecraft.server.v1_19_R1.ItemStack nmsHorn = CraftItemStack.asNMSCopy(GOAT_HORN);
                World world = p.getWorld();
                world.spawnEntity(p.getLocation(), EntityType.GOAT);
            }```
#

what does craftitemstack does btw

winged pebble
#

CraftItemStack is just the class name

#

And you're accessing a static method from it

lyric gyro
#

oh ok

#

get it

#

so uh

lyric gyro
#

its asking me to add a dependency for it

winged pebble
#

1.17+ doesn't include the version in the package name for nms

winged pebble
#

You use the updated package name

lyric gyro
#

nonono

#

I think I got it

#

I didn't need to use that

#

net.minecraft.server thing

#

just the ItemStack part

#

I didn't need to refer the package

winged pebble
#

Potentially

lyric gyro
# winged pebble Potentially

'asNMSCopy(org.bukkit.inventory.ItemStack)' in 'org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack' cannot be applied to '(org.bukkit.Material)'

#

it's saying this

winged pebble
#

Yup, makes sense

#

You're not giving it the parameter it's asking for

lyric gyro
winged pebble
#

It tells you in the error

lyric gyro
#

Im trying to use a material

#

when it needs a itemstack?

winged pebble
#

Correct

lyric gyro
#

really whats the difference between these two

winged pebble
#

Well the main difference is that CraftItemStack.asNMSCopy accepts an ItemStack as a parameter, and a Material is not an ItemStack

#

It's the difference between a Door and Wood

#

An ItemStack has more properties than a Material

lyric gyro
#

so uh

#

what do I

#

put

winged pebble
#

You give it an ItemStack

lyric gyro
#

oh wait

#

I see now

#

I need to create an item stack

#

for the material goat horn

winged pebble
#

You don't actually

#

You're using an event, right?

lyric gyro
#

yeah

#

playerinteract event

winged pebble
#

And how are you checking the material type?

lyric gyro
#


import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

import static org.bukkit.Material.*;

public class Listeners implements Listener {


    @EventHandler
    public void usedGoatHorn (PlayerInteractEvent e){
        Player p = e.getPlayer();
        Material goatHorn = e.getMaterial();
        p.setCooldown(GOAT_HORN, 800);
        if (goatHorn == GOAT_HORN){
            if (p.hasCooldown(goatHorn)){
              return;
            } else {
                ItemStack nmsHorn = CraftItemStack.asNMSCopy(GOAT_HORN);
                World world = p.getWorld();
                world.spawnEntity(p.getLocation(), EntityType.GOAT);
            }


        }

        }


    }```
#

the whole thing

#

im checking material type with get material and an if statement if thats what you mean

winged pebble
#

Oh, legit didn't know that getMaterial() was a method on that event

#

I've always just gotten it from the item

lyric gyro
#

so

#

what do you suggest

winged pebble
#

Get the item from the event instead

mystic gull
#

Bukkit.getScheduler().getPendingTasks() will return all the pending tasks from my plugin or from the whole server?

lyric gyro
#

so instead of getmaterial

winged pebble
lyric gyro
#

i would just be

#

material material = goathorn

#

or something like that

winged pebble
#

I'm just saying that you can get the ItemStack from the event and pass that in asNMSCopy()

lyric gyro
#

i think ill just create a new itemstack

winged pebble
#

You do realize the issue with that, right?

lyric gyro
#

what

winged pebble
#

Imagine you have two boards, you write on one board, and in order to see what you have written on the board, you cut another board from a tree

#

The second board isn't going to have the writing that the first board does

#

You're trying to create a second board to read the writing on the first

#

The nbt data that you're trying to read, won't exist on the new itemstack that you create

lyric gyro
#

oh

#

@winged pebble

#

I think ill have a break

#

I feel my head is full rn

#

and I cant understand this

#

can we do that later

nimble leaf
#

Can PAPI run on Bungeecord?

#

or the API be accessed by a BungeeCord plugin?

#

I mean

#

I want to script a plugin with placeholders on Bungeecord

#

so all backends servers can access that placeholder

merry knoll
merry knoll
#

but you need to hook up to the servers individually and pull data to bungee

merry knoll
#

is probably the best idea

#

spigot feeds the data to papi and bungee handles logic

nimble leaf
#

at this point yes

#

Thanks for answering mate

lyric gyro
#

could anyone help me with this

#

since deerjump isnt online

#

I just want to get the nbt tags of a goat horn

#

and make them do different stuff

#

depending on the horn

#

but idk how to get the nbt tags

#

ItemStack nmsHorn = CraftItemStack.asNMSCopy();

#

more specifically

#

idk what to put in the parameter

#

Material goatHorn = e.getMaterial();

#

we also have this

#

should I just make it an itemstack?

#
    public void usedGoatHorn (PlayerInteractEvent e){
        Player p = e.getPlayer();
        Material goatHorn = e.getMaterial();
        p.setCooldown(GOAT_HORN, 800);
        if (goatHorn == GOAT_HORN){
            if (p.hasCooldown(goatHorn)){
              return;
            } else {
                ItemStack nmsHorn = CraftItemStack.asNMSCopy();
                World world = p.getWorld();
                world.spawnEntity(p.getLocation(), EntityType.GOAT);
            }


        }```
#

the full thing

winged pebble
#

Focus on one step at a time

#

In order to get an nbt value from an item, you need the NBTTagCompound from the item, since you can't access the NBTTagCompound from the Bukkit version of the item (org.bukkit.inventory.ItemStack), you need to pass in the Bukkit item you do have to CraftItemStack.asNMSCopy(), which gives you the NMS version of the item (net.minecraft.world.item.ItemStack), which does have access to the NBTTagCompound

lyric gyro
#

yes

lyric gyro
#

im asking about the parameter though

winged pebble
#

It doesn't seem like you do though

lyric gyro
#

now I do

lyric gyro
#

But I don't have an itemstack for goat horn

lyric gyro
#

yes but how

#

if it's not an itemstack

#

it's a material

winged pebble
#

It is

#

I didn't say get the Material

#

I said get the ItemStack

#

Look at the methods on PlayerInteractEvent

#

Which one gives you an ItemStack?

lyric gyro
winged pebble
#

Look at the methods of this class, and look for one that returns an ItemStack

lyric gyro
#

is it getItem?

#

yeah it is

winged pebble
#

Yup

#

then you can get that item and pass it into CraftItemStack.asNMSCopy()

#

Which will give you the nms version of the item the player interacted with in their hand

lyric gyro
#

I think I got it

#

but the ide isn't allowing me to use getitem

#

like

#

p.getItem();

winged pebble
#

What is p?

lyric gyro
#

player object

winged pebble
#

And what class has getItem() as a method?

lyric gyro
#

oh

#

im stupid

#

and slow

#

lol

lyric gyro
#

so in this case

#

hmmm

#

let me see

#

@winged pebble

#

It's playerinteract event

#

no wait

#

it's uhh itemstack?

winged pebble
#

right, so get the ItemStack from the event and pass it through

#

e.getItem()

#

That is what you're looking for

#

e is your PlayerInteractEvent variable

lyric gyro
#

oh

#

what does e do

#

it's the name of my "p.i.e" variable

#

im just lazy dont want to type the whole thing

winged pebble
#

It's the event

lyric gyro
#

yeah

#

do i have to erase the material object?

#

material material = e.getmaterial

#

or nah

lyric gyro
#

I can't have both right?

#

that thing

#

with the boards you said

winged pebble
#

There is no reason to get the Material from both the event and the Item

#

One or the other works fine

#

But you need the item because you need to pass it to asNMSCopy()

lyric gyro
#

if (p.hasCooldown(goatHorn)){

#

this

#

it gives me an error if i try to make it an itemstack

#

idk if you went silent because you are thinking on a solution or because you are thinking im stupid

#

well i am stupid

#

but ig i used all my brainpower for the day

#

and im slower than usual for some reason

winged pebble
#

Well hasCooldown() only accepts a Material

lyric gyro
#

see

#

that's why we need both the material and an itemstack

#

will it work if i just add getType on the end?

winged pebble
#

I never said you didn't need Material

lyric gyro
#

if (p.hasCooldown(goatHorn.getType())){

#

like that

winged pebble
#

That works

lyric gyro
#

so we can move on ig

#

now the parameter

#

no wait

#

if (goatHorn == GOAT_HORN){

#

we still have this

#

if (goatHorn = GOAT_HORN){

#

this to be more specific

#

so it says that it needs to be a material

winged pebble
#

So do the same thing that you did for hasCooldown

lyric gyro
#

yeah done

#

i think it works

#

it isnt giving me any more errors related to this

#

but we still have that parameter

#

what do i put there again?

#
        p.setCooldown(GOAT_HORN, 800);
        ItemStack goatHorn = e.getItem();
        if (goatHorn.getType() == GOAT_HORN){
            if (p.hasCooldown(goatHorn.getType())){
              return;
            } else {
                ItemStack nmsHorn = CraftItemStack.asNMSCopy();
                World world = p.getWorld();
                world.spawnEntity(p.getLocation(), EntityType.GOAT);
            }```
#

code btw

winged pebble
#

For simplicity's sake, lets shuffle things around a little

Player p = e.getPlayer();
// p.setCooldown(GOAT_HORN, 800) You don't actually want this here. Worry about this later
ItemStack item = e.getItem();
if (item.getType() != GOAT_HORN) return;
if (p.hasCooldown(GOAT_HORN)) return;

// ...
lyric gyro
#

if (item.getType() != GOAT_HORN) return;

#

i am sure this part is not needed

#

well

#

for your code

#

it might be

winged pebble
#

It just verifies that the item you're interacting with is in fact a goat horn

lyric gyro
#
            if (p.hasCooldown(goatHorn.getType())){
              return;```
#

isnt this good enough

#

?

#

i mean

#

its a mess of parenthesis

#

reminds me of middle school

winged pebble
#

Couple reasons I changed things around:

  1. you're calling the ItemStack variable goatHorn but you haven't yet verified that it's type is in fact GOAT_HORN
  2. inverting the check and returning reduces indentation levels and improve readability
lyric gyro
#

if i do your way

#

I can make an if statement with a bunch of switch statements inside

#

which look nicer

winged pebble
#

No, my way eliminates the nesting

lyric gyro
#

so I think I'll do your way

#

so i have a system where when you put on a certain block, you get a rainbow glass helmet. it constantly checks if the item on your head has certain nbt data, and if so, continues the loop. the issue, i want it so when you click on your helmet slot with the same item it stops the loop. although i do not know how to do this since they are same exact item. (clicking on rainbow glass helmet currently on head with glass would continue the loop as it would check for nbt data and obviously it would have that since same item).

winged pebble
#

These two snippets are functionally the same

Player p = e.getPlayer();
ItemStack item = e.getItem();
if (item.getType() != GOAT_HORN) return;
if (p.hasCooldown(GOAT_HORN)) return;
// do something
``````java
Player p = e.getPlayer();
ItemStack item = e.getItem();
if (item.getType() == GOAT_HORN) {
  if (!p.hasCooldown(GOAT_HORN)) {
    // do something
  }
}
```But which one is easier to read?
lyric gyro
#

less curly braces

#

means more readability

#
                World world = p.getWorld();
                world.spawnEntity(p.getLocation(), EntityType.GOAT);```
#

just gonna

#

put this here

winged pebble
#

Also, you should verify that the item isn't null

if (item == null || item.getType() != GOAT_HORN) return;
#

Forgot about that detail

lyric gyro
#

@winged pebble

#
        p.setCooldown(GOAT_HORN, 800);
        ItemStack goatHorn = e.getItem();
        if (goatHorn == null || goatHorn.getType() != GOAT_HORN) return;
        if (p.hasCooldown(GOAT_HORN)) return;```
#

much better

winged pebble
#

So then after those checks, you can be sure that it is a goat horn

lyric gyro
#

holdup

#

instead of p.hascooldown(goat_horn)

#

wouldnt it be better if it was the object goat horn

#

not the material?

winged pebble
#

No, because hasCooldown() only accepts a Material

lyric gyro
#

will it work the same though?

winged pebble
#

It only accepts a Material

lyric gyro
#

I know

#

Im asking if your way

#

will it work the same

#

if i use material instead of the itemstack goathorn

winged pebble
#

so passing item.getType() on a goat horn or passing in Material.GOAT_HORN is the exact same thing

lyric gyro
#

ok

#

so now let me guess

winged pebble
#

It only accepts Material, so you literally can't pass in the ItemStack

lyric gyro
#

if (goatHorn.getType() = GOAT_HORN){

#

now I just add all the crap that I posted here

#

done

#

now

#

the parameter

#

@winged pebble what do I put there

#

im still not sure about what I should put there

#

oh wait

#

nevermind

#

net.minecraft.world.item.ItemStack nmsHorn = CraftItemStack.asNMSCopy(goatHorn);

#

im so stupid

#

and blind

#

I somehow knew it was this

#

all I had to do was check the quick solutions on intellij

#

lmao

#

now we can finally

#

finally

#

go to the next step

#

the compound

#

I think now I finally have an idea of what i've got to do

#

get the nbt tag with the compound

#

then

#

create an object with the nbt tag

#

and after that

#

switch

#

statements

winged pebble
#

Well first you need to identify how you retrieve the specific type of goathorn from the nbt

#

Which is something you'll have to explore yourself

lyric gyro
winged pebble
#

I can't do everything for you

lyric gyro
#

I know

winged pebble
#

A big part of learning something new is fumbling with it yourself

lyric gyro
#

yes yes

#

I'll try to do it by myself

#

this is hard

#

but I'll get the hang of it

winged pebble
#

What I would do is print out the nbt data of the item to see how each goat horn is differentiated

lyric gyro
#

just one last question

#

is this a good spot for my net.minecraft.server thingy

#

this is like

#

my first decent plugin

#

I wanted to make it open source

#

so I gotta make it readable

winged pebble
#

At that point in the code, has the item been verified as a goat horn?

winged pebble
#

Then no, not a good place for it

dusky harness
#

instead of e and p

#

also I would put the ... nmsHorn = ... on one line

lyric gyro
#

too long idk

#

I think i'll put it where it was before

#

right below getWorld

#
        if (p.hasCooldown(GOAT_HORN)) return;
        if (goatHorn.getType() == GOAT_HORN){

            World world = p.getWorld();
            net.minecraft.world.item.ItemStack nmsHorn = CraftItemStack.asNMSCopy(goatHorn);
            world.spawnEntity(p.getLocation(), EntityType.GOAT);```
#

the code if anyone has any objections

#

i'll also create my compound right below it

dusky harness
#

also
nms 🤢

#

but you already have it set up so I won't make a big deal out of it

lyric gyro
#

you won't be saying this when you see what i'll do with these goat horns

winged pebble
#

If only there was a GoatHornMeta 😛

dusky harness
lyric gyro
#

please god

dusky harness
#

i wonder why spigot doesn't have it

#

smh md_5

lyric gyro
#

this would make my life so much easier

dusky harness
lyric gyro
#

I do

dusky harness
#

nope

lyric gyro
#

you know that goat horn that sounds like the THX opening?

#

yeah

#

I wanted to do so when you play it

#

a horde of goats spawn and attack mobs

dusky harness
#

well it's not built-in to the spigot api
and this is such a common thing that it's basically documented so in this case it really doesn't matter

dusky harness
#

💀

lyric gyro
#

since

#

it's a goat horn

#

and its the best horn

#

so i figured it would have the best effect

lyric gyro
#

so you would be callin your soldiers

#

if people actually download this ill make it into a mod

#

idk how but ig ill try

dusky harness
#

you mean plugin?

#

or like fabric/forge

lyric gyro
#

forge

dusky harness
#

o

lyric gyro
#

but

#

that's for a really distant future

#

since afaik

#

spigot doesn't exist in mod creation

#

wait forge is an api right?

#

idk what it is

#

💀

winged pebble
#

It's a framework

#

That's how I'd describe it

dusky harness
#

using nbt api it'd be ```java
String type = new NBTItem(goatHorn).getString("instrument" /* or whatever the key is */);


I'd say forge/fabric itself are modding "platforms" which also have an API
lyric gyro
#

NBTTagCompound hornsCompound = (nmsHorn.hasTag()) ? nmsHorn.getTag() : new NBTTagCompound();

#

Has tag and get tag

#

doesnt exist

dusky harness
#

Anyways I've gtg now, cya

lyric gyro
#

bye

dusky harness
#

bye

winged pebble
lyric gyro
#

Did they change anything else after 1.17 that I need to know?

#

what are these methods called now

winged pebble
#

In 1.17+ they included support for Mojang Mappings

#

Which means the didn't need to manually map things as much anymore

#

So they left a lot of the names obfuscated

dusky harness
#

ok me go bye

#

cya

lyric gyro
#

will anyone tell me how do I call these methods or nah

#

bye

winged pebble
#

Use this to find what you are looking for

dusky harness
#

screaming sandals has a gradle plugin to easily add multi version support

#

on the page deerjump sent

#

but its best if you keep 1.14.4+ support only or else it gets a little messy since below doesn't have mojang mappings

#

ok afk

lyric gyro
winged pebble
#

Follow the package

proud pebble
#

they are named as such

#

theres a method for getting the tag or a new compoundtag if it doesnt exist

lyric gyro
#

5 or 6

#

different instances of compoundtag

winged pebble
#

Which class does getTag and hasTag come from

lyric gyro
#

why you askin me dude

winged pebble
#

For your own good

lyric gyro
#
            NBTTagCompound hornsCompound = (nmsHorn.hasTag()) ? nmsHorn.getTag() : new NBTTagCompound();```
winged pebble
#

So hasTag and getTag belong to which class?

proud pebble
#

itemstack

#

getOrCreateTag() exists btw

lyric gyro
#

then why is the ide giving me an error

#

it says it cant resolve getTag or hasTag

#

in itemstack

winged pebble
#

Because they are obfuscated for you

proud pebble
#

Because your using the obfuscated jar, not the remapped version

winged pebble
#

So use the link I sent to see the connection between the obfuscated names and the normal names

lyric gyro
#

are you fucking KIDDING ME

winged pebble
#

Or you can learn how to use the remapped jar

proud pebble
#

with the regular spigot jar you have to deal with obfucated names

lyric gyro
#

i will get used to it

#

i mean

dusky harness
#

The Father

#

I am back

#

do you use gradle

lyric gyro
#

maven

proud pebble
#

tbh the remapped jar makes life so much easier

dusky harness
#

Oh okay

#

then bye bye

lyric gyro
#

bye

lyric gyro
#

im not going to

proud pebble
proud pebble
#

look at this pom file, it has the md5 plugin and the extra text in the spigot dependancy thats required for remapped

#

all you have to do other then that is run buildtools with --remapped at the end

lyric gyro
#

I have two spigot servers, do I have to do anything to them?

#

what is the primary difference between ofuscated and remapped

proud pebble
#

it still works in 1.19.2, you just have to change the 1.18.2 to 1.19.2

lyric gyro
#

im using 1.19

proud pebble
proud pebble
lyric gyro
#

all I have to do is run buildtools with --remapped at the end

#

and thats it?

proud pebble
#

you have to reobfuscate for it to be useable

#

which is what the md5 plugin does.

#

to use the remapped jar just make the changes thats shown in the pom.xml i linked

lyric gyro
#

cant i just paste whats in that file in my pom.xml file and make the few needed changes for my version

#

and run buildtools again

#

?

proud pebble
#

you dont want to copy and paste my xml

lyric gyro
#

hm

proud pebble
#

copy and paste some, not all

#

22 to 54

lyric gyro
#

can you send here what lines I need to change while I rerun buildtools?

proud pebble
#

101 to 107

lyric gyro
#

or

#

do I have to change the pom file first

proud pebble
#

im telling you what to copy from my pom.xml tonyour pom.xml

lyric gyro
#

what do I have to do first

#

or it doesnt matter the order

wintry grove
#

Imagine using maven

lyric gyro
#

couldnt be me

proud pebble
#

copy 22-54 then copy 101-107

lyric gyro
#

there is no 22 in my pom file

#

or 101

#

oh no

#

lMAO

proud pebble
#

22-54 and 101-107, line numbers

lyric gyro
#

Those are the lines

#

LMAO

#

im dumb

proud pebble
#

then replace the 1.18.2 with 1.19

lyric gyro
#

so I just put lines 22-54 in the same place?

proud pebble
#

to your run.bat add --remapped to the end

lyric gyro
#

ok

#

so

#

I'll do that

proud pebble
#

then with 101 to 107 you replace your old with the new

lyric gyro
#

Plugin 'net.md-5:specialsource-maven-plugin:1.2.2' not found

#

3 errors

#

all of them are this

proud pebble
#

post the pom.xml

#

your

#

to helpchat paste

#

im on mobile, i cant see that

lyric gyro
proud pebble
#

you didnt change the 1.18.2 to 1.19

#

33 35 48 49

#

lines

lyric gyro
#

i did just that now

#

the errors are still there

proud pebble
#

weird

lyric gyro
#

Plugin 'net.md-5:specialsource-maven-plugin:1.2.2' not found

proud pebble
#

did you create the remapped jar with buildtools?

lyric gyro
#

i still havent done that

proud pebble
#

that will be why

lyric gyro
#

ok

lyric gyro
#

replaced lines 101 to 107

#

and changed the version

#

so now i'll run buildtools again

lyric gyro
#

explain to me how do I start buildtools again

#

I keep forgetting

#

I think I need to open a git bash

#

i cant remember that well

proud pebble
#

you didnt create a bat file?

lyric gyro
#

I think I just used git to run buildtools

#

since the bat file method wasnt working for me

proud pebble
#

theres a spigotmc page on running buildtools

lyric gyro
#

ik ik

proud pebble
#

i think you just need the latest version of java running to use the bat file

grand zodiac
#
    @Override
    public void onEnable() {
        getCommand("heal").setExecutor(new Heal());
        getCommand("feed").setExecutor(new Feed());
        getCommand("day").setExecutor(new Day());
        getCommand("time").setExecutor(new Time());
        getCommand("day").setExecutor(new Day());
        getCommand("noon").setExecutor(new Noon());
        getCommand("sunset").setExecutor(new Sunset());
        getCommand("night").setExecutor(new Night());
        getCommand("midnight").setExecutor(new Midnight());
        getCommand("sunrise").setExecutor(new Sunrise());
        getCommand("weather").setExecutor(new Weather());
        getCommand("sun").setExecutor(new Sun());
        getCommand("rain").setExecutor(new Rain());
        getCommand("gamemode").setExecutor(new Gamemode());
        getCommand("gmc").setExecutor(new Gmc());
        getCommand("gms").setExecutor(new Gms());
        getCommand("gmsp").setExecutor(new Gmsp());
        getCommand("gma").setExecutor(new Gma());
        getCommand("kill").setExecutor(new Kill());

        getServer().getPluginManager().registerEvents(new JoinLeaveListener(), this);
    }```

Anyone got suggestions on how I could compact this code and make it less messy?
winged pebble
#

Doesn't really look that messy to me tbh

lyric gyro
#

I just gotta create a bat file

#

with java -jar BuildTools.jar --rev 1.19 -- (i forgot what to put here)

#

and run it

proud pebble
#

remapped

lyric gyro
#

yeah

#

thats all?

proud pebble
#

yep

lyric gyro
#

k

proud pebble
#

then you just update NBTTagCompound to CompoundTag and you should be good

lyric gyro
#

wow

#

it instantly closed

#

amazing

proud pebble
#

pause on the line below it

lyric gyro
#

troubleshooting time

proud pebble
#

write pause

#

itll stop it from closing instantly

lyric gyro
#

are youf ucking kidding me

proud pebble
#

no?

lyric gyro
#

its because the run file is using java 8

#

instead of the java 17 i have installed

#

specifically for newer versions of minecraft

#

dont worry ik what i need to do

proud pebble
#

yep

#

makesnsense

grand zodiac
#

Maybe not messy but just

#

Cluttered

#

So I'd like to compact it a little

lyric gyro
#

uh

winged pebble
#

Having 100 commands in a single plugin seems unlikely tbh

lyric gyro
proud pebble
#

oops

#

wrong person

lyric gyro
#

e
c

if you are wondering

#

oh yeah

#

forgot the .exe

#

still

#

it isnt working

#

wait

proud pebble
#

hepto, id move all command registering to a seperate method like registerCommands()

lyric gyro
#

im trying to run

#

buildtools

#

in a folder where i already ran buildtools

#

for the exact same version

#

thats why it isnt working

#

lmao

proud pebble
#

doesnt matter afaik

lyric gyro
#

yeah

#

thats not the reason

proud pebble
#

whats the error when it attempts to build?

lyric gyro
#

could not find or load main class

#

java.lang.classNotFoundException

proud pebble
#

java.exe in the "" bit

#

remove the second java

#

otherwise its just like saying java java

lyric gyro
#

yeah

#

that was the problem

#

i did this a few days ago

#

to run spigot on this version

#

to develop this plugin

#

now its building

lyric gyro
#

wait @proud pebble

#

i have two versions of buildtools for 1.19

#

will this make a difference

#

or cause an error

proud pebble
#

no?

#

no

#

it wont

lyric gyro
#

it will only use the remapped version right

#

?

proud pebble
#

tho id just delete both and redownload buildtools cus atleast its updated

lyric gyro
proud pebble
#

huh

lyric gyro
lyric gyro
proud pebble
#

copy the error into google

#

cus that should be working

#

unless im blind

#

update buildtools ig?

#

cus that might be why

lyric gyro
#

@proud pebble

#

I opened intellij

#

something was telling me to do it

#

and the 3 errors disappeared

#

and

#

getTag and hasTag

#

now exist

#

oh wait

#

now its telling me that

#

NBTTagCompound doesnt exist

#

cannot resolve symbol

winged pebble
#

CompoundTag

#

Just look at the return type of getTag

lyric gyro
#

done

#

now im set up ig

#

next step

#

@winged pebble

#

I'm not sure what I've got to do

#

I think I forgot

#

just say the next steps

proud pebble
#

String hornSound = hornsCompound.getString("instrument");

lyric gyro
#

it's a string called hornsound

#

that gets instrument

#

which is like

#

the nbt tag?

#

I like to understand my code before I write it

proud pebble
#

there are 8 types of goat horn sound right

#

this gets what is on the item

lyric gyro
#

well what I wanted to do

#

is add a switch statement

#

that triggers a specific condition

#

when a specific horn is sounded

#

but for this

#

I need to know what the nbt tag looks like

#

right?

proud pebble
#

switch(hornSound)

#

scroll down to item data

#

itll show you every case

#

if you wanna know what the nbt looks like then use a nbt tooltip mod

lyric gyro
#
                case("ponder_goat_horn")```
#

like this?

proud pebble
#

thats not how switch statements work

#

close

lyric gyro
#

how do they work then

#

im asking if the string is correct

proud pebble
#

case "ponder_goat_horn" -> {
yourcodehere
}

lyric gyro
#

of course I know how switch statements work smh

#

im just asking if the string name is correct

#

if I played the ponder horn

#

would it execute whats in there?

proud pebble
#

if you are unsure, printbthe result of goatSound to either yourself or console

#

its what id do

lyric gyro
proud pebble
#

im sure thats right

#

but to confirm it, do what i said

lyric gyro
#

wait

#

here's the whole thing

proud pebble
#

ok?

lyric gyro
proud pebble
#

first

lyric gyro
#

which one of these

#

ok

proud pebble
#

you dont need the brackets in case

lyric gyro
#

no shit

proud pebble
#

then why do it?

lyric gyro
#

anyways

#

it didn't work

#
                case("ponder_goat_horn"):
                    world.spawnEntity(p.getLocation(), EntityType.GOAT);
            }```
#

are you sure its really "ponder_goat_horn"

proud pebble
#

are you going to even try debug it?

wintry grove
#

thats not how switch's work

#

at leaast the case part

#

it doesnt use parenthesis iirc

lyric gyro
lyric gyro
proud pebble
lyric gyro
#

im skeptical about the "ponder_goat_horn" part

proud pebble
#

then print hornSound

lyric gyro
#

in chat or console

proud pebble
#

does it matter? you will figure it out either way

lyric gyro
#

yeah

#

ill do it on chat

proud pebble
#

its what i normally do

lyric gyro
#

when this shit work

#

ill be the happiest man alive

#

bold of me to assume it will work

lyric gyro
proud pebble
#

so no output?

#

code?

lyric gyro
#

i play the goat horn

#

and nothing else happens

viral moth
#

what is the output in your chat?

lyric gyro
#

it was supposed to be

#

"Tá certo" and output the horn name or something like that

#

and spawn a goat

viral moth
#

one of your if statements are preventing it

lyric gyro
lyric gyro
viral moth
#

idk

#

debug it

#

just send a message to the player after each if statement to figure out how far it can get

proud pebble
#

stick a sendmessage in every step of the if statements

#

also the 3rd one is uses

#

useless

lyric gyro
proud pebble
#

yes, the third one, you already checked if the item wasnt null or wasnt a goathorn and returned

viral moth
#

also, why are you doing if statements differently?

if (goatHorn == null || goatHorn.getType() != GOAT_HORN) return;
        if (p.hasCooldown(GOAT_HORN)) return;
        if (goatHorn.getType() == GOAT_HORN){```

your first 2 are fine, but since the last if statement doesnt have an else clause, why not just do the following

```if (goatHorn.getType() != GOAT_HORN) return;```

it wont affect how your code performs/what happens, but it makes it a lot easier to read without extra indentations
viral moth
#

no

lyric gyro
#

because it already returned

#

the whole code cant run

viral moth
#

the first if statement and the 3rd one check the same thing, the 3rd one is completely redundant, but it isnt causing problems

viral moth
#

oh

#

i found the issue

#

p.setCooldown(GOAT_HORN, 800);

#

if (p.hasCooldown(GOAT_HORN)) return;

#

you give them a cooldown and then check if they have a cooldown

lyric gyro
#

wait

viral moth
#

which they always will, since you are setting them on cooldown

lyric gyro
#

this method isnt for checking if the item has a cooldown before you use it?

#

like

#

bruh

proud pebble
#

you set the cooldown, check if the cooldown exists and return

lyric gyro
#

hold up

proud pebble
#

so you should set the cooldown after

lyric gyro
#

like

#

above the world object?

#

where would you place it

viral moth
#

at the end

#

very end would be best

proud pebble
#

like right at the end

viral moth
#

but

#

it just has to be after the check

proud pebble
#

otherwise you cancelled out all your code

viral moth
#

but still it should be at the end, because logically you go on cooldown after something has happened, wont affect how anything works but is a good practice

lyric gyro
#

after the switch statements then?

#

i just put it here

viral moth
#

put a break statement in your switch

lyric gyro
#

k

#

i hope it works

#

also

#

I have another issue

#

when I use the horn

#

it goes on a 20 second cooldown

#

like I intended

#

but

#

If I try to use it again during the cooldown

#

it just resets it

#

why

viral moth
#

send your code

lyric gyro
#

import net.minecraft.nbt.CompoundTag;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import static org.bukkit.Material.*;

public class Listeners implements Listener {


    @EventHandler
    public void usedGoatHorn (PlayerInteractEvent e){

        Player p = e.getPlayer();
        ItemStack goatHorn = e.getItem();

        if (goatHorn == null || goatHorn.getType() != GOAT_HORN) return;
        if (p.hasCooldown(GOAT_HORN)) return;
        if (goatHorn.getType() == GOAT_HORN){

            World world = p.getWorld();

            net.minecraft.world.item.ItemStack nmsHorn = CraftItemStack.asNMSCopy(goatHorn);
            CompoundTag hornsCompound = (nmsHorn.hasTag()) ? nmsHorn.getTag() : new CompoundTag();
            String hornSound = hornsCompound.getString("instrument");

            p.sendMessage(hornSound);
            switch(hornSound){
                case "ponder_goat_horn":
                    world.spawnEntity(p.getLocation(), EntityType.GOAT);
                    p.sendMessage("Tá certo.");
                    break;
            }



        }

        p.setCooldown(GOAT_HORN, 800);
        }


    }

viral moth
#

not sure tbh

lyric gyro
#

my guess

#

it was because the set cooldown wasn't in the right place

#

watching rick and morty while starting my server

dusky harness
lyric gyro
#

hope my 4 gigs of ram can handle it lmao

lyric gyro
#

what do i use to cancel the event

dusky harness
#

e.setCancelled(true) (also I'd recommend not naming variables one letter)

dusky harness
#

watching rick and morty while starting my server
?

#

Oh

#

oh I didn't see the message above it

lyric gyro
#

the setcooldown just wasnt in the right place

dusky harness
#

lol

#

if you're using IntelliJ press ctrl alt L

lyric gyro
lyric gyro
dusky harness
#

format the code

lyric gyro
#

the only thing is that it isn't spawning the goat and sending the chat message when i use the ponder horn

#

but I think I know why

#

ITS WORKING

#

FINALLY

lyric gyro
#

why strength doesnt show up on potion effect type?

#

i think its cause its increase damage

#

weird

lyric gyro
#

i kinda have a problem

#

I made it so that when you play a goat horn

#

it gives you a potion effect

#

like

#

if you play ponder it gives you absorption

#

but

#

when you play it

#

the effect just disappears a second after

#

wait

#

wait wait wait wait wait

#

are you telling me that

#

it's not based on seconds

#

but ticks

#

p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 15, 1));

#

like this

#

that 15

#

is supposed to be 15 seconds

#

not ticks

#

ohhh

#

hold up gonna count tick by tick by hand

shell moon
#

Cancelling the damage event still makes the "hit no damage" sound to the client in new versions

#

someone knows if that exists in legacy versions too?

lyric gyro
#

The effect is activating even when you click with the left hand

#

you dont need to click with the right hand

shell moon
#

what? whats your issue?

#

effect happening with both hands, both clicks, or what?

lyric gyro
#

Basically

#

If you play a goat horn (right click that is)

#

It will give you a potion effect

#

but if you click with the left hand

#

You won't play the horn

#

but it will still give you the effect

#

because both things are player interact event I believe

#

But I don't know how to solve this

shell moon
#

"if you click with left hand"?

lyric gyro
#

sorry

#

I meant

#

If you click with the left mouse button

shell moon
#

why not checking which action it is then?

lyric gyro
#

can I do that?

shell moon
#

yes you can

#

read the methods available in the event

#

and you'll see the options

#

(and what others things you can do)

lyric gyro
#

is it getAction?

shell moon
#

yes

lyric gyro
#

let me see

#

Idk how to write this line of code

#

how would it look like

#

oh

#

hold up

#

@shell moon

#

nvm i still need help

#

idk how to type this out

shell moon
#

How?

#

exactly what you said

#

getAction

#

compare the action with what you want (or what you dont want)

#

if doesnt matter, return;

#

otherwise continue with your code

lyric gyro
#

ik ik

shell moon
lyric gyro
#

do I have to import anything?

#

like create an object named action

shell moon
#

indeed you have to

lyric gyro
#

yeah

shell moon
#

if what getAction returns something

lyric gyro
#

cause when I do, it asks me to import block action

shell moon
#

you need to check that

#

lets say Block#getType returns Material

#

then when you compare you use block.getType() == Material.STONE

#

you need to do something similar with getAction

#

check what it returns, and compare to the available options there

#

its enum

lyric gyro
#

yo

#

why isnt the ide allowing me to use || in my if statement

shell moon
#

¯_(ツ)_/¯

lyric gyro
#
        if (p.hasCooldown(GOAT_HORN)) return;
        if (goatHorn.getType() == GOAT_HORN){

            World world = p.getWorld();
            Action action = e.getAction();
            if (action == Action.LEFT_CLICK_AIR || Action.LEFT_CLICK_BLOCK) return;```
#

ignore that first part