Implemented shear prevention on spawned sheep
This commit is contained in:
parent
9dba2a1be3
commit
572cb5a9d6
@ -13,6 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
public final class DiscoSheep extends JavaPlugin {
|
public final class DiscoSheep extends JavaPlugin {
|
||||||
|
|
||||||
private ArrayList<Sheep> sheepArray = new ArrayList<Sheep>();
|
private ArrayList<Sheep> sheepArray = new ArrayList<Sheep>();
|
||||||
|
private SheepDeshearer deshear = new SheepDeshearer(sheepArray);
|
||||||
private static final DyeColor[] discoColours = {
|
private static final DyeColor[] discoColours = {
|
||||||
DyeColor.RED,
|
DyeColor.RED,
|
||||||
DyeColor.ORANGE,
|
DyeColor.ORANGE,
|
||||||
@ -33,14 +34,15 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
|
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
|
||||||
|
getServer().getPluginManager().registerEvents(deshear, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Watashi Wa Kawaii, Ne?
|
getServer().getPluginManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Sheep> getSheep(){
|
ArrayList<Sheep> getSheep() {
|
||||||
return sheepArray;
|
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
|
// Mark all sheep in the sheep array for removal, then clear the array
|
||||||
void removeAllSheep() {
|
void removeAllSheep() {
|
||||||
for (Sheep sheep: getSheep()) {
|
for (Sheep sheep : getSheep()) {
|
||||||
sheep.remove();
|
sheep.remove();
|
||||||
}
|
}
|
||||||
getSheep().clear();
|
getSheep().clear();
|
||||||
@ -80,7 +82,7 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
// Set a random colour for all sheep in array
|
// Set a random colour for all sheep in array
|
||||||
void randomizeSheepColours() {
|
void randomizeSheepColours() {
|
||||||
for (Sheep sheep : getSheep()) {
|
for (Sheep sheep : getSheep()) {
|
||||||
sheep.setColor(discoColours[(int)Math.random() * discoColours.length]);
|
sheep.setColor(discoColours[(int) Math.random() * discoColours.length]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,14 +4,28 @@
|
|||||||
*/
|
*/
|
||||||
package gibstick.bukkit.discosheep;
|
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.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Mauve
|
* @author Mauve
|
||||||
*/
|
*/
|
||||||
public class SheepDeshearer implements Listener{
|
public class SheepDeshearer implements Listener {
|
||||||
public SheepDeshearer(DiscoSheep parent){
|
|
||||||
|
|
||||||
|
List<Sheep> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user