#help-development
1 messages · Page 1969 of 1
and i ran into this since gson cant deserialize itemstacks
But it should work
and slower
i am using json
Hmn i dont think so
because with yml you forgot item deserialization
You can just save directly the item object and get it back
i still want to use json since it took me a long time to get it working and i want it to be fast
yml is slow
menuitems?
If I wanted to check if the name testingabc under worlds existed in my code how would i do that?
https://paste.md-5.net/ewefinazax.makefile
You can see it on javadocs MountMario
i just need a way to smash two variables in one parameter in a method
Javadocs have all methods from a library or java program
fromJson only has two
and i can't modify it
i need two variables in the second parameter somehow
no, two arraylists
in that one parameter
one called name
one called postition
name is a string
position is an int
Hmn
guys how do we check if a player's inventory is full?
?jd
?jd
Check if firstEmpty is -1
?jd
any one can tell me how would I run server with logger in ALL mode
I use to do it but forgot
how is that done
getLogger()?
If you open the docs your answers are in there you don't have to wait for people to answer
I think it had something with server start bat
you could've said that 🙂
Agree
We told you...
I shouldn't need to say it. Docs haven't gone anywhere
help
if not then its fine
What are you trying to do
docs are useless if you dont know how to navigate them
Yeah i dont udnerstand that part
FullArrayHandler[] m = gson.fromJson(reader, variableone + variabletwo);
Most of the answers you get here are just straight from the docs which you also have access to. It's equivalent to asking someone what the definition of a word is so they read the dictionary to you.
In my menu api, i use a custom object called (MenuButton) which contains the ItemStack and he Consumer<ClickEvent>. That button it saved over Map<Slot, Button>
variable one is a string called name
variable two is an int called position
whatever dude
I would construct this string outside of the function call if I were you
For my own sanity
Might be a bit easier
What about this giz?
Using an object for the items?
Wouldnt be easier?
Easier than what alternative?
Instead of saving item stack, name and slot all separated, do an object for that
This is one of reasons why spigot plugin development its not simple
Is there any way to make ping update faster? I've seen someone do it before but I'm not sure on how
Would it be possible to overwrite the Bukkit.getPlayer() method? (Make other plugins run a custom method when they call Bukkit.getPlayer())
Bukkit::setServer would be an option
Amazing errors thrown the bukkit api
I lvoe because they are really understable
Haha
?
How would I add a tabcomplete to a Command instance ?
Hmn i love Java!!
Oh lol
Override the tabComplete method
oh ?
Ye
lemme check
I assume you mean this ?
Assuming you don’t got yourself a PluginCommand which would allow you to set a strategy for tab completing
Well
That’s better
Yea, I dont have a PluginCommand, I just have Command
But it requires you to use ::setTabCompleter which is a method of PluginCommand
I never used before PluginCommand
I only use it on my command api for registering commands
Then for nothing else
Cool
Because my command api uses PluginCommand and CommandMap for registering commands
I hate having thousands of line on pl.yml
Thats what Im trying to make, a simple api for easy making and registering of commands with some additional features, like required arguements and stuff
^
Or well take a look at one of the existing ones
Preferably one of the more pervasive ones
Will do, that seems like a good idea
Good luck
👍
You’ll soon find out people handle commands similarly but not similarly if that makes sense
thanks
Lang systems are generally painful 🥲
I just want to have every message run through my translate system
Why is that so complicated
Overflowstack could be thrown because im trying to connect a fake player to server on main thread?
Probably not
Just some method calling itself finitely
I will still looking what happening
Which overflows the stack
Some recursive function of yours if I’d gues
Lol you close the socket?
No?
Thread#sleep won’t cause a stack overflow
Allright
so i will still looking what happenins
Im confuse
What if I recursively call thread.sleep
Im calling the method fron onEnable
I dont think onEnable method its called recursively
😠
As said you call close on the socket
@sterile token are you calling thread#sleep from a spigot thread?
Unless I happen to be blind
Im calling the method FakePlayer#connect() from onEnable method
I have to sleep it if not the fake player fet disconnected
I used to work without thread.sleep() but them fake player get taken out from server
^^^
But if i dont freeze the player get disconnected
Why are you connecting a fake player anyway
Well do you have to connect and do all that login stuff on the server thread?
PMC (Plugin Message channel)
Like you could just use another thread in principle
That’s
Oh i will try doing that
One janky way to share data
yeah
And it required a player
So im connecting a fake one
:hummy:
But you have to tell the fake player to connect
Or well vulgar in some sense
Im not connecting it?
Im sending handshake and login packet
My issue is that it get disconnected from the bukkit server
idk why
Anyway i have taken out the socket#close and thread.sleep and getting the error
I will have to make an exausted checked
Myeah try catch throwable maybe
Also don’t use sneaky throws
It’s kinda big ew, especially what it allows you as the coder to bypass
Ok lol
Why lol?
I mean if you’re trying to fiddling something into a mediocre working state just start a Thread object and then try catch throwable and print the stack trace perhaps?
Don’t need to make anything fancy before it even works
Lol
Fuck
Im still having the error
idk what happening
Mnns
I think the problem is not caused there
I think find the problem
what are you doing o.O
Fake player connection to use plugin message channel
that is so pointless lol
Redis its to much for just sending simple cross-server message
I dont wanna send nothing else
why does everyone want to send messages on a server with no players o.O
it doesnt make sense using a player for receive the message
Why dont use each server as receiver?
That my biggest question
what I mean is a server with no players shouldn't be doing anything
because the plugin message channel stuff is part of MC protocol
I am sure more could be added on in terms of bungee and spigot communicating, but you are free to modify both of those things as well as make PR's
as for making a fake player that is legit there is easier ways to do it
really?
But the ways i tried no one add it as a real connection
for the purpose of plugin message channel it is pointless though since I mean servers with no players shouldn't be doing things
Tabcompleters for generic Command
basically if you want a real connection you will have to minimally have the client stuff on the bungee server
since the connection needs to start at bungee
Its my own
And im trying to conenct it from bungee plugin
there are better uses of having a fake player like you are creating though
other then plugin messaging stuff
like making a video camera
easier to record videos of your server using fake players with a minimal client 😛
its possible?
inflating online count is just a matter of modifying the number lol
my goal its find an simple solution for sending simple cross-server messages without extra things
How does Luckperms
It doesnt use anything
And it send cross server message
the easiest way is to initiate your own socket connection
you are not going to get anymore efficient then that
unless you use unix sockets I suppose
Doesnt socket require extra setup?
Carrier pigeon
you only need like 10 lines of code total or so maybe slight more to create a socket or to connect to a socket
not overly difficult
Poor birb
So there is a method for getting ping Player#getPing() but what about modifying that field?
Why do you want to modify it
But if you connect one socket to other socket, i cannot send message to every server or yes?
I have a more accurate method of calculating it
But I want it to interact with multiple already existing plugins
you can handle multiple connections on a single port o.O
e.g tab
but that a ServerSocket
who cares?
I mean go ahead and reflect it then
Wait its possible to connect a socket from a hosting to socket server on linux vps?
when I try to restart my server with the plugin UltimateAutoRestart it says "could not force restart because your interval argument is faulty" what does this mean?
not sure why you couldn't connect between two systems
I mean software does this all the time
well your question wasn't quite clear in what you were asking
anyways not sure why you keep insisting on message channels
there is no extra setup with sockets either
other then putting the plugin on the server
if you can't do that then you really shouldn't be running servers
dont you require a specific port for each socket?
That the problem if you dont use a vps you cannot achive it
you don't need multiple sockets for multiple connections
not sure what you mean by this
this is obviously wrong
because sockets are not dependent on having a vps or not
That what i was making refence
...
you can use unix sockets then
or make use of the loopback interface
Oh i never listened before
I will give a try thanks
And sorry for lsoting your time
sure but most of your problem is the language barrier
in trying to convey what you are asking
Java 17 introduced unix sockets natively 🙂
before java 17 you will have to find a library or make your own in software unix socket implementation
Oh i would use java 17 to compile, but them i cannot use it for plugins
Because you cant run java 17 plugins on old versions
your other alternative is making use of the loopback device which is known as localhost or more precisely 127.0.0.1
opening sockets on the loopback device shouldn't trigger anything for the firewall
And how you connect thems?
mainly because loopback device doesn't talk to the outside world 😛
instead of just making a socket on all devices, specifically tell java the device/ip you want to create the socket on
I know but if you are using a hosting you cannot open ports, they already assign one
loopback device is an exception
Oh i will read about it
as I said it is a device that can't make outside connections
therefore, you should be able to create sockets on it
I don't know what this means
Google java reflection
frost i dont still understand what its loopback device
I search "loopback device java examples"
And looks like java sockets
in code you would do nothing different
the difference however is you will instead specify the device or ip to create the socket on
which is going to be localhost or 127.0.0.1
while the host you are on prevents creating sockets, they usually only do so for the device that communicates to the outside world or the public IP
which is not what you are going to be using anyways
the loopback device can not communicate to the outside world
therefore it makes no sense to attempt blocking creating sockets on it
?java
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
thamk
the loopback device however can still be used to communicate to your servers that are on the same system.
Ah allright so if have 3 servers running on a hosting. I will use as address for socket 127.0.0.1 and then the port they assigned
right?
you can use whatever port you want as long as it isn't in use. Generally want to stay above port 1024 because that port and those below it require elevated permissions to use
which you most likely won't have
yes i read that < 1024 are reserved for the system
Realised i've used it before but im not sure what method im even looking for
How to make spigot server item translate to player local language?
this isn't an automatic thing. Assets in the game will use whatever language the client uses, but for custom stuff you would need to have your own translations
22.02 00:50:22 [Server] WARN java.lang.NoSuchFieldException: ping
then its a matter of grabbing the client locale which you should be able to do from the player object and display the translation to that player
auto doxxed
you send an ip address
Line right above that is my ip 😟
Ah no it not an ip address
declaration: package: org.bukkit.entity, interface: Player
isnt deobfuscated using -remap on buildtools?
Ya I already change spigot en_us.json language but it just work for few thing not work for cmi placeholder display item name
well for placeholders it is dependent on the plugin or if you are creating them then the limitation is going to be it most likely doesn't support per player translations
Ok so you mean I already translate it but plugin placeholder are not use spigot translate?
spigot doesn't translate anything
you can set the language of the server which only applies to what is in the game already
also, the client language will translate on the client, again for stuff already in the game
but for stuff added by plugins, it is on the plugin authors to setup translations and most do however what most don't do is per-player translations
anyone know if breaking a block is under PlayerInteractEvent useInteractedBlock or useItemInHand?
it is an all or nothing setting in regards to language for most plugins
which is iat
*it
declaration: package: org.bukkit.event.block, class: BlockBreakEvent
It work but it disconnect the player 😠
it also falls under PIE
which thing is it
yes because playerinteractevent is basically a catch all
I mean like this I want translate "Wooden Pickaxe"
yea, but under the event does it count as using your held item or using the interacted block?
it could be both
multiple events for the same thing can be fired
use which ever one you need for whatever you are trying to do
?tas
no
im asking bc i dont want to
and if someone's willing to answer they can answer
if you don't want to answer just dont
Well I already stated both those events can fire
both of which?
Wha tdo you think?
then use which ever method you want or need
im asking which methods do what
Apparantly there are 0 fields in the Player class 🤔
like does the useItemInHand method used for breaking blocks or is it the other one
Player is an interface
CraftPlayer is the implementation
aa
useInteractedBlock takes whatever action with the clicked block and useIteminhand will apply durability stuff for whatever item is in hand when you were interacting with the block
declaration: package: org.bukkit.event.player, class: PlayerInteractEvent
should read the javadocs
?jd
what I told you was from the docs, except for the itemin hand one, which is ambiguous only because it depends what item is in the hand at the time
if its a tool or item that can take durability damage it will apply that
Finally it working
22.02 01:07:39 [Server] WARN java.lang.ClassNotFoundException: org.bukkit.craftbukkit.entity.CraftPlayer sad days
Doesn’t craftbukkit still have the version in the package name
dont think so but i'll give it a go
you are not ussing Spigot-jar
You are using spigot-api that the problem
Spigot jar its the one you get from building it with build-tools
ffs
nice
but my problem its that the player get disconnected
?bootstrap
Bootstrap Jar
The main spigot-1.18.jar is now a bootstrap jar which contains all libraries. You cannot directly depend on this jar. You should depend on Spigot/Spigot-API/target/spigot-api-1.18-R0.1-SNAPSHOT-shaded.jar, or the entire contents of the bundler directory from your server, or use a dependency manager such as Maven or Gradle to handle this automatically.
Please read the release notes for further information: https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-1-release.534760/#post-4305163
well, the way I was telling you was you didn't need a player, you could just directly communicate with your servers via a plugin. Player connection isn't going to truly work because the loopback device can't communicate with the outside world, which means can't connect to mojang auth servers.
this isn't really an issue as you could just simply allow your player to connect regardless of auth
No but i have worked with the fake player
And it still connected for 2500ms then it get auto disconnected
most likely as I stated because of the auth stuff lol
well fake players need to be legit, unless you tell the server to let it connect regardless
yes but mojang auth servers are involved
oh i didnt know that part
which the client needs to communicate with so that a session can be created
I didnt know
But the client involve the mojan session?
or the launcher itself does it
normally the launcher does it, but you can do it at the connection level. In either case however you would still need to communicate with the mojang auth servers
which can not be done from the loopback device
Oh ok
so, a way around it is you could instead allow your player to connect without fully authenticating so as long as it comes from 127.0.0.1. but I would put some kind of protection in place so you know for a fact it is your software player and not some other thing lol.
you would need a plugin on the bungee server to allow that to happen
22.02 01:22:19 [Server] WARN java.lang.NoSuchFieldException: ping 😢
because you need to tell the server yeah let the connection happen lol
read above about the server jar
go to that post read it, there will be another link in said post in regards to NMS
and with that post combined, you should be able to resolve your problem
What event to use if i want to check if a player has a certain armor piece on?
not sure why you would need an event for this
i would want to give the player potion effects if they have a certain armor piece on
Because with InventoryCloseEvent, you can bypass the check by right clicking the armor
Is it possible to overwrite a bukkit method without making a subclass, if so how?
Bytebuddy
Alright, thanks
not sure how you would close the inventory and then also right click the armor?
no because there are two ways to check if a player wears an armor
they can either put it on in their inv
or right click the armor, and put in on
and it seems to bypass the Invcloseeevent
is there a specific event that checks for both?
just check on inventoryclick then?
isnt there a specific event that checks for armor everytime? i feel like it isnt efficient
no?
the "armor put on" can also be bypassed if a dispenser gives the armor
how do i fix that
dispenser has an event for whenever it dispenses
declaration: package: org.bukkit.event.block, class: BlockDispenseArmorEvent
how about /replaceitem?
that is a command, so you should be able to handle that easily
There’s a library that adds an armor equip event
so i need to think of every possible way that a player can put on armor?
sounds like they should pr it to spigot 😛
yeah that is part of programming
preventing interference
ah, thanks. I just hope that there is an event for that
sometimes there is, other times there isn't
and as Coll said above
you can also use libraries that add events
It’s been a PR for a while
oh I guess we wait then lol
i hope it gets implemented
so i can use 1 event handler for armor instead of making a whole bunch
which i think maybe is inefficient
it isn't that it is inefficient, just cumbersome to create all the code for the checks
yes, this is what i mean
exactly!
anyways thank you
however you should become accustomed to such things though because ideally you should be preventing your plugin from working in unintended ways anyways or be used to introduce dupes 😛
Hi so I need to count player hits, should I do it with EntityDamageByEntityEvent? If so, how could I count them?
player on player hits, entity hitting players? wdym
Specific conbat
Combat*
lmao
Yea (player) e.getEntity()
player on player
Then the event you listed will work, just check if they are players and just make a method that counts the hits to each of them
you are going to have to create some kind of grace period where it is determined they are no longer in combat or whatever else
yeah like int hits;
well going to need a list or hashmap
use a map
but you are going to have to determine for yourself when combat is dictated as being over
so you know when to clear out that list/map
It's for a duels plugin (1v1)
even so, the server doesn't have a mechanism in place that keeps track if a player is in combat or not
or when said combat is over
so you will have to create your own rules on that
AnY HELP?
or if the other player dies
Someone tag me
?
Oh kk thanks
#help-server for plugins/server issues
Wdym?
here its for plugin development
they are talking about creating a plugin so this channel is the appropriate place 🙂
ah sorry
I'm developing a plugin🤨
I got confused btw
Np
and now confusion is gone hopefully
?
When making like an onjoin event where you need to give player certain items and also prevent those items from being dropped, should you create a separate class for every event? Like a class for onjoin, ondrop, and also a class that handles the items? or should you just stuff it all together
Depend
On the context
for example i done a core
That contains multiple things
And i have one listener for data loading/unloading (onJoin, onQuit and onKick), the for managing the items i have another class called ItemListener
Ahh
Do ihave explained
Ty yes that makes sense
u too!
I usually make a PlayerListener and put everything on there but You can do it the way you prefee
Ok thanks
yw
hello sir i need help, i wanna understand why Player is not an enum please
I am a little curious about hypixel skyblocks pets... anyone have any guides/links that can teach me about them (or floating heads in general?)
SS:
what exactly is the question? it's an armorstand following the player prob. sent via packets to each client in near
ah it's an armor stand
I was just trying to think in my head what it could even be I don't know why I didn't think about that
xD
thank you, gonna go do some research >:)
np, hf
hey just wondering if i were to make an economy plugin but i want it to work across servers is there anything i have to do for it to work on servers in a bungee setup or do i just connect it to a mongodb and that should be good?
For private use or for a public plugin?
private use atm, possibly public but right now its only for my server network
If you wanted it to work across servers just store the uuid and the balance of the player
boom
Do you need vault or can you also use a custom implementation. Meaning -> do you use public plugins that depend on vault.
thats what i had a feeling of but i just wanted to confirm i wouldnt need to do anything special
i plan on adding vault support
and using plugins that depend on vault
You need to do some special stuff if you dont want your servers performance to tank
oh alright like?
Let me look into the src of vault to see if they have any async support by now.
This is probably what you should do: Use a cache like Redis or Hazelcast between your network and the DB.
There are 2 approaches.
- Have only the cache hold the data. Every data received should be considered stale instantly. You should use redis locks to make sure your data is eventually consistent.
- Every server has its own cache and you use Redis Topics to notify when a value needs to be changed. This could yield an even better performance but is also
infinitely more complex.
Is there a way to get an entity from its int ID?
so i want it connected to redis instead of directly to the db?
i think i can do that
Yes. And you only request data from redis. And when redis doesnt have the data then it will load it from the DB and hold it for N minutes.
alright ill play around with that and see if i can figure that out, thanks for the tip 👍
Why do you need this? There is no API way for doing that.
I'm listening to outgoing packets for entity equipment to hide equipment it if they crouch, but I need to get the player object from the id (could also be a mob)
Hm i can only think of expensive ways at the moment
I found a protocol lib utility for it
Ah nice
But I can't tell if its more expensive than just looping though all mobs in world
Make sure it uses mapping internally and not loop over every entitiy XD
Another way is to maybe just put all crouched players in a map
Is it only for players?
ye but if the packet could also be a mob
Isn’t there an easy way to get the entity from its id
Player starts crouching -> Add his id to a Set<Integer>
Player stops crouching -> Remove him from the set
I thought there was
I thought it was just a map lookup
Anyone have a good tutorial on StringLists in yaml files?
tried: plugin.enabledpvp.getStringList("enabled-pvp").add(player.getUniqueId().toString()); but it doesn't seem to want to add it to the string list
Not much content for a tutorial...
maybe you can help me solve my problem then xD
getStringList returns a copy.
This does add it to the string list. You just do nothing with that list afterwards
I saved it
When I try to access it later or manually look at the file it's not there
Dont use configs during runtime.
Load all your data when the server starts. From then on you use properly named variables and data structures/classes.
Then save everything when the server stops. You can also regularly save everything every few minutes if you like.
you need to get the string list, modify it, and then set it back into the configuration using the set method or do what 7smile7 said.
Does it return the list or a copy?
Do you need to do set afterwards?
it returns a copy
Okay then you would need to call set
But you should really just use pdc for this
Much easier
Actually just adding a Scoreboard tag would be super simple here.
public boolean hasPvPEnabled(Player player) {
return player.getScoreboardTags().contains("_pvp_");
}
public void enablePvP(Player player) {
player.getScoreboardTags().add("_pvp_");
}
public void disablePvP(Player player) {
player.getScoreboardTags().remove("_pvp_");
}
public void togglePvP(Player player) {
if (this.hasPvPEnabled(player)) {
this.disablePvP(player);
} else {
this.enablePvP(player);
}
}
XDD just came up with this idea
public void togglePvP(Player player) {
((this.hasPvPEnabled(player) ? (Consumer<Player>) this::disablePvP : (Consumer<Player>) this::enablePvP)).accept(player);
}
can someone send a basic maven config with just spigot as dependency
If you use intellij then i got a treat for your
i do
could even remove the hasPvPEnabled check in togglePvP and just check the return value of enablePvP.
With this you can create a clean maven or gradle project for all the minecraft platforms
Intellij has maven bundled but you should def install maven.
You just need to download the maven folder and then add the maven/bin directory to your PATH
i am literally so clueless about maven
can the plugin generate maven project for an exiting project?
No. And you should not try to mavenfy an existing project.
Create a clean maven project and simply copy paste the src folder. IJ can handle that.
why not try ? if i can ask
it only depends on spigot if that matters
It will lead to inconsistencies because there is more to a clean maven project than just the pom.xml
Also you say IJ has maven bundled, so can I create a maven project with that? or do i need to install it
happy tuesday
You dont need to install it but you should. *Its been tuesday for 6 hours for me already XD
Yugioh?
maven project
Basically a template
Ok i think i got it
made a new maven project
So does the pom.xml get automatically generated?
Yes
its generated an src/main/java directory should i just overwrite the main/java with whatever my src folder has?
Click on your old src folder in IJ. Press ctrl + C. Click on your new src folder. Press ctrl + V.
ok. should i move my config.yml to resources or does that matter?
Yes everything that is not part of your source code is now put in the resources folder. Like you plugin.yml and other files like configs.
so its ok that the java folder is empty?
And how do you trigger the pom.xml to update the dependencies?
ah ok i see
Wheres that maven window
Top right corner for me
goit it
view>tool windows>maven
hm
clicked that and my pom.xml is still missing spigot api
Did you generate a maven project or a minecraft project?
maven project
guess it was supposed to be minecraft lol
im gonna go though getting late. ill do this later in the week
How do you update a player's uuid in the playerList? (for Bukkit.getPlayer())
Probably reflection
Probably by using a ton of nms and/or reflections.
The players UUID is deeply rooted in a ton of internal mappings.
Better disconnect him and change the UUID early in the handshake.
I tried setting the entity uuid and gameprofile but they dont seem to change the Bukkit.getPlayer() method
Where do you try to do that?
in an on join event
Thats WAY to late. You need to take a look at the protocol and see what handshake packets are being sent and when the UUID is evaluated.
I see so would I just listen to the handshake packets and change the uuid there?
Probably somewhere there
Alright thanks
Login Success
is where the UUID gets set
but if you are trying to change the UUID you might break the session though
I would do PreLoginEvent
since there’s nothing else that logs in besides a player really xd
you could put this under a PlayerEvents class
So (plugin namePlayerEvents)
Classes generally are capitialized
I wouldn't do per-event per class
I mean you can if you want
just you are going to have a lot of classes that contain probably just 5 or 10 lines of code and that is it
and you are going to have to register all those classes too
might be better to name it PlayerListeners
I didn't say it wasn't easy
Well there is a balance
I think 3-4 events in a class is fine
as long as they are related to each other in some fashion
like player events spanned across 3-4 classes would be perfectly fine
everyone has their preference. There really is no right way of doing something as long as it compiles and runs 😛
I don't like having super long classes myself
but I also don't like needlessly creating classes either that doesn't contain much lol
Anyways do what you think is right. Most projects it really doesn't matter unless you intend to have a bunch of people contribute to it
yea that's a fine way of doing it.
.
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
Which event should I use if I want to cancel the event when player tries to fix a item In a anvil
the code you posted earlier is in package private.
the constructor has to be public not the variable.
the variable can be whatever visibility you want it to but it's likely better to keep it private.
encapsulation is nice
if you change that to private you couldn't instantiate it outside of that class.
Encapsulation doesn’t mean declare everything private
what event is fired when a player tries to fix/enchant something in an anvil
It means that instance variables are only directly changed within the class itself, any dependency that interacts with the instance outside must use its methods it exposes by the type
I meant the main field. It's up to you if you want to keep it private or not, I was just saying it might be better since I doubt you want anyone having access to that field.
the public Main pl; field
^
Yeah to some extent if you use the preprocess event
but else not really unless you do some really intricate stuff which you probably shouldn’t do anyway
that won't work to block /plugins and /pl that well.
since you can type /bukkit:plugins or even /plugins <any string beyond here> to bypass what you put.
could just use permissions
bukkit.commands.plugins
sure
stops them from using the command lol
there is other commands you can block too from the server, they all have permissions
most of which are just under bukkit.commands node
most people don't realize there is permissions attached to the commands bukkit/spigot provides even the vanilla ones too
hence you get all these plugins trying to block commands that already are blockable with just a permission plugin 😂
you can, depends what it needs to do
but in general you should make your plugin handle server reloads as well
not just a reload command for your plugin 😉
the reason people say not to do this
is because most devs don't code their plugin to handle it like they are supposed to
the more people that learn to handle such things, the better 🙂
server reload nulls out objects
like player stuff etc
so you need to recreate your objects or check to ensure they are not null
and basically have a way to correct a null object
most plugins listen for onplayerjoin to add them to a list
but on a server reload you won't have player join event
because the players are already connected 😛
Hi,
What is the best way to implement a shared damage system? Something like if Player1 gets damaged, 50% of that damage would be negated and transfered to Player2
@EventHandler
public void damage_event(EntityDamageEvent e) {
Player p = (Player) e.getEntity();
if(p instanceof Player) {
double damagetaken = p.getLastDamage();
String player2name = "Notch";
Player player2 = Bukkit.getPlayer(player2name);
player2.setHealth(p.getHealth() - damagetaken);
}
}
didnt tested it
I wouldn't. You can end up with too many classes trying to be organized lol
but it is up to you, as long as it is easy to understand and intuitive you are generally fine
anything that might be questionable to someone, add some comments before/during/after the method where it seems feasible to document something
main key is documentation and comments. Those help just as much as having organized classes and intuitive naming schemes
this is how I do my commands
just need to handle when the sender is the console and not just check for a player lol
you should only check if the sender is a player if the command being ran is dependent on such things
I think most permission plugins allow you to prefix a permission with - to negate it
so like -<permission>
this is the standard in regards to permission plugins
or the adopted one that permission plugins have taken to using
always nice to have something work on the first try
returning false gives them the message automatically that they don't have permission
I generally return true in all the methods for the if's the last outer return false if nothing matched
exactly
hmm wonder if that got changed
or maybe its dependent on the permission plugin being used
I don't use luckperms
I use groupmanager which many here will despise you of using 😛
well I have a customized version of groupmanager
it is open source after all
I use GM because it works and does what I need it to without much fuss
yeah that is really what it comes down to
I just don't have a need for such a feature
some people like that which is understandable
and all the more reason to go use something like luckperms
but, I don't need all the frills 😛
basically GM is what you would think of Debian
and luckperms ubuntu the go to Debian distro
There are people that like Debian vanilla because it doesn't have all the frills that they don't use or care about anyways
where as ubuntu adds quite a lot of useful things out of the box
well, was just an analogy anyways 😛
what is the difference of getvalue() and getdefaultvalue()?
whoWasHit.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()
whoWasHit.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue()
entity damage by entity event
yup
no im not getting the damage
im getting the current health
of who was hit
sorry if it confused you
the difference is getDefaultValue() is at it says, gets what the default is supposed to be, getValue() gets whatever the value is even if its not the default one since it can be changed.
so getdefaultvalue will always be 20 right?
why do more work when i can just get the value directly from getAttribute xD
it should be unless the default is changed, not sure if defaults can be changed in server config stuff or not. But as far as I am aware it should do that
alright thanks
could do that, but you shouldn't worry what the default is either
default just implies that is what the server is configured for
and you should always respect the default regardless of the number 😛
just have to ensure you don't encounter negative numbers unexpectedly is all
otherwise your players die 🙂
Player#getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue() is the same as Player#getHealth?
getHealth() should return what the players health currently is
wait
wtf
ok im confused
getValue() gets whatever the value is even if its not the default one since it can be changed
by changed do you mean damaged?
so isnt that the same as getValue()?
you can change the max health number
oh i see what you mean
getValue() returns whatever that number is, it can be the default number
or a different number that it was changed to
mhm yup, thanks
getValue gets the max health the player has if he has bonus hearts, etc, getDefault always returns 20 which is the default vanilla
I have a question which I cant seem to find an answer anywhere for:
I am registering commands via the commandmap, they work, but then trying to get an instance of PluginCommand from them doesnt want to work, I went trough the map, the commands are in there, but just not as PluginCommands, just as regular Command type. Tried to convert it, but that doesnt seem to work either.
Looked into other plugins that do something like this, but most I looked at do it in very different ways to each other and for me not very understandably.
Just for the sake of completion, cause this might be easier, idk, I want to register a tabcomplete to the command, if that helps, this is my final goal anyways.
Is it possible to runtasktimer once?
PluginCommands are generated if the plugin.yml contains plugin entries. I would just follow the breadcrumbs of the CraftBukkit implementation.
Sure. Do you just want to run a task once right away (in the next tick) or wait N ticks.
Next tick
declaration: package: org.bukkit.scheduler, interface: BukkitScheduler
these days vault isn't really needed for permissions
query the permissions plugin being used
whats even the difference to just using Player#hasPermission?
luckperms and pex are the common permission plugins in use they have API's
ah i see
Permissions are used to verify immediate action of a Player. Why do you need to check the permission of an offline player?
Elaborate pls
if it is your voting plugin, why not just keep your own list of players that have been given permission?
or you could proccess the vote when they log on
if every user that has ever joined has been given permission
Still not enough information. Its probably better to store the players name and wait for his next login.
then why would you need to check if they still have permission if they are offline?
why would you need to
you just said this
just wait for them to log on
isn't it pointless to check perms if everyone has perms?
then query their rank
should be fairly easier to do that then to worry about permissions
What if someone doesnt use luckperms?
this is for their own personal needs
Ah i see
if you are using luckperms just use mysql DB option with it
then with your vote plugin, query the DB
for their rank
no need to hook into anything at that point except just use some SQL stuff 😛
This sounds like a hacky way if you have the whole LuckPermsAPI at your disposal...
not really o.O
that is what DB's are for
why would I go through middleware
You joking, right?
no? Not hard to query a DB, acting like as if its some big risky thing o.O
I am not going to use some large API to just query a DB with a simple sql connection
nor would I recommend for someone to do so either
It fking is. What if the scheme gets migrated to a new one?
Do you then look into the db and write your quries new instead of doing nothing because the API abstracted that away from you?
if you are in control of the DB
you know when the scheme changes
you shouldn't be allowing something to change the DB freely without your knowledge
Yes. And its better if you dont have to react on changes because you use an abstract API anyways.
and the API can't stop me from querying the DB no matter how hard it tries
Its like measuring the currencies of your calculator instead of using the lcd display...
If you like to let software change your DB without your knowledge that is on you and poor security practices
anyways you can even setup a function on the DB too
so you don't actually have to query anything
you could just invoke the function instead
in this case bypassing it would be more efficient
I really hope you dont work in the backend...
But it has a clearly defined job. And everything accessing the DB should go through that service for several reasons.
ok what are the several reasons
other then DB scheme
which isn't really a big concern since no writing is happening
I agree. Database should be an implementation detail
its a variable
its probably at the top
Consistency. Metrics. Not breaking SOLID principles. Modularity.
Basically everything that makes out micro service architecture.
If everyone uses this services abstract API then you just have to swap out the implementation
if you want to change something on the data structure. But if 20 other services access this DB
by hand then 20 more services need to be updated.
I really don't care about someone elses metrics
someone elses metrics is not a valid reason to use someones api
consistency sure, but again we just checking for two things combined, user to get their rank
solid principles? not sure which you infer
Modularity? What modularity? This isn't some large project where we got tons of moving parts
I also disagree on that too. Metrics are crucial to find bottlenecks. And i want the API that i use to function at its best.
thats pretty likely ye
ok you can disagree but an opinion is not a fact either
metrics is not a fact of anything in why you should use it
You are right. I just stated that i disagree and explained why.
Anyways this is not a fruitful conversation. Lets just move on. 👍
Basically you are advocating that this large API should be used to query two small data pieces and I would argue bypassing it would be far more efficient in the long run then using said API
I am sure you could probably setup a test to prove that bypassing it would be more efficient even scaling wise
simply because we cut out the middle man
Depends on what your concerns are imho
Yes you can cut out all your middlemen if you like that.
But lets just move on.
a microservice is only as good as the service it provides, if it isn't good enough then you simply don't use it.
in this case it is just too much
in my opinion and I wouldn't use it
If it’s about speed then maybe, but in the long run having layers (such as an api) which separates concerns makes it simpler and more robust against changes
That is factually not true. You provide a better implementation. I mean... come on.
or just don't use it
I dont care anymore
of course you don't but I don't tell businesses to buy something they don't need either. Not that luckperms costs anything. but still same principle
An api allows for the actual concretion to scale and change whilst still supporting consumers
pls just stop your rant and lets move on
Very nice
Hi guys, I'm trying to use a scoreboard to save player data for a minigame but I've some questions. First of all is it a good practice?
Cant understand how you don’t want robustness in design
Using a scoreboard to store data is not a good practice. It should only be used to display data.
Its an observer of data
So, if I use it to count player kills is ok, right?
Nope.
Its ok if you use it to display player kills.
Not as slow that it would matter. Do you want the data to persist over server restarts?
Nope
It is harder to manage and wiping data, comparing to relational database
Use pdc ftw
Uh, you are right XD
You should use a centralised way of storing your data. Maybe a PlayerKillManager singleton that
hosts a Map<UUID, Integer>. Or if you want to store statistics then a PlayerStatsManager.
OK , what if that manager uses PDC?
This way sorting and doing a top list is possible. PDC doesnt provide that luxus.
Also valid. But then you would need to erase the data by hand.
Or just set it to 0 at the start of whatever you are tracking
The client does that sorting. You just send it a bunch of Strings.
Client does
you could either use OfflinePlayer to get the UUID or you could query mojang servers to get UUID. Generally better to use OfflinePlayer since it already has mechanisms in place if the user doesn't exist to query mojang servers as well as built in rate limits since mojang servers only allow so many requests every so often.
Bukkit.getOfflinePlayer(string).getUniqueId();
players name
Yes
It’s not deprecated for removal
Because it might make a request to mojang
To lookup uuid based on name
because generally you should use UUID to get a offlineplayer object or player object, however sometimes that isn't feasible. It is basically warning you that a players name can change
when a player is offline, they can change their user name via mojang account settings
this is what the deprecation is warning you about
however this doesn't really apply to you
because you want the UUID anyways
not that you are using player names only to store info etc lol
the method that is deprecated is getOfflinePlayer(String) even if you are using methods provided by offline player, that specific method is deprecated and instead should use getOfflinePlayer(UUID) but you are getting their UUID anyways, therefore the deprecation doesn't apply in how you are making use of the method. Also the reason why that method isn't marked for removal because it is needed otherwise how would we lookup UUID's of players 😛
Its not deprecated because it gets removed or is draft but simply to make sure people use UUID for retrieval whenever possible. So dont be worried.
getOfflinePlayer will automatically check for online players first
Player player = Bukkit.getPlayer(username); probably should change this too
for a voting plugin you should always assume players are offline
you can easily check if they are online and convert to a Player Object from offlineplayer
as it provides a method to do so as well as you can cast
you can cast
but if the player isn't on the server though
you are not going to get a valid player object regardless
not without some hacks
doesn't luck perms allow you to query users regardless?
don't think it requires an online player to use its api to query permissions
all permission plugins allow you to query an offline players perms, IF you use their API
Or you look directly into the DB and bypass their API. 
eww, you need shooting
still wouldn't require an online player as well
but it seems they are having more troubles using the api then making a simple sql query though lol
Dont bother getting an online player directly
its what I said above
should be using OfflinePlayer until you check and know they are actually on the server
then you could cast it to Player, but I don't really see where they would really need to do that though
OfflinePlayer is all that is needed
I mean if he wants to give him immediate feedback then he can call isOnline() and then getPlayer()
But other than that its not really needed, right
Us vault
Use
perms.has()
But
U gotta run that async
Or luckperms will complain
using vault isn't needed and just adds another api into the mix, since all vault is going to do is query the permission plugins api anyways
Vault permissions API ga always worked for me 😐
means creating a thread
the spigot api has methods for this to make it easier to do things async
Not really...
No need to over complicate stuff
Let the bukkit scheduler do it
well you are not going to have async any other way
without another thread, it is just sync o.O
Yes. You can also do something async on the main thread.
Hello, im currently making a plugin and im wondering if anyone can help me with the following issue:
I have an instance of an entity in my class, but once the server unloads that entity i cant use that instance of the entity anymore. anyone here knows how to either keep the chunks at the entity loaded, or how to make it so the refrenced entity doesnt change so i can keep using the object?
Async does not mean multi threaded
iirc you can use the uuid
Best example is FAWE. Its async but everything is happening on the main thread.
yes but im updating the entity every tick, (armorstand animation).
I will have to look at it, but I am pretty sure additional threads are created
so thats not a good idea i think
