-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttackSheep.java
More file actions
111 lines (97 loc) · 3.72 KB
/
AttackSheep.java
File metadata and controls
111 lines (97 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package incineratorcow2.incineratorcow2;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.*;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Random;
public class AttackSheep extends IncineratorCow {
private JavaPlugin _mainPlugin;
Cow _myCow;
BukkitTask task = null;
Random rand = new Random();
ArrayList<Player> nearbyPlayers = new ArrayList<Player>();
int playerCheckDistance = 30;
public AttackSheep(JavaPlugin mainPlugin, Cow myCow) {
super(mainPlugin, myCow);
_mainPlugin = mainPlugin;
_myCow = myCow;
}
public void Sheep() {
task = new BukkitRunnable() {
Player target;
ArrayList<Sheep> aliveSheep = new ArrayList<Sheep>();
boolean isNoAmo = false;
boolean isPlayer = false;
int i = 0;
int sheepLeft = 0;
@Override
public void run() {
//List<Entity> nearbyEntities = _myCow.getNearbyEntities(30,30,30);
/*for(Entity e : nearbyEntities) {
if(e instanceof Player) {
isPlayer = true;
}
}
if(!isPlayer) {
Bukkit.broadcastMessage("Cancelling");
CancelAbility( false);
task.cancel();
Bukkit.broadcastMessage("not going sheep");
}*/
target = GetRandomPlayer(playerCheckDistance);
if(target != null) {
if (!isNoAmo) {
//launches fireballs
EntityFacePlayer(_myCow, target, false);
launchSheep(target, aliveSheep);
i++;
}
if (i > 4) {
isNoAmo = true;
}
for (Sheep sheep : aliveSheep) {
if (checkSurroundingBlocks(sheep, 1.0)) {
TNTPrimed tntPrimed = (TNTPrimed) Bukkit.getWorld("World").spawnEntity(sheep.getLocation(),
EntityType.PRIMED_TNT);
tntPrimed.setFuseTicks(0);
}
}
Bukkit.broadcastMessage("Alive Sheep: " + aliveSheep.size());
for (Sheep sheep : aliveSheep) {
if (sheep.isDead()) {
aliveSheep.remove(sheep);
}
}
if (aliveSheep.size() == 0) {
_myCow.addScoreboardTag("Ready");
task.cancel();
}
}
else {
CancelAbility(false);
this.cancel();
}
}
}.runTaskTimer(_mainPlugin, 0, 4);
}
private void launchSheep(Player target, ArrayList<Sheep> aliveSheep) {
Location targetLoc;
Vector loc1;
Vector loc2;
Vector direction;
Sheep missileSheep = (Sheep) Bukkit.getWorld("World").spawnEntity(_myCow.getLocation(),
EntityType.SHEEP);
missileSheep.addScoreboardTag("ExplosiveContact");
aliveSheep.add(missileSheep);
targetLoc = target.getLocation();
loc1 = missileSheep.getLocation().toVector();
loc2 = targetLoc .toVector();
loc2.setY(targetLoc.getY() + 1);
direction = (loc2.subtract(loc1).normalize());
missileSheep.setVelocity(direction.multiply(3));
}
}