-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
SentinelChaseCommands.java
122 lines (115 loc) · 5.99 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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.command.CommandSender;
import org.mcmonkey.sentinel.SentinelPlugin;
import org.mcmonkey.sentinel.SentinelTrait;
import org.mcmonkey.sentinel.utilities.SentinelWorldGuardHelper;
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: " + SentinelCommand.colorEmphasis + 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: " + SentinelCommand.colorEmphasis + 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 = "wgregion REGION_NAME",
desc = "Limits the NPC to only chase inside of a WorldGuard region.",
modifiers = {"wgregion"}, permission = "sentinel.wgregion", min = 1, max = 2)
@Requirements(livingEntity = true, ownership = true, traits = {SentinelTrait.class})
public void wgRegion(CommandContext args, CommandSender sender, SentinelTrait sentinel) {
if (!SentinelPlugin.instance.hasWorldGuard) {
sender.sendMessage(SentinelCommand.prefixBad + "WorldGuard not loaded! This command does nothing!");
return;
}
if (args.argsLength() <= 1) {
sentinel.worldguardRegionCache = null;
sentinel.worldguardRegion = null;
sender.sendMessage(SentinelCommand.prefixGood + "WorldGuard region limit disabled.");
return;
}
Object region = SentinelWorldGuardHelper.getRegionFor(args.getString(1), sentinel.getNPC().getStoredLocation().getWorld());
if (region == null) {
sender.sendMessage(SentinelCommand.prefixBad + "Invalid WorldGuard region name!");
return;
}
sentinel.worldguardRegion = args.getString(1);
sentinel.worldguardRegionCache = region;
sender.sendMessage(SentinelCommand.prefixGood + "WorldGuard region limit set!");
}
@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!");
}
}
}