use of org.mcmonkey.sentinel.SentinelTrait in project Sentinel by mcmonkey4eva.
the class SentinelWorldGuardHelper method onWantsPath.
@EventHandler
public void onWantsPath(SentinelWantsToPathEvent event) {
SentinelTrait sentinel = event.getNPC().getOrAddTrait(SentinelTrait.class);
ProtectedRegion region = getRegionFor(sentinel);
if (region == null) {
return;
}
if (!region.contains(BukkitAdapter.asBlockVector(event.destination))) {
event.setCancelled(true);
}
}
use of org.mcmonkey.sentinel.SentinelTrait in project Sentinel by mcmonkey4eva.
the class SentinelCommand method onCommand.
/**
* Handles a player or server command.
*/
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String modifier = args.length > 0 ? args[0] : "";
if (!manager.hasCommand(command, modifier) && !modifier.isEmpty()) {
String closest = manager.getClosestCommandModifier(command.getName(), modifier);
if (!closest.isEmpty()) {
sender.sendMessage(prefixBad + "Unknown command. Did you mean:");
sender.sendMessage(prefixGood + " /" + command.getName() + " " + closest);
} else {
sender.sendMessage(prefixBad + "Unknown command.");
}
return true;
}
NPC selected = CitizensAPI.getDefaultNPCSelector().getSelected(sender);
SentinelTrait sentinel = null;
CommandContext context = new CommandContext(sender, args);
if (context.hasValueFlag("id") && sender.hasPermission("npc.select")) {
try {
selected = CitizensAPI.getNPCRegistry().getById(context.getFlagInteger("id"));
} catch (NumberFormatException ex) {
sender.sendMessage(prefixBad + "ID input is invalid (not an integer)!");
return true;
}
}
if (selected != null) {
sentinel = selected.getTraitNullable(SentinelTrait.class);
}
Object[] methodArgs;
if (isSentinelRequired(command.getName(), modifier)) {
if (sentinel == null) {
if (selected == null) {
sender.sendMessage(prefixBad + "Must have a Sentinel NPC selected!");
} else {
sender.sendMessage(prefixBad + "Selected NPC is not a Sentinel! Use /trait sentinel to ensure an NPC becomes a Sentinel.");
}
return true;
}
if (!selected.getOrAddTrait(Owner.class).isOwnedBy(sender) && !sender.hasPermission("citizens.admin")) {
sender.sendMessage(prefixBad + "You do not own this NPC (and you are not an admin).");
return true;
}
methodArgs = new Object[] { sender, sentinel };
} else {
methodArgs = new Object[] { sender };
}
return manager.executeSafe(command, args, sender, methodArgs);
}
use of org.mcmonkey.sentinel.SentinelTrait in project Sentinel by mcmonkey4eva.
the class SentinelCommand method onTabComplete.
/**
* Handles tab completion for a player or server command.
*/
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
if (s.equals("sentinel") && strings.length == 2) {
NPC npc = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
if (npc != null && npc.hasTrait(SentinelTrait.class)) {
SentinelTrait sentinel = npc.getOrAddTrait(SentinelTrait.class);
switch(strings[0].toLowerCase()) {
case "addtarget":
case "addignore":
case "addavoid":
String low = strings[1].toLowerCase();
int colon = low.indexOf(':');
if (colon != -1 && colon + 1 < low.length()) {
String prefix = low.substring(0, colon);
if (itemPrefixes.contains(prefix)) {
List<String> materials = filterForArg(materialNames, low.substring(colon + 1));
materials.add("lore:");
materials.add("name:");
return filterForArg(materials.stream().map(m -> prefix + ":" + m).collect(Collectors.toList()), low);
}
}
return filterForArg(addTargetTabCompletions, low);
case "removetarget":
return filterForArg(sentinel.allTargets.getTargetRemovableStrings(), strings[1]);
case "removeignore":
return filterForArg(sentinel.allIgnores.getTargetRemovableStrings(), strings[1]);
case "removeavoid":
return filterForArg(sentinel.allAvoids.getTargetRemovableStrings(), strings[1]);
}
}
}
return manager.onTabComplete(commandSender, command, s, strings);
}
Aggregations