#help-development
1 messages · Page 1374 of 1
if (block.isBlockPowered()) {
...
}else if(!block.isBlockPowered()){
uh @quaint mantle what is this code?
you dont need to do it twice
lol
read before you try and clown me
Ah, so It's possible. Is it complicated tho?
what lol
You need brigadier and commodore
getType().equals(Material.LEVER) ❌
getType() == Material.LEVER ✅
Then it’s all possible (:
or you can make a builder like this for just brigad https://github.com/PulseBeat02/MinecraftMediaLibrary/blob/master/DeluxeMediaPlugin/src/main/java/com/github/pulsebeat02/deluxemediaplugin/command/ImageCommand.java
(:
Yes but that’s without commodore
Though it’s just a single method call to hook into that
Literally the same. What do you think forEach internally calls?
He also forgot the method reference 👀
Yeah lol
This is the reason why people trash talk lambdas.
Horrendous.
It looks fine to me
^^
lol
I mean with commendore you put that into a file
Not rly
the structure at least
if you scroll down, (without getting fucking mad at me for making your code block cleaner,) you'd see I just said it makes it look cleaner
That’s optional
🙂
how is it horrendous tho? Is it cause of srp lmao
id rather do that then do like 20 conditionals
lmao
Well yeah but that is necessary for tree structure
If you deliver this code in a company you will just get kicked out.
Fortunately he isn’t working for a company
HAHA
Volatility for days. Every functionality has its own expressive method.
when my lecture is over
I usually make my design such that any sub commands of a command may only be exposed with in that specific command instance and not any higher. But it also has drawbacks.
I think it’s possible to accomplish that with brig also
getItemMeta can return null when?
Lambdas > Anonymous classes
arent they also slightly faster?
Air
Sure java compilers might actually optimize lambdas
Yeah
wot?
thats no way possible lmao
he's talking about getItemMeta
.
Or for some reason hasItemMeta returns java.lang.Boolean
may be air
scroll up a little bit xd
it does?
.
Probably not
We already answered that one though
^
I mean getItemMeta returns null if the ItemStack has material air but then again it’s actually stated in javadocs iirc
Javadocs are really strange
ooo, my bad
It's either you read the javadoc but do not listen to the annotations, or the other way around. There are too many instances where the javadocs say that it can return null, while the method annotation says otherwise
The Null annotations are also present in the JavaDocs. I havent seen a single instance where a method
was annotated as NotNull and still returned null.
I'd trust the annotations over the doc comments
Better save than be sorry, the annotations do not enforce themselves
Annotations are more up-to-date than the docs are
Still doesn't work.
Keep in mind that sometimes implementations change while API docs do not
same as here
Block#isBlockPowered() isn't quite what you want to check whether or not a lever is activated
You need to poll from its BlockData
Switch lever = (Switch) block.getBlockData()
if (lever.isPowered())```
if (e.getClickedBlock() == null) return;
if(e.getItem().hasItemMeta()){``` so were sure hasItemMeta isnnt going to return null here?
hasItemMeta() cannot return null, it returns a primitive boolean. getItemMeta() will only ever return null if the item type is air
Generally when creating a new item I'll do this:
ItemStack item = new ItemStack(Material.STONE);
ItemMeta meta = item.getItemMeta();
assert meta != null; // Because this is theoretically impossible, if it returns air... this is a bug in Spigot, we can assert that this is true```
thank you very much it worked
👍
Btw, unless you're doing something with those blocks, you don't have to make variables for them
Just do a world.getBlockAt(32,102,-64).setType(Material.OAK_PLANKS) instead. Halves your code size
Hi, I want to implement method to detect best suitable slot for specific ItemStack, what would be the best place to include this method? The best would be ItemStack, but I cannot reference NMS from Bukkit. Second best place I found would be PlayerInventory, but that is not the best solution IMO... The method I am talking about would be something like:
public EquipmentSlot getItemStackEquipmentSlot(ItemStack stack) {
return CraftEquipmentSlot.getSlot(EntityInsentient.j(CraftItemStack.asNMSCopy(stack)));
}
Yeah that's the problem with ItemStack or Material not being an interface
imho, Material with a switch statement
But don't worry! Choco is PRing that update to the Spigot development API.
Yea, I know you are preparing big overhaul of this, but do you think PlayerInventory would be good until then?
I always advise against that because i often see people getting confused by
stacked method calls. So allocating actual variables makes the code more clear in some cases.
Preference at that point 
Dawon,
imho, Material with a switch statement
and then write a CraftBukkit unit test to ensure it's accurate for all Materials according to that method
The new interfaces will be MaterialBlock and MaterialItem, with the block and item material references being constant registries.
deprecated
md wants compat between 1.13 - 1.16, so deprecated probably
k makes sense
I have to revisit that
Yea, that is exectly what I wanted to avoid, because this switch would have to be kept updated, while NMS have method just for this... :/
There are a lot of methods in Material that could be (and have been in my PR) simplified with a single method
Though we're stuck with that technical debt until I can get it merged
should actually just delete the class so older versions have to update to use newer plugins https://i.kym-cdn.com/entries/icons/original/000/028/577/pepelaughz.jpg
wand.getItemMeta().setLore(Arrays.asList("Left Click - Position 1", "Right Click - Position 2"));
wand.getItemMeta().setDisplayName("Claiming Wand");
return wand;``` why does this return a regular wooden axe
That was my original goal and is where the PR stands today, imagine
getItemMeta() returns a copy, Tom
you have to extract and set the item meta
o
Ok switch case in ItemStack it is then
Yeah, just be sure you're writing a unit test for it
ItemMeta meta = wand.getItemMeta();
// meta.***
wand.setItemMeta(meta);
mmm i see
Can I use the NMS method in the test, so the behaviour is the same?
CB sided test, so yes
ok, thank you!
Where do I have an error?
if(p.getInventory().getItemInMainHand())
Hey! I'm trying to verify if the block that is broken has specific metadata. I got this in my onPlayerBreakBlock():
String displayName = event.getItemInHand().getItemMeta().getDisplayName();
It's a snippet I found on the forum but the player will not get the item in hand as I'm changing it to air and giving them a new one with ItemStack. How can i check if the broken block has the DisplayName?
RE: Limey,
getItemInMainHand() is an ItemStack, not a boolean
Mekae, BlockBreakEvent#getItemInHand() probably returns null if breaking without an item but afaik that method doesn't exist on Spigot. If you're using a fork, you should be asking for support there
oh actually they don't even have that. lol. I don't know what you're trying to do then
Anyone know here if there is a better way to mitigate arrow drag in water? The only way im able to think of is making a new entity that extends arrow and overrides whatever method does it
Oh haha, the item is a hopper but ItemMeta I gave it (like displayname and lore). Now I have it set when you break the hopper it turns into air before it even reaches your inventory and dropItemNaturally(blockBroken.getLocation() will drop the one i've created with lore and all. This works fine but now all hoppers give the special item.
Use the PDC of the hopper to determine if its special or not
Hopper extends https://hub.spigotmc.org/javadocs/spigot/org/bukkit/persistence/PersistentDataHolder.html
declaration: package: org.bukkit.persistence, interface: PersistentDataHolder
I will look in to that, thanks!
I made a thing that spawns a mob and then make a EntityDeathEvent class in the same class and checks if the mob is the same and it works but if I walk away and come back after some time and just unloads the chunk when I come back it doesn't work
So a custom nms mob?
Yes
Then you need to register the type in the IRegitry class for your mob which is pretty complicated.
I'm on 1.8.8 does this still exist?
No idea. This version is half a decade old. Search in old forum posts for that. IRegistries where introduced a short time ago to push data driven architecture in minecraft.
Programmatically?
Found a 1.8.8 thread about it let me see if it owrks
To do what exactly?
Do I need to register every mob?
Every custom mob that should be persistent. And you should also overwrite the nbt serialization methods for saving persistent data in its NBTComponent. (save and load iirc) but dont forget to call super on them.
when does Block#getLocation return null
Never
it so just did for me
You need to load the world before teleporting there.
Use the WorldCreator for that
pretty sure
Strange
Worldloadevent might work
That would be very improbable. Then something made a custom implementation of the Block interface which would just be stupid unless you want to write unit tests.
declaration: package: org.bukkit, class: WorldCreator
It doesnt. He wants to initialize a load and not react to one.
7smile7 if it wasn't NMS how would I do it?
My prediction is that something returned a null Block which lead to a NPE for you.
In 1.8? You cant.
1.13+ has PersistentDataContainers where you can create custom mobs without having to worry about nms.
But 1.8 just lacks a ton of API features so you will have to dig into NMS quite often.
um ok so heres my error
Sure
the error is from my PlayerInteractEvent handler
but it shows up whenever I drop an item
The clicked block is null
not interact
i am so confused rn
like i press q and it says could not pass playerinteractevent
Pls show your listener method...
for dropitemevent or playerinteractevent
playerinteractevent
https://gyazo.com/1e2859271e6c6951febb90a991899c5f line 139 is the error
dooes this server help with NMS
Sure. If someone knows how to help ^^
But i personally only look into 1.16 nms
ah ty
e.getClickedBlock() might return null. A player could just click an entity or in the air. Then there is no block to get from the event so it returns null.
why is the method getting called when i drop an item though? is it a bug maybe?
Player interact fires when you drop items
If the player does ANYTHING it fires essentially except really chatting
if the slot is empty it returns null
nvm
just null check it
getType also cant return null. The Block you call getType on is just null.
does getType return Air now in the inventory?
i think so thats why i was confused
I remember it used to be Air then it was null, then it was some weird thing
I just threw like 3 checks in and called it a day havent looked at it since
like i can fix that null error smile but i still dont want it to say "land is claimed" if youre dropping an item
maybe i am just accidentally clicking the mouse when i press q
idk
Nope that event is fired when you drop an ItemStack. You should just check for some conditions like the Action type
hi !
wait no
i can have helps plz i create my first plugin and i need helps i have big problem :x
there is no drop item action
How do I find the offset that the block is at in terms of Y?
is that a psysical action?
Cause I'm spawning NPCS and if it's a slab or SNOW they're stuck mid air
hey guys, so I'm looking to make a PR to Spigot that adds the ServerTickStartEvent and ServerTickEndEvent from one of Spigot's downstreams, Paper, and I was just wondering, do I add this directly to the Bukkit repo? or do I make a patch on the Spigot repo?
1 dev plugins can helps me plz :x?
?ask
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.
@lost matrix dropping an item triggers RIGHT_CLICK_AIR Action
how to differentiate between the two?
@worldly ingot pls fix
i need /reload no stop for have my grade 😦 (rank)
Just a quirk of vanilla, can’t fix it
Or, rather, a quirk of the way we check for right clicking air
It just listens for when the arm swing happens
Is there a thing called block state location or whatever
Or do I need to manually hardcode the offsets of y of each snow layer, slabs, etc?
Could be a million things. But if you just started coding then you should not try to support reloads. They are unsupported and break stuff all the time.
If I just do ItemStack#addUnsafeEnchantment(Enchantment.DURABILITY, 1); - That should render the enchantglint, right?
Yes. If you add an enchantment then the ItemStack displays the enchantment glow.
Strange, all I'm doing is this: https://bin.bloom.host/kisuwidive.lua and it doesn't add the enchant
You can ray trace below the npc and get the distance to the next surface or just hard code Materials which cause problems.
ItemStack wand = new ItemStack(Material.WOODEN_AXE, 1);
ItemMeta meta = wand.getItemMeta();
meta.setLore(Arrays.asList("Left Click - Position 1", "Right Click - Position 2"));
meta.setDisplayName("Claiming Wand");
wand.setItemMeta(meta);
return wand;
}
public static boolean isWand(ItemStack s){
if(!s.getType().equals(Material.WOODEN_AXE)) return false;
if(!s.hasItemMeta()) return false;
if(s.getItemMeta().equals(getWand().getItemMeta())) return true;
return false;
}``` can anybody tell me why the second boolean function isn't returning true
Can I store something gotten statically from the Bukkit class in a static field. I'd assume Spigot makes sure to load the classes when state is safe, right?
Or is there some state there
In some occasions you will get weird errors when initializing anything Bukkit related statically.
Becasue the metas dont match up exactly. So maybe the durability differs? Or there is some other tiny difference.
Use PersistentDataContainer of an ItemStack to define custom items.
Why do you want to allocate a static PluginManager variable? I dont see any reason for this.
static PluginManager pluginManager = Bukkit.getPluginManager(); pls dont do this ok thanks
Yes. For obvious reasons.
Check the portal enter event and send the player to the custom nether if he is currently in the custom world
Using the WorldCreator class with the Environment set to NETHER
ItemStack mainhand = p.getInventory().getItemInMainHand();
ItemStack lefthand = p.getInventory().getItemInOffHand();
if(mainhand = Material.AIR){
}
why is there an error in if(mainhand = Material.AIR) ?
Nevermind
but correct me anyway
- An ItemStack is never equal to a Material
- Use
==or in most cases.equals()
Put == not =
thx
or air
which one is better lol
Apparently it was an issue with the metadata
Item is an entity so you just call .remove() on it
thanks
Oh yea. You added an enchantment and after that, you replaced the ItemMeta with the one that had no enchantments on it..
can anyone here tell me where I can get org.spigotmc:minecraft-server and org.bukkit:bukkit from? trying to contribute to CraftBukkit but it's missing those dependencies
do I need to download and apply mappings to the official server JAR then add it to Maven Local? if so, what about the Bukkit dependency?
<dependency>
<groupId>org.spigotmc....</groupId>
<artifactId>spigot</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
spigot-api iirc
anyone know why i can't find this dependency?
I'm trying to contribute to CraftBukkit remember, not Spigot
because it's not public
its spigot-api, right?
i've do it, but it doesn't find nothing
you sure you want the server, not the API?
You need to run BuildTools for the version you are using. Any reason why you use 1.16.4 instead of .5 ?
and this ^
yeah i've builded 1.16.5 and i put them in a lib dir, but it can't find anything
What do you mean by " put them in a lib dir"
BuildTools installs the spigot artifact into your local maven repository.
This can be accessed by maven to resolve dependencies.
If you use maven then you should not add any libraries by hand and only use the pom.xml for that
okay ty!
I made a thing that spawns a mob and then make a EntityDeathEvent class in the same class and checks if the mob is the same and it works but if I walk away and come back after some time and just unloads the chunk when I come back it doesn't work (NON NMS)
How do you check of the mob is still the same? Show some code pls.
?paste
https://paste.md-5.net/kakuhodoru.java (The Class)
You should never register events dynamically. The whole event handler list has to be rebaked each time you register an event. And it can lead to memory leaks really fast.
Register one Listener that delegates the event to every other class that needs it.
Now
This will be false when the entity unloads and then is spawned again because its now a new instance of the Entity class and has nothing to do with your allocated variable anymore.
e.getEntity() == getEntity()
Having hard references to an Entity is a bad idea in most cases and should be avoided. Just use the UUID for comparisons.
You just allocate the UUID of your mob and then check against it. If you need the instance of the mob then you can get it from the static method the Bukkit class provides where you can pass a UUID
Dont register a ton of listeners and dont have a variable of type Entity.
do you guys chain methods? im wondering when should you chain methods and when you should not. I've saw some method chaining in builder classes but should you do in normal classes? Anyone have a rule of thumb? Just trying to get the clean coding practises
Create one Listener class that delegates the events to a single manager class which holds a Map<UUID, Mob>
Ah... I may want to remove my dynamic listener registration then
nvm
How would I get the Bukkit class provdires where I can pass through a uuid?
i dont really understand the persistentdatacontainers. why is there no boolean
Chaining methods is ok if none of the variables in the process is re-used again.
But as soon as you see a chain twice you should allocate new variables.
Also if you exceed the character limit of around 130 chars per line you should allocate new variables.
If it makes the code more clear then you should also allocate new variables.
So in most cases i would not chain method calls.
Or has(), set for true, unset for false
what do you mean by "allocating new variables", and also wdym about char limit
oh nvm
sorry excuse the shit screenshot i had to use printscreen
this is when i use BYTE and 0 or 1
meta.getPersistentDataContainer().set(key, PersistentDataType.BYTE, 1);
(byte) 1
ty
I guess you could make a boolean type too if you wanted
now when looking at items for this new persistentcontainer do i need to do a check for the key before i use get ?
or will it just return null
null
How can I simulate right click event in spigot 1.16.4?
You can call it manually
PlayerInteractEvent#getAction
Alright, ill search some more about it and return if i have any more questions
im deleting
if (byte == 1) {
//true
} else {
//false
}
I am a newbie, can anyone help me real quick?
if (e.getItem().getItemMeta().getCustomModelData(1)) {
//code
}
How do I make the code to check the item's custom model data?
Basically if a item has custom model data 1, it will do stuff.
Thank you!
It returns an integer, you can just compare it
ok i still don't understand your statement
Ah
Can you give an example please?
does getPersistentDataContainer() return null ever (besides on air)
You may want to learn java before making plugins
#ItemMeta.getCustomModelData()
if (xxx.getCustomModelData() == 1)
Plugins should check that hasCustomModelData() return true before calling this method
Thank you so much
That's my way of learning 😬
Yea i've done that
ItemMeta meta = e.getItem().getItemMeta();
if (meta.hasCustomModelData() && meta.getCustomModelData() == YOUR_MODEL_ID) {
//your logic code
}
Learning java with an external API isn't recommended
Thank you
@young knoll ikr, can't resist
Works like a charm
ItemStack wand = new ItemStack(Material.WOODEN_AXE, 1);
ItemMeta meta = wand.getItemMeta();
assert meta != null;
meta.setLore(Arrays.asList("Left Click - Position 1", "Right Click - Position 2"));
meta.setDisplayName("Claiming Wand");
meta.getPersistentDataContainer().set(key, PersistentDataType.BYTE, (byte) 1);
wand.setItemMeta(meta);
return wand;
}
public static boolean isWand(ItemStack s){
if(!s.getType().equals(Material.WOODEN_AXE)) return false;
if(s.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.BYTE) == 1) return true;
return false;
}``` ok i added all the persistentdatacontainer things. i think its wrong cause my method is still returning false
removed unnecessary checks
This example:
public void handleEvent(final PrepareItemCraftEvent event) {
final Recipe recipe = event.getRecipe();
if (!(recipe instanceof ShapedRecipe)) {
return;
}
final NamespacedKey recipeKey = ((ShapedRecipe) recipe).getKey();
final CustomShapedRecipe customRecipe = this.customShapedRecipeMap.get(recipeKey);
if (customRecipe == null) {
return;
}
customRecipe.handlePreparation(event);
}
There are a lot of variables that dont need to be there. But just to make the code a little bit more clear i created
extra variables with expressive names to make sure everyone that reads this code can understand what it does.
Wait why doesn't the regular recipe have a getKey
are we sure that we're talking about the same thing?
Ah... MerchantRecipe
i meant something like
SomeRandomObject randomObj = new SomeRandomObject();
// both methods manipulate SomeRandomObject fields and return the instance of the object
randomObj.method1();
randomObj.method2();
vs:
SomeRandomObject randomObj = new SomeRandomObject().method1().method2();
i think you meant recursion by your example
I use the second version with builders
same
but i'm not sure if its doable with normal classes
not with utility ones like builder
Technically the first one will only work if it's a mutable object
It's doable if they return themselves
If the method returns the object it's generally because it's designed to be chained
Oh. Thats only used in builder patterns.
yea i use it in my builder classes too but thought if it was practical to use with data classes
but i think not
but technically possible
Its not used outside of the builder pattern because that would support many bad habits like side effects and its really hard for some clean code patterns to be enforced in that type of structure.
hey smile could u take a look at the isWand method i did again? i remade it to use persistentdatacontainers
Has anyone had any issues with PlayerInteractEvent and berry bushes? Looks like even if the event is cancelled, you can get the berries if you right-click and left-click at the same time.
I would just call hasKey on the PDC. So:
public static boolean isWand(final ItemStack itemStack) {
if (!itemStack.getType().equals(Material.WOODEN_AXE)) {
return false;
}
PersistentDataContainer container = itemStack.getItemMeta().getPersistentDataContainer();
return container.has(key, PersistentDataType.BYTE);
}
There is an event for berry bush harvesting i think. Try this one:
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerHarvestBlockEvent.html
ok ill try that thanks
Oh, thank you so much. I didn't know about that event. I'll try it right now.
How would I do this?
Looks like PlayerHarvestBlockEvent solved the issue. ty
how do i register commands in kotlin?
Bukkit.getEntity(uuid)
I did some research but I couldn't find anything about this. How can I simulate right click event? Like, make the player click mouse right button. Basically something like:
player.rightClick()
You'd have to manually fire teh click event and use packets to run the animation on the client
Using the net.minecraft.server.v1_16_R3.PlayerInteractManager field of the
net.minecraft.server.v1_16_R3.EntityPlayer instance
Looks like a promising start. It has methods like:
Maybe this method
I am confused at why this isnt working
Sick, thanks
Crafting is the 2x2 crafting field in the players inventory. And there is no way to detect when a user opens his own inventory
I have one question
Hey, Does anybody know where I can find some guide/tutorial/example how to write something in a file? I need to write an exact location of a block and A username/uid in a file.
so whats the crafting table type
are all data types objects?
like strings, int, etc
oh workbench
ty
Would this work?https://paste.md-5.net/zubonixoka.java
@graceful turret You asked this yesterday, the answer is still the same.
just create the command and register it
no i didn't
lmao
maybe i asked about it month ago
bo i 'am not sure
not yestterday
on this topic how do i register a command in kotlin?
hey so going from craftbukkit.v1_16_R2 to R3
An error pops up when i do that
CraftMetaBook no longer contains a list of IChatBaseComponents for its pages
What is that error?
instead it's just a list of Strings
does this mean BaseComponent support in books is just gone now?
still returning false
I have a chunk of code that I've been using for years that renders a bunch of data into a book with hover and click events
trying to update it to 1.16.5
maybe im not setting it right?
hey how can i make a simple headlist and footer tablist with 1.12.2 spigot?
Then the tested item is either not a wooden axe or does not have the container entry
because i cant find IChatBaseComponent or anything like that
i cant register the command in kotlin
and i don't know why
I've got this
getCommand("hello").setExecutor(CommandHello())```
@lost matrix ```public static ItemStack getWand(){
ItemStack wand = new ItemStack(Material.WOODEN_AXE, 1);
ItemMeta meta = wand.getItemMeta();
assert meta != null;
meta.setLore(Arrays.asList("Left Click - Position 1", "Right Click - Position 2"));
meta.setDisplayName("Claiming Wand");
meta.getPersistentDataContainer().set(key, PersistentDataType.BYTE, (byte) 1);
wand.setItemMeta(meta);
return wand;
}``` Here is the code for getting the item. Im pretty sure I set the entry right
Looks fine
tis a longshot, but does anyone in here happen to know how to add hover and click events to books as of 1.16.5?
Using exactly your code
is what i forgot
classic
yup
sorry for the trouble lol. at least i know about the persistentdatacontainers now
Not sure if this is still up to data:
https://www.spigotmc.org/wiki/interactive-books/
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
But the api methods are all still there
nope, no longer up to date
as of the R3 varient of craftbukkit
CraftBookMeta no longer has a List<IChatBaseCompoennt>
is List<String>
https://gyazo.com/16b3c8b7e4a5df01099eb953d16813d0 shouldnt this say final at the end
or maybe my code is even older than this and has been doing it with reflection . . .
give me a few I'll see if this method works instead
Works just fine for me
hey smile, my claim wand methods are static that's not "static abuse" is it?
Eh. They are stateless so its on the verge of being still fine.
Not abuse but discouraged. Its more tolerable if the rest of your design shows
that you understood the implications and dangers of the static keyword and actively decided to use it
and not just threw it in so your code works in the first place.
But it would be better to make them not static and instantiate a ClaimWand instance to use the methods?
sorry for confusing wording if it was the class is just called claimwand those methods are in
Not in this context. ClaimWand.getWand() and ClaimWand.isWand(ItemStack) are understandable methods.
The problem is that this approach is very unmalleable. So if you wanted to create new items then you would
probably either have to re write everything or violate clean code principles like DRY
Hey, I need help using a List<Entity>
Pretty much what I'm trying to do is remove AI and Awareness from all entities when a new chunk is loaded. I know that my current code doesnt work because List<Entity> doesnt work as I wanted it to so I'm trying to find another way to do it or a possible solution. Anything will help, thank you :)
- You are currently getting all entities in the world whenever a chunk is loaded.
- You cant cast a collection of entities to a single LivingEntity. Makes no sense.
- This looks like you didnt take your time to learn the very basics of Java before jumping into Spigot
Iterating a collection or an array is no witchcraft and still counts as fundamental knowledge.
yeah my code is very old (older than the Component api) so I guess I just need to update it to use the Component api
this looks like It's a much nicer way of doing it anyway
@lost matrix how do i make tablist on 1.12.2? spigot
- Intentional
- I know, that's why I came here
- Its been a few years since I've done anything Java related, my bad. I'll go back and look into arrays and collections and see if I can figure something out.
I have actually no idea... ive started programming with 1.13 or 1.14...
So all i can do is point you to the javadocs
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Player.html#setPlayerListHeaderFooter(java.lang.String,java.lang.String)
If this doesnt apply to you then you will probably just have to send the header and footer package yourself.
They are really simple.
wait theres something like that function? ty
i was trying to do the ichatbasecomponent thingy like and it just said cnf
ty
I think in 1.12 they had the same methods with just BaseComponent[]
So using the ComponentBuilder this should be quite easy.
can someone explain this phenomenon: Integer.MAX_VALUE + 1. What does this do? Overflow the Integer, and what then? I saw this somewhere being used
does it return random int or what?
wouldnt it return the MIN_VALUE or smtng
tho its a shame java doesnt have unsigned int etc
Yes, it would overflow to the minimum value
All this is doing is overflow. So int hex it would look like:
0xFFFFFFFF -> 0x0
And in binary it would look like this.
1111 1111 1111 1111 -> 0000 0000 0000 0000
In actuality java does preserve the sign bit. So the memory representation is:
1000 0000 0000 0000
Which is just MIN_VALUE i guess...
thanks wikipedians
lol
nvm this gif is too weird
I'm trying to edit signs and setting lines with Sign#setLine but it doesnt seem to update it
might have to explicitly call update
You need to set the BlockData after editing the sign
ah ok
oh nvm thats for BlockStates
I think the BlockState thing is deprecated... im not sure which one is right actually
why cant a nonstatic method be in a constructor
It can be there if its in the same class.
trying to call it from another
I think Conclure is right. Try calling update(true) on the TileState
im trying to rewrite my entire plugin
Then you need to pass an instance of the class you want the method from in the constructor
7smile7 how are you always online helping random people?
honestly every single time i get in here i see you helping someone lmao
respect
the goat
Im just studying/writing code because i have 100% online lectures. And helping here lets me discover interesting things and strengthens my knowledge. But im not always here.
There are a lot of guys without a live on here like ElgarL and Conclure. (jk)
if (!(sender.hasPermission("sb.help")) || (!(sender.hasPermission("sb.admin")))) {
sender.sendMessage(ChatColor.RED + "Missing permission:" + " sb.help");
return true;
}
Player player = (Player) sender;
sendHelpMessage();
return true;
}
private void sendHelpMessage(Player p) {
TextComponent helpMsgTest = new TextComponent(ChatColor.GOLD + "§l/sb test§r" + ChatColor.WHITE + " - " + ChatColor.AQUA + "Tests plugin & config.");
helpMsgTest.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sb test"));
helpMsgTest.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("/sb test").color(ChatColor.AQUA).create()));
p.spigot().sendMessage(helpMsgTest);
return;
}
'sendHelpMessage(org.bukkit.entity.Player)' in 'com.lethalflame.teleportationball.Commands.SwitcherCommand' cannot be applied to '()'
gotta send the help message to someone, doncha?
hey smile. Would a hashmap containing all players/factions be OK for being static? I feel I would use it a lot in other classes. maybe not idk
You would normally create a wrapper class for this. Like a manager class of which you create only one single instance and
that contains the data structures you need. Then you make sure to never expose the collections and only provide higher level methods
for modifications like "setPlayerFaction(Player, Faction)" or "getPlayerFaction(UUID)" and so on.
Why static? I mean it would work with it being not static also?
Having it non static would probably help loosely couple your code nvrtheless
so I made the wrapper class. Now say I have a class to handle some events and a class to handle commands. Does each need a separate instance?
or the same one
wait it would be the same
or the data is different
how do i make 1 and use it in all the different classes
Everyone needs the same instance. Two different instances would access two different Maps, which would be bad.
So you create one instance of your Manager class in the onEnable() method and then pass this instance to your Listener
and Command classes.
next level entrepreneur
What is a singleton
how would i make a plugin that deletes files in other plugins files
like
im trying to make a command
that resets your progress
in survival
ur money
ur mcmmo skills
ur claims
etc.
use API's not delete files
wdym
all those plugins have an API
true
you deleting their files will only break things
okay ill do that
How would I parse relative locations in my commands?
Is there some utility for this
ur talking about reading the ~ ~1 ~ stuff?
Yep
idk
brigadier probably
You can use a simple String parsing approach. Check if the first character is ~ then use the players coordinate as relative offset
to the followed parsed Integer String (if present). Otherwise use global coordinates for one of the given input.
But you could also check how its done internally.
Or use brigadier...
For some reason I can't see the sources
I can just see the interfaces
Maybe I imported the API only somehow?
Are you using maven?
How would I add 1 to the z coord if I have the location? Lets say the location is 100 100 100 and i want to make it 100 100 101
how would I do that?
I am using Maven
Then you need to change the artifact from spigot-api to spigot
loc.setZ(loc.getZ()+1)
location.add(0, 0, 1)
or what elgarl said
Both work the same
How to set the speed a particle gets removed at?
tysm
there isnt one
its when the chunk is unloaded i think?
Hello, i have multi module project for have multi platform support (bukkit & bungee).
I want to use ACF for create my commands but i don't find how i can shade it into my final jar.
I have that in an sub-module i use for merge all together : https://paste.md-5.net/fuwaminixo.xml
In specific platform i have :
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-paper</artifactId>
<version>${libs.acf}</version>
</dependency>
I shade all sub modules (common, bukkit and bungee) in only 1 jar but that jar doesn't contain my dependency.
I need to specify that dependency in my module i use for shading projet ?
Thanks
why not a single project? bungee and spigot cohabit just fine
I'm not too sure, the javadocs somewhat do suggest it, so I'd just look if it works
I don't believe it does.
No. It just spawns a new entity. You need to transfer the PersistentDataContainer to the Snowball in order to keep checkable data.
How would I do that? Would I do that when creating the itemstack and giving it to the player?
The ItemMeta has a PersistentDataContainer which can hold data. The same goes for Entities. They also hold a PersistentDataContainer.
So you need to write data in the ItemMetas PDC, then listen for the event that fires the snowball and transfer the data to the PDC of the Snowball.
ok ty
Is there any way to get player name from a player head block?
im trying to get block data ect and i cant find where its at
declaration: package: org.bukkit.block, interface: Skull
return (((long) x) << 32) | y; merges two integers into a long, right?
Uhm. No?
No
I think not
Does this even compile?
Yes it does. But i think it might mess up the sign bit.
return (long) x & 0xFFFFFFFFL | ((long) y & 0xFFFFFFFFL) << 32;
This preserves the sign bit of both
Is it bad to host multiple minigame instances on one spigot server
is it possible to mix java button key click actions into the minecraft game
like if i were to be like something like
if (sender instanceof Player) {
//if has item in hand ,
// if player presses B key{
//player event happens
}}
No a lot of servers do that like hypixel
hi, how can I call a class with the parameter set<EntityType> targets ?
(in java)
make a set and put EntityTypes in it?
@sullen marlin what is a good client mod in your opinion
idk
wdym
I dont get your question
I have an example java programm with that class:
private TargetNearbyEntityGoal(NPC npc, Set<EntityType> targets, boolean aggressive, double radius) {}```
so I call it by doing ```TargetNearbyEntityGoal(npc,???,true,radius)``` where npc and radius are variables but idk what to put at the ???
A Set containing the EntityTypes to target
make a HashSet, add the types, pass it in
this may be a dumb question but are forge mods able to mix with spigot mods
no
oh ok thx
one more question thank you for all the help md_5 if im trying to make like a mini map or a special custom gui or something like that would it have to be in forge
Define "mix"
They can communicate (client mod with spigot server) but i dont know of any stable software that runs both forge mods and spigot plugins.
There are some but they are far from stable.
Yes. Thats all client side.
is there what plugin that allows illegal enchants to work with essentials? ex. /eenchant protection 5
define "connect"
Your client already gets all the information it needs to create a map. There are many minimap mods that you can use on any spigot server.
well im learning java and im trying to make a complete server from scratch kinda like a game so ill understand java. As well as im building a resume; but ive been reading the docs for spigot and watching a bit of videos. I am also trying to add lots of interactive like player examining items in hand and custom guis and anything you could really imagin that you would see in a real game like a fps. but i want it all on a server
@lost matrix
should i be looking at forge
im also wondering if this is possible to connect evrything back and forth through a website
Yes. But Spigot is not that beginner friendly and forge is very not beginner friendly.
No idea what you mean by "make a complete server from scratch" but you will run against
a wall for at least 2 years if you jump into such a big project without prior knowledge.
Take it slow and learn the basics step by step.
i have prior knowlage
ive been working with java script json 2 years and learning basics for java for like a month
so im just trying to understand what i should use 🙂
ik
spigot > forge if you are new
hm
any reason this doesn't work?
public static boolean LogEvents = Util.getConfig().getBoolean("Debug.Log Events");
where Util.getConfig() is defined as:
public static FileConfiguration getConfig() {
return getPlugin().getConfig();
}```
and getPlugin defined as:
public static Plugin getPlugin() {
return Main.getPlugin();
}```
my config contains this:
Do you get any exceptions?
nope
the space. It's non-stanvard YAML
that YAML was generated by spigot
Ah i see. the yml is deformed and your ide even tells you that
either do Log_Events or "Log Events"
PlayerData or Player_Data or "Player Data"
no i mean, that's working fine
when i get the configs
i was just showing rainbow indentation there
Change it to LogEvents and see if that works
is there what plugin that allows illegal enchants to work with essentials? ex. /eenchant protection 5
k thx
# Allow 'unsafe' enchantments in kits and item spawning.
# Warning: Mixing and overleveling some enchantments can cause issues with clients, servers and plugins.
unsafe-enchantments: false```
config.yml
tfw i found why my code doesnt work
i screwed up my biuld script
tfw my build script doesnt work anymore
it no longer copies my plugin.yml
okay cool, fixed it
k f
nvm
does PersistentDataContainer#set(key, boolean (as string)) convert the string to a NBTTagByte?
it keeps telling me whenever i save a boolean as a string it is a NBTTagByte
very strange
Do eclipse and intelij code look different? so if i used a intelij tutorial would it work on eclipse?
They have different colors but the function pretty much identical
I like intelij better because it has a Minecraft plugin that makes the plugin yml for you and imports spigot
ok thanks for the help
Hey all
Anyone know of a way to mitigate arrow drag in water?
It is effected by a 0.6f multiplier per tick in water
and it doesnt seem to be in AbstractArrow or Arrow
is that on the client?
EntityArrow almost last call in tick()
Maybe try overriding that, by just calling super.tick() and just adding the motion upwards afterward?
heyhey I'm trying to make a custom potion where when the player finishes drinking it, it will make them completely invincible to all damage for 10 seconds. Right now, I'm having trouble finding the name of the event when a player drink a bottle
public static void onPotionDrink(EntityPotionEffectEvent event) {
Player player = event.getPlayer();
}
}```
this doesn't work at all btw, I'm just trying to find it
oh adding onto that, you could also just override isInWater to always return false, would also mean that the bubbles disappear but who cares
oh ok
++num increments the variable before using it, right? and would it keep it incremented if i put it in an if statement?
ie java if (++num == 1) { something; } else { //num should stay incremented, right? }
I think you might want to use PlayerItemConsumeEvent for that.
oke will check it out
@summer scroll I'm not quite sure where to go from here, like this line below checks if the item is the custom item, right?
Player player = event.getPlayer();
if (event.getItem().getItemMeta().equals(ItemManager.deus.getItemMeta())) {
}```
but how to I check when the item is consumed?
it is consumed in that event
oh okay, so it basically already checks that it's been consumed
it does check, it gets called when it gets consumed
riiight, okie thanks!
and is there a way to add the GENERIC_KNOCKBACK_RESISTANCE attribute (the one on netherite armor) to a temporary potion effect?
because I am making a potion which temporarily gives resistance 5 for 10 seconds, and I'm wondering i could put a temporary armour attribute too
you can probably do some packet stuff but you cant add armour attribs to potions iirc
Yeah you would have to add it to the player and then remove it with a scheduler
yeah that makes sense, it seems quite daunting to me as I'm very new to this
I can see a lot of problems that I don't know the language/syntax to work around
like what if the player has full set of armor on? things like that I still can't wrap my head around because I barely know the language haha
guess I'll have to leave that for another day
What about the armor?
armour maxes out anyway so if you set it over the max value it pads itself i thinkl
if not oyu can just use Math.max
like I think I'd have to temporarily replace the player's armor with a piece which gives the player knockback resistance 100 or something, then give the existing one back when the timer is done
which I have no clue how to do, but that's not important now
You can add the attribute directly to the player
what, fr?
but is it possible to do it temporarily, or do i need to add scheduler
You will need a scheduler
right, i should learn how to do that then
oh god dont use item meta to compare
give it a tag in the PersistentDataContainer and check for that
oh ok
or nbt
I'm guessing using item meta to compare will lag the server if there is a shit load of stuff
if someone renames an item it will stop working
never heard/seen a case of it being iffy?
pdc is just nbt using the spigot api. And its not really practical for raw usage but you can
always build your own wrapper classes to make it pretty.
also how do you setColor for a potion using item meta?
I think by setting the base potion
ItemStack item = new ItemStack(Material.POTION, 1);
so this part right here?
Yo smile. Remember when we were talking about the wrapper class that I will instantiate once to use in other classes
If I wanna use it’s methods in a class that gets instantiated many different times how do I do that. Should the one instance of the wrapper class be static?
You can make the instance of your manager static. This is then the typical singleton pattern.
But there is no shame in passing this variable to other classes even when they get instanciated a lot.
You dont actually copy the whole instance but only a reference to the instance. So the memory impact is very small.
Are singletons bad? That’s what I was getting from chocos post
Nope. They are not inherently bad. But using dependency injection just forces you more to think about your design.
(dependency injection or in short di is accomplished by passing the reference to constructors for example)
But its not always practical. I would stay with the static singleton instance for now 😄
Ok thanks
public void onEnable() {
new BukkitRunnable() {
@Override
public void run() {
for(Player player : Bukkit.getOnlinePlayers()) {
resetCps(player);
}
}
}.runTaskTimer(this, 100L, 1);``` Do I have to put this in my main class, or can I put it in my listener class.
You can also create a new class, name it ApacheAttackHelicopter and put it in there if you want to.
Just make sure that you pass your JavaPlugin instance where you are currently using this
yeah. I just needed to put something there for now
It will be an instance of my Main class
Far too often I see static being used to access a field from another class, particularly Collection and Map implementations, as well as an instance of the main class. This is a common mistake for new developers and poses some serious issues in terms of code design and flexibility in the future. how do i avoid making a static instance of the main class. to do runnables for example
he doesnt really say in the post
di
Should I create a new package or just a new class along with my listeners.
oh wait for runnables
By using dependency injection. Meaning you pass your JavaPlugin instance to other classes using their constructor.
This can be done by referencing the current instance you are in with this. Commonly done in the onEnable() method.
I have no idea what you are trying to do actually.
Make something happen every 5 seconds
Ok cool. And you said dependency injection didn't really affect performance with many instances of the class right? Cause its just the reference
I don't wanna just shove it all into my main class
Right.
for people who use protocollib and 1.16.5, does multiblockchange packet work for you? I seem to get an error. if anyone can help me dm me
what error are oyu getting
what happens when you pass in null to HashMap#remove()
hey guys. just having a question.
what ways exist, to change a players displayname (just the name above their head)? obv. there is a setDisplayName and a setCustomName - are there any other?
seems like a question for viaversion
so how can they dupe the items with a runnable?
like
I would make something like this:
one second
@EventHandler
public void menu(PlayerSwapHandItemsEvent e){
Player player = e.getPlayer();
if(!player.isSneaking()) return;
ItemStack mainhand = e.getOffHandItem();
ItemStack offhand = e.getMainHandItem();
player.openInventory(PlayerMenu.build(player));
Bukkit.getScheduler().runTaskLater(RPGCoreHoof.instance, new Runnable() {
@Override
public void run() {
player.getEquipment().setItemInOffHand(offhand);
player.setItemInHand(mainhand);
}
}, 5L);
}
like this @drowsy helm
but I actually don't understand why cancelling the event doesn't do the job, it should
but I actually am being dumb
I shouldn't pick the items before the schedule
I should pick the items from the player's slots during the scheduler
it should prevent duping or something like that
but that's not ideal :/
user player.getInventory.setItemInMainHand()
I used .getinventory() and stuff
yeah
hmm i dont see why it wouldnt cancel tho
me neither
gradle question, how can i include resources?
do you need a runnable to swap them back?
what do you mean by resources?
default config.yml files are resources
plugin.yml
yes
if I want this behaviour to happen, yes
or I should swap them before the swap happens
it's even smarter lol
lol that's what I will do
you can try lol
yes im using intellij, and have the gradle plugin enabled
resources should be in your root
none of these are being included
my plugin.yml also exists in the java folder, doesnt work either
just download the minecraft extension
it makes a default project
with everything set up
even the shade plugin from maven
that uses maven doesnt it
space wants to use gradle
why
so the plugin yml shows up in your root folder but spigot isnt recognising it?
no, its not in my root folder at all
gradle has some benefits over maven, they asked a question relating to gra dle
jar task:
sorry, sorry
like what benefits? I'm curious now
depending on the benefits I will switch
makebukkitjar:
do you have a sourceSEts thing yet
What’s harder? Coding plugins, or coding Minecraft mods?
coding mods is harder
coding mods definetly
Ah alright
but currently both are easy
because of the abstractions and great API's
don't feel unmotivated just because mods are harder
update: after a lot of fiddeling:
you can learn both, I'm sure
I heard 1.16 mods are hard to program
time to clean up
Are they in anyway similar?
somewhat
but barely
plugins scrape the surface of what is possible, but are accessible to way more people
mods can achieve a lot but not many people might play it
you can achieve a modded experience with plugins but it takes alot of knowledge and resource packs
and obviously it would be much less optimised
i finally have a proper-ish build env
Have you tried looking at the docs?
?jd
package index
wouldnt that fire PlayerMoveEvent?
slow down i legit barely know java
Learn some java first, it helped me out quite a bit.
i went batch -> java -> C#
and now im back to java because plugins
imagine if i made a dotnet plugin interface
package index
thanks
how do i find connect it to plugin?
I'm trying out scheduling for the first time so please bare with me 😅
show full code
You need an instance of your main class
To be exact, the instance of your main class
excuse me, UHCumEvents?
I'm really stupid, I don't know the basics of coding nor the terminology, how do i do that?
haha yes do not mind the names i'm giving the plugin it's all part of the server
I would say learn java first
But nevertheless, pass the instance of your main class through the constructor of your event class
class MyClass {
public void doSomething() {
A a = new A(this);
}
}
class A {
private final MyClass c;
public A(MyClass c) {
this.c = c;
}
}
@R053#8187
@haughty haven
thats dependency injection, or DI
oh okk, but my main class is in a separate java file
like, I don't really get how to link between files
it doesnt matter
is it the stuff at the top?
import com.r053.uhcum.items.ItemManager;
I see things like this pop up at the top, but it happens automatically
Java tutorial for beginners - Learn Java, the language behind millions of apps and websites.
🔥 Want to master Java? Get my complete Java mastery bundle: http://bit.ly/2tKoy8C
👍 Subscribe for more Java tutorials like this: https://goo.gl/6PYaGF
📕 Get my FREE #Java cheat sheet: http://bit.ly/2JNlQnw
⭐️ Want to learn more from me? Check out thes...
so I don't actually know what happens in the back you know
lmao
Java tutorial for beginners - Learn Java, the language behind millions of apps and websites.
🔥 Want to master Java? Get my complete Java mastery bundle: http://bit.ly/2tKoy8C
👍 Subscribe for more Java tutorials like this: https://goo.gl/6PYaGF
📕 Get my FREE #Java cheat sheet: http://bit.ly/2JNlQnw
⭐️ Want to learn more from me? Check out thes...
not
just learn some java
import your class
its not letting me though
i do and it wants me to make a class in the in the actual code
lol
stop pls
stop what?
watch the java course, itll teach you everything you need to know
hey guys. just having a question.
what ways exist, to change a players displayname (just the name above their head)? obv. there is a setDisplayName and a setCustomName - are there any other?
also spacedash is laughing with you not at you
customname i think
regardless
you can also use teams
yikes
Bruh ive never used this crap before lmfao
"crap"
yes
welcome to programming and logical thinking*
fucking automod warning me for talking
nah i mean, at least the c# compiler points out "hey you cant make an instance of a variable"
can anyone figure out why my mending code doesnt work?
hey i mean for a first plugin, i think when you mine a diamond ore it drops 100 oak buttons is pretty dope
eh
Datapacks can do that
its mostly a test btw
i want to learn so im starting easy
this is my first plugin lol
and thats fucking hard
1.6mb 😂
yeah what about it lol
okay so one last question
i think ill be good to continue toying with this once i know this
why is it red
player does not exist there
because what player
Because you don’t have a ;
cant just pull a player outta ya ass
or can I
so what do I do?
r/suddenlyhomosexual
lmao
is this in an event?
wait no
show all of your code
define the player variable 
event.getPlayer
cant just pull a player outta ya ass
Player player = event.getPlayer();
Player player = event.getPlayer();
do you not know Java?
nope 😛
👀
im trying to learn but its not going well
Learn java, you are doing yourself no favours trying to learn it with a third party API
go watch
ReturnType myVariable = (someValue);
myVariable.hasFunctionsToCall();
// This is a comment
I am fluent in ass assing
- unnessesary brackets
- make it one line lol
i think you missed the part where i said "imma teach you java syntax rq"
Why make it one line when it obviously is meant to show them what it is
horrible formatting wtf
autoformatted
Nice staircase
📉
and horrid nesting
xD
lambda where?

no because event doesnt exist
cant just pull event outta ya ass
who doesn't use lambda for runnables
OR CAN I
dummies
since when does java support lambdas?
since forever
how the fuck do i do this bullshit
No
ive tried using lambdas in java and it just doesnt
with java 8 comes lambdas
a.b(C::method);
Java 8, or 1.8, or class version 52