From b0f55fbefb46657dd822350f3819dab5bf371857 Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Fri, 12 Jul 2013 11:56:22 -0400 Subject: [PATCH] users now set duration in ticks, and parties now stop on player quit --- .../discosheep/BaaBaaBlockSheepEvents.java | 11 ++++++++- .../bukkit/discosheep/DiscoParty.java | 6 ++--- .../bukkit/discosheep/DiscoSheep.java | 24 +++++++++++-------- .../discosheep/DiscoSheepCommandExecutor.java | 7 +++--- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/gibstick/bukkit/discosheep/BaaBaaBlockSheepEvents.java b/src/gibstick/bukkit/discosheep/BaaBaaBlockSheepEvents.java index aa00fa8..830bc03 100644 --- a/src/gibstick/bukkit/discosheep/BaaBaaBlockSheepEvents.java +++ b/src/gibstick/bukkit/discosheep/BaaBaaBlockSheepEvents.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Sheep; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerShearEntityEvent; /** @@ -22,6 +23,7 @@ public class BaaBaaBlockSheepEvents implements Listener { this.parent = parent; } + // prevent sheep shearing @EventHandler public void onPlayerShear(PlayerShearEntityEvent e) { if (e.getEntity() instanceof Sheep) { @@ -47,4 +49,11 @@ public class BaaBaaBlockSheepEvents implements Listener { } } } -} \ No newline at end of file + + @EventHandler + public void onPlayerQuitEvent(PlayerQuitEvent e) { + String name = e.getPlayer().getName(); + + parent.stopParty(name); + } +} diff --git a/src/gibstick/bukkit/discosheep/DiscoParty.java b/src/gibstick/bukkit/discosheep/DiscoParty.java index d47e8bf..f804ae5 100644 --- a/src/gibstick/bukkit/discosheep/DiscoParty.java +++ b/src/gibstick/bukkit/discosheep/DiscoParty.java @@ -27,7 +27,6 @@ public class DiscoParty { private Player player; private ArrayList sheepList = new ArrayList(); private int duration, frequency = 20; - private int numSheep = 5; static int defaultDuration = 300; // ticks for entire party static int defaultPeriod = 10; // ticks per state change static int defaultRadius = 5; @@ -68,7 +67,6 @@ 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.setTarget(player); newSheep.setBreed(false); getSheep().add(newSheep); } @@ -81,12 +79,14 @@ public class DiscoParty { for (int i = 0; i < num; i++) { double x, y, z; - // random x and z coordinates within a 5 block radius + // random x, z, and yaw // safe y-coordinate x = -sheepSpawnRadius + (Math.random() * ((sheepSpawnRadius * 2) + 1)) + player.getLocation().getX(); z = -sheepSpawnRadius + (Math.random() * ((sheepSpawnRadius * 2) + 1)) + player.getLocation().getZ(); y = world.getHighestBlockYAt((int) x, (int) z); loc = new Location(world, x, y, z); + //loc.setYaw(0); + //loc.setPitch((float) Math.random() * 360 - 180); spawnSheep(world, loc); } } diff --git a/src/gibstick/bukkit/discosheep/DiscoSheep.java b/src/gibstick/bukkit/discosheep/DiscoSheep.java index e4d8d8f..5f1fbf0 100644 --- a/src/gibstick/bukkit/discosheep/DiscoSheep.java +++ b/src/gibstick/bukkit/discosheep/DiscoSheep.java @@ -23,26 +23,26 @@ public final class DiscoSheep extends JavaPlugin { config.addDefault("max.sheep", DiscoParty.maxSheep); config.addDefault("max.radius", DiscoParty.maxRadius); - config.addDefault("max.duration", DiscoParty.maxDuration); - config.addDefault("max.period", DiscoParty.maxPeriod); - config.addDefault("min.period", DiscoParty.minPeriod); + config.addDefault("max.duration", toSeconds_i(DiscoParty.maxDuration)); + config.addDefault("max.period-ticks", DiscoParty.maxPeriod); + config.addDefault("min.period-ticks", DiscoParty.minPeriod); config.addDefault("default.sheep", DiscoParty.defaultSheep); config.addDefault("default.radius", DiscoParty.defaultRadius); - config.addDefault("default.duration", DiscoParty.defaultDuration); - config.addDefault("default.period", DiscoParty.defaultPeriod); + config.addDefault("default.duration", toSeconds_i(DiscoParty.defaultDuration)); + config.addDefault("default.period-ticks", DiscoParty.defaultPeriod); config.options().copyDefaults(true); saveConfig(); DiscoParty.maxSheep = getConfig().getInt("max.sheep"); DiscoParty.maxRadius = getConfig().getInt("max.radius"); - DiscoParty.maxDuration = getConfig().getInt("max.duration"); - DiscoParty.maxPeriod = getConfig().getInt("max.period"); - DiscoParty.minPeriod = getConfig().getInt("min.period"); + DiscoParty.maxDuration = toTicks(getConfig().getInt("max.duration")); + DiscoParty.maxPeriod = getConfig().getInt("max.period-ticks"); + DiscoParty.minPeriod = getConfig().getInt("min.period-ticks"); DiscoParty.defaultSheep = getConfig().getInt("default.sheep"); DiscoParty.defaultRadius = getConfig().getInt("default.radius"); - DiscoParty.defaultDuration = getConfig().getInt("default.duration"); - DiscoParty.defaultPeriod = getConfig().getInt("default.period"); + DiscoParty.defaultDuration = toTicks(getConfig().getInt("default.duration")); + DiscoParty.defaultPeriod = getConfig().getInt("default.period-ticks"); } @Override @@ -57,6 +57,10 @@ public final class DiscoSheep extends JavaPlugin { double toSeconds(int ticks) { return (double) Math.round(ticks / 20.0); } + + int toSeconds_i(int ticks) { + return (int) Math.round(ticks / 20.0); + } public synchronized Map getPartyMap() { return this.parties; diff --git a/src/gibstick/bukkit/discosheep/DiscoSheepCommandExecutor.java b/src/gibstick/bukkit/discosheep/DiscoSheepCommandExecutor.java index 8ca3cfa..899a784 100644 --- a/src/gibstick/bukkit/discosheep/DiscoSheepCommandExecutor.java +++ b/src/gibstick/bukkit/discosheep/DiscoSheepCommandExecutor.java @@ -2,6 +2,7 @@ package gibstick.bukkit.discosheep; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.CommandExecutor; @@ -93,10 +94,10 @@ public class DiscoSheepCommandExecutor implements CommandExecutor { return true; } } else if (args[i].equalsIgnoreCase("-t")) { - duration = parseNextIntArg(args, i); + duration = parent.toTicks(parseNextIntArg(args, i)); - if (duration < 1 || duration > parent.toSeconds(DiscoParty.maxDuration)) { - sender.sendMessage("The duration in ticks must be an integer within the range [1, " + if (duration < 1 || duration > DiscoParty.maxDuration) { + sender.sendMessage("The duration in seconds must be an integer within the range [1, " + parent.toSeconds(DiscoParty.maxDuration) + "]"); return true; }