A little help

Discussion in 'Plugin Development' started by mista_ninja_3, Jul 17, 2012.

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

    mista_ninja_3

    Hi there,
    I was wondering if you could help me with a plugin im trying to develop. I am beginner (self taught) coder and im having trouble. Its simple stuff that I can't implement.

    i.e- Help command, reload command.

    Stuff that I have implemented:
    - /profile command
    -/profile <playername> (player must be online)

    Things I would like to change/having trouble with:
    - Help command
    - Reload command
    - allowing /profile <player> to view offline players
    - Putting my code on multiple javas and linking it to main java.
    - A color utils so I can use &[a-f, 0-9] in my coding.

    If you could help me, thats what I would like done.
    P.S- As you can see, I have already put in color codes without a util :\

    Note- Anything saying "NotConnected!" I will be able to implement myself. Just the commands I am having trouble with.​

    Also I am planning in releasing this after I get commands finished and implement some other things into it, eg- permissions and other options (editable)​
    Thanks,
    Mistaa

    Show Spoiler
    Code:
    package me.mista.mistaprofile;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class MistaProfile extends JavaPlugin{
       
              public static MistaProfile plugin;
            public final Logger logger = Logger.getLogger("Minecraft");
              public String pluginTag = "&7[&cMistaProfile&7]";
           
            @Override
            public void onDisable() {
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info(pdfFile.getName() + " is now disabled!");
            }
         
            @Override
            public void onEnable() {
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info( pdfFile.getName() + " version " + pdfFile.getVersion() + " is now enabled!");
            }
           
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                Player player = (Player) sender;
                if(commandLabel.equalsIgnoreCase("profile")) {
                    if(args.length == 0) {
                    player.sendMessage("oOo__________[MistaProfile]__________oOo");
                        player.sendMessage("Name: " + player.getDisplayName());
                        player.sendMessage("First Online: " + "NotConnected!");
                        player.sendMessage("Last Online: " + "NotConnected!");
                        player.sendMessage("Total Time Online: " + "NotConnected!");
                        player.sendMessage("Balance: " + "NotConnected!");
                        player.sendMessage("Rank/Title: " + "NotConnected!");
                    } else if (args.length == 1) {
                        if(player.getServer().getPlayer(args[0]) != null) {
                            Player targetplayer = player.getServer().getPlayer(args[0]);   
                      player.sendMessage("oOo__________[MistaProfile]__________oOo");
                          player.sendMessage("Name: " + targetplayer.getDisplayName());
                          player.sendMessage("First Online: " + "NotConnected!");
                          player.sendMessage("Last Online: " + "NotConnected!");
                          player.sendMessage("Total Time Online: " + "NotConnected!");
                          player.sendMessage("Balance: " + "NotConnected!");
                          player.sendMessage("Rank/Title: " + "NotConnected!");
                        } else {
                            player.sendMessage(pluginTag + ChatColor.WHITE + " This player is offline!");
                        }
                    }
                }
                return false;
            }
    }
     
  2. Offline

    EnvisionRed

    >.<

    In your actual code you can just use ChatColor to add color to messages, e.g:
    Code:
    player.sendMessage(ChatColor.RED + "You can't do that!" + ChatColor.BLUE + "This is an example!");
    Your profile command just shows the same messages no matter what, all of them being "&bNotConnected" so what does it matter if the player is online or offline?
     
  3. Offline

    mista_ninja_3

    Yeah, I did that for some of it, but the color codes is just easier for longer messages :)
    Each one will be connected to another plugin. For example: Balance will be connected to iConomy later showing the balance of each player. The main point is to show a profile of another player. Showing their player total time, first registered, credits and more! :)
     
  4. Offline

    EnvisionRed

    It isn't easier for long messages once you know how to do it ^-^
    Anyway, you would connect it to vault to do that, so it has support for multiple economy plugins etc.
     
  5. Offline

    mista_ninja_3

    Thanks! Any ideas on how I can implement the stuff I had trouble with?
     
  6. Offline

    lx3krypticx

    What are you trying to implement?
     
  7. Offline

    mista_ninja_3

    - Help command
    - Reload command
    - allowing /profile <player> to view offline players not just online
    I know its easy, but im new to java :)
     
  8. did you try it first whitout our help?
     
  9. Offline

    mista_ninja_3

    What help? I just asked. And yes! Tried many times and failed as the plugin wouldn't run because of an error, I tried adding another public boolean onCommand1(etc, etc, etc) and it didnt work. :(
     
  10. example of 1 command
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. Player player = null;
    4. if (sender instanceof Player) {
    5. player = (Player) sender;
    6. }
    7.  
    8. if (cmd.getName().equalsIgnoreCase("basic")){
    9. // do something...
    10. return true;
    11. }
    12. return false;
    13. }
    2 commands:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. Player player = null;
    3. if (sender instanceof Player) {
    4. player = (Player) sender;
    5. }
    6.  
    7. if (cmd.getName().equalsIgnoreCase("basic")){
    8. // do something...
    9. return true;
    10. } else if (cmd.getName().equalsIgnoreCase("basic2")) {
    11. // do something else...
    12. return true;
    13. }
    14. return false;
    15. }
    you can gues how it look whit 3 commands, I dont gona give it, because I dont like copy/paste-people
     
  11. Offline

    bajsko

    rofl.. but anyway for a help command, its just to add the onCommand method in your code and check when the player type "/yourplugin help" or just /help and for the reload, do you mean the whole server? or just the plugin config? Also, /profile the fuq? so it returns what? the location of the player? please tell me what excactly you mean.


    EDIT::

    http://wiki.bukkit.org/HUGE_Plugin_Tutorial
     
  12. Offline

    mista_ninja_3

    I dont copy paste, but thanks. I try to go through the code and understand it. Self taught..
    /profile returns with a series of messages.
     
  13. Offline

    bajsko

  14. Offline

    mista_ninja_3

  15. Offline

    bajsko

    np, hope it helps ;)
     
  16. Offline

    mista_ninja_3

    Code:
    package me.mista.mistaprofile;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class MistaProfileCommandExecutor implements CommandExecutor {
     
        public MistaProfile plugin;
     
        public MistaProfileCommandExecutor(MistaProfile plugin) {
            this.plugin = plugin;
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("mp help")){
            player.sendMessage("oOo__________[MistaProfile Help]__________oOo");
            player.sendMessage("/mp help - Displays this help screen");
            player.sendMessage("/mprofile - Displays your profile");
            player.sendMessage("/mprofile <player_name> - Displayer targetplayers profile");
            player.sendMessage("/mp reload - Reloads MistaProfile");
            player.sendMessage("/mp version - Retreives the current available version");
         
                return true;
                }
        return false;
      }
    }
    
    Code:
    package me.mista.mistaprofile;
     
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class MistaProfile extends JavaPlugin{
       
              public static MistaProfile plugin;
            public final Logger logger = Logger.getLogger("Minecraft");
              private MistaProfileCommandExecutor myExecutor;
             
            @Override
            public void onDisable() {
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info(pdfFile.getName() + " is now disabled!");
            }
         
            @Override
            public void onEnable() {
                PluginDescriptionFile pdfFile = this.getDescription();
                this.logger.info( pdfFile.getName() + " version " + pdfFile.getVersion() + " is now enabled!");
               
                myExecutor = new MistaProfileCommandExecutor(this);
                getCommand("mphelp").setExecutor(myExecutor);
            }
    }
    

    Does this work? Please answer!
     
  17. no, since commands cant have spaces inside it, however bukkit wont throw an error if its found, bukkit commands works like: split the user iput by spaces, the first is the command, send the other part to the arg[] at the command methode
     
  18. Offline

    bajsko

    i havnt tested it but yes, that seems to work in my eyes. go go go
     
  19. Offline

    mista_ninja_3

    Got rid of the spaces and edited everything, and now I am coming up with an error.
    Code:
    rror occurred while enabling MistaProfile v1.0 (Is it up to date?)
    java.lang.NoClassDefFoundError: me/mista/mistaprofile/MistaProfileCommandExecutor
        at me.mista.mistaprofile.MistaProfile.onEnable(MistaProfile.java:25)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:215)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:256)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:238)
        at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:381)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:368)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:197)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:432)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ClassNotFoundException: me.mista.mistaprofile.MistaProfileCommandExecutor
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:41)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 11 more
    
    Something about the CommandExecutor?

    The wiki page really helped! Thanks! Im slowly getting it now :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  20. Offline

    EnvisionRed

  21. java.lang.NoClassDefFoundError: me/mista/mistaprofile/MistaProfileCommandExecutor
    it cant find that class
     
  22. Offline

    bajsko

    if you need more help, just pm me :D
     
  23. Offline

    Kodfod

    You should never ask for help in a PM, help should be done publicly so people don't always have to create a thread about it.
     
  24. Offline

    bajsko

    hah lol... Sure thing dude, will never happen again..
     
  25. Offline

    -_Husky_-

    The error = define the main class (javaplugin one) into the plugin.yml, it cant find the class you put in, :p
     
  26. Offline

    mista_ninja_3

    Thanks for clarifying that! I fixed it :)
    Screen Shot 2012-07-18 at 5.45.56 PM.png
     
Thread Status:
Not open for further replies.

Share This Page