Esempio n. 1
0
 private String getPermission(Noun noun, Verb verb) {
   String nounPerm = noun.getClass().getAnnotation(PermissionName.class).value();
   String verbPerm = verb.getClass().getAnnotation(PermissionName.class).value();
   if (nounPerm == null || verbPerm == null)
     throw new IllegalArgumentException(
         "The arguments you supplied do not specify permission values!");
   return "core.permissions." + nounPerm + "." + verbPerm;
 }
Esempio n. 2
0
 Response doSend() throws IOException {
   connection.setRequestMethod(this.verb.name());
   if (connectTimeout != null) {
     connection.setConnectTimeout(connectTimeout.intValue());
   }
   if (readTimeout != null) {
     connection.setReadTimeout(readTimeout.intValue());
   }
   if (boundary != null) {
     connection.setRequestProperty(CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
   }
   addHeaders(connection);
   if (verb.equals(Verb.PUT) || verb.equals(Verb.POST)) {
     addBody(connection, getByteBodyContents());
   }
   return new Response(connection);
 }
Esempio n. 3
0
 Response doSend(RequestTuner tuner) throws IOException
 {
   connection.setRequestMethod(this.verb.name());
   if (connectTimeout != null) 
   {
     connection.setConnectTimeout(connectTimeout.intValue());
   }
   if (readTimeout != null)
   {
     connection.setReadTimeout(readTimeout.intValue());
   }
   tuner.tune(this);
   addHeaders(connection);
   if (verb.equals(Verb.PUT) || verb.equals(Verb.POST))
   {
     addBody(connection, getByteBodyContents());
   }
   return new Response(connection);
 }
Esempio n. 4
0
 @Override
 protected List<String> handleTabComplete(
     CommandSender sender, Command command, String alias, String[] args) {
   if (!sender.hasPermission(PERMISSION)) return Collections.emptyList();
   // 0 - noun
   // 1 - noun autocomplete
   // 2 - verb
   // 3+ - not supported
   switch (args.length) {
     case 1:
       List<String> nounNames = new ArrayList<>();
       for (Noun<?> noun : nouns) {
         String s1 = args[0].toLowerCase();
         for (String s : noun.getNames()) {
           if (s.toLowerCase().startsWith(s1)) nounNames.add(s);
         }
       }
       return nounNames;
     case 2:
       Noun<?> nounFor = getNounFor(args[0]);
       if (nounFor == null) return Collections.emptyList();
       return nounFor.getTabCompleteFor(args[1]);
     case 3:
       Noun<?> nounFor1 = getNounFor(args[0]);
       if (nounFor1 == null) return Collections.emptyList();
       List<String> strings = new ArrayList<>();
       for (Verb<? extends CPermissible> verb : nounFor1.getVerbs()) {
         String s1 = args[2].toLowerCase();
         for (String s : verb.getNames()) {
           if (s.toLowerCase().startsWith(s1)
               && sender.hasPermission(getPermission(nounFor1, verb))) strings.add(s);
         }
       }
       return strings;
     default:
       return Collections.emptyList();
   }
 }
Esempio n. 5
0
 protected <T extends CPermissible> void handleCommandUnspecific0(
     Noun<T> n, CommandSender sender, String[] args) throws CommandException {
   Verb<T> verb = null;
   for (Verb<T> verb1 : n.getVerbs()) {
     if (RandomUtils.contains(verb1.getNames(), args[2])) verb = verb1;
   }
   if (verb == null)
     throw new ArgumentRequirementException("The verb you specified is not valid!");
   if (!sender.hasPermission(getPermission(n, verb)))
     throw new PermissionException("You do not have permission for this command!");
   if (args.length - 3 < verb.getRequiredArguments())
     throw new ArgumentRequirementException("You have not specified enough arguments!");
   T target = n.get(args[1]);
   String[] strings =
       args.length <= 3 ? new String[] {} : Arrays.copyOfRange(args, 3, args.length);
   if (target == null && !verb.canAcceptNullTarget())
     throw new ArgumentRequirementException("The target you specified is invalid!");
   else if (target == null) strings = new String[] {args[1]};
   verb.perform(sender, target, strings);
   Core.getPermissionsManager().save();
   Core.getPermissionsManager().reloadPermissions();
   if (Core.getNetworkManager() != null)
     Core.getNetworkManager().sendMassNetCommand(new PermissionsReloadNetCommand());
 }