Code Monkey home page Code Monkey logo

Comments (2)

Spitz4478 avatar Spitz4478 commented on July 26, 2024

That's an easy one... in MobPlugin.onCommand() method under case "spawn" the first line is String mob = args[1]; But nothing in the previous code ever verified there actually is an args[1] - only args[0] is checked.

from mobplugin.

Spitz4478 avatar Spitz4478 commented on July 26, 2024

Super simple fix would be to add:
if (args.length == 1) { commandSender.sendMessage("/mob spawn <mob> <opt:player> - Spawn a mob"); break; }
right at the beginning of case "spawn" to give them a syntax hint and avoid the outofbounds error.

But that fix ignores all the other potential failure cases when a user enters a /mob command. And speaking in more general terms, it's going to be a difficult to read switch case as you add more commands later.

It may be better to move the code block that gives the player the proper syntax for /mob commands into it's own method. Then have the various cases in MobPlugin.onCommand(), including default, call that method if they run into cases where args[0] is not a valid command or args.length is not the correct size for the command.

And you may even consider moving the code for each switch case into their own methods for readability reasons.

from mobplugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.