Fixed bad cast, added more structure for handling multiple players.

This commit is contained in:
RangerMauve 2013-06-30 17:39:57 -04:00
parent c14892f40b
commit a087e07052
2 changed files with 12 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public final class DiscoSheep extends JavaPlugin { public final class DiscoSheep extends JavaPlugin {
private ArrayList<Sheep> sheepArray = new ArrayList<Sheep>(); private ArrayList<Sheep> sheepArray = new ArrayList<Sheep>();
private ArrayList<Player> playerArray = new ArrayList<Player>();
private SheepDeshearer deshear = new SheepDeshearer(sheepArray); private SheepDeshearer deshear = new SheepDeshearer(sheepArray);
private static final DyeColor[] discoColours = { private static final DyeColor[] discoColours = {
DyeColor.RED, DyeColor.RED,
@ -50,6 +51,10 @@ public final class DiscoSheep extends JavaPlugin {
ArrayList<Sheep> getSheep() { ArrayList<Sheep> getSheep() {
return sheepArray; return sheepArray;
} }
ArrayList<Player> getPlayers(){
return this.playerArray;
}
void spawnSheep(World world, Location loc) { void spawnSheep(World world, Location loc) {
Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP); Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP);
@ -103,21 +108,23 @@ public final class DiscoSheep extends JavaPlugin {
// Called after discosheep is stopped // Called after discosheep is stopped
void cleanUp() { void cleanUp() {
removeAllSheep(); removeAllSheep();
this.playerArray.clear();
} }
void scheduleUpdate() { void scheduleUpdate() {
updater.runTaskLater((Plugin) updater, updater.frequency); updater.runTaskLater(this, updater.frequency);
} }
void startDisco(int frequency, int duration, List<Player> players) { void startDisco(int duration, List<Player> players) {
this.playerArray.addAll(players);
for(Player player : players){ for(Player player : players){
this.spawnSheep(player, this.defaultSheepAmount); this.spawnSheep(player, this.defaultSheepAmount);
} }
updater.start(frequency, duration); updater.start(duration,this.defaultFrequency);
} }
void startDisco(List<Player> players) { void startDisco(List<Player> players) {
this.startDisco(this.defaultFrequency,this.defaultDuration,players); this.startDisco(this.defaultDuration,players);
} }
void stopDisco() { void stopDisco() {

View File

@ -15,7 +15,7 @@ public class DiscoUpdater extends BukkitRunnable {
this.duration = 0; this.duration = 0;
parent.cleanUp(); parent.cleanUp();
} }
public void start(int duration, int frequency) { public void start(int duration, int frequency) {
this.frequency = frequency; this.frequency = frequency;
this.duration = duration; this.duration = duration;