users now set duration in ticks, and parties now stop on player quit
This commit is contained in:
parent
869210e0d2
commit
b0f55fbefb
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuitEvent(PlayerQuitEvent e) {
|
||||
String name = e.getPlayer().getName();
|
||||
|
||||
parent.stopParty(name);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ public class DiscoParty {
|
||||
private Player player;
|
||||
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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<String, DiscoParty> getPartyMap() {
|
||||
return this.parties;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user