My first plugin!

Discussion in 'Plugin Development' started by AcePilot10, Nov 28, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    AcePilot10

    Hi people of Bukkit, i'm extremely new to coding. I was hoping somebody could take a look at my code. The game is infection. I don't even know if there is anything wrong with it but I wanted somebody to take a look at it to see if there is anything wrong with it. So heres my code http://prntscr.com/5b63jf
    http://prntscr.com/5b66aq
    Thanks for readin!
     
  2. AcePilot10 First off, no need to say it is enabled/disabled Bukkit already does that. Secondly label.equalsIgnoreCase("") is not correct it is command.equalsIgnoreCase(""). Thirdly i11 is always 0 so the game can never start. Lastly, if you want multiple arguments it isn't command.equalsIgnoreCase("something 2") you have to use arguments.
     
  3. Offline

    Googlelover1234

    AcePilot10
    Why don't you test the plugin and see if there's anything wrong..?
     
    ChipDev likes this.
  4. Offline

    teej107

    Your code posting method.... *facepalm*

    As for you code, do you have a reason on why you are using static?
     
    Nedinator likes this.
  5. There are a few problems.

    1. Package naming convention is lowercase.
    2. You don't need messages in onEnable() and onDisable(), Bukkit does this automatically.
    3. Is there any reason you canStart and hasStarted fields are static?
    4. Method naming convention is camelCase
    5. You set hasStarted to true and then immediately check if it's true. If it isn't at this point, something has gone horribly wrong.
    6. I think you're missing braces on your if statement.
    7. There's a lot of indentation errors - eclipse can correct this for you if you ask it to.
    8. Your onCommand has no Override annotation - this isn't necessarily a big problem, but it's good practice to put it when overriding a method as it will cause a compilation error if you try to override a method that doesn't exist (good for preventing typos)
    9. Check the command's name, not the label, in order to support aliases.
    10. Your i11 will always be 0, so this will mess up with the if statements that follow it.

    All in all, I'd seriously recommend leaving Bukkit plugin developing until you've learned more Java, or else you'll just run into problems :) I'd recommend either the Oracle tutorials or a Java book.
     
    Rocoty and teej107 like this.
  6. Offline

    AcePilot10

    I really do appreciate all the responses, and AdamQpzm i will check out those tutorials. I made some changes to the code and here is what I got: http://prntscr.com/5b81yn and as I said before I apologies if I didd not understand your responses I am still very new to bukkit
     
  7. Offline

    teej107

    AcePilot10 Are you new to Java as well? I highly recommend learning Java first before learning the Bukkit API.
     
  8. Offline

    AcePilot10

    I will look into it. I would love to finish this plugin up for my server as well
     
  9. Offline

    AcePilot10

    So i't taking some of the tutorials and learning java. thanks so much for all the support. Also is this code http://prntscr.com/5b81yn correct?
     
  10. Offline

    Skionz

    AcePilot10 No. You have some logic errors at the top.
     
  11. Offline

    Hex_27

    AcePilot10 it would help if you put your code here in this thread, and not as a picture a we would be able to copy parts from your code that is wrong and show it to you.
     
  12. Offline

    AcePilot10

    package me.AcePilot10.Infection;​
    import org.bukkit.Bukkit;​
    import org.bukkit.Location;​
    import org.bukkit.command.Command;​
    import org.bukkit.command.CommandSender;​
    import org.bukkit.entity.Player;​
    import org.bukkit.plugin.java.JavaPlugin;​
    public class Game extends JavaPlugin{​
    private static boolean canStart = false;​
    private static boolean hasStarted = false;​
    public static void Start(boolean gameStart) {​
    hasStarted = true;​
    if(Game.hasStarted)​
    new Survivors("Survivors", new Location(Bukkit.getWorld("Ace"), 100, 100, 100));​
    new Infected("Infected", new Location(Bukkit.getWorld("Ace"), 100, 100, 100));​
    }​
    public boolean canStart() {​
    return hasStarted = true;​
    }​
    public void stop() {​
    hasStarted = false;​
    }​
    public boolean hasStarted() {​
    return hasStarted;​
    }​
    public boolean onCommand(CommandSender sender, Command cmd,​
    String label, String[] args) {​
    if (label.equalsIgnoreCase("assign")) {​
    for (Player player : Bukkit.getOnlinePlayers()) {​
    int i11 = 2;​
    if (i11 < Bukkit.getOnlinePlayers().length / 2) {​
    Survivors.addToTeam(TeamType.Survivors, player);​
    } else {​
    Infected.addToTeam(TeamType.Infected, player);​
    return Game.hasStarted;​
    }​
    if (i11 > Bukkit.getOnlinePlayers().length / 2) {​
    sender.sendMessage("Not enough people to start the game!");​
    break;​
    }​
    }​
    return true;​
    } ​
    return false;​
    }​
    }​
     
  13. Offline

    PreFiXAUT

    Well first of, you can use the Syntax/Code Formatting (In the Editor the 3rd from the right, 2nd row), but that doesn't matter right now.

    I can see that you're trying to learn, and I also see that you wanna finish this Plugin. But apparently you're trying to make a Minigame as far as I see. And Minigames aren't that easy. You're gonna have alot of Bugs and problems, if you make this Plugin without (or at least not allot) any knowledge of Java nor Bukkit. This is not gonna workout good in the end.

    So I would suggest you to really stop/pause this Plugin until you understand Java. I made the same mistake and had to redo somany things, that I have mostly left all of my Plugins and they are full of Bugs and Problems etc. So seriously, learn it before you start to do this. Otherwise I'll come back to you :/
     
  14. Offline

    ProMCKingz

    AcePilot10
    Is that your only class? If not, then register your events, or at least make an OnEnable() statement. It good practise
     
  15. Offline

    AcePilot10

    no, this is my main class. I dont have any problems in the others
     
  16. Offline

    Darkpicasa

    Well, I'm just saying, it's usually a bad idea to create a minigame like Infected as your first Bukkit plugin.
    Start small ;)
     
Thread Status:
Not open for further replies.

Share This Page