#help-development
1 messages · Page 1961 of 1
A lot
Not all
o
Not all but a lot yeah
You can write a parser that doesn't use bnf
Bnf is just a way to can make it simpler
ic
It's typically used as a regex-like format that parser generators read to generate code that does the same thing
nah this aint simple ._.
What, the bnf?
yes
You just have to learn it
It is though
how is this simple at all
integer ::= [0-9]+
If it weren't simple, Groovy wouldn't use ANTLR, which uses an extended form of BNF.
Any digit between 0 and 9, and there must be one or more of it.
"a decimal is a series of digits, then a dot, then another series of digits"
That's what that represents.
Then this is just two integers separated by a .
This is self-explanatory.
"a boolean is either the literal word true or the literal word false"
list ::= "[" sep (object ("," sep object))? sep "]"
map ::= "{" sep (mapEntry ("," sep mapEntry))? sep "}"
mapEntry ::= string sep ":" sep object
what the is this
Start with list
I imagine if there were no sep then it would be easier to read
Yes get rid of sep for now
list ::= "[" (object ("," object)*)? "]"
Sep just matches whitespace
Now you have a list
It starts with [
It optionally has an object in it
Where an object can be any value
and the object can have another object
That object is followed by a comma and another object repeated between 0 and infinity times
o
So it can be []
Or [1]
Or [1,2,3]
If you put the seps back in it just allows you to have whitespace between those tokens
So it can be [1, 2, 3] or [ 1 , 2,3 ]
Make sense?
how can i disable natural mob spawn in specific area but be able to spawn mobs there from code?
yes
So yeah BNF is really easy to understand you just need to understand the syntax and break it down like any language.
i guess its simpler than what it looks like
Yeah it's really powerful
Too bad I haven't had a good use for it
I'll use it next time I make a custom format I guess
i should learn json
It's easy as hell
Typically people write grammars (language descriptions) in BNF before actually writing their parser
You can learn json in a few minutes
It's like an outline of what to do
o
BNF essentially becomes the bridge between machine and human understanding of language.
That spits out a token tree you can then parse much more easily than a raw string
Oh that's p'cool
https://github.com/Redempt/RedLex if you're interested
thats cool
RedLex-JSON is basically just a demo of how to use it
But there's no real reason to use that as an actual JSON parser
Making a parser for json is probably way too good for me atm, or am I overestimating it
velocity
Because it's ~5x slower than my regular json parser
It's not all that bad but you should be at least intermediate with Java
everytime i see @waxen plinth in this channel he is selfadvertising for his libs
idk how to set a vector that will throw players depending on their location from an explosion
You can start with simpler parsers
❤️
ic
get the location of the explosion, get the direction, invert it, set velocity
i can do
double distance = e.getEntity().getLocation().distanceSquared(le.getLocation));
thats the distance but thats all ive done
i just thought maybe if theyre closer
itll do more knockback
then get the vector of the explosion in relation to the players
player.getLocation().subtract(tnt.getLocation()).toVector()
That gives you the vector from the tnt to the player
Writing an HTTP server is also a pretty good exercise imo
Then you can normalize it and add it to the player's velocity
then i should invert it and add some velocity to the player?
oh ok
That's pretty broad though
that would be a cool idea for a black hole thing lol
I mean you don't need to make a full server
No I mean an http server can be just about anything
That's arguably more broad
A server that displays a page when you visit it in a browser
Yeah but what
What page?
A file server could be a good project
Literally fucking anything :p
A chat room
Yeah that's a bit like saying "writing a program is a good project" lol
"try making a plugin"
I REALLY want to make smth like that
Though for anyone trying to write an http server and wanting to make it use https
Not hard, just need a bit of socket magic
Which I do not know how to perform
🧠
The java.net API, while a bit dated, is still very good.
The entire idea is to code the requests yourself
ok so this
I mean
I did this a while ago: https://github.com/MaowImpl/maowhttp
wdym
so uh
But you might wanna add instead of setting
i dont think there is an addvelocity
maybe im wrong
entity.setVelocity(entity.getVelocity().add(vector));
@waxen plinth is it possible to make a website to write the messages that chatroom receives?
i mean it is possible but do you know some keywords I can use to search?
hey
is there is a list of yaw and their direction values
e.g. NORTH, EAST, SOUTH, WEST
ended up figuring thato ut
either way I need to learn html so fuck
1.8.8 is what i use
I have created an item but I want to make it only have one use, that is, when it is used it disappears. how could i do it?
what is its use
Yeah
if its a breaking tool then check for break event then player's main hand
and replace it with air
On maven you have only spigot-api, for using the spigot jar
it is an item that when you right click gives you positive effects
it is not a tool
You would want 1.8.8, not just 1.8, everything else as well
So in the end, 1.8.8-R0.1-SNAPSHOT
I'm using essentials to give me a spawner, however, when I break the spawner it always says the .getSpawnedType() is PIG. Does anyone know how I should go about getting the real spawnedType?
Is there a way to clear out player data for all plugins?
data should be cleared on restart/reload if they don't use a database
otherwise just clear the database
Alright thanks
How to set look direction
of a bat?
yaw seems to be always 0
despite changing the direction with #setDirection()
of the entity
Then listen for a PlayerInteractEvent and if the action is click air or click block check if the amount of the ItemStack clicked is greater or equal to 2, if yes, subtract one from the ItemStack if no, set the ItemStack to be air
The direction is a vector getting the yaw and pitch to make a 3D line.
To set the yaw, make a new location, change the yaw and then teleport the bat to it
Hi how I can copy all world region? Exists API to do it without problems?
Like if I wanted to take a block by location how can I do that. I know there is getWorld().getBlockAt(x, y, z); but I have a problem because I want to loop this about 8mil times.
Is it possible to copy a blocks persistentDataContainer?
And if so, how do you set one blocks persistentDataContainer to another block
why does it show an error i have the spigot jar added to the modules
what the hell are you doing 8 million times
use something like maven or gradle. you cannot use the jar anymore as a module
whats that supposed to mean
use a proper dependency handler like maven or gradle
?maven
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Gradle is for people who wash paper plates
lmfao
ok thank you
then after u run ur code
remove item from inventory
is the "minecraft developement" intelliji plugin good or no like should i set it up normally without it or is it actually helpful?
Hi, does anybody have suggestions for software that renders Minecraft chunks into like an isometric view 2d image?
ok thank you
I want to do something like https://opensea.io/collection/lymmzy-chunks
its good for everything related to mc development
not just spigot
Not create NFTs but just the images
even forge, paper, velocity, bungeecord
thx
its amazing
Getting and saving blocks to a file.
does using a method that returns an object for example
World.getAtBlock(x, y, z)
will the block
object keep it self in memory
(if we dont assign it to a variable)
The jvm should chuck the memory back in the heap eventually but it will exist for a little bit
o
Wdym?
so will creating a new thread every 100 blocks and doing operations for 8m blocks lag it
I think it will
the jvm is pretty smart, but im not sure exactly how it will work with that
I am trying to use components for chat. I am using the component builder however the text I want is already colored so i cannot just do .color(ChatColor.something). An example of this is I am trying to allow users to type [item] in chat and display the item that they are currently holding. I am using hex colors for this so it has made my life a lot more complicated and i do not want to over complicate things if there is an easier solution. please let me know if you know one.
for example:
(pseudo code)
for 8m blocks each 100 blocks make a new thread, and in that thread save the 100 blocks with their material name in a hashmap
not sure if thats even psuedo code
what are you exactly trying to do? bukkit is not thread safe so everything has to be done on the main thread
it isnt but yes
That's... not how that works.
Somethings are thread safe some are not
most arent
Bukkit isn't thread-safe so you can't have shared mutable state.
But you could still easily have a bunch of asynchronous operations.
Couldn’t you have a listener for chat messages and if it contains [item] replace that with the held item’s name?
will this lag the server
thats the easy part
Obviously yes
imagine if the hashmap suddenly disappears
will the memory still have something related to what we just did
Why would it? If it is deleted
Yes, deleted
the name is not this... the real name is a bunch of hex colors
real name
if the object is deleted then the memory will be freed
They will be there in the world but not in the hashmap
I know
ahhhh 1s lemme say it simpler
i looped through 8 million entries without creating new variables, printed out each one, what will happen to memory after the process is finished
in order to do that I would have to do something like new ComponentBuilder().color(ChatColor.of("#0000FF")).append(text to be colored).create however the string that I am appending is already pre colored
Anyways Why would you save that amount of blocks?
Is there a faster way to do it?
If you are not saving it in any persistent place the memory will be freed
Sadly I think no
./fill (limit of 32k blocks and its prob the same so ignore that)
:o
bukkit will handle that, the blocks were either previously loaded in memory or if the chunks were unloaded, bukkit will load them and then unload them. I am not entirely sure on the second part of my statement but bukkit handles all of it
So why would you color it again?
what if it wasnt using bukkit
Then what are you using? NMS
thats how the component builder works, thats how you should color things, however it makes it complicated for me to get hex colors from a string like this §x§0§0§F§B§2§8D§x§0§0§F§4§4§9i§x§0§0§E§D§6§Aa§x§0§0§E§7§8§Am§x§0§0§E§0§A§Bo§x§0§0§D§9§C§Cn§x§0§0§D§2§E§Dd §x§0§1§B§F§F§9P§x§0§4§9§F§F§2i§x§0§6§7§F§E§Bc§x§0§9§6§0§E§4k§x§0§B§4§0§D§Ca§x§0§E§2§0§D§5x§x§1§0§0§0§C§Ee
?
you could try using chunksnapshots
I want to make that on mc versions from 1.8 to 1.18.1
is there a way to remove warnings for CommandExecutor onCommand overrides?
Oh my god
you see my pain now... lol
Then you can trim the colors off and color it after?
can you try to explain what you are trying to do exactly so we can give you a definitive answer without a bunch of unknowns/whatifs?
right, i have done something like this recently for multiversions - i had to use multiple modules for that cause on older versions the getMaterial returns an int. but eh it might not be that much faster
what if u get an object from an arraylist, then without assigning it to a variable, u perform operations to it
will the memory still keep the object in memory
if so for how long
my thought process is strip the color, turn it into a char[] (since each letter has a different color because of the gradient) and then translate the color of that letter to a hex color so §x§0§0§0§0§F§F -> #0000FF and then apply the color one by one, but i dont want to overlook an easier solution first lol
yes because it's reference and lasts until gc sees there are no more references
If you get it from an array it is already a variable tho
Yeah
I wouldn't worry about memory in java for a start unless you're using large amounts of data, then you should just worry about how much you're actually taking up
Also there is no real difference between assigning a variable and not assigning it
if the array list exist then it is already in memory. your operation is just pointing to the one that is already in memory rather than putting another copy of it in memory
You're still pushing the reference to the stack internally
Its the only thing I can think of…
Difference is if the reference persists in that method through the frame's locals
(Which it will if the variable is then used later on, e.g. loading it through ALOAD <index>)
So yeah no there is no real difference.
o
Could you say what are you trying to do with 8 mil blocks? Maybe there is a simpler way… just explain
its not my problem it's someone elses and he just dipped but im wondering how would u replace 8 million blocks
i learned java a couple months ago and it took months for me to understand pointers and such but if memory usage is a concern, i would try to get a good understanding of pointers (assuming you dont have one already)
The best performant way i can think of is by dividing them in 1.000 blocks sections and do them
simple answer is anything created inside of a block is dead when the block is exited
Cause by counting them one by one you are adding bytes to the for loop I guess
Not technically true, but it is a simple way to look at it.
So by making more you free some space
Technically blocks are just syntactic sugar.
basically true too though
Primitive values are bound to a method while the method is being executed.
gc will get it
wym
ic
alr
This is because they are either:
- Locals from the method's parameters (which are copied to the method on invocation by the JVM)
- Constants from the class's constant pool
from experience there are 2 ways to do this well, one, use FAWE's API. two, you have to do some math and split your operations between multiple ticks whilst tracking how long each tick is taking to keep the MSPT under 50. After messing with the second option and rewriting a lot of code a lot of times, i recommend option 1.
Meanwhile, references are cleaned by the GC, instead of just cleaning out the method's operand stack after execution.
for(int i = 0; i < 5; i++) {
int x = 2;
System.out.println(x);
}```
what happens to x and i @lavish hemlock
Uhh you mean for code or for servers?
what is your code
Faster to write or faster to read for minecraft?
you cant just ask your code to run faster generically, you have to optimize it piece by piece
get a faster cpu and faster memory - best generic way lol
x gets popped from the operand stack on the println invocation, and I'm pretty sure i's value is only ever used as a local that is loaded and stored at the start and end of the for statement.
while(true) will still make a memory leak even if u have ultra gaming cpu
Oh and actually x is likely an ICONST_2 instruction considering it is never used beyond the println
what happens to it when the for loop is done and the code goes on
There aren’t a lot of ways to boost performance, whatever you handle will count towards your performance. It doesn’t really change if you have an array or a list
Well they don't exist after the for loop because they were used (popped) by previous instructions.
Syntactically, they are bound to that scope.
Compiled, they are just values.
that's what I meant here
It's true on a language level but when it comes to how the program actually executes it's false.
FAWE Does a lot of calculations, for example if you have a plain 512x512 it will divide into smaller pieces to decrease the amount of data processed
it also doesnt rely on bukkit so it runs incredibly fast
Let's see...
well I'm coding in java and understand that the variables will quickly go away from memory after leaving a block
Yeah
Okay so immediately we have a constant of value 0 (this is the i = 0 assignment)
This is then stored and loaded because the compiler is shit
We push another constant of value 5 and compare it to the previous 0 (which we just loaded)
(i < 5)
A memory leak is when you have objects that don’t get deallocated. In Java, the garbage collector should automatically be handling that. If you want to write more performant code in general, I would start off with looking for places where you can lower computational complexity.
Push constant 2, that's the x = 2, which gets stored so we can shift its position around in the operand stack.
what are those numbers after getstatic
why do they not get deallocated
and invokevirtual
what happens to the variables and constants in the end
Uhhh we get System.out, load x again, invoke println and then increment i
Then we go back to pc 2 and do another comparison
Constant indices
I get that they're always marked alive, but how did they end up like that
That one points to a Fieldref
Which is a combination of a Class and NameAndType constant
In languages like C, you have to allocate the memory for your objects yourself. So you also have to take care of deallocating that memory. In Java, to allocate memory you just call new Object()
They disappear, they're not "cleaned."
why are they constant integers, couldnt the bytecode just contains fully qualified names and then the jvm can map them directly to memory addresses once the class is loaded
what is your meaning of "cleaned" here
and what makes them disappear?
They're not passed to the GC.
They disappear because the instructions in front of them use them.
O
why can't you use them anymore?
damn C must be literal pain
Well you could, actually.
There's no scoping.
You can just throw in a ILOAD to retrieve i or x again.
but what if if u dont have a variable of it, how to clean it from memory
If that's the only reference, maybe?
so a for loop with 10,000,000 iterations will leave 10,000,000 extra values in your memory until you exit the program?
Yeah that wouldn’t deallocate it early. I believe you can call garbage collector directly
Well the bytecode does actually store the qualified names.
what
They're stored as Utf8 constants which other constants refer to.
no, it increments one value on the stack taking up the size of one int (4 bytes)
btw pls ping me when u reply to my msg
do u mean System.gc()?
except if you make more
but any variables inside the loop are cleared from the stack per iteration i think
And stack memory is pretty different from heap memory.
Yes
"You can delete an object in Java by removing the reference to it by assigning null. After that, it will be automatically deleted by the Garbage Collector. You set it to null. Java doesn't give you the option to deallocate memory."
F
what if Object o = new Object() was in there?
and that's my point
Yeah but the GC doesn't take into account scope here
kinda sucks that that isnt a thing
lol
It just knows that, since nothing in the program has used that reference, it should clean the reference.
it would make stuff a lot faster, that developers can choose to manually manage memory if they want performance
i mean object = null; does the thing as google says
I think that'd be cool, yeah.
yeah
I mean... you simply dereference an Object.
But you'd struggle with the problem of "what happens to object"
?
Or do you mean that you want to manually free memory on the spot?
well we're using Java here so try to use a variable from a nested block
yeah
like a System.free(Object) or something
or even a System.finalize(Object) to force the gc to clean it
yeah like System.gc.collect(Object)
{
int x = 1;
}
System.out.println(x);```
or smth idk
Just never use managed memory :) @glossy venture Only ever Unsafe
This would fk with the garbage collector because the freed space could be anywhere.
Would pretty much decrease performance because all that out of order memory management
would be quite expensive.
lmfao yeah
best idea ever
Kind of semantics here. Basically the way garbage collector works is it looks for objects that don’t have any references to it. So by pointing the reference to null, the original object no longer has a reference which allows gc to pick it up
Object o = unsafe.allocateInstance(MyClass.class);
unsafe.invokeMethod("<init>", o, ...); // idk if this is an actual method
I should make a project that allows you to use Java as if it were a low-level language.
Also this is how in C you would get a memory leak. Since there is no GC
*If there is not another reference to that object somewhere.
But thats a part why strong encapsulation is important.
You probably can't do that.
which happens automatically even if you dont set it to null. right?
yeah i know
when you leave a block, consider the object dead, gone, left for gc to put it simply. so right
but with reflection you might be able to just call the <init> method
on an object
I don't think reflection allows you to do that unfortunately :p
bruh
Yeah exactly say when a method finishes, all of the local objects get cleaned
top 10 biggest bruh moments
If there were a way to inject an invokespecial though...
there is with asm right
a class has a block of code
i can close the class block of code and then access the var from another class
it will not get cleaned, will it
Y'know what I am totally gonna make the world's hackiest Java library
i wonder how hard it is to implement a System.free(Object)
yes please
if you create an object with the class, the variables are still there from within an object. public and static variables are accessible
A combination of Unsafe and classloading/ASM hacks >:)
It already exists. Its called Gson.
Look up how Gson instantiates classes that have no no-args constructor. Its funny.
Who needs it anyways
@glossy venture Quick, Orby, give me a name for a manual memory management Java lib
How about we leave the poor memory alone? The biggest benefit of java is that we dont have to worry about that.
like wouldnt it just be
public static native void free(Object obj);
JNIEXPORT void JNICALL Java_java_lang_System_free(JNIEnv *env, jobject obj) {
someMagicJvmDestroyObject(obj);
}
manmemman
yes
meman
memman
meman
maneman
yes
manenemaneman
Without finalizing the Objects? This will just crash everything that might point to anything inside that memory block.
manemanemanemamenamenamnamen
Well finalizers are deprecated now.
what are tips to make software more performing though
ok maybe call finalize too
even the least bits of performance is good for me
This is a pretty big question
And it really depends on your use case
Generally, multi threading and lowering computational complexity
just makes things as simple as possible tbh
i am currently looking through the jdk hotspot source to find the sacred someMagicJvmMethodToDestroyObject
alright and i also need
some thing like SOLID to learn
to make my projects more OOP styled ig?
Program alot. You will see that if you try to think about how to write cleaner code you will discover most of those principles by your own.
The SRP (Single Responsibility Principle) kind of leads to the rest. So focus on that first.
Can you copy a blocks persistentDataContainer and put it on a different item?
wait so @lavish hemlock in this code segment from one of my plugins,
Map<EntityType, Integer> entityMap = new HashMap<>();
for(Entity e : c.getEntities()) {
EntityType k = e.getType(); // k is EntityType in entityMap
if(entityMap.containsKey(k)) {
entityMap.put(k, entityMap.get(k) + 1); // Sets EntityType key to previous value +1
} else {
entityMap.put(k, 1); // Sets amount of EntityType to 1
}
}```
the variable k isn't actually created but e is just referenced 4 times? or would e only be referenced if there was only 1 reference to k?
Sure. But you cant just replace a pdc. You need to iterate over the keys and copy its content.
Yup, PDC is implemented the same for everything that supports it iirc
btw i should just make ur spigot profile bookmarked, literally a wikipedia tbh
Oh yeah so basically k is just the following:
INVOKEVIRTUAL Entity::getType
ASTORE <index>
oh that's cool, I didn't know
And actually that for loop there
Is just syntactic sugar
It compiles down to iterator access
So e comes from like iterator.next()
I am breaking your perception of Java, aren't I?
the way it works yeah
but not the way to write it or anhthing that like
like that*
((CreatureSpawner) blockA).getPersistentDataContainer().getKeys().forEach(key -> {
blockBMeta.getPersistentDataContainer().set(key, //what goes here);
});
I wonder how much of this I can convert to bytecode from memory
Write a utility method for that.
public static void copyContents(PersistentDataHolder donor, PersistentDataHolder receiver) {
}
Either way, still wouldn't know what to put in //what goes here
btw what do I do if i have some utility method like this for example, where do i store it
in a way that it doesnt break SRP
Hm i just realised that this is a bit tricky because you dont know the persistent data types of each entry. And they could be custom ones.
Yup exactly what I was struggling with
If the functionalities of the methods are stateless then a utility class with static methods only, is ok.
Basically no context stored between two method calls. If you have fields then you have a state.
new Copied(from, to).copy() you know
package me.cosmic.farmingpluginfordvddevroom;
import org.bukkit.plugin.java.JavaPlugin;
public final class Farming extends JavaPlugin {
@Override
public void onEnable() {
// Plugin startup logic
getConfig().addDefault("FarmLevelIncrement", 10);
getConfig().addDefault("PercentChanceOfGettingRewardOnBreakingCrops", 0.001);
getConfig().addDefault("Pools.Tier1Pool.FarmLevelMax", "200");
getConfig().addDefault("Pools.Tier1Pool.Rewards", "diamond");
getConfig().options().copyDefaults(true);
saveDefaultConfig();
}
}
```The config doesn't have any values. This is the class, there are no errors and the config is successfully created.
create a new config and try to add the values to that instead
saveDefaultConfig just writes your config.yml to disk. You need to call saveConfig() which will save the FileConfiguration you are currently editing to disk.
Let me explain my issue and see if you can help then, since I'm not sure where to go from here now. I having a plugin that stacks spawners (custom coded). When giving myself a spawner through essentialsx and stacking it, it works, however, when I try to break the spawner it drops the proper spawner. Then upon placement, instead of going to the correct spawner type it goes to a pig spawner.
I was just copying the block data but since essentialsx uses psd to store the spawner type there isn't much I can do without having access to the psd value
That works, can't believe I missed that. Thanks!
Ah i see. You could iterate through all primitive types for each key and copy them based on that.
Even custom types should be interpretable as their primitive raw data. Let me think of a quick impl of that.
yo smile, how would i serialize an array<itemstack> with this instead of just an itemstack?
the java parser implementation is 5000 lines and its somehow very readable
i severely misread the number lmao
??? = What I don't know, since it's a small code snippet.
Also some of the store/load indices are obviously gonna be off, but I tried my best.
new java/util/HashMap
invokespecial java/util/HashMap, <init>()V
astore 1
aload ???
invokevirtual ???, getEntities()Ljava/util/List;
invokevirtual java/util/List, iterator()Ljava/util/Iterator;
astore 2
aload 2
invokevirtual java/util/Iterator, hasNext()Z
if_icmpeq 0, /* SNIPPET END > */
invokevirtual Entity, getType()LEntityType;
astore 3
aload 1
aload 3
invokevirtual java/util/Map, containsKey(Ljava/lang/Object;)Z
if_icmpeq 0, /* ELSE BRANCH > */
aload 1
aload 3
dup2
invokevirtual java/util/Map, get(Ljava/lang/Object;)Ljava/lang/Object;
// I actually don't know if this is how the compiler auto-unboxes, but I assume so:
checkcast java/lang/Integer
invokevirtual java/lang/Integer, intValue()I
iconst 1
iadd
invokevirtual java/util/Map, put(Ljava/lang/Object;Ljava/lang/Object;)V
// > ELSE BRANCH
aload 1
aload 3
iconst 1
invokevirtual java/util/Map put(Ljava/lang/Object;Ljava/lang/Object;)V
// > SNIPPET END
That should be it ^
Ok, so I have implemented this into a class, but what do i do with the base64 data once i have it?
do i do .tojson
This is more verbose than needed
what happens if you remove the checkcast
Mismatched types
will it attempt to cast anything
Just realized I didn't cast anything else
So that is not the full method
But I do not care
but keeping k is better for performance as getType() doesnt have to get called, i actually think the compiler might optimize four e.getType() calls into a variable automatically but im not sure
In fact you'd probably get some kind of LinkageError
Try if this works
private static final List<PersistentDataType<?, ?>> types = new ArrayList<>(){{
add(PersistentDataType.TAG_CONTAINER_ARRAY);
add(PersistentDataType.TAG_CONTAINER);
add(PersistentDataType.STRING);
add(PersistentDataType.LONG_ARRAY);
add(PersistentDataType.INTEGER_ARRAY);
add(PersistentDataType.BYTE_ARRAY);
add(PersistentDataType.LONG);
add(PersistentDataType.DOUBLE);
add(PersistentDataType.INTEGER);
add(PersistentDataType.FLOAT);
add(PersistentDataType.SHORT);
add(PersistentDataType.BYTE);
}};
@SuppressWarnings("unchecked")
public static void copyContents(PersistentDataHolder donor, PersistentDataHolder receiver) {
Preconditions.checkArgument(donor != null && receiver != null);
PersistentDataContainer donorContainer = donor.getPersistentDataContainer();
PersistentDataContainer receiverContainer = receiver.getPersistentDataContainer();
for (NamespacedKey key : donorContainer.getKeys()) {
for (PersistentDataType<?, ?> type : types) {
if (donorContainer.has(key, type)) {
receiverContainer.set(key, type.getClass().cast(type), Objects.requireNonNull(donorContainer.get(key, type)));
}
}
}
}
If not you need to switch-case your way through the keys
maow human compiler
i meant an arraylist, i thought that and arrays were the same thing
Indeed.
They aren’t, but you can convert an ArrayList to an array trivially
Java was not a language meant to be hand-compiled, though.
lets say i have map:
Map<Integer, ItemStack> map = new HashMap<>();
is there any way to get this class object safely without generic warnings?
by using .getClass() is get Class<capture ? extends Map>, and in order to get Class<Map<Integer, Object>>, i need to cast it, but that prompts me as a warning that the variable is not safe to cast
Perhaps with a decent assembler, stuff like Jasmin could've kicked off :p
ik that now but idk what trivially is
An array list is just an array in the end
Easily
but i cant use .add
which i need
?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.
generics
List<ItemStack> itemList = ...;
ItemStack[] array = itemList.toArray(new ItemStack[0]);
This is something you should duckduckgo (google)
alright
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
``` anyone know what this means when i try to build
ok
Wdym?
It does 3 specific things
Checks if the key is in the map, if it is then add 1 to the key’s value
Other wise add the key with a value of 1
Map<EntityType, Integer> entityMap = new HashMap<>();
Arrays.stream(c.getEntities()).forEach(e -> entityMap.compute(e.getType(), (k, v) -> v == null ? 1 : v + 1));```
Without a stream?
for (Entity entity : c.getEntities()) {
entityMap.compute(entity.getType(), (k, v) -> v == null ? 1 : v + 1);
}```
I think it’s quicker to understand a simple if else tbh
Map<EntityType, Integer> entityMap = new HashMap<>();
c.getEntities().stream().map(Entity::getType).forEach(type -> entityMap.compute(type, (k, v) -> v == null ? 1 : v + 1));
sniped -.-
Anyone can help?
Well if you want to fork it and replace it then go ahead but personally I think the if else is easier to understand
for (Entity entity : c.getEntities()) {
EntityType type = entity.getType()
entityMap.put(type, entityMap.containsKey(type) ? entityMap.get(type) + 1 : 1);
}```
But that's gonna be much slower than compute
Since compute only needs to do one hash operation and one lookup, it should be a bit faster than the other methods which involve performing multiple lookups on the map
I mean... "much slower". We are still speaking of O(1) ops here.
Noticed that ^^
...
Map<EntityType, Integer> entityMap = new EnumMap<>(EntityType.class);
Arrays.stream(c.getEntities()).forEach(e -> entityMap.compute(e.getType(), (k, v) -> v == null ? 1 : v + 1));```
Slightly faster 🔥
compute is way much cleaner and better in some cases
at least for me
especially for creating new objects
I mean I guess you shouldn't use a stream if you want the fastest but still
that are not existant in the map
btw dont check if it contains k, just entityMap.put(k, Optional.ofNullable(entityMap.get(k).orElse(0) + 1));
I think that's faster, right?
Nothing else you can do besides carefully reading the article, looking at a chunk with an nbt explorer and reverse engineering your way through it.
what redempt and others said is faster either way but yes
its way better to use computeIfAbsent(key, (key) -> new RandomObject()) than putIfAbsent(key, new RandomObject()) since the argument init in the first case would be lazy (it wouldnt create a new object if the key already present in the map)
but I've heard that using streams in hot loops can be bad, so if you use stream in loops often it can become slower than a normal loop
I get it, it's not a trivial task, блять :(
Been there. In 1.15 i had the task to send completely fabricated chunk packets async. Took me a while to figure out how the format works.
And dont get me started on lighting the chunks afterwards...
that's actually the case due to everhead the stream api adds up
but for example you can do parallel streams which could be faster than for loops
since it utilise parallelism internally
Yo! Is this the channel where I can ask for help with coding problems??? 🙂
another thing to search "parallel streams" tysm
Which decreases performance even more unless you have a gigantic amount of data.
And im speaking of expensive operations on several 100k objects.
Can you share a code example? it will be easier than dealing with the format from scratch
o
i wanted to add up to that but you were faster
Yes
does onDisable get ran on /reload?
Yes
yes
Sry but i cant share code from that project
ill keep u updated
Yay! Awesome :3 I'll start asking a way then. :>
😩
wiki.vg has documentation and example implementations available
It's a good start
Agreed
Hi i have a question, you are the one that used to work on Skript plugin?
hehe i used to write skripts 2 years ago
i jumped on java since then
i swear you saw my old posts on skunity
Thanks 😅
So, if anyone can help me with like ehm, a bunch of things! First of all, I just started to learn to do coding with Java. So everything is new. But I've managed to setup the foundation of a Spigot plugin. That when I click run from IntelliJ. It completes perfectly.
But anyway, basically I would like to know now how do I make a loading screen? Is it possible? So I created a class under src > main > ehm I forget the rest after that. But it's how it should be. Down the line I created a class called 'Startup Loading Screen'.
Now I just gotta put in some code to get it running. To be clear, I wouldn't want anyone to write me code. Although I would love that. But I would rather learn like the building blocks for it. So what exactly is that Spigot page on the web where it lists all of these Classes, Tree, etc. All Bukkit things. That's the API, I know that much. But what do I use that for? What exactly is an API? Is it syntax that falls under Java syntax? Like a made up language that Spigot uses to make it easier for people to code with Spigot? Or is it something else?
Sorry about the long post. Just very new is all. I would really like to know if I can use that site to understand how to make some code for the 'loading screen'.
Okay I'll stop typing now 😛
😄
i literally used java's packages inside skript back then
what exactly do you mean by a loading screen?
as in like a black screen when the player joins or something?
Oh like, I would like to just place a blank black screen when loading up the majority of things in my server :)))
And yeah a loading . . . thing also would be nice 😛
Minecraft is not a game engine remember that, you need to be creative to do these sorts of things
i would suggest you to build a room inside your server filled with itemframes with a white background
and teleporting player there
or just use end dimension blocks or end dimension itself
as a background
Hey, i'm trying to compile a plugin with WorldGuard as a dependency. But it doesn't compile:
cannot access com.sk89q.worldguard.WorldGuard
pom.xml:
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.6</version>
<scope>provided</scope>
</dependency>
1.12.2 btw
How are you compiling
Maven install
do package
Install works fine
Package doesn't work to
Did you add the worldguard jar besides just adding it as a dependency in your pom.xml?
No
I'll look into that.
Is there a way to manipulate the default minecraft loading screen though? Like get into its source code and stuff and tweak it to use another image? Or would that be only for Forge mods and stuff to do that??? I don't know how limiting Spigot is. That's why was wondering about the API thing that Spigot links where it has all this information about all the different things the API does :>
loading screen cannot be changed via server unless it's a resource pack
Bugger D:
that's client sided thing
but I don't think the loading screen will even show
since when you disconnect it unloads it
you cant modify that unless you prompt players to download your own resource pack
then you can have some wizardry of customizability
Oh dam dam dam XD Trying to make it that the client doesn't have to download anything :S
well server allows you to send resource pack to players
client is going to have to download something, otherwise how will it know 🙂
all they need to do is to click allow
whenever they join a server
^ nice resolution google
loving it
Yeah I'm gonna make a resource pack then. 😛 I'll Google on how to and stuff. Thank you all for the help! I'll ask away later on if I'm having trouble again 🙂
but you can do it without that, but it would be limited loading screen
you cant do that stuff as flexible as resource packs can be
So basically Spigot is server side only. This means things are limited. For example you cannot change rendering, add custom blocks and items. You can however use resourcepacks to simulate more items and blocks by using model data and unused block states.
If you're new I suggest starting with something easy and work your way up. I've seen too many people try to do advanced things right away and get stuck.
Do you have other dependencies that also depend on worldguard and might use an older version?
With a resource pack, can I change the HUD, etc? Like creating bars and stuff around the screen or do anything basically, visually????
Only with a lot of trickery. What you can access is the standard UI of minecraft. Actionbars, Health, food, bossbars etc
I'm trying to do that. I just need to know where I can find the library of coding terms and stuff for Spigot. Then I can read about what each one does and stuff. Which would be very cool. Cause then I know the fundamentals of what a certain coding word does 🙂
Minecraft is a sandbox game, you need to creative to be play it and modify it to your needs
?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.
Maybe
depend: [ KingdomCraft, ProtocolLib, WorldGuard ] #KingdomCraft uses WorldGuard
Should i try to use the version of KingdomCraft's Worldguard?
?jd-s
Im speaking of maven dependencies not runtime ones
Basically paste your whole pom
this turned:
Map<Player, List<Pair<Integer, Pair<ItemStack, ObjectDataFile<List<ItemStack>>>>>>
into:
Map<Player, InventoryDataStorage>
how great
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.
Okay just oooonnnneeee last little thing? What exactly is an API???? I've tried reading into it. But it doesn't make much sense for my brain XD Is it an additional language thing used, to make coding/programming easier for the person writing code????
any ideas smile?
Basically a bunch of classes and methods that are designed to be used by others in their projects
shouldn't the capture of ? be Z?
Order of dependencies matter a bit. But spigot at first and wg at last.
Okay now it's making more sense! Okay I'll stop with the questions now 😛 Thank you
Lets say you have a car, you have crucial components like engine, and you have a car salon (radio, wheel, hand brakes), API is literally that. it allows you to safely tinker with the "engine", without thinking too much about its technical characteristics
Engine makes your car drive, but wheel makes your car drive wherever you want
Keep asking questions it's a good way to learn :) also my DMs are open if you need me
logic folks is this going to work how it sounds https://paste.md-5.net/uhabemoyis.cs
or perhaps a better way to compare them
Still doesn't work
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.
also how would i override hashcode with this
equals must be implemented so that x.equals(y) == y.equals(x)
Sou you have a bit of double checking in there
If you're using Intellij you can use ALT + Insert to let it generate equals and hashcode :)
it generated this public int hashCode() { return Objects.hash(f1, f2); } but i want them to be equal even if the 2 factions exist in the different variable
unordered
maybe i could use a unordered set
i've never implemented equals() before, but i think if (o == null || getClass() != o.getClass()) return false; could be replaced with if (!(object instanceof Alliance)) return false; since instanceof allows you to check for null values and the class type at the same time, and you're casting to Alliance object after the comparison, it would fail if the classes would be different than the Alliance
They return if the classes are different, so it’ll never get to the cast
still one clause vs two
But there’s no error possible
Which is an important distinction
yes, it wouldnt fail because its checking the same class type its overriding
but i think the second version is a bit, BIT faster
I mean it’s doing the same thing under the hood
You’re not bypassing the null check
I basically am just trying to make an unordered pair
but by using instanceof you can prevent errors due to how instanceof is checked at compile time
but this is not important here
You could base the order of the hashcode on the order of the elements when sorted
true
I think instead of 2 variables i will just have a set
and make sure it only has 2 values
That’s overkill if you’re using a fixed 2 elements
You’re better off using 2 fields like you are currently
i wish java had a data type for this
I dont... What do you need that for?
That just sounds like you should use Sets. Those are basically unordered bags.
Sets are for many elements, it’s a waste if you’re only ever gonna have two
Right but a set with only 2 elements. an "UnorderedPair" we can call it
def should be a thing
Map.Entry
lol
If they're the same type then you could use an array size 2
If they're not you could use a record
That’s ordered
Okay why do they specifically need to be unordered
They’re saying they want an object such that (a, b) = (b, a)
Then store it in an array size 2 and sort on creation
So... a Set
Because it’s not going into what instanceof is doing
Lol
Instanceof has to get broken down into those steps eventually
Yes, but without the additional set memory and overhead presumably
What’s the overhead?
Creating the set and the backing hashmap with its buckets
yes , but its broken down by jvm internally since its a separate bytecode operation rather by multiple bytecode operations
which should be in theory still cheaper
At that point it’s basically a micro optimization though
i know
i was just curious if i was right
lol
i still might be wrong tho
it depends on jvm
Using Class == Class odes not yield the same result as instanceof. You should
always use instanceof in equality checks.
Ok well I guess im just gonna use a Set
Disregarding the performance.
That’s true, assuming you want to support inheritance
I honestly smell xy
Yeah i think its coming from the other room
Ok well ill go way back then to the main problem
got a factions plugin. i keep a list of factions and a map of players that are in factions and their faction
want to make alliances and heres where im at https://paste.md-5.net/baxidihuro.java
bad design?
Hy
And here is how I check for legal actions https://paste.md-5.net/ezedevobus.cs
which is the main thing alliances pertain to
If it’s always just two factions, you could just have two class variables faction1 and faction2
This is the typical problem you also get when doing friendlists for example.
Who is in charge of handling this cross reference data.
And as alex stated: A graph is the perfect tool for relationships of that type.
Each node represent a faction.
Whatever I do, I just cannot get an instance of another plugin [10:05:14] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to PlotsForRanks v0.8-SNAPSHOT java.lang.ClassCastException: class sh.okx.rankup.RankupPlugin cannot be cast to class sh.okx.rankup.RankupPlugin (sh.okx.rankup.RankupPlugin is in unnamed module of loader 'Rankup-3.13.2.jar' @69b4a744; sh.okx.rankup.RankupPlugin is in unnamed module of loader 'plotsForRanks-0.8-SNAPSHOT.jar' @f83dd35) at me.grovre.plotsforranks.PlotsForRanks.getRankupPlugin(PlotsForRanks.java:41) ~[plotsForRanks-0.8-SNAPSHOT.jar:?]
and it's come to the point it's telling me this
public static RankupPlugin getRankupPlugin() {
return (RankupPlugin) getPlugin().getServer().getPluginManager().getPlugin("Rankup");
}```
Because you shade the other plugin in. Dont do that. scope -> provided
scope -> provided?
I use maven
Show your pom dpendencies
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.palmergames.bukkit.towny</groupId>
<artifactId>towny</artifactId>
<version>0.97.5.15</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>okx-code</groupId>
<artifactId>Rankup3</artifactId>
<version>3</version>
</dependency>
</dependencies>
Rankup3 needs to have a "provided" scope
what do you mean by that?
Look at your other dependencies
Items dissapear like after 2 minutes on ground
I don't have clearlag or any plugin for that
they jsut dissapear quicker than usual
how do I changed the it to 10 minutes on like paper cause I guess thats what it is
does anyone have the link for the guide spigot forum i remember it but cant seem to find it now
what the
heck is wrong with towny
0.97.5.15
lmao
It’s the version a server uses for some reason
But it should work with. Erosions moving forward
Versions
It just listens for players joining, joining towns, leaving towns, and ranking up
And adds bonus blocks based on what happens
how could i check if player is holding fishing rod in left or right hand?
Check both hands for Material.FISHING_ROD
not working
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
if(p.getInventory().getItemInMainHand().equals(Material.FISHING_ROD)) {
fortune = (p.getInventory().getItemInMainHand().getItemMeta()).getEnchantLevel(Enchantment.LUCK);
}
when i'm using Material.etc it's just skipping the code
.
p.getInventory().getItemInMainHand().equals(Material.FISHING_ROD) -> p.getInventory().getItemInMainHand().getType().equals(Material.FISHING_ROD)
Technically you should also switch .equals to ==
But it’s not the end of the world
Does anybody know a plugin were I can have a tellraw/broadcast being sent in chat for everybody every 10 minutes?
For instance having "Join our discord blabla"
Google your question before asking it:
https://www.google.com/
I just dont know what to search for
I did that i just got a thread of someone wanting to make a plugin like that
Sending me google isn't gonna help when I literally asked if you knew a plugin
#help-server this is help-development we are assuming your making the plugin lol.
Spigot auto broadcast plugin
prob works
doesn't essentials have something like that
ye thx
this is a big plugin, but it has lots of server management stuff. It allows scheduling broadcasts etc. If your looking for tons of tiny stuff this might be the way to go as you can disable modules. I've used it for a while now its pretty nice
https://www.spigotmc.org/resources/servertools-➜-modular-server-management-1-8-1-18-1-open-source.95853/updates
Only tried CMI, paid but works
That’s very overkill for an auto broadcast
Can replace essentials itself
he's been asking about a lot of small stuff recently so I thought I'd send something over
almost guarantee you there's one called "autobroadcast"
lol
Man I shoulda put money on that shit. First result.
https://www.spigotmc.org/resources/autobroadcast.69377/
Apparently you have to use mini-message formatting
How can I add a custom texture to my SkullMeta?
Version?
1.18
Update spigot
I'm using paper
Talk to paper then
alr
im using stone
Does anybody know a plugin that let's me run a command when're at a specific coordinate
lets log to the console whenever a player moves
Okay
There is no music that allows for regional music with music discs. So I'm trying to do
/playsound minecraft:music_disc.otherside music <p>
whenever you enter a store, and when u leave it will do /stopsound <p>
@young knoll
playsound <sound> <source> <targets> [<pos>] [<volume>] [<pitch>] [<minVolume>]
how would I skip a string?
after <sound> <source> <targets>
I just want to put in volume
so how would I skip "pos"
cause it wants me to fill in pos
as for the next stream after target obviously
I don’t know if you can
Maybe just do ~ ~ ~
I think a sound needs to have a location
So, not sure if I am dumb or something. But I am new to plugin development and want to make a plugin where the player goes like "/show add firework [type] [color] [effect]" I think I know how to do that part but right now I am trying to work on grabbing the players location and writing it down on some document so that the plugin can go back later and grab that data. However I cant seem to find a proper way of grabbing a players location (using coordinates) or finding a way of putting that on some sort of document (preferably txt) if you know of any tutorials or know of a way of doing this help is appreciated.
for some reason there is no ".setOwnerProfile()"
Every class should be final class right? If not people will be able to extend the class
You know you can just set location directly
you can directly save the loation with: cfg.set("location". loc);
I'm using spigot now. But how can I update it with IntelliJ? (Sorry I'm new too)
Wait what?
Maven or gradle?
Did someone answer my question? I saw a ping but dont see me being pinged here.
earlier I was using aper
*paper
I tried but it was shit what I said, sorry
For developing on spigot you have the ?jd
Which is your problem? I will try to help you
this is it
lol, you good.
What your inssue?
go to the reply of this reply
I just gave him the code of my /spawn plugin. But it was not what he wants
Your idea for saving its the worst. You should save data on yaml or json files
How would I write to a yaml? Didn't think about that.
Spigots config API can handle location directly
But can it call back on that location at a later date if a user leaves that location.
Yes
So how would you store that?
You can use* my own FileHandler, its based on Spigot ones. And it make really easy the usage/managment of yaml files
Okay. And how can I update it now? With IDEA IntelliJ?
YanlConfiguration#set(“key”, location)
I help him dont worry
I will sent you a class, please add it to your project
And then i explain how it works
You made one or the name is "FileHandler"?
I make a FileHandler, called FileHandler
Gotcha.
Itself its a FileHandler, because it help you to manage files
New to this all. First day coding so the overall goal is to make a show plugin that can syncronize things to openaudioMC but I am working on each individual command one at a time.
If you are new* i straigth recommend a lot learning about the SpigotAPI and Java API
literally just make a FileConfiguration and tell it to add a new key with the location, then call the save function on it
?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.
no need for this extra class
It takes like, 5 lines to do it with the existing API
I know but if you wanna manage multiple Files, for me it a mess. That why i use my own FileHandler
This would be great if it was set in stone but I want the thing to be able to make a file on the spot so players can create shows in game.
Clearly that’s way too many
?afk eating
Yea if you could send it to me and explain it I would be greatful.
Allright i will be eating, prob im back in 10-15m
?jd
Go ahead
ty
So I guess when he gets back from AFK he will send me it or do I need someone else to help me with this?
I mean
Just create a file with the Java API, and then use YamlConfiguration.loadConfiguration(file)
Can the plugin create it based off an arg a player said in chat or do I have to make that manually?
I want each show to haves its own file.
Sure why not
How would I go about doing that?
So if a player runs a command like "/show create [arg1]"
then java will create a file with the name of the arg1 with what I tell it to put in the file?
Mhm
Sweet. Thanks. My dad is a java developer and luckily works from home and being home schooled I can easily get him to help me with java API.
@young knoll second thing, how can I store the coordinates of a player in this file? I want the players coords and not spigot stuff. Any way of doing that?
Like how do you get player coords.
So many spigot documentation to go through and when I search "coordinates" can't find anything.
Player.getLocation
Will that give all the x, y, and z, or do I need to specifically do "Player.getY()" "Player.getX()" "Player.getZ()"
It will give X Y Z pitch yaw and world
?jd
