From 5abaffeee753d01099dcf7855f9c6ab99b90f93f Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Mon, 17 Aug 2015 13:24:02 -0400 Subject: [PATCH] add BabyParty, update helpCommand --- src/me/cwang/discosheep/BabyParty.java | 45 ++++++++++++++++++++++ src/me/cwang/discosheep/DiscoCommands.java | 4 +- src/me/cwang/discosheep/PartyBuilder.java | 14 +++++-- 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/me/cwang/discosheep/BabyParty.java diff --git a/src/me/cwang/discosheep/BabyParty.java b/src/me/cwang/discosheep/BabyParty.java new file mode 100644 index 0000000..88c8b80 --- /dev/null +++ b/src/me/cwang/discosheep/BabyParty.java @@ -0,0 +1,45 @@ +package me.cwang.discosheep; + +import org.bukkit.entity.Ageable; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Sheep; + +/** + * Created by Charlie on 2015-08-17. + */ +public class BabyParty extends DiscoDecorator { + private int guestBabyCount; + private int sheepBabyCount; + + public BabyParty(AbstractParty p, int babyness) { + super(p); + sheepBabyCount = (int) ((babyness / 100.0d) * getSheep()); + int totalGuests = 0; + for (int i : getGuestMap().values()) { + totalGuests += i; + } + guestBabyCount = (int) ((babyness / 100.0d) * totalGuests); + } + + @Override + protected Entity spawnGuest(EntityType type) { + Entity guest = super.spawnGuest(type); + if (guest instanceof Ageable && guestBabyCount > 0) { + Ageable baby = (Ageable) guest; + baby.setBaby(); + --guestBabyCount; + } + return guest; + } + + @Override + protected Sheep spawnSheep() { + Sheep sheep = super.spawnSheep(); + if (sheepBabyCount > 0) { + sheep.setBaby(); + --sheepBabyCount; + } + return sheep; + } +} diff --git a/src/me/cwang/discosheep/DiscoCommands.java b/src/me/cwang/discosheep/DiscoCommands.java index f7407bf..994ac64 100644 --- a/src/me/cwang/discosheep/DiscoCommands.java +++ b/src/me/cwang/discosheep/DiscoCommands.java @@ -60,7 +60,7 @@ public class DiscoCommands implements CommandExecutor { PartyBuilder builder = new PartyBuilder(player); // ctor takes "program name" as first arg so we pass the sub-command as that // args then start at args[1] so we slice args[1:] - Getopt g = new Getopt(args[0], Arrays.copyOfRange(args, 1, args.length), "n:t:p:r:g:lwjP"); + Getopt g = new Getopt(args[0], Arrays.copyOfRange(args, 1, args.length), "n:t:p:r:g:lwjPb:"); int c; while ((c = g.getopt()) != -1) { @@ -111,6 +111,8 @@ public class DiscoCommands implements CommandExecutor { case 'P': builder.pentatonic(); break; + case 'b': + builder.baby(Integer.parseInt(g.getOptarg())); } } catch (IllegalArgumentException e) { sender.sendMessage("Bad command: " + e.getMessage()); diff --git a/src/me/cwang/discosheep/PartyBuilder.java b/src/me/cwang/discosheep/PartyBuilder.java index f21cefe..a004ff7 100644 --- a/src/me/cwang/discosheep/PartyBuilder.java +++ b/src/me/cwang/discosheep/PartyBuilder.java @@ -22,6 +22,7 @@ public class PartyBuilder { private boolean lightning = false; private boolean jeb = false; private boolean pentatonic = false; + private int babyness = 0; public PartyBuilder(Player player) { this.player = player; @@ -115,10 +116,19 @@ public class PartyBuilder { if (lightning) party = new LightningParty(party); if (jeb) party = new JebParty(party); if (pentatonic) party = new PentatonicParty(party); + if (babyness > 0) party = new BabyParty(party, babyness); return party; } + public void pentatonic() { + pentatonic = true; + } + + public void baby(int babyness) { + this.babyness = babyness; + } + public AbstractParty buildOther(Player newPlayer) { Player oldPlayer = player; player = newPlayer; @@ -127,7 +137,5 @@ public class PartyBuilder { return otherParty; } - public void pentatonic() { - pentatonic = true; - } + }