Solved Getting The Player That Joined

Discussion in 'Plugin Development' started by Reptar_, Mar 13, 2013.

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

    Reptar_

    So after replicating the fireworks plugin made by theBCBroz on YouTube, I decided I wanted to extend it and make it more unique. Basically, I want the player who join (and has a certain permission) to shoot a random firework above their head. The only problem is, in the video, he shows you how to shoot a firework over all online players' using (Player player : Bukkit.getOnlinePlayers()). I just want it to shoot over the player who just joined. How can I get that player?

    Here's my code:
    http://pastebin.com/kH9mz7vZ

    Thanks for any help!
     
  2. event.getPlayer()

    Edit: Oh I see you've already done that. Just pass player as an argument to shootFireworks()

    So like this
    Code:
    shootFireworks(player); 
    Code:
    public void shootFireworks(Player player) { 
     
    Reptar_ likes this.
  3. Offline

    LaxWasHere

    @EventHandler
    public void onPlayerjoin(PlayerJoinEvent event) {
    Player p = event.getPlayer();
     
  4. Offline

    Burnett1

    Modified it to your needs. Also if u want to have some fun you can put this line below "fw.setFireworkMeta(fm);" "fw.setPassenger(p);"


    Code:
    @EventHandler
            public void playerJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
         
                Firework fw = (Firework) p.getWorld().spawn(p.getLocation(), Firework.class);
                FireworkMeta fm = fw.getFireworkMeta();
                Random r = new Random();
             
                int fType = r.nextInt(5) + 1;
                Type type = Type.BALL;
                switch (fType){
                default:
                case 1:
                    type = Type.BALL;
                    break;
                case 2:
                    type = Type.BALL_LARGE;
                    break;
                case 3:
                    type = Type.BURST;
                    break;
                case 4:
                    type = Type.STAR;
                    break;
                case 5:
                    type = Type.CREEPER;
             
                }
             
                int c1i = r.nextInt(17) + 1;
                int c2i = r.nextInt(17) + 1;
                Color c1 = getColor(c1i);
                Color c2  = getColor(c2i);
                FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
                fm.addEffect(effect);
                int power = r.nextInt(2) + 1;
             
                fm.setPower(power);
                fw.setFireworkMeta(fm);
             
            }
         
         
            public Color getColor(int c){
                switch (c){
                case 1:return Color.BLACK;
                case 2:return Color.AQUA;
                case 3:return Color.BLUE;
                case 4:return Color.FUCHSIA;
                case 5:return Color.GRAY;
                case 6:return Color.GREEN;
                case 7:return Color.LIME;
                case 8:return Color.MAROON;
                case 9:return Color.NAVY;
                case 10:return Color.OLIVE;
                case 11:return Color.ORANGE;
                case 12:return Color.PURPLE;
                case 13:return Color.RED;
                case 14:return Color.SILVER;
                case 15:return Color.TEAL;
                case 16:return Color.WHITE;
                case 17:return Color.YELLOW;
                 
                }
                return null;
             
            }
     
    Reptar_ likes this.
  5. Offline

    Reptar_

    TfT_02
    Thanks a lot! Works perfectly! :D

    Where exactly would I put those two lines?

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

    Burnett1

    No u put setPassenger after fw.setFireworkMeta
     
  7. Offline

    Reptar_

    My bad. xP I misread your post.
     
  8. Offline

    Burnett1

    Also then you might want another class to get a fall event. So when u shoot add them to it, then if there in it and get fall damage it cancels the fall damage. Would get you code but im just going off.
     
  9. Offline

    Reptar_

    That's fine. I'd prefer they didn't fall from it. But I just tried it out. All it does is teleport me to where it explodes. Aren't I supposed to ride it the whole way up?
     
  10. Offline

    chasechocolate

    Well you should with the code you have. But when the firework explodes, the entity will get destroyed, causing you to stop riding it.
     
  11. Offline

    Burnett1

    Ye sorry forgot to mention if you have a slow logging time the firework will already be up when u fully join you may want to add a delay to it. Look at http://wiki.bukkit.org/Scheduler_Programming to delay it by maybe 2-3 seconds.
     
Thread Status:
Not open for further replies.

Share This Page