added config file for default guests

This commit is contained in:
Gibstick 2013-07-26 16:20:11 -04:00
parent e73f0414d2
commit d8cd43891a
3 changed files with 41 additions and 9 deletions

View File

@ -40,7 +40,7 @@ public class BaaBaaBlockSheepEvents implements Listener {
}
}
// actually make sheep invincible
// actually make sheep and other guests invincible
@EventHandler
public void onLivingEntityDamageEvent(EntityDamageEvent e) {
if (e.getEntity() instanceof Sheep) {
@ -53,6 +53,7 @@ public class BaaBaaBlockSheepEvents implements Listener {
}
}
}
for (DiscoParty party : parent.getParties()) {
if (party.getGuestList().contains(e.getEntity())) {
e.setCancelled(true);

View File

@ -34,15 +34,14 @@ public class DiscoParty {
static int defaultPeriod = 10; // ticks per state change
static int defaultRadius = 5;
static int defaultSheep = 10;
static int defaultCreepers = 1;
static float defaultSheepJump = 0.35f;
static int maxDuration = 2400; // 120 seconds
static int maxSheep = 100;
static int maxRadius = 100;
static int minPeriod = 5; // 0.25 seconds
static int maxPeriod = 40; // 2.0 seconds
static int maxCreepers = 5;
private HashMap<String, Integer> guestNumbers = new HashMap<String, Integer>();
static HashMap<String, Integer> defaultGuestNumbers = new HashMap<String, Integer>();
private boolean doFireworks = false;
private boolean doJump = true;
private int duration, period, radius, sheep;
@ -71,6 +70,8 @@ public class DiscoParty {
this.period = DiscoParty.defaultPeriod;
this.radius = DiscoParty.defaultRadius;
this.sheep = DiscoParty.defaultSheep;
this.guestNumbers = DiscoParty.getDefaultGuestNumbers();
}
public DiscoParty(DiscoSheep parent) {
@ -79,6 +80,7 @@ public class DiscoParty {
this.period = DiscoParty.defaultPeriod;
this.radius = DiscoParty.defaultRadius;
this.sheep = DiscoParty.defaultSheep;
this.guestNumbers = DiscoParty.getDefaultGuestNumbers();
}
// copy but with new player
@ -101,6 +103,10 @@ public class DiscoParty {
return guestList;
}
public static HashMap<String, Integer> getDefaultGuestNumbers() {
return defaultGuestNumbers;
}
public int getSheep() {
return this.sheep;
}
@ -239,7 +245,7 @@ public class DiscoParty {
}
// Mark all guests for removal, then clear the array
void removeAllGuests() {
void removeAll() {
for (Sheep sheeple : getSheepList()) {
sheeple.remove();
}
@ -417,14 +423,13 @@ public class DiscoParty {
}
void startDisco() {
this.guestNumbers.put("CREEPER", 5);
this.spawnAll(sheep, radius);
this.scheduleUpdate();
ds.getPartyMap().put(this.player.getName(), this);
}
void stopDisco() {
removeAllGuests();
removeAll();
this.duration = 0;
if (updater != null) {
updater.cancel();

View File

@ -7,6 +7,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -22,6 +23,7 @@ public final class DiscoSheep extends JavaPlugin {
static final String PERMISSION_CHANGEDEFAULTS = "discosheep.changedefaults";
static final String PERMISSION_SAVECONFIG = "discosheep.saveconfig";
static final String PERMISSION_ONJOIN = "discosheep.onjoin";
static final String PERMISSION_SPAWNGUESTS = "discosheep.spawnguests";
Map<String, DiscoParty> parties = new HashMap<String, DiscoParty>();
private BaaBaaBlockSheepEvents blockEvents = new BaaBaaBlockSheepEvents(this);
FileConfiguration config;
@ -45,6 +47,22 @@ public final class DiscoSheep extends JavaPlugin {
config.addDefault("default.duration", toSeconds_i(DiscoParty.defaultDuration));
config.addDefault("default.period-ticks", DiscoParty.defaultPeriod);
Map<String, Integer> defaultGuests = new HashMap<String, Integer>();
// create a default hashmap of <EntityType, 0> for all living entities
// this creates a default config entry with all living entites present
// except for bosses (they throw NPE for some reason)
for (EntityType ent : EntityType.values()) {
if (ent.isAlive() && !ent.equals(EntityType.ENDER_DRAGON) && !ent.equals(EntityType.WITHER)) {
defaultGuests.put(ent.toString(), 0);
}
}
for (Map.Entry<String, Integer> entry : defaultGuests.entrySet()) {
config.addDefault("default.guests." + entry.getKey(), entry.getValue());
}
loadConfigFromDisk();
}
@ -61,6 +79,11 @@ public final class DiscoSheep extends JavaPlugin {
DiscoParty.defaultRadius = getConfig().getInt("default.radius");
DiscoParty.defaultDuration = toTicks(getConfig().getInt("default.duration"));
DiscoParty.defaultPeriod = getConfig().getInt("default.period-ticks");
for (String key : getConfig().getConfigurationSection("default.guests").getKeys(false)) {
DiscoParty.getDefaultGuestNumbers().put(key, getConfig().getInt("default.guests." + key));
}
}
void reloadConfigFromDisk() {
@ -77,6 +100,10 @@ public final class DiscoSheep extends JavaPlugin {
config.set("default.radius", DiscoParty.defaultRadius);
config.set("default.duration", toSeconds_i(DiscoParty.defaultDuration));
config.set("default.period-ticks", DiscoParty.defaultPeriod);
for (Map.Entry<String, Integer> entry : DiscoParty.getDefaultGuestNumbers().entrySet()) {
config.addDefault("default.guests." + entry.getKey(), entry.getValue());
}
saveConfig();
}
@ -106,7 +133,6 @@ public final class DiscoSheep extends JavaPlugin {
return new ArrayList(this.getPartyMap().values());
}
public void stopParty(String name) {
if (this.hasParty(name)) {
this.getParty(name).stopDisco();