#help-development
1 messages Β· Page 2054 of 1
Add it as a dependency
What's the event for opening an enderchest?
InventoryOpenEvent
didn't work, probably doing it wrong
the thing is i'm already using a jar
it just doesn't have that class
You're definitely doing it wrong then
I cant seem to use addPotionEffect on an Entity, is there a alternative to it that works for Entities?
What version are you on?
Spigot API 1.18.1-R0.1-SNAPSHOT
Nvm I thought you could as well
What are you trying to do
I think you need to cast it to a living entity
using the EntityDamageByEntityEvent to apply a potion effect to the victim if the attacker is on a list
these are some nice cliffs (if you ignore the giant block of water)
dont even ask what i did with the water...
You need LivingEntity then
Check and cast to that
Is that custom world gen or just vanilla doing weird stuff
something else :troll:
bruh why my ttroll emoji
basically i made it so every flowing water turns into a source
ram be like:
btw State.getData() isnt deprecated but returns materialdata
im guessing they forgor π
anyways how do you check if grass is snowyt
isSnowy
BlockData I think
whats with all the Levelable and Snowable stuff bruh coudlnt they just like do it in a class called Grass or smth
i installed a new craftbukkit jar and it's literally the same
like GrassBlock could have functions that Snowable currently has
and Water could have the Levelable stuff
I still cannot extend from EntityZombie or any other of its type
If you built it properly with build tools all you have to do is add it as a dependency in your pom.xml if you are using maven
or gradle.something if you are using gradle
shit
i thought that was the case but i couldnt find any pom.xml stuff for craftbukkit
thank you though
yeah how am i supposed to add it to pom?
do I just have to paste this into it? https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/pom.xml
i don't understand
you can add it to a folder in your project and use
<dependency>
<artifactId>..</artifactId>
<groupId>..</groupId>
<scope>system</scope>
<systemPath>${basedir}/lib/dependency.jar</systemPath>
</dependency>
tysm
no no no
never do that
o
this is deprecated and will be removed from maven in the future
didn't know that, although when I used to use it I was very lazy lol
yes I also did it like that 1-2 years ago
but maven throws a ton of warnings if you do it like that
and every of those warnings say "yo this works now but pls don't do it, future versions of maven won't allow this anymore"
so better just install the .jar to the repo π
it's just one command
oh wait
you wanna use NMS classes
this is something totally different
what MC verison are you using @desert musk
?
1.18.2
okay then check out the first link of my last message pls
alright
it's very important to use "--remapped" when running BuildTools
yes pls
ok
[WARNING] The requested profile "remapped" could not be activated because it does not exist.
?
is this a message from buildtools?
yeah
ok
?bt
alright it seems to be doing its thing
names of what?
reasons for the name changes are explained here (headline "NMS") -> https://www.spigotmc.org/threads/spigot-bungeecord-1-17-1-17-1.510208/#post-4184317
Can I make a blog post on your site about how to enable dark theme and then you follow it? π
there's a reason why I am using the light theme in intellij π
which is "the sun"
try to read something in dark mode when the sun is shining onto your screen 6 hours a day π
the screen is the sun
when in light mode
and everyone who gets blinded by my screenshots should really see a doctor
but it's better to be mocked for using light theme than people yelling at me for being gay or drunk all the time or sth lol
but yeah I have a legitimate reason for using light mode, just check this:
good luck reading something there in dark mode π
Why is your monitor so dark 
it's not dark, the surrounding is just very bright
Atleast you have Discord dark theme
sometimes
don't give him ideas
my discord is bright again since 2 days lol
also the 1.2.2 in the version field is throwing an error
1.2.2?
did you click the "maven reload" button?
uhhh
no i kinda just copypasted everything from the website into my thing
oh shit ok that worked nvm
awesome
np
How would I go about saving data in this format using FileConfiguration?
<uuid>:
<another uuid>,
<yet another uuid>,
<and another uuid>
<uuid>:
<another uuid>
that won't work
you can't have two keys both being called "uuid"
Would something like this work?
players:
<a player uuid>:
<another uuid>,
<yet another uuid>,
<and another uuid>
<another player uuid>:
<another uuid>
yes, sure
right that's what i interpreted it as
Yeah
YamlConfiguration yaml = new YamlCOnfiguration();
yaml.set("players." + uuid1,yourListOfUUIDsForFirstPlayer);
yaml.set("players." + uuid2,yourListOfUUIDsForSecondPlayer);
then save it to a file
i wanna learn how to make minecraft plugins, what would be my best resource for learning how?
important: all the UUIDs must be strings for this to work
and then reading it, how would i get the list of uuids back into a list?
for example this (one second, gotta type it quickly)
imagine you have this:
players:
firstplayer:
- aa00000151251258612581528615
- aaaa725115723651976135976153
then it's actually a List<String>. but you can just use a stream->map to turn it into a list of UUID objects:
List<UUID> uuids = getConfig().getStringList("players.firstplayer").stream().map(UUID::fromString).collect(Collectors.toList());
Great, thanks
if you never used streams before, look for a tutorial about how they work
streams are awesome
oh no the chocolate guy is typing D:
did I say sth wrong
lol
I've heard praise from TheSourceCode on YouTube if that's your cup of tea (though I've never watched them myself so I can't verify this). Else we have some wiki pages on the forums on how to get started
https://www.spigotmc.org/wiki/spigot-plugin-development/
Nah you're fine lol
baeldung is such a weird site
50% of their articles are good and the other 50% are garbage
I believe they're community-contributed
you sure?
some of their articles exactly explain stuff while others are just "you can do this or that" but they don't explain why or how
Can somebody help me? I want to do that during the storm there is a bossbar that tells you the time that the storm has left
If it's not too much trouble to pass the code xD...
e.g. their "java 8 streams" article is worthless unless you already know what streams are and if you know that, you dont need the article anyway
- listen to WorldWeatherChangeEvent or however it is called
- Get the world's clear weather duration
declaration: package: org.bukkit, interface: World
Yeah. baeldung's got some good resources most of the time
They cover a pretty hefty variety of stuff
then create a bossbar and update it every tick/second/whatever until the wheather is clear again
yes, true, but their streams article is shit
this doesn't help anyone IMHO unless they know streams anyway
this explains it way better imho
for example, I didn't know for 2 years that streams are actually "lazy", e.g. if you do "map" and findFirst, it only maps one thing if the others aren't needed
Doesn't seem terrible. The first part of that is mostly bleh, but the latter half does touch on a good pipeline for streams and how to use them with decent performance
I explained it badly but you know what I mean π
Can I get help about GriefPreventionAPI here?π
how to get claim details of a player?
like claimed block, remain claim block, total claim, trusted player, claim date etc
They only have a mvn dependency on there API wiki and discord channel look like dead
moving my entire workspace over to my laptop now, is it true that you have to use OpenJDK17 and not OpenJDK18?
quick q. does this sound right?
moveCard.teleport(targetPointer.getLocation());
LTS?
Long term support
oh i see
Should it be looking like this? (please ping me when responding, am going to sleep shortly :P)
players:
f7c77d99-9f15-4a66-a87d-c4a51ef30d19:
- !!java.util.UUID 'af74a02d-19cb-445b-b07f-6866a861f783'
Not quite. Call .toString() on the UUID when you save it
Right now you're doing set(String, UUID) but that's going to serialize it as a UUID type. Though you can just save it in string form
(please ping me when responding, am going to sleep shortly :P)
@silent timber
Oh yeah, they even told me to do that
Thank you lol
After that you're good to go
command /resetmines: permission: mine.reset permission message: You need VIP to use this trigger: set {_waited} difference between {resetmines.%player%.lastused} and now if {_waited} is less than 20 minutes: message "You have to wait %difference between 20 minutes and {waited}% before you can use this command again!" stop execute console command "/mrl reset diamond" execute console command "/mrl reset wood" execute console command "/mrl reset obsidian" execute console command "/mrl reset iron" execute console command "/mrl reset amethyst" execute console command "/mrl reset ancient_debris" execute console command "/mrl reset NETHERITE" set {resetmines.%player%.lastused} to now
uhh can someone tell me why this isn't working
i am trying to make a command that resets all mines with 20 minute cooldown but it has 2 errors
if you spawn two Particle.DustTransition at the same location they appear as one with their colors merged.
The more you know...
public void onPlayerHarvestBlock(PlayerHarvestBlockEvent event) {
Player player = event.getPlayer();
Block block = event.getHarvestedBlock();
if (block.getType().equals("diamond_ore")) {
player.sendMessage("mined diamondeeee");
}
}```
tthis doesnt do anything when a player harvests a block
bc youre equalling a enum with a string
if(block.getType() == Material.DIAMOND_ORE)
that checks it
can u help me out with the command
i can tell u where are the errors
cant send image
copy it from the logs
line 5 and line 6
line 5
'set {_waited} difference between {resetmines.%player%.lastused} and now' is not an entry (like 'name : value')
line 6
Unexpected entry 'if {_waited} is less than 20 minutes:'. Check whether it's spelled correctly or remove it.
here
what are alternatives to .teleport?
not a lot
i mean
you can give someone the exact velocity to yeeeett them over to the location you want them at
Lol
or spawn a pig with a pathfindergoal to push the player to the desired location
*will not work between dimensions unless you yeet the player into a portal first
.teleport is not working for me, and nor is any workaround do to different issues
Probably best to figure out why .teleport isn't working for you
It is rather unlikely that the logic itself is broken
maybe your teleport is in an if statement that isnt actually gonna ever be true
nope, I teated for that
is it a cmd, eventhander or smth else?
Any exceptions? Share code if possible
because if it's an event, did you register it
?didyouregistertheeventhandler
@undone axle command missing pls fix
{
ArmorStand moveCard = (ArmorStand) mainscript.GetTag(targets,mainscript.TagCard'Move);
Location moveTo = new Location(targetPointer.getWorld(), targetPointer.getLocation().getX(), targetPointer.getLocation().getY(), targetPointer.getLocation().getZ() );
moveCard.teleport(moveTo);
mainscript.ConMessage("Moving " + moveCard.getCustomName());
}```
this is a small example of my slow decent into maddness. notice the location moveto = new location {target pointer loctation }
its been 3 hours
Is there a player riding the armor stand
Also why are your methods named in PascalCase
Rip
Well that's why it can't teleport
You can't teleport entities with passengers I believe
You gotta dismount, then teleport the entity, then teleport its passenger back to it and re-mount it
It's very annoying
But it's not ".teleport not working" and you should have been more specific
T_T its a stack of armor stands that is needed for thiiingggs!!!
Then either kill them and respawn them where they are needed
Or do it the hard way with dismounting and remounting
hey now
you ok?
Huh
I dunno if you're tyring to be passive aggressive or what
I'm just saying that you should give as many details as possible when asking for help because if I hadn't asked about that then you wouldn't have specified it, and we wouldn't have been able to help you
Hi, I try to create a new Command with the CommandExecutor in Spigot for 1.18.1. I just created my first command and now I want to create a command with extra args. How can I cast a String Argument to a Material.X?
Material.matchMaterial might also work out well for you
Careful though, because it throws an exception if a value is not matched rather than returning null
Yeah honestly that's probably a better idea
I always forget that method exists
and Material.getMaterial(String)?
?jd
I'm not sure how getMaterial differs from matchMaterial
I'm guessing matchMaterial is more what you want though
ok thanks π
It seems like getMaterial might need to include minecraft: in the names
Not 100% clear though
yea I read the docs, getMaterial needs the precise name and matchMaterial will format b4 checking:
This is a match lookup; names will be stripped of the "minecraft:" namespace, converted to uppercase, then stripped of special characters in an attempt to format it like the enum.
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),"tp @e[tag=" + mainscript.TagCardMove + "] " + targetPointer.getLocation().getX() + " " + targetPointer.getLocation().getY() + " " + targetPointer.getLocation().getZ());
that worked
Im New Java Developer , How do I get the coordinates of a dead player?
well is this in a listener?
yes
if you have the player reference you can just call getLocation
based on the fact that playerrespawnevent doesnβt implement cancelable, iβm not really sure - try getting the players location when the event is called and see where it is
otherwise you might need to have a death listener and save the locations
ok
are there no ways of cancelling an armor equip on right click, tried interact event
How do I find out the main class in which the Java Plugin extends?
Try PlayerDeathEvent then do event.getPlayer().getLocation()
thatll get their death location rather than their location where they spawn
MainClass.getProvidingPlugin(MainClass.class);
What does this mean
If I name the class not MainClass, it will not work
Are you trying to get the plugin instance?
yes
if so do <MainPluginClass>.getPlugin(<MainPluginClass>.class)
replace <MainPluginClass> with the name of ur class
I wanted to make it work when changing the class name
??
Like u want it to autoupdate when u change ur class name?
why?
ok show code im so lost as to why youd ever do this
Okay
?paste
not only should it not be, it couldnt be
unless u feel like doin a whole lot of bytecode hackery
Why not just pass in OwnExperienceWorld in the constructor of the ChestGUI class? is that not possible in this case?
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
It won't be convenient
I guess u can just pass it into the constructor
ChestGUI gui = new ChestGUI(6, Component.text("Test-gui"));
gui.fillingEmptySlots(new ItemStack(Material.VINE));
gui.setItem(1,1, new GUIButton(new ItemStack(Material.EXPERIENCE_BOTTLE), event -> {
event.getWhoClicked().sendMessage("1");
}));
gui.setItem(2,2, new GUIButton(new ItemStack(Material.EXPERIENCE_BOTTLE), event -> {
event.getWhoClicked().sendMessage("2");
}));
gui.open(p);
if for whatever god forsaken reason you need it to be dynamic, pass the plugin instance into the ChestGUI class constructor as a Plugin parameter
It won't be convenient
but changing the name is????????
alternatively: Bukkit.getServer(), but people dont like that around here
that is the sole reason hes getting the plugin anyway
I still dont understand why u need the main class name to be dynamic
doesnt make sense in any context
I will use it not only in this project
then if ur using intellij make it into a live template if ur gonna reuse code
and make the name a parameter of the live template
but just name it Main?
why do u NEED it to be anything else
I honestly dont understand
it is not possible to have a java class name dynamic
without it being extremely counter-intuitive
Maybe the name of the class in which extends JavaPlugin?
Yeah you canβt change that
There is literally no reason for it to be dynamic
You havenβt explained an actual reason as to why you need this to be possible
This is something like a GUI library
But why do you need it to be dynamic
It makes zero logical sense to make it dynamic
Also in a library you wouldnβt have a plug-in instance class in a library, also wouldnβt make sense
I just need to make everything work when copying GUI classes to another project where the name of the main class is different
Ok so do what I said before, pass the plug-in instance into the ChestGUI class
Best way to do it
It will not be convenient all the time
How�
Plugin plugin = OwnExperienceWorld.getPlugin(OwnExperienceWorld.class);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
It works, but if I suddenly move this class to another project, it won't work
Yeah because u need to pass it as an parameter
Create a plugin parameter in ur default constructor and set the plugin variable to it
How can I, for example, get the name of the class in which JavaPlugin is extended
Bro, you really shouldnβt need to
Iβm telling you, pass the instance
There is zero reason why you would ever do that
You logically canβt without jumping through 70 different wacky programming hoops
I just thought it was possible to get the name of the class in which JavaPlugin is extended.
Bukkit.getServer().getPlugin(String name);
Not really, not without passing the instance
And if you pass the instance thereβs no reason to do it the way you suggested
Bro please, just pass the instance, itβs not more complicated
Okay, thanks
so what could be done actually is something like
in the constructor of ChestGUI, u add a param like Class<? extends JavaPlugin> pluginCls and then in the constructor method u do JavaPlugin ownerPl = JavaPlugin.getProvidingPlugin(pluginCls);
?jd
that should let u still use it as more of an API rather than part of a specific plugin i think @quaint mantle, whatdya think @low temple ?
Class<? extends JavaPlugin> pluginCls = null;
Plugin plugin = JavaPlugin.getProvidingPlugin(pluginCls);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
Right?
no u put Class<? extends JavaPlugin> pluginCls in the constructor params
I mean its the same thing as just passing it as JavaPlugin
not necessarily
Basically the same thing
to pass the actual object vs the class
oh wait yeah u could do just JavaPlugin then
true but wouldnt it just make sense to just to JavaPlugin
yeah bc then it avoids having to do a lookup every time u make a gui
unless you only need the class, even then you can get it from the object
ur getting the object from the class in the end so if u could provide the object then u bypass a whole step
he just needs the plugin instance, the class is irrelevant since its used to get the plugin instance
yeah
for convenience i think mine would win since u wouldnt need to worry about having the instance stored somewhere, could literally just do like new ChestGUI(other params, MainPluginClass.class), but for optimization (and probably sanity), ur idea is the way to go
I wanted to get an instance without entering anything
But either way you need to pass something in and store it
Not possible
I understood. Thanks for the answers
Np man
any way of making this work for offhand
nvm it works on both hands, just making bad checks
dumb I was checking mainhand only xD
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
I think this is not the right place to ask for that ig
I've been looking in the Spigot page, but I can't find where I can make a thread.
I am getting this error
java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.ItemStack.getType()" because "result" is null
at org.bukkit.inventory.ShapedRecipe.<init>(ShapedRecipe.java:46) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at com.init.test.items.ItemManager.createWand(ItemManager.java:36) ~[Plugins.jar:?]
at com.init.test.items.ItemManager.init(ItemManager.java:19) ~[Plugins.jar:?]
at com.init.test.TestPlugin.onEnable(TestPlugin.java:16) ~[Plugins.jar:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:501) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugin(CraftServer.java:562) ~[paper-1.18.1.jar:git-Paper-216]
at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugins(CraftServer.java:476) ~[paper-1.18.1.jar:git-Paper-216]
at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:736) ~[paper-1.18.1.jar:git-Paper-216]
at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:503) ~[paper-1.18.1.jar:git-Paper-216]
at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:313) ~[paper-1.18.1.jar:git-Paper-216]
at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1211) ~[paper-1.18.1.jar:git-Paper-216]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.18.1.jar:git-Paper-216]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
createWand() [it was getting long so used pastebin] https://paste.pythondiscord.com/otisosibuk
why in the fuck does it use org.bukkit.inventory.ItemStack for the implementation and not org.bukkit.craftbukkit.v_.inventory.ItemStack
thats so fucking stupid
why copy all data twice
the craftbukkit one just holds a handle to the nms stack
item = wand; why add this
I am using the spigot api
I saw it in a yt tutorial
remove it
ohk
when watching yt tutorials make sure you understand what the guy is doing
wand = item;?
or its a copy paste in the end
I understud what he was doing
but why can't u fix it yourself then by looking at your code?
it was working before and suddenly broke
might be some random person used ur pc and added that line ig
I am the only one to use my mac
Can I somehow add same hover hologram effect as itemframes with named item in them have on other blocks?
did removing it work?
wait lemme try
are you know Java?
aight awesome goodluck
Like this
This is not invisible armorstand right?
But I think frames are entity
it has hitboxes when placed
I am trying to make PLAYER_HEAD with hologram when placed, but without complicated logic of handling the armorstand holograms
Do not want bunch of "dead" unconnected holograms around map when something goes wrong
just place an armorstand when the skull head is placed
when head is broken, remove the armorstand too
yea, but then I need to handle like dozen of events of block destroy
wdym on launch
when plugin start
Use #setPersistent(true) and #setRemoveWhenFarAway(false)
for the armorstand?
and you can try saving the hashmap inside a file
onDisable
and restore it onEnable
yea... and that way I can also remove armorstands when head is no longer on that place
for some reason.
or use pdc and make ur life easier
pdc?
PersistentDataContainer
?pdc
Blocks can hold pdc
Not all blocks
I know. I hold NBT tags of that Head in there
So they can be recovered into item after drop
Holding it in pdc does not fix the problem when head block gets destroyed in some weird way, tho... Armorstand will persist
why does new GameProfile() not work
yeah not all blocks can do pdc mb, only some with tilestates
they can if you use the resource by @tender shard
You can try saving it in hashmap, just like I said before
?notworking
"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.
Yea... I will do that
says method does not exist
Are you on 1.18.2
1.18.1
Is there any universal event for block being destroyed? I believe that BlockBreakEvent is not called for every possible way of block deletion right?
There isn't
BlockBreakEvent is called when a player breaks a block
π₯²
Block break event works on heads
why would you need a global one
Yea but Pistons, explosion, enderman, etc π
just gotta do checks and as much as possible the right block that is broken
so use multiple events
they all have events
Sure π But do you know all of them?
I dont π
And do not want players to loose their NBT tags on heads π
when they do something weird π
BlockBreakEvent, PistonExtendEvent, PistonRetractEvent, EntityChangeBlockEvent
BlockExplodeEvent, BlockBurnEvent
EntityChangeBlock is called for enderman picking up blocks and sheep eating grass i believe
That should be all?
well There is BlockFromToEvent i believe
for water, lava flowing
also called for dragonegg teleportation
Hopefully thats all π
nope
π
there is also BlockFadeEvent
Called when a block fades, melts or disappears based on world conditions
what is the best way to start if I want to start writing my own plugins
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/block/BlockEvent.html view all block events on here at "direct known subclasses"
declaration: package: org.bukkit.event.block, class: BlockEvent
Do you know Java?
Jup
how to I assign function to my custom Item?
function?
events
youl need to elaborate
thanks... Nothing in plugin dev can be simple... π
playerinteractEvent?
nope, it would actually be a pretty cool idea to make an api that can block all of these with 1 event.
Take a look at thia then https://www.spigotmc.org/wiki/spigot-plugin-development/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
what kind of function u want
when the user right clicks, a tnt summons and explodes
interact event
ohk
you can spawn a primed tnt
yea... π
where can learn the spigot api?
package index
java doc
idk but a tag exist fot that
check the link above
try using the api version u have
Oh... I can use BlockDropItemEvent
That would cover everything π
Because I want the custom item to drop only if it actually drop from the action
So not e.g. when it burn in lava
I have 1.18 so thats no problem
Good :)
Breaking glass without silk touch.
Meh... it does work only for player breaks...
This might be relevant:
https://papermc.io/javadocs/paper/1.18/com/destroystokyo/paper/event/block/BlockDestroyEvent.html
declaration: package: com.destroystokyo.paper.event.block, class: BlockDestroyEvent
Yea... that seems promising
Though it is paper, so if you plan on the plugin ever being deployed without it you would have to do something else.
I mean... Who wouldn't use paper?
weird is that for some reason this event is not firing
How do I create a directory and example file with only the path of the dir?
Is it just
Yea... it is broken in 1.18.2
File#getParentFile()#mkdirs?
I am getting this error
java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.ItemStack.getItemMeta()" because "com.init.test.items.ItemManager.wand" is null
at com.init.test.events.testEvents.onPlayerRightClick(testEvents.java:22) ~[Plugins.jar:?]
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor5.execute(Unknown Source) ~[?:?]
at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:75) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:git-Paper-216]
on using
@EventHandler
public void onRightClick(PlayerInteractEvent event){
if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
if(event.getItem() != null){
if(event.getItem().getItemMeta().equals(ItemManager.wand.getItemMeta())){
Player player = event.getPlayer();
player.getWorld().strikeLightning(player.getLocation());
}
ItemManager.wand is null
but how can it be null, it is a ItemStack
it is. didn't initialized it?
I did
itemManager
public class ItemManager {
public static ItemStack wand;
public static void init() {
createWand();
}
private static void createWand() {
ItemStack item = new ItemStack(Material.STICK, 1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName("Β§6Β§ Wand Of Thunder");
List<String> lore = new ArrayList<>();
lore.add("Β§7Β§oRight click to use");
lore.add("Β§7Β§oSummon a lightning bolt");
meta.setLore(lore);
meta.addEnchant(Enchantment.LUCK, 1, true);
item.setItemMeta(meta);
//Recipe
ShapedRecipe sr = new ShapedRecipe(NamespacedKey.minecraft("wand"), item);
sr.shape(" G ",
" N ",
" T ");
sr.setIngredient('G',Material.ENCHANTED_GOLDEN_APPLE);
sr.setIngredient('N',Material.NETHERITE_BLOCK);
sr.setIngredient('T',Material.TRIDENT);
Bukkit.getServer().addRecipe(sr);
}
no you didnt
you created a new itemstack, but never initialized wand.
doesn't matter if you never assign it to wand
ItemStack item = new ItemStack(Material.STICK, 1);
would have to be
wand = new ItemStack....
or in the end wand = item or whatever
then why would the recipe work?
with that current code wand remains null
because you registered it. there is no error in your code
you just never initialize wand
wand = item returns a error
yes, in an other scope because this scope doesn't initialize the wand variable
this is static abuse btw
how?
you are using the static keyword not what its meant for. but just for easy accessibility
ok, I will remove it
ew
wht?
- no abstraction
- static abuse
- using raw item stack api of bukkit (just use a library or smth)
I am new to the API
ohk
yea 2hex is right. you might wanna make yourself to easily create itemstacks, this is how i make them for example
ItemCreator.of(CompMaterial.OAK_SIGN)
.name("&e&lInfo")
.lores(Arrays.asList(
"",
"&eCosmeticType: &7" + cosmetics.getCosmeticType().getFancyName(),
"&eCosmetic: &7" + cosmetics.getCosmetic().getCosmeticName(),
"&eCost: &7" + cost,
"",
"&eYour balance: &7" + cache.getRankedCoins(),
"&eNew balance: &7" + (cache.getRankedCoins() - cost),
""
))
.build()
.makeButton();
which lib to use?
also that should be called ItemFactory, implementing Factory<ItemStack>
What is the event when block gets destroyed by water flow and piston? BlockFromToEvent is not the right event, because it gets called on water flow, notp on block break.
ur talking about stuff like torches then?
Maybe
idk π they do on 1.18.2
rlly?
they dont afaik
wat
but im still pretty sure u can use blockfromto event. just check if the "to" location is something you dont want to break
yea but thats not actually break event
that is just that water moved TO the location of head
there is nothing like ItemCreator in the bukkit lib
But you cannot cancel this event
Then water will not flow there
@EventHandler
public void onBlockFromTo(BlockFromToEvent e) {
if (e.getToBlock().getType() == Material.TORCH || e.getToBlock().getType() == Material.WALL_TORCH) {
e.setCancelled(true);
}
}
this code would avoid torches
I want to alter the drop... So I want to cancel original drop and drop my own item
But still want water to displace the head as usual
ah
Easy
use that event
EpicGod used
but break the block ur own way
and drop the item u want
yes... but then two items drop if I not cancel the flow event π
Mhm
how do I use ItemFactory?
Water doesn't destroy heads
OMG
by default it apperantly does
It does?
yes. this is because of I disabled the event
yes
Does Kotlinx's serialisation support arrays of things that have a designated KSerializer?
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
if(playerHeadBreak(event.getToBlock()))
event.setCancelled(true);
}
I cancel the event when my custom head drops
but then the above screenshot happens
I do not believe there is no event for piston and water breaks lol...
How do I use ItemFactory?
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
if(playerHeadBreak(event.getToBlock()))
{
event.getToBlock().setType(Material.AIR);
//drop your item
}
}
cant u do this?
Will try
refactor -> introduce variable
yea its just psuedo code
yea... still drops two heads.
its an example
one default and one mine
so cancel the event as well
EW
Allman style
sucks to suck
r u talking to me?
Yea thats seems to do the trick
yep
it will probably just delay the water by flowing there by 1 tick
Only downside seems to be that it is 1 tick behind with fillinf that destination block
π
spigotmc
yes
well u could also work arround that
I think that it is not a big problem
by checking the neighbors of the To block
but if ur not bothered by it π€·ββοΈ
idk why there is no BlockBreakNaturallyEvent tbh
but there probs is a good explaination
yea...
set the block type to air and cancel the event
already figured it out for both piston and water. thanks
@EventHandler
public void onBlockFromTo(BlockFromToEvent event) {
if(playerHeadBreak(event.getToBlock())) {
event.getToBlock().setType(Material.AIR);
event.setCancelled(true);
}
}
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
for(Block block : event.getBlocks()){
if(playerHeadBreak(block)) {
block.setType(Material.AIR);
event.setCancelled(true);
}
}
}
(playerHeadBreak() actually drops the item naturally π)
what is playerheadbreak
yeah whats inside of that
thats some bad naming
wip
even worse
boolean playerHeadBreak(Block block){
if(!isMyCustomBlock)
return false;
Iterator<ItemStack> it = block.getDrops().iterator();
// If there is actually head drop
if(it.hasNext()){
ItemStack item = // make custom head
block.getDrops().clear();
block.getWorld().dropItemNaturally(block.getLocation(), item);
return true;
}
return false;
}
if you name stuff like that while youre working on ur code
stuff will get messy
i would even name block "blockAffected"
so its not a boolean
ehh... wait
what is it supposed to do anyways
not complete code it can be boolean if he send the modifiers
and return type if its not void
...
what, u using wrapper classes for the return type?
aight
I use this method on all drop events
so I not dupe code...
thats why it is weird a little
renaming it to dropPlayerHead π
why not just use only the
return false;
to determine if its the right block inside the event listener
sure that is what I am doing π
But after that I drop my custom item and want to cancel drop of original one
I have custom PLAYER_HEAD item with custom NBT Compound... When I place it, NBT gets saved into PDC and then retrieved in every block break event so it can be used to create the original item again.
does your head drop the custom one when broken without any of these checks?
It does not thats why I need to check for every single one block break event what drops it
Because I cannot loose the NBT
and still give players ability to place and destroy the special head
so its making a new custom itemstack every break, I see
Yes
Or I can edit existing one?
I think that block.getDrops() is immutable right?
yea. it is...
So I can remove the original item and put there my new one right?
does not work...
block.getDrops().clear();
block.getDrops().add(myCustomItem);
And it still drops the original one...
isnt there a setDrops method?
nope
ah i guess it was in a event then
yea... because BlockPistonExtendEvent and BlockFromToEvent are not block break events, they cannot alter drops
it should work for other events, tho
haha lol... behaving weird when there is a block between head and piston π
why it does not play here?
its not virus I promise π
Discord doesn't support mkv
try BlockDropItemEvent it has a method that returns an mutable list of drops
Anyways yeah that's some interessting behaviour
its actually you modify the drops and drop it naturally
#setDropItems(false) then modify the drops, drop it naturally
Thats what I am doing
you are editing the list
Actually just use this https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/block/data/type/Piston.html
declaration: package: org.bukkit.block.data.type, interface: Piston
^^
ah
you can just replace previous drops instead of clearing it
.
actually you don't even need to do #clear on that since you set the block type to air and cancelled the event. since u make drops out of an new itemstack
#setDropItems(false) then drop the new itemstack naturally saves you some lines
this does not get fired on my server
Same with the Paper's BlockDestroyEvent
Yea... BlockDropItemEvent is called only for items destroyed by player, not naturally
This does not work... When I set it, piston just loose movable part and block not move.
Hm alright
I must somehow cancel the drop and not the piston event
Seems like no other way here
Try setting the head to air
Why would that help?
I thought it was working well?
Aight imma head out, im kinda lost here now
Same
Feels like im talking same shit for the pass 30 minutes
You dont
Let's start over. What are you trying to do with the piston
give me second π
works fine when head is in first place tho
Thats the current problem π everything else is solved
This is very promising: https://papermc.io/javadocs/paper/1.18/com/destroystokyo/paper/event/block/BlockDestroyEvent.html
declaration: package: com.destroystokyo.paper.event.block, class: BlockDestroyEvent
The problem is that it is not firing π
I am using PufferfishMC which is Paper fork...
you want the first one to make the stone move?
video looks good to me
why?
whats the issue in the video?
not sure if thats a vanilla mechanics or it can be changed
it is
vanilla mechanic π
it does not move the block because I cancelled the piston event
but If I not cancel it, I also get the default head drop I dont want
See the dilema?
cancelling it is the best option ig, as long as the relative block is the custom head
Yea... It works fine when piston directly push the head
but indirectly it gets broken
Break the head manually instead of cancelling?
And that stops the block being moved?
yea
Weird
You could mark the location and then listen for the ItemSpawnEvent
And compare locations
wait a minute...
Oh I am stupid.. I miss looked the right event...
It seems to work when I not cancel the event and just replace block with AIR
yes π it works...
yea but I thought for some reason that if I not cancel it it drops default head
Sorry for that
Fine π So I covered BlockBreakEvent, BlockDestroyEvent, BlockFromToEvent and BlockPistonExtendEvent.. Hopefully there is no other way of destroying the block π
I already sent this an hour ago
Explosion events
Yea but you said cancel event
block break event does not fire when piston removes item
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
for(Block block : event.getBlocks()){
if(dropPlayerHead(block)) {
block.setType(Material.AIR);
}
}
}
this does the trick...
If we drop custom head, then we set the block to AIR
aight now im sure i got lost last time cuz of the two events
yea
there was no specific event stated last time
Thats possible, sorry.
great its already worked out
wtf... BlockExplodeEvent is also not get called on my server what is hapenning π
EntityExplodeEvent
BlockExplodeEvent is for blocks exploding, like beds in the nether
entity
yea. thx
tnt should also be entity
It is. yes
Hello, how do I find the 2 points that are perpendicular to one vector?
the point that connects the arrow and the dashed lines is what im finding
That is basic trigonometry
hello guys. Why is this doesn t work?
oh i can't ask this type of question here?
But the question would be where?
here
about beams?
there are infinite, 1 (not sure) or 0 points that are perpendicular between three vectors
yes but i'm trying to find the perpendicular vectors that are (x) blocks away from each other
the given is the vector that is pointing (the solid one)
If the vectors are parallel there is an endless amount of points
yes im trying to find the points that are, lets say, 1 block away
how would i do that
1 block away from where?
from the given vector
its parallel to the vector given
then ur looking for if vector b is a multiple of vector a
u-> = v-> * r i think
it was xD
so i'm going to multiply the given vector by x where x is the distance?
From the origin point of the vector?
its 1 block away from every point of the given vector
its parallel
so no matter the origin point or any point of the vector its still 1 block away
Oh, then it's just pythagoras
that does not work, it will do funky stuff, i already tried that
what if the vector is not actually straight
as in diagonal
Oh right
it works in some extent
but it usually isn't reliable when the direction is diagonal
is there a built in method for this?
I think I know what you mean
in spigot api?
?jd-s
no, is there a method that creates a parallel vector of a given vector that is x distance away from the given?
thats what im trying to say xD
does bukkit's vector even have a direction?
no but you can get the Direction of something from its Location
you would just need the increment and direction or not?
wouldn't u just normalise the vector, invert it (f(x)->-1/f(x)), then multiple that vector by x?
what do you mean by this
a vector can either be a point V(x|y|z) or a direction vector V-> x y z.
@valid solstice
if u know ur orig vector and u know the distance why dont u just add it to the point and keep the directional vector untouched?
rotate teh vector 90 or 180, move (multiply by distance) and rotate back
wanted vector * r = orig vector like ive said in the beginning
which is better? IntelliJ remote development or github
r is the distance i assume?
what is the diff?
no clue
ok ill try that, thanks
Do you mean Github desktop with github?
Oh then no idea
I always used the CLI because my IDE sucks at supporting signing commits
@valid solstice thats the formula to determine wheter or not it is parallel sorry
which needs to return true results
oh
Yeah i got the github project onto my other computer but it sends tons of errors when i try to build it
well im trying to find the parallel vector of x
mainly that βno goals have been specified for this buildβ
Do you use maven/gradle?
maven
i think uhmm a-> + u-> * s + v-> * t @valid solstice
a being ur vector of the starting point
forget it needa get home first to check it properly
um alright ill look more into that
Well the formula to create a paralell function from function f(x) = mx + b would be p(x) = mx + b + (1 - 1/mΒ²) or something like that idk
actually no, that wouldn't work
tbh ik its u-> = v-> * r to determine wheter or not theyre parellel
but i forgot how to derrive the formula to create one from it
i'm thinking that a good way to make this possible is to get the direction of the location
are there any enum classes built in to java?
To determine whether they are parallel it is just m1 = m2, no?
add or subtract 90 to it to get the parallel vector points, then just multiply it by (x) for the distance and multiply it again from the original direction to form the line
Probably yes
StandardOpenOptions is one I know of
StandardCopyOptions is another
yes I'll use that
I just need some enums for a unit tests and didnt want to use Material etc since they are being removed SOME time
Alternatively, open up the javadocs and check which classes extends Enum
if thats the case you compare a set point a with a wanted point b
and then theyre identical
if thats true
u have to add the multiplier factor if theyre parallel but not identical
I mean any linear function has to be f(x) = mx+b. b's value does not matter for determining paralellity
In other words, f'(x) = p'(x). Since f'(x) = m, only m matters
to dertermine if theyre parallel u have to derterime if theyre a factor of each other
sorry hard to translate
they smashed it into my brain in german
and ive hated that topic xD
another german arrived
Ich denke du sprichst von normalen hier
man muss rausfinden ob der neue vektor ein vielfaches des alten is
bzw
man muss einen neuen erzeugen der ein vielfaches des alten is
hab nich nie vektoren gehabt
can't find a single updated tutorial on making a custom entity for a noob like me
in der schule
Vectors are Q1+ maths or physics afaik
π€·ββοΈ sei froh
braucht man auch nich wenn man nich ne low level physics engine schreibt
all of the ones that use EntityX in them use deprecated methods i think
The stupid thing is that I cannot deal with vector properly yet, so I try to translate them to linear functions
i have been taught about vectors during my 8th grade physics but these are just simple multiplication/addition operations
plus they're 2 dimentional vectors, so exploring 3d vectors are a new thing to me
Actually math vectors are different to physics vectors - so disregard my previous statement
Oh right, vectors in mc are 3 dimensional π€¦
anyways i think i may have found a way to make this possible using the locations yaw instead of dealing with the vector itself
still going to experiment with it though
you cant do that
a vector is an array
its just a different word for array
Yeah, but a physics vector is a linear function usually
It's really stupid that physics and mathematics use vector for two different things.
Technically they are kinda similar, yes - but noone will teach you those similarities
for my lib I need to instantiate collections generically. I have until now just used CollectionClazz.getConstructor().invoke(). However, that won't work if the constructor requires an argument, e.g. EnumMap requires an Enum.class as parameter. I have now just added a method that doesn't only take a collectionClazz, but also a collectionSupplier, like this:
/**
* Turns an existing DataType into one that holds a {@link Collection} of the same class
* @param collectionClazz The {@link Collection} to use.
* @param collectionSupplier A {@link Supplier} that returns an empty instance of the given Collection class.
* @param type The existing DataType
*/
static <C extends Collection<D>, D> CollectionDataType<C,D> asGenericCollection(final @NotNull Class<C> collectionClazz,
final @NotNull Supplier<C> collectionSupplier,
final @NotNull PersistentDataType<?, D> type) {
return new CollectionDataType<>(collectionClazz, collectionSupplier, type);
}
Anyone maybe have an easier idea?
for example getting an EnumMap would now look like this:
/**
* Creates a DataType holding an {@link EnumMap} of the given Enum Class and DataType
* @param enumClazz Enum class
* @param valueType Existing DataType for the map's values
*/
static <K extends Enum<K>,V> MapDataType<EnumMap<K,V>,K,V> asEnumMap(final @NotNull Class<K> enumClazz,
final @NotNull PersistentDataType<?,V> valueType) {
return new MapDataType(EnumMap.class, (Supplier<EnumMap>) () -> new EnumMap(enumClazz),DataType.asEnum(enumClazz), valueType);
}
a collector?
wrong reply
how would a collector help here
I.e. so a call is something like asGenericCollection(() -> new EnumSet(Enum.class), type);
you asked for easier ideas?
yes but I have no idea how it would work using a collector π
so could you explain please how it'd work? π
ehm well read this:
https://www.baeldung.com/java-8-collectors
but hopefully you ought to be familiar with what it can do as I hope you've for instance touched Stream::collect
thx. Of course I've used collectors before but I've never looked at their source nor did I ever wonder how they work