add BabyParty, update helpCommand
This commit is contained in:
parent
5daee8b5f1
commit
5abaffeee7
45
src/me/cwang/discosheep/BabyParty.java
Normal file
45
src/me/cwang/discosheep/BabyParty.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user