diff --git a/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java b/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java index d3d7e40..3346904 100644 --- a/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java +++ b/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java @@ -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); diff --git a/src/ca/gibstick/discosheep/DiscoParty.java b/src/ca/gibstick/discosheep/DiscoParty.java index 1b13267..4632072 100644 --- a/src/ca/gibstick/discosheep/DiscoParty.java +++ b/src/ca/gibstick/discosheep/DiscoParty.java @@ -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 guestNumbers = new HashMap(); + static HashMap defaultGuestNumbers = new HashMap(); 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 getDefaultGuestNumbers() { + return defaultGuestNumbers; + } + public int getSheep() { return this.sheep; } @@ -227,8 +233,8 @@ public class DiscoParty { void spawnSheep(World world, Location loc) { Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP); newSheep.setColor(discoColours[(int) (Math.random() * (discoColours.length - 1))]); - newSheep.setBreed(false); // this prevents breeding - no event listener required - newSheep.teleport(loc); // teleport is needed to set orientation + newSheep.setBreed(false); // this prevents breeding - no event listener required + newSheep.teleport(loc); // teleport is needed to set orientation getSheepList().add(newSheep); } @@ -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(); diff --git a/src/ca/gibstick/discosheep/DiscoSheep.java b/src/ca/gibstick/discosheep/DiscoSheep.java index f79061a..eadb301 100644 --- a/src/ca/gibstick/discosheep/DiscoSheep.java +++ b/src/ca/gibstick/discosheep/DiscoSheep.java @@ -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 parties = new HashMap(); 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 defaultGuests = new HashMap(); + + + // create a default hashmap of 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 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 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();