#help-development
1 messages · Page 1859 of 1
The code in OnEnable() doesn't work the first time the server runs, but it works when I do /reload.
do you use Bukkit.broadcast ?
do not use reload confirm
That usually means you are throwing an NPE on startup due to not initializing a Field.
null pointer exception
aha
You might listen to interact event, check if player is holding an empty bucket and if he clicked water.
But there may be a better solution
But if a NullPointerException is thrown, why is the error not displayed?
or BucketFillItemEvent and get the item in the hand of the player
it will be somewhere in the startup
i think it's not
I restarted the server and checked, but nothing appears to be an error.
Doesn’t an exception in onEnable disable the plugin anyway
Actually nvm, reload will try to enable it again anyway
PlayerBucketFillEvent doesnt give me an previous empty bucket's ItemStack data,
PlayerInteractEvent says RIGHT_CLICK_AIR when i click an water
@frosty tinsel
Should I put a message in OnEnable()?
Is the event cancellable?
If that line doesn't work, my plugin is meaningless.
Then the envent is probably called beforehand, so if you check players current item in hand it should be the previous bucket
yes
cancel -> check -> undo cancel?
i cant understand that event called beforehand
The code inside your on.. method is called right before the thing actually happens
so if you check the player current item in hand, it should still be the empty bucket
oh
and once the method is done, the buvket is filled
I might be wrong, but am pretty sure its right
I tried this but its not working
public void onEntityExplode(EntityExplodeEvent event) {
java.util.List<Block> blocksToUndo = new ArrayList<>();
for (Block block : event.blockList()) {
if (block.getType() == Material.CHEST) {
blocksToUndo.add(block);
}
}
event.blockList().removeAll(blocksToUndo);
}
Unable to find handler list for event org.bukkit.event.player.PlayerEvent. Static getHandlerList method required!
suddenly? i didint have this error until use other LIsteners
I think you need need to set the block list.
how i can set the list?
Oh it's mutable, my bad.
arew you implementing listener
PlayerInteractEvent do well without error but PlayerBucketEvent make that error
yes
show your class
public class BucketFillListener implements Listener {
private Main plugin;
public BucketFillListener(Main plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public boolean onFill(PlayerBucketEvent e) {
Bukkit.broadcastMessage("1"); //DEBUGING
if (e.getPlayer().getInventory().getItemInMainHand().getType() == Material.BUCKET) {
Bukkit.broadcastMessage("1"); //DEBUGING
}
return false;
}
}
anyone know how i can start with making custom world gen chunks?
like i'm making a custom survival server and i want each player to be in the same world 5k blocks apart, and each player will have like a 250x250 terrain block, that also has some custom stuff
yes
Start with void and work from there.
I think there are some open source WorldGeneration plugins to.
i don't want to make a void world, i want to make customized vanilla terrain chunks in a void world
you cant customize vanilla to generate exact same chunks every x blocks
you will have to do it manually
@frosty tinsel how do i know a certain event is abstact or not?
wdym?
You said "start with world gen" I recommend you start with learning how to make a void world.
oh sorry, i meant something else then
use the worldcreator.setChunkGenerator and create your own ChunkGenerator
and the terrain will be different for everyone, right?
IT WORKS THX u all
where do i learn all of this
public class VoidChunkGenerator extends ChunkGenerator {
@SuppressWarnings("deprecation")
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
Environment env = world.getEnvironment();
Biome b = (env == Environment.NORMAL) ? Biome.JUNGLE : (env == Environment.NETHER) ? Biome.NETHER_WASTES : Biome.THE_END;
for(int c1 = 0; c1 <= 15; c1++) {
for(int c3 = 0; c3 <= 15; c3++) {
biome.setBiome(c1, c3, b);
}
}
return createChunkData(world);
}
}
```Simple void world generator. Build your own terrain generation methods from here.
Can event listener methods be private?
never thought about this but i think so
Yes but make them public, so paper can optimize them
its useless to have them private
Its a design thing
If I want the events to only be called by Bukkit and not anyone else
(not counting reflection)
This is spigot
do you want the actual event private or a listener?
How will a listener being private do anything
Paper generates code at runtime to call event handler methods instead of using reflection, which is much faster. If you make them private they'd have to use reflection
bla bla bla bla
screw it
instead do not give access to the your listeners to others. Separate plugin api and implementation
🤦 typical paper supporter.
bla bla bla bla
yea
what are you trying to accomplish?
He just gave an advice
Hes telling to do something for paper in spigots discord and says "Bla" when it was commented on
Well it did help me even tho it is spigot, so I don't see a problem
To steer the conversation away from paper vs spigot, especially in spigot's discord server, I have a question - is it possible, and if so, what is the optimal way of creating ambient lighting/particle effects at a biome, or at a region (using world guard)?
if instead of biome specific you created region specific lighting effects by hooking into wg api
Only thing I can think of are the new light blocks
haven't heard of this, can you create a new light block? are there any javadocs for this?
This is a minecraft thiong
wth .... Inventory has no getTitle ?
It’s in InventoryView now
It's an invisible block, that emits light
I wasn't questioning whether or not it was helpful. I was stating that this is spigots discord. He was talking about a forks functions. IDK why this has to be explained.
and if i have only InventoryView it sucks ^^ xD
View has, but you shouldnt use titles to compare inventories
Why does this statement only run on reload() and usually doesn't work when activating the server?
It's new in 1.17/18
I see, thank you for the feedback, and do you know by any chance if it's possible to apply colors to these lights?
can't seem to find any info regarding the subject anywhere
When are you calling the function?
onEnable()
I don't think so
How you reload the plugin?
just /reload or /reload confirm
Do not use reload.
If the plugin is being loaded before worlds, there are no chunks loaded yet
Please don't. Reload should never be used. You should create reload methiods with in your plugin.
add this to your plugin.yml
load: POSTWORLD
Why is /reload bad? They all tell me not to use it, but it doesn't tell me why :(
I'll try Thanks
It is inconsistent
plugins might break
because not actually everything is reloaded and such
yea
Never use it in production
damn it why is it my sha1 calculation doesn't match up with online ones
Even if you do reload in dev it can suck
If your server can restart its self in like ~20 seconds just restart
Do they use the same text encoding?
IllegalStateException: zip file closed 🙄
Yeah if you are getting err's from your plugin reload then test again, reload breaks stuff a lot
You probably use UTF_8, they might use somethig else
I don't really know, I tried a bunch of methods, right now I'm trying DIgestUtils from apache commons
show your functiuon
try (InputStream input = new FileInputStream(file)) {
return DigestUtils.sha1Hex(input);
} catch (Exception ex) {
return null;
}
not much to it, really
it give me a value but not something that matches
you're taking it into account that its returning a hex string?
hm no actually I switched it and didn't look into how that would impact it
I need to convert it from hex right
Yes
I had issues with that earlier
Or you use one of the other sha1 methods, one returns a byte[]
thanks but i don't really understand this
yeah I went down this road before, just need to find a good conversion to get it to become a string then
do anyone know by any chance how does a permissions system work on bungeecord
im pretty sure you just override the permissible field on spigot but i don't really know about bungeecord (I think I have seen people use an event?)
wonder if the encoding will work with just new string
Sent a link to a better explanation
lol I'm going to go with "no"
How can I turn something async into sync again without using the Bukkit.getScheduler().runTask() (I don't want to make the task number go up)
nohow
?
Literally no way
Sadge, guess I'll just have to make a new gui so it can be sync
Do you know what the max amount of tasks a server can have before it go boom?
if you get near that you're doing something wrong
Lol yeah I know that much
Do not blindly fire tasks
Just curious
is there a non deprecated method of doing this?
see deprecation note
how do i see that
docs
There should be a little comment (or just hover over the deprecated method in your IDE)
yeah I know, I was just curious. (hence why I was asking for a way to avoid doing something like that.)
I think the max amount of tasks that a server can run before go boom is 2147483647 (as that's the max integer in java.)
Probably the int max
Ya
I thought they just kept going up
No idea
Task IDs are silly anyway
When you can get a task instance instead
Although those probably still have an ID
can someone help me understand this code?
is there a non deprecated method for this though
I thought you can understand that code… if not then probably your own way of learning java isnt that effective, you should change it.
Yeah this was actually a problem on a server I used to play on apparently, they got to the point where negative ids was used instead and then back to positive ones where there were repeating tasks still using those ids. Tho I wonder how many tasks they used to even reach this "bug".
You got bigger problems if your issue is the max number of taskids lol
Indeed
smallest/best primitive to safe itemstacks ? or best way like toBase64
why I can't use 1.18.1 jar to make plugin?
its the bootstrap jar your using there
if you run the server with it once it generates a "bunder"-dir
import everything out of it to code plugins
How do I give users in ubuntu access to my server folder?
After running java -Xms16G -Xmx16G -jar server.jar nogui I get
java.nio.file.AccessDeniedException: /home/mcuser/worldmc/cache```
sudo java...
Save ItemStack a to what? A database or a file or to a string?
persistentdatacontainer
Why not just to bytes or sth
im saving it in base64 in a file rn
yeah just wondering what would be better since to bytes for a diamond sword with nothing changed is litterly a lot if bytes
hmm base64 was my way to go before too...
Tho using bytes is probably somewhat faster
Conclure is that your doggo on your pf?
Ya
is it a him or a her?
Him (:
he's cute 🥺
is he fletching his tooths there ?
like rawr
oh yeah he’s growling <:
😊
🙂
actually can a boolean array be better than like 20 booleans as fields ina class?
Using base64 in pdc is pointless. extra calculations and extra space
instead of returning the field i could just return arr[i]
Well depends, you lose readability a bit (tho it’s possible to make up for it in other ways)
situation like this
Hmm yeah maybe, or just use an Enum as flags for those bistates
why set it with constructor ... you could check those stuff in methods directly
I'd make a some sort of permission system here
mwoa a class where i have getters for each of these things goes brr but this also goes brr
eh I'd recommend having some kind of Options class
i believe its a scalling rank system ... you could easy check it with a simple id for each rank ... and then you only need to check canTalk = id > 2
I mean I’d just have something like
enum {
TALK,
INVITE}
And then use an immutable enumset maybe
daaamn that's hot
Ofc it depends on how dynamically resizable the system should be
i wanted to make it scalable, so addon developers can simply use builtin permission system
Sounds fair enough (:
yeah but the other cool thing is that you can do reverse lookup
e.g. like enum field -> enum constant
with actual enums, you'd need to have redundancy in either of two ways:
- using a map (which would require looping through each value)
- using a long switch statement (which breaks on refactoring)
what if i would just make states like talk, setpassword and add booleans for each of the ranks 🤷♂️
Enum::valueOf tho maow
but yeah this makes more sense in the context of what FourteenBrush is doing
Sure it might throw
only applies to the constant name
not the value of a constant
that’s not what you want?
e.g. one of its fields
Oh yeah
my thing was to have a default channelrank when you join a chatchannel
with flags saying what you can do
it didn't works :(
Despite being in onEnable(), strangely it doesn't work the first time I open the server Bruh
it is the default anyways
what is possible is that the chunks are not fully loaded (I'd defer this task a tick after ChunkLoadEvent), but I do not know if that is the actual cause
By default only the spawn chunks are loaded afaik
And of course register your listener in your onLoad method and do the load: STARTUP and have your current code in case someone does the /reload confirm
actually when i /reload confirm , it works well nah
As you said, it seems to happen because the server is not loaded the first time it is running.
well then should i run this after ChunkLoadedEvent only one time when server starts?
No, every time
The server will never have all chunks loaded at the same time
So instead of iterating over the world'chunks you just iterate over all the entities in the chunk that was loaded a tick after the chunk was loaded (as I do not know how it reacts when doing that within the ChunkLoadEvent directly)
Is it correct to create a new BukkitRunnable and run it after few ticks to check after event?
Yes, though I'd prefer
Bukkit.getScheduler().runTask(plugin, () -> {
// Your code here
});
since we are no longer living under the tyranny of Java 7
All well and good until you want to cancel it 😄
no
Just use a lib to handle it, far easier lol.
Bukkit.getScheduler().runTask(instance, task -> {
task.cancel();
});
eh?
lmao you're too fast
actually, that makes no sense
BukkitTask task = Bukkit.getScheduler().runTask(plugin, () -> {
// code
});
task.cancel();
this makes more sense
because you won't cancel the task while it is running, makes absolutely no sense at all
?
cancel it when something is true
you use task.cancel(); when you want to?
It’s quite sad that the one that takes the consumer doesn’t return BukkitTask
so check while its running?
you just cancel it when you wanna 🤷♂️
Yea
is it possible to check if a players input for a particle exists? i know about Material.matchMaterial but i cant find anything similar for particles
huh
Could just make your own. Use a try catch
alright thanks
You could use Enum#valueOf but a bit dangerous considering it will be gone one day
Will it?
Not guaranteed, but I consider it to be inevitable
Just give or take a few years or decades
Where can I got the spigot api
hmm yeah gotta go through deprecation first 🤡
Why cant valueOf be just nullable 🙄
you mean that it takes an enumset in the constructor?
Which event should I use to monitor when the player destroys the block
blockbreakevent
Thanks
yeah or just a vararg
hello I have probleme with mu /rtp code, the programe is all time null in the getSafeLocation, anyone can help me please ?
this is the code :
public class CommandRtp implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
Random random = new Random();
Player p = (Player) sender;
Location ppos = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ());
Location rtp = new Location(p.getWorld(), random.nextInt(10000), random.nextInt(200), random.nextInt(10000));
if (getSafeLocation(rtp) != null) {
p.sendMessage("§aLancement du teleportement aleatoire...");
p.teleport(rtp);
}
else {
rtp = new Location(p.getWorld(), random.nextInt(10000), random.nextInt(200), random.nextInt(10000));
p.sendMessage("Bug, réessais");
}
}
return false;
}
public Location getSafeLocation(Location location) {
Block b = location.getWorld().getHighestBlockAt(location);
if(!b.isEmpty() && !b.isLiquid()) {
return b.getLocation();
}
return null;
}
}```
well getHighestBlock returns a block that is AIR ?
if you do !block.isEmpy -> its false because air is empty
Hi, does anyone know how would I find the time until my repeating Bukkit Task is run again?
well you should know what time is set in for the BukkitTask
if it runs you set a variable to System.currentTimeMillies()
with that you can calc the time until it will run again
aaah
Well, am I able to fetch this value from Spigot API?
how can I add an exeption for air ?
show the code ^^
Of what
just check block.isAir()
your runnable
oh okay
bukkit task^^
currentTask = new BukkitRunnable()
{
@Override
public void run ()
{
decrease();
}
}.runTaskTimer(plugin, 0, unit.getTicks());
unit.getTicks ?
then it will run every 20 ticks O.o
I am in 1.12.2 I don't have b.isAir()
each second
block.getType == Material.AIR then
ah yes okay
I know, but how would I now anytime in the code would check, how many ticks remain til running
with the BukkitTask object
i already explained to you that you need to store the last run time
well I work with ticks here
I want to tp the player on the ground
If I would want it to be synced and like precise to the ticks
you can do math for that ?
if you have lastRun just do:
dif = System.timemillis - lastRun
now you have the dif in millis and calculate out of that the ticks
20 ticks = 1 s
1s = 1000 millies
Any way to get the time in ticks. For example ticks from the server start
dk
but not in blocks ?
exact
so the block where the teleport should go should be empty ? ... and not not empty ?
Also the SystemTime is not prtecise, if the server has lags or something, the ticks may not be 1 second = 20
the player do to tp in the surface
like the /top
nothing precicer then this ... you can run your task every tick and only if tick%20 == 0 run the stuff inside
if(!b.isEmpty() && !b.isLiquid()) {
return b.getLocation();
}
then this is just wrong like i told you 3 times now ...
I meant, that the time may not correspond with ticks if there are lags
you WANT an empty block and not an not empty block
the block cant be liquid i guess either
okay
i know but you cant do smth else then running it every tick and use those ticks to calculate the next run
sounds more like xy problem
this not resolve the problem, if i am tp in a cliff i am in the ground
and i do that ```java
public Location getSafeLocation(Location location) {
Block b = location.getWorld().getHighestBlockAt(location);
if(!b.isEmpty() && !b.isLiquid()) {
return null;
}
return b.getLocation();
}```
you dont want to teleport the player if there is liquid or blocks right ?
no
i want to tp the player in liquid or on the ground for not take fall damage
aaah i have found my error
I have 200iq
if the payer tp I add an rresistance effect 1000 for 30 sec
does the translateAlternateColorCodes method only replaces & by § ?
And what if the ground is lava
is liquid ?
yea, lava is liquid
ah ! uh good idea
the ground is liquid
it can use every char
yeah but its basically a glorified String::replace (not rly but sort of)
this is good ? ```java
if(b.isEmpty() && b.isLiquid() && !(b.getType() == Material.LAVA)) {
return b.getLocation();
}
return null;
}```
it's just that the ampersand is most prevalent due to historical reasons
highest non-empty (impassable) block... so it will be a solid block or maybe liquid.. you should test for the block above that
and check if the block itself is a solid block
there is no block above if it is the highest solid block
i dont know about that "impassable" in the javadocs so i would test rather this
could be that liquids dont count and you can land on the ground of a ocean with that method
like this ? ```java
public Location getSafeLocation(Location location) {
Block b = location.getWorld().getHighestBlockAt(location);
if(!b.isEmpty() || !b.isLiquid() || (b.getType() == Material.LAVA)) {
return null;
}
return b.getLocation();
}```
-.-
uh okay
Not using depenency injection
I don't understand and google translate is not very intellectual x)
i use it so many but i dont trust it
Checks if this block is empty.
A block is considered empty when getType() returns Material.AIR.
public Location getSafeLocation(Location location) {
Block blockNotEmpty = location.getWorld().getHighestBlockAt(location);
if(blockNotEmpty.getType().isSolid() && blockNotEmpty.getRelative(BlockFace.UP).isEmpty()){
return blockNotEmpty.getLocation().add(0,1,0); // <-- Location to teleport player
}
return null;
}
FreeSoccerHDX's code does not make sense
okay
aaaah okay
where O.o
The highest non-empty block will never have a non-empty block above it
You can also use public int getHighestBlockYAt(int x, int z, @NotNull HeightMap heightMap); to be extra sure
depends on what impassable means since liquid is passable in some kind
As
/**
* The highest non-air block.
*/
WORLD_SURFACE,
So I'm writing a plugin that targets both Fabric and Spigot, and I'm wondering if vanilla minecraft classess are accessible in Spigot
ye they are
no
okay
depends
you got all the server nms classes at least if you add spigot (not spigot-api)
They will have different names
idk if the client ones are added as well
I'm aware of that
probably not
But they will be present mostly, although some might be changed
Spigot has basically no access to client classes but Fabric has access to all classes.
Yeah
@quiet ice this code will not work above grass (!not blocks) or liquids !
it will return null
Fuck it, I will write a proof-of-concept plugin
this works perfectly fine with everything except liquids ^^ probably the result that he wanted
is it good or did I make a mistake again? ```java
public class CommandRtp implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
Random random = new Random();
Player p = (Player) sender;
Location ppos = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ());
Location rtp = new Location(p.getWorld(), random.nextInt(10000), random.nextInt(200), random.nextInt(10000));
if (getSafeLocation(rtp) == null) {
p.sendMessage("§aLancement du teleportement aleatoire...");
p.teleport(rtp);
}
else if (getSafeLocation(rtp) != null) {
rtp = new Location(p.getWorld(), random.nextInt(10000), random.nextInt(200), random.nextInt(10000));
p.sendMessage("Bug, réessais");
}
}
return false;
}
public Location getSafeLocation(Location location) {
Random random = new Random();
Block blockNotEmpty = location.getWorld().getHighestBlockAt(location);
if(blockNotEmpty.getType().isSolid() && blockNotEmpty.getRelative(BlockFace.UP).isEmpty()){
return blockNotEmpty.getLocation().add(random.nextInt(10000),1,random.nextInt(10000)); // <-- Location to teleport player
}
return null;
}
}```
At this point use HeightMap.WORLD_SURFACE instead
actually, I see
why do you add smth random to it @wraith hare
uh this is a test i forgot to remove
the add(rnd10000,1,rnd10000) just destroys the concept of checkig for a good block to teleport
new SentryTask(Livingentity).runTaskTimer(Bukkit.getPluginManager().getPlugin("Sentry"), 0, 30);
Did I wrong?
it works only one time
okay
dont Bukkit.getPluginManager... use the instance of your JavaPlugin directly instead
this is probably want you rly want @wraith hare ... returns location only if not liquid
can you show me some example?
dont have a example but in your onEnable you can set a static of you plugin ...
create an public static getter for it and then use it
This is the plugin in question: https://github.com/Server-Cross-Platform/SXP-API
do u mean NMS?
yes
but I don't have the "isPassable()" function
I'm Scared of using static
terrible trauma
what mc version ?
1.12.2
do you have isSolid ?
yes
replace isPassable with !isSolid
should probably work too
Use JavaPlugin.getPlugin(MyPlugin.class) instead
upgrade to 1.18
Typical 1.8 user
Thanks
I stop I continue tomorrow it is a little complicated
Why doesn't the itemStack.getEnchantments() method return a list that contains my unsafe enchantment?
Use dependency injection
It has the enchantment
custom enchants are generally unsupported
how do I get it then
Custom enchants and unsafe enchants are not the same thing
ah
so do I have to use an other method to add my enchantment or what?
No
it adds in-game, but I can't get it using this method
Can we see the code
yes
CustomEnchantmentWrapper.java: https://pastebin.com/gW1zfHSt
CustomEnchant.java: https://pastebin.com/AHmxLDCr
TestSubCommand.java: https://pastebin.com/X1NpvTRt
Oh so you are doing custom enchantments
yes
I’m not sure if that method can return enchantments not part of normal Minecraft
That may be your issue
well yes, but what method should I use instead
I don’t know
I’m not sure how the spigot internals handle that off the top of my head
I’ll take a look
Tentatively it seems like that method should work
I'd suggest using pdc for custom enchants
@spare prism how many enchantments are returned in the map?
[19:05:48 INFO]: [ProjectZ] get / itemEnch: [Enchantment[minecraft:sharpness, DAMAGE_ALL]]
in the fact there are two of them
So none of your custom ones
yeah
When you log out are your custom ones still on the item?
u want me to rejoin my server?
Yes
maybe
yes
How do you implement getKey?
should I override it?
Huh? What identifiers
like parameter names, fields etc
In reality it supports almost every unicode char
Is the JavaPlugin$onLoad method ran before the world is loaded?
i saw utf8 so i was confused
Actually, not by default, but it is possible to do so via load: Startup in the plugin.yml
@brave sparrow, @quaint mantle, the problem was that I put the wrong check when I registered the echantments. Now it works. Tysm for trying to help me
By default onLoad executes before worlds are loaded, unless performing a reload
Ah yeah, Elgar is right I am blind
I'm not sure how I managed to mistake that as it loading after world load
[17:48:33 INFO]: [PlayerCurrency] Loading PlayerCurrency v0.0.1-SNAPSHOT
[17:48:33 INFO]: Server permissions file permissions.yml is empty, ignoring it
[17:48:33 INFO]: Preparing level "world"
[17:48:34 INFO]: Preparing start region for dimension minecraft:overworld
[17:48:35 INFO]: Time elapsed: 357 ms
[17:48:35 INFO]: Preparing start region for dimension minecraft:the_nether
[17:48:35 INFO]: Time elapsed: 169 ms
[17:48:35 INFO]: Preparing start region for dimension minecraft:the_end
[17:48:35 INFO]: Time elapsed: 144 ms
[17:48:35 INFO]: [PlayerCurrency] Enabling PlayerCurrency v0.0.1-SNAPSHOT
That being said, the load arg is a bit strange knowing that officially it is postworld by default
is there a set that doesnt allow nulls?
hashset allows one null
concerning users doing stupid things
you shouldnt store nulls
Hello everyone! I've got a quick question
it seems like you're typing the bible though
lmao
that isnt exactly what i expected from a quick question 😔
I created a listener which sends a player the coordinates of the location where they died which gets executed when said player dies (on player death event). In the chat the player receives this message before before the server broadcasts the global death event. So the chat looks like this:
<Player> died from falling
Is there an easy way to make it display like this without scheduling a timer?
Psst, you died at [x,y,z]
So first the server message and then the personal message
Haha, I'm tryin to make the question as clear as possible
set the eventpriority to Monitor?
i think the server will still broadcast it after that
maybe worth trying
I tried changing
@EventHandler to @EventHandler (priority = EventPriority.LOWEST) and @EventHandler (priority = EventPriority.HIGHEST) and neither of those made a difference
What does eventpriority Monitor do?
like the same to highest but it indicates that the listener shouldnt cancel the event
Send the message in the respawn event https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerRespawnEvent.html
Else you will have to schedule it.
I was thinking about that too! But I think the respawn event doesn't have a location logged in it? So that would mean that I need to listen for the deathevent, record the location and then display it in the respawn event?
@glossy marsh alternatively you can save the death message string with event.getDeathMessage() then set it to empty with event.setDeathMessage(“”)
The player is not yet dead at the PlayerDeathEvent, which is why it does not work
Then just reprint the message after ur cords
Perhaps the monitor priority does it, but I highly doubt it
Just store the death location in the players PDC, or simplest is just RunTask when he dies.
^ probably the best solution
The Monitor priority didn't fix it
is there way to speed up crop growth but not everything random tick speed related
I kinda like this solution as well. I was playing with the idea of showing the death message as usual for all the players but making a different death message for the player that died which is clickable and copies the coordinates to your clipboard
You mean reprint it as a server broadcast?
Ohh right yeah thats easy
I don't fully understand your solution because of my lack of java knowledge. What is a player PDC and what is RunTask?
@EventHandler
public void onDeath(PlayerDeathEvent event) {
String deathMessage = event.getDeathMessage();
event.setDeathMessage("");
Location loc = event.getEntity().getLocation();
event.getEntity().sendMessage(loc.getX() + ", " + loc.getY() + ", " + loc.getZ());
Bukkit.getServer().getOnlinePlayers().forEach(player -> player.sendMessage(deathMessage));
}
this will print the message after and should print it to all of the players
Thanks!
And thanks!
You all have been of great help, thanks a lot! Is there any way in which I can support this community? It's really great how quickly and well you guys help me
np man, anytime!
i think setting the message to an empty string will show an empty line to the client
i had it with the join event
null might be better
Yeah maybe, if "" doesnt work try null
you can support the community by donating a sum of money to me, a representative of the community
I'm trying to create a written book, but the addPage() method doesn't seem to work for the book's BookMeta.
No matter what I put into the String argument, when I open the book it just shows "* Invalid book tag *"
Am I doing something wrong?
make sure ur updating the meta after you set it
here's my entire code for it
ItemStack smelterBook = new ItemStack(Material.WRITTEN_BOOK);
BookMeta meta = (BookMeta) smelterBook.getItemMeta();
meta.setTitle("A Guide to Smelters");
meta.addPage("test1","test2");
smelterBook.setItemMeta(meta);
a common question, is there a way to change max stack size of vanilla itemstack?
Maybe try adding an author?
I looked at the NBT data for the book
All the page text is getting put in the "extra" section of the page info, and the text field is empty
I'm assuming it has to do with that
ill try that
yep that seems to have worked
thanks
For me this shows no line at all, so it works!
🤑
For anyone wondering! I found a way for to classes to communicate efficiently
Makes it easy to organise code
I'm really tired but I want to get this done before I head out, can someone tell me if getting a CME:null makes any sense on this line?
for (ObjectiveDestinations iteratedObjectiveDestinations : objectiveDestinations)
can CMEs even fire when you just call for an iteration
I'm trying to make a command that takes a string, but every space (even if theres quotes) is considered a different arg. How do I either take a string inistead of a list, or join the args as a string (keep in mind theres no set amount of words/args per cmd)
do you want any args after the string?
no
then you can take the args array and loop through it and create a string builder
String combine = "";
for (String arg : args) combine += arg+" ";
combine = combine.substring(0, combine.length()-1);
So like a ban command? where you have to give a reason?
stringbuilder would like to know your location
Xd
@tame shoal kinda. @low temple @upper niche thx
who need stringbuilder when you have += 😎
SO basically you just need to add the arg untill there is no more or you reach an arg that has a certain string
yea
Alr anything else?
no
kk
it would be /cmd {the rest of this is one string}
yea
String.join(" ", args) or something close
hhow would i do that tho
StringBuilder builder = new StringBuilder("");
for (String str : args)
builder.append(str + " ");
String argString = builder.toString().trim();
for (String args : in args) {
if (arg.equalsignorecase("thing")) {
// idk
} else {
//something else idk
}
POV: Discord is your IDE
And you make the classes as channels
lmfao
XD
POV: you don't know what code block is.
POV: yOU CAN'T CODE IN JAVA
haha what a joke
if you want the block format use a tripple "`" before and after ur text
what's the minecraft id for "Air"
minecraft:air
Novas in the njmber
minecraft:air or 0 if you;re using numerical ids
Anyone know how often the player's right click action is repeated when holding down the mouse button
how do i add an element to a list
probably once
List#add()?
?
I think it depends if theyre holding it on an interactable block
i think it goes up to 20cps
i dont understant what # is. i see it all the time, but i dont get it
like if they hold right click on a static block like stone it might only fire once
Pretty sure # means an instance method
but if its a block like a chest or door itll fire as fast as they door id opening/closing
Take it as an replacement for .
oh ok thx
But like
How would you tell static method?
.?
i think no matter what its #, it's mainly for documentation tho
ok
You are incorrect 🙂
nvm
how is it?
is documentation
aha, knew it
it doesn;t really matter which you use
in here we generally use # unless writing actual code
It may be a javadoc thing.
anybody know 1.7-1.12 fawe maven rep/dep?
Somehow I couldnt find it
I've also learned that '.' is used for static and '#' is used for instance context.
I see that the inet partly disagrees...
There doesn't seem to be a consensus. But discussions here in the past have generally come down to "it doesn't matter" and "# is documentation".
i was about to say
it really doesnt matter
originates from url addresses i think, hence documentation
Heya all, question, I made my first plugin to mute the chat and it works flawlessly on my private server but when I put it on my public server it decides to just not work at all the command doesn't show up or anything...
have you checked your log?
Type in /pl and see if its listed and/or red
not listed...
Then its not in the plugins folder
did you add it after starting the server ? then use reload first ...
in bungeecord, is there an event or way to execute code when a server is about to stop? i'm trying to setup a fallback server that players get sent to when the server they're in stops or restarts. i tried to find a way to do it without a plugin but i can't find a way
It's there and I turned the server off added it and then started it after adding it
"root root"
Why does your root user have ftp access???
plot twist he just made a user called root
...
Thats pterodactyl isnt it
How'd you know? XD
I made a parrot rideable but how can I make it controllable?
Because when I search on google I always find about custom entity but mine is the normal parrot so can I do it
is there anyone here that can answer my question
Are you talking to me or him?
to vizored
i guess so. i tried to look at the config.yml to see if there was an option to setup a fallback server but i couldn't find anything.
oh ok
im digging through code to see if i can help you
i would go to #help-server first, there should be a config option
i tried. no one responded.
alright. thanks for helping me either way
so far the only way to do it is to set a temptation item on the entity by accessing its pathfinder
or just make a custom entity that overrides the move method
the second is gonna be a lot more painful than the first
both require NMS
So the easier one is the first one right?
yes
Ok I will try that
but that means the player has to have an item in hand
ok
this.goalSelector.addGoal(4, new PathfinderGoalTempt(this, 1.2D, RecipeItemStack.of(Items.CARROT_ON_A_STICK), false)); thats what i found for a pig
So I can choose any item in the hand and he will just follow it right?
youll have to test it yourself, this isnt something ive done before
but that is my assumption
what mc version are you using btw
i might see if i can PR something that allows for this change in spigot
1.14.4 atm
eh well my change wont help you then
You could change it if it was a newer version?
i can only patch latest versions of spigot
Is there a way to shade protocol lib into your plugin?
why would you want to do that?
would you? couldn't you just replace that goal with a new one in an existing pig entity?
the movement controller for passengers isnt controlled by pathfinders
its the acutal movement method in the entity
ah nvm then.
Creating a custom entity and making it controllable
how do I code in spigot
why do java
yeah, why smoke tobacco if you can use crack instead, right?
Why not scratch
how do i hypixel
no idea, I'm banned there
yeah id even know why
have you appealed it
spoken like a true cheater
I really didnt cheat 😄
my account was banned for "security reasons"
Happens when your account logs in from weird places
yea
Like
what is a weird place
The United States and then Australia right after
Germany
what if they moved
Me = germany, not a weird place lol
how could i implement unit of work design pattern in spring
whut
is there a way to speed up plant growth not all random tick speed
sure, just manually grow those crops
._.
all crops blockstates are instanceof ageable
Sometimes I wish we had a random tick event
myPotato = (Ageable) block.getState() or sth like that
but why
Like he said, do it manually
Running into an issue as to why my commands are not executing
public class RemoveRing implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
System.out.print("Here");
if (sender.isOp()) {
System.out.print("Here2");
if (command.getName().equalsIgnoreCase("removering")) {
System.out.print("Here3");
if (args.length == 2) {
Player admin = (Player) sender;
Player target = Bukkit.getPlayer(args[0]);
admin.sendMessage("Here");
String oldArray[] = {"dwarvenRing", "Narya", "Nenya", "Vilya", "nazgulRing", "thePrecious", "theOneRing", "witchKingsRing"};
String translateTable[] = {"Dwarven Ring", "Narya", "Nenya", "Vilya", "Nazgul Ring", "The Precious", "The One Ring", "WitchKings Ring"};
String ringName = translateTable[Arrays.asList(oldArray).indexOf(args[1])];
admin.sendMessage("ThisPoint");
ItemStack itemToRemove = null;
List<ItemStack> itemList = Arrays.asList(target.getInventory().getContents());
for (ItemStack item : itemList) {
if (item.hasItemMeta() & item.getItemMeta().getLore().contains(ChatColor.WHITE + ringName)) {
itemToRemove = item;
break;
}
}
if (itemToRemove != null) {
target.getInventory().remove(itemToRemove);
target.setMaxHealth(20);
}
}
}
}
return true;
}
}
This is my executor Class
My plugin.yml command register line:
removeRing:
description: test
usage: /<Command> <Target> <ringType>
package mythicmidgard.feroxidus.mythicutilities;
import mythicmidgard.feroxidus.mythicutilities.commands.adminCommands.RingCommands.GiveRing;
import mythicmidgard.feroxidus.mythicutilities.commands.adminCommands.RingCommands.RemoveRing;
import mythicmidgard.feroxidus.mythicutilities.commands.adminCommands.loreCommands.*;
import mythicmidgard.feroxidus.mythicutilities.customEnchants.ringEnchants.OneRingUse;
import mythicmidgard.feroxidus.mythicutilities.customEnchants.ringEnchants.RingEffects;
import mythicmidgard.feroxidus.mythicutilities.customEnchants.ringEnchants.SoulLock;
import org.bukkit.plugin.java.JavaPlugin;
public class MythicUtilities extends JavaPlugin {
public static MythicUtilities plugin;
@Override
public void onEnable() {
//Commands
getCommand("getMat").setExecutor(new GetMat());
getCommand("getList").setExecutor(new GetList());
getCommand("addEnchant").setExecutor(new AddLoreEnchantment());
getCommand("addLore").setExecutor(new AddLoreInfo());
getCommand("setName").setExecutor(new ChangeDisplayName());
getCommand("removeLore").setExecutor(new RemoveLore());
getCommand("giveRing").setExecutor(new GiveRing());
getCommand("removeRing").setExecutor(new RemoveRing());
//Load Enchants
getServer().getPluginManager().registerEvents(new SoulLock(), this);
getServer().getPluginManager().registerEvents(new RingEffects(this), this);
getServer().getPluginManager().registerEvents(new OneRingUse(), this);
}
}
Main Class
The issue is, whenever I fire a command
it never reaches the executor, and just prompts me with the Usage of the command
I know that it is not reaching the executor as it never prints in console
@ me
Is there any way to stop an event listener from, listening
Explain?
so where you use PluginManager.registerEvents to register event listeners, how would I deregister them
You only have one command in yoru plugin.yml and you are not registering that command.
I can send the whole yml I just send a small thing...
name: MythicUtilities
version: '${project.version}'
main: mythicmidgard.feroxidus.mythicutilities.MythicUtilities
commands:
getMat:
description: Retrieves items Material Enum (For Development)
usage: /<Command>
addLore:
description: Adds lore to an item
usage: /<Command> <Lore> <ChatColor>
setName:
description: Changes the displayName and color of an ItemStack
usage: /<Command> <Name> <ChatColor>
getList:
description: Returns varied listTypes, (listTypes found with listType "listList")
usage: /<Command> <listType>
removeLore:
description: Removes a line in an items lore with line number
usage: /<Command> <Line>
giveRing:
description: Gives a ring of power to specified player
usage: /<Command> <Target> <ringType>
removeRing:
description: Removes a ring of power from specified player
usage: /<Command> <Target> <ringType>
Entire yml
Check yoru latest log startup for any errors
reloading causes no errors, shall I restart server entirely?
yes, clean startup
k
an OnEnable error I see
For some reason it was warning me that there was missing imports wierd
ty Elgar
HandlerList.removeAll
Hey when I try to use gson for serialization of objects I get the java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.Object java.lang.ref.Reference.referent accessible: error what exactly can I do about this?
Thank you, is there any way to get a handler list if I don't have an event object
That is a static method
guys, so i'm making a "rank shop" gui, and for example a "diamond rank" will expire after 7 days. how can i do that with bukkitscheduler?
i tried to watch videos or read docs but i cant get that in my mind
like the idea would be this: when i buy it to run the "timer", and on server stop to store the time left in a config. then when server starts it should get the updated time left. but idk how to program that
Hey, I'm trying to make a countdown that starts at 300 seconds if there aren't enough players in the game, and if there are enough, it goes down to 60 players and if players leave and there arent enough players again, it goes back to the original 300 seconds, and so on. How would I go on about creating this?
I do know how to create a countdown, just not quite sure how to make it do all that
It depends on how you want resuming to work, but you can keep a reference to the task that is currently running and keep a boolean variable representing whether or not the time is in shortMode. Then whenever a player leaves or joins the lobby you can check for your conditions and change the runnable and shortMode variable accordingly
couldn't you just store the time that the rank was bought and then use basic math to work it out from there (by starting a repeating task in onEnable that checks every x amount of time, like every 5 minutes or so)?
if (currentTimeMs - timeStartedMs >= amountOfTimeTheRankIsAllowedMs) {
// the rank has expired, remove it
}
to get the current time use
System.currentTimeMillis();
there's probably a better way of doing it, but thats off the top of my head
oh that's even better
thank you so much ^^
Some permission plugins already do this. GroupManager has timed permissions and groups
^ theres that too
i'm using the luckperms api and it doesnt have any timed permission function lol
How can I do so that if I run, for example, 3 tasks (runTaskLater) that are to be executed, for example, in 5 seconds, and if the task is called again during this time, the previous ones will be canceled, and the one that was called last, will be done
What are you trying to do
for example, I type a command, and a message will be sent in 5 seconds. But if I type this command quickly several times, it will send several messages. I would like to do so that if there is already a task in the queue and it is called again, the one in the queue will be canceled and the "newest" one will be executed.
and then it will only be done once, not a few times
I tried this: https://paste.md-5.net/edazojopop.java, https://paste.md-5.net/hevoyuzahi.java - But it didn't work out as I wanted it to. When there isnt enough players, it just stays at 290 but when there are, it doesnt switch to 60 seconds, it then starts to countdown from 290 seconds
How can I get highest block in x, y coords?
I have x and y coordinates and I would like to get highest y coord
world.getHighestBlockAt(x, y);
okay so i want to run a method after x amount of seconds, it also needs to be able to access fields in my plugin class too
make a task, and run it x seconds later
and how would i make a task exactly
all the ones ive tried cant access the fields in my plugin class
Is there a way of tping someone to the center of the block?
instead in the middle of 4?
I tried adding 0 .5 to x znd z
but doesn't work
It does
Player player = ((Player) sender).getPlayer();
Random random = new Random();
World world = player.getWorld();
int x = random.nextInt(7500);
int z = random.nextInt(7500);
int y = world.getHighestBlockYAt(x, z);
x += 0.5;
z += 0.5;
Location randomTP = new Location(player.getWorld(), x, y, z);
player.teleport(randomTP);
player.sendMessage(color.translate("&aHas sido teletransportado a: " + x + ", " + y + ", " + x));
what does chat msg say ?
oh
yes adding double to int ^^
you cant add 0.5 to an int ^^
No
The problem is adding a double to an int
Use location#add Instead
It will also keep your output as whole numbers, which I assume you want
try casting int to double
he isnt the one who needs help ^^
Hey, I'm trying to make a countdown that starts at 300 seconds if there aren't enough players in the game, and if there are enough, it goes down to 60 players, and if players leave and there aren't enough players again, it goes back to the original 300 seconds, and so on. How would I go on about creating this?
I do know how to create a countdown, just not quite sure how to make it do all that. Till now I got this: https://paste.md-5.net/evunupuned.java, https://paste.md-5.net/etasexiqic.java - But when I tested it out, it didn't work out as I wanted it to. It doesn't go down to 60 seconds when there are enough players, and it does not go back to the original time if there aren't enough anymore.
the problem is that I don't get tped to the center of the block
because its integer i think
@terse ore the reason for you problem is litterly 3 times in the chat now
Location.add(0.5,0,0.5)
yea its nice too
just do loc.add(x, y, z);
Is there any way that I could detect flight cheats accuratly? I don't want spoon feed code i just need help with a method that I could do this. just explain mostly xd
p.getAllogFlight(true/false);
maybe player.isFlying ?
.<.
You do know... that it won't work JUST like that
player.getAllowFlight()```
if you want to detect if a player is flying then use this method ...
not as in cheating
I know basic spigot api/java
I'm not that dumb
I need a method of detecting flight hacks
I know how to detect KA
but not flight......
Do anyone know how to help me with the quoted issue?
AHh what s it called
Hey I'm trying to add "waits" or "sleeps" whatever you want to call them. I just want to be able to pause the code for a certain amount of time. Here...
And every time just do time = time -1
I know all that
then set the chat thing as time
That I know
Then that's all you need...?
it just doesn't work if you look at the two pastes that I linked
It doesn't go down to 60 seconds when there are enough players, and it does not go back to the original time if there aren't enough anymore.
that's the issue
that is it
Alr
Every second, check the amount of players
and make a different public void
and if the players are less, run one of them
and if the players are more
run the other 1
Isn't that what I'm doing here tho? https://paste.md-5.net/etasexiqic.java
It's not every second
What I would do (incredibly inneficiently)
Is that it countdowns a second
.runTaskTimer(Game.getInstance(), 0, 0); that shouldnt even work tbh
and takes away a second from a defined int
1
untill that int becomes 0
so 60, 59, 58... 0(STOP)
and for every time it does that
it checks the players
not sure why we would need to do this every second o.O
adds a value to a location
as long as you recognized it isn't efficient because there is events you can listen to that would make it better lol
Xd ik
I tried adding java if (!(Bukkit.getOnlinePlayers().size() >= EnoughPlayersCheck.minimumPlayers)) { new Thread(new EnoughPlayersCheck(stateUpdater, chatUtil)).start(); cancel(); } to the countdown file but then it just spams the original time and doesnt go down
need to add a method to reduce the time
loops don't automatically do that on their own 🙂
How can I do so that if I run, for example, 3 tasks (runTaskLater) that are to be executed, for example, in 5 seconds, and if the task is called again during this time, the previous ones will be canceled, and the one that was called last, will be done
Unable to make field private java.lang.Object java.lang.ref.Reference.referent accessible: module java.base does not "opens java.lang.ref" to unnamed module @20ef37c3 does anyone know what this means..? I have been looking for ages but I can't really find an answer 😦
you're likely passing garbage into gson
but without the full error we really cant help you
gson is not magic, it can't just turn everything you give it into json
I'll give the full error 🙂
It basically means you are doing naughty things with reflections
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Basically GSON cannot serialise a java.lang.ref.Reference object
probably trying to throw a Location into gson without writing a serializer
Locations contain a World, how can gson write an entire world to json?
you should just use yaml, spigot contains extensive APIs for handling yaml, and inbuilt types like Location
Aha, okay did not know that 🙂
Hey so i'm a bit new to creating plugins and need to recompile a plugin i had someone make for me. They created it and since its creation some external endpoints it calls to have changed and I need to recompile. Can someone help me with this?
This is the Github of the plugin's source. https://github.com/FoldedLettuce/Hyper-Minecraft-Auth
Ahn yes it works! @sullen marlin Thank you!
Just broke the Location down to it's x, y, z coordinates and its world name 🙂
You could always use the inbuild Location#serialize()
Anyone know the difference between these two repos? Which one should I use?
https://hub.spigotmc.org/nexus/content/repositories/snapshots/
https://hub.spigotmc.org/nexus/content/groups/public/
snapshots
bump
I still don't really understand the difference, both jars have -SNAPSHOT, are they both snapshots?
/public/ is a relic from when we mirrored maven central
we don't anymore, but you should use /snapshots/ in your own project
that plugin has no build system so you need to compile it the same way is if you were making a plugin from scratch
any tutorial on creating a plugin will help you with this
Alright, Got any links to something good? There are so many.
I don't have a tutorial handy, someone else might, but you will find thousands on google
Ok thanks will just look thru them
either specifically for your IDE, or maven/gradle
no, visual studio is not a java IDE
Ah
Netbeans, Eclipse, IntelliJ are Java IDEs; Maven and Gradle are Java build systems
you can probably find tutorials for any one of those 5
Perfect let me get looking.
VS does support Java however
I wouldn't consider it a proper IDE for Java like some other ones that are more tailored for it
but you can still use it and compile etc
Yea, Im just gonna download IntelliJ
presumably you mean visual studio code; and that's like saying notepad supports java
it still needs a build system to build java
it supports it natively
Nah I mean physical Visual Studio.
Think this vid will be good or should I find a more recent one? https://www.youtube.com/watch?v=FnqZJjgGGmo
In this episode, I show you how to export your plugin's code to a jar file in the server plugins folder with a few buttons clicks. No longer will you have to use Maven and then move the files manually. #Spigot #MinecraftPluginDevelopment
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin int...
I don't use VS for java because that is just a way too bulky/bloated IDE for such things and we have better IDE's specifically geared to Java
VS isn't specifically geared for Java lol
Spigot has some actual tutorials rather than videos
Oh got a link?
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Ty let me try this.
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
ty
anyone know open source plugin use AspectJ?
I try make Load-Time Weaving in AspectJ but ...
not gonna be fun
yea ;/
I mean if you just add it as an agent its probably ok?
for public plugin though, no one wants that
I am honestly a bit of a beginner in AspectJ
overall I was looking for a way to turn off the falling gravel and sand
but I couldn't find a good solution other than editing the engine and AspectJ
I am making a plugin that makes some sort of a gun I got stuck when I was trying to get an arrow to launch out of the player I know how to launch the arrow its just that the vector I made is throwing an error or intelliJ is throwing an error ```java
Vector v = e.getPlayer().getLocation().getDirection();
wait
isn't there a method to make a location to a vector