-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
SentinelChaseCommands.java
96 lines (90 loc) · 4.51 KB
/
SentinelChaseCommands.java
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
package org.mcmonkey.sentinel.commands;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.Requirements;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.mcmonkey.sentinel.SentinelTrait;
public class SentinelChaseCommands {
@Command(aliases = {"sentinel"}, usage = "speed SPEED",
desc = "Sets the NPC's movement speed modifier.",
modifiers = {"speed"}, permission = "sentinel.speed", min = 1, max = 2)
@Requirements(livingEntity = true, ownership = true, traits = {SentinelTrait.class})
public void speed(CommandContext args, CommandSender sender, SentinelTrait sentinel) {
if (args.argsLength() <= 1) {
sender.sendMessage(SentinelCommand.prefixGood + "Current speed: " + ChatColor.AQUA + sentinel.speed);
return;
}
try {
Double d = Double.parseDouble(args.getString(1));
if (d < 1000 && d >= 0) {
sentinel.speed = d;
sender.sendMessage(SentinelCommand.prefixGood + "Speed set!");
}
else {
throw new NumberFormatException("Number out of range (must be >= 0 and < 1000).");
}
}
catch (NumberFormatException ex) {
sender.sendMessage(SentinelCommand.prefixBad + "Invalid speed number: " + ex.getMessage());
}
}
@Command(aliases = {"sentinel"}, usage = "chaserange RANGE",
desc = "Changes the maximum distance an NPC will run before returning to base.",
modifiers = {"chaserange"}, permission = "sentinel.chaserange", min = 1, max = 2)
@Requirements(livingEntity = true, ownership = true, traits = {SentinelTrait.class})
public void chaseRange(CommandContext args, CommandSender sender, SentinelTrait sentinel) {
if (args.argsLength() <= 1) {
sender.sendMessage(SentinelCommand.prefixGood + "Current chase range: " + ChatColor.AQUA + sentinel.chaseRange);
return;
}
try {
double d = Double.parseDouble(args.getString(1));
sentinel.chaseRange = d;
sender.sendMessage(SentinelCommand.prefixGood + "Chase range set!");
}
catch (NumberFormatException ex) {
sender.sendMessage(SentinelCommand.prefixBad + "Invalid range number: " + ex.getMessage());
}
}
@Command(aliases = {"sentinel"}, usage = "chaseclose ['true'/'false']",
desc = "Toggles whether the NPC will chase while in 'close quarters' fights.",
modifiers = {"chaseclose"}, permission = "sentinel.chase", min = 1, max = 2)
@Requirements(livingEntity = true, ownership = true, traits = {SentinelTrait.class})
public void chaseClose(CommandContext args, CommandSender sender, SentinelTrait sentinel) {
boolean mode = !sentinel.closeChase;
if (args.argsLength() > 1 && "true".equalsIgnoreCase(args.getString(1))) {
mode = true;
}
if (args.argsLength() > 1 && "false".equalsIgnoreCase(args.getString(1))) {
mode = false;
}
sentinel.closeChase = mode;
if (sentinel.closeChase) {
sender.sendMessage(SentinelCommand.prefixGood + "NPC now will chase while close!");
}
else {
sender.sendMessage(SentinelCommand.prefixGood + "NPC no longer will chase while close!");
}
}
@Command(aliases = {"sentinel"}, usage = "chaseranged ['true'/'false']",
desc = "Toggles whether the NPC will chase while in ranged fights.",
modifiers = {"chaseranged"}, permission = "sentinel.chase", min = 1, max = 2)
@Requirements(livingEntity = true, ownership = true, traits = {SentinelTrait.class})
public void chaseRanged(CommandContext args, CommandSender sender, SentinelTrait sentinel) {
boolean mode = !sentinel.rangedChase;
if (args.argsLength() > 1 && "true".equalsIgnoreCase(args.getString(1))) {
mode = true;
}
if (args.argsLength() > 1 && "false".equalsIgnoreCase(args.getString(1))) {
mode = false;
}
sentinel.rangedChase = mode;
if (sentinel.rangedChase) {
sender.sendMessage(SentinelCommand.prefixGood + "NPC now will chase while ranged!");
}
else {
sender.sendMessage(SentinelCommand.prefixGood + "NPC no longer will chase while ranged!");
}
}
}