@Override public boolean check(RequirementsContext context, List<String> args) throws RequirementCheckException { boolean outcome = false; String name = null; String value = "true"; String index = ""; Type type = Type.PLAYER; for (String arg : args) { if (aH.matchesArg("GLOBAL, NPC, DENIZEN, GLOBAL", arg)) type = Type.valueOf(arg.toUpperCase().replace("DENIZEN", "NPC")); else if (arg.split(":", 2).length > 1) { String[] flagArgs = arg.split(":"); value = flagArgs[1].toUpperCase(); if (flagArgs[0].contains("[")) { name = flagArgs[0].split("\\[", 2)[0].trim(); index = flagArgs[0].split("\\[", 2)[1].split("\\]", 2)[0].trim(); } else { name = flagArgs[0].toUpperCase(); } } else name = arg.toUpperCase(); } FlagManager flagMng = DenizenAPI.getCurrentInstance().flagManager(); FlagManager.Flag flag = null; String player = context.getPlayer().getName(); switch (type) { case NPC: flag = flagMng.getNPCFlag(context.getNPC().getId(), name); break; case PLAYER: flag = flagMng.getPlayerFlag(player, name); break; case GLOBAL: flag = flagMng.getGlobalFlag(name); break; } if (index.length() == 0) { if (flag.getLast().asString().equalsIgnoreCase(value)) outcome = true; else dB.echoDebug( context.getScriptContainer(), "... does not match '" + flag.getLast().asString() + "'."); } else if (index.matches("\\d+")) { if (flag.get(Integer.parseInt(index)).asString().equalsIgnoreCase(value)) outcome = true; else dB.echoDebug( context.getScriptContainer(), "... does not match '" + flag.get(Integer.parseInt(index)).asString() + "'."); } return outcome; }
/** * Removes an NPC from the Registry when removed from Citizens. * * @param event NPCRemoveEvent */ @EventHandler public void onRemove(NPCRemoveEvent event) { NPC npc = event.getNPC(); getDenizen(npc).action("remove", null); if (_isRegistered(npc)) { denizenNPCs.remove(npc.getId()); npcInventories.remove(npc.getId()); } FlagManager.clearNPCFlags(npc.getId()); }