#help-development
1 messages · Page 1598 of 1
hmmm
can someone helpes me
theres got to be a better way to do this bc .getChunk() doesn't have any .getPlayers or .getCreatures
and the issue with having .getEntities is players & item drops :/
don't use static unless absolutely needed
Dependency injection 👀
but without it
it turn 1 error
into 7 error
Then fix those 7 errors
That's because your code sucks enough to cause 7 errors
then it give another error
Which is a bad recommendation
Because that method is static
no?
bruh
He has a local variable and wants a static getter
Yes literally
it literally says the non static method is in a static context
how fix
You’re trying to do something from an instance variable and then referencing it in a static method, or you got a static method and try to invoke that on an instance.
Paste your classes
?paste
how do armorstands react when they are in unloaded chunks and it try to access them?
probably wouldn't work bc they'd be unloaded
yea thats wht i thought..
I just think you’d get null if you try get them by id or anything
Maybe not but might be
Send SurgeCore @quaint mantle
thats the main class
hmmm
Okay so do you know what dependency injection is cimex?
It’s a really buzzy term for a simple thing
I did find something interesting
a thingy where put dependency into a covid vaccine and inject
hm?
ok
👀
wat that got to do with thing
according to this https://www.reddit.com/r/MinecraftCommands/comments/hi3eum/teleporting_to_entities_in_unloaded_chunks_116/
you can run commands through entities in unloaded chunks
Lombok is fine Ig
cant speak for the authenticity but
Yeah that's fine but making a getter for itself?
I'd be mad if it were static but seeing it not static makes me even angrier
getShopConfig is not static
but if i make static
but its being referred to in something that is static
it says nio make static
so try making the other thing not static
how
I'd just say read
https://www.baeldung.com/java-static
No it’s Lombok?
It would produce a getter method
Yeah but what is the getter returning?
Probably null
you'll never learn and be able to do stuff by yourself if you dont do that
it makes a getter for itself
https://paste.md-5.net/lemazofina.java @quaint mantle anyways I fixed the command part, this time only
yes but, if you understand that then you wont need help for this anymore
?learnjava read into this
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.
SurgeCore core = ...;
assert core == core.getInstance(); // true
my advice is to listen to these guys's advice bc they have the best (in their opinion) resources that will teach you the basics
It's rough getting told to learn java BUT it is worth it to write your first bits of code without help and then see yourself improve over time

he gave me more error
No because then in main you pass new ShopsCommand(this) with the keyword this which is a reserved variable that points to the class instance itself
And that will probably make 0 sense whatsoever (for you)
lol
wat do i do with public SurgeCommand(SurgeCore plugin {
this.plugin = plugin;
}
Cimex I hope you realize it's kinda hard to explain stuff to beginners because half the stuff we say is nonsense to them IMO
^
Where you had it before
i never had it anywhere]]
???
Cimex, do you understand the concept of object-oriented programming?
Just be honest and close those google tabs for now 👀
meanie

