MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Commande inutilisable

    Planifier Épinglé Verrouillé Déplacé Résolu 1.12.x
    1.12.2
    12 Messages 2 Publieurs 441 Vues 2 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • robin4002R Hors-ligne
      robin4002 Moddeurs confirmés Rédacteurs Administrateurs
      dernière édition par

      Bonsoir,
      Quel est la ligne 31 ? (comme tu n’as pas mis les importations, elles ne correspondent pas avec ce qui est affiché).

      FeedBackF 1 réponse Dernière réponse Répondre Citer 1
      • FeedBackF Hors-ligne
        FeedBack @robin4002
        dernière édition par

        @robin4002 Désolé ^^

        Voici toute la class

        package com.drastic.redskyll.commands;
        
        import java.util.List;
        
        import com.drastic.redskyll.util.interfaces.IMoney;
        import com.drastic.redskyll.util.provider.MoneyProvider;
        import com.google.common.collect.Lists;
        
        import net.minecraft.command.CommandBase;
        import net.minecraft.command.CommandException;
        import net.minecraft.command.ICommandSender;
        import net.minecraft.entity.player.EntityPlayer;
        import net.minecraft.entity.player.EntityPlayerMP;
        import net.minecraft.server.MinecraftServer;
        import net.minecraft.util.math.BlockPos;
        import net.minecraft.util.text.TextComponentString;
        import net.minecraft.util.text.TextFormatting;
        
        public class CommandMoney extends CommandBase
        {
            private final List<String> aliases = Lists.newArrayList("eco", "money", "purse");
        
            @Override
            public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
            {
        
                EntityPlayerMP player = (EntityPlayerMP)sender;
        
                String s = args[0];
        
                if(player instanceof EntityPlayer)
                {
                    IMoney money = (player).getCapability(MoneyProvider.MONEY_CAP, null);
        
                    System.out.println(args[0]);
                    System.out.println(args[1]);
                    System.out.println(args[2]);
        
                    if(s == null)
                    {
                        sender.sendMessage(new TextComponentString(TextFormatting.GREEN + (money.getMoney() + "$")));
                    }
                    else
                    {
                        if(s == "give")
                        {
                            if(args[1] == null)
                            {
                                player.sendMessage(new TextComponentString(TextFormatting.RED + "Format Incorrect"));
                            }
                            else
                            {
                                money.addMoney(Integer.parseInt(args[1]));
                            }
                        }
        
                        else if(s == "remove")
                        {
                            if(args[1] == null)
                            {
                                player.sendMessage(new TextComponentString(TextFormatting.RED + "Format Incorrect"));
                            }
                            if(args[2] != null)
                            {
                                money.shrinkMoney(Integer.parseInt(args[1]));
                            }
        
                        }
                    }
                }
            }
        
            @Override
            public String getName()
            {
                return "money";
            }
        
            @Override
            public String getUsage(ICommandSender sender)
            {
                return "money (give/remove) (count)";
            }
        
            @Override
            public List<String> getAliases()
            {
                return aliases;
            }
        
            @Override
            public boolean checkPermission(MinecraftServer server, ICommandSender sender)
            {
                return true;
            }
        
            @Override
            public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos)
            {
                return java.util.Collections.EMPTY_LIST;
            }
        
        }
        
        
        1 réponse Dernière réponse Répondre Citer 0
        • robin4002R Hors-ligne
          robin4002 Moddeurs confirmés Rédacteurs Administrateurs
          dernière édition par

          Ton code a changé depuis que tu as eu le rapport de crash ? Car je ne vois pas comment tu peux avoir un ArrayIndexOutOfBoundsException sur ta ligne 31 sachant qu’il n’y a aucune array à cette ligne.
          Cela semble plutôt être la ligne 29 :

                  String s = args[0];
          

          Et si tu as cette erreur, c’est probablement car tu n’as pas mis d’argument lorsque tu as tapé ta commande.

          FeedBackF 1 réponse Dernière réponse Répondre Citer 1
          • FeedBackF Hors-ligne
            FeedBack @robin4002
            dernière édition par

            @robin4002 pas possible de rendre des arguments non obligatoires ?

            1 réponse Dernière réponse Répondre Citer 0
            • robin4002R Hors-ligne
              robin4002 Moddeurs confirmés Rédacteurs Administrateurs
              dernière édition par

              Si, pour cela il faut que tu adapte ton code.

              Il faut commencer avec un if sur args.length et ensuite tu adapte ta logique en fonction du nombre d’arguments.

              FeedBackF 1 réponse Dernière réponse Répondre Citer 1
              • FeedBackF Hors-ligne
                FeedBack @robin4002
                dernière édition par

                @robin4002 j’ai modifié mon code mais maintenant le jeu me met toujours “format incorrect” quel que sois le premier arg

                package com.drastic.redskyll.commands;
                
                import java.util.List;
                
                import com.drastic.redskyll.util.interfaces.IMoney;
                import com.drastic.redskyll.util.provider.MoneyProvider;
                import com.google.common.collect.Lists;
                
                import net.minecraft.command.CommandBase;
                import net.minecraft.command.CommandException;
                import net.minecraft.command.ICommandSender;
                import net.minecraft.entity.player.EntityPlayer;
                import net.minecraft.entity.player.EntityPlayerMP;
                import net.minecraft.server.MinecraftServer;
                import net.minecraft.util.math.BlockPos;
                import net.minecraft.util.text.TextComponentString;
                import net.minecraft.util.text.TextFormatting;
                
                public class CommandMoney extends CommandBase
                {
                    private final List<String> aliases = Lists.newArrayList("eco", "money", "purse");
                
                    @Override
                    public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
                    {
                
                        EntityPlayerMP player = (EntityPlayerMP)sender;
                
                        if(player instanceof EntityPlayer)
                        {
                            IMoney money = (player).getCapability(MoneyProvider.MONEY_CAP, null);
                
                            if(args.length == 0)
                            {
                                sender.sendMessage(new TextComponentString(TextFormatting.GREEN + (money.getMoney() + "$")));
                            }
                            else
                            {
                                if(args[0] == "give")
                                {
                                    if(args.length < 2)
                                    {
                                        player.sendMessage(new TextComponentString(TextFormatting.RED + "Format Incorrect"));
                                    }
                                    else if(args.length == 2)
                                    {
                                        money.addMoney(Integer.parseInt(args[1]));
                                    }
                                }
                
                                else if(args[0] == "remove")
                                {
                                    if(args.length == 1)
                                    {
                                        player.sendMessage(new TextComponentString(TextFormatting.RED + "Format Incorrect"));
                                    }
                                    else if(args.length == 2)
                                    {
                                        money.shrinkMoney(Integer.parseInt(args[1]));
                                    }
                
                                }
                                else
                                {
                                    player.sendMessage(new TextComponentString(TextFormatting.RED + "Format Incorrect"));
                                }
                            }
                        }
                    }
                
                    @Override
                    public String getName()
                    {
                        return "money";
                    }
                
                    @Override
                    public String getUsage(ICommandSender sender)
                    {
                        return "/money [action] [count]";
                    }
                
                    @Override
                    public List<String> getAliases()
                    {
                        return aliases;
                    }
                
                    @Override
                    public boolean checkPermission(MinecraftServer server, ICommandSender sender)
                    {
                        return true;
                    }
                
                    @Override
                    public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos)
                    {
                        return java.util.Collections.EMPTY_LIST;
                    }
                
                }
                
                1 réponse Dernière réponse Répondre Citer 0
                • robin4002R Hors-ligne
                  robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                  dernière édition par

                  Est-ce qu’il y a une erreur dans la console ?

                  FeedBackF 2 réponses Dernière réponse Répondre Citer 0
                  • FeedBackF Hors-ligne
                    FeedBack @robin4002
                    dernière édition par

                    @robin4002 non

                    1 réponse Dernière réponse Répondre Citer 0
                    • FeedBackF Hors-ligne
                      FeedBack @robin4002
                      dernière édition par

                      @robin4002 il détecte pas que c’est le bon texte

                      1 réponse Dernière réponse Répondre Citer 0
                      • FeedBackF Hors-ligne
                        FeedBack
                        dernière édition par

                        C’est bon !
                        Voici le code ^^

                        package com.drastic.redskyll.commands;
                        
                        import java.util.List;
                        
                        import com.drastic.redskyll.util.interfaces.IMoney;
                        import com.drastic.redskyll.util.provider.MoneyProvider;
                        import com.google.common.collect.Lists;
                        
                        import net.minecraft.command.CommandBase;
                        import net.minecraft.command.CommandException;
                        import net.minecraft.command.ICommandSender;
                        import net.minecraft.entity.player.EntityPlayer;
                        import net.minecraft.entity.player.EntityPlayerMP;
                        import net.minecraft.server.MinecraftServer;
                        import net.minecraft.util.math.BlockPos;
                        import net.minecraft.util.text.TextComponentString;
                        import net.minecraft.util.text.TextFormatting;
                        
                        public class CommandMoneyGive extends CommandBase
                        {
                            private final List<String> aliases = Lists.newArrayList("eco", "money", "purse");
                        
                            @Override
                            public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
                            {
                        
                                EntityPlayerMP player = (EntityPlayerMP)sender;
                        
                                if(player instanceof EntityPlayer)
                                {
                                    IMoney money = (player).getCapability(MoneyProvider.MONEY_CAP, null);
                        
                                    if(args.length == 0)
                                    {
                                        sender.sendMessage(new TextComponentString(TextFormatting.GREEN + (money.getMoney() + "$")));
                                    }
                                    else
                                    {
                                        System.out.println(args[0]);
                        
                                        if("give".equalsIgnoreCase(args[0]))
                                        {
                                            if(args.length < 2)
                                            {
                                                player.sendMessage(new TextComponentString(TextFormatting.RED + "Format Incorrect, utilisez la commande comme ça : /money give <nombre>"));
                                            }
                                            else if(args.length == 2)
                                            {
                                                try
                                                {
                                                    money.addMoney(Integer.parseInt(args[1]));
                                                    sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Vous venez de recevoir " + args[1] + "$"));
                                                }
                                                catch(NumberFormatException e)
                                                {
                                                    sender.sendMessage(new TextComponentString(TextFormatting.RED + "Chiffre incorrect"));
                                                }
                                            }
                                        }
                                        else if("remove".equalsIgnoreCase(args[0]))
                                        {
                                            if(args.length == 1)
                                            {
                                                player.sendMessage(new TextComponentString(TextFormatting.RED + "Format Incorrect, utilisez la commande comme ça : /money remove <nombre>"));
                                            }
                                            else if(args.length == 2)
                                            {
                                                try
                                                {
                                                    money.shrinkMoney(Integer.parseInt(args[1]));
                                                    sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Vous venez de perdre " + args[1] + "$"));
                                                }
                                                catch(NumberFormatException e)
                                                {
                                                    sender.sendMessage(new TextComponentString(TextFormatting.RED + "Chiffre incorrect"));
                                                }
                        
                                            }
                        
                                        }
                                        else
                                        {
                                            player.sendMessage(new TextComponentString(TextFormatting.RED + "Format Incorrect"));
                                        }
                                    }
                                }
                            }
                        
                            @Override
                            public String getName()
                            {
                                return "money";
                            }
                        
                            @Override
                            public String getUsage(ICommandSender sender)
                            {
                                return "/money [action] [count]";
                            }
                        
                            @Override
                            public List<String> getAliases()
                            {
                                return aliases;
                            }
                        
                            @Override
                            public boolean checkPermission(MinecraftServer server, ICommandSender sender)
                            {
                                return true;
                            }
                        
                            @Override
                            public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos)
                            {
                                return java.util.Collections.EMPTY_LIST;
                            }
                        
                        }
                        
                        
                        1 réponse Dernière réponse Répondre Citer 0
                        • robin4002R Hors-ligne
                          robin4002 Moddeurs confirmés Rédacteurs Administrateurs
                          dernière édition par

                          Attention par contre, au début de ta fonction execute il faut faire le cast après le check d’instance, comme ceci :

                                  if(player instanceof EntityPlayerMP)
                                  {
                                      EntityPlayerMP player = (EntityPlayerMP)sender;
                          

                          Sinon tu vas avoir une erreur si tu utilises la commande depuis la console du serveur.

                          1 réponse Dernière réponse Répondre Citer 0
                          • 1 / 1
                          • Premier message
                            Dernier message
                          Design by Woryk
                          ContactMentions Légales

                          MINECRAFT FORGE FRANCE © 2024

                          Powered by NodeBB