#help-development
1 messages · Page 463 of 1
just read it and still no idea why use injection :l
any example with the same case?
Is there a list of valid API-Versions? My server is running 1.19.4-R0.1-SNAPSHOT, unsure what the format looks like in the server.yml file.
The API version would be 1.19
Thank you
There's a max distance property
declaration: package: org.bukkit, interface: World
cannot
version?
1.16
tried that
It does work
Make sure you have the right import
isn't it calculated other way tho
You shouldn't have to cast it back to item meta
with +
instead of -
why?
If I want to make a logger file for every chat message that is sent
Do I make my ChatListener write every single log into a LogManager which saves it into a file?
Like, how can I constantly append onto a file without removing current contents
ChatListener should get the data and call a Writer to write to a file
Because you want to increase the damage to the item not decrease it?
Yes yes ok same page, cool
ohhhhhh
alr
ill try
the javadocs description might be a bit hard to understand
yes lmao
why xor mojang
you can learn by coding with somebody who already has some knowledge
and by just asking questions too
JREE
java runtime enterprise environment/edition
java.lang.IllegalStateException: PhoneMessageEvent may only be triggered synchronously.
How can I make my event trigger async from AsyncChatEvent?
Wut
?stash
BukkitScheduler#runTask
for async you need to add other stuff into the event
check staff for async chat event
how can I copy a module? when I do, intellij doesn't treat it as a module for some reason as you can see (the 1_19_R3 is the copied module and the 1_8_R3 is the original one)
did you add the module name to parent pom
i haven't but i remember the other modules working before doing that
lemme test rq
oh nevermind
thank you
Did you help that guy with a ray tracing bukkit thingy?
Did you do a ray tracing thingy?
No wait it was u
How can i make a plugin that drops an item every time a certain amount of people join
?learnjava!
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming. https://media.discordapp.net/attachments/694661573125472256/998143126373941248/6n0v4g.gif
track PlayerJoinEvent -> spawn item -> profit (?)
thanks
what
what potato wrote this?
oh man
what page are you reading
tf is that nonsense
wdym
What lang is that
click the link
guys this is a basic java question but how can i break from an if statement?
and continue to the rest of the code
:/
Put your new code on the same line as the if statement
or move yrou code into a method so you can return when you are finished
Like
if {}
else {}
New Code
if i am ight
is that just an alias?
Use a command framework that can register them at runtime
id just parse them myself and do some reflection with the commandmap
oops
get sniped
half hour now 💀
Guys I'm using the code:
if (getNearestEntityInSight(p, 100).equals(null)) { Bukkit.broadcastMessage("null"); } else { org.bukkit.entity.Damageable Shot = (org.bukkit.entity.Damageable) getNearestEntityInSight(p, 100); Shot.damage(10, p);
If getNearestIntityInSight returns null it is meant to broadcast null to the server.
It still damages the entity if it is in sight and carries on with the code afterwards, but if the output is null, it doesn't carry on with the code, or output null to the server like is written.
And you can call getKeys for any given section
to get all the keys for that section
yes skull me
so if you call
config.getKeys(false) -> ["Menus"]
guys type +:skull:
but if you call
getConfigurationSection("Menus").getKeys(false) -> ["menu1", "menu2"]
So what if
You do something like
if i want to see if something returns null do i just do .equals(null) or what?
== null should be fine
ConfigurationSection menusSection = config.getConfigurationSection("Menus");
for(String key : menusSection.getKeys(false)) {
if(!menusSection.isConfigurationSection(key)) {
// incorrectly formatted config
continue;
}
ConfigurationSection submenuSection = menusSection.getConfigurationSection(key);
...
}
to check for nullability
.equals() is a method that is defined on the Object class
and it's an instance menu
so it'll throw a NPE
// You can open the inventory with this
public void openInventory(final HumanEntity ent) {
ent.openInventory(inv);
}
Found this code on the internet just for looking, but the cmd is then ./inv?
registering commands dynamically is a whole other process
you can still make it
you're learning
Same, i started few days ago with Spigotdev
registering commands dynamically is a bit annoying
but it boils down to simple concepts
- access the command manager
- inject new commands into it
and maybe optionally refresh all the commands for all players
why do you need to register new commands dnamically?
atm i dont know how to link a cmd to a eventhandler
There should almost never be a reason to reg dynamic commands. At least the core /xyz. Sub commands are a lot easier to make dynamic
ehh
my command engine does shit dynamically
I see
the main thing is skipping the plugin.yml
Dynamic as in when the server loads?
uhh
I thought we were talking about on the fly
the server loads, I do some database stuff
and then it loads after the first tick
on the fly is a bit icky but I don't do it immediately on startup
package kloppie74.wildwestern.minerrobot;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
public class ExampleGui implements Listener {
private final Inventory inv;
public ExampleGui() {
// Create a new inventory, with no owner (as this isn't a real inventory), a size of nine, called example
inv = Bukkit.createInventory(null, 9, "Example");
// Put the items into the inventory
initializeItems();
}
// You can call this whenever you want to put the items in
public void initializeItems() {
inv.addItem(createGuiItem(Material.DIAMOND_SWORD, "Example Sword", "§aFirst line of the lore", "§bSecond line of the lore"));
inv.addItem(createGuiItem(Material.IRON_HELMET, "§bExample Helmet", "§aFirst line of the lore", "§bSecond line of the lore"));
}
// Nice little method to create a gui item with a custom name, and description
protected ItemStack createGuiItem(final Material material, final String name, final String... lore) {
final ItemStack item = new ItemStack(material, 1);
final ItemMeta meta = item.getItemMeta();
// Set the name of the item
meta.setDisplayName(name);
// Set the lore of the item
meta.setLore(Arrays.asList(lore));
item.setItemMeta(meta);
return item;
}
// You can open the inventory with this
public void openInventory(final HumanEntity ent) {
ent.openInventory(inv);
}
}
any reason why you cannot use something like /open menu and /open help
How to link a ./command to this like ./inv?
then you can just get the argument from what's in the config
The frog has a gun!
So, I want to optimize a plugin I am making that will only apply to a specific location. I have thought of two ways but I am wondering if there are any other ways. 1st, doing a simple check if the world or location is within the sought area of effect. 2nd (which I don't know how to do but I am thinking it would be possible) activating the event checks and commands for whenever a specified command is run and stopped at another specified command. Any ideas?
micro optimization
I feel like after a certain amount of event checkers it'd start to build up. Plus the code itself in the checkers is not opimized whatsoever ¯_(ツ)_/¯
3sec
Besides, any small optimization is a good optimization
not really no
premature optimization is the root of all evil
It's already made
I would rather focus on actual optimizations rather than small baby things
How to link a cmd to this one
As of right now, it is implementing the 1st type I mentioned
what do you mean by link a command to it
sheeeit
atm their is no way to open the menu
What does entity target block mean? I want to get the first block on the player sight with 15 blocks limitation, I'm using player.getTargetBlockExact(15), is it fine?
Alright well thanks I guess for the... suggestion
yes
but honestly, option 2 sounds like it would be worse for performance
Really? I'd think the opposite. You'd use a plugin like world guard or something to run the initial command and only apply to that specific player initiator.
how do i execute a command when the player clicks on slot 0 position? I tried with event.getSlot() == 0 but it works only if I open the inventory and click with the mouse arrow..
Actually wait, can you attach event handlers to specific players outside of running them on every player and doing a check for UUID, username, or any check in general?
uhhh no
bad idea
i mean u can. but u'd have to make ur own system and you would still just be filtering for which players to trigger an event
Damn, that'd suck. Guess I'll just stick with what I have now. I'm already doing short-circuit with the first if statement being the world check
how else can a player click on the slot if not with the mouse cursor?
but did u even do any benchmarks?, is ur code really performing that poorly?
It's not, but I have only tested it on my dev server and not the actual server yet
shoulnt you create some timings reports while using your plugin then?
or run some spark profilers
Oh my god, I never knew that was a thing
I mean when the player right clicks on whatever item is in inventory position 0
The more you know
and why didnt your approach work?
like when you enter the hub and click on the compass in your inventory to open the menu
Hey Guys. Looking for a bit of advice on the best way of going about developing a custom world generation system. I'm looking to emulate similiarly what origin realms do, where users can create a 'realm' and build in a 1000x1000 area that is generated. I'm fine with that, however what would be the best way of doing this? I see on origin realms, they have created a world with a UUID for each realm, I would have thought it made more sense to have a world with multiple 'realms' on it. Is this efficient? loading, unloading worlds as players teleport to their own.
What's a quick way to add color to text?
ChatColor.GREEN + "text"
I'm getting error java.lang.IllegalArgumentException: Unsupported class file major version 63 when trying to shade my plugin. Is there a reason why I am getting it?
why should i use a getItemInHand but i want whatever item is in slot 0 when i right click execute a command
depends on how big ur playerbase is tbh
I never said anything about a hand, I said why didnt youir approach work, event.getSlot() == 0?
There is greater potential of better ticking performance when using different worlds
Depends on setup. If they use SlimeWorlds, then yes, it's far better for each of them to be loaded individually. Otherwise, you could probably load a "cluster" of realms at a time.
well, origin realms seem to be able to do with 400~ players. Guessing they have some way of storing a world in a database, as I don't think flat file with that many worlds makes sense
if its pretty big best course of action would probably be to have an automatically scaling networks that starts up mini servers as they are needed acting as the players realm
similar to hypixel handles their islands
How do you give text a color based on a hex value?
ChatColor#of()
Thank you
I thought this also, but it seems they run it all on one instance which is impressive
or maybe I'm wrong
they probably have some very impressive hardware then. but i dont have any knowledge of their actual hardware
Their islands are probably on a separate network with some scaling infrastructure.
probably yea
using slimeworlds might not be viable
if 400 worlds are to be loaded into memory
even if they are only 1k by 1k
hypixel has a proprietary very shitty scaling system
It's better than 400 normal worlds though
from what I've understood from my interviews
they run a mini server with all the plugins and just toggle them off depending on what's being played
Their slime world tech is pretty cool though.
slime worlds are cool but it's more of a fancy proprietary system to save a lot of disk space
because event.getSlot() == 0 it works only if your inventory is open, it doesn't work when it's closed, btw I was trying to make a plugin similar to ItemJoin and in the config file I put a config part for each slot so slot1: name,material,lore,command But I can't execute a command when player click on that slot
they also have this thing where you can paste a structure anywhere n shit
and spin up tons of new worlds
💀
Well it's not really proprietary anymore. :p
i loved reading about their replay system
very interesting read
Why don't they just deploy the plugins they need when the spin up a server
Their process for things is pretty cool. So I find it hard to believe that they would just disable certain plugins instead of just using a template or selecting the plugins they need.
My favorite
find that pretty weird too
it's a very old legacy system
cannot execute command when player clicks on item
made back in like 2014 iirc
I'm willing to bet hypixel has a large amount of jank going on behind the scenes
ChatColor#of(), I can't find the of method anywhere
there is some jank
Probably, but what company doesn't? lol
i mean to be honest, what big network doesnt
there is also a bunch of cool shit
Are you using the bungee import?
Something can be both cool and jank
I am not.
That would be why
You pretty much always want the bungee ChatColor now
Sort of. The ChatColor api is just available in the spigot api.
https://www.spigotmc.org/resources/slimeworldmanager.69974/ is this what you guys are talking about?
So there's no downside to using it.
I'm surprised the bukkit one isn't deprecated
Yes, but that is someone's implementation of the underlying tech. You could probably use that though.
That's not the spigot API
Do you know why we don't use the bukkit one anymore? Why did everything except #stripColor() get added to the bungee one?
import net.md_5.bungee.api.ChatColor; fixed the import
i'll look into it and see what it's doing before that, thanks for advice guys
Hexxxx
Yea, but why does all the new stuff get added to the bungee import instead of the bukkit one?
Yeah hex isn't in the bukkit one
I just don't fully understand the rationale behind it.
because the bungee one is just more up to date
It just seems inconsistent is all. I mean, we use the Spigot API to develop but most of the imports are from Bukkit and the only time we need to use chatcolor, we now have to use the BungeeCord API to do so. It's just weird to me.
I have a configuration for each slot in the config file: slot1: name, material,lore slot2: ... How do I add a command: example command to execute a command when I right click on a certain slot?..
Add a section for commands?
yes, but how do I understand the item I'm holding? this can change according to the configuration as i assign the command ??
Configurations are held in memory so once it's set, you'd have to either restart or reload the configuration for anything to be changed.
Secondly, clarify something. Are you talking about an item in a GUI or an item the player is holding in their hand?
an item the player is holding, such as itemjoin
I'm assuming that you already have item checks in place to determine that the item the player is holding is the one that matches in the config,
You'd only have to add some code to execute the commands if the item matches.
and just what you said i can't do...
yes, I'll send you the code so you can see how I did it, each slot has a piece of code that takes the content of the strings in the yml file
would you know how to do it?
Manual file read? I don't think there is an api method available to change it. So you're left with the yaml file import.
File spigotYML = new File(<Server Directory>, "spigot.yml");
FileConfiguration spigotYMLConfig = YamlConfiguration.loadConfiguration(spigotYML);
spigotYMLConfig.getString("messages.unknown-command");
You just need some simple checks then. You already have your criteria, you just need to verify it.
ItemMeta#hasDisplayName()
ItemMeta#getDisplayName()
ItemMeta#hasLore()
ItemMeta#getLore()
You'll need to check if the item has those properties first, then you can compare with the getter methods.
I want to add an item to a chest once it gets generated. I have this code
https://paste.md-5.net/powirahuco.cs
But I get a ClassCastException
https://paste.md-5.net/inifojemuk.pl
Line 45 is
Chest chest = (Chest) state.getBlock();
the problem is that i can't match because the name of the object can be changed at any time as well as the lore ecc from the config file
Well, that's to be expected. Are you wanting the item to persist even if the data changes?
if in the code I put the object in the first slot has the name "hello" and then change the name to game it will give an error
?paste your code
you cast the state not the block
Yes wait 10 minutes pla
Sorry, I don't understand what you mean. I am getting the block from the BlockState and cast that Block to a Chest
You don't cast to a block though. You cast to the state. So just Chest chest = (Chest) state;
ah ok, I'll try that Thank you
how to manually make an item break?
The question is not about minecraft but about the java. Today I learned about Function Consumer and Supplier, so is there any need in custom functional interfaces when you can always use existing ones?
I don't get an error anymore but the Item isn't put into the chest
i need to detect what painting a played based is that a thing
Maybe if the method should take a lot of parameters it's okay. But if the method takes only one parameter...
I could be wrong, but I don't think chests generate with loot anymore. The loot should now be generated upon first open using LootTables.
And do you know if there is an event for when the loot generates?
How do I pass in the main class to an enum class without storing the main class as a static instance?
There is a LootGenerateEvent.
ah, thank you
yes
Is it possible?
what do you wanna do?
@kind hatch https://paste.md-5.net/ikulivodes.pl this is the code
Store NamespacedKeys as enum objects
which requires a reference to the main class
I have exactly the same question, when you are you doing DI, how do you pass Main class instance into utilities? So far utilities musnt be initialized
Yeah basically the same
Now why do that when you can instead make them public static final in a util class?
utilities should not be an intialized class
Yes but what if you need a main class reference?
The keys will never change anyways
not unless it's a static singleton
That could work. I could store the keys in a Util class as public static final
I like that
Let me type an example what i mean
i need to detect what painting a played based is that a thing
How would you get the config instance from main class ? without doing a shity static getter for the instance
public enum Messages {
private Config config;
PREFIX(config.getString("General.Prefix")),
INVALID_USER(config.getString("Messages.Invalid.Sender"));
@Getter private final String text;
Messages(String text) {
this.text = text;
}
}
.
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/Painting.html probably somthing with art
declaration: package: org.bukkit.entity, interface: Painting
Painting#getArt()
You'll have to get cast the blockstate, but you can def get the painting value.
?
Paintings are entities, not blocks
All mc thing are entities ¿
Is there a way to do this without making the main class a static reference?
No
Blocks are not
Neither are chunks nor worlds or particles
you could try using JavaPlugins getPlugin
Entity is every object which represents a model?
Dependency Injection if you wanted to go that route.
Entities are everything that extends the Entity class
But what about if its not the default config, custom class let say?
Oh you are talking about mc entities, because entities in programming doesnt mean that
Yeah i just wanted to say that BlockPlaceEvent won‘t work for paintings lol
Seems I can't quite get it right 🤔
I always have that confuse tho my bad alex
Well, if you use DI, then your variables can't be static.
yea dont instantiate a util class
Make the key not static, but create it in the constructor
But how you pass the main class instance? If you cant initialize it?
See my example for asking
this
A utils class shouldnt need an instance. Just store the keys in the main class
Then it has to be a static instance. There's really no way around that.
can some 1 help?
Set it to null and play the break effect
Isnt not good doing static getters for instances?
yes, but isnt there a method for it?
As with everything, it depends.
I mean i just wanna learn because i dont like that ugly getter
When ever i need to code over a code they provide and it contain a static getter for instance i prefer to reject it
I have this abstract class and i wanna call it in another class, the purpose of this is: if i extend this class just make the getFileName method and bc it is extended i dont need to make more methods, right?
the other class:
Correct
yes
UsersConfig should be better naming and also following the naming convention
yes i know
well, since you shouldn't instantiate a util class, theres no other way
srry
You didnt declare any load() method
Either you think it's static, (which it's not) or that method isn't public.
yes, i thought that, so what happens if i make it static
u changed your pfp
Also why is that class name in lower case
load() is a method provided from YamlConfiguration
error
guys im using this code:
}.runTaskTimer(MinecraftPluginJava, 5, 1);
it says to reference your plugin as the first parameter, should i just put my plugin name? for some reason it doesnt accept this
What class is that in?
thats in the abstract
the instance
You still confuse class names wirh instances
oh so i have to make it an instance before i do?
ah ok no dw i gotcha
for example
ty 🙂
you can make a getInstance() method in your main plugin class
that returns the plugin instance
Plscan you help me?
and then do YourMainPlugin.getInstance() to access the instnace
your Main class is extending JavaPlugin. You must pass an instance of this
what would that method entail?
wdym
What part of this isn't working? Because although hard to read, it looks like everything is working as intented.
i mean how would i make that method?
public class Main extends Java {
private static Main instance;
public void onEnable() {
isntance = this;
}
public static Main getInstance() {
return instance;
}```
@kind hatch do you remember the speech from before??
You should be able to access that method so long as you are extending it in another class. How are you creating the users class? (Which should be uppercase btw)
normal class
like New Java Class
Class
.
I don't fully understand then. If someone changes the name, then that's the user's fault. If you want to make it so that the item works regardless of name changes, then you need to put special data in the PDC of the item and compare against that.
?paste
@sterile token if you really desire an enum wrap it in a class, like so https://paste.md-5.net/udigecadog.java
that allows you to initialize your class while keeping the enum
You can also use the JavaPlugin#getPlugin in an enum if you really needed to.
yep.
Are you giving the player items when they join?
when i in slot1 configuration then slot1: name:"test" material:"test" i also want to add command: "kill test" for example. So I want to connect the content of the command string with the object which is in slot 1 so that when the player clicks the object which is defined in slot one he executes the command which is assigned in the slot. at least i can't find a way to merge these yml files and code
The above evample you can fetch keys with RecipeManager.RECIPIES.ZOMBIE.getKey();
yes
I wil ltake a look
Ok, then forego the item name and lore checks and instead use the PDC to assign custom data. That way, you won't have to worry about players changing the item name.
can you give me an example of how to do it?
@tender shard I forget, do you have a PDC tutorial on your blog?
@smoky adder Use that link ^
Then you'll have to use NBT instead.
why would u program on 1.12.2 if the server runs on 1.8.9 tho
Otherwise, tell your players not to rename those items.
u only risk shit not working for no reason
moreover why are you on 1.8 at all
I don't know since the plugin works in server 1.8.9 even if and 1.12.2 I think up to that version it is compatible
thank u i couldnt find that doc on google
idk why
ehm well, it will work it 1.12.2 but if you use anything from 1.12 and try it on your 1.8. server it will stop working. there are ways to make it compatible for multiple "major" versions but i am not the right contact for that 😄
Dont critize people using legacy versions we are all free to use the versions we want. But then we cant complain about issues or bugs that must be solved on own
word.
?
Why are you this angry
I have the perfect answer and well explained, let me translate it
Sorry if i sound rude on the text but is the truth
You needda calm down
I mean i have seen this situation related to legacy since i join this community
Its really bad that people oblise you to use ewer versions
it means I agree with you
what are u talking about, there is nothing wrong with his message
salty?
wrong chat guys ❤️
yes #general
Extraordinary stuff going on.
It is really annoying this situation of the versioning issue, since they are there to use them and everyone is free to choose the one they want. But then I would not have the right to come to complain because certain things do not work or ask for support itself. Maybe someone will help you, that's the good thing. Basically it is supply and demand, if there were still no people requiring legacy plugins there would be no developers programming them.
Translated with www.DeepL.com/Translator (free version)
What if i come this server for help regarding minecraft version 1.5.2. Is it usual?
u could try
probably wont get much response
but i woulnt be angry at you for trying.
Im trying to find that answer haha, i dont understand why people get mad when using legacy versions because there is nothing wrong with them
.
For me it is something related to consumerism. Because I have seen 1.8 programmers making over $100 (usd) in really simple commissions. But in 1.19 on the contrary they pay you less, because supposedly the api is better
I get you mate yeah
I think there's a stigma around using legacy code. As developers, we are drawn towards using the latest and greatest. The same applies to minecraft. People usually want what's in the newest updates and developers have to follow with them. So when the majority is using the latest, it gets annoying to try and backport features that clearly can't work on older versions.
They are paying 1.8 devs more because it's harder to find a 1.8 dev. You can demand more money.
id just ignore hate tbh xD
I totally agree with your point, but there is no need for being rude with those using legacy versions
just my suggestion i learned to absorb criticism and filter/+ ignore toxcicity
unless its towards beginners xD
then i dont ignore it
Hello elgar
As when they go around annoying, the one who gets angry loses. It's something you learn a long time ago, you have to ignore simply because it's worse if you play along.
u know what ppl hated me on for?
Im not really sure if you can explai nit
im translating my native c++ library to work with different languages ```csharp
public string GetFileExtension()
{
if (IniParser.m_pIniParser_getFileExtension != nullptr)
{
unsafe
{
string? str = Marshal.PtrToStringAnsi(((delegate* unmanaged[Stdcall]<IntPtr, IntPtr>)IniParser.m_pIniParser_getFileExtension.ToPointer())(this.m_pIniParser));
if (str != null)
{
return str;
}
}
}
return "";
}
why are you using unsafe contexts, why are you using pointers, this is c#, why are you using delegates, just scrap your project its useless blablabla
when i literally explained this before ```txt
im translating my native c++ library to work with different languages
once i finished this, ill make my lib work for java and to that extend spigot
so yea^ xD
For me is still being consumism
You mean consumerism?
Hey, I was directed to AsyncPlayerChatEvent to see how a event could be called Async
yes my bad* its diff world for me
wdym
But I can't seem to figure out how to mirror the implementation or what part allows it to be async
I want my custom event to be able to be called async
isnt player chat running on a different thread altogether?
as such being async
or wdym
Yes
yea
And calling a event that's sync from a async thread isn't possible
So I need to make my event support async
write an interface
that is thread safe
let ur async event populate it
and let ur sync thread fetch it
basically uni or bidirectional populating with commands and fetching
It’s just calling super(whatever, true) in the constructor
but im still not entirely sure if i got ur question right
Oh yeah lol I just looked at Event class
kekw ```txt
(process 1776) exited with code -1
I'm trying to use FileHandler to be able to write log-type messages to a file but getting some weird errors
great now my minecraft launcher keeps crashing with the error msg failed to update launcher all of a sudden
.txt.lck
FileHandler fileHandler = new FileHandler(file.getPath());
This line says a file with whatever.txt.lck does not exist:
- The line above makes a new file called
whatever.txtnotwhatever.txt.lckand I checked that the path wasn't wrong - I think maybe using FileHandler is not the correct approach
Is that a lock file?
Uhhh asuming I don't know what a lock file is I'm gonna say no
file = new File(plugin.getDataFolder(), "logs/" + uuid + ".txt");
FileHandler fileHandler = new FileHandler(file.getPath());
I think indeed FileHandler is not the right thing for this
Maybe BufferedWriter
I looked online and said it was a decent option
a file lock is a mechanic to ensure one process at a time can write/read to the file
But they tend to use it with a logger
Interesting
Ok ok I'm gonna switch to bufferedWriter since it's a log-system it should constantly write
Isn't BufferedWriter the default recommendation for that?
Prolly
Wasn't when I searched but now I will use it
buffered writer is buffed at writing ye
Are you a buttom?

lmao
lmao
well
is anyone else having problems with their mc launcher rn?
Doesn't make much of a different right? I could literally make it .thisisalogfile
It would be better if you had a standard extension though.
.log is for informative purposes
Well what sort of logs are you storing?
Yes that is of course correct
Lets say I'm storing
Chat messages
Called by an event inside my plugin
So obviously I think .log is the right way
Why not use a database or some cool format like json
.log will work just fine.
I feel like having 1 long log file is worse
Than being able to straight up separate it by objects
File extensions are mostly arbitrary. On UNIX systems, it doesn't matter what the file extension is. The file contents determines the type
So you can straight up see the logs for a individual object
Thought so, thanks for the help guys
You can have more json files.
Why would I chose json over just... text tho
Is there a specific?
Besides maybe future readability
I guess parsing for statstics.
Why not? Easy to decode and encode.
It's an extra step tho for something that might be writing into the file 2-3 times per second
I guess making a cache is also smart
But yeah, i got the idea now
JSON is a lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. JSON is a text format that is completely language-independent but uses conventions that are familiar to programmers of the C family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. JSON is a better choice than plain text because it provides a standardized format for structuring data and almost every programming language can parse it
Chatgpt but yes, I do agree with that
I will probably end up doing it with json
Now I have one last qustion
Unless you plan on doing anything with the logs, like statistics, then it doesn't matter how you store it.
Using FileHandler like before, you could set a formatter
Like for example
SimpleFormatter formatter = new SimpleFormatter();
Instead of that I assume I make my own format for the message before it's written
Yah. Just setup your json encoder and decoder
You can tell it how to store as well as how to read.
👍
Thanks
...
file = new File(plugin.getDataFolder(), "logs/" + uuid + ".log");
Since when does this not create the file
If it isn't there
Forever.
tf
You have to call #createFile()
What
File phoneDataFile = new File(plugin.getDataFolder(), "phoneData/" + phone.getPhoneUUID() + ".yml");
I'm using this literally 1 class above and it creates the file if it isn't there
Could you imagine what would happen if it created a file every time you initialized the class?
Are you saving a yaml later?
It's just the former.
File phoneDataFile = new File(plugin.getDataFolder(), "phoneData/" + phone.getPhoneUUID() + ".yml");
phoneData = YamlConfiguration.loadConfiguration(phoneDataFile);
phoneData.save(phoneDataFile);
Yes
Is that why?
Damn, interesting
Yes
The Yaml implementation that spigot has is all loaded into memory. You have to write it if you want it to persist.
Learn something new every hour, good philosophy
A file is just a pointer
Is that why it's never null?
What’s never null?
The File object
It says it's nullable
When you read "Then the new file is created" instead of "then the new file instance is created"
Makes sense now
I mens ur literally creating an object
Why would it be null
Because there's a difference between declaration and initialization.
So wait let me understand something about File then
file = new File(plugin.getDataFolder(), "logs/" + uuid + ".log"); <--- Path to the file, can exist or not
if (!file.exists()) { <--- Check if there is a actual file here
file.createNewFile(); <----- Create the file
<----- I still need to load the file again like the first line?
}
It’ll just be a file instance representing nothing. It won’t be null
It’s a pinter
Pointer
It doesn’t load shit
#createNewFile returns a boolean. It won't create anything if it already exists.
Oh... bruh
It returns whether or not it was actually able to create the file.
Don’t put air into your brain
Why does argv++; break google java convection?
.
[16:58:09 WARN]: java.io.IOException: The system cannot find the path specified
Hm?
file = new File(plugin.getDataFolder(), "logs/" + uuid + ".log");
if (!file.exists()) {
file.createNewFile();
}
```how
How does it not find the path if it just created it
it took 4 hours for the guy to accept
is there a logs folder already?
mkdirs
lol
Huh? I sent the question and left for hours I just got back 10 minutes ago, relax
np i just came back too
Another thing that I thought was done by File but instead is done internally by Spigot YamlConf
Is there a way to spawn a vanilla structure with a plugin
you still have mkdir() on File
that's just an upgraded version for bukkit to utilize mkdir multiple times afair
Use the structure manager
?jd-s
According to Google's Java Style Guide, you should use the prefix form of the increment operator (++i) in preference to the postfix form (i++)¹.
The reason for this is that the prefix version (++i) can be more efficient than the postfix version (i++) because it avoids the overhead of creating a temporary variable.
Source: Conversation with Bing, 11/04/2023(1) Google Java Style Guide - GitHub. https://google.github.io/styleguide/javaguide.html Accessed 11/04/2023.
(2) increment operator in java - Stack Overflow. https://stackoverflow.com/questions/27891504/increment-operator-in-java Accessed 11/04/2023.
(3) Google Style Guides | styleguide. https://google.github.io/styleguide/ Accessed 11/04/2023.
(4) Google Java Style Guide - GitHub. https://google.github.io/styleguide/javaguide.html Accessed 11/04/2023.
(5) increment operator in java - Stack Overflow. https://stackoverflow.com/questions/27891504/increment-operator-in-java Accessed 11/04/2023.
(6) Google Style Guides | styleguide. https://google.github.io/styleguide/ Accessed 11/04/2023.
(7) Google Java Style Guide - GitHub. https://google.github.io/styleguide/javaguide.html Accessed 11/04/2023.
(8) increment operator in java - Stack Overflow. https://stackoverflow.com/questions/27891504/increment-operator-in-java Accessed 11/04/2023.
(9) Google Style Guides | styleguide. https://google.github.io/styleguide/ Accessed 11/04/2023.
uh oh
Wth, there's a difference in functionality. One adds before, one adds after. What would it matter if you are using the appropriate one?
Is that the power of 4.5?
performance most likely is not the cause
You are correct that there is a difference in functionality between the prefix and postfix forms of the increment operator. However, according to Google's Java Style Guide, you should use the prefix form (++i) in preference to the postfix form (i++) because it can be more efficient than the postfix version as it avoids the overhead of creating a temporary variable¹.
Source: Conversation with Bing, 11/04/2023(1) Google Java Style Guide - GitHub. https://google.github.io/styleguide/javaguide.html Accessed 11/04/2023.
(2) Google Style Guides | styleguide. https://google.github.io/styleguide/ Accessed 11/04/2023.
(3) styleguide/eclipse-java-google-style.xml at gh-pages - Github. https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml Accessed 11/04/2023.
(4) Google Java Style Guide - GitHub. https://google.github.io/styleguide/javaguide.html Accessed 11/04/2023.
(5) Google Style Guides | styleguide. https://google.github.io/styleguide/ Accessed 11/04/2023.
(6) styleguide/eclipse-java-google-style.xml at gh-pages - Github. https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml Accessed 11/04/2023.
Tihi
Google can kiss my ass
Yes it is @tardy delta
New 4.5 is pretty crazxy
It’s bing, but yes.
If I had to guess it is more of an error-avoidance mechanism. A loop like
int x = 0;
while (x < 10) {
x = x++;
}
will loop ad infinitum.
But
int x = 0;
while (x < 10) {
x = ++x;
}
not.
does i++ really create a temp variable?
bing gives weird answers
i thought processor/ASM just uses some command for incrementation
On a bytecode level probably. On a JIT level? Unlikely.
create folder
And with temporary variable I mean like pushing an element to the operand stack
Not what the styling guide says 🤷🏽♂️
Not a fully-fledged LVT var
Go yell at google
oh it might be
LOAD_FAST i
LOAD_FAST a
and
TRUE_ADD a
or smth similar
that's python dis, not real instruction
Yes, it does matter if the JIT optimizes the bytecode. The JIT compiler can optimize code by removing unnecessary operations and simplifying expressions. In some cases, this can result in the postfix form of the increment operator being optimized to the prefix form². However, it is still generally recommended to use the prefix form of the increment operator (++i) instead of the postfix form (i++) because it can be more efficient than the postfix version as it avoids the overhead of creating a temporary variable².
Source: Conversation with Bing, 11/04/2023(1) How the JIT compiler optimizes code - IBM. https://www.ibm.com/docs/en/SSYKE2_8.0.0/com.ibm.java.vm.80.doc/docs/jit_optimize.html Accessed 11/04/2023.
(2) Increase performance in OpenJDK with JIT | Red Hat Developer. https://developers.redhat.com/articles/2021/06/23/how-jit-compiler-boosts-java-performance-openjdk Accessed 11/04/2023.
(3) Compiler optimization: Java bytecode - Stack Overflow. https://stackoverflow.com/questions/1680024/compiler-optimization-java-bytecode Accessed 11/04/2023.
(4) Increase performance in OpenJDK with JIT | Red Hat Developer. https://developers.redhat.com/articles/2021/06/23/how-jit-compiler-boosts-java-performance-openjdk Accessed 11/04/2023.
(5) Compiler optimization: Java bytecode - Stack Overflow. https://stackoverflow.com/questions/1680024/compiler-optimization-java-bytecode Accessed 11/04/2023.
(6) Understanding JIT Compilation and Optimizations - Oracle. https://docs.oracle.com/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/underst_jit.html Accessed 11/04/2023.
When a method is chosen for compilation, the JVM feeds its bytecodes to the Just-In-Time compiler (JIT). The JIT needs to understand the semantics and syntax of the bytecodes before it can compile the method correctly.
Learn how HotSpot's multi-tiered execution system uses the interpreter, quick compiler, and optimizing compiler to help enhance Java's performance in OpenJDK.
Biing
Source?
Chat GPT seems to have made that up
It links to the ibm post
file.getParentFile().mkdirs();
file.createNewFile();
You know what? Let's test it for ourselves
In python one can make a string using
whatever_string = f'This string has {variable_number} numbers'
What's the alternative for something easy to build strings in java
String builder and just have 10 appends?
String.format or String#formatted
"this string has %s numbers".formatted(num) or whatever placeholder
we are getting string templates or smth (forgot what its called)
Eh str substitutor is similar from some library
but the syntax is weird
But well, it’s not the same at sll.
Prefix:
0: iconst_0
1: istore_1
2: iload_1
3: ldc #7 // int 1000000
5: if_icmpge 26
8: getstatic #8 // Field java/lang/System.out:Ljava/io/PrintStream;
11: iload_1
12: invokedynamic #14, 0 // InvokeDynamic #0:makeConcatWithConstants:(I)Ljava/lang/String;
17: invokevirtual #18 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
20: iinc 1, 1
23: goto 2
26: return
Postfix is exactly the same. For
class TestPostfix {
public static void main(String[] args) {
for (int postfix = 0; postfix < 1_000_000; postfix++) {
System.out.println("postfix: " + postfix);
}
}
}
Gonna be honest I don't like python
Use kotlin 💪🏻
But jesus the python one is clean
Being able to do functions/variables inside { }
Is so nice
If I had to guess javac will optimize any postfix operation that can be compiled down to iinc to use iinc (which basically is the prefix variant)
how do I make this file be in plugins folder when plugin starts
Hi guys, Im trying to make server like bhop or surf servers in cs, I mean passing maps and be able to vote for the next one. So the problem is that one map using command blocks can affect another map. So I think it's a good idea to just unload rest of maps (Server.unloadWorld) when map changing, but the problem is that for some reason bukkit won't allow to unload maps which have dimension = 0 (Overworld), I found out it from source code. Have you any ideas how to solve that?
put it in your jar
Include in the jar
So whatever but it seems that ChatGPT clearly does not know what it is saying
Then just do saveResource(whatever, false)
chatgpt didnt know what it was saying when i let it wrote assembly either
It used what some other noobs said in other places haha.
No - it made up it's own sources
i'm making a multi module project to make a plugin compatible with different nms versions and i'm getting some compilation errors because of different java versions of the spigot dependency when compiling. Can anyone help me?
bad class file: C:\Users\kill05\.m2\repository\org\spigotmc\spigot\1.19.4-R0.1-SNAPSHOT\spigot-1.19.4-R0.1-SNAPSHOT.jar(net/minecraft/network/NetworkManager.class)
class file has wrong version 61.0, should be 52.0
I grepped it's referenced sources and it does not mention it
Oh well tiip
The issue with ChatGPT is that it will make up it's own sources once you ask for verification.
Riip
Or rather said it will use unrelated sources
its not loading
Bing was supposed to be better 🥲 Well it’s good for some things.
Did you use saveResource?
That IBM document has nothing to do with prefix/postfix incrememnt but rather JIT optimisation (and deoptimisation) in general
bing is just, here you have some small info and here are the sources, go figure it out yourself
it doesnt really get deep
wdym
gn
plugin.saveResource("file.png")
(or this instead of plugin if you are within your JavaPlugin class)
or no this :)
(and not using static methods)
this.getPlugin(MainClass.class).saveResource
:D
we arent the first of april anymore
Uhhh
BufferedWriter writer = new BufferedWriter(new java.io.FileWriter(file, true));
writer.write(message);
I see this doesn't include a next line character every time
can anyone help me with that
Files.newBufferedWriter
Do I really need to add the endLine each?
Oh will change that too
i don't know how i'm supposed to make a plugin compatible through versions 1.8 to 1.19 by using the same java version
I think you have to compile for java 8
musnt you use the lowest java version, not sure if you can set java version per module
writer.write(message);
writer.newLine();
i'm compiling for java 8, but maven doesn't like me compiling to java 8 with a dependency from java 17
bad class file: C:\Users\kill05\.m2\repository\org\spigotmc\spigot\1.19.4-R0.1-SNAPSHOT\spigot-1.19.4-R0.1-SNAPSHOT.jar(net/minecraft/network/NetworkManager.class)
class file has wrong version 61.0, should be 52.0
@tender shard ^
what are you doing?
If you don't add a newLine
It will all go to the side
And I saw it had a writer.newLine() method
writer needs a special character to understand there is a new line
otherwise it doesn't know where to stop
Fair
Just stick it all on one line
and it doesn't provide line writing
New lines are a waste of bytes
declaration: module: java.base, package: java.io, class: PrintWriter
declaration: module: java.base, package: java.io, class: FileWriter
in there you can use the same thing
so can anyone help me?
set your jdk to 17
are you using IJ?
you simply have to start maven through java 17
that's all
File -> Project Settings -> JDK
you can keep target/source level at 8
yes
erm yes
and that would still run on 1.8 servers wouldn't it
yes
aight lemme try
this lets you compile against java 17 dependencies, while keeping your actual .jar compatible with java 8
that worked, thanks
np
also when building a multi module project, am I supposed to build the parent project?
yes
but the parent doesn't have any .jar itself
usually you have a distribution module that shades in all your other modules
[22:41:52 ERROR]: Could not load 'plugins/worldedit-bukkit-7.2.14.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized!
who can help me
yeah that's what i did, i have a plugin module that shades the core and the core shades all the nms implementations
You did „new MyMainClass()“ somewhere
Dont do that
??
Oh its worldedit
yes lol
Wrong channel
shutdown server
can u help me in #help-server ?
Hey, I'm getting java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 error, this is the code: https://pastebin.com/rawHC2sz
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Any idea how to fix? I get the error when I break a block outside an area
line 41
Yeah I got that, I'm asking if you got an idea what to do to fix xd
if the array is empty there is no get(0)
check this.mines.getMinesByLocation(location);
if (masterLocation == null || masterLocation.isEmpty())
hello has anyone ever used traincarts and bkcommon lib? I would like to launch a train from my plugin
That worked, thanks a lot! :)
Bruh
You're coding now?
just do some basic reverse engineering
nvm it's open source lmao
hu
Are ACF tryhards online?
I want to make a command like:
@Subcommand("text")
@Description("Text a contact.")
@CommandCompletion("@contacts")
public void onTextCommand(Player sender, @Single String phoneNickname, String... message) {}
But currently the autocomplete goes for all parameters after phoneNickname which is actually the only one it should apply to, then I want to allow the user to be able to enter any amount of arguments since it's a message
@lost matrix Only acf tryhard I remember
Please don't use @CommandCompletion on this method, so no autocomplete suggestions are shown after the first arg. Users will have to manually enter the full message
@Subcommand("text")
@Description("Text a contact.")
@CommandCompletion("@contacts")
public void onTextCommand(Player sender, @Single String phoneNickname, @VarArgs String... message) {}``` Here, I am using an `@VarArgs` on the method, to allow any number of args
And here, I am using an `StringBuilder` to concatenate all further args into the message:
```java
public void onTextCommand(Player sender, @Single String phoneNickname, String... messageParts) {
StringBuilder message = new StringBuilder(phoneNickname);
for (String part : messageParts) {
message.append(" ").append(part);
}
// Use message...
}```
Generally, to avoid autocomplete applying to all further `args`, you have two options:
1. Don't use `@CommandCompletion`
2. Use `@VarArgs` to allow an arbitrary count of args, and concatenate them yourself
No problem, If have time, I will answer everywhere 😄
Ask away
I have a logger method that is supposed to write to 2 different files at the same time
For that I created 2 File instances, 2 BufferedWriter instances, 2 String builders
But I'm getting a very sexy StackOverflow error
It's so long I can't even read it
show the code please
?paste
https://paste.md-5.net/yexaqudihe.cpp
If you want to look at a 1.1k staroverflow error
synchronize your access to the files, to avoid write conflicts
you can synchronize the whole method
or just use the File/BufferedWriter operations
There is no chance both files would be the same
wait, let me rewrite it
One thing I can tell you is, the synchronized keyword will ensure only a single thread can execute the method at a time
that will avoid conflicts
properly closing the resources ensures no leaks
checking for and handling IOException is always a good idea
Wait but
What is the actual issue
Like I understand about synchronized
But if the method is just called once
Why does it matter
That could be
your method is calling itself repeatedly
you have a recursive call to writeMessageLock() inside the method
you're accidentally creating and closing the File, BufferedWriter etc
You saw the entire method tho
resources in a loop, causing repeated re-opening
Let me log how many times it's called
Nope
Just once
I am big confusion
Slowly commenting 1 by 1 here we go
Will do your alternative if I can't find the reason why
You don’t need to make that synchronized
It’s not being called from multiple threads
That’s unnecessary overhead
Uhm ok
hold on
This is bad
So, commenting out line by line
And eventually reaching the bottom
Now... no stackoverflow
Simplify
//me.tomisanhues2.rpphones.phone.abs.APhone.receiveText(APhone.java:314)
Oh wait
I found something
What’s on that line
He sent it
Maybe it's not directly related with that
But another question
So in my logs, I'm openning and closing the files
Can't remove this file cause it says in use O.o
But it should've been closed
logic error, thats not valid
That could be the error
I think it's time to implement a buffer to write stuff to files
Doing it on every log seems really inefficient
I gtg rn so please tag me and I will see it. Thanks a lot
Wait what did you even change
The send message line
hi, my default config file isn't being saved to my plugin folder
i have a config.yml file in the resources folder
#saveDefaultConfig()
and this.saveDefaultConfig(); was placed into the onEnable event
no errors are being thrown in the console
Objects.requireNonNull(Bukkit.getPlayer(this.phoneOwner)) should be Objects.requireNonNull(Bukkit.getPlayer(phoneOwner)).
no opening { before public void receiveText(Text text)
no closing } at the end of the method
color should be Color
event should be new ClickEvent()
append should .append()
this is what caught my eye at first glance
am i wrong, please correct, maybe i sleep with open eyes too
On enable Event? Or the overriding method in your main class?
the latter
Why are you overriding it
?
?
You shouldnt override it lmao
What?
It's the method inherited from javaplugin
when i first created the plugin it made this file automatically with an onEnable method and onDisable method
OK?
It’s normal to override onEnable
saveDefaultConfig
Not onEnable
Or I misunderstand lol
Is there already a different config file in your plugins folder @quaint mantle
nope
It’s hard to answer a programming question without code
Oh no! You ran into a problem. But no worries, people are willing to help, but first they need to see your code. This is because otherwise, they would be providing help based on guesses instead of concrete knowledge. Whether it be a compile error, runtime error, or an unexpected output, I'm sure that if you were to provide code, you'd receive a quick solution.
sometimes I need to add spigot instead of spigot-api as a dependency in my maven for a plugin due to needing NMS. when I do this, I don’t get javadoc descriptions when doing ctrl q on a method. how can I fix this / add javadoc descriptions back since it’s not in spigot jar
this is my first ever java project if code is spaghetti that is why
public void onEnable() {
MyDeathEventListener deathEventListener = new MyDeathEventListener(this);
getServer().getPluginManager().registerEvents(deathEventListener, this);
this.saveDefaultConfig();
Logger logger = getLogger();
File f = new File(getDataFolder() + "/");
if(!f.exists())
f.mkdir();
File myFile = new File(f,"playerdata.yml");
try {
myFile.createNewFile();
logger.info("Created playerdata file.");
} catch (IOException e) {
logger.severe("Failed to create playerdata file: " + e.getMessage());
}
getServer().getPluginManager().registerEvents(new MyJoinEventListener(this, myFile), this);
logger.info("Exponential Bans is now started");
}
i put it in the resources folder
startingTime: 4
increaseAmt: 4
maximumBanTime: 48
Are you building with maven or gradle
maven
Hi guys, Im trying to make server like bhop or surf servers in cs, I mean passing maps and be able to vote for the next one. So the problem is that one map using command blocks can affect another map. So I think it's a good idea to just unload rest of maps (Server.unloadWorld) when map changing, but the problem is that for some reason bukkit won't allow to unload maps which have dimension = 0 (Overworld), I found out it from source code. Have you any ideas how to solve that?
You can’t unload the main world
well it can't be
it's not "main"
because there's no config.yml file
Check the exported jar with something like 7zip
Make sure the config is in there in the right spot
where should i be looking
It should be in the same place as plugin.yml
it should be in the base jar
hello, does anyo0ne know of a way i could make it possible to place end crystals when there are light blocks in the way? i havent been able tot figure this out and i dont want to have to remov ethe light blovcks from my maps, cuz they dont look the best without light. please let me know if its possible
