From 572cb5a9d6820fb79e2636c4d3fb0d0953a4d682 Mon Sep 17 00:00:00 2001 From: RangerMauve Date: Sun, 30 Jun 2013 16:13:29 -0400 Subject: [PATCH] Implemented shear prevention on spawned sheep --- .../bukkit/discosheep/DiscoSheep.java | 12 ++++++----- .../bukkit/discosheep/SheepDeshearer.java | 20 ++++++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/gibstick/bukkit/discosheep/DiscoSheep.java b/src/gibstick/bukkit/discosheep/DiscoSheep.java index ba63afc..514a963 100644 --- a/src/gibstick/bukkit/discosheep/DiscoSheep.java +++ b/src/gibstick/bukkit/discosheep/DiscoSheep.java @@ -13,6 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin; public final class DiscoSheep extends JavaPlugin { private ArrayList sheepArray = new ArrayList(); + private SheepDeshearer deshear = new SheepDeshearer(sheepArray); private static final DyeColor[] discoColours = { DyeColor.RED, DyeColor.ORANGE, @@ -33,14 +34,15 @@ public final class DiscoSheep extends JavaPlugin { @Override public void onEnable() { getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this)); + getServer().getPluginManager().registerEvents(deshear, this); } @Override public void onDisable() { - // Watashi Wa Kawaii, Ne? + getServer().getPluginManager(); } - - ArrayList getSheep(){ + + ArrayList getSheep() { return sheepArray; } @@ -71,7 +73,7 @@ public final class DiscoSheep extends JavaPlugin { // Mark all sheep in the sheep array for removal, then clear the array void removeAllSheep() { - for (Sheep sheep: getSheep()) { + for (Sheep sheep : getSheep()) { sheep.remove(); } getSheep().clear(); @@ -80,7 +82,7 @@ public final class DiscoSheep extends JavaPlugin { // Set a random colour for all sheep in array void randomizeSheepColours() { for (Sheep sheep : getSheep()) { - sheep.setColor(discoColours[(int)Math.random() * discoColours.length]); + sheep.setColor(discoColours[(int) Math.random() * discoColours.length]); } } diff --git a/src/gibstick/bukkit/discosheep/SheepDeshearer.java b/src/gibstick/bukkit/discosheep/SheepDeshearer.java index f566f94..d382550 100644 --- a/src/gibstick/bukkit/discosheep/SheepDeshearer.java +++ b/src/gibstick/bukkit/discosheep/SheepDeshearer.java @@ -4,14 +4,28 @@ */ package gibstick.bukkit.discosheep; +import java.util.List; +import org.bukkit.entity.Sheep; +import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerShearEntityEvent; /** * * @author Mauve */ -public class SheepDeshearer implements Listener{ - public SheepDeshearer(DiscoSheep parent){ - +public class SheepDeshearer implements Listener { + + List sheep; + + public SheepDeshearer(List sheep) { + this.sheep = sheep; + } + + @EventHandler + public void onPlayerShear(PlayerShearEntityEvent e) { + if (e.getEntity() instanceof Sheep && sheep.contains((Sheep) e.getEntity())) { + e.setCancelled(true); + } } }