What's wrong with my Code?

Status
This thread has been locked.

Stylez

Server Owner & World Painter
Premium
Feedback score
3
Posts
725
Reactions
240
Resources
0
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Vapey

mcteams.com
Premium
Feedback score
7
Posts
495
Reactions
234
Resources
0
I saw Vapey's youtube channel with tutorials and I must say they have some very bad practices and many mistakes.
Could you give me constructive criticism so I can learn from my mistakes?
 

7rory768

Feedback score
3
Posts
27
Reactions
8
Resources
0
FfZjn27.png

http://i.imgur.com/FfZjn27.png

Why aren't you returning when they don't have permission, these checks are ineffective otherwise.[DOUBLEPOST=1457567619][/DOUBLEPOST]Your commands aren't setup properly the way you coded it you first check if a player uses the command /cc and then if they did you check if their command is forums or apply but if their command is /cc how can it equal forums or apply.
 
Last edited:

Skionz

ogminecraft.com
Premium
Feedback score
1
Posts
1,544
Reactions
1,527
Resources
0
Could you give me constructive criticism so I can learn from my mistakes?
I skimmed your videos and here is what I came up with.
  • It may not seem like it, but good vocabulary is essential. At one point you say: "Here we write the public void." Uhm you wrote a method, not a public void.
  • In episode 2 you supposedly taught viewers how to make repeating tasks? Wrong, you taught them how to write for loops.
  • As ItsMonkey mentions. A package named 'commands' does not follow naming conventions.
  • Java is object oriented, not class oriented. Pass the instance of you main class to other classes through their constructors when they instantiated.
  • A general rule to keep in mind is that fields should be private unless there is a valid reason for them not to be which there is not.
  • If a CommandSender was always a Player there would be no reason to have it as a super class. Check before casting.
  • Names of variables should be descriptive. 'p' is not descriptive.
  • Being very blunt, you aren't a very good teacher. You don't explain what you are doing, what private means, what void means, what ChatColor is, what a class is, or anything. This is most likely because you don't know yourself.
Before posting more videos think about this scenario: So I never went to med school, but I have watched every episode of House. Should I start giving out medical advice?

I highly suggest reading oracle's tutorials.
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/
 
Last edited:

Tyler

Developer
Supreme
Feedback score
14
Posts
2,589
Reactions
2,238
Resources
0
1. You need to be using the correct paperspigot build in your IDE.
2. You forgot the "@Override" annotation above the public boolean onCommand
3. Make sure you have the command registered in your plugin.yml, or else it won't work.
4. Also a quick tip, it looks better if you actually adjusted the spacing/tabbing. Because reading this code is strange to me, using correct spacing will make it clear to read.

If you have any more questions, or if none of the fixes above work, PM me :)
i just wanna know why you say you need @Override above your onCommand? I've never ever used it, so I'm assuming it's pointless..
 

Skionz

ogminecraft.com
Premium
Feedback score
1
Posts
1,544
Reactions
1,527
Resources
0
i just wanna know why you say you need @Override above your onCommand? I've never ever used it, so I'm assuming it's pointless..
Not required; Java compiler interprets it at compilation and will still work fine (as long as the method name is exactly the same, in this case he failed to do this). I never use @Override in any of my subclasses because I don't like how it looks. It is only really necessary if you are working with a team that wants you to have it (to make it clear that you are in fact overriding a method from a parent class).
A subclass will override a method in the superclass as long as it has the same name and parameters.
 

Tyler

Developer
Supreme
Feedback score
14
Posts
2,589
Reactions
2,238
Resources
0
A subclass will override a method in the superclass as long as it has the same name and parameters.
I didn't see that post :p
 

Nagi

