Command args

Discussion in 'Spigot Plugin Development' started by bronzzze, May 8, 2015.

  1. I crated method

    Code (Text):
    public GiveBomb(Main main, Player p, String args) {
            this.p = p;
            this.args = args;
            this.main = main;
         
         
         
            is = new ItemStack(Material.getMaterial(main.getConfig().getInt(
                    "CustomBombs." + args + ".id")));
            is.hasItemMeta();
            is.getItemMeta().hasDisplayName();
            ItemMeta itemmeta = is.getItemMeta();
            itemmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&' , main.getConfig().getString("CustomBombs." + args + ".name")));
            List<String> converted = new ArrayList<String>();
            for (String s : main.getConfig().getStringList(
                    "CustomBombs." + args + ".lore")) {
                converted.add(ChatColor.translateAlternateColorCodes('&', s));
            }
            itemmeta.setLore(converted);
            is.setItemMeta(itemmeta);
            p.getInventory().addItem(is);
         

        }
     
    }
    Then on command
    Code (Text):
          if(args.length == 1){
           new GiveBomb(main, p, args[0]);
         }
     


    Everything is working perficly fine but problem is when I reload, Server forget args[0](what is usally), but how could I save this args[0] So I can get ItemStack.

    After reload this rightclick Event is not working anymore unless I use command again:
    Code (Text):
    if (hand != null && hand.isSimilar(GiveBomb.is)) {
    ...
    }
     
  2. Set the args to a config. So create a path argsplayers.UUID.args[0]
    And then you can save for each player (UUID) his args[0]
     
  3. So do I use hashmap to save it in config?
    I am not sure where to add this path? Under command or what?
     
    #3 bronzzze, May 14, 2015
    Last edited: May 14, 2015
  4. Anyone know how could I set args[0] , UUID to config I am not sure what to do.
     
    • Make a config and set the path to players.(uuid).args , and set the value to null. (JoinEvent)
    • If the player set the args save it to the config under his UUID.
    • When you need it , get the config under his uuid, and you have the args.
     
    • Like Like x 1
  5. Ty dude gonna try to do this. I think I understand now
     
  6. Problem is. If they get this bomb from other players and not command(args[0]) it will not work?
     
  7. Then can you store it per user? Or make a little unique id in a Map for each item?
     
  8. So something like this?
    Code (Text):
        public HashMap<UUID, String> configargs = new HashMap<UUID, String>();
     
    Code (Text):
        @EventHandler
        public void onJoin(PlayerJoinEvent e){
            Player p = (Player) e.getPlayer();
            main.configargs.put(p.getUniqueId(), main.givebomb.args);
           
           
           
        }
     
     
  9. Then use the otherplayer and what he set as args[0] , check first if it is null, if so you can send him a message
     
  10. No you didn't.
    You should create a method, but instead you created a new class, which isn't correct and should be undone.

    Why do you store all the things? You only need them in this constructor. In fact, you see, you don't need the entire class....

    This two calls do nothing! They're pointless and show that you don't understand what you're doing and that you're lacking basic java knowledge.

    Seems like GiveBomb.is is static. This shows how static is used simple wrong. Not the reload is the problem here, it's your usage of static. If two or more people use your command your plugin will break.

    I highly suggest you learn a bit more java, the language of bukkit plugins before trying to make a plugin.
     
  11. @Coder
    I am pretty sure when server reload the args are lost


    What's wrong with using new class? Its pretty small plugin so I created new class I dont know what is wrong with this.
    No I dont need it in only consturctor... I neeed this args in other class


    I changed this already I was only testing this beacuse if(is.hasItemMeta()).


    This wrote this wrong beacuse I didn't copy it exactly from eclipse I was just typing on phone. Its not static I made like this
    Code (Text):
        GiveBomb givebomb;
        @Override
        public void onEnable() {
            givebomb = new GiveBomb(this);
    }
    Code (Text):
    main.givebomb.is
     
    #12 bronzzze, May 19, 2015
    Last edited: May 19, 2015