[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


    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

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

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


    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. 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


    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. 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 (Text):
    2.         try
    3.         {
    4.             if(message.length > 1)
    5.             {
    6.                 event.getPlayer().getInventory().addItem(new ItemStack[] {
    7.                     new ItemStack(Integer.parseInt(message[0].substring(1)), Integer.parseInt(message[1]))
    8.                 });
    9.             } else
    10.             {
    11.                 event.getPlayer().getInventory().addItem(new ItemStack[] {
    12.                     new ItemStack(Integer.parseInt(message[0].substring(1)), 64)
    13.                 });
    14.             }
    15.             event.setCancelled(true);
    16.         }
    17.         catch(Exception exception) { }
    18.         return;
    19.     }
    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


    It doesn't. If the plugin recognizes that the command is for the plugin, it cancels the event, getting rid of that message.
  8. 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


    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


  11. 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 (Text):
    2. class SpwnrCommandExec implements CommandExecutor {
    3.     @Override
    4.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    5.         if (sender instanceof Player) {
    6.         Player player = (Player) sender;
    7.         if( args.length > 2) {
    8.             player.sendMessage("Too many arguments!");
    9.             return true;
    10.         }
    11.         int[] iargs = new int[args.length+1];
    12.         try {
    13.             for(int i=0; i<=args.length; i++)
    14.                 if(i == 0)
    15.                 iargs[i] = Integer.parseInt(command.getName());
    16.                 else
    17.                 iargs[i+1] = Integer.parseInt(args[i]);
    18.         }
    19.         catch (Exception e) {
    20.         player.sendMessage("Incorrectly formatted command");
    21.         System.err.println(player.getName()+" cannot type properly!");
    22.         return true;
    23.         }
    24.             if( args.length > 1 )
    25.                 player.getInventory().addItem(new ItemStack(iargs[0], iargs[1]));
    26.             else
    27.                 player.getInventory().addItem(new ItemStack(iargs[0], 64));
    28.         }
    29.         else {
    30.             sender.sendMessage("Only players can use these commands!");
    31.         }
    32.         return true;
    33.     }
    35. }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 18, 2016
  12. Offline


    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. 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


    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


    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