#help-development
1 messages · Page 183 of 1
inserts command framework
commands:
command:
description: blahblah
^
still not working
?paste your plugin.yml
um, check yrou startup log you will see an error about Main
something about Main not found
what is the package your Main is in?
very top of the Main.class
is it even in a package?
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
no
uhh
weird
ok
Why!!
You can do that, but it's not normal
That why haha
hhhhhh
add in your onCommand a sysout to show it's being callled. I say it will not be
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
hm
When you find your onCommand never fires, you need to fix your project setup and add a package
also fix your plugin.yml to point main to the new location
put it above the 'if`
ok
then I see no reason for your issue
unless
wrap the code inside your executor in a try/catch
I'm going to bet teh executor is consuming an error
eclipse 🤢
I mean i dont like it as personal experiences hahaha
Just dont give attention to my msg
Exception not IOException
Did he learnt java before coding?
I dont want to sound rude but i dont think he learn it
you sound rude
not working
- no errors
I mean its okay, but you should self realize that if you dont learn how a language work or learn it its really diffuclt to code
And people will get tired of helping because they will explain u in a technical way which you should not really understand them
I recommend getting rid of your executor service and use teh Bukkit Scheduler
ok.
Hello
Can someone help me with the ChunkGen class?
Have you searched for the answer on google first tahd?
guys
Tried, but nothing is close to what I am trying to do
I'm sure if I search up what you are asking I will find an answer rather quickly
what the
in real spigot versions we have the PersistentDataContainer on entities
what is the similar on 1.8?
before you say anything, it is for a client
declaration: package: org.bukkit.generator, class: ChunkGenerator
here is the dogs
docs
hello buddy
update your graphics driver?
Im trying to gen a world based on scematics. IS that possible?
Already done lmao
So what is the problem
I'm trying to add some attributes modifiers adding some armor points, this actually works, but somehow when I try to use it, it doubles the damage
Did you not read it?
Any ideas?
Also this guy has a video about it https://www.youtube.com/watch?v=8qlnlvigodM
Love the video or need more help...or maybe both?
💬Join us on Discord: http://discord.gg/invite/fw5cKM3
Thank you for tuning in to this episode of TheSourceCode! ❤️
If you enjoyed this video make sure to show your support by liking , commenting your thoughts, and sharing for all your friends to see and learn!
All code is available on Github:
...
Hold on lemme test mine
thanks
Il come back with a error
Anyone know a good resource I could read up on how to postpone a method continuing to run?
Like if a method is run, I want the function to stop, until that method says that it should continue.
I thaught about having a kind of manager class in a different thread and then just stopping the main thread until the the method is done.
But this has the issue, that it would also stop any processing of other incoming events... soooo
Ping me, if you got something. Still need to do some more research
?scheduling
fair enough, but I can't use this, since it's not a spigot specific thing, rather just a java util.
But I don't want to wrap it in a runnable either
Why you wouldn't be able to use it.
I mean, usually you'd wait for a future to complete
that represents the other data
DeveloperWilliam, I got no errors, but the scematic doesn't seem to load for the world, may I send my source code here?
go ahead
Alright
Main class: https://paste.md-5.net/egufehuvup.java
ChunkGeneratorClass: https://paste.md-5.net/ohikebifev.java
The main issue I have, was that I don't want to use a bunch of lambdas and create a "power tower" of lambdas, cause the api I am using has a bunch of things async.
That's why I want to have like an annotation or smth which just goes: "Hey, wait until this is done ;P" and just does it, without having to do a lot with lambdas
will respond in some time, currently doing something.
I mean, lambda wise you just want to flatten your thing or well join on the same thread. Depends on what you want.
Could also just use a super straight forward locking mechanism
like a plain semaphore
can i teleport entities through worlds?
how to rotate armostand to an location?
Greened123, you gotta learn some stuff on your own my man
if you type that exact thing into google and add "spigot" before it will show up
Google your question before asking it:
https://www.google.com/
already did it
Location loc = armorStand.getLocation(); loc.setYaw(loc.getYaw() + 2.0F); armorStand.teleport(loc);
put that into a timerRunnable and change the delay / the rotation increment if you need to
wdym
turn it's head to be straight to some location
so basically the armorstand has to look at a location?
yes.
you mean you need the math to find the angle between two points?
yes.
^
pitch then
dud
yes
do i need to use math? :/
are you wanting to make a plugin on ur own
...
or do you want someone else
to make it for you
since you can apply for someone to make it in the spigot forums
this channel is for helping, not spoon feeding every line
there isnt some magical thing already implemented to do every math equation you would ever need
what is atan2?
Google your question before asking it:
https://www.google.com/
haha, look at me using commands
;)
Anyone here know what im doing wrong?
if I use ```java
location.getWorld().spawnParticle(Particle.SHRIEK, new Location(location.getWorld(), location.getX(), location.getY()+1, location.getZ()), 1, 0);
A. it spawns it at 0,1,0 when thats not the location's values
B. it will kick me and spew that error below (the photo)
But if I try using
```java
location.getWorld().spawnParticle(Particle.SHRIEK, new Location(location.getWorld(), location.getX(), location.getY()+1, location.getZ()), 1);
I just get java.lang.IllegalArgumentException: Particle SHRIEK requires data, null provided
For Context this was why I thought the first option would work: https://www.spigotmc.org/threads/comprehensive-particle-spawning-guide-1-13-1-19.343001/
how do I make a try-within-resources statement?
?paste
This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment
Map::of doesnt seem to decide whether it should be a identityhashmap or normal one right?
is there like a builder for an identityhashmap?
How can I make it within server resources?
public static Map<Player, BukkitTask> tasks = new HashMap<>()
How save this map into config ?
you cant save a runnable to a config, its not serializable
And if without BukkitTask, then how?
For example <Player, Long>
you can perfectly serialize that, use uuid however
so probably no one knows abt this huh
✨ google ✨
Qucik question
?
How can I paste schematics the player looks at?
Going to need more info then that XD
Do you mean how to paste a schematic where the player is looking?
Well, trying to make the backrooms, orginally tried pasting in all loaded chunks,
But it was too laggy
So I want the schematic to paste where the players are looking at
and if the player walks backwards
ok maybe load 1-2 chunks near the player
What I would do is take what you did here ^, and just apply it to only a radius around the player (s)
probably whatever you have your view distance on the server set to
can I show you what I have for the pasting logic/
sure
And you said that was to laggy?
It was, it even crashed the server
Were there any errors?
[WARNING] java.lang.OutOfMemoryError: Java heap space
[WARNING] java.lang.OutOfMemoryError: Java heap space
xD
says enough
In that case I would just try using a different method to paste in the schematics, or you just need more memory
It is 1 GB ram
but even with 4 GB ram,
it still crashes
thats.... really bad
ik lmao, but with 4gb ram itstill crashes
Then I would try to use a different method to paste in the schematics
Such as?
Hooking into WorldEdit or FastAsyncWorldEdit maybe, there are definitely more efficient and memory saving methods than the one you used. Because i have pasted in schematics and it didnt kill the server.
Alternatively, what you could do is add a buffer, instead of trying to paste them all in at the exact same time (probably why you run out of memory), do it 1 at a time
Alright, how can I paste 1 at a time?
Im relatively new to java
What I would do, make a list and on the chunk load event it adds the event to the list.
Have a runnable that runs at whatever interval you want that takes the first thing in the list and pastes it then removes it from the list
hm, I'm still confused.
Unfortunately
check the impl of worldedit ig
I'm trying to think of how to give more info without spoonfeeding XD
Just make a List of the Chunk Load Events some where and inside of your listener, add the 'e' object to the list
Then make a bukkit runnable (if you don't know how there are loads of tutorials just look it up), that runs at whatever interval you think would be good.
And in the runnabble it grabs the event at the index of 0, and does the logic that you currently have in your listener
does that make more sense?
Somewhat
Last question, before I go on a google adventure
?
ah yes now my image comes
??
wha.
How do I get the list of chunk events that will happen?
Is there a variable, etc
how would you explain on how for loops work? (I know what they do, i just idrk how they work. )
-
make variable
-
make boolean
-
increment?
-
for loop checks if the boolean is still true, if so, it does the code?
Just define it as a public static variable in some utility class. make a method to get the list and a method to set the list. Use them in both the listener and the runnable
I wish you luck
cant you just do stuff async?
fawe is shit and crashes the server easily
oh.
I have never had fawe crash a server ???
It's always been better then normal WE
In my experience
idk
commands:
/set:
description: blah
or was it some kind of PlayerCommandPrePocessEvent listener

probably just registering the command with an extra /
well iirc WE had tab completion
so probably that was commandexecutor
nah
breaks the entire thing
just register it double command on setExecutor
?
you need around the command to make it a string
how can I make a List of the Chunk Load Events
`
yeah
what?
just add a slash to that
will it work lol
can only test
uh, how can I list the chunk load events
Im trying to load schematics 1 at a time
so it doesn't crash servers
what
Ign, uh, how can I get the list of chunkload events?
you cant
oh.
and why do you need that
To load schematics one at a time
List<ChunkLoadEvent> events = new ArrayList<>();
instead of loading all at once
ez
bro what
you mean you want to store all chunks which loaded with all events
and then paste schematic to every chunk
one by one
yea
create global chunk list and just fill it every event
how lma
What are you using to paste the schematic?
List<Chunk> chunksToPaste = new ArrayList<Chunk>();
FAWE?
ye
isn't there a pasting queue in FAWE tho?
then what could I do
dude I have admin access on so many people consoles
in your main class
why do these people trust me
?workload
no way
fuck it
Lmao
work distro
in FAWE
distrophic
time to think about reflections in my bed
@raw prairie
Tyty ily
what exactly isn't working
if it isn't executing, be sure to register your event!
does your tab work tho
W purple
header and footer
W
L
Anyone new have any idea of this XD
is the ign correct?
well then default tab in spigot uses getName()
omegalul
not displayname
Lmao
does it throw errors in console tho
Lmao
you pasted 2 different codes
and your problem is location where particle spawns i guess
The problem is that if I spawn the particle how I'm supposed to it kicks me when I render it
and in first code you have 0, 1);
bro this sentence structure scares me
it might be my english level causing me to die from cringe
commas i guess
A. No need to be toxic, B. I'm just not focusing on grammar because it isn't really necessary?
i mean i'm not native, so it's hard to read messages sometimes
what happens when you run your first code
The player is kicked, you can see the error in the photo attached to the original message
There are no errors on the server side
Don't mind nuker
The first one should be working tbh
He's the only person in this server that had the privilege of being blocked
That's a weird error 
That's what I thought but it just, isn't XD
so mean lol
It might be a codec thing
? Afraid I don't know what that means
It's like a protocol issue
(Also if you guys want the full error from my log I can provide it)
and he is disgusted for no reason
Gotta decompile the client n all
Oh I see
Same issue
Just look at how nms does it
where do you spawn particle tho
It could just be a bukkit bug honestly
Wouldn't be the first time I've run into one XD, had one with the allay not that long ago
I can change the visual ig
allay?
mob in 1.19
LMAO
You dev mc plugins
Yet you don't know abt mc
tbh I think there's a lot of devs that don't play MC
exactly
When you spend hours coding in it you don't necessarily want to spend your freetime playing it
there is a mob vote on currently
Should be pretty simple
as milliseconds to map or in pdc
or in file or smth
oh
well basically have a task timer which gets currentTimeMillis()
and then compares current time to player's stored number
if current time is greater -> ban the player
if(k.equalsIgnoreCase(e.getMessage())) {
log("adada");
}
});``` how could i get Configuration section(i'm getting null error)
combatTime: 15
blockedCommandsWhilePvp:
-"sethome"
-"home"
-"spawn"
-"tpa"``` this is my config
ok so, how can i get it from config
use getStringList or whatever it's called
thanks
how can I queue schematic pasting?
basically, I am trying to load schematics into new chunks, 1 at a time
Hey, I used this tutorial (https://bukkit.fandom.com/wiki/Developing_a_World_Generator_Plugin) to create my own world generator, but I’d like to add caves (like the default generator) but I don’t know how to do.. can anyone help me pls ? (Ping)
how to find out that the player has broken the block (I just think that the BlockBreakEvent event will not be very accurate in this situation)
Thats a very, complicated thing
Hey, I need help with creating an npc...
im trying to make a custom npc in 1.19.2 adn it was going fine until I realised that the construction of EntityPlayer now requires 4 args and I dont know how to get the profilepublickey.
The other choice I have is to use the basic minecraft generator but I don’t know how I could generate an area of 200 blocks around the center with only a roofted forest
Pass null maybe? It's annotated with Nullable so 
I know you can get an actual player's key with
ServerPlayer serverPlayer = ((CraftPlayer) playerEntry).getHandle().getProfilePublicKey();
But that probably wouldn't work with NPCs
You can always check how Citizens does it or use their API
thanks
If its for an NPC you can pass null. If it's going to send chat you need an actual key
are you depending on spigot api or spigot
spigot
ok, do you know how I can actually spawn the npc?
can i somehow force ij to use double quotes in certain file types?
its annoying when they mix
How can you get a method to list chunk events?
log(plugin.getConfig().getStringList("blockedCommandsWhilePvp").toString()); why am i getting empty list
combatTime: 15
blockedCommandsWhilePvp:
-"sethome"
-"home"
-"spawn"
-"tpa"``` this is my config
public void getChunksQueue(){
}```
Hi! how to drop items from a block(example: Diamond Ore)
So I have a pre made config.yml file in my plugin, and im trying to save these defaults and getting this error, any clue on why? I thought it might be spacing but it doenst seem to be that
Currently learning about CompleteableFuture, I hope it should have the same effect.
You are using the wrong comment prefix
YAML uses # for comments
ah 🤦♂️
(see bukkit.yml)
I am using BungeeCord, have a proxiedplayer instance, and I need to broadcast a chat message on their server. How can I go about doing this without a bukkit/spigot plugin?\
Nuker
and broadcast it's contents
Can you help me with something in dms
@fluid river can you help me with somehting in dms
spawn a drop or what
dm me then
lol
shouldn't you have smth like this tho
blockedCommandsWhilePvp:
- sethome
- home
- spawn
- tpa```
check if you saved your config with saveDefaultConfig() on plugin enable
when i broke block(example dirt) i get drop 3 coals
i dmed
manually drop items nearby
world.dropItem or smth
how do I set the color of the Spell particle?
since particle is enum(not a class), you can't directly modify spawned particle
particles are rendered by client
maybe with NMS, not spigot-api
that's what i just sent
but this is only for dust
redstone dust actually
how would I use NMS for it
smth like this
Question when I place a sign and typing something in line 0 and 1 can I get this with the block place event or do I need the SignChange Event?
test it out i guess
probably would run BlockPlace when right clicking
and when confirming line changes would call SignChange
Thx then I know what I need
i'm not sure tho
tho you probably should use ProtocolLib
cuz it wraps some packets
Hey guys,
What could be a reason for my Tabcomplete list to be shown, but not respond to typing (sticking to the first item of the list) ?
my Snipped:
public List<String> commandComplete(CommandSender sender, Command command, String alias, String[] args){
if(command.getName().equalsIgnoreCase("additem")){
List<String> list = new ArrayList<>();
// /addshopitem <material> <sellprice> <buyprice>
// arg - 1 = Materials
if (args.length == 1){
for(Material material : Material.values()){
list.add(material.toString());
}
}
return list; //returns the possibility's to the client
}
return null;
}
You want to filter everything that isn't starting with args[0]
everything that contains
I use this example on my other plugin, with a fixed list, which works like a charm :|
like that
return list.stream().filter(s -> s.toLowerCase().startsWith(args[0].toLowerCase())).toList();
I'd be hesitant using a stream in a method called every time a key is pressed
A traditional for loop will work fine
but the only diff, is my for loop, which gives this 'weird' effect
Like yeah, but it's just easier to do in this case
Yeah, you need to filter out the options that don't start with the input arg
how do I make when I type player name small or capital it returns player name?
An if statement in your for loop matching the one ikfir mentioned above will suffice
Ok, thnx will try that!
public List<String> commandComplete(CommandSender sender, Command command, String alias, String[] args){
if(command.getName().equalsIgnoreCase("additem")){
List<String> list = new ArrayList<>();
// /addshopitem <material> <sellprice> <buyprice>
// arg - 1 = Materials
if (args.length == 1){
for(Material material : Material.values()){
String s = material.toString();
if (!s.toLowerCase().startsWith(args[0].toLowerCase()) continue;
list.add(s);
}
}
return list; //returns the possibility's to the client
}
return null;
}
@mental sorrel
@worldly ingot You know stream isn't that of a big performance issue in that case
is casting both to lower, better than using equalsIgnoreCase ?
how do I make when I type player name small or capital it returns player name?
Bump
You don't want to use equalsIgnoreCase because you want to check if the material just start with args[0]
but you want to ignore case when check startsWith in that case
Yeah makes sense for this case, was just wondering about the casting vs equals. performance wise.
for example
material is DIAMOND
args[0] is diam
there aren't equals but material start with args[0] if we lower case both of them
if you use equals and want to ignore case
just use equalsIgnoreCase
Did you try to clear .m2 cache and reuse BuildTools?
if you didn't go to there and delete org/spigotmc
Windows: C:\Users\<user>\.m2\repository\org\spigotmc
Linux: ~/.m2/repository/org/spigotmc
This... worked.. like perfect
Can you explain this again? I dont understand.
?paste
I try to create an EntityPig like this:
Object entityPig = ReflectionUtils.getNMSClassInstance("EntityPig", ReflectionUtils.getNMSClass("EntityTypes").getField("PIG").get(null), entityPlayerObj.getClass().getField("world").get(entityPlayerObj));
But I get this exception:
https://paste.md-5.net/enajojiyuw.css
Im on 1.16.5 to test with the old nms-structure
thats half an error
net.minecraft.server.v1_16_R3.EntityPig would be a deobfuscated name
actually, its saying the class was found but no constructor which takes EntityType and WorldServer
When you used it without reflections, did you use specialsource to compile your plugin?
No mojang mappings, if you mean that
If you are using Mojmaps are you running the remapped server?
ie WorldServer will not be called that once you are on a live server
Yeah thats strange
what if... the constructor is just flipped
no clue I've only done NMS since 1.18
It never interested me before Spigot adopted Majang mappings 😉
just delete all the folder the and again build spigot with buildTools
Is it possible to build a chunk generator based on a schematics??
Dms now
How might someone generate schematics a certain amount of chunks from the player
Like 2-3 chunks
From the player
Right now I use a ChunkLoadEvent to generate schematics
Which is extremely laggy
hi yall i have a problem with registering aliases in code
getCommand("withdraw").setAliases(config.getStringList("withdraw.aliases"));
System.out.println(config.getStringList("withdraw.aliases"));
System.out.println(getCommand("withdraw").getAliases());
so this is the code
and output looks like this
[banknote]
[]
no idea why that happens
don tell me i must use reflection
that wont do in my scenario
mine are defined by user in config.yml
thats what im using in code above
it doesnt seem to work
i think it has to do with aliases needing to be registered when command is, and that part executes if command is already registered
so yea what i need is a way to dynamically register command aliases
It's exactly for this reason
By the time you invoke setAliases(), the command and all its aliases have already been registered
why do you even use the normal commands that need to be confirmed in plugin.yml If you want I can share a class I use that auto registers it with reflection
💀 💀 🔥
1.8 💀
is this responsible for how many mobs will spawn?
it is for a client
i dont like 1.8
Yes plz
you can strip out a lot of my bullshit I still need to go back and fix this for sub commands and such
Thx
?paste
here is an example https://paste.md-5.net/sakuwuneqi.java
How can you paste a schematic based on players
Like paste a schematic 1-3 chunsk from the player
do you know how to paste a schematic in general?
yes.
I already have code to generate it every 16 blocks
Then we don't really understand your question. You already know how to paste a schematic
How can I for a certain radius within the player
like paste schematics on 2-3 chunks near the player
would this be right?
if(cmd.getName().equalsIgnoreCase("name")){
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world))) {
if(sender instanceof Player){
Player player = (Player) sender;
Location loc = player.getLocation();
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(BlockVector3.at(loc.getX() * 11, 40, loc.getZ() * 11))
.build();
Operations.complete(operation);
}
}
}
return false;
}```
how might i run a light of code every frame for a player? I cant seem to find an "PlayerUpdate" event, and onUpdate doesnt refer to a player
currently am using playermoveevent but thats making it kinda janky
The server doesn;t have any idea about frames
you can use teh scheduler to run code every tick
?scheduling
Bukkit.getScheduler().runTaskTimer(myPluginInstance, () -> {
System.out.println("This runs every tick.");
}, 0, 1);
usually you would call this in your onEnable() method
you can create a class that extends/implements BukkitRunnable, overriding the void run() method
but in 99.9% of cases, you'd want to start the scheduler from your main class
depending on what you are trying to do
How can I paste a schematic up to a certain distance from a player?
This is what I have so far.
try (EditSession editSession = WorldEdit.getInstance().newEditSession(BukkitAdapter.adapt(world))) {
Player player = (Player) world;
Location loc = player.getLocation();
Operation operation = new ClipboardHolder(clipboard)
.createPaste(editSession)
.to(BlockVector3.at(loc.getX() * 11, 40, loc.getZ() * 11))
.build();
Operations.complete(operation);
}
return false;
}```
(lmk if im doing this way wrong)
im trying to make it so an armorstand follows my cursor, and with playerMoveEvent, it is quite jank
Do not multiply X and Z. add or subtract from
however i also only want to do it after I click
e.g. this is a runnable in it's own (anonymous) class. of course you could just create a "proper" class instead. but technically, the BukkitRunnable is NOT part of the main class
Me?
yes
if you multiply it may look ok near to spawn, but the further away you go it grows exponentially.
So + 11
can I end this or does it go on indefinately?
yes
ty
you can end this in different ways. it would be more helpful if you explain what exactly you need to do, and then we can tell you what we think the best way is
e.g. you can call "cancel()" inside your BukkitRunnable to cancel "yourself"
i would like to make an armorstand follow my cursor for a set time, and then stop
okay, then you are going to want to do something like this: (gimme a minute, gotta write sth down)
so far i am simply just spawning an armorstand playerMoveEvent, which is creating new armorstands everytime, instead of making it follow the cursor
whats the plugin to change the >=
something like this should do what you want. now whenever you create one of your armor stands, you'D just create a new ArmorStandFollower(...), then call runTaskTimer() on it
it's builtin, it's called "ligatures" or so. gimme a sec
love you
np
could you extend BukkitRunnable and also listener? or better to just have multiple classes
well
BukkitRunnable is a class. you can extend that
Listener is an interface, you can implement that
whenever you create a new bukkitrunnable, thats not the same as running on a separate thread or ?
you can implement as many interfaces as you want, and you can always extend exactly one class
however, you shouldnt register a new listener for every of your armor stands. you should rather have only one listener for all of them
ok
no, creating the BukkitRunnable does nothing on its own. it's just a new object. You still need to "schedule" it using e.g. runTaskTimer(...). and whether that runs on "its own" thread depends on whether you schedule it async or not
e.g. runTaskTimer() runs on the main thread
yaya
im spawning the armorstand withing an PlayerInteractEvent, how do I reference it outside of it, or do I just put the public void run inside the event
runTaskTimerAsynchronously() runs on a random thread from the scheduler's thread pool
you would put it into a field, or into a field that holds a list, set, or any other collection of entities
why do you need to access it from outside?
as in
the run wouldnt reference the stand spawned in the interact event
right
?
you really shouldnt mix up listeners and runnables in one class
you should have one listener, and one runnable. you don't even need one runnable per armor stand
I'll send you some example in a minute or 5
alright
It produced no errors, however it didn't paste the schematics.
OH IM SO DUMB
LMAo
forgot to save it? xd
I set it as a boolean, and made it return false
instead of true
💀
💀
VERY DIRTY CODE, but you get the idea:
public class NMS extends JavaPlugin implements Listener {
private final Map<ArmorStand, Player> armorStandMap = new ConcurrentHashMap<>();
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
Bukkit.getScheduler().runTaskTimer(this, () -> {
for(ArmorStand armorStand : armorStandMap.keySet()) {
Player player = armorStandMap.get(armorStand);
if(!player.isOnline()) continue;
armorStand.teleport(player.getLocation());
if(armorStand.getTicksLived() >= 20) {
armorStand.remove();
armorStandMap.remove(armorStand);
}
}
}, 1, 1);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
ArmorStand armorStand = event.getPlayer().getWorld().spawn(event.getPlayer().getLocation(), ArmorStand.class);
armorStandMap.put(armorStand, event.getPlayer());
}
}
this will spawn an armor stand for every new joined player and make it follow them for 20 ticks, then after that, remove the armor stand again
normally, you should NOT put entities into a map, but rather only store their UUIDs
e.g. imagine John has phone number 12345 and Lea has phone number 9876
then you can do map.get("John") and it returns 12345
kinda similar to like an array but instead of index being ints, it can be any var
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
you should check out one of those tutorials, I'm sure they all have a good explanation about maps ^
sorry lol im a migrant from C# in unity
does NMS stand for something?
oh that's just the name of the class I used for my example code
it doesnt mean anything in this case
I just put the example code into the first class I had open
Hey, im getting an error here
what should I iniatlize world
to ?
You cannot cast a player to world
And you probably need the WorldEdit world, not the bukkit one
the WE player?
What exactly is the error you got?
Well, it produced no error specifically, but it didn't paste my schematic either.
Might I do Bukkit.getWorld("world"); for the inializer?
You never set „world“ to anything
What?
Do not do „World world“ but do „World world = myPlayer.getWorld())“
I've not used WorldEdit so I've no idea what it requires
player.getWorld();?
It requires a WE world which you get by throwing a bukkit world into BukkitAdapter.adapt(…)
Yes
Have you read any basic java tutorial?
Im aware, but what should I set it to
I should set player to something
but what
That isn;t valid Spigot code. EventHandler annotation is for actual events
command is not one
right now, you only tell java "yo, I have a Player, and I will call it "player" from now on". but you never told java WHO this player is.
String myName; // Okay, we got a variable called name, but it has no value
String myName = "mfnalex"; // Now we're talking!
btw your whole command() method cannot work, you annotated it with EventHandler but it doesnt take any Event object as argument
🤦♂️ oh
Yea i removed that
if this is supposed to be a command, then it should implement CommandExecutor and have a onCommand(CommandSender, Command, String, String[]) method instead
if it's supposed to listen to events, you need an EventHandler annotated method that takes only one event as argument and nothing else
so - is it supposed to be a listener for events, or a command executor?
Its supposed to paste schematics
yeah, but when? when someone does something "ingame", e.g. when they die, when they spawn, when the left-click something, ... ? (listener)
or when they enter /dosomething ? (command)
?paste
what ever they do, its going to paste a schematic, move, stand still etc
anyone know why this code is causing the stacktrace below https://paste.md-5.net/vipujiqowa.coffeescript
what's line 26 in your Main class?
thats this code
try {
loadConfiguration();
} catch (IOException e) {
e.printStackTrace();
}```
this would be his line 26 if (config.getFloat("Config-Version") != 1.0) {
you don;t set a config value
thats line 32
should mention this is bungeecord btw
if that helps
the line I posted is where your error is (from what you have shown)
thats odd
because line 26 is the try loadconfig thing
line 32 is the one that checks the value
its failing on .getFloat(String) as config is null
but if i remove that return; at the end of the value checker the issue seems to be completely not existent
and it shows the message
im wondering about the maps thing, wouldnt it be easier to just assign the armorstand to the player at the time of armorstand spawn, which is on intteract?
do you attempt to read a float anywhere else?
nope
then your error is you never assign a value to your config field
thats odd tho
Configuration config;
you never assigned anything to your "config" field
because loadconfiguration() runs before the value checker and if i keep the return; in if (config.getFloat("Config-Version") != 1.0) { commented it shows it just fine
then you should be doing config = loadConfiguration();
if loadConfiguration() returns a config
loadconfiguration doesnt return a config. it simply loads the config itself
public void loadConfiguration() throws IOException {
File configFile = new File(getDataFolder(), "config.yml");
if (!configFile.exists()) {
getDataFolder().mkdir();
Files.copy(this.getResourceAsStream("config.yml"),
configFile.toPath());
getLogger().info(ChatColor.translateAlternateColorCodes('&', "&aConfig Created"));
}
config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
}```
hack jobby ik
make sure you config.yml has actually been saved
and make sure the very last line runs without error
ill try that
yeah please paste the full class
oh, is this a bungee plugin?
ah I see
bungee configs are weird
yeah that error you posted does not align with that code
line 26 is impossible to throw that error
i cant import JavaPlugin, even though im running on JDK 17 and i am using maven, everything seems fine to me anyone know why thi is happening?
thats what it throws with that exact code
Your config loading code is fine
then the jar you have on yoru bungee proxy is not the same as that code
its impossible for a try { to throw an NPE error
You must have had an old jar on yoru bungee
maybe you accidentally only restarted the backend server and not the proxy
weird
My guess would be tried to replace teh jar with proxy still running without realizing
must just be a case of old jar syndrome
yep
cause its working fine now
did you see my reply in the thread? just asking because for me, discord never sends notifications for thread replies
Question with mysql. I got a playerData table and want to take all the info from it and store it in memory so I don't have to keep pulling from the database. What would be the best way of doing this? (I have searched, but nothing that I think would work has shown yet)
it depends what playerData contains
you should create a new class called PlayerData
and it should have the same fields as your table
e.g. if your table looks like this:
INT age;
VARCHAR(32) name;
then your class should look like this:
public class PlayerData {
int age;
String name;
}
then just construct this class with all the data you need when a player joins, or whenever you need it
you should NOT load the whole database of course, but always only the players you need
otherwise using sql in the first place makes no sense
Ok cool, last thing then is how would I do this per player?
you would usually have a Map<Player, PlayerData> (or, better, a Map<UUID,PlayerData>)
Did you not create the table and store the data?
you might want to look into using Futures though, otherwise looking up data might block your main thread.....
final Map<UUID,PlayerData> map = new HashMap<>();
@EventHander
pubic void onJoin(PlayerJoinEvent event) {
UUID uuid = event.getPlayer().getUUID();
// Do your SQL stuff here
String name = ...;
int age = ...;
// End of your SQL stuff
map.put(uuid, new PlayerData(name, age));
}
this is a very dirty solution
you should normally NOT do it like this
you should run your SQL stuff async and use futures
it depends on how fast you need the data, ofc.
do you need it right when they join? or is it okay if you only get it 5 ticks later? etc etc

yeah when they join I want it to be there so I can access it later on
then delete it from memory when they leave
what are futures, just so I can google the correct thing 😛
you can google "java CompletableFuture"
but
do you ever need data of offline players?
and do you save tons of data, or just a tiny bit?
because this sounds like you'd be way better off using the player's PDC instead
then you don't need any external mysql databases
How might I paste a schematic at the middle/corner of the chunk the player is currently located at?
and you always have the data instantly
pseudo code:
Location location = new Location(chunk.getX() * 16 + 8, 0, chunk.getZ() * 16 + 8)
tyty
it's just pseudo code
pseudo code is "that's the general idea but not valid java"
yeah id need to access curtain bits of data. also need to store other things like clans and other things like it
so you also need to be able to get data of offline players?
yes
then you need to take a look at CompletableFutures. Doing SQL stuff is a pain in the ass if you don't wanna block the main thread, and you really don'T want to block it :/
basically EVERYTIME you ask for data, you will have to check if the data is already there
you can never directly do myPlayerData.getClan(), you always have to deal with futures
I got this error :/
[ERROR] Failed to read chunk [1, 1]
java.util.concurrent.CompletionException: java.nio.file.FileSystemException: /home/gs-41479/./world/entities: Disk quota exceeded
?paste
disk quota exceeded
what does that mean
not enough disk space
storage
your disk is full
df -h
Yea, the pasting clogged my storage
Like it kept spamming history file
for WE
How do I get the chunk of the player?
i don't
So going back to this, is this the correct way to use CompletableFuture? https://pastebin.com/65tTs0nF
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.
no
that will completely ignore the advantages of it
you block the main thread by calling .get()
so, whoever calls your getPlayerBal() method will do this:
- Create a nice async completable future, that will try to get the balance async, in the background
- but in the next second you immediately use .get(), telling the future to "GET IT RIGHT NOW!!!!!!!11111", blocking the whole thread
Your method should return the CompletableFuture
your method should not return a Double (it should, at all, return a double instead of a Double anyway), but rather a Future<Double> or sth
CompletableFuture specifically. Returning a Future doesn't grant you access to a lot of CF's useful methods
sure, true
return values should always be as specific as possible anyway
there's no reason to ever return a Map<?,?> if you could return a HashMap<?,?>
The opposite, actually
You should be as generic as possible so that if implementation ever changes, then nothing breaks
the output should always declare what it returns as specific as possible
if you return a HashMap, why not declare that it returns a HashMap?
doesn't that also extend HashMap?
Nope
It's just that in the case of CompletableFuture, there are methods you will absolutely need when working with futures
Things like whenComplete() or thenAccept() don't exist on Future
anyway, if I'd have a method that returns a List, I'd rather declare it to return a List instead of a Collection
I mean, otherwise we could just make everything return Object
If you specifically have a reason to return a List (i.e. to denote that it's ordered or for the sake of random accessibility), then yes
You can't Collection.get(0), but you can with a List
yeah but now one could also say "you broke ABI" if the List ever changes to something that's not a list anymore
Correct, but that's more of an API design fault than anything
You would almost never return ArrayList for instance
I'd rather make the return values as specific as possible, and the "input things" as generic as possible. and when something changes, well, then whoever depends on it has to change it too
yeah true. my HashMap thing was a bad example
You accept what you need, and you return when you want to expose and guarantee. It's the whole purpose of polymorphism. It's how Bukkit works
I actually meant to say "as input: take the most generic INTERFACE possible. as output: return the most specific INTERFACE possible"
not implementations, but interfaces
that's what I wanted to say
well tho
You need to find balance
Cuz if you return object you will only have like .clone() and .equals()
but if you return a collection instead of list
you won't lose much
yeah obviously, I didnt ask people to return Object everywhere
you would still be able to use .get() and .add()
I used this example to say that "using the most generic super-class/interface is a bad idea"
i dont see any reason to not use the most specific one in return values
well choco gave one example, but that was for implementations, not interfaces, so I adjusted my statement
I think you should give the most specific return value and the least specific input thingy
i mean that's a genereic programming paradigm pattern
i guess
you should have a super-interface as a return type if it doesn't break anything
But how would you know if it breaks anything
Eg i remember when bukkit changed the return type of getOnlinePlayers
Used to be Player[] now its collection<Player>
If they just used Iterable, there woukd be no problem
arrays don't implement iterable tho
I think they do
Hm okay i have to trust you on that, im only on the phone
instead
so most of arrays code is implemented into jvm itself
so under the hood it's always type*
I mean for List and ArrayList and LinkedList
they definitely have all same methods
and List is a superinterface to both AL and LL
So if you return a list instead of linked list nothing's gonna break
all of the methods would still be accessable
the only thing which is gonna break is performance
Cuz if guys would cast list to ArrayList and loop through it, it would be slower than looping through list which was casted to LinkedList
yeah sure, I think I misphrased my above statement. I wanted to say "you should return the most specific interface that makes sense". If you return a List but might think that it could also be a Set in the future, then return a Collection. But if you're sure that I'll keep staying a List, then it makes no sense to say "yeah this is a Collection"
the main reason arrays don't implement iterable
are primitive types which iterable can't store
blame java devs i guess
In Rust this is fixed probably
yeah this whole boxing/unboxing stuff is a bit weird
anyway, I'm almost first in line at the security now, gotta put my phone into the xray, brb lol
Yes, pic is from yesterday
Here you go lol
bruh tih coat
so with this if I return the CompletableFuture<Double> and when calling do something like Double bal = getPlayerBal(uuid).join(); would that be better than what i previously did or worse? Im a bit puzzled by it all :/
No.
Join() and get() both block. You must make your code wait until the future has completed. That means, everywhere you need the balance, you need to do it with a scheduler
you cannot just magically do ```java
double balance = myBalanceFuture.get();
and expect it to both, work without blocking but still immediately get you the result
you either must wait until the result is there (async, whatever), or block.
yes, but if they e.g. need the result in an event, this wouldnt work
I imagine they want do so something like this:
well you can cancel the event and when future is like happened
manually do the work
not the best solution
but i don't know what guy needs
goin' up
@EventHandler
public void onTradeWithTrader(VillagerTradeEvent event) {
double balance = getBalanceOfPlayer(event.getPlayer());
if(balance <= 10) {
event.setCancelled(true);
}
}
so that will obviously need the balance RIGHT NOW.
There is one solution to your problem:
Fetch all the data you need on player join, and save it, e.g. in your Map<UUID,PlayerData> thing. If the result isn't there yet, block ALL interactions made by this player, until the information is there.
@sand vector
but he gets balance from SQL or smth?
they want to gather the data on join from SQL, yes
can't you modify out-of-block variables like in scheduler tho
in completable future
like
how would you cancel the event when it already happened?
even after the event is cancelled
like if you declare Player p = event.getPlayer();
and next line run task timer
in the event, you need to have the data. or you cancel the event immediately and tell them "You cannot interact with this villager yet, please try again in a second, we still need to load your player data"
that's the only reasonable solution I see
well, or to block the whole server, but that sounds like a shitty idea
pdc gonna be slower
lag spikes go brrt
they dont wanna use PDC since they also want to read offline player datas
IIRC it's for a clan system or similar
in theory, they could ofc just load all data from a flat file or similar on join. unless they have 2 million players, this shouldnt be a problem
UUID ID = UUID.fromString(arr[0][0]);
Double balance = Double.parseDouble(arr[0][1]);
ez
where is realloc at java hmm