#help-development
1 messages Β· Page 1468 of 1
creating your own connection pool isn't hard at all, what is hard is keeping it optimal and not over bloated or keeping the speed up whatever your requirements are π
^^
Is better use a library for that
For doing async tasks, executors and all those stuffs, is not so hard
And performance is not affected at all if you know what you're doing
No need a library for that
the server will keep the spawn that is set loaded @vestal dome not sure if its possible to have a world loaded without atleast having a single chunk loaded lol
Hey good point.
Sadly mc can't be made totally async because is not totally thread safe
how does one check if (args.length == 0) {}, as everytime I try it says "this statement is always false"
@vale cradle no game is completely async anyways. At some point even with async you need to synchronize somewhere at some point π
I mean, comparing to web world xD
Async libraries in those cases are godlike
In minecraft, having a good simple implementation should be enough
well web world stuff is different
I ended up getting it a week ago thanks for recommending it is so helpful
It wouldβve taken me like a month to get on my feet the way the course taught me
@vestal dome use the async chunk api
and don't use the console sender for logging
use your plugin's logger
if you want to do stuff with chunks that are normally unloaded, add a plugin ticket to keep them loaded
instead of repeatedly loading and then unloading them
Yes, that's why you shouldn't be bothering about what does a library and whatnot, just do it, 5m to an async implementation
Worthless...
This is me just testing.
there's NO POINT.
further more, What the hell do you mean by "async chunk api"?
well if you ever do it for realsies, do it properly
How would I go about creating a constructor without creating a new instance of that class?
That is not gonna be in a public version
that IS LITERALLY
FOR TESTING PURPOSES
u kidding?
are you really gonna argue over such stupid reason?
well again, if you ever do it for realsies, do it properly
wdym? what are you actually trying to achieve?
i don't think you're understanding what i'm saying
google it or whatever
is this a joke?=
you are overreacting
no u
My apologies if it's a bit vague, I have a class called InterestTask which has a decrementing time variable that decrements once per second using a bukkit runnable. I am trying to access this class from my main so I can update a config value on server disable. However, from my tests, the only way I can get this to work is from the following code:
InterestTask interestTask = new InterestTask(this);
But I would like to be able to access this without creating a new instance of the class
basically, if you ever do this not as a "test" but rather for real, you should do it properly
i'm giving you advice on how to do it properly
i'm not telling you to do it right this instant
AS i said.
i'm telling you that if you do it for real at some point, you should do it properly
So you don't retain the initial instance you make but you need to access it again?
alright, I'll accept, thank you, now explain it
not using paper btw
you posted a paper timings report earlier
so the people who use your plugin are using paper
shade in paperlib and they'll be 300% more satisfied
you'll still retain spigot compatibility and you don't need to make large changes to your code
what answer are you even talking about
So what I'm trying to do is take the time variable from this class:
https://hastebin.com/feqayogije.java
and have it update a value in the config.
This is the section in my main that I am in reference to:
https://hastebin.com/gogimalehi.kotlin
I'm just CHECKING if the chunk is "loaded".......
how can it be that hard?
I said the problem is that it is not correct.
I'm not even close to this chunk
why are you being so fucking touchy about this
so you make the task on enable i assume right? And then you need to access that same instance again?
The issue is that when I go to update the config value while creating a new instance of the class, it resets the variable that I am trying to update. Unless my issues is located else where
I'M SORRY WHAT?
Correct
My question is why the hell is the chunk LOADED when I'm not even close to it
You need to storage that instance as a variable in your class so you can reference it later
simple right?
anyway, isLoaded is isLoaded
it doesn't lie
if it returns true, it's loaded
the reason could be anything really
a nether portal, spawn chunks, a plugin ticket...
I restarted the server and it's still loaded.
Essentially, I'm trying to store the amount left on the timer across reboots
Just an example with a different piece of data https://zak.pink/2021/05/Stubborn-Dobermanpinscher-12182.png
each instance of a class has its own fields
if you create a new instance, then the value will obviously "reset"
Create a variable in your class, on enable set that variable to what you want.
as you just created a new instance
and that instance's fields now hold the default values
On disable, use that variable you assigned the instance to.
it is NOT a spawn chunk
and I'm not even close to the chunk in the first place.
not even gonna join the server.
dunno, not really your problem though is it
How you sure?
Isn't it a Spawn Chunk?
probably a spawn chunk
ya
But
whatβs the protocollib packet type for actionbar
I used /setworldspawn
There is not the coordinates of the chunk
on a complete opposite side..
chat
Isnβt CHAT the actual chat
fine I'll go to 1M, 1M
That's not the point
you might also be calling something like getBlock or whatever on the chunk and that loads it, idk
Then what is the point?
listen to chunk load events if you want to make sure
anything that accesses the world in any way will load the related chunk, f.e Block::getType
make sure you're not calling anything like that before testing if it's loaded
those are the spawn chunks, and if I remember correctly (don't trust me so much), the spawn chunks are the same even if you change the spawn point
can you tell me
Other plugins?
no other plugin....
Check entities inside the loaded plugin
would this load a chunk tho?
I can't get it to boot with this, but it looks like the error is coming from else where
maybe there is an entity that prevents the chunk to be unloaded
the world has no entities...
I would say..
and even if there is
they don't have anything that prevents them from despawning.
listen to chunk load events and check when it gets loaded
if that's how you were running it before sure. But remember you're never using the interestTaskTimer variable.
if the event doesn't fire, it's a spawn chunk
now, print a stack trace
smart one
well gonna mod api 1s
if this was paper and you were an end user, you would be instructed to enable sync load monitoring and check the related logfile
it records the stack traces of all sync chunk load requests
the issue is then fixed either by removing the plugin or finding an alternative that doesn't cause sync chunk loads
aside from entities, it's usually the first thing that is checked in a timings report
yeah, Block::getType loads the chunk
ignore the machine entirely if the chunk is unloaded
basically this is going to be loading every chunk every tick or however often this runs that has a machine in it
which is why your paper friend was seeing this using fucking +200% tick time
And if you want to work with worlds and stuff, I'd recommend you to use paper
I think you won't like to load unloaded chunks just for everything
spigot doesn't even delay chunk unloads like paper does I don't think, so the chunk will literally unload the same tick just to get loaded again the next tick
omega π€‘
there is a chunk cache. Chunks don't unload immediately in the event they are needed again
they're not flushed to disk no, but it still takes time to load and unload them
if the chunk isn't re-loaded in a given time frame it will unload completely
ChunkSnapshot?
im working on a plugin atm and im not having any errors but im getting a warning message... the plugin compiles and exports correctly with no errors but when I run it on my server nothing happens ;( Do you know how I can correct the "warning" message: Class 'Main' is never used
I am assuming the warning comes from the compiler?
yup
god this is going to be the easiest fix and im going to look super dumb lol
idk why its giving me that warning though
should?
aha
lol okay
public class main extends.....
show us some code so we can see what you are doing wrong
the warning is fine
not here
oh
at the link provided
the IDE just doesn't know that the bukkit server is going to reflectively go and grab your main class and instantiate it
so it doesn't see any uses for it
and as such warns you for an unused class
get the mcdev plugin for intellij or whatever to get rid of the warning
its a super simple plugin to enable a texturepack with a command and i had it working before although after making some very small changes and recompiling its just not even getting "executed?" by the server
does the server say something about it when you try to load it in
paste logs or something
that's the first thing to do yes
Anyone have an idea why this isn't being liked
target might be null
there is a case where it's null? lol
@sage swift its more of a case that it could be null
@twilit rivet you should check that target isn't null. The only way it isn't null, is if the check where you set it, gets ran, but if it doesn't run, target will be null
there are a myriad of different command senders
@wraith rapids they do
Cannot find main class `me.freddie.badplugin.BadPlugin'
lol
they just check at the beginning if its the console and state command doesn't work from the console
look further down and they check if its a player
yes, but they should not be checking for a console command sender
they should be checking for a not player command sender
they should if they don't want to allow the console to run the command
they only want a player to use the command
they don't have any special case for a Creeper executing the command
one day
lol
the if else is pretty spaghetti anyway
all commandsenders are permissible, so you should first get the hasPermission check out of the way
you shouldn't hardcode the op check either, as the end user may not want an op to have this permission
instead, you should declare the permission with a permission default of OP
ack wtf... how do i "use" a class?
why are you asking that
are you trying to solve the main class not found issue
because that has nothing to do with using a class
yes?
what is your main class called
thats the error its sending
main
what is the package called that your main class is in
OMG
now what do you have written in your plugin.yml for main
NOooooOooo π π
you named your main class as main, but you put in the plugin.yml that your main class is me.freddie.badplugin.BadPlugin
the main property in plugin.yml must be the path to your main class
it should be main.freddie.....
if your main class is called Main, and is in package com.mydomain.myplugin, then main should be "com.mydomain.myplugin.Main"
but you put me.freddie.badplugin.BadPlugin in the plugin.yml that is where the server picks up to find your main class
wait so me.freddie.badplugin.main?
if that is where your main class is in, yes
that little bit of text is how the server finds your main class
Remember that's case sensitive
right...
only if you are on linux which most people have their servers running on linux @vale cradle
i AM LINUX
linux cringe ngl
Me too
Hmmmmmm
linux is far better then windows
You're not prepared enough, sorry
obligatory templeos reference
lol
um im getting errors
good
lol
java.lang.RuntimeException: Unable to access address of buffer
at io.netty.channel.epoll.Native.read(Native Method) ~[server.jar:git-Spigot-db6de12-18fbb24]
at io.netty.channel.epoll.EpollSocketChannel$EpollSocketUnsafe.doReadBytes(EpollSocketChannel.java:678) [server.jar:git-Spigot-db6de12-18fbb24]
at io.netty.channel.epoll.EpollSocketChannel$EpollSocketUnsafe.epollInReady(EpollSocketChannel.java:714) [server.jar:git-Spigot-db6de12-18fbb24]
at io.netty.channel.epoll.EpollSocketChannel$EpollSocketUnsafe$3.run(EpollSocketChannel.java:755) [server.jar:git-Spigot-db6de12-18fbb24]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:380) [server.jar:git-Spigot-db6de12-18fbb24]
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:268) [server.jar:git-Spigot-db6de12-18fbb24]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [server.jar:git-Spigot-db6de12-18fbb24]
at java.base/java.lang.Thread.run(Thread.java:834) [?:?]``` it prints this like 1000 times and then crashes
and idk what it means ;-;
its probs to due that its 1.8.8 but most of the plugins on here dont support above 1.10 and i dont want to go updating every single one that is 1.10+
1.8 doesnt support whatever java version you are using
i think its java 11
because spoiler alert, that java version didn't exist 6 years ago when 1.8 was released
are you using viaversion? @granite stirrup
yes
It is either going to be that or something involved with that, or what md_5 said
i think its cuz were running on java 11 but idk if we can change that
I have never experienced that problem and I use java 14 currently, haven't upgraded to 16 yet
its a 1.8.8 server lmao
well i cant upgrade since most the plugins dont support 1.10+
and i dont want to go through all the plugins
to update them
that isn't our problem π
you are free to use outdated software, but you are going to have to live with whatever problems that brings with it or deal with it anyways π
yeah but its not a choice to upgrade if i dont have plugins that support 1.12.2 or 1.16.5
it is your choice
your solution is pretty clear, is it not?
you just simply don't want to put the work in required to maintain updated stuff
in either case what Gecko said
?
use a compatible java version like md_5 said
i dont know if u can change the java version on the host
sounds like you need a better hosting provider
anyway i cant check since i dont own the server i only have access to files and stuff
Well you got the answers to your problem. Just because you don't like the answers doesn't mean they are not the solutions. What you choose to do or how you go about it is up to you lol
i didnt say i dont like them but i just said i cant update to 1.12.2 or higher cuz most of the plugins dont support it and idk if the host lets you change the java version to 1.8 (java 8)
seems like you are going to have fun then. π
you can try disabling native transport in server.properties, but really you need to downgrade your java version as I'm not sure what other issues there may be
i will try
So I want to place a wall depending on where the player is looking at ...
is there a simple way to make this?
uhhh
i disabled native transport and now its not crashing or displaying that error 1000 times
is it really this simple...
sus
but what if I have to put some type of data int he blocks?
then how do I do it?
for example, wool color
because of 1.12 or 1.8
So I am having trouble interpreting this entry on wiki.vg: https://wiki.vg/Protocol#Entity_Equipment
Here is my code: https://paste.md-5.net/juhixonefi.java
When I run the command, I get this in the console:
Caused by: com.comphenix.protocol.reflect.FieldAccessException: No field with type net.minecraft.server.v1_16_R3.ItemStack exists in class PacketPlayOutEntityEquipment.
at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureModifier.java:365) ~[?:?]
at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:345) ~[?:?]
at testplugin.TestPlugin.sendPacket(TestPlugin.java:44) ~[?:?]
at testplugin.TestPlugin.onCommand(TestPlugin.java:27) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot.jar:3084-Spigot-9fb885e-afa0678]
... 19 more
What is going on here? this is kind of wack yo
More importantly: How do you interpret that wiki entry?
go look at the protocollib packet wrappers
ya
some wiki vg packets arent updated with 1.16 stuff, i just decompile and check the constructor
How do I get that on the classpath? is it a jar I download?
wait
Yeah, because I can't access WrapperPlayServerEntityEquipment in eclipse
nevermind I just had to read for 20 seconds:
You can use PacketWrapper as a dependency if you wish, although it is highly recommended that plugin authors simply copy and paste the classes they need into their project. T
alright thank you sir
WOW this repo is fucking cash
good deal
wtf
Caused by: com.comphenix.protocol.reflect.FieldAccessException: No field with type net.minecraft.server.v1_16_R3.ItemStack exists in class PacketPlayOutEntityEquipment.
at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureModifier.java:365) ~[?:?]
at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:345) ~[?:?]
at testplugin.WrapperPlayServerEntityEquipment.setItem(WrapperPlayServerEntityEquipment.java:90) ~[?:?]
at testplugin.TestPlugin.sendPacket(TestPlugin.java:46) ~[?:?]
at testplugin.TestPlugin.onCommand(TestPlugin.java:27) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot.jar:3084-Spigot-9fb885e-afa0678]
... 19 more
try asking them I guess
fack
in 1.16 the actual type is a List<Pair<EnumItemSlot, ItemStack>>
idk if there's a way to get that in protocollib
is there is a way to convert textcomponent to json string?
How do I get the book enchantment? From objects I can get it, but from books I canβt do it!
ComponentSerializer
and look at the meta
declaration: package: org.bukkit.inventory.meta, interface: EnchantmentStorageMeta
EntityEnderCrystal enderCrystal = new EntityEnderCrystal(((CraftWorld) loc.getWorld()).getHandle());
enderCrystal.setPosition(loc.getX(), loc.getY(), loc.getZ());
but i dont see anything
@EventHandler
public void onSnowballThrow(ProjectileHitEvent e){
if (e.getEntity() instanceof Snowball) {
Snowball projectile = (Snowball) e.getEntity();
Location loc = e.getEntity().getLocation();
EntityEnderCrystal enderCrystal = new EntityEnderCrystal(((CraftWorld) loc.getWorld()).getHandle());
enderCrystal.setPosition(loc.getX(), loc.getY(), loc.getZ());
if (projectile.getShooter() instanceof Player) {
Player player = (Player) projectile.getShooter();
player.sendMessage(ChatColor.GOLD + "You spawned in an " + ChatColor.DARK_PURPLE + "End Crystal" + ChatColor.GOLD + "!");
}
}
}```
java code ^
why are you using nms for this
Thank you!
declaration: package: org.bukkit, interface: World
1.9 they made it an item
spawnEntity has existed for a hell of a long time before 1.8.9
damn
like did you honestly think spigot had no api to spawn an entity
no offense but spigot didnt have a decent chunck of things in 1.8.9
like titles, bossbars, actionbars, etc
you've been able to spawn an entity since probably beta 1.2
there is bossbars api i think
like seriously bro
using nms
bossbars didnt exist till 1.9
and guess what, there was a bossbar api added in 1.9
whats the entity type?
for end cristal
declaration: package: org.bukkit.entity, enum: EntityType
well when I try to send that using CraftPlayer.playerConnection, clients get disconnected. How do Packet-IDs work? Is there a way to get the latest packet ID?
ayyy thanks now i have a endercrystal-shooting snowball for my crystalpvp server lmao
@late cliff the packet would be PacketPlayOutEntityEquipment that you have to send
final thing, the end crystals dont actuall damage the player, is this fixable? or am i just doing sum wong
no idea
What is the first arg? The packet ID?
new PacketPlayOutEntityEquipment(var0, pairs);
the entity id
got it
do you use worldguard @warm galleon ?
if so, there is some settings in there relating to explosions
void sendPacket(Player holder, Player observer) {
ItemStack testItem = new ItemStack(Material.DIAMOND_CHESTPLATE);
List<Pair<EnumItemSlot, net.minecraft.server.v1_16_R3.ItemStack>> pairs =
Arrays.asList(new Pair<>(EnumItemSlot.CHEST, CraftItemStack.asNMSCopy(testItem)));
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(holder.getEntityId(), pairs);
CraftPlayer craftHolder = (CraftPlayer) holder;
craftHolder.getHandle().playerConnection.sendPacket(packet);
}
>here we go
here we go
>here we go
here we go
yeh im currently uninstalling it from srever ill get bnak to u
lol
probably had to wait for an update packet of some sort
interesting
there is multiple packets relating to entities
fun fact: In creative mode, if you click on the chestplate while it is in your chest slot, it becomes an item
Obviously not in survival mode though
We donβt talk about creative mode
If I specify api-version to be 1.16, will it stop using LEGACY_* materials?
I think its fucking it up
yea
alright that worked
Now I need to figure out these "update packets"
I am basically trying to make color cycling armor
Would that be too packet-intensive?
Probably not
Do you know which packets these are?
What's the best way to store item enchantments in the database?
Considering doing it fully server side sends the packets anyway
https://wiki.vg/Protocol#Entity_Movement
@late cliff
I see, thanks
basically after you send the entity equipment packet, just send that packet. will make the client update the entity faster
I will send it only if the player isnt moving
since that might mess up the smoothness of the movement on the observer's end
that packet is sent even if the entity doesn't move
i just created two npcs{znpcs plugin} with the skins of wallibear r purpled , today when i logged into the server their skins were showing as steve and even if i am trying to load another npc with another skins they are sometimes loading as stev
Is there a way to interrupt these packets with NMS? Whenever an enemy hits the player, the armor blips with the actual underlying armor
in my case its an iron chestplate disguised as a diamond chestplate
Protocol lib has packet listeners
But it may be the client doing it, which you canβt really stop
I dont think so, these "blips" can be cancelled (I know I can with protocollib in THEORY, but protocollib is being a bitch)
I even used the wrapper repo
and errors everywhere
Up down left right
in my pants
under my hat
they are just everywhere, flooding my console
so I am gonna stick with NMS i guess
why do you want to update the entities equipment with packets instead of just changing the equipment on said entity?
In modern versions you can modify the armor values of an item, so you can have leather armor be just a strong as diamond
If thatβs what you want
you can create your own listener, just need to inject your handler into the network
Because I am running a vanilla server and only want it to be aesthetic
I guess the problem would be durability, why hasnβt Mojang made that an attribute yet
I dont want it to interfere with the vanilla grind if you know what im saying
I have no idea what you are saying
@young knoll they don't want to interfere with the normal drops
I mean, you could solve that with a listener
yep
just keep track of the equipment the entity originally had, then when it dies, instead of dropping your items you used to make it look better
just drop the original items
or just use the loot table
HMMMMM
I dont know, I feel like there are too many "leaks" that free items could "seep" through
what you are wanting is completely doable with just the API and no need to go with packets or NMS
Nobody has made a plugin that turns all armor into dyeable leather
I know what Iβm doing tomorrow
But which events should I look out for?
lol
I have to catch EVERY event that could possible get the armor piece out
idk man, I like the idea but
From a mob?
from a player
well I know entity death event yes
hmmm
inventory move item event?
that one as well
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerInteractEntityEvent.html
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityDamageByEntityEvent.html
declaration: package: org.bukkit.event.player, class: PlayerInteractEntityEvent
declaration: package: org.bukkit.event.entity, class: EntityDamageByEntityEvent
so IDK, I dont want to miss any events
if I do, I have to roll back the world because otherwise it's "vanilla virginity" would have been lost
and the worst case scenario is not knowing IF it's precious vanilla virginity has been lost
or WHEN
you don't have to worry about hoppers
so I wouldnt know how far to roll it back
as long as you cancel the event for item drops, the hopper won't grab them π
basically, I need every event that could possibly remove an item from any EquipmentSlot
including hands, because I will have it do custom-shields
custom shields, and have diamond/netherite swords look like fancy gold swords
well, you only have like 3 events to work with. Really only have 1 event where the items drop and that is when the entity dies
hmmm, for hands, I would have to consider the event where the player scrolls in their hotbar
or swaps offhand
why?
becuase when they hold their netherite sword, it will become a gold sword aesthetically
if they scroll to another slot in their hotbar, it must go back to a netherite sword
this is kind of tricky
ahhhhh
so....why not just give them a custom gold sword?
this way when it gets dropped, you know it should be a netherite one
hmm
then you don't have to worry about constantly modifying stuff in player inventories
only have to worry about it on item drop instead
just add custom data to the gold sword is what I am saying, doing so makes it not the same as a normal gold sword
what if I want a sword to be disguised as a bow? I never mentioned this, but this plugin will allow players to pick any item they want
So wait
You want them to look different when held, but only when held
Why
How is it less vanilla if they look different all the time
its a FEELING man
I cant describe it, but it doesnt seem right, something is off, like the boogey man is going to rekt my sword and explosion my world
ignore that
its late, I need to go to bed
Whatever, you can handle held items with the PlayerItemHeldEvent, and armor with https://www.spigotmc.org/resources/lib-armorequipevent.5478/
nah its okay
inventory is fine
but, I would have to change attribute modifiers of the sword and what not
players base deal 1 attack damage with an attack speed of 4
So the EVENTS would be 3 of them?
- Drop item event
- shift click into chest/inventory event
- ???
itemmetadata exists π
yeah persistentdata
I will use that
I am just trying to figure out which instances an item will leave their inventory
why do you need to worry about inventory events?
basically all the times where an item could leave the player's inventory
also
if the player configures their SWORD to look like a BOW, they could shoot with it
hmmmmmmm
I will sit on this idea
I am going to bed
is there a way to disable ppl from getting illegal items in their saved hotbar while in creative mode?
This is so relevant to so many conversations thank you Iβm stealing this
Also imagine being unverified
how do I prevent players from taking GUI items out
event.setCancelled(true)
oh that's right lmao me is no brian
How to change this? (I can edit spigot)
photoshop or paint
Hey how can i remove something from PlayerInventory? https://paste.md-5.net/orisagisac.cs
version 1.9 btw
MainListener.java:140 incorrect inventory size
Caused by: java.lang.IllegalArgumentException: Invalid inventory size; expected 36 or less
ik bcz i cant remove the armor and offhand item
bcz the fucking 1.9 bug gets even the armor and offhand making it 41 and not 36
um, you are looping over your armorContents and setting the whole contents every time
yea
bruh plugin wasnt working bcs i forgot a !
You content.getContents().length will always return 41 as empty spaces will be AIR or null
oh so how do i fix that?
you strip null or AIR from teh beginning of the array
use substring
like on the?
teh returned array
uhh
Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_16_R3.command.ColouredConsoleSender cannot be cast to org.bukkit.entity.Player
final Player p = (Player) sender;
does give me error when trying to execute from console
the array will alwasy be 41 long, so just suibstring and ignore the armor slots
you have to test instanceof to see if its a Player before casting
w8 how can i remove smth from ItemStack[]?
if (!(sender instanceOf Player)) {
sender.sendMessage(Component.text("This command is only for players!")));
return true;
}
final Player player = (Player) sender;
basically like that
oh i initialised the player p just under the onCommand
Yea you don't wanna do that
How do I get items in the shulker box? To save them later!
exactly how you'd get the contents of a chest
how can i check if the item in mainhand is null?
i have this but it says its always false
Does someone know why Chest keep being opened If there's no one views the chests?
I opened the chest using code.
i think maybe try getType and check if its air
like this?
if (p.getInventory().getItemInMainHand().getType() != Material.AIR) return true;
is it impossible to include Item meta in a crafting recipe?
as ingredients for shaped recipes, yes, see RecipeChoice.ExactChoice
yes, for shaped recipes
so you mean it's possible for unshaped?
no, its only possible for shaped recipes
to have itemMeta?
yes
can I have some resources
new ShapedRecipe(...).setIngredient('#', new RecipeChoice.ExactChoice(item))
declaration: package: org.bukkit.inventory, class: ShapedRecipe
nullpointer
so does someone knows how to cancel when the players isnt holding something in his mainhand?
it says that its always true
if (cmd.getName().equalsIgnoreCase("store")) {
if (!(sender instanceof Player)) {
sender.sendMessage("the console cannot run this command!");
return true;
}
final Player p = (Player) sender;
if(args.length > 0) {
StringBuilder message = new StringBuilder();
for(String arg : args) {
message.append(arg + " ");
}
if (p.getInventory().getItemInMainHand() != null) return true;
ItemStack itemStack = p.getInventory().getItemInMainHand();
ItemMeta itemMeta = itemStack.getItemMeta();
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
if(container.has(new NamespacedKey(MagmaBuildNetwork.getPlugin(), "MBN"), PersistentDataType.STRING)) {
p.sendMessage(ChatColor.GREEN + "There is already a message stored inside this item!");
p.sendMessage(ChatColor.GREEN + "Message: " + ChatColor.GREEN + container.get(new NamespacedKey(MagmaBuildNetwork.getPlugin(), "MBN"), PersistentDataType.STRING));
}
else {
container.set(new NamespacedKey(MagmaBuildNetwork.getPlugin(), "MBN"), PersistentDataType.STRING, message.toString());
itemStack.setItemMeta(itemMeta);
p.sendMessage(ChatColor.GREEN + "Message stored!");
}
} else {
p.sendMessage(ChatColor.RED + "You need to provide a message to store!");
}
}
if the item in hand is never null you are good
wtfa re you doing lmao
just means that it will return an ItemStack(Material.AIR) when the player holds nothing
STATIC
so i have to check if the type != Material.AIR?
unless u can then π€·
then how the fuck does it throw an NPE
well i just want to check if the player's holding an item
what
if there is a valid item, itemMeta won't be null. Can't get metadata of something that is null
it can definitely be null
AIR is a valid item but has no ItemMeta
@Override
public ItemMeta getItemMeta(Material material) {
Validate.notNull(material, "Material cannot be null");
return getItemMeta(material, null);
}
private ItemMeta getItemMeta(Material material, CraftMetaItem meta) {
material = CraftLegacy.fromLegacy(material); // This may be called from legacy item stacks, try to get the right material
switch (material) {
case AIR:
return null;
like
so would checking if it's not null be useless?
it can definitely be null
like the actual itemstack
theres a method for hasItemMeta
it is definitely nullable
so yes can be
^
oh
are you o k
idk, my brain didn't really think of something as stupid as that
probably best
so how can i fix it? :))
you null check the item meta
just like you did for checking the item
hasItemMeta
or that
either way works
if (p.getInventory().getItemInMainHand().hasItemMeta()) return true;
fuck off xD
oh
and no fourteen you'd wanna save the item meta as you are using it later
so like
final ItemStack inHand = player.getInventory().getItemInMainHand();
final ItemMeta inHandMeta = inHand.getItemMeta();
if (inHandMeta == null) {
// PLayer does not have an item in hand
} else {
// Player has item
}
assumes that item in hand is not null
which it never is
and to cancel the command its just return true right?
yes
i assume this will work
if (cmd.getName().equalsIgnoreCase("store")) {
if (!(sender instanceof Player)) {
sender.sendMessage("the console cannot run this command!");
return true;
}
final Player p = (Player) sender;
if(args.length > 0) {
StringBuilder message = new StringBuilder();
for(String arg : args) {
message.append(arg + " ");
}
final ItemStack itemStack = p.getInventory().getItemInMainHand();
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) {
return true;
} else {
// Player has item
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
if(container.has(new NamespacedKey(MagmaBuildNetwork.getPlugin(), "MBN"), PersistentDataType.STRING)) {
p.sendMessage(ChatColor.GREEN + "There is already a message stored inside this item!");
p.sendMessage(ChatColor.GREEN + "Message: " + ChatColor.GREEN + container.get(new NamespacedKey(MagmaBuildNetwork.getPlugin(), "MBN"), PersistentDataType.STRING));
}
else {
container.set(new NamespacedKey(MagmaBuildNetwork.getPlugin(), "MBN"), PersistentDataType.STRING, message.toString());
itemStack.setItemMeta(itemMeta);
p.sendMessage(ChatColor.GREEN + "Message stored!");
}
}
} else {
p.sendMessage(ChatColor.RED + "You need to provide a message to store!");
}
}
lets try
yep
could clean it up a bit, try avoid using so many nested if statements
just do early returns
yea i have some coding spaghetti
How do I make a config that looks like this:```yml
players:
- 6334d54b-1b2a-4ab1-813f-c85610b972a7:
level: 10
xp: 50 - 6334d54b-1b2a-4ab1-813f-c85610b972a8:
level: 5
xp: 6
config.set("players." + uuid + ".level", 1);
will produce
players:
uuid:
level: 1
But I will not be able to read the players as a list
cuz it's a configuration section
why?
but idk if the spigot one allows it
To be able to get a list of all players
you can do that using configuration section too
i'll give you an example
for(String uuid : config.getConfigurationSection("players").getKeys(false))){
int level = config.getInt("players." + uuid + ".level");
int xp = config.getInt("players." + uuid + ".xp");
}
Oh I didn't know that was possible π
Thank you!
no problem.
Rec1.setIngredient('C', new RecipeChoice().ExactChoice(Mat)); did I do something wrong? the new RecipeChoice part is underlined
?paste
line 11 shoudl be || not &&
Hey elgarl
and yesterday they said me it has to be && :/
only if you want to exit if BOTH are false
Im trying to have an Item ingredient in a shaped recipe to have ItemMeta
and MD_5 said it's .setIngredient('#', new RecipeChoice().ExactChoice(ItemStack));
but it gets underlined
Your code reqires teh block to both have a TileState and be Locable, so either of those not being correct needs to exit
i have this error when trying to cast aCraftEnchantingTable to Lockable
so putting || would solve it?
because its not lockable
changing to || woudl mean enchanting tables would not allow yoru code to run as they are not Lockabale
What is underlined?
new RecipeChoice()
you should be using new RecipeChoice.ExactChoice(ItemStack)
if you are and its underlining, hover over it and see what the error says
no
k
Your test code in BlockBreak is bad then
you need to cancel the event if its locked
i havent test code in block break π
That would be why then π
xd
so in fact it would be the same code as the eventHandler except its for blockbreak and not for interact?
pretty much yes
just a question is this bad? or
and now players can override a lock by putting a lock on the same block again ._.
ty
so i have to check if the block not already has a lock and then i can put one
yes
just to understand what would happen if i didnt add <?>?
and what happens when i add it
nothign much, it woudl just warn
okay thank you
Hey Guys is there an an alternative to the Material.LEGACY_STATIONARY_WATER , because it is @deprecated and I don`t find an alternative ?
something like this?
if (container.has(key, PersistentDataType.STRING)) return; // cannot override existing lock
if (MagmaBuildNetwork.getPlayersWantingLock().remove(event.getPlayer().getUniqueId())) {
event.setCancelled(true);
container.set(key, PersistentDataType.STRING, p.getUniqueId().toString());
blockState.update(); //apply the lock!
p.sendMessage(ChatColor.DARK_GREEN + "Locked!");
...
Okay, but now there is the Problem, that a player canΒ΄t click a Block with the Material.WATER. So the by the PlayerInteractEvent the event.getClickedBlock() will never have the Material.WATER
send your code
Hi, I'am still in my problem, can you help me to get, remove and add tags to entity?
(in 1.8.9)
You will never click a water block. instead use https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/Block.html#rayTrace(org.bukkit.Location,org.bukkit.util.Vector,double,org.bukkit.FluidCollisionMode)
how can i get the block who is broken in the blockBreakEvent?
just event.getBlock()?
yes
okay
like this?
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
Player p = event.getPlayer();
NamespacedKey key = new NamespacedKey(plugin, "MBN");
BlockState blockState = block.getState();
if (!(blockState instanceof TileState) || (!(blockState instanceof Lockable))) return;
TileState tileState = (TileState) blockState;
PersistentDataContainer container = tileState.getPersistentDataContainer();
if (container.has(key, PersistentDataType.STRING)) event.setCancelled(true);
}
maybe remove some unneccesary parts but yea
I would writ it so but, yes so can get the block
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
Player p = event.getPlayer();
NamespacedKey key = new NamespacedKey(plugin, "MBN");
BlockState blockState = block.getState();
if (blockState instanceof TileState || blockState instanceof Lockable){
TileState tileState = (TileState) blockState;
PersistentDataContainer container = tileState.getPersistentDataContainer();
if (container.has(key, PersistentDataType.STRING)) event.setCancelled(true);
}
}
oh thats pretty the same thing
oh wait there s something more
i havent checked if the uuid stored is the same as that from the owner
only the fact that you dont`t have an return statement that is unnecessary
I would create some helper methods.
boolean isLockable(BlockState state)
boolean isLocked(BlockState state, @Nullable Player player)
boolean setLock(BlockState state, @NutNull Player player)```
need help in bungeecord server
listeners:
- query_port: 25577
motd: '&1Another Bungee server'
tab_list: GLOBAL_PING
query_enabled: false
proxy_protocol: false
forced_hosts:
pvp.md-5.net: pvp
ping_passthrough: false
priorities:- lobby
bind_local_address: true
host: 0.0.0.0:28409
max_players: 4000
tab_size: 100
force_default_server: false
remote_ping_cache: -1
network_compression_threshold: 256
permissions:
default: - bungeecord.command.server
- bungeecord.command.list
admin: - bungeecord.command.alert
- bungeecord.command.end
- bungeecord.command.ip
- bungeecord.command.reload
log_pings: true
connection_throttle_limit: 3
server_connect_timeout: 5000
timeout: 30000
stats: ceb0560d-f953-43a8-a6f2-1ea0188f3892
player_limit: 4000
ip_forward: true
groups:
md_5: - admin
remote_ping_timeout: 5000
connection_throttle: 4000
log_commands: false
prevent_proxy_connections: false
online_mode: false
forge_support: false
disabled_commands:
- lobby
- disabledcommandhere
servers:
lobby:
motd: '&1Just another BungeeCord - Forced Host'
address: us3.falix.gg:28409
restricted: false
hub:
motd: '&1Just another BungeeCord - Forced Host'
address: de10.falix.gg:28803
restricted: false
jesus
bungee config
this is help dev not bungee
?paste not spam
where i can get that
and you need #help-server
Hi
I am trying to create a file and save us data only that I always make this error:
at cryptomanager.cryptomanager.Main.<init>(Main.java:12) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_51]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_51]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_51]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_51]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_51]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[server.jar:git-Spigot-37d799b-3eb7236]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[server.jar:git-Spigot-37d799b-3eb7236]
... 8 more```
Code:
public class WalletWriter {
String path;
public WalletWriter(String path){
this.path = path;
}
public void write(String user, int money,int crypto) throws IOException {
File wallets = new File("wallets.txt");
if (!wallets.exists()){
try {
wallets.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileWriter myWriter = new FileWriter("wallets.txt");
myWriter.write(user+" "+money+" "+crypto);
System.out.println("[CryptoManager] Wallet Writed...");
myWriter.close();
System.out.println("[CryptoManager] Wallet Closed...");
}
Please help me
i did the check part like this
String lock = container.get(key, PersistentDataType.STRING);
if (lock != null && !lock.equalsIgnoreCase(p.getUniqueId().toString())) {
event.getPlayer().sendMessage(ChatColor.RED + "You cannot break this!");
}
else: you can break it..
See above for my recommended methods you should write
can you link the message pls
What is Main.java:12
this: public WalletWriter myWriter = new WalletWriter(plugin.getDataFolder() + "wallets.txt");
then plugin is null
for some reason when i set a lock i cant open it either
you need to check for a lock and if its not yours cancel the opening event.
https://www.spigotmc.org/resources/nbt-api.7939/ I used the nbt api but there is no options to add an array
Trying to put Main.plugin.getDataFolder from the same error
plugin is null
how i change it?
you can;t initialize fields in the class where you depend on values like plugin which are not set until onEnable
MY statement still stands
onEnable runs long AFTER class instancing
you should not be trying to access getDataFolder() in your class instance
initialize it in your onEnable after you set your plugin reference.
public WalletWriter myWriter;
public void onEnable() {
this.plugin = this;
myWriter = new WalletWriter(this.getDataFolder() + "wallets.txt");```
Thanks
what does that ~ do?
List<String> arguments = new ArrayList<String>();
?
Its private so only accessible from inside that class, but its static so there can only ever be one instance
no matter how many copies of that class are created at runtime they will all share the same arguments
oh
xd
I have never in my life used it
I've never even seen it used
where is this from?
that is intellij collapsing the type parameters
oh
if you click on it it'll expand to the actual params
stupid intelij
the ~ is there to differentiate it from the diamond notation shit
I found a solution but I have another problem while trying to load this line : java NBTInjector.inject(); because I have this error :
can you paste the error on a paste site
k
i don't feel like downloading a txt file
look into what SpawnEntityCustomNbtInjectorTest.java:27 is doing ig
i don't use 1.8 so I can't help you beyond that
maybe ask your community of fellow 1.8 plebians
there are quite a few of them here
although in a typical 1.8'er fashion they never answer anyone's questions, only ask their own
I early checked but this is a test maked by the api I'm actually using and it failed that's my question
yeah you need to open it up and look at it to figure out why it failed
since the failure message isn't exactly descriptive
i'll start compiling a list of 1.8 people that i'll ping whenever a 1.8 guy has a question
i'll foster a community out of you fucks yet
so you can piss off to your own discord
What is the difference between using the player's username as comparison or to find and using the player's UUID as comparison or to find? How?
UUIDs can't change
Player names can change and there are also rare cases of two accounts with the same name
i see, thanks
but would it matter if the server was offline mode anyway
or should i still use uuid for good practice
Yeah if the server is offline mode it doesn't matter
UUID will change with the username
thanks
But please don't make offline mode servers ;/
i actually wouldn't, trust me, but most of my friends have the pirated version of minecraft
and i have no one to test my plugins with
you should still use UUIDs even if the server is in offline mode
relying on UUIDs allows you to for example easily implement username changes
simply substitute the joining player's UUID with a different one, and all of their data is swapped
f.e if playerA with uuidA changes their username to playerB, this would also change their offline mode UUID to uuidB
however you can easily switch the uuid back to uuidA
which allows them to retain all of their data despite the username change
plus keying data by UUID is the standard, anyway
how can i make smth like that player cant damage any entity?
?paste
like how can i get smth like entity.getDamager
Cancel PlayerDamageEntityEvent
ohh ty i thought it was smth like entitydamage
Or EntityDamageByEntityEvent is better, check if entity is a player
okay
for some reason is the part that says "you cannot open this not working"
https://paste.md-5.net/urejowoviq.cs
could you try debugging the lock what does it say?
What is MagmaBuildNetwork.getPlayersWantingLock()?
yea a list with the users who wants a lock on their container
Then you mean replace it with contains?
look when i do /lock set the player is added to the list
if (cmd.getName().equalsIgnoreCase("lock")) {
if (!(sender instanceof Player)) {
sender.sendMessage("the console cannot run this command!");
return true;
}
final Player p = (Player) sender;
if (args.length == 1) {
if (args[0].equalsIgnoreCase("set")) {
MagmaBuildNetwork.getPlayersWantingLock().add(p.getUniqueId());
sender.sendMessage(ChatColor.DARK_GREEN + "Right click a block to lock it!\nOr type /lock cancel to cancel");
okay try
uhh never done debugging
System.out.println(lock);
oh
line 17 is exiting if ANY lock is present
owh i understand
how do i fix then that i can cannot override an existing lock?
so another player cannot 'claim' your locked chest?
Map<Player, Lock> , check if player contains with the lock
I would recommend set the location, because it is always different
String lock = container.get(key, PersistentDataType.STRING;
if (lock != null) { // Has a lock so test.
if (!lock.equalsIgnoreCase(p.getUniqueId().toString())) {
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You cannot open this!");
return;
}
} else { //no lock
if (MagmaBuildNetwork.getPlayersWantingLock().remove(event.getPlayer().getUniqueId())) {
event.setCancelled(true);
container.set(key, PersistentDataType.STRING, p.getUniqueId().toString());
blockState.update(); // apply the lock!
p.sendMessage(ChatColor.DARK_GREEN + "Locked!");
}
}```
what does those 2 first lines do?
they confuse you
because they introduce you to concepts you're not ready for and aren't necessary here
retrieves teh UUID lock if it exists, else null
String lock = container.get(key, PersistentDataType.STRING);
if (lock != null) {
functionally identical to this
so then i have to check if the lock is equal to the players uuid
the above code does that
if the container is locked
if the player is trying to lock something
if the container is locked by the player
"you have already locked this container"
else
"someone else has already locked this container"
else
"you cannot open this, this is locked"
else
if the player is trying to lock something
lock the container
else
open the container
updated code to include adding the lock
π₯
illegible spaghetti
it's still illegible spaghetti
tested it with my alt and he cant open/break it
you should clean it up a bit
yea i know i dont know how π
lines 18 through 21 are horror
other than that it's fine
but on line 18 you have an if clause that splits on a newline without a {} block
and on line 19 you have another if clause that does the same
you should combine them into a single if clause and use {} if you can't fit it on a single line
and you will want an empty line after them before line 21 because otherwise it looks like an illegible blob
i think i've corrected it all
https://paste.md-5.net/ufukulamuv.cs
you still have a 2 nested ifs that could be a single if with a &&
and the first if doesn't have a {} block but splits to a new line
and move line 8 to the very top
and don't create a new namespaced key each time this runs
and be more liberal with empty lines
right now you have all the way from line 18 to line 35 without a single break
does that namespace key matters?
Is lockable even used
not really
create a field for the NamespacedKey so its only created once when the class is
so a private field and then a getter for it?
no need for getter, just private
no need for a getter since it's in the same class
oki
ite so im trying to import the BetterRTP api, i think ive done it successfully however when i attempt to build my plugin this happens:
i cant put an image :I
inb4 you imported it as an artifact with your ide instead of with maven or gradle or whatever you're using to build
you need to verify btw for images
upload the image somewhere else and then link it here
How do i import it with raven
Hi !
I was looking at plugin messaging system between Spigot and Bungee, and I just wanted to know if there is a way to get all connected players on Bungeeserver with a special perm, and send them a message, from a Spigot plugin ?
Thanks,
could you show how you imported it?
you need to add its dependency information to your pom.xml
show your pom.xml and link to the github of the api or whatever
Howd i do that, im new to maven
open up the file
take a screenshot
and then send it
the file is at the root of your project directory
btw @wraith rapids do you know how to save resource under other name? Server#getResource
Do i just add
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
but replace that with the information for the api
yes
write the inputstream down to disk
okay
you dont have an repository
open up their pom
on lines 7 through 10 you will find the information you need
<groupId>me.SuperRonanCraft</groupId>
<artifactId>BetterRTP</artifactId>
<packaging>jar</packaging>
<version>3.1.0-4</version>
got it
yeah you'll have to build it locally
i added that to my pom.xml
since they don't deploy it to an online repository
and it doesnt like it
You can use JitPack