Making a nickname plugin but i get errors

Discussion in 'Plugin Development' started by SillySAKE, Aug 27, 2015.

Thread Status:
Not open for further replies.
  1. I get those things https://gyazo.com/d4cb7d9d1627664d5a64994edf446a38 and i cant fix it

    Code:
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Plugin1 extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public Permission playerPermission = new Permission("Sillynicks.set");
        @Override
        public void onEnable() {
            PluginDescriptionFile pdf = this.getDescription();
            this.logger.info(pdf.getName() + " Is now enabled");
            saveConfig();
            PluginManager pm = getServer().getPluginManager();
            pm.addPermission(playerPermission);
        }
      
        @Override
        public void onDisable() {
            PluginDescriptionFile pdf = this.getDescription();
            this.getLogger().info(pdf.getName() + " Is now disabled");
            saveConfig();
          
        }
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
            if(!p.hasPlayedBefore()){
                getServer().broadcastMessage(ChatColor.AQUA + p.getName() + ChatColor.DARK_AQUA + "has entered the best server!");
            }
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (sender instanceof Player){
                Player p = (Player)sender;
                if(args.length==2){
                    String name = args[0];
                    String newname = args[1];
                    for(Player pl : getServer().getOnlinePlayers()){
                        if(pl.getName().equals(name)){
                            if(getServer().getPlayer(name).isOp()||getServer().getPlayer(name).hasPermission("Sillynicks.set"))
                            getServer().getPlayer(name).setDisplayName(newname);
                        }
                    }
                }
          
                return true;
           
            }
      
            return false;
        }  
      
    }
     
  2. Offline

    teej107

    *facepalm*
    That is not an error. That is just the IDE warning you about something. Maybe you should read what that warning is about.
     
  3. Offline

    meguy26

    A wild BCBroz Watcher has appeared!


    @SillySAKE
    You're code is filled with outdated and bad practices. Fun facts:
    • Bukkit displays enable/disable messages
    • Every plugin has its own logger
    • A plugins's name can be accessed from within the main class
    Anyway, a small picture of a method call does not show us where the error is, on what line in the above code is the error?

    EDIT: For sake of teej:
    Code:
    Post post = this.getContainer();
    String text = post.getText().replaceAll("error", "warning");
    post.setText(text);
    post.update();
     
    Last edited: Aug 27, 2015
    bwfcwalshy likes this.
  4. Offline

    teej107

  5. So all of this is outdated
    i should rewrite the code?
     
  6. Offline

    au2001

    @SillySAKE That would be a good idea yes, and maybe follow a tutorial (not TheBCBroz though).
     
  7. Offline

    meguy26

    teej107 likes this.
  8. The thing is what ever i do i got tons of errors in my console and i don't know why
    i tried rewriting the plugin in a different way it still doesn't work
     
  9. Offline

    timtower Administrator Administrator Moderator

  10. Offline

    timtower Administrator Administrator Moderator

  11. Nvm i got it to work i rewrote it again but now it works :)
    Only prob now is i need to add the color codes
    and i have no clue how? lol noob
     
  12. @SillySAKE
    In messages:
    ChatColor.<COLOR>

    In a config:
    coloured-message: '&aThis is coloured'
    ChatColor.translateAlternateColorCodes('&', getConfig.getString("coloured-message");
     
  13. (colored-message: '&aThis is colored') is that necessary?
    and ("coloured-message"); what it the couloured message suppose to be
     
  14. @SillySAKE It's not necessary, that's just an example. Make it whatever you want and in the ChatColor method make it whatever your config string is.
     
  15. Can you help because the getConfig doesnt work
    This is what i got now:
    Code:
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class SillyNicnames extends JavaPlugin {
       @Override
       public void onEnable() {
         getLogger().info("onEnable has been invoked!");
         PluginManager pm = getServer().getPluginManager();
         pm.addPermission(playerPermission);
       }
       @Override
       public void onDisable() {
         getLogger().info("onDisable has been invoked!");
       }
       public Permission playerPermission = new Permission("nickname.set");
       @Override
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         if (cmd.getName().equalsIgnoreCase("nickname") && sender instanceof Player) {
           Player player = (Player) sender;
           if(player.isOp() || player.hasPermission("nickname.set")){
             if(args.length==1);
             String name = args[0];
             ChatColor.translateAlternateColorCodes('&', getConfig.getString(name));
             player.setCustomName(name);
             player.setDisplayName(name);
             player.sendMessage(ChatColor.GOLD + "Your Nickname has changed");
               }else{
          player.sendMessage(ChatColor.DARK_RED + "You do not have permission to use this command!");
               }
        }  return true;  
     }
    }
     
    Last edited: Aug 28, 2015
  16. Offline

    Gonmarte

Thread Status:
Not open for further replies.

Share This Page