Simple Code

Discussion in 'Plugin Development' started by Dukeletsplay, Dec 20, 2014.

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

    Dukeletsplay

    Is there away to make this code Simple i wrote it along time ago and i believe this code has changed since then or atlessed the layout has.

    Code:
    package me.xOpWarriorx.Example;
    
    import java.util.logging.*;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Youtube extends JavaPlugin{
        public final Logger logger= Logger.getLogger("minecraft");
        public static Youtube plugin;
       
        @Override
        public void onDisable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "Version" + pdfFile.getVersion() + " Has been Disabled");
        }
       
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "Version" + pdfFile.getVersion() +  " Has been Enabled!");
        }
        public boolean onCommand(Command sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("sendme")){
                player.sendMessage(ChatColor.GOLD + "Sent");
            }
            return false;
        }
       
       
       
    }
    
     
  2. Offline

    Experminator

    It's good.
     
  3. Offline

    Dukeletsplay

  4. Offline

    ZackBlazes

    @Dukeletsplay Get rid of the logger, that is not needed with newer versions of Bukkit as Bukkit now does it automatically.

    Is that from TheBCBroz? :p
     
    Dukeletsplay likes this.
  5. Offline

    HeadGam3z

    Code:
    public static Youtube plugin;
    That isn't needed. I also recommend checking if the sender is a player before casting.
     
  6. Offline

    ChipDev

    Did you copy paste this from a youtube video?
    I have read your brain!
     
  7. Offline

    Dukeletsplay

    @ChipDev umm yes but i am starting to code my own stuff... i just search around for references to see if i can make code easier.
     
    ChipDev likes this.
  8. Offline

    ChipDev

    I went through that too :)
     
    VG.Developments likes this.
  9. Offline

    LordZeus

    This is what I recommend:

    - Get rid of the Logger because Bukkit now automatically does that for you.
    - Use "cmd" instead of "command" in line 26

    Code:
    package me.xOpWarriorx.Example;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Youtube extends JavaPlugin{
      
        @Override
        public void onDisable(){
    
        }
      
        @Override
        public void onEnable(){
        }
        public boolean onCommand(Command sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(cmd.equalsIgnoreCase("sendme")){
                player.sendMessage(ChatColor.GOLD + "Sent");
            }
            return false;
        }
      
      
      
    }
     
  10. Offline

    teej107

    And this is what I recommend:
    Stop watching BCBroz. They're tutorials are outdated, awful and poorly coded.
     
    VG.Developments, LordZeus and Skionz like this.
  11. Offline

    HeadGam3z

    Little issue...

    Also, you don't need to make the sender a player. Just send the message to the sender. Consoles like messages, too!
     
    teej107 likes this.
  12. Offline

    teej107

    Also consoles don't like being casted to a player.
     
  13. Offline

    Skionz

    @Dukeletsplay As I said before my post was removed for 'Inappropriate Behavior,' don't use static, don't use minecraft's logger, don't log enable and disable messages, use the instanceof keyword to check if the sender is a player before casting, and use constructors to pass your main instance to other classes (in the future).
     
  14. Offline

    Dukeletsplay

    @Skionz I am sorry its my falt i am new to this. please forgive me i was mad at the time.
     
    Skionz likes this.
Thread Status:
Not open for further replies.

Share This Page