Assistance on a Project!

Status
This thread has been locked.

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Hello MC - Market,

I recently (tonight), have decided I want to start programming again.


I have made it this far - https://github.com/kingArchie/Cubec...src/com/kingarchie/plugins/cubecorestatistics

It is meant to show your kills - deaths "score" in your name as a suffix.

I have done something wrong in the listener when I put the numbers into the config - it is showing a NPE.

Can anyone spot any other mistakes / improvements?

If you can solve the NPE problem then please, feel free.


Thank you!
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Do some debugging? Would help if we knew what line the NPE is on :p
I would prefer someone to read the code, it isn't too long - suggest improvements etc.
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

saint

IPVP.ORG
Premium
Feedback score
2
Posts
86
Reactions
87
Resources
0
I would prefer someone to read the code, it isn't too long - suggest improvements etc.
https://github.com/kingArchie/Cubec...lugins/cubecorestatistics/CSListener.java#L38
Will throw NPE when the file doesn't contain the player name due to Java trying to unbox a null Integer object. Either replace the get call with getInt or replace int with Integer and perform a null check like the following:
Java:
Integer score = (Integer) CubecoreStatistics.instance.file.get(player.getName());
if (score != null) {
    String scoreString = CubecoreStatistics.instance.col("&6" + String.valueOf(score));
    CubecoreStatistics.instance.getChat().setPlayerSuffix(player, CubecoreStatistics.instance.col(" &8[" + scoreString + "&8]"));
}
 

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
https://github.com/kingArchie/Cubec...lugins/cubecorestatistics/CSListener.java#L38
Will throw NPE when the file doesn't contain the player name due to Java trying to unbox a null Integer object. Either replace the get call with getInt or replace int with Integer and perform a null check like the following:
Java:
Integer score = (Integer) CubecoreStatistics.instance.file.get(player.getName());
if (score != null) {
    String scoreString = CubecoreStatistics.instance.col("&6" + String.valueOf(score));
    CubecoreStatistics.instance.getChat().setPlayerSuffix(player, CubecoreStatistics.instance.col(" &8[" + scoreString + "&8]"));
}
What if score DOES = null?
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
The join event is throwing a NPE too.
then they must not have kills or deaths
It has to be there though?! Because when they join if they aren't there, it puts them in it as 0.
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

saint

IPVP.ORG
Premium
Feedback score
2
Posts
86
Reactions
87
Resources
0
The join event is throwing a NPE too.

It has to be there though?! Because when they join if they aren't there, it puts them in it as 0.
Only obvious issue I can see is if your chat provider is null

Edit: The hell is DataFile? Just use YamlConfiguration.loadConfiguration(File)

Edit2: I've submitted a PR (here) to your repository with a general code cleanup. The PR changes the project structure to maven so if you have any questions about compiling with maven please feel free to ask. Also ask if you have any questions about anything I've done to your code.
 
Last edited:

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
Only obvious issue I can see is if your chat provider is null

Edit: The hell is DataFile? Just use YamlConfiguration.loadConfiguration(File)

Edit2: I've submitted a PR (here) to your repository with a general code cleanup. The PR changes the project structure to maven so if you have any questions about compiling with maven please feel free to ask. Also ask if you have any questions about anything I've done to your code.
That was Justis R's API (DataFile).

I don't really understand "this.getServer" and such - I keep looking this up but I don't know when you need to use it etc.
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)

saint

IPVP.ORG
Premium
Feedback score
2
Posts
86
Reactions
87
Resources
0
That was Justis R's API (DataFile).

I don't really understand "this.getServer" and such - I keep looking this up but I don't know when you need to use it etc.
"this" just refers to the current object that is executing a piece of code. Think of it as a hidden variable in every object that is a reference to the current object executing code.

You can view detailed information here: https://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html

Expanding on the first example in that link:
For example, the Point class was written like this

Java:
public class Point {
    public int x = 0;
    public int y = 0;
      
    //constructor
    public Point(int a, int b) {
        x = a;
        y = b;
    }
}

but it could have been written like this:

Java:
public class Point {
    public int x = 0;
    public int y = 0;
      
     //constructor
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

The reason why the this keyword is used in the sample example is because if you were to define the constructor in the following:
Java:
private int x = 0;
private int y = 0;

public Point(int x, int y) {
    x = x;
    y = y;
}
The private ints x and y would never be assigned anything because the x = x and y = y assignments would be referencing the actual (int x, int y) objects passed in the Constructors parameters. This also holds true for methods:
Java:
private int x = 0;
private int y = 0;

public Point(int x, int y) {
    this.x = x;
    this.y = y;
}

public void setX(int x) {
    // Below must be this.x to reference the private int x, otherwise 
    // would reference the int x passed in the method parameter 
    // (assigning the value to itself - essentially doing nothing)
    this.x = x; 
}

In terms of referencing methods such as this.getServer(), it is essentially the same as calling getServer() from inside an object but is just a personal preference I have in my codestyle. However with this notation you can replace the call to "this" with a call to super which references the method inside the superclass of the current object. You can read more about the super keyword here: https://docs.oracle.com/javase/tutorial/java/IandI/super.html
 

Archie

Jᴀᴠᴀ Dᴇᴠᴇʟᴏᴘᴇʀ
Banned
Feedback score
0
Posts
715
Reactions
263
Resources
0
"this" just refers to the current object that is executing a piece of code. Think of it as a hidden variable in every object that is a reference to the current object executing code.

You can view detailed information here: https://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html

Expanding on the first example in that link:


The reason why the this keyword is used in the sample example is because if you were to define the constructor in the following:
Java:
private int x = 0;
private int y = 0;

public Point(int x, int y) {
    x = x;
    y = y;
}
The private ints x and y would never be assigned anything because the x = x and y = y assignments would be referencing the actual (int x, int y) objects passed in the Constructors parameters. This also holds true for methods:
Java:
private int x = 0;
private int y = 0;

public Point(int x, int y) {
    this.x = x;
    this.y = y;
}

public void setX(int x) {
    // Below must be this.x to reference the private int x, otherwise
    // would reference the int x passed in the method parameter
    // (assigning the value to itself - essentially doing nothing)
    this.x = x;
}

In terms of referencing methods such as this.getServer(), it is essentially the same as calling getServer() from inside an object but is just a personal preference I have in my codestyle. However with this notation you can replace the call to "this" with a call to super which references the method inside the superclass of the current object. You can read more about the super keyword here: https://docs.oracle.com/javase/tutorial/java/IandI/super.html
Daddy <3
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/archie-scam-report.114655/)
Status
This thread has been locked.
Top