PM Only - No Skype
Supreme
Feedback score
12
Posts
535
Reactions
679
Resources
0
Code:
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public class Core extends JavaPlugin {

    public void onEnable() {

    }

    public void onDisable() {

    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if (commandLabel.equalsIgnoreCase("cc")) {
            if (!sender.hasPermission("cc.use"))
                sender.sendMessage(ChatColor.RED + "You do not have permissions for this command.");
            else {
                for (int i = 0; i < 250; i++)
                    Bukkit.broadcastMessage("");
                Bukkit.broadcastMessage(ChatColor.GRAY + "Chat has been cleared by " + ChatColor.YELLOW + sender.getName() + ChatColor.GRAY + ".");
            }
        } else if (commandLabel.equalsIgnoreCase("forums")) {
            if (!sender.hasPermission("forums.use"))
                sender.sendMessage(ChatColor.RED + "You do not have permissions for this command.");
            else
                sender.sendMessage(ChatColor.GREEN + "Website: " + ChatColor.GRAY + "www.enhancedhcf.com");
        } else if (commandLabel.equalsIgnoreCase("apply")) {
            if (!sender.hasPermission("apply.use"))
                sender.sendMessage(ChatColor.RED + "You do not have permissions for this command.");
            else
                sender.sendMessage(ChatColor.YELLOW + "www.enhancedhcf.com/apply");
        }
        return false;
    }
}
 

Skionz

ogminecraft.com
Premium
Feedback score
1
Posts
1,544
Reactions
1,527
Resources
0
Code:
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public class Core extends JavaPlugin {

    public void onEnable() {

    }

    public void onDisable() {

    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if (commandLabel.equalsIgnoreCase("cc")) {
            if (!sender.hasPermission("cc.use"))
                sender.sendMessage(ChatColor.RED + "You do not have permissions for this command.");
            else {
                for (int i = 0; i < 250; i++)
                    Bukkit.broadcastMessage("");
                Bukkit.broadcastMessage(ChatColor.GRAY + "Chat has been cleared by " + ChatColor.YELLOW + sender.getName() + ChatColor.GRAY + ".");
            }
        } else if (commandLabel.equalsIgnoreCase("forums")) {
            if (!sender.hasPermission("forums.use"))
                sender.sendMessage(ChatColor.RED + "You do not have permissions for this command.");
            else
                sender.sendMessage(ChatColor.GREEN + "Website: " + ChatColor.GRAY + "www.enhancedhcf.com");
        } else if (commandLabel.equalsIgnoreCase("apply")) {
            if (!sender.hasPermission("apply.use"))
                sender.sendMessage(ChatColor.RED + "You do not have permissions for this command.");
            else
                sender.sendMessage(ChatColor.YELLOW + "www.enhancedhcf.com/apply");
        }
        return false;
    }
}
Spoonfeeding teaches him nothing.
 

Tyler

Developer
Supreme
Feedback score
14
Posts
2,589
Reactions
2,238
Resources
0
Well, it's the way superclasses and parent classes work, not something outlined in a.... "post?"
I did not the see post that he quoted, which explained it. That is what I meant by post. Don't know how that's hard to understand?
 

Vapey

mcteams.com
Premium
Feedback score
7
Posts
495
Reactions
234
Resources
0
I skimmed your videos and here is what I came up with.
  • It may not seem like it, but good vocabulary is essential. At one point you say: "Here we write the public void." Uhm you wrote a method, not a public void.
  • In episode 2 you supposedly taught viewers how to make repeating tasks? Wrong, you taught them how to write for loops.
  • As ItsMonkey mentions. A package named 'commands' does not follow naming conventions.
  • Java is object oriented, not class oriented. Pass the instance of you main class to other classes through their constructors when they instantiated.
  • A general rule to keep in mind is that fields should be private unless there is a valid reason for them not to be which there is not.
  • If a CommandSender was always a Player there would be no reason to have it as a super class. Check before casting.
  • Names of variables should be descriptive. 'p' is not descriptive.
  • Being very blunt, you aren't a very good teacher. You explain what you are doing, what private means, what void means, what ChatColor is, what a class is, or anything. This is most likely because you don't know yourself.
Before posting more videos think about this scenario: So I never went to med school, but I have watched every episode of House. Should I start giving out medical advice?

I highly suggest reading oracle's tutorials.
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/
Ty :)
 
Status
This thread has been locked.
Top