I need help creating Loosing Rewards at the end of the game.

Discussion in 'Plugin Development' started by VinexAx789, Jun 12, 2015.

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

    VinexAx789

    Hello I need some help giving the loosing teams rewards in my minigame I have done the winners rewards but I'm struggling and sorta confused and mixed up on how to do it here's my code for my winner rewards, I'm using the VAULT API too.

    CODE:

    Code:
    public void end(int winner){
        //0 green
        //1 red
        //2 blue
        //3 purple
        //4 draw
        ended = true;
        if(winner == 0){
            for(Player p : greenplayers){
                 econ1.depositPlayer(p.getPlayer(), 3);
                 p.getPlayer().sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Game Reward §f§l> §f§l§n3§r §a§lCoins");
             }
           
             Title title = new Title("","§a§lGreen Team wins");
             title.setTimingsToTicks();
             title.setFadeOutTime(10);
             title.setFadeInTime(10);
             title.broadcast();
                new BukkitRunnable() {
                    int counter = 8;
                    public void run() {
                            counter = counter - 1;
                            for(Player p : greenplayers){
                                if(p.isOnline()){
                                     Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
                                     FireworkMeta fwm = fw.getFireworkMeta();
                                     Random r = new Random();  
                                     int rt = r.nextInt(4) + 1;
                                     Type type = Type.BALL;      
                                     if (rt == 1) type = Type.BALL;
                                     if (rt == 2) type = Type.BALL_LARGE;
                                     if (rt == 3) type = Type.BURST;
                                     if (rt == 4) type = Type.CREEPER;
                                     if (rt == 5) type = Type.STAR;
                                     Color c1 = Color.LIME;
                                     Color c2 = Color.LIME;
                                     FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
                                     fwm.addEffect(effect);
                                     int rp = r.nextInt(2) + 1;
                                     fwm.setPower(rp);
                                     fw.setFireworkMeta(fwm);
                                }
                            }
                            if(counter == 0){
                                cancel();
                            }
                       
                    }
                }.runTaskTimer(this, 20L, 20L);
            
        }else if(winner == 1){
             for(Player p : redplayers){
                 econ1.depositPlayer(p.getPlayer(), 3);
                 p.getPlayer().sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Game Reward §f§l> §f§l§n3§r §a§lCoins");
             }
             Title title = new Title("","§cRed team wins!");
             title.setTimingsToTicks();
             title.setFadeOutTime(10);
             title.setFadeInTime(10);
             title.broadcast();
    
                new BukkitRunnable() {
                    int counter = 8;
                    public void run() {
                            counter = counter - 1;
                            for(Player p : redplayers){
                                if(p.isOnline()){
                                     Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
                                     FireworkMeta fwm = fw.getFireworkMeta();
                                     Random r = new Random();  
                                     int rt = r.nextInt(4) + 1;
                                     Type type = Type.BALL;      
                                     if (rt == 1) type = Type.BALL;
                                     if (rt == 2) type = Type.BALL_LARGE;
                                     if (rt == 3) type = Type.BURST;
                                     if (rt == 4) type = Type.CREEPER;
                                     if (rt == 5) type = Type.STAR;
                                     Color c1 = Color.RED;
                                     Color c2 = Color.RED;
                                     FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
                                     fwm.addEffect(effect);
                                     int rp = r.nextInt(2) + 1;
                                     fwm.setPower(rp);
                                     fw.setFireworkMeta(fwm);
       
                                }
                            }
                            if(counter == 0){
                                cancel();
                            }
                       
                    }
                }.runTaskTimer(this, 20L, 20L);
        }else if(winner == 2){
             for(Player p : blueplayers){
                 econ1.depositPlayer(p.getPlayer(), 3);
                 p.getPlayer().sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Game Reward §f§l> §f§l§n3§r §a§lCoins");
             }
             Title title = new Title("","§9Blue team wins!");
             title.setTimingsToTicks();
             title.setFadeOutTime(10);
             title.setFadeInTime(10);
             title.broadcast();
                new BukkitRunnable() {
                    int counter = 8;
                    public void run() {
                            counter = counter - 1;
                            for(Player p : blueplayers){
                                if(p.isOnline()){
                                     Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
                                     FireworkMeta fwm = fw.getFireworkMeta();
                                     Random r = new Random();  
                                     int rt = r.nextInt(4) + 1;
                                     Type type = Type.BALL;      
                                     if (rt == 1) type = Type.BALL;
                                     if (rt == 2) type = Type.BALL_LARGE;
                                     if (rt == 3) type = Type.BURST;
                                     if (rt == 4) type = Type.CREEPER;
                                     if (rt == 5) type = Type.STAR;
                                     Color c1 = Color.BLUE;
                                     Color c2 = Color.BLUE;
                                     FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
                                     fwm.addEffect(effect);
                                     int rp = r.nextInt(2) + 1;
                                     fwm.setPower(rp);
                                     fw.setFireworkMeta(fwm); 
                                     /*econ1.depositPlayer(p.getPlayer(), 3);
                                     p.getPlayer().sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Game Reward §f§l> §f§l§n3§r §a§lCoins");*/
                                }
                            }
                            if(counter == 0){
                                cancel();
                            }
                       
                    }
                }.runTaskTimer(this, 20L, 20L);
        }else if(winner == 3){
             for(Player p : purpleplayers){
                 econ1.depositPlayer(p.getPlayer(), 3);
                 p.getPlayer().sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Game Reward §f§l> §f§l§n3§r §a§lCoins");
             }
             Title title = new Title("","§5Purple team wins!");
             title.setTimingsToTicks();
             title.setFadeOutTime(10);
             title.setFadeInTime(10);
             title.broadcast();
                new BukkitRunnable() {
                    int counter = 8;
                    public void run() {
                            counter = counter - 1;
                            for(Player p : purpleplayers){
                                if(p.isOnline()){
                                     Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
                                     FireworkMeta fwm = fw.getFireworkMeta();
                                     Random r = new Random();  
                                     int rt = r.nextInt(4) + 1;
                                     Type type = Type.BALL;      
                                     if (rt == 1) type = Type.BALL;
                                     if (rt == 2) type = Type.BALL_LARGE;
                                     if (rt == 3) type = Type.BURST;
                                     if (rt == 4) type = Type.CREEPER;
                                     if (rt == 5) type = Type.STAR;
                                     Color c1 = Color.PURPLE;
                                     Color c2 = Color.PURPLE;
                                     FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
                                     fwm.addEffect(effect);
                                     int rp = r.nextInt(2) + 1;
                                     fwm.setPower(rp);
                                     fw.setFireworkMeta(fwm);
                                     /*econ1.depositPlayer(p.getPlayer(), 3);
                                     p.getPlayer().sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Game Reward §f§l> §f§l§n3§r §a§lCoins");**/
                               
                                }
                            }
                            if(counter == 0){
                                cancel();
                            }
                       
                    }
                }.runTaskTimer(this, 20L, 20L);
        }else if(winner == 4){
            Bukkit.broadcastMessage("§7§lDraw");
             Title title = new Title("","§7§lDraw");
             title.setTimingsToTicks();
             title.setFadeOutTime(10);
             title.setFadeInTime(10);
             title.broadcast();
                new BukkitRunnable() {
                    int counter = 8;
                    public void run() {
                            counter = counter - 1;
                            for(Player p : players){
                                if(p.isOnline()){
                                     Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
                                     FireworkMeta fwm = fw.getFireworkMeta();
                                     Random r = new Random();
                                     int rt = r.nextInt(4) + 1;
                                     Type type = Type.BALL;      
                                     if (rt == 1) type = Type.BALL;
                                     if (rt == 2) type = Type.BALL_LARGE;
                                     if (rt == 3) type = Type.BURST;
                                     if (rt == 4) type = Type.CREEPER;
                                     if (rt == 5) type = Type.STAR;
                                     Color c1 = Color.WHITE;
                                     Color c2 = Color.WHITE;
                                     FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withFade(c2).with(type).trail(r.nextBoolean()).build();
                                     fwm.addEffect(effect);
                                     int rp = r.nextInt(2) + 1;
                                     fwm.setPower(rp);
                                     fw.setFireworkMeta(fwm);                           
                                }
                            }
                            if(counter == 0){
                                cancel();
                            }
                       
                    }
                }.runTaskTimer(this, 20L, 20L);
        }

    I really need some help.
     
  2. Offline

    LeePMC

    If int winner is the team placing, then just go if winner = the total number of teams playing then give the reward to them, I cant exactly give you the code because people need to learn to work out the code, but this is how you would do it, first I would reccommend searching up how to get amount of teams
     
  3. Offline

    VinexAx789

    @LeePMC Man this is so confusing I understand you don't want me to get the code I'll keep working hard straining my eyes out xD :) Thanks anyway.
     
Thread Status:
Not open for further replies.

Share This Page