[ADMN] LiteSpwnr v1.1 - The Easiest, Most Lightweight Item Spawner That Exists [1317]

Discussion in 'Inactive/Unsupported Plugins' started by insanj, Aug 12, 2011.

  1. Offline

    insanj

    LiteSpwnr - The Most Lightweight Item Spawner Ever Created!
    Version: 1.1

    Easy to use, elegantly simple. Just type in an item id, as if it was a command, and get a stack of that item. Type in an item id and an amount, get that amount. All added instantly to your inventory.
    Example: /5 or /5 300

    Features:
    • Spawn items in an instant by typing in the id, or the id and the amount. (/5 or /5 300)
    Download LiteSpwnr!
    Source!

     
  2. Offline

    codename_B

    You aren't registering the commands for each item - so that's a major issue.
     
  3. Offline

    insanj

    I'm not sure why you're not okay with this, but there would be no way to make this plugin and register the commands using the YAML/onCommand().
     
  4. Offline

    codename_B

    Yes there would be - you can register commands without having them in the YAML - you could for example register a command executor in a for loop through all the item ids. If you want me to code it for you, I can do - but obviously you'd have to give credit :p
     
  5. Offline

    insanj

    That seems entirely overcomplicated. If you take a look at the code I have right now, I'm digging it, and think it's fine. If there is an issue with registering commands using onPlayerCommandPreprocess(), let me know, and then I'll tweak it. :O
     
  6. Offline

    codename_B

    The fact it returns command not recognised when people type the command since you're not registering it?

    EDIT: My bad, I didn't see this bit.
    Code:
            try
            {
                if(message.length > 1)
                {
                    event.getPlayer().getInventory().addItem(new ItemStack[] {
                        new ItemStack(Integer.parseInt(message[0].substring(1)), Integer.parseInt(message[1]))
                    });
                } else
                {
                    event.getPlayer().getInventory().addItem(new ItemStack[] {
                        new ItemStack(Integer.parseInt(message[0].substring(1)), 64)
                    });
                }
                event.setCancelled(true);
            }
            catch(Exception exception) { }
            return;
        }
    
    Still, it seems like a really hacky way of doing it to me - and you're causing all those exceptions which you're just casually discarding!
     
  7. Offline

    insanj

    It doesn't. If the plugin recognizes that the command is for the plugin, it cancels the event, getting rid of that message.
     
  8. Offline

    codename_B

    I edited my above post - you're generating a lot of exceptions and just discarding them without even printing an error message. Admittedly you don't need to in this case but it's REALLY bad practise to have that kind of exception be generated on EVERY command.
     
  9. Offline

    insanj

    Any exceptions that I can see that would pass through that code sequence would not apply to this plugin, which is why there aren't any error messages- because anything that causes and error in this case wouldn't really apply. Also, I said this is an extremely lightweight plugin, if I were to expand on it so much, it would just be another average spawner, no better than the default commands. If an Admin doesn't approve of the contiuous try/catch at every command, then I guess they'll just have to live without this plugin.

    Footnote: I normally try to make my plugins as efficient and well coded as can be (with the exception of my first plugin, the replicator), this was just a kind of spur-of-the-moment idea that I had.
     
  10. Offline

    SwearWord

  11. Offline

    codename_B

    You could get rid of the playerCommandPreProcess event even!

    @insanj I even made a start for you - let me know if you need more coded.
    Code:
    class SpwnrCommandExec implements CommandExecutor {
    	@Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (sender instanceof Player) {
    		Player player = (Player) sender;
    		if( args.length > 2) {
    			player.sendMessage("Too many arguments!");
    			return true;
    		}
    		int[] iargs = new int[args.length+1];
    		try {
    			for(int i=0; i<=args.length; i++)
    				if(i == 0)
    				iargs[i] = Integer.parseInt(command.getName());
    				else
    				iargs[i+1] = Integer.parseInt(args[i]);
    		}
    		catch (Exception e) {
    		player.sendMessage("Incorrectly formatted command");
    		System.err.println(player.getName()+" cannot type properly!");
    		return true;
    		}
    			if( args.length > 1 )
    				player.getInventory().addItem(new ItemStack(iargs[0], iargs[1]));
    			else
    				player.getInventory().addItem(new ItemStack(iargs[0], 64));
    		}
            else {
                sender.sendMessage("Only players can use these commands!");
            }
            return true;
        }
    
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  12. Offline

    insanj

    No offense, but, ew. I just can't get used to that code, I personally feel like my way of implementing this is easier to understand and somehow better. Also, most of those error messages to the player would be really annoying, because you could type in "/time set 0" and get a glaring error, even though the plugin and that command aren't related, and there wasn't an error at all.


    Is blockface just another plugin reposistory? Never heard of it! What's it's deal?
    Also, I'm saying lightweight == easy to use, hardly any commands, faster than using default commands.
     
  13. Offline

    codename_B

    What if I wrote in a configuration option to let people choose between the different ways of handling things?
    Throwing exceptions on every single command is really, really, really TERRIBLE practise. Please listen, you're far better writing code that doesn't need to throw exceptions.
    Basically - if you don't fix your code - I'll release my rewritten code as a new plugin.
     
  14. Offline

    SwearWord

    Are you kidding me. Givings the user error messages is a must.
     
    RugRats likes this.
  15. Offline

    Rich Boos

    Can this discussion be taken to github?
     
  16. Offline

    insanj

    Uh... why?

    Okay, okay, jeez. I'll add in some error messages... just thought it would be nice to introduce a new kind of lightweight plugin without people getting extremely defensive and threatening to steal ideas rewritten.


    Okay everyone! After slaving for a little while, I introduced a lot of new code, and pretty much rewrote the plugin from the ground up. There are still a few things here and there I'm sure all of us would prefer different, but I'm downright satisfied with how it turned out. There is more checking, a few error messages, and a lot more tests to make sure things don't get just thrown away for no particular reason. Also, I added a ton of comments and such, so everyone knows my thought process behind everything.

    As a final comment: Sorry that I got so agressive before. Really, I was obnoxiously proud of my plugin, and was just ignorant and raging for no good reason. Now that I've had some deep breaths, a delicious bowl of popcorn, and some downtime, I realize that I was plain old stupid... and almost all of the points you guys made up above were valid and true. I'm especially sorry to codename_B, because I know he's such an awesome guy, and was just trying to help- and doing a damn good job at it too- and I never even got to repay him for helping me on the IRC before, and now I did the equivalent of slapping him in the face.

    Enjoy! The source link is all updated as well!

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

Share This Page