Skip to content

Commit a158200

Browse files
Add a /twa team command to add existing entities to the TWA_Golems team
1 parent c254e0d commit a158200

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

src/main/java/me/eccentric_nz/tardisweepingangels/commands/TARDISWeepingAngelsCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
7070
case "give" -> {
7171
return new GiveCommand(plugin).give(sender, args);
7272
}
73+
case "team" -> {
74+
return new TeamCommand(plugin).join(sender);
75+
}
7376
case "teleport" -> {
7477
return new TeleportCommand(plugin).add(sender, args);
7578
}

src/main/java/me/eccentric_nz/tardisweepingangels/commands/TabComplete.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
public class TabComplete extends TARDISCompleter implements TabCompleter {
3535

36-
final ImmutableList<String> CMD_SUBS = ImmutableList.of("spawn", "equip", "disguise", "kill", "count", "follow", "stay", "remove", "set", "give", "teleport");
36+
final ImmutableList<String> CMD_SUBS = ImmutableList.of("spawn", "equip", "disguise", "kill", "count", "follow", "stay", "remove", "set", "give", "team", "teleport");
3737
private final ImmutableList<String> ONOFF_SUBS = ImmutableList.of("on", "off");
3838
private final ImmutableList<String> TP_SUBS = ImmutableList.of("replace", "true", "false");
3939
private final ImmutableList<String> WORLD_SUBS;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package me.eccentric_nz.tardisweepingangels.commands;
2+
3+
import me.eccentric_nz.TARDIS.TARDIS;
4+
import me.eccentric_nz.TARDIS.enumeration.TardisModule;
5+
import me.eccentric_nz.TARDIS.sonic.actions.TARDISSonicFreeze;
6+
import me.eccentric_nz.TARDIS.utility.TARDISVector3D;
7+
import me.eccentric_nz.tardisweepingangels.utils.TeamAdder;
8+
import org.bukkit.Location;
9+
import org.bukkit.command.CommandSender;
10+
import org.bukkit.entity.ArmorStand;
11+
import org.bukkit.entity.Entity;
12+
import org.bukkit.entity.EntityType;
13+
import org.bukkit.entity.Player;
14+
15+
public class TeamCommand {
16+
17+
private final TARDIS plugin;
18+
19+
public TeamCommand(TARDIS plugin) {
20+
this.plugin = plugin;
21+
}
22+
23+
public boolean join(CommandSender sender) {
24+
Player player = null;
25+
if (sender instanceof Player) {
26+
player = (Player) sender;
27+
}
28+
if (player == null) {
29+
plugin.getMessenger().send(sender, TardisModule.MONSTERS, "CMD_PLAYER");
30+
return true;
31+
}
32+
// get the entity the player is targeting
33+
Location observerPos = player.getEyeLocation();
34+
TARDISVector3D observerDir = new TARDISVector3D(observerPos.getDirection());
35+
TARDISVector3D observerStart = new TARDISVector3D(observerPos);
36+
TARDISVector3D observerEnd = observerStart.add(observerDir.multiply(16));
37+
Entity entity = null;
38+
// get nearby entities
39+
for (Entity target : player.getNearbyEntities(8.0d, 8.0d, 8.0d)) {
40+
// bounding box of the given player
41+
TARDISVector3D targetPos = new TARDISVector3D(target.getLocation());
42+
TARDISVector3D minimum = targetPos.add(-0.5, 0, -0.5);
43+
TARDISVector3D maximum = targetPos.add(0.5, 1.67, 0.5);
44+
if (TARDISSonicFreeze.hasIntersection(observerStart, observerEnd, minimum, maximum)) {
45+
if (entity == null || entity.getLocation().distanceSquared(observerPos) > target.getLocation().distanceSquared(observerPos)) {
46+
entity = target;
47+
}
48+
}
49+
}
50+
if (entity != null) {
51+
// add entity to the team
52+
TeamAdder.joinTeam(entity);
53+
plugin.getMessenger().send(player, TardisModule.MONSTERS, "WA_TEAM");
54+
} else {
55+
plugin.getMessenger().send(sender, TardisModule.MONSTERS, "WA_TEAM_LOOK");
56+
return true;
57+
}
58+
return true;
59+
}
60+
}

src/main/resources/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,8 @@ WA_STAND: "You are not looking at an armour stand within 8 blocks!"
12751275
WA_STAY: "Please tell your follower to stay before removing it! /twa stay"
12761276
WA_STOLE: "A Weeping Angel stole your TARDIS Key"
12771277
WA_STRAX: "Strax is not lactating right now, try again later."
1278+
WA_TEAM: "Entity added to TWA_Golems team."
1279+
WA_TEAM_LOOK: "You are not looking at an entity within 8 blocks!"
12781280
WA_UUID: "Command can only be used by a player, or a player UUID must be supplied!"
12791281
WEATHER_CLEAR: "clear"
12801282
WEATHER_COLD: "clear, but cold"

0 commit comments

Comments
 (0)