Skip to content

Commit

Permalink
Finish: the fireworks are launched in a small area centered on the pl…
Browse files Browse the repository at this point in the history
…ayer.

(Not from an unique point.)
  • Loading branch information
AmauryCarrade committed Sep 14, 2014
1 parent 757633d commit 023f92a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
package me.azenet.UHPlugin.task;

import java.util.List;
import java.util.Random;

import me.azenet.UHPlugin.UHPlugin;
import me.azenet.UHPlugin.UHUtils;

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

Expand All @@ -32,19 +34,34 @@ public class FireworksOnWinnersTask extends BukkitRunnable {
private UHPlugin p = null;
private List<Player> winners = null;

private Double areaSize;
private Random rand;

private long startTime = 0L;

public FireworksOnWinnersTask(UHPlugin p, List<Player> winners) {
this.p = p;
this.winners = winners;

this.areaSize = p.getConfig().getDouble("finish.fireworks.areaSize");
this.rand = new Random();

this.startTime = System.currentTimeMillis();
}

@Override
public void run() {
// The fireworks are launched in a square centered on the player.
Double halfAreaSize = areaSize / 2;

for(Player winner : winners) {
UHUtils.generateRandomFirework(winner.getLocation(), 0, 5);
Location fireworkLocation = winner.getLocation();

fireworkLocation.add(rand.nextDouble() * areaSize - halfAreaSize, // a number between -halfAreaSize and halfAreaSize
2, // y+2 for a clean vision of the winner.
rand.nextDouble() * areaSize - halfAreaSize);

UHUtils.generateRandomFirework(fireworkLocation, 0, 5);
}

if((System.currentTimeMillis() - startTime) / 1000 > p.getConfig().getInt("finish.fireworks.duration", 10)) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ finish:
fireworks:
enabled: true # If true, some fireworks will be launched at the location of the winners.
duration: 10 # In seconds.
areaSize: 6 # The size of the square, centered on each player, where the fireworks will be launched.


dynmap:
Expand Down

0 comments on commit 023f92a

Please sign in to comment.