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);
}
}
}
}
#development
1 messages · Page 12 of 1
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);
}
this simplifies things a little bit
what is the item stack thing for
The item you clicked
Uhh it's not needed I think
is it possible to return a net.kyori.Component on placeholder request?
You can do either or. But you still have to check if its null
no, it's only Strings
I'll pretend I didn't see that @dusky harness 😉
I mean it was true, but I realized that was a while ago so I just deleted it
as it wasn't relevant
idk I don't feel like scrolling up and checking
if the component can be represented as a String, sure, you have to serialize it with LegacyComponentSerializer
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
x y problem?
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
why not just create one runnable
and loop over the mobs / entities
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
It's code which affects mobs AI, would feel weird to have each mob AI change in some MobManager class
state machine?
again the runnable itself is not a big deal
it depends on what you do inside it
okay that's kinda what I wanted to hear
make sure to cancel the tasks as they die though
Yeah of course
I'd literally just be comparing a few doubles together, and then setting a field from time to time
with goat horns
seriously
the first goat horn
"ponder" isnt considered a goat horn?
nvm, the server was just bitching with m
me
how do I pull a nbt tag from an item?
using nms
of course
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```
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
unless you want to pay for a conversion api just google like "convert png to jpg java"
Ffmpeg can do all of those video and audio conversions yeah
bump
just cant figure out the method or how to do it
do I have to create a new item to get its nbt tag?
like
I want to make goat horns do different things
but I don't want to create a new item for them
You have to have an instance of an item to set its nbt tags, yes
But not to read from them
i dont want to set nbt tags
just read them
like
if nbt tag = 5 (idk)
do something
No, you don't need to create a separate item to read from it, you just use the item you already have
that's what I wanted
so
how do i do it
^
Idk if this article helps
the whole thing
Ctrl + f is your friend
yeah i tried that
What did you search
read
Do "get"
do I have to worry about this nbttag compound stuff
what is it about
goddamn so much text
its making me confused
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
hmm let me see
what is nbt compound though
and nms copy
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
Will I use this for what I am trying to do?
If a specific goat horn is played
Add potion effect absorption
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 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
Basically iirc, getTag() can return null
So they are just giving it an instance if it is null
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
net.minecraft.server.v1_12_R1.ItemStack nmsApple = CraftItemStack.asNMSCopy(apple);
where do I put this
this net.minecraft.server thing
That's just the package of nms you're using
It's the fully qualified name of the class you're accessing
I don't have to write this anywhere in my code then?
You'll most likely have to adapt it for your version
yes
As you can't just say ItemStack because you also have the bukkit ItemStack class so it needs to differentiate them somehow
what do I got to do then
Use the fully qualified name of the class
goddamn why am I so slow today
where do i put this though @winged pebble
thats what I want to know
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
What do you mean where do you put it?
You put it wherever you're checking to see if the item in question is that item
ok
like this?
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
CraftItemStack is just the class name
And you're accessing a static method from it
is this correct?
its asking me to add a dependency for it
1.17+ doesn't include the version in the package name for nms
so what do I do
what
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
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
what parameter do i use then
It tells you in the error
itemstack
Im trying to use a material
when it needs a itemstack?
Correct
really whats the difference between these two
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
You give it an ItemStack
And how are you checking the material type?
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
Oh, legit didn't know that getMaterial() was a method on that event
I've always just gotten it from the item
Get the item from the event instead
Bukkit.getScheduler().getPendingTasks() will return all the pending tasks from my plugin or from the whole server?
Returns a list of all pending tasks. The ordering of the tasks is not related to their order of execution.
Seems to suggest all of them
oh ty
I mean, you can continue to get the Material from the event or from the ItemStack, that's your choice
I'm just saying that you can get the ItemStack from the event and pass that in asNMSCopy()
i think ill just create a new itemstack
You do realize the issue with that, right?
what
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
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
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
no
semi yes, if you implement it yourself
but you need to hook up to the servers individually and pull data to bungee
but for this, a setup with both bungee + spigot plugins
is probably the best idea
spigot feeds the data to papi and bungee handles logic
im back
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
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
yes
yeah i understood this part
im asking about the parameter though
It doesn't seem like you do though
now I do
ik you gotta put an itemstack
But I don't have an itemstack for goat horn
^
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?
the only thing related to an itemstack here is the nmshorn
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
ok
I think I got it
but the ide isn't allowing me to use getitem
like
p.getItem();
What is p?
player object
And what class has getItem() as a method?
its player interact event
so in this case
hmmm
let me see
@winged pebble
It's playerinteract event
no wait
it's uhh itemstack?
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
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
yeah
do i have to erase the material object?
material material = e.getmaterial
or nah
^
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()
I think there is actually
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
Well hasCooldown() only accepts a Material
see
that's why we need both the material and an itemstack
will it work if i just add getType on the end?
I never said you didn't need Material
That works
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
So do the same thing that you did for hasCooldown
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
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;
// ...
if (item.getType() != GOAT_HORN) return;
i am sure this part is not needed
well
for your code
it might be
It just verifies that the item you're interacting with is in fact a goat horn
if (p.hasCooldown(goatHorn.getType())){
return;```
isnt this good enough
?
i mean
its a mess of parenthesis
reminds me of middle school
Couple reasons I changed things around:
- you're calling the ItemStack variable
goatHornbut you haven't yet verified that it's type is in fact GOAT_HORN - inverting the check and returning reduces indentation levels and improve readability
tbh if i just keep going this way ill end up making a mess of nested if statements
if i do your way
I can make an if statement with a bunch of switch statements inside
which look nicer
No, my way eliminates the nesting
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).
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?
the first one of course
less curly braces
means more readability
World world = p.getWorld();
world.spawnEntity(p.getLocation(), EntityType.GOAT);```
just gonna
put this here
Also, you should verify that the item isn't null
if (item == null || item.getType() != GOAT_HORN) return;
Forgot about that detail
@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
So then after those checks, you can be sure that it is a goat horn
holdup
instead of p.hascooldown(goat_horn)
wouldnt it be better if it was the object goat horn
not the material?
No, because hasCooldown() only accepts a Material
will it work the same though?
It only accepts a Material
I know
Im asking if your way
will it work the same
if i use material instead of the itemstack goathorn
so passing item.getType() on a goat horn or passing in Material.GOAT_HORN is the exact same thing
It only accepts Material, so you literally can't pass in the ItemStack
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
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
your free trial as teacher ends here then?
I can't do everything for you
I know
A big part of learning something new is fumbling with it yourself
What I would do is print out the nbt data of the item to see how each goat horn is differentiated
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
At that point in the code, has the item been verified as a goat horn?
not yet
Then no, not a good place for it
make the variable names event, player, etc
instead of e and p
also I would put the ... nmsHorn = ... on one line
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
this
also
nms 🤢
but you already have it set up so I won't make a big deal out of it
you won't be saying this when you see what i'll do with these goat horns
If only there was a GoatHornMeta 😛
mhm
please god
this would make my life so much easier
you don't need nms for it
I do
nope
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
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
since
it's a goat horn
and its the best horn
so i figured it would have the best effect
horns are usually used in army to call a push or something like that
so you would be callin your soldiers
if people actually download this ill make it into a mod
idk how but ig ill try
forge
o
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
💀
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
NBTTagCompound hornsCompound = (nmsHorn.hasTag()) ? nmsHorn.getTag() : new NBTTagCompound();
Has tag and get tag
doesnt exist
Anyways I've gtg now, cya
bye
bye
That's because in 1.17+, they are just letters as names
Did they change anything else after 1.17 that I need to know?
what are these methods called now
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
1.14.4*
ok me go bye
cya
yes spigot
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
where exactly
Follow the package
they are named if you use the remapped jar instead of the regular one
they are named as such
theres a method for getting the tag or a new compoundtag if it doesnt exist
there are like
5 or 6
different instances of compoundtag
Which class does getTag and hasTag come from
why you askin me dude
For your own good
NBTTagCompound hornsCompound = (nmsHorn.hasTag()) ? nmsHorn.getTag() : new NBTTagCompound();```
So hasTag and getTag belong to which class?
then why is the ide giving me an error
it says it cant resolve getTag or hasTag
in itemstack
Because they are obfuscated for you
Because your using the obfuscated jar, not the remapped version
So use the link I sent to see the connection between the obfuscated names and the normal names
are you fucking KIDDING ME
Or you can learn how to use the remapped jar
with the regular spigot jar you have to deal with obfucated names
maven
tbh the remapped jar makes life so much easier
bye
do I have to reinstall spigot
im not going to
that's what I am trying to do
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
I have two spigot servers, do I have to do anything to them?
what is the primary difference between ofuscated and remapped
it still works in 1.19.2, you just have to change the 1.18.2 to 1.19.2
im using 1.19
the difference is in the ide only really, the md5 plugin is used to reobfuscate the code to be useable on servers
works for 1.19 too
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
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
?
you dont want to copy and paste my xml
hm
can you send here what lines I need to change while I rerun buildtools?
101 to 107
im telling you what to copy from my pom.xml tonyour pom.xml
Imagine using maven
couldnt be me
copy 22-54 then copy 101-107
what this is to be exact
there is no 22 in my pom file
or 101
oh no
lMAO
22-54 and 101-107, line numbers
then replace the 1.18.2 with 1.19
so I just put lines 22-54 in the same place?
to your run.bat add --remapped to the end
22-54 you dont replace, you just paste
then with 101 to 107 you replace your old with the new
Plugin 'net.md-5:specialsource-maven-plugin:1.2.2' not found
3 errors
all of them are this
weird
Plugin 'net.md-5:specialsource-maven-plugin:1.2.2' not found
did you create the remapped jar with buildtools?
i still havent done that
that will be why
ok
I'm done fixing the pom file
replaced lines 101 to 107
and changed the version
so now i'll run buildtools again
can you
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
you didnt create a bat file?
I think I just used git to run buildtools
since the bat file method wasnt working for me
theres a spigotmc page on running buildtools
ik ik
i think you just need the latest version of java running to use the bat file
@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?
Doesn't really look that messy to me tbh
so
I just gotta create a bat file
with java -jar BuildTools.jar --rev 1.19 -- (i forgot what to put here)
and run it
remapped
yep
k
then you just update NBTTagCompound to CompoundTag and you should be good
pause on the line below it
troubleshooting time
are youf ucking kidding me
no?
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
Well if I add 100 commands which knowing the nature of the plugin I'm making I probably will before publishing it on SpigotMC, it'll look quite messy
Maybe not messy but just
Cluttered
So I'd like to compact it a little
uh
Having 100 commands in a single plugin seems unlikely tbh
java.exe
oops
wrong person
hepto, id move all command registering to a seperate method like registerCommands()
im trying to run
buildtools
in a folder where i already ran buildtools
for the exact same version
thats why it isnt working
lmao
doesnt matter afaik
whats the error when it attempts to build?
java.exe in the "" bit
remove the second java
otherwise its just like saying java java
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
true, ty
wait @proud pebble
i have two versions of buildtools for 1.19
will this make a difference
or cause an error
tho id just delete both and redownload buildtools cus atleast its updated
yes since you told it to just use the remapped
huh
whats wrong
copy the error into google
cus that should be working
unless im blind
update buildtools ig?
cus that might be why
i'll check
@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
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
String hornSound = hornsCompound.getString("instrument");
so what this is
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
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?
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
case "ponder_goat_horn" -> {
yourcodehere
}
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?
if you are unsure, printbthe result of goatSound to either yourself or console
its what id do
if you are saying this then you are unsure
ok?
first
you dont need the brackets in case
no shit
then why do it?
probably did it by accident
anyways
it didn't work
case("ponder_goat_horn"):
world.spawnEntity(p.getLocation(), EntityType.GOAT);
}```
are you sure its really "ponder_goat_horn"
are you going to even try debug it?
thats not how switch's work
at leaast the case part
it doesnt use parenthesis iirc
what does debugging do
i dont think it makes a difference
you figure out what went wrong
tbh
im skeptical about the "ponder_goat_horn" part
then print hornSound
in chat or console
does it matter? you will figure it out either way
its what i normally do
when this shit work
ill be the happiest man alive
bold of me to assume it will work
yeah it doesnt work
what is the output in your chat?
it was supposed to be
"Tá certo" and output the horn name or something like that
and spawn a goat
one of your if statements are preventing it
if you played ponder, specifically
which one
idk
debug it
just send a message to the player after each if statement to figure out how far it can get
stick a sendmessage in every step of the if statements
also the 3rd one is uses
useless
the third if statement?
yes, the third one, you already checked if the item wasnt null or wasnt a goathorn and returned
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
thats why it isnt working
no
if the third if statement cant be executed
because it already returned
the whole code cant run
the first if statement and the 3rd one check the same thing, the 3rd one is completely redundant, but it isnt causing problems
well if the condition is false, then that's what should happen
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
wait
which they always will, since you are setting them on cooldown
this method isnt for checking if the item has a cooldown before you use it?
like
bruh
you set the cooldown, check if the cooldown exists and return
hold up
so you should set the cooldown after
like right at the end
otherwise you cancelled out all your code
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
put a break statement in your switch
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
send your code
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);
}
}
not sure tbh
my guess
it was because the set cooldown wasn't in the right place
watching rick and morty while starting my server
try making it so that if they have the cooldown, instead of just returning, cancel the event and return
hope my 4 gigs of ram can handle it lmao
ill try to do that
what do i use to cancel the event
e.setCancelled(true) (also I'd recommend not naming variables one letter)
actually
I was right
watching rick and morty while starting my server
?
Oh
oh I didn't see the message above it
the setcooldown just wasnt in the right place
sometimes I watch it on hbo max
what does it do
format the code
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
why strength doesnt show up on potion effect type?
i think its cause its increase damage
weird
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
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?
I still have a problem though
The effect is activating even when you click with the left hand
you dont need to click with the right hand
Well
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
"if you click with left hand"?
oh
sorry
I meant
If you click with the left mouse button
why not checking which action it is then?
can I do that?
yes you can
read the methods available in the event
and you'll see the options
(and what others things you can do)
is it getAction?
yes
hmmm
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
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
ik ik

indeed you have to
yeah
if what getAction returns something
cause when I do, it asks me to import block action
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
¯_(ツ)_/¯
send code