[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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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!


    This post has been edited 5 times. It was last edited by insanj Aug 13, 2011.
  2.  
  3. Offline

    codename_B

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You aren't registering the commands for each item - so that's a major issue.
  4. Offline

    insanj

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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().
  5. Offline

    codename_B

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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
  6. Offline

    insanj

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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
  7. Offline

    codename_B

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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!

    This post has been edited 1 time. It was last edited by codename_B Aug 12, 2011.
  8. Offline

    insanj

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    It doesn't. If the plugin recognizes that the command is for the plugin, it cancels the event, getting rid of that message.
  9. Offline

    codename_B

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.
  10. Offline

    insanj

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.
  11. Offline

    SwearWord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME

    This post has been edited 1 time. It was last edited by SwearWord Aug 12, 2011.
  12. Offline

    codename_B

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You could get rid of the playerCommandPreProcess event even!
  13. Offline

    codename_B

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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;
        }
    
    }
    
  14. Offline

    insanj

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.

    This post has been edited 6 times. It was last edited by insanj Aug 12, 2011.
  15. Offline

    codename_B

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.

    This post has been edited 1 time. It was last edited by codename_B Aug 12, 2011.
  16. Offline

    SwearWord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Are you kidding me. Givings the user error messages is a must.
    RugRats likes this.
  17. Offline

    Rich Boos

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Can this discussion be taken to github?
  18. Offline

    insanj

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.

    This post has been edited 2 times. It was last edited by insanj Aug 13, 2011.
  19. Offline

    insanj

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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!

Share This Page