If not, I'll explain it in the simplest technical way I can
ooh can i try?
ello desk
hy
Is that an answer to Idolp or me?
bRuh ok
how are ppl mean
I'm just gonna do it
i fixed it myself
yk what classes are right?
my man left the server
basically OOP is sort of like this common practice thing where you should use reusable pieces of code and put them into classes so you can reuse them to make-
oh
That's not very specific
Give me a topic you don't understand
me?
Yeah sure
he really took that personally
?kick @reef wind disrespect inappropriate
Done. That felt good.
man said "help me" and when we tried and gave him stuff to learn with he said "ur mean" and left
i hope he does read those docs
wh-
it was cursed
what did they send?
He was washing a motherboard in a sink and it was amazing
It said “cry about it”
I will not that motherboard was being lathered
I recently learned that water isnt actually going to damage a motherboard its the minerals in it that do SO
why
you woke up
and decided to say that today
why
remember before you post, think NUT
is this
Necessary
Useful
THOUGHTFUL
yeah it was
im gonna cry
Eh, crying feels good
in other news I have run out of brain energy and forgotten how to use or statements so its time for me to sleep
cya later stay safe and dont remove the plastic from your motherboard
even if its to spite others you will create an abomination
Well new MinecraftFont().getWidth(ChatColor.stripColor(colorize(s))); is better then the enum with each char's width. xD
I believe that internally, it does some funky stuff where it gets the ascii length + string length
idk why the string length
But keep that in mind if you're having weird results
I'm not having issues with that. I found it as a replacement for my previous code. I created an enum and added all chars with their width to it. Plus a bit of other code to check the width and shit... Anyway it was all reduced to that line of code.
I believe you can even use the static font instead of instancing a new one
As I did here
👍
I am making basically a custom permission system to suit my needs. whats a good way to store permissions that the players have?
just make JSON file
Or a yml
How does bukkit do it?
yml
ok
bukkit (and spigot by extension) stores permissions in the permissions.yml file
ok thanks
do the gui rows start from top or bottom
since like
I have 36 item slots, and I want to center my items in the gui. Would I have to start from the top or bottom by putting the item sltos
slots*
Top left = 0
np
I have an entity which is travelling down a vector path
i need to work out when it is going to go into unloaded chunks in order to despawn it so that teh chunks dont get loaded as it travels.
anyone know how to work this out
bump
how can i cancel that lava is floating?
you could look forward into the path hes going and check if the chunks are the same. if not, check if the chunk is loaded with the #isLoaded method. otherwise you could also listen for the ChunkLoadEvent, remove the entity if its his or the next chunk which is being loaded and unload it a tick later.
hmm
i wonder
if i could just cancel the load event and have it work properly 
cancel the BlockFromToEvent
you cant cancel the load event
you cant?
just event.setCancled(true) ?
thats a shame
spelt correctly... yes
if the block is lava, yes.
sry xD
it dont matter
yeah. its not cancellable. probably because it would break too many things
wouldnt it be always an entity?
by spawn i mean like spawn chunks on start
but mostly, yes actually
HMm
what is the least performant part of loading chunks
but the most important question is: do entities really load chunks by itself?
the fact that the chunk is ticking?
what, do you think that it would not load the chunk?
probably not. otherwise entities would have to keep every chunk active they are in.. and they do not
hmm true
but i think that once it gets to an unloaded chunk it would just freeze in place you know?
stops ticking
not sure, never looked at the chunk loading stuff. probably its just sending packets since the chunk should be already generated. but i am not sure, could be totally wrong
also why should the chunk tick?
you could just test it
no the entity
yep about to
yeah my sysout with the drone location data isn't changing when it is not in loaded chunks
so i mean i could just always load the chunk that the drone is in and then just unload them as it leaves them
but, that seems, stupid
my approach was gonna be to:
despawn the entity when it reaches an unloaded chunk
calculate how many chunks/blocks until it was in loaded chunks, wait an amount of time that is precalculated based on that
once in loaded chunks respawn the entity
hi @opal juniper, can you send me a NMS Tutorial? i want to learn how to insert multiples versions on my plugins
i not fouded
You're not ready for NMS yet
yeah, i think to...
The thing about NMS is that it's undocumented
^
well, unless u work at mojang
You will have to figure things out on your own and we might not help
(sorry my bad english)
practice?
Just keep doing normal plugins and practicing Java
java
lmao
that would be aids i guess since you'll have to do some maths with block and time prediction
Is there a good way to sort a Map<UUID, Integer> on the highest Integer values? Like if UUID1=3, UUID2=1, UUID3=2, then I want UUID1, UUID3, UUID2 in a List
or is the location just continueing
eh the time prediction aint the hard bit
its working out when the chunks are unloaded and how far for
I will look, thx
treemap ftw
Thats like, hashmap's biggest flaw
^
would this work?
if(clickEvent.getSlot() == 11-14); ```
Ok, I will look into TreeMap, but I have never used it
how would i go about working out which chunks a ray passes through?
Are there any docs for?
many
Yes it is part of java util
oke
Ok I will search on the web, thx for the help
this means if the slot int == -3
just predict the future and check the chunks i guess. not sure what you mean
predict the future lmao
its like i need to get the points along the ray
to get their location
to get their chunk
to check if it is loaded
never really worked with raytracing except of custom mades
so i can just recommend using the bezier formula to get a line to a location in front of the drone
https://docs.oracle.com/javase/8/docs/api/java/util/TreeMap.html I see this is only sorted for keys
That i know of
how does that help doe
I mean it should most prob be a tree if you want it sorted, and you also want map. So yea, treemap
you are getting a line into "the future of the drone" and can check the locations of the line to get the chunk
Yes I understand, but I don't want it sorted by UUID, I want it sorted by value (Integer)
Then integer is the key
hmmm yeah. idk about teh bezier shit doe
Key value are just names
//pseudo
for(Location loc : line(droneLoc, destinationLoc)) {
Sysout(loc.getChunk().isLoaded());
}
Do I need to reverse the map to <Integer, UUID> if I want to get the values?
Yes
yeyeh
i can send you the methods you need. you just have to probably change the rise of the float t. it was cancer to find out even if its that simple
look up your pms
But then another problem: What do I do if 2 players have the same Integer as kills?
to learn the JAVA CLASSES section in https://www.w3schools.com/java/
Then you break the tie
Using uuid
?
No I mean, if UUID1=5 and UUID2=5
Yep ik
Then UUID1 will get removed
Yep so you may want to use a custom made class
Extending comparable
That contains uuid and score
Compare with score, break tie with uuid
Ok I will create a custom class
private static class KillScore implements Comparable<Integer>
{
@Override
public int compareTo(Integer o)
{
return 0;
}
}```
What to do here?
Hello can someone please help me with my plugin
i am trying to make just a simple npc
but i cant do the .ADD_PLAYER
i am on 1.17
KillScore implements Comparable<KillScore>
Ah
so KillScore will have two fields, score and player/uuid
And what to return there?
Yes I understand
What to do in compareTo ?
return this.score == o.score ? this.uuid.compareTo(o.uuid) : (this.score - o.score);
sth like that
It can't compare this.score, because that is an int
So now you sort them by putting them into a TreeSet
what does this exception mean: java.lang.IllegalArgumentException: Plugin already initialized!
maybe it is the last 3 words?
yes i know but how can i fix it?
Ok just creating a new TreeSet, and the get(0) will return the highest or lowest value?
also full stacktrace helps more
that's right
Ok highest?
That I don't know you have to test it yourself
Ok
just read the docs
From TreeSet then
Don't create a new instance of main class
okay
and if you just want the highest element, you can also consider priority queue
Why not .size() - place ?
wdym
I mean TreeSet gets everything sorted
so you will have the benefit of having an ordered list for ranking or idk
but if you just want the highest
priority queue wins trees in time complexity of doing the query, but doesnt matter if you dun have a lot of players
How do I open a gui when a player join?
under PlayerJoinEvent
evt.getPlayer().openInventory(...), might have to do it one tick later not sure
you can do so using Bukkit.getScheduler().runTask()
is there an asynchronous quit event?
?jd just search async
But to save you the time, no
Nope. If you want to do something async when a user disconnects you can just spawn a new thread or schedule an async task.
hey
is there a way to listen to blockbreakevent in a specific region ?
like block.getLocation().getY() == 62 to 70
so all blocks between Y62 and Y70 are listened
Just make a simple check if the broken blocks y coordinate is between 62 and 70
yeh but how do i do that ?
if(block.getLocation().getY() == 62 && block.getType().equals(Material.IRON_ORE))
no spoonfeed
just wht method
how do i get the users UUID?
thanks
@EventHandler
public void onBlockBreak(final BlockBreakEvent event) {
final Block block = event.getBlock();
int y = block.getY();
if (y < 62 || y > 70) {
return;
}
event.getPlayer().sendMessage("You can read this message if a block is between y [62, 70]");
}
Just simple Java
<
oh well thank you
what is the point of writing final in the arguments' type
In this scenario there is none. But its done to make sure the variable doesnt get overwritten later on.
but under what circumstances is that unfavorable?
Also i can automatically assure that i can access them from anonymous inner classes and lambdas.
ok that's true
Hi. Anyone knows how to create waypoints?
why is .exists erroring?
if (tpcsurvival.getBankFile().get("player" + player.getUniqueId()).exists())
What error does it raises
cannot resolve method exist in object
of what type?
wdym?
Send the full stack trace
yeah
declaration: package: org.bukkit.configuration.file, class: FileConfiguration
There's no such thing as a exists() method, is there ?
Then you need to call FileConfiguration#isSet(String)
get returns an arbitrary Object from of the FileConfiguration.
okay thanks
But i think you can also just null check the Object
When you think code is gonna work first time and it doesn't work at all 
What would 1 minute in double be?
Well start by telling us where that is from
oh thanks
?paste use this when sharing code
signs 😏
for some reason bossbar.removePlayer doesnt work
Hey, how to fixit, i am try to save mobs to config data. and data saved. but cant loaded data if i am reload it. and this is my onEnable and onDisable code:
https://paste.md-5.net/etaquhatun.cs
MobData hash map variable is mdata
oh yeah, someone cant help me
well, its early for some people still, just wait a little.
it's always early for some people
est gang 🦀
bst gang 
14:09/2:09 PM For me 😎
XD, because i think. in discord, i can get more fast response
There is a lot wrong with that code and the assumptions you are making.
Just because a world is loaded doesnt mean it contains all entities ever spawned there.
Entities get unloaded with the chunk they stand in.
The first thing i would do is clean the code.
let your IDE format it and split all the functionalities into new classes and methods.
Cluttering your onEnable and onDisable like this will make maintaining that code a nightmare.
who looking for development at smp server craked
?services
If you wish to request or offer development/art/building/administration services, please do so at https://www.spigotmc.org/forums/services-recruitment-v2.54/
So if you want to persist entity specific data you should listen to ChunkLoadEvent and ChunkUnloadEvent.
Using the PersistentDataContainer of that Entity is also a viable approach.
okay, i will try to make new class for it
my file doesnt get created
i have this in my main class
private File Bank;
private YamlConfiguration modifyBankFile;
@Override
public void onEnable() {
//some code here
try {
InitiateFiles();
} catch (IOException e) {
e.printStackTrace();
}
}
//some code here
public YamlConfiguration getBankFile(){ return modifyBankFile; }
public void InitiateFiles() throws IOException {
Bank = new File(this.getDataFolder(), "bank.yml");
if (!Bank.exists()){
Bank.createNewFile();
}
modifyBankFile = YamlConfiguration.loadConfiguration(Bank);
}
btw, what is diferences between getWorld#getEntities with getWorld#getLivingEntities
The one gets all entities the other only the living ones. A minecart for example is an entitiy but not a living one.
Is this all in your "main" class?
yeah
then change Bukkit.getServer().getPluginManager().getPlugin("TPCSurvival").getDataFolder() to -> this.getDataFolder()
Okay, Thanks for Helping, i will try it
okay
Since many people here us Nexus for Dependency Management, i have a question. What Priviliges do i need to give to a group, so it's able to deploy to a maven repository
After you have done that und it doesnt work, put some sysouts before and after some lines of code. Then see what gets printed. Also look out for stack traces in your console.
Ive always just created a user that has CRUD access to a specific area. I think the user needs all CRUD privileges in order to deploy. But i hate dev ops stuff so...
Do you know the Exact Names of the Privileges
I assigned nx-repository-view-maven2-- and it doesn't work
this doesnt write anything in my file
if (!tpcsurvival.getBankFile().isSet("players")){
tpcsurvival.getBankFile().createSection("players");
} else{
if (tpcsurvival.getBankFile().isSet("players." + player.getUniqueId())){
int bank = tpcsurvival.getBankFile().getInt("players." + player.getUniqueId() + ".bank");
int purse = tpcsurvival.getBankFile().getInt("players." + player.getUniqueId() + ".purse");
bank = bank + purse;
tpcsurvival.getBankFile().set("players." + player.getUniqueId() + ".purse", bank);
} else{
tpcsurvival.getBankFile().createSection("players." + player.getUniqueId());
}
}
Show more code pls. What IDE do you use?
intellij
did ya save it
wdym?
the file
Then press ctrl + alt + L pls
Yeah that formatting is whack
oh lol
Thanks that helped
And then post more code ^^
if (ChatColor.translateAlternateColorCodes('&', e.getView().getTitle()).equals(ChatColor.DARK_GRAY + "Deposit Menu")) {
if (e.getCurrentItem() != null) {
e.setCancelled(true);
switch (e.getCurrentItem().getType()) {
case CHEST:
if (!tpcsurvival.getBankFile().isSet("players")) {
tpcsurvival.getBankFile().createSection("players");
} else {
if (tpcsurvival.getBankFile().isSet("players." + player.getUniqueId())) {
int bank = tpcsurvival.getBankFile().getInt("players." + player.getUniqueId() + ".bank");
int purse = tpcsurvival.getBankFile().getInt("players." + player.getUniqueId() + ".purse");
bank = bank + purse;
tpcsurvival.getBankFile().set("players." + player.getUniqueId() + ".purse", bank);
} else {
tpcsurvival.getBankFile().createSection("players." + player.getUniqueId());
}
}
break;
case OAK_SIGN:
player.sendMessage(ChatColor.YELLOW + "[NPC] " + ChatColor.WHITE + "Banker» " + ChatColor.GRAY + "Type the amount you want to deposit in chat");
break;
case GOLD_BLOCK:
player.closeInventory();
Bukkit.getScheduler().runTaskLater(tpcsurvival, new Runnable() {
@Override
public void run() {
bankerGui.bankerGUI(player);
}
}, 1);
break;
default:
return;
}
}
player.closeInventory();
}
if (ChatColor.translateAlternateColorCodes('&', e.getView().getTitle()).equals(ChatColor.DARK_GRAY + "Withdraw Menu")) {
if (e.getCurrentItem() != null) {
e.setCancelled(true);
switch (e.getCurrentItem().getType()) {
case PAPER:
break;
case OAK_SIGN:
player.sendMessage(ChatColor.YELLOW + "[NPC] " + ChatColor.WHITE + "Banker» " + ChatColor.GRAY + "Type the amount you want to withdraw in chat");
break;
case GOLD_BLOCK:
player.closeInventory();
Bukkit.getScheduler().runTaskLater(tpcsurvival, new Runnable() {
@Override
public void run() {
bankerGui.bankerGUI(player);
}
}, 1);
break;
default:
return;
}
}
player.closeInventory();
}
?paste
lmao
soo.. do you save it at any point?
and i have this
i think it saves in the thing i sent up more ^^
there's no point in the code you sent where you save the file
Ok so FileConfiguration is basically a glorified HashMap. Which means it only exists in memory until you write it to a File.
oh that would be so stupid of me
where do i save it? like whats the best spot/way to do it
I would probably break that code down into several methods.
But you can write it after you are done modifying the FileConfiguration.
FileConfiguration#save(File)
so this does not work
tpcsurvival.getBankFile().save("bank.yml");
Does this return a new instance or is it the same instance you modified?
You should also save it into a File and not just a String
Also writing to a File during any event is in most cases a bad idea because it can cause lags really fast. Writing to disk on the main thread blocks the whole game for some millis.
so i should call a saving method?
can someone explain what this does? ```java
this.plugin.reloadConfig();
Either periodically save the data async every n minutes or just when the server stops.
Nope, basically it's reloading the config.yml
what does that mean what does it do???
For example you have value: 1 on the config, and when you change the value to other number and you try to get the value, the value will still be 1, unless you reload the config.
oh ok thx
You have a FileConfiguration in memory that gets loaded from a File when the server starts.
You get this FileConfiguration with Plugin#getConfig()
Exactly this FileConfiguration is discarded and loaded from the disk if you call Plugin#reloadConfig()
also how can I put stuff in a config.yml with my code?
how to prevent creeper dead after exploded?
how would i do the periodically saving?
FileConfiguration#set and don't forget to save it.
Plugin#saveConfig() after you have written something into the FileConfiguration retrieved by Plugin#getConfig()
I think you need NMS for that.
thanks you
With a scheduled task
okay
But the fact that you dont use any object oriented programming will make this really tedious.
I would just make sure that it runs for now. So save it when a player clicks the icon.
ohkay
I have been looking into making a plugin that can stack potions but i have been looking into it and everything i can find in the documentation and forum posts does not work. can someone help me with this?
You just need to listen for all events that could modify the inventory of the player (like pickup or inv click) and then do some logic involving ItemStack#isSimilar(ItemStack) and stack amount checking/changing.
also how can I do something like this with getConfig.set()? Config: blocks: IRON_BLOCK: - DIRT?
Section -> Section -> List<String>
?
We need more infos
like?
You are just showing a yml setup that has the structure
Section:
List<String>:
- String
Without context. So you can just create a section called "blocks" and then add a List<String> with the name "IRON_BLOCK" to it.
This list contains the element "DIRT"
What are you trying to do for example
I just want to change a drop of really any block
using config
Ah i see.
How works String.format()?
Found it here https://dzone.com/articles/java-string-format-examples
Materials can be represented by Strings as they are just enum entries.
Your problem will be that blocks will not be able to drop custom items like named iron ingots or enchanted fishing rods.
Anyways. You could read the config like this:
public class BlockData {
private final FileConfiguration configuration;
public BlockData(final JavaPlugin plugin) {
this.configuration = plugin.getConfig();
}
public Map<Material, List<Material>> getMappedDrops() {
final Map<Material, List<Material>> dropMap = new HashMap<>();
final ConfigurationSection blockSection = this.configuration.getConfigurationSection("blocks");
if (blockSection == null) {
return dropMap;
}
for (final String materialKey : blockSection.getKeys(false)) {
final Material material = Material.matchMaterial(materialKey);
final List<String> materialValues = blockSection.getStringList(materialKey);
final List<Material> dropMaterialList = new ArrayList<>();
for (final String materialValue : materialValues) {
final Material dropMaterial = Material.matchMaterial(materialValue);
dropMaterialList.add(dropMaterial);
}
dropMap.put(material, dropMaterialList);
}
return dropMap;
}
}
@foggy bough
im doing this, but i still get the old config, what else do i need to do? idr, wasnt reloadConfig enough?
instance.saveDefaultConfig();
instance.reloadConfig();
FileConfiguration config = instance.getConfig();
reloadConfig will load the content into the FileConfiguration retrieved by Plugin#getConfig()
and saveDefaultConfig fails silently if a config already exists.
Make sure that you actually use the content of your newly loaded config after calling those methods because the rest of your code doesnt magically update just because you reloaded your FileConfiguration.
yea, i was loading the config after using it, im retarded
this is the code I have: java for(int i = 0; i <= mats.length; i++) { this.plugin.getConfig().set("blocks", mats[i]); } but I don't know how to set it like this: blocks: DIRT: - IRON_INGOT
Again too little to work with
Whats the type of your "mats" array
what is java?
Material
A type of flower or tree iirc
So this will result in only the last entry of your array appear in your config.
Example:
[IRON_ORE, STONE, DIRT]
Will result in:
blocks: DIRT
Because you overwrite the section again and again with other materials.
so how can I get a new line to put a new material in the config?
You want the array of Materials in the config?
yeah
trying to make something that drops a random item and stays like that drop
public void saveTo(Material[] mats, FileConfiguration configuration) {
List<String> materialList = new ArrayList<>();
for (Material material : mats) {
materialList.add(mats.toString());
}
configuration.set("blocks", materialList);
}
this will put it in my config.yml right not my plugin.yml?
It will put it in neither of those...
bruv
just provide the respective config
This code just writes the materials into the FileConfiguration. Which exists entirely in memory. You need to save it to the file you want later.
k
ohh yeah, i am still cannot load data. but, when data saving, i see location just *id001. anyone knows?
Nothing in that code will work
No the issue was I had extends JavaPlugin on a command class
https://paste.md-5.net/ebuxebonuc.cs simply, this is my new code for saving
This will sometimes save some entities and players and sometimes none
But in most cases none
error just does at mobs, not at player
Entity specific data has to be saved/loaded with the chunk they stand in.
Player specific data has to be saved/loaded when they log in or out.
Hello again
so
I did not succeed in restarting the servers because I need java 16
But I don't know how to install it
@quaint mantle how did you do?
windows or linux?
linux
DuckDuckGo. Privacy, Simplified.
what link ?
?java16_linux
add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
apt-get update
apt-get install -y openjdk-16-jdk
update-alternatives --config "java"```
try this
.
?java16_linux
add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
apt-get update
apt-get install -y openjdk-16-jdk
update-alternatives --config "java"```
you can use it XD
This wont install it as a default jdk and is quite tedious. Just use apt for installing.
what commands should I do?
just copy it
ok
Just follow the command
Back to your problem. Dont randomly save stuff. Some players may have logged off and some entities just randomly unload. So you will never properly save any data like this. You need to react to events if you want to save data.
I did everything but I'm still in java 11
but, my entity test just at near me
Did you call every single command from the list above?
try, configure
search on google
we need more than one channel but that's not my question.
Can I get an event fired when a player attempts to place a shulker in another shulker?
Inventory move item event iirc
k thanks
try use it
sudo update-alternatives --config java
i try
Nope. This only fires if a Hopper transfers items. @smoky oak
Nothing to Configure.
btw
You need to check for InventoryClickEvents
Oh wait yeah its that stupidly named one 
it say Nothing to Configure.
try ss
ss ?
Nobody will be able to help you with this. The code is just messy and full of faulty assumptions.
Take it slow. Format your code properly and split it into several methods. This way it is way easier to maintain.
screen shooooooooot
okay
Why did he pm it to me...
idk
Why my Gson dont has all the functionalities, its the most updated, bruh.
Do you use the one that is bundled with spigot?
Not.
How do you manage your dependencies?
spigot 1.8 + no dependency manager. Im out.
InventoryType type = e.getInventory().getType();```
That's always the inventory type of whats opened, how do I know if it's a click in the player inventory or the other inventory? Count slots?
fair
event.getClickedInventory().getType()
getInventory() always returns the primary inventory involved in the event. (Which is the top one)
ah thanks
No. What are we even seeing here. But no.
If you delete gson out of the server jar then it wont work anymore.
Looks like he manually wants to tinker with the spigot server jar and just delete stuff out of there.
^
SetCursor is deprecated, what should i use instead?
look at the message
from the look of it
it just says not to use it
Deprecated.
This changes the ItemStack in their hand before any calculations are applied to the Inventory, which has a tendency to create inconsistencies between the Player and the server, and to make unexpected changes in the behavior of the clicked Inventory.
okay different question
what im trying to do is
exchanging slot and cursor to get a shulker into another shulker
but now it just throws it in the player inventory
//Checks if Shulker box
ItemStack a = e.getCurrentItem();
ItemStack b = e.getCursor();
e.setCurrentItem(b);
e.setCursor(a);```
wait
it calls the event twice i think?
when I'm trying to put another item in it it puts it in the shulker and then back in my hand
okay problem solved
?java16_linux
add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
apt-get update
apt-get install -y openjdk-16-jdk
update-alternatives --config "java"```
Does anyone know how to make a new line in a config.yml so then I don't override the existing data in my config this is my code so far ```java
for(int i = 0; i <= mats.length; i++) {
this.plugin.getConfig().set("blocks", mats[i]);
}
add them all at once, under one key
blocks1, blocks2, blocks3
you're setting mats[i] to the key "blocks" in every iteration of theloop
yea like god said
you are just replacing the same key every time
on another note: Is there a common material for shulker boxes? or do i have to check the 17 different boxes?
I want to do something like this ```
blocks:
DIRT:
- IRON_INGOT
I have no idea how to do this
BlockBreakEvent, block.getType(), check if its in the config as key
if yes
grab the value from the config and replace the drop with that
I just want to push all minecraft items into the config so then it will change the drop
have you seen Dreams video on drops are Random and Multiplied?
that is what I want to do
Map<Material, Material> blocks...
blocks.add(Material.DIRT, Material.IRON_INGOT);
this.plugin.getConfig().set("blocks", blocks);```
or you could even change teh second to a list if you want multiple drops from one material
can I do this? java HashMap<Material, Material> map = new Hashmap<>(); Material[] mats = Material.values(); Random ran = new Random(); Material rmats = mats[ran.nextInt(mats.length)]; map.add(mats, rmats); this.plugin.getConfig().set("blocks", map);?
I want all blocks in minecraft
not all Materials are blocks
what?
Some materials you can;t create, like AIR
then how can I get rid of the materialss that I don't want?
it all depends on what your end goal is
are you just messing up what drops from each block break? or you want it totally random?
like Dreams video https://www.youtube.com/watch?v=KDlO64GbxIQ&t=642s
I'm not watchign a whoel video to get an idea of what you want
just watch intro
it will explain
ok, completely random drops
yes
Does anyone know the name of the event before the player joins
so break two sand blocks can give different drops
nvm, playerloginevent
no 2 sand drops same random drop
Not in that video
thats why I am doing it in a config
it is in the vid
If you just want to randomize drops use Sethblings datapack
I want to make itttt
hello @eternal oxide ?
.-. Then you will have to filter materials yourself
You will either have to compile a list of droppable items and assign drops per type
or completely random
In that video even mobs are droppign other things
nvm I can just do some other plugin this is hurting my head
I really don't need that
What the hell is the difference between SHIFT_LEFT and SHIFT_RIGHT
shift left = your left shift
lol
shift right = your right shift
but everythign else treats those as the same key
look closely on uir keyboard
they do the same thing, but they aren't the same key
also
how can i wait a certain amount of time before executing a command ?
my code is
@Override
public void run() {
event.getPlayer().sendMessage("hello");
}
}, 100L);
and the first runTaskLater gives me aan error
The method runTaskLater(Plugin, Runnable, long) in the type BukkitScheduler is not applicable for the arguments (RegenBlockListener, new Runnable(){}, long)
I don't understand the error tho
post it
^
First argument has to be of type JavaPlugin
and "this" refers to your listener class.
means i have to import javaplugin?
no
confused lvl 100
Nope. You need to get an instance of your JavaPlugin class
oooh
And dont use new YourMainClass()
so bsically "implements JavaPlugin"
Nope. Only one class in your entire plugin is allowed to extend JavaPlugin
You need to get the instance of that class
yep i have the instance
Then pass that instance as first argument
so it'd be javapluginclass.
I've been trying for the past 3 hours to get NMS to work on the temporary plugin I'm doing and when I compile I get cannot access net.minecraft.world.item.Item
Idk why use vanilla mappings, Fabric literally uses yarn mappings with no problems, and forge uses MCP mappings, spigot can use Spigot mappings for generated NMS file
alternatively just do Bukkit.getServer.getPluginHandler().getPlugin("Plugin name here")
How you name the variable containing that instance is up to you...
*PluginManager
alrighty i'll try, i'll get back here if it won't work, thanks a lot
Or just JavaPlugin.getPlugin(YourMainClass.class)
eh im saving it in a static variable anyways
Using a singleton pattern like this or dependency injection is usually the way to go.
I'm kind of worried about InventoryHolders potentially staying in ram even if they're not being used...
I have a GUIHolder interface that I made that is implemented by a custom inventory class that extends InventoryHolder, and is used to store inventory data as well as methods such as inventoryClick(). What if I make a new one for one players inventory, the player uses the inventory, then closes it? Will the inventory holder stay in RAM? Will it be deleted by the garbage collector?
well java generally deletes stuff when theres no pointers to it anymore
so do variable = null
or in your case, listen for the event when the inventory closes then remove it
How would I remove it, though?
Thats a sign of faulty design
theres two kinds of people lol
Unless you have like, an array of references, then you should null your stuff
Do you hold a reference to the inventory object?
Nope
Here's the code, one sec
Code to open the inventory in question:```JAVA
BossActivationInventory activationInv = new BossActivationInventory();
Inventory inv = activationInv.getInventory();
player.openInventory(inv);
If you create it inside a method and then dont hold a reference to it in your class its just on the stack and will be garbage collected when the method is done.
Is there a stack?
Pretty sure it just makes the reference somewhere, but it's smart enough to know to delete it when the scope is done
But... BossActivationInventory has processes running inside of it, right? Like maybe a BukkitRunnable to play an animation
That isn't yours
Having anonymous inner classes can change stuff.
Make sure to stop that stuff under the right circumstances
If you cancel the runnable when the inventory closes you should be fine... But thats a bad separation of concernes.
How so?
You should have one single runnable that runs all the time and contains some collection of your custom inventories. Then add and remove them from the runnable when they get created or discarded.
What about using a BukkitTask?
This runnable should tick the inventories. Having a task for every single inventory will just clutter the mem with anonymous classes
Saving it as one, and then cancelling it when I need to
He's saying it should be a daemon runnable, essentially
Not really something you'd cancel until plugin disable or some other reason
This is quite clean. I like you
Satisfying solution
One example:
public class InventoryRunnable implements Runnable {
private final Set<CustomInventory> inventorySet = new HashSet<>();
public void addInv(CustomInventory inv) {
inventorySet.add(inv);
}
@Override
public void run() {
inventorySet.removeIf(inv -> {
inv.tick();
return inv.isClosed();
});
}
}
And then schedule this
And then in the inv close event -> customInventory.setClosed()
This will automatically let the inv remove itself without having a reference to the runnable
Hey so i'm coming back again because it won't work
Eclipse doesn't throw me any errors but it doesnt work ig
code ```public class RegenBlockListener implements Listener{
@EventHandler
public void onMine(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
int y = block.getY();
int x = block.getX();
int z = block.getZ();
if(!(y < 68 || y > 72) && !(x < -223 || x > -218) && !(z < 273 || z > 279) && block.getType() == Material.IRON_ORE){
//ItemStack ep = new ItemStack(Material.ENDER_PEARL);
//ItemMeta epM = ep.getItemMeta();
//epM.setDisplayName("§cEnder Perle du futur");
//epM.setLore(Arrays.asList("§cCette ender perle est unique","§cIssou"));
//epM.addEnchant(Enchantment.MULTISHOT, 200, true);
//ep.setItemMeta(epM);
player.sendMessage("123");
Bukkit.getScheduler().runTaskLater(Bukkit.getServer().getPluginManager().getPlugin("GCAPlugin"), new Runnable() {
@Override
public void run() {
event.getPlayer().sendMessage("hello");
}
}, 20 * 4);
return;
}
}
}
basically it says 123 when someone breaks an iron ore, and what i want to do is, 4 secs later (80 ticks), send "hello" to the same player
Or a more simple approach:
public class InventoryRunnable implements Runnable {
private final Set<CustomInventory> inventorySet = new HashSet<>();
public void addInv(final CustomInventory inv) {
this.inventorySet.add(inv);
}
public void removeInv(final CustomInventory inv) {
this.inventorySet.remove(inv);
}
@Override
public void run() {
for (CustomInventory inv : inventorySet) {
inv.tick();
}
}
}
Did you register the listener?
public clss RegenBlockListener implements Listener
and i imported the Listener, if its what you ment
meant
But did you register an instance of your Listener with your JavaPlugin? Just writing a class doesnt do anything. You need to create an instance of that class and work with it. In your case: register it with your JavaPlugin class
so i register my RegenBlockListener in my class that extends JavaPlugin?
In your main class's onEnable, insert Bukkit.getPluginManager().registerEvents(new RegenBlockListener, this). This will register your Listener's events for Spigot's event handler to later call.
Yeah
Yes
An instance of your RegenBlockListener class
You'd need a reference to this to add the inventories that you want to be ticked, right
Yeah... But singleton pattern could be used here.
getServer().getPluginManager().registerEvents(new RegenBlockListener, this)
hey all, what is the best method for saving hash map at reload
Then sysout some messages before your conditional statement and afterwards to see if it even goes throuh.
Entirely depends on the type of the map
it goes through
it tells me 123 when i mine iron ore
but it doesnt go through my scheduler, thus doesnt send me hello aft-er 4 secs
Are you sure you compiled and used this version? Look out for any stack traces.
just uuid and data int, location and name
10000% sure
Hm... try player.sendMessage(...) instead of event.getPlayer().sendMessage(...)
Other than that i dont see a problem.
org.bukkit.event.EventException: null```
```Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:153) ~[?:?]
at java.util.AbstractList.add(AbstractList.java:111) ~[?:?]
It's the wrong type of list
Then you can just go through the map in your onDisable() and save the content as <String, Integer> into your FileConfiguration.
WHole stack trace pls. Sometimes it states what operation is unsupported
Because UOE there means the implementation doesn't want you to modify it
Like add() to a SingletonList
i have save it to UUID, can i use uuid
The thing is i dont see anything collection related in his code...
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:529) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:514) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.PlayerInteractManager.breakBlock(PlayerInteractManager.java:295) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.PlayerInteractManager.a(PlayerInteractManager.java:254) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.PlayerInteractManager.a(PlayerInteractManager.java:151) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.PlayerConnection.a(PlayerConnection.java:1185) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.PacketPlayInBlockDig.a(SourceFile:40) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.PacketPlayInBlockDig.a(SourceFile:10) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]```
Weird
at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.MinecraftServer.aX(MinecraftServer.java:909) [minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.MinecraftServer.executeNext(MinecraftServer.java:902) [minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.MinecraftServer.sleepForTick(MinecraftServer.java:886) [minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:819) [minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:153) ~[?:?]
at java.util.AbstractList.add(AbstractList.java:111) ~[?:?]
at fr.pierronus.gcaplugin.RegenBlockListener.onMine(RegenBlockListener.java:35) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:316) ~[minecraft_server.jar:git-Spigot-cbd1a1b-009d8af]
... 20 more```
No, no, no
You can just use UUID#toString() and UUID.fromString(...)
Please paste
Whats in RegenBlockListener line 35 ?
Thank you guys for all of your help, but upon realizing that I don't actually need a new inventory for each player, since there are only 2 variations in total, I have decided to create 2 different inventories and open the same inventory for each player with the same outcome.
wow, i will try it
Then you did not compile and add the right version. "10000% sure" @manic bison
i did
3 times
imma downlod the plugin from my server files and open it
i don't know if that's related but i'm using plugman to reload the plugin
Dont use stuff like that while developing. Reloading causes so many weird behaviours. Just restart the server.
Inventory inv = Bukkit.createInventory(null, 27, "Shulker Box");
inv.setContents( ((ShulkerBox) e.getCurrentItem().getItemMeta()).getInventory().getContents() );```
leads to
`Could not Pass event` where e is `InventoryClickEvent` and ```java
e.getInventory().getType().equals(InventoryType.SHULKER_BOX)``` equals true
correction
e.getCurrentItem().getType()``` is a shulker item
so yes, my server compiled the right version of the plugin, but plugman broke it
Confusing. Pls send the whole method in.
if(type.equals(InventoryType.PLAYER)
&& (e.getInventory().getType().equals(InventoryType.SHULKER_BOX))
&& (shulkerset.contains(e.getCurrentItem().getType()))
&& ((e.getClick().equals(ClickType.SHIFT_LEFT)) || e.getClick().equals(ClickType.SHIFT_RIGHT))){
player.sendMessage("5");
Inventory inv = Bukkit.createInventory(null, 27, "Shulker Box");
inv.setContents( ((ShulkerBox) e.getCurrentItem().getItemMeta()).getInventory().getContents() );
player.sendMessage("Click");
if(inv.isEmpty()){
player.sendMessage("Empty");
}
}```
Returns '5' in chat then a error to console
I think plugman doesnt load plugins from disk. It just uses those which are already in the memory then just unloads and loads them again.
Stack trace pls
all right, restarted, and it works all fine, thanks a lot for your help
java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaBlockState cannot be cast to class org.bukkit.block.ShulkerBox (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaBlockState and org.bukkit.block.ShulkerBox are in unnamed module of loader 'app')
This means the BlockState you are trying to cast is not of type ShulkerBox...
wait what's the shulker box item?
Ah i see. ItemMeta can not be a BlockState
Cast the ItemMeta to BlockStateMeta
And get the BlockState from that BlockStateMeta
Then cast the BlockState to ShulkerBox
And do it line by line.
I have a problem with the scoreboard, if I display the health of a player it is 0. If the player gets hit (for the first time), then the health changes and keeps displaying the correct health
Hm. Not that i know of. This information is contained within the BlockState.
Ah. Then you need to check every time someone clicks ^^
ohh yeah, nothing doesent
already did that but the problem is actually getting the shulker into the other shulker
When do you init the first health?
and im now working on the code for the shift click since the other function body is done
Get the ItemStack in the clicked slot and clone it. Check if there is space in the top inv and transfer it. Then set the clicked slot to null.
thanks
Do u know how to fix it?
I have no idea what you are doing ^^
What spigot version are you using?
1.17
I think I had the same issue, I think I managed to get around it by manually setting the score to their current health
Lmao I mean it would work though
I am adding an Objective to the scoreboard with DisplaySlot.BELOW_NAME, and with criteria health, when the game starts I see 0 as health for everyone. From the moment somebody takes damage the health is set to their current health and keeps changing, so that works
I did player.setHealth(20);
Set their score & their health to 20
Yeah you should be able to
Ok I will try it
for(Player player : Bukkit.getOnlinePlayers())
healthNameObjective.getScore(player.getName()).setScore((int) player.getHealth());
Like this?
Does not work, it is still 0
No errors
Was doing it on board initializing, and not on applying so I will retest
Still not working
Will try to find out tomorrow
yo, i tried making a buildtools rev on 1.17.1 and it said my java was out of date for it, i need java 16, yet......
i just got 16.0.2 today
Nice
those 2 are in my programs list
but it's still saying my java is out of date
i went into cmd prompt and did java -version and it says "Java 1.8.0"
which i have but i still have java 16
You have to change your path variable to the Java 16 jdk
how......?
Google how to change path variables
nothing's helped, i have java 16 installed but it doesn't show up in my Program Files (86x), Oracle, Java, javapath at all
and i'e searched youtube and weba nd found NOTHING helpful, nothing but indians i can't understand and 140p videos that skip through everything and don't explain shit
what the fuck is so hard about just showing HOW the actual fuck to change a path.......
it's funny how people keep saying that indian videos are everywhere yet I hardly ever run into any
i searched up "how to change my path from 1.8 to 16" and the 1st video i clicked was an indian dude
the most recent one I've seen was one linked by reddit where it was literally just a dude bullshitting for 5 hours straight pretending to remake twitter but the code was 100% nonsensical bullshit and he was clearly buying bots to promote his channel, it was hilarious
at the end he says he's going to show the results of his twitter clone and opens... twitter
ok that's great, that still doesn't help me find out how to change my path
11/10 what a great programmer
or do what im attempting to do
Doesn't the openjdk installer set path for you?
I installed it from oracle, and I just clicked next and whatnot
it installed the path like that when i did it for 1.8
unless java 16 decided to ucking change because nothing can be simple anymore..?!??!
Don't use oracle, use adoptopenjdk
so i gotta delete the 2 java 16's i have and replace them with adoptopenjdk
also y not use oracle? they've been around since java was basically made
Why is the PlayererChatEvent like crossed out but still readeable
if you know what i mean
licensing changes, openjdk uses open source licenses
it works it's just not used anymore for the specific version of minecraft you're coding for
@quaint mantle AsyncPlayerChatEvent is used because chat is now async
different version, different methods
ok but is it the same as PlayerChatEvent
define async btw?
ok but can it be cancellable
yes
yes
ok thats all i need thx
can anyone tell me whether or not i need to remove both my java 1.16's from oracle in my programs list and get 1 from adoptopenjdk or just get the 1 from adoptopenjdk and let that set its path
you don't need to but you probably should
Just noticed this, why do some of my classes have a $1 at the back of it, as if there was a inner class called 1 there, but there isn't. What is this?
Hello again
so
I did not succeed in restarting the servers because I need java 16
But I don't know how to install it
@quaint mantle how did you do?
1 isn't the name of the inner class, it refers to an anonymous inner class in there
oh so its generating anonymous classes somewhere? 🤔
I don't use anonymous classes so this is kinda a surprise
well you've made an anonymous class or I've seen it can be an enum as well
huh
this class has 4 overriden functions and one other function. All of those just do simple stuff, and yet it is generating that $1 class
I'm trying to move my npc (EntityPlayer) as if it was walking (so no tp)
I tried to use PacketPlayOutRelEntityMove but no matter what I find on the internet nothing works (barely moves, or goes anywhere...) If anyone knows how to use this.
Thanks
what's in the class
is that the right class? it's FriendManageInventory
do i get it from HotSpot or OpenJ9?
hotspot
please
how can i download java 16 on my VPS
it appears that switching an enum causes that
it contains an array which helps determine where to jump to for each case
and yeah that would line up with the classes were this is not generated
so just metadata for the switch statement?
i wonder why that is just not in the main class
Are you not able to get is a ResultSet is null?
i'm looking at getting into plugin development, I have some java experience from my runescape botting days. where should I start? are there any resources that might help?
the spigot api has starter resources which start you down the right path
wiki I mean
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
that aside you'll probably need to hit up the forums quite a bit when you're first starting off to get a feel for how things are generally structured
it's easy to find a solution for pretty much every basic issue on there