#help-development
1 messages · Page 1733 of 1
you can either set a default value in the getInt method
sooo like
getConfig().getInt("zombies-amount",50);
of you set a global default value
getConfig().addDefault("zombies-amount",50);
or setDefault? idk right now
i'll use that when i actually need it
you can do things like this:
YamlConfiguration messageConfig = YamlConfiguration.load(new File("filename"));
and then just do messageConfig.getString("message-name");
indeed 😄
but don't forget to save your custom config files
you can just do
saveResource("messages.yml", false);
that will save your included messages.yml file inside the plugin folder
whats the false for
false means "don't overwrite existing files"
oh
buuut
it'll print a warning when the file already exists
so first check whether the file exists
sth like this:
File messageFile = new File(getDataFolder(),"messages.yml");
if(!messageFile.exists()) {
saveResource("messages.yml",false);
}
getDataFolder() from JavaPlugin?
yep
that returns the folder named after your plugin
like, the directory where your config.yml is stored
😛
bump I really need help with this :/
Maybe the bot can help me lmao @undone axle
the name is kinda cringe but you know, personal likings we can't interfere lmao
Are there other ways to get all Online players without "Bukkit.getOnlinePlayers()" ?
I dont know why but i think the normal getOnlinePlayers not working perfectly for me
You want a list/collection?
that will return ALL online players
sec
in JavaPlugin
Will not that count also the npcs ?
1.7/1.8?
It will count anyone who is a valid online player
No, 1.17
what isn’t working
@tender shard is it good to saveConfig(); in the on disable
NORMALLY you want people to use a proper editor to edit the files. you only want to call saveConfig when people can actually change the config ingame
I wouldnt do that
because
it will simply dump the configuration, meaning you lose all comments etc
oh
for example, check out the AngelChest config I sent above
when you do saveConfig, it will look like this afterwards:
(1 sec pls)
Post and share your source code or server logs here.
ok cheers
only call saveConfig when the config has actually changed
you 99% don't want / have to use it
Can nobody help me? ^^
how often / when are you calling this method?
ah just checked
you call it on every teleport event
you should store the player or sth in a map/list etc and only call it once for every player
You mean in the loop (Teleport Event) ?
yes
Thx, i try it. Sec
anyone like familiar w/ arrays able to help me w/ an array issue? got Strings not showing up and stuff for Array.contains() can't seem to figure it out
can you show your code pls?
!paste
?paste
okayyyy so what's the problem?
so the command adds player's uuid to the array
event handler looks for that uuid onBreak
and the issue is
it cant find it
first of all:
so the onBreak method never executes
erm
is there any reason why you are converting the UUID to string instead of just storing the UUID directly?
i was originally storing it directly
did .toString to attempt to debug
just havent changed it back
arraylist would still work how im using it though right? or no
soooo the problem is that the list never contains your player's uuid string, right?
you are only adding players in the command method
so that's definitely the place to look for the error
when you run the command, does it say "block debugger enabled" etc?
(btw you have a typo, you're printing "WATC[h]BLOCK" without the "H"^^)
it seems like the player UUID string is never actually added to the list
yeah it seems as tho the list never contains the uuid string
so heres the interesting thing
yes
and if i run it a second time
it disables and prints disable message
thats what i dont get
okay
the info is clearly in the array but @EventHandler methods cant see it for some reason
in your blockplace / block break event, print out the list to console
lemme try to remember
show you rmain class
I think
your problem is this:
You are creating two instances of this class
one handles the commands and the other one gets registered as listener
so how do i do it all as one instance
you are creating your ToggleBlockDebugger three times
You can do it like this:
ToggleBlockDebugger blabla = new ToggleBlockDebugger();
getServer().getPluginManager().registerEvents(blabla, this);
getCommand("yourCommand").setExecutor(blabla);
right now, you are creating the instance of that class more than once, so your listener doesn't "see" the changes you did in the command executor
they have two different lists
you know what I mean?
oki
it should work when you use the same instance for everything
you create an object of that class three times
so
getServer().getPluginManager().registerEvents(toggleblockdebugger, this);```
and then obv register the command as well
exactly
that got lost in the debugging i think didnt mean to do that
sorry for asking this, but
you DO know the difference between classes and their instances, right?
i do but i also dont have a full understanding of like creating instances and initiating them and all that jazz
im 100% self taught and this is legit my third week of working on this plugin in my days off only
trying things till they work then building off that
basically
0 coding experience whatsoever prior to 3 weeks ago
okay so I'll explain it very very shortly: A class is like the blueprint for an instance. Like, imagine a person class that has one String called "name". Now you can do
Person myself = new Person("n0_grief");
Person mfnalex = new Person("mfnalex");
Both objects are a Person but they are independent from each other. Right now, you create several instances of your BlockToggleDebugger that are indepent from each other. But they have to share the same list of UUIDs so you want them to be the SAME instance
The explanation is shitty but I hope you get what I mean
it's a very good explanation
thx 😄
I tried that, it would work in itself, but after the loop the list should be deleted again, but then it dont work anymore. In itself, the check is actually not necessary, I already save the armorstand for the player in the method
everytime you do "new ToggleBlockDebugger" it's a new object and it also has it's own list of UUIDs
@tender shard i want to thank you for ur help for me in config
no problem, glad I could help 🙂
it works like a charm
you caused this
@tender shard the explanation makes sense for sure
so this code has to go in my main class? does it need to go in a constructor or any changes in ToggleBlockDebugger.java? @tender shard
to make it short:
Do some kind of "ToggleBlockDebugger blabla = new ToggleBlockDebugger();" and then replace every line of code where you are using "new ToggleBlockDebugger()" with "blabla"
ONLY in main correct?
buuuut I have to add: you didn't really understand the concepts of classes and instances yet (which is totally normal, almost noone understands it at first) soooo you might want to watch some tutorials explaining the concept of objects, classes and instances 🙂
this is like the part that trips me up w/ these instances is like what needs to go where and why
EVERYWHERE where you are using "new ToggleBlockDebugger"
ok that is definitely only in my main class
would i also need to change this in ToggleBlockDebugger.java ? public class ToggleBlockDebugger implements Listener , CommandExecutor { private Main plugin; public ToggleBlockDebugger(Main plugin) { this.plugin = plugin; plugin.getCommand("wblockdebugger").setExecutor(this); }
that's fine, buuuut
I would say it's a bad habit to register the command in the executor's debugger
buuuut it should work fine nonetheless
ok
in my opinion, an executor shouldnt register itself
that's a job your main class should do
but as said, it will work anyway
it's just bad OOP
and as far as creating an instance of ToggleBlockDebugger in Main ToggleBlockDebugger toggleblockdebugger = new ToggleBlockDebugger(this); ?
yes. do this ONCE, and then everytime you want to access that class, use toggleblockdebugger instead of using "new"
and then getServer().getPluginManager().registerEvents(toggleblockdebugger, this); basically registers events to that instance right
if im understanding correctly
ok so one more dumb question
sure
and i feel like the usage of 'this' everywhere is what is confusing me
i can just straight up get rid of this right new ToggleBlockDebugger(this);
public class Person {
String name;
}
u can't
because this creates ANOTHER new instance of toggleblockdebugger and thats all it does
and now you have a method called "setName(String name)"
when you use this.name, it means "use the class instance's "name" variable"
when you simply use "name", it means use the parameter
99% of the time, you do not have to use "this."
you only need "this." when a method has a parameter that has the same name as your class'es variable
Example:
public class Person {
String name;
public Person(String name) {
this.name = name;
}
}```
is the same as this;
public class Person {
String name;
public Person(String newName) {
name = newName;
}
}
in the first example, you have to use "this" because both variables are called "name"
in the second example you don't need it because the variable is called "newName" in the method
that's normal because you didn't (fully) understand the concept of objects yet 🙂
Someone know how to make an item impossible to dispawn ?
a dropped item?
yep
hmm
declaration: package: org.bukkit.event.entity, class: ItemDespawnEvent
you can listen to this event and simply cancel it
nope there isn't
pickupdelay
pickup delay means "how long does a player have to stand 'inside' the item to pick it up"
hmm okay thx
you only want certain items to "survive" longer than the default 5 minutes. ,right?
@pastel stag https://www.youtube.com/watch?v=mx2HFzRvQg0
Ask your questions here: http://joincfe.com/knock
Up vote your favorites.
Suggest a project, tutorial, or topic: http://joincfe.com/suggest/
The long term goal: build a search engine of technical and non-technical questions with concise video responses. The more questions that we get, the more answers we can research and respond with.
http:/...
this a visual shop and i don't wanna the item to dispawn but is ok i handle the event thx
(I didnt watch the video but it seems like it explains what you're struggling with)
that really needs a video?
it does. understanding the difference between classes and their instances is something many people struggle with
A Player is an object. For every person who logs in the server creates an instance of Player for each.
everytime you spawn an item, store in a list or sth, and then listen to the ItemDespawnEvent and cancel it when the item is in your list
is ok i handle the event it take me 5 secondes
I know, you don't have to explain it to me, but some people don't understand the difference between a "Player" and an instance of "Player" because "Player" is already provided by spigot^^
no need a list i attached a persistant data container on the item
Perfect! I love PDC lol
I just found it odd that someone actually made a full video explaining what takes one sentence.
I can totally understand that people find it confusing, especially when they didn't worked with OOP languages before
@tender shard well everything works as intended now, i really appreciate your help, also i watched the video
i feel like i know what objects vs instances are by even just your explanation, i get really tripped up on the 'this' stuff tho
"this" always refers to the current instance you have
like why does ToggleBlockDebugger toggleblockdebugger = new ToggleBlockDebugger(this); work
but ToggleBlockDebugger toggleblockdebugger = new ToggleBlockDebugger(); doesnt?
that's because you defined a Constructor in your ToggleBlockDebugger that needs to get an instance of your main plugin
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
so the this in that line of code passes through the main class
well
it passes a reference to the instance of your main class
just imagine the following scenario (I'll try to explain it without any programming stuff)
You have a method greet(People someone)
sooo for example
n0_grief can greet people
but it has to know WHO to greet
so we pass that person as parameter
like n0_grief.greet(mfnalex)
you have to give the method "greet" a parameter
in your case, you decided that your ToggleBlockDebugger also needs a parameter which is your main class
because you probably call some methods of your main class in your ToggleBlockDebugger class
soooo
it cannot access them when you don't tell it what your main class is
ToggleBlockDebugger cannot access anything from your main class when it doesnt know your main class
so the only use that i see of the main class in toggleblockdebugger.java was where i set the executor for the command
yeah
exactly. and you want the SAME ToggleBlockDebugger to work as both, a command executor, and a listener
you do not want two DIFFERENT ToggleBlockDebuggers
you want them to be the same
that's why you only create the object once and use it for both
otherwise, you have two different objects, which do NOT share the same UUID list
right right i just meant; you said that i have to use (this) when i create the instance of ToggleBlockDebugger in main because of the ToggleBlockDebugger(Main plugin) {} constructor in ToggleBlockDebugger.java right
show your ToggleBlockDebugger class again pls
I will then explain why or why not you need "this" when creating an instance of it
check out line 21
you said that when creating an instance of your class, it needs to be provided with an instance of your main class
and, in your main class, "this" obviously refers to its instance
sorry I cannot explain it that good
so the (this) in the main class when i create the instance of ToggleBlockDebugger just references the instance of the main class
just tells it where to find it more or less? idk how else to explain it
"this" in your main class refers to the INSTANCE of your plugin
imagine bukkit's code
it basically does sth like this:
YourPlugin plugin = new YourPlugin();
public class MainClassExample {
House house1 = new House();
House house2 = new House(this);
}```
house1 and house2 are separate instances. house2 has been passes a reference to MainClassExample, but it will only be available to house2. house1 will not know about MainClassExample.
and in your plugin, "this" also refers to the newly created "YourPlugin" object
"this" basically means exactly what it says: "THIS", i.e. the current object that was created based of this class
this i think i understand
yep. In this case, "house2" gets a reference to the instance of the "MainClassExample" class that created "house2"
I know it's hard to understand at first lol
i actually understand it with the house code bit
that makes sense to me
i def need to fix my main class its a mess and a half
this is the first thing (other than helloworld) that i ever coded and obv main class kinda in itself shows the evolution of me learning lmao spaghetti code forsure
My first dive into coding was all god classes. OOP never existed 🙂
Well it was actually punch cards, but thats showing my age.
[15:52:39] [Server thread/WARN]: java.io.IOException: No such file or directory
[15:52:39] [Server thread/WARN]: at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
[15:52:39] [Server thread/WARN]: at java.base/java.io.File.createNewFile(File.java:1034)
[15:52:39] [Server thread/WARN]: at CimeyRolePlay-1.1.0.jar//de.cimeyclust.utils.guilds.GuildInventoryManager.<init>(GuildInventoryManager.java:28)
[15:52:39] [Server thread/WARN]: at CimeyRolePlay-1.1.0.jar//de.cimeyclust.utils.guilds.Guild.<init>(Guild.java:45)
[15:52:39] [Server thread/WARN]: at CimeyRolePlay-1.1.0.jar//de.cimeyclust.Plugin.onEnable(Plugin.java:205)
[15:52:39] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263)
[15:52:39] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:370)
[15:52:39] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:500)
[15:52:39] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugin(CraftServer.java:529)
[15:52:39] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugins(CraftServer.java:443)
[15:52:39] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.loadWorld(MinecraftServer.java:639)
[15:52:39] [Server thread/WARN]: at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:306)
[15:52:39] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1126)
[15:52:39] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:316)
[15:52:39] [Server thread/WARN]: at java.base/java.lang.Thread.run(Thread.java:831)
public GuildInventoryManager(Plugin plugin, Guild guild) throws IOException {
this.plugin = plugin;
this.guild = guild;
this.file = new File(this.plugin.getDataFolder().getAbsolutePath(), this.guild.getGuildName() + ".yml");
this.file.mkdir();
if(!this.file.exists()) {
this.file.createNewFile(); // line 28
}
this.c = YamlConfiguration.loadConfiguration(this.file);
}
Please help me. Why do I get this error?
@tender shard hey what about this type of yml
x:
- y
- z
yeah? what about it? ^^
File(this.plugin.getDataFolder(), this.guild.getGuildName() + ".yml");
how to make such
Yeah?
you want to produce this yaml using code?
Should I do it like that?
I doN't really understand what's the question
no i want to use such yaml configurations in my code
well your code is just creating an empty file
it only contains strings, right?
yes
List<String> myList = getConfig().getStringList("x");
Huh. How do I prevent that?
do you have a yml in your jar you want to use?
No. Not really
they are new to using config files, I think they just wanna read an existing config
yes
I always used databases before
Look at teh custom config section https://www.spigotmc.org/wiki/config-files/
But I don't want a default config. I want a custom. Not the one from the plugin
look at the CUSTOM section
wait
you either have to provide some default to begin with, or you can generate via code if you must
let me
you want to have something like "mycustomconfig.yml" right?
if yes: 1. Save your custom default config using JavaPlugin#saveResource
and 2. Load your custom config using https://hub.spigotmc.org/javadocs/spigot/org/bukkit/configuration/file/YamlConfiguration.html YamlConfiguartion#loadConfiguration(File)
declaration: package: org.bukkit.configuration.file, class: YamlConfiguration
sorry for typos I'm drunk
if you don;t have one then don;t load but create new
no need to
loadConfiguration will return an empty config when the file doesnt exist
ah ok, did not know that
Any errors loading the Configuration will be logged and then ignored. If the specified input is not a valid config, a blank config will be returned.
🙂
quite handy, lol
oh and in case you ever decide to use NBT tags: don't!! Use PDC instead: https://blog.jeff-media.com/persistent-data-container-the-better-alternative-to-nbt-tags/
java.lang.IllegalArgumentException: The embedded resource 'Yadel.yml' cannot be found in plugins/CimeyRolePlay-1.1.0.jar
at org.bukkit.plugin.java.JavaPlugin.saveResource(JavaPlugin.java:192) ~[patched_1.17.1.jar:git-Paper-157]
public GuildInventoryManager(Plugin plugin, Guild guild) throws IOException {
this.plugin = plugin;
this.guild = guild;
this.file = new File(this.plugin.getDataFolder(), this.guild.getGuildName() + ".yml");
if(!this.file.exists()) {
this.file.getParentFile().mkdirs();
this.plugin.saveResource(this.guild.getGuildName() + ".yml", false); // Error
}
this.c = new YamlConfiguration();
try {
this.c.load(this.file);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
saveResource doesnt work.
@eternal oxide What did I wrong?
is the file in your jar 😂
well save resource expects that file to exist in your jar to save it to the disk doesn't it ?
Ah. thanks
Should I create the file in the resources folder in my plugin @eternal night ?
concerning you seem to be creating files dynamically based on guild name that would not scale too well
Yes. I just save them as guild.yml and write them with the guild name.
So: this.plugin.saveResource("guild.yml", false);
can the guild change name?
No.
good
xD
To lazy
public GuildInventoryManager(Plugin plugin, Guild guild) throws IOException {
this.plugin = plugin;
this.guild = guild;
this.file = new File(this.plugin.getDataFolder(), "guild.yml");
if(!this.file.exists()) {
this.file.getParentFile().mkdirs();
this.plugin.saveResource(this.guild.getGuildName() + ".yml", false);
}
this.c = new YamlConfiguration();
try {
this.c.load(this.file);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
```Can I do this?
No.
can someone help me?
Will this work in 1.18 too (negative Y coords)?
Try... it?
I thought maybe someone knows the answer. As you probably know, there's no spigot 1.18 yet lol
"org.bukkit.entity.LivingEntity.getCustomName()" is null
@EventHandler
public void on(EntityDeathEvent e) {
if (e.getEntity().getType().equals(EntityType.ZOMBIE)) {
if (e.getEntity().getCustomName().contains("§c§lHenchman")) {
if (e.getEntity().getKiller() instanceof Player) {
ItemStack reward = new ItemStack(Material.HEART_OF_THE_SEA);
reward.addUnsafeEnchantment(Enchantment.MENDING, 1);
ItemMeta meta = reward.getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.setDisplayName("§4Henchman's §csoul");
reward.setItemMeta(meta);
e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), reward);
}
}
}
}
why is this
it only gives error
rest of the things work
Custom name is the name applied to entity via nametag or setCustomName method it can be null
You can add a simple null check
e.getEntity().getCustomName() != null
o ty
Oh RIGHT lol
Then who knows? I dont see how anybody would know the answer
It will not remain negative at release
hey @tawdry scroll whos in your pfp
A person
specify the person
Myself
how old are u
How its related to your customname error?
Its 18
The point is why no one wanne say there age
The point is why people ask lol
Age is just a number.
😄
im also 13
It's like we make a useless code into a useless plugin.
(but then what makes sense of the plugin?? XD)
4 weeks of spigot api
i knew java
i have a spigotmc account and a plugin on it with 20 downloads B))
eyo
do sending invites man
D:
(another fun fact: I always reject these. XD)
I do not join these unverified servers.
dude wtf
Do you think I am a server..? 🤣
ur unverified tho..
Sadly I am a human, but I would like to be a dead server... XD
Who cares? 😎
🤣
At least I still have spaces in my name. XD
Those kids these days.. 🤡
They do not understand so many things.. 🤡
If that would be my problem... .-.
But I have other problems like depression. .-.
"you was"? 👀
Don't you mean "were"? 😄
But anyway nvm because it is just a typo.
You're a human.
All humans has the rights to do mistakes.
It is a typo. .-.
I always thought it's sachins dog lol
@weary geyser discord link in dm next time
Or even the whole song. 😄
They cannot DM me. 😄
Then add them as friend
You can add them?
But I won't.
I do not know who he is. .-.
He is just like...
And unknown host...
.-.
(at least for me)
Idm, we don’t want discord links posted here, no discussion
Solve it if you really need the link, shouldn’t be that hard
I must agree with you.
Even with the fact I never liked angry mods.
idk
I was mentioning other mods.
¯_(ツ)_/¯
But I am happy and sad at the same time. 😆
To solve this problem, please read your #general at null. 🤡
I think you should learn English more harder. .-.
I feel English is not your first lang.
Am I right?
DUDE! WTF?!
How could I open the fridge by walking 5 centiméter-ek into the walls, to teleport into North Korea to kill myself?!
I am already at the top floor....
Okay I need a pchyhologist here.
This was autism not sarcasm, you know?
This was autism, not sarcasm.
At least what you have been writing down was.
Fúúú baszd meg... -.-
$ suicide
are you supposed to add the defaults each time the plugin is enabled?
yea
im making a method and planning to call it in the onEnable
is there a better way or would you do the same?
uhh are enum values loaded first or is the static {} block executed first?
putting them in a map and making sure their constructor is been called before
enum constants are initialised before the static blocks are executed
oki that's enough for me
Enom nom 😮
let's try three days of coding out 😳
:0
it compiled
its something liek Lang.NO_CONSOLE.get()
get0() gets the corresponding value from lang file loads it in the map
if nothing is found is uses the default
?paste
Im not good with using the config and inserting values into it via code. Im adding defaults to it but how can I make the defaults be inserted into the config file when the method is run?
if i just return the message nothing is from config
i also want to check if its not null and log it
so
it doesnt exist in config then
so i give a default
i don't get it
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.
that wouldnt help to prevent me getting values from config
these are defaults
i do and return a default 🤡
well yea i could do that in the constructor tho
so liek this?https://paste.md-5.net/ehayuvohul.cs
reverse lookup
(although you could just have a map that gets edited in the constructor)
he was kinda right i could do it in the constructor
why the fuck are you so aggressive
this is what Java does to your brain
try Kotlin™️ today!
try cheese
🧀
btw is ur name dutch?
yep
wouch im also dutch
😎
uh instead checking if the inventory i'm clicking on is instance of one of mine, cant i just check if the inv.class.package.name starts with my package name?
Why would you do that
idk instead of inv instanceof that or instanceof that or instanceof that or instanceof that
I mean it would probably work, but you should keep using instanceof
mwwo yea
hey anyone can help me with an hashmap
What's the issue?
i want to whitelist the code only on one Bow enchantment (excatly Punch 2)
HashMap<Arrow, Integer> arrowPunch = new HashMap<>();
arrowPunch.containsKey(arrow);
arrowPunch.get(arrow);
int punch = 2;
arrowPunch.put(arrow, punch);
arrowPunch.remove(arrow); this is my code
noone? 😦
I made a code that when you shoot an arrow and it hits you, you always go straight
does any one can tell me if there is a good way of checking for an inventory in the clickEvent without going by the name because if you rename a chest you can get the same effects
but this work with all bows
i want only on enchantment punch 2 to work
You are seeing these files. Don't add them.
first you check the material and then you check the name
ok ty
np
I didnt add them
it also happens to everyone who clones the repo :/
how do u make a gui that you cant exit
Re-open the GUI when you closed the GUI.
add a delay too
how do i color a glass pane because stained glass pane doesnt exist
did you check out the Material class?
oh woth color name infront sry
np 😄
I always use Enums.getIfPresent(Material.class, "MAT_NAME").or(Material.FALL_BACK_MATERIAL);
What do you mean with material?
????
obviously I didn't git add them
Not sure why would would bother unless you are reading the string from somewhere
...
why
lol
of course the harcoded "MAT_NAME" was meant to be replaced with some config value etc
There is also matchMaterial for that
But I guess you do have to handle null with that
yes but that one doesn't allow you to specify a "fall back" mat
Not in one line, no
yep that's why I suggested Enums.getIfPresent 🙂
I would make a method using matchMaterial
Since it can handle formats such as minecraft:egg iirc
does any one can tell me if there is a good way of checking for an inventory in the clickEvent without going by the name because if you rename a chest you can get the same effects
for GUIs?
yes
OpenInventory returns a view
You can add it to a set and then check set.contains in the event
either create a custmo GUIHolder class, or just store your GUIs in a list
ok
why do you use that
instead of material enum
I don't understand your question
why not use Mateiral.X
because it might happen that a user enters a "material" that doesn'T exist
and I want to avoid that, I wanna provide a "fall back" mat
for example my angelchest plugin: i tdoes sth like this:
Material mat = Enums.getIfPresent(Material.class, getConfig().getString("material")).or(Material.CHEST);
Feels like material x is the most useless library
LoL
but i want a button that closes the gui
Reopen it when closed unless they use the button
okay let me try
i... need... project ideas
minecraft sex mod
wut
Implement the Minecraft server protocol in C++ and make it playable.
Start Skynet
Hack google using html only
😏
what
wasnt talking about a library
pol
Oh lol
hard code the material
but apparently in his plugin the user inputs it
so thats why
Ye
I just made this
public static Material getMaterial(String mat, Material def) {
Material material = Material.getMaterial(mat.toUpperCase());
return material == null ? def : material;
}
Probably don't need the toUpperCase but meh
Will cause errors if the material doesn't exist.
Like if you put wool instead of white_wool
How so
Just the way enums work.
that isn't #valueOf
^
getMaterial returns null instead of throwing an exception
Carry on xD
Uuuh, i have a simple problem that i cannot solve. when i use : player.teleport((Bukkit.getServer().getWorld("world2").getSpawnLocation())); I get an error.
Error:
Console Error:
Show the full error
1 sec
any fixes?
I tried: player.teleport(Bukkit.getWorld("world2").getSpawnLocation()) player.teleport(new Location(Bukkit.getServer().getWorld("world2"), 0, 80, 0)); player.teleport((Bukkit.getServer().getWorld("world2").getSpawnLocation()));
Store it to a variable and check if it is null
an example please?
also 1.8.8 👀
World w = getWorld(name)
if (w != null) {
//stuff
}
, _ ,
@young knoll
if(w != null) {
Msg.send(player, "&cNull");
}else{
Msg.send(player, "&c FU");
}```
isn't a null
You are sending null if it is not null
probably just means your world isn't loaded
u mean world?
yea sorry
any fixes so i can load the world?
you don't have to
you can also use the spigot api to load a world
tsymmmm worked, just wasted 5 hours of my life trying to figure out how to fix it ❤️
how do i reopen a gui once it's closed?
I basivally don't want players to close it
how do i do it
yes
Sure there is
will it work if i have a button to close the inventory tho?
Sure
The event will always get fired unless its the players own inventory. You just have to re-open it one tick later.
okay i will try thanks
does anyone know why when you use PlayerDeathEvent#setDeathMessage it will overwrite the client's language?
For example if I have my client language set to german, this is what it looks like when I'm killed by a husk:
however if I have this in my code:
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerDeath(@NotNull final PlayerDeathEvent event) {
event.setDeathMessage(event.getDeathMessage());
}```
I get this:
sorry wrong screenshot for first one:
The original message is likely a translation component that is flattened into a string in the default language
getDeathMessage does not return a translatable component but a mere String
is there anyway to update the death message without losing the translation?
We really need to expand the component API
does anyone know how to set a priority for my rank system? [ i use scoreboard.main ].
; v ;
I assume it is alphabetical
scoreboards are ordered by String#compare
So you could append some color codes to the front for ordering
*prepend
the last time i did this i got kicked for having a 20 characters name
, _ ,
; v ;
any fixes pls?
It is possible to order the tab list non-alphabetically
how?
Via Scoreboard values
wdym?
Do you have any other plugins on a server
cancel the event
event.setCancelled(true);
// Handle item operations
don't use a string builder if you want to work with components
there is a component builder for a reason
actually
it was because it had no string in the constructor
added an empty string and it worked
Use the compinentbuilder
compinent
CompinentBuilder
?paste
how do i safely handle onInventoryClick events without checkign the title?
inventoryholder
whats that?
an inventoryholder
you mean owner?
you can see some examples here https://github.com/WizardlyBump17/WLib/tree/main/core/src/main/java/com/wizardlybump17/wlib/inventory
ok ty
wtf is this
there is nothing explained its just some random classes
yea, i need to document it
You shouldn’t use holder anymore
ok what then?
thats not what its for
Use the InventoryView
OpenInventory returns a view you can add to a set
if it works then it is the right 😎
Or you can do that, yeah
e.g. throw the inventory instance in a map and remove on InventoryCloseEvent
ok
but is there some kind of video out there that explaines how bukkit handles events and commands exactly i just cant get my head around this works
there are a ton of "Writing a listener" tutorials on youtube
i dont mean that but i think i found something
I mean its basically scanning every method for the passed class in registerEvents
then someone needs to make the purpose of the inventoryholder at the docs
then it creates an EventExecutor instance for each which invokes the method reflectively
package index
' Note: While the Bukkit API makes every effort to ensure stability, this is not guaranteed, especially across major versions. In particular the following is a (incomplete) list of things that are not API. '
"Implementing interfaces. The Bukkit API is designed to only be implemented by server software. Unless a class/interface is obviously designed for extension (eg BukkitRunnable), or explicitly marked as such, it should not be implemented by plugins. Although this can sometimes work, it is not guaranteed to do so and resulting bugs will be disregarded."
'Implementing interfaces. '
if you check what classes implement InventoryHolder, it should be apparent what you're actually meant to pass into the method if you use it https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/InventoryHolder.html
declaration: package: org.bukkit.inventory, interface: InventoryHolder
the problem is people saw 'ooh look interface with only one method, it's free real estate'
yes
can i save a player in a variable and the == with a player from an event?
technically yes
Should be able to
ok i try
Generally better to use uuid
look at an interface with 1 method and not documented
i am going to try both
is the getCursor, from the InventoryClickEvent, nullable?
what does the annotation say
declaration: package: org.bukkit.event.inventory, class: InventoryClickEvent
that would be really helpful if i was in 1.17
i added https://pastebin.com/GHUti04s my pom.xml file to add FAWE but im getting these errors Dependency 'com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:' not found Dependency 'com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit:' not found
https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki/API-Usage
I given tpa permission to player but when player does they dont have permission, how to solve this when i give player op they can use tpa permission help me plzzz
Plzz help me naaaa plzzz
Hey, what would be the best way to save data on disable to a sql db ?
Imagine of course, that there are several players and each player has to save his data inside the db
Is there a plugin that can track a certian item weather its in a players inventory or in a chest?
Also one that prevents a certian item from entering a enderchest
You can make your own or when I get on my PC I can make you ne
One"
Rly? thanks a ton lmao
pogg
Addme
aightt
Depending on how long your planning on storing that player, might not be the best way to go
As comparing player objects directly means that when they die or relog they are no longer the same player object
I mean you can just make a loop if necessary and get the event's player name and do this 'Bukkit.getExactPlayer(String);'
Much better to just save UUIDs instead
Yeah sure
im spawning a WitherSkull and i want to set its speed, i have
Vector speed = player.getEyeLocation().getDirection().multiply(5);
ws.setVelocity(speed);
this is the only way its wokred and it dosent really work, its just kinda stops after a second and goes at a normal speed
player.launchProjectile will automatically set the velocity
But you may have to override it each tick with a witherskull
deam that's cringe
dream is cringe, you're right
I noticed a small flaw in the rules posted on the spigot site and wanted to see how some situations would be handled
So when writing kotlin plugins not everything directly translates to java and there aren't really kotlin decompilers
so how would this rule be applied?
Even kotlin decompiled to java is very hard to understand so I wanna see how this edge case is treated.
Can someone help? I made this code for a blank gui when /gui is done but the plugin does not print anything to console OR show up with /pl
And if I somehow got my plugin.yml wrong here it is too:
version: 1.0
name: Update Gui
main: gui.that.will.be.updated.Main
commands:
gui:
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Thanks for this but the thing is the plugin is not registering anything
getCommand("gui").setExecutor(this);
remove if (cmd.getName()...)
You do not need to setExecutor to your main class
since when
theres a startup error
look in your console
Wait then how does it know what command I am using?
Ever since I learned the basics of spigot commands like, 8 years ago
The main class is the default executor
So what would I type?
I tryed fixing this but it still says this:
Could not load 'plugins\Plugin.jar' in folder 'plugins': uses the space-character (0x20) in its name
Oh ok (I thought it was the name of the .jar file)
Hi all, I'm new to plugin development and I have been finding it really hard to learn how to create scoreboards for players for 1.17. I've followed 3 tutorials now (The only ones that show up when searching for a tutorial) and they don't show anything when in game. I dont have any errors in my code and its exactly how they have written theirs. Is it just a version thing? I must be missing something right?
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.*;
public final class UntitledPlugin extends JavaPlugin implements Listener {
@Override
public void onEnable() {
// Plugin startup logic
this.getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
createBoard(event.getPlayer());
if(Bukkit.getOnlinePlayers().isEmpty())
for(Player online : Bukkit.getOnlinePlayers())
createBoard(online);
}
public void createBoard(Player player) {
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard board = manager.getNewScoreboard();
Objective obj = board.registerNewObjective("InfoGUI", "dummy", "Information");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
Score score4 = obj.getScore("=-=-=-=-=-=-=-=-=-=-=-=");
score4.setScore(4);
Score score3 = obj.getScore("Information");
score3.setScore(3);
String time = String.valueOf(Bukkit.getWorld("world").getGameTime());
Score score2 = obj.getScore("Time: " + time);
score2.setScore(2);
Score score1 = obj.getScore("=-=-=-=-=-=-=-=-=-=-=-=");
score1.setScore(1);
}
}
There is my most recent attempt. The only difference from my code to the tutorials is the text inside my scores.
You're creating a new scoreboard in this example
But you don't seem to be assigning the player to view that scoreboard
You have to call player.setScoreboard(board);
That worked! Thanks so much. Spent too much time on this I feel like lol
Why do you create another scoreboard for everyone when someone joins
Yes
Any response to how this woukd be handled??
Kotlin compiles to sane java from what I have seen
It's intended to be cross-compatible; you can use kotlin libraries in java, and vice versa
A downside of kotlin is that it drastically inflates jar files though, stuffs a bunch of kotlin standard library stuff in there
idk if im missing something but does spigot mess with java.sql stuff? I tried to run simple sql code in a plugin and it keeps telling my ResultSet is closed, however when i try outside of a plugin environment it works fine
You can write sql code in your spigot project
what
nvm im just dumb, i put my statement in a try with resources, forgot that closes anything after lmao
Hey! Quick question: I have created the following listener:
@EventHandler
public void movelistener(PlayerMoveEvent event) {
Player player = event.getPlayer();
if(player.getLocation().getZ() >= Main.instance.getConfig().getDouble("destination.z")) {
Location fireWorkloc = player.getLocation().add(0, 0, 2);
fireWorkloc.getWorld().spawnEntity(fireWorkloc, EntityType.FIREWORK);
Bukkit.getScheduler().runTaskLater(Main.getPlugin(), () -> {
Location location = (Location) Main.instance.getConfig().get("location");
event.setTo(location);
}, 100);
}
}
I have the problem that everything in the runtasklater method is not executed. Does anyone know why?
try Main.instance.getConfig().getLocation(path) as it is default now
the event would have already finished long ago
5 seconds later means that the event would have already run and finished
you will have to tp them or something
^^
and maybe you can change if that destination is a location then:
Main.instance.getConfig().getLocation(path).getZ i hope i write it right to get the z coord
yeah with teleport it works. thank you
do you mean in the query?
yes that is a good idea. Until now, I had only saved the z coordinates individually there.
does anyone know where the error is ? I'm using the https://github.com/Arnuh/ArmorEquipEvent/ API
that isn't even an error
and if you think it is really an error
post the log
im not sure if that an error too, but the event can't be called
that just means u load a dependecies that you forgot to put as a depend
give log
@tacit dagger go to plugin.yml, and make it as a dependency
pretty easy stuff
like this
but you replace Netherboard with ArmorEquipEvent
ahh okay thanks
np
hey if i colourize a string and then replace a part of the string, will that replaced part be colored or not?
like i colourize this and then replace the {0}
"&aSuccessfully set your new home ( &6{0}&a )."
Yes
Yep
I can confirm because i tested it myself
This is a line from the config file of one of my plugins %prefix% &b%player% Has been jailed!
Even if you replace %prefix% with “&a[Hello]” if there is ChatColor.translateAlternateColorCodes (idk if the method is exactly this) it will be a green [Hello]
How do I get a config in another class
?paste
Learn java, then this would be obvious
Can you just say, it's not like I am not trying to learn. How would I learn if I don't ask questions.
You'd pass it as a param in either a method, or constructor.
This is basic java knowledge you'd know by learning the lang itself first
or pass the class, and have a getter
👍
so again, learn java first.
This is all basic knowledge
I am learning while coding the plugin
learn first, then you won't be asking simple questions like this
just about any tutorial goes through the exact question you asked
is there no Map.of(K, V) method somewhere?
Java 9+ has it
smh me using java 8
ImmutableMap.of
mmmh yea
That's immutable however.
If you want to use "Map", then you need to use java 9 or higher
why lol
Map.of returns an immutable map impl tho
So in principle they’re equivalent in terms of what they achieve but Java’s hiding it thus breaking liskov principle Ig
idk maybe my server is running on java8
is there a way to set inventory title without createing a new one?
i don't think there is
ok ty
does someone know how fast allatori responds to purchases?
I didnt get any information from them after the purchase lol, not even an email
lol that can be reversed easily
that's not the question
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Create a thread in case the help channel you are using is already in use!
Yea i know, i basically said you just wasted money lol
The plugin rainbowpro i want get the normal not pro
I don't think so. after starting to use allatori I haven't ever seen my plugins on warez sites anymore
How to get it
They're dumb asf then.
Java-deobfuscator should deal with most of it
😐
Dunno
What?
I don't know
Here i ask?
does a free version even exist?
This channel isn’t for questions about servers and plugins, we got #help-server for it :p
Ok sorry
No worries 👍
what's better: an abstract class or a private constructor? (both dont have instances)
Hey, does somebody know how to do a Scoreboard Plugin in Spigot 1.17.1?
I would just need to know how to set it up
declaration: package: org.bukkit.scoreboard, interface: Scoreboard
rn i got this piece of code but i dont know what i can change:
public void createBoard (Player p) {
Scoreboard board = (Scoreboard) Bukkit.getScoreboardManager().getNewScoreboard();
Objective obj = board.registerNewObjective("mainscoreboard", "dummy");
obj.setDisplayName("§6§lScoreboard");
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.getScore("Teams§8:").setScore(14);
p.setScoreboard(board);
}
letting go? you mean dropping?
yes
is there a way to check wether a user has forge or not and if so, it will give them the custom item. i want to be able to have a minecraft rpg server in which people can connect even if they dont have the mod installed but the mod will improve their experience. ik its a lot to ask but it would be kinda cool
InventoryClickEvent, getAction will be Action.DROP or sth like that
thank you
I sometimes hate IntelliJ. All dependencies are setup correctly but intellij simply doesnt see them after restarting... invalidating caches also doesn't help....... >.<
this only seems to happen using the Ultimate Edition... never had this problem before switching to IDEA Ultimate -.-
MY EYES AAAAAAAA
yeah the sun is shining too bright for dark mode 😛
xD
but for real... what's wrong with IntelliJ... it compiles fine >.<
I use eclipse cuz it's much simpler tbh
I actually think eclipse is much more complicated^^
I switched from Eclipse to IntelliJ about a year ago or sth
shading is hard in eclipse
I just wrote a pom generator that I use every time sooo creating a new plugin is just copy / pasting the pom.xml^^ https://pom-generator.jeff-media.com/
maven is easier on inteliJ
looks good, should try that
maybe I should upload it to github so other people can contribute
yaaay
IntelliJ just fixed itself
is it possible to serialize an itemstack via object output stream ?
i don't wanna use base64 to wright it
a single itemstack?
yep
i have an object which contain a variable itemstack and i wanna serialize this object
but itemstack is not serializable
why cant you use b64
how do you serialize an entire object with a partencoded in base64 ?
public class Stand implements Serializable {
public static List<Stand> serverStands = new ArrayList<>();
public static String shopName = "§6Stand";
private ItemStack item;
private int price;
private Location location;
public static NamespacedKey shopKey = new NamespacedKey(Histeria.getInstance(), "stand");
private final String uuid = UUID.randomUUID().toString();
...
...
}```
How do i customize max enchant levels with enchant gui?
i wanna serialize Stand object which contain an itemstack
How do i customize max enchant levels with enchant gui?
1.17.1
NoSerializableException : itemStack
already done, else i'll be not here to ask help
you need to implement
org.bukkit.configuration.serialization.ConfigurationSerializable
and implement the method
How do i customize max enchant levels with enchant gui?
1.17.1
stop spamming
i try