#dev-general
1 messages · Page 160 of 1
imo it's one of those symbols where unless you know the language, it's not really clear what it does
primarily functional
could be procedural too though
and kind of pseudo-oop as well
hmm someone said
Kotlin is only good if you intend on using it for android dev. Aside from that it doesn't give much benefit.
wrong
well tell that to him he says thats the only benefit
¯\_(ツ)_/¯
Clearly a smoother brain 
Anyone have any idea what would cause an IOException when creating a file for a single person? My plugin works for me and others that I know use it but there is this one person who seems to get an IOException and I have no idea what would cause it.
depends what the exception message is?
Well I currently don't know I cant recreate the exception and only one person out of the many who use my plugin have the issue. Could it be possible that the plugin does not have permission to create the file?
possibly
does it always happen for that person?
and nobody else?
oh you mean 1 user of the plugin
not 1 player
it's really hard to say, possibly
get them to send the exception?

Is there anything in the Spigot API you guys don't like or think could be simplified/shouldn't need NMS? for ASF, I already asked on Reddit and that flopped, don't buuly
There should be ways to unregister for events at runtime
There already are, aren't there? HandlerList.unregisterAll(yourListener) works for me, or someEvent.handlers.unregister(yourListener)
Holy fuck. This helps soo fucking much
lol
Any suggestions on how someone would improve their documentation/over all information when it comes to commits and such? Does anyone have any informative templates?
Keep it clean concise and informative
I mean yea but how
Keep it clean concise and informative
xD
oooo custom entities and pathfinding
pretty much
things simplified from 1.9
but 1.8 is so annoying
Literally need packets for everything
Well, I'd be building off of 1.16, but if you have 1.8 code for it you can submit an issue/pr and I'll add it
I can't bother anymore
I'm already working o n my own server impl
Screw spigot
or mc server code
¯_(ツ)_/¯
Does looping through constructors also include super class constructors?
Using reflections
reflections or reflection?
just they're very different things lol
and no I don't think so
since superclass constructors usually aren't applicable to their subclasses
cmdManager.parameterHandler.register(Entity::class.java) { argument ->
// Gets the entity from the UUID
val entity = Bukkit.getEntity(UUID.fromString(java.lang.String.valueOf(argument)))
?: return@register TypeResult(argument)
// Checks if the entity is null or not and returns only the argument used
TypeResult(entity, argument)
}``` this is how it gets automatically get converted by IIJ
Yeah it's better here xD
the default example
so I have the same list of strings. How would I make them into a parameter type?
I don't think you can make a List of strings a parameter type, since the argument will always be just one
Yo guys is it better practice to name Player player; rather than Player p;?
I name it player myself Fresh but I saw a lot of people using p for player and e for event. I just go for the long names xD
You'd probably just use String, since you'll be getting one value from the List
Descriptive variable names are always better
also I know this from my teacher so yeah
I think it's more readable and moree descriptivbe
yea
Yo why do i get error when I name a variable class or inferface?
String interface;
String class;
Because those are used keywords
keywords that was the word I was looking for xD
so I cant have a variable named class or interface?
Nope
Is it true that it would be safer to assume -> is a constructor rather than a method because it has capital? Hello()
helloder() <- that would be method right?
Yes, classes will always be upper camel case while methods lower camel case
^ nOoB DEvS saY nO
"Professional " announce yourself as that when you make a living wage from it
You should always assume that, if you're wrong, remove what ever api you're using xD
And make a pr to fix it
yo i dont get this...
int m = 4;
int n = 5;
m = n++;
//n++ // n = n + 1,
System.out.println(m);``` Why is it returning 5? But when I do ++n, I know its post and pre increement but I just dont see n++ the value of m being 5. shouldnt it be 6?
Basically it'll run like this:
m = n++;
m = n;
n += 1;
So m = 5
Which was the value of n when it was assigned to m
so n will be 6?
Yeah n will be 6 and m 5
is it beetter to have say (n+2==1) or to have (n + 2 == 1)?
Second imo, but that's more of preference
What would you call == basicaly? Would you call it same? Like 1 == 1, one is same as one?
Yo why does this keep printing hello infinitely on my end
for (int i=0;i<5;i++) {
System.out.println("Hello");
}
int i=1;
while(i<=5) {
System.out.println("Hello");
}```
Because you never increase i
OHH lol true
In the second loop
Yea
Qucikq uestion ok so
for (int i=0;i<5;i++) {
System.out.println("Hello");
}
int i=1;
while(i<=5) {
System.out.println("Hello");
i++;
}```
In taht code, do the i's not interfere?
both variables are named the same
shouldn't it mess anything up?
no
The first variable is only inside the scope of the for loop
So when you're outside the loop, i doesn't exist
Oh
The next one would if you were doing anything afterwards
if u want the loop to be constant until a condition changes
Yeah
For loops are better for predefined ranges
Eg looping over every item in a list
While loops are better for dynamic ranges
dynamic ranges?
Think of repeating code until a condition is met
is good imo
yea repeating the code until condition is met. isn't that the same with For loop?
u could have it loop twice, or a thousand times
Yeah
For loop just loops through variables
While loop executes code while the boolean is true
yeah for just loops thru known things
for loops also have to define a variable
like variables, ranges etc.
That'll loop forever
than just what for can do
Which one is better?
while(true)
for(;;)
None tbh xD
matt lol
Sometimes you need while trues
wtf is for(;;)?
defines no variable, checks no condition and changes no value
probably an infinite loop
Basically an infinite loop
o wow
in that case while
A lot of the times that you need while true, you probably can find a better way to do it
SO you dont need a variable for a forloop?
@ocean quartz How would you do this better
🥴
A lot of the times
SO BASICALLY use While loop when you have a true or false thing/loop that you wanna do?
Probably
This is just my minecraft server impl
Most likely, for the ticking
handshake is fun
rather a for a loop but, you can do that with a for loop as well right?
handshake is fun
@quiet sierra no it isn't
It's part of handshake
The real fun begins after handshake
sending all map packets
Why would you use a do while loop
clean code I guess
Just to hav ea condition run at least once?
Do while loop <-
Same
I already want to die
Kinda crashes my client
gross
Although that makes sense
Considering the wiki.vg docs aren't updated for 1.16 yet lol
Unless I was doing something wrong
When you say you're on X at the moment, are y'all following some course?
const log = console.log;
I can access any variables in a method if that method is in INSIDe the class right?
Yo why can't I do this?
class Calc {
int num1;
int num2;
int result;
public void perform() {
result = num1 + num2;
}
}
public class FirstCode {
int hello;
public static void main(String args[]) {
Calc obj = new Calc(); // The new Calc() is the object.
obj.num1 = 3;
obj.num2 = 5;
obj.perform();
System.out.println(obj.perform().result);
}
why cant I do printline of obj.perform().result?
i dont think u can access result variable
instead, i would recommend returning num1 + num2, then itll print out
System.out.println(obj.result);
works but
I am wondering why you cant do obj.perform().result
Ah is it cus of return type?
Because that method doesn't return anything
yes
If you returned Calc then yeah
System.out.println(obj.result);
works but
@viscid charm this works because its declared outside of the method
u wouldnt be able to access the variable inside the method
hence why it should be returned instead
int result; <- this is what you mean by "declared outside" right?
Also what do you mean hence why it should be returned instead? @onyx loom
int result; <- this is what you mean by "declared outside" right?
yes, that is outside of the perform() method
Also what do you mean hence why it should be returned instead?
something like
public int perform() {
return num1 + num2;
}```
and then just print `System.out.println(obj.perform()`
yup
🙂
but can you do
println(obj.perform().result;?
IF you declare result in there?
like int result;?
i highly doubt it
AH so you can't really GO inside a method which is returning something
Oh rip you cant go inside a method period
ya
when u call a method all u are mainly doing is returning something or returning nothing (void) as such, there is no need to access the contents of the method itself, but rather the end result of the method
if that makes sense
not really
y shud one declare varialbes INSIDE a method?
ASSUMIGN they arent constant
you won't be able to access it
u should aim to have variables inside methods (and then pass the variables in parameters when needed) where possible, afaik it saves more resources
someone can correct me on stuff that im saying, im not very good myself 😅
o rip
OK WATHA BOUT THIS question
Also qucik question about constructors. What if you create a constructor but add a VOID return type to it. Does it just make it a method now? Or wat happens? Or even if you make it a return type.
example?
class Calc {
int num1;
int num2;
int result;
public Calc() {
num1 = 5;
num2 = 2;
}
public void Calc() {
}
}
public class FirstCode {
public static void main(String args[]) {
Calc obj = new Calc(); // The new Calc() is the object.
System.out.println(obj.num1);
}
}```
See the public void Calc() {} <- ?
thats not a constructor?
oh because of the naming?
yea
shouldnt do
to access it it would just be obj.Calc() probably
and ur accessing ||(insert better word here, ur not really accessing it rn) || the constructor when initalising the class
yea hmm ok
So to like communicate with a class
you must intilias the class using the constructor of that class
right?
If your in another class that is.
And once you do that you can technically access or use any of the methods INSIDe that class in a different class where you initilized that class? right?
Class Calc {
int num1;
public Calc(int number1) {
number1 = num1;```
Whats better to do? number1 = num1; or num1 = number1;? I know it means the same thing but what do you guys prefer and if theres conventional way?
Also would num1 be considered local?
class Calc {
int num1;
int num2;
int result;
public Calc(int number1) {
number1 = num1;
System.out.println("Hello");
}
}
public class FirstCode {
public static void main(String args[]) {
Calc obj = new Calc(1); // The new Calc() is the object.
}
}
btw you can use kotlin markdown, it's a thing apparently
nhmber1 is a local variable, not num1
anyway, by default they are private but it has getters
iirc
so it seems like it is public but kotlin actually generates getters for you
if number1 is a local variable which it is, WHAT would be call num1? Some say instance variable
BUT what if I didn't create new Calc(1);
would it still be called instance variable?
is public Calc(int number1) supposed to be a constructor?
Yes any variable defined without static keyword and not in a method is an instance variable
Or constructor
wait are you able to create constructors like that hmm
I thought you had to define it in the class xyz
and use init
yeah this code is invalid I think
what code/
Also would num1 be considered local?
class Calc {
int num1;
int num2;
int result;
public Calc(int number1) {
number1 = num1;
System.out.println("Hello");
}
}
public class FirstCode {
String helloder;
public static void main(String args[]) {
Calc obj = new Calc(1); // The new Calc() is the object.
}
}
wait nvm
Yeah
number1 is a parameter, num1 is a field
anyway you might want to specify private for all those values
java convention is using getters and setters and not changing it by defining it public (I think?)
haven't gotten to that yet
Is it bad to have this. FOR all fields taht your mention or instance variables inside your methods whilst assignign them to the local variable or parameter?
like
public Casio(int i) {
this.num1 = i;```
as in is it bad to have just variables around in the class?
I didn't need to add this <-. num1 is instance variable/field btw.
No like
public Casio(int i) {
num1 = i;``` VS
```JAVA
public Casio(int i) {
this.num1 = i;```
"this." is not needed in this case unless its this.i = i;
yeah
Yea so would using this. be bad convention?
using this or defining variables that belongs to the class/object?
I'll show an example
using this
this is just more explicit
if it seems clearer, you can use it
but if you can understand what you are changing without calling this there is no use I guess
Hm I see, if it helps you see that it's OUTISDE of that method
I see what u mean
But someone whos experienced would definately not use this because they already know its outside. and this should generally be only used if they are the same named variables
not definitely, but they have the choice not to use it
this is one of those conventions no one really cares about (I think?)
but try to keep it consistent throughout your project
does that answer your question?
What do most people use?
Some people use this some people don't
I mean like majority
like if they use this as a majority
it would make more sense to use this EVEN if you dont need it because more people can understand ur code better
this might help if your constructor has loads of variable, maybe you are doing some calculations or something in it
it is more project-dependent than anything else
if you want, you can check out some examples on github and see how people use then
I hope that answers your question?
static just means the method/variables will belong the the class, not the object
so you don't need to instantiate it by calling the constructor
you call the method directly to the class
you don't call it on an instance of that class
Hmm you said u dont need to instantiate by claling constructor OK so
class Emp {
int eid;
int salary;
static String ceo;
public static void shtatic() {
System.out.println("Static");
}
public void nonStatic() {
System.out.println("Not Static");
}
}
public class StaticDemo {
public static void main(String args[]) {
Emp.shtatic();
Emp.nonStatic();
}
}```
AHH so the Emp.nonStatic(); won't work without calling the constructor and creating an object
So i'd need to add:
Emp obj = new Emp();
obj.nonStatic();```
I have heard static abuse. What does that mean btw? Are static's bad? Isn't it good that you don't need to create "new EMP();" because wouldn't that take up more space/
don't worry about it taking up more space
wait so you can't access non static variables in a static method correct? Theres no OTHERT way other then to make the varaible static to access that variable?
static's aren't bad, it's just recommended you avoid them till you fully understand how they work
public class StaticDemo {
int i = 0;
public static void main(String args[]) {
i = 1;
Emp.shtatic();
Emp obj = new Emp();
obj.nonStatic();
}
}
Like that
yeah that wouldn't work
new StaticDemo().i = 1;
public class StaticDemo {
int i = 0;
public static void main(String args[]) {
i = 1;
}
}```
but obviously that only changes i for the instance of StaticDemo you just created
Oh like this
public class StaticDemo {
int i = 0;
public static void main(String args[]) {
StaticDemo satatic = new StaticDemo();
satatic.i = 1;
}
}```
yes
that'd change the value of i for the instance of staticdemo you're creating
if you created another instance of staticdemo, i would be 0, whereas your old instance would still be 1
oh btw, in our conversation the other day, I mentioned ids
technically java does have ids, but they're obviously not numbers
1 - 3
they are numbers, just not like that, they called hashcodes
wait so
if its static
i create another method
and make i = 1;
i will be even in other methods
is what ur saying right?
just write the code out
public class StaticDemo {
static int i = 0;
public static void main(String args[]) {
StaticDemo satatic = new StaticDemo();
satatic.i = 1;
}
}
would thsi work?
oh thanks.
Thats just a guess tho
I see what u mean @quiet depot
public class StaticDemo {
int i = 0;
public void show() {
System.out.println(i);
}
public static void main(String args[]) {
StaticDemo obj = new StaticDemo();
obj.show();
obj.i = 0;
obj.show();
}
}
where as if it was static and you changed it inside the method it would actually be 1
Yo i don't get the obj.new concept
Outer obj = new Outer();
Outer.Inner obj1 = obj.new Inner();```
new Outer.Inner();
What does new exactly mean?
I get that Outer is the class reference, obj is name of the reference, i dont get what NEW means. but I get Outer() is the constructor.
new literally just means construct a new instance
new allows you to call a constructor
to get an instance
ok then what is obj.new?
that's not valid java
Outer.Inner obj1 = obj.new Inner(); this is not valid java
public class StaticDemo {
//variables, methods, class
public static void main(String args[]) {
Outer obj = new Outer();
Outer.Inner obj1 = obj.new Inner(); // Outer.Inner obj1 = new Outer.Inner();
obj1.display();
}
}```
It works for me
class Outer {
class Inner {
Inner() {
}
public void display() {
System.out.println("In Display");
}
}```
Outer.Inner obj1 = new Outer.Inner(); do this
No
thats if its static
You do that if its static
BUt let me try it
Outer.Inner obj1 = new Outer.Inner();
oops
No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing instance of type Outer (e.g. x.new A() where x is an instance of Outer).
If I make inner class static
then it works
static class Inner {
k
But I just dont see
what don't you see?
Outer.Inner obj1 = obj.new Inner();
Understnad the obj.new Inner(); part
well frankly I didn't even know that was valid syntax until now
but I can make an educated assumption
Inner is not static, as you said, and is therefore bound by the instance of it's upper class
so in order to construct an instance of inner, you first need an instance of Outer
obj is your instance of outer
so, obj.new Inner();
however, I'd just like to point out, I've never seen this sort of system used once in my entire time coding in java
there's probably a very good reason for that
What do you mean this "therefore bound by the instance of it's upper class"
IF it was static
it wouldnt be bound by the instace of it's upper calss?
So in other words we can say, static doesnt require a new instance right?
yes
So it requires a new instance of it's upper class is what you meant. when you said the bound part.
So
Outer.Inner obj1 = new Inner(); wouldn't work because it needsthe instance of outer and obj.
OK i see that now
took a while xD
had to read what u wrote many times and see it x_x
BUT what do we needa do this?
i dont get this part
Outer.Inner obj1 = new Outer.Inner();```
FOR static class
if it's static why do we need the "NEW" stuff
aka the instance stuff
the class is static, that doesn't necessarily mean it's properties are
generally static classes are preferred iirc
wait what do u mean iirc?
if i recall correctly
java
Ok but like what is static abuse then?
the misuse of static as an access modifier, instead of what it actually is, a memory tool
What do you mean by memory tool?
Java's memory usage is automatically managed, by something called a garbage collector
not all languages have this
for example, c
you have to manually remove your data from memory
and manually add it
with java, it's not like that
you create an instance, and the jvm handles the memory portion of it
when that instance is no longer needed, the garbage collector automatically removes it
static things, can not be garbage collected (unless you kill their classloader, this is somewhat irrelevant though)
this is a MASSIVE oversimplification
because the simple fact is, it's not beginner friendly
erm
yeah I suppose so
that's why so many people use it by accident
they see static, and see that it easily allows them to pass instances around
but they don't realise what static is actually doing underneath
which can lead to memory leaks, and semantic issues
i.e. static abuse
which is why we strongly recommend you completely avoid static until you fully understand how it works
yes, you can code without ever using static in java
yep
I see
It's important to note, static isn't bad
it's just hard to understand
and therefore beginners should avoid it
yo what does the : mean for the for each loop or the for enhanced loop
yea
think of it as the word in
for String s in someListOfStrings
then you loop through that entire list of strings
and do something with each string
its only meant for arrays or lists right?
maps, arrays, lists, etc. anything that stores multiple things
thats not a great way to explain it but hopefully it gets the point across lol
So basically
For String s : ListsofString)
Loop through Reference Name of reference In Collection of Things.
What is s used for tho?
String s is a variable
yea thats a goo way to explain it
the s is the string itself
Looping through a collection or array
its called an enhanced for loop or in some other languages, a for each loop
ok but what would we do with the s in the loop?
depends
that's the variable
String s is a variable fresh, equal to the element of the current iteration
the s is an element in the list
No i get its the name of hte variable
String is reference type of String
so if I have print s
it owuld print out everyt possible thing in the list/collection?
yes pepp
This can also be achieved via For Loop tho right?
Yes
this is a for loop
Not in all cases possibly
Sets, you will most likely go with the iterator and while loop or something if not enhanced for
coz the for loop approach depends on having an index
you cant fetch a set element with a index
https://www.spigotmc.org/resources/trollcommands-troll-your-frenemies.24237/
Would it be possible to make the plugin above with no commands and instead have all the of the features be enacted at a random time?
Does java compiler cast objects to the required value, for example JavaPlugin to Plugin, or that's just the decompiler or anything else?
bit of both
Interestig
if(e.getBlock().getType() != null && e.getBlock().getType() == Material.IRON_ORE) {
if (e.getBlock().getLocation().getChunk().getBlock(3, 3, 3).getType() == Material.ACACIA_DOOR) {``` is this correct? xD
you need to check if the block is null before access other methods such as getType
Yo @quiet depot someone on here said that whenever you can, you should create local variables/ variables inside methods rather than having instance variables/fields? To be more optimized/use less resources?
Is this true?
Isnt it the other way around?
The compiler will do some optimizations for you anyways
I thought it was other way around
but, dude said that
You should always access your variables via getter/setter methods right?
Yes, public mutable fields arent good.
@regal gale lol why not just to MemorySection#getValues?
@prisma wave you would need another recursive anyway, as value could be another MemorySection
yo what does SOmething#getSomething mean?
I see people do that a lot but i dont get it
Method reference
Dont get it what do u mean by reference?
MemorySection <- Would be the name of the class or method?
and getvalue is name of the ^?
ClassName#methodName()
Method methodName from class ClassName.
class A {
public void show() {
System.out.println("in A Show");
}
}
public class StaticDemo {
public static void main(String args[]) {
A obj = new A()
{
public void show() {
System.out.println("in sadgsg");
}
};
obj.show();
}
Why is the new A() {}; considered a class?
Doesnt that only apply to Interfaces?
No it can also work with class
its called an anonymous class
Do we use many lambda expressions in minecraft plugins? It only applies for functional interfaces right so if they only have 1 abstract method?
functional interfaces
Lambdas apply to only interfaces with a single non-default function
yea i tested it on abstract class and it didn't work
Yes
Oh iw as just wondering if you could add lambda to abstract
No
Is lambda like faster or something?
No just more readable
No?
So I've got a slight issue, when placing the block I get the first location, and when I break it I get the second one, issue now is that I use a location to identify a spawner there, and since the locations don't match (even though they should), it completelly breaks
[1] Location{world=CraftWorld{name=world},x=-250.5,y=64.8999969959259,z=42.5,pitch=0.0,yaw=0.0}
[2] Location{world=CraftWorld{name=world},x=-251.0,y=65.0,z=42.0,pitch=0.0,yaw=0.0}
I have to somehow normalize the location which is given when a user places the spawner, yet I've no idea how I'd do that
Also, the fuck is this, one rounds up, the other down?
42.5 -> 42.0
250.5 -> 251.0
Normalizing the location, yet it still prints out decimals so..
private Location normalize(final Location location) {
location.setX(location.getBlockX());
location.setY(location.getBlockY());
location.setZ(location.getBlockZ());
return location;
}
output: Location{world=CraftWorld{name=world},x=-258.5,y=64.8999969959259,z=42.5,pitch=0.0,yaw=0.0}
I'm hella confused
Some weird shit is going on..
oke so how i get block locations is
(kotlin)
block.x
block.y
block.z
?
and why do you normalize locations, how do you get those locations=
use
block.getLocation()
That's what I'm using yes.
interesting
so example
val cropLocation = CropLocation(base.x, base.y, base.z, base.world.name)
For me prints
x = 5
y = 5
z = 20
i dont get decimals
val base = event.block.getRelative(BlockFace.UP)
i dont like normalize locaitons
I mean yea because you create a new location
thats seperate class, smaller since i dont need yaw and pitch
but both dont give decimals for me
can we check a brekead block with itemstack?
HeadDatabaseAPI api = new HeadDatabaseAPI();
ItemStack NetherGenerator = api.getItemHead("39000");
if (block.getType() == NetherGenerator) {```
maybe we can't check a block that is custom like heads
type is always gona be head, you have to check its blockdata?
type is just gonna be PlayerHead
Also, lowerCamelCase plz, ktnxbye
HeadDatabaseAPI api = new HeadDatabaseAPI();
ItemStack NetherGenerator = api.getItemHead("39000");
if (block.getData() == NetherGenerator) {``` depricated ;/
Anyone know hwy this throws an error? Is it a java 1.8 bug?
public class StaticDemo {
public static void main(String args[]) {
int i, j;
i=8;
j=0;
try {
int k = i/j;
if (k == 0 ) {
throw new CustomException("This is not possible");
}
}
catch(CustomException e) {
System.out.println("Error" + e.getMessage());
}
System.out.println("hello");
}
}```
what type of error does it throw?
so then he just needs to check for that error, thats basic since you cant devide something by 0.
Indeed
catch(Exception e) { seems to work
but the catch(CustomException e) {
says the arthemitic error
Well catch the other error
wat do u mean?
instead of using Customexception use ArthemeticException....
yes.. I know that tho lol
I mean what's the issue then?
Exception in thread "main" java.lang.ArithmeticException: / by zero
at me.freshpeppermint.StaticDemo.main(StaticDemo.java:13)
thats what it says when I run it
Gasper..
^
To learn about CustomExceptions
I don't think you can just go around throwing your own exceptions to bypass others
anyone knows why when blockgrowevent is triggered by melon/pumpkin growing the block that grew is AIR?
its not pumpkin or melon
https://youtu.be/KFoN6hQ3yAs?t=151 works for this guy
How do I cahnge java versions?
in eclipse
Dont use eclipse
Also it works for him since j isnt 0
You cannot divide something by 0, and as such the Arithmetic exception is thrown
Ah I didnt see that my bad
Hey guys I heard this is bad to do, why. And why is this other thing a better solution?
public class ConfigValues {
LitTestPlugin main = new LitTestPlugin();
public String configString() {
return main.getConfig().getString("String");
}
public String getitemName() {
return ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("itemname"));
}
}```
does LitTestPlugin extend javaplugin?
LitTestPlugin main = new LitTestPlugin();
If it's your main, this ain't it chief
yea
it's not bad practice, it simply doesn't work
public class ConfigValues {
private LitTestPlugin main;
public ConfigValues(LitTestPlugin main) {
this.main = main;
}
public String configString() {
return main.getConfig().getString("String");
}
public String getitemName() {
return ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("itemname"));
}
}```
that's better
you can't initialize your main class in plugins
you can only pass it's instance around
Oh cus its an interface?
No
oh then why?
spigot just prevents more than one instance of JavaPlugin existing at runtime
it's called a singleton
Whats another alternative to what I just did there?
https://discordapp.com/channels/164280494874165248/695431668944732270/744487199826903130 this is what you should do
Dependency Injection
main can be final though
sTaTiC
You can retrieve an instance of your javaplugin class via JavaPlugin.getPlugin
JavaPlugin.getPlugin(LitTestPlugin.class)
you can use a dependency injection framework (like guice)
you can create your own static instance getter
there's many options
stick with dependency injection though
whats dependency injection?
?java-dependency
Dependency Injection
Dependency Injection is a method of passing our dependencies, into the classes that need them. In java, this is commonly done by passing an instance of the dependency via the constructor.
public final class CoolPlugin extends JavaPlugin {
@Override
public void onEnable() {
final Other other = new Other(this);
other.method();
}
public void myMethod() {
/* Some code goes in here */
}
}
public final class Other {
private final CoolPlugin main;
public Other(@NotNull final CoolPlugin main) {
this.main = main;
}
public void method() {
main.myMethod();
}
}```
smh
Doesn't final mean it's a constant?
no
a constant is static and final
final alone, simply means the variable is immutable
so anything that doesnt change should have final next to it
yes
you should make absolutely everything final by default, except for methods/functions
it's redundant to make methods/functions final, because your classes will be final
if your class isn't final, then those methods/functions are obviously meant to be extended, so still redundant to make them final
i forgot what fucntions were. What are functions again?
static methods
Ah ok
Technically the term function does not exist in java terminology
Except with functional interfaces perhaps
Having trouble seeing/understanding this tho.
public class ConfigValues {
private final LitTestPlugin main;
public ConfigValues(LitTestPlugin main) {
this.main = main;
}```
But static methods are still called methods
yeah
not official naming, but I swear by it, because it makes sense
and most people will understand it
y do we need this
public ConfigValues(LitTestPlugin main) {
this.main = main;
}```
WHEn we already have this:
```JAVA
private final LitTestPlugin main;```
cuz u have to assign a value to the field main
otherwise it's just an empty variable declaration
Hold up why does private int a; not give an error?
because it's not final
a final variable has to be assigned a value
non final variables do not
private final LitTestPlugin main;```
What is that saying technically?
like private access modifier, final is to signify no change, LitTestPlugin , main is the name of the reference.
nvm i just realised its class is what it's staying
Reference to a class
Ok why do we have these 2 values in the brackets?
public ConfigValues(LitTestPlugin main)```
cant we just use a default constructor with no parameters?
technically you can store the main plugin instance as a constant
private static final LitTestPlugin MAIN = JavaPlugin.getPlugin(LitTestPlugin.class);
as a beginner though, it's crucial that you get used to dependency injection
as you'll need to use it everywhere else
Ok but why are we doing the dependency injection here?
private final LitTestPlugin main;
public ConfigValues(LitTestPlugin main) {
this.main = main;
}```
Do you know? You do this to communicate with the other classes? And why is it on a constructor? Can't you basically create a method instead for it?
You need to look at both sides of it, the class you're using DI in, and the class you're initializing your other class in
Can you have a method inside method btw?
dont think so
You can in Kotlin, but idk why you'd want that
Yo how come this is not working
public class TestCode {
public void show() {
System.out.println("Okay!");
}
public static void main(String args[]) {
TestCode obj = new TestCode();
obj.show();
}
}
class Hello {
private final TestCode classname;
public Hello(TestCode classname) {
this.classname = classname;
}
classname.show();
}```
the classname.show() <- part
Well if you wanna count lambdas or anonymous/local classes you can
PepperMint, you can't run code outside of blocks
wat do u mean?
well, you can't run the classname.show() code outside a block like you are doing, hence it doesn't like it
wat do u mean by a outside a block?
"A block in Java is a group of one or more statements enclosed in braces. A block begins with an opening brace ({) and ends with a closing brace (}). Between the opening and closing braces, you can code one or more statements"
O
Take your constructor and main function as an example of one
public class TestCode {
public void show() {
System.out.println("Okay!");
}
public static void main(String args[]) {
Hello obj = new Hello(X);
obj.hello();
}
}
class Hello {
private final TestCode classname;
public Hello(TestCode classname) {
this.classname = classname;
}
public void hello() {
classname.show();
}
}```
what would I put in X?
Hello(X);
this
What would this mean in THAT scenario?
this would refer to the TestCode class
public class TestCode {
public TestCode a;
public void show() {
System.out.println("Okay!");
}
public static void main(String args[]) {
Hello obj = new Hello(a);
obj.hello();
}
}
class Hello {
private final TestCode classname;
public Hello(TestCode classname) {
this.classname = classname;
}
public void hello() {
classname.show();
}
}```
that would work?
having a instead?
cus I put public TestCode a;
TryAndSEE
but it says cannot chance static reference to non static thing
oh
public TestCode a; that would just be null
Would still just be null
I did say twice it would be null
Because you never instantiate it
public TestCode a; is the same as doing public TestCode a = null;
hmm I still don't get what goes inside the Hello() <-
this
Cannot use this in a static context
BUT this wouldnt return null btw?
and the other thing I said would?
Why wouldn't this return null as well?
this is a Java thing, it's never null.
o
It always points to an instance of the class you use it in
public TestCode a = this; and then passing in a might work.
I only really do stuffs in Kotlin now and we don't really have static. Our mains are literally just
fun main(args: Array<String> (<- optional btw)) {
//do whatever
}``` so `this` is perfectly valid for us Kool Kotlin Kids
just make new class and initialize everything there thats how i used to do.
No i am like trying to see
private final TestCode classname;
public Hello(TestCode classname) {
this.classname = classname;
}
that part to understand it a bit better
whilst keeping the code as simple as possible
rip
It does
So what have I done wrong
Prefix it with ./
Still doesn't like it
Can you send a link to the repo
this might help you
yeah thats what I tried
hbahahaha
Thats idiotic, thanks
XD
oh if you need more infO:
https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-readmes
You can add a README file to your repository to tell other people why your project is useful, what they can do with your project, and how they can use it.
Ah well url encoding
yeh
XDD
What do we learn from this? Don't use spaces in file names
indeed
one more simple question
!= means false, == means true, || means or, && means and, am i right?
yeah
lets say it that way yes, but for me != means not equal and == means equal.
!= if it doesnt equal == if it does if this is || or if this is if this is && and this is
anyone has any good formula for leveling like how much xp for each level?
not mc one
oh?
i need it for something else
ye but i cant find good one
either i get to small amount of xp or to big of a change between levels
consider one axis to be level and the other experience
Work on making a curve
And choose what seems right
i think this is kinda broken:
what is?
oh god
This is not broken
Dont use too high exponents
But not suitable for levels
oh it was raise to 2
2 is not a high exponent lol
I saw it as 2 * 100 xD
@regal gale pretty sure getValues(true) will get literally every value, no recursion necessary
who the frick downvoted papi 3 in showcase
getValues() returns a map
It isn't making any difference dude...
You would get this later on anyway: Map<String, MemorySection>
I'm not sure that's what happens with getValues(true)
It'll flatten the keys and just use a Map<String, Object> afaik
It is a different story with this for example:
data:
data1: "Hello"
data2:
- Hi
- property: Hello
- Hello2
data1 will return a normal String object, but with data2, it will not be recognized as a full Array, as there is another property inside
who the frick downvoted papi 3 in showcase
@onyx loom 😠 my beautiful api 😦
😭
He already did in #off-topic
imo its solving a problem that doesnt exist

Doing some fun shit with commands lol
owo level xp circle isnt prfectly centered
Owo I just made an auto command/listener detection system (injecting variables) without reflections
Out of boredom
sound in java is trash
why?
this application has an alarm system and it crashed while running and this super loud screeching just kept going
idk what ya doing
Owo I just made an auto command/listener detection system (injecting variables) without reflections
@signal tinsel how's it work?
how does it work behind the scenes lol
NerdCon
idc about the api
how does it find the classes?
Uhh i use guavas classpath
oh
careful with that, I've always had issues with it when using it in spigot plugins
I gave up on classpath scanning ages ago, ended up just recursing through the jar itself to find classes.
i love how mc added support for animated "world maps"
is 1.16 ready?
wdym?
does it support 1.16?
What are you referring to by it?
ChatReaction 1.8.0
It does not say so on the plugin thread but seems to work fine on my server
another question of the day: is it a good idea to merge like 5 plugins into a "core" plugin and only have one plugin?
no
@quiet depot aight ima try ur thing
Update, @quiet depot ty, also works
Tbf ACF is good
Rewriting my prison plugin
Tbh its less of a server now tbh
Its more of a side project for fun
To experiment with
I wanna add things to my GUI framework tbh, its fairly simple rn
anyone has any good GUI framework?
I have one
Niallgui
whats the sound for tool break?
Doesn’t Matt have a framework
I’d recommend looking into Mfgui, helper, Smartinvs, vignette, if, inventorygui, Canvas
if?
InventoryFramework
if then if then if then else if then if
canvas?
Tf, did that just embed and then disappear for anyone then
Sounds dumb 
another question of the day: is it a good idea to merge like 5 plugins into a "core" plugin and only have one plugin?
no
@heady birch why isn't it?
Well I mean if it's for a private thing it makes sense, not always the cleanest thing tho
^ often if you aim to make a public plugin it should only have 1 core feature
The server owner will most likely already have a plugin for that other feature
SRP should apply to plugins too
A plugin should do 1 thing well, rather than many things poorly
I mean sure but be sure to keep a good structure
and the plugins are with almost the same objective
BM, I mean if you split it up properly you can still abide by it 
as "core" systems
sooo
what's the answer
xd
I mean sure but be sure to keep a good structure
and yes
that's why I want it to be in one single plugin
cause I have methods that I use in both
soo
ye
I want to compact it
Go ahead, it’s private anyways so creating a bunch of stuff like making 5 invidual plugins is quite unnecessary in your case is only going to slow you down.
Just put it all in one plugin but keep it maintained
Location{world=CraftWorld{name=world},x=-256.5,y=67.8999969959259,z=41.5,pitch=0.0,yaw=0.0}
Location{world=CraftWorld{name=world},x=-257.0,y=68.0,z=41.0,pitch=0.0,yaw=0.0}
@prisma wave I still don't know what to do about this.. I tried rounding it myself but it still doesn't change the location printout
you mean organized?
Yeah
I mean rlly depends
Yup
but ye


