#help-development
1 messages · Page 1672 of 1
He is not trying to check if a block is within a BoundingBox but get every Block within a box.
https://i.imgur.com/yEjfvp2.png
@stone sinew
I at least hope he doesnt check if a block is within the bounds like that
add the commas that are missing
yes i found but cancel() doesnt exist
Ah shit yeah forgot. One sec
there I forgot the BukkitRunnable portion
where ?
on task Timers where you want them to be able to be cancelled.
why I can take items from inventory if I set it e.setCancelled(true);
I can take only with shift click
why would he need to do that?
if(event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD || event.getAction() == InventoryAction.HOTBAR_SWAP || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
event.setCancelled(true); p.updateInventory();
}
Oh I didn't know about those. I installed maven, what should be my next step?
if you are trying to setup a spigot plugin using maven, there are a bunch of nice tutorials out there
btw, how can i do that?
https://www.spigotmc.org/wiki/spigot-maven/ this is a written tutorial.
https://plugins.jetbrains.com/plugin/8327-minecraft-development can create the entire project layout for a spigot plugin using maven for you
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
thanks
NP. If it still doesn't work can always add a delay and remove the item and reupdate the player inventory.
i have: java @EventHandler public static void onRclick(PlayerInteractEvent event) { Player player = event.getPlayer(); if (event.getAction() == Action.LEFT_CLICK_AIR && player.getInventory().getItemInMainHand().getType() == Material.AIR) { and for some reason ti sometimes triggers when i rightclick on villagers.
left click air is triggered every time the client sends an animation packet for the arm swing which happens when interacting with villagers afaik
there is sadly no better way to trigger left click air, as the client does not communicate it :/
ok thank you
How would I add onto a PersistentDataType.LONG_ARRAY
Idk. Maybe he wants to fill an area with blocks or check if there is a certain type of block inside.
final long[] newData = new long[]{1};
final long[] data = persistentDataContainer.get(namespacedKey, PersistentDataType.LONG_ARRAY);
final long[] updatedData = ArrayUtils.addAll(data, newData);
persistentDataContainer.set(namespacedKey, PersistentDataType.LONG_ARRAY, updatedData);
something around that ?
basic concept is to just get the array -> create a new one that contains the old one plus the added array -> store the new one
I always use System.arraycopy for that
the apache utils does too
How do I make a kill counter
is there a way to make the plugin run before all other plugins?
Trying to think of a good way to generate blocks from a starting point dependant on which direction the player is facing. Here's a reference picture: (0,0 being the start location). I could for sure do this without problem if it were just one direction, but I want this to work with North, South, East, and West. Any thought? https://i.imgur.com/mS6F6Ea.png
No. What are you trying to do?
world delete plugin, where on startup before world is generated it deletes the world file contents.
So many doing that today
i got the delete part
did some server just do a popular game mode or something?
You are the 4th person today to ask how to do it
Idk, but i'm remaking a very very old gamemode
If you use the Spigot app within your IDE, you can make your plugin load post world or on startup https://i.imgur.com/csOpvJb.png
You can do that in your onLoad method.
@true perch thats what im using, but its still not working
@lost matrix is onload an event just like onEnable?
I never tried it, I always assumed it worked.
I think they go by alphabetical order?
so set it to 1 or something?
Its a method you can overwrite in your JavaPlugin. Just like onEnable()
But be aware that you can basically not use anything spigot related as nothing is loaded properly at this time.
in onLoad, check Bukkit.getWorlds().isEmpty() then recursive delete all files and folders for your main world.
Anyone know a good way of doing this?
You must check worlds is empty or you will attempt to delete an active world if you do a reload
Hey, I'm having some trouble with the remapped version of 1.17. I get an error where an obfuscated class is missing when running my plugin after having reobfuscated it it with specialsource.
Here's a section of my pom.xml:
And here's the error I'm getting
SO much spam. Not read a line of it
Sorry for the spam, I realise now that I should have uploaded them as files
Check the nms section https://www.spigotmc.org/threads/spigot-bungeecord-1-17-1-17-1.510208/
Here's the pom.xml: https://pastebin.com/CRvmChW6
Here's the error: https://pastebin.com/9jrKBbxM
I read the 1.17 post, which I used to add the specialsource plugin
what about deleting the file after the world has been saved. unfortunately the onDisable event occurs before the world is saved, so it will delete the file and then save it again.
And that the remapped jar should be distribution ready
You are using maven so you don;t need specialsource
But I need to reobfuscate it if I want to distribute the files legally, no?
When choosing to use the 'Mojang Mappings', it is absolutely imperative that you are aware of the conditions attached to them as well as the Mojang EULA. These are not restrictions you can simply ignore. In particular you may only 'use the mappings for development purposes'. This means that you must only use the remapped-mojang jar for development and must remap your plugin prior to distribution. For those **not** using Maven you can download SpecialSource to help you do this here, and we encourage the creation of instructions/tools for other build systems.
I'm pretty sure I have a dependency on the deobfuscated jar file, and that the specialsource-maven-plugin reobfuscates it for distribution
Or have I misunderstood the post?
It reads to me that the Maven section does it all for you
I have never done it so I'm just going on what I've read and others have said
Ah
When compiling and testing my plugin without the specialsource-maven-plugin I get another error:https://pastebin.com/vrL6BW6h
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Which makes sense, since the server doesn't use mojang mappings if I'm correct
how would I check if ArrayList of Locations already contains location
would it be better to use hashmap for it
and use cordinates as key
or something
Try this
public void cloneInDirection(final Block start, final BlockFace face, final int count) {
final BlockData data = start.getBlockData();
final Location base = start.getLocation();
for (int i = 0; i < count; i++) {
base.add(face.getDirection());
base.getBlock().setBlockData(data);
}
}
Oooo I will try it! Thank you a ton ❤️
what would I get with set ?
Hugely better performance.
Well what are you trying to do? Tldr
For contains
so I am calculating some locations adding them to lets say arraylist
So i want to get the online players and check if they are above or equal to 1 and im getting this error in console and i don't know how can i fix it doe
The set interface guarantees no duplicates, however the common implementation HashSet#contains is O(1) if the elements contained have rightfully implemented the Object#hashCode method
and when u check if it contains(location)
A player is not a number.
Wait you mean the amount of players
problem is location is object
ye
and it is not same
; 7
yes that’s why I asked for your intentions
final Collection<? extends Player> onlinePlayerList = Bukkit.getOnlinePlayers();
final int countOfOnlinePlayers = onlinePlayerList.size();
if (countOfOnlinePlayers > 0) {
// Do stuff
}
org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError: pluginpack/Plugin has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes c```
because I am confused a bit now xd
Well give us the entire picture
how can I fix that?
Compile time java version doesnt match server java version
so...
Either compile with an older java version or update the version that is running the server.
Just to make it very clear
I think it was compiled with java 15 but my server is using java 8
You should compile and run your jars with java 16.
This is even required for the newest version.
im using version 1.16
Are you using maven?
no
Then no idea how to change the compile src version...
so what I am doing is calculating some shapes and then adding there location to list
sometimes I get same cordinates because I am using Math.round
and I don't want the multiple location object with same cordiantes
and if I check if list.contains(location)
it wont work because every location is differenet object but they can have same coordinates
Ah wait i know.
lol I can just copy my code into jdk8 project
Or you change the version of your current project
that's good idea!
This will not work in most cases because you very very very rarely get the same Location twice.
Also List#contains scales suuuper bad
does anyone have a decent amount of experience with fabric that can answer a few question?
Do you want to fetch the list of mods published by the client?
I'd have used Block#getRelative(face) so you can skip the whole Location construction.
public void cloneInDirection(final Block start, final BlockFace face, final int count) {
Block current = start;
BlockData data = start.getBlockData();
for (int i = 0; i < count; i++) {
current = current.getRelative(face);
current.setBlockData(data);
}
}```
Either works though
or in eclipse I think that I must just that:
btw, how can i broadcast textcomponent?
Yeah this looks nice
no, a guy is asking me to make a MCMMO type of thing but in fabric, i never really used it and i was wondering if it worth it, what can you do with it and is it better than spigot or a waste of time
Java compiler
Completely different platform and target audience.
Every player that wants to join a Fabric server has to download and install all mods.
im not sure what it is creating
Fabric is not targeted towards public servers but rather small, closed communities where every player
knows each other.
bdw why I can't paste pictures in this chat?
You are not verified
?verify
?verified
idk
ok I will quickly do that
https://www.reddit.com/r/fabricmc/comments/htiup7/i_made_a_list_of_fabric_server_side_mods/
but you can create the mods server side?
Sure. But every client still has to download the mods.
ah
He has to go to a website. Install Fabric and then download and install each mod that is on the server.
Manually
I must make spigot account and than verify it?
Sure
aight lets say the player now downloads all mods, what could a mod do? is it like spigot where you can edit an event and execute something or you can customize things like internal data of items, create new blocks and stuff like that
You can do absolutely everything you want.
There are no limits. Only your knowledge and time will determine whats possible.
With Spigot you're restricted to the server. On Fabric you can manipulate both the server and the client
That is unless you're making a Fabric mod that should be useable on a non-Fabric server in which case you're bound to the client
and the client? thats interesting, lets say i want to create the good old emerald pick, i could make the texture, add the values to it and make it work?
both server and client side
Yes, though the server would have to be a Fabric server running your mod so it recognizes and registers your pickaxe properly
and then client side shows the new pick
Can't make an emerald pickaxe and expect to join a vanilla or Spigot server for instance
Yes
This will give you a glimpse of whats possible:
https://www.youtube.com/watch?v=jDIuWv7ROi8
Today coming at you with the least efficient cake factory ever made.
Create is a Minecraft mod for Forge 1.14.4, with 1.15 to follow. It adds a variety of very useful building tools, as well as technology based on kinetics and rotational power. It is a free-time open-source project by a bunch of Minecraft players who love the creative aspect of ...
i have another question, so somehow i managed to create the script(with some help) that sends a message when there is 1 or more players online, every 10 minutes, and now i don't know how to register it into the main .java file
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
I dont know what you are doing. Ive seen a ServerListPingEvent before from you so i just guessed you
dont know how to register events.
hello iam about to edit the Essentials plugin tho i encountered a problem.. i want to change colors but i dont know how to do it is there any other way instead of changing the .jar file itself
You should never access and change a .jar file.
uu nice to know they are very messy
Here is the source code of essentials:
https://github.com/EssentialsX/Essentials
look i just used the Java Decomplier and see the color is $6
but i cant copy that part
and insert it to my text editor
Dont do that. Doesnt Essentials have enough config files for that?
yes i looked that up
i want to change it in locale (and no they dont have setting for color itself)
the problem here is that i dont know where is the locale file
If you dont have prior java experience then you will not be able to just change a jar on the fly.
something went wrong
Does anyone know why the block at the desired location isn't being set to stone?java @EventHandler public boolean onTablePlace(BlockPlaceEvent e){ e.setCancelled(true); Location location = e.getBlockPlaced().getLocation(); generateTable(location) } public void generateTable(Location location){ location.getBlock().setType(Material.STONE); }
so i did this
Try a one tick delay
Alrighty
- This does nothing
- This will just straight up crash your server
*If it runs once
hm
Do you call this method somewhere?
nope
public boolean generateTable(Location location, Player player){
new BukkitRunnable() {
@Override
public void run() {
cancel();
}
}.runTaskTimer(YuCraft.MAINPLUGIN,1,0);
location.getBlock().setType(Material.STONE);
return false;
}```the delay didn't help
org.bukkit.plugin.AuthorNagException: No legacy enum constant for FIRE_CHARGE. Did you forget to define a modern (1.13+) api-version in your plugin.yml?```
This is not a delay. This does nothing.
Oh, how can I make a delay then?
?scheduling


The program cant just guess what you are thinking. You need to tell the program to run your code somehow
why i cant copy the A with the ˇ
You. Can not. Edit. Compiled. Java. Code.
what must I implement in plugin.yml then?
you mean on cracked servers when players have to /register ?
how do i get all all players in scoreboard team ?
I think that the site for plugin.yml is a bit outdated
not with that attitude
.runTaskLater(YuCraft.MAINPLUGIN,1L) worked, thanks for the resource
You can fiddle with bytecode. But you shouldnt.
who doesn't love breaking shit
holy.. i did it 😄
What plugin? We need more information. I dont think any half decent plugin uses readable Strings for authorization.
I mean you can listen for the PlayerCommandPreprocessEvent and read the values from there
and also plugin now somehow load and then it stops because that message occurs: [22:58:34 ERROR]: Error occurred while enabling fireball v1.16.5 (Is it up to date?) java.lang.NullPointerException: null
how do i get all players in a scoreboard team ?
hey guys, how do I make my ItemStack public so I can use it in other classes rather than copy-pasting it?
public ItemStack itemStack?
aha but I'm not sure how to set its variables, like material type, item meta etc.
you have to instantiate the itemstack to change the item
Does anyone know how to get default item attributes without NMS?
@true perch
u make a delay with
Bukkit.getScheduler().runTaskLater(hgawuegauweghaweiughawei0ghaiweg0);
if u dont know what to replace in hgawuegauweghaweiughawei0ghaiweg0 learn java
:D
I thanked the person who sent the resource after I read up about it :^)
Not sure what that is.
o
I'm currently trying to code something that copies the structure on the left, this is what I've gotten so far. https://prnt.sc/1qtz3w4
Can you please show me an example of making a public ItemStack? I googled, found many articles, but it still lead me to nowhere... @worldly ice
what
public ItemStack item = new ItemStack(Material.EMERALD);
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
nah
that won't work, tried
What do you want to do with the ItemStack?
use it in another class without having to copy-paste it there
Then make it a static reference
You could do public static ItemStack item = new ItemStack(Material.EMERALD);
Then do ClassName.item to get said static object.
Very bad practice to do that for most things, but that's one way to do it.
ok thanks, I'll try sum
why plugin doesn't load corectly?
[23:35:06 ERROR]: Error occurred while enabling fireball v1.16.5 (Is it up to date?)
java.lang.NullPointerException: null```
how can i tell if an armor stand collides with a block?
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
you're famous
hi
what lib/method/ressource should i do todo a url request with bearer token and json response?
idk java libs at all so please give an easy one
thx
i dont see there any java example or lib at all
What version are you on?
i need to whitelist this website fionally...
Are the Armostands packet based or spawned via the Spigot API?
Then log the line right before the teleportation and see if it is even called
thanks, will try
Guys, we have threads. Use them, it'll make things so much easier to keep track of
Use teh spawn method with the consumer
Use this method:
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/RegionAccessor.html#spawn(org.bukkit.Location,java.lang.Class,org.bukkit.util.Consumer)
declaration: package: org.bukkit, interface: RegionAccessor
how can I check if entitiy is 2 blocks away from player?
use command blocks / datapacks
no I need that in plugin
you can add datapacks to servers
Location#distanceSquared
ofc but that is just one part, than I must do other stuff with plugins
ok
Thanks.
I found this: if (distanceSquared(pl.getLocation(), en.getLocation()) < as
no, there is a method in Location
is it possible to use breakNaturaly()
and check if block can be broken
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Create a thread in case the help channel you are using is already in use!
So what I am saying I am braking block which are in HashSet
but will it breakNaturaly() check if event is cancled
If you want to see if other plugins are going to prevent the block break you need to fire an event so they can see your attempt
does it even runs block brake event
so I need to call
BlockBrakeEvent
for every block
and check the cancelled state
ok thanks
I was thinking breakNaturaly()
runs event
when u use it with getBlock().breakNaturally(e.getPlayer().getItemInHand());
thanks
You can test it but I don;t believe it does
I need to grab all those block
and give drops to player direcly to inventory
so best will be to call event
?paste
hi how do i put that i can edit the complete tab in the basic version of bungeecord
what
I have to modify the complete Tab and put only some commands that I want
Are you trying to modify the default tab complete of a command?
Yep
if i remember correctly u use the tabcomplete interface
Ok
Hello everyone, EntityChangeBlockEvent does not seem to work with TNTPrimed and a tnt does not seem to be a FallingBlock either
any idea ?
the tnt event
only happens just before it goes bang
^
if you are looking for when it spawns EntitySpawnEvent
Just spawn it
Its one entity. it has a small base
You dont need the bedrock
oh he means that thing
you cant remove that
yes maybe I can check if it moved with a timer
I'm making a plugin where I listen to BlockBreakEvent and use event.setDropItems(false) to stop items from being dropped from the block that was broken. However, this seems to also stop items from being dropped from blocks that "depend" on the block that was broken, such as torches, flowers, levers, etc. I initially thought that maybe two BlockBreakEventss were being called, but that doesn't seem to be the case. It this a bug or expected behaviour? If it's expected behaviour, how do I get around it (no hacky ways please)?
Cancel BlockDropItemEvent
what are you trying to do
package com.thechemicalworkshop.com.disasterscontrol;
import java.net.HttpURLConnection;
import java.net.URL;
public class kill_on_stop {
public static void main(String[] args) {
try {
URL url = new URL("https://mc.thechemicalworkshop.com/api/client");
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestProperty("Accept", "Application/vnd.pterodactyl.v1+json");
http.setRequestProperty("Content-Type", "application/json");
http.setRequestProperty("Authorization", "Bearer REDACTED");
System.out.println(http.getResponseCode() + " " + http.getResponseMessage());
http.disconnect();
} catch (Exception e) {
/*
* Fail quietly.
* No need to spam a stack trace.
*/
System.out.println("error!");
}
}
}
i created this file, stuff.java
how would i use it inside main java file?
is it even correct lol
wat
how do i tell the plugin to run this
by putting it in a plugin

...
yeah i dropped java 8 years ago 🙄
void doThing() {
// thing
}
onEnable {
doThing();
}
should probs refresh your self
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
should, but then, i just need like 10 plugins and hoping to cheese thru and dont touch it even again
well i know i need to load/import it, question how
r
custom enchant
so if I call manually block brake event
that will not brake block
crap, it's not giving me anything except 200 code... no data
thouight responsemessage would give me smth
@timid root
hello
hi
how soon?
can you cancel the enderpearl teleportation event inside the onProjectileHitEvent?
or can you at least get a cast of the Enderpearl that caused the teleportation in the TeleportationEvent?
What are you trying to do?
cancel the teleportation of the enderpearl depending on the lore of the enderpearl
what you should do is listen for the PlayerInteractEvent, and if the enderpearl meets your criteria, set the owner field to null
ooo
that's the cleanest solution really
Yeah
never thought of that. can you set the owner field in player the onProjectileLaunch event?
Lore is exploitable
yeah
k
Use a persistent data container
As long as you can get the projectile it will work
tell me why you are using lore over PDC
because lore is uncomplicated
So is pdc
its horrible and unsafe
localized-name is a good way for identifying custom items
yet its not
eh
?pdc @median anvil
idk what pdc is
learn
pdc is better
ive been using lore for everything xD
Persistent data container
its easy
damn.
Store data in an items json
lore is pretty gross for item identification, especially if you're iterating through multiple lines
then you shouldve suggested it to him
but for the sake of simplicity, localized names work well
I didn't suggest it to him forehead
Simplicity deos not always mean good
you said names are good
localized names
i've been using lore cause I watch youtube and thats what they do... thanks for telling me pdc exists tho.
codedred?
That's not the display name field, it's invisible meta on the item intended for resource pack translation
hes a bullshitter who spreads bad code
localized name =/= display name
his code has worked for me so far, but then again im new to java in general so...
yeah his practices suck
its working code but bad code
he's one of the ones I used in the beginning lol
Wow ok just because his code may not be the best does not mean he is bad. He is helping people understand spigot for free. Obviously there are some things that he should improve but there is no reason to hate.
well, ill probably rewrite my plugin the correct way after I get everything working.
when tf did I say he was bad
true
I'll try, i'm still a beginner. I'm already on my second rewrite actually.
each time i get further and further
btw the I grabbed the enderpearl and set the shooter to null but it did not work, i still teleported.
make sure you're registering your listener
and when something doesn't work, put some lines that output a string right above the part that makes the change to see if it even fires
Any errors?
@median anvil is there a setOwner method?
I see you have setShooter, see if there is a setOwner method as well
Is this listener registered?
Put a System.out.println("ooga"); above that
ooga
see if it's even being reached
setShooter
declaration: package: org.bukkit.entity, interface: Projectile
also looked at ender pearl code
can confirm
it is setShooter
Cool
Bukkit.getConsoleSender().sendMessage("TESTING ENDERPEARL");enderPearl.setShooter(null);
its being reached just not doing anything.
what version of spigot are you using
1.17.1 from intelij plugin
java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "org.bukkit.entity.EnderPearl.getShooter()" is null
hmm
it is turning it null, but its still teleporting me
I event tried canceling the enderpearl land event, but still teleported me.
Can you confirm that you can modify the ender pearl in other ways?
i have no idea at this point
possible forum thread about it? https://bukkit.org/threads/cancelling-enderpearl-teleport-from-projectile-hit-event.404620/
I need to see when an enderpearl hits a certain location and cancel it. You can't cancel the projectile hit event. But I don't want the enderpearl to...
yeah, I set it to explode when it hits the ground.
the op specifically states that setting the shooter to null didn't work
it explodes, but also teleports me into the explosion
is there a post thats realy indeeph about what to learn. I know post say learn OOP learn abstract learn java öearn spigot but not deep pls @ me if you have link or can tell me deeper
thats all it is lol
1.Maps rarely are passed through classes
-
Never hardcode if statements for things like quests, skills, create check objects
-
Always create an API for your classes and allow everything to be changed
-
Javadoc everywhere
-
static isnt to make life easier
-
understand OOP
-
abstract everything
-
understand object constants vs enums and when to use them
i did it by deleting the enderpearl when it hit the ground!
thx imaginedev but I dont understand the first two. Can you show examples where its right and where its wrong thx
best way to store data permanently?
in general
Use a config file
so is pdc part of nms?
cause i've been storing my persistent data as lore in items xD
ye
i didn't even know pdc existed. but now i'm interested
its like easy nbt
i don't think i can do nbt/nms with the spigot plugin im using in intelij cause it doesnt have the imports. I was trying to follow a tutorial on creating npcs, and I couldn't cause I dont have the nms imports.
you dont need it
pdc handles it all
okay.
@quaint mantle will persistent data be injected into the block placed from the block item in hand?
so if i had an itemstack of blocks with persistent data, and placed a block, would that placed block hold the data I stored in the Itemstack of that block?
no
oh.
It will
had to do some research
but it only works on certain types
Banner, Barrel, Beacon, Bed, Beehive, Bell, BlastFurnace, BrewingStand, Campfire, Chest, CommandBlock, Comparator, Conduit, Container, CreatureSpawner, DaylightDetector, Dispenser, Dropper, EnchantingTable, EnderChest, EndGateway, EntityBlockStorage<T>, Furnace, Hopper, Jigsaw, Jukebox, Lectern, SculkSensor, ShulkerBox, Sign, Skull, Smoker, Structure
I wish I knew about pdc before writing thousands of lines of code depending on lore...

PlayerInventory playerInventory = player.getInventory();
playerInventory.clear();
playerInventory.setExtraContents(null);
playerInventory.setItemInMainHand(null);
playerInventory.setItemInOffHand(null);
playerInventory.setArmorContents(null);
playerInventory.setStorageContents(null);
``` How do I clear the little crafting area in the player's inventory? I've managed to clear every other part of the player's inventory except for this
Ended up closing the inventory first then clearing it
save contents
close
set contents
can you allow crafting recipes under certain conditions/permissions?
Yes. There's a PrepareItemCraftEvent you can use
To check which recipe is in the table in that event, there's a getRecipe() method
Choco choco
ty
# Yes, the file extension is .ASS
# Cry about it.
final var name = prompt()
print('Hello', name)
@worldly ingot Choco likes?
Sad
What is .ass? Async script? ;p
Figured as much
Choco Choco rate syntax
with the PrepareItemCraftEvent can you check if the event.recipe is equal to a custom recipe you created?
Yeah. Check if the Recipe is an instanceof Keyed. You can then cast it and getKey(), compare it to the key you used when you created the recipe
Recipe recipe = event.getRecipe();
if (recipe instanceof Keyed keyed && !keyed.getKey().toString().equals("yourplugin:key")) { // or equals() the NamespacedKey directly
return; // Return if it's not your recipe
}
event.getInventory().setResult(null); // Remove it from the result under x condition
@worldly ingot i have a separate class that holds my custom recipes in functions that return the recipes
example function from my class CustomRecipes: https://paste.md-5.net/ecanuqayim.cpp
creating a new recipe everytime its called 
its only called once on startup
how would I access that recipe / key?
the instanceof Keyed keyed is what is confusing me rn.
Java 16 feature
Equivalent to
Recipe recipe = event.getRecipe();
if (recipe instanceof Keyed) {
Keyed keyed = (Keyed) recipe;
}
did you know: Choco likes ass?
it should be namespace:seed_stew
replace namespace with wherever it comes from, e.g. minecraft
I set the namespace as the plugin I think
getKey().equals("some string") will never be true
Note in my initial snippet I did getKey().toString().equals("some string")
NamespacedKey.equals(String) is impossible. String.equals(String) however. 
Amazing, thank you!
Hey guys I have a question for you if you know the answer i'd really appreciate it.
My server pulls the docker container image for about 4 minutes. When it finally pulls it after 4 minutes, the server starts like normal. But what is causing the container image to be so slow?
It's a rise-2 from OVH. I have 18G allocated to the docker container, and only 14 on the actual minecraft server (4g heap)
How do I spawn particles for every player except one?
for (Player player : Bukkit.getOnlinePlayers()) {
if (!/* check if player = your player*/)
// Do something
}
No
Hey! quick question: I was dealing with JDBC yesterday and asked for help here in this regard. Someone helped me and gave me an example of how to create a DataSource.Then I created the following class:
public static DataSource MySQLDataSource() throws SQLException {
MysqlDataSource dataSource = new MysqlConnectionPoolDataSource();
File file = new File("D:\Programming\Plugins\sfspConfig.yml");
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(file);
dataSource.setServerName(yamlConfiguration.getString("host"));
dataSource.setPortNumber(yamlConfiguration.getInt("port"));
dataSource.setDatabaseName(yamlConfiguration.getString("database"));
dataSource.setUser(yamlConfiguration.getString("user"));
dataSource.setPassword(yamlConfiguration.getString("password"));
testDataSource(dataSource);
return dataSource;
}
private static void testDataSource(DataSource dataSource) throws SQLException {
try (Connection conn = dataSource.getConnection()) {
if(!conn.isValid(1000)) {
throw new SQLException("Database not connected!");
} else
System.out.println("Database connected!");
}
}
However, now I don't know how to continue. Can anyone help me there?
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
how do i get player nbt ?
hello is there any reason why my dynmap should not work ?
I made two actions now, is this good enough to register if the player right cliekd an entity?
UUID uuid = e.getPlayer().getUniqueId();
Player p = e.getPlayer();
Class clasS = Main.getClassManager().getClass(uuid);
if (clasS.equals(Class.PRIEST)) {
Entity action = e.getRightClicked();
if ((action.equals(action) && ```
Oh yes, there was also that. Thank you
if ((action.equals(action.getType() == EntityType.ZOMBIE) ahhh like this, but can I do an entitytype for all entities there is?
you can loop over the entitytypes
for(EntityType entityType : EntityType.values())
if(entityType == EntityType.ZOMBIE) System.out.println("a zombey");
I see
How can I store PacketPlayOutMap in files efficiently?
actually my goal is to be able to cache again every of my PacketPlayOutMap after restarting serv
how can I make that BukkitRunnable will repeat the proces 10 seconds
.runTaskTimer(this, 0L, 2L);
so 20L I must put there then?
If 2 is 1/10 of a second what do you think 20 is
10
think carefully, because I did also just say
1 / 20 ticks per second * 20 = Once per second
is there any way to get a twitch chat into minceraft with spigot
Yep
Probably, there’s probably some sort of webhook you could use
you will need some sort of library or something like that
i think i have one but i have no idea how it owrks
you can just find an example on internet
I'm having trouble compiling my plugin. I get this error:
org.bukkit.plugin.InvalidPluginException: Cannot find main class `nl.naimverboom.aresessentials.GeneralClasses.AresEssentials'
In my plugin.yml, I have this:
What do I do to fix?
That's not going to fix the problem I'm facing
Well does your main class exist in that location
It does
how to check if block is blast protected
Show us because the error says it doesn't
your main: should be the one where you have public onEnable() method
You mean on the top?
Yes
Wait I think i found the problem
Alright
The problem was very dumb
if you look at the project files i forgot to wrap everything in a package
how to check if block is blast protected
what so like if they are sneaking completely ignore it
why when I try to teleport the location I create here
World world = plugin.getServer().getWorld(data.getString("world"));
Location location = new Location(world, data.getInt("LocX"), data.getInt("LocY"), data.getInt("LocZ"));
its gives me an error java.lang.IllegalArgumentException: location.world
and when i try to create item there it works?
ig you could listen to the move event - check how close to the edge of a block they are and if that next block is air disable the crouch
can I make egg entity unbreackable? I mean when it colides with a block it won't break
what do you mean by break
Eggs break when they hit a block
Looks like he wants to just have a bunch of eggs floating or smth
not really?
except if u have a very shitty server
I can just when player throws it get his position into 3 intagers and then when the egg breaks I can just spawn new one in the same direction
how to check if block is blast protected
@mellow edge im pretty sure Material enum class has method to check if enum block type is unbreakable
I could be wrong tho
Is there a way to get it higher? java.lang.IllegalArgumentException: Health must be between 0 and 20.0, but was 20.200000762939453. (attribute base value: 20.0)
So I just switched to java 16 for 1.17.1 plugin and I received a warning saying that's the class could be a Java Record, and I'm wondering If it will have the same effect like the dependency injection. Because I originally want to pass my main class to other class and I got this warning instead.
public record PlayerEvents(PersonaPlugin plugin) implements Listener {
}
It's like lombok tbh lol
Set max health to higher with an attriubute
Ok so the attribute is able to have a higher value?
Do I have to set baseValue?
Believe so
infinite i think
Probably float max
https://minecraft.fandom.com/wiki/Attribute Sadly it's only 1024 😦
Yep true 😄
can i combine a textcomponent (clickable message) with a normal string message?
component builder
Got this error on this line, what is the problem? https://paste.helpch.at/uvofuzinal.md
Thats not the line that gave the error, but it is the text you sent. Use prepared statements
You also definitely don't wank all those columns to be TEXT
Ok those readings are a bit weird...
can't use prepared statements to replace table names
no but you can for all the rest
Can I somehow delete the item after someone dropped it?
not needed, it's a hardcoded statement to create the table
destory the entity
Seems to be -0.5 - 2.0 in 1.17 and for 1.18 will become -0.7 - 2.0
could still use some help with this
You can not cast a String to a Material. Use the method Material.matchMaterial()
how can i obfuscate my code ?
ping me for answers
how 2 use this
declaration: package: org.bukkit, enum: Material
Use an obfuscator
Like?
Material.matchMaterial(String) is a static method of Material that takes a String and returns a Material.
so like this?
Material.matchMaterial(cfgn.getMaterialsConfig().getString("disableElytraMovementCheckMaterialDisabledConfig"));
I found the error, turns out I can't use desc because it's used for sorting stuff.
Yes but thats quite unreadable. Write it line by line.
String materialKey = "disableElytraMovementCheckMaterialDisabledConfig";
String materialString = cfgn.getMaterialsConfig().getString(materialKey);
Material matchedMaterial = Material.matchMaterial(materialString);
I tried to delete the Item after it gets dropped but with that method I only delete Items that are already dropped and not the one that I am currently dropping. How can I delete the Item as fast as possible after someone dropped it?
Collection<Entity> list = player.getWorld().getNearbyEntities(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation(), 10, 10, 10, (entity) -> entity.getType() == EntityType.DROPPED_ITEM);
for (Entity entity : list) {
Item item = (Item) entity;
if (item.getItemStack().getType() == RegisterManager.getPlayersElements().get(player.getUniqueId())) {
item.getItemStack().setAmount(0);
player.sendMessage("deleted");
}
}
@EventHandler
public void onDrop(PlayerDropItemEvent event) {
event.getItemDrop().remove();
}
^
Im pretty sure you can cancel that event too in case there are items you dont want to delete...
No I cant cancel it because it triggers my InteractListener then
Yeah but I do something on left click Air and it the dropp triggers the left click air and thats the problem
If the event is set cancelled shouldnt it not trigger that anymore?
it does because of the swing animation or something:
https://github.com/SkriptLang/Skript/issues/2731
Welp, gotta figure out a workaround then. Maybe try something like a public static boolean you set false when it happens and if its false you cancel the interact event?
Worked for entityspawnevent
Its okay I already fixed it but thank you
Ok so, how can I get what block a snowball hit in 1.8.8?
im confused
Never worked with 1.8.8 but isnt there a projectileHitEvent or something?
Yeah but I need to know what block it hit
Event.gethitBlock or something?
It's getEntity, and no.
I don't need an exact block, shall I just get the snowball's location and round that to a block?
Maybe even use the vector it has before hitting to determine the actual block it hit...
True
Might be weird around corners tho
Yeah
This will work
Write your own getHitBlock method XD
😄
think it wants the index of the biggest number in the array
im confused i forgot how to do it
Snowball snowball = (Snowball) p.getWorld().spawnEntity(p.getLocation(), EntityType.SNOWBALL);
snowball.setVelocity(p.getLocation().getDirection().multiply(2));
```This isn't going to work is it.
The snowball will instantly destroy right?
XD
I did, I'm asking you guy's opinion on it.
Well, did it work?
as far as I know that should work
No because it spawns on the player so instantly destroys, adding the players direction to the spawn location fixes that.
anyone know why i can't use this in another class?
public static ItemStack createItem(String name, Material mat, List<String> lore, int cmd) {
ItemStack item = new ItemStack(mat,1);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setCustomModelData(cmd);
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}``` i could before but i did some stuff and for some reason now i can't
nvm
it just doesn't suggest it
so offset it.. 😐
what is wrong herejava public static void brodcastToTeam(Team team, String message) { Player LoopingPlayer = null; for(int i = 0; i <= playersList.size(); i++) { LoopingPlayer = playersList.get(i); if(team.getPlayers().contains(LoopingPlayer)) { LoopingPlayer.sendMessage(message); } } return; } ?
in your code i think you have nothing wrong, check if the players is in team.getPlayers() and playerList
how can i send error ?
it it is, then you can simply do to send to all team members
for(Player TeamMember : team.getPlayers()) TeamMember.sendMessage(message)
it doesen't let me upload a filr
just copy last 5 lines there should be the error message
this ? at net.minecraft.server.v1_16_R3.MinecraftServer.sleepForTick(MinecraftServer.java:1220) ~[patched_1.16.5.jar:git-Paper-787] at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1134) ~[patched_1.16.5.jar:git-Paper-787] at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Paper-787] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_275]
isnt that incorrect use of "for" ?
you should find "Caused by:" message
it is a correct usage when you want to loop ever an array list
i can't find "Caused by:"
well i saw that : [17:03:47 ERROR]: Could not pass event BlockBreakEvent to bedwars v1.0
Found a random error online...
The errors usually look like this
[12:37:14 ERROR]: Could not pass event PlayerInteractEvent to hub v1.0
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:226) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:724) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot-18.jar:git-Spigot-c3c767f-33d5de3]
at java.base/java.lang.Thread.run(Thread.java:832) [?:?]
Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.ItemStack.hasItemMeta()" because the return value of "org.bukkit.event.player.PlayerInteractEvent.getItem()" is null
at me.Items.Interact.onInteract(Interact.java:15) ~[?:?]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[?:?]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[?:?]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot-18.jar:git-Spigot-c3c767f-33d5de3]
... 16 more
you can see the two parts, first one is the exception and a stack trace and the second one is the error message
the code you send: it returns
Required type:
OfflinePlayer
Provided:
Player
null
so it's a list of OfflinePlayer? List<OfflinePlayer>
for(Player/*not offlien player*/ TeamMember : team.getPlayers())
what is the return type for team.getPlayers()
Set<offline player>
Why are the team members offline players? Can you even send a message to offline player?
i don't think so
also i am realy new to java
and i got it to work with:java public static void brodcastToTeam(Team team, String message) { Player LoopingPlayer = null; for(int i = 0; i < playersList.size(); i++) { if(team.getPlayers().contains(playersList.get(i))) { playersList.get(i).sendMessage(message); } } return; }
Cool
you can try the other version of for too. to learn that
other versions ?
this:
for(OfflinePlayer TeamMember : team.getPlayers())
TeamMember.sendMessage(message)
learn about for loop here:
https://www.w3schools.com/java/java_for_loop.asp
but i don't understand why are you using OfflinePlayer. and how can you call the sendMessage method on an Offline Player. That one doesn't exist i believe
well i didn't know about for-each as i don't think C has that
thank you for the help
the code works if i do:java for(OfflinePlayer TeamMember : team.getPlayers()) { TeamMember.getPlayer().sendMessage(message); }
Hey there guys. I've been getting a bunch of differing results when trying to get where a player is looking, and can't really seem to make any of them work. Any tips?
I more or less want to get the entity or block a player is looking at, whichever comes first.
Just what entity they're looking at
Is there a better way than this to convert enchantment names to their "pretty" names such as DAMAGE_ALL to Sharpness?
Checked the javadocs and the .getName() method just returns the namespaced name.
https://bukkit.org/threads/getting-enchantment-name-level-from-item-to-string.170737/
I'm trying to get the enchantment name and level, of an item, to a string. But the only string I get is: {Enchantment[16, DAMAGE_ALL]=1} on a sword...
have you tried https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/util/RayTraceResult.html
just found that
declaration: package: org.bukkit.util, class: RayTraceResult
I haven't yet, I'll give it a try now. Thank you!
Is there a way to check if a sound is allready playing? (1.12.2)
I looked into the docs, but i can only find things like playSound() and stopSound()
Can someone show me a quick plugin.yml file like just a command.
Or something.
I have problems with it.
And I wanna know if you guys have the solution for my problem.
When Bukkit loads a plugin, it needs to know some basic information about it. It reads this information from a YAML file, 'plugin.yml'. This file consists of a set of attributes, each defined on a new line and with no indentation.
A command block starts with the command's name, and then has a list of attributes.
A permission block starts wit...
what about the command name.
I believe that is done just on the client side as you can change the language in the settings.
found this:
https://www.spigotmc.org/threads/looking-for-the-in-game-enchant-names.290133/
Essentials plugin do that too. The last message also contains a code with the finished thing. You can just copy that and add some new enchanments added since 2017
thanks anyways tho
I'm having some issues trying to use the RayTraceResult, if anybody can help me with how it works.
yeah, but you can do different methods too,
Essentials apparently does it with a Map<String, Enchantment> and it's all coded in a file
But you could also just load that from a text or config file
version: version
main: main of your class. com.dublindevil.dubshop.DubShop
api-version: 1.17
prefix: log prefix like CoolPlugin or DS or smtn
depend: [ ] plugins to depend on
authors: [ your name here ]
description: desc of your plugin
commands:
createshop:
permission-message: You do not have permission to execute this command
permission: dubshop.createshop
description: Create Sign Shops
aliases: setshop
usage: /createshop <price> <quantity> [Warp Name]```
so just import the essX library and get the enchs? that seems like a pretty good option tbh
World#rayTraceEntities
rayTraceEntities(Location start, Vector direction, double maxDistance)
ohhh, once I run that I should run the result?
that method returns the result and you can getHitEntity()
What about just the command one?
Like commands:HelloWorld:usage </command>?
Oh, so like this?
wdym
like it shows an example command of createshop there
/createshop
the usage is just what is shown when the commandexecutor returns false
do something like
Player.getLocation().getWorld().rayTraceEntities(Player.getLocation(), Player.getEyeLocation().getDirection(), 10)
How do I enable my command via a .yml?
the plugin.yml in a plugin declares the command, you then need to create an executor for it in the main
Where should I put that, though? After the RayTraceResult?
the executor class is called when the command is executed
Yeah I know but how do I control the like prefix.
Like if I were to type /hello
How do I make that valid?
So it says Hello Again!
I know how to do it in Java.
you need a lot more than just a yml to do anything lol
I know how to create the command.
But I don't know how to set a "prefix" for it.
Like so it's valid typing /hello
that method returns a result...
RayTraceResult Result = Player.getLocation().getWorld().rayTraceEntities(Player.getLocation(), Player.getEyeLocation().getDirection(), 10);
//then something like
Entity LookingAt = Result.getHitEntity();
And it would return an result.
OH. I get it now, thank you!
dubz88?
in the onEnable put this to declare the HelloCommand class as the one that handles /hello
this.getCommand("hello").setExecutor(new HelloCommand());
then make a class called HelloCommand and make it implement the CommandExecutor
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
sender.sendMessage("hello");
return true;
}
}
Are you sure about that?
I saw an tutorial.
there are several ways to do it
An it said something like command:
HelloWorld:
usage: </command>
the usage is just shown if the command returns false
I got the code to run, but the .getHitEntity() is returning null despite looking at an entity.
Safe to say I'm looking at one.
Entity LookingAt = Result.getHitEntity();
if(p.hasPermission("laserEyes.use")){
if(!(LookingAt == null)) {
p.sendMessage("Target " + LookingAt + " removed.");
LookingAt.remove();
return true;
} else {
p.sendMessage("Target is unable to be removed.");
return true;
}
} else {
p.sendMessage("You do not have permission to execute this command!");
}
return false;```
this is the code that is acting up
what about the distance, try to get as close as possible. I'm not sure if the distance is in blocks 😄
oo good point
@atomic gyrotry p.getEyeLocation() else p.getLocation
It was the distance that was the issue.
Had to ram into the mob to remove them.
Is the distance in Pixels or 1 = .1 blocks?
whatever
do Double.POSITIVE_INFINITY
that might not work though 😄
Oh yeah, as long as you can see it it should work.
didn't work, it has to be finite. I guess 99999 will cover it.
I'm going to develop a custom plugin for my 1.17.1 server, do I need to use J16?
That isn't a number. that might cause the error. Try Double.MAX_VALUE
For some reason, 10 is the only working value.
I tried 100, and Double.MAX_VALUE.
these work fine for me
whats the issue
Trying to set it so that an entity I'm looking at while I run the command is removed.
and for what the double?
For some reason, the double value on
RayTraceResult Result = p.getLocation().getWorld().rayTraceEntities(p.getLocation(), p.getEyeLocation().getDirection(), 10);
Isn't working
10 worked before, and now is no longer working.
- Naming convention.
result - How do you determine failure or success?
- should I change it to lowercase?
- Failure would be looking at an entity, running the command, and it returning
null. Success would be looking at it, running the command, and it disappears.
Try starting the ray trace from the players head and not his feet
??? What do you mean?
Also pls dont use singe character variables.
?services
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
What's wrong with p? Works like a cmd block.
readability
Changed it to start from my head, removed myself from game.
@quaint mantle
Read @hybrid spoke 's message
Ok
I know that all the youtube tutorial kids think its cool if they use single chars like p and e and still know what they mean but its just very unclean.
I'll change it up next time I make a plugin I guess.
How do I avoid removing myself from the game?
You need to use a Predicate so that the ray trace doesnt instantly hit yourself
entity != you
How would I input a predicate? I'm pretty rusty on my implementation.
final World world = player.getWorld();
final Location start = player.getEyeLocation();
final Vector direction = start.getDirection();
final double distance = 10.0;
final Predicate<Entity> filter = (hit) -> !hit.equals(player);
final RayTraceResult result = world.rayTraceEntities(start, direction, distance, filter);
You might also get away with
final Predicate<Entity> filter = (hit) -> hit != player;
final final final final final
Yes. I like it and thats why i configured my IDE to make everything final on default.
What would (hit) be?
hit is the entity that is being hit. This is called a lambda expression.
It takes an entity and returns a boolean (Predicates are defined like that)
so (hit) is the same as .getHitEntity()?
how can you call it before the method finishes?
isn't that fine? the values won't change either way?
You can not call this method yourself. This is a method that you construct. It gets called internally for every entity that is hit.
If the method you passed returns false then the hit entity gets ignored and just proceeds. Its like a filter for when to stop the ray trace.
i am thoroughly confused because this is glowing red like the sun in my IDE and theres no bukkit imports to fix it
final RayTraceResult Result = world.rayTraceEntities(start, direction, 10, this::isViableEntity);
...
private boolean isViableEntity(final Entity entity) {
// Check if entity is viable
return true; // Or false
}
You can also define them like this.
Its basically just a delegate method you pass.
Java version, Spigot version?
1.8 / 1.17.1
RayTraceResult Result = p.getLocation().getWorld().rayTraceEntities(p.getEyeLocation(), p.getEyeLocation().getDirection(), 10, filter);
Entity LookingAt = Result.getHitEntity();```
oh jeez thats messy
isnt that messy on my side, sorry
It gets less messy if you define more variables
Can anyone tell me why my server logs out a message saying my permissions.yml is empty?
is there a difference between ```java
new Gui().open();
and
Gui obj = new Gui();
obj.open();
Can anyone tell me why my server logs out a message saying my permissions.yml is empty?
its reading that statement as a second double for some reason.
no, but you can't do Gui obj = new Gui().open();
its "fine". literally opinion-based. it doesnt restrict anything. in my opinion its an overuse of final and very messy.
how
then why use private
Can anyone tell me why my server logs out a message saying my permissions.yml is empty?
thats normal
you cant compare that with each other
how
they both won't stop ur code from working in most cases but they should be used
once you get into api design you will understand it
private is important. final is too, but not for local vars.
hmm
For some reason, p.getWorld() doesn't work.
private is used to have something "class-only". important for encapsulation. final is used to declare something as "will not change anymore" what is not necressary for local vars in most cases.
p.getLoc.getworld
Still doesn't work.
what does it say
It's saying there's a type mismatch and that it can't convert org.bukkit.World to the MC version of .world.
Type mismatch: cannot convert from org.bukkit.World to net.minecraft.world.level.World
are you using org.bukkit.World?
It autoreplaced my org.bukkit.World with the second one when I imported. Sorry.
Now, how do I get rayTraceEntities to stop seeing my Predicate as a double?
I want to cancel the scheduled task or delayed task 30 sec or 600ticks when player mount on entity but i am not sure how to do it
start in in the player mount event or something?
300 ticks isn't 30 seconds
sorry its 600ticks or 30sec
you need to create a global variable for the taskID, create the task, save the id of it to the variable. And on PlayerMountEntityEvent Cancel Task with that ID
Also check if it's been 30 seconds, and don't do it. Clear for next time.
You could put the taskIDs to a HashMap. so each player can do that at the same time
Does canceled delayed task will start again whenever a player activates the delayed task?
Bukkit.getScheduler().cancelTask(pid);
if you tell it to 😂
Is there way to read in .jar files and use them as addons for the main plugin ?
Seems to be outside the scope
okay
Outside of which scope?
dependency
@atomic gyro
the {}
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
if you don't understand what conclure said
I understand what he wrote, not how to implement it.
also
I understand what scope is, just not where he was referring to it.
I'm not gonna claim I know java well but I understand it enough.
you don't seem to
Damn
OkaKnight thing is
I created an abstract class..
i want that other developers who are not able to see my code write addons wich depends on my abstract class...
what conclure said is 10 minutes of java
A variable only lives inside the
{
}
It’s declared in usually
thats what dependencies are
if you have something like this:
{
Object result;
}
result.method();
at line 4 variable result becomes unreachable
is you assume other devs dont use a decompiler then they cant read it
So a good way to handle it is to move the result.method() part to line 3, whilst } comes at lines 4 instead
can someone help? i got an error
Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.configuration.file.FileConfiguration.getString(String)" because the return value of "ConfigManager.getMaterialsConfig()" is null
public FileConfiguration getMaterialsConfig() {
return materials;
}```
tell me what more code u need btw
Yes.
They only got the plugin.jar
bro
smh how do i do a word with a line through
send the code
pls
the "org.bukkit.configuration.file.FileConfiguration.getString(String)
show us the getString
ill fix it for you
Material mat = Material.matchMaterial(cfgn.getMaterialsConfig().getString(name + "ConfigEnabled"));
The problem is inside the ConfigManager and another class that depends on it tho 2Hex
Material mat = Material.matchMaterial(cfgn.getMaterialsConfig().getString(name + "ConfigEnabled", ""));