Filled Rocket

Discussion in 'Plugin Requests' started by patricksterza, Feb 9, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    I Al Istannen

    @Irantwomiles
    Getting a random Type is easy. The class "FireworkEffect.Type" is a special one, an "enum". If you don't know what that is, google it! This means we have access to the "Enum#values()" method, which is available in EVERY enum. This method returns all the enum entries. So for the type, it would return (after beeing formatted, it is an array)
    Code:
    [BALL, BALL_LARGE, STAR, BURST, CREEPER]
    Now we have all the different types it can have in one array. This is just perfect, as we can now grab one of them. To do this, we create a random number (e.g. via a "Random" object or by using "Math#random()") between 0 (it is an array) and the array#length - 1 (INCLUSIVE, meaning you can get 0 and you can get array#length - 1). The minus one is also for the counting mechanism, as it counts from 0 on. We than use the entry from the array we got using the "values()" method at the index of the random number we calculated. This is the type we use.

    So it would look like this:
    Code:
    array with types = FireworkEffects.Type.values()
    int index = random number between 0 and types.length - 1 (inclusive)
    Type = types[index]
    
    Be happy with your random type
    For the color it gets trickier. The class "Color" is no enum, but a regular class. We can't use the "values()" method here. There are multiple options, but I will settle for the easiest, most understandable one I can think of :)
    By simply counting the Variables in the Color class (for example on the JavaDoc or with your IDE) we will find out, that there are 17 colors defined. Now we will create a different private method, returning a Color object for a number between 0 and 16. This is achieved by using a switch statement for the input:
    Code:
    private Color getColor(int index) {
      switch(index) {
      case 0: {
        return Color.AQUA;
      }
      case 1: {
        return Color.BLACK;
      }
      ...
      }
    }
    Then we use the same method as above. We create a new random number between 0 and 16 (INCLUSIVE). The 16 is because that is the last possible color we can get. Than we save the result from "getColor(random number)" in a variable and that is it. You can repeat getting a random color as long as you like, resulting in more colors on the firework. You can apply other random colors to the fade too.
    With a (Random.nextBoolean()) you can decide if you want to use flicker, trail, ... . Just toy around with it!

    I think you know how to apply it to a Firework, if not the JavaDoc of Firework and FireworkMeta and FireworkEffect are quite handy.
     
    patricksterza likes this.
  2. Offline

    patricksterza

    @I Al Istannen Could you code it? Could you make it? I don't know how to code...
     
  3. Offline

    I Al Istannen

    @patricksterza Does this suit your needs?
    The permissions are "rocket.use" and "rocket.bypassCooldown", the commands are "/rocket" and "/foguete", but more can be added in the config. You can remove the foguete command, but the "/rocket" is permanent. The firwork will be fully random, however you can change some things in the config.

    Link: DropBox
     
    patricksterza likes this.
  4. Offline

    patricksterza

    Thank you so much
    @I Al Istannen God bless yoy buddy

    EDIT: Could you make me a change please? Make a new command like /rocket + amount
    Like: /rocket 10 (will launch 10 fireworks).
    Permission: rocket.use.number or rocket.use.amount
     
    Last edited: Feb 28, 2016
  5. Offline

    I Al Istannen

    @patricksterza
    I will look into it tomorrow. The system with permissions is really inconvenient for what you though of. I will see if I can make it work with the permissions. The only method I know of checks if the player has a permission, so I would have to check every permission from the number on upwards.
     
  6. Offline

    pie_flavor

    @I Al Istannen Permissible#getEffectivePermissions()
    Also, are you sure you read that correctly? Maybe the permission is literally just rocket.use.amount, and you can then use any custom amount if you have the permission
     
  7. Offline

    patricksterza

  8. Offline

    I Al Istannen

    @patricksterza Just redownload it from the link. Amount is capped at 100, to reduce the iterations in the loop (there is a limit for particles anyways).

    You need to delete your config (consider backing it up before) in order for the new settings and messages to appear.
     
    patricksterza likes this.
  9. Offline

    patricksterza

    @I Al Istannen Thanks man, i will test it out now...
    One question tho... If i do /rocket 9 (will it launch 9 rockets?)

    By the way i do not understand the "amount is capped at 100" what do you mean by that, i didn't get it :p?

    EDIT: As i mentioned the permission for launching the /rocket 10 (Amount) what would be the permission for that command? Sorry...
     
  10. Offline

    I Al Istannen

    @patricksterza
    Sorry, was away.

    Permission:
    rocket.use.amount. So for 9 it would be "rocket.use.9".

    And yes, it will just launch 9 rockets:
    Code:
    for(int i = 0; i < amount; i++) {      
      Firework firework = (Firework) p.getWorld().spawnEntity(p.getEyeLocation(), EntityType.FIREWORK);
      setRandomFireworkMeta(firework);
    }
    For capped at 100:
    Code:
    for(int i = amount; i <= 100; i++) {
      if(p.hasPermission("rocket.use." + i)) {
        found = true;
        break;
      }
    }
    It checks for the permission "rocket.use.i", where i is increasing up to 100. So /rocket 101 wouldn't work, as it doesn't check that high. That means you can't spawn more than 100 rockets with one command.

    EDIT:
    Just realized a logic error in a loop... . Please redownload it from the link. You don't need to change anything, apart from the Jar file.
    DropBox (same as somwhere above)
     
    patricksterza likes this.
  11. Offline

    pie_flavor

    @I Al Istannen Again, are you sure that the permission wasn't meant to be literally 'rocket.use.number', not 'rocket.use.<i>', and that just allows them to do any number?
     
  12. Offline

    patricksterza

    Ok buddy...
    So what's up with the permission rocket.use.i i didn't get it tho...
    What does it means? What does it do?
     
  13. Offline

    I Al Istannen

    @pie_flavor

    No, i am not :)


    @patricksterza
    To die flavors question, do you want the permission rocket.use.number to allow the user to launch any amount oft rockers, or do you want him to be only able to launch <number> rockers. Right now thr user has the peemission rocket.use.50 and can launchup to 50 rockers, a user withtl the permission rocket.use.10 csn launch up to 10 and so on.

    EDIT: [sic!] Written from a phone... :D
     
    Last edited: Mar 1, 2016
    patricksterza likes this.
  14. Offline

    patricksterza

    @I Al Istannen Its fine this way buddy, thank you so much. Thanks alot have a wonderful day.
     
  15. Offline

    I Al Istannen

Thread Status:
Not open for further replies.

Share This